SPB Git

Repository Public

Universe.tsx 10.3 KB 153 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : src/components/universe/Universe.tsx9 * Module           : components10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243"use client";44import Image from "next/image";45import Link from "next/link";46import { useEffect, useMemo, useRef, useState } from "react";47import { AnimatePresence, motion } from "motion/react";48import type { Platform, Status } from "@/models/constants";4950export type UniverseApp = { slug: string; name: string; icon: string | null; accent: string | null; href: string; summary: string; status: Status; platforms: Platform[] };51type Labels = { all: string; open: string; pause: string; play: string; hint: string; platforms: Record<Platform, string>; status: Record<Status, string> };5253const W = 1080, H = 540, CX = 540, CY = 270;54/** Three orbits, by distance from release: what is released rides the two inner ones, what is still to come the outer one. */55const RINGS = [56  { rx: 205, ry: 78, period: 52 },57  { rx: 345, ry: 132, period: 74 },58  { rx: 478, ry: 186, period: 96 },59];60const INNER = 4;61const ellipse = (rx: number, ry: number) => `M ${CX + rx} ${CY} A ${rx} ${ry} 0 1 1 ${CX - rx} ${CY} A ${rx} ${ry} 0 1 1 ${CX + rx} ${CY}`;6263export function Universe({ apps, labels }: { apps: UniverseApp[]; labels: Labels }) {64  const [filter, setFilter] = useState<Platform | "">("");65  const [active, setActive] = useState<string>(apps[0]?.slug ?? "");66  const [paused, setPaused] = useState(false);67  const [scale, setScale] = useState(1);68  const box = useRef<HTMLDivElement>(null);69  /** A finger cannot hover: its first tap selects the application, the second one opens it. */70  const touch = useRef(false), before = useRef("");7172  useEffect(() => {73    const el = box.current; if (!el) return;74    const ro = new ResizeObserver(([e]) => setScale(e.contentRect.width / W));75    ro.observe(el);76    const io = new IntersectionObserver(([e]) => el.classList.toggle("paused", !e.isIntersecting));77    io.observe(el);78    return () => { ro.disconnect(); io.disconnect(); };79  }, []);8081  const placed = useMemo(() => {82    const released = apps.filter((a) => a.status === "available"), rest = apps.filter((a) => a.status !== "available");83    const groups = [released.slice(0, INNER), released.slice(INNER), rest];84    // With nothing released yet, or nothing left to come, the orbits are shared out evenly instead.85    if (!groups[1].length || !groups[2].length) { const all = [...released, ...rest], k = Math.ceil(all.length / 3); groups[0] = all.slice(0, Math.min(INNER, k)); groups[1] = all.slice(groups[0].length, groups[0].length + k); groups[2] = all.slice(groups[0].length + groups[1].length); }86    return groups.flatMap((members, r) => members.map((app, i) => ({ app, ring: RINGS[r], r, phase: -(RINGS[r].period * (i / members.length) + r * 5) })));87  }, [apps]);88  const platforms = useMemo(() => (["ios", "ipados", "macos"] as Platform[]).filter((p) => apps.some((a) => a.platforms.includes(p))), [apps]);89  const current = apps.find((a) => a.slug === active) ?? apps[0];90  const matches = (a: UniverseApp) => !filter || a.platforms.includes(filter);91  // Icons shrink less on small screens so they stay comfortable touch targets.92  const size = Math.max(64, Math.min(92, 46 / Math.max(scale, 0.01)));9394  return (95    <div data-testid="universe">96      <div className="flex flex-wrap items-center gap-2" role="group" aria-label="Platform">97        <button type="button" className="chip" aria-pressed={filter === ""} onClick={() => setFilter("")}>{labels.all}</button>98        {platforms.map((p) => <button key={p} type="button" className="chip" aria-pressed={filter === p} onClick={() => setFilter(p)} data-testid={`universe-filter-${p}`}>{labels.platforms[p]}</button>)}99        <button type="button" className="chip ml-auto" aria-pressed={paused} onClick={() => setPaused((p) => !p)}>{paused ? labels.play : labels.pause}</button>100      </div>101102      <div className="mt-8 grid items-center gap-8 lg:grid-cols-[minmax(0,1fr)_21rem]">103        <div ref={box} className={`overflow-hidden ${paused ? "paused" : ""}`} style={{ height: H * scale }}>104          <div className="orbit-stage" style={{ transform: `scale(${scale})` }}>105            <svg width={W} height={H} viewBox={`0 0 ${W} ${H}`} className="absolute inset-0" aria-hidden>106              <defs>107                <linearGradient id="ring" x1="0" y1="0" x2={W} y2="0" gradientUnits="userSpaceOnUse"><stop stopColor="var(--blue)" stopOpacity=".05" /><stop offset=".5" stopColor="var(--violet)" stopOpacity=".55" /><stop offset="1" stopColor="var(--cyan)" stopOpacity=".05" /></linearGradient>108                <radialGradient id="core"><stop stopColor="var(--violet)" stopOpacity=".5" /><stop offset="1" stopColor="var(--violet)" stopOpacity="0" /></radialGradient>109              </defs>110              {RINGS.map((r, i) => <path key={i} className="orbit-ring" pathLength={1} style={{ "--i": i } as never} d={ellipse(r.rx, r.ry)} stroke="url(#ring)" strokeWidth={1.4 / Math.max(scale, 0.4)} fill="none" />)}111              <circle className="orbit-core" cx={CX} cy={CY} r="120" fill="url(#core)" />112              {RINGS.map((r, i) => <circle key={i} className="orbit-comet" r={3.2 / Math.max(scale, 0.5)} fill="var(--cyan)" style={{ offsetPath: `path("${ellipse(r.rx, r.ry)}")`, "--period": `${r.period / 3.2}s`, "--phase": `${-i * 4}s` } as never} />)}113            </svg>114            <div className="absolute grid place-items-center" style={{ left: CX - 46, top: CY - 46, width: 92, height: 92, zIndex: 15 }} aria-hidden>115              <svg width="92" height="92" viewBox="0 0 32 32" fill="none"><circle cx="16" cy="16" r="11" stroke="url(#ring-core)" strokeWidth="3.2" /><defs><linearGradient id="ring-core" x1="2" y1="2" x2="30" y2="30" gradientUnits="userSpaceOnUse"><stop stopColor="var(--blue)" /><stop offset=".55" stopColor="var(--violet)" /><stop offset="1" stopColor="var(--cyan)" /></linearGradient></defs><circle cx="25.2" cy="6.8" r="3.2" fill="var(--ink)" stroke="var(--bg)" strokeWidth="1.4" /></svg>116            </div>117            {placed.map(({ app, ring, phase }) => (118              <div key={app.slug} className="orb" data-dim={!matches(app)} style={{ offsetPath: `path("${ellipse(ring.rx, ring.ry)}")`, "--period": `${ring.period}s`, "--phase": `${phase}s`, width: size, height: size } as never}>119                <span className="orb-depth">120                  <Link href={app.href} aria-label={`${app.name} — ${labels.status[app.status]}`} aria-current={active === app.slug ? "true" : undefined} tabIndex={matches(app) ? 0 : -1}121                    className={`block rounded-[22.37%] transition-[box-shadow] duration-300 ${active === app.slug ? "shadow-[0_0_0_3px_var(--ink)]" : ""}`} style={{ "--accent": app.accent ?? "var(--blue)" } as never}122                    onPointerEnter={(e) => { if (e.pointerType === "mouse") setActive(app.slug); }} onPointerDown={(e) => { touch.current = e.pointerType !== "mouse"; before.current = active; }} onFocus={() => setActive(app.slug)}123                    onClick={(e) => { /* A tap focuses (and so selects) the icon before the click arrives: compare with the state before the tap. */ if (touch.current && before.current !== app.slug) { e.preventDefault(); setActive(app.slug); } }} data-testid={`orb-${app.slug}`}>124                    {app.icon125                      ? <span className="icon w-full"><Image src={app.icon} alt="" width={96} height={96} sizes="96px" /></span>126                      : <span className="icon icon-empty w-full"><span aria-hidden data-i={app.name.replace(/^ORIX\s+/i, "").slice(0, 2)} /></span>}127                  </Link>128                </span>129              </div>130            ))}131          </div>132        </div>133134        <div className="card relative min-h-[15.5rem] overflow-hidden p-6" aria-live="polite" data-testid="universe-detail">135          <AnimatePresence mode="wait" initial={false}>136            {current && (137              <motion.div key={current.slug} initial={{ opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -8 }} transition={{ duration: 0.28, ease: [0.16, 1, 0.3, 1] }}>138                <div className="flex items-center justify-between gap-3">139                  <h3 className="h3">{current.name}</h3>140                  <span className="status" data-s={current.status}>{labels.status[current.status]}</span>141                </div>142                <p className="mt-1.5 flex flex-wrap gap-1.5">{current.platforms.map((p) => <span key={p} className="tag">{labels.platforms[p]}</span>)}</p>143                <p className="mt-4 text-[0.96rem] leading-relaxed text-ink2">{current.summary}</p>144                <Link href={current.href} className="btn btn-ghost btn-sm mt-5">{labels.open}<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden><path d="M2 7h10M8 3l4 4-4 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg></Link>145              </motion.div>146            )}147          </AnimatePresence>148        </div>149      </div>150    </div>151  );152}153
Files main
Menu

Theme