@madeinbruno/music-plug 0.2.0 → 0.5.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 +90 -5
- package/dist/chunk-3HM3NTBS.js +296 -0
- package/dist/headless.d.ts +2 -0
- package/dist/headless.js +13 -0
- package/dist/index-CxM1NkLk.d.ts +160 -0
- package/dist/index.d.ts +49 -1
- package/dist/index.js +70 -0
- package/dist/player.d.ts +54 -53
- package/dist/player.js +227 -177
- package/package.json +5 -1
- package/styles.css +467 -78
package/dist/index.js
CHANGED
|
@@ -146,14 +146,84 @@ 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/logos.ts
|
|
163
|
+
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";
|
|
164
|
+
var LOGO_PATHS = {
|
|
165
|
+
here: YT,
|
|
166
|
+
ytvideo: YT,
|
|
167
|
+
spotify: "M12 0C5.4 0 0 5.4 0 12s5.4 12 12 12 12-5.4 12-12S18.66 0 12 0zm5.521 17.34c-.24.359-.66.48-1.021.24-2.82-1.74-6.36-2.101-10.561-1.141-.418.122-.779-.179-.899-.539-.12-.421.18-.78.54-.9 4.56-1.021 8.52-.6 11.64 1.32.42.18.479.659.301 1.02zm1.44-3.3c-.301.42-.841.6-1.262.3-3.239-1.98-8.159-2.58-11.939-1.38-.479.12-1.02-.12-1.14-.6-.12-.48.12-1.021.6-1.141C9.6 9.9 15 10.561 18.72 12.84c.361.181.54.78.241 1.2zm.12-3.36C15.24 8.4 8.82 8.16 5.16 9.301c-.6.179-1.2-.181-1.38-.721-.18-.601.18-1.2.72-1.381 4.26-1.26 11.28-1.02 15.721 1.621.539.3.719 1.02.419 1.56-.299.421-1.02.599-1.559.3z",
|
|
168
|
+
apple: "M23.994 6.124a9.23 9.23 0 00-.24-2.19c-.317-1.31-1.062-2.31-2.18-3.043a5.022 5.022 0 00-1.877-.726 10.496 10.496 0 00-1.564-.15c-.04-.003-.083-.01-.124-.013H5.986c-.152.01-.303.017-.455.026-.747.043-1.49.123-2.193.4-1.336.53-2.3 1.452-2.865 2.78-.192.448-.292.925-.363 1.408-.056.392-.088.785-.1 1.18 0 .032-.007.062-.01.093v12.223c.01.14.017.283.027.424.05.815.154 1.624.497 2.373.65 1.42 1.738 2.353 3.234 2.801.42.127.856.187 1.293.228.555.053 1.11.06 1.667.06h11.03a12.5 12.5 0 001.57-.1c.822-.106 1.596-.35 2.295-.81a5.046 5.046 0 001.88-2.207c.186-.42.293-.87.37-1.324.113-.675.138-1.358.137-2.04-.002-3.8 0-7.595-.003-11.393zm-6.423 3.99v5.712c0 .417-.058.827-.244 1.206-.29.59-.76.962-1.388 1.14-.35.1-.706.157-1.07.173-.95.045-1.773-.6-1.943-1.536a1.88 1.88 0 011.038-2.022c.323-.16.67-.25 1.018-.324.378-.082.758-.153 1.134-.24.274-.063.457-.23.51-.516a.904.904 0 00.02-.193c0-1.815 0-3.63-.002-5.443a.725.725 0 00-.026-.185c-.04-.15-.15-.243-.304-.234-.16.01-.318.035-.475.066-.76.15-1.52.303-2.28.456l-2.325.47-1.374.278c-.016.003-.032.01-.048.013-.277.077-.377.203-.39.49-.002.042 0 .086 0 .13-.002 2.602 0 5.204-.003 7.805 0 .42-.047.836-.215 1.227-.278.64-.77 1.04-1.434 1.233-.35.1-.71.16-1.075.172-.96.036-1.755-.6-1.92-1.544-.14-.812.23-1.685 1.154-2.075.357-.15.73-.232 1.108-.31.287-.06.575-.116.86-.177.383-.083.583-.323.6-.714v-.15c0-2.96 0-5.922.002-8.882 0-.123.013-.25.042-.37.07-.285.273-.448.546-.518.255-.066.515-.112.774-.165.733-.15 1.466-.296 2.2-.444l2.27-.46c.67-.134 1.34-.27 2.01-.403.22-.043.442-.088.663-.106.31-.025.523.17.554.482.008.073.012.148.012.223.002 1.91.002 3.822 0 5.732z",
|
|
169
|
+
youtube: "M12 0C5.376 0 0 5.376 0 12s5.376 12 12 12 12-5.376 12-12S18.624 0 12 0zm0 19.104c-3.924 0-7.104-3.18-7.104-7.104S8.076 4.896 12 4.896s7.104 3.18 7.104 7.104-3.18 7.104-7.104 7.104zm0-13.332c-3.432 0-6.228 2.796-6.228 6.228S8.568 18.228 12 18.228s6.228-2.796 6.228-6.228S15.432 5.772 12 5.772zM9.684 15.54V8.46L15.816 12l-6.132 3.54z"
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/picked.ts
|
|
173
|
+
var str = (v, max) => typeof v === "string" && v.trim() ? v.trim().slice(0, max) : void 0;
|
|
174
|
+
var https = (v) => typeof v === "string" && v.startsWith("https://") && v.length < 1e3 ? v : void 0;
|
|
175
|
+
function readPickedSong(value) {
|
|
176
|
+
let v = value;
|
|
177
|
+
if (typeof v === "string") {
|
|
178
|
+
try {
|
|
179
|
+
v = JSON.parse(v);
|
|
180
|
+
} catch {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!v || typeof v !== "object") return null;
|
|
185
|
+
const o = v;
|
|
186
|
+
const title = str(o.title, 200);
|
|
187
|
+
if (!title) return null;
|
|
188
|
+
const yt = o.youtube?.id;
|
|
189
|
+
return {
|
|
190
|
+
title,
|
|
191
|
+
artist: str(o.artist, 200) ?? "",
|
|
192
|
+
...str(o.album, 200) ? { album: str(o.album, 200) } : {},
|
|
193
|
+
...https(o.artwork) ? { artwork: https(o.artwork) } : {},
|
|
194
|
+
...https(o.apple)?.startsWith("https://music.apple.com/") ? { apple: https(o.apple) } : {},
|
|
195
|
+
...typeof yt === "string" && /^[\w-]{11}$/.test(yt) ? { youtube: { id: yt } } : {}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
async function searchSongs(query, { base = MUSIC_PLUG_URL, signal } = {}) {
|
|
199
|
+
const res = await fetch(`${base}/api/search?q=${encodeURIComponent(query)}`, { signal });
|
|
200
|
+
const data = await res.json().catch(() => null);
|
|
201
|
+
if (!res.ok || !data?.songs) throw new Error(data?.error ?? "\uC9C0\uAE08\uC740 \uCC3E\uC9C0 \uBABB\uD588\uC5B4\uC694");
|
|
202
|
+
return data.songs;
|
|
203
|
+
}
|
|
204
|
+
async function matchYoutube(song, { base = MUSIC_PLUG_URL } = {}) {
|
|
205
|
+
try {
|
|
206
|
+
const res = await fetch(`${base}/api/match?t=${encodeURIComponent(song.title)}&a=${encodeURIComponent(song.artist)}`);
|
|
207
|
+
const data = await res.json();
|
|
208
|
+
return typeof data.youtube === "string" && /^[\w-]{11}$/.test(data.youtube) ? data.youtube : null;
|
|
209
|
+
} catch {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
149
213
|
export {
|
|
214
|
+
LINKABLE_SERVICES,
|
|
215
|
+
LOGO_PATHS,
|
|
150
216
|
MUSIC_PLUG_URL,
|
|
151
217
|
SERVICES,
|
|
218
|
+
cleanSongLinks,
|
|
152
219
|
cleanTitle,
|
|
153
220
|
getService,
|
|
154
221
|
linkService,
|
|
155
222
|
listenGoUrl,
|
|
156
223
|
listenPageUrl,
|
|
224
|
+
matchYoutube,
|
|
225
|
+
readPickedSong,
|
|
226
|
+
searchSongs,
|
|
157
227
|
songFromUrl,
|
|
158
228
|
songFromVideo,
|
|
159
229
|
songFromYoutube,
|
package/dist/player.d.ts
CHANGED
|
@@ -1,75 +1,76 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
import { S as SongSearchOptions, P as PlugPlayerOptions, a as Song, b as Service, c as ServiceId } from './index-CxM1NkLk.js';
|
|
4
|
+
export { u as usePlugPlayer, d as useSongSearch } from './index-CxM1NkLk.js';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* 곡 고르기 기본 화면: 인스타그램처럼 곡을 검색해서 고른다 (쓰는 사람 화면). 동작은 useSongSearch.
|
|
8
|
+
*
|
|
9
|
+
* ┌ 🔍 곡 이름이나 가수 ─────────────┐ 고른 뒤: ┌ [앨범] 밤편지 🔍 × ┐
|
|
10
|
+
* └──────────────────────────────────┘ │ 아이유 · Palette │
|
|
11
|
+
* ┌ [앨범] 밤편지 (▶) ┐ └─────────────────────────────┘
|
|
12
|
+
* │ 아이유 · Palette │
|
|
13
|
+
* └ … ┘
|
|
14
|
+
*
|
|
15
|
+
* - form 안에 두면 숨은 입력(name)에 고른 곡이 JSON으로 들어간다 (비우면 빈 값). 저장할 때 readPickedSong으로 읽는다.
|
|
16
|
+
* 스타일은 styles.css (흰 라운드 카드 + 그림자, PlugPlayer와 같은 모양).
|
|
9
17
|
*/
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
id: ServiceId;
|
|
18
|
+
type SongFieldProps = SongSearchOptions & {
|
|
19
|
+
/** 숨은 입력의 이름 */
|
|
13
20
|
name: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type Song = {
|
|
20
|
-
title: string;
|
|
21
|
-
artist: string;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
/** 'light'(기본) · 'dark' · 'auto' */
|
|
23
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: CSSProperties;
|
|
22
26
|
};
|
|
27
|
+
declare function SongField({ name, placeholder, theme, className, style, ...options }: SongFieldProps): react.JSX.Element;
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
|
-
*
|
|
30
|
+
* @madeinbruno/music-plug/player: 기본 화면. 어느 사이트에 붙여도 같은 모양(흰 라운드 카드 + 그림자)으로 보인다.
|
|
31
|
+
* 스타일은 '@madeinbruno/music-plug/styles.css' (클래스는 모두 mp-). 동작만 쓰고 직접 그리려면 '@madeinbruno/music-plug/headless'.
|
|
26
32
|
*
|
|
27
|
-
*
|
|
33
|
+
* ┌──────────────────────────────────────┐
|
|
34
|
+
* │ [앨범] 밤편지 (▶) │
|
|
35
|
+
* │ 아이유 │
|
|
36
|
+
* │ ──────────────────────────────────── │
|
|
37
|
+
* │ [멜론] 멜론에서 들어요 바꾸기 │ ← 듣는 곳을 고른 뒤에만
|
|
38
|
+
* └──────────────────────────────────────┘
|
|
28
39
|
*
|
|
29
|
-
* - 처음 누르면
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* - 고르면 그곳에서 이 곡을 연다 (Music plug가 곡을 찾아 보낸다. 폰에서는 앱으로). YouTube면 글 안에서 유튜브 플레이어가 열린다.
|
|
33
|
-
* - 고른 곳은 기억해서 다음부터는 누르면 바로 그곳에서 연다. 곡 옆에 옅게 '멜론 · 바꾸기'가 보이고, 바꾸기로 다시 고른다.
|
|
34
|
-
* 기억은 쿠키 mp_service(madeinbruno.com 아래에서는 Music plug와 같이)와 이 브라우저(localStorage)에 둔다.
|
|
35
|
-
* - 곡을 모르면(song이 null) 다른 곳에서 찾을 수 없어서 이 페이지에서 YouTube로만 튼다 (유튜브가 아닌 곡 링크면 그 링크를 연다).
|
|
36
|
-
* - 테마 음악을 정한 곡 링크(source)가 있으면, 듣는 사람이 같은 곳을 골랐을 때 찾지 않고 그 링크를 바로 연다.
|
|
37
|
-
* - 유튜브로 듣는 중에 읽어 내려가 플레이어가 화면 밖으로 나가면 왼쪽 아래에 멈추기·다시 듣기 단추가 뜬다 (avoid로 준 요소가 보일 때는 숨긴다).
|
|
38
|
-
*
|
|
39
|
-
* 스타일은 '@madeinbruno/music-plug/styles.css' (클래스는 모두 mp-). 곡 줄은 둘러싼 글의 색을 따르고, 듣기 플러그는 Music plug 색이다.
|
|
40
|
+
* - 처음 누르면 듣기 플러그(PlugSheet)가 떠서 어디서 들을지 고른다. 고른 곳은 기억해서 다음부터 바로 그곳에서 연다.
|
|
41
|
+
* - YouTube를 고르면 카드 안에 유튜브 플레이어가 열리고 ▶가 ❚❚(멈추기)가 된다. 읽어 내려가 플레이어가 화면 밖으로 나가면
|
|
42
|
+
* 왼쪽 아래에 작은 음악 바(▶/❚❚ + 흐르는 곡 제목)가 뜬다 (avoid로 준 요소가 보일 때는 숨긴다).
|
|
40
43
|
*/
|
|
41
|
-
type PlugPlayerProps = {
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
/** 유튜브 영상. 있으면 YouTube를 고를 때 글 안에서 바로 틀고, 없으면 YouTube로 연다 */
|
|
47
|
-
youtube?: {
|
|
48
|
-
id: string;
|
|
49
|
-
start?: number;
|
|
50
|
-
};
|
|
51
|
-
/** 이 곡을 정한 곡 링크 (songFromUrl이 준 service·url). 듣는 사람이 같은 곳을 고르면 그 링크를 바로 연다 */
|
|
52
|
-
source?: {
|
|
53
|
-
service: ServiceId;
|
|
54
|
-
url: string;
|
|
55
|
-
};
|
|
56
|
-
/** 유튜브 플레이어가 화면 밖일 때 뜨는 멈추기 단추를, 이 요소가 보이면 숨긴다 (예: '.mib-footer') */
|
|
57
|
-
avoid?: string;
|
|
58
|
-
/** Music plug 주소 (기본 https://musicplug.madeinbruno.com) */
|
|
59
|
-
base?: string;
|
|
44
|
+
type PlugPlayerProps = PlugPlayerOptions & {
|
|
45
|
+
/** 앨범 그림 주소 (없으면 Music plug 심볼) */
|
|
46
|
+
artwork?: string;
|
|
47
|
+
/** 'light'(기본) · 'dark' · 'auto'(기기 설정을 따름) */
|
|
48
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
60
49
|
className?: string;
|
|
50
|
+
style?: CSSProperties;
|
|
61
51
|
};
|
|
62
|
-
declare function PlugPlayer({
|
|
52
|
+
declare function PlugPlayer({ artwork, theme, className, style, ...options }: PlugPlayerProps): react.JSX.Element;
|
|
63
53
|
/**
|
|
64
|
-
*
|
|
65
|
-
* 바깥을 누르거나 Esc로 닫는다.
|
|
54
|
+
* 듣기 플러그: 어디서 들을지 고르는 창. 폰에서는 아래에서 올라오고, 넓은 화면에서는 가운데 카드.
|
|
55
|
+
* 바깥을 누르거나 Esc로 닫는다. 테마는 둘러싼 mp-ui의 것을 따른다 (따로 쓰면 theme으로).
|
|
66
56
|
*/
|
|
67
|
-
declare function PlugSheet({ song, services, current, onChoose, onClose, }: {
|
|
57
|
+
declare function PlugSheet({ song, services, current, onChoose, onClose, theme, }: {
|
|
68
58
|
song: Song | null;
|
|
69
59
|
services: Service[];
|
|
70
60
|
current: ServiceId | null;
|
|
71
61
|
onChoose: (s: Service) => void;
|
|
72
62
|
onClose: () => void;
|
|
63
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
64
|
+
}): react.JSX.Element;
|
|
65
|
+
/** 음원 서비스 표시: 공식 로고가 있으면 그것을, 없으면 그 색의 머리글자 동그라미 */
|
|
66
|
+
declare function ServiceMark({ service, size, className }: {
|
|
67
|
+
service: Service;
|
|
68
|
+
size?: number;
|
|
69
|
+
className?: string;
|
|
70
|
+
}): react.JSX.Element;
|
|
71
|
+
/** Music plug 심볼: 플러그 몸통, 꽂는 쇠 둘, 음파 막대 다섯 (어두운 타일 위에 그린다) */
|
|
72
|
+
declare function Symbol({ size }: {
|
|
73
|
+
size?: number;
|
|
73
74
|
}): react.JSX.Element;
|
|
74
75
|
|
|
75
|
-
export { PlugPlayer, type PlugPlayerProps, PlugSheet };
|
|
76
|
+
export { PlugPlayer, type PlugPlayerProps, PlugSheet, ServiceMark, SongField, type SongFieldProps, Symbol };
|