@sdeck/plugin-spotify 0.0.0-stage → 0.2.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/api.d.ts +106 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1316 -0
- package/dist/index.js.map +12 -0
- package/dist/panels.d.ts +11 -0
- package/dist/panels.d.ts.map +1 -0
- package/package.json +60 -4
- package/src/api.ts +425 -0
- package/src/index.tsx +873 -0
- package/src/panels.tsx +261 -0
- package/README.md +0 -3
package/src/panels.tsx
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/** What Spotify keys draw with, and the Now playing panel, which draws itself. */
|
|
2
|
+
import { useHostState, useImage } from "@sdeck/plugin";
|
|
3
|
+
import type { CSSProperties } from "react";
|
|
4
|
+
|
|
5
|
+
export const GREEN = "#1ed760";
|
|
6
|
+
export const BACKGROUND = "#121212";
|
|
7
|
+
export const MUTED = "#a7a7a7";
|
|
8
|
+
export const FAINT = "#2a2a2a";
|
|
9
|
+
|
|
10
|
+
/** A filled circle as an image, for badges behind icons. */
|
|
11
|
+
export const disc = (color: string, opacity = 1) =>
|
|
12
|
+
`data:image/svg+xml,${encodeURIComponent(
|
|
13
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100"><circle cx="50" cy="50" r="50" fill="${color}" fill-opacity="${opacity}"/></svg>`,
|
|
14
|
+
)}`;
|
|
15
|
+
|
|
16
|
+
const box: CSSProperties = { display: "flex" };
|
|
17
|
+
|
|
18
|
+
function Icon({ icon, size, color }: { icon: string; size: number; color: string }) {
|
|
19
|
+
const src = useImage(`icon:${icon}`, color);
|
|
20
|
+
return src ? (
|
|
21
|
+
<img src={src} width={size} height={size} alt="" />
|
|
22
|
+
) : (
|
|
23
|
+
<div style={{ ...box, width: size, height: size }} />
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function Progress({ value, height }: { value: number; height: number }) {
|
|
28
|
+
return (
|
|
29
|
+
<div style={{ ...box, width: "100%", height, background: "rgba(255,255,255,0.18)" }}>
|
|
30
|
+
<div
|
|
31
|
+
style={{
|
|
32
|
+
...box,
|
|
33
|
+
width: `${Math.min(100, Math.max(0, value))}%`,
|
|
34
|
+
height,
|
|
35
|
+
background: GREEN,
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What the published state says is playing. */
|
|
43
|
+
function useNowPlaying() {
|
|
44
|
+
const asText = (value: unknown) => (typeof value === "string" ? value : "");
|
|
45
|
+
const track = asText(useHostState("spotify.track"));
|
|
46
|
+
const artist = asText(useHostState("spotify.artist"));
|
|
47
|
+
const artUrl = asText(useHostState("spotify.art"));
|
|
48
|
+
const progress = Number(useHostState("spotify.progress") ?? 0) || 0;
|
|
49
|
+
const playing = useHostState("spotify.playing") === true;
|
|
50
|
+
const liked = useHostState("spotify.liked") === true;
|
|
51
|
+
const art = useImage(artUrl);
|
|
52
|
+
return { track, artist, art, progress, playing, liked };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The cover, track and artist, with how far through it is, for a key, the window or a strip. */
|
|
56
|
+
export function NowPlaying({ kind }: { kind: "key" | "window" | "sensor" }) {
|
|
57
|
+
const { track, artist, art, progress, playing, liked } = useNowPlaying();
|
|
58
|
+
|
|
59
|
+
if (kind === "sensor") {
|
|
60
|
+
return (
|
|
61
|
+
<div
|
|
62
|
+
style={{
|
|
63
|
+
...box,
|
|
64
|
+
width: "100%",
|
|
65
|
+
height: "100%",
|
|
66
|
+
alignItems: "center",
|
|
67
|
+
background: BACKGROUND,
|
|
68
|
+
gap: 4,
|
|
69
|
+
padding: "0 4px",
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
<Icon
|
|
73
|
+
icon={playing ? "tb/TbPlayerPlayFilled" : "tb/TbPlayerPauseFilled"}
|
|
74
|
+
size={10}
|
|
75
|
+
color={playing ? GREEN : MUTED}
|
|
76
|
+
/>
|
|
77
|
+
<div style={{ ...box, flexGrow: 1 }}>
|
|
78
|
+
<Progress value={track ? progress : 0} height={4} />
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!track) {
|
|
85
|
+
return (
|
|
86
|
+
<div
|
|
87
|
+
style={{
|
|
88
|
+
...box,
|
|
89
|
+
width: "100%",
|
|
90
|
+
height: "100%",
|
|
91
|
+
flexDirection: kind === "window" ? "row" : "column",
|
|
92
|
+
alignItems: "center",
|
|
93
|
+
justifyContent: "center",
|
|
94
|
+
gap: 8,
|
|
95
|
+
background: BACKGROUND,
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<Icon icon="si/SiSpotify" size={kind === "window" ? 30 : 40} color={GREEN} />
|
|
99
|
+
<div
|
|
100
|
+
style={{ ...box, color: MUTED, fontSize: kind === "window" ? 15 : 11, fontWeight: 700 }}
|
|
101
|
+
>
|
|
102
|
+
Not playing
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (kind === "window") {
|
|
109
|
+
return (
|
|
110
|
+
<div
|
|
111
|
+
style={{
|
|
112
|
+
...box,
|
|
113
|
+
width: "100%",
|
|
114
|
+
height: "100%",
|
|
115
|
+
flexDirection: "column",
|
|
116
|
+
background: BACKGROUND,
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<div style={{ ...box, flexGrow: 1, alignItems: "center", gap: 10, padding: "0 10px 0 0" }}>
|
|
120
|
+
{art ? (
|
|
121
|
+
<img src={art} width={55} height={55} alt="" />
|
|
122
|
+
) : (
|
|
123
|
+
<div
|
|
124
|
+
style={{
|
|
125
|
+
...box,
|
|
126
|
+
width: 55,
|
|
127
|
+
height: 55,
|
|
128
|
+
background: FAINT,
|
|
129
|
+
alignItems: "center",
|
|
130
|
+
justifyContent: "center",
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<Icon icon="lucide/music" size={26} color={MUTED} />
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
<div
|
|
137
|
+
style={{
|
|
138
|
+
...box,
|
|
139
|
+
flexDirection: "column",
|
|
140
|
+
flexGrow: 1,
|
|
141
|
+
flexShrink: 1,
|
|
142
|
+
minWidth: 0,
|
|
143
|
+
fontWeight: 700,
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
<div
|
|
147
|
+
style={{
|
|
148
|
+
...box,
|
|
149
|
+
color: "#ffffff",
|
|
150
|
+
fontSize: 15,
|
|
151
|
+
overflow: "hidden",
|
|
152
|
+
whiteSpace: "nowrap",
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
{track}
|
|
156
|
+
</div>
|
|
157
|
+
<div
|
|
158
|
+
style={{
|
|
159
|
+
...box,
|
|
160
|
+
color: MUTED,
|
|
161
|
+
fontSize: 12,
|
|
162
|
+
overflow: "hidden",
|
|
163
|
+
whiteSpace: "nowrap",
|
|
164
|
+
}}
|
|
165
|
+
>
|
|
166
|
+
{artist}
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
{liked ? <Icon icon="tb/TbHeartFilled" size={16} color={GREEN} /> : null}
|
|
170
|
+
<Icon
|
|
171
|
+
icon={playing ? "tb/TbPlayerPauseFilled" : "tb/TbPlayerPlayFilled"}
|
|
172
|
+
size={20}
|
|
173
|
+
color={playing ? "#ffffff" : GREEN}
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
<Progress value={progress} height={3} />
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// A key: the cover fills it, with the names on a dark band at the bottom.
|
|
182
|
+
return (
|
|
183
|
+
<div
|
|
184
|
+
style={{
|
|
185
|
+
...box,
|
|
186
|
+
width: "100%",
|
|
187
|
+
height: "100%",
|
|
188
|
+
position: "relative",
|
|
189
|
+
background: BACKGROUND,
|
|
190
|
+
}}
|
|
191
|
+
>
|
|
192
|
+
{art ? (
|
|
193
|
+
<img
|
|
194
|
+
src={art}
|
|
195
|
+
width={96}
|
|
196
|
+
height={96}
|
|
197
|
+
alt=""
|
|
198
|
+
style={{ position: "absolute", left: 0, top: 0, width: "100%", height: "100%" }}
|
|
199
|
+
/>
|
|
200
|
+
) : null}
|
|
201
|
+
<div
|
|
202
|
+
style={{
|
|
203
|
+
...box,
|
|
204
|
+
position: "absolute",
|
|
205
|
+
left: 0,
|
|
206
|
+
right: 0,
|
|
207
|
+
bottom: 0,
|
|
208
|
+
flexDirection: "column",
|
|
209
|
+
padding: "14px 6px 0 6px",
|
|
210
|
+
backgroundImage: "linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.88) 45%)",
|
|
211
|
+
fontWeight: 700,
|
|
212
|
+
}}
|
|
213
|
+
>
|
|
214
|
+
<div
|
|
215
|
+
style={{
|
|
216
|
+
...box,
|
|
217
|
+
color: "#ffffff",
|
|
218
|
+
fontSize: 12,
|
|
219
|
+
overflow: "hidden",
|
|
220
|
+
whiteSpace: "nowrap",
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
{track}
|
|
224
|
+
</div>
|
|
225
|
+
<div
|
|
226
|
+
style={{
|
|
227
|
+
...box,
|
|
228
|
+
color: "#d4d4d4",
|
|
229
|
+
fontSize: 10,
|
|
230
|
+
overflow: "hidden",
|
|
231
|
+
whiteSpace: "nowrap",
|
|
232
|
+
marginBottom: 5,
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
{artist}
|
|
236
|
+
</div>
|
|
237
|
+
<div style={{ ...box, margin: "0 -6px" }}>
|
|
238
|
+
<Progress value={progress} height={3} />
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
{playing ? null : (
|
|
242
|
+
<div
|
|
243
|
+
style={{
|
|
244
|
+
...box,
|
|
245
|
+
position: "absolute",
|
|
246
|
+
right: 6,
|
|
247
|
+
top: 6,
|
|
248
|
+
width: 26,
|
|
249
|
+
height: 26,
|
|
250
|
+
borderRadius: 13,
|
|
251
|
+
alignItems: "center",
|
|
252
|
+
justifyContent: "center",
|
|
253
|
+
background: GREEN,
|
|
254
|
+
}}
|
|
255
|
+
>
|
|
256
|
+
<Icon icon="tb/TbPlayerPlayFilled" size={14} color="#000000" />
|
|
257
|
+
</div>
|
|
258
|
+
)}
|
|
259
|
+
</div>
|
|
260
|
+
);
|
|
261
|
+
}
|
package/README.md
DELETED