@istmx/ui 0.1.12 → 0.1.13
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 -21
- package/README.md +533 -469
- package/bin/istmx.mjs +481 -318
- package/package.json +27 -27
- package/registry/accordion.tsx +186 -0
- package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
- package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
- package/registry/ai-chat-block/attachment.tsx +466 -466
- package/registry/ai-chat-block/chat-code-block.tsx +50 -50
- package/registry/ai-chat-block/chat-composer.tsx +51 -51
- package/registry/ai-chat-block/chat-logo.tsx +18 -18
- package/registry/ai-chat-block/chat-message.tsx +161 -161
- package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
- package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
- package/registry/ai-chat-block/code-highlighter.tsx +342 -357
- package/registry/ai-chat-block/default-attachments.tsx +42 -42
- package/registry/ai-chat-block/index.ts +30 -30
- package/registry/ai-chat-block/message-content.tsx +287 -287
- package/registry/ai-chat-block/message-list.tsx +93 -93
- package/registry/ai-chat-block/send-button.tsx +102 -102
- package/registry/ai-chat-block/types.ts +70 -71
- package/registry/ai-chat-block/utils.ts +6 -6
- package/registry/ai-chat-block/voice-button.tsx +66 -66
- package/registry/alert-dialog.tsx +229 -0
- package/registry/alert.tsx +188 -0
- package/registry/animated-text.tsx +228 -225
- package/registry/aspect-ratio.tsx +32 -0
- package/registry/avatar-group.tsx +66 -0
- package/registry/avatar.tsx +121 -0
- package/registry/badge.tsx +52 -0
- package/registry/bento-grid.tsx +438 -433
- package/registry/button.tsx +156 -237
- package/registry/carousel.tsx +184 -0
- package/registry/dock-navigation.tsx +200 -198
- package/registry/drift-canvas.tsx +383 -0
- package/registry/drift-wall.tsx +361 -0
- package/registry/flex-carousel.tsx +1430 -0
- package/registry/guided-gallery.tsx +1506 -0
- package/registry/image-accordion.tsx +306 -302
- package/registry/image-trail.tsx +126 -121
- package/registry/infinite-image-canvas.tsx +268 -263
- package/registry/input-otp.tsx +332 -0
- package/registry/list-card.tsx +130 -0
- package/registry/mobile-menu-dock.tsx +216 -211
- package/registry/morph-slider.tsx +756 -0
- package/registry/pixel-cat.tsx +972 -1020
- package/registry/scroll-canvas-cards.tsx +643 -640
- package/registry/scroll-parallax-hero.tsx +566 -565
- package/registry/scroll-story-cards.tsx +443 -438
- package/registry/slider.tsx +163 -0
- package/registry/spotlight-grid.tsx +226 -0
- package/registry/streaming-text.tsx +269 -278
- package/registry/text-reveal.tsx +311 -307
- package/registry/user-avatar.tsx +99 -0
- package/registry/utils.ts +6 -6
package/registry/pixel-cat.tsx
CHANGED
|
@@ -1,1020 +1,972 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
type
|
|
34
|
-
type
|
|
35
|
-
type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
(x
|
|
123
|
-
(
|
|
124
|
-
(y
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
[
|
|
135
|
-
[
|
|
136
|
-
[
|
|
137
|
-
[1,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
[
|
|
142
|
-
[
|
|
143
|
-
[
|
|
144
|
-
[1,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
[
|
|
149
|
-
[3,
|
|
150
|
-
[
|
|
151
|
-
[
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
g.rect(hx +
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
g.px(hx +
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
g.
|
|
175
|
-
g.px(hx
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
g.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
g.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
g.px(cx
|
|
192
|
-
g.px(cx, hy +
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
eye(hx +
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
g.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
g.px(hx +
|
|
206
|
-
g.px(hx +
|
|
207
|
-
g.px(hx +
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
g.px(hx - 2, hy +
|
|
212
|
-
g.px(hx
|
|
213
|
-
g.px(hx + 14, hy +
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
[
|
|
230
|
-
[
|
|
231
|
-
[
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
let
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (legs ===
|
|
244
|
-
if (legs ===
|
|
245
|
-
if (legs ===
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
g.
|
|
254
|
-
g.rect(
|
|
255
|
-
g.rect(
|
|
256
|
-
g.rect(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
g.rect(
|
|
263
|
-
g.rect(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
g.round(
|
|
269
|
-
g.
|
|
270
|
-
g.rect(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
g.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
g.
|
|
282
|
-
g.
|
|
283
|
-
g.rect(
|
|
284
|
-
g
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
drawLeg(g,
|
|
289
|
-
|
|
290
|
-
g.round(
|
|
291
|
-
g.
|
|
292
|
-
g.rect(
|
|
293
|
-
g
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
g.
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
{ body: 'sit' },
|
|
323
|
-
{ body: 'sit'
|
|
324
|
-
{ body: 'sit' },
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
{ body: 'loaf', breath:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
{ eyes: 'wide', tallEars: true, tail: 'up', sway:
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
{ body: 'sit', pawLick: true, headDX: 1, headDY:
|
|
360
|
-
{ body: 'sit', pawLick:
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
.
|
|
375
|
-
.
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
)
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
canvas.
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
img.data[p * 4] =
|
|
412
|
-
img.data[p * 4 +
|
|
413
|
-
img.data[p * 4 +
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
| '
|
|
482
|
-
| '
|
|
483
|
-
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
if (
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
if (
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
if (
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
{interactive && (
|
|
974
|
-
<button
|
|
975
|
-
type="button"
|
|
976
|
-
tabIndex={0}
|
|
977
|
-
aria-label={`Pet the ${breed} cat`}
|
|
978
|
-
onClick={handlePet}
|
|
979
|
-
className="focus-visible:ring-ring pointer-events-auto absolute -inset-2 cursor-pointer rounded-full outline-none focus-visible:ring-1"
|
|
980
|
-
/>
|
|
981
|
-
)}
|
|
982
|
-
|
|
983
|
-
{/* Speech Bubble */}
|
|
984
|
-
<AnimatePresence>
|
|
985
|
-
{bubbleText && (
|
|
986
|
-
<motion.div
|
|
987
|
-
key={bubbleText}
|
|
988
|
-
initial={{ opacity: 0, y: 4, scale: 0.9 }}
|
|
989
|
-
animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
990
|
-
exit={{ opacity: 0, y: -2, scale: 0.9 }}
|
|
991
|
-
transition={{ duration: 0.18 }}
|
|
992
|
-
className="border-border bg-popover text-popover-foreground pointer-events-none absolute bottom-full left-1/2 mb-1.5 -translate-x-1/2 rounded-md border px-2 py-0.5 font-mono text-[11px] font-medium whitespace-nowrap shadow-sm"
|
|
993
|
-
>
|
|
994
|
-
{bubbleText}
|
|
995
|
-
{/* Tiny speech pointer notch */}
|
|
996
|
-
<div className="border-border bg-popover absolute -bottom-1 left-1/2 h-1.5 w-1.5 -translate-x-1/2 rotate-45 border-r border-b" />
|
|
997
|
-
</motion.div>
|
|
998
|
-
)}
|
|
999
|
-
</AnimatePresence>
|
|
1000
|
-
|
|
1001
|
-
{/* Floating Hearts Reaction */}
|
|
1002
|
-
<AnimatePresence>
|
|
1003
|
-
{hearts.map((h) => (
|
|
1004
|
-
<motion.span
|
|
1005
|
-
key={h.id}
|
|
1006
|
-
initial={{ opacity: 1, y: 0, x: h.x, scale: 0.8 }}
|
|
1007
|
-
animate={{ opacity: 0, y: -24, scale: 1.2 }}
|
|
1008
|
-
exit={{ opacity: 0 }}
|
|
1009
|
-
transition={{ duration: 1, ease: 'easeOut' }}
|
|
1010
|
-
className="pointer-events-none absolute -top-1 left-1/2 -translate-x-1/2 text-xs leading-none select-none"
|
|
1011
|
-
>
|
|
1012
|
-
❤️
|
|
1013
|
-
</motion.span>
|
|
1014
|
-
))}
|
|
1015
|
-
</AnimatePresence>
|
|
1016
|
-
</motion.div>
|
|
1017
|
-
)
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
export default PixelCat
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
forwardRef,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useId,
|
|
8
|
+
useImperativeHandle,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
type CSSProperties,
|
|
12
|
+
} from 'react'
|
|
13
|
+
import {
|
|
14
|
+
AnimatePresence,
|
|
15
|
+
animate,
|
|
16
|
+
motion,
|
|
17
|
+
useMotionValue,
|
|
18
|
+
useReducedMotion,
|
|
19
|
+
} from 'motion/react'
|
|
20
|
+
import { cn } from '@/lib/utils'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export const CAT_SIZE = 32
|
|
24
|
+
export const CAT_FEET_Y = 27
|
|
25
|
+
|
|
26
|
+
export type PixelCatBreed =
|
|
27
|
+
'white' | 'orange' | 'black' | 'calico' | 'gray' | 'theme'
|
|
28
|
+
|
|
29
|
+
export type PixelCatPose =
|
|
30
|
+
'idle' | 'walk' | 'sit' | 'sleep' | 'alert' | 'happy' | 'stretch' | 'groom'
|
|
31
|
+
|
|
32
|
+
type Eyes = 'open' | 'blink' | 'happy' | 'closed' | 'wide'
|
|
33
|
+
type Mouth = 'smile' | 'open'
|
|
34
|
+
type TailKind = 'low' | 'mid' | 'up'
|
|
35
|
+
type Body = 'stand' | 'sit' | 'loaf' | 'stretch' | 'scratch'
|
|
36
|
+
|
|
37
|
+
interface CatFrame {
|
|
38
|
+
body?: Body
|
|
39
|
+
bob?: number
|
|
40
|
+
headDX?: number
|
|
41
|
+
headDY?: number
|
|
42
|
+
eyes?: Eyes
|
|
43
|
+
mouth?: Mouth
|
|
44
|
+
tallEars?: boolean
|
|
45
|
+
tail?: TailKind
|
|
46
|
+
sway?: number
|
|
47
|
+
legs?: 0 | 1 | 2 | 3 | 'jump'
|
|
48
|
+
breath?: number
|
|
49
|
+
pawLick?: boolean
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const CAT_PALETTES: Record<
|
|
53
|
+
PixelCatBreed,
|
|
54
|
+
Record<1 | 2 | 3 | 4, string>
|
|
55
|
+
> = {
|
|
56
|
+
white: {
|
|
57
|
+
1: '#f5f5f5',
|
|
58
|
+
2: '#cccccc',
|
|
59
|
+
3: '#18181b',
|
|
60
|
+
4: '#27272a',
|
|
61
|
+
},
|
|
62
|
+
orange: {
|
|
63
|
+
1: '#f59e0b',
|
|
64
|
+
2: '#d97706',
|
|
65
|
+
3: '#451a03',
|
|
66
|
+
4: '#78350f',
|
|
67
|
+
},
|
|
68
|
+
black: {
|
|
69
|
+
1: '#262626',
|
|
70
|
+
2: '#3f3f46',
|
|
71
|
+
3: '#facc15',
|
|
72
|
+
4: '#09090b',
|
|
73
|
+
},
|
|
74
|
+
calico: {
|
|
75
|
+
1: '#fef3c7',
|
|
76
|
+
2: '#ea580c',
|
|
77
|
+
3: '#18181b',
|
|
78
|
+
4: '#27272a',
|
|
79
|
+
},
|
|
80
|
+
gray: {
|
|
81
|
+
1: '#94a3b8',
|
|
82
|
+
2: '#64748b',
|
|
83
|
+
3: '#0f172a',
|
|
84
|
+
4: '#1e293b',
|
|
85
|
+
},
|
|
86
|
+
theme: {
|
|
87
|
+
1: '#e4e4e7',
|
|
88
|
+
2: '#a1a1aa',
|
|
89
|
+
3: '#18181b',
|
|
90
|
+
4: '#27272a',
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
class Grid {
|
|
95
|
+
data = new Uint8Array(CAT_SIZE * CAT_SIZE)
|
|
96
|
+
px(x: number, y: number, v: number) {
|
|
97
|
+
if (x < 0 || y < 0 || x >= CAT_SIZE || y >= CAT_SIZE) return
|
|
98
|
+
this.data[y * CAT_SIZE + x] = v
|
|
99
|
+
}
|
|
100
|
+
rect(x: number, y: number, w: number, h: number, v: number) {
|
|
101
|
+
for (let j = 0; j < h; j++) {
|
|
102
|
+
for (let i = 0; i < w; i++) this.px(x + i, y + j, v)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
round(x: number, y: number, w: number, h: number, v: number, r = 1) {
|
|
106
|
+
for (let j = 0; j < h; j++) {
|
|
107
|
+
for (let i = 0; i < w; i++) {
|
|
108
|
+
const cx = Math.min(i, w - 1 - i)
|
|
109
|
+
const cy = Math.min(j, h - 1 - j)
|
|
110
|
+
if (cx + cy < r) continue
|
|
111
|
+
this.px(x + i, y + j, v)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
outline() {
|
|
116
|
+
const src = this.data.slice()
|
|
117
|
+
for (let y = 0; y < CAT_SIZE; y++) {
|
|
118
|
+
for (let x = 0; x < CAT_SIZE; x++) {
|
|
119
|
+
if (src[y * CAT_SIZE + x]) continue
|
|
120
|
+
const n =
|
|
121
|
+
(x > 0 && src[y * CAT_SIZE + x - 1]) ||
|
|
122
|
+
(x < CAT_SIZE - 1 && src[y * CAT_SIZE + x + 1]) ||
|
|
123
|
+
(y > 0 && src[(y - 1) * CAT_SIZE + x]) ||
|
|
124
|
+
(y < CAT_SIZE - 1 && src[(y + 1) * CAT_SIZE + x])
|
|
125
|
+
if (n) this.data[y * CAT_SIZE + x] = 4
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const TAILS: Record<TailKind, [number, number][]> = {
|
|
132
|
+
low: [
|
|
133
|
+
[4, 15],
|
|
134
|
+
[3, 16],
|
|
135
|
+
[2, 17],
|
|
136
|
+
[1, 18],
|
|
137
|
+
[1, 20],
|
|
138
|
+
],
|
|
139
|
+
mid: [
|
|
140
|
+
[4, 14],
|
|
141
|
+
[3, 13],
|
|
142
|
+
[2, 12],
|
|
143
|
+
[1, 11],
|
|
144
|
+
[1, 9],
|
|
145
|
+
],
|
|
146
|
+
up: [
|
|
147
|
+
[4, 14],
|
|
148
|
+
[3, 12],
|
|
149
|
+
[3, 10],
|
|
150
|
+
[2, 8],
|
|
151
|
+
[3, 6],
|
|
152
|
+
],
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function drawTail(g: Grid, kind: TailKind, sway: number, dy: number) {
|
|
156
|
+
TAILS[kind].forEach(([x, y], i) => {
|
|
157
|
+
const dx = i >= 4 ? sway * 2 : i >= 2 ? sway : 0
|
|
158
|
+
g.rect(x + dx, y + dy, 2, 2, 1)
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function drawHead(g: Grid, hx: number, hy: number, f: CatFrame) {
|
|
163
|
+
const tall = f.tallEars ? 1 : 0
|
|
164
|
+
for (let row = 0; row < 4 + tall; row++) {
|
|
165
|
+
const y = hy - 4 - tall + row
|
|
166
|
+
const w = row - tall + 1 > 0 ? row - tall + 1 : 1
|
|
167
|
+
g.rect(hx + 1, y, w, 1, 1)
|
|
168
|
+
g.rect(hx + 12 - w, y, w, 1, 1)
|
|
169
|
+
}
|
|
170
|
+
g.px(hx + 2, hy - 2, 2)
|
|
171
|
+
g.px(hx + 10, hy - 2, 2)
|
|
172
|
+
|
|
173
|
+
g.round(hx, hy, 13, 10, 1, 2)
|
|
174
|
+
g.px(hx - 1, hy + 5, 1)
|
|
175
|
+
g.px(hx + 13, hy + 5, 1)
|
|
176
|
+
|
|
177
|
+
const eye = (cx: number, mirror: boolean) => {
|
|
178
|
+
const e = f.eyes ?? 'open'
|
|
179
|
+
if (e === 'open') {
|
|
180
|
+
const glintX = mirror ? cx : cx - 1
|
|
181
|
+
g.rect(glintX, hy + 3, 2, 2, 3)
|
|
182
|
+
g.px(glintX, hy + 3, 1)
|
|
183
|
+
} else if (e === 'blink' || e === 'closed') {
|
|
184
|
+
g.rect(mirror ? cx - 1 : cx - 1, hy + 4, 3, 1, 3)
|
|
185
|
+
} else if (e === 'wide') {
|
|
186
|
+
const glintX = mirror ? cx - 1 : cx - 1
|
|
187
|
+
g.rect(glintX, hy + 2, 3, 3, 3)
|
|
188
|
+
g.px(glintX, hy + 2, 1)
|
|
189
|
+
} else if (e === 'happy') {
|
|
190
|
+
g.px(cx - 1, hy + 4, 3)
|
|
191
|
+
g.px(cx, hy + 3, 3)
|
|
192
|
+
g.px(cx + 1, hy + 4, 3)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
eye(hx + 3, false)
|
|
196
|
+
eye(hx + 9, true)
|
|
197
|
+
|
|
198
|
+
g.rect(hx + 5, hy + 5, 2, 1, 3)
|
|
199
|
+
|
|
200
|
+
if (f.mouth === 'open') {
|
|
201
|
+
g.rect(hx + 5, hy + 6, 2, 2, 3)
|
|
202
|
+
g.px(hx + 5, hy + 7, 2)
|
|
203
|
+
} else {
|
|
204
|
+
g.px(hx + 5, hy + 6, 3)
|
|
205
|
+
g.px(hx + 6, hy + 6, 3)
|
|
206
|
+
g.px(hx + 4, hy + 5, 3)
|
|
207
|
+
g.px(hx + 7, hy + 5, 3)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
g.px(hx - 2, hy + 5, 2)
|
|
211
|
+
g.px(hx - 2, hy + 7, 2)
|
|
212
|
+
g.px(hx + 14, hy + 5, 2)
|
|
213
|
+
g.px(hx + 14, hy + 7, 2)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function drawLeg(g: Grid, x: number, y0: number, len: number, v: number) {
|
|
217
|
+
g.rect(x, y0, 2, len, v)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function buildCatGrid(f: CatFrame): Uint8Array {
|
|
221
|
+
const g = new Grid()
|
|
222
|
+
const body = f.body ?? 'stand'
|
|
223
|
+
const bob = f.bob ?? 0
|
|
224
|
+
|
|
225
|
+
if (body === 'stand') {
|
|
226
|
+
const legs = f.legs
|
|
227
|
+
const spec: [number, number, 'A' | 'B'][] = [
|
|
228
|
+
[5, 1, 'A'],
|
|
229
|
+
[8, 2, 'B'],
|
|
230
|
+
[14, 2, 'A'],
|
|
231
|
+
[17, 1, 'B'],
|
|
232
|
+
]
|
|
233
|
+
drawTail(g, f.tail ?? 'low', f.sway ?? 0, bob)
|
|
234
|
+
spec.forEach(([x, v, pair]) => {
|
|
235
|
+
let dx = 0
|
|
236
|
+
let lift = 0
|
|
237
|
+
if (legs === 'jump') {
|
|
238
|
+
dx = x < 12 ? -2 : 2
|
|
239
|
+
lift = 0
|
|
240
|
+
} else if (legs !== undefined) {
|
|
241
|
+
const A = pair === 'A'
|
|
242
|
+
if (legs === 0) dx = A ? 1 : -1
|
|
243
|
+
if (legs === 1) lift = A ? 1 : 0
|
|
244
|
+
if (legs === 2) dx = A ? -1 : 1
|
|
245
|
+
if (legs === 3) lift = A ? 0 : 1
|
|
246
|
+
}
|
|
247
|
+
const top = 22 + bob
|
|
248
|
+
const len = 5 - lift - (legs === 'jump' ? 1 : 0)
|
|
249
|
+
drawLeg(g, x + dx, top, Math.max(1, len), v)
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
g.round(4, 12 + bob, 17, 10, 1, 2)
|
|
253
|
+
g.rect(6, 22 + bob, 13, 1, 1)
|
|
254
|
+
g.rect(8, 23 + bob, 9, 1, 2)
|
|
255
|
+
g.rect(7, 14 + bob, 3, 1, 2)
|
|
256
|
+
g.rect(11, 14 + bob, 2, 1, 2)
|
|
257
|
+
|
|
258
|
+
drawHead(g, 17 + (f.headDX ?? 0), 8 + (f.headDY ?? 0) + bob, f)
|
|
259
|
+
} else if (body === 'sit') {
|
|
260
|
+
for (let x = 2; x <= 22; x++) g.rect(x, 26, 1, 2, 1)
|
|
261
|
+
g.rect(1, 24, 2, 3, 1)
|
|
262
|
+
g.rect(23, 25, 2, 2, 1)
|
|
263
|
+
g.rect(24, 23, 2, 3, 1)
|
|
264
|
+
const sway = f.sway ?? 0
|
|
265
|
+
if (sway) g.px(25, 22, 1)
|
|
266
|
+
|
|
267
|
+
g.round(4, 14, 13, 12, 1, 3)
|
|
268
|
+
g.round(13, 10, 10, 16, 1, 2)
|
|
269
|
+
g.rect(18, 22, 3, 4, 2)
|
|
270
|
+
g.rect(13, 24, 3, 2, 2)
|
|
271
|
+
|
|
272
|
+
if (f.pawLick) {
|
|
273
|
+
g.rect(18, 15, 3, 3, 1)
|
|
274
|
+
g.px(19, 14, 3)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
drawHead(g, 15 + (f.headDX ?? 0), 4 + (f.headDY ?? 0), f)
|
|
278
|
+
} else if (body === 'loaf') {
|
|
279
|
+
const b = f.breath ?? 0
|
|
280
|
+
g.rect(2, 22, 2, 4, 1)
|
|
281
|
+
g.round(3, 15 - b, 24, 12 + b, 1, 4)
|
|
282
|
+
g.rect(5, 25, 18, 1, 2)
|
|
283
|
+
g.rect(24, 23, 2, 3, 1)
|
|
284
|
+
drawHead(g, 17, 14 - b, { ...f, eyes: 'closed' })
|
|
285
|
+
} else if (body === 'stretch') {
|
|
286
|
+
drawTail(g, 'up', 1, -2)
|
|
287
|
+
drawLeg(g, 5, 18, 9, 1)
|
|
288
|
+
drawLeg(g, 8, 18, 9, 2)
|
|
289
|
+
g.round(5, 10, 15, 8, 1, 2)
|
|
290
|
+
g.round(13, 15, 10, 8, 1, 2)
|
|
291
|
+
g.rect(18, 24, 8, 2, 1)
|
|
292
|
+
g.rect(20, 25, 6, 2, 2)
|
|
293
|
+
drawHead(g, 19, 13, { ...f, eyes: 'closed' })
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
g.outline()
|
|
297
|
+
return g.data
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const IDLE_TAIL = [0, 1, 0, -1]
|
|
301
|
+
const idleFrames: CatFrame[] = Array.from({ length: 12 }, (_, i) => ({
|
|
302
|
+
tail: 'up',
|
|
303
|
+
sway: IDLE_TAIL[i % 4],
|
|
304
|
+
eyes: i === 9 ? 'blink' : 'open',
|
|
305
|
+
}))
|
|
306
|
+
|
|
307
|
+
const ANIMATIONS: Record<PixelCatPose, { fps: number; frames: CatFrame[] }> = {
|
|
308
|
+
idle: { fps: 4, frames: idleFrames },
|
|
309
|
+
walk: {
|
|
310
|
+
fps: 8,
|
|
311
|
+
frames: [0, 1, 2, 3].map((p) => ({
|
|
312
|
+
legs: p as 0 | 1 | 2 | 3,
|
|
313
|
+
tail: 'up',
|
|
314
|
+
sway: p % 2 === 0 ? 1 : -1,
|
|
315
|
+
bob: p % 2 === 1 ? -1 : 0,
|
|
316
|
+
})),
|
|
317
|
+
},
|
|
318
|
+
sit: {
|
|
319
|
+
fps: 2,
|
|
320
|
+
frames: [
|
|
321
|
+
{ body: 'sit' },
|
|
322
|
+
{ body: 'sit', sway: 1 },
|
|
323
|
+
{ body: 'sit' },
|
|
324
|
+
{ body: 'sit', eyes: 'blink' },
|
|
325
|
+
],
|
|
326
|
+
},
|
|
327
|
+
sleep: {
|
|
328
|
+
fps: 1,
|
|
329
|
+
frames: [
|
|
330
|
+
{ body: 'loaf', breath: 0 },
|
|
331
|
+
{ body: 'loaf', breath: 1 },
|
|
332
|
+
],
|
|
333
|
+
},
|
|
334
|
+
alert: {
|
|
335
|
+
fps: 3,
|
|
336
|
+
frames: [
|
|
337
|
+
{ eyes: 'wide', tallEars: true, tail: 'up', sway: 0 },
|
|
338
|
+
{ eyes: 'wide', tallEars: true, tail: 'up', sway: 1 },
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
happy: {
|
|
342
|
+
fps: 8,
|
|
343
|
+
frames: [0, -3, 0, -3].map((b, i) => ({
|
|
344
|
+
bob: b,
|
|
345
|
+
eyes: 'happy' as const,
|
|
346
|
+
tail: 'up' as const,
|
|
347
|
+
sway: i % 2 ? 1 : -1,
|
|
348
|
+
legs: b < 0 ? ('jump' as const) : undefined,
|
|
349
|
+
})),
|
|
350
|
+
},
|
|
351
|
+
stretch: {
|
|
352
|
+
fps: 2,
|
|
353
|
+
frames: [{ body: 'stretch' }, { body: 'stretch' }],
|
|
354
|
+
},
|
|
355
|
+
groom: {
|
|
356
|
+
fps: 3,
|
|
357
|
+
frames: [
|
|
358
|
+
{ body: 'sit', pawLick: true, headDX: 1, headDY: 2, eyes: 'closed' },
|
|
359
|
+
{ body: 'sit', pawLick: true, headDX: 1, headDY: 3, eyes: 'closed' },
|
|
360
|
+
{ body: 'sit', pawLick: false, headDX: 0, headDY: 1, eyes: 'happy' },
|
|
361
|
+
],
|
|
362
|
+
},
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const canvasCache = new Map<string, HTMLCanvasElement>()
|
|
366
|
+
|
|
367
|
+
function hexToRgb(hex: string): [number, number, number] {
|
|
368
|
+
if (hex.startsWith('#')) {
|
|
369
|
+
const raw = hex.slice(1)
|
|
370
|
+
const n = parseInt(
|
|
371
|
+
raw.length === 3
|
|
372
|
+
? raw
|
|
373
|
+
.split('')
|
|
374
|
+
.map((c) => c + c)
|
|
375
|
+
.join('')
|
|
376
|
+
: raw,
|
|
377
|
+
16,
|
|
378
|
+
)
|
|
379
|
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255]
|
|
380
|
+
}
|
|
381
|
+
return [240, 240, 240]
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function getCatFrameCanvas(
|
|
385
|
+
pose: PixelCatPose,
|
|
386
|
+
index: number,
|
|
387
|
+
palette: Record<1 | 2 | 3 | 4, string>,
|
|
388
|
+
): HTMLCanvasElement | null {
|
|
389
|
+
if (typeof document === 'undefined') return null
|
|
390
|
+
const frames = ANIMATIONS[pose].frames
|
|
391
|
+
const i = ((index % frames.length) + frames.length) % frames.length
|
|
392
|
+
const palKey = `${palette[1]}_${palette[2]}_${palette[3]}_${palette[4]}`
|
|
393
|
+
const key = `${pose}:${i}:${palKey}`
|
|
394
|
+
const hit = canvasCache.get(key)
|
|
395
|
+
if (hit) return hit
|
|
396
|
+
|
|
397
|
+
const canvas = document.createElement('canvas')
|
|
398
|
+
canvas.width = CAT_SIZE
|
|
399
|
+
canvas.height = CAT_SIZE
|
|
400
|
+
const ctx = canvas.getContext('2d')
|
|
401
|
+
if (!ctx) return null
|
|
402
|
+
|
|
403
|
+
const img = ctx.createImageData(CAT_SIZE, CAT_SIZE)
|
|
404
|
+
const data = buildCatGrid(frames[i])
|
|
405
|
+
for (let p = 0; p < data.length; p++) {
|
|
406
|
+
const v = data[p]
|
|
407
|
+
if (!v) continue
|
|
408
|
+
const hex = palette[v as 1 | 2 | 3 | 4] || '#ffffff'
|
|
409
|
+
const [r, g, b] = hexToRgb(hex)
|
|
410
|
+
img.data[p * 4] = r
|
|
411
|
+
img.data[p * 4 + 1] = g
|
|
412
|
+
img.data[p * 4 + 2] = b
|
|
413
|
+
img.data[p * 4 + 3] = 255
|
|
414
|
+
}
|
|
415
|
+
ctx.putImageData(img, 0, 0)
|
|
416
|
+
canvasCache.set(key, canvas)
|
|
417
|
+
return canvas
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function CatSpriteCanvas({
|
|
421
|
+
pose,
|
|
422
|
+
palette,
|
|
423
|
+
animated,
|
|
424
|
+
}: {
|
|
425
|
+
pose: PixelCatPose
|
|
426
|
+
palette: Record<1 | 2 | 3 | 4, string>
|
|
427
|
+
animated: boolean
|
|
428
|
+
}) {
|
|
429
|
+
const canvasRef = useRef<HTMLCanvasElement>(null)
|
|
430
|
+
|
|
431
|
+
useEffect(() => {
|
|
432
|
+
const canvas = canvasRef.current
|
|
433
|
+
if (!canvas) return
|
|
434
|
+
const ctx = canvas.getContext('2d')
|
|
435
|
+
if (!ctx) return
|
|
436
|
+
|
|
437
|
+
ctx.imageSmoothingEnabled = false
|
|
438
|
+
const animDef = ANIMATIONS[pose]
|
|
439
|
+
const { fps, frames } = animDef
|
|
440
|
+
let index = 0
|
|
441
|
+
|
|
442
|
+
const draw = () => {
|
|
443
|
+
ctx.clearRect(0, 0, CAT_SIZE, CAT_SIZE)
|
|
444
|
+
const frameCanvas = getCatFrameCanvas(pose, index, palette)
|
|
445
|
+
if (frameCanvas) {
|
|
446
|
+
ctx.drawImage(frameCanvas, 0, 0)
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
draw()
|
|
451
|
+
if (!animated) return
|
|
452
|
+
|
|
453
|
+
const interval = window.setInterval(() => {
|
|
454
|
+
index = (index + 1) % frames.length
|
|
455
|
+
draw()
|
|
456
|
+
}, 1000 / fps)
|
|
457
|
+
|
|
458
|
+
return () => window.clearInterval(interval)
|
|
459
|
+
}, [pose, palette, animated])
|
|
460
|
+
|
|
461
|
+
return (
|
|
462
|
+
<canvas
|
|
463
|
+
ref={canvasRef}
|
|
464
|
+
width={CAT_SIZE}
|
|
465
|
+
height={CAT_SIZE}
|
|
466
|
+
aria-hidden="true"
|
|
467
|
+
className="block h-full w-full select-none"
|
|
468
|
+
style={{
|
|
469
|
+
imageRendering: 'pixelated',
|
|
470
|
+
}}
|
|
471
|
+
/>
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
export type PixelCatPosition =
|
|
477
|
+
| 'random'
|
|
478
|
+
| 'center'
|
|
479
|
+
| 'top-left'
|
|
480
|
+
| 'top-right'
|
|
481
|
+
| 'bottom-left'
|
|
482
|
+
| 'bottom-right'
|
|
483
|
+
| { x: number; y: number }
|
|
484
|
+
|
|
485
|
+
export type PixelCatProps = {
|
|
486
|
+
size?: number
|
|
487
|
+
breed?: PixelCatBreed
|
|
488
|
+
palette?: Record<1 | 2 | 3 | 4, string>
|
|
489
|
+
wandering?: boolean
|
|
490
|
+
speed?: number
|
|
491
|
+
boundary?: 'parent' | 'viewport'
|
|
492
|
+
position?: PixelCatPosition
|
|
493
|
+
initialPose?: PixelCatPose
|
|
494
|
+
pose?: PixelCatPose
|
|
495
|
+
interactive?: boolean
|
|
496
|
+
cursorInteraction?: boolean
|
|
497
|
+
messages?: string[]
|
|
498
|
+
showBubble?: boolean
|
|
499
|
+
onPet?: (state: { count: number; pose: PixelCatPose }) => void
|
|
500
|
+
onPoseChange?: (pose: PixelCatPose) => void
|
|
501
|
+
padding?: number
|
|
502
|
+
className?: string
|
|
503
|
+
style?: CSSProperties
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const DEFAULT_MESSAGES = ['meow', 'meow!', 'purrr...', 'mrrp', ':3', 'nya~']
|
|
507
|
+
|
|
508
|
+
const rand = (min: number, max: number) => min + Math.random() * (max - min)
|
|
509
|
+
const clamp = (v: number, min: number, max: number) =>
|
|
510
|
+
Math.min(max, Math.max(min, v))
|
|
511
|
+
|
|
512
|
+
export const PixelCat = forwardRef<HTMLDivElement, PixelCatProps>(function PixelCat({
|
|
513
|
+
size = 36,
|
|
514
|
+
breed = 'white',
|
|
515
|
+
palette,
|
|
516
|
+
wandering = true,
|
|
517
|
+
speed = 1,
|
|
518
|
+
boundary = 'parent',
|
|
519
|
+
position = 'random',
|
|
520
|
+
initialPose = 'sit',
|
|
521
|
+
pose: fixedPose,
|
|
522
|
+
interactive = true,
|
|
523
|
+
cursorInteraction = true,
|
|
524
|
+
messages = DEFAULT_MESSAGES,
|
|
525
|
+
showBubble = true,
|
|
526
|
+
onPet,
|
|
527
|
+
onPoseChange,
|
|
528
|
+
padding = 8,
|
|
529
|
+
className,
|
|
530
|
+
style,
|
|
531
|
+
}: PixelCatProps, ref) {
|
|
532
|
+
const reduceMotion = useReducedMotion()
|
|
533
|
+
const instanceId = useId()
|
|
534
|
+
|
|
535
|
+
const x = useMotionValue(-999)
|
|
536
|
+
const y = useMotionValue(-999)
|
|
537
|
+
const [currentPose, setCurrentPose] = useState<PixelCatPose>(
|
|
538
|
+
fixedPose ?? initialPose,
|
|
539
|
+
)
|
|
540
|
+
const [facing, setFacing] = useState<1 | -1>(1)
|
|
541
|
+
const [bubbleText, setBubbleText] = useState<string | null>(null)
|
|
542
|
+
const [petCount, setPetCount] = useState(0)
|
|
543
|
+
const [hearts, setHearts] = useState<{ id: number; x: number; y: number }[]>(
|
|
544
|
+
[],
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
548
|
+
useImperativeHandle(ref, () => rootRef.current as HTMLDivElement)
|
|
549
|
+
const cursorRef = useRef<{ x: number; y: number } | null>(null)
|
|
550
|
+
const activeAnimations = useRef<Set<{ stop: () => void }>>(new Set())
|
|
551
|
+
const isInteracting = useRef(false)
|
|
552
|
+
const containerDimensions = useRef({ width: 0, height: 0 })
|
|
553
|
+
|
|
554
|
+
const activePalette = palette ?? (CAT_PALETTES as any)[breed] ?? CAT_PALETTES.white
|
|
555
|
+
|
|
556
|
+
const setCatPose = useCallback(
|
|
557
|
+
(p: PixelCatPose) => {
|
|
558
|
+
if (fixedPose) return
|
|
559
|
+
setCurrentPose(p)
|
|
560
|
+
onPoseChange?.(p)
|
|
561
|
+
},
|
|
562
|
+
[fixedPose, onPoseChange],
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
const getBounds = useCallback(() => {
|
|
566
|
+
let w = containerDimensions.current.width
|
|
567
|
+
let h = containerDimensions.current.height
|
|
568
|
+
|
|
569
|
+
if (
|
|
570
|
+
boundary === 'viewport' ||
|
|
571
|
+
(typeof window !== 'undefined' && (!w || !h))
|
|
572
|
+
) {
|
|
573
|
+
if (boundary === 'viewport') {
|
|
574
|
+
w = window.innerWidth
|
|
575
|
+
h = window.innerHeight
|
|
576
|
+
} else {
|
|
577
|
+
const parent = rootRef.current?.parentElement
|
|
578
|
+
if (parent) {
|
|
579
|
+
w = parent.clientWidth
|
|
580
|
+
h = parent.clientHeight
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
const minX = padding
|
|
586
|
+
const maxX = Math.max(padding, (w || 300) - size - padding)
|
|
587
|
+
const minY = padding
|
|
588
|
+
const maxY = Math.max(padding, (h || 200) - size - padding)
|
|
589
|
+
|
|
590
|
+
return { minX, maxX, minY, maxY, width: w, height: h }
|
|
591
|
+
}, [boundary, padding, size])
|
|
592
|
+
|
|
593
|
+
const resolveInitialPos = useCallback(() => {
|
|
594
|
+
const { minX, maxX, minY, maxY, width, height } = getBounds()
|
|
595
|
+
|
|
596
|
+
if (typeof position === 'object' && position !== null) {
|
|
597
|
+
const pos = position as { x: number; y: number }
|
|
598
|
+
const px = (pos.x / 100) * (width - size)
|
|
599
|
+
const py = (pos.y / 100) * (height - size)
|
|
600
|
+
return {
|
|
601
|
+
x: clamp(px, minX, maxX),
|
|
602
|
+
y: clamp(py, minY, maxY),
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
switch (position) {
|
|
607
|
+
case 'center':
|
|
608
|
+
return { x: (minX + maxX) / 2, y: (minY + maxY) / 2 }
|
|
609
|
+
case 'top-left':
|
|
610
|
+
return { x: minX, y: minY }
|
|
611
|
+
case 'top-right':
|
|
612
|
+
return { x: maxX, y: minY }
|
|
613
|
+
case 'bottom-left':
|
|
614
|
+
return { x: minX, y: maxY }
|
|
615
|
+
case 'bottom-right':
|
|
616
|
+
return { x: maxX, y: maxY }
|
|
617
|
+
case 'random':
|
|
618
|
+
default:
|
|
619
|
+
return { x: rand(minX, maxX), y: rand(minY, maxY) }
|
|
620
|
+
}
|
|
621
|
+
}, [getBounds, position, size])
|
|
622
|
+
|
|
623
|
+
useEffect(() => {
|
|
624
|
+
if (typeof window === 'undefined') return
|
|
625
|
+
|
|
626
|
+
const updateDimensions = () => {
|
|
627
|
+
if (boundary === 'viewport') {
|
|
628
|
+
containerDimensions.current = {
|
|
629
|
+
width: window.innerWidth,
|
|
630
|
+
height: window.innerHeight,
|
|
631
|
+
}
|
|
632
|
+
} else {
|
|
633
|
+
const parent = rootRef.current?.parentElement
|
|
634
|
+
if (parent) {
|
|
635
|
+
containerDimensions.current = {
|
|
636
|
+
width: parent.clientWidth,
|
|
637
|
+
height: parent.clientHeight,
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
updateDimensions()
|
|
644
|
+
|
|
645
|
+
const initial = resolveInitialPos()
|
|
646
|
+
x.set(initial.x)
|
|
647
|
+
y.set(initial.y)
|
|
648
|
+
|
|
649
|
+
if (boundary === 'viewport') {
|
|
650
|
+
window.addEventListener('resize', updateDimensions)
|
|
651
|
+
return () => window.removeEventListener('resize', updateDimensions)
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const parent = rootRef.current?.parentElement
|
|
655
|
+
if (!parent) return
|
|
656
|
+
|
|
657
|
+
const ro = new ResizeObserver((entries) => {
|
|
658
|
+
for (const entry of entries) {
|
|
659
|
+
containerDimensions.current = {
|
|
660
|
+
width: entry.contentRect.width,
|
|
661
|
+
height: entry.contentRect.height,
|
|
662
|
+
}
|
|
663
|
+
const b = getBounds()
|
|
664
|
+
if (x.get() > b.maxX) x.set(b.maxX)
|
|
665
|
+
if (y.get() > b.maxY) y.set(b.maxY)
|
|
666
|
+
}
|
|
667
|
+
})
|
|
668
|
+
ro.observe(parent)
|
|
669
|
+
|
|
670
|
+
return () => ro.disconnect()
|
|
671
|
+
}, [boundary, getBounds, resolveInitialPos, x, y])
|
|
672
|
+
|
|
673
|
+
useEffect(() => {
|
|
674
|
+
if (!cursorInteraction || typeof window === 'undefined') return
|
|
675
|
+
|
|
676
|
+
const handlePointerMove = (e: PointerEvent) => {
|
|
677
|
+
if (e.pointerType === 'touch') return
|
|
678
|
+
if (boundary === 'viewport') {
|
|
679
|
+
cursorRef.current = { x: e.clientX, y: e.clientY }
|
|
680
|
+
} else {
|
|
681
|
+
const parent = rootRef.current?.parentElement
|
|
682
|
+
if (!parent) return
|
|
683
|
+
const rect = parent.getBoundingClientRect()
|
|
684
|
+
cursorRef.current = {
|
|
685
|
+
x: e.clientX - rect.left,
|
|
686
|
+
y: e.clientY - rect.top,
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const handlePointerLeave = () => {
|
|
692
|
+
cursorRef.current = null
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
const target =
|
|
696
|
+
boundary === 'viewport'
|
|
697
|
+
? window
|
|
698
|
+
: (rootRef.current?.parentElement ?? window)
|
|
699
|
+
|
|
700
|
+
target.addEventListener('pointermove', handlePointerMove as EventListener, {
|
|
701
|
+
passive: true,
|
|
702
|
+
})
|
|
703
|
+
target.addEventListener('pointerleave', handlePointerLeave as EventListener)
|
|
704
|
+
|
|
705
|
+
return () => {
|
|
706
|
+
target.removeEventListener(
|
|
707
|
+
'pointermove',
|
|
708
|
+
handlePointerMove as EventListener,
|
|
709
|
+
)
|
|
710
|
+
target.removeEventListener(
|
|
711
|
+
'pointerleave',
|
|
712
|
+
handlePointerLeave as EventListener,
|
|
713
|
+
)
|
|
714
|
+
}
|
|
715
|
+
}, [boundary, cursorInteraction])
|
|
716
|
+
|
|
717
|
+
const handlePet = useCallback(() => {
|
|
718
|
+
if (!interactive) return
|
|
719
|
+
isInteracting.current = true
|
|
720
|
+
const nextCount = petCount + 1
|
|
721
|
+
setPetCount(nextCount)
|
|
722
|
+
|
|
723
|
+
setCatPose('happy')
|
|
724
|
+
onPet?.({ count: nextCount, pose: 'happy' })
|
|
725
|
+
|
|
726
|
+
if (showBubble && messages.length > 0) {
|
|
727
|
+
const msg = messages[Math.floor(Math.random() * messages.length)]
|
|
728
|
+
setBubbleText(msg)
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const heartId = Date.now() + Math.random()
|
|
732
|
+
setHearts((prev) => [
|
|
733
|
+
...prev.slice(-3),
|
|
734
|
+
{ id: heartId, x: rand(-8, 8), y: rand(-4, 4) },
|
|
735
|
+
])
|
|
736
|
+
|
|
737
|
+
window.setTimeout(() => {
|
|
738
|
+
setHearts((prev) => prev.filter((h) => h.id !== heartId))
|
|
739
|
+
}, 1200)
|
|
740
|
+
|
|
741
|
+
window.setTimeout(() => {
|
|
742
|
+
setBubbleText(null)
|
|
743
|
+
isInteracting.current = false
|
|
744
|
+
if (!fixedPose) setCatPose('sit')
|
|
745
|
+
}, 2000)
|
|
746
|
+
}, [
|
|
747
|
+
fixedPose,
|
|
748
|
+
interactive,
|
|
749
|
+
messages,
|
|
750
|
+
onPet,
|
|
751
|
+
petCount,
|
|
752
|
+
setCatPose,
|
|
753
|
+
showBubble,
|
|
754
|
+
])
|
|
755
|
+
|
|
756
|
+
useEffect(() => {
|
|
757
|
+
if (!wandering || reduceMotion || fixedPose) return
|
|
758
|
+
|
|
759
|
+
let cancelled = false
|
|
760
|
+
const timers = new Set<number>()
|
|
761
|
+
|
|
762
|
+
const wait = (ms: number) =>
|
|
763
|
+
new Promise<void>((resolve) => {
|
|
764
|
+
const t = window.setTimeout(() => {
|
|
765
|
+
timers.delete(t)
|
|
766
|
+
resolve()
|
|
767
|
+
}, ms)
|
|
768
|
+
timers.add(t)
|
|
769
|
+
})
|
|
770
|
+
|
|
771
|
+
const walkTo = async (tx: number, ty: number) => {
|
|
772
|
+
if (cancelled) return
|
|
773
|
+
const dx = tx - x.get()
|
|
774
|
+
const dy = ty - y.get()
|
|
775
|
+
const dist = Math.hypot(dx, dy)
|
|
776
|
+
if (dist < 4) return
|
|
777
|
+
|
|
778
|
+
setFacing(dx >= 0 ? 1 : -1)
|
|
779
|
+
setCatPose('walk')
|
|
780
|
+
|
|
781
|
+
const travelSpeed = Math.max(16, rand(28, 44) * speed)
|
|
782
|
+
const duration = dist / travelSpeed
|
|
783
|
+
|
|
784
|
+
const ax = animate(x, tx, { duration, ease: 'linear' })
|
|
785
|
+
const ay = animate(y, ty, { duration, ease: 'linear' })
|
|
786
|
+
|
|
787
|
+
activeAnimations.current.add(ax)
|
|
788
|
+
activeAnimations.current.add(ay)
|
|
789
|
+
|
|
790
|
+
await Promise.all([ax, ay]).catch(() => {})
|
|
791
|
+
activeAnimations.current.delete(ax)
|
|
792
|
+
activeAnimations.current.delete(ay)
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
const runLoop = async () => {
|
|
796
|
+
await wait(rand(1000, 2500))
|
|
797
|
+
|
|
798
|
+
while (!cancelled) {
|
|
799
|
+
if (isInteracting.current) {
|
|
800
|
+
await wait(500)
|
|
801
|
+
continue
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
const b = getBounds()
|
|
805
|
+
const c = cursorRef.current
|
|
806
|
+
|
|
807
|
+
if (cursorInteraction && c) {
|
|
808
|
+
const cx = x.get() + size / 2
|
|
809
|
+
const cy = y.get() + size / 2
|
|
810
|
+
const distToCursor = Math.hypot(c.x - cx, c.y - cy)
|
|
811
|
+
|
|
812
|
+
if (distToCursor < 36) {
|
|
813
|
+
const ang = Math.atan2(cy - c.y, cx - c.x) + rand(-0.4, 0.4)
|
|
814
|
+
const escapeDist = rand(60, 110)
|
|
815
|
+
await walkTo(
|
|
816
|
+
clamp(x.get() + Math.cos(ang) * escapeDist, b.minX, b.maxX),
|
|
817
|
+
clamp(y.get() + Math.sin(ang) * escapeDist, b.minY, b.maxY),
|
|
818
|
+
)
|
|
819
|
+
continue
|
|
820
|
+
} else if (distToCursor < 120) {
|
|
821
|
+
setFacing(c.x >= cx ? 1 : -1)
|
|
822
|
+
setCatPose('alert')
|
|
823
|
+
await wait(rand(800, 1600))
|
|
824
|
+
if (Math.random() < 0.35 && cursorRef.current) {
|
|
825
|
+
const target = cursorRef.current
|
|
826
|
+
const ang = Math.atan2(target.y - cy, target.x - cx)
|
|
827
|
+
await walkTo(
|
|
828
|
+
clamp(target.x - Math.cos(ang) * 44 - size / 2, b.minX, b.maxX),
|
|
829
|
+
clamp(target.y - Math.sin(ang) * 44 - size / 2, b.minY, b.maxY),
|
|
830
|
+
)
|
|
831
|
+
}
|
|
832
|
+
continue
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
const roll = Math.random()
|
|
837
|
+
|
|
838
|
+
if (roll < 0.45) {
|
|
839
|
+
const targetX = rand(b.minX, b.maxX)
|
|
840
|
+
const targetY = rand(b.minY, b.maxY)
|
|
841
|
+
await walkTo(targetX, targetY)
|
|
842
|
+
} else if (roll < 0.65) {
|
|
843
|
+
setCatPose('sit')
|
|
844
|
+
if (showBubble && Math.random() < 0.15 && messages.length > 0) {
|
|
845
|
+
setBubbleText(messages[Math.floor(Math.random() * messages.length)])
|
|
846
|
+
await wait(1800)
|
|
847
|
+
setBubbleText(null)
|
|
848
|
+
} else {
|
|
849
|
+
await wait(rand(2500, 5000))
|
|
850
|
+
}
|
|
851
|
+
} else if (roll < 0.78) {
|
|
852
|
+
setCatPose('sleep')
|
|
853
|
+
await wait(rand(4000, 8000))
|
|
854
|
+
} else if (roll < 0.88) {
|
|
855
|
+
setCatPose('groom')
|
|
856
|
+
await wait(rand(2000, 4000))
|
|
857
|
+
} else if (roll < 0.94) {
|
|
858
|
+
setCatPose('stretch')
|
|
859
|
+
await wait(rand(1800, 3200))
|
|
860
|
+
} else {
|
|
861
|
+
setCatPose('idle')
|
|
862
|
+
if (Math.random() < 0.4) setFacing((f) => (f === 1 ? -1 : 1))
|
|
863
|
+
await wait(rand(1500, 3000))
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
if (cancelled) break
|
|
867
|
+
setCatPose('idle')
|
|
868
|
+
await wait(rand(600, 1800))
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
runLoop()
|
|
873
|
+
|
|
874
|
+
const anims = activeAnimations.current
|
|
875
|
+
return () => {
|
|
876
|
+
cancelled = true
|
|
877
|
+
anims.forEach((a) => a.stop())
|
|
878
|
+
anims.clear()
|
|
879
|
+
timers.forEach((t) => window.clearTimeout(t))
|
|
880
|
+
}
|
|
881
|
+
}, [
|
|
882
|
+
cursorInteraction,
|
|
883
|
+
fixedPose,
|
|
884
|
+
getBounds,
|
|
885
|
+
messages,
|
|
886
|
+
reduceMotion,
|
|
887
|
+
setCatPose,
|
|
888
|
+
showBubble,
|
|
889
|
+
size,
|
|
890
|
+
speed,
|
|
891
|
+
wandering,
|
|
892
|
+
x,
|
|
893
|
+
y,
|
|
894
|
+
])
|
|
895
|
+
|
|
896
|
+
const activePose = fixedPose ?? currentPose
|
|
897
|
+
|
|
898
|
+
return (
|
|
899
|
+
<motion.div
|
|
900
|
+
ref={rootRef}
|
|
901
|
+
id={`pixel-cat-${instanceId}`}
|
|
902
|
+
className={cn(
|
|
903
|
+
boundary === 'viewport' ? 'fixed' : 'absolute',
|
|
904
|
+
'pointer-events-none top-0 left-0 z-20 select-none',
|
|
905
|
+
className,
|
|
906
|
+
)}
|
|
907
|
+
style={{
|
|
908
|
+
width: size,
|
|
909
|
+
height: size,
|
|
910
|
+
x,
|
|
911
|
+
y,
|
|
912
|
+
...style,
|
|
913
|
+
}}
|
|
914
|
+
>
|
|
915
|
+
<div
|
|
916
|
+
className="pointer-events-none h-full w-full transition-transform duration-100"
|
|
917
|
+
style={{ transform: `scaleX(${facing})` }}
|
|
918
|
+
>
|
|
919
|
+
<CatSpriteCanvas
|
|
920
|
+
pose={activePose}
|
|
921
|
+
palette={activePalette}
|
|
922
|
+
animated={!reduceMotion}
|
|
923
|
+
/>
|
|
924
|
+
</div>
|
|
925
|
+
|
|
926
|
+
{interactive && (
|
|
927
|
+
<button
|
|
928
|
+
type="button"
|
|
929
|
+
tabIndex={0}
|
|
930
|
+
aria-label={`Pet the ${breed} cat`}
|
|
931
|
+
onClick={handlePet}
|
|
932
|
+
className="focus-visible:ring-ring pointer-events-auto absolute -inset-2 cursor-pointer rounded-full outline-none focus-visible:ring-1"
|
|
933
|
+
/>
|
|
934
|
+
)}
|
|
935
|
+
|
|
936
|
+
<AnimatePresence>
|
|
937
|
+
{bubbleText && (
|
|
938
|
+
<motion.div
|
|
939
|
+
key={bubbleText}
|
|
940
|
+
initial={{ opacity: 0, y: 4, scale: 0.9 }}
|
|
941
|
+
animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
942
|
+
exit={{ opacity: 0, y: -2, scale: 0.9 }}
|
|
943
|
+
transition={{ duration: 0.18 }}
|
|
944
|
+
className="border-border bg-popover text-popover-foreground pointer-events-none absolute bottom-full left-1/2 mb-1.5 -translate-x-1/2 rounded-md border px-2 py-0.5 font-mono text-[11px] font-medium whitespace-nowrap shadow-sm"
|
|
945
|
+
>
|
|
946
|
+
{bubbleText}
|
|
947
|
+
<div className="border-border bg-popover absolute -bottom-1 left-1/2 h-1.5 w-1.5 -translate-x-1/2 rotate-45 border-r border-b" />
|
|
948
|
+
</motion.div>
|
|
949
|
+
)}
|
|
950
|
+
</AnimatePresence>
|
|
951
|
+
|
|
952
|
+
<AnimatePresence>
|
|
953
|
+
{hearts.map((h) => (
|
|
954
|
+
<motion.span
|
|
955
|
+
key={h.id}
|
|
956
|
+
initial={{ opacity: 1, y: 0, x: h.x, scale: 0.8 }}
|
|
957
|
+
animate={{ opacity: 0, y: -24, scale: 1.2 }}
|
|
958
|
+
exit={{ opacity: 0 }}
|
|
959
|
+
transition={{ duration: 1, ease: 'easeOut' }}
|
|
960
|
+
className="pointer-events-none absolute -top-1 left-1/2 -translate-x-1/2 text-xs leading-none select-none"
|
|
961
|
+
>
|
|
962
|
+
❤️
|
|
963
|
+
</motion.span>
|
|
964
|
+
))}
|
|
965
|
+
</AnimatePresence>
|
|
966
|
+
</motion.div>
|
|
967
|
+
)
|
|
968
|
+
})
|
|
969
|
+
|
|
970
|
+
PixelCat.displayName = 'PixelCat'
|
|
971
|
+
|
|
972
|
+
export default PixelCat
|