@vicyangorg/dsh-music 0.0.0-stage → 0.3.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.
Files changed (54) hide show
  1. package/README.md +59 -2
  2. package/client/index.js +3868 -0
  3. package/cordis.patch.yml +7 -0
  4. package/docs/DETAIL.md +173 -0
  5. package/docs/assets/artist-page.webp +0 -0
  6. package/docs/assets/library-toolbar.webp +0 -0
  7. package/docs/assets/reco-columns.webp +0 -0
  8. package/host/binaries.js +94 -0
  9. package/host/download.js +204 -0
  10. package/host/history.js +230 -0
  11. package/host/library.js +229 -0
  12. package/host/likes.js +188 -0
  13. package/host/lock.js +64 -0
  14. package/host/main.js +68 -0
  15. package/host/manage.js +169 -0
  16. package/host/media-core.js +299 -0
  17. package/host/metadata/artist.js +85 -0
  18. package/host/metadata/cache.js +51 -0
  19. package/host/metadata/embedded.js +28 -0
  20. package/host/metadata/index.js +78 -0
  21. package/host/metadata/lrc.js +63 -0
  22. package/host/metadata/lrclib.js +69 -0
  23. package/host/metadata/lyrics.js +110 -0
  24. package/host/onboarding.js +225 -0
  25. package/host/playback.js +137 -0
  26. package/host/preview.js +242 -0
  27. package/host/reco/discover.js +568 -0
  28. package/host/reco/diversity.js +140 -0
  29. package/host/reco/images.js +290 -0
  30. package/host/reco/index.js +693 -0
  31. package/host/reco/llm.js +65 -0
  32. package/host/reco/mb.js +29 -0
  33. package/host/reco/pools.js +172 -0
  34. package/host/reco/quota.js +91 -0
  35. package/host/reco/style.js +157 -0
  36. package/host/reco/verify.js +114 -0
  37. package/host/routes.js +222 -0
  38. package/host/search.js +125 -0
  39. package/host/starter.js +317 -0
  40. package/host/storage.js +34 -0
  41. package/host/sync.js +267 -0
  42. package/host/t2s.js +31 -0
  43. package/host/tags.js +47 -0
  44. package/icon.svg +16 -0
  45. package/index.js +2 -0
  46. package/locale/de.json +7 -0
  47. package/locale/en.json +7 -0
  48. package/locale/es.json +7 -0
  49. package/locale/fr.json +7 -0
  50. package/locale/ja.json +7 -0
  51. package/locale/pt.json +7 -0
  52. package/locale/ru.json +7 -0
  53. package/locale/zh.json +7 -0
  54. package/package.json +62 -4
@@ -0,0 +1,3868 @@
1
+ /**
2
+ * dsh-music — Client half (S1: 曲库 + 播放 + UI 骨架).
3
+ *
4
+ * Single self-contained browser artifact, registered through the Harness
5
+ * module loader. No build step, no Harness Client package imports: React
6
+ * comes from the browser module table; every color is a --dsw-alias-* theme
7
+ * token so light/dark follow the host. Visible text goes through the Client
8
+ * locale service (namespace `dshMusic`, zh + en).
9
+ *
10
+ * Surfaces (verified against ui-layout / ui-sidebar contracts):
11
+ * - sidebar.panellist : global "音乐" panel icon (owner props {size, active})
12
+ * - main (keyed) : the music panel, key = 'music'
13
+ * - shell.overlay : persistent mini player, mounted across navigation
14
+ *
15
+ * The audio engine is a singleton owned by apply() (NOT by any React
16
+ * component), so playback survives main-panel switches; the mini player in
17
+ * shell.overlay stays mounted and keeps controlling it.
18
+ *
19
+ * Host contract (agreed with 磐石, S1): same-origin HTTP routes under
20
+ * /dsh-music — GET api/library, POST api/rescan, prefix audio/ (Range),
21
+ * prefix cover/. See bundle/host and docs for the Host half.
22
+ */
23
+ window.__ModuleLoader__.load({
24
+ id: '@vicyangorg/dsh-music',
25
+ factory(require) {
26
+ const React = require('react');
27
+ const h = React.createElement;
28
+ const { useState, useEffect, useMemo, useRef, useCallback } = React;
29
+
30
+ /* The mini player should sit above every panel/dialog of the DSH shell.
31
+ * Portalling to <body> is the only reliable way to escape a host stacking
32
+ * context; when react-dom is not in the module table we fall back to a
33
+ * fixed, very high z-index node rendered in place. */
34
+ let ReactDOM = null;
35
+ try { ReactDOM = require('react-dom'); } catch { ReactDOM = null; }
36
+ function portalToBody(node) {
37
+ if (!ReactDOM || typeof ReactDOM.createPortal !== 'function' || typeof document === 'undefined') return node;
38
+ return ReactDOM.createPortal(node, document.body);
39
+ }
40
+
41
+ const NS = 'dshMusic';
42
+ const PANEL_ID = 'music';
43
+
44
+ /* ================================================================
45
+ * 1. Locale dictionaries (zh primary, en fallback)
46
+ * ================================================================ */
47
+ const zh = {
48
+ panel: '音乐',
49
+ welcomeTitle: '欢迎使用 dsh-music',
50
+ welcomeSub: '本地优先的音乐库与推荐。花一分钟告诉我你想听什么,我把界面调到合你口味。',
51
+ welcomeStart: '开始设置',
52
+ welcomeSkip: '先随便看看',
53
+ welcomeBack: '返回界面',
54
+ welcomePoint1: '播放本地曲库,歌词与歌手资料齐全',
55
+ welcomePoint2: '按你的口味推荐,喜欢的歌才入库',
56
+ welcomePoint3: '所有数据只留在这台电脑上',
57
+ welcomeTasteTitle: '你喜欢听什么?',
58
+ welcomeTasteSub: '可以多选,也可以跳过;之后随时能在推荐里调整。',
59
+ welcomeGenres: '流派',
60
+ welcomeLanguages: '语言',
61
+ welcomePrev: '上一步',
62
+ welcomeNext: '下一步',
63
+ welcomeLibTitle: '从哪里开始?',
64
+ welcomeLibSub: '已经有本地音乐就选第一个;没有的话,我准备了一个免费的公共版权 starter 曲库。',
65
+ welcomeLocalTitle: '使用我已有的音乐库',
66
+ welcomeLocalBody: '扫描 ~/Music/dsh-music、spotify-liked 等默认目录',
67
+ welcomeStarterTitle: '用插件默认 starter 曲库',
68
+ welcomeStarterBody: '几首 CC0 / 公有领域曲目,逐首核实并署名',
69
+ welcomeStarterHint: '曲目会串行取回到 ~/Music/dsh-music/starter,完成后自动入库;网络失败会跳过,不影响使用。',
70
+ welcomeLocalHint: '完成后会立即扫描曲库并进入曲库页。',
71
+ welcomeFinish: '完成',
72
+ welcomeStarterDownloading: '正在准备 starter 曲库…',
73
+ welcomeStarterReady: 'starter 曲库已就绪',
74
+ welcomeStarterSkipped: '网络不可用,已跳过 starter,稍后可在推荐页探索',
75
+ welcomeCredits: '曲目与许可',
76
+ welcomeEnter: '进入推荐',
77
+ welcomeSaveFail: '保存失败,请重试',
78
+ welcomePreview: '预览欢迎页',
79
+ genre_jazz: '爵士',
80
+ genre_classical: '古典',
81
+ genre_electronic: '电子',
82
+ genre_blues: '布鲁斯',
83
+ genre_reggae: '雷鬼',
84
+ genre_soul: '灵魂乐',
85
+ genre_folk: '民谣',
86
+ genre_metal: '金属',
87
+ genre_funk: '放克',
88
+ genre_ambient: '氛围',
89
+ lang_zh: '中文',
90
+ lang_en: '英语',
91
+ lang_yue: '粤语',
92
+ lang_ja: '日语',
93
+ lang_ko: '韩语',
94
+ lang_fr: '法语',
95
+ lang_es: '西班牙语',
96
+ lang_pt: '葡萄牙语',
97
+ lang_it: '意大利语',
98
+ welcomeTasteNote: '偏好只用于微调探索批次,不会锁死你的推荐;之后随时能改。',
99
+ welcomePathLabel: '音乐目录(可选)',
100
+ welcomePathPlaceholder: '~/Music/我的音乐',
101
+ welcomePathHint: '留空则使用已经扫描到的曲库;填了会自动挂载并重新扫描。',
102
+
103
+ tabLibrary: '曲库',
104
+ tabReco: '推荐',
105
+ tabNow: '正在播放',
106
+ searchPlaceholder: '搜索歌曲、歌手或专辑',
107
+ groupNone: '列表',
108
+ groupArtist: '按歌手',
109
+ groupAlbum: '按专辑',
110
+ groupLabel: '分组方式',
111
+ rescan: '重新扫描',
112
+ rescanning: '扫描中…',
113
+ tracksUnit: '首',
114
+ playAll: '播放全部',
115
+ shufflePlay: '随机播放',
116
+ loading: '正在扫描曲库…',
117
+ loadError: '曲库加载失败',
118
+ retry: '重试',
119
+ emptyLibraryTitle: '曲库还是空的',
120
+ emptyLibraryBody: '搜歌手或歌名就能在线试听,喜欢的歌会自动入库;已有音乐也可以放进扫描目录。',
121
+ emptySearchCta: '搜歌手/歌名试听',
122
+ emptyAddDirHint: '默认扫描目录(支持 mp3 / flac / m4a / wav 等):',
123
+ emptyRescanCta: '重新扫描曲库',
124
+ emptyDirNote: '也可以在插件配置里用 directories 自定义扫描目录。',
125
+ syncOptional: 'Spotify 同步(可选)',
126
+ syncOptionalHint: '可选功能:需要机器上已安装 spotify-sync CLI,没有也不影响听歌',
127
+ syncUnavailableHint: '未检测到 spotify-sync CLI,同步功能暂不可用(可跳过,不影响听歌)',
128
+ exploreChip: '探索批次',
129
+ recoColdTitle: '还没有收听历史',
130
+ recoColdBody: '先搜歌手或歌名试听,喜欢的歌会自动入库;听过几首后这里会按你的口味推荐。',
131
+ unknownAlbum: '未知专辑',
132
+ unknownArtist: '未知歌手',
133
+ nowPlaying: '正在播放',
134
+ queue: '播放队列',
135
+ queueEmpty: '队列空空如也,去曲库点一首歌吧。',
136
+ noTrackTitle: '还没有在播放的歌',
137
+ noTrackBody: '去曲库挑一首,按下播放,这里会变成你的专属播放台。',
138
+ goLibrary: '去曲库',
139
+ play: '播放',
140
+ pause: '暂停',
141
+ prev: '上一首',
142
+ next: '下一首',
143
+ shuffle: '随机播放',
144
+ shuffleOn: '随机播放:开',
145
+ repeat: '循环模式',
146
+ repeatOff: '循环:关',
147
+ repeatAll: '循环:列表循环',
148
+ repeatOne: '循环:单曲循环',
149
+ volume: '音量',
150
+ mute: '静音',
151
+ unmute: '取消静音',
152
+ stop: '停止并关闭',
153
+ miniLabel: '迷你播放条',
154
+ openNow: '打开正在播放',
155
+ playError: '播放出错',
156
+ recoTitle: '推荐',
157
+ recoBody: '基于你的收听历史,每批约 10 首:7 首口味相近 + 3 首强制探索(流派 / 语言 / 年代轮换,还有"意外之喜"位),帮你打破信息茧房。',
158
+ recoNote: '每首候选都会先联网核实真实存在,附推荐理由;试听不占空间,喜欢的歌才自动入库到 ~/Music/dsh-music。',
159
+ recoTaste: '口味相近',
160
+ recoSimilar: '相近',
161
+ recoExplore: '强制探索',
162
+ recoVerify: '联网核实',
163
+ searchEmpty: '没有匹配的歌曲,换个关键词试试。',
164
+ untitled: '未命名',
165
+ sourceSpotify: 'Spotify 收藏',
166
+ sourceDsh: '推荐入库',
167
+ sourceApple: 'Apple Music',
168
+ seekLabel: '播放进度',
169
+ playTrack: '播放这首歌',
170
+ scanFailedHint: '请确认 Host 半已安装并启用(/dsh-music/api/library)。',
171
+ networkError: '无法连接音乐服务,请确认插件 Host 半已启用。',
172
+ audioError: '音频加载失败,文件可能已移动或损坏。',
173
+ lyricsTitle: '歌词',
174
+ lyricsNone: '暂无歌词,仅播放',
175
+ lyricsLoading: '歌词加载中…',
176
+ lyricsError: '歌词加载失败',
177
+ lyricsRetry: '重试',
178
+ lyricsSourceEmbedded: '内嵌标签',
179
+ lyricsSourceLrclib: 'LRCLIB',
180
+ lyricsSourceWeb: '联网补齐',
181
+ lyricsSource: '歌词来源',
182
+ artistOpen: '查看歌手卡片',
183
+ artistIntro: '简介',
184
+ artistNews: '近期动态',
185
+ artistTrivia: '逸闻趣事',
186
+ artistSimilarArtists: '相似歌手',
187
+ artistSimilarSongs: '相似歌曲',
188
+ kindFact: '事实',
189
+ kindRumor: '传闻',
190
+ citeLink: '来源链接',
191
+ citeSource: '来源',
192
+ noSection: '暂无内容',
193
+ statPlays: '播放次数',
194
+ statSeconds: '总时长',
195
+ statSongs: '歌曲数',
196
+ statArtists: '歌手数',
197
+ statSkipped: '跳过次数',
198
+ statCompletion: '平均完整度',
199
+ trendTitle: '近 7 天',
200
+ topSongs: '常听歌曲',
201
+ topUnplayable: '该歌曲当前不在曲库,无法播放',
202
+ topArtists: '常听歌手',
203
+ playsUnit: '次',
204
+ modeOne: '单曲循环',
205
+ modeOrder: '顺序播放',
206
+ modeShuffle: '随机播放',
207
+ hideMini: '隐藏迷你播放条',
208
+ showMini: '显示迷你播放条',
209
+ recoToday: '今日推荐',
210
+ recoArtist: '歌手推荐',
211
+ recoNew: '新歌推荐',
212
+ recoSectionEmpty: '这一栏还没有内容,点「换一批」生成。',
213
+ deleteTrack: '删除',
214
+ revealTrack: '在 Finder 显示',
215
+ deleteConfirm: '从曲库删除这首歌?本地文件会被移除。',
216
+ deleteLikedConfirm: '这是 Spotify 收藏里的歌。删除只会去掉本地文件,不会取消云端收藏。确定继续?',
217
+ deleteLikedConfirm2: '再次确认:本地文件删除后无法从插件恢复。',
218
+ deleteFailed: '删除失败',
219
+ searchTypeSong: '歌曲',
220
+ searchTypeArtist: '歌手',
221
+ searchWebTitle: '网上补全(MusicBrainz)',
222
+ searchNoLocal: '本地曲库没有匹配,可以试试下面的在线补全。',
223
+ styleBtn: '搜风格',
224
+ stylePlaceholder: '描述一种风格,如:深夜爵士 / 粤语经典',
225
+ styleLoading: '正在按风格检索并逐首核实,约需几十秒…',
226
+ styleError: '风格搜索失败',
227
+ styleEmpty: '没有匹配这个风格的已核实歌曲,换个描述试试。',
228
+ interpretedAs: '理解为',
229
+ styleChip: '风格',
230
+ backToReco: '返回推荐',
231
+ colToday: '今日推荐',
232
+ colArtist: '歌手推荐',
233
+ colNew: '新歌推荐',
234
+ playColumn: '播放本栏',
235
+ likeBtn: '喜欢',
236
+ likedBtn: '已喜欢',
237
+ unlikeBtn: '取消喜欢',
238
+ previewLoading: '试听准备中,请稍候…',
239
+ previewFail: '试听失败',
240
+ previewNoVerify: '该曲目缺少核实记录,暂无法试听',
241
+ previewLabel: '试听(不入库)',
242
+ modeHintOne: '单曲循环:反复播放当前这首',
243
+ modeHintOrder: '顺序播放:按队列依次播放',
244
+ modeCycleHint: '点击切换播放模式',
245
+ modeHintShuffle: '随机播放:每轮打乱不重复',
246
+ artistPageBack: '返回推荐',
247
+ artistSongs: '的歌曲',
248
+ artistLoading: '正在打开歌手页…',
249
+ artistError: '歌手页加载失败',
250
+ artistNoSongs: '这位歌手暂时没有已核实的歌曲。',
251
+ miniNeedsTrack: '播放任意歌曲后,这里会出现迷你播放条',
252
+ miniCollapse: '收起',
253
+ miniExpand: '展开',
254
+ miniDrag: '拖动调整位置',
255
+ miniLyrics: '歌词',
256
+ playList: '播放该列表',
257
+ recoGenerate: '生成推荐',
258
+ recoRegenerate: '换一批',
259
+ recoGenerating: '正在生成推荐(每首候选先联网核实,约需半分钟)…',
260
+ recoEmptyTitle: '还没有推荐',
261
+ recoEmptyBody: '基于你的收听历史生成一批 10 首:7 首口味相近 + 3 首强制探索(流派/语言/年代轮换),每首都先联网核实真实存在,杜绝幻觉歌曲。多听几首歌,推荐会更懂你。',
262
+ recoError: '推荐生成失败',
263
+ downloadTitle: '入库队列',
264
+ downloadBtn: '入库',
265
+ downloading: '入库中…',
266
+ downloadDone: '已入库',
267
+ downloadFail: '失败',
268
+ downloadPlay: '已入库,曲库已刷新,可直接播放。',
269
+ downloadError: '入库失败',
270
+ downloadIdle: '暂无入库任务',
271
+ syncBtn: '同步 Spotify',
272
+ syncing: '同步中…',
273
+ syncCloud: '云端收藏',
274
+ syncAdded: '新增入库',
275
+ syncRemoved: '云端移除',
276
+ syncOk: '本地已有',
277
+ syncFail: '失败',
278
+ syncMissing: '本地缺失',
279
+ syncError: '同步失败',
280
+ tabHistory: '历史',
281
+ historyTitle: '收听历史',
282
+ historyEmpty: '还没有播放记录,去曲库放几首歌吧。',
283
+ historyLoading: '历史加载中…',
284
+ historyError: '历史加载失败',
285
+ historySkipped: '跳过',
286
+ historyComplete: '完整度',
287
+ verified: '已核实',
288
+ };
289
+ const en = {
290
+ panel: 'Music',
291
+ welcomeTitle: 'Welcome to dsh-music',
292
+ welcomeSub: 'A local-first music library and recommender. Tell me what you like and I will tune the panel to you.',
293
+ welcomeStart: 'Set it up',
294
+ welcomeSkip: 'Just browse',
295
+ welcomeBack: 'Back to the app',
296
+ welcomePoint1: 'Play your local library with lyrics and artist profiles',
297
+ welcomePoint2: 'Recommendations tuned to your taste; only liked songs are saved',
298
+ welcomePoint3: 'Everything stays on this computer',
299
+ welcomeTasteTitle: 'What do you like to hear?',
300
+ welcomeTasteSub: 'Pick as many as you want, or skip; you can change this later in Recommendations.',
301
+ welcomeGenres: 'Genres',
302
+ welcomeLanguages: 'Languages',
303
+ welcomePrev: 'Back',
304
+ welcomeNext: 'Next',
305
+ welcomeLibTitle: 'Where should we start?',
306
+ welcomeLibSub: 'Already have local music? Pick the first one. Otherwise I prepared a free public-domain starter library.',
307
+ welcomeLocalTitle: 'Use my existing music',
308
+ welcomeLocalBody: 'Scan ~/Music/dsh-music, spotify-liked and other default folders',
309
+ welcomeStarterTitle: 'Use the built-in starter library',
310
+ welcomeStarterBody: 'A few CC0 / public-domain tracks, verified and credited one by one',
311
+ welcomeStarterHint: 'Tracks download one at a time to ~/Music/dsh-music/starter and are added automatically; network failures are skipped, never blocking.',
312
+ welcomeLocalHint: 'The library will be scanned right away and you will land in Library.',
313
+ welcomeFinish: 'Finish',
314
+ welcomeStarterDownloading: 'Preparing the starter library…',
315
+ welcomeStarterReady: 'Starter library is ready',
316
+ welcomeStarterSkipped: 'Network unavailable — starter skipped, explore Recommendations instead',
317
+ welcomeCredits: 'Tracks & licences',
318
+ welcomeEnter: 'Open Recommendations',
319
+ welcomeSaveFail: 'Could not save — please try again',
320
+ welcomePreview: 'Preview welcome',
321
+ genre_jazz: 'Jazz',
322
+ genre_classical: 'Classical',
323
+ genre_electronic: 'Electronic',
324
+ genre_blues: 'Blues',
325
+ genre_reggae: 'Reggae',
326
+ genre_soul: 'Soul',
327
+ genre_folk: 'Folk',
328
+ genre_metal: 'Metal',
329
+ genre_funk: 'Funk',
330
+ genre_ambient: 'Ambient',
331
+ lang_zh: 'Chinese',
332
+ lang_en: 'English',
333
+ lang_yue: 'Cantonese',
334
+ lang_ja: 'Japanese',
335
+ lang_ko: 'Korean',
336
+ lang_fr: 'French',
337
+ lang_es: 'Spanish',
338
+ lang_pt: 'Portuguese',
339
+ lang_it: 'Italian',
340
+ welcomeTasteNote: 'Preferences only bias the discovery batch - nothing is locked, and you can change them any time.',
341
+ welcomePathLabel: 'Music folder (optional)',
342
+ welcomePathPlaceholder: '~/Music/My Music',
343
+ welcomePathHint: 'Leave empty to use the library already scanned; a folder is mounted and rescanned.',
344
+
345
+ tabLibrary: 'Library',
346
+ tabReco: 'For You',
347
+ tabNow: 'Now Playing',
348
+ searchPlaceholder: 'Search songs, artists or albums',
349
+ groupNone: 'List',
350
+ groupArtist: 'By artist',
351
+ groupAlbum: 'By album',
352
+ groupLabel: 'Group by',
353
+ rescan: 'Rescan',
354
+ rescanning: 'Scanning…',
355
+ tracksUnit: 'tracks',
356
+ playAll: 'Play all',
357
+ shufflePlay: 'Shuffle',
358
+ loading: 'Scanning your library…',
359
+ loadError: 'Library failed to load',
360
+ retry: 'Retry',
361
+ emptyLibraryTitle: 'Your library is empty',
362
+ emptyLibraryBody: 'Search an artist or song to preview it right away — liked songs are added automatically. Your own music can also go into the scanned folders.',
363
+ emptySearchCta: 'Search to preview',
364
+ emptyAddDirHint: 'Default scanned folders (mp3 / flac / m4a / wav…):',
365
+ emptyRescanCta: 'Rescan library',
366
+ emptyDirNote: 'You can also set custom folders with `directories` in the plugin config.',
367
+ syncOptional: 'Spotify sync (optional)',
368
+ syncOptionalHint: 'Optional: needs the spotify-sync CLI installed; music works without it',
369
+ syncUnavailableHint: 'spotify-sync CLI not found — sync is unavailable (safe to skip)',
370
+ exploreChip: 'Exploration batch',
371
+ recoColdTitle: 'No listening history yet',
372
+ recoColdBody: 'Search and preview some songs first — liked songs are added automatically, and recommendations will follow your taste.',
373
+ unknownAlbum: 'Unknown album',
374
+ unknownArtist: 'Unknown artist',
375
+ nowPlaying: 'Now playing',
376
+ queue: 'Queue',
377
+ queueEmpty: 'The queue is empty — pick a song from the library.',
378
+ noTrackTitle: 'Nothing is playing',
379
+ noTrackBody: 'Pick a song from the library and press play; this becomes your personal deck.',
380
+ goLibrary: 'Open library',
381
+ play: 'Play',
382
+ pause: 'Pause',
383
+ prev: 'Previous',
384
+ next: 'Next',
385
+ shuffle: 'Shuffle',
386
+ shuffleOn: 'Shuffle: on',
387
+ repeat: 'Repeat mode',
388
+ repeatOff: 'Repeat: off',
389
+ repeatAll: 'Repeat: queue',
390
+ repeatOne: 'Repeat: one',
391
+ volume: 'Volume',
392
+ mute: 'Mute',
393
+ unmute: 'Unmute',
394
+ stop: 'Stop and close',
395
+ miniLabel: 'Mini player',
396
+ openNow: 'Open Now Playing',
397
+ playError: 'Playback error',
398
+ recoTitle: 'For You',
399
+ recoBody: 'Built from your listening history, ~10 tracks per batch: 7 close to your taste + 3 forced explorations (genre / language / era rotation plus a wildcard slot) to break the filter bubble.',
400
+ recoNote: 'Every candidate is verified online first and ships with a reason; previews cost no space, and only liked songs land in ~/Music/dsh-music.',
401
+ recoTaste: 'Close to taste',
402
+ recoSimilar: 'Similar',
403
+ recoExplore: 'Forced exploration',
404
+ recoVerify: 'Verified online',
405
+ searchEmpty: 'No matching tracks — try another keyword.',
406
+ untitled: 'Untitled',
407
+ sourceSpotify: 'Spotify liked',
408
+ sourceDsh: 'Recommended',
409
+ sourceApple: 'Apple Music',
410
+ seekLabel: 'Seek',
411
+ playTrack: 'Play this track',
412
+ scanFailedHint: 'Make sure the Host half is installed and enabled (/dsh-music/api/library).',
413
+ networkError: 'Cannot reach the music service. Is the plugin Host half enabled?',
414
+ audioError: 'Audio failed to load; the file may have moved or is corrupt.',
415
+ lyricsTitle: 'Lyrics',
416
+ lyricsNone: 'No lyrics — just play',
417
+ lyricsLoading: 'Loading lyrics…',
418
+ lyricsError: 'Lyrics failed to load',
419
+ lyricsRetry: 'Retry',
420
+ lyricsSourceEmbedded: 'Embedded tags',
421
+ lyricsSourceLrclib: 'LRCLIB',
422
+ lyricsSourceWeb: 'Web lookup',
423
+ lyricsSource: 'Lyrics source',
424
+ artistOpen: 'Open artist card',
425
+ artistIntro: 'Intro',
426
+ artistNews: 'Recent news',
427
+ artistTrivia: 'Trivia',
428
+ artistSimilarArtists: 'Similar artists',
429
+ artistSimilarSongs: 'Similar songs',
430
+ kindFact: 'Fact',
431
+ kindRumor: 'Rumor',
432
+ citeLink: 'Source link',
433
+ citeSource: 'Source',
434
+ noSection: 'Nothing here yet',
435
+ statPlays: 'Plays',
436
+ statSeconds: 'Listening time',
437
+ statSongs: 'Songs',
438
+ statArtists: 'Artists',
439
+ statSkipped: 'Skipped',
440
+ statCompletion: 'Avg completion',
441
+ trendTitle: 'Last 7 days',
442
+ topSongs: 'Most played songs',
443
+ topUnplayable: 'This song is not in your library right now',
444
+ topArtists: 'Most played artists',
445
+ playsUnit: 'plays',
446
+ modeOne: 'Repeat one',
447
+ modeOrder: 'In order',
448
+ modeShuffle: 'Shuffle',
449
+ hideMini: 'Hide mini player',
450
+ showMini: 'Show mini player',
451
+ recoToday: 'Today',
452
+ recoArtist: 'By artist',
453
+ recoNew: 'New',
454
+ recoSectionEmpty: 'Nothing in this section yet. Generate a new batch.',
455
+ deleteTrack: 'Delete',
456
+ revealTrack: 'Show in Finder',
457
+ deleteConfirm: 'Remove this track from the library? The local file will be deleted.',
458
+ deleteLikedConfirm: 'This is a Spotify liked track. Deleting removes only the local file, not the cloud like. Continue?',
459
+ deleteLikedConfirm2: 'Confirm again: the local file cannot be restored from the plugin.',
460
+ deleteFailed: 'Delete failed',
461
+ searchTypeSong: 'Songs',
462
+ searchTypeArtist: 'Artists',
463
+ searchWebTitle: 'Web matches (MusicBrainz)',
464
+ searchNoLocal: 'Nothing local matched — try a web match below.',
465
+ styleBtn: 'Search style',
466
+ stylePlaceholder: 'Describe a vibe, e.g. late-night jazz / cantonese classics',
467
+ styleLoading: 'Searching by style and verifying each track (~tens of seconds)…',
468
+ styleError: 'Style search failed',
469
+ styleEmpty: 'No verified songs match that style — try another description.',
470
+ interpretedAs: 'Understood as',
471
+ styleChip: 'Style',
472
+ backToReco: 'Back to recommendations',
473
+ colToday: 'Today for You',
474
+ colArtist: 'Artists',
475
+ colNew: 'New Finds',
476
+ playColumn: 'Play column',
477
+ likeBtn: 'Like',
478
+ likedBtn: 'Liked',
479
+ unlikeBtn: 'Unlike',
480
+ previewLoading: 'Preparing preview…',
481
+ previewFail: 'Preview failed',
482
+ previewNoVerify: 'This track has no verification record yet — preview unavailable.',
483
+ previewLabel: 'Preview (not added to library)',
484
+ modeHintOne: 'Repeat one: loop the current song',
485
+ modeHintOrder: 'Play in order through the queue',
486
+ modeCycleHint: 'Click to switch play mode',
487
+ modeHintShuffle: 'Shuffle: random each pass, no repeats',
488
+ artistPageBack: 'Back to recommendations',
489
+ artistSongs: 'songs',
490
+ artistLoading: 'Opening artist page…',
491
+ artistError: 'Artist page failed to load',
492
+ artistNoSongs: 'No verified songs for this artist yet.',
493
+ miniNeedsTrack: 'Play any song and the mini player appears here',
494
+ miniCollapse: 'Collapse',
495
+ miniExpand: 'Expand',
496
+ miniDrag: 'Drag to move',
497
+ miniLyrics: 'Lyrics',
498
+ playList: 'Play this list',
499
+ recoGenerate: 'Generate',
500
+ recoRegenerate: 'Another batch',
501
+ recoGenerating: 'Generating recommendations (every candidate is verified online first, ~30s)…',
502
+ recoEmptyTitle: 'No recommendations yet',
503
+ recoEmptyBody: 'We build a batch of 10 from your listening history: 7 close to your taste + 3 forced explorations (genre / language / era rotation), each verified online before it shows up. Play a few more songs and it gets smarter.',
504
+ recoError: 'Recommendations failed',
505
+ downloadTitle: 'Add-to-library queue',
506
+ downloadBtn: 'Add',
507
+ downloading: 'Adding…',
508
+ downloadDone: 'In library',
509
+ downloadFail: 'Failed',
510
+ downloadPlay: 'Added — the library was refreshed; play it from Library.',
511
+ downloadError: 'Could not add to library',
512
+ downloadIdle: 'Nothing queued',
513
+ syncBtn: 'Sync Spotify',
514
+ syncing: 'Syncing…',
515
+ syncCloud: 'Cloud liked',
516
+ syncAdded: 'New songs',
517
+ syncRemoved: 'Removed from cloud',
518
+ syncOk: 'Already local',
519
+ syncFail: 'Failed',
520
+ syncMissing: 'Missing locally',
521
+ syncError: 'Sync failed',
522
+ tabHistory: 'History',
523
+ historyTitle: 'Listening history',
524
+ historyEmpty: 'No plays yet — go play something from the library.',
525
+ historyLoading: 'Loading history…',
526
+ historyError: 'History failed to load',
527
+ historySkipped: 'Skipped',
528
+ historyComplete: 'Completion',
529
+ verified: 'Verified',
530
+ };
531
+
532
+ /* ================================================================
533
+ * 2. Small helpers
534
+ * ================================================================ */
535
+ const cx = (...parts) => parts.filter(Boolean).join(' ');
536
+
537
+ function formatTime(sec) {
538
+ if (sec == null || !isFinite(sec) || sec < 0) return '--:--';
539
+ const s = Math.floor(sec % 60);
540
+ const m = Math.floor(sec / 60) % 60;
541
+ const hh = Math.floor(sec / 3600);
542
+ const mm = hh > 0 ? String(m).padStart(2, '0') : String(m);
543
+ return (hh > 0 ? hh + ':' : '') + mm + ':' + String(s).padStart(2, '0');
544
+ }
545
+
546
+ const baseUrl = typeof document !== 'undefined' ? document.baseURI : '/';
547
+ const resolveUrl = (path) => {
548
+ try {
549
+ // Host convention (agreed with 磐石): JSON carries root-absolute paths,
550
+ // resolved here against the document base with the leading '/' stripped
551
+ // (same rule as the boot graph) so a non-root mount keeps working.
552
+ const rel = String(path).replace(/^\/+/, '');
553
+ return new URL(rel, baseUrl).href;
554
+ } catch { return path; }
555
+ };
556
+
557
+ /* Traditional→simplified map (S1-002): covers the characters occurring in
558
+ * this library's song titles so a simplified query matches traditional
559
+ * tags. Search-only normalization, never rewrites displayed text. */
560
+ const T2S = {
561
+ 輝:'辉',歲:'岁',軌:'轨',跡:'迹',猶:'犹',闊:'阔',夢:'梦',淚:'泪',橋:'桥',
562
+ 牽:'牵',掛:'挂',鴿:'鸽',與:'与',妳:'你',湯:'汤',蹈:'蹈',彎:'弯',呂:'吕',孫:'孙',
563
+ 張:'张',學:'学',陳:'陈',葉:'叶',蕭:'萧',許:'许',譚:'谭',鄭:'郑',黃:'黄',盧:'卢',
564
+ 愛:'爱',戀:'恋',風:'风',雲:'云',車:'车',馬:'马',鳥:'鸟',語:'语',難:'难',場:'场',
565
+ 遊:'游',戲:'戏',傑:'杰',會:'会',執:'执',曖:'暧',無:'无',曉:'晓',濕:'湿',內:'内',
566
+ 傷:'伤',癡:'痴',聲:'声',絕:'绝',對:'对',終:'终',雙:'双',發:'发',過:'过',後:'后',
567
+ 開:'开',關:'关',門:'门',見:'见',聽:'听',書:'书',畫:'画',樂:'乐',團:'团',隊:'队',
568
+ 員:'员',飛:'飞',機:'机',雞:'鸡',鴨:'鸭',魚:'鱼',飯:'饭',麵:'面',藝:'艺',鐘:'钟',
569
+ 響:'响',歸:'归',訊:'讯',號:'号',個:'个',們:'们',這:'这',裡:'里',麼:'么',義:'义',
570
+ 於:'于',戰:'战',術:'术',補:'补',萬:'万',專:'专',業:'业',歷:'历',動:'动',靜:'静',
571
+ 讓:'让',誰:'谁',變:'变',東:'东',兩:'两',嚴:'严',臨:'临',為:'为',蘋:'苹',帶:'带',
572
+ 離:'离',雜:'杂',館:'馆',頭:'头',點:'点',廳:'厅',錯:'错',錄:'录',錢:'钱',長:'长',
573
+ 時:'时',鏈:'链',閃:'闪',閒:'闲',問:'问',間:'间',誤:'误',悶:'闷',壽:'寿',覺:'觉',覽:'览',觀:'观',
574
+ 歡:'欢',殘:'残',湊:'凑',滅:'灭',滿:'满',漸:'渐',燒:'烧',燈:'灯',獨:'独',獲:'获',
575
+ 環:'环',種:'种',積:'积',窮:'穷',競:'竞',筆:'笔',築:'筑',簡:'简',類:'类',級:'级',
576
+ 練:'练',縣:'县',織:'织',續:'续',經:'经',緣:'缘',編:'编',緩:'缓',縮:'缩',劇:'剧',
577
+ 勸:'劝',勝:'胜',務:'务',區:'区',醫:'医',廠:'厂',廢:'废',強:'强',彈:'弹',徹:'彻',
578
+ 憶:'忆',懷:'怀',擁:'拥',擊:'击',據:'据',擬:'拟',攝:'摄',敵:'敌',斷:'断',舊:'旧',
579
+ 顯:'显',頂:'顶',頓:'顿',頻:'频',顆:'颗',題:'题',顏:'颜',願:'愿',養:'养',餘:'余',
580
+ 餵:'喂',馳:'驰',驅:'驱',驚:'惊',癢:'痒',畢:'毕',
581
+ };
582
+ function normalizeZh(s) {
583
+ const lower = String(s || '').toLowerCase();
584
+ let out = '';
585
+ for (const ch of lower) out += T2S[ch] || ch;
586
+ return out;
587
+ }
588
+
589
+ function readPrefs() {
590
+ try {
591
+ const raw = localStorage.getItem('dsh-music.prefs');
592
+ return raw ? JSON.parse(raw) : {};
593
+ } catch { return {}; }
594
+ }
595
+ function writePrefs(patch) {
596
+ try {
597
+ localStorage.setItem('dsh-music.prefs', JSON.stringify({ ...readPrefs(), ...patch }));
598
+ } catch { /* private mode etc. — prefs are best-effort */ }
599
+ }
600
+
601
+ /** Minimal observable store: getSnapshot + subscribe, immutable updates. */
602
+ function createStore(initial) {
603
+ let state = initial;
604
+ const listeners = new Set();
605
+ return {
606
+ getSnapshot: () => state,
607
+ subscribe: (fn) => { listeners.add(fn); return () => { listeners.delete(fn); }; },
608
+ set: (patch) => {
609
+ state = { ...state, ...patch };
610
+ for (const fn of [...listeners]) fn();
611
+ },
612
+ };
613
+ }
614
+
615
+ /* ================================================================
616
+ * 3. Original icon set (hand-drawn paths, currentColor, 24 viewBox)
617
+ * ================================================================ */
618
+ function makeIcon(nodes, defaults) {
619
+ return function Icon({ size = 18, style, className } = {}) {
620
+ return h('svg', {
621
+ viewBox: '0 0 24 24', width: size, height: size,
622
+ fill: 'none', stroke: 'currentColor', strokeWidth: 1.8,
623
+ strokeLinecap: 'round', strokeLinejoin: 'round',
624
+ 'aria-hidden': true, focusable: false, style, className,
625
+ ...defaults,
626
+ }, nodes.map((n, i) => h(n[0], { key: i, ...n[1] })));
627
+ };
628
+ }
629
+ const FILLED = { fill: 'currentColor', stroke: 'none' };
630
+
631
+ const IconNote = makeIcon([
632
+ ['path', { d: 'M9 18V5l10-2v13' }],
633
+ ['circle', { cx: 6.5, cy: 18, r: 2.5 }],
634
+ ['circle', { cx: 16.5, cy: 16, r: 2.5 }],
635
+ ]);
636
+ const IconPlay = makeIcon([['path', { d: 'M8 5.4v13.2L19 12z', ...FILLED }]]);
637
+ const IconPause = makeIcon([
638
+ ['rect', { x: 7, y: 5, width: 3.4, height: 14, rx: 1.1, ...FILLED }],
639
+ ['rect', { x: 13.6, y: 5, width: 3.4, height: 14, rx: 1.1, ...FILLED }],
640
+ ]);
641
+ const IconPrev = makeIcon([
642
+ ['path', { d: 'M18.5 6v12L10 12z', ...FILLED }],
643
+ ['path', { d: 'M6.5 5.5v13', strokeWidth: 2.2 }],
644
+ ]);
645
+ const IconNext = makeIcon([
646
+ ['path', { d: 'M5.5 6v12L14 12z', ...FILLED }],
647
+ ['path', { d: 'M17.5 5.5v13', strokeWidth: 2.2 }],
648
+ ]);
649
+ const IconShuffle = makeIcon([
650
+ ['path', { d: 'M3 7h3.4c1.5 0 2.9.7 3.8 1.9l4.2 6.2c.9 1.2 2.3 1.9 3.8 1.9H21' }],
651
+ ['path', { d: 'M3 17h3.4c1.5 0 2.9-.7 3.8-1.9l.8-1.2' }],
652
+ ['path', { d: 'M14.1 8.8l.8-1.1C15.8 6.5 17.2 5.8 18.7 5.8H21' }],
653
+ ['path', { d: 'M18.5 3.3 21.5 5.8 18.5 8.3' }],
654
+ ['path', { d: 'M18.5 14.5 21.5 17 18.5 19.5' }],
655
+ ]);
656
+ const IconRepeat = makeIcon([
657
+ ['path', { d: 'M17 2.8 20.4 6.2 17 9.6' }],
658
+ ['path', { d: 'M3.6 11.2V9.6a3.4 3.4 0 0 1 3.4-3.4h13.4' }],
659
+ ['path', { d: 'M7 21.2 3.6 17.8 7 14.4' }],
660
+ ['path', { d: 'M20.4 12.8v1.6a3.4 3.4 0 0 1-3.4 3.4H3.6' }],
661
+ ]);
662
+ const IconRepeatOne = makeIcon([
663
+ ['path', { d: 'M17 2.8 20.4 6.2 17 9.6' }],
664
+ ['path', { d: 'M3.6 11.2V9.6a3.4 3.4 0 0 1 3.4-3.4h13.4' }],
665
+ ['path', { d: 'M7 21.2 3.6 17.8 7 14.4' }],
666
+ ['path', { d: 'M20.4 12.8v1.6a3.4 3.4 0 0 1-3.4 3.4H3.6' }],
667
+ ['path', { d: 'M11.2 10.4l1.4-.9V15', strokeWidth: 1.6 }],
668
+ ]);
669
+ const IconVolume = makeIcon([
670
+ ['path', { d: 'M4 9.5v5h3.5L12 18.6V5.4L7.5 9.5z', ...FILLED }],
671
+ ['path', { d: 'M15.5 9.2a4.1 4.1 0 0 1 0 5.6' }],
672
+ ['path', { d: 'M18.2 6.6a7.9 7.9 0 0 1 0 10.8' }],
673
+ ]);
674
+ const IconMute = makeIcon([
675
+ ['path', { d: 'M4 9.5v5h3.5L12 18.6V5.4L7.5 9.5z', ...FILLED }],
676
+ ['path', { d: 'M16 9.5l5 5M21 9.5l-5 5' }],
677
+ ]);
678
+ const IconSearch = makeIcon([
679
+ ['circle', { cx: 11, cy: 11, r: 6.5 }],
680
+ ['path', { d: 'M15.8 15.8 20.5 20.5' }],
681
+ ]);
682
+ const IconRefresh = makeIcon([
683
+ ['path', { d: 'M20 12a8 8 0 1 1-2.34-5.66' }],
684
+ ['path', { d: 'M20.4 2.8v4h-4' }],
685
+ ]);
686
+ const IconClose = makeIcon([['path', { d: 'M6 6l12 12M18 6 6 18' }]]);
687
+ const IconChevronDown = makeIcon([['path', { d: 'M6 9.5l6 6 6-6' }]]);
688
+ const IconChevronUp = makeIcon([['path', { d: 'M6 14.5l6-6 6 6' }]]);
689
+ const IconGrip = makeIcon([
690
+ ['path', { d: 'M9 7.2h.1M15 7.2h.1M9 12h.1M15 12h.1M9 16.8h.1M15 16.8h.1', strokeWidth: 2.6 }],
691
+ ]);
692
+ const IconSparkles = makeIcon([
693
+ ['path', { d: 'M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z' }],
694
+ ['path', { d: 'M18.6 15.4l.8 2 2 .8-2 .8-.8 2-.8-2-2-.8 2-.8z' }],
695
+ ]);
696
+ const IconCheck = makeIcon([['path', { d: 'M5 12.5l4.4 4.4L19 7' }]]);
697
+ const IconFolder = makeIcon([
698
+ ['path', { d: 'M4 6.8A1.8 1.8 0 0 1 5.8 5h3.1l1.8 2.1h7.5A1.8 1.8 0 0 1 20 8.9v8.3a1.8 1.8 0 0 1-1.8 1.8H5.8A1.8 1.8 0 0 1 4 17.2z' }],
699
+ ]);
700
+ const IconDisc = makeIcon([
701
+ ['circle', { cx: 12, cy: 12, r: 8.6 }],
702
+ ['circle', { cx: 12, cy: 12, r: 2.4 }],
703
+ ]);
704
+ const IconAlert = makeIcon([
705
+ ['circle', { cx: 12, cy: 12, r: 8.6 }],
706
+ ['path', { d: 'M12 7.6v5.2M12 16.4v.1' }],
707
+ ]);
708
+ const IconQueue = makeIcon([['path', { d: 'M4 6.5h16M4 12h16M4 17.5h10' }]]);
709
+ const IconDownload = makeIcon([
710
+ ['path', { d: 'M12 4v10' }],
711
+ ['path', { d: 'M8 10.5 12 14.5 16 10.5' }],
712
+ ['path', { d: 'M5 18.5h14' }],
713
+ ]);
714
+ const IconHeart = makeIcon([
715
+ ['path', { d: 'M12 20s-7.4-4.6-9.3-9C1.4 7.6 3.4 4.5 6.6 4.5c2 0 3.4 1.1 4.2 2.4l1.2 2 1.2-2c.8-1.3 2.2-2.4 4.2-2.4 3.2 0 5.2 3.1 3.9 6.5-1.9 4.4-9.3 9-9.3 9z' }],
716
+ ], { 'data-heart': 1 });
717
+
718
+ /* ================================================================
719
+ * 4. Styles — every color is a host theme token (--dsw-alias-*)
720
+ * ================================================================ */
721
+ const CSS = `
722
+ .dshm-panel{position:relative;display:flex;flex-direction:column;height:100%;min-height:0;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);font-size:13px;}
723
+ .dshm-welcome{position:relative;height:100%;display:flex;align-items:center;justify-content:center;overflow:auto;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);font-size:13px;animation:dshm-fade-in .28s ease-out;}
724
+ .dshm-welcome-inner{position:relative;width:min(540px,calc(100% - 48px));padding:32px 0;text-align:center;}
725
+ .dshm-welcome-preview .dshm-wclose{position:absolute;right:0;top:6px;appearance:none;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);width:28px;height:28px;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;}
726
+ .dshm-welcome-preview .dshm-wclose:hover{background:var(--dsw-alias-interactive-bg-hover);}
727
+ .dshm-welcome-hero{position:relative;}
728
+ .dshm-welcome-glow{position:absolute;left:50%;top:0;width:330px;height:300px;transform:translateX(-50%);border-radius:50%;background:radial-gradient(circle,var(--dsw-alias-brand-primary),transparent 70%);opacity:.16;filter:blur(18px);pointer-events:none;}
729
+ .dshm-welcome-fish{position:relative;display:flex;justify-content:center;animation:dshm-float 4.5s ease-in-out infinite;}
730
+ .dshm-welcome-title{font-size:26px;font-weight:700;margin:12px 0 6px;letter-spacing:-.2px;}
731
+ .dshm-welcome-sub{color:var(--dsw-alias-label-secondary);font-size:13px;line-height:1.65;max-width:430px;margin:0 auto;}
732
+ .dshm-welcome-actions{display:flex;gap:10px;justify-content:center;margin-top:22px;flex-wrap:wrap;}
733
+ .dshm-wbtn{appearance:none;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;padding:9px 18px;border-radius:10px;cursor:pointer;display:inline-flex;align-items:center;gap:7px;transition:background .15s,border-color .15s,transform .15s;}
734
+ .dshm-wbtn:hover{background:var(--dsw-alias-interactive-bg-hover);}
735
+ .dshm-wbtn:active{transform:translateY(1px);}
736
+ .dshm-wbtn:disabled{opacity:.55;cursor:not-allowed;}
737
+ .dshm-wbtn-primary{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);border-color:transparent;}
738
+ .dshm-wbtn-primary:hover{background:var(--dsw-alias-button-primary-hover);}
739
+ .dshm-welcome-points{display:flex;flex-direction:column;gap:7px;margin:26px auto 0;width:fit-content;text-align:left;}
740
+ .dshm-wpoint{display:flex;align-items:center;gap:7px;color:var(--dsw-alias-label-secondary);font-size:12px;}
741
+ .dshm-welcome-panel{width:100%;}
742
+ .dshm-wstep-title{font-size:18px;font-weight:650;margin:0 0 6px;}
743
+ .dshm-wstep-sub{color:var(--dsw-alias-label-secondary);font-size:12.5px;line-height:1.6;margin:0 auto 18px;max-width:440px;}
744
+ .dshm-wgroup{margin:0 0 16px;text-align:left;}
745
+ .dshm-wlabel{font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary);margin-bottom:8px;}
746
+ .dshm-wchips{display:flex;flex-wrap:wrap;gap:7px;}
747
+ .dshm-wchip{appearance:none;font:inherit;font-size:12px;padding:6px 13px;border-radius:999px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);cursor:pointer;transition:background .15s,border-color .15s,color .15s;}
748
+ .dshm-wchip:hover{background:var(--dsw-alias-interactive-bg-hover);}
749
+ .dshm-wchip-on{background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-primary-inverted);border-color:transparent;}
750
+ .dshm-wcards{display:flex;flex-direction:column;gap:10px;text-align:left;}
751
+ .dshm-wcard{appearance:none;font:inherit;display:flex;gap:12px;align-items:flex-start;padding:14px;border-radius:12px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);cursor:pointer;text-align:left;transition:background .15s,border-color .15s,box-shadow .15s;}
752
+ .dshm-wcard:hover{background:var(--dsw-alias-interactive-bg-hover);}
753
+ .dshm-wcard-on{border-color:var(--dsw-alias-brand-primary);box-shadow:0 0 0 1px var(--dsw-alias-brand-primary) inset;}
754
+ .dshm-wcard-icon{flex:none;width:34px;height:34px;border-radius:9px;display:flex;align-items:center;justify-content:center;background:var(--dsw-alias-bg-layer-2);}
755
+ .dshm-wcard-text{display:flex;flex-direction:column;gap:3px;}
756
+ .dshm-wcard-title{font-size:13px;font-weight:600;}
757
+ .dshm-wcard-body{font-size:12px;color:var(--dsw-alias-label-secondary);line-height:1.5;}
758
+ .dshm-whint{font-size:11.5px;color:var(--dsw-alias-label-secondary);margin:12px 0 0;line-height:1.55;}
759
+ .dshm-wpath{text-align:left;margin-top:14px;}
760
+ .dshm-winput{width:100%;box-sizing:border-box;font:inherit;font-size:12.5px;padding:9px 11px;border-radius:9px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);outline:none;transition:border-color .15s;}
761
+ .dshm-winput:focus{border-color:var(--dsw-alias-brand-primary);}
762
+ .dshm-winput::placeholder{color:var(--dsw-alias-label-tertiary);}
763
+ .dshm-whint-err{color:var(--dsw-alias-state-error-primary);}
764
+ .dshm-wdots{display:flex;gap:6px;justify-content:center;margin-top:22px;}
765
+ .dshm-wdot{width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-border-l2);transition:all .2s;}
766
+ .dshm-wdot-on{background:var(--dsw-alias-brand-primary);width:18px;border-radius:3px;}
767
+ .dshm-wprogress{display:flex;align-items:center;gap:10px;margin:4px 0 14px;}
768
+ .dshm-wprogress-track{flex:1;height:6px;border-radius:99px;background:var(--dsw-alias-bg-layer-2);overflow:hidden;}
769
+ .dshm-wprogress-fill{height:100%;border-radius:99px;background:var(--dsw-alias-brand-primary);transition:width .3s;}
770
+ .dshm-wtracks{text-align:left;display:flex;flex-direction:column;gap:5px;margin-bottom:16px;}
771
+ .dshm-wtrack{display:flex;align-items:center;gap:8px;font-size:11.5px;color:var(--dsw-alias-label-secondary);}
772
+ .dshm-wtrack-lic{margin-left:auto;font-size:10.5px;color:var(--dsw-alias-label-tertiary);flex:none;}
773
+ @keyframes dshm-float{0%,100%{transform:translateY(0);}50%{transform:translateY(-7px);}}
774
+ @keyframes dshm-fade-in{from{opacity:0;transform:translateY(6px);}to{opacity:1;transform:none;}}
775
+ .dshm-panel *{box-sizing:border-box;}
776
+ .dshm-header{flex:none;padding:14px 20px 0;border-bottom:1px solid var(--dsw-alias-border-l1);}
777
+ .dshm-title-row{display:flex;align-items:center;gap:10px;margin-bottom:14px;}
778
+ .dshm-title{font-size:17px;font-weight:650;margin:0;letter-spacing:.2px;}
779
+ .dshm-count{color:var(--dsw-alias-label-tertiary);font-size:12px;}
780
+ .dshm-header-actions{margin-left:auto;display:flex;gap:8px;align-items:center;}
781
+ .dshm-tabs{display:flex;gap:4px;}
782
+ .dshm-tab{position:relative;appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:13px;padding:8px 12px 10px;cursor:pointer;border-radius:8px 8px 0 0;display:inline-flex;align-items:center;gap:6px;transition:color .15s;}
783
+ .dshm-tab:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover);}
784
+ .dshm-tab[aria-selected="true"]{color:var(--dsw-alias-brand-text);font-weight:600;}
785
+ .dshm-tab[aria-selected="true"]::after{content:"";position:absolute;left:10px;right:10px;bottom:-1px;height:2px;border-radius:2px;background:var(--dsw-alias-brand-primary);}
786
+ .dshm-tab-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-brand-primary);animation:dshm-pulse 1.6s ease-in-out infinite;}
787
+ .dshm-body{flex:1;min-height:0;display:flex;flex-direction:column;container-type:inline-size;}
788
+ .dshm-toolbar{flex:none;display:flex;align-items:center;gap:8px;padding:10px 20px;border-bottom:1px solid var(--dsw-alias-border-l1);flex-wrap:wrap;width:100%;max-width:1120px;margin:0 auto;}
789
+ .dshm-search{display:flex;align-items:center;gap:8px;flex:1;min-width:180px;max-width:340px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:9px;padding:6px 10px;color:var(--dsw-alias-label-tertiary);transition:border-color .15s;}
790
+ .dshm-search:focus-within{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-secondary);}
791
+ .dshm-search input{flex:1;min-width:0;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;outline:none;}
792
+ .dshm-search input::placeholder{color:var(--dsw-alias-label-tertiary);}
793
+ .dshm-select{appearance:none;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;border-radius:9px;padding:6px 26px 6px 10px;cursor:pointer;outline:none;background-image:linear-gradient(45deg,transparent 50%,currentColor 50%),linear-gradient(135deg,currentColor 50%,transparent 50%);background-position:calc(100% - 14px) 55%,calc(100% - 9px) 55%;background-size:5px 5px;background-repeat:no-repeat;}
794
+ .dshm-select:focus-visible{border-color:var(--dsw-alias-brand-primary);}
795
+ .dshm-chipbtn{display:inline-flex;align-items:center;gap:6px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;border-radius:9px;padding:6px 12px;cursor:pointer;transition:background .15s,color .15s,border-color .15s,transform .1s;}
796
+ .dshm-chipbtn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary);}
797
+ .dshm-chipbtn:active:not(:disabled){transform:scale(.97);}
798
+ .dshm-chipbtn:disabled{opacity:.5;cursor:default;}
799
+ .dshm-chipbtn-primary{background:var(--dsw-alias-button-primary-fill);border-color:transparent;color:var(--dsw-alias-label-primary-inverted);}
800
+ .dshm-chipbtn-primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover);color:var(--dsw-alias-label-primary-inverted);}
801
+ .dshm-list{flex:1;min-height:0;overflow-y:auto;padding:6px 16px 20px;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-bg-l2) transparent;width:100%;max-width:1120px;margin:0 auto;}
802
+ .dshm-list::-webkit-scrollbar{width:10px;}
803
+ .dshm-list::-webkit-scrollbar-track{background:transparent;}
804
+ .dshm-list::-webkit-scrollbar-thumb{background:var(--dsw-alias-scrollbar-bg-l2);border-radius:6px;border:2px solid var(--dsw-alias-bg-base);}
805
+ .dshm-list::-webkit-scrollbar-thumb:hover{background:var(--dsw-alias-scrollbar-hover-l2);}
806
+ .dshm-group-head{position:sticky;top:0;z-index:1;display:flex;align-items:center;gap:6px;padding:10px 8px 6px;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;}
807
+ .dshm-group-head .dshm-group-count{color:var(--dsw-alias-label-tertiary);font-weight:400;}
808
+ .dshm-row{display:grid;grid-template-columns:40px minmax(0,1fr) auto auto auto 26px;align-items:center;gap:12px;padding:7px 8px;border-radius:10px;cursor:pointer;transition:background .12s;outline:none;}
809
+ .dshm-row-actions{display:flex;gap:2px;opacity:0;}
810
+ .dshm-row:hover .dshm-row-actions,.dshm-row:focus-within .dshm-row-actions{opacity:1;}
811
+ .dshm-row:hover{background:var(--dsw-alias-interactive-bg-hover);}
812
+ .dshm-row:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-brand-primary);}
813
+ .dshm-row-current{background:var(--dsw-alias-interactive-bg-active);}
814
+ .dshm-row-current .dshm-row-title{color:var(--dsw-alias-brand-text);}
815
+ .dshm-row-info{min-width:0;}
816
+ .dshm-row-title{display:flex;align-items:center;gap:7px;font-size:13px;font-weight:520;color:var(--dsw-alias-label-primary);}
817
+ .dshm-row-sub{font-size:11.5px;color:var(--dsw-alias-label-tertiary);margin-top:2px;}
818
+ .dshm-row-dur{font-size:11.5px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;}
819
+ .dshm-row-play{display:flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-secondary);opacity:0;transition:opacity .12s;}
820
+ .dshm-row:hover .dshm-row-play,.dshm-row:focus-visible .dshm-row-play{opacity:1;}
821
+ .dshm-row-current .dshm-row-play{opacity:0;}
822
+ .dshm-ellipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;}
823
+ .dshm-cover{flex:none;position:relative;border-radius:8px;overflow:hidden;background:linear-gradient(145deg,var(--dsw-alias-bg-layer-2),var(--dsw-alias-bg-layer-3));display:flex;align-items:center;justify-content:center;border:1px solid var(--dsw-alias-border-l1);}
824
+ .dshm-cover img{width:100%;height:100%;object-fit:cover;display:block;}
825
+ .dshm-cover-fallback{color:var(--dsw-alias-label-tertiary);display:flex;}
826
+ .dshm-eq{display:inline-flex;align-items:flex-end;gap:2px;height:12px;flex:none;}
827
+ .dshm-eq i{width:3px;border-radius:1.5px;background:var(--dsw-alias-brand-primary);height:30%;}
828
+ .dshm-eq-on i{animation:dshm-eq 1s ease-in-out infinite;}
829
+ .dshm-eq-on i:nth-child(2){animation-delay:.25s;}
830
+ .dshm-eq-on i:nth-child(3){animation-delay:.5s;}
831
+ @keyframes dshm-eq{0%,100%{height:25%;}50%{height:100%;}}
832
+ @keyframes dshm-pulse{0%,100%{opacity:1;}50%{opacity:.35;}}
833
+ .dshm-iconbtn{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-secondary);width:32px;height:32px;border-radius:8px;display:inline-flex;align-items:center;justify-content:center;cursor:pointer;transition:background .13s,color .13s,transform .1s;flex:none;padding:0;}
834
+ .dshm-iconbtn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary);}
835
+ .dshm-iconbtn:active:not(:disabled){transform:scale(.92);}
836
+ .dshm-iconbtn:disabled{opacity:.4;cursor:default;}
837
+ .dshm-iconbtn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px;}
838
+ .dshm-iconbtn-active{color:var(--dsw-alias-brand-text);}
839
+ .dshm-iconbtn-active:hover:not(:disabled){color:var(--dsw-alias-brand-text);}
840
+ .dshm-spin{animation:dshm-spin 1s linear infinite;}
841
+ @keyframes dshm-spin{to{transform:rotate(360deg);}}
842
+ .dshm-state{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:40px 24px;text-align:center;color:var(--dsw-alias-label-secondary);min-height:0;}
843
+ .dshm-state-icon{color:var(--dsw-alias-label-tertiary);width:64px;height:64px;border-radius:18px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);display:flex;align-items:center;justify-content:center;margin-bottom:4px;}
844
+ .dshm-state-title{font-size:14px;font-weight:600;color:var(--dsw-alias-label-primary);}
845
+ .dshm-empty-ctas{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;margin-top:12px;}
846
+ .dshm-empty-dirs{display:flex;flex-direction:column;gap:4px;align-items:flex-start;text-align:left;max-width:440px;margin:14px auto 0;padding:12px 14px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:10px;font-size:12px;color:var(--dsw-alias-label-secondary);}
847
+ .dshm-empty-dirs-head{line-height:1.5;}
848
+ .dshm-empty-dir{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:5px;padding:1px 6px;}
849
+ .dshm-chipbtn-off{opacity:.55;}
850
+ .dshm-state-body{font-size:12.5px;line-height:1.7;max-width:420px;color:var(--dsw-alias-label-tertiary);}
851
+ .dshm-state-error{color:var(--dsw-alias-state-error-primary);}
852
+ .dshm-skel{padding:8px 16px;}
853
+ .dshm-skel-row{display:flex;gap:12px;align-items:center;padding:8px;}
854
+ .dshm-skel-box{border-radius:8px;background:var(--dsw-alias-bg-skeleton);animation:dshm-pulse 1.4s ease-in-out infinite;}
855
+ .dshm-now{flex:1;min-height:0;overflow-y:auto;padding:18px 20px;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-bg-l2) transparent;width:100%;max-width:980px;margin:0 auto;}
856
+ .dshm-now::-webkit-scrollbar{width:10px;}
857
+ .dshm-now::-webkit-scrollbar-thumb{background:var(--dsw-alias-scrollbar-bg-l2);border-radius:6px;border:2px solid var(--dsw-alias-bg-base);}
858
+ .dshm-now-hero{display:grid;grid-template-columns:240px minmax(0,1fr);gap:28px;align-items:center;max-width:860px;margin:0 auto;}
859
+ .dshm-now-cover{width:240px;height:240px;border-radius:16px;box-shadow:0 12px 32px var(--dsw-alias-bg-mask-2);}
860
+ .dshm-now-meta{min-width:0;display:flex;flex-direction:column;gap:10px;}
861
+ .dshm-now-title{font-size:20px;font-weight:680;margin:0;line-height:1.3;}
862
+ .dshm-now-sub{font-size:13px;color:var(--dsw-alias-label-secondary);margin:0;}
863
+ .dshm-source-chip{display:inline-flex;align-items:center;gap:5px;align-self:flex-start;font-size:11px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);padding:3px 9px;border-radius:99px;}
864
+ .dshm-seekrow{display:flex;align-items:center;gap:10px;margin-top:6px;}
865
+ .dshm-time{font-size:11px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;min-width:38px;}
866
+ .dshm-time-end{text-align:right;}
867
+ .dshm-slider{position:relative;flex:1;height:20px;display:flex;align-items:center;cursor:pointer;touch-action:none;outline:none;min-width:40px;}
868
+ .dshm-slider-track{position:relative;width:100%;height:4px;border-radius:2px;background:var(--dsw-alias-bg-layer-3);overflow:visible;}
869
+ .dshm-slider-fill{position:absolute;left:0;top:0;bottom:0;border-radius:2px;background:var(--dsw-alias-brand-primary);}
870
+ .dshm-slider-thumb{position:absolute;top:50%;width:12px;height:12px;border-radius:50%;background:var(--dsw-alias-brand-primary);transform:translate(-50%,-50%) scale(0);transition:transform .12s;box-shadow:0 1px 4px var(--dsw-alias-bg-mask-2);}
871
+ .dshm-slider:hover .dshm-slider-thumb,.dshm-slider:focus-visible .dshm-slider-thumb,.dshm-slider-drag .dshm-slider-thumb{transform:translate(-50%,-50%) scale(1);}
872
+ .dshm-slider:focus-visible .dshm-slider-track{box-shadow:0 0 0 2px var(--dsw-alias-brand-primary);}
873
+ .dshm-slider-disabled{opacity:.4;cursor:default;}
874
+ .dshm-transport{display:flex;align-items:center;gap:10px;margin-top:4px;}
875
+ .dshm-playbtn{width:48px;height:48px;border-radius:50%;border:0;background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);display:inline-flex;align-items:center;justify-content:center;cursor:pointer;transition:background .15s,transform .12s;box-shadow:0 4px 14px var(--dsw-alias-bg-mask-2);flex:none;padding:0;}
876
+ .dshm-playbtn:hover{background:var(--dsw-alias-button-primary-hover);transform:scale(1.05);}
877
+ .dshm-playbtn:active{transform:scale(.96);}
878
+ .dshm-playbtn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px;}
879
+ .dshm-volumerow{display:flex;align-items:center;gap:8px;max-width:240px;}
880
+ .dshm-volumerow .dshm-slider{flex:1;}
881
+ .dshm-volume-pct{font-size:11px;color:var(--dsw-alias-label-tertiary);min-width:32px;font-variant-numeric:tabular-nums;}
882
+ .dshm-errorline{display:flex;align-items:center;gap:7px;color:var(--dsw-alias-state-error-primary);font-size:12px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:9px;padding:8px 12px;}
883
+ .dshm-queue{max-width:860px;margin:28px auto 0;}
884
+ .dshm-queue-head{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--dsw-alias-label-secondary);padding:0 8px 8px;border-bottom:1px solid var(--dsw-alias-border-l1);margin-bottom:6px;}
885
+ .dshm-queue-head .dshm-count{font-weight:400;}
886
+ @container (max-width:680px){
887
+ .dshm-now-hero{grid-template-columns:1fr;justify-items:center;text-align:center;gap:18px;}
888
+ .dshm-now-cover{width:190px;height:190px;}
889
+ .dshm-now-meta{align-items:center;width:100%;}
890
+ .dshm-source-chip{align-self:center;}
891
+ .dshm-transport{justify-content:center;}
892
+ .dshm-volumerow{margin:0 auto;}
893
+ }
894
+ .dshm-mini{position:fixed;right:16px;bottom:16px;z-index:2147483000;width:min(380px,calc(100% - 32px));background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l2);border-radius:14px;box-shadow:0 10px 30px var(--dsw-alias-bg-mask-2);overflow:hidden;animation:dshm-mini-in .22s ease-out;}
895
+ .dshm-mini-fab{position:fixed;right:16px;bottom:16px;z-index:2147483000;width:48px;height:48px;border-radius:50%;padding:0;overflow:hidden;display:flex;align-items:center;justify-content:center;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l2);box-shadow:0 10px 30px var(--dsw-alias-bg-mask-2);cursor:grab;touch-action:none;animation:dshm-mini-in .18s ease-out;}
896
+ .dshm-mini-fab:hover{box-shadow:0 12px 34px var(--dsw-alias-bg-mask-2);}
897
+ .dshm-mini-fab:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px;}
898
+ .dshm-mini-fab-dragging{cursor:grabbing;animation:none;box-shadow:0 16px 40px var(--dsw-alias-bg-mask-2);}
899
+ .dshm-mini-fab-badge{position:absolute;right:1px;bottom:1px;width:19px;height:19px;border-radius:50%;display:flex;align-items:center;justify-content:center;background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);border:2px solid var(--dsw-alias-bg-layer-1);pointer-events:none;}
900
+ .dshm-mini-dragging{box-shadow:0 16px 40px var(--dsw-alias-bg-mask-2);transition:none;animation:none;}
901
+ @keyframes dshm-mini-in{from{opacity:0;transform:translateY(10px);}to{opacity:1;transform:none;}}
902
+ .dshm-mini-inner{display:flex;align-items:center;gap:6px;padding:8px 10px 8px 20px;}
903
+ .dshm-mini-main{display:flex;align-items:center;gap:10px;flex:1;min-width:0;border:0;background:transparent;color:inherit;font:inherit;cursor:pointer;padding:2px;border-radius:9px;text-align:left;}
904
+ .dshm-mini-main:hover{background:var(--dsw-alias-interactive-bg-hover);}
905
+ .dshm-mini-main:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px;}
906
+ .dshm-mini-text{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1;}
907
+ .dshm-mini-title{font-size:12.5px;font-weight:600;color:var(--dsw-alias-label-primary);}
908
+ .dshm-mini-sub{font-size:11px;color:var(--dsw-alias-label-tertiary);}
909
+ .dshm-mini-sub-error{color:var(--dsw-alias-state-error-primary);}
910
+ .dshm-mini-grip{position:absolute;left:3px;top:50%;transform:translateY(-50%);width:14px;height:44px;display:flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary);cursor:grab;border-radius:6px;touch-action:none;opacity:.6;}
911
+ .dshm-mini-grip:hover,.dshm-mini-grip:focus-visible{opacity:1;background:var(--dsw-alias-interactive-bg-hover);outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px;}
912
+ .dshm-mini-grip:active{cursor:grabbing;}
913
+ .dshm-mini-artist{display:inline-flex;align-items:center;gap:4px;max-width:100%;border:0;background:transparent;padding:0;margin:0;font:inherit;font-size:11px;line-height:14px;color:var(--dsw-alias-label-tertiary);cursor:pointer;text-align:left;border-radius:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
914
+ .dshm-mini-artist:hover{color:var(--dsw-alias-brand-text);text-decoration:underline;}
915
+ .dshm-mini-artist:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px;}
916
+ .dshm-mini-seek{padding:0 12px 0 20px;}
917
+ .dshm-mini-seek .dshm-slider{height:16px;}
918
+ .dshm-mini-lyrics{display:flex;flex-direction:column;gap:1px;padding:2px 14px 8px 20px;overflow:hidden;}
919
+ .dshm-mini-lyric{font-size:11.5px;line-height:16px;color:var(--dsw-alias-label-tertiary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;opacity:.5;transition:opacity .25s ease,color .25s ease;}
920
+ .dshm-mini-lyric-on{color:var(--dsw-alias-label-primary);opacity:1;font-weight:600;}
921
+ .dshm-mode-cycle{min-width:32px;}
922
+ .dshm-chipbtn.dshm-mode-cycle{padding:0 9px;}
923
+ .dshm-mini-controls{display:flex;align-items:center;gap:2px;flex:none;}
924
+ .dshm-mini-play{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);border-radius:50%;width:34px;height:34px;}
925
+ .dshm-mini-play:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover);color:var(--dsw-alias-label-primary-inverted);}
926
+ .dshm-reco{max-width:560px;margin:0 auto;}
927
+ .dshm-reco-tags{display:flex;gap:8px;justify-content:center;flex-wrap:wrap;margin-top:6px;}
928
+ .dshm-reco-tag{font-size:11px;color:var(--dsw-alias-label-secondary);border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);border-radius:99px;padding:4px 10px;}
929
+ .dshm-reco-page{flex:1;min-height:0;overflow-y:auto;padding:12px 20px;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-bg-l2) transparent;width:100%;max-width:1280px;margin:0 auto;}
930
+ .dshm-reco-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:12px;margin-top:14px;}
931
+ .dshm-reco-card{background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:12px;padding:14px 16px;display:flex;flex-direction:column;gap:8px;transition:border-color .15s,box-shadow .15s;}
932
+ .dshm-reco-card:hover{border-color:var(--dsw-alias-border-l3);box-shadow:0 2px 10px var(--dsw-alias-bg-mask-2);}
933
+ .dshm-reco-card-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap;}
934
+ .dshm-cat-chip{font-size:11px;padding:2px 9px;border-radius:99px;border:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);}
935
+ .dshm-cat-explore{color:var(--dsw-alias-brand-text);border-color:var(--dsw-alias-brand-primary);}
936
+ .dshm-axis-chip{font-size:11px;padding:2px 9px;border-radius:99px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-tertiary);}
937
+ .dshm-reco-title{font-size:13.5px;font-weight:600;color:var(--dsw-alias-label-primary);}
938
+ .dshm-reco-sub{font-size:11.5px;color:var(--dsw-alias-label-tertiary);}
939
+ .dshm-reco-reason{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary);}
940
+ .dshm-reco-foot{margin-top:auto;display:flex;align-items:center;gap:8px;padding-top:4px;}
941
+ .dshm-dl{background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:12px;padding:12px 14px;display:flex;flex-direction:column;gap:6px;}
942
+ .dshm-dl-row{display:flex;align-items:center;gap:8px;font-size:12.5px;min-width:0;}
943
+ .dshm-dl-dot{width:8px;height:8px;border-radius:50%;background:var(--dsw-alias-label-tertiary);flex:none;}
944
+ .dshm-dl-ok{background:var(--dsw-alias-state-success-primary);}
945
+ .dshm-dl-fail{background:var(--dsw-alias-state-error-primary);}
946
+ .dshm-dl-status{font-size:11px;color:var(--dsw-alias-label-tertiary);flex:none;}
947
+ .dshm-dl-bar{height:3px;border-radius:2px;background:var(--dsw-alias-bg-layer-3);overflow:hidden;margin:2px 0 4px;}
948
+ .dshm-dl-bar>div{height:100%;background:var(--dsw-alias-brand-primary);transition:width .4s ease;}
949
+ .dshm-sync{margin:12px 24px 0;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:12px;padding:12px 16px;display:flex;flex-direction:column;gap:10px;}
950
+ .dshm-sync-chips{display:flex;gap:8px;flex-wrap:wrap;}
951
+ .dshm-sync-chip{font-size:11.5px;border:1px solid var(--dsw-alias-border-l1);border-radius:99px;padding:4px 12px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-2);}
952
+ .dshm-sync-detail{font-size:11.5px;color:var(--dsw-alias-label-tertiary);line-height:1.7;}
953
+ .dshm-hrow{display:grid;grid-template-columns:40px minmax(0,1fr) auto auto auto;gap:10px;align-items:center;padding:6px 8px;border-radius:10px;}
954
+ .dshm-hrow-click{cursor:pointer;}
955
+ .dshm-hrow-click:hover{background:var(--dsw-alias-interactive-bg-hover);}
956
+ .dshm-hrow-click:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px;}
957
+ .dshm-row-sub-btn{appearance:none;background:none;border:0;padding:0;margin:0;cursor:pointer;text-align:left;font-family:inherit;font-size:12px;color:var(--dsw-alias-label-tertiary);max-width:100%;overflow:hidden;display:inline-flex;align-items:center;gap:4px;vertical-align:middle;}
958
+ .dshm-row-sub-btn:hover{color:var(--dsw-alias-brand-text);text-decoration:underline;text-underline-offset:3px;}
959
+ .dshm-hrow:hover{background:var(--dsw-alias-interactive-bg-hover);}
960
+ .dshm-hbar{height:4px;border-radius:2px;background:var(--dsw-alias-bg-layer-3);overflow:hidden;}
961
+ .dshm-hbar>div{height:100%;background:var(--dsw-alias-brand-primary);}
962
+ .dshm-hskip{font-size:10.5px;color:var(--dsw-alias-label-tertiary);border:1px solid var(--dsw-alias-border-l2);border-radius:99px;padding:1px 8px;flex:none;}
963
+ .dshm-htime{font-size:11px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;}
964
+ .dshm-hlist{max-width:960px;margin:0 auto;padding:10px 8px 20px;}
965
+ .dshm-explore-chip{flex:none;font-size:11px;font-weight:600;padding:1px 6px;border-radius:99px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);border:1px solid var(--dsw-alias-border-l1);}
966
+ .dshm-explore-note{display:flex;align-items:flex-start;gap:7px;margin:10px 18px 0;padding:8px 11px;border-radius:9px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.5;}
967
+ .dshm-columns{flex:1;min-height:0;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:0;}
968
+ .dshm-column{min-height:0;display:flex;flex-direction:column;border-right:1px solid var(--dsw-alias-border-l1);}
969
+ .dshm-column:last-child{border-right:0;}
970
+ .dshm-col-head{flex:none;display:flex;align-items:center;gap:8px;padding:12px 14px 8px;}
971
+ .dshm-col-title{font-size:13.5px;font-weight:680;color:var(--dsw-alias-label-primary);display:flex;align-items:center;gap:6px;}
972
+ .dshm-col-count{font-size:11px;color:var(--dsw-alias-label-tertiary);}
973
+ .dshm-col-play{margin-left:auto;}
974
+ .dshm-col-list{flex:1;min-height:0;overflow-y:auto;padding:2px 8px 16px;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-bg-l2) transparent;}
975
+ .dshm-srow{display:grid;grid-template-columns:38px minmax(0,1fr) auto auto;align-items:center;gap:10px;padding:6px;border-radius:10px;transition:background .12s;}
976
+ .dshm-srow:hover{background:var(--dsw-alias-interactive-bg-hover);}
977
+ .dshm-srow-main{min-width:0;display:flex;flex-direction:column;gap:1px;border:0;background:transparent;font:inherit;color:inherit;text-align:left;padding:0;cursor:pointer;}
978
+ .dshm-srow-title{font-size:12.5px;font-weight:560;color:var(--dsw-alias-label-primary);}
979
+ .dshm-srow-sub{font-size:11px;color:var(--dsw-alias-label-tertiary);}
980
+ .dshm-srow-artist{appearance:none;background:none;border:0;padding:0;margin:0;font:inherit;color:inherit;cursor:pointer;border-radius:4px;}
981
+ .dshm-srow-artist:hover{color:var(--dsw-alias-brand-text);text-decoration:underline;text-underline-offset:3px;}
982
+ .dshm-srow-artist:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px;}
983
+ .dshm-srow-reason{font-size:10.5px;color:var(--dsw-alias-label-tertiary);line-height:1.5;margin-top:2px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;}
984
+ .dshm-like-btn{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-tertiary);width:30px;height:30px;border-radius:8px;display:inline-flex;align-items:center;justify-content:center;cursor:pointer;padding:0;flex:none;transition:transform .12s,color .12s;}
985
+ .dshm-like-btn:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover);}
986
+ .dshm-like-btn:active{transform:scale(1.18);}
987
+ .dshm-like-btn-on{color:var(--dsw-alias-state-error-primary);}
988
+ .dshm-playround{appearance:none;border:0;width:30px;height:30px;border-radius:50%;background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);display:inline-flex;align-items:center;justify-content:center;cursor:pointer;padding:0;flex:none;transition:background .13s,transform .1s;}
989
+ .dshm-playround:hover{background:var(--dsw-alias-button-primary-hover);transform:scale(1.06);}
990
+ .dshm-playround:disabled{opacity:.45;cursor:default;transform:none;}
991
+ .dshm-tile{border-radius:8px;overflow:hidden;background:linear-gradient(145deg,var(--dsw-alias-bg-layer-2),var(--dsw-alias-bg-layer-3));border:1px solid var(--dsw-alias-border-l1);display:flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary);flex:none;}
992
+ .dshm-tile img{width:100%;height:100%;object-fit:cover;display:block;}
993
+ .dshm-arow{display:grid;grid-template-columns:44px minmax(0,1fr) 18px;align-items:center;gap:10px;width:100%;padding:6px;border:0;background:transparent;font:inherit;color:inherit;text-align:left;border-radius:10px;cursor:pointer;transition:background .12s;}
994
+ .dshm-arow:hover{background:var(--dsw-alias-interactive-bg-hover);}
995
+ .dshm-arow-text{display:flex;flex-direction:column;gap:1px;min-width:0;}
996
+ .dshm-arow-arrow{color:var(--dsw-alias-label-tertiary);font-size:16px;line-height:1;}
997
+ .dshm-apage-banner{position:relative;height:132px;border-radius:16px;overflow:hidden;background:linear-gradient(135deg,var(--dsw-alias-bg-layer-2),var(--dsw-alias-bg-module-platform));margin-bottom:-38px;display:flex;align-items:center;justify-content:flex-end;padding:0 14px;color:var(--dsw-alias-label-tertiary);}
998
+ .dshm-apage-banner img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;opacity:.85;}
999
+ .dshm-apage-banner-mask{position:absolute;inset:0;background:linear-gradient(180deg,transparent 30%,var(--dsw-alias-bg-base));}
1000
+ .dshm-apage-hero{position:relative;display:flex;align-items:flex-end;gap:16px;margin-bottom:16px;padding:0 8px;}
1001
+ .dshm-apage-ava-wrap{width:96px;height:96px;border-radius:50%;border:2px solid var(--dsw-alias-bg-base);box-shadow:0 6px 18px var(--dsw-alias-bg-mask-2);overflow:hidden;flex:none;background:var(--dsw-alias-bg-module-platform);}
1002
+ .dshm-apage-ava-wrap .dshm-tile{width:100%!important;height:100%!important;border:0;border-radius:0;}
1003
+ .dshm-agrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(96px,1fr));gap:10px;padding:4px 6px;}
1004
+ .dshm-artcard{appearance:none;border:0;background:transparent;font:inherit;color:inherit;display:flex;flex-direction:column;align-items:center;gap:7px;padding:10px 6px;border-radius:12px;cursor:pointer;transition:background .13s;}
1005
+ .dshm-artcard:hover{background:var(--dsw-alias-interactive-bg-hover);}
1006
+ .dshm-artcard:hover .dshm-artava{box-shadow:0 4px 14px var(--dsw-alias-bg-mask-2);}
1007
+ .dshm-artava{width:62px;height:62px;border-radius:50%;background:var(--dsw-alias-bg-module-platform);border:1px solid var(--dsw-alias-border-l2);display:flex;align-items:center;justify-content:center;font-size:22px;font-weight:700;color:var(--dsw-alias-label-secondary);transition:box-shadow .15s;}
1008
+ .dshm-artname{font-size:12px;font-weight:600;text-align:center;max-width:100%;}
1009
+ .dshm-arthint{font-size:10.5px;color:var(--dsw-alias-label-tertiary);text-align:center;line-height:1.45;}
1010
+ .dshm-mode-group{display:inline-flex;align-items:center;gap:2px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:99px;padding:2px;}
1011
+ .dshm-mode-btn{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-tertiary);width:30px;height:28px;border-radius:99px;display:inline-flex;align-items:center;justify-content:center;cursor:pointer;padding:0;}
1012
+ .dshm-mode-btn:hover{color:var(--dsw-alias-label-primary);}
1013
+ .dshm-mode-btn-on{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);}
1014
+ .dshm-mode-btn-on:hover{color:var(--dsw-alias-label-primary-inverted);}
1015
+ .dshm-mode-hint{font-size:11px;color:var(--dsw-alias-label-tertiary);margin-top:6px;}
1016
+ .dshm-apage{flex:1;min-height:0;overflow-y:auto;padding:16px 20px 28px;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-bg-l2) transparent;width:100%;max-width:1120px;margin:0 auto;}
1017
+ .dshm-apage-hero{display:flex;align-items:center;gap:16px;margin-bottom:16px;}
1018
+ .dshm-apage-ava{width:76px;height:76px;border-radius:50%;background:var(--dsw-alias-bg-module-platform);border:1px solid var(--dsw-alias-border-l2);display:flex;align-items:center;justify-content:center;font-size:28px;font-weight:700;color:var(--dsw-alias-label-secondary);flex:none;}
1019
+ .dshm-apage-name{font-size:20px;font-weight:700;margin:0;}
1020
+ @media (max-width:980px){
1021
+ .dshm-columns{grid-template-columns:1fr;}
1022
+ .dshm-toolbar{padding:10px 12px;}
1023
+ .dshm-header{padding:12px 12px 0;}
1024
+ .dshm-reco-page{padding:10px 12px;}
1025
+ .dshm-apage{padding:14px 12px 24px;}
1026
+ .dshm-now{padding:14px 12px;}
1027
+ .dshm-column{border-right:0;border-bottom:1px solid var(--dsw-alias-border-l1);max-height:46vh;}
1028
+ }
1029
+ .dshm-history-page{width:100%;max-width:960px;margin:0 auto;padding:12px 8px 24px;}
1030
+ .dshm-stats-wrap{display:flex;flex-direction:column;gap:12px;margin-bottom:8px;}
1031
+ .dshm-stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(118px,1fr));gap:8px;}
1032
+ .dshm-stat{background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:12px;padding:10px 12px;min-width:0;}
1033
+ .dshm-stat-value{font-size:16px;font-weight:700;color:var(--dsw-alias-label-primary);}
1034
+ .dshm-stat-label{font-size:11px;color:var(--dsw-alias-label-tertiary);margin-top:2px;}
1035
+ .dshm-trend{background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:12px;padding:10px 12px;display:flex;flex-direction:column;gap:6px;}
1036
+ .dshm-bars{display:flex;align-items:flex-end;gap:6px;height:88px;}
1037
+ .dshm-bar-col{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:4px;height:100%;min-width:0;}
1038
+ .dshm-bar{width:100%;max-width:34px;border-radius:6px 6px 2px 2px;background:linear-gradient(180deg,var(--dsw-alias-brand-primary),var(--dsw-alias-bg-layer-3));min-height:3px;}
1039
+ .dshm-bar-label{font-size:10px;color:var(--dsw-alias-label-tertiary);}
1040
+ .dshm-tops{display:grid;grid-template-columns:1fr 1fr;gap:16px;}
1041
+ .dshm-top-col{display:flex;flex-direction:column;gap:2px;min-width:0;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:12px;padding:10px 12px;}
1042
+ .dshm-top-row{display:flex;align-items:center;gap:8px;padding:4px 6px;border-radius:8px;font-size:12px;min-width:0;}
1043
+ .dshm-top-row-click{cursor:pointer;}
1044
+ .dshm-top-row-click:hover{background:var(--dsw-alias-interactive-bg-hover);}
1045
+ .dshm-top-row-click:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px;}
1046
+ .dshm-top-row-artist{appearance:none;border:0;background:transparent;font:inherit;color:inherit;text-align:left;width:100%;cursor:pointer;}
1047
+ .dshm-top-row-artist:hover{background:var(--dsw-alias-interactive-bg-hover);}
1048
+ .dshm-top-row-off{opacity:.55;cursor:not-allowed;}
1049
+ .dshm-top-row-off:hover{background:transparent;}
1050
+ .dshm-top-row:hover{background:var(--dsw-alias-interactive-bg-hover);}
1051
+ .dshm-top-rank{width:18px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;font-size:11px;flex:none;}
1052
+ .dshm-hgroup{margin-top:10px;}
1053
+ .dshm-hgroup-label{position:sticky;top:0;z-index:1;display:flex;align-items:center;gap:8px;padding:6px 8px;background:var(--dsw-alias-bg-base);font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary);}
1054
+ .dshm-hbadge{font-size:10.5px;border-radius:99px;padding:1px 8px;border:1px solid var(--dsw-alias-border-l2);flex:none;font-variant-numeric:tabular-nums;}
1055
+ .dshm-hbadge-good{color:var(--dsw-alias-state-success-primary);border-color:var(--dsw-alias-state-success-primary);}
1056
+ .dshm-hbadge-mid{color:var(--dsw-alias-state-warn-primary);border-color:var(--dsw-alias-state-warn-primary);}
1057
+ .dshm-hbadge-low{color:var(--dsw-alias-label-tertiary);}
1058
+ @media (max-width:680px){
1059
+ .dshm-tops{grid-template-columns:1fr;}
1060
+ .dshm-hrow{grid-template-columns:40px minmax(0,1fr) auto;}
1061
+ .dshm-hskip,.dshm-htime{display:none;}
1062
+ }
1063
+ .dshm-state-spin{animation:dshm-spin 1.4s linear infinite;}
1064
+ .dshm-toolbar-flat{margin:0;padding:8px 0;border-bottom:0;}
1065
+ @media (max-width:560px){
1066
+ .dshm-hrow{grid-template-columns:40px minmax(0,1fr) auto;}
1067
+ .dshm-hbar,.dshm-hskip,.dshm-htime{display:none;}
1068
+ .dshm-sync{margin:12px 12px 0;}
1069
+ .dshm-reco-page{padding:16px 12px;}
1070
+ }
1071
+ .dshm-lyrics{max-width:860px;margin:24px auto 0;display:flex;flex-direction:column;gap:8px;}
1072
+ .dshm-lyrics-head{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--dsw-alias-label-secondary);padding:0 8px;}
1073
+ .dshm-lyrics-scroll{position:relative;max-height:300px;overflow-y:auto;padding:4px 8px;display:flex;flex-direction:column;gap:2px;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-bg-l2) transparent;}
1074
+ .dshm-lyric-line{padding:5px 10px;border-radius:8px;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.6;transition:color .2s,background .2s;}
1075
+ .dshm-lyric-line-past{color:var(--dsw-alias-label-secondary);}
1076
+ .dshm-lyric-line-active{color:var(--dsw-alias-label-primary);font-weight:600;background:var(--dsw-alias-interactive-bg-hover);}
1077
+ .dshm-plain-lyrics{white-space:pre-wrap;color:var(--dsw-alias-label-secondary);line-height:1.8;padding:6px 10px;font-size:13px;}
1078
+ .dshm-lyrics-hint{color:var(--dsw-alias-label-tertiary);font-size:12px;padding:6px 10px;}
1079
+ .dshm-drawer-mask{position:absolute;inset:0;background:var(--dsw-alias-bg-mask-1);z-index:5;}
1080
+ .dshm-drawer{position:absolute;top:0;right:0;bottom:0;width:min(430px,92%);background:var(--dsw-alias-bg-layer-1);border-left:1px solid var(--dsw-alias-border-l2);box-shadow:-12px 0 32px var(--dsw-alias-bg-mask-2);z-index:6;display:flex;flex-direction:column;animation:dshm-drawer-in .2s ease-out;}
1081
+ @keyframes dshm-drawer-in{from{opacity:0;transform:translateX(16px);}to{opacity:1;transform:translateX(0);}}
1082
+ .dshm-drawer-head{flex:none;display:flex;align-items:center;gap:8px;padding:14px 16px;border-bottom:1px solid var(--dsw-alias-border-l1);}
1083
+ .dshm-drawer-name{font-size:15px;font-weight:650;margin:0;min-width:0;}
1084
+ .dshm-drawer-body{flex:1;min-height:0;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:20px;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-bg-l2) transparent;}
1085
+ .dshm-asec{display:flex;flex-direction:column;gap:8px;}
1086
+ .dshm-asec-title{font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary);display:flex;align-items:center;gap:6px;}
1087
+ .dshm-acard{background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:10px;padding:10px 12px;display:flex;flex-direction:column;gap:6px;}
1088
+ .dshm-acard-text{font-size:12.5px;line-height:1.7;color:var(--dsw-alias-label-primary);word-break:break-word;}
1089
+ .dshm-acard-meta{font-size:11px;color:var(--dsw-alias-label-tertiary);display:flex;align-items:center;gap:8px;flex-wrap:wrap;}
1090
+ .dshm-acard-meta a{color:var(--dsw-alias-link);text-decoration:none;}
1091
+ .dshm-acard-meta a:hover{text-decoration:underline;}
1092
+ .dshm-kind-chip{font-size:10px;padding:1px 8px;border-radius:99px;border:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);}
1093
+ .dshm-sim{display:flex;flex-direction:column;gap:6px;}
1094
+ .dshm-sim-chip{display:inline-flex;align-items:center;gap:5px;display:inline-flex;flex-direction:column;align-items:flex-start;gap:2px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);border-radius:10px;padding:7px 12px;font-size:12.5px;color:var(--dsw-alias-label-primary);cursor:pointer;text-align:left;font:inherit;}
1095
+ .dshm-sim-chip:hover{background:var(--dsw-alias-interactive-bg-hover);}
1096
+ .dshm-sim-chip-reason{font-size:11px;color:var(--dsw-alias-label-tertiary);}
1097
+ .dshm-artist-btn{appearance:none;background:none;border:0;color:inherit;font:inherit;padding:0;cursor:pointer;text-align:left;display:inline-flex;align-items:center;gap:5px;max-width:100%;vertical-align:middle;}
1098
+ .dshm-artist-btn:hover{text-decoration:underline;text-underline-offset:3px;}
1099
+ @media (prefers-reduced-motion:reduce){
1100
+ .dshm-eq-on i,.dshm-tab-dot,.dshm-skel-box,.dshm-spin,.dshm-state-spin,.dshm-mini,.dshm-mini-fab,.dshm-drawer,.dshm-welcome,.dshm-welcome-fish{animation:none;}
1101
+ .dshm-mini{animation:none;}
1102
+ .dshm-row,.dshm-iconbtn,.dshm-chipbtn,.dshm-playbtn,.dshm-slider-thumb,.dshm-mini-progress>div,.dshm-reco-card,.dshm-dl-bar>div,.dshm-like-btn,.dshm-playround,.dshm-artcard,.dshm-mode-btn{transition:none;}
1103
+ }
1104
+ `;
1105
+
1106
+ /* ================================================================
1107
+ * 5. Host API (same-origin HTTP, agreed contract with the Host half)
1108
+ * ================================================================ */
1109
+ function createHostApi(t) {
1110
+ /* Taste is a soft bias; unknown values are ignored by the host. */
1111
+ function tasteQuery(taste) {
1112
+ if (!taste || typeof taste !== 'object') return '';
1113
+ const genres = (taste.genres || []).filter(Boolean);
1114
+ const languages = (taste.languages || []).filter(Boolean);
1115
+ const parts = [];
1116
+ if (genres.length) parts.push('genres=' + encodeURIComponent(genres.join(',')));
1117
+ if (languages.length) parts.push('languages=' + encodeURIComponent(languages.join(',')));
1118
+ return parts.length ? '?' + parts.join('&') : '';
1119
+ }
1120
+
1121
+ async function request(path, options) {
1122
+ let res;
1123
+ try {
1124
+ res = await fetch(resolveUrl(path), options);
1125
+ } catch {
1126
+ throw new Error(t('networkError'));
1127
+ }
1128
+ if (!res.ok) {
1129
+ let message = 'HTTP ' + res.status;
1130
+ try {
1131
+ const body = await res.json();
1132
+ if (body && typeof body.error === 'string') message = body.error;
1133
+ } catch { /* non-JSON error body */ }
1134
+ throw new Error(message);
1135
+ }
1136
+ return res.json();
1137
+ }
1138
+ return {
1139
+ library: () => request('/dsh-music/api/library'),
1140
+ rescan: () => request('/dsh-music/api/rescan', { method: 'POST' }),
1141
+ lyrics: (trackId) => request('/dsh-music/api/lyrics?track=' + encodeURIComponent(trackId)),
1142
+ artist: (name) => request('/dsh-music/api/artist?name=' + encodeURIComponent(name)),
1143
+ artistImage: (name) => request('/dsh-music/api/reco/artist-image?name=' + encodeURIComponent(name)),
1144
+ recoSections: (taste) => request('/dsh-music/api/reco/sections' + tasteQuery(taste)),
1145
+ deleteTrack: (trackId, confirm) => request('/dsh-music/api/library/delete', {
1146
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
1147
+ body: JSON.stringify({ trackId, confirm: !!confirm }),
1148
+ }),
1149
+ revealTrack: (trackId) => request('/dsh-music/api/library/reveal', {
1150
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
1151
+ body: JSON.stringify({ trackId }),
1152
+ }),
1153
+ reco: (taste) => request('/dsh-music/api/reco' + tasteQuery(taste)),
1154
+ recoStatus: () => request('/dsh-music/api/reco/status'),
1155
+ download: (items) => request('/dsh-music/api/download', {
1156
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ items }),
1157
+ }),
1158
+ downloadStatus: () => request('/dsh-music/api/download/status'),
1159
+ sync: () => request('/dsh-music/api/sync', { method: 'POST' }),
1160
+ syncStatus: () => request('/dsh-music/api/sync/status'),
1161
+ syncAvailability: () => request('/dsh-music/api/sync/availability'),
1162
+ history: (limit) => request('/dsh-music/api/history?limit=' + (limit || 50)),
1163
+ historyStats: () => request('/dsh-music/api/history/stats'),
1164
+ onboardingState: () => request('/dsh-music/api/onboarding/state'),
1165
+ onboardingComplete: (payload) => request('/dsh-music/api/onboarding/complete', {
1166
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload || {}),
1167
+ }),
1168
+ librarySearch: (q, type) => request('/dsh-music/api/library/search?q=' + encodeURIComponent(q) + '&type=' + (type || 'song')),
1169
+ recoStyle: (q) => request('/dsh-music/api/reco/style?q=' + encodeURIComponent(q)),
1170
+ recoArtist: (name) => request('/dsh-music/api/reco/artist?name=' + encodeURIComponent(name)),
1171
+ playback: (patch) => request('/dsh-music/api/playback', {
1172
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(patch),
1173
+ }),
1174
+ playbackNext: (trackId) => request('/dsh-music/api/playback/next?trackId=' + encodeURIComponent(trackId || '')),
1175
+ like: (body) => request('/dsh-music/api/library/like', {
1176
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
1177
+ }),
1178
+ likes: () => request('/dsh-music/api/library/likes'),
1179
+ preview: (body) => request('/dsh-music/api/library/preview', {
1180
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
1181
+ }),
1182
+ previewStatus: () => request('/dsh-music/api/library/preview/status'),
1183
+ };
1184
+ }
1185
+
1186
+ /* ================================================================
1187
+ * 6. Library store
1188
+ * ================================================================ */
1189
+ function createLibrary(api) {
1190
+ const store = createStore({ status: 'idle', tracks: [], error: null, scannedAt: 0 });
1191
+ let inflight = false;
1192
+ async function load(rescan) {
1193
+ if (inflight) return;
1194
+ inflight = true;
1195
+ store.set({ status: 'loading', error: null });
1196
+ try {
1197
+ const data = rescan ? await api.rescan() : await api.library();
1198
+ const tracks = Array.isArray(data && data.tracks) ? data.tracks : [];
1199
+ store.set({ status: 'ready', tracks, error: null, scannedAt: (data && data.scannedAt) || Date.now() });
1200
+ } catch (err) {
1201
+ store.set({ status: 'error', error: (err && err.message) || String(err) });
1202
+ } finally {
1203
+ inflight = false;
1204
+ }
1205
+ }
1206
+ async function remove(trackId, confirm) {
1207
+ await api.deleteTrack(trackId, confirm);
1208
+ await load(false);
1209
+ }
1210
+ return {
1211
+ source: store,
1212
+ load: () => load(false),
1213
+ rescan: () => load(true),
1214
+ remove,
1215
+ reveal: (trackId) => api.revealTrack(trackId),
1216
+ /* 统一搜索:song+artist 两个口径并行,合并去重并打类型标签。 */
1217
+ searchRemote: async (q) => {
1218
+ const [song, artist] = await Promise.all([
1219
+ api.librarySearch(q, 'song').catch(() => ({ local: [], remote: [] })),
1220
+ api.librarySearch(q, 'artist').catch(() => ({ local: [], remote: [] })),
1221
+ ]);
1222
+ const localMap = new Map();
1223
+ for (const tr of [...((song && song.local) || []), ...((artist && artist.local) || [])]) {
1224
+ if (tr && tr.id && !localMap.has(tr.id)) localMap.set(tr.id, tr);
1225
+ }
1226
+ const remoteMap = new Map();
1227
+ for (const r of (song && song.remote) || []) {
1228
+ const k = 'song::' + normalizeZh(r && r.artist) + '::' + normalizeZh(r && r.title);
1229
+ if (!remoteMap.has(k)) remoteMap.set(k, { ...r, kind: 'song' });
1230
+ }
1231
+ for (const r of (artist && artist.remote) || []) {
1232
+ const k = 'artist::' + normalizeZh(r && (r.name || r.artist));
1233
+ if (!remoteMap.has(k)) remoteMap.set(k, { ...r, kind: 'artist' });
1234
+ }
1235
+ return { local: [...localMap.values()], remote: [...remoteMap.values()] };
1236
+ },
1237
+ };
1238
+ }
1239
+
1240
+ /* ================================================================
1241
+ * 6b. Lyrics + artist services (S2; contract: host/metadata/CONTRACT.md)
1242
+ * ================================================================ */
1243
+ function createLyricsService(api) {
1244
+ const store = createStore({ trackId: null, status: 'idle', data: null, error: null });
1245
+ let inflightFor = null;
1246
+ async function load(trackId) {
1247
+ if (!trackId || inflightFor === trackId) return;
1248
+ /* Mini player + now-playing panel both mount for the same track: keep
1249
+ * the ready/loading result instead of firing a second request. */
1250
+ const cur = store.getSnapshot();
1251
+ if (cur.trackId === trackId && (cur.status === 'ready' || cur.status === 'loading')) return;
1252
+ inflightFor = trackId;
1253
+ store.set({ trackId, status: 'loading', data: null, error: null });
1254
+ try {
1255
+ const data = await api.lyrics(trackId);
1256
+ if (store.getSnapshot().trackId !== trackId) return; // user moved on
1257
+ store.set({ status: 'ready', data });
1258
+ } catch (err) {
1259
+ if (store.getSnapshot().trackId !== trackId) return;
1260
+ store.set({ status: 'error', error: (err && err.message) || String(err) });
1261
+ } finally {
1262
+ if (inflightFor === trackId) inflightFor = null;
1263
+ }
1264
+ }
1265
+ return { source: store, load };
1266
+ }
1267
+
1268
+ function createArtistService(api) {
1269
+ const store = createStore({ name: null, status: 'idle', data: null, error: null });
1270
+ let inflightFor = null;
1271
+ async function load(name) {
1272
+ if (!name || inflightFor === name) return;
1273
+ inflightFor = name;
1274
+ store.set({ name, status: 'loading', data: null, error: null });
1275
+ try {
1276
+ const data = await api.artist(name);
1277
+ if (store.getSnapshot().name !== name) return;
1278
+ store.set({ status: 'ready', data });
1279
+ } catch (err) {
1280
+ if (store.getSnapshot().name !== name) return;
1281
+ store.set({ status: 'error', error: (err && err.message) || String(err) });
1282
+ } finally {
1283
+ if (inflightFor === name) inflightFor = null;
1284
+ }
1285
+ }
1286
+ return { source: store, load };
1287
+ }
1288
+
1289
+ /* Artist portraits (batch 2, v6): one lightweight image lookup per name.
1290
+ * Requests are coalesced in a 150ms window and limited to 3 in flight, so a
1291
+ * page that renders 20 artist rows does not fire 20 parallel lookups.
1292
+ * Results live in an in-memory map (null = looked up, no image). */
1293
+ function createArtistImageService(api) {
1294
+ const store = createStore({ images: {} });
1295
+ const inflight = new Set();
1296
+ const queue = [];
1297
+ let timer = null;
1298
+ let active = 0;
1299
+
1300
+ function keyOf(name) { return normalizeZh(name).trim(); }
1301
+
1302
+ function pump() {
1303
+ while (active < 3 && queue.length) {
1304
+ const name = queue.shift();
1305
+ const key = keyOf(name);
1306
+ if (!key || inflight.has(key) || Object.prototype.hasOwnProperty.call(store.getSnapshot().images, key)) continue;
1307
+ inflight.add(key);
1308
+ active += 1;
1309
+ api.artistImage(name)
1310
+ .then((data) => {
1311
+ const url = (data && (data.thumbnailUrl || data.imageUrl)) || null;
1312
+ store.set({ images: { ...store.getSnapshot().images, [key]: url } });
1313
+ })
1314
+ .catch(() => { store.set({ images: { ...store.getSnapshot().images, [key]: null } }); })
1315
+ .finally(() => {
1316
+ inflight.delete(key);
1317
+ active -= 1;
1318
+ pump();
1319
+ });
1320
+ }
1321
+ }
1322
+
1323
+ function request(name) {
1324
+ const key = keyOf(name);
1325
+ if (!key || inflight.has(key) || Object.prototype.hasOwnProperty.call(store.getSnapshot().images, key)) return;
1326
+ queue.push(name);
1327
+ if (!timer) timer = setTimeout(() => { timer = null; pump(); }, 150);
1328
+ }
1329
+
1330
+ function reset() { queue.length = 0; if (timer) { clearTimeout(timer); timer = null; } }
1331
+
1332
+ return { source: store, request, reset };
1333
+ }
1334
+
1335
+ /* First-run onboarding state (v7): whether the welcome flow was completed,
1336
+ * the starter-library provisioning progress, and the taste profile. */
1337
+ function createOnboardingService(api) {
1338
+ const store = createStore({ status: 'idle', completed: null, mode: null, libraryConfigured: false, libraryPath: null, starter: null, taste: null, error: null });
1339
+ let timer = null;
1340
+ async function load() {
1341
+ try {
1342
+ const data = await api.onboardingState();
1343
+ const starter = (data && (data.starter || data.starterLibrary)) || null;
1344
+ store.set({
1345
+ status: 'ready', completed: !!(data && data.completed),
1346
+ mode: (data && data.mode) || null,
1347
+ libraryConfigured: !!(data && data.libraryConfigured),
1348
+ libraryPath: (data && data.libraryPath) || null,
1349
+ starter, taste: (data && data.taste) || null, error: null,
1350
+ });
1351
+ return data;
1352
+ } catch (err) {
1353
+ store.set({ status: 'error', error: (err && err.message) || String(err) });
1354
+ return null;
1355
+ }
1356
+ }
1357
+ async function complete(payload) {
1358
+ await api.onboardingComplete(payload);
1359
+ writePrefs({
1360
+ taste: (payload && payload.taste) || null,
1361
+ libraryMode: (payload && payload.libraryMode) || null,
1362
+ });
1363
+ store.set({ completed: true, taste: (payload && payload.taste) || null });
1364
+ pollStarter();
1365
+ }
1366
+ function pollStarter() {
1367
+ if (timer) return;
1368
+ const tick = async () => {
1369
+ const data = await load();
1370
+ const st = data && ((data.starter || data.starterLibrary) || null);
1371
+ if (!st || st.status !== 'downloading') { timer = null; return; }
1372
+ timer = setTimeout(tick, 1500);
1373
+ };
1374
+ timer = setTimeout(tick, 800);
1375
+ }
1376
+ function dispose() { if (timer) { clearTimeout(timer); timer = null; } }
1377
+ return { source: store, load, complete, pollStarter, dispose };
1378
+ }
1379
+
1380
+ /* ================================================================
1381
+ * 6c. S3 services: recommendations / downloads / sync / history
1382
+ * ================================================================ */
1383
+ function createRecoService(api) {
1384
+ const store = createStore({ status: 'idle', items: [], sections: null, generatedAt: 0, stats: null, error: null, bootstrapNote: null });
1385
+ let inflight = false;
1386
+ async function pollUntilIdle() {
1387
+ for (;;) {
1388
+ try {
1389
+ const s = await api.recoStatus();
1390
+ if (!s || !s.running) return s || null;
1391
+ } catch { return null; }
1392
+ await new Promise((resolve) => setTimeout(resolve, 2000));
1393
+ }
1394
+ }
1395
+ async function generate() {
1396
+ if (inflight) return;
1397
+ inflight = true;
1398
+ store.set({ status: 'generating', error: null });
1399
+ try {
1400
+ const data = await api.reco(readPrefs().taste || null);
1401
+ store.set({
1402
+ status: 'ready', items: (data && data.items) || [], generatedAt: (data && data.generatedAt) || Date.now(),
1403
+ stats: (data && data.stats) || null,
1404
+ bootstrapNote: data && data.bootstrap ? (data.note || null) : null,
1405
+ });
1406
+ } catch (err) {
1407
+ const msg = (err && err.message) || String(err);
1408
+ // BUSY (409): someone else is generating — follow the status endpoint.
1409
+ if (msg.indexOf('409') >= 0 || msg.indexOf('生成中') >= 0 || msg.indexOf('正在生成') >= 0) {
1410
+ const s = await pollUntilIdle();
1411
+ if (s && s.items && s.items.length) {
1412
+ store.set({ status: 'ready', items: s.items, generatedAt: s.generatedAt || Date.now(), stats: s.stats || null });
1413
+ } else {
1414
+ store.set({ status: 'error', error: msg });
1415
+ }
1416
+ } else {
1417
+ store.set({ status: 'error', error: msg });
1418
+ }
1419
+ } finally {
1420
+ inflight = false;
1421
+ }
1422
+ }
1423
+ async function loadSections() {
1424
+ if (!api.recoSections) return false;
1425
+ try {
1426
+ const data = await api.recoSections(readPrefs().taste || null);
1427
+ if (!data) return false;
1428
+ const sections = {
1429
+ today: data.today || [],
1430
+ artist: data.artist || [],
1431
+ new: data.new || data['new'] || [],
1432
+ };
1433
+ if (!sections.today.length && !sections.artist.length && !sections.new.length) return false;
1434
+ store.set({
1435
+ status: 'ready', sections, items: sections.today, generatedAt: data.generatedAt || Date.now(),
1436
+ error: null, bootstrapNote: data.exploreOnly ? (data.note || null) : null,
1437
+ });
1438
+ return true;
1439
+ } catch { return false; }
1440
+ }
1441
+ async function load() {
1442
+ if (inflight || store.getSnapshot().status === 'generating') return;
1443
+ if (await loadSections()) return;
1444
+ try {
1445
+ const s = await api.recoStatus();
1446
+ if (s && s.running) { generate(); return; }
1447
+ if (s && s.items && s.items.length) {
1448
+ store.set({ status: 'ready', items: s.items, generatedAt: s.generatedAt || Date.now(), stats: s.stats || null });
1449
+ }
1450
+ } catch { /* keep empty CTA; user can still generate */ }
1451
+ }
1452
+ return { source: store, generate, load, searchStyle: (q) => api.recoStyle(q), artistPage: (name) => api.recoArtist(name) };
1453
+ }
1454
+
1455
+ function createDownloadService(api) {
1456
+ const store = createStore({ running: false, total: 0, done: 0, items: [], error: null, finishedAt: 0 });
1457
+ let timer = null;
1458
+ async function refresh() {
1459
+ try {
1460
+ const s = await api.downloadStatus();
1461
+ store.set({ running: !!s.running, total: s.total || 0, done: s.done || 0, items: s.items || [] });
1462
+ return s;
1463
+ } catch { return null; }
1464
+ }
1465
+ function poll() {
1466
+ if (timer) return;
1467
+ const tick = async () => {
1468
+ const s = await refresh();
1469
+ if (s && !s.running) {
1470
+ timer = null;
1471
+ if (s.total > 0) store.set({ finishedAt: Date.now() });
1472
+ return;
1473
+ }
1474
+ timer = setTimeout(tick, 1500);
1475
+ };
1476
+ tick();
1477
+ }
1478
+ async function start(items) {
1479
+ try {
1480
+ await api.download(items);
1481
+ store.set({ error: null, finishedAt: 0 });
1482
+ } catch (err) {
1483
+ store.set({ error: (err && err.message) || String(err) });
1484
+ return false;
1485
+ }
1486
+ poll();
1487
+ return true;
1488
+ }
1489
+ async function warm() { const s = await refresh(); if (s && s.running) poll(); }
1490
+ function dispose() { if (timer) { clearTimeout(timer); timer = null; } }
1491
+ return { source: store, start, warm, dispose };
1492
+ }
1493
+
1494
+ function createSyncService(api) {
1495
+ const store = createStore({ phase: 'idle', result: null, error: null, available: null, hint: null });
1496
+ let timer = null;
1497
+ /* Host probe endpoint: sync is optional, so a failed probe means "unavailable". */
1498
+ async function probe() {
1499
+ try {
1500
+ const a = await api.syncAvailability();
1501
+ store.set({ available: !!(a && a.available), hint: (a && a.hint) || null });
1502
+ } catch {
1503
+ store.set({ available: false, hint: null });
1504
+ }
1505
+ }
1506
+ function noteAvailable(s) {
1507
+ if (s && typeof s.available === 'boolean') store.set({ available: s.available, hint: s.hint || null });
1508
+ }
1509
+ async function refresh() {
1510
+ try {
1511
+ const s = await api.syncStatus();
1512
+ noteAvailable(s);
1513
+ if (s.running) { store.set({ phase: 'running' }); return true; }
1514
+ if (s.result || s.error) {
1515
+ store.set({ phase: 'done', result: s.result || null, error: s.error || null });
1516
+ return false;
1517
+ }
1518
+ return false;
1519
+ } catch { return false; }
1520
+ }
1521
+ function poll() {
1522
+ if (timer) return;
1523
+ const tick = async () => {
1524
+ const running = await refresh();
1525
+ if (!running) { timer = null; return; }
1526
+ timer = setTimeout(tick, 1500);
1527
+ };
1528
+ tick();
1529
+ }
1530
+ async function start() {
1531
+ if (store.getSnapshot().phase === 'running') return;
1532
+ store.set({ phase: 'running', error: null, result: null });
1533
+ try {
1534
+ await api.sync();
1535
+ } catch (err) {
1536
+ store.set({ phase: 'error', error: (err && err.message) || String(err) });
1537
+ timer = null;
1538
+ return;
1539
+ }
1540
+ poll();
1541
+ }
1542
+ async function warm() { await probe(); const r = await refresh(); if (r) poll(); }
1543
+ function dispose() { if (timer) { clearTimeout(timer); timer = null; } }
1544
+ return { source: store, start, warm, dispose, probe };
1545
+ }
1546
+
1547
+ function createHistoryService(api) {
1548
+ const store = createStore({ status: 'idle', events: [], total: 0, stats: null, error: null });
1549
+ async function load(limit) {
1550
+ store.set({ status: store.getSnapshot().events.length ? 'ready' : 'loading', error: null });
1551
+ const statsPromise = api.historyStats
1552
+ ? api.historyStats().catch(() => null)
1553
+ : Promise.resolve(null);
1554
+ try {
1555
+ const data = await api.history(limit || 50);
1556
+ const stats = await statsPromise;
1557
+ store.set({
1558
+ status: 'ready',
1559
+ events: (data && data.events) || [],
1560
+ total: (data && data.total) || 0,
1561
+ stats,
1562
+ });
1563
+ } catch (err) {
1564
+ store.set({ status: 'error', error: (err && err.message) || String(err) });
1565
+ }
1566
+ }
1567
+ return { source: store, load };
1568
+ }
1569
+
1570
+ /* ================================================================
1571
+ * 6d. V3 services: likes (♥才入库) + preview (试听不入库)
1572
+ * ================================================================ */
1573
+ function likeKey(o) {
1574
+ return normalizeZh(o.artist) + '::' + normalizeZh(o.title);
1575
+ }
1576
+
1577
+ function createLikesService(api, onAutoDownload) {
1578
+ const store = createStore({ keys: {}, loaded: false, error: null });
1579
+ async function load() {
1580
+ try {
1581
+ const data = await api.likes();
1582
+ const keys = {};
1583
+ for (const it of (data && data.items) || []) if (it.liked !== false) keys[likeKey(it)] = it;
1584
+ store.set({ keys, loaded: true, error: null });
1585
+ } catch (err) {
1586
+ store.set({ loaded: true, error: (err && err.message) || String(err) });
1587
+ }
1588
+ }
1589
+ async function toggle(item, liked) {
1590
+ const body = item.id
1591
+ ? { trackId: item.id, liked }
1592
+ : { artist: item.artist, title: item.title, album: item.album, durationMs: item.durationMs, coverUrl: item.coverUrl, verification: item.verification, liked };
1593
+ let res = null;
1594
+ try { res = await api.like(body); } catch (err) { return { error: (err && err.message) || String(err) }; }
1595
+ const key = likeKey(res && res.key ? { artist: res.key.split('::')[0], title: res.key.split('::')[1] } : item);
1596
+ const keys = { ...store.getSnapshot().keys };
1597
+ if (liked) keys[key] = { artist: item.artist, title: item.title, trackId: res && res.trackId, inLibrary: res && res.inLibrary };
1598
+ else delete keys[key];
1599
+ store.set({ keys });
1600
+ if (res && res.downloading && onAutoDownload) onAutoDownload();
1601
+ return res || {};
1602
+ }
1603
+ function isLiked(item) {
1604
+ return !!store.getSnapshot().keys[likeKey(item)];
1605
+ }
1606
+ load();
1607
+ return { source: store, toggle, isLiked, load };
1608
+ }
1609
+
1610
+ function createPreviewService(api) {
1611
+ const store = createStore({ status: 'idle', item: null, error: null });
1612
+ let timer = null;
1613
+ function stopTimer() { if (timer) { clearTimeout(timer); timer = null; } }
1614
+ function poll(ready) {
1615
+ stopTimer();
1616
+ timer = setTimeout(async () => {
1617
+ try {
1618
+ const s = await api.previewStatus();
1619
+ if (s && s.status === 'ready' && s.audioUrl) { store.set({ status: 'idle', item: null }); ready({ audioUrl: s.audioUrl }); return; }
1620
+ if (s && s.status === 'fail') { store.set({ status: 'idle', item: null, error: s.error || null }); ready({ error: s.error || '试听失败' }); return; }
1621
+ if (s && (s.status === 'downloading' || s.running)) { poll(ready); return; }
1622
+ } catch { /* transient — keep polling a bit */ }
1623
+ poll(ready);
1624
+ }, 2000);
1625
+ }
1626
+ async function start(item, ready) {
1627
+ const snap = store.getSnapshot();
1628
+ if (snap.item && snap.item.artist === item.artist && snap.item.title === item.title) return;
1629
+ store.set({ status: 'downloading', item, error: null });
1630
+ try {
1631
+ const res = await api.preview({
1632
+ artist: item.artist, title: item.title, album: item.album,
1633
+ durationMs: item.durationMs, coverUrl: item.coverUrl, verification: item.verification,
1634
+ });
1635
+ if (res && res.status === 'ready' && res.audioUrl) {
1636
+ store.set({ status: 'idle', item: null });
1637
+ ready({ audioUrl: res.audioUrl });
1638
+ } else {
1639
+ poll(ready);
1640
+ }
1641
+ } catch (err) {
1642
+ store.set({ status: 'idle', item: null, error: (err && err.message) || String(err) });
1643
+ ready({ error: (err && err.message) || String(err) });
1644
+ }
1645
+ }
1646
+ function dispose() { stopTimer(); }
1647
+ return { source: store, start, dispose };
1648
+ }
1649
+
1650
+ /* ================================================================
1651
+ * 7. Player engine — singleton audio, survives panel navigation
1652
+ * ================================================================ */
1653
+ function createPlayer(t, api) {
1654
+ const prefs = readPrefs();
1655
+ const store = createStore({
1656
+ track: null,
1657
+ playing: false,
1658
+ loading: false,
1659
+ position: 0,
1660
+ duration: 0,
1661
+ volume: typeof prefs.volume === 'number' ? Math.min(1, Math.max(0, prefs.volume)) : 0.9,
1662
+ muted: !!prefs.muted,
1663
+ queue: [],
1664
+ queueIndex: -1,
1665
+ shuffle: !!prefs.shuffle,
1666
+ repeat: prefs.repeat === 'all' || prefs.repeat === 'one' ? prefs.repeat : 'off',
1667
+ error: null,
1668
+ });
1669
+
1670
+ const hasAudio = typeof Audio !== 'undefined';
1671
+ const audio = hasAudio ? new Audio() : null;
1672
+ const cleanups = [];
1673
+ if (audio) {
1674
+ audio.preload = 'auto';
1675
+ audio.volume = store.getSnapshot().volume;
1676
+ audio.muted = store.getSnapshot().muted;
1677
+ }
1678
+
1679
+ const set = (patch) => store.set(patch);
1680
+ const snap = () => store.getSnapshot();
1681
+
1682
+ /* S3 listening history: fire-and-forget report on natural track end
1683
+ * (skipped=false) and manual switches (skipped=true). Values are read
1684
+ * synchronously before any state change; failures never affect playback. */
1685
+ /* Preview tracks carry a synthetic "preview:" id — never report them to
1686
+ * history or push them into the Host playback queue (S1-003 validates
1687
+ * real library ids only). */
1688
+ function isLibraryId(id) {
1689
+ return typeof id === 'string' && /^[0-9a-f]{8,}$/.test(id);
1690
+ }
1691
+
1692
+ function report(track, skipped) {
1693
+ if (!track || !track.id || !isLibraryId(track.id)) return;
1694
+ const s = snap();
1695
+ const completion = s.duration > 0
1696
+ ? Math.min(1, Math.max(0, s.position / s.duration))
1697
+ : 0;
1698
+ try {
1699
+ void fetch(resolveUrl('/dsh-music/api/history'), {
1700
+ method: 'POST',
1701
+ headers: { 'Content-Type': 'application/json' },
1702
+ body: JSON.stringify({ trackId: track.id, completion, skipped }),
1703
+ }).catch(() => { /* best-effort */ });
1704
+ } catch { /* best-effort */ }
1705
+ }
1706
+
1707
+ function listen(target, name, fn) {
1708
+ target.addEventListener(name, fn);
1709
+ cleanups.push(() => target.removeEventListener(name, fn));
1710
+ }
1711
+
1712
+ function updateMediaSession(track) {
1713
+ try {
1714
+ if (typeof navigator === 'undefined' || !('mediaSession' in navigator)) return;
1715
+ const ms = navigator.mediaSession;
1716
+ ms.metadata = new MediaMetadata({
1717
+ title: track.title || '',
1718
+ artist: track.artist || '',
1719
+ album: track.album || '',
1720
+ artwork: track.coverUrl ? [{ src: resolveUrl(track.coverUrl) }] : [],
1721
+ });
1722
+ } catch { /* MediaSession unsupported — playback still works */ }
1723
+ }
1724
+
1725
+ function loadTrack(track, autoplay) {
1726
+ if (!audio) return;
1727
+ set({ track, error: null, loading: true, position: 0, duration: track.duration || 0 });
1728
+ updateMediaSession(track);
1729
+ audio.src = resolveUrl(track.audioUrl);
1730
+ audio.load();
1731
+ if (autoplay) {
1732
+ const p = audio.play();
1733
+ if (p && p.catch) p.catch((err) => {
1734
+ if (err && err.name === 'AbortError') return; // superseded by a newer load
1735
+ set({ playing: false, loading: false, error: t('audioError') });
1736
+ });
1737
+ }
1738
+ }
1739
+
1740
+ function hostMode() {
1741
+ const s = snap();
1742
+ return s.shuffle ? 'shuffle' : s.repeat === 'one' ? 'single' : 'sequential';
1743
+ }
1744
+
1745
+ function syncHost(extra) {
1746
+ if (!api || !api.playback) return;
1747
+ const s = snap();
1748
+ const patch = {
1749
+ mode: hostMode(),
1750
+ trackId: s.track && isLibraryId(s.track.id) ? s.track.id : null,
1751
+ queue: (s.queue || []).map((tr) => tr && tr.id).filter((id) => id && isLibraryId(id)),
1752
+ ...extra,
1753
+ };
1754
+ api.playback(patch).catch(() => { /* Host not installed yet — local playback still works */ });
1755
+ }
1756
+
1757
+ function playTracks(tracks, startIndex, opts) {
1758
+ const list = (tracks || []).filter((tr) => tr && tr.audioUrl);
1759
+ if (!list.length) return;
1760
+ if (snap().track) report(snap().track, true);
1761
+ /* D1:播放全部必须跟随当前模式——随机态先打乱队列再随机起播,
1762
+ * 顺序/单曲态从首曲开始(单曲由 repeat=one 循环当前首)。 */
1763
+ const wantShuffle = opts && typeof opts.shuffle === 'boolean' ? opts.shuffle : snap().shuffle;
1764
+ let queue = list;
1765
+ let index = Math.min(Math.max(0, startIndex | 0), list.length - 1);
1766
+ if (wantShuffle && queue.length > 1) {
1767
+ queue = [...list];
1768
+ for (let i = queue.length - 1; i > 0; i -= 1) {
1769
+ const j = Math.floor(Math.random() * (i + 1));
1770
+ const tmp = queue[i];
1771
+ queue[i] = queue[j];
1772
+ queue[j] = tmp;
1773
+ }
1774
+ index = Math.floor(Math.random() * queue.length);
1775
+ }
1776
+ set({ queue, queueIndex: index, shuffle: wantShuffle });
1777
+ if (opts && typeof opts.shuffle === 'boolean') writePrefs({ shuffle: wantShuffle });
1778
+ loadTrack(queue[index], true);
1779
+ syncHost({ trackId: queue[index].id, queue: queue.map((tr) => tr.id).filter(Boolean) });
1780
+ }
1781
+
1782
+ function jumpTo(index) {
1783
+ const { queue } = snap();
1784
+ if (index < 0 || index >= queue.length) return;
1785
+ report(snap().track, true);
1786
+ set({ queueIndex: index });
1787
+ loadTrack(queue[index], true);
1788
+ syncHost({ trackId: queue[index].id });
1789
+ }
1790
+
1791
+ function playById(id) {
1792
+ const { queue } = snap();
1793
+ const idx = queue.findIndex((tr) => tr && tr.id === id);
1794
+ if (idx < 0) return false;
1795
+ set({ queueIndex: idx });
1796
+ loadTrack(queue[idx], true);
1797
+ syncHost({ trackId: id });
1798
+ return true;
1799
+ }
1800
+
1801
+ function advanceLocal(auto) {
1802
+ const { queue, queueIndex, shuffle, repeat } = snap();
1803
+ if (!queue.length) return;
1804
+ if (auto && repeat === 'one') {
1805
+ if (audio) { audio.currentTime = 0; const p = audio.play(); if (p && p.catch) p.catch(() => {}); }
1806
+ return;
1807
+ }
1808
+ let next;
1809
+ if (shuffle && queue.length > 1) {
1810
+ do { next = Math.floor(Math.random() * queue.length); } while (next === queueIndex);
1811
+ } else {
1812
+ next = queueIndex + 1;
1813
+ if (next >= queue.length) {
1814
+ if (repeat === 'all' || !auto) next = 0;
1815
+ else { set({ playing: false }); return; }
1816
+ }
1817
+ }
1818
+ set({ queueIndex: next });
1819
+ loadTrack(queue[next], true);
1820
+ syncHost({ trackId: queue[next].id });
1821
+ }
1822
+
1823
+ async function advance(auto) {
1824
+ const cur = snap().track;
1825
+ if (cur) report(cur, !auto);
1826
+ if (auto && cur && api && api.playbackNext) {
1827
+ try {
1828
+ const data = await api.playbackNext(cur.id);
1829
+ if (!data || !data.trackId) { set({ playing: false }); return; }
1830
+ if (data.reason === 'replay' || data.trackId === cur.id) {
1831
+ if (audio) { audio.currentTime = 0; const p = audio.play(); if (p && p.catch) p.catch(() => {}); }
1832
+ return;
1833
+ }
1834
+ if (playById(data.trackId)) return;
1835
+ } catch { /* Host unavailable — local decision below */ }
1836
+ }
1837
+ advanceLocal(auto);
1838
+ }
1839
+
1840
+ function prev() {
1841
+ const { queue, queueIndex, shuffle, position } = snap();
1842
+ if (!queue.length) return;
1843
+ if (position > 3 && audio) { audio.currentTime = 0; set({ position: 0 }); return; }
1844
+ report(snap().track, true);
1845
+ let index;
1846
+ if (shuffle && queue.length > 1) {
1847
+ do { index = Math.floor(Math.random() * queue.length); } while (index === queueIndex);
1848
+ } else {
1849
+ index = queueIndex - 1;
1850
+ if (index < 0) index = queue.length - 1;
1851
+ }
1852
+ set({ queueIndex: index });
1853
+ loadTrack(queue[index], true);
1854
+ }
1855
+
1856
+ function toggle() {
1857
+ if (!audio || !snap().track) return;
1858
+ if (snap().playing) audio.pause();
1859
+ else {
1860
+ const p = audio.play();
1861
+ if (p && p.catch) p.catch((err) => {
1862
+ if (err && err.name === 'AbortError') return;
1863
+ set({ error: t('audioError'), playing: false });
1864
+ });
1865
+ }
1866
+ }
1867
+
1868
+ function seek(seconds) {
1869
+ if (!audio || !snap().track) return;
1870
+ const dur = snap().duration;
1871
+ const target = Math.min(Math.max(0, seconds), dur > 0 ? dur : seconds);
1872
+ try { audio.currentTime = target; } catch { /* not seekable yet */ }
1873
+ set({ position: target });
1874
+ }
1875
+
1876
+ function setVolume(v) {
1877
+ const volume = Math.min(1, Math.max(0, v));
1878
+ if (audio) { audio.volume = volume; if (volume > 0 && audio.muted) { audio.muted = false; set({ muted: false }); } }
1879
+ set({ volume });
1880
+ writePrefs({ volume });
1881
+ }
1882
+
1883
+ function toggleMute() {
1884
+ const muted = !snap().muted;
1885
+ if (audio) audio.muted = muted;
1886
+ set({ muted });
1887
+ writePrefs({ muted });
1888
+ }
1889
+
1890
+ function setMode(mode) {
1891
+ const next = mode === 'one'
1892
+ ? { shuffle: false, repeat: 'one' }
1893
+ : mode === 'shuffle'
1894
+ ? { shuffle: true, repeat: 'all' }
1895
+ : { shuffle: false, repeat: 'all' };
1896
+ set(next);
1897
+ writePrefs(next);
1898
+ syncHost({ mode: mode === 'one' ? 'single' : mode === 'shuffle' ? 'shuffle' : 'sequential' });
1899
+ }
1900
+
1901
+ function cycleMode() {
1902
+ const s = snap();
1903
+ const cur = s.shuffle ? 'shuffle' : s.repeat === 'one' ? 'one' : 'order';
1904
+ setMode(cur === 'order' ? 'shuffle' : cur === 'shuffle' ? 'one' : 'order');
1905
+ }
1906
+
1907
+ function stop() {
1908
+ if (audio) { audio.pause(); audio.removeAttribute('src'); audio.load(); }
1909
+ set({ track: null, playing: false, loading: false, position: 0, duration: 0, queue: [], queueIndex: -1, error: null });
1910
+ try { if (typeof navigator !== 'undefined' && 'mediaSession' in navigator) navigator.mediaSession.metadata = null; } catch { /* ignore */ }
1911
+ }
1912
+
1913
+ if (audio) {
1914
+ listen(audio, 'timeupdate', () => {
1915
+ const patch = { position: audio.currentTime };
1916
+ if (isFinite(audio.duration) && audio.duration > 0 && audio.duration !== snap().duration) patch.duration = audio.duration;
1917
+ set(patch);
1918
+ });
1919
+ listen(audio, 'loadedmetadata', () => {
1920
+ if (isFinite(audio.duration) && audio.duration > 0) set({ duration: audio.duration });
1921
+ });
1922
+ listen(audio, 'durationchange', () => {
1923
+ if (isFinite(audio.duration) && audio.duration > 0) set({ duration: audio.duration });
1924
+ });
1925
+ listen(audio, 'play', () => set({ playing: true, error: null }));
1926
+ listen(audio, 'pause', () => set({ playing: false }));
1927
+ listen(audio, 'playing', () => set({ playing: true, loading: false }));
1928
+ listen(audio, 'waiting', () => set({ loading: true }));
1929
+ listen(audio, 'canplay', () => set({ loading: false }));
1930
+ listen(audio, 'ended', () => advance(true));
1931
+ listen(audio, 'error', () => {
1932
+ if (!snap().track) return; // stop() clears src; ignore that teardown
1933
+ set({ playing: false, loading: false, error: t('audioError') });
1934
+ });
1935
+ }
1936
+
1937
+ try {
1938
+ if (typeof navigator !== 'undefined' && 'mediaSession' in navigator) {
1939
+ const ms = navigator.mediaSession;
1940
+ const handlers = {
1941
+ play: () => toggle(),
1942
+ pause: () => { if (audio) audio.pause(); },
1943
+ previoustrack: () => prev(),
1944
+ nexttrack: () => advance(false),
1945
+ seekto: (d) => { if (d && typeof d.seekTime === 'number') seek(d.seekTime); },
1946
+ };
1947
+ for (const [name, fn] of Object.entries(handlers)) {
1948
+ try { ms.setActionHandler(name, fn); } catch { /* action unsupported */ }
1949
+ cleanups.push(() => { try { ms.setActionHandler(name, null); } catch { /* ignore */ } });
1950
+ }
1951
+ }
1952
+ } catch { /* MediaSession unavailable */ }
1953
+
1954
+ function dispose() {
1955
+ for (const fn of cleanups.splice(0)) { try { fn(); } catch { /* ignore */ } }
1956
+ if (audio) { audio.pause(); audio.removeAttribute('src'); audio.load(); }
1957
+ }
1958
+
1959
+ return {
1960
+ source: store,
1961
+ playTracks,
1962
+ playAll: (tracks, opts) => playTracks(tracks, 0, opts),
1963
+ jumpTo,
1964
+ toggle,
1965
+ next: () => advance(false),
1966
+ prev,
1967
+ seek,
1968
+ setVolume,
1969
+ toggleMute,
1970
+ setMode,
1971
+ cycleMode,
1972
+ stop,
1973
+ dispose,
1974
+ };
1975
+ }
1976
+
1977
+ /* ================================================================
1978
+ * 8. Shared UI atoms
1979
+ * ================================================================ */
1980
+ function IconButton({ label, onClick, active, disabled, className, children }) {
1981
+ return h('button', {
1982
+ type: 'button',
1983
+ className: cx('dshm-iconbtn', active && 'dshm-iconbtn-active', className),
1984
+ 'aria-label': label, title: label, onClick, disabled,
1985
+ 'aria-pressed': active === undefined ? undefined : !!active,
1986
+ }, children);
1987
+ }
1988
+
1989
+ function Cover({ track, size, className }) {
1990
+ const [failed, setFailed] = useState(false);
1991
+ const id = track && track.id;
1992
+ useEffect(() => { setFailed(false); }, [id]);
1993
+ const url = track && track.coverUrl && !failed ? resolveUrl(track.coverUrl) : null;
1994
+ // With `size`, dimensions are inline; without it, a CSS class owns them
1995
+ // (the now-playing hero shrinks through a container query).
1996
+ const style = size ? { width: size, height: size } : undefined;
1997
+ const glyph = size ? Math.max(14, Math.round(size * 0.4)) : 64;
1998
+ return h('div', { className: cx('dshm-cover', className), style },
1999
+ url
2000
+ ? h('img', { src: url, alt: '', loading: 'lazy', draggable: false, onError: () => setFailed(true) })
2001
+ : h('span', { className: 'dshm-cover-fallback' }, h(IconNote, { size: glyph })));
2002
+ }
2003
+
2004
+ function EqBars({ playing }) {
2005
+ return h('span', { className: cx('dshm-eq', playing && 'dshm-eq-on'), 'aria-hidden': true },
2006
+ h('i'), h('i'), h('i'));
2007
+ }
2008
+
2009
+ /** One-cycle play-mode button meta: icon/label/hint for the current mode. */
2010
+ function modeMeta(t, shuffle, repeat) {
2011
+ if (shuffle) return { icon: IconShuffle, label: t('modeShuffle'), hint: t('modeHintShuffle') };
2012
+ if (repeat === 'one') return { icon: IconRepeatOne, label: t('modeOne'), hint: t('modeHintOne') };
2013
+ return { icon: IconRepeat, label: t('modeOrder'), hint: t('modeHintOrder') };
2014
+ }
2015
+
2016
+ /** Token-styled slider with pointer + keyboard control, value 0..1. */
2017
+ /* ------------------------------------------------------------------
2018
+ * Welcome (v7): the blue big-fish-with-headphones mascot.
2019
+ * Drawn as inline SVG; every colour comes from theme tokens so the
2020
+ * illustration follows light/dark like the rest of the panel.
2021
+ * ------------------------------------------------------------------ */
2022
+ function FishLogo({ size }) {
2023
+ return h('svg', {
2024
+ viewBox: '0 0 200 200', width: size || 168, height: size || 168,
2025
+ className: 'dshm-fish', 'aria-hidden': 'true', focusable: 'false',
2026
+ },
2027
+ h('defs', null,
2028
+ h('linearGradient', { id: 'dshmFishBody', x1: '0.1', y1: '0', x2: '0.9', y2: '1' },
2029
+ h('stop', { offset: '0%', style: { stopColor: 'var(--dsw-alias-brand-primary)' } }),
2030
+ h('stop', { offset: '100%', style: { stopColor: 'var(--dsw-alias-brand-primary)', stopOpacity: '0.72' } }))),
2031
+ /* tail fin */
2032
+ h('path', {
2033
+ d: 'M44 104 C24 88 18 72 24 60 C42 72 52 83 60 96 L60 112 C52 125 42 136 24 148 C18 136 24 120 44 104 Z',
2034
+ fill: 'url(#dshmFishBody)',
2035
+ }),
2036
+ /* dorsal fin */
2037
+ h('path', {
2038
+ d: 'M92 58 C100 40 122 36 134 50 C126 60 110 66 98 68 Z',
2039
+ fill: 'url(#dshmFishBody)', opacity: '0.9',
2040
+ }),
2041
+ /* body */
2042
+ h('ellipse', { cx: 104, cy: 104, rx: 60, ry: 46, fill: 'url(#dshmFishBody)' }),
2043
+ /* belly highlight */
2044
+ h('ellipse', { cx: 110, cy: 122, rx: 38, ry: 20, fill: 'var(--dsw-alias-label-primary-inverted)', opacity: '0.18' }),
2045
+ /* headphone band */
2046
+ h('path', {
2047
+ d: 'M62 92 C62 44 144 44 144 92', fill: 'none',
2048
+ stroke: 'var(--dsw-alias-label-primary)', strokeWidth: 9, strokeLinecap: 'round',
2049
+ }),
2050
+ /* ear cups */
2051
+ h('rect', { x: 52, y: 84, width: 22, height: 38, rx: 10, fill: 'var(--dsw-alias-label-primary)' }),
2052
+ h('rect', { x: 132, y: 84, width: 22, height: 38, rx: 10, fill: 'var(--dsw-alias-label-primary)' }),
2053
+ h('rect', { x: 58, y: 91, width: 10, height: 24, rx: 5, fill: 'var(--dsw-alias-bg-layer-1)', opacity: '0.35' }),
2054
+ h('rect', { x: 138, y: 91, width: 10, height: 24, rx: 5, fill: 'var(--dsw-alias-bg-layer-1)', opacity: '0.35' }),
2055
+ /* eye + pupil */
2056
+ h('circle', { cx: 140, cy: 104, r: 10, fill: 'var(--dsw-alias-label-primary-inverted)' }),
2057
+ h('circle', { cx: 143, cy: 104, r: 4.6, fill: 'var(--dsw-alias-label-primary)' }),
2058
+ /* mouth */
2059
+ h('path', {
2060
+ d: 'M148 122 q9 7 17 1', fill: 'none',
2061
+ stroke: 'var(--dsw-alias-label-primary)', strokeWidth: 3, strokeLinecap: 'round', opacity: '0.7',
2062
+ }),
2063
+ /* musical note */
2064
+ h('g', { transform: 'translate(158 52) rotate(12)', fill: 'var(--dsw-alias-label-primary)', opacity: '0.85' },
2065
+ h('rect', { x: 2, y: 0, width: 3, height: 22, rx: 1.5 }),
2066
+ h('path', { d: 'M5 0 q9 3 9 10 q-4 -4 -9 -3 Z' }),
2067
+ h('circle', { cx: 1, cy: 23, r: 4.4 })));
2068
+ }
2069
+
2070
+ /* First-run welcome flow: hero -> taste -> library choice -> starter progress.
2071
+ * The host owns starter provisioning; this view only reflects its status. */
2072
+ function WelcomeView({ t, onboarding, useOnboarding, preview, onExitPreview, onRoute }) {
2073
+ const snap = useOnboarding((st) => st);
2074
+ const [step, setStep] = useState(0);
2075
+ const [genres, setGenres] = useState([]);
2076
+ const [langs, setLangs] = useState([]);
2077
+ const [mode, setMode] = useState('starter');
2078
+ const [dirPath, setDirPath] = useState('');
2079
+ const [busy, setBusy] = useState(false);
2080
+ const [failed, setFailed] = useState(false);
2081
+
2082
+ const genreOptions = ['jazz', 'classical', 'electronic', 'blues', 'reggae', 'soul', 'folk', 'metal', 'funk', 'ambient'];
2083
+ const langOptions = [
2084
+ { value: '中文', key: 'lang_zh' }, { value: '英语', key: 'lang_en' }, { value: '粤语', key: 'lang_yue' },
2085
+ { value: '日语', key: 'lang_ja' }, { value: '韩语', key: 'lang_ko' }, { value: '法语', key: 'lang_fr' },
2086
+ { value: '西班牙语', key: 'lang_es' }, { value: '葡萄牙语', key: 'lang_pt' }, { value: '意大利语', key: 'lang_it' },
2087
+ ];
2088
+ const toggle = (list, setList, value) =>
2089
+ setList(list.indexOf(value) >= 0 ? list.filter((x) => x !== value) : list.concat([value]));
2090
+
2091
+ const starter = snap.starter;
2092
+ const starterTracks = (starter && starter.tracks) || [];
2093
+ const starterTotal = (starter && starter.total) || starterTracks.length;
2094
+ const starterDone = (starter && starter.done) || 0;
2095
+ const starterStatus = starter ? starter.status : 'idle';
2096
+ const starterPct = starterTotal > 0 ? Math.min(100, Math.round((starterDone / starterTotal) * 100)) : (starterStatus === 'ready' ? 100 : 0);
2097
+
2098
+ async function finish() {
2099
+ /* Preview mode must never touch real state: no POST, no prefs, no route. */
2100
+ if (preview) { onExitPreview(); return; }
2101
+ if (busy) return;
2102
+ setBusy(true);
2103
+ setFailed(false);
2104
+ try {
2105
+ const payload = { taste: { genres, languages: langs }, libraryMode: mode };
2106
+ if (mode === 'starter') payload.useStarter = true;
2107
+ else if (dirPath.trim()) payload.libraryPath = dirPath.trim();
2108
+ await onboarding.complete(payload);
2109
+ } catch (err) {
2110
+ setFailed(true);
2111
+ setBusy(false);
2112
+ return;
2113
+ }
2114
+ setBusy(false);
2115
+ if (mode === 'starter') setStep(3);
2116
+ else onRoute('library');
2117
+ }
2118
+
2119
+ function skipAll() {
2120
+ if (preview) { onExitPreview(); return; }
2121
+ onRoute('reco');
2122
+ }
2123
+
2124
+ const tasteChip = (value, label, list, setList) => h('button', {
2125
+ key: value, type: 'button',
2126
+ className: cx('dshm-wchip', list.indexOf(value) >= 0 && 'dshm-wchip-on'),
2127
+ 'aria-pressed': list.indexOf(value) >= 0,
2128
+ onClick: () => toggle(list, setList, value),
2129
+ }, label);
2130
+
2131
+ const dots = h('div', { className: 'dshm-wdots', 'aria-hidden': true },
2132
+ [0, 1, 2, 3].map((i) => h('span', { key: i, className: cx('dshm-wdot', i === step && 'dshm-wdot-on') })));
2133
+
2134
+ const hero = h('div', { className: 'dshm-welcome-hero' },
2135
+ h('div', { className: 'dshm-welcome-glow', 'aria-hidden': true }),
2136
+ h('div', { className: 'dshm-welcome-fish' }, h(FishLogo, { size: 176 })),
2137
+ h('h1', { className: 'dshm-welcome-title' }, t('welcomeTitle')),
2138
+ h('p', { className: 'dshm-welcome-sub' }, t('welcomeSub')),
2139
+ h('div', { className: 'dshm-welcome-actions' },
2140
+ h('button', {
2141
+ type: 'button', className: 'dshm-wbtn dshm-wbtn-primary',
2142
+ onClick: () => setStep(1),
2143
+ }, h(IconSparkles, { size: 16 }), t('welcomeStart')),
2144
+ preview
2145
+ ? h('button', { type: 'button', className: 'dshm-wbtn', onClick: onExitPreview }, t('welcomeBack'))
2146
+ : h('button', { type: 'button', className: 'dshm-wbtn', onClick: skipAll }, t('welcomeSkip'))),
2147
+ h('div', { className: 'dshm-welcome-points' },
2148
+ [t('welcomePoint1'), t('welcomePoint2'), t('welcomePoint3')]
2149
+ .map((text, i) => h('div', { className: 'dshm-wpoint', key: i }, h(IconCheck, { size: 13 }), h('span', null, text)))));
2150
+
2151
+ const taste = h('div', { className: 'dshm-welcome-panel' },
2152
+ h('h2', { className: 'dshm-wstep-title' }, t('welcomeTasteTitle')),
2153
+ h('p', { className: 'dshm-wstep-sub' }, t('welcomeTasteSub')),
2154
+ h('div', { className: 'dshm-wgroup' },
2155
+ h('div', { className: 'dshm-wlabel' }, t('welcomeGenres')),
2156
+ h('div', { className: 'dshm-wchips' }, genreOptions.map((g) => tasteChip(g, t('genre_' + g), genres, setGenres)))),
2157
+ h('div', { className: 'dshm-wgroup' },
2158
+ h('div', { className: 'dshm-wlabel' }, t('welcomeLanguages')),
2159
+ h('div', { className: 'dshm-wchips' }, langOptions.map((o) => tasteChip(o.value, t(o.key), langs, setLangs)))),
2160
+ h('p', { className: 'dshm-whint' }, t('welcomeTasteNote')),
2161
+ h('div', { className: 'dshm-welcome-actions' },
2162
+ h('button', { type: 'button', className: 'dshm-wbtn', onClick: () => setStep(0) }, t('welcomePrev')),
2163
+ h('button', { type: 'button', className: 'dshm-wbtn dshm-wbtn-primary', onClick: () => setStep(2) }, t('welcomeNext'))));
2164
+
2165
+ const pickCard = (value, icon, title, body) => h('button', {
2166
+ key: value, type: 'button',
2167
+ className: cx('dshm-wcard', mode === value && 'dshm-wcard-on'),
2168
+ 'aria-pressed': mode === value,
2169
+ onClick: () => setMode(value),
2170
+ },
2171
+ h('span', { className: 'dshm-wcard-icon' }, h(icon, { size: 20 })),
2172
+ h('span', { className: 'dshm-wcard-text' },
2173
+ h('span', { className: 'dshm-wcard-title' }, title),
2174
+ h('span', { className: 'dshm-wcard-body' }, body)));
2175
+
2176
+ const library = h('div', { className: 'dshm-welcome-panel' },
2177
+ h('h2', { className: 'dshm-wstep-title' }, t('welcomeLibTitle')),
2178
+ h('p', { className: 'dshm-wstep-sub' }, t('welcomeLibSub')),
2179
+ h('div', { className: 'dshm-wcards' },
2180
+ pickCard('local', IconFolder, t('welcomeLocalTitle'), t('welcomeLocalBody')),
2181
+ pickCard('starter', IconSparkles, t('welcomeStarterTitle'), t('welcomeStarterBody'))),
2182
+ mode === 'starter'
2183
+ ? h('p', { className: 'dshm-whint' }, t('welcomeStarterHint'))
2184
+ : h('div', { className: 'dshm-wpath' },
2185
+ h('label', { className: 'dshm-wlabel', htmlFor: 'dshm-wpath' }, t('welcomePathLabel')),
2186
+ h('input', {
2187
+ id: 'dshm-wpath', type: 'text', className: 'dshm-winput',
2188
+ placeholder: t('welcomePathPlaceholder'), value: dirPath,
2189
+ onChange: (e) => setDirPath(e.target.value),
2190
+ }),
2191
+ h('p', { className: 'dshm-whint' }, t('welcomePathHint'))),
2192
+ failed ? h('p', { className: 'dshm-whint dshm-whint-err' }, t('welcomeSaveFail')) : null,
2193
+ h('div', { className: 'dshm-welcome-actions' },
2194
+ h('button', { type: 'button', className: 'dshm-wbtn', onClick: () => setStep(1) }, t('welcomePrev')),
2195
+ h('button', {
2196
+ type: 'button', className: 'dshm-wbtn dshm-wbtn-primary', disabled: busy,
2197
+ onClick: finish,
2198
+ }, h(IconCheck, { size: 15 }), t('welcomeFinish'))));
2199
+
2200
+ const starterPanel = h('div', { className: 'dshm-welcome-panel' },
2201
+ h('h2', { className: 'dshm-wstep-title' }, t('welcomeStarterTitle')),
2202
+ h('p', { className: 'dshm-wstep-sub' },
2203
+ starterStatus === 'ready' ? t('welcomeStarterReady')
2204
+ : starterStatus === 'failed' || starterStatus === 'skipped' ? t('welcomeStarterSkipped')
2205
+ : t('welcomeStarterDownloading')),
2206
+ h('div', { className: 'dshm-wprogress' },
2207
+ h('div', { className: 'dshm-wprogress-track' },
2208
+ h('div', { className: 'dshm-wprogress-fill', style: { width: starterPct + '%' } })),
2209
+ h('span', { className: 'dshm-count' }, starterDone + ' / ' + starterTotal)),
2210
+ starterTracks.length
2211
+ ? h('div', { className: 'dshm-wtracks' },
2212
+ h('div', { className: 'dshm-wlabel' }, t('welcomeCredits')),
2213
+ starterTracks.slice(0, 6).map((tr, i) => h('div', { className: 'dshm-wtrack', key: i },
2214
+ h('span', { className: 'dshm-ellipsis' }, (tr.title || '') + (tr.artist ? ' · ' + tr.artist : '')),
2215
+ h('span', { className: 'dshm-wtrack-lic' }, tr.license || tr.source || ''))))
2216
+ : null,
2217
+ h('div', { className: 'dshm-welcome-actions' },
2218
+ h('button', {
2219
+ type: 'button', className: 'dshm-wbtn dshm-wbtn-primary',
2220
+ onClick: () => (preview ? onExitPreview() : onRoute('reco')),
2221
+ }, h(IconSparkles, { size: 15 }), t('welcomeEnter'))));
2222
+
2223
+ const panels = [hero, taste, library, starterPanel];
2224
+ return h('div', { className: cx('dshm-welcome', preview && 'dshm-welcome-preview') },
2225
+ h('div', { className: 'dshm-welcome-inner' },
2226
+ panels[step] || hero,
2227
+ step > 0 && step < 3 ? dots : null,
2228
+ preview
2229
+ ? h('button', { type: 'button', className: 'dshm-wclose', title: t('welcomeBack'), onClick: onExitPreview }, h(IconClose, { size: 14 }))
2230
+ : null));
2231
+ }
2232
+
2233
+ function Slider({ value, onChange, label, disabled, className }) {
2234
+ const ref = useRef(null);
2235
+ const [drag, setDrag] = useState(null);
2236
+ const v = Math.min(1, Math.max(0, drag == null ? (value || 0) : drag));
2237
+ const fromEvent = (e) => {
2238
+ const el = ref.current;
2239
+ if (!el) return 0;
2240
+ const r = el.getBoundingClientRect();
2241
+ return r.width > 0 ? Math.min(1, Math.max(0, (e.clientX - r.left) / r.width)) : 0;
2242
+ };
2243
+ return h('div', {
2244
+ ref,
2245
+ className: cx('dshm-slider', drag != null && 'dshm-slider-drag', disabled && 'dshm-slider-disabled', className),
2246
+ role: 'slider', tabIndex: disabled ? -1 : 0,
2247
+ 'aria-label': label, 'aria-valuemin': 0, 'aria-valuemax': 100,
2248
+ 'aria-valuenow': Math.round(v * 100), 'aria-disabled': disabled || undefined,
2249
+ onPointerDown: (e) => {
2250
+ if (disabled) return;
2251
+ e.currentTarget.setPointerCapture(e.pointerId);
2252
+ const f = fromEvent(e); setDrag(f); onChange(f);
2253
+ },
2254
+ onPointerMove: (e) => {
2255
+ if (disabled || drag == null) return;
2256
+ const f = fromEvent(e); setDrag(f); onChange(f);
2257
+ },
2258
+ onPointerUp: () => { if (drag != null) setDrag(null); },
2259
+ onPointerCancel: () => { if (drag != null) setDrag(null); },
2260
+ onKeyDown: (e) => {
2261
+ if (disabled) return;
2262
+ const step = 0.05;
2263
+ if (e.key === 'ArrowRight' || e.key === 'ArrowUp') { onChange(Math.min(1, (value || 0) + step)); e.preventDefault(); }
2264
+ else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') { onChange(Math.max(0, (value || 0) - step)); e.preventDefault(); }
2265
+ else if (e.key === 'Home') { onChange(0); e.preventDefault(); }
2266
+ else if (e.key === 'End') { onChange(1); e.preventDefault(); }
2267
+ },
2268
+ }, h('div', { className: 'dshm-slider-track' },
2269
+ h('div', { className: 'dshm-slider-fill', style: { width: (v * 100) + '%' } }),
2270
+ h('div', { className: 'dshm-slider-thumb', style: { left: (v * 100) + '%' } })));
2271
+ }
2272
+
2273
+ function EmptyState({ icon, title, body, tone, children }) {
2274
+ return h('div', { className: 'dshm-state' },
2275
+ h('div', { className: cx('dshm-state-icon', tone === 'error' && 'dshm-state-error') }, icon),
2276
+ h('div', { className: cx('dshm-state-title', tone === 'error' && 'dshm-state-error') }, title),
2277
+ body ? h('div', { className: 'dshm-state-body' }, body) : null,
2278
+ children);
2279
+ }
2280
+
2281
+ function SkeletonRows() {
2282
+ const rows = [];
2283
+ for (let i = 0; i < 9; i++) {
2284
+ rows.push(h('div', { key: i, className: 'dshm-skel-row' },
2285
+ h('div', { className: 'dshm-skel-box', style: { width: 40, height: 40 } }),
2286
+ h('div', { style: { flex: 1, display: 'flex', flexDirection: 'column', gap: 6 } },
2287
+ h('div', { className: 'dshm-skel-box', style: { height: 12, width: (38 + ((i * 17) % 40)) + '%' } }),
2288
+ h('div', { className: 'dshm-skel-box', style: { height: 9, width: (22 + ((i * 11) % 26)) + '%' } }))));
2289
+ }
2290
+ return h('div', { className: 'dshm-skel', 'aria-hidden': true }, rows);
2291
+ }
2292
+
2293
+ function sourceLabel(source, t) {
2294
+ if (source === 'spotify-liked') return t('sourceSpotify');
2295
+ if (source === 'dsh-music') return t('sourceDsh');
2296
+ if (source === 'apple-music') return t('sourceApple');
2297
+ return source || '';
2298
+ }
2299
+
2300
+ function LikeButton({ t, item, likes, useLikes }) {
2301
+ const liked = useLikes((st) => !!st.keys[likeKey(item)]);
2302
+ return h('button', {
2303
+ type: 'button',
2304
+ className: cx('dshm-like-btn', liked && 'dshm-like-btn-on'),
2305
+ 'aria-label': liked ? t('unlikeBtn') : t('likeBtn'),
2306
+ 'aria-pressed': !!liked,
2307
+ title: liked ? t('likedBtn') : t('likeBtn'),
2308
+ onClick: (e) => { e.stopPropagation(); likes.toggle(item, !liked); },
2309
+ }, h(IconHeart, { size: 15, style: liked ? { fill: 'currentColor' } : undefined }));
2310
+ }
2311
+
2312
+ function TrackRow({ track, index, isCurrent, playing, onPlay, onDelete, onReveal, onOpenArtist, likes, useLikes, t }) {
2313
+ return h('div', {
2314
+ className: cx('dshm-row', isCurrent && 'dshm-row-current'),
2315
+ role: 'button', tabIndex: 0,
2316
+ 'aria-label': t('playTrack') + ': ' + track.title,
2317
+ onClick: () => onPlay(track, index),
2318
+ onKeyDown: (e) => {
2319
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onPlay(track, index); }
2320
+ },
2321
+ },
2322
+ h(Cover, { track, size: 40 }),
2323
+ h('div', { className: 'dshm-row-info' },
2324
+ h('div', { className: 'dshm-row-title' },
2325
+ isCurrent ? h(EqBars, { playing }) : null,
2326
+ h('span', { className: 'dshm-ellipsis' }, track.title || t('untitled'))),
2327
+ h('div', { className: 'dshm-row-sub dshm-ellipsis' },
2328
+ onOpenArtist && track.artist
2329
+ ? h('button', {
2330
+ type: 'button', className: 'dshm-row-sub-btn',
2331
+ title: t('artistOpen'), 'aria-label': t('artistOpen'),
2332
+ onClick: (e) => { e.stopPropagation(); onOpenArtist(track.artist); },
2333
+ }, track.artist)
2334
+ : (track.artist || t('unknownArtist')),
2335
+ track.album ? ' · ' + track.album : '')),
2336
+ h('span', { className: 'dshm-row-dur' }, formatTime(track.duration)),
2337
+ likes ? h(LikeButton, { t, item: track, likes, useLikes }) : null,
2338
+ onDelete ? h('span', { className: 'dshm-row-actions', onClick: (e) => e.stopPropagation() },
2339
+ h(IconButton, { label: t('revealTrack'), onClick: (e) => { e.stopPropagation(); onReveal(track); } }, h(IconDisc, { size: 14 })),
2340
+ h(IconButton, { label: t('deleteTrack'), onClick: (e) => { e.stopPropagation(); onDelete(track); } }, h(IconClose, { size: 14 }))) : null,
2341
+ h('span', { className: 'dshm-row-play', 'aria-hidden': true }, h(IconPlay, { size: 15 })));
2342
+ }
2343
+
2344
+ /* ================================================================
2345
+ * 9. Library view — search, grouping, play-all / shuffle
2346
+ * ================================================================ */
2347
+ function LibraryView({ t, player, library, sync, download, preview, likes, openArtistPage, artistImages, useSync, useDownload, useLibrary, usePlayer, useLikes, useArtistImages }) {
2348
+ const status = useLibrary((s) => s.status);
2349
+ const tracks = useLibrary((s) => s.tracks);
2350
+ const error = useLibrary((s) => s.error);
2351
+ const currentId = usePlayer((s) => (s.track ? s.track.id : null));
2352
+ const playing = usePlayer((s) => s.playing);
2353
+ const [query, setQuery] = useState('');
2354
+ const [searchState, setSearchState] = useState({ status: 'idle', local: [], remote: [] });
2355
+ const [groupBy, setGroupBy] = useState('none');
2356
+ const [rowError, setRowError] = useState('');
2357
+ const [playNotice, setPlayNotice] = useState('');
2358
+ const searchRef = useRef(null);
2359
+ const shuffle = usePlayer((s) => s.shuffle);
2360
+ const repeat = usePlayer((s) => s.repeat);
2361
+ const mode = modeMeta(t, shuffle, repeat);
2362
+ const syncAvail = useSync ? useSync((st) => st.available) : null;
2363
+ const syncHint = useSync ? useSync((st) => st.hint) : null;
2364
+ const syncUsable = syncAvail !== false;
2365
+ const syncState = useSync ? useSync((st) => st.phase) : 'idle';
2366
+
2367
+ /* Backend search (local filter + MusicBrainz completion), debounced.
2368
+ * Empty query keeps the pure client-side browse below. */
2369
+ useEffect(() => {
2370
+ const q = query.trim();
2371
+ if (!q) { setSearchState({ status: 'idle', local: [], remote: [] }); return; }
2372
+ setSearchState((s0) => ({ ...s0, status: 'loading' }));
2373
+ const timer = setTimeout(() => {
2374
+ let dead = false;
2375
+ library.searchRemote
2376
+ ? library.searchRemote(q)
2377
+ .then((data) => { if (!dead) setSearchState({ status: 'ready', local: (data && data.local) || [], remote: (data && data.remote) || [] }); })
2378
+ .catch((err) => { if (!dead) setSearchState({ status: 'error', local: [], remote: [], error: (err && err.message) || String(err) }); })
2379
+ : null;
2380
+ return () => { dead = true; };
2381
+ }, 350);
2382
+ return () => clearTimeout(timer);
2383
+ }, [query]);
2384
+
2385
+ /* Remote match = preview (temporary cache, never added to the library);
2386
+ * only ♥ puts a song into the library. Same flow as recommendations. */
2387
+ function playRemote(item) {
2388
+ setPlayNotice('');
2389
+ playSong(item, player, tracks, preview, setPlayNotice, t);
2390
+ }
2391
+
2392
+ const filtered = useMemo(() => {
2393
+ const q = normalizeZh(query.trim());
2394
+ if (!q) return tracks;
2395
+ return tracks.filter((tr) =>
2396
+ normalizeZh(tr.title).includes(q) ||
2397
+ normalizeZh(tr.artist).includes(q) ||
2398
+ normalizeZh(tr.album).includes(q));
2399
+ }, [tracks, query]);
2400
+ /* While the backend search is ready, its local list wins (it shares the
2401
+ * same normalization); otherwise fall back to instant client filtering. */
2402
+ const searching = !!query.trim();
2403
+ const shownList = searching && searchState.status === 'ready' ? searchState.local : filtered;
2404
+
2405
+ const groups = useMemo(() => {
2406
+ if (groupBy === 'none' || searching) return null;
2407
+ const map = new Map();
2408
+ for (const tr of shownList) {
2409
+ const key = (groupBy === 'artist' ? tr.artist : tr.album) || (groupBy === 'artist' ? t('unknownArtist') : t('unknownAlbum'));
2410
+ if (!map.has(key)) map.set(key, []);
2411
+ map.get(key).push(tr);
2412
+ }
2413
+ return [...map.entries()].sort((a, b) => a[0].localeCompare(b[0], 'zh'));
2414
+ }, [shownList, groupBy, searching, t]);
2415
+
2416
+ // The queue is always the flat shown list, so grouped rows map back
2417
+ // to their flat index and next/prev keep walking the visible results.
2418
+ const playFromFiltered = useCallback((track) => {
2419
+ const index = shownList.indexOf(track);
2420
+ player.playTracks(shownList, index >= 0 ? index : 0);
2421
+ }, [shownList, player]);
2422
+
2423
+ async function onDelete(track) {
2424
+ const liked = track.source === 'spotify-liked';
2425
+ if (liked) {
2426
+ if (!window.confirm(t('deleteLikedConfirm'))) return;
2427
+ if (!window.confirm(t('deleteLikedConfirm2'))) return;
2428
+ } else if (!window.confirm(t('deleteConfirm'))) return;
2429
+ try {
2430
+ setRowError('');
2431
+ await library.remove(track.id, true);
2432
+ } catch (err) {
2433
+ setRowError((err && err.message) || t('deleteFailed'));
2434
+ }
2435
+ }
2436
+ async function onReveal(track) {
2437
+ try { setRowError(''); await library.reveal(track.id); }
2438
+ catch (err) { setRowError((err && err.message) || t('deleteFailed')); }
2439
+ }
2440
+ const renderRow = (tr, i) => h(TrackRow, {
2441
+ key: tr.id || i, track: tr, index: i,
2442
+ isCurrent: currentId === tr.id, playing,
2443
+ onPlay: playFromFiltered, onDelete, onReveal, onOpenArtist: openArtistPage, likes, useLikes, t,
2444
+ });
2445
+
2446
+ function RemoteRow(item, i) {
2447
+ const isArtist = item.kind === 'artist';
2448
+ const name = isArtist ? (item.name || item.artist || '') : (item.title || '');
2449
+ const sub = isArtist
2450
+ ? t('searchTypeArtist')
2451
+ : (item.artist || '') + (item.album ? ' · ' + item.album : '');
2452
+ return h('div', { className: 'dshm-row', key: 'r' + i, role: 'listitem' },
2453
+ isArtist
2454
+ ? h(ArtistAvatar, { name, size: 40, service: artistImages, useArtistImages })
2455
+ : h('div', { className: 'dshm-tile', style: { width: 40, height: 40 } }, h(IconNote, { size: 15 })),
2456
+ h('div', { className: 'dshm-row-info' },
2457
+ h('div', { className: 'dshm-row-title' },
2458
+ isArtist ? h('span', { className: 'dshm-cat-chip' }, t('searchTypeArtist')) : null,
2459
+ h('span', { className: 'dshm-ellipsis' }, name)),
2460
+ h('div', { className: 'dshm-row-sub dshm-ellipsis' },
2461
+ isArtist || !item.artist
2462
+ ? sub
2463
+ : h(React.Fragment, null,
2464
+ h('button', {
2465
+ type: 'button', className: 'dshm-row-sub-btn',
2466
+ title: t('artistOpen'), 'aria-label': t('artistOpen'),
2467
+ onClick: () => openArtistPage(item.artist),
2468
+ }, item.artist),
2469
+ item.album ? ' · ' + item.album : ''))),
2470
+ isArtist
2471
+ ? h('button', {
2472
+ type: 'button', className: 'dshm-chipbtn',
2473
+ onClick: () => openArtistPage(name),
2474
+ }, h(IconNote, { size: 13 }), t('artistOpen'))
2475
+ : h('button', {
2476
+ type: 'button', className: 'dshm-chipbtn',
2477
+ onClick: () => playRemote(item),
2478
+ title: t('previewLabel'),
2479
+ }, h(IconPlay, { size: 13 }), t('previewLabel')));
2480
+ }
2481
+
2482
+ let content;
2483
+ const remoteList = searching && searchState.status === 'ready' ? searchState.remote : [];
2484
+ if (status === 'loading' && tracks.length === 0) {
2485
+ content = h('div', { className: 'dshm-list' }, h(SkeletonRows));
2486
+ } else if (status === 'error' && tracks.length === 0) {
2487
+ content = h(EmptyState, {
2488
+ icon: h(IconAlert, { size: 30 }), tone: 'error',
2489
+ title: t('loadError'),
2490
+ body: (error || '') + ' ' + t('scanFailedHint'),
2491
+ }, h('button', { type: 'button', className: 'dshm-chipbtn', onClick: () => library.load() }, t('retry')));
2492
+ } else if (status === 'ready' && tracks.length === 0) {
2493
+ content = h(EmptyState, {
2494
+ icon: h(IconNote, { size: 30 }),
2495
+ title: t('emptyLibraryTitle'), body: t('emptyLibraryBody'),
2496
+ },
2497
+ h('div', { className: 'dshm-empty-ctas' },
2498
+ h('button', {
2499
+ type: 'button', className: 'dshm-chipbtn dshm-chipbtn-primary',
2500
+ onClick: () => { if (searchRef.current) searchRef.current.focus(); },
2501
+ }, h(IconSearch, { size: 14 }), t('emptySearchCta')),
2502
+ h('button', {
2503
+ type: 'button', className: 'dshm-chipbtn',
2504
+ onClick: () => library.rescan(),
2505
+ }, h(IconRefresh, { size: 14 }), t('emptyRescanCta')),
2506
+ sync ? h('button', {
2507
+ type: 'button',
2508
+ className: cx('dshm-chipbtn', !syncUsable && 'dshm-chipbtn-off'),
2509
+ disabled: !syncUsable || syncState === 'running',
2510
+ title: syncUsable ? (syncHint || t('syncOptionalHint')) : (syncHint || t('syncUnavailableHint')),
2511
+ onClick: () => sync.start(),
2512
+ }, h(IconRefresh, { size: 14, className: syncState === 'running' ? 'dshm-spin' : undefined }), t('syncOptional')) : null),
2513
+ h('div', { className: 'dshm-empty-dirs' },
2514
+ h('div', { className: 'dshm-empty-dirs-head' }, t('emptyAddDirHint')),
2515
+ ['~/Music/dsh-music', '~/Music/spotify-liked', '~/Music/Music/Media.localized']
2516
+ .map((d) => h('code', { key: d, className: 'dshm-empty-dir' }, d)),
2517
+ h('div', { className: 'dshm-count' }, t('emptyDirNote'))));
2518
+ } else if (searching && searchState.status === 'loading') {
2519
+ content = h('div', { className: 'dshm-list' }, h(SkeletonRows));
2520
+ } else if (shownList.length === 0 && remoteList.length === 0) {
2521
+ content = h(EmptyState, {
2522
+ icon: h(IconSearch, { size: 28 }),
2523
+ title: query.trim() ? '“' + query.trim() + '”' : t('searchEmpty'),
2524
+ body: query.trim() ? t('searchNoLocal') : t('searchEmpty'),
2525
+ });
2526
+ } else {
2527
+ content = h('div', { className: 'dshm-list' },
2528
+ groups ? groups.map(([name, list]) =>
2529
+ h('section', { key: name },
2530
+ h('div', { className: 'dshm-group-head' },
2531
+ groupBy === 'artist' && name !== t('unknownArtist')
2532
+ ? h(ArtistAvatar, { name, size: 20, service: artistImages, useArtistImages })
2533
+ : h(groupBy === 'artist' ? IconNote : IconDisc, { size: 14 }),
2534
+ h('span', { className: 'dshm-ellipsis' }, name),
2535
+ h('span', { className: 'dshm-group-count' }, list.length + ' ' + t('tracksUnit'))),
2536
+ list.map((tr, i) => renderRow(tr, i))))
2537
+ : shownList.map((tr, i) => renderRow(tr, i)),
2538
+ remoteList.length > 0
2539
+ ? h('section', null,
2540
+ h('div', { className: 'dshm-group-head' },
2541
+ h(IconSearch, { size: 14 }),
2542
+ h('span', { className: 'dshm-ellipsis' }, t('searchWebTitle')),
2543
+ h('span', { className: 'dshm-group-count' }, remoteList.length + ' ' + t('tracksUnit'))),
2544
+ remoteList.map((item, i) => RemoteRow(item, i)))
2545
+ : null,
2546
+ shownList.length === 0 && remoteList.length > 0 && searching
2547
+ ? h('div', { className: 'dshm-lyrics-hint', style: { padding: '4px 8px' } }, t('searchNoLocal'))
2548
+ : null);
2549
+ }
2550
+
2551
+ const busy = status === 'loading';
2552
+ return h(React.Fragment, null,
2553
+ sync ? h(SyncPanel, { t, sync, useSync }) : null,
2554
+ rowError ? h('div', { className: 'dshm-errorline', role: 'alert', style: { margin: '8px 24px 0' } }, rowError) : null,
2555
+ h('div', { className: 'dshm-toolbar' },
2556
+ h('label', { className: 'dshm-search' },
2557
+ h(IconSearch, { size: 15 }),
2558
+ h('input', {
2559
+ type: 'search', value: query, placeholder: t('searchPlaceholder'), ref: searchRef,
2560
+ 'aria-label': t('searchPlaceholder'),
2561
+ onChange: (e) => setQuery(e.target.value),
2562
+ })),
2563
+ h('select', {
2564
+ className: 'dshm-select', value: groupBy, 'aria-label': t('groupLabel'),
2565
+ onChange: (e) => setGroupBy(e.target.value),
2566
+ },
2567
+ h('option', { value: 'none' }, t('groupNone')),
2568
+ h('option', { value: 'artist' }, t('groupArtist')),
2569
+ h('option', { value: 'album' }, t('groupAlbum'))),
2570
+ h('button', {
2571
+ type: 'button', className: 'dshm-chipbtn dshm-chipbtn-primary',
2572
+ disabled: busy || shownList.length === 0,
2573
+ onClick: () => player.playAll(shownList),
2574
+ }, h(IconPlay, { size: 13 }), t('playAll')),
2575
+ h('button', {
2576
+ type: 'button', className: cx('dshm-chipbtn', 'dshm-mode-cycle'),
2577
+ 'aria-label': mode.label, title: mode.hint + ' · ' + t('modeCycleHint'),
2578
+ onClick: () => player.cycleMode(),
2579
+ }, h(mode.icon, { size: 14 })),
2580
+ sync ? h('button', {
2581
+ type: 'button', className: cx('dshm-chipbtn', !syncUsable && 'dshm-chipbtn-off'),
2582
+ disabled: syncState === 'running' || busy || !syncUsable,
2583
+ title: syncUsable ? (syncHint || t('syncOptionalHint')) : (syncHint || t('syncUnavailableHint')),
2584
+ onClick: () => sync.start(),
2585
+ }, h(IconRefresh, { size: 13, className: syncState === 'running' ? 'dshm-spin' : undefined }),
2586
+ syncState === 'running' ? t('syncing') : t('syncBtn')) : null,
2587
+ h('span', { className: 'dshm-count', style: { marginLeft: 'auto' } },
2588
+ busy && tracks.length === 0 ? t('rescanning') : shownList.length + ' ' + t('tracksUnit'))),
2589
+ playNotice
2590
+ ? h('div', { className: 'dshm-mode-hint', style: { margin: '0 20px 6px', textAlign: 'right' }, role: 'status' }, playNotice)
2591
+ : null,
2592
+ content);
2593
+ }
2594
+
2595
+ /* ================================================================
2596
+ * 10. Now-playing view — hero + transport + queue
2597
+ * ================================================================ */
2598
+ function NowPlayingView({ t, player, lyrics, usePlayer, useLyrics, openView, openArtistPage, artistImages, useArtistImages }) {
2599
+ const track = usePlayer((s) => s.track);
2600
+ const playing = usePlayer((s) => s.playing);
2601
+ const position = usePlayer((s) => s.position);
2602
+ const duration = usePlayer((s) => s.duration);
2603
+ const volume = usePlayer((s) => s.volume);
2604
+ const muted = usePlayer((s) => s.muted);
2605
+ const shuffle = usePlayer((s) => s.shuffle);
2606
+ const repeat = usePlayer((s) => s.repeat);
2607
+ const mode = modeMeta(t, shuffle, repeat);
2608
+ const error = usePlayer((s) => s.error);
2609
+ const queue = usePlayer((s) => s.queue);
2610
+ const queueIndex = usePlayer((s) => s.queueIndex);
2611
+
2612
+ if (!track) {
2613
+ return h(EmptyState, {
2614
+ icon: h(IconDisc, { size: 30 }),
2615
+ title: t('noTrackTitle'), body: t('noTrackBody'),
2616
+ }, h('button', { type: 'button', className: 'dshm-chipbtn dshm-chipbtn-primary', onClick: () => openView('library') }, h(IconNote, { size: 14 }), t('goLibrary')));
2617
+ }
2618
+
2619
+ const frac = duration > 0 ? position / duration : 0;
2620
+ const RepeatIcon = repeat === 'one' ? IconRepeatOne : IconRepeat;
2621
+ const repeatLabel = repeat === 'one' ? t('repeatOne') : repeat === 'all' ? t('repeatAll') : t('repeatOff');
2622
+
2623
+ return h('div', { className: 'dshm-now' },
2624
+ h('div', { className: 'dshm-now-hero' },
2625
+ h(Cover, { track, className: 'dshm-now-cover' }),
2626
+ h('div', { className: 'dshm-now-meta' },
2627
+ h('span', { className: 'dshm-source-chip' }, h(IconDisc, { size: 12 }), sourceLabel(track.source, t)),
2628
+ h('h2', { className: 'dshm-now-title dshm-ellipsis' }, track.title),
2629
+ h('p', { className: 'dshm-now-sub dshm-ellipsis' },
2630
+ h('button', {
2631
+ type: 'button', className: 'dshm-artist-btn',
2632
+ title: t('artistOpen'), 'aria-label': t('artistOpen'),
2633
+ onClick: () => openArtistPage(track.artist || ''),
2634
+ },
2635
+ h(ArtistAvatar, { name: track.artist || '', size: 18, service: artistImages, useArtistImages }),
2636
+ h('span', null, track.artist || t('unknownArtist'))),
2637
+ track.album ? ' · ' + track.album : ''),
2638
+ error ? h('div', { className: 'dshm-errorline', role: 'alert' }, h(IconAlert, { size: 15 }), error) : null,
2639
+ h('div', { className: 'dshm-seekrow' },
2640
+ h('span', { className: 'dshm-time' }, formatTime(position)),
2641
+ h(Slider, {
2642
+ value: frac, label: t('seekLabel'), disabled: !(duration > 0),
2643
+ onChange: (f) => player.seek(f * duration),
2644
+ }),
2645
+ h('span', { className: 'dshm-time dshm-time-end' }, formatTime(duration))),
2646
+ h('div', { className: 'dshm-transport' },
2647
+ h(IconButton, {
2648
+ label: mode.label, title: mode.hint + ' · ' + t('modeCycleHint'),
2649
+ className: cx((shuffle || repeat === 'one') && 'dshm-iconbtn-active'),
2650
+ onClick: () => player.cycleMode(),
2651
+ }, h(mode.icon, { size: 17 })),
2652
+ h(IconButton, { label: t('prev'), onClick: () => player.prev() }, h(IconPrev, { size: 20 })),
2653
+ h('button', {
2654
+ type: 'button', className: 'dshm-playbtn',
2655
+ 'aria-label': playing ? t('pause') : t('play'),
2656
+ onClick: () => player.toggle(),
2657
+ }, h(playing ? IconPause : IconPlay, { size: 22 })),
2658
+ h(IconButton, { label: t('next'), onClick: () => player.next() }, h(IconNext, { size: 20 }))),
2659
+ h('div', { className: 'dshm-volumerow' },
2660
+ h(IconButton, { label: muted ? t('unmute') : t('mute'), onClick: () => player.toggleMute() },
2661
+ h(muted || volume === 0 ? IconMute : IconVolume, { size: 17 })),
2662
+ h(Slider, { value: muted ? 0 : volume, label: t('volume'), onChange: (f) => player.setVolume(f) }),
2663
+ h('span', { className: 'dshm-volume-pct' }, Math.round((muted ? 0 : volume) * 100) + '%')))),
2664
+ h(LyricsPanel, { t, lyrics, useLyrics, usePlayer }),
2665
+ h('div', { className: 'dshm-queue' },
2666
+ h('div', { className: 'dshm-queue-head' },
2667
+ h(IconQueue, { size: 15 }), t('queue'),
2668
+ h('span', { className: 'dshm-count' }, queue.length + ' ' + t('tracksUnit'))),
2669
+ queue.length === 0
2670
+ ? h('div', { className: 'dshm-state-body', style: { padding: '12px 8px' } }, t('queueEmpty'))
2671
+ : queue.map((tr, i) => h(TrackRow, {
2672
+ key: (tr.id || '') + ':' + i, track: tr, index: i,
2673
+ isCurrent: i === queueIndex, playing: playing && i === queueIndex,
2674
+ onPlay: (_tr, idx) => player.jumpTo(idx), onOpenArtist: openArtistPage, t,
2675
+ }))));
2676
+ }
2677
+
2678
+ /* ================================================================
2679
+ * 11. Recommendations view (S3 live): batch cards + download queue
2680
+ * ================================================================ */
2681
+ function DownloadPanel({ t, download, useDownload }) {
2682
+ const s = useDownload((st) => st);
2683
+ if (!s.running && s.items.length === 0 && !s.error) return null;
2684
+ const anyOk = s.items.some((it) => it.status === 'ok');
2685
+ return h('div', { className: 'dshm-dl' },
2686
+ h('div', { className: 'dshm-asec-title' },
2687
+ h(IconDownload, { size: 13 }), t('downloadTitle'),
2688
+ s.running ? h('span', { className: 'dshm-count' }, s.done + ' / ' + s.total) : null),
2689
+ s.total > 0 ? h('div', { className: 'dshm-dl-bar', 'aria-hidden': true },
2690
+ h('div', { style: { width: Math.round((s.done / s.total) * 100) + '%' } })) : null,
2691
+ s.error
2692
+ ? h('div', { className: 'dshm-errorline', role: 'alert' }, h(IconAlert, { size: 14 }), t('downloadError') + ':' + s.error)
2693
+ : null,
2694
+ s.items.map((it, i) => h('div', { className: 'dshm-dl-row', key: i },
2695
+ h('span', { className: cx('dshm-dl-dot', it.status === 'ok' && 'dshm-dl-ok', it.status === 'fail' && 'dshm-dl-fail') }),
2696
+ h('span', { className: 'dshm-ellipsis', style: { flex: 1 } },
2697
+ (it.artist || '') + ' - ' + (it.title || '')),
2698
+ h('span', { className: 'dshm-dl-status' },
2699
+ it.status === 'ok' ? t('downloadDone')
2700
+ : it.status === 'fail' ? t('downloadFail')
2701
+ : t('downloading')),
2702
+ it.status === 'fail' && it.note ? h('span', { className: 'dshm-sim-chip-reason' }, it.note) : null)),
2703
+ !s.running && anyOk ? h('div', { className: 'dshm-lyrics-hint' }, t('downloadPlay')) : null);
2704
+ }
2705
+
2706
+ /* V3 helpers: shared play-or-preview flow (preview never enters the
2707
+ * library; only ♥-like downloads it — the Host handles that on like). */
2708
+ function playSong(item, player, tracks, preview, setNotice, t) {
2709
+ const local = (item.trackId && tracks.find((tr) => tr.id === item.trackId))
2710
+ || tracks.find((tr) =>
2711
+ normalizeZh(tr.artist) === normalizeZh(item.artist) &&
2712
+ normalizeZh(tr.title) === normalizeZh(item.title));
2713
+ if (local) {
2714
+ setNotice('');
2715
+ player.playTracks([local], 0);
2716
+ return;
2717
+ }
2718
+ if (!item.verification) { setNotice(t('previewNoVerify')); return; }
2719
+ setNotice(t('previewLoading'));
2720
+ preview.start(item, (res) => {
2721
+ if (res.error) { setNotice(t('previewFail') + ':' + res.error); return; }
2722
+ setNotice('');
2723
+ player.playTracks([{
2724
+ id: 'preview:' + likeKey(item),
2725
+ title: item.title, artist: item.artist, album: item.album,
2726
+ coverUrl: item.coverUrl || null, audioUrl: res.audioUrl, duration: null,
2727
+ }], 0);
2728
+ });
2729
+ }
2730
+
2731
+ /* Image URL: external absolute URLs pass through; root-absolute Host paths
2732
+ * resolve against the document base. */
2733
+ function imgUrl(url) {
2734
+ return /^https?:\/\//i.test(String(url || '')) ? url : resolveUrl(url);
2735
+ }
2736
+
2737
+ /* Square/round image with a graceful glyph fallback (no broken icons). */
2738
+ function Thumb({ src, size, round, glyph, style, className }) {
2739
+ const [failed, setFailed] = useState(false);
2740
+ const s = size || 38;
2741
+ const box = {
2742
+ width: s, height: s,
2743
+ borderRadius: round ? '50%' : 8,
2744
+ flex: 'none',
2745
+ ...style,
2746
+ };
2747
+ if (src && !failed) {
2748
+ return h('div', { className: cx('dshm-tile', className), style: box },
2749
+ h('img', {
2750
+ src: imgUrl(src), alt: '', loading: 'lazy', draggable: false,
2751
+ onError: () => setFailed(true),
2752
+ }));
2753
+ }
2754
+ return h('div', { className: cx('dshm-tile', className), style: box },
2755
+ h(glyph || IconNote, { size: Math.max(12, Math.round(s * 0.4)) }));
2756
+ }
2757
+
2758
+ /* Small round artist portrait: one shared batch lookup with a glyph fallback. */
2759
+ function ArtistAvatar({ name, size, service, useArtistImages }) {
2760
+ const key = normalizeZh(name).trim();
2761
+ const url = useArtistImages((s) => (key ? s.images[key] : null));
2762
+ useEffect(() => { if (name) service.request(name); }, [name]);
2763
+ return h(Thumb, { src: url || null, size: size || 20, round: true, glyph: IconNote });
2764
+ }
2765
+
2766
+ function SongRow({ t, item, likes, useLikes, onPlay, onOpenArtist, isCurrent, playing, showReason }) {
2767
+ const liked = useLikes((st) => !!st.keys[likeKey(item)]);
2768
+ return h('div', { className: cx('dshm-srow', isCurrent && 'dshm-row-current') },
2769
+ h(Thumb, { src: item.coverUrl, size: 38 }),
2770
+ h('div', {
2771
+ className: 'dshm-srow-main', role: 'button', tabIndex: 0,
2772
+ 'aria-label': t('playTrack') + ': ' + (item.title || ''),
2773
+ onClick: () => onPlay(item),
2774
+ onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onPlay(item); } },
2775
+ },
2776
+ h('span', { className: 'dshm-srow-title dshm-ellipsis' }, item.title || t('untitled')),
2777
+ h('span', { className: 'dshm-srow-sub dshm-ellipsis' },
2778
+ onOpenArtist && item.artist
2779
+ ? h('button', {
2780
+ type: 'button', className: 'dshm-srow-artist',
2781
+ title: t('artistOpen'), 'aria-label': t('artistOpen'),
2782
+ onClick: (e) => { e.stopPropagation(); onOpenArtist(item.artist); },
2783
+ }, item.artist)
2784
+ : (item.artist || t('unknownArtist')),
2785
+ item.album ? ' · ' + item.album : ''),
2786
+ showReason && item.reason ? h('span', { className: 'dshm-srow-reason' }, item.reason) : null),
2787
+ h('button', {
2788
+ type: 'button',
2789
+ className: cx('dshm-like-btn', liked && 'dshm-like-btn-on'),
2790
+ 'aria-label': liked ? t('unlikeBtn') : t('likeBtn'),
2791
+ 'aria-pressed': !!liked,
2792
+ title: liked ? t('likedBtn') : t('likeBtn'),
2793
+ onClick: () => likes.toggle(item, !liked),
2794
+ }, h(IconHeart, { size: 15, style: liked ? { fill: 'currentColor' } : undefined })),
2795
+ h('button', {
2796
+ type: 'button', className: 'dshm-playround',
2797
+ 'aria-label': isCurrent && playing ? t('pause') : t('play'),
2798
+ title: isCurrent && playing ? t('pause') : t('previewLabel'),
2799
+ onClick: () => onPlay(item),
2800
+ }, h(isCurrent && playing ? IconPause : IconPlay, { size: 13 })));
2801
+ }
2802
+
2803
+ /* Artist column row: real artist/band image + name + genre hint + chevron. */
2804
+ function ArtistTile({ t, a, onOpen }) {
2805
+ return h('button', {
2806
+ type: 'button', className: 'dshm-arow',
2807
+ onClick: () => onOpen(a.name),
2808
+ title: a.reason || (t('artistOpen') + ': ' + (a.name || '')),
2809
+ },
2810
+ h(Thumb, { src: a.imageUrl, size: 44, round: true, glyph: IconNote }),
2811
+ h('span', { className: 'dshm-arow-text' },
2812
+ h('span', { className: 'dshm-srow-title dshm-ellipsis' }, a.name || ''),
2813
+ a.genreHint ? h('span', { className: 'dshm-srow-sub dshm-ellipsis' }, a.genreHint) : null),
2814
+ h('span', { className: 'dshm-arow-arrow', 'aria-hidden': true }, '›'));
2815
+ }
2816
+
2817
+ function RecoView({ t, reco, download, player, library, likes, preview, history, openArtistPage, useReco, useDownload, useLibrary, useLikes, usePlayer, useHistory }) {
2818
+ const s = useReco((st) => st);
2819
+ const histStats = useHistory ? useHistory((st) => st.stats) : null;
2820
+ const coldStart = !(histStats && histStats.totalPlays > 0);
2821
+ const finishedAt = useDownload((st) => st.finishedAt);
2822
+ const tracks = useLibrary((st) => st.tracks);
2823
+ const currentId = usePlayer((st) => (st.track ? st.track.id : null));
2824
+ const playing = usePlayer((st) => st.playing);
2825
+ const [notice, setNotice] = useState('');
2826
+ const [styleQ, setStyleQ] = useState('');
2827
+ const [styleState, setStyleState] = useState({ status: 'idle', q: '', items: [], interpretedTags: [], fallback: false, message: null, error: null });
2828
+ function runStyle() {
2829
+ const q = styleQ.trim();
2830
+ if (!q || styleState.status === 'loading') return;
2831
+ setStyleState({ status: 'loading', q, items: [], interpretedTags: [], fallback: false, message: null, error: null });
2832
+ reco.searchStyle(q)
2833
+ .then((data) => setStyleState({
2834
+ status: 'ready', q,
2835
+ items: (data && data.items) || [],
2836
+ interpretedTags: (data && data.interpretedTags) || [],
2837
+ matchedTerms: (data && data.matchedTerms) || [],
2838
+ fallback: !!(data && data.fallback),
2839
+ message: (data && data.message) || null,
2840
+ error: null,
2841
+ }))
2842
+ .catch((err) => setStyleState({ status: 'error', q, items: [], interpretedTags: [], fallback: false, message: null, error: (err && err.message) || String(err) }));
2843
+ }
2844
+ // Finished downloads trigger a client-side library refresh as well; the
2845
+ // Host rescans on its side, this only picks the new rows up sooner.
2846
+ useEffect(() => { if (finishedAt) library.load(); }, [finishedAt]);
2847
+ useEffect(() => { reco.load(); }, []);
2848
+ function findLocal(item) {
2849
+ return (item.trackId && tracks.find((tr) => tr.id === item.trackId))
2850
+ || tracks.find((tr) =>
2851
+ normalizeZh(tr.artist) === normalizeZh(item.artist) &&
2852
+ normalizeZh(tr.title) === normalizeZh(item.title));
2853
+ }
2854
+ function onPlay(item) {
2855
+ playSong(item, player, tracks, preview, setNotice, t);
2856
+ }
2857
+ /* Clicking a row queues the whole visible list (deduped local matches)
2858
+ * and jumps straight to the clicked song; preview-only items fall back
2859
+ * to the single-song preview flow. */
2860
+ function playListFrom(list, item) {
2861
+ const localTracks = [];
2862
+ let at = 0;
2863
+ for (const it of list) {
2864
+ const lc = findLocal(it);
2865
+ if (!lc || localTracks.some((tr) => tr.id === lc.id)) continue;
2866
+ if (it === item) at = localTracks.length;
2867
+ localTracks.push(lc);
2868
+ }
2869
+ if (localTracks.length) player.playTracks(localTracks, at);
2870
+ else if (list.length) onPlay(item || list[0]);
2871
+ }
2872
+ function playColumn(list) { playListFrom(list, null); }
2873
+
2874
+ const sections = s.sections || { today: s.items, artist: [], new: [] };
2875
+ const styleActive = styleState.status !== 'idle';
2876
+
2877
+ function isCur(item) {
2878
+ const lc = findLocal(item);
2879
+ return lc ? currentId === lc.id : currentId === ('preview:' + likeKey(item));
2880
+ }
2881
+ function songRows(list, showReason) {
2882
+ if (!list.length) return h('div', { className: 'dshm-lyrics-hint' }, t('recoSectionEmpty'));
2883
+ return list.map((item, i) => h(SongRow, {
2884
+ key: i, t, item, likes, useLikes, onPlay: (it) => playListFrom(list, it), onOpenArtist: openArtistPage, showReason,
2885
+ isCurrent: isCur(item), playing,
2886
+ }));
2887
+ }
2888
+ function column(headKey, icon, list, extraHead) {
2889
+ return h('section', { className: 'dshm-column', key: headKey },
2890
+ h('div', { className: 'dshm-col-head' },
2891
+ h('div', { className: 'dshm-col-title' }, h(icon, { size: 14 }), t(headKey)),
2892
+ h('span', { className: 'dshm-col-count' }, list.length + ' ' + t('tracksUnit')),
2893
+ extraHead),
2894
+ h('div', { className: 'dshm-col-list' }, songRows(list, true)));
2895
+ }
2896
+
2897
+ const toolbar = h('div', { className: 'dshm-toolbar dshm-toolbar-flat' },
2898
+ h('label', { className: 'dshm-search', style: { maxWidth: '280px' } },
2899
+ h(IconSearch, { size: 15 }),
2900
+ h('input', {
2901
+ type: 'search', value: styleQ, placeholder: t('stylePlaceholder'),
2902
+ 'aria-label': t('styleBtn'),
2903
+ onChange: (e) => setStyleQ(e.target.value),
2904
+ onKeyDown: (e) => { if (e.key === 'Enter') runStyle(); },
2905
+ })),
2906
+ h('button', { type: 'button', className: 'dshm-chipbtn', disabled: !styleQ.trim(), onClick: runStyle }, t('styleBtn')),
2907
+ notice ? h('span', { className: 'dshm-mode-hint', style: { margin: '0 0 0 8px', flex: '1', minWidth: '120px' } }, notice) : null,
2908
+ h('button', {
2909
+ type: 'button', className: 'dshm-chipbtn', style: { marginLeft: 'auto' },
2910
+ disabled: s.status === 'generating', onClick: () => reco.generate(),
2911
+ }, h(IconSparkles, { size: 13 }), t('recoRegenerate')));
2912
+
2913
+ if (s.status === 'generating') {
2914
+ return h('div', { className: 'dshm-reco-page' }, toolbar,
2915
+ h('div', { className: 'dshm-columns' },
2916
+ [0, 1, 2].map((i) => h('section', { className: 'dshm-column', key: i },
2917
+ h('div', { className: 'dshm-col-head' },
2918
+ h('div', { className: 'dshm-col-title' }, h(IconSparkles, { size: 14, className: 'dshm-state-spin' }), t('recoGenerating'))),
2919
+ h('div', { className: 'dshm-col-list' }, h(SkeletonRows))))));
2920
+ }
2921
+ if (s.status === 'error') {
2922
+ return h('div', { className: 'dshm-reco-page' }, toolbar,
2923
+ h(EmptyState, {
2924
+ icon: h(IconAlert, { size: 30 }), tone: 'error',
2925
+ title: t('recoError'), body: s.error || '',
2926
+ }, h('button', { type: 'button', className: 'dshm-chipbtn', onClick: () => reco.generate() }, t('lyricsRetry'))));
2927
+ }
2928
+ if (!styleActive && s.status !== 'ready' && !s.sections) {
2929
+ return h('div', { className: 'dshm-reco-page' }, toolbar,
2930
+ h(EmptyState, {
2931
+ icon: h(IconSparkles, { size: 30 }),
2932
+ title: coldStart ? t('recoColdTitle') : t('recoEmptyTitle'),
2933
+ body: coldStart ? t('recoColdBody') : t('recoEmptyBody'),
2934
+ }, h('button', { type: 'button', className: 'dshm-chipbtn dshm-chipbtn-primary', onClick: () => reco.generate() },
2935
+ h(IconSparkles, { size: 14 }), t('recoGenerate'))));
2936
+ }
2937
+ if (styleActive) {
2938
+ return h('div', { className: 'dshm-reco-page' }, toolbar,
2939
+ styleState.status === 'loading'
2940
+ ? h('div', { className: 'dshm-state' },
2941
+ h('div', { className: 'dshm-state-icon' }, h(IconSparkles, { size: 30, className: 'dshm-state-spin' })),
2942
+ h('div', { className: 'dshm-state-title' }, t('styleLoading')))
2943
+ : styleState.status === 'error'
2944
+ ? h(EmptyState, { icon: h(IconAlert, { size: 30 }), tone: 'error', title: t('styleError'), body: styleState.error || '' },
2945
+ h('button', { type: 'button', className: 'dshm-chipbtn', onClick: runStyle }, t('lyricsRetry')))
2946
+ : h(React.Fragment, null,
2947
+ h('div', { className: 'dshm-acard-meta', style: { padding: '10px 4px 0' } },
2948
+ h('button', { type: 'button', className: 'dshm-chipbtn', onClick: () => setStyleState({ status: 'idle', q: '', items: [], interpretedTags: [], fallback: false, message: null, error: null }) }, t('backToReco')),
2949
+ h('button', {
2950
+ type: 'button', className: 'dshm-chipbtn dshm-chipbtn-primary',
2951
+ disabled: styleState.items.length === 0,
2952
+ title: t('playList'),
2953
+ onClick: () => playListFrom(styleState.items, null),
2954
+ }, h(IconPlay, { size: 12 }), t('playList')),
2955
+ styleState.interpretedTags.length
2956
+ ? h('span', null, t('interpretedAs') + ':'
2957
+ + (styleState.matchedTerms && styleState.matchedTerms.length
2958
+ ? styleState.matchedTerms.join('、') + ' → '
2959
+ : '')
2960
+ + styleState.interpretedTags.join(' / '))
2961
+ : null,
2962
+ styleState.message
2963
+ ? h('span', { className: 'dshm-sim-chip-reason' }, styleState.message)
2964
+ : null),
2965
+ h('div', { className: 'dshm-col-list', style: { maxHeight: 'none' } }, songRows(styleState.items, true))));
2966
+ }
2967
+ return h('div', { className: 'dshm-reco-page', style: { padding: '12px 16px 0', display: 'flex', flexDirection: 'column' } },
2968
+ toolbar,
2969
+ h(DownloadPanel, { t, download, useDownload }),
2970
+ s.bootstrapNote
2971
+ ? h('div', { className: 'dshm-explore-note', role: 'note' },
2972
+ h(IconSparkles, { size: 13 }),
2973
+ h('span', { className: 'dshm-explore-chip' }, t('exploreChip')),
2974
+ h('span', null, s.bootstrapNote))
2975
+ : null,
2976
+ h('div', { className: 'dshm-columns' },
2977
+ column('colToday', IconSparkles, sections.today || [],
2978
+ h('button', {
2979
+ type: 'button', className: 'dshm-chipbtn dshm-col-play',
2980
+ disabled: !(sections.today || []).length,
2981
+ onClick: () => playColumn(sections.today || []),
2982
+ }, h(IconPlay, { size: 12 }), t('playColumn'))),
2983
+ h('section', { className: 'dshm-column', key: 'colArtist' },
2984
+ h('div', { className: 'dshm-col-head' },
2985
+ h('div', { className: 'dshm-col-title' }, h(IconNote, { size: 14 }), t('colArtist')),
2986
+ h('span', { className: 'dshm-col-count' }, (sections.artist || []).length + ' ' + t('tracksUnit'))),
2987
+ h('div', { className: 'dshm-col-list' },
2988
+ (sections.artist || []).length === 0
2989
+ ? h('div', { className: 'dshm-lyrics-hint' }, t('recoSectionEmpty'))
2990
+ : (sections.artist || []).map((a, i) => h(ArtistTile, { key: i, t, a, onOpen: openArtistPage })))),
2991
+ column('colNew', IconDisc, sections.new || [],
2992
+ h('button', {
2993
+ type: 'button', className: 'dshm-chipbtn dshm-col-play',
2994
+ disabled: !(sections.new || []).length,
2995
+ onClick: () => playColumn(sections.new || []),
2996
+ }, h(IconPlay, { size: 12 }), t('playColumn')))));
2997
+ }
2998
+
2999
+ /* Shared artist profile block (intro / news / trivia / similar), reused by
3000
+ * the S2 drawer and the V3 full artist page. */
3001
+ function ArtistProfileSections({ t, data, onOpenArtist, artistImages, useArtistImages }) {
3002
+ if (!data) return null;
3003
+ const items = (list) => (list && list.length ? list : null);
3004
+ return h(React.Fragment, null,
3005
+ data.intro && data.intro.text
3006
+ ? h('section', { className: 'dshm-asec' },
3007
+ h('div', { className: 'dshm-asec-title' }, h(IconNote, { size: 13 }), t('artistIntro')),
3008
+ h('div', { className: 'dshm-acard' },
3009
+ h('div', { className: 'dshm-acard-text' }, data.intro.text),
3010
+ h(CiteMeta, { item: data.intro, t })))
3011
+ : null,
3012
+ h('section', { className: 'dshm-asec' },
3013
+ h('div', { className: 'dshm-asec-title' }, h(IconSparkles, { size: 13 }), t('artistNews')),
3014
+ items(data.news)
3015
+ ? data.news.map((n, i) => h('div', { className: 'dshm-acard', key: i },
3016
+ h('div', { className: 'dshm-acard-text' }, n.text),
3017
+ h(CiteMeta, { item: n, t })))
3018
+ : h('div', { className: 'dshm-lyrics-hint' }, (data && data.message) || t('noSection'))),
3019
+ h('section', { className: 'dshm-asec' },
3020
+ h('div', { className: 'dshm-asec-title' }, h(IconQueue, { size: 13 }), t('artistTrivia')),
3021
+ items(data.trivia)
3022
+ ? data.trivia.map((n, i) => h('div', { className: 'dshm-acard', key: i },
3023
+ h('div', { className: 'dshm-acard-text' }, n.text),
3024
+ h('div', { className: 'dshm-acard-meta' },
3025
+ n.kind ? h('span', { className: 'dshm-kind-chip' }, n.kind === 'rumor' ? t('kindRumor') : t('kindFact')) : null,
3026
+ h('span', null, (n.source || '') + (n.date ? ' · ' + n.date : '')),
3027
+ n.url ? h('a', { href: n.url, target: '_blank', rel: 'noreferrer noopener' }, t('citeLink')) : null)))
3028
+ : h('div', { className: 'dshm-lyrics-hint' }, t('noSection'))),
3029
+ h('section', { className: 'dshm-asec' },
3030
+ h('div', { className: 'dshm-asec-title' }, h(IconDisc, { size: 13 }), t('artistSimilarArtists')),
3031
+ items(data.similarArtists)
3032
+ ? data.similarArtists.map((s, i) => h('button', {
3033
+ key: i, type: 'button', className: 'dshm-sim-chip',
3034
+ title: s.reason || '', onClick: () => onOpenArtist(s.name),
3035
+ },
3036
+ h(ArtistAvatar, { name: s.name, size: 18, service: artistImages, useArtistImages }),
3037
+ h('span', null, s.name),
3038
+ s.reason ? h('span', { className: 'dshm-sim-chip-reason' }, s.reason) : null))
3039
+ : h('div', { className: 'dshm-lyrics-hint' }, t('noSection'))),
3040
+ items(data.similarSongs)
3041
+ ? h('section', { className: 'dshm-asec' },
3042
+ h('div', { className: 'dshm-asec-title' }, h(IconPlay, { size: 13 }), t('artistSimilarSongs')),
3043
+ data.similarSongs.map((s, i) => h('div', { className: 'dshm-acard', key: i },
3044
+ h('div', { className: 'dshm-acard-text' }, (s.title || '') + (s.artist ? ' · ' + s.artist : '')),
3045
+ s.reason ? h('div', { className: 'dshm-sim-chip-reason' }, s.reason) : null,
3046
+ h(CiteMeta, { item: s, t }))))
3047
+ : null);
3048
+ }
3049
+
3050
+ /* ================================================================
3051
+ * 11a2. Artist page (V3): profile + songs, play/preview + like
3052
+ * ================================================================ */
3053
+ function ArtistPageView({ t, reco, player, likes, preview, library, openView, openArtistPage, artistImages, useUi, useLikes, useLibrary, usePlayer, useArtistImages }) {
3054
+ const name = useUi((s) => s.artistName);
3055
+ const tracks = useLibrary((st) => st.tracks);
3056
+ const currentId = usePlayer((st) => (st.track ? st.track.id : null));
3057
+ const playing = usePlayer((st) => st.playing);
3058
+ const [st, setSt] = useState({ status: 'loading', data: null, error: null });
3059
+ const [notice, setNotice] = useState('');
3060
+ useEffect(() => {
3061
+ if (!name) return undefined;
3062
+ let dead = false;
3063
+ setSt({ status: 'loading', data: null, error: null });
3064
+ reco.artistPage(name)
3065
+ .then((data) => { if (!dead) setSt({ status: 'ready', data, error: null }); })
3066
+ .catch((err) => { if (!dead) setSt({ status: 'error', data: null, error: (err && err.message) || String(err) }); });
3067
+ return () => { dead = true; };
3068
+ }, [name]);
3069
+ function onPlaySong(item) {
3070
+ playSong(item, player, tracks, preview, setNotice, t);
3071
+ }
3072
+ function isCur(item) {
3073
+ const lc = (item.trackId && tracks.find((tr) => tr.id === item.trackId))
3074
+ || tracks.find((tr) => normalizeZh(tr.artist) === normalizeZh(item.artist) && normalizeZh(tr.title) === normalizeZh(item.title));
3075
+ return lc ? currentId === lc.id : currentId === ('preview:' + likeKey(item));
3076
+ }
3077
+ const data = st.data || {};
3078
+ const profile = data.profile || null;
3079
+ /* 横幅用专用 bannerUrl(适中尺寸,避免 10MB 原图白屏),头像用缩略图;
3080
+ * 兼容顶层字段与 profile 内嵌两种形态。 */
3081
+ const heroImg = data.bannerUrl || data.imageUrl || (profile && profile.imageUrl) || null;
3082
+ const thumbImg = data.thumbnailUrl || (profile && (profile.imageUrl || profile.thumbnailUrl)) || heroImg;
3083
+ const songs = data.songs || [];
3084
+ const ready = st.status === 'ready';
3085
+ /* Row click queues the whole artist song list and jumps to that song. */
3086
+ function playListFrom(list, item) {
3087
+ const localTracks = [];
3088
+ let at = 0;
3089
+ for (const it of list) {
3090
+ const lc = (it.trackId && tracks.find((tr) => tr.id === it.trackId))
3091
+ || tracks.find((tr) => normalizeZh(tr.artist) === normalizeZh(it.artist) && normalizeZh(tr.title) === normalizeZh(it.title));
3092
+ if (!lc || localTracks.some((tr) => tr.id === lc.id)) continue;
3093
+ if (it === item) at = localTracks.length;
3094
+ localTracks.push(lc);
3095
+ }
3096
+ if (localTracks.length) player.playTracks(localTracks, at);
3097
+ else if (list.length) onPlaySong(item || list[0]);
3098
+ }
3099
+ return h('div', { className: 'dshm-apage' },
3100
+ h('div', { className: 'dshm-toolbar dshm-toolbar-flat' },
3101
+ h('button', { type: 'button', className: 'dshm-chipbtn', onClick: () => openView('reco') }, '← ' + t('artistPageBack')),
3102
+ notice ? h('span', { className: 'dshm-mode-hint', style: { marginLeft: '8px' } }, notice) : null,
3103
+ library && ready ? h('button', {
3104
+ type: 'button', className: 'dshm-chipbtn', disabled: !songs.length,
3105
+ style: { marginLeft: 'auto' },
3106
+ title: t('playList'),
3107
+ onClick: () => playListFrom(songs, null),
3108
+ }, h(IconPlay, { size: 12 }), t('playList')) : null),
3109
+ st.status === 'loading'
3110
+ ? h('div', { className: 'dshm-state' },
3111
+ h('div', { className: 'dshm-state-icon' }, h(IconNote, { size: 30 })),
3112
+ h('div', { className: 'dshm-state-title' }, t('artistLoading')))
3113
+ : st.status === 'error'
3114
+ ? h(EmptyState, { icon: h(IconAlert, { size: 30 }), tone: 'error', title: t('artistError'), body: st.error || '' })
3115
+ : h(React.Fragment, null,
3116
+ h('div', { className: 'dshm-apage-banner', 'aria-hidden': true },
3117
+ heroImg
3118
+ ? h('img', {
3119
+ src: imgUrl(heroImg), alt: '', loading: 'lazy', draggable: false,
3120
+ onError: (e) => { e.currentTarget.style.display = 'none'; },
3121
+ })
3122
+ : null,
3123
+ h('div', { className: 'dshm-apage-banner-mask' }),
3124
+ h(IconNote, { size: 28 })),
3125
+ h('div', { className: 'dshm-apage-hero' },
3126
+ h('div', { className: 'dshm-apage-ava-wrap', 'aria-hidden': true },
3127
+ h(Thumb, { src: thumbImg, size: 96, round: true, glyph: IconNote })),
3128
+ h('div', { style: { minWidth: 0 } },
3129
+ h('h2', { className: 'dshm-apage-name dshm-ellipsis' }, name || ''),
3130
+ h('div', { className: 'dshm-count' }, songs.length + ' ' + t('artistSongs')))),
3131
+ profile
3132
+ ? h(ArtistProfileSections, { t, data: profile, onOpenArtist: openArtistPage, artistImages, useArtistImages })
3133
+ : null,
3134
+ h('section', { className: 'dshm-asec', style: { marginTop: '18px' } },
3135
+ h('div', { className: 'dshm-asec-title' }, h(IconPlay, { size: 13 }), t('artistSongs')),
3136
+ songs.length === 0
3137
+ ? h('div', { className: 'dshm-lyrics-hint' }, t('artistNoSongs'))
3138
+ : h('div', { className: 'dshm-col-list', style: { maxHeight: 'none' } },
3139
+ songs.map((item, i) => h(SongRow, {
3140
+ key: i, t, item, likes, useLikes,
3141
+ onPlay: (it) => playListFrom(songs, it), onOpenArtist: openArtistPage, showReason: false,
3142
+ isCurrent: isCur(item), playing,
3143
+ }))))));
3144
+ }
3145
+
3146
+ /* ================================================================
3147
+ * 11b. Spotify sync panel (S3): trigger + result chips
3148
+ * ================================================================ */
3149
+ function SyncPanel({ t, sync, useSync }) {
3150
+ const s = useSync((st) => st);
3151
+ if (s.phase === 'idle' && !s.result && !s.error) return null;
3152
+ const r = s.result || {};
3153
+ const chips = [
3154
+ ['syncCloud', r.cloud], ['syncAdded', r.added], ['syncRemoved', r.removed],
3155
+ ['syncOk', r.ok], ['syncFail', r.fail], ['syncMissing', r.missing],
3156
+ ];
3157
+ const problems = (s.tracks || []).filter((tr) => tr && (tr.status === 'fail' || tr.status === 'missing'));
3158
+ return h('div', { className: 'dshm-sync', role: 'status' },
3159
+ h('div', { className: 'dshm-asec-title' }, h(IconRefresh, { size: 13, className: s.phase === 'running' ? 'dshm-spin' : undefined }),
3160
+ s.phase === 'running' ? t('syncing') : s.phase === 'error' ? t('syncError') : t('syncBtn')),
3161
+ s.error ? h('div', { className: 'dshm-errorline', role: 'alert' }, h(IconAlert, { size: 14 }), s.error) : null,
3162
+ s.phase !== 'running' && s.result
3163
+ ? h('div', { className: 'dshm-sync-chips' },
3164
+ chips.map(([key, value]) => h('span', { className: 'dshm-sync-chip', key },
3165
+ t(key) + ' ' + (value == null ? '—' : value))))
3166
+ : null,
3167
+ problems.length
3168
+ ? h('div', { className: 'dshm-sync-detail' },
3169
+ problems.slice(0, 8).map((tr, i) => h('div', { key: i },
3170
+ (tr.status === 'fail' ? '✕ ' : '⚠ ') + (tr.artist || '') + ' - ' + (tr.title || '') + (tr.note ? '(' + tr.note + ')' : ''))),
3171
+ problems.length > 8 ? h('div', null, '… +' + (problems.length - 8)) : null)
3172
+ : null);
3173
+ }
3174
+
3175
+ /* ================================================================
3176
+ * 11c. History view (S3): plays, completion, skips
3177
+ * ================================================================ */
3178
+ function fmtDuration(sec) {
3179
+ const v = Math.max(0, Math.round(sec || 0));
3180
+ const hh = Math.floor(v / 3600), mm = Math.floor((v % 3600) / 60);
3181
+ return hh > 0 ? hh + ' 小时 ' + mm + ' 分' : mm + ' 分 ' + (v % 60) + ' 秒';
3182
+ }
3183
+
3184
+ function dayKeyOf(ts) {
3185
+ const d = new Date(ts || Date.now());
3186
+ return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
3187
+ }
3188
+
3189
+ function HistoryView({ t, history, player, openArtistPage, artistImages, useHistory, useLibrary, useArtistImages }) {
3190
+ const s = useHistory((st) => st);
3191
+ const [notice, setNotice] = useState('');
3192
+ const tracks = useLibrary ? useLibrary((st) => st.tracks) : [];
3193
+ useEffect(() => { history.load(50); }, []);
3194
+ const stats = s.stats;
3195
+ const coverOf = (ev) => {
3196
+ const tr = ev.trackId && tracks.find((x) => x.id === ev.trackId);
3197
+ return tr && tr.coverUrl ? tr.coverUrl : null;
3198
+ };
3199
+ const statCard = (label, value) => h('div', { className: 'dshm-stat', key: label },
3200
+ h('div', { className: 'dshm-stat-value dshm-ellipsis' }, value),
3201
+ h('div', { className: 'dshm-stat-label' }, label));
3202
+ const trackForTop = (it) => (it && ((it.trackId && tracks.find((x) => x.id === it.trackId)) || (it.id && tracks.find((x) => x.id === it.id)))) || null;
3203
+ const topTracks = [];
3204
+ for (const it of (stats && stats.topSongs) || []) {
3205
+ const tr = trackForTop(it);
3206
+ if (tr && !topTracks.some((x) => x.id === tr.id)) topTracks.push(tr);
3207
+ }
3208
+ const playTopSong = (it) => {
3209
+ const tr = trackForTop(it);
3210
+ if (!tr) return;
3211
+ const idx = topTracks.findIndex((x) => x.id === tr.id);
3212
+ player.playTracks(topTracks, idx >= 0 ? idx : 0);
3213
+ };
3214
+ const daily = (stats && stats.daily) || [];
3215
+ const maxPlays = Math.max(1, ...daily.map((d) => d.plays || 0));
3216
+ const statsBlock = stats
3217
+ ? h('div', { className: 'dshm-stats-wrap' },
3218
+ h('div', { className: 'dshm-stats' },
3219
+ statCard(t('statPlays'), String(stats.totalPlays || 0)),
3220
+ statCard(t('statSeconds'), fmtDuration(stats.totalSeconds)),
3221
+ statCard(t('statSongs'), String(stats.uniqueSongs || 0)),
3222
+ statCard(t('statArtists'), String(stats.uniqueArtists || 0)),
3223
+ statCard(t('statSkipped'), String(stats.skippedCount || 0)),
3224
+ statCard(t('statCompletion'), Math.round((stats.avgCompletion || 0) * 100) + '%')),
3225
+ h('div', { className: 'dshm-trend' },
3226
+ h('div', { className: 'dshm-asec-title' }, h(IconQueue, { size: 13 }), t('trendTitle')),
3227
+ h('div', { className: 'dshm-bars' }, daily.map((d, i) => h('div', { className: 'dshm-bar-col', key: i },
3228
+ h('div', { className: 'dshm-bar', title: (d.date || '') + ' · ' + (d.plays || 0) + ' ' + t('playsUnit'), style: { height: Math.max(3, Math.round(((d.plays || 0) / maxPlays) * 100)) + '%' } }),
3229
+ h('div', { className: 'dshm-bar-label' }, String(d.date || '').slice(5)))))),
3230
+ h('div', { className: 'dshm-tops' },
3231
+ h('div', { className: 'dshm-top-col' },
3232
+ h('div', { className: 'dshm-asec-title' }, h(IconNote, { size: 13 }), t('topSongs'),
3233
+ h('button', {
3234
+ type: 'button', className: 'dshm-chipbtn dshm-col-play', style: { marginLeft: 'auto' },
3235
+ disabled: topTracks.length === 0, title: t('playList'),
3236
+ onClick: () => player.playTracks(topTracks, 0),
3237
+ }, h(IconPlay, { size: 12 }), t('playList'))),
3238
+ ((stats.topSongs || []).length
3239
+ ? stats.topSongs.map((it, i) => {
3240
+ const tr = trackForTop(it);
3241
+ const play = () => { setNotice(''); playTopSong(it); };
3242
+ const explain = () => setNotice(t('topUnplayable'));
3243
+ return h('div', {
3244
+ className: cx('dshm-top-row', tr ? 'dshm-top-row-click' : 'dshm-top-row-off'), key: i,
3245
+ role: 'button', tabIndex: 0,
3246
+ 'aria-disabled': tr ? undefined : true,
3247
+ title: tr ? t('playTrack') : t('topUnplayable'),
3248
+ onClick: tr ? play : explain,
3249
+ onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); if (tr) play(); else explain(); } },
3250
+ },
3251
+ h('span', { className: 'dshm-top-rank' }, String(i + 1)),
3252
+ h('span', { className: 'dshm-ellipsis', style: { flex: 1 } }, (it.title || '') + (it.artist ? ' · ' + it.artist : '')),
3253
+ h('span', { className: 'dshm-count' }, (it.plays || 0) + ' ' + t('playsUnit')));
3254
+ })
3255
+ : h('div', { className: 'dshm-lyrics-hint' }, t('noSection')))),
3256
+ h('div', { className: 'dshm-top-col' },
3257
+ h('div', { className: 'dshm-asec-title' }, h(IconDisc, { size: 13 }), t('topArtists')),
3258
+ ((stats.topArtists || []).length
3259
+ ? stats.topArtists.map((it, i) => h('button', {
3260
+ key: i, type: 'button', className: 'dshm-top-row dshm-top-row-artist',
3261
+ title: t('artistOpen'), onClick: () => openArtistPage(it.name || ''),
3262
+ },
3263
+ h('span', { className: 'dshm-top-rank' }, String(i + 1)),
3264
+ h('span', { className: 'dshm-ellipsis', style: { flex: 1 } }, it.name || ''),
3265
+ h('span', { className: 'dshm-count' }, (it.plays || 0) + ' ' + t('playsUnit'))))
3266
+ : h('div', { className: 'dshm-lyrics-hint' }, t('noSection'))))))
3267
+ : null;
3268
+
3269
+ let list;
3270
+ if (s.status === 'loading' && s.events.length === 0) {
3271
+ list = h(React.Fragment, null,
3272
+ h('div', { className: 'dshm-lyrics-hint' }, t('historyLoading')),
3273
+ h(SkeletonRows));
3274
+ } else if (s.status === 'error' && s.events.length === 0) {
3275
+ list = h(EmptyState, {
3276
+ icon: h(IconAlert, { size: 30 }), tone: 'error',
3277
+ title: t('historyError'), body: s.error || '',
3278
+ }, h('button', { type: 'button', className: 'dshm-chipbtn', onClick: () => history.load(50) }, t('lyricsRetry')));
3279
+ } else if (s.events.length === 0) {
3280
+ list = h(EmptyState, { icon: h(IconQueue, { size: 30 }), title: t('historyEmpty') });
3281
+ } else {
3282
+ const groups = [];
3283
+ let last = null;
3284
+ for (const ev of s.events) {
3285
+ const k = dayKeyOf(ev.timestamp || Date.now());
3286
+ if (k !== last) { groups.push({ key: k, label: k, items: [] }); last = k; }
3287
+ groups[groups.length - 1].items.push(ev);
3288
+ }
3289
+ const trackById = (ev) => (ev && ev.trackId ? tracks.find((x) => x.id === ev.trackId) : null);
3290
+ const queue = [];
3291
+ for (const ev of s.events) {
3292
+ const tr = trackById(ev);
3293
+ if (tr && !queue.some((x) => x.id === tr.id)) queue.push(tr);
3294
+ }
3295
+ const playHistory = (ev) => {
3296
+ const tr = trackById(ev);
3297
+ if (!tr) return;
3298
+ const idx = queue.findIndex((x) => x.id === tr.id);
3299
+ player.playTracks(queue, idx >= 0 ? idx : 0);
3300
+ };
3301
+ list = h('div', { className: 'dshm-hlist' },
3302
+ h('div', { className: 'dshm-queue-head' }, h(IconQueue, { size: 14 }), t('historyTitle'),
3303
+ h('span', { className: 'dshm-count' }, s.total + ' ' + t('tracksUnit')),
3304
+ h('button', {
3305
+ type: 'button', className: 'dshm-chipbtn dshm-col-play', style: { marginLeft: 'auto' },
3306
+ disabled: queue.length === 0,
3307
+ title: t('playList'),
3308
+ onClick: () => player.playTracks(queue, 0),
3309
+ }, h(IconPlay, { size: 12 }), t('playList'))),
3310
+ groups.map((g) => h('section', { className: 'dshm-hgroup', key: g.key },
3311
+ h('div', { className: 'dshm-hgroup-label' },
3312
+ g.label,
3313
+ h('span', { className: 'dshm-count' }, g.items.length + ' ' + t('playsUnit'))),
3314
+ g.items.map((ev, i) => {
3315
+ const pct = Math.round((ev.completion || 0) * 100);
3316
+ const tone = pct >= 80 ? 'good' : pct >= 40 ? 'mid' : 'low';
3317
+ const tr = trackById(ev);
3318
+ return h('div', {
3319
+ className: cx('dshm-hrow', tr && 'dshm-hrow-click'), key: i,
3320
+ role: tr ? 'button' : undefined, tabIndex: tr ? 0 : undefined,
3321
+ title: tr ? t('playTrack') : undefined,
3322
+ onClick: tr ? () => playHistory(ev) : undefined,
3323
+ onKeyDown: tr ? (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); playHistory(ev); } } : undefined,
3324
+ },
3325
+ h(Thumb, { src: coverOf(ev), size: 40 }),
3326
+ h('div', { className: 'dshm-row-info' },
3327
+ h('div', { className: 'dshm-row-title dshm-ellipsis' }, ev.title || ev.trackId || ''),
3328
+ ev.artist
3329
+ ? h('button', {
3330
+ type: 'button', className: 'dshm-row-sub dshm-ellipsis dshm-row-sub-btn',
3331
+ title: t('artistOpen'), onClick: (e) => { e.stopPropagation(); openArtistPage(ev.artist); },
3332
+ },
3333
+ h(ArtistAvatar, { name: ev.artist, size: 16, service: artistImages, useArtistImages }),
3334
+ h('span', { className: 'dshm-ellipsis' }, ev.artist))
3335
+ : h('div', { className: 'dshm-row-sub dshm-ellipsis' }, '')),
3336
+ h('span', { className: 'dshm-hbadge dshm-hbadge-' + tone, title: t('historyComplete') }, pct + '%'),
3337
+ ev.skipped ? h('span', { className: 'dshm-hskip' }, t('historySkipped')) : h('span', null),
3338
+ h('span', { className: 'dshm-htime' },
3339
+ ev.timestamp ? new Date(ev.timestamp).toLocaleString(undefined, { hour: '2-digit', minute: '2-digit' }) : ''));
3340
+ }))));
3341
+ }
3342
+ return h('div', { className: 'dshm-history-page' },
3343
+ notice ? h('div', { className: 'dshm-mode-hint', role: 'status', style: { margin: '6px 8px 0' } }, notice) : null,
3344
+ statsBlock, list);
3345
+ }
3346
+
3347
+ /* ================================================================
3348
+ * 11b. Lyrics panel (S2): synced LRC highlight + auto-scroll
3349
+ * ================================================================ */
3350
+ function lyricsSourceLabel(source, t) {
3351
+ if (source === 'embedded') return t('lyricsSourceEmbedded');
3352
+ if (source === 'lrclib') return t('lyricsSourceLrclib');
3353
+ if (source === 'web') return t('lyricsSourceWeb');
3354
+ return source || '';
3355
+ }
3356
+
3357
+ function LyricsPanel({ t, lyrics, useLyrics, usePlayer }) {
3358
+ const track = usePlayer((s) => s.track);
3359
+ const position = usePlayer((s) => s.position);
3360
+ const trackId = track ? track.id : null;
3361
+ const snap = useLyrics((s) => (s.trackId === trackId ? s : null));
3362
+
3363
+ useEffect(() => { if (trackId) lyrics.load(trackId); }, [trackId]);
3364
+
3365
+ const scrollRef = useRef(null);
3366
+ const activeRef = useRef(null);
3367
+ const lines = snap && snap.data && snap.data.synced ? snap.data.lines : null;
3368
+ let activeIdx = -1;
3369
+ if (lines && lines.length) {
3370
+ for (let i = 0; i < lines.length; i++) {
3371
+ const tm = lines[i].time;
3372
+ if (tm == null) continue;
3373
+ if (position + 0.2 >= tm) activeIdx = i;
3374
+ else break;
3375
+ }
3376
+ }
3377
+ useEffect(() => {
3378
+ const el = activeRef.current, box = scrollRef.current;
3379
+ if (el && box) {
3380
+ box.scrollTo({
3381
+ top: el.offsetTop - box.clientHeight / 2 + el.clientHeight / 2,
3382
+ behavior: 'smooth',
3383
+ });
3384
+ }
3385
+ }, [activeIdx]);
3386
+
3387
+ if (!track || !snap) return null;
3388
+
3389
+ let body;
3390
+ if (snap.status === 'loading') {
3391
+ body = h('div', { className: 'dshm-lyrics-hint' }, t('lyricsLoading'));
3392
+ } else if (snap.status === 'error') {
3393
+ body = h(React.Fragment, null,
3394
+ h('div', { className: 'dshm-errorline', role: 'alert' }, h(IconAlert, { size: 14 }), t('lyricsError') + ':' + snap.error),
3395
+ h('button', { type: 'button', className: 'dshm-chipbtn', style: { alignSelf: 'flex-start', margin: '6px 10px 0' }, onClick: () => lyrics.load(trackId) }, t('lyricsRetry')));
3396
+ } else if (snap.data && snap.data.source === 'none') {
3397
+ body = h('div', { className: 'dshm-lyrics-hint' }, (snap.data.message || t('lyricsNone')));
3398
+ } else if (lines && lines.length) {
3399
+ body = h('div', { className: 'dshm-lyrics-scroll', ref: scrollRef },
3400
+ lines.map((line, i) => h('div', {
3401
+ key: i,
3402
+ ref: i === activeIdx ? activeRef : null,
3403
+ className: cx('dshm-lyric-line',
3404
+ i === activeIdx && 'dshm-lyric-line-active',
3405
+ i < activeIdx && 'dshm-lyric-line-past'),
3406
+ }, line.text || '♪')));
3407
+ } else if (snap.data && snap.data.plain) {
3408
+ body = h('div', { className: 'dshm-plain-lyrics' }, snap.data.plain);
3409
+ } else {
3410
+ body = h('div', { className: 'dshm-lyrics-hint' }, t('lyricsNone'));
3411
+ }
3412
+
3413
+ return h('section', { className: 'dshm-lyrics', 'aria-label': t('lyricsTitle') },
3414
+ h('div', { className: 'dshm-lyrics-head' },
3415
+ h(IconNote, { size: 14 }),
3416
+ t('lyricsTitle'),
3417
+ snap.data && snap.data.source && snap.data.source !== 'none'
3418
+ ? h('span', { className: 'dshm-source-chip' }, t('lyricsSource') + ' · ' + lyricsSourceLabel(snap.data.source, t))
3419
+ : null),
3420
+ body);
3421
+ }
3422
+
3423
+ /* ================================================================
3424
+ * 11c. Artist drawer (S2): intro / news / trivia / similar, cited
3425
+ * ================================================================ */
3426
+ function CiteMeta({ item, t }) {
3427
+ if (!item || (!item.source && !item.date && !item.url)) return null;
3428
+ return h('div', { className: 'dshm-acard-meta' },
3429
+ h('span', null, (item.source || t('citeSource')) + (item.date ? ' · ' + item.date : '')),
3430
+ item.url ? h('a', { href: item.url, target: '_blank', rel: 'noreferrer noopener' }, t('citeLink')) : null);
3431
+ }
3432
+
3433
+ /* ================================================================
3434
+ * 12. Music panel (main slot): header + tabs + per-view body
3435
+ * ================================================================ */
3436
+ function MusicPanel({ t, player, library, lyrics, reco, download, sync, history, likes, preview, openView, openArtistPage, setMiniHidden, ui, artistImages, onboarding, useUi, useLibrary, usePlayer, useLyrics, useReco, useDownload, useSync, useHistory, useLikes, usePreview, useArtistImages, useOnboarding }) {
3437
+ const view = useUi((s) => s.view);
3438
+ const welcomePreview = useUi((s) => s.welcomePreview);
3439
+ const onboardingSnap = useOnboarding((st) => st);
3440
+ const miniHidden = useUi((s) => s.miniHidden);
3441
+ const hasTrack = usePlayer((s) => !!s.track);
3442
+ const status = useLibrary((s) => s.status);
3443
+ const count = useLibrary((s) => s.tracks.length);
3444
+ const playing = usePlayer((s) => s.playing);
3445
+ const busy = status === 'loading';
3446
+
3447
+ if (view === 'welcome') {
3448
+ return h(WelcomeView, {
3449
+ t, onboarding, useOnboarding,
3450
+ preview: !!welcomePreview,
3451
+ onExitPreview: () => { ui.set({ welcomePreview: false, view: 'library' }); openView('library'); },
3452
+ onRoute: (target) => {
3453
+ ui.set({ welcomePreview: false });
3454
+ if (target === 'library') {
3455
+ library.load();
3456
+ setTimeout(() => library.load(), 1500);
3457
+ openView('library');
3458
+ } else openView('reco');
3459
+ },
3460
+ });
3461
+ }
3462
+
3463
+ const tabs = [
3464
+ { id: 'library', label: t('tabLibrary') },
3465
+ { id: 'reco', label: t('tabReco') },
3466
+ { id: 'now', label: t('tabNow'), dot: playing },
3467
+ { id: 'history', label: t('tabHistory') },
3468
+ ];
3469
+
3470
+ const body = view === 'library'
3471
+ ? h(LibraryView, { t, player, library, sync, download, preview, likes, openArtistPage, artistImages, useLikes, useSync, useDownload, useLibrary, usePlayer, useArtistImages })
3472
+ : view === 'reco'
3473
+ ? h(RecoView, { t, reco, download, player, library, likes, preview, history, openArtistPage, useReco, useDownload, useLibrary, useLikes, usePlayer, useHistory })
3474
+ : view === 'artist'
3475
+ ? h(ArtistPageView, { t, reco, player, likes, preview, library, openView, openArtistPage, artistImages, useUi, useLikes, useLibrary, usePlayer, useArtistImages })
3476
+ : view === 'history'
3477
+ ? h(HistoryView, { t, history, player, openArtistPage, artistImages, useHistory, useLibrary, useArtistImages })
3478
+ : h(NowPlayingView, { t, player, lyrics, usePlayer, useLyrics, openView, openArtistPage, artistImages, useArtistImages });
3479
+
3480
+ return h(React.Fragment, null,
3481
+ h('div', { className: 'dshm-panel' },
3482
+ h('header', { className: 'dshm-header' },
3483
+ h('div', { className: 'dshm-title-row' },
3484
+ h('h1', { className: 'dshm-title' }, t('panel')),
3485
+ h('span', { className: 'dshm-count' }, count > 0 ? count + ' ' + t('tracksUnit') : ''),
3486
+ h('div', { className: 'dshm-header-actions' },
3487
+ onboardingSnap && onboardingSnap.completed
3488
+ ? h('button', {
3489
+ type: 'button', className: 'dshm-chipbtn',
3490
+ title: t('welcomePreview'), onClick: () => ui.set({ view: 'welcome', welcomePreview: true }),
3491
+ }, h(IconSparkles, { size: 12 }), t('welcomePreview'))
3492
+ : null,
3493
+ h('button', {
3494
+ type: 'button', className: cx('dshm-chipbtn', !miniHidden && 'dshm-chipbtn-primary'),
3495
+ disabled: miniHidden && !hasTrack,
3496
+ title: miniHidden && !hasTrack ? t('miniNeedsTrack') : (miniHidden ? t('showMini') : t('hideMini')),
3497
+ onClick: () => setMiniHidden(miniHidden ? false : true),
3498
+ }, h(IconNote, { size: 14 }), miniHidden ? t('showMini') : t('hideMini')),
3499
+ h('button', {
3500
+ type: 'button', className: 'dshm-chipbtn', disabled: busy,
3501
+ onClick: () => library.rescan(),
3502
+ }, h(IconRefresh, { size: 14, className: busy ? 'dshm-spin' : undefined }), busy ? t('rescanning') : t('rescan')))),
3503
+ h('nav', { className: 'dshm-tabs', role: 'tablist', 'aria-label': t('panel') },
3504
+ tabs.map((tab) => h('button', {
3505
+ key: tab.id, type: 'button', role: 'tab',
3506
+ className: 'dshm-tab', 'aria-selected': view === tab.id,
3507
+ onClick: () => openView(tab.id),
3508
+ }, tab.label, tab.dot ? h('span', { className: 'dshm-tab-dot', 'aria-hidden': true }) : null)))),
3509
+ h('div', { className: 'dshm-body', role: 'tabpanel' }, body)));
3510
+ }
3511
+
3512
+ /* ================================================================
3513
+ * 13. Sidebar panel icon (sidebar.panellist owner props)
3514
+ * ================================================================ */
3515
+ function PanelIcon({ size, active }) {
3516
+ return h(IconNote, {
3517
+ size: size || 18,
3518
+ style: { color: active ? 'var(--dsw-alias-brand-text)' : 'currentColor', display: 'block' },
3519
+ });
3520
+ }
3521
+
3522
+ /* ================================================================
3523
+ * 14. Mini player (shell.overlay — mounted across navigation)
3524
+ * ================================================================ */
3525
+ function MiniPlayer({ t, player, lyrics, artistImages, usePlayer, useUi, useLyrics, useArtistImages, openNow, openArtistPage, setMiniHidden, setMiniCollapsed }) {
3526
+ const track = usePlayer((s) => s.track);
3527
+ const playing = usePlayer((s) => s.playing);
3528
+ const position = usePlayer((s) => s.position);
3529
+ const duration = usePlayer((s) => s.duration);
3530
+ const error = usePlayer((s) => s.error);
3531
+ const hidden = useUi((s) => s.miniHidden);
3532
+ const collapsed = useUi((s) => s.miniCollapsed);
3533
+ const shuffle = usePlayer((s) => s.shuffle);
3534
+ const repeat = usePlayer((s) => s.repeat);
3535
+ const mode = modeMeta(t, shuffle, repeat);
3536
+ const trackId = track ? track.id : null;
3537
+ const snap = useLyrics((s) => (s.trackId === trackId ? s : null));
3538
+ const [pos, setPos] = useState(() => readPrefs().miniPos || null);
3539
+ const [fabPos, setFabPos] = useState(() => readPrefs().miniFabPos || null);
3540
+ const [dragging, setDragging] = useState(false);
3541
+ const boxRef = useRef(null);
3542
+ const dragRef = useRef(null);
3543
+ const posRef = useRef(pos);
3544
+ posRef.current = pos;
3545
+ const fabRef = useRef(null);
3546
+ const fabDragRef = useRef(null);
3547
+ const fabPosRef = useRef(fabPos);
3548
+ fabPosRef.current = fabPos;
3549
+ const fabMoved = useRef(0);
3550
+
3551
+ useEffect(() => { if (trackId) lyrics.load(trackId); }, [trackId]);
3552
+
3553
+ /* Keep dragged positions inside the viewport when the window resizes. */
3554
+ useEffect(() => {
3555
+ if (typeof window === 'undefined') return undefined;
3556
+ const clampAll = () => {
3557
+ const cur = posRef.current;
3558
+ if (cur) {
3559
+ const el = boxRef.current;
3560
+ const w = el ? el.offsetWidth : 380, hh = el ? el.offsetHeight : 96;
3561
+ const next = {
3562
+ left: Math.max(0, Math.min(cur.left, window.innerWidth - w - 8)),
3563
+ top: Math.max(0, Math.min(cur.top, window.innerHeight - hh - 8)),
3564
+ };
3565
+ if (next.left !== cur.left || next.top !== cur.top) { setPos(next); writePrefs({ miniPos: next }); }
3566
+ }
3567
+ const fp = fabPosRef.current;
3568
+ if (fp) {
3569
+ const next = {
3570
+ left: Math.max(0, Math.min(fp.left, window.innerWidth - 56)),
3571
+ top: Math.max(0, Math.min(fp.top, window.innerHeight - 56)),
3572
+ };
3573
+ if (next.left !== fp.left || next.top !== fp.top) { setFabPos(next); writePrefs({ miniFabPos: next }); }
3574
+ }
3575
+ };
3576
+ clampAll();
3577
+ window.addEventListener('resize', clampAll);
3578
+ return () => window.removeEventListener('resize', clampAll);
3579
+ }, []);
3580
+
3581
+ if (!track) return null;
3582
+ /* Closed = gone until the panel's 「显示迷你播放条」 brings it back. */
3583
+ if (hidden) return null;
3584
+
3585
+ /* ---------------- collapsed: circular floating badge ---------------- */
3586
+ if (collapsed) {
3587
+ const onFabDown = (e) => {
3588
+ const el = fabRef.current;
3589
+ if (!el) return;
3590
+ e.preventDefault();
3591
+ const box = el.getBoundingClientRect();
3592
+ fabDragRef.current = { px: e.clientX, py: e.clientY, left: box.left, top: box.top };
3593
+ fabMoved.current = 0;
3594
+ try { el.setPointerCapture(e.pointerId); } catch { /* unsupported */ }
3595
+ };
3596
+ const onFabMove = (e) => {
3597
+ const d = fabDragRef.current;
3598
+ if (!d) return;
3599
+ const dx = e.clientX - d.px, dy = e.clientY - d.py;
3600
+ fabMoved.current = Math.max(fabMoved.current, Math.abs(dx) + Math.abs(dy));
3601
+ if (fabMoved.current < 3) return;
3602
+ const next = {
3603
+ left: Math.max(0, Math.min(d.left + dx, window.innerWidth - 56)),
3604
+ top: Math.max(0, Math.min(d.top + dy, window.innerHeight - 56)),
3605
+ };
3606
+ fabPosRef.current = next;
3607
+ setFabPos(next);
3608
+ };
3609
+ const onFabUp = (e) => {
3610
+ if (!fabDragRef.current) return;
3611
+ fabDragRef.current = null;
3612
+ if (fabMoved.current < 5) { setMiniCollapsed(false); return; }
3613
+ if (fabPosRef.current) writePrefs({ miniFabPos: fabPosRef.current });
3614
+ try { if (fabRef.current) fabRef.current.releasePointerCapture(e.pointerId); } catch { /* released */ }
3615
+ };
3616
+ const fabStyle = fabPos ? { left: fabPos.left, top: fabPos.top, right: 'auto', bottom: 'auto' } : undefined;
3617
+ return portalToBody(h('div', {
3618
+ ref: fabRef, style: fabStyle,
3619
+ className: cx('dshm-mini-fab', dragging && 'dshm-mini-fab-dragging'),
3620
+ role: 'button', tabIndex: 0,
3621
+ title: t('miniExpand'), 'aria-label': t('miniExpand'),
3622
+ onPointerDown: onFabDown, onPointerMove: onFabMove,
3623
+ onPointerUp: onFabUp, onPointerCancel: onFabUp,
3624
+ onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setMiniCollapsed(false); } },
3625
+ },
3626
+ h(Thumb, { src: track.coverUrl, size: 48, round: true, glyph: IconNote }),
3627
+ h('span', { className: 'dshm-mini-fab-badge', 'aria-hidden': true },
3628
+ h(playing ? IconPause : IconPlay, { size: 11 }))));
3629
+ }
3630
+
3631
+ /* ---------------- expanded: the full mini bar ---------------- */
3632
+ const gripDown = (e) => {
3633
+ const el = boxRef.current;
3634
+ if (!el) return;
3635
+ e.preventDefault();
3636
+ const box = el.getBoundingClientRect();
3637
+ dragRef.current = { px: e.clientX, py: e.clientY, left: box.left, top: box.top, w: box.width, h: box.height };
3638
+ setDragging(true);
3639
+ try { el.setPointerCapture(e.pointerId); } catch { /* unsupported */ }
3640
+ };
3641
+ const gripMove = (e) => {
3642
+ const d = dragRef.current;
3643
+ if (!d) return;
3644
+ const next = {
3645
+ left: Math.max(0, Math.min(d.left + (e.clientX - d.px), window.innerWidth - d.w - 8)),
3646
+ top: Math.max(0, Math.min(d.top + (e.clientY - d.py), window.innerHeight - d.h - 8)),
3647
+ };
3648
+ posRef.current = next;
3649
+ setPos(next);
3650
+ };
3651
+ const gripUp = (e) => {
3652
+ if (!dragRef.current) return;
3653
+ dragRef.current = null;
3654
+ setDragging(false);
3655
+ if (posRef.current) writePrefs({ miniPos: posRef.current });
3656
+ try { if (boxRef.current) boxRef.current.releasePointerCapture(e.pointerId); } catch { /* released */ }
3657
+ };
3658
+
3659
+ const frac = duration > 0 ? Math.min(1, position / duration) : 0;
3660
+ const lines = snap && snap.data && snap.data.synced ? snap.data.lines : null;
3661
+ let activeIdx = -1;
3662
+ if (lines) {
3663
+ for (let i = 0; i < lines.length; i++) {
3664
+ if (lines[i].time == null) continue;
3665
+ if (position + 0.2 >= lines[i].time) activeIdx = i;
3666
+ else break;
3667
+ }
3668
+ }
3669
+ const win = [];
3670
+ if (lines && lines.length) {
3671
+ const start = activeIdx < 0 ? 0 : Math.max(0, Math.min(activeIdx - 1, lines.length - 3));
3672
+ for (let i = start; i < Math.min(lines.length, start + 3); i++) win.push({ i, text: lines[i].text || '♪' });
3673
+ }
3674
+ const style = pos ? { left: pos.left, top: pos.top, right: 'auto', bottom: 'auto' } : undefined;
3675
+ const activeLine = activeIdx >= 0 && lines && lines[activeIdx] ? (lines[activeIdx].text || '♪') : '';
3676
+ const artistBtn = h('button', {
3677
+ type: 'button', className: 'dshm-mini-artist',
3678
+ title: t('artistOpen'), 'aria-label': t('artistOpen'),
3679
+ onClick: (e) => { e.stopPropagation(); openArtistPage(track.artist || ''); },
3680
+ },
3681
+ track.artist
3682
+ ? h(ArtistAvatar, { name: track.artist, size: 14, service: artistImages, useArtistImages })
3683
+ : null,
3684
+ h('span', { className: 'dshm-ellipsis' }, error ? t('playError') : (track.artist || t('unknownArtist'))));
3685
+
3686
+ return portalToBody(h('div', {
3687
+ ref: boxRef, style,
3688
+ className: cx('dshm-mini', dragging && 'dshm-mini-dragging'),
3689
+ role: 'region', 'aria-label': t('miniLabel'),
3690
+ },
3691
+ h('div', {
3692
+ className: 'dshm-mini-grip', role: 'button', tabIndex: 0,
3693
+ title: t('miniDrag'), 'aria-label': t('miniDrag'),
3694
+ onPointerDown: gripDown, onPointerMove: gripMove,
3695
+ onPointerUp: gripUp, onPointerCancel: gripUp,
3696
+ onKeyDown: (e) => {
3697
+ const step = 12;
3698
+ const cur = posRef.current || (boxRef.current ? { left: boxRef.current.getBoundingClientRect().left, top: boxRef.current.getBoundingClientRect().top } : { left: 0, top: 0 });
3699
+ const dl = e.key === 'ArrowLeft' ? -step : e.key === 'ArrowRight' ? step : 0;
3700
+ const dt = e.key === 'ArrowUp' ? -step : e.key === 'ArrowDown' ? step : 0;
3701
+ if (!dl && !dt) return;
3702
+ e.preventDefault();
3703
+ const next = { left: Math.max(0, cur.left + dl), top: Math.max(0, cur.top + dt) };
3704
+ setPos(next);
3705
+ writePrefs({ miniPos: next });
3706
+ },
3707
+ }, h(IconGrip, { size: 14 })),
3708
+ h('div', { className: 'dshm-mini-inner' },
3709
+ h('button', {
3710
+ type: 'button', className: 'dshm-mini-main',
3711
+ onClick: openNow, title: t('openNow'), 'aria-label': t('openNow'),
3712
+ },
3713
+ h(Cover, { track, size: 36 }),
3714
+ h('span', { className: 'dshm-mini-text' },
3715
+ h('span', { className: 'dshm-mini-title dshm-ellipsis' }, track.title),
3716
+ artistBtn)),
3717
+ h('div', { className: 'dshm-mini-controls' },
3718
+ h(IconButton, { label: t('prev'), onClick: () => player.prev() }, h(IconPrev, { size: 15 })),
3719
+ h(IconButton, {
3720
+ label: playing ? t('pause') : t('play'), className: 'dshm-mini-play',
3721
+ onClick: () => player.toggle(),
3722
+ }, h(playing ? IconPause : IconPlay, { size: 16 })),
3723
+ h(IconButton, { label: t('next'), onClick: () => player.next() }, h(IconNext, { size: 15 })),
3724
+ h(IconButton, {
3725
+ label: mode.label, title: mode.hint + ' · ' + t('modeCycleHint'),
3726
+ className: cx((shuffle || repeat === 'one') && 'dshm-iconbtn-active'),
3727
+ onClick: () => player.cycleMode(),
3728
+ }, h(mode.icon, { size: 15 })),
3729
+ h(IconButton, {
3730
+ label: t('miniCollapse'), title: t('miniCollapse'),
3731
+ onClick: () => setMiniCollapsed(true),
3732
+ }, h(IconChevronDown, { size: 15 })),
3733
+ h(IconButton, { label: t('hideMini'), title: t('hideMini'), onClick: () => setMiniHidden(true) }, h(IconClose, { size: 13 })))),
3734
+ h('div', { className: 'dshm-mini-seek' },
3735
+ h(Slider, {
3736
+ value: frac, label: t('seekLabel'), disabled: !(duration > 0),
3737
+ onChange: (f) => player.seek(f * duration),
3738
+ })),
3739
+ win.length
3740
+ ? h('div', { className: 'dshm-mini-lyrics', 'aria-label': t('miniLyrics') },
3741
+ win.map((ln) => h('div', {
3742
+ key: ln.i,
3743
+ className: cx('dshm-mini-lyric', ln.i === activeIdx && 'dshm-mini-lyric-on'),
3744
+ title: ln.text,
3745
+ }, ln.text)))
3746
+ : null));
3747
+ }
3748
+
3749
+ /* ================================================================
3750
+ * 15. Plugin body
3751
+ * ================================================================ */
3752
+ const inject = ['slots', 'locale', 'layout'];
3753
+
3754
+ function apply(ctx) {
3755
+ ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-music: dictionaries');
3756
+ const t = ctx.locale.bind(NS);
3757
+
3758
+ const api = createHostApi(t);
3759
+ const library = createLibrary(api);
3760
+ const lyricsService = createLyricsService(api);
3761
+ const artistService = createArtistService(api);
3762
+ const artistImageService = createArtistImageService(api);
3763
+ const onboardingService = createOnboardingService(api);
3764
+ const recoService = createRecoService(api);
3765
+ const downloadService = createDownloadService(api);
3766
+ const syncService = createSyncService(api);
3767
+ const historyService = createHistoryService(api);
3768
+ const player = createPlayer(t, api);
3769
+ const previewService = createPreviewService(api);
3770
+ const likesService = createLikesService(api, () => downloadService.warm());
3771
+ ctx.effect(() => () => {
3772
+ downloadService.dispose();
3773
+ syncService.dispose();
3774
+ previewService.dispose();
3775
+ }, 'dsh-music: s3 poll timers');
3776
+ downloadService.warm();
3777
+ syncService.warm();
3778
+ /* First run: open the welcome flow only when the host explicitly says the
3779
+ * flow is not completed (a missing endpoint must never interrupt users). */
3780
+ onboardingService.load().then((data) => {
3781
+ if (data && data.completed === false) ui.set({ view: 'welcome' });
3782
+ });
3783
+ ctx.effect(() => () => onboardingService.dispose(), 'dsh-music: onboarding timer');
3784
+ /* v6 mini-window semantics changed: close now means "hidden until shown".
3785
+ * One-time prefs migration makes the mini player visible by default for
3786
+ * users whose stored prefs come from the old floating-ball behaviour. */
3787
+ const savedPrefs = readPrefs();
3788
+ const miniPrefsOk = savedPrefs.miniVersion === 2;
3789
+ if (!miniPrefsOk) writePrefs({ miniVersion: 2, miniHidden: false, miniCollapsed: false });
3790
+ const ui = createStore({
3791
+ view: 'library',
3792
+ miniHidden: miniPrefsOk ? !!savedPrefs.miniHidden : false,
3793
+ miniCollapsed: miniPrefsOk ? !!savedPrefs.miniCollapsed : false,
3794
+ artistName: null,
3795
+ welcomePreview: false,
3796
+ });
3797
+ const openView = (view) => ui.set({ view });
3798
+ const openArtistPage = (name) => ui.set({ view: 'artist', artistName: name });
3799
+ const setMiniHidden = (hidden) => {
3800
+ /* Showing the mini player always restores the full bar (fab -> bar). */
3801
+ ui.set(hidden ? { miniHidden: true } : { miniHidden: false, miniCollapsed: false });
3802
+ writePrefs(hidden ? { miniHidden: true } : { miniHidden: false, miniCollapsed: false });
3803
+ };
3804
+ const setMiniCollapsed = (collapsed) => {
3805
+ ui.set({ miniCollapsed: collapsed });
3806
+ writePrefs({ miniCollapsed: collapsed });
3807
+ };
3808
+
3809
+ ctx.effect(() => () => player.dispose(), 'dsh-music: player engine');
3810
+
3811
+ ctx.effect(() => {
3812
+ if (typeof document === 'undefined') return () => {};
3813
+ const el = document.createElement('style');
3814
+ el.setAttribute('data-dsh-music', '');
3815
+ el.textContent = CSS;
3816
+ document.head.appendChild(el);
3817
+ return () => { el.remove(); };
3818
+ }, 'dsh-music: styles');
3819
+
3820
+ // Sidebar entry: global "音乐" panel icon.
3821
+ ctx.effect(() => ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
3822
+ name: 'sidebar.panellist',
3823
+ id: PANEL_ID,
3824
+ order: 30,
3825
+ label: () => t('panel'),
3826
+ locale: NS,
3827
+ }, PanelIcon)), 'dsh-music: sidebar entry');
3828
+
3829
+ // Main panel keyed by the same id.
3830
+ ctx.effect(() => ctx.slots.inject('main', () => ctx.slots.register({
3831
+ name: 'main',
3832
+ key: PANEL_ID,
3833
+ locale: NS,
3834
+ inject: () => ({
3835
+ player, library, lyrics: lyricsService, artist: artistService, artistImages: artistImageService, onboarding: onboardingService,
3836
+ reco: recoService, download: downloadService, sync: syncService, history: historyService,
3837
+ likes: likesService, preview: previewService,
3838
+ openView, openArtistPage, setMiniHidden, ui,
3839
+ hooks: {
3840
+ player: player.source, library: library.source, ui,
3841
+ lyrics: lyricsService.source, artist: artistService.source, artistImages: artistImageService.source, onboarding: onboardingService.source,
3842
+ reco: recoService.source, download: downloadService.source,
3843
+ sync: syncService.source, history: historyService.source,
3844
+ likes: likesService.source, preview: previewService.source,
3845
+ },
3846
+ }),
3847
+ }, MusicPanel)), 'dsh-music: main panel');
3848
+
3849
+ // Persistent mini player above every column.
3850
+ ctx.effect(() => ctx.slots.inject('shell.overlay', () => ctx.slots.register({
3851
+ name: 'shell.overlay',
3852
+ id: 'dsh-music.mini-player',
3853
+ locale: NS,
3854
+ inject: () => ({
3855
+ player, lyrics: lyricsService, artistImages: artistImageService, setMiniHidden, setMiniCollapsed,
3856
+ openNow: () => { openView('now'); ctx.layout.selectPanel(PANEL_ID); },
3857
+ openArtistPage: (name) => { if (!name) return; openArtistPage(name); ctx.layout.selectPanel(PANEL_ID); },
3858
+ hooks: { player: player.source, ui, lyrics: lyricsService.source, artistImages: artistImageService.source },
3859
+ }),
3860
+ }, MiniPlayer)), 'dsh-music: mini player');
3861
+
3862
+ // Warm the library so the panel opens populated; errors surface in-view.
3863
+ library.load();
3864
+ }
3865
+
3866
+ return { inject, apply };
3867
+ },
3868
+ });