Kremta-Website/_astro/SpotifyPlayer.CNtkvnvX.js

19 lines
4.2 KiB
JavaScript

import{r as c}from"./index.Cd_vQiNd.js";var h={exports:{}},x={};/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var v;function m(){if(v)return x;v=1;var r=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function u(d,n,t){var s=null;if(t!==void 0&&(s=""+t),n.key!==void 0&&(s=""+n.key),"key"in n){t={};for(var l in n)l!=="key"&&(t[l]=n[l])}else t=n;return n=t.ref,{$$typeof:r,type:d,key:s,ref:n!==void 0?n:null,props:t}}return x.Fragment=a,x.jsx=u,x.jsxs=u,x}var g;function y(){return g||(g=1,h.exports=m()),h.exports}var e=y();const j=({progress:r,isPlaying:a})=>{const[u,d]=c.useState([]);c.useEffect(()=>{const t=[];for(let s=0;s<50;s++)t.push(Math.floor(Math.random()*800)+700);d(t)},[]);const n=()=>{const t=Math.floor(r/2),s=[],l=a?3:8,i=a?25:20;for(let o=1;o<51;o++){const p=o<=t;s.push(e.jsx("line",{x1:o+o*6,y1:l,x2:o+o*6,y2:i,strokeWidth:"2",stroke:p?"var(--ctp-green)":"var(--ctp-overlay0)",style:{transformOrigin:"center",transition:"stroke 1s ease-in-out",animation:a?`sound ${u[o]}ms linear infinite alternate`:"none"}},o))}return s};return e.jsxs("div",{children:[e.jsx("svg",{width:"302",height:"28",viewBox:"0 0 344 28",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{maxWidth:"100%",height:"auto"},children:n()}),e.jsx("style",{children:`
@keyframes sound {
0% {
transform: scaleY(0.4);
}
100% {
transform: scaleY(1);
}
}
`})]})},k=()=>{const[r,a]=c.useState(null),[u,d]=c.useState(!1),[n,t]=c.useState(!0),[s,l]=c.useState(0);return c.useEffect(()=>{const i=async()=>{try{const p=await fetch("/api/spotify/now-playing");if(p.status===204){a(null),d(!1),t(!1);return}const f=await p.json();a(f),d(f.isPlaying),l(f.progress||0),t(!1)}catch(p){console.error("Error fetching now playing:",p),t(!1)}};i();const o=setInterval(i,1e4);return()=>clearInterval(o)},[]),n?e.jsx("div",{style:{textAlign:"center",color:"var(--ctp-subtext0)"},children:"Loading..."}):r?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1.5rem"},children:[e.jsxs("div",{style:{display:"flex",gap:"1.5rem",alignItems:"center"},children:[r.albumArt&&e.jsx("img",{src:r.albumArt,alt:r.album,style:{width:"80px",height:"80px",borderRadius:"8px",border:"2px solid var(--ctp-green)"}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"1.25rem",fontWeight:"600",color:"var(--ctp-text)",marginBottom:"0.25rem",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.title}),e.jsx("div",{style:{fontSize:"1rem",color:"var(--ctp-subtext0)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.artist}),r.album&&e.jsx("div",{style:{fontSize:"0.9rem",color:"var(--ctp-subtext1)",marginTop:"0.25rem",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.album})]})]}),e.jsx("div",{style:{display:"flex",justifyContent:"center"},children:e.jsx(j,{progress:s,isPlaying:u})}),r.trackUrl&&e.jsx("a",{href:r.trackUrl,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"0.5rem",padding:"0.75rem 1.5rem",backgroundColor:"var(--ctp-green)",color:"var(--ctp-base)",borderRadius:"9999px",textDecoration:"none",fontWeight:"500",alignSelf:"center",transition:"all 0.3s ease"},onMouseEnter:i=>{i.currentTarget.style.transform="scale(1.05)",i.currentTarget.style.backgroundColor="var(--ctp-teal)"},onMouseLeave:i=>{i.currentTarget.style.transform="scale(1)",i.currentTarget.style.backgroundColor="var(--ctp-green)"},children:"Open in Spotify"})]}):e.jsxs("div",{style:{textAlign:"center",color:"var(--ctp-subtext0)"},children:[e.jsx("svg",{width:"64",height:"64",viewBox:"0 0 24 24",fill:"none",style:{margin:"0 auto 1rem",color:"var(--ctp-green)"},children:e.jsx("path",{d:"M9 18V5l12-2v13M9 18c0 1.657-1.343 3-3 3s-3-1.343-3-3 1.343-3 3-3 3 1.343 3 3zm12-2c0 1.657-1.343 3-3 3s-3-1.343-3-3 1.343-3 3-3 3 1.343 3 3z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsx("p",{children:"Not playing anything right now"})]})};export{k as default};