@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/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 as useEffect2, useRef as useRef2, useState as useState2 } from "react";
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, 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);
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
- 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" }),
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__ */ 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
- ] })
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
- (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" }),
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", onClick: () => setSearching(false), children: "\uADF8\uB9CC" })
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 === "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" }),
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-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"
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
- var KEY = "musicplug.service";
223
- var SHARED_DOMAIN = "madeinbruno.com";
224
- function readChoice() {
225
- const cookie = document.cookie.match(/(?:^|;\s*)mp_service=([^;]+)/)?.[1];
226
- let stored = null;
227
- try {
228
- stored = localStorage.getItem(KEY);
229
- } catch {
230
- }
231
- return getService(cookie)?.id ?? getService(stored)?.id ?? null;
232
- }
233
- function saveChoice(id) {
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
- (known || links) && remembered && /* @__PURE__ */ jsxs2("span", { className: "mp-plug__where", children: [
332
- remembered.name,
333
- /* @__PURE__ */ jsx2("span", { "aria-hidden": "true", children: " \xB7 " }),
334
- /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => setSheet(true), children: "\uBC14\uAFB8\uAE30" })
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
- open && youtube && /* @__PURE__ */ jsx2("div", { className: "mp-plug__frame", children: /* @__PURE__ */ jsx2(
338
- "iframe",
339
- {
340
- ref: frame,
341
- src: `${YT_ORIGIN}/embed/${youtube.id}?autoplay=1&playsinline=1&rel=0&enablejsapi=1&origin=${encodeURIComponent(location.origin)}${youtube.start ? `&start=${youtube.start}` : ""}`,
342
- title: label,
343
- allow: "autoplay; encrypted-media; picture-in-picture",
344
- allowFullScreen: true,
345
- onLoad: listen
346
- }
347
- ) }),
348
- open && chip && /* @__PURE__ */ jsxs2(
349
- "button",
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
- type: "button",
352
- className: "mp-plug__chip",
353
- "aria-label": `${song?.title || fallbackLabel} ${playing ? "\uBA48\uCD94\uAE30" : "\uD2C0\uAE30"}`,
354
- onClick: () => {
355
- command(playing ? "pauseVideo" : "playVideo");
356
- setPlaying(!playing);
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
- useEffect2(() => {
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("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, {}),
388
- " Music plug"
389
- ] }),
390
- /* @__PURE__ */ jsx2("button", { type: "button", className: "mp-sheet__close", onClick: onClose, "aria-label": "\uB2EB\uAE30", children: "\xD7" })
391
- ] }),
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 })
395
- ] }),
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(
398
- "button",
399
- {
400
- type: "button",
401
- "aria-current": (current ? s.id === current : s.id === "here" || s.id === "ytvideo") ? "true" : void 0,
402
- onClick: () => onChoose(s),
403
- children: [
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" })
407
- ]
408
- }
409
- ) }, s.id)) }),
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." })
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", { className: "mp-plug__icon", width: "12", height: "12", viewBox: "0 0 12 12", "aria-hidden": "true", children: playing ? /* @__PURE__ */ jsxs2(Fragment, { children: [
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] = useState2(0);
423
- useEffect2(() => {
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 Mark({ service }) {
436
- const logo = LOGO_PATHS[service.id];
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 })
440
- ] }) });
441
- }
442
- function Symbol() {
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" })
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
- SongField
272
+ ServiceMark,
273
+ SongField,
274
+ Symbol,
275
+ usePlugPlayer,
276
+ useSongSearch
460
277
  };