@madeinbruno/music-plug 0.1.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/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, avoid, base = MUSIC_PLUG_URL, className }) {
68
- const [choice, setChoice] = useState(null);
69
- const [sheet, setSheet] = useState(false);
70
- const [open, setOpen] = useState(false);
71
- const [playing, setPlaying] = useState(false);
72
- const [chip, setChip] = useState(false);
73
- const frame = useRef(null);
74
- useEffect(() => setChoice(readChoice()), []);
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,9 @@ function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube
82
257
  setPlaying(true);
83
258
  return;
84
259
  }
85
- window.open(listenGoUrl(s.id, song, youtube, { base }), "_blank", "noopener");
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");
86
263
  }
87
264
  function choose(s) {
88
265
  saveChoice(s.id);
@@ -91,12 +268,45 @@ function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube
91
268
  play(s);
92
269
  }
93
270
  function tap() {
94
- if (!known && youtube) return play(SERVICES[0]);
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");
95
274
  if (remembered) play(remembered);
96
275
  else setSheet(true);
97
276
  }
98
- const command = (func) => frame.current?.contentWindow?.postMessage(JSON.stringify({ event: "command", func, args: [] }), "https://www.youtube-nocookie.com");
99
- useEffect(() => {
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(() => {
100
310
  if (!open) return;
101
311
  const seen = /* @__PURE__ */ new Map();
102
312
  const io = new IntersectionObserver((entries) => {
@@ -111,45 +321,47 @@ function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube
111
321
  return () => io.disconnect();
112
322
  }, [open, avoid]);
113
323
  const label = song && [song.title, song.artist].filter(Boolean).join(" \xB7 ") || fallbackLabel;
114
- return /* @__PURE__ */ jsxs("div", { className: ["mp-plug", className].filter(Boolean).join(" "), children: [
115
- /* @__PURE__ */ jsxs("div", { className: "mp-plug__row", children: [
116
- /* @__PURE__ */ jsxs("button", { type: "button", className: "mp-plug__song", onClick: tap, children: [
117
- /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u266A" }),
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" }),
118
328
  " ",
119
329
  label
120
330
  ] }),
121
- known && remembered && /* @__PURE__ */ jsxs("span", { className: "mp-plug__where", children: [
331
+ (known || links) && remembered && /* @__PURE__ */ jsxs2("span", { className: "mp-plug__where", children: [
122
332
  remembered.name,
123
- /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: " \xB7 " }),
124
- /* @__PURE__ */ jsx("button", { type: "button", onClick: () => setSheet(true), children: "\uBC14\uAFB8\uAE30" })
333
+ /* @__PURE__ */ jsx2("span", { "aria-hidden": "true", children: " \xB7 " }),
334
+ /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => setSheet(true), children: "\uBC14\uAFB8\uAE30" })
125
335
  ] })
126
336
  ] }),
127
- open && youtube && /* @__PURE__ */ jsx("div", { className: "mp-plug__frame", children: /* @__PURE__ */ jsx(
337
+ open && youtube && /* @__PURE__ */ jsx2("div", { className: "mp-plug__frame", children: /* @__PURE__ */ jsx2(
128
338
  "iframe",
129
339
  {
130
340
  ref: frame,
131
- src: `https://www.youtube-nocookie.com/embed/${youtube.id}?autoplay=1&playsinline=1&rel=0&enablejsapi=1${youtube.start ? `&start=${youtube.start}` : ""}`,
341
+ src: `${YT_ORIGIN}/embed/${youtube.id}?autoplay=1&playsinline=1&rel=0&enablejsapi=1&origin=${encodeURIComponent(location.origin)}${youtube.start ? `&start=${youtube.start}` : ""}`,
132
342
  title: label,
133
343
  allow: "autoplay; encrypted-media; picture-in-picture",
134
- allowFullScreen: true
344
+ allowFullScreen: true,
345
+ onLoad: listen
135
346
  }
136
347
  ) }),
137
- open && chip && /* @__PURE__ */ jsxs(
348
+ open && chip && /* @__PURE__ */ jsxs2(
138
349
  "button",
139
350
  {
140
351
  type: "button",
141
352
  className: "mp-plug__chip",
353
+ "aria-label": `${song?.title || fallbackLabel} ${playing ? "\uBA48\uCD94\uAE30" : "\uD2C0\uAE30"}`,
142
354
  onClick: () => {
143
355
  command(playing ? "pauseVideo" : "playVideo");
144
356
  setPlaying(!playing);
145
357
  },
146
358
  children: [
147
- "\u266A ",
148
- playing ? "\uBA48\uCD94\uAE30" : "\uB2E4\uC2DC \uB4E3\uAE30"
359
+ /* @__PURE__ */ jsx2(PlayIcon, { playing }),
360
+ /* @__PURE__ */ jsx2(Marquee, { text: song?.title || fallbackLabel })
149
361
  ]
150
362
  }
151
363
  ),
152
- sheet && /* @__PURE__ */ jsx(PlugSheet, { song, services, current: remembered?.id ?? null, onChoose: choose, onClose: () => setSheet(false) })
364
+ sheet && /* @__PURE__ */ jsx2(PlugSheet, { song, services, current: remembered?.id ?? null, onChoose: choose, onClose: () => setSheet(false) })
153
365
  ] });
154
366
  }
155
367
  function PlugSheet({
@@ -159,7 +371,7 @@ function PlugSheet({
159
371
  onChoose,
160
372
  onClose
161
373
  }) {
162
- useEffect(() => {
374
+ useEffect2(() => {
163
375
  const onKey = (e) => e.key === "Escape" && onClose();
164
376
  window.addEventListener("keydown", onKey);
165
377
  const prev = document.body.style.overflow;
@@ -169,57 +381,80 @@ function PlugSheet({
169
381
  document.body.style.overflow = prev;
170
382
  };
171
383
  }, [onClose]);
172
- return /* @__PURE__ */ jsx("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__ */ jsxs("div", { className: "mp-sheet__panel", children: [
173
- /* @__PURE__ */ jsxs("div", { className: "mp-sheet__head", children: [
174
- /* @__PURE__ */ jsxs("span", { className: "mp-sheet__brand", children: [
175
- /* @__PURE__ */ jsx(Symbol, {}),
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, {}),
176
388
  " Music plug"
177
389
  ] }),
178
- /* @__PURE__ */ jsx("button", { type: "button", className: "mp-sheet__close", onClick: onClose, "aria-label": "\uB2EB\uAE30", children: "\xD7" })
390
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "mp-sheet__close", onClick: onClose, "aria-label": "\uB2EB\uAE30", children: "\xD7" })
179
391
  ] }),
180
- song?.title && /* @__PURE__ */ jsxs("div", { className: "mp-sheet__song", children: [
181
- /* @__PURE__ */ jsx("p", { className: "mp-sheet__song-title", children: song.title }),
182
- song.artist && /* @__PURE__ */ jsx("p", { className: "mp-sheet__sub", children: song.artist })
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 })
183
395
  ] }),
184
- /* @__PURE__ */ jsx("p", { className: "mp-sheet__ask", children: "\uC5B4\uB514\uC11C \uB4E4\uC744\uAE4C\uC694?" }),
185
- /* @__PURE__ */ jsx("ul", { className: "mp-sheet__grid", children: services.map((s) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
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(
186
398
  "button",
187
399
  {
188
400
  type: "button",
189
401
  "aria-current": (current ? s.id === current : s.id === "here" || s.id === "ytvideo") ? "true" : void 0,
190
402
  onClick: () => onChoose(s),
191
403
  children: [
192
- /* @__PURE__ */ jsx(Mark, { service: s }),
193
- /* @__PURE__ */ jsx("span", { children: s.name }),
194
- (s.id === "here" || s.id === "ytvideo") && /* @__PURE__ */ jsx("span", { className: "mp-sheet__tag", children: "\uAE30\uBCF8" })
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" })
195
407
  ]
196
408
  }
197
409
  ) }, s.id)) }),
198
- /* @__PURE__ */ jsx("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." })
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." })
199
411
  ] }) });
200
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
+ }
201
435
  function Mark({ service }) {
202
436
  const logo = LOGO_PATHS[service.id];
203
- return /* @__PURE__ */ jsx("svg", { width: "26", height: "26", viewBox: "0 0 24 24", "aria-hidden": "true", className: "mp-sheet__mark", children: logo ? /* @__PURE__ */ jsx("path", { d: logo, fill: service.color }) : /* @__PURE__ */ jsxs(Fragment, { children: [
204
- /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "12", fill: service.color }),
205
- /* @__PURE__ */ jsx("text", { x: "12", y: "16.8", textAnchor: "middle", fontSize: "13.5", fontWeight: "800", fill: "#0b0b0d", children: service.initial })
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 })
206
440
  ] }) });
207
441
  }
208
442
  function Symbol() {
209
- return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 64 64", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("g", { transform: "translate(0 3.5)", children: [
210
- /* @__PURE__ */ jsx("rect", { x: "21.5", y: "8.5", width: "5.5", height: "13", rx: "2.75", fill: "#f2f2ee" }),
211
- /* @__PURE__ */ jsx("rect", { x: "37", y: "8.5", width: "5.5", height: "13", rx: "2.75", fill: "#f2f2ee" }),
212
- /* @__PURE__ */ jsx("rect", { x: "12", y: "19", width: "40", height: "29", rx: "5", fill: "#f2f2ee" }),
213
- /* @__PURE__ */ jsxs("g", { fill: "#141417", children: [
214
- /* @__PURE__ */ jsx("rect", { x: "17.9", y: "30.25", width: "3.4", height: "6.5", rx: "1.7" }),
215
- /* @__PURE__ */ jsx("rect", { x: "24.1", y: "27.25", width: "3.4", height: "12.5", rx: "1.7" }),
216
- /* @__PURE__ */ jsx("rect", { x: "30.3", y: "24.5", width: "3.4", height: "18", rx: "1.7" }),
217
- /* @__PURE__ */ jsx("rect", { x: "36.5", y: "27.25", width: "3.4", height: "12.5", rx: "1.7" }),
218
- /* @__PURE__ */ jsx("rect", { x: "42.7", y: "30.25", width: "3.4", height: "6.5", rx: "1.7" })
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" })
219
453
  ] })
220
454
  ] }) });
221
455
  }
222
456
  export {
223
457
  PlugPlayer,
224
- PlugSheet
458
+ PlugSheet,
459
+ SongField
225
460
  };
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "@madeinbruno/music-plug",
3
- "version": "0.1.0",
4
- "description": "글 속 노래를 듣는 사람이 쓰는 음원 앱(멜론·지니·벅스·FLO·VIBE·Spotify·Apple Music·YouTube Music)에서, 없으면 YouTube로 바로 듣게 하는 플러그",
5
- "license": "MIT",
6
- "author": "codingbotPark <pbk575@gmail.com>",
7
- "homepage": "https://madeinbruno.com",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/codingbotPark/madeinbruno.git",
11
- "directory": "packages/music-plug"
12
- },
13
- "type": "module",
14
- "sideEffects": [
15
- "*.css"
16
- ],
17
- "main": "./dist/index.js",
18
- "types": "./dist/index.d.ts",
19
- "exports": {
20
- ".": {
21
- "types": "./dist/index.d.ts",
22
- "import": "./dist/index.js"
23
- },
24
- "./player": {
25
- "types": "./dist/player.d.ts",
26
- "import": "./dist/player.js"
27
- },
28
- "./styles.css": "./styles.css"
29
- },
30
- "files": [
31
- "dist",
32
- "styles.css"
33
- ],
34
- "scripts": {
35
- "build": "tsup",
36
- "dev": "tsup --watch",
37
- "check": "tsc --noEmit",
38
- "test": "node --test --experimental-strip-types src/*.test.ts",
39
- "prepublishOnly": "pnpm build"
40
- },
41
- "peerDependencies": {
42
- "react": ">=18"
43
- },
44
- "devDependencies": {
45
- "@types/react": "^19",
46
- "react": "19.2.3",
47
- "tsup": "^8.5.0",
48
- "typescript": "^5"
49
- }
50
- }
1
+ {
2
+ "name": "@madeinbruno/music-plug",
3
+ "version": "0.4.0",
4
+ "description": "글 속 노래를 듣는 사람이 쓰는 음원 앱(멜론·지니·벅스·FLO·VIBE·Spotify·Apple Music·YouTube Music)에서, 없으면 YouTube로 바로 듣게 하는 플러그",
5
+ "license": "MIT",
6
+ "author": "codingbotPark <pbk575@gmail.com>",
7
+ "homepage": "https://madeinbruno.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/codingbotPark/madeinbruno.git",
11
+ "directory": "packages/music-plug"
12
+ },
13
+ "type": "module",
14
+ "sideEffects": [
15
+ "*.css"
16
+ ],
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ },
24
+ "./player": {
25
+ "types": "./dist/player.d.ts",
26
+ "import": "./dist/player.js"
27
+ },
28
+ "./styles.css": "./styles.css"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "styles.css"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsup",
36
+ "dev": "tsup --watch",
37
+ "check": "tsc --noEmit",
38
+ "test": "tsup && node --test --experimental-strip-types src/*.test.ts",
39
+ "prepublishOnly": "pnpm build"
40
+ },
41
+ "peerDependencies": {
42
+ "react": ">=18"
43
+ },
44
+ "devDependencies": {
45
+ "@types/react": "^19",
46
+ "react": "19.2.3",
47
+ "tsup": "^8.5.0",
48
+ "typescript": "^5"
49
+ }
50
+ }