Skip to main content
Planetary Axis

Planetary Axis

Zero-dependency 3D projected armillary sphere with obliquity presets, inclined orbit, depth-dimmed arcs, and drag-to-orbit.

3D Canvas
15/16

1. Install Dependencies

$npm install framer-motion lucide-react

2. Copy Component Code

components/ui/PlanetaryAxis.tsx
1"use client";
2
3import React, { useCallback, useEffect, useId, useRef, useState } from "react";
4import { motion, useReducedMotion } from "framer-motion";
5import { Pause, Play, RotateCcw } from "lucide-react";
6
7const APPLE_EASE = [0.22, 1, 0.36, 1] as const;
8const LIQUID_GLASS_SPRING = {
9 type: "spring",
10 stiffness: 350,
11 damping: 30,
12 mass: 0.9,
13} as const;
14
15function getLiquidToggleMotion(
16 prefersReducedMotion: boolean | null | undefined,
17 hasToggled: boolean
18) {
19 if (prefersReducedMotion || !hasToggled) {
20 return {
21 initial: false as const,
22 animate: { scaleX: 1, scaleY: 1 },
23 transition: {
24 layout: { duration: 0 },
25 duration: 0,
26 },
27 };
28 }
29
30 return {
31 initial: { scaleX: 1, scaleY: 1 },
32 animate: { scaleX: [1, 1.16, 1], scaleY: [1, 0.86, 1] },
33 transition: {
34 layout: LIQUID_GLASS_SPRING,
35 scaleX: { duration: 0.36, times: [0, 0.35, 1], ease: APPLE_EASE },
36 scaleY: { duration: 0.36, times: [0, 0.35, 1], ease: APPLE_EASE },
37 },
38 };
39}
40
41export type PlanetaryAxisVariant = "ambient" | "interactive" | "background";
42
43export interface PlanetaryAxisProps {
44 /** "interactive" renders controls + HUD; "ambient" renders a compact orb; "background" renders a full-viewport low-glare backdrop. */
45 variant?: PlanetaryAxisVariant;
46 /** Axial tilt / obliquity in degrees (default 23.5). */
47 defaultTilt?: number;
48 /** Inclined outer orbital plane angle in degrees (default 14). */
49 defaultInclination?: number;
50 /** Optional wrapper classes (ambient mode uses sizing classes such as "h-28 w-28"). */
51 className?: string;
52}
53
54interface Vec3 {
55 x: number;
56 y: number;
57 z: number;
58}
59
60const DEG_TO_RAD = Math.PI / 180;
61const TILT_PRESETS = [0, 23.5, 45, 72] as const;
62const RING_SEGMENTS = 64;
63const EMERALD_RGB = "16, 185, 129";
64
65function rotatePoint(
66 p: Vec3,
67 spinY: number,
68 obliquityZ: number,
69 viewPitchX: number,
70 viewYawY: number,
71): Vec3 {
72 // 1. Spin around planetary polar Y axis
73 const cosS = Math.cos(spinY);
74 const sinS = Math.sin(spinY);
75 const x1 = p.x * cosS + p.z * sinS;
76 const y1 = p.y;
77 const z1 = -p.x * sinS + p.z * cosS;
78
79 // 2. Apply axial tilt / obliquity around Z axis
80 const cosT = Math.cos(obliquityZ);
81 const sinT = Math.sin(obliquityZ);
82 const x2 = x1 * cosT - y1 * sinT;
83 const y2 = x1 * sinT + y1 * cosT;
84 const z2 = z1;
85
86 // 3. Apply viewer yaw around world Y axis
87 const cosY = Math.cos(viewYawY);
88 const sinY = Math.sin(viewYawY);
89 const x3 = x2 * cosY + z2 * sinY;
90 const y3 = y2;
91 const z3 = -x2 * sinY + z2 * cosY;
92
93 // 4. Apply viewer pitch around world X axis
94 const cosP = Math.cos(viewPitchX);
95 const sinP = Math.sin(viewPitchX);
96 return {
97 x: x3,
98 y: y3 * cosP - z3 * sinP,
99 z: y3 * sinP + z3 * cosP,
100 };
101}
102
103function projectPoint(p: Vec3, cx: number, cy: number, radius: number) {
104 const cameraDistance = 4.2;
105 const perspective = cameraDistance / Math.max(0.5, cameraDistance - p.z);
106 return {
107 x: cx + p.x * radius * perspective,
108 y: cy + p.y * radius * perspective,
109 z: p.z,
110 scale: perspective,
111 };
112}
113
114function createLatitudeRing(latRad: number, ringRadius = 1): Vec3[] {
115 const y = Math.sin(latRad) * ringRadius;
116 const r = Math.cos(latRad) * ringRadius;
117 const pts: Vec3[] = [];
118 for (let i = 0; i <= RING_SEGMENTS; i++) {
119 const a = (i / RING_SEGMENTS) * Math.PI * 2;
120 pts.push({ x: Math.cos(a) * r, y, z: Math.sin(a) * r });
121 }
122 return pts;
123}
124
125function createMeridianRing(lonRad: number, ringRadius = 1): Vec3[] {
126 const cosL = Math.cos(lonRad);
127 const sinL = Math.sin(lonRad);
128 const pts: Vec3[] = [];
129 for (let i = 0; i <= RING_SEGMENTS; i++) {
130 const a = (i / RING_SEGMENTS) * Math.PI * 2;
131 const x0 = Math.cos(a) * ringRadius;
132 const y0 = Math.sin(a) * ringRadius;
133 pts.push({ x: x0 * cosL, y: y0, z: x0 * sinL });
134 }
135 return pts;
136}
137
138function createInclinedOrbit(incRad: number, ringRadius: number): Vec3[] {
139 const cosI = Math.cos(incRad);
140 const sinI = Math.sin(incRad);
141 const pts: Vec3[] = [];
142 for (let i = 0; i <= RING_SEGMENTS; i++) {
143 const a = (i / RING_SEGMENTS) * Math.PI * 2;
144 const x0 = Math.cos(a) * ringRadius;
145 const z0 = Math.sin(a) * ringRadius;
146 pts.push({
147 x: x0 * cosI,
148 y: x0 * sinI,
149 z: z0,
150 });
151 }
152 return pts;
153}
154
155export function PlanetaryAxis({
156 variant = "interactive",
157 defaultTilt = 23.5,
158 defaultInclination = 14,
159 className = "",
160}: PlanetaryAxisProps) {
161 const prefersReducedMotion = Boolean(useReducedMotion());
162 const isInteractive = variant === "interactive";
163 const isBackground = variant === "background";
164
165 const [tiltDeg, setTiltDeg] = useState(defaultTilt);
166 const [hasToggledPreset, setHasToggledPreset] = useState(false);
167 const presetGroupId = useId();
168 const [inclinationDeg, setInclinationDeg] = useState(defaultInclination);
169 const [isPlaying, setIsPlaying] = useState(true);
170 const [isDragging, setIsDragging] = useState(false);
171
172 const canvasRef = useRef<HTMLCanvasElement>(null);
173 const wrapperRef = useRef<HTMLDivElement>(null);
174
175 const animRef = useRef({
176 spin: 0.4,
177 orbitPhase: 0.9,
178 currentTilt: defaultTilt,
179 targetTilt: defaultTilt,
180 currentInc: defaultInclination,
181 targetInc: defaultInclination,
182 viewPitch: isBackground ? 0.24 : 0.28,
183 viewYaw: isBackground ? -0.35 : -0.25,
184 hoverPitch: 0,
185 hoverYaw: 0,
186 scrollMod: 0,
187 isPlaying: true,
188 inView: true,
189 tabVisible: true,
190 isDark: true,
191 width: 0,
192 height: 0,
193 dpr: 1,
194 });
195
196 const dragStartRef = useRef<{
197 x: number;
198 y: number;
199 startYaw: number;
200 startPitch: number;
201 } | null>(null);
202
203 const drawFrame = useCallback(() => {
204 const canvas = canvasRef.current;
205 if (!canvas) return;
206 const ctx = canvas.getContext("2d");
207 if (!ctx) return;
208
209 const state = animRef.current;
210 const w = state.width;
211 const h = state.height;
212 if (w <= 0 || h <= 0) return;
213
214 ctx.clearRect(0, 0, w, h);
215
216 const cx = isBackground ? (w >= 768 ? w * 0.56 : w * 0.5) : w / 2;
217 const cy = h / 2;
218 const radius = isBackground
219 ? Math.min(w, h) * 0.44
220 : Math.min(w, h) * (isInteractive ? 0.31 : 0.34);
221
222 const obliquityRad = state.currentTilt * DEG_TO_RAD;
223 const incRad = state.currentInc * DEG_TO_RAD;
224 const totalPitch = state.viewPitch + state.hoverPitch + state.scrollMod * 0.35;
225 const totalYaw = state.viewYaw + state.hoverYaw + state.scrollMod * 0.5;
226
227 const monoRgb = state.isDark
228 ? isBackground
229 ? "228, 228, 232"
230 : "255, 255, 255"
231 : "17, 17, 17";
232 const emeraldRgb = !state.isDark && isBackground ? "5, 150, 105" : EMERALD_RGB;
233
234 const drawRingSegments = (
235 points: Vec3[],
236 spinAngle: number,
237 frontAlpha: number,
238 backAlpha: number,
239 lineWidth: number,
240 ) => {
241 for (let i = 0; i < points.length - 1; i++) {
242 const a3 = rotatePoint(
243 points[i],
244 spinAngle,
245 obliquityRad,
246 totalPitch,
247 totalYaw,
248 );
249 const b3 = rotatePoint(
250 points[i + 1],
251 spinAngle,
252 obliquityRad,
253 totalPitch,
254 totalYaw,
255 );
256 const avgZ = (a3.z + b3.z) * 0.5;
257 const depthT = Math.max(0, Math.min(1, (avgZ + 1.15) / 2.3));
258 const alpha = backAlpha + (frontAlpha - backAlpha) * depthT;
259
260 const a2 = projectPoint(a3, cx, cy, radius);
261 const b2 = projectPoint(b3, cx, cy, radius);
262
263 ctx.beginPath();
264 ctx.moveTo(a2.x, a2.y);
265 ctx.lineTo(b2.x, b2.y);
266 ctx.strokeStyle = `rgba(${monoRgb}, ${alpha.toFixed(3)})`;
267 ctx.lineWidth = lineWidth;
268 ctx.stroke();
269 }
270 };
271
272 const ringAlphas = isBackground
273 ? state.isDark
274 ? { lat: [0.11, 0.035], eq: [0.17, 0.05], mer: [0.1, 0.03], inc: [0.15, 0.045] }
275 : { lat: [0.075, 0.025], eq: [0.12, 0.04], mer: [0.07, 0.02], inc: [0.11, 0.035] }
276 : { lat: [0.34, 0.08], eq: [0.72, 0.14], mer: [0.3, 0.07], inc: [0.52, 0.12] };
277
278 // Latitude rings (tropics + equator)
279 drawRingSegments(
280 createLatitudeRing(-45 * DEG_TO_RAD),
281 state.spin,
282 ringAlphas.lat[0],
283 ringAlphas.lat[1],
284 1,
285 );
286 drawRingSegments(
287 createLatitudeRing(45 * DEG_TO_RAD),
288 state.spin,
289 ringAlphas.lat[0],
290 ringAlphas.lat[1],
291 1,
292 );
293 drawRingSegments(
294 createLatitudeRing(0),
295 state.spin,
296 ringAlphas.eq[0],
297 ringAlphas.eq[1],
298 isBackground ? 1.15 : 1.35,
299 );
300
301 // Longitudinal meridian rings
302 drawRingSegments(
303 createMeridianRing(0),
304 state.spin,
305 ringAlphas.mer[0],
306 ringAlphas.mer[1],
307 1,
308 );
309 drawRingSegments(
310 createMeridianRing(60 * DEG_TO_RAD),
311 state.spin,
312 ringAlphas.mer[0],
313 ringAlphas.mer[1],
314 1,
315 );
316 drawRingSegments(
317 createMeridianRing(120 * DEG_TO_RAD),
318 state.spin,
319 ringAlphas.mer[0],
320 ringAlphas.mer[1],
321 1,
322 );
323
324 // Inclined outer orbital path
325 drawRingSegments(
326 createInclinedOrbit(incRad, 1.18),
327 0,
328 ringAlphas.inc[0],
329 ringAlphas.inc[1],
330 1.1,
331 );
332
333 // Tilted central polar axis spine & poles
334 const northPole = projectPoint(
335 rotatePoint({ x: 0, y: -1.26, z: 0 }, 0, obliquityRad, totalPitch, totalYaw),
336 cx,
337 cy,
338 radius,
339 );
340 const southPole = projectPoint(
341 rotatePoint({ x: 0, y: 1.26, z: 0 }, 0, obliquityRad, totalPitch, totalYaw),
342 cx,
343 cy,
344 radius,
345 );
346
347 const axisAlpha = isBackground ? (state.isDark ? 0.25 : 0.22) : isInteractive ? 0.85 : 0.72;
348 const poleAlpha = isBackground ? (state.isDark ? 0.42 : 0.32) : 1;
349
350 ctx.beginPath();
351 ctx.moveTo(southPole.x, southPole.y);
352 ctx.lineTo(northPole.x, northPole.y);
353 ctx.strokeStyle = `rgba(${emeraldRgb}, ${axisAlpha})`;
354 ctx.lineWidth = isInteractive ? 1.5 : 1.2;
355 ctx.stroke();
356
357 for (const pole of [northPole, southPole]) {
358 ctx.beginPath();
359 ctx.arc(pole.x, pole.y, isInteractive ? 2.6 : 2, 0, Math.PI * 2);
360 ctx.fillStyle = `rgba(${emeraldRgb}, ${poleAlpha})`;
361 ctx.fill();
362 }
363
364 // Center core pivot dot
365 ctx.beginPath();
366 ctx.arc(cx, cy, isInteractive ? 2.2 : 1.75, 0, Math.PI * 2);
367 ctx.fillStyle = `rgba(${monoRgb}, ${isBackground ? 0.16 : 0.55})`;
368 ctx.fill();
369
370 // 2 Surgical Emerald orbital nodes (equatorial + inclined ring)
371 const eqNode3 = rotatePoint(
372 {
373 x: Math.cos(state.orbitPhase),
374 y: 0,
375 z: Math.sin(state.orbitPhase),
376 },
377 state.spin,
378 obliquityRad,
379 totalPitch,
380 totalYaw,
381 );
382
383 const incAngle = -state.orbitPhase * 0.72 + 1.8;
384 const xInc = Math.cos(incAngle) * 1.18;
385 const zInc = Math.sin(incAngle) * 1.18;
386 const incNode3 = rotatePoint(
387 {
388 x: xInc * Math.cos(incRad),
389 y: xInc * Math.sin(incRad),
390 z: zInc,
391 },
392 0,
393 obliquityRad,
394 totalPitch,
395 totalYaw,
396 );
397
398 for (const node3 of [eqNode3, incNode3]) {
399 const node2 = projectPoint(node3, cx, cy, radius);
400 const isFront = node3.z >= -0.05;
401 const baseNodeAlpha = isBackground ? (state.isDark ? 0.48 : 0.34) : 1;
402 const nodeAlpha = (isFront ? 1 : 0.42) * baseNodeAlpha;
403 const dotR = (isInteractive ? 3.6 : isBackground ? 3 : 2.6) * node2.scale;
404
405 ctx.beginPath();
406 ctx.arc(node2.x, node2.y, dotR * 2.1, 0, Math.PI * 2);
407 ctx.fillStyle = `rgba(${emeraldRgb}, ${(0.2 * nodeAlpha).toFixed(3)})`;
408 ctx.fill();
409
410 ctx.beginPath();
411 ctx.arc(node2.x, node2.y, dotR, 0, Math.PI * 2);
412 ctx.fillStyle = `rgba(${emeraldRgb}, ${nodeAlpha.toFixed(3)})`;
413 ctx.fill();
414 }
415 }, [isBackground, isInteractive]);
416
417 useEffect(() => {
418 animRef.current.targetTilt = tiltDeg;
419 animRef.current.targetInc = inclinationDeg;
420 if (prefersReducedMotion || !isPlaying) {
421 animRef.current.currentTilt = tiltDeg;
422 animRef.current.currentInc = inclinationDeg;
423 drawFrame();
424 }
425 }, [tiltDeg, inclinationDeg, prefersReducedMotion, isPlaying, drawFrame]);
426
427 useEffect(() => {
428 animRef.current.isPlaying = isPlaying;
429 }, [isPlaying]);
430
431 // Keep canvas synchronized with Light/Dark root class, DPR, ResizeObserver & IntersectionObserver
432 useEffect(() => {
433 const wrapper = wrapperRef.current;
434 const canvas = canvasRef.current;
435 if (!wrapper || !canvas) return;
436
437 const syncTheme = () => {
438 animRef.current.isDark =
439 document.documentElement.classList.contains("dark");
440 drawFrame();
441 };
442 syncTheme();
443
444 const themeObserver = new MutationObserver(syncTheme);
445 themeObserver.observe(document.documentElement, {
446 attributes: true,
447 attributeFilter: ["class"],
448 });
449
450 const measureCanvas = () => {
451 const w = canvas.clientWidth;
452 const h = canvas.clientHeight;
453 if (w <= 0 || h <= 0) return;
454
455 const dpr = Math.min(window.devicePixelRatio || 1, 2);
456 canvas.width = Math.round(w * dpr);
457 canvas.height = Math.round(h * dpr);
458 const ctx = canvas.getContext("2d");
459 if (ctx) {
460 ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
461 }
462
463 animRef.current.width = w;
464 animRef.current.height = h;
465 animRef.current.dpr = dpr;
466 drawFrame();
467 };
468
469 measureCanvas();
470 const resizeObserver = new ResizeObserver(measureCanvas);
471 resizeObserver.observe(canvas);
472
473 const intersectionObserver = new IntersectionObserver(
474 (entries) => {
475 const entry = entries[0];
476 if (!entry) return;
477 animRef.current.inView = entry.isIntersecting;
478 },
479 { threshold: 0.01 },
480 );
481 intersectionObserver.observe(wrapper);
482
483 const handleVisibilityChange = () => {
484 animRef.current.tabVisible = document.visibilityState === "visible";
485 };
486 document.addEventListener("visibilitychange", handleVisibilityChange);
487
488 let scrollRafId: number | null = null;
489 const handleScroll = () => {
490 if (!isBackground || scrollRafId !== null) return;
491 scrollRafId = window.requestAnimationFrame(() => {
492 scrollRafId = null;
493 const maxScroll = Math.max(
494 1,
495 document.documentElement.scrollHeight - window.innerHeight,
496 );
497 animRef.current.scrollMod = Math.min(1, Math.max(0, window.scrollY / maxScroll));
498 if (prefersReducedMotion) drawFrame();
499 });
500 };
501 if (isBackground) {
502 window.addEventListener("scroll", handleScroll, { passive: true });
503 }
504
505 let rafId: number | null = null;
506 let lastTime = performance.now();
507
508 const tick = (now: number) => {
509 const dt = Math.min(0.05, Math.max(0.001, (now - lastTime) / 1000));
510 lastTime = now;
511
512 const s = animRef.current;
513 if (s.inView && s.tabVisible && s.isPlaying && !prefersReducedMotion) {
514 s.spin += dt * (isBackground ? 0.16 : 0.42);
515 s.orbitPhase += dt * (isBackground ? 0.32 : 0.85);
516 s.currentTilt += (s.targetTilt - s.currentTilt) * 0.14;
517 s.currentInc += (s.targetInc - s.currentInc) * 0.14;
518 drawFrame();
519 }
520
521 if (!prefersReducedMotion) {
522 rafId = window.requestAnimationFrame(tick);
523 }
524 };
525
526 if (!prefersReducedMotion) {
527 rafId = window.requestAnimationFrame(tick);
528 }
529
530 return () => {
531 if (rafId !== null) window.cancelAnimationFrame(rafId);
532 if (scrollRafId !== null) window.cancelAnimationFrame(scrollRafId);
533 themeObserver.disconnect();
534 resizeObserver.disconnect();
535 intersectionObserver.disconnect();
536 document.removeEventListener("visibilitychange", handleVisibilityChange);
537 if (isBackground) {
538 window.removeEventListener("scroll", handleScroll);
539 }
540 };
541 }, [drawFrame, isBackground, prefersReducedMotion]);
542
543 const handlePointerDown = (event: React.PointerEvent<HTMLCanvasElement>) => {
544 if (!isInteractive || event.button !== 0) return;
545 event.currentTarget.setPointerCapture(event.pointerId);
546 dragStartRef.current = {
547 x: event.clientX,
548 y: event.clientY,
549 startYaw: animRef.current.viewYaw,
550 startPitch: animRef.current.viewPitch,
551 };
552 setIsDragging(true);
553 };
554
555 const handlePointerMove = (event: React.PointerEvent<HTMLCanvasElement>) => {
556 const rect = event.currentTarget.getBoundingClientRect();
557 if (dragStartRef.current) {
558 const dx = event.clientX - dragStartRef.current.x;
559 const dy = event.clientY - dragStartRef.current.y;
560 animRef.current.viewYaw = dragStartRef.current.startYaw + dx * 0.008;
561 animRef.current.viewPitch = Math.max(
562 -1.1,
563 Math.min(1.1, dragStartRef.current.startPitch + dy * 0.008),
564 );
565 if (prefersReducedMotion || !isPlaying) drawFrame();
566 return;
567 }
568
569 if (rect.width > 0 && rect.height > 0) {
570 const nx = (event.clientX - rect.left) / rect.width - 0.5;
571 const ny = (event.clientY - rect.top) / rect.height - 0.5;
572 animRef.current.hoverYaw = nx * 0.24;
573 animRef.current.hoverPitch = ny * 0.2;
574 if (prefersReducedMotion || !isPlaying) drawFrame();
575 }
576 };
577
578 const handlePointerUpOrCancel = (
579 event: React.PointerEvent<HTMLCanvasElement>,
580 ) => {
581 if (
582 dragStartRef.current &&
583 event.currentTarget.hasPointerCapture(event.pointerId)
584 ) {
585 event.currentTarget.releasePointerCapture(event.pointerId);
586 }
587 dragStartRef.current = null;
588 setIsDragging(false);
589 };
590
591 const handlePointerLeave = () => {
592 animRef.current.hoverYaw = 0;
593 animRef.current.hoverPitch = 0;
594 if (prefersReducedMotion || !isPlaying) drawFrame();
595 };
596
597 const handleReset = () => {
598 setTiltDeg(defaultTilt);
599 setInclinationDeg(defaultInclination);
600 animRef.current.viewPitch = 0.28;
601 animRef.current.viewYaw = -0.25;
602 animRef.current.currentTilt = defaultTilt;
603 animRef.current.targetTilt = defaultTilt;
604 animRef.current.currentInc = defaultInclination;
605 animRef.current.targetInc = defaultInclination;
606 drawFrame();
607 };
608
609 if (isBackground) {
610 return (
611 <div
612 ref={wrapperRef}
613 aria-hidden="true"
614 className={`pointer-events-none relative h-full w-full select-none ${className}`}
615 >
616 <canvas ref={canvasRef} className="pointer-events-none h-full w-full" />
617 </div>
618 );
619 }
620
621 if (!isInteractive) {
622 return (
623 <div
624 ref={wrapperRef}
625 aria-hidden="true"
626 className={`relative aspect-square select-none ${className || "h-24 w-24"}`}
627 >
628 <canvas
629 ref={canvasRef}
630 onPointerMove={handlePointerMove}
631 onPointerLeave={handlePointerLeave}
632 className="h-full w-full touch-pan-y"
633 />
634 </div>
635 );
636 }
637
638 return (
639 <div
640 ref={wrapperRef}
641 className={`cosrim-surface-card w-full max-w-[520px] min-w-0 rounded-[20px] p-2 ${className}`}
642 >
643 {/* Recessed 3D Canvas Stage */}
644 <div className="cosrim-surface-recessed relative h-[320px] w-full overflow-hidden rounded-[12px] sm:h-[360px]">
645 <div
646 aria-hidden="true"
647 className="pointer-events-none absolute top-3.5 left-3.5 z-10 flex items-center gap-3 font-mono text-xs tabular-nums text-[#525252] dark:text-[#A1A1AA]"
648 >
649 <span className="inline-flex items-center gap-1.5">
650 <span className="h-1.5 w-1.5 rounded-full bg-emerald-500" />
651 Tilt {tiltDeg.toFixed(1)}°
652 </span>
653 <span>
654 Inc {inclinationDeg >= 0 ? `+${inclinationDeg}` : inclinationDeg}°
655 </span>
656 </div>
657
658 <canvas
659 ref={canvasRef}
660 aria-label="Interactive 3D planetary axis projection. Drag horizontally or vertically to inspect."
661 onPointerDown={handlePointerDown}
662 onPointerMove={handlePointerMove}
663 onPointerUp={handlePointerUpOrCancel}
664 onPointerCancel={handlePointerUpOrCancel}
665 onPointerLeave={handlePointerLeave}
666 className={`h-full w-full touch-pan-y ${
667 isDragging ? "cursor-grabbing" : "cursor-grab"
668 }`}
669 />
670 </div>
671
672 {/* Controls Strip */}
673 <div className="flex flex-col gap-3 p-3">
674 <div className="flex flex-wrap items-center justify-between gap-2">
675 <div
676 role="group"
677 aria-label="Axial tilt presets"
678 className="inline-flex items-center gap-1 rounded-[10px] bg-[#F5F5F7] p-1 dark:bg-[#141416]"
679 >
680 {TILT_PRESETS.map((preset) => {
681 const active = Math.abs(tiltDeg - preset) < 0.05;
682 return (
683 <button
684 key={preset}
685 type="button"
686 aria-pressed={active}
687 onClick={() => {
688 if (!active) setHasToggledPreset(true);
689 setTiltDeg(preset);
690 }}
691 className={`relative inline-flex min-h-7 cursor-pointer items-center rounded-[7px] px-2.5 font-mono text-xs tabular-nums transition-colors ${
692 active
693 ? "text-[#0A0A0A] dark:text-white"
694 : "text-[#525252] hover:text-[#0A0A0A] dark:text-[#A1A1AA] dark:hover:text-white"
695 }`}
696 >
697 {active && (
698 <motion.span
699 layoutId={`${presetGroupId}-tilt-preset`}
700 {...getLiquidToggleMotion(
701 prefersReducedMotion,
702 hasToggledPreset
703 )}
704 aria-hidden="true"
705 className="absolute inset-0 rounded-[7px] bg-white shadow-[0_1px_2px_rgba(0,0,0,0.08)] dark:bg-[#232328]"
706 />
707 )}
708 <span className="relative z-10">{preset}°</span>
709 </button>
710 );
711 })}
712 </div>
713
714 <div className="flex items-center gap-1.5">
715 <button
716 type="button"
717 onClick={() => setIsPlaying((p) => !p)}
718 aria-label={isPlaying ? "Pause orbit animation" : "Play orbit animation"}
719 title={isPlaying ? "Pause" : "Play"}
720 className="cosrim-control inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-[8px]"
721 >
722 {isPlaying ? (
723 <Pause className="h-3.5 w-3.5" strokeWidth={1.75} aria-hidden="true" />
724 ) : (
725 <Play className="h-3.5 w-3.5" strokeWidth={1.75} aria-hidden="true" />
726 )}
727 </button>
728
729 <button
730 type="button"
731 onClick={handleReset}
732 aria-label="Reset camera and inclination"
733 title="Reset"
734 className="cosrim-control inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-[8px]"
735 >
736 <RotateCcw className="h-3.5 w-3.5" strokeWidth={1.75} aria-hidden="true" />
737 </button>
738 </div>
739 </div>
740
741 <label className="flex items-center justify-between gap-4 rounded-[10px] bg-[#F5F5F7] px-3 py-2 dark:bg-[#141416]">
742 <span className="shrink-0 font-mono text-xs text-[#525252] dark:text-[#A1A1AA]">
743 Orbital Inclination
744 </span>
745 <input
746 type="range"
747 min={-45}
748 max={45}
749 step={1}
750 value={inclinationDeg}
751 onChange={(e) => setInclinationDeg(Number(e.target.value))}
752 aria-label="Orbital inclination in degrees"
753 className="h-1.5 w-full max-w-[200px] cursor-pointer accent-emerald-600 dark:accent-emerald-400"
754 />
755 <span className="w-10 shrink-0 text-right font-mono text-xs tabular-nums text-[#0A0A0A] dark:text-white">
756 {inclinationDeg}°
757 </span>
758 </label>
759 </div>
760 </div>
761 );
762}

Usage Example

import { PlanetaryAxis } from "@/components/ui/PlanetaryAxis";
export default function OrbitalStage() {
return (
<PlanetaryAxis
variant="interactive"
defaultTilt={23.5}
defaultInclination={14}
/>
);
}

3. Props Reference

Planetary Axis props API reference
PropTypeDefaultDescription
variant"ambient" | "interactive""interactive"Switches between compact masthead canvas mode and full interactive obliquity/inclination showcase.
defaultTiltnumber23.5Starting axial tilt angle in degrees (Earth obliquity default).
defaultInclinationnumber14Initial angle of the outer orbital ring in degrees (-45 to 45).
classNamestring""Optional Tailwind sizing or spacing utility classes.