@madeinbruno/music-plug 0.4.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 +69 -6
- 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 +3 -1
- package/dist/index.js +11 -0
- package/dist/player.d.ts +48 -99
- package/dist/player.js +180 -363
- package/package.json +5 -1
- package/styles.css +374 -179
package/dist/player.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import {
|
|
3
|
+
usePlugPlayer,
|
|
4
|
+
useSongSearch
|
|
5
|
+
} from "./chunk-3HM3NTBS.js";
|
|
2
6
|
|
|
3
7
|
// src/player.tsx
|
|
4
|
-
import { useEffect
|
|
8
|
+
import { useEffect, useRef as useRef2, useState } from "react";
|
|
5
9
|
|
|
6
10
|
// src/logos.ts
|
|
7
11
|
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";
|
|
@@ -13,189 +17,59 @@ var LOGO_PATHS = {
|
|
|
13
17
|
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"
|
|
14
18
|
};
|
|
15
19
|
|
|
16
|
-
// src/services.ts
|
|
17
|
-
var SERVICES = [
|
|
18
|
-
{ id: "here", name: "YouTube", color: "#ff0033", initial: "Y" },
|
|
19
|
-
{ id: "ytvideo", name: "YouTube", color: "#ff0033", initial: "Y" },
|
|
20
|
-
{ id: "melon", name: "\uBA5C\uB860", color: "#00cd3c", initial: "M" },
|
|
21
|
-
{ id: "genie", name: "\uC9C0\uB2C8", color: "#2aa8ff", initial: "G" },
|
|
22
|
-
{ id: "bugs", name: "\uBC85\uC2A4", color: "#ff5a3c", initial: "B" },
|
|
23
|
-
{ id: "flo", name: "FLO", color: "#7a6bff", initial: "F" },
|
|
24
|
-
{ id: "vibe", name: "VIBE", color: "#ff4d8d", initial: "V" },
|
|
25
|
-
{ id: "spotify", name: "Spotify", color: "#1ed760", initial: "S" },
|
|
26
|
-
{ id: "apple", name: "Apple Music", color: "#fa586a", initial: "A" },
|
|
27
|
-
{ id: "youtube", name: "YouTube Music", color: "#ff4444", initial: "Y" }
|
|
28
|
-
];
|
|
29
|
-
function getService(id) {
|
|
30
|
-
return SERVICES.find((s) => s.id === id);
|
|
31
|
-
}
|
|
32
|
-
var MUSIC_PLUG_URL = "https://musicplug.madeinbruno.com";
|
|
33
|
-
function tail(song, youtube) {
|
|
34
|
-
const p = new URLSearchParams();
|
|
35
|
-
if (song?.title) p.set("t", song.title);
|
|
36
|
-
if (song?.artist) p.set("a", song.artist);
|
|
37
|
-
if (youtube?.id) p.set("v", youtube.id);
|
|
38
|
-
if (youtube?.start) p.set("start", String(youtube.start));
|
|
39
|
-
return p.toString();
|
|
40
|
-
}
|
|
41
|
-
function listenGoUrl(service, song, youtube, { base = MUSIC_PLUG_URL, remember = false } = {}) {
|
|
42
|
-
return `${base}/listen/go?s=${service}${remember ? "&remember=1" : ""}&${tail(song, youtube)}`;
|
|
43
|
-
}
|
|
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
20
|
// src/picker.tsx
|
|
21
|
+
import { useRef } from "react";
|
|
86
22
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
87
|
-
function SongField({ name,
|
|
88
|
-
const
|
|
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);
|
|
23
|
+
function SongField({ name, placeholder = "\uACE1 \uC774\uB984\uC774\uB098 \uAC00\uC218", theme = "light", className, style, ...options }) {
|
|
24
|
+
const s = useSongSearch(options);
|
|
95
25
|
const input = useRef(null);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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" }),
|
|
26
|
+
return /* @__PURE__ */ jsxs("div", { className: ["mp-ui mp-pick", className].filter(Boolean).join(" "), "data-mp-theme": theme, style, children: [
|
|
27
|
+
/* @__PURE__ */ jsx("input", { type: "hidden", name, value: s.value }),
|
|
28
|
+
s.song && !s.searching && /* @__PURE__ */ jsxs("div", { className: "mp-card mp-pick__chosen", children: [
|
|
29
|
+
s.song.artwork ? /* @__PURE__ */ jsx("img", { src: s.song.artwork, alt: "", className: "mp-art" }) : /* @__PURE__ */ jsx("span", { className: "mp-art mp-art--empty", "aria-hidden": "true" }),
|
|
155
30
|
/* @__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 ") })
|
|
31
|
+
/* @__PURE__ */ jsx("span", { className: "mp-pick__title", children: s.song.title }),
|
|
32
|
+
/* @__PURE__ */ jsx("span", { className: "mp-pick__sub", children: [s.song.artist, s.song.album].filter(Boolean).join(" \xB7 ") })
|
|
158
33
|
] }),
|
|
159
|
-
/* @__PURE__ */
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
34
|
+
/* @__PURE__ */ jsx(
|
|
35
|
+
"button",
|
|
36
|
+
{
|
|
37
|
+
type: "button",
|
|
38
|
+
className: "mp-icon-button",
|
|
39
|
+
"aria-label": "\uB2E4\uB978 \uACE1 \uCC3E\uAE30",
|
|
40
|
+
title: "\uB2E4\uB978 \uACE1 \uCC3E\uAE30",
|
|
41
|
+
onClick: () => {
|
|
42
|
+
s.startSearch();
|
|
43
|
+
window.setTimeout(() => input.current?.focus(), 0);
|
|
44
|
+
},
|
|
45
|
+
children: /* @__PURE__ */ jsx(SearchIcon, {})
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mp-icon-button", "aria-label": "\uACE1 \uBE7C\uAE30", title: "\uACE1 \uBE7C\uAE30", onClick: s.clear, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
|
|
173
49
|
] }),
|
|
174
|
-
|
|
175
|
-
/* @__PURE__ */ jsxs("label", { className: "mp-pick__bar", children: [
|
|
176
|
-
/* @__PURE__ */ jsx(
|
|
50
|
+
s.searching && /* @__PURE__ */ jsxs("div", { className: "mp-pick__search", children: [
|
|
51
|
+
/* @__PURE__ */ jsxs("label", { className: "mp-card mp-pick__bar", children: [
|
|
52
|
+
/* @__PURE__ */ jsx(SearchIcon, {}),
|
|
177
53
|
/* @__PURE__ */ jsx(
|
|
178
54
|
"input",
|
|
179
55
|
{
|
|
180
56
|
ref: input,
|
|
181
57
|
type: "search",
|
|
182
|
-
value: query,
|
|
183
|
-
onChange: (e) => setQuery(e.target.value),
|
|
58
|
+
value: s.query,
|
|
59
|
+
onChange: (e) => s.setQuery(e.target.value),
|
|
184
60
|
onKeyDown: (e) => e.key === "Enter" && e.preventDefault(),
|
|
185
61
|
placeholder,
|
|
186
62
|
"aria-label": "\uACE1 \uCC3E\uAE30",
|
|
187
63
|
autoComplete: "off"
|
|
188
64
|
}
|
|
189
65
|
),
|
|
190
|
-
song && /* @__PURE__ */ jsx("button", { type: "button",
|
|
66
|
+
s.status === "loading" || s.status === "matching" ? /* @__PURE__ */ jsx("span", { className: "mp-spinner", "aria-label": s.status === "matching" ? "\uACE0\uB974\uB294 \uC911" : "\uCC3E\uB294 \uC911" }) : s.song && /* @__PURE__ */ jsx("button", { type: "button", className: "mp-icon-button", "aria-label": "\uADF8\uB9CC \uCC3E\uAE30", title: "\uADF8\uB9CC \uCC3E\uAE30", onClick: s.stopSearch, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
|
|
191
67
|
] }),
|
|
192
|
-
status === "
|
|
193
|
-
status === "
|
|
194
|
-
status
|
|
195
|
-
|
|
196
|
-
|
|
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" }),
|
|
68
|
+
s.status === "empty" && /* @__PURE__ */ jsx("p", { className: "mp-pick__note", children: "\uCC3E\uB294 \uACE1\uC774 \uC5C6\uC5B4\uC694" }),
|
|
69
|
+
s.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" }),
|
|
70
|
+
s.results.length > 0 && s.status !== "matching" && /* @__PURE__ */ jsx("ul", { className: "mp-card mp-pick__list", "aria-label": "\uCC3E\uC740 \uACE1", children: s.results.map((r, i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
71
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "mp-pick__row", onClick: () => void s.pick(r), children: [
|
|
72
|
+
r.artwork ? /* @__PURE__ */ jsx("img", { src: r.artwork, alt: "", className: "mp-art", loading: "lazy" }) : /* @__PURE__ */ jsx("span", { className: "mp-art mp-art--empty", "aria-hidden": "true" }),
|
|
199
73
|
/* @__PURE__ */ jsxs("span", { className: "mp-pick__text", children: [
|
|
200
74
|
/* @__PURE__ */ jsx("span", { className: "mp-pick__title", children: r.title }),
|
|
201
75
|
/* @__PURE__ */ jsx("span", { className: "mp-pick__sub", children: [r.artist, r.album].filter(Boolean).join(" \xB7 ") })
|
|
@@ -205,163 +79,78 @@ function SongField({ name, defaultValue = null, onChange, placeholder = "\uACE1
|
|
|
205
79
|
"button",
|
|
206
80
|
{
|
|
207
81
|
type: "button",
|
|
208
|
-
className: "mp-
|
|
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 ? "
|
|
82
|
+
className: "mp-play mp-play--small mp-play--soft",
|
|
83
|
+
"aria-label": s.previewing === r.preview ? "\uBBF8\uB9AC \uB4E3\uAE30 \uBA48\uCD94\uAE30" : "\uBBF8\uB9AC \uB4E3\uAE30",
|
|
84
|
+
"aria-pressed": s.previewing === r.preview,
|
|
85
|
+
onClick: () => s.togglePreview(r.preview),
|
|
86
|
+
children: /* @__PURE__ */ jsx("svg", { width: "11", height: "11", viewBox: "0 0 12 12", "aria-hidden": "true", children: s.previewing === r.preview ? /* @__PURE__ */ jsx("rect", { x: "2", y: "2", width: "8", height: "8", rx: "1.2", fill: "currentColor" }) : /* @__PURE__ */ jsx("path", { d: "M3.4 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.4 1.8z", fill: "currentColor" }) })
|
|
213
87
|
}
|
|
214
88
|
)
|
|
215
89
|
] }, `${r.title}|${r.artist}|${i}`)) })
|
|
216
90
|
] })
|
|
217
91
|
] });
|
|
218
92
|
}
|
|
93
|
+
function SearchIcon() {
|
|
94
|
+
return /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", "aria-hidden": "true", className: "mp-pick__icon", children: [
|
|
95
|
+
/* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "4.6" }),
|
|
96
|
+
/* @__PURE__ */ jsx("path", { d: "M10.4 10.4L14 14" })
|
|
97
|
+
] });
|
|
98
|
+
}
|
|
99
|
+
function CloseIcon() {
|
|
100
|
+
return /* @__PURE__ */ jsx("svg", { width: "12", height: "12", viewBox: "0 0 14 14", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M2 2l10 10M12 2L2 12", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }) });
|
|
101
|
+
}
|
|
219
102
|
|
|
220
103
|
// src/player.tsx
|
|
221
104
|
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
localStorage.setItem(KEY, id);
|
|
236
|
-
} catch {
|
|
237
|
-
}
|
|
238
|
-
const host = location.hostname;
|
|
239
|
-
const shared = host === SHARED_DOMAIN || host.endsWith(`.${SHARED_DOMAIN}`) ? `; domain=.${SHARED_DOMAIN}` : "";
|
|
240
|
-
document.cookie = `mp_service=${id}; path=/; max-age=31536000; samesite=lax${shared}`;
|
|
241
|
-
}
|
|
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()), []);
|
|
250
|
-
const known = Boolean(song?.title);
|
|
251
|
-
const services = SERVICES.filter((s) => s.id === "here" ? Boolean(youtube) : s.id === "ytvideo" ? !youtube : known || Boolean(links?.[s.id]));
|
|
252
|
-
const isYoutube = (id) => id === "here" || id === "ytvideo";
|
|
253
|
-
const remembered = services.find((s) => s.id === choice || isYoutube(choice) && isYoutube(s.id)) ?? null;
|
|
254
|
-
function play(s) {
|
|
255
|
-
if (s.id === "here") {
|
|
256
|
-
setOpen(true);
|
|
257
|
-
setPlaying(true);
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
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);
|
|
262
|
-
window.open(direct ?? listenGoUrl(s.id, song, youtube, { base }), "_blank", "noopener");
|
|
263
|
-
}
|
|
264
|
-
function choose(s) {
|
|
265
|
-
saveChoice(s.id);
|
|
266
|
-
setChoice(s.id);
|
|
267
|
-
setSheet(false);
|
|
268
|
-
play(s);
|
|
269
|
-
}
|
|
270
|
-
function tap() {
|
|
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");
|
|
274
|
-
if (remembered) play(remembered);
|
|
275
|
-
else setSheet(true);
|
|
276
|
-
}
|
|
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(() => {
|
|
310
|
-
if (!open) return;
|
|
311
|
-
const seen = /* @__PURE__ */ new Map();
|
|
312
|
-
const io = new IntersectionObserver((entries) => {
|
|
313
|
-
for (const e of entries) seen.set(e.target, e.isIntersecting);
|
|
314
|
-
setChip(![...seen.values()].some(Boolean));
|
|
315
|
-
});
|
|
316
|
-
const targets = [frame.current, avoid ? document.querySelector(avoid) : null].filter((el) => el !== null);
|
|
317
|
-
for (const el of targets) {
|
|
318
|
-
seen.set(el, false);
|
|
319
|
-
io.observe(el);
|
|
320
|
-
}
|
|
321
|
-
return () => io.disconnect();
|
|
322
|
-
}, [open, avoid]);
|
|
323
|
-
const label = song && [song.title, song.artist].filter(Boolean).join(" \xB7 ") || fallbackLabel;
|
|
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" }),
|
|
328
|
-
" ",
|
|
329
|
-
label
|
|
105
|
+
function PlugPlayer({ artwork, theme = "light", className, style, ...options }) {
|
|
106
|
+
const p = usePlugPlayer(options);
|
|
107
|
+
const { video } = p;
|
|
108
|
+
const playing = video.open && video.playing;
|
|
109
|
+
return /* @__PURE__ */ jsxs2("div", { className: cx("mp-ui mp-card mp-player", className), "data-mp-theme": theme, style, children: [
|
|
110
|
+
/* @__PURE__ */ jsxs2("div", { className: "mp-player__row", children: [
|
|
111
|
+
/* @__PURE__ */ jsxs2("button", { type: "button", className: "mp-player__main", onClick: p.listen, "aria-label": `${p.title}${p.artist ? ` \xB7 ${p.artist}` : ""} \uB4E3\uAE30`, children: [
|
|
112
|
+
/* @__PURE__ */ jsx2(Artwork, { src: artwork }),
|
|
113
|
+
/* @__PURE__ */ jsxs2("span", { className: "mp-player__text", children: [
|
|
114
|
+
/* @__PURE__ */ jsx2("span", { className: "mp-player__title", children: p.title }),
|
|
115
|
+
p.artist && /* @__PURE__ */ jsx2("span", { className: "mp-player__artist", children: p.artist })
|
|
116
|
+
] })
|
|
330
117
|
] }),
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
118
|
+
/* @__PURE__ */ jsx2(
|
|
119
|
+
"button",
|
|
120
|
+
{
|
|
121
|
+
type: "button",
|
|
122
|
+
className: "mp-play",
|
|
123
|
+
onClick: video.open ? video.toggle : p.listen,
|
|
124
|
+
"aria-label": playing ? "\uBA48\uCD94\uAE30" : "\uB4E3\uAE30",
|
|
125
|
+
"aria-pressed": video.open ? playing : void 0,
|
|
126
|
+
children: /* @__PURE__ */ jsx2(PlayIcon, { playing })
|
|
127
|
+
}
|
|
128
|
+
)
|
|
336
129
|
] }),
|
|
337
|
-
|
|
338
|
-
"
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
130
|
+
p.current && (p.known || options.links) && /* @__PURE__ */ jsxs2("div", { className: "mp-player__foot", children: [
|
|
131
|
+
/* @__PURE__ */ jsxs2("span", { className: "mp-player__via", children: [
|
|
132
|
+
/* @__PURE__ */ jsx2(ServiceMark, { service: p.current, size: 16 }),
|
|
133
|
+
p.current.name,
|
|
134
|
+
"\uC5D0\uC11C \uB4E4\uC5B4\uC694"
|
|
135
|
+
] }),
|
|
136
|
+
/* @__PURE__ */ jsx2("button", { type: "button", className: "mp-link", onClick: p.picker.show, children: "\uBC14\uAFB8\uAE30" })
|
|
137
|
+
] }),
|
|
138
|
+
video.frameProps && /* @__PURE__ */ jsx2("div", { className: "mp-player__video", children: /* @__PURE__ */ jsx2("iframe", { ...video.frameProps }) }),
|
|
139
|
+
video.offscreen && /* @__PURE__ */ jsxs2("button", { type: "button", className: "mp-card mp-mini", onClick: video.toggle, "aria-label": `${p.title} ${video.playing ? "\uBA48\uCD94\uAE30" : "\uD2C0\uAE30"}`, children: [
|
|
140
|
+
/* @__PURE__ */ jsx2("span", { className: "mp-play mp-play--small", "aria-hidden": "true", children: /* @__PURE__ */ jsx2(PlayIcon, { playing: video.playing }) }),
|
|
141
|
+
/* @__PURE__ */ jsx2(Marquee, { text: p.title })
|
|
142
|
+
] }),
|
|
143
|
+
p.picker.open && /* @__PURE__ */ jsx2(
|
|
144
|
+
PlugSheet,
|
|
350
145
|
{
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
},
|
|
358
|
-
children: [
|
|
359
|
-
/* @__PURE__ */ jsx2(PlayIcon, { playing }),
|
|
360
|
-
/* @__PURE__ */ jsx2(Marquee, { text: song?.title || fallbackLabel })
|
|
361
|
-
]
|
|
146
|
+
song: { title: p.title, artist: p.artist },
|
|
147
|
+
services: p.services,
|
|
148
|
+
current: p.current?.id ?? null,
|
|
149
|
+
onChoose: p.listenOn,
|
|
150
|
+
onClose: p.picker.close,
|
|
151
|
+
theme
|
|
362
152
|
}
|
|
363
|
-
)
|
|
364
|
-
sheet && /* @__PURE__ */ jsx2(PlugSheet, { song, services, current: remembered?.id ?? null, onChoose: choose, onClose: () => setSheet(false) })
|
|
153
|
+
)
|
|
365
154
|
] });
|
|
366
155
|
}
|
|
367
156
|
function PlugSheet({
|
|
@@ -369,9 +158,10 @@ function PlugSheet({
|
|
|
369
158
|
services,
|
|
370
159
|
current,
|
|
371
160
|
onChoose,
|
|
372
|
-
onClose
|
|
161
|
+
onClose,
|
|
162
|
+
theme
|
|
373
163
|
}) {
|
|
374
|
-
|
|
164
|
+
useEffect(() => {
|
|
375
165
|
const onKey = (e) => e.key === "Escape" && onClose();
|
|
376
166
|
window.addEventListener("keydown", onKey);
|
|
377
167
|
const prev = document.body.style.overflow;
|
|
@@ -381,46 +171,70 @@ function PlugSheet({
|
|
|
381
171
|
document.body.style.overflow = prev;
|
|
382
172
|
};
|
|
383
173
|
}, [onClose]);
|
|
384
|
-
return /* @__PURE__ */ jsx2(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
/* @__PURE__ */
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
174
|
+
return /* @__PURE__ */ jsx2(
|
|
175
|
+
"div",
|
|
176
|
+
{
|
|
177
|
+
className: "mp-ui mp-sheet",
|
|
178
|
+
"data-mp-theme": theme,
|
|
179
|
+
role: "dialog",
|
|
180
|
+
"aria-modal": "true",
|
|
181
|
+
"aria-label": "\uC5B4\uB514\uC11C \uB4E4\uC744\uAE4C\uC694",
|
|
182
|
+
onClick: (e) => e.target === e.currentTarget && onClose(),
|
|
183
|
+
children: /* @__PURE__ */ jsxs2("div", { className: "mp-card mp-sheet__panel", children: [
|
|
184
|
+
/* @__PURE__ */ jsxs2("div", { className: "mp-sheet__head", children: [
|
|
185
|
+
/* @__PURE__ */ jsxs2("span", { className: "mp-sheet__brand", children: [
|
|
186
|
+
/* @__PURE__ */ jsx2(Symbol, { size: 22 }),
|
|
187
|
+
" Music plug"
|
|
188
|
+
] }),
|
|
189
|
+
/* @__PURE__ */ jsx2("button", { type: "button", className: "mp-icon-button", onClick: onClose, "aria-label": "\uB2EB\uAE30", children: /* @__PURE__ */ jsx2("svg", { width: "14", height: "14", viewBox: "0 0 14 14", "aria-hidden": "true", children: /* @__PURE__ */ jsx2("path", { d: "M2 2l10 10M12 2L2 12", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }) }) })
|
|
190
|
+
] }),
|
|
191
|
+
song?.title && /* @__PURE__ */ jsxs2("div", { className: "mp-sheet__song", children: [
|
|
192
|
+
/* @__PURE__ */ jsx2("p", { className: "mp-sheet__song-title", children: song.title }),
|
|
193
|
+
song.artist && /* @__PURE__ */ jsx2("p", { className: "mp-sheet__sub", children: song.artist })
|
|
194
|
+
] }),
|
|
195
|
+
/* @__PURE__ */ jsx2("p", { className: "mp-sheet__ask", children: "\uC5B4\uB514\uC11C \uB4E4\uC744\uAE4C\uC694?" }),
|
|
196
|
+
/* @__PURE__ */ jsx2("ul", { className: "mp-sheet__grid", children: services.map((s) => /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsxs2(
|
|
197
|
+
"button",
|
|
198
|
+
{
|
|
199
|
+
type: "button",
|
|
200
|
+
"aria-current": (current ? s.id === current : s.id === "here" || s.id === "ytvideo") ? "true" : void 0,
|
|
201
|
+
onClick: () => onChoose(s),
|
|
202
|
+
children: [
|
|
203
|
+
/* @__PURE__ */ jsx2(ServiceMark, { service: s, size: 24 }),
|
|
204
|
+
/* @__PURE__ */ jsx2("span", { children: s.name }),
|
|
205
|
+
(s.id === "here" || s.id === "ytvideo") && /* @__PURE__ */ jsx2("span", { className: "mp-sheet__tag", children: "\uAE30\uBCF8" })
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
) }, s.id)) }),
|
|
209
|
+
/* @__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. \uCE74\uB4DC\uC758 \u2018\uBC14\uAFB8\uAE30\u2019\uB85C \uB2E4\uC2DC \uACE0\uB97C \uC218 \uC788\uC5B4\uC694." })
|
|
210
|
+
] })
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
function ServiceMark({ service, size = 24, className }) {
|
|
215
|
+
const logo = LOGO_PATHS[service.id];
|
|
216
|
+
return /* @__PURE__ */ jsx2("svg", { width: size, height: size, viewBox: "0 0 24 24", "aria-hidden": "true", className: cx("mp-mark", className), children: logo ? /* @__PURE__ */ jsx2("path", { d: logo, fill: service.color }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
217
|
+
/* @__PURE__ */ jsx2("circle", { cx: "12", cy: "12", r: "12", fill: service.color }),
|
|
218
|
+
/* @__PURE__ */ jsx2("text", { x: "12", y: "16.8", textAnchor: "middle", fontSize: "13.5", fontWeight: "800", fill: "#0b0b0d", children: service.initial })
|
|
411
219
|
] }) });
|
|
412
220
|
}
|
|
221
|
+
function Artwork({ src }) {
|
|
222
|
+
if (src) {
|
|
223
|
+
return /* @__PURE__ */ jsx2("img", { src, alt: "", className: "mp-art", loading: "lazy" });
|
|
224
|
+
}
|
|
225
|
+
return /* @__PURE__ */ jsx2("span", { className: "mp-art mp-art--plug", "aria-hidden": "true", children: /* @__PURE__ */ jsx2(Symbol, { size: 30 }) });
|
|
226
|
+
}
|
|
413
227
|
function PlayIcon({ playing }) {
|
|
414
|
-
return /* @__PURE__ */ jsx2("svg", {
|
|
228
|
+
return /* @__PURE__ */ jsx2("svg", { width: "14", height: "14", viewBox: "0 0 12 12", "aria-hidden": "true", children: playing ? /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
415
229
|
/* @__PURE__ */ jsx2("rect", { x: "2", y: "1.5", width: "2.6", height: "9", rx: "0.8", fill: "currentColor" }),
|
|
416
230
|
/* @__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" }) });
|
|
231
|
+
] }) : /* @__PURE__ */ jsx2("path", { d: "M3.4 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.4 1.8z", fill: "currentColor" }) });
|
|
418
232
|
}
|
|
419
233
|
function Marquee({ text }) {
|
|
420
234
|
const box = useRef2(null);
|
|
421
235
|
const inner = useRef2(null);
|
|
422
|
-
const [shift, setShift] =
|
|
423
|
-
|
|
236
|
+
const [shift, setShift] = useState(0);
|
|
237
|
+
useEffect(() => {
|
|
424
238
|
const measure = () => {
|
|
425
239
|
if (box.current && inner.current) setShift(Math.max(0, inner.current.scrollWidth - box.current.clientWidth));
|
|
426
240
|
};
|
|
@@ -432,29 +246,32 @@ function Marquee({ text }) {
|
|
|
432
246
|
const style = shift ? { "--mp-shift": `-${shift}px`, "--mp-dur": `${(shift / 30 + 3).toFixed(1)}s` } : void 0;
|
|
433
247
|
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
248
|
}
|
|
435
|
-
function
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
/* @__PURE__ */
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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" })
|
|
249
|
+
function Symbol({ size = 20 }) {
|
|
250
|
+
return /* @__PURE__ */ jsxs2("svg", { width: size, height: size, viewBox: "0 0 64 64", "aria-hidden": "true", className: "mp-symbol", children: [
|
|
251
|
+
/* @__PURE__ */ jsx2("rect", { width: "64", height: "64", rx: "14", fill: "#141417" }),
|
|
252
|
+
/* @__PURE__ */ jsxs2("g", { transform: "translate(0 3.5)", children: [
|
|
253
|
+
/* @__PURE__ */ jsx2("rect", { x: "21.5", y: "8.5", width: "5.5", height: "13", rx: "2.75", fill: "#f2f2ee" }),
|
|
254
|
+
/* @__PURE__ */ jsx2("rect", { x: "37", y: "8.5", width: "5.5", height: "13", rx: "2.75", fill: "#f2f2ee" }),
|
|
255
|
+
/* @__PURE__ */ jsx2("rect", { x: "12", y: "19", width: "40", height: "29", rx: "5", fill: "#f2f2ee" }),
|
|
256
|
+
/* @__PURE__ */ jsxs2("g", { fill: "#141417", children: [
|
|
257
|
+
/* @__PURE__ */ jsx2("rect", { x: "17.9", y: "30.25", width: "3.4", height: "6.5", rx: "1.7" }),
|
|
258
|
+
/* @__PURE__ */ jsx2("rect", { x: "24.1", y: "27.25", width: "3.4", height: "12.5", rx: "1.7" }),
|
|
259
|
+
/* @__PURE__ */ jsx2("rect", { x: "30.3", y: "24.5", width: "3.4", height: "18", rx: "1.7" }),
|
|
260
|
+
/* @__PURE__ */ jsx2("rect", { x: "36.5", y: "27.25", width: "3.4", height: "12.5", rx: "1.7" }),
|
|
261
|
+
/* @__PURE__ */ jsx2("rect", { x: "42.7", y: "30.25", width: "3.4", height: "6.5", rx: "1.7" })
|
|
262
|
+
] })
|
|
453
263
|
] })
|
|
454
|
-
] })
|
|
264
|
+
] });
|
|
265
|
+
}
|
|
266
|
+
function cx(...names) {
|
|
267
|
+
return names.filter(Boolean).join(" ");
|
|
455
268
|
}
|
|
456
269
|
export {
|
|
457
270
|
PlugPlayer,
|
|
458
271
|
PlugSheet,
|
|
459
|
-
|
|
272
|
+
ServiceMark,
|
|
273
|
+
SongField,
|
|
274
|
+
Symbol,
|
|
275
|
+
usePlugPlayer,
|
|
276
|
+
useSongSearch
|
|
460
277
|
};
|