@madeinbruno/music-plug 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/dist/index.d.ts +47 -1
- package/dist/index.js +59 -0
- package/dist/player.d.ts +56 -4
- package/dist/player.js +292 -59
- package/package.json +1 -1
- package/styles.css +199 -5
package/README.md
CHANGED
|
@@ -58,11 +58,33 @@ export default async function Post({ music }: { music: string }) {
|
|
|
58
58
|
|
|
59
59
|
곡 줄은 둘러싼 글의 색을 따르고, 듣기 플러그 창은 Music plug 색이에요. 멈추기 단추의 바탕은 `--mp-ground`로 바꿀 수 있어요.
|
|
60
60
|
|
|
61
|
+
## 곡 고르기 (쓰는 사람 화면)
|
|
62
|
+
|
|
63
|
+
인스타그램처럼 곡을 검색해서 고르는 칸이에요. form 안에 두면 고른 곡이 숨은 입력(`name`)에 JSON으로 들어가요.
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
'use client';
|
|
67
|
+
import { SongField } from '@madeinbruno/music-plug/player';
|
|
68
|
+
|
|
69
|
+
<SongField name="musicSong" defaultValue={saved ?? null} placeholder="테마 음악 (곡 이름이나 가수)" />
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// 저장할 때 (서버)
|
|
74
|
+
import { readPickedSong } from '@madeinbruno/music-plug';
|
|
75
|
+
const song = readPickedSong(form.get('musicSong')); // 믿을 수 있는 모양만 남긴다. 없으면 null
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- 치면 Music plug(`/api/search`, Apple 목록)에서 찾아 앨범 그림과 함께 보여 주고, ▶로 30초 미리 들을 수 있어요.
|
|
79
|
+
- 고르면 Music plug(`/api/match`)가 그 곡의 유튜브 영상을 찾아 같이 담아요 (`youtube.id`). 글 화면에서는 `<PlugPlayer song={...} youtube={song.youtube} source={{ service: 'apple', url: song.apple }} />`처럼 쓰면 YouTube는 글 안에서 무료로, Apple Music은 그 곡으로 바로 열어요.
|
|
80
|
+
- 고른 곡: `PickedSong` = `{ title, artist, album?, artwork?, apple?, youtube?: { id } }`. 따로 부르려면 `searchSongs(q)`, `matchYoutube(song)`.
|
|
81
|
+
|
|
61
82
|
## Music plug 쪽
|
|
62
83
|
|
|
63
84
|
듣기 플러그의 본체는 Music plug 앱(`apps/music-plug`)에 있어요.
|
|
64
85
|
- `/listen?t=제목&a=가수[&v=유튜브번호][&start=초][&pick=1]`: 어디서 들을지 고르는 화면. 전에 고른 곳이 있으면 바로 그곳으로 (`pick=1`이면 다시 고른다). 공유받은 플레이리스트의 곡마다 붙은 '듣기'도 여기로 와요.
|
|
65
86
|
- `/api/song?url=곡링크`: 곡 링크 하나로 제목·가수를 읽어 줘요 (`src/server/song`). `songFromUrl`이 불러요.
|
|
87
|
+
- `/api/search?q=…`: 곡 검색 (Apple iTunes 검색, 하루 캐시). `/api/match?t=제목&a=가수`: 그 곡의 유튜브 영상 찾기 (YouTube Data API, Music plug 환경변수 `YOUTUBE_API_KEY`, 하루 약 100곡, 같은 곡은 30일 캐시, madeinbruno.com 아래 화면에서만).
|
|
66
88
|
- `/listen/go?s=고른곳&…[&remember=1]`: 그곳에서 이 곡을 찾아 보내요 (`src/server/listen.ts`). `remember=1`이면 고른 곳을 기억해요.
|
|
67
89
|
|
|
68
90
|
## 개발
|
package/dist/index.d.ts
CHANGED
|
@@ -99,5 +99,51 @@ declare function linkService(input: string | null | undefined): ServiceId | null
|
|
|
99
99
|
declare function songFromUrl(input: string | null | undefined, { base }?: {
|
|
100
100
|
base?: string | undefined;
|
|
101
101
|
}): Promise<SongLink | null>;
|
|
102
|
+
/**
|
|
103
|
+
* 곳마다 직접 정해 둔 곡 링크 (예: { melon: 'https://www.melon.com/song/detail.htm?songId=…', apple: '…' }).
|
|
104
|
+
* 곡을 못 찾아 곡까지 가지 않는 곳이 있을 때, 쓰는 사람이 그곳의 곡 링크를 직접 정해 둔다. 정해 둔 곳은 찾지 않고 그 링크를 연다.
|
|
105
|
+
*/
|
|
106
|
+
type SongLinks = Partial<Record<ServiceId, string>>;
|
|
107
|
+
/** 곡 링크를 직접 정할 수 있는 곳 (YouTube는 테마 음악의 유튜브 영상을 쓰므로 뺀다) */
|
|
108
|
+
declare const LINKABLE_SERVICES: ServiceId[];
|
|
109
|
+
/**
|
|
110
|
+
* 받은 링크들에서 그곳의 곡 링크가 맞는 것만 남긴다 (폼·저장된 값을 믿지 않고 거른다). 남은 게 없으면 null.
|
|
111
|
+
* 글과 함께 복사된 것("제목 https://…")이면 주소만 남긴다.
|
|
112
|
+
*/
|
|
113
|
+
declare function cleanSongLinks(input: unknown): SongLinks | null;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 곡 고르기(SongField)로 고른 곡. 글에 그대로 저장한다.
|
|
117
|
+
* - youtube: 고를 때 Music plug가 찾아 준 유튜브 영상 (있으면 글 안에서 무료로 바로 튼다)
|
|
118
|
+
* - apple: Apple Music 곡 주소 (듣는 사람이 Apple Music을 고르면 찾지 않고 바로 연다)
|
|
119
|
+
*/
|
|
120
|
+
type PickedSong = {
|
|
121
|
+
title: string;
|
|
122
|
+
artist: string;
|
|
123
|
+
album?: string;
|
|
124
|
+
artwork?: string;
|
|
125
|
+
apple?: string;
|
|
126
|
+
youtube?: {
|
|
127
|
+
id: string;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
/** 곡 검색 결과 한 줄 (미리 듣기는 고르는 동안만 쓴다) */
|
|
131
|
+
type FoundSong = Omit<PickedSong, 'youtube'> & {
|
|
132
|
+
preview?: string;
|
|
133
|
+
};
|
|
134
|
+
/** 저장해 둔 값(JSON)을 믿을 수 있는 모양으로 (모르는 것은 버린다). 곡 제목이 없으면 null */
|
|
135
|
+
declare function readPickedSong(value: unknown): PickedSong | null;
|
|
136
|
+
/** Music plug 곡 검색 (/api/search) */
|
|
137
|
+
declare function searchSongs(query: string, { base, signal }?: {
|
|
138
|
+
base?: string;
|
|
139
|
+
signal?: AbortSignal;
|
|
140
|
+
}): Promise<FoundSong[]>;
|
|
141
|
+
/** 고른 곡의 유튜브 영상 찾기 (/api/match). 못 찾으면 null */
|
|
142
|
+
declare function matchYoutube(song: {
|
|
143
|
+
title: string;
|
|
144
|
+
artist: string;
|
|
145
|
+
}, { base }?: {
|
|
146
|
+
base?: string | undefined;
|
|
147
|
+
}): Promise<string | null>;
|
|
102
148
|
|
|
103
|
-
export { MUSIC_PLUG_URL, SERVICES, type Service, type ServiceId, type Song, type SongLink, cleanTitle, getService, linkService, listenGoUrl, listenPageUrl, songFromUrl, songFromVideo, songFromYoutube, songQuery, youtubeId, youtubeStart };
|
|
149
|
+
export { type FoundSong, LINKABLE_SERVICES, MUSIC_PLUG_URL, type PickedSong, SERVICES, type Service, type ServiceId, type Song, type SongLink, type SongLinks, cleanSongLinks, cleanTitle, getService, linkService, listenGoUrl, listenPageUrl, matchYoutube, readPickedSong, searchSongs, songFromUrl, songFromVideo, songFromYoutube, songQuery, youtubeId, youtubeStart };
|
package/dist/index.js
CHANGED
|
@@ -146,14 +146,73 @@ async function songFromUrl(input, { base = MUSIC_PLUG_URL } = {}) {
|
|
|
146
146
|
}
|
|
147
147
|
return { service, url: url.href, song: null };
|
|
148
148
|
}
|
|
149
|
+
var LINKABLE_SERVICES = ["melon", "genie", "bugs", "flo", "vibe", "spotify", "apple", "youtube"];
|
|
150
|
+
function cleanSongLinks(input) {
|
|
151
|
+
if (!input || typeof input !== "object") return null;
|
|
152
|
+
const out = {};
|
|
153
|
+
for (const id of LINKABLE_SERVICES) {
|
|
154
|
+
const raw = input[id];
|
|
155
|
+
if (typeof raw !== "string") continue;
|
|
156
|
+
const url = firstUrl(raw.slice(0, 1e3));
|
|
157
|
+
if (url && linkService(url.href) === id) out[id] = url.href;
|
|
158
|
+
}
|
|
159
|
+
return Object.keys(out).length ? out : null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/picked.ts
|
|
163
|
+
var str = (v, max) => typeof v === "string" && v.trim() ? v.trim().slice(0, max) : void 0;
|
|
164
|
+
var https = (v) => typeof v === "string" && v.startsWith("https://") && v.length < 1e3 ? v : void 0;
|
|
165
|
+
function readPickedSong(value) {
|
|
166
|
+
let v = value;
|
|
167
|
+
if (typeof v === "string") {
|
|
168
|
+
try {
|
|
169
|
+
v = JSON.parse(v);
|
|
170
|
+
} catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (!v || typeof v !== "object") return null;
|
|
175
|
+
const o = v;
|
|
176
|
+
const title = str(o.title, 200);
|
|
177
|
+
if (!title) return null;
|
|
178
|
+
const yt = o.youtube?.id;
|
|
179
|
+
return {
|
|
180
|
+
title,
|
|
181
|
+
artist: str(o.artist, 200) ?? "",
|
|
182
|
+
...str(o.album, 200) ? { album: str(o.album, 200) } : {},
|
|
183
|
+
...https(o.artwork) ? { artwork: https(o.artwork) } : {},
|
|
184
|
+
...https(o.apple)?.startsWith("https://music.apple.com/") ? { apple: https(o.apple) } : {},
|
|
185
|
+
...typeof yt === "string" && /^[\w-]{11}$/.test(yt) ? { youtube: { id: yt } } : {}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
async function searchSongs(query, { base = MUSIC_PLUG_URL, signal } = {}) {
|
|
189
|
+
const res = await fetch(`${base}/api/search?q=${encodeURIComponent(query)}`, { signal });
|
|
190
|
+
const data = await res.json().catch(() => null);
|
|
191
|
+
if (!res.ok || !data?.songs) throw new Error(data?.error ?? "\uC9C0\uAE08\uC740 \uCC3E\uC9C0 \uBABB\uD588\uC5B4\uC694");
|
|
192
|
+
return data.songs;
|
|
193
|
+
}
|
|
194
|
+
async function matchYoutube(song, { base = MUSIC_PLUG_URL } = {}) {
|
|
195
|
+
try {
|
|
196
|
+
const res = await fetch(`${base}/api/match?t=${encodeURIComponent(song.title)}&a=${encodeURIComponent(song.artist)}`);
|
|
197
|
+
const data = await res.json();
|
|
198
|
+
return typeof data.youtube === "string" && /^[\w-]{11}$/.test(data.youtube) ? data.youtube : null;
|
|
199
|
+
} catch {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
149
203
|
export {
|
|
204
|
+
LINKABLE_SERVICES,
|
|
150
205
|
MUSIC_PLUG_URL,
|
|
151
206
|
SERVICES,
|
|
207
|
+
cleanSongLinks,
|
|
152
208
|
cleanTitle,
|
|
153
209
|
getService,
|
|
154
210
|
linkService,
|
|
155
211
|
listenGoUrl,
|
|
156
212
|
listenPageUrl,
|
|
213
|
+
matchYoutube,
|
|
214
|
+
readPickedSong,
|
|
215
|
+
searchSongs,
|
|
157
216
|
songFromUrl,
|
|
158
217
|
songFromVideo,
|
|
159
218
|
songFromYoutube,
|
package/dist/player.d.ts
CHANGED
|
@@ -21,6 +21,54 @@ type Song = {
|
|
|
21
21
|
artist: string;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* 곳마다 직접 정해 둔 곡 링크 (예: { melon: 'https://www.melon.com/song/detail.htm?songId=…', apple: '…' }).
|
|
26
|
+
* 곡을 못 찾아 곡까지 가지 않는 곳이 있을 때, 쓰는 사람이 그곳의 곡 링크를 직접 정해 둔다. 정해 둔 곳은 찾지 않고 그 링크를 연다.
|
|
27
|
+
*/
|
|
28
|
+
type SongLinks = Partial<Record<ServiceId, string>>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 곡 고르기(SongField)로 고른 곡. 글에 그대로 저장한다.
|
|
32
|
+
* - youtube: 고를 때 Music plug가 찾아 준 유튜브 영상 (있으면 글 안에서 무료로 바로 튼다)
|
|
33
|
+
* - apple: Apple Music 곡 주소 (듣는 사람이 Apple Music을 고르면 찾지 않고 바로 연다)
|
|
34
|
+
*/
|
|
35
|
+
type PickedSong = {
|
|
36
|
+
title: string;
|
|
37
|
+
artist: string;
|
|
38
|
+
album?: string;
|
|
39
|
+
artwork?: string;
|
|
40
|
+
apple?: string;
|
|
41
|
+
youtube?: {
|
|
42
|
+
id: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 곡 고르기: 인스타그램처럼 곡을 검색해서 고른다 (쓰는 사람 화면).
|
|
48
|
+
*
|
|
49
|
+
* ♪ [곡 이름이나 가수 ]
|
|
50
|
+
* [앨범] 밤편지 ▶
|
|
51
|
+
* 아이유 · Palette
|
|
52
|
+
*
|
|
53
|
+
* - 치면 Music plug(/api/search, Apple 목록)에서 찾아 앨범 그림과 함께 보여 준다. ▶로 30초 미리 듣기.
|
|
54
|
+
* - 고르면 Music plug(/api/match)가 그 곡의 유튜브 영상을 찾아 같이 담는다 (글 안에서 무료로 바로 틀 수 있게).
|
|
55
|
+
* - 고른 곡은 앨범 그림·제목·가수로 보이고, '바꾸기'로 다시 찾고 '빼기'로 비운다.
|
|
56
|
+
* - form 안에 두면 숨은 입력(name)에 고른 곡이 JSON으로 들어간다 (비우면 빈 값). 저장할 때 readPickedSong으로 읽는다.
|
|
57
|
+
* 스타일은 styles.css의 mp-pick. 둘러싼 글의 색을 따른다.
|
|
58
|
+
*/
|
|
59
|
+
type SongFieldProps = {
|
|
60
|
+
/** 숨은 입력의 이름 */
|
|
61
|
+
name: string;
|
|
62
|
+
defaultValue?: PickedSong | null;
|
|
63
|
+
/** 고르거나 뺄 때마다 */
|
|
64
|
+
onChange?: (song: PickedSong | null) => void;
|
|
65
|
+
placeholder?: string;
|
|
66
|
+
/** Music plug 주소 (기본 https://musicplug.madeinbruno.com) */
|
|
67
|
+
base?: string;
|
|
68
|
+
className?: string;
|
|
69
|
+
};
|
|
70
|
+
declare function SongField({ name, defaultValue, onChange, placeholder, base, className }: SongFieldProps): react.JSX.Element;
|
|
71
|
+
|
|
24
72
|
/**
|
|
25
73
|
* 글 속 노래 한 곡의 '음악 듣기'.
|
|
26
74
|
*
|
|
@@ -34,7 +82,9 @@ type Song = {
|
|
|
34
82
|
* 기억은 쿠키 mp_service(madeinbruno.com 아래에서는 Music plug와 같이)와 이 브라우저(localStorage)에 둔다.
|
|
35
83
|
* - 곡을 모르면(song이 null) 다른 곳에서 찾을 수 없어서 이 페이지에서 YouTube로만 튼다 (유튜브가 아닌 곡 링크면 그 링크를 연다).
|
|
36
84
|
* - 테마 음악을 정한 곡 링크(source)가 있으면, 듣는 사람이 같은 곳을 골랐을 때 찾지 않고 그 링크를 바로 연다.
|
|
37
|
-
*
|
|
85
|
+
* 곳마다 직접 정해 둔 곡 링크(links)가 있으면 그곳도 찾지 않고 그 링크를 연다 (곡을 못 찾는 곳을 위해).
|
|
86
|
+
* - 유튜브로 듣는 중에 읽어 내려가 플레이어가 화면 밖으로 나가면 왼쪽 아래에 작은 음악 바(▶/❚❚ + 곡 제목)가 뜬다
|
|
87
|
+
* (avoid로 준 요소가 보일 때는 숨긴다). 제목이 길면 왼쪽으로 흘러가며 뒷부분을 보여 준다.
|
|
38
88
|
*
|
|
39
89
|
* 스타일은 '@madeinbruno/music-plug/styles.css' (클래스는 모두 mp-). 곡 줄은 둘러싼 글의 색을 따르고, 듣기 플러그는 Music plug 색이다.
|
|
40
90
|
*/
|
|
@@ -53,13 +103,15 @@ type PlugPlayerProps = {
|
|
|
53
103
|
service: ServiceId;
|
|
54
104
|
url: string;
|
|
55
105
|
};
|
|
56
|
-
/**
|
|
106
|
+
/** 곳마다 직접 정해 둔 곡 링크. 듣는 사람이 그곳을 고르면 찾지 않고 이 링크를 연다 (source보다 먼저) */
|
|
107
|
+
links?: SongLinks | null;
|
|
108
|
+
/** 유튜브 플레이어가 화면 밖일 때 뜨는 음악 바를, 이 요소가 보이면 숨긴다 (예: '.mib-footer') */
|
|
57
109
|
avoid?: string;
|
|
58
110
|
/** Music plug 주소 (기본 https://musicplug.madeinbruno.com) */
|
|
59
111
|
base?: string;
|
|
60
112
|
className?: string;
|
|
61
113
|
};
|
|
62
|
-
declare function PlugPlayer({ song, fallbackLabel, youtube, source, avoid, base, className }: PlugPlayerProps): react.JSX.Element;
|
|
114
|
+
declare function PlugPlayer({ song, fallbackLabel, youtube, source, links, avoid, base, className }: PlugPlayerProps): react.JSX.Element;
|
|
63
115
|
/**
|
|
64
116
|
* Music plug 듣기 플러그: 어디서 들을지 고르는 창. Music plug의 /listen 화면과 같은 모양.
|
|
65
117
|
* 바깥을 누르거나 Esc로 닫는다.
|
|
@@ -72,4 +124,4 @@ declare function PlugSheet({ song, services, current, onChoose, onClose, }: {
|
|
|
72
124
|
onClose: () => void;
|
|
73
125
|
}): react.JSX.Element;
|
|
74
126
|
|
|
75
|
-
export { PlugPlayer, type PlugPlayerProps, PlugSheet };
|
|
127
|
+
export { PlugPlayer, type PlugPlayerProps, PlugSheet, SongField, type SongFieldProps };
|
package/dist/player.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/player.tsx
|
|
4
|
-
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
5
5
|
|
|
6
6
|
// src/logos.ts
|
|
7
7
|
var YT = "M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z";
|
|
@@ -42,8 +42,183 @@ function listenGoUrl(service, song, youtube, { base = MUSIC_PLUG_URL, remember =
|
|
|
42
42
|
return `${base}/listen/go?s=${service}${remember ? "&remember=1" : ""}&${tail(song, youtube)}`;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// src/youtube.ts
|
|
46
|
+
var YT_ORIGIN = "https://www.youtube-nocookie.com";
|
|
47
|
+
function playerState(raw) {
|
|
48
|
+
let data = raw;
|
|
49
|
+
if (typeof raw === "string") {
|
|
50
|
+
try {
|
|
51
|
+
data = JSON.parse(raw);
|
|
52
|
+
} catch {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!data || typeof data !== "object") return void 0;
|
|
57
|
+
const { event, info } = data;
|
|
58
|
+
if (event === "onStateChange" && typeof info === "number") return info;
|
|
59
|
+
if (info && typeof info === "object" && typeof info.playerState === "number") {
|
|
60
|
+
return info.playerState;
|
|
61
|
+
}
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/picker.tsx
|
|
66
|
+
import { useEffect, useRef, useState } from "react";
|
|
67
|
+
|
|
68
|
+
// src/picked.ts
|
|
69
|
+
async function searchSongs(query, { base = MUSIC_PLUG_URL, signal } = {}) {
|
|
70
|
+
const res = await fetch(`${base}/api/search?q=${encodeURIComponent(query)}`, { signal });
|
|
71
|
+
const data = await res.json().catch(() => null);
|
|
72
|
+
if (!res.ok || !data?.songs) throw new Error(data?.error ?? "\uC9C0\uAE08\uC740 \uCC3E\uC9C0 \uBABB\uD588\uC5B4\uC694");
|
|
73
|
+
return data.songs;
|
|
74
|
+
}
|
|
75
|
+
async function matchYoutube(song, { base = MUSIC_PLUG_URL } = {}) {
|
|
76
|
+
try {
|
|
77
|
+
const res = await fetch(`${base}/api/match?t=${encodeURIComponent(song.title)}&a=${encodeURIComponent(song.artist)}`);
|
|
78
|
+
const data = await res.json();
|
|
79
|
+
return typeof data.youtube === "string" && /^[\w-]{11}$/.test(data.youtube) ? data.youtube : null;
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/picker.tsx
|
|
86
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
87
|
+
function SongField({ name, defaultValue = null, onChange, placeholder = "\uACE1 \uC774\uB984\uC774\uB098 \uAC00\uC218", base = MUSIC_PLUG_URL, className }) {
|
|
88
|
+
const [song, setSong] = useState(defaultValue);
|
|
89
|
+
const [searching, setSearching] = useState(!defaultValue);
|
|
90
|
+
const [query, setQuery] = useState("");
|
|
91
|
+
const [results, setResults] = useState([]);
|
|
92
|
+
const [status, setStatus] = useState("idle");
|
|
93
|
+
const [previewing, setPreviewing] = useState(null);
|
|
94
|
+
const audio = useRef(null);
|
|
95
|
+
const input = useRef(null);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const q = query.trim();
|
|
98
|
+
if (!q) {
|
|
99
|
+
setResults([]);
|
|
100
|
+
setStatus("idle");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const ctrl = new AbortController();
|
|
104
|
+
const timer = window.setTimeout(async () => {
|
|
105
|
+
setStatus("loading");
|
|
106
|
+
try {
|
|
107
|
+
const found = await searchSongs(q, { base, signal: ctrl.signal });
|
|
108
|
+
setResults(found);
|
|
109
|
+
setStatus(found.length ? "idle" : "empty");
|
|
110
|
+
} catch {
|
|
111
|
+
if (!ctrl.signal.aborted) setStatus("error");
|
|
112
|
+
}
|
|
113
|
+
}, 350);
|
|
114
|
+
return () => {
|
|
115
|
+
window.clearTimeout(timer);
|
|
116
|
+
ctrl.abort();
|
|
117
|
+
};
|
|
118
|
+
}, [query, base]);
|
|
119
|
+
useEffect(() => () => audio.current?.pause(), []);
|
|
120
|
+
function togglePreview(url) {
|
|
121
|
+
if (!audio.current) {
|
|
122
|
+
audio.current = new Audio();
|
|
123
|
+
audio.current.onended = () => setPreviewing(null);
|
|
124
|
+
}
|
|
125
|
+
if (previewing === url) {
|
|
126
|
+
audio.current.pause();
|
|
127
|
+
setPreviewing(null);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
audio.current.src = url;
|
|
131
|
+
void audio.current.play().catch(() => setPreviewing(null));
|
|
132
|
+
setPreviewing(url);
|
|
133
|
+
}
|
|
134
|
+
function set(next) {
|
|
135
|
+
setSong(next);
|
|
136
|
+
onChange?.(next);
|
|
137
|
+
}
|
|
138
|
+
async function pick(found) {
|
|
139
|
+
audio.current?.pause();
|
|
140
|
+
setPreviewing(null);
|
|
141
|
+
const { preview: _preview, ...rest } = found;
|
|
142
|
+
void _preview;
|
|
143
|
+
setStatus("matching");
|
|
144
|
+
const youtube = await matchYoutube(found, { base });
|
|
145
|
+
set({ ...rest, ...youtube ? { youtube: { id: youtube } } : {} });
|
|
146
|
+
setSearching(false);
|
|
147
|
+
setQuery("");
|
|
148
|
+
setResults([]);
|
|
149
|
+
setStatus("idle");
|
|
150
|
+
}
|
|
151
|
+
return /* @__PURE__ */ jsxs("div", { className: ["mp-pick", className].filter(Boolean).join(" "), children: [
|
|
152
|
+
/* @__PURE__ */ jsx("input", { type: "hidden", name, value: song ? JSON.stringify(song) : "" }),
|
|
153
|
+
song && !searching && /* @__PURE__ */ jsxs("div", { className: "mp-pick__chosen", children: [
|
|
154
|
+
song.artwork ? /* @__PURE__ */ jsx("img", { src: song.artwork, alt: "", className: "mp-pick__art" }) : /* @__PURE__ */ jsx("span", { className: "mp-pick__art mp-pick__art--empty", children: "\u266A" }),
|
|
155
|
+
/* @__PURE__ */ jsxs("span", { className: "mp-pick__text", children: [
|
|
156
|
+
/* @__PURE__ */ jsx("span", { className: "mp-pick__title", children: song.title }),
|
|
157
|
+
/* @__PURE__ */ jsx("span", { className: "mp-pick__sub", children: [song.artist, song.album].filter(Boolean).join(" \xB7 ") })
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ jsxs("span", { className: "mp-pick__actions", children: [
|
|
160
|
+
/* @__PURE__ */ jsx(
|
|
161
|
+
"button",
|
|
162
|
+
{
|
|
163
|
+
type: "button",
|
|
164
|
+
onClick: () => {
|
|
165
|
+
setSearching(true);
|
|
166
|
+
window.setTimeout(() => input.current?.focus(), 0);
|
|
167
|
+
},
|
|
168
|
+
children: "\uBC14\uAFB8\uAE30"
|
|
169
|
+
}
|
|
170
|
+
),
|
|
171
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => set(null), children: "\uBE7C\uAE30" })
|
|
172
|
+
] })
|
|
173
|
+
] }),
|
|
174
|
+
(searching || !song) && /* @__PURE__ */ jsxs("div", { className: "mp-pick__search", children: [
|
|
175
|
+
/* @__PURE__ */ jsxs("label", { className: "mp-pick__bar", children: [
|
|
176
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u266A" }),
|
|
177
|
+
/* @__PURE__ */ jsx(
|
|
178
|
+
"input",
|
|
179
|
+
{
|
|
180
|
+
ref: input,
|
|
181
|
+
type: "search",
|
|
182
|
+
value: query,
|
|
183
|
+
onChange: (e) => setQuery(e.target.value),
|
|
184
|
+
onKeyDown: (e) => e.key === "Enter" && e.preventDefault(),
|
|
185
|
+
placeholder,
|
|
186
|
+
"aria-label": "\uACE1 \uCC3E\uAE30",
|
|
187
|
+
autoComplete: "off"
|
|
188
|
+
}
|
|
189
|
+
),
|
|
190
|
+
song && /* @__PURE__ */ jsx("button", { type: "button", onClick: () => setSearching(false), children: "\uADF8\uB9CC" })
|
|
191
|
+
] }),
|
|
192
|
+
status === "loading" && /* @__PURE__ */ jsx("p", { className: "mp-pick__note", children: "\uCC3E\uB294 \uC911\u2026" }),
|
|
193
|
+
status === "matching" && /* @__PURE__ */ jsx("p", { className: "mp-pick__note", children: "\uACE0\uB974\uB294 \uC911\u2026" }),
|
|
194
|
+
status === "empty" && /* @__PURE__ */ jsx("p", { className: "mp-pick__note", children: "\uCC3E\uB294 \uACE1\uC774 \uC5C6\uC5B4\uC694" }),
|
|
195
|
+
status === "error" && /* @__PURE__ */ jsx("p", { className: "mp-pick__note", children: "\uC9C0\uAE08\uC740 \uCC3E\uC9C0 \uBABB\uD588\uC5B4\uC694. \uC7A0\uC2DC \uB4A4\uC5D0 \uB2E4\uC2DC \uD574 \uBCF4\uC138\uC694" }),
|
|
196
|
+
results.length > 0 && status !== "matching" && /* @__PURE__ */ jsx("ul", { className: "mp-pick__list", "aria-label": "\uCC3E\uC740 \uACE1", children: results.map((r, i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
197
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "mp-pick__row", onClick: () => void pick(r), children: [
|
|
198
|
+
r.artwork ? /* @__PURE__ */ jsx("img", { src: r.artwork, alt: "", className: "mp-pick__art", loading: "lazy" }) : /* @__PURE__ */ jsx("span", { className: "mp-pick__art mp-pick__art--empty", children: "\u266A" }),
|
|
199
|
+
/* @__PURE__ */ jsxs("span", { className: "mp-pick__text", children: [
|
|
200
|
+
/* @__PURE__ */ jsx("span", { className: "mp-pick__title", children: r.title }),
|
|
201
|
+
/* @__PURE__ */ jsx("span", { className: "mp-pick__sub", children: [r.artist, r.album].filter(Boolean).join(" \xB7 ") })
|
|
202
|
+
] })
|
|
203
|
+
] }),
|
|
204
|
+
r.preview && /* @__PURE__ */ jsx(
|
|
205
|
+
"button",
|
|
206
|
+
{
|
|
207
|
+
type: "button",
|
|
208
|
+
className: "mp-pick__preview",
|
|
209
|
+
"aria-label": previewing === r.preview ? "\uBBF8\uB9AC \uB4E3\uAE30 \uBA48\uCD94\uAE30" : "\uBBF8\uB9AC \uB4E3\uAE30",
|
|
210
|
+
"aria-pressed": previewing === r.preview,
|
|
211
|
+
onClick: () => togglePreview(r.preview),
|
|
212
|
+
children: previewing === r.preview ? "\u25A0" : "\u25B6"
|
|
213
|
+
}
|
|
214
|
+
)
|
|
215
|
+
] }, `${r.title}|${r.artist}|${i}`)) })
|
|
216
|
+
] })
|
|
217
|
+
] });
|
|
218
|
+
}
|
|
219
|
+
|
|
45
220
|
// src/player.tsx
|
|
46
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
221
|
+
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
47
222
|
var KEY = "musicplug.service";
|
|
48
223
|
var SHARED_DOMAIN = "madeinbruno.com";
|
|
49
224
|
function readChoice() {
|
|
@@ -64,16 +239,16 @@ function saveChoice(id) {
|
|
|
64
239
|
const shared = host === SHARED_DOMAIN || host.endsWith(`.${SHARED_DOMAIN}`) ? `; domain=.${SHARED_DOMAIN}` : "";
|
|
65
240
|
document.cookie = `mp_service=${id}; path=/; max-age=31536000; samesite=lax${shared}`;
|
|
66
241
|
}
|
|
67
|
-
function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube, source, avoid, base = MUSIC_PLUG_URL, className }) {
|
|
68
|
-
const [choice, setChoice] =
|
|
69
|
-
const [sheet, setSheet] =
|
|
70
|
-
const [open, setOpen] =
|
|
71
|
-
const [playing, setPlaying] =
|
|
72
|
-
const [chip, setChip] =
|
|
73
|
-
const frame =
|
|
74
|
-
|
|
242
|
+
function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube, source, links, avoid, base = MUSIC_PLUG_URL, className }) {
|
|
243
|
+
const [choice, setChoice] = useState2(null);
|
|
244
|
+
const [sheet, setSheet] = useState2(false);
|
|
245
|
+
const [open, setOpen] = useState2(false);
|
|
246
|
+
const [playing, setPlaying] = useState2(false);
|
|
247
|
+
const [chip, setChip] = useState2(false);
|
|
248
|
+
const frame = useRef2(null);
|
|
249
|
+
useEffect2(() => setChoice(readChoice()), []);
|
|
75
250
|
const known = Boolean(song?.title);
|
|
76
|
-
const services = SERVICES.filter((s) => s.id === "here" ? Boolean(youtube) : s.id === "ytvideo" ? !youtube : known);
|
|
251
|
+
const services = SERVICES.filter((s) => s.id === "here" ? Boolean(youtube) : s.id === "ytvideo" ? !youtube : known || Boolean(links?.[s.id]));
|
|
77
252
|
const isYoutube = (id) => id === "here" || id === "ytvideo";
|
|
78
253
|
const remembered = services.find((s) => s.id === choice || isYoutube(choice) && isYoutube(s.id)) ?? null;
|
|
79
254
|
function play(s) {
|
|
@@ -82,7 +257,8 @@ function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube
|
|
|
82
257
|
setPlaying(true);
|
|
83
258
|
return;
|
|
84
259
|
}
|
|
85
|
-
const
|
|
260
|
+
const viaVideo = Boolean(youtube) && (s.id === "ytvideo" || s.id === "youtube");
|
|
261
|
+
const direct = links?.[s.id] ?? (source && source.service === s.id && !viaVideo ? source.url : null);
|
|
86
262
|
window.open(direct ?? listenGoUrl(s.id, song, youtube, { base }), "_blank", "noopener");
|
|
87
263
|
}
|
|
88
264
|
function choose(s) {
|
|
@@ -92,13 +268,45 @@ function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube
|
|
|
92
268
|
play(s);
|
|
93
269
|
}
|
|
94
270
|
function tap() {
|
|
95
|
-
|
|
96
|
-
if (!known &&
|
|
271
|
+
const linked = Boolean(links && Object.keys(links).length);
|
|
272
|
+
if (!known && !linked && youtube) return play(SERVICES[0]);
|
|
273
|
+
if (!known && !linked && source) return void window.open(source.url, "_blank", "noopener");
|
|
97
274
|
if (remembered) play(remembered);
|
|
98
275
|
else setSheet(true);
|
|
99
276
|
}
|
|
100
|
-
const command = (func) => frame.current?.contentWindow?.postMessage(JSON.stringify({ event: "command", func, args: [] }),
|
|
101
|
-
|
|
277
|
+
const command = (func) => frame.current?.contentWindow?.postMessage(JSON.stringify({ event: "command", func, args: [] }), YT_ORIGIN);
|
|
278
|
+
const heard = useRef2(false);
|
|
279
|
+
useEffect2(() => {
|
|
280
|
+
if (!open) return;
|
|
281
|
+
heard.current = false;
|
|
282
|
+
const onMessage = (e) => {
|
|
283
|
+
if (e.origin !== YT_ORIGIN || e.source !== frame.current?.contentWindow) return;
|
|
284
|
+
const state = playerState(e.data);
|
|
285
|
+
if (state === void 0) return;
|
|
286
|
+
heard.current = true;
|
|
287
|
+
if (state === 1) setPlaying(true);
|
|
288
|
+
else if (state !== 3) setPlaying(false);
|
|
289
|
+
};
|
|
290
|
+
window.addEventListener("message", onMessage);
|
|
291
|
+
let tries = 0;
|
|
292
|
+
const retry = window.setInterval(() => {
|
|
293
|
+
if (heard.current || ++tries > 20) window.clearInterval(retry);
|
|
294
|
+
else listen();
|
|
295
|
+
}, 500);
|
|
296
|
+
const onBack = () => document.visibilityState === "visible" && listen();
|
|
297
|
+
document.addEventListener("visibilitychange", onBack);
|
|
298
|
+
window.addEventListener("pageshow", onBack);
|
|
299
|
+
window.addEventListener("focus", onBack);
|
|
300
|
+
return () => {
|
|
301
|
+
window.removeEventListener("message", onMessage);
|
|
302
|
+
window.clearInterval(retry);
|
|
303
|
+
document.removeEventListener("visibilitychange", onBack);
|
|
304
|
+
window.removeEventListener("pageshow", onBack);
|
|
305
|
+
window.removeEventListener("focus", onBack);
|
|
306
|
+
};
|
|
307
|
+
}, [open]);
|
|
308
|
+
const listen = () => frame.current?.contentWindow?.postMessage(JSON.stringify({ event: "listening", id: "mp" }), YT_ORIGIN);
|
|
309
|
+
useEffect2(() => {
|
|
102
310
|
if (!open) return;
|
|
103
311
|
const seen = /* @__PURE__ */ new Map();
|
|
104
312
|
const io = new IntersectionObserver((entries) => {
|
|
@@ -113,45 +321,47 @@ function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube
|
|
|
113
321
|
return () => io.disconnect();
|
|
114
322
|
}, [open, avoid]);
|
|
115
323
|
const label = song && [song.title, song.artist].filter(Boolean).join(" \xB7 ") || fallbackLabel;
|
|
116
|
-
return /* @__PURE__ */
|
|
117
|
-
/* @__PURE__ */
|
|
118
|
-
/* @__PURE__ */
|
|
119
|
-
/* @__PURE__ */
|
|
324
|
+
return /* @__PURE__ */ jsxs2("div", { className: ["mp-plug", className].filter(Boolean).join(" "), children: [
|
|
325
|
+
/* @__PURE__ */ jsxs2("div", { className: "mp-plug__row", children: [
|
|
326
|
+
/* @__PURE__ */ jsxs2("button", { type: "button", className: "mp-plug__song", onClick: tap, children: [
|
|
327
|
+
/* @__PURE__ */ jsx2("span", { "aria-hidden": "true", children: "\u266A" }),
|
|
120
328
|
" ",
|
|
121
329
|
label
|
|
122
330
|
] }),
|
|
123
|
-
known && remembered && /* @__PURE__ */
|
|
331
|
+
(known || links) && remembered && /* @__PURE__ */ jsxs2("span", { className: "mp-plug__where", children: [
|
|
124
332
|
remembered.name,
|
|
125
|
-
/* @__PURE__ */
|
|
126
|
-
/* @__PURE__ */
|
|
333
|
+
/* @__PURE__ */ jsx2("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
334
|
+
/* @__PURE__ */ jsx2("button", { type: "button", onClick: () => setSheet(true), children: "\uBC14\uAFB8\uAE30" })
|
|
127
335
|
] })
|
|
128
336
|
] }),
|
|
129
|
-
open && youtube && /* @__PURE__ */
|
|
337
|
+
open && youtube && /* @__PURE__ */ jsx2("div", { className: "mp-plug__frame", children: /* @__PURE__ */ jsx2(
|
|
130
338
|
"iframe",
|
|
131
339
|
{
|
|
132
340
|
ref: frame,
|
|
133
|
-
src:
|
|
341
|
+
src: `${YT_ORIGIN}/embed/${youtube.id}?autoplay=1&playsinline=1&rel=0&enablejsapi=1&origin=${encodeURIComponent(location.origin)}${youtube.start ? `&start=${youtube.start}` : ""}`,
|
|
134
342
|
title: label,
|
|
135
343
|
allow: "autoplay; encrypted-media; picture-in-picture",
|
|
136
|
-
allowFullScreen: true
|
|
344
|
+
allowFullScreen: true,
|
|
345
|
+
onLoad: listen
|
|
137
346
|
}
|
|
138
347
|
) }),
|
|
139
|
-
open && chip && /* @__PURE__ */
|
|
348
|
+
open && chip && /* @__PURE__ */ jsxs2(
|
|
140
349
|
"button",
|
|
141
350
|
{
|
|
142
351
|
type: "button",
|
|
143
352
|
className: "mp-plug__chip",
|
|
353
|
+
"aria-label": `${song?.title || fallbackLabel} ${playing ? "\uBA48\uCD94\uAE30" : "\uD2C0\uAE30"}`,
|
|
144
354
|
onClick: () => {
|
|
145
355
|
command(playing ? "pauseVideo" : "playVideo");
|
|
146
356
|
setPlaying(!playing);
|
|
147
357
|
},
|
|
148
358
|
children: [
|
|
149
|
-
|
|
150
|
-
|
|
359
|
+
/* @__PURE__ */ jsx2(PlayIcon, { playing }),
|
|
360
|
+
/* @__PURE__ */ jsx2(Marquee, { text: song?.title || fallbackLabel })
|
|
151
361
|
]
|
|
152
362
|
}
|
|
153
363
|
),
|
|
154
|
-
sheet && /* @__PURE__ */
|
|
364
|
+
sheet && /* @__PURE__ */ jsx2(PlugSheet, { song, services, current: remembered?.id ?? null, onChoose: choose, onClose: () => setSheet(false) })
|
|
155
365
|
] });
|
|
156
366
|
}
|
|
157
367
|
function PlugSheet({
|
|
@@ -161,7 +371,7 @@ function PlugSheet({
|
|
|
161
371
|
onChoose,
|
|
162
372
|
onClose
|
|
163
373
|
}) {
|
|
164
|
-
|
|
374
|
+
useEffect2(() => {
|
|
165
375
|
const onKey = (e) => e.key === "Escape" && onClose();
|
|
166
376
|
window.addEventListener("keydown", onKey);
|
|
167
377
|
const prev = document.body.style.overflow;
|
|
@@ -171,57 +381,80 @@ function PlugSheet({
|
|
|
171
381
|
document.body.style.overflow = prev;
|
|
172
382
|
};
|
|
173
383
|
}, [onClose]);
|
|
174
|
-
return /* @__PURE__ */
|
|
175
|
-
/* @__PURE__ */
|
|
176
|
-
/* @__PURE__ */
|
|
177
|
-
/* @__PURE__ */
|
|
384
|
+
return /* @__PURE__ */ jsx2("div", { className: "mp-sheet", role: "dialog", "aria-modal": "true", "aria-label": "\uC5B4\uB514\uC11C \uB4E4\uC744\uAE4C\uC694", onClick: (e) => e.target === e.currentTarget && onClose(), children: /* @__PURE__ */ jsxs2("div", { className: "mp-sheet__panel", children: [
|
|
385
|
+
/* @__PURE__ */ jsxs2("div", { className: "mp-sheet__head", children: [
|
|
386
|
+
/* @__PURE__ */ jsxs2("span", { className: "mp-sheet__brand", children: [
|
|
387
|
+
/* @__PURE__ */ jsx2(Symbol, {}),
|
|
178
388
|
" Music plug"
|
|
179
389
|
] }),
|
|
180
|
-
/* @__PURE__ */
|
|
390
|
+
/* @__PURE__ */ jsx2("button", { type: "button", className: "mp-sheet__close", onClick: onClose, "aria-label": "\uB2EB\uAE30", children: "\xD7" })
|
|
181
391
|
] }),
|
|
182
|
-
song?.title && /* @__PURE__ */
|
|
183
|
-
/* @__PURE__ */
|
|
184
|
-
song.artist && /* @__PURE__ */
|
|
392
|
+
song?.title && /* @__PURE__ */ jsxs2("div", { className: "mp-sheet__song", children: [
|
|
393
|
+
/* @__PURE__ */ jsx2("p", { className: "mp-sheet__song-title", children: song.title }),
|
|
394
|
+
song.artist && /* @__PURE__ */ jsx2("p", { className: "mp-sheet__sub", children: song.artist })
|
|
185
395
|
] }),
|
|
186
|
-
/* @__PURE__ */
|
|
187
|
-
/* @__PURE__ */
|
|
396
|
+
/* @__PURE__ */ jsx2("p", { className: "mp-sheet__ask", children: "\uC5B4\uB514\uC11C \uB4E4\uC744\uAE4C\uC694?" }),
|
|
397
|
+
/* @__PURE__ */ jsx2("ul", { className: "mp-sheet__grid", children: services.map((s) => /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsxs2(
|
|
188
398
|
"button",
|
|
189
399
|
{
|
|
190
400
|
type: "button",
|
|
191
401
|
"aria-current": (current ? s.id === current : s.id === "here" || s.id === "ytvideo") ? "true" : void 0,
|
|
192
402
|
onClick: () => onChoose(s),
|
|
193
403
|
children: [
|
|
194
|
-
/* @__PURE__ */
|
|
195
|
-
/* @__PURE__ */
|
|
196
|
-
(s.id === "here" || s.id === "ytvideo") && /* @__PURE__ */
|
|
404
|
+
/* @__PURE__ */ jsx2(Mark, { service: s }),
|
|
405
|
+
/* @__PURE__ */ jsx2("span", { children: s.name }),
|
|
406
|
+
(s.id === "here" || s.id === "ytvideo") && /* @__PURE__ */ jsx2("span", { className: "mp-sheet__tag", children: "\uAE30\uBCF8" })
|
|
197
407
|
]
|
|
198
408
|
}
|
|
199
409
|
) }, s.id)) }),
|
|
200
|
-
/* @__PURE__ */
|
|
410
|
+
/* @__PURE__ */ jsx2("p", { className: "mp-sheet__note", children: "\uACE0\uB978 \uACF3\uC740 \uAE30\uC5B5\uD574 \uB450\uACE0 \uB2E4\uC74C\uBD80\uD130 \uBC14\uB85C \uADF8\uACF3\uC5D0\uC11C \uC5F4\uC5B4\uC694. \uACE1 \uC606\uC758 \u2018\uBC14\uAFB8\uAE30\u2019\uB85C \uB2E4\uC2DC \uACE0\uB97C \uC218 \uC788\uC5B4\uC694." })
|
|
201
411
|
] }) });
|
|
202
412
|
}
|
|
413
|
+
function PlayIcon({ playing }) {
|
|
414
|
+
return /* @__PURE__ */ jsx2("svg", { className: "mp-plug__icon", width: "12", height: "12", viewBox: "0 0 12 12", "aria-hidden": "true", children: playing ? /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
415
|
+
/* @__PURE__ */ jsx2("rect", { x: "2", y: "1.5", width: "2.6", height: "9", rx: "0.8", fill: "currentColor" }),
|
|
416
|
+
/* @__PURE__ */ jsx2("rect", { x: "7.4", y: "1.5", width: "2.6", height: "9", rx: "0.8", fill: "currentColor" })
|
|
417
|
+
] }) : /* @__PURE__ */ jsx2("path", { d: "M3 1.8v8.4a.7.7 0 0 0 1.06.6l6.8-4.2a.7.7 0 0 0 0-1.2l-6.8-4.2A.7.7 0 0 0 3 1.8z", fill: "currentColor" }) });
|
|
418
|
+
}
|
|
419
|
+
function Marquee({ text }) {
|
|
420
|
+
const box = useRef2(null);
|
|
421
|
+
const inner = useRef2(null);
|
|
422
|
+
const [shift, setShift] = useState2(0);
|
|
423
|
+
useEffect2(() => {
|
|
424
|
+
const measure = () => {
|
|
425
|
+
if (box.current && inner.current) setShift(Math.max(0, inner.current.scrollWidth - box.current.clientWidth));
|
|
426
|
+
};
|
|
427
|
+
measure();
|
|
428
|
+
const ro = new ResizeObserver(measure);
|
|
429
|
+
if (box.current) ro.observe(box.current);
|
|
430
|
+
return () => ro.disconnect();
|
|
431
|
+
}, [text]);
|
|
432
|
+
const style = shift ? { "--mp-shift": `-${shift}px`, "--mp-dur": `${(shift / 30 + 3).toFixed(1)}s` } : void 0;
|
|
433
|
+
return /* @__PURE__ */ jsx2("span", { ref: box, className: shift ? "mp-marquee mp-marquee--move" : "mp-marquee", children: /* @__PURE__ */ jsx2("span", { ref: inner, className: "mp-marquee__text", style, children: text }) });
|
|
434
|
+
}
|
|
203
435
|
function Mark({ service }) {
|
|
204
436
|
const logo = LOGO_PATHS[service.id];
|
|
205
|
-
return /* @__PURE__ */
|
|
206
|
-
/* @__PURE__ */
|
|
207
|
-
/* @__PURE__ */
|
|
437
|
+
return /* @__PURE__ */ jsx2("svg", { width: "26", height: "26", viewBox: "0 0 24 24", "aria-hidden": "true", className: "mp-sheet__mark", children: logo ? /* @__PURE__ */ jsx2("path", { d: logo, fill: service.color }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
438
|
+
/* @__PURE__ */ jsx2("circle", { cx: "12", cy: "12", r: "12", fill: service.color }),
|
|
439
|
+
/* @__PURE__ */ jsx2("text", { x: "12", y: "16.8", textAnchor: "middle", fontSize: "13.5", fontWeight: "800", fill: "#0b0b0d", children: service.initial })
|
|
208
440
|
] }) });
|
|
209
441
|
}
|
|
210
442
|
function Symbol() {
|
|
211
|
-
return /* @__PURE__ */
|
|
212
|
-
/* @__PURE__ */
|
|
213
|
-
/* @__PURE__ */
|
|
214
|
-
/* @__PURE__ */
|
|
215
|
-
/* @__PURE__ */
|
|
216
|
-
/* @__PURE__ */
|
|
217
|
-
/* @__PURE__ */
|
|
218
|
-
/* @__PURE__ */
|
|
219
|
-
/* @__PURE__ */
|
|
220
|
-
/* @__PURE__ */
|
|
443
|
+
return /* @__PURE__ */ jsx2("svg", { width: "20", height: "20", viewBox: "0 0 64 64", "aria-hidden": "true", children: /* @__PURE__ */ jsxs2("g", { transform: "translate(0 3.5)", children: [
|
|
444
|
+
/* @__PURE__ */ jsx2("rect", { x: "21.5", y: "8.5", width: "5.5", height: "13", rx: "2.75", fill: "#f2f2ee" }),
|
|
445
|
+
/* @__PURE__ */ jsx2("rect", { x: "37", y: "8.5", width: "5.5", height: "13", rx: "2.75", fill: "#f2f2ee" }),
|
|
446
|
+
/* @__PURE__ */ jsx2("rect", { x: "12", y: "19", width: "40", height: "29", rx: "5", fill: "#f2f2ee" }),
|
|
447
|
+
/* @__PURE__ */ jsxs2("g", { fill: "#141417", children: [
|
|
448
|
+
/* @__PURE__ */ jsx2("rect", { x: "17.9", y: "30.25", width: "3.4", height: "6.5", rx: "1.7" }),
|
|
449
|
+
/* @__PURE__ */ jsx2("rect", { x: "24.1", y: "27.25", width: "3.4", height: "12.5", rx: "1.7" }),
|
|
450
|
+
/* @__PURE__ */ jsx2("rect", { x: "30.3", y: "24.5", width: "3.4", height: "18", rx: "1.7" }),
|
|
451
|
+
/* @__PURE__ */ jsx2("rect", { x: "36.5", y: "27.25", width: "3.4", height: "12.5", rx: "1.7" }),
|
|
452
|
+
/* @__PURE__ */ jsx2("rect", { x: "42.7", y: "30.25", width: "3.4", height: "6.5", rx: "1.7" })
|
|
221
453
|
] })
|
|
222
454
|
] }) });
|
|
223
455
|
}
|
|
224
456
|
export {
|
|
225
457
|
PlugPlayer,
|
|
226
|
-
PlugSheet
|
|
458
|
+
PlugSheet,
|
|
459
|
+
SongField
|
|
227
460
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@madeinbruno/music-plug",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "글 속 노래를 듣는 사람이 쓰는 음원 앱(멜론·지니·벅스·FLO·VIBE·Spotify·Apple Music·YouTube Music)에서, 없으면 YouTube로 바로 듣게 하는 플러그",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "codingbotPark <pbk575@gmail.com>",
|
package/styles.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @madeinbruno/music-plug 스타일. 쓰는 쪽에서 한 번만 불러온다: import '@madeinbruno/music-plug/styles.css'
|
|
2
2
|
클래스 이름은 모두 mp- 로 시작한다.
|
|
3
3
|
- 곡 줄(.mp-plug)은 둘러싼 글의 색(currentColor)을 따라서 밝은·어두운 화면 어디서나 맞는다.
|
|
4
|
-
|
|
4
|
+
음악 바의 바탕은 --mp-ground로 바꿀 수 있다 (기본: 흰색 반투명).
|
|
5
5
|
- 듣기 플러그(.mp-sheet)는 Music plug 색(검은 바탕, 노란 고른 표시)이다. */
|
|
6
6
|
|
|
7
7
|
.mp-plug {
|
|
@@ -58,15 +58,71 @@
|
|
|
58
58
|
bottom: 16px;
|
|
59
59
|
left: 16px;
|
|
60
60
|
z-index: 40;
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
display: inline-flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
gap: 8px;
|
|
64
|
+
max-width: min(60vw, 240px);
|
|
65
|
+
padding: 7px 14px 7px 12px !important;
|
|
63
66
|
border: 1px solid currentColor !important;
|
|
64
67
|
border-radius: 999px;
|
|
65
68
|
background: var(--mp-ground) !important;
|
|
66
69
|
opacity: 0.85;
|
|
67
|
-
|
|
70
|
+
line-height: 1.2;
|
|
71
|
+
animation: mp-fade 160ms ease-out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.mp-plug__icon {
|
|
75
|
+
flex: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* 길면 흘러가는 한 줄 글씨 (곡 제목) */
|
|
79
|
+
.mp-marquee {
|
|
80
|
+
display: block;
|
|
81
|
+
min-width: 0;
|
|
68
82
|
overflow: hidden;
|
|
69
|
-
|
|
83
|
+
white-space: nowrap;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.mp-marquee__text {
|
|
87
|
+
display: inline-block;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* 흐를 때는 양쪽에 여백을 둬서 처음·마지막 글자가 흐린 끝에 걸리지 않게 (왼쪽 여백만큼 아이콘과의 틈을 줄인다) */
|
|
91
|
+
.mp-plug__chip:has(.mp-marquee--move) {
|
|
92
|
+
gap: 3px;
|
|
93
|
+
}
|
|
94
|
+
.mp-marquee--move .mp-marquee__text {
|
|
95
|
+
padding: 0 16px 0 5px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.mp-marquee--move {
|
|
99
|
+
/* 흐를 때는 양 끝을 흐리게 지워서 잘린 티가 덜 나게 */
|
|
100
|
+
-webkit-mask-image: linear-gradient(90deg, transparent, #000 5px, #000 calc(100% - 12px), transparent);
|
|
101
|
+
mask-image: linear-gradient(90deg, transparent, #000 5px, #000 calc(100% - 12px), transparent);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.mp-marquee--move .mp-marquee__text {
|
|
105
|
+
animation: mp-marquee var(--mp-dur, 8s) ease-in-out infinite alternate;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@keyframes mp-marquee {
|
|
109
|
+
0%,
|
|
110
|
+
18% {
|
|
111
|
+
transform: translateX(0);
|
|
112
|
+
}
|
|
113
|
+
82%,
|
|
114
|
+
100% {
|
|
115
|
+
transform: translateX(var(--mp-shift, 0));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@media (prefers-reduced-motion: reduce) {
|
|
120
|
+
.mp-marquee--move .mp-marquee__text {
|
|
121
|
+
animation: none;
|
|
122
|
+
}
|
|
123
|
+
.mp-marquee {
|
|
124
|
+
text-overflow: ellipsis;
|
|
125
|
+
}
|
|
70
126
|
}
|
|
71
127
|
|
|
72
128
|
/* ───────── 듣기 플러그 (Music plug) ───────── */
|
|
@@ -230,3 +286,141 @@
|
|
|
230
286
|
animation: none;
|
|
231
287
|
}
|
|
232
288
|
}
|
|
289
|
+
|
|
290
|
+
/* ───────── 곡 고르기 (SongField) ─────────
|
|
291
|
+
쓰는 사람 화면. 둘러싼 글의 색(currentColor)을 따른다. */
|
|
292
|
+
|
|
293
|
+
.mp-pick {
|
|
294
|
+
font-size: 14px;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.mp-pick button {
|
|
298
|
+
padding: 0;
|
|
299
|
+
border: 0;
|
|
300
|
+
background: none;
|
|
301
|
+
color: inherit;
|
|
302
|
+
font: inherit;
|
|
303
|
+
cursor: pointer;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.mp-pick__bar {
|
|
307
|
+
display: flex;
|
|
308
|
+
align-items: baseline;
|
|
309
|
+
gap: 8px;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.mp-pick__bar input {
|
|
313
|
+
flex: 1;
|
|
314
|
+
min-width: 0;
|
|
315
|
+
padding: 2px 0;
|
|
316
|
+
border: 0;
|
|
317
|
+
background: transparent;
|
|
318
|
+
color: inherit;
|
|
319
|
+
font: inherit;
|
|
320
|
+
outline: none;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/* 브라우저가 붙이는 파란 지우기 단추는 숨긴다 (둘러싼 글의 모양을 따르게) */
|
|
324
|
+
.mp-pick__bar input::-webkit-search-cancel-button {
|
|
325
|
+
appearance: none;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.mp-pick__bar input::placeholder {
|
|
329
|
+
color: currentColor;
|
|
330
|
+
opacity: 0.45;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.mp-pick__bar button,
|
|
334
|
+
.mp-pick__actions button {
|
|
335
|
+
opacity: 0.6;
|
|
336
|
+
font-size: 13px;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.mp-pick__note {
|
|
340
|
+
margin: 8px 0 0 20px;
|
|
341
|
+
opacity: 0.55;
|
|
342
|
+
font-size: 13px;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.mp-pick__list {
|
|
346
|
+
max-height: 340px;
|
|
347
|
+
margin: 8px 0 0;
|
|
348
|
+
padding: 0;
|
|
349
|
+
overflow-y: auto;
|
|
350
|
+
list-style: none;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.mp-pick__list li {
|
|
354
|
+
display: flex;
|
|
355
|
+
align-items: center;
|
|
356
|
+
gap: 8px;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.mp-pick__row,
|
|
360
|
+
.mp-pick__chosen {
|
|
361
|
+
display: flex !important;
|
|
362
|
+
flex: 1;
|
|
363
|
+
align-items: center;
|
|
364
|
+
gap: 10px;
|
|
365
|
+
min-width: 0;
|
|
366
|
+
padding: 6px 0 !important;
|
|
367
|
+
text-align: left;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.mp-pick__row:hover {
|
|
371
|
+
opacity: 0.75;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.mp-pick__art {
|
|
375
|
+
flex-shrink: 0;
|
|
376
|
+
width: 40px;
|
|
377
|
+
height: 40px;
|
|
378
|
+
border-radius: 4px;
|
|
379
|
+
object-fit: cover;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
.mp-pick__art--empty {
|
|
383
|
+
display: flex;
|
|
384
|
+
align-items: center;
|
|
385
|
+
justify-content: center;
|
|
386
|
+
border: 1px solid currentColor;
|
|
387
|
+
opacity: 0.4;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.mp-pick__text {
|
|
391
|
+
display: flex;
|
|
392
|
+
flex-direction: column;
|
|
393
|
+
min-width: 0;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.mp-pick__title,
|
|
397
|
+
.mp-pick__sub {
|
|
398
|
+
overflow: hidden;
|
|
399
|
+
white-space: nowrap;
|
|
400
|
+
text-overflow: ellipsis;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.mp-pick__sub {
|
|
404
|
+
opacity: 0.55;
|
|
405
|
+
font-size: 12px;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.mp-pick__preview {
|
|
409
|
+
flex-shrink: 0;
|
|
410
|
+
width: 32px;
|
|
411
|
+
height: 32px;
|
|
412
|
+
border-radius: 999px !important;
|
|
413
|
+
font-size: 11px !important;
|
|
414
|
+
opacity: 0.7;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.mp-pick__preview[aria-pressed='true'] {
|
|
418
|
+
opacity: 1;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
.mp-pick__actions {
|
|
422
|
+
display: flex;
|
|
423
|
+
flex-shrink: 0;
|
|
424
|
+
gap: 12px;
|
|
425
|
+
margin-left: auto;
|
|
426
|
+
}
|