@zhangxij/dsh-yoyo-bubbles 1.0.0 → 1.0.1
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/README.md +2 -0
- package/client.js +417 -44
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ dsh plugin add @zhangxij/dsh-yoyo-bubbles
|
|
|
16
16
|
|
|
17
17
|
- **入口**:`shell.overlay` 里的一个圆形泡泡按钮,不占用侧边栏和主区。
|
|
18
18
|
- **玩**:进入后是深蓝色全屏画面,点一下(或按任意键)就生成一个泡泡或一条小鱼,它们会自己飘走、游走,最多同时 48 个。
|
|
19
|
+
- **唱歌模式**:左上角两个图标 —— ⭐ `小星星`、🎅 `铃儿响叮当`。选一首后,每点一下(或按一下键)唱下一个音节:泡泡、方泡泡、小鱼、小星星四种元素随机冒出来,音节字就落在元素里面,每个字换一种颜色,音高和音符时值按歌谱走,一首唱完自动从头再来。再点同一个图标就取消,回到自由玩。音色是 Web Audio 现场合成的,没有额外音频文件。
|
|
19
20
|
- **计时**:`每次看几分钟` 可调 1–15 分钟(默认 2 分钟)。**第一次触碰才开始计时**,所以孩子还在犹豫时不计时。
|
|
20
21
|
- **到点**:画面蒙上一层柔光,播放 `最后的提示音`,播完自动回到入口。可选项有三种:
|
|
21
22
|
- 温柔语音(内置一段「悠悠宝贝,已经 N 分钟了,休息休息再来看吧」的中文语音,不依赖系统朗读者);
|
|
@@ -54,6 +55,7 @@ dsh plugin add @zhangxij/dsh-yoyo-bubbles
|
|
|
54
55
|
- 语音提示依赖浏览器允许自动播放:第一次交互(进入乐园、点设置)会顺带解锁音频,若浏览器仍拦截则只剩静音。
|
|
55
56
|
- 计时用 `setTimeout`,标签页被系统挂起时可能比设定值晚一点结束。
|
|
56
57
|
- 时长只支持 1–15 分钟的整数分钟,没有「无限玩」模式。
|
|
58
|
+
- 唱歌模式的旋律是合成音色(三角波 + 正弦),音量跟着系统输出走,插件里没有单独的音量滑杆。
|
|
57
59
|
|
|
58
60
|
## 截图
|
|
59
61
|
|
package/client.js
CHANGED
|
@@ -18,6 +18,56 @@ window.__ModuleLoader__.load({
|
|
|
18
18
|
const ESC_HOLD_MS = 1400;
|
|
19
19
|
const SETTINGS_KEY = 'yoyo-bubbles:settings:v1';
|
|
20
20
|
const MAX_AUDIO_BYTES = 1.5 * 1024 * 1024;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sing-along melodies. One tap sings one syllable, so every entry is
|
|
24
|
+
* [MIDI note, beats, syllable]; the note's own length follows the song and
|
|
25
|
+
* the tap decides when the next syllable starts.
|
|
26
|
+
*/
|
|
27
|
+
const SONGS = {
|
|
28
|
+
star: {
|
|
29
|
+
bpm: 100,
|
|
30
|
+
notes: [
|
|
31
|
+
[60, 1, '一'], [60, 1, '闪'], [67, 1, '一'], [67, 1, '闪'], [69, 1, '亮'], [69, 1, '晶'], [67, 2, '晶'],
|
|
32
|
+
[65, 1, '满'], [65, 1, '天'], [64, 1, '都'], [64, 1, '是'], [62, 1, '小'], [62, 1, '星'], [60, 2, '星'],
|
|
33
|
+
[67, 1, '挂'], [67, 1, '在'], [65, 1, '天'], [65, 1, '上'], [64, 1, '放'], [64, 1, '光'], [62, 2, '明'],
|
|
34
|
+
[67, 1, '好'], [67, 1, '像'], [65, 1, '许'], [65, 1, '多'], [64, 1, '小'], [64, 1, '眼'], [62, 2, '睛'],
|
|
35
|
+
[60, 1, '一'], [60, 1, '闪'], [67, 1, '一'], [67, 1, '闪'], [69, 1, '亮'], [69, 1, '晶'], [67, 2, '晶'],
|
|
36
|
+
[65, 1, '满'], [65, 1, '天'], [64, 1, '都'], [64, 1, '是'], [62, 1, '小'], [62, 1, '星'], [60, 2, '星'],
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
santa: {
|
|
40
|
+
bpm: 120,
|
|
41
|
+
notes: [
|
|
42
|
+
[64, 0.5, '叮'], [64, 0.5, '叮'], [64, 1, '当'],
|
|
43
|
+
[64, 0.5, '叮'], [64, 0.5, '叮'], [64, 1, '当'],
|
|
44
|
+
[64, 0.5, '铃'], [67, 0.5, '儿'], [72, 1, '响'], [74, 1, '叮'], [76, 1.5, '当'],
|
|
45
|
+
[65, 0.5, '我'], [65, 0.5, '们'], [65, 1, '滑'], [65, 1, '雪'],
|
|
46
|
+
[65, 0.5, '多'], [64, 0.5, '快'], [64, 2, '乐'],
|
|
47
|
+
[64, 1, '我'], [64, 1, '们'], [62, 1, '坐'], [62, 1, '在'],
|
|
48
|
+
[64, 0.5, '雪'], [62, 0.5, '橇'], [67, 2, '上'],
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const SONG_IDS = ['star', 'santa'];
|
|
53
|
+
|
|
54
|
+
/** 唱歌模式里每个音节随机用的字色 */
|
|
55
|
+
const SYLLABLE_INKS = [
|
|
56
|
+
'#e5397f',
|
|
57
|
+
'#7b3ff2',
|
|
58
|
+
'#0a84ff',
|
|
59
|
+
'#00997a',
|
|
60
|
+
'#ef6c00',
|
|
61
|
+
'#c81e5b',
|
|
62
|
+
'#5b21b6',
|
|
63
|
+
'#0f766e',
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
function midiHz(midi) {
|
|
68
|
+
return 440 * Math.pow(2, (midi - 69) / 12);
|
|
69
|
+
}
|
|
70
|
+
|
|
21
71
|
const DEFAULT_SETTINGS = Object.freeze({ minutes: 2, reminder: 'voice', customAudio: '' });
|
|
22
72
|
const NS = 'yoyo.bubbles';
|
|
23
73
|
|
|
@@ -25,6 +75,9 @@ window.__ModuleLoader__.load({
|
|
|
25
75
|
zh: {
|
|
26
76
|
settings: '设置',
|
|
27
77
|
close: '关闭',
|
|
78
|
+
starSong: '小星星',
|
|
79
|
+
santaSong: '铃儿响叮当',
|
|
80
|
+
songHint: '选一首歌,点一下唱一个字',
|
|
28
81
|
openGarden: '打开泡泡乐园',
|
|
29
82
|
minutes: '每次看几分钟',
|
|
30
83
|
minuteUnit: '分钟',
|
|
@@ -49,6 +102,9 @@ window.__ModuleLoader__.load({
|
|
|
49
102
|
en: {
|
|
50
103
|
settings: 'Settings',
|
|
51
104
|
close: 'Close',
|
|
105
|
+
starSong: 'Twinkle Twinkle',
|
|
106
|
+
santaSong: 'Jingle Bells',
|
|
107
|
+
songHint: 'Pick a tune: one tap sings one syllable',
|
|
52
108
|
openGarden: 'Open bubble garden',
|
|
53
109
|
minutes: 'Play time',
|
|
54
110
|
minuteUnit: 'min',
|
|
@@ -150,8 +206,8 @@ window.__ModuleLoader__.load({
|
|
|
150
206
|
}
|
|
151
207
|
}
|
|
152
208
|
|
|
153
|
-
function makeBubble(x, y, id) {
|
|
154
|
-
const size = rand(42, 94);
|
|
209
|
+
function makeBubble(x, y, id, forcedSize) {
|
|
210
|
+
const size = forcedSize || rand(42, 94);
|
|
155
211
|
const startX = clamp(x - size / 2, 6, Math.max(6, window.innerWidth - size - 6));
|
|
156
212
|
const startY = clamp(y - size / 2, 6, Math.max(6, window.innerHeight - size - 6));
|
|
157
213
|
const dx = rand(-72, 72);
|
|
@@ -175,6 +231,19 @@ window.__ModuleLoader__.load({
|
|
|
175
231
|
};
|
|
176
232
|
}
|
|
177
233
|
|
|
234
|
+
function makeSquare(x, y, id, size) {
|
|
235
|
+
const entity = makeBubble(x, y, id, size);
|
|
236
|
+
entity.kind = 'square';
|
|
237
|
+
return entity;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function makeStar(x, y, id, size) {
|
|
241
|
+
const entity = makeBubble(x, y, id, size);
|
|
242
|
+
entity.kind = 'star';
|
|
243
|
+
entity.hue = 44;
|
|
244
|
+
return entity;
|
|
245
|
+
}
|
|
246
|
+
|
|
178
247
|
function makeFish(x, y, id) {
|
|
179
248
|
const width = rand(100, 154);
|
|
180
249
|
const height = width * 0.72;
|
|
@@ -313,6 +382,27 @@ window.__ModuleLoader__.load({
|
|
|
313
382
|
|
|
314
383
|
.yoyo-entities { position: absolute; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
|
|
315
384
|
.yoyo-entity { position: absolute; pointer-events: none; will-change: transform, opacity; }
|
|
385
|
+
.yoyo-entity.is-rise { animation: yoyo-bubble-rise var(--dur) cubic-bezier(0.22, 0.61, 0.36, 1) forwards; }
|
|
386
|
+
|
|
387
|
+
/* 正在唱的这个放大、唱过的缩小,孩子一眼能看出轮到哪个 */
|
|
388
|
+
.yoyo-shape {
|
|
389
|
+
position: relative;
|
|
390
|
+
display: block;
|
|
391
|
+
width: 100%;
|
|
392
|
+
height: 100%;
|
|
393
|
+
transform: scale(0.82);
|
|
394
|
+
transition: transform 280ms cubic-bezier(0.34, 1.32, 0.6, 1);
|
|
395
|
+
will-change: transform;
|
|
396
|
+
}
|
|
397
|
+
.yoyo-entity.is-latest .yoyo-shape {
|
|
398
|
+
transform: scale(1.18);
|
|
399
|
+
animation: yoyo-shape-pop 320ms cubic-bezier(0.34, 1.42, 0.6, 1);
|
|
400
|
+
}
|
|
401
|
+
@keyframes yoyo-shape-pop {
|
|
402
|
+
0% { transform: scale(0.9); }
|
|
403
|
+
62% { transform: scale(1.28); }
|
|
404
|
+
100% { transform: scale(1.18); }
|
|
405
|
+
}
|
|
316
406
|
|
|
317
407
|
.yoyo-bubble {
|
|
318
408
|
border-radius: 50%;
|
|
@@ -325,7 +415,6 @@ window.__ModuleLoader__.load({
|
|
|
325
415
|
inset -8px -10px 18px hsla(var(--hue), 90%, 50%, 0.18),
|
|
326
416
|
inset 6px 8px 16px rgba(255, 255, 255, 0.35),
|
|
327
417
|
0 0 22px hsla(var(--hue), 100%, 72%, 0.4);
|
|
328
|
-
animation: yoyo-bubble-rise var(--dur) cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
|
|
329
418
|
}
|
|
330
419
|
.yoyo-bubble::after {
|
|
331
420
|
content: '';
|
|
@@ -345,6 +434,39 @@ window.__ModuleLoader__.load({
|
|
|
345
434
|
transform: rotate(-32deg);
|
|
346
435
|
filter: blur(1px);
|
|
347
436
|
}
|
|
437
|
+
.yoyo-square {
|
|
438
|
+
border-radius: 26%;
|
|
439
|
+
background:
|
|
440
|
+
radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.96) 0 5%, rgba(255, 255, 255, 0.32) 12%, transparent 30%),
|
|
441
|
+
radial-gradient(circle at 70% 78%, hsla(var(--hue), 100%, 80%, 0.5) 0%, transparent 50%),
|
|
442
|
+
radial-gradient(circle at 46% 40%, hsla(var(--hue), 96%, 84%, 0.2) 0%, hsla(var(--hue), 96%, 68%, 0.32) 58%, hsla(var(--hue), 92%, 58%, 0.5) 88%, hsla(var(--hue), 92%, 74%, 0.75) 100%);
|
|
443
|
+
border: 1.5px solid hsla(var(--hue), 100%, 88%, 0.7);
|
|
444
|
+
box-shadow:
|
|
445
|
+
inset -6px -8px 16px hsla(var(--hue), 90%, 50%, 0.16),
|
|
446
|
+
inset 5px 7px 14px rgba(255, 255, 255, 0.3),
|
|
447
|
+
0 0 20px hsla(var(--hue), 100%, 72%, 0.36);
|
|
448
|
+
}
|
|
449
|
+
.yoyo-square::before {
|
|
450
|
+
content: '';
|
|
451
|
+
position: absolute;
|
|
452
|
+
left: 21%;
|
|
453
|
+
top: 15%;
|
|
454
|
+
width: 26%;
|
|
455
|
+
height: 12%;
|
|
456
|
+
border-radius: 50%;
|
|
457
|
+
background: rgba(255, 255, 255, 0.86);
|
|
458
|
+
filter: blur(1px);
|
|
459
|
+
transform: rotate(-28deg);
|
|
460
|
+
}
|
|
461
|
+
.yoyo-star-shape {
|
|
462
|
+
clip-path: polygon(50% 1%, 61.8% 36.6%, 98% 36.6%, 68.8% 58%, 79.4% 92.6%, 50% 71.2%, 20.6% 92.6%, 31.2% 58%, 2% 36.6%, 38.2% 36.6%);
|
|
463
|
+
background:
|
|
464
|
+
radial-gradient(circle at 46% 40%, rgba(255, 255, 255, 0.92) 0 3%, rgba(255, 250, 226, 0.52) 11%, rgba(216, 242, 255, 0.36) 30%, rgba(176, 224, 255, 0.2) 60%, rgba(150, 206, 255, 0.08) 100%);
|
|
465
|
+
filter:
|
|
466
|
+
drop-shadow(0 0 12px rgba(198, 236, 255, 0.65))
|
|
467
|
+
drop-shadow(0 0 28px rgba(255, 244, 210, 0.4));
|
|
468
|
+
opacity: 0.94;
|
|
469
|
+
}
|
|
348
470
|
@keyframes yoyo-bubble-rise {
|
|
349
471
|
0% { transform: translate3d(0, 0, 0) scale(0.16); opacity: 0; }
|
|
350
472
|
10% { opacity: 1; }
|
|
@@ -466,6 +588,67 @@ window.__ModuleLoader__.load({
|
|
|
466
588
|
.yoyo-control:focus-visible { outline: 2px solid #bdefff; outline-offset: 2px; }
|
|
467
589
|
.yoyo-control svg { width: 19px; height: 19px; display: block; }
|
|
468
590
|
|
|
591
|
+
.yoyo-songs {
|
|
592
|
+
position: fixed;
|
|
593
|
+
top: 26px;
|
|
594
|
+
left: 25%;
|
|
595
|
+
transform: translateX(-50%);
|
|
596
|
+
z-index: 4;
|
|
597
|
+
display: flex;
|
|
598
|
+
flex-direction: column;
|
|
599
|
+
align-items: center;
|
|
600
|
+
gap: 14px;
|
|
601
|
+
pointer-events: auto;
|
|
602
|
+
}
|
|
603
|
+
.yoyo-song {
|
|
604
|
+
width: 58px;
|
|
605
|
+
height: 58px;
|
|
606
|
+
padding: 0;
|
|
607
|
+
display: grid;
|
|
608
|
+
place-items: center;
|
|
609
|
+
border: 0;
|
|
610
|
+
background: transparent;
|
|
611
|
+
color: #ffe9a8;
|
|
612
|
+
cursor: pointer;
|
|
613
|
+
opacity: 0.58;
|
|
614
|
+
filter: drop-shadow(0 0 10px rgba(150, 214, 255, 0.35));
|
|
615
|
+
transition: opacity 200ms ease, transform 200ms ease, filter 200ms ease;
|
|
616
|
+
-webkit-tap-highlight-color: transparent;
|
|
617
|
+
}
|
|
618
|
+
.yoyo-song:hover { opacity: 0.92; transform: scale(1.06); }
|
|
619
|
+
.yoyo-song:active { transform: scale(0.94); }
|
|
620
|
+
.yoyo-song:focus-visible { outline: 2px solid #bdefff; outline-offset: 4px; border-radius: 12px; }
|
|
621
|
+
.yoyo-song svg { width: 48px; height: 48px; display: block; overflow: visible; }
|
|
622
|
+
.yoyo-song.is-on {
|
|
623
|
+
opacity: 1;
|
|
624
|
+
transform: scale(1.12);
|
|
625
|
+
filter:
|
|
626
|
+
drop-shadow(0 0 14px rgba(255, 240, 190, 0.85))
|
|
627
|
+
drop-shadow(0 0 26px rgba(150, 214, 255, 0.55));
|
|
628
|
+
}
|
|
629
|
+
.yoyo-syllable {
|
|
630
|
+
position: absolute;
|
|
631
|
+
inset: 0;
|
|
632
|
+
display: grid;
|
|
633
|
+
place-items: center;
|
|
634
|
+
line-height: 1;
|
|
635
|
+
font-weight: 800;
|
|
636
|
+
color: rgba(8, 34, 60, 0.88);
|
|
637
|
+
text-shadow:
|
|
638
|
+
0 0 6px rgba(255, 255, 255, 0.9),
|
|
639
|
+
0 1px 0 rgba(255, 255, 255, 0.85),
|
|
640
|
+
0 -1px 0 rgba(255, 255, 255, 0.85);
|
|
641
|
+
pointer-events: none;
|
|
642
|
+
user-select: none;
|
|
643
|
+
-webkit-user-select: none;
|
|
644
|
+
}
|
|
645
|
+
.yoyo-syllable-inside {
|
|
646
|
+
inset: auto;
|
|
647
|
+
left: 50%;
|
|
648
|
+
top: 50%;
|
|
649
|
+
transform: translate(-50%, -50%);
|
|
650
|
+
}
|
|
651
|
+
|
|
469
652
|
.yoyo-settings-backdrop {
|
|
470
653
|
position: fixed;
|
|
471
654
|
inset: 0;
|
|
@@ -709,6 +892,9 @@ window.__ModuleLoader__.load({
|
|
|
709
892
|
.yoyo-hourglass { right: 18px; bottom: 18px; width: 62px; height: 90px; }
|
|
710
893
|
.yoyo-controls { top: 14px; right: 14px; gap: 8px; }
|
|
711
894
|
.yoyo-control { width: 36px; height: 36px; }
|
|
895
|
+
.yoyo-songs { top: 14px; left: 25%; gap: 8px; }
|
|
896
|
+
.yoyo-song { width: 44px; height: 44px; }
|
|
897
|
+
.yoyo-song svg { width: 36px; height: 36px; }
|
|
712
898
|
.yoyo-settings-backdrop { padding: 12px; }
|
|
713
899
|
.yoyo-settings-card { padding: 18px; border-radius: 18px; }
|
|
714
900
|
.yoyo-stepper { gap: 14px; }
|
|
@@ -834,6 +1020,43 @@ window.__ModuleLoader__.load({
|
|
|
834
1020
|
);
|
|
835
1021
|
}
|
|
836
1022
|
|
|
1023
|
+
function StarIcon() {
|
|
1024
|
+
return h(
|
|
1025
|
+
'svg',
|
|
1026
|
+
{ viewBox: '0 0 24 24', 'aria-hidden': true },
|
|
1027
|
+
h('path', {
|
|
1028
|
+
d: 'M12 2.4l2.94 6.1 6.66.96-4.86 4.72 1.14 6.66L12 17.66l-5.88 3.18 1.14-6.66L2.4 9.46l6.66-.96Z',
|
|
1029
|
+
fill: 'rgba(255, 246, 210, 0.3)',
|
|
1030
|
+
stroke: 'rgba(255, 249, 224, 0.92)',
|
|
1031
|
+
strokeWidth: 1.1,
|
|
1032
|
+
strokeLinejoin: 'round',
|
|
1033
|
+
strokeLinecap: 'round',
|
|
1034
|
+
}),
|
|
1035
|
+
h('circle', { cx: 12, cy: 10.6, r: 1.5, fill: 'rgba(255, 255, 255, 0.92)' }),
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
function SantaIcon() {
|
|
1040
|
+
return h(
|
|
1041
|
+
'svg',
|
|
1042
|
+
{ viewBox: '0 0 24 24', 'aria-hidden': true },
|
|
1043
|
+
h('circle', { cx: 12, cy: 13.4, r: 5.8, fill: '#f7d0b2' }),
|
|
1044
|
+
h('path', {
|
|
1045
|
+
d: 'M12 20.4c-3.9 0-6.7-2.6-6.7-6.3 2.2 1.2 4.4 1.8 6.7 1.8s4.5-.6 6.7-1.8c0 3.7-2.8 6.3-6.7 6.3Z',
|
|
1046
|
+
fill: '#ffffff',
|
|
1047
|
+
}),
|
|
1048
|
+
h('path', {
|
|
1049
|
+
d: 'M5.2 10.6c0-3.6 3-6.5 6.8-6.5s6.8 2.9 6.8 6.5Z',
|
|
1050
|
+
fill: '#e2412f',
|
|
1051
|
+
}),
|
|
1052
|
+
h('rect', { x: 4.8, y: 9.9, width: 14.4, height: 2.5, rx: 1.25, fill: '#ffffff' }),
|
|
1053
|
+
h('circle', { cx: 18.6, cy: 4.9, r: 1.8, fill: '#ffffff' }),
|
|
1054
|
+
h('circle', { cx: 9.8, cy: 13.6, r: 0.9, fill: '#3b2a22' }),
|
|
1055
|
+
h('circle', { cx: 14.2, cy: 13.6, r: 0.9, fill: '#3b2a22' }),
|
|
1056
|
+
h('circle', { cx: 12, cy: 15.3, r: 0.8, fill: '#dd7d6b' }),
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
837
1060
|
function PlayIcon() {
|
|
838
1061
|
return h(
|
|
839
1062
|
'svg',
|
|
@@ -962,10 +1185,13 @@ window.__ModuleLoader__.load({
|
|
|
962
1185
|
const [settingsOpen, setSettingsOpen] = useState(false);
|
|
963
1186
|
const [settingsError, setSettingsError] = useState('');
|
|
964
1187
|
const [runDuration, setRunDuration] = useState(DEFAULT_SETTINGS.minutes * 60000);
|
|
1188
|
+
const [song, setSong] = useState('');
|
|
965
1189
|
|
|
966
1190
|
const modeRef = useRef('closed');
|
|
967
1191
|
const sessionRef = useRef(0);
|
|
968
1192
|
const sequenceRef = useRef(0);
|
|
1193
|
+
const songRef = useRef('');
|
|
1194
|
+
const songIndexRef = useRef(0);
|
|
969
1195
|
const timerStartedRef = useRef(false);
|
|
970
1196
|
const settingsOpenRef = useRef(false);
|
|
971
1197
|
const settingsRef = useRef(settings);
|
|
@@ -1210,19 +1436,72 @@ window.__ModuleLoader__.load({
|
|
|
1210
1436
|
}
|
|
1211
1437
|
}, [ensureAudio]);
|
|
1212
1438
|
|
|
1439
|
+
const playNote = useCallback(
|
|
1440
|
+
(midi, durationSec) => {
|
|
1441
|
+
const ac = ensureAudio();
|
|
1442
|
+
if (!ac) return;
|
|
1443
|
+
if (ac.state === 'suspended') {
|
|
1444
|
+
void ac.resume().catch(() => {});
|
|
1445
|
+
}
|
|
1446
|
+
try {
|
|
1447
|
+
const start = ac.currentTime + 0.008;
|
|
1448
|
+
const end = start + Math.max(0.18, durationSec);
|
|
1449
|
+
const master = ac.createGain();
|
|
1450
|
+
master.gain.setValueAtTime(0.0001, start);
|
|
1451
|
+
master.gain.exponentialRampToValueAtTime(0.16, start + 0.014);
|
|
1452
|
+
master.gain.exponentialRampToValueAtTime(0.0001, end);
|
|
1453
|
+
master.connect(ac.destination);
|
|
1454
|
+
const base = midiHz(midi);
|
|
1455
|
+
const voices = [
|
|
1456
|
+
{ type: 'triangle', ratio: 1, level: 1 },
|
|
1457
|
+
{ type: 'sine', ratio: 2, level: 0.3 },
|
|
1458
|
+
{ type: 'sine', ratio: 0.5, level: 0.2 },
|
|
1459
|
+
];
|
|
1460
|
+
for (const voice of voices) {
|
|
1461
|
+
const osc = ac.createOscillator();
|
|
1462
|
+
const gain = ac.createGain();
|
|
1463
|
+
osc.type = voice.type;
|
|
1464
|
+
osc.frequency.setValueAtTime(base * voice.ratio, start);
|
|
1465
|
+
gain.gain.setValueAtTime(voice.level, start);
|
|
1466
|
+
osc.connect(gain);
|
|
1467
|
+
gain.connect(master);
|
|
1468
|
+
osc.start(start);
|
|
1469
|
+
osc.stop(end + 0.03);
|
|
1470
|
+
}
|
|
1471
|
+
} catch {
|
|
1472
|
+
/* the bubble still appears when a browser refuses the sound */
|
|
1473
|
+
}
|
|
1474
|
+
},
|
|
1475
|
+
[ensureAudio],
|
|
1476
|
+
);
|
|
1477
|
+
|
|
1213
1478
|
const removeEntity = useCallback((id) => {
|
|
1214
1479
|
setEntities((prev) => prev.filter((entity) => entity.id !== id));
|
|
1215
1480
|
}, []);
|
|
1216
1481
|
|
|
1217
1482
|
const spawnEntity = useCallback(
|
|
1218
|
-
(x, y) => {
|
|
1483
|
+
(x, y, syllable) => {
|
|
1219
1484
|
if (modeRef.current !== 'play' || settingsOpenRef.current) return;
|
|
1220
1485
|
sequenceRef.current += 1;
|
|
1221
|
-
const kind =
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
?
|
|
1225
|
-
:
|
|
1486
|
+
const kind = syllable
|
|
1487
|
+
? pick(['bubble', 'square', 'fish', 'star'])
|
|
1488
|
+
: Math.random() < 0.55
|
|
1489
|
+
? 'bubble'
|
|
1490
|
+
: 'fish';
|
|
1491
|
+
let entity;
|
|
1492
|
+
if (kind === 'bubble') {
|
|
1493
|
+
entity = makeBubble(x, y, sequenceRef.current, syllable ? rand(66, 94) : 0);
|
|
1494
|
+
} else if (kind === 'square') {
|
|
1495
|
+
entity = makeSquare(x, y, sequenceRef.current, rand(66, 96));
|
|
1496
|
+
} else if (kind === 'star') {
|
|
1497
|
+
entity = makeStar(x, y, sequenceRef.current, rand(62, 92));
|
|
1498
|
+
} else {
|
|
1499
|
+
entity = makeFish(x, y, sequenceRef.current);
|
|
1500
|
+
}
|
|
1501
|
+
if (syllable) {
|
|
1502
|
+
entity.text = syllable;
|
|
1503
|
+
entity.ink = pick(SYLLABLE_INKS);
|
|
1504
|
+
}
|
|
1226
1505
|
setEntities((prev) => {
|
|
1227
1506
|
const next =
|
|
1228
1507
|
prev.length >= MAX_ENTITIES
|
|
@@ -1231,11 +1510,36 @@ window.__ModuleLoader__.load({
|
|
|
1231
1510
|
next.push(entity);
|
|
1232
1511
|
return next;
|
|
1233
1512
|
});
|
|
1234
|
-
playPop();
|
|
1513
|
+
if (!syllable) playPop();
|
|
1235
1514
|
},
|
|
1236
1515
|
[playPop],
|
|
1237
1516
|
);
|
|
1238
1517
|
|
|
1518
|
+
const singNext = useCallback(
|
|
1519
|
+
(x, y) => {
|
|
1520
|
+
const tune = SONGS[songRef.current];
|
|
1521
|
+
if (!tune) return false;
|
|
1522
|
+
const index = songIndexRef.current % tune.notes.length;
|
|
1523
|
+
songIndexRef.current += 1;
|
|
1524
|
+
const [midi, beats, syllable] = tune.notes[index];
|
|
1525
|
+
spawnEntity(x, y, syllable);
|
|
1526
|
+
playNote(midi, (beats * 60) / tune.bpm);
|
|
1527
|
+
return true;
|
|
1528
|
+
},
|
|
1529
|
+
[playNote, spawnEntity],
|
|
1530
|
+
);
|
|
1531
|
+
|
|
1532
|
+
const chooseSong = useCallback(
|
|
1533
|
+
(id) => {
|
|
1534
|
+
const next = songRef.current === id ? '' : id;
|
|
1535
|
+
songRef.current = next;
|
|
1536
|
+
songIndexRef.current = 0;
|
|
1537
|
+
setSong(next);
|
|
1538
|
+
if (next) unlockAudio();
|
|
1539
|
+
},
|
|
1540
|
+
[unlockAudio],
|
|
1541
|
+
);
|
|
1542
|
+
|
|
1239
1543
|
const close = useCallback(() => {
|
|
1240
1544
|
sessionRef.current += 1;
|
|
1241
1545
|
modeRef.current = 'closed';
|
|
@@ -1414,6 +1718,7 @@ window.__ModuleLoader__.load({
|
|
|
1414
1718
|
|
|
1415
1719
|
const open = useCallback(() => {
|
|
1416
1720
|
sessionRef.current += 1;
|
|
1721
|
+
songIndexRef.current = 0;
|
|
1417
1722
|
modeRef.current = 'play';
|
|
1418
1723
|
setMode('play');
|
|
1419
1724
|
setEntities([]);
|
|
@@ -1554,9 +1859,11 @@ window.__ModuleLoader__.load({
|
|
|
1554
1859
|
event.preventDefault();
|
|
1555
1860
|
unlockAudio();
|
|
1556
1861
|
startTimer();
|
|
1557
|
-
|
|
1862
|
+
if (!singNext(event.clientX, event.clientY)) {
|
|
1863
|
+
spawnEntity(event.clientX, event.clientY);
|
|
1864
|
+
}
|
|
1558
1865
|
},
|
|
1559
|
-
[spawnEntity, startTimer, unlockAudio],
|
|
1866
|
+
[singNext, spawnEntity, startTimer, unlockAudio],
|
|
1560
1867
|
);
|
|
1561
1868
|
|
|
1562
1869
|
useEffect(() => {
|
|
@@ -1593,10 +1900,9 @@ window.__ModuleLoader__.load({
|
|
|
1593
1900
|
if (modeRef.current !== 'play' || event.repeat) return;
|
|
1594
1901
|
unlockAudio();
|
|
1595
1902
|
startTimer();
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
);
|
|
1903
|
+
const keyX = rand(window.innerWidth * 0.12, window.innerWidth * 0.88);
|
|
1904
|
+
const keyY = rand(window.innerHeight * 0.3, window.innerHeight * 0.82);
|
|
1905
|
+
if (!singNext(keyX, keyY)) spawnEntity(keyX, keyY);
|
|
1600
1906
|
};
|
|
1601
1907
|
const onKeyUp = (event) => {
|
|
1602
1908
|
if (event.key === 'Escape' && escHoldRef.current) {
|
|
@@ -1622,7 +1928,7 @@ window.__ModuleLoader__.load({
|
|
|
1622
1928
|
escHoldRef.current = 0;
|
|
1623
1929
|
}
|
|
1624
1930
|
};
|
|
1625
|
-
}, [mode, close, closeSettings, spawnEntity, startTimer, unlockAudio]);
|
|
1931
|
+
}, [mode, close, closeSettings, singNext, spawnEntity, startTimer, unlockAudio]);
|
|
1626
1932
|
|
|
1627
1933
|
useEffect(() => {
|
|
1628
1934
|
return () => {
|
|
@@ -1715,10 +2021,24 @@ window.__ModuleLoader__.load({
|
|
|
1715
2021
|
h(
|
|
1716
2022
|
'div',
|
|
1717
2023
|
{ className: 'yoyo-entities' },
|
|
1718
|
-
entities.map((entity) => {
|
|
1719
|
-
const
|
|
1720
|
-
const
|
|
2024
|
+
entities.map((entity, index) => {
|
|
2025
|
+
const isFish = entity.kind === 'fish';
|
|
2026
|
+
const isLatest = index === entities.length - 1;
|
|
2027
|
+
const style = isFish
|
|
1721
2028
|
? {
|
|
2029
|
+
left: px(entity.x),
|
|
2030
|
+
top: px(entity.y),
|
|
2031
|
+
width: px(entity.width),
|
|
2032
|
+
height: px(entity.height),
|
|
2033
|
+
'--dur': entity.duration + 'ms',
|
|
2034
|
+
'--fx1': px(entity.fx1),
|
|
2035
|
+
'--fy1': px(entity.fy1),
|
|
2036
|
+
'--fx2': px(entity.fx2),
|
|
2037
|
+
'--fy2': px(entity.fy2),
|
|
2038
|
+
'--fx3': px(entity.fx3),
|
|
2039
|
+
'--fy3': px(entity.fy3),
|
|
2040
|
+
}
|
|
2041
|
+
: {
|
|
1722
2042
|
left: px(entity.x),
|
|
1723
2043
|
top: px(entity.y),
|
|
1724
2044
|
width: px(entity.size),
|
|
@@ -1733,45 +2053,98 @@ window.__ModuleLoader__.load({
|
|
|
1733
2053
|
'--dy3': px(entity.dy3),
|
|
1734
2054
|
'--dx4': px(entity.dx4),
|
|
1735
2055
|
'--dy4': px(entity.dy4),
|
|
1736
|
-
}
|
|
1737
|
-
: {
|
|
1738
|
-
left: px(entity.x),
|
|
1739
|
-
top: px(entity.y),
|
|
1740
|
-
width: px(entity.width),
|
|
1741
|
-
height: px(entity.height),
|
|
1742
|
-
'--dur': entity.duration + 'ms',
|
|
1743
|
-
'--fx1': px(entity.fx1),
|
|
1744
|
-
'--fy1': px(entity.fy1),
|
|
1745
|
-
'--fx2': px(entity.fx2),
|
|
1746
|
-
'--fy2': px(entity.fy2),
|
|
1747
|
-
'--fx3': px(entity.fx3),
|
|
1748
|
-
'--fy3': px(entity.fy3),
|
|
1749
2056
|
};
|
|
2057
|
+
const shapeClass =
|
|
2058
|
+
entity.kind === 'square'
|
|
2059
|
+
? 'yoyo-square'
|
|
2060
|
+
: entity.kind === 'star'
|
|
2061
|
+
? 'yoyo-star-shape'
|
|
2062
|
+
: isFish
|
|
2063
|
+
? 'yoyo-fish-swim'
|
|
2064
|
+
: 'yoyo-bubble';
|
|
2065
|
+
const label = entity.text
|
|
2066
|
+
? h(
|
|
2067
|
+
'span',
|
|
2068
|
+
{
|
|
2069
|
+
className: 'yoyo-syllable' + (isFish ? ' yoyo-syllable-inside' : ''),
|
|
2070
|
+
style: {
|
|
2071
|
+
color: entity.ink || 'rgba(8, 34, 60, 0.88)',
|
|
2072
|
+
fontSize: px(
|
|
2073
|
+
isFish
|
|
2074
|
+
? entity.height * 0.28
|
|
2075
|
+
: entity.size * (entity.kind === 'star' ? 0.34 : 0.42),
|
|
2076
|
+
),
|
|
2077
|
+
},
|
|
2078
|
+
'aria-hidden': true,
|
|
2079
|
+
},
|
|
2080
|
+
entity.text,
|
|
2081
|
+
)
|
|
2082
|
+
: null;
|
|
1750
2083
|
return h(
|
|
1751
2084
|
'div',
|
|
1752
2085
|
{
|
|
1753
2086
|
key: entity.id,
|
|
1754
2087
|
className:
|
|
1755
|
-
'yoyo-entity ' +
|
|
2088
|
+
'yoyo-entity ' +
|
|
2089
|
+
(isFish ? 'yoyo-fish-swim' : 'is-rise') +
|
|
2090
|
+
(isLatest ? ' is-latest' : ''),
|
|
1756
2091
|
style,
|
|
1757
2092
|
onAnimationEnd: (event) => {
|
|
1758
2093
|
if (event.target === event.currentTarget) removeEntity(entity.id);
|
|
1759
2094
|
},
|
|
1760
2095
|
},
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
:
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
2096
|
+
h(
|
|
2097
|
+
'div',
|
|
2098
|
+
{ className: 'yoyo-shape ' + shapeClass },
|
|
2099
|
+
isFish
|
|
2100
|
+
? h(
|
|
2101
|
+
'div',
|
|
2102
|
+
{ className: 'yoyo-fish-bob' },
|
|
2103
|
+
h(FishArt, {
|
|
2104
|
+
palette: entity.palette,
|
|
2105
|
+
mirrored: entity.dir < 0,
|
|
2106
|
+
}),
|
|
2107
|
+
label,
|
|
2108
|
+
)
|
|
2109
|
+
: h(
|
|
2110
|
+
React.Fragment,
|
|
2111
|
+
null,
|
|
2112
|
+
entity.kind === 'bubble'
|
|
2113
|
+
? h('i', { className: 'yoyo-bubble-shine' })
|
|
2114
|
+
: null,
|
|
2115
|
+
label,
|
|
2116
|
+
),
|
|
2117
|
+
),
|
|
1771
2118
|
);
|
|
1772
2119
|
}),
|
|
1773
2120
|
),
|
|
1774
2121
|
timerStarted ? h(Hourglass, { durationMs: runDuration }) : null,
|
|
2122
|
+
mode === 'play'
|
|
2123
|
+
? h(
|
|
2124
|
+
'div',
|
|
2125
|
+
{
|
|
2126
|
+
className: 'yoyo-songs',
|
|
2127
|
+
role: 'group',
|
|
2128
|
+
'aria-label': tr('songHint'),
|
|
2129
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
2130
|
+
},
|
|
2131
|
+
SONG_IDS.map((id) =>
|
|
2132
|
+
h(
|
|
2133
|
+
'button',
|
|
2134
|
+
{
|
|
2135
|
+
key: id,
|
|
2136
|
+
type: 'button',
|
|
2137
|
+
className: 'yoyo-song' + (song === id ? ' is-on' : ''),
|
|
2138
|
+
onClick: () => chooseSong(id),
|
|
2139
|
+
'aria-label': tr(id === 'star' ? 'starSong' : 'santaSong'),
|
|
2140
|
+
'aria-pressed': song === id,
|
|
2141
|
+
title: tr(id === 'star' ? 'starSong' : 'santaSong'),
|
|
2142
|
+
},
|
|
2143
|
+
id === 'star' ? h(StarIcon) : h(SantaIcon),
|
|
2144
|
+
),
|
|
2145
|
+
),
|
|
2146
|
+
)
|
|
2147
|
+
: null,
|
|
1775
2148
|
h(
|
|
1776
2149
|
'div',
|
|
1777
2150
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhangxij/dsh-yoyo-bubbles",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "深蓝色全屏泡泡乐园:轻触即冒出彩色泡泡或小鱼,可设 1–15 分钟游玩时长,到点播放温柔提示音。纯客户端、不联网、不上传。",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -61,5 +61,8 @@
|
|
|
61
61
|
"@deepseek-ai/dsh-client-ui-conversation"
|
|
62
62
|
]
|
|
63
63
|
}
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"dsh": "^0.2.1"
|
|
64
67
|
}
|
|
65
68
|
}
|