sky.tsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. "use client";
  2. import { useTheme } from "next-themes";
  3. import { type CSSProperties, useEffect, useId, useState } from "react";
  4. import {
  5. FOOTHILLS,
  6. RAINIER,
  7. RAINIER_SNOW,
  8. SEATTLE_HILLS,
  9. SKYLINE_SIZE,
  10. } from "./rainier-skyline";
  11. import { useT } from "@/components/locale-provider";
  12. import { switchTheme } from "@/lib/theme-transition";
  13. import { cn } from "@/lib/utils";
  14. type Phase = "night" | "dawn" | "day" | "dusk";
  15. const TZ = "Asia/Shanghai";
  16. const SYNODIC_DAYS = 29.530588853;
  17. /** A known new moon, 2000-01-06 18:14 UTC. */
  18. const NEW_MOON = Date.UTC(2000, 0, 6, 18, 14);
  19. const MOON_NAMES = [
  20. "New moon",
  21. "Waxing crescent",
  22. "First quarter",
  23. "Waxing gibbous",
  24. "Full moon",
  25. "Waning gibbous",
  26. "Last quarter",
  27. "Waning crescent",
  28. ];
  29. /** Sky, horizon glow, and landscape colors for each part of the day. */
  30. const PALETTE: Record<
  31. Phase,
  32. {
  33. sky: string;
  34. glow: string;
  35. far: string;
  36. snow: string;
  37. snowShade: string;
  38. mid: string;
  39. near: string;
  40. }
  41. > = {
  42. night: {
  43. sky: "linear-gradient(180deg,#050b1f 0%,#0b1736 46%,#172a52 80%,#22365e 100%)",
  44. glow: "rgb(255 176 128 / 0.16)",
  45. far: "#2b3b60",
  46. snow: "#d5dff1",
  47. snowShade: "#8fa2c6",
  48. mid: "#17223e",
  49. near: "#0a1022",
  50. },
  51. dawn: {
  52. sky: "linear-gradient(180deg,#27356b 0%,#6a5a92 38%,#d48aa0 70%,#ffc39b 100%)",
  53. glow: "rgb(255 214 170 / 0.5)",
  54. far: "#6f5f88",
  55. snow: "#ffdcd2",
  56. snowShade: "#df9fa5",
  57. mid: "#3d3259",
  58. near: "#1f1931",
  59. },
  60. day: {
  61. sky: "linear-gradient(180deg,#2f80d6 0%,#5ea5ec 45%,#9fcdf6 82%,#d6ecfd 100%)",
  62. glow: "rgb(255 255 255 / 0.35)",
  63. far: "#86a2c6",
  64. snow: "#ffffff",
  65. snowShade: "#cfdbec",
  66. mid: "#5d7ca3",
  67. near: "#3a5476",
  68. },
  69. dusk: {
  70. sky: "linear-gradient(180deg,#1b2457 0%,#5b3f80 40%,#c45f80 72%,#ff9b63 100%)",
  71. glow: "rgb(255 170 110 / 0.45)",
  72. far: "#5e4b75",
  73. snow: "#ffc6b4",
  74. snowShade: "#d68b93",
  75. mid: "#352a52",
  76. near: "#1a1630",
  77. },
  78. };
  79. /** The last hour or so of daylight, when the light turns warm. */
  80. const GOLDEN: (typeof PALETTE)["day"] = {
  81. sky: "linear-gradient(180deg,#3a78c6 0%,#78a7dc 42%,#e6c09a 84%,#ffd2a0 100%)",
  82. glow: "rgb(255 200 140 / 0.5)",
  83. far: "#8b92b4",
  84. snow: "#fff1de",
  85. snowShade: "#e0c2b2",
  86. mid: "#5f6e98",
  87. near: "#3b496f",
  88. };
  89. // Integer LCG so the star field is identical on the server and in every browser.
  90. let seed = 11;
  91. const rand = () => ((seed = (seed * 16807) % 2147483647) - 1) / 2147483646;
  92. const STARS = Array.from({ length: 30 }, () => {
  93. const size = rand();
  94. return {
  95. x: (rand() * 100).toFixed(1),
  96. y: (rand() * 66).toFixed(1),
  97. size: size < 0.12 ? 2 : size < 0.45 ? 1.5 : 1,
  98. opacity: (0.3 + rand() * 0.6).toFixed(2),
  99. twinkle: rand() < 0.3 ? (2.4 + rand() * 3).toFixed(1) : null,
  100. };
  101. });
  102. const GRAIN =
  103. "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.25'/%3E%3C/svg%3E\")";
  104. const clock = (h: number, hour12: boolean) => {
  105. const minutes = Math.round(h * 60) % (24 * 60);
  106. const hh = Math.floor(minutes / 60);
  107. const mm = String(minutes % 60).padStart(2, "0");
  108. return hour12
  109. ? `${((hh + 11) % 12) + 1}:${mm} ${hh >= 12 ? "PM" : "AM"}`
  110. : `${hh}:${mm}`;
  111. };
  112. // Qingdao (市南/市中心). China is UTC+8 year-round, with no DST.
  113. const LAT = 36.0671;
  114. const LON = 120.3826;
  115. const UTC_OFFSET = 8;
  116. const rad = Math.PI / 180;
  117. /** Sunrise, solar noon, and sunset in local hours (NOAA's solar equations, accurate to about a minute). */
  118. function sunTimes(doy: number, utcOffset: number) {
  119. const g = ((2 * Math.PI) / 365) * (doy - 1);
  120. const eqTime =
  121. 229.18 *
  122. (0.000075 +
  123. 0.001868 * Math.cos(g) -
  124. 0.032077 * Math.sin(g) -
  125. 0.014615 * Math.cos(2 * g) -
  126. 0.040849 * Math.sin(2 * g));
  127. const decl =
  128. 0.006918 -
  129. 0.399912 * Math.cos(g) +
  130. 0.070257 * Math.sin(g) -
  131. 0.006758 * Math.cos(2 * g) +
  132. 0.000907 * Math.sin(2 * g) -
  133. 0.002697 * Math.cos(3 * g) +
  134. 0.00148 * Math.sin(3 * g);
  135. const ha =
  136. Math.acos(
  137. Math.cos(90.833 * rad) / (Math.cos(LAT * rad) * Math.cos(decl)) -
  138. Math.tan(LAT * rad) * Math.tan(decl),
  139. ) / rad;
  140. const local = (minutes: number) => minutes / 60 + utcOffset;
  141. return {
  142. rise: local(720 - 4 * (LON + ha) - eqTime),
  143. noon: local(720 - 4 * LON - eqTime),
  144. set: local(720 - 4 * (LON - ha) - eqTime),
  145. };
  146. }
  147. /** Qingdao's sky right now: the sun's real position and the moon's phase and rough place. */
  148. function qingdaoSky(now: Date, hour12: boolean) {
  149. const parts = Object.fromEntries(
  150. new Intl.DateTimeFormat("en-US", {
  151. timeZone: TZ,
  152. hour: "numeric",
  153. minute: "2-digit",
  154. hourCycle: "h23",
  155. month: "numeric",
  156. day: "numeric",
  157. year: "numeric",
  158. })
  159. .formatToParts(now)
  160. .map((p) => [p.type, p.value]),
  161. );
  162. const hour = Number(parts.hour) + Number(parts.minute) / 60;
  163. const year = Number(parts.year);
  164. const doy =
  165. (Date.UTC(year, Number(parts.month) - 1, Number(parts.day)) -
  166. Date.UTC(year, 0, 0)) /
  167. 864e5;
  168. const { rise, noon, set } = sunTimes(doy, UTC_OFFSET);
  169. let phase: Phase = "night";
  170. if (hour >= rise - 0.6 && hour < rise + 0.7) phase = "dawn";
  171. else if (hour >= rise + 0.7 && hour < set - 0.8) phase = "day";
  172. else if (hour >= set - 0.8 && hour < set + 0.6) phase = "dusk";
  173. // The moon transits about age × 24.8 h after the sun and is up for roughly 12.4 h.
  174. const age =
  175. ((((now.getTime() - NEW_MOON) / 864e5 / SYNODIC_DAYS) % 1) + 1) % 1;
  176. const moon = ((((hour - (noon + age * 24.8 - 6.2)) % 24) + 24) % 24) / 12.4;
  177. let label = MOON_NAMES[Math.round(age * 8) % 8];
  178. if (phase === "dawn") label = hour < rise ? "First light" : "Sunrise";
  179. else if (phase === "dusk") label = hour < set ? "Sunset" : "Blue hour";
  180. else if (phase === "day")
  181. label = hour > set - 1.8 ? "Golden hour" : "Daylight";
  182. const time = new Intl.DateTimeFormat("en-US", {
  183. timeZone: TZ,
  184. hour: "numeric",
  185. minute: "2-digit",
  186. ...(hour12 ? {} : { hourCycle: "h23" as const }),
  187. }).format(now);
  188. const sunUp = hour >= rise && hour < set;
  189. return {
  190. phase,
  191. label,
  192. next: sunUp
  193. ? { kind: "sunset" as const, at: clock(set, hour12) }
  194. : { kind: "sunrise" as const, at: clock(rise, hour12) },
  195. time: time.replace(/\s?[AP]M$/, ""),
  196. meridiem: hour12 ? (/PM$/.test(time) ? "PM" : "AM") : "",
  197. sun: (hour - rise) / (set - rise),
  198. moon,
  199. age,
  200. };
  201. }
  202. /** Position along the sky's arc, from the left horizon (0) to the right (1). */
  203. const arc = (p: number): CSSProperties => ({
  204. left: `${6 + p * 88}%`,
  205. top: `${78 - Math.sin(Math.PI * Math.min(1, Math.max(0, p))) * 30}%`,
  206. });
  207. /** The moon's lit shape for its age (0 new, 0.5 full), as seen from the northern hemisphere. */
  208. function Moon({
  209. age,
  210. className,
  211. craters,
  212. }: {
  213. age: number;
  214. className?: string;
  215. craters?: boolean;
  216. }) {
  217. const clip = useId().replace(/[^\w-]/g, "");
  218. const k = Math.cos(2 * Math.PI * age);
  219. const waxing = age < 0.5;
  220. const lit = `M0 -10A10 10 0 0 ${waxing ? 1 : 0} 0 10A${(Math.abs(k) * 10).toFixed(2)} 10 0 0 ${
  221. waxing === k > 0 ? 0 : 1
  222. } 0 -10Z`;
  223. return (
  224. <svg aria-hidden className={className} viewBox="-11 -11 22 22">
  225. <circle fill="currentColor" opacity="0.16" r="10" />
  226. <path d={lit} fill="currentColor" />
  227. {craters && (
  228. <>
  229. <clipPath id={clip}>
  230. <path d={lit} />
  231. </clipPath>
  232. <g clipPath={`url(#${clip})`} fill="#5b6478" opacity="0.18">
  233. <circle cx="-3.2" cy="-3.4" r="2.6" />
  234. <circle cx="3.6" cy="1.6" r="1.9" />
  235. <circle cx="-1.2" cy="4.8" r="1.4" />
  236. <circle cx="4.4" cy="-4.6" r="1.1" />
  237. </g>
  238. </>
  239. )}
  240. </svg>
  241. );
  242. }
  243. const DIGITS =
  244. "font-display text-[46px] font-semibold tracking-[-0.025em] tabular-nums sm:text-[58px]";
  245. /**
  246. * Clock digits made of glass, like the iOS 26 Lock Screen: a clear body that
  247. * lets the sky through, a bevel lit from the upper left, and a bright top rim.
  248. */
  249. function GlassTime({ time, meridiem }: { time: string; meridiem: string }) {
  250. const id = useId().replace(/[^\w-]/g, "");
  251. return (
  252. <svg
  253. aria-label={time ? `${time} ${meridiem}` : undefined}
  254. className={cn(
  255. "mt-1 block h-[44px] w-full overflow-visible transition-opacity duration-500 sm:h-[56px]",
  256. time ? "opacity-100" : "opacity-0",
  257. )}
  258. role="img"
  259. >
  260. <defs>
  261. <filter
  262. colorInterpolationFilters="sRGB"
  263. height="170%"
  264. id={id}
  265. width="130%"
  266. x="-15%"
  267. y="-35%"
  268. >
  269. <feFlood floodColor="#fff" floodOpacity="0.16" />
  270. <feComposite in2="SourceAlpha" operator="in" result="body" />
  271. <feGaussianBlur in="SourceAlpha" result="height" stdDeviation="1.5" />
  272. <feSpecularLighting
  273. in="height"
  274. lightingColor="#fff"
  275. result="light"
  276. specularConstant="1.2"
  277. specularExponent="14"
  278. surfaceScale="3.2"
  279. >
  280. <feDistantLight azimuth="225" elevation="40" />
  281. </feSpecularLighting>
  282. <feComposite
  283. in="light"
  284. in2="SourceAlpha"
  285. operator="in"
  286. result="gloss"
  287. />
  288. <feOffset dy="1.2" in="SourceAlpha" result="down" />
  289. <feComposite
  290. in="SourceAlpha"
  291. in2="down"
  292. operator="out"
  293. result="edge"
  294. />
  295. <feFlood floodColor="#fff" floodOpacity="0.9" />
  296. <feComposite in2="edge" operator="in" result="rim" />
  297. <feGaussianBlur in="SourceAlpha" stdDeviation="5" />
  298. <feOffset dy="3" result="drop" />
  299. <feFlood floodColor="#020617" floodOpacity="0.28" />
  300. <feComposite in2="drop" operator="in" />
  301. <feComposite in2="SourceAlpha" operator="out" result="shadow" />
  302. <feMerge>
  303. <feMergeNode in="shadow" />
  304. <feMergeNode in="body" />
  305. <feMergeNode in="gloss" />
  306. <feMergeNode in="rim" />
  307. </feMerge>
  308. </filter>
  309. </defs>
  310. <text
  311. className={DIGITS}
  312. fill="#fff"
  313. filter={`url(#${id})`}
  314. x="0"
  315. y="0.84em"
  316. >
  317. {time}
  318. </text>
  319. {/* An invisible copy of the digits sets the pen position for AM/PM. */}
  320. <text aria-hidden className={DIGITS} x="0" y="0.84em">
  321. <tspan fill="none">{time}</tspan>
  322. <tspan
  323. className="text-[13px] font-semibold tracking-normal"
  324. dx="6"
  325. fill="rgb(255 255 255 / 0.85)"
  326. >
  327. {meridiem}
  328. </tspan>
  329. </text>
  330. </svg>
  331. );
  332. }
  333. function PhaseIcon({ phase, age }: { phase: Phase; age: number }) {
  334. if (phase === "night") return <Moon age={age} className="size-[13px]" />;
  335. if (phase === "day") {
  336. return (
  337. <svg aria-hidden className="size-[13px]" fill="none" viewBox="0 0 16 16">
  338. <circle cx="8" cy="8" fill="currentColor" r="3.2" />
  339. <path
  340. d="M8 1.6v1.5M8 12.9v1.5M1.6 8h1.5M12.9 8h1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1"
  341. stroke="currentColor"
  342. strokeLinecap="round"
  343. strokeWidth="1.4"
  344. />
  345. </svg>
  346. );
  347. }
  348. return (
  349. <svg aria-hidden className="size-[13px]" fill="none" viewBox="0 0 16 16">
  350. <path d="M4.4 11.6a3.6 3.6 0 0 1 7.2 0Z" fill="currentColor" />
  351. <path
  352. d={
  353. phase === "dawn"
  354. ? "M1.5 11.6h13M8 2v3.6M6.4 3.6 8 2l1.6 1.6"
  355. : "M1.5 11.6h13M8 2v3.6M6.4 4 8 5.6 9.6 4"
  356. }
  357. stroke="currentColor"
  358. strokeLinecap="round"
  359. strokeLinejoin="round"
  360. strokeWidth="1.4"
  361. />
  362. </svg>
  363. );
  364. }
  365. /**
  366. * An Apple Weather-style widget for Qingdao's real sky right now: the sun or
  367. * the moon in its actual phase over a decorative mountain skyline (the paths
  368. * are still the original Rainier silhouette). It doubles as the site's light
  369. * switch. Time via Intl, sunrise via NOAA's equations, moon phase via the
  370. * synodic month — all local, so no network request and no loading state.
  371. */
  372. export function SkyCard() {
  373. const { sky: t, nav } = useT();
  374. const { resolvedTheme, setTheme } = useTheme();
  375. const [sky, setSky] = useState<ReturnType<typeof qingdaoSky> | null>(null);
  376. useEffect(() => {
  377. const tick = () => setSky(qingdaoSky(new Date(), t.hour12));
  378. tick();
  379. const id = window.setInterval(tick, 20_000);
  380. return () => window.clearInterval(id);
  381. }, [t.hour12]);
  382. const phase = sky?.phase ?? "night";
  383. const colors = sky?.label === "Golden hour" ? GOLDEN : PALETTE[phase];
  384. const [width, height] = SKYLINE_SIZE;
  385. const sunVisible = sky !== null && sky.sun >= -0.02 && sky.sun <= 1.02;
  386. const moonVisible =
  387. sky !== null && sky.moon <= 1 && sky.age > 0.03 && sky.age < 0.97;
  388. return (
  389. <div
  390. className="relative h-full overflow-hidden rounded-[inherit] text-white transition-[background] duration-1000"
  391. // The film grain is a background layer, not a blended overlay: Safari can
  392. // lift a mix-blend-mode layer out of the card's rounded clip, which showed
  393. // as a square corner. The full-bleed layers also carry the corners.
  394. style={
  395. {
  396. background: `${GRAIN}, ${colors.sky}`,
  397. backgroundBlendMode: "soft-light, normal",
  398. "--far": colors.far,
  399. "--snow": colors.snow,
  400. "--snow-shade": colors.snowShade,
  401. "--mid": colors.mid,
  402. "--near": colors.near,
  403. } as CSSProperties
  404. }
  405. >
  406. <div
  407. aria-hidden
  408. className="absolute inset-0 rounded-[inherit] transition-[background] duration-1000"
  409. style={{
  410. background: `radial-gradient(85% 42% at 58% 84%, ${colors.glow}, transparent 72%)`,
  411. }}
  412. />
  413. <div
  414. aria-hidden
  415. className={cn(
  416. "absolute inset-0 rounded-[inherit] transition-opacity duration-1000",
  417. phase === "night"
  418. ? "opacity-100"
  419. : phase === "day"
  420. ? "opacity-0"
  421. : "opacity-40",
  422. )}
  423. >
  424. {STARS.map((s, i) => (
  425. <span
  426. key={i}
  427. className="absolute rounded-full bg-white"
  428. style={{
  429. left: `${s.x}%`,
  430. top: `${s.y}%`,
  431. width: s.size,
  432. height: s.size,
  433. opacity: s.opacity,
  434. animation: s.twinkle
  435. ? `twinkle ${s.twinkle}s ease-in-out ${-i * 0.7}s infinite`
  436. : undefined,
  437. }}
  438. />
  439. ))}
  440. </div>
  441. {sky && moonVisible && (
  442. <span
  443. aria-hidden
  444. className={cn(
  445. "absolute -translate-x-1/2 -translate-y-1/2 text-[#f5f1e4] transition-opacity duration-1000 [animation:fade-in_1s_ease_both]",
  446. phase === "day" ? "opacity-50" : "opacity-100",
  447. )}
  448. style={arc(sky.moon)}
  449. >
  450. <span className="absolute -inset-3 rounded-full bg-[radial-gradient(closest-side,rgb(245_241_228/0.3),transparent)]" />
  451. <Moon
  452. craters
  453. age={sky.age}
  454. className="relative block size-[17px] sm:size-5"
  455. />
  456. </span>
  457. )}
  458. {sky && sunVisible && (
  459. <span
  460. aria-hidden
  461. className="absolute size-[18px] -translate-x-1/2 -translate-y-1/2 [animation:fade-in_1s_ease_both] sm:size-[22px]"
  462. style={arc(sky.sun)}
  463. >
  464. <span
  465. className={cn(
  466. "absolute -inset-[180%] rounded-full",
  467. phase === "day"
  468. ? "bg-[radial-gradient(closest-side,rgb(255_236_180/0.5),transparent)]"
  469. : "bg-[radial-gradient(closest-side,rgb(255_170_110/0.6),transparent)]",
  470. )}
  471. />
  472. <span
  473. className={cn(
  474. "absolute inset-0 rounded-full",
  475. phase === "day"
  476. ? "bg-[radial-gradient(circle,#fffef8_45%,#fff1c2)] shadow-[0_0_16px_4px_rgb(255_240_200/0.7)]"
  477. : "bg-[radial-gradient(circle,#fff3dc_40%,#ffc58a)] shadow-[0_0_18px_6px_rgb(255_170_110/0.55)]",
  478. )}
  479. />
  480. </span>
  481. )}
  482. <svg
  483. aria-hidden
  484. className="absolute inset-x-0 bottom-0 h-[44%] w-full"
  485. preserveAspectRatio="xMidYMax slice"
  486. viewBox={`${width * 0.29} 0 ${width * 0.56} ${height}`}
  487. >
  488. <defs>
  489. <linearGradient id="rainier-snow" x1="0" x2="0" y1="0" y2="1">
  490. <stop offset="0.2" stopColor="var(--snow)" />
  491. <stop offset="0.85" stopColor="var(--snow-shade)" />
  492. </linearGradient>
  493. </defs>
  494. <path
  495. className="transition-[fill] duration-1000"
  496. d={RAINIER}
  497. fill="var(--far)"
  498. />
  499. <path d={RAINIER_SNOW} fill="url(#rainier-snow)" />
  500. <path
  501. className="transition-[fill] duration-1000"
  502. d={FOOTHILLS}
  503. fill="var(--mid)"
  504. />
  505. <path
  506. className="transition-[fill] duration-1000"
  507. d={SEATTLE_HILLS}
  508. fill="var(--near)"
  509. />
  510. </svg>
  511. <div className="relative flex h-full flex-col justify-between p-5 [text-shadow:0_1px_10px_rgb(0_0_0/0.18)] sm:p-6">
  512. <div className="flex items-start justify-between gap-2">
  513. <div className="min-w-0 flex-1 leading-none">
  514. <p className="flex items-center gap-1 text-[15px] font-semibold">
  515. {t.city}
  516. <svg
  517. aria-hidden
  518. className="size-[10px] opacity-90"
  519. viewBox="0 0 16 16"
  520. >
  521. <path
  522. d="M14.2 1.8 2.3 6.9c-.6.3-.5 1.1.1 1.2l4.9 1 1 4.9c.1.6.9.7 1.2.1L14.2 1.8Z"
  523. fill="currentColor"
  524. />
  525. </svg>
  526. </p>
  527. <GlassTime meridiem={sky?.meridiem ?? ""} time={sky?.time ?? ""} />
  528. </div>
  529. <button
  530. aria-label={nav.theme}
  531. className="lg grid size-8 shrink-0 place-items-center rounded-full text-white [--glass-ink:#fff] [--glass-tint:rgb(255_255_255/0.14)]"
  532. data-cursor={nav.lights}
  533. type="button"
  534. onClick={(e) => {
  535. const r = e.currentTarget.getBoundingClientRect();
  536. switchTheme(
  537. resolvedTheme === "dark" ? "light" : "dark",
  538. setTheme,
  539. {
  540. x: r.left + r.width / 2,
  541. y: r.top + r.height / 2,
  542. },
  543. );
  544. }}
  545. >
  546. <span className="lg-caustic" />
  547. <svg aria-hidden className="size-4" fill="none" viewBox="0 0 16 16">
  548. <circle
  549. cx="8"
  550. cy="8"
  551. r="6"
  552. stroke="currentColor"
  553. strokeWidth="1.5"
  554. />
  555. <path d="M8 2a6 6 0 0 1 0 12Z" fill="currentColor" />
  556. </svg>
  557. </button>
  558. </div>
  559. <div
  560. className={cn(
  561. "text-[13px] leading-[1.3] transition-opacity duration-500",
  562. sky ? "opacity-100" : "opacity-0",
  563. )}
  564. >
  565. <p className="flex items-center gap-1.5 font-semibold">
  566. {sky && <PhaseIcon age={sky.age} phase={phase} />}
  567. {sky ? (t.labels[sky.label] ?? sky.label) : t.city}
  568. </p>
  569. <p className="opacity-85">
  570. {sky ? `${t[sky.next.kind]} ${sky.next.at}` : t.sunrise}
  571. </p>
  572. </div>
  573. </div>
  574. </div>
  575. );
  576. }