import React, { useState, useEffect } from 'react';
import {
Sparkles,
Search,
Stamp,
BookOpen,
ChevronRight,
X,
RefreshCw,
Box,
Shapes,
Type,
PenTool,
Maximize2,
ZoomIn,
RotateCcw
} from 'lucide-react';
const JADE_TYPES = [
{ id: 'hetian', name: '和田羊脂玉', desc: '温润如脂,精光内蕴', prompt: 'Mutton-fat White Jade, translucent, greasy luster' },
{ id: 'feicui', name: '翡翠冰种', desc: '澄澈如水,翠意生辉', prompt: 'Ice-type Green Jadeite, glass-like transparency' },
{ id: 'xiuyan', name: '岫岩老玉', desc: '质地朴茂,古韵悠长', prompt: 'Xiu-jade, dark green with natural stone texture' },
{ id: 'dushan', name: '独山玉', desc: '色彩斑斓,如梦似幻', prompt: 'Dushan Jade, multi-color patterns' },
{ id: 'nanred', name: '南红玛瑙', desc: '色泽鲜红,温润饱满', prompt: 'Southern Red Agate, deep solid red, semi-translucent' }
];
const JADE_SHAPES = ['山子', '牌片', '圆雕件', '手把件', '随形料', '器皿'];
const SEAL_MATERIALS = [
{ id: 'tianhuang', name: '寿山田黄', color: '#ffb300', texture: 'warm yellow honey-like stone with radish-silk veins' },
{ id: 'jixue', name: '昌化鸡血', color: '#d32f2f', texture: 'bright cinnabar red patches on grey stone base' },
{ id: 'furong', name: '寿山芙蓉', color: '#f8bbd0', texture: 'pale pink porcelain-like stone texture' },
{ id: 'qingtian', name: '青田封门', color: '#c5e1a5', texture: 'olive green semi-translucent stone' },
{ id: 'balin', name: '巴林福黄', color: '#ffd54f', texture: 'bright glassy yellow stone' },
{ id: 'kunlun', name: '昆仑冻石', color: '#e0f2f1', texture: 'crystal-like translucent white stone' },
{ id: 'yaan', name: '雅安绿', color: '#4caf50', texture: 'vibrant emerald green stone texture' },
{ id: 'chongqing', name: '重庆漆石', color: '#212121', texture: 'pitch black polished lacquer-like stone' }
];
const SEAL_FONTS = [
{ id: 'zhuanshu', name: '秦汉篆书', style: 'seal script style, rounded and balanced lines' },
{ id: 'lishu', name: '汉隶碑刻', style: 'clerical script style, flared strokes, ancient and thick' },
{ id: 'kaishu', name: '唐风楷书', style: 'regular script style, sharp and formal strokes' },
{ id: 'xingshu', name: '文人行书', style: 'running script style, fluid and elegant cursive strokes' }
];
async function generateNanoBananaImage(prompt, aspectRatio = "1:1") {
const apiKey = ""; // Runtime auto-fill
const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent?key=${apiKey}`;
const payload = {
contents: [{
role: 'user',
parts: [{ text: prompt }]
}],
generationConfig: {
responseModalities: ['IMAGE'],
imageConfig: { aspectRatio: aspectRatio }
}
};
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (!response.ok) throw new Error('Generation failed');
const result = await response.json();
const part = result?.candidates?.[0]?.content?.parts?.find(p => p.inlineData);
if (part) {
return `data:${part.inlineData.mimeType};base64,${part.inlineData.data}`;
}
return null;
} catch (error) {
console.error("Image generation error:", error);
return null;
}
}
export default function JadeDesignApp() {
const [activeTab, setActiveTab] = useState('相玉定形');
const [previewImage, setPreviewImage] = useState(null);
return (
{/* 侧边导航 - 典雅金石风格 */}
{[
{ id: '相玉定形', icon:
, sub: 'DESIGN' },
{ id: '方寸金石', icon:
, sub: 'SEAL' }
].map((tab) => (
setActiveTab(tab.id)}
className={`w-full group flex flex-col items-start px-6 py-5 rounded-sm transition-all duration-500 border-l-2 ${
activeTab === tab.id
? 'bg-gradient-to-r from-[#c2a47a10] to-transparent border-[#c2a47a] text-[#c2a47a]'
: 'border-transparent text-[#8c8c82] hover:text-[#e5e5e0]'
}`}
>
{tab.sub}
))}
{/* 主操作区 - 类似展厅的灯光感 */}
{activeTab === '相玉定形' && }
{activeTab === '方寸金石' && }
{/* 全屏大图预览 */}
{previewImage && (
setPreviewImage(null)}
>
e.stopPropagation()}
/>
)}
);
}
function ModuleDesign({ onShowFull }) {
const initialForm = { type: JADE_TYPES[0].name, shape: JADE_SHAPES[0], appearance: '', design: '' };
const [formData, setFormData] = useState(initialForm);
const [generating, setGenerating] = useState(false);
const [imgUrl, setImgUrl] = useState(null);
const handleReset = () => { setFormData(initialForm); setImgUrl(null); };
const handleGenerate = async () => {
if (!formData.appearance || !formData.design) return;
setGenerating(true);
const typeObj = JADE_TYPES.find(t => t.name === formData.type);
const prompt = `Extreme realistic professional museum macro photography.
Subject: A master-level Chinese jade carving.
Material: ${typeObj.prompt}, high subsurface scattering, realistic oily or icy texture.
Form: ${formData.shape}.
Raw stone features incorporated: ${formData.appearance}.
Artistic Concept: ${formData.design}.
Lighting: Soft side lighting to reveal texture and depth, dark neutral background, 8k resolution, cinematic quality.`;
const url = await generateNanoBananaImage(prompt, "1:1");
if (url) setImgUrl(url);
setGenerating(false);
};
return (
相玉定形
AI-DRIVEN JADE ARTISTRY
重置构思
{/* Input fields with elegant labels */}
品类
setFormData({...formData, type: e.target.value})}
className="w-full bg-[#080807] border border-[#2d2a20] p-3 text-sm text-[#f2f2ed] outline-none focus:border-[#c2a47a/50] transition-all cursor-pointer"
>
{JADE_TYPES.map(t => {t.name} )}
形制
{JADE_SHAPES.map(s => (
setFormData({...formData, shape: s})}
className={`py-2 text-[11px] border transition-all ${formData.shape === s ? 'bg-[#c2a47a10] border-[#c2a47a] text-[#c2a47a]' : 'border-[#2d2a20] text-[#63635e] hover:border-[#4d4d4a]'}`}
>
{s}
))}
原石样貌描述
设计构想
{generating ? : }
{generating ? "神工演算中" : "造化生图"}
imgUrl && onShowFull(imgUrl)}
>
{!imgUrl && !generating && (
)}
{generating && (
)}
{imgUrl && !generating && (
)}
);
}
function ModuleSeal({ onShowFull }) {
const initialData = { content: '金石为开', material: SEAL_MATERIALS[0].id, shape: '正方形', font: SEAL_FONTS[0].id, intent: '' };
const [data, setData] = useState(initialData);
const [generating, setGenerating] = useState(false);
const [results, setResults] = useState(null);
const handleReset = () => { setData(initialData); setResults(null); };
const handleGenerate = async () => {
setGenerating(true);
const material = SEAL_MATERIALS.find(m => m.id === data.material);
const font = SEAL_FONTS.find(f => f.id === data.font);
// Shared stone visual identity for consistency
const stoneIdentity = `${material.texture}, unique stone patterns, consistent color palette, professional macro photography.`;
// Side View Prompt
const sidePrompt = `Extreme macro photography of a Chinese stone seal (SIDE VIEW).
Material: ${stoneIdentity}
Overall Shape: A ${data.shape} pillar stone seal.
Design Intent: ${data.intent || 'Simple classic plain style'}.
The base is clean and shows the exact same stone material as the body.
Lighting: Studio lighting, sharp details of stone grain and polished surface. No text on this side view. Dark background.`;
// Bottom View Prompt
const bottomPrompt = `Extreme macro photography of the EXACT BOTTOM BASE of the seal mentioned above.
Material: ${stoneIdentity}
The flat ${data.shape} base shows physically carved Chinese characters "${data.content}" in ${font.style}.
The carving depth is visible with sharp stone-to-stone edges, showing the raw stone grain inside the carved grooves.
No ink, no paper, just the physical stone carving. Perfectly centered view from bottom-up.`;
const [sideUrl, bottomUrl] = await Promise.all([
generateNanoBananaImage(sidePrompt, "1:1"),
generateNanoBananaImage(bottomPrompt, "1:1")
]);
if (sideUrl && bottomUrl) setResults({ side: sideUrl, bottom: bottomUrl });
setGenerating(false);
};
return (
方寸金石
PRECISION SEAL CARVING
重置勒石
印文内容
setData({...data, content: e.target.value.slice(0, 4)})}
className="w-full bg-[#080807] border border-[#2d2a20] p-4 text-2xl tracking-[0.5em] text-[#f2f2ed] focus:border-[#c2a47a/50] outline-none text-center"
placeholder="四字以内"
/>
材质
{SEAL_MATERIALS.map(m => (
setData({...data, material: m.id})}
className={`p-3 text-[10px] border transition-all flex items-center gap-2 ${data.material === m.id ? 'bg-[#c2a47a10] border-[#c2a47a] text-[#c2a47a]' : 'border-[#2d2a20] text-[#63635e] hover:border-[#4d4d4a]'}`}
>
{m.name}
))}
书体
{SEAL_FONTS.map(f => (
setData({...data, font: f.id})}
className={`p-3 text-[10px] border transition-all ${data.font === f.id ? 'bg-[#c2a47a10] border-[#c2a47a] text-[#c2a47a]' : 'border-[#2d2a20] text-[#63635e] hover:border-[#4d4d4a]'}`}
>
{f.name}
))}
形状
{['正方形', '长方形', '椭圆形'].map(s => (
setData({...data, shape: s})}
className={`flex-1 py-3 text-[10px] border transition-all ${data.shape === s ? 'bg-[#c2a47a10] border-[#c2a47a] text-[#c2a47a]' : 'border-[#2d2a20] text-[#63635e] hover:border-[#4d4d4a]'}`}
>
{s}
))}
意境构思
{generating ? : }
{generating ? "勒石刻金中" : "勒石印金"}
{/* Side View Result */}
results?.side && onShowFull(results.side)}
>
侧部预览 · 材质造型
{!results && !generating && (
)}
{generating && (
实体演算
)}
{results && !generating && (
查看大图
)}
{/* Bottom View Result */}
results?.bottom && onShowFull(results.bottom)}
>
底部视角 · 真实刻痕
{!results && !generating && (
)}
{generating && (
刻凿模拟
)}
{results && !generating && (
查看大图
)}
);
}