跳至正文
获取 Pro
东方雅集E.04

宣纸朱砂印鉴

FreeRegistry
components/linyi/cinnabar-seal.tsx
motion
"use client";
 
import * as React from "react";
import { motion, AnimatePresence } from "motion/react";
import { cn } from "@/lib/cn";
import { SPRING_SNAPPY } from "@/lib/motion";
import { playSound } from "@/lib/sound";
 
export type SealCarving = "yang" | "yin" | "leisure";
export type SealPigment = "cinnabar" | "pine" | "jade";
 
export interface CinnabarSealProps {
text?: string;
carving?: SealCarving;
pigment?: SealPigment;
onStamp?: (timestamp: string) => void;
compact?: boolean;
className?: string;
}
 
const PIGMENT_MAP: Record<SealPigment, { color: string; soft: string; name: string }> = {
cinnabar: { color: "var(--oriental-cinnabar, #B83322)", soft: "rgba(184, 51, 34, 0.11)", name: "西泠朱砂" },
pine: { color: "var(--ink-1, #262320)", soft: "rgba(38, 35, 32, 0.10)", name: "徽州松烟" },
jade: { color: "var(--oriental-bronze, #2C6B5E)", soft: "rgba(44, 107, 94, 0.12)", name: "石绿松石" },
};
 
export function CinnabarSeal({
text = "素宣雅集",
carving = "yin",
pigment = "cinnabar",
onStamp,
compact = false,
className,
}: CinnabarSealProps) {
const [stampCount, setStampCount] = React.useState(0);
const [stampedAt, setStampedAt] = React.useState<string | null>(null);
const uid = React.useId().replace(/:/g, "");
const ink = PIGMENT_MAP[pigment];
 
const chars = Array.from(text).slice(0, 4);
 
const handleStamp = () => {
playSound("stamp");
const time = new Date().toLocaleTimeString("zh-CN", { hour12: false });
setStampCount((c) => c + 1);
setStampedAt(time);
onStamp?.(time);
};
 
const isYin = carving === "yin";
const isLeisure = carving === "leisure";
 
return (
<div className={cn("flex flex-col items-center gap-3 select-none", className)}>
<div className="relative flex items-center justify-center">
{/* Ink bleed pulse ring on stamp */}
<AnimatePresence mode="popLayout">
{stampCount > 0 && (
<motion.span
key={stampCount}
initial={{ scale: 0.9, opacity: 0.48 }}
animate={{ scale: 1.24, opacity: 0 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.45, ease: "easeOut" }}
className="pointer-events-none absolute inset-0"
style={{
borderRadius: isLeisure ? "9999px" : "8px",
border: `1.5px solid ${ink.color}`,
}}
/>
)}
</AnimatePresence>
 
<motion.button
type="button"
onClick={handleStamp}
whileHover={{ y: -1.5 }}
whileTap={{ scale: 0.91, rotate: -2.2 }}
transition={SPRING_SNAPPY}
aria-label={`落印:${text}`}
className={cn(
"relative overflow-hidden cursor-pointer flex items-center justify-center font-serif outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2",
isLeisure
? compact
? "px-3.5 py-2.5 rounded-full"
: "px-4 py-3.5 rounded-full"
: compact
? "h-16 w-16 rounded-[7px]"
: "h-20 w-20 rounded-[8px]"
)}
style={{
background: isYin ? ink.color : ink.soft,
color: isYin ? "var(--oriental-seal-yin-fg, #FBF8F1)" : ink.color,
border: isYin ? `1px solid ${ink.color}` : `2px solid ${ink.color}`,
boxShadow: isYin
? `0 8px 18px -10px ${ink.color}, inset 0 0 0 1.5px rgba(251, 248, 241, 0.24)`
: `inset 0 0 0 1px ${ink.soft}`,
}}
>
{/* Mineral cinnabar pigment paper-tooth filter */}
<svg aria-hidden="true" className="pointer-events-none absolute inset-0 h-full w-full opacity-[0.26]">
<filter id={`seal-grain-${uid}`}>
<feTurbulence type="fractalNoise" baseFrequency="1.4" numOctaves="3" seed="5" />
<feColorMatrix type="saturate" values="0" />
</filter>
<rect width="100%" height="100%" filter={`url(#seal-grain-${uid})`} />
</svg>
 
{isLeisure ? (
<span className="relative z-10 text-sm tracking-[0.28em] font-medium pl-[0.28em]">
{text.slice(0, 3)}
</span>
) : (
<span className="relative z-10 grid grid-cols-2 gap-x-1 gap-y-0.5 text-lg leading-none font-semibold">
{chars.map((ch, idx) => (
<span key={`${ch}-${idx}`} className="flex items-center justify-center">
{ch}
</span>
))}
</span>
)}
</motion.button>
</div>
 
<div className="flex items-center gap-2 font-mono-num text-[11px] text-fg-secondary">
<span>{ink.name}</span>
<span className="opacity-35">·</span>
<span style={{ color: stampedAt ? ink.color : "var(--fg-muted)" }}>
{stampedAt ? `已落印 ${stampedAt}` : "点击落印"}
</span>
</div>
</div>
);
}