Commit f4ce9222 authored by fisherdaddy's avatar fisherdaddy

chore: 更新名言卡片生成器样式

parent 9d2af22d
import React, { useState, useRef } from 'react'; import React, { useState, useRef } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import html2canvas from 'html2canvas'; import html2canvas from 'html2canvas';
import { useTranslation } from '../js/i18n';
// 更新中文字体数组,包含显示名称和 CSS 字体族名称 // 更新中文字体数组,包含显示名称和 CSS 字体族名称
const chineseFonts = [ const chineseFonts = [
{ name: '系统默认', value: '-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif' }, { name: 'system', value: '-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif' },
{ name: '无衬线', value: '"PingFang SC", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif' }, { name: 'sans', value: '"PingFang SC", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif' },
{ name: '衬线', value: 'Georgia, "Nimbus Roman No9 L", "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "Source Han Serif CN", STSong, "AR PL New Sung", "AR PL SungtiL GB", NSimSun, SimSun, serif' }, { name: 'serif', value: 'Georgia, "Nimbus Roman No9 L", "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "Source Han Serif CN", STSong, "AR PL New Sung", "AR PL SungtiL GB", NSimSun, SimSun, serif' },
{ name: '等宽', value: '"SF Mono", SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, "Noto Sans Mono CJK SC", monospace' }, { name: 'mono', value: '"SF Mono", SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, "Noto Sans Mono CJK SC", monospace' },
]; ];
// 定义可选的英文字体 // 定义可选的英文字体
...@@ -21,10 +22,9 @@ const englishFonts = [ ...@@ -21,10 +22,9 @@ const englishFonts = [
// 定义可选的背景颜色 // 定义可选的背景颜色
const backgroundOptions = [ const backgroundOptions = [
{ name: '白色', value: '#FFFFFF' }, { name: 'white', value: '#FFFFFF' },
{ name: '黑色', value: '#333333' }, // 修改为深灰色 { name: 'dark', value: '#333333' }, // 修改为深灰色
{ name: '黄色纸张', value: '#fdf6e3' }, { name: 'paper', value: '#fdf6e3' },
{ name: '自定义', value: 'custom' },
]; ];
const Container = styled.div` const Container = styled.div`
...@@ -203,6 +203,8 @@ const DownloadButton = styled.button` ...@@ -203,6 +203,8 @@ const DownloadButton = styled.button`
`; `;
function QuoteCard() { function QuoteCard() {
const { t } = useTranslation();
const [chineseText, setChineseText] = useState(''); const [chineseText, setChineseText] = useState('');
const [englishText, setEnglishText] = useState(''); const [englishText, setEnglishText] = useState('');
const [author, setAuthor] = useState(''); const [author, setAuthor] = useState('');
...@@ -242,36 +244,34 @@ function QuoteCard() { ...@@ -242,36 +244,34 @@ function QuoteCard() {
return ( return (
<Container> <Container>
<ContentWrapper> <ContentWrapper>
{/* 左侧输入区域 */}
<InputContainer> <InputContainer>
<TitleLabel>名言卡片生成器</TitleLabel> <TitleLabel>{t('tools.quoteCard.title')}</TitleLabel>
<InputText <InputText
placeholder="请输入中文名人名言" placeholder={t('tools.quoteCard.chinesePlaceholder')}
value={chineseText} value={chineseText}
onChange={(e) => setChineseText(e.target.value)} onChange={(e) => setChineseText(e.target.value)}
/> />
<InputText <InputText
placeholder="请输入英文翻译" placeholder={t('tools.quoteCard.englishPlaceholder')}
value={englishText} value={englishText}
onChange={(e) => setEnglishText(e.target.value)} onChange={(e) => setEnglishText(e.target.value)}
/> />
<InputField <InputField
placeholder="请输入作者姓名" placeholder={t('tools.quoteCard.authorPlaceholder')}
value={author} value={author}
onChange={(e) => setAuthor(e.target.value)} onChange={(e) => setAuthor(e.target.value)}
/> />
{/* 字体选择 */} <Label>{t('tools.quoteCard.selectChineseFont')}:</Label>
<Label>选择中文字体:</Label>
<Select value={chineseFont} onChange={(e) => setChineseFont(e.target.value)}> <Select value={chineseFont} onChange={(e) => setChineseFont(e.target.value)}>
{chineseFonts.map((font) => ( {chineseFonts.map((font) => (
<option key={font.value} value={font.value}> <option key={font.value} value={font.value}>
{font.name} {t(`tools.quoteCard.fonts.${font.name}`)}
</option> </option>
))} ))}
</Select> </Select>
<Label>选择英文字体:</Label> <Label>{t('tools.quoteCard.selectEnglishFont')}:</Label>
<Select value={englishFont} onChange={(e) => setEnglishFont(e.target.value)}> <Select value={englishFont} onChange={(e) => setEnglishFont(e.target.value)}>
{englishFonts.map((font) => ( {englishFonts.map((font) => (
<option key={font.value} value={font.value}> <option key={font.value} value={font.value}>
...@@ -280,70 +280,57 @@ function QuoteCard() { ...@@ -280,70 +280,57 @@ function QuoteCard() {
))} ))}
</Select> </Select>
{/* 字体颜色选择 */} <Label>{t('tools.quoteCard.selectFontColor')}:</Label>
<Label>选择字体颜色:</Label>
<ColorInput <ColorInput
type="color" type="color"
value={fontColor} value={fontColor}
onChange={(e) => setFontColor(e.target.value)} onChange={(e) => setFontColor(e.target.value)}
/> />
{/* 作者颜色选择 */} <Label>{t('tools.quoteCard.selectAuthorColor')}:</Label>
<Label>选择作者颜色:</Label>
<ColorInput <ColorInput
type="color" type="color"
value={authorColor} value={authorColor}
onChange={(e) => setAuthorColor(e.target.value)} onChange={(e) => setAuthorColor(e.target.value)}
/> />
{/* 背景色选择 */} <Label>{t('tools.quoteCard.selectBackground')}:</Label>
<Label>选择背景颜色:</Label>
<Select <Select
value={ value={backgroundOptions.some((option) => option.value === bgColor) ? bgColor : 'custom'}
backgroundOptions.some((option) => option.value === bgColor)
? bgColor
: 'custom'
}
onChange={handleBackgroundChange} onChange={handleBackgroundChange}
> >
{backgroundOptions.map((option) => ( {backgroundOptions.map((option) => (
<option key={option.name} value={option.value}> <option key={option.value} value={option.value}>
{option.name} {t(`tools.quoteCard.backgrounds.${option.name}`)}
</option> </option>
))} ))}
</Select> </Select>
{bgColor === 'custom' && ( {bgColor === 'custom' && (
<> <>
<Label>选择自定义背景颜色:</Label> <Label>{t('tools.quoteCard.customBackground')}:</Label>
<ColorInput <ColorInput
type="color" type="color"
value={customBgColor} value={customBgColor}
onChange={(e) => setBgColor(e.target.value)} onChange={(e) => setBgColor(e.target.value)}
title="选择自定义背景颜色" title={t('tools.quoteCard.customBackground')}
/> />
</> </>
)} )}
{/* 下载按钮 */}
<DownloadButton onClick={handleDownload}> <DownloadButton onClick={handleDownload}>
下载图片 {t('tools.quoteCard.downloadButton')}
</DownloadButton> </DownloadButton>
</InputContainer> </InputContainer>
{/* 右侧预览区域 */} <PreviewContainer $bgColor={bgColor} $fontColor={fontColor} ref={previewRef}>
<PreviewContainer
$bgColor={bgColor}
$fontColor={fontColor}
ref={previewRef}
>
<QuoteText $color={fontColor} $fontFamily={chineseFont}> <QuoteText $color={fontColor} $fontFamily={chineseFont}>
{chineseText || '请输入中文名人名言'} {chineseText || t('tools.quoteCard.defaultQuote')}
</QuoteText> </QuoteText>
<QuoteText $color={fontColor} $fontFamily={englishFont}> <QuoteText $color={fontColor} $fontFamily={englishFont}>
{englishText || 'Enter the English translation here.'} {englishText || t('tools.quoteCard.defaultTranslation')}
</QuoteText> </QuoteText>
<QuoteAuthor $color={authorColor} $fontFamily={englishFont}> <QuoteAuthor $color={authorColor} $fontFamily={englishFont}>
—— {author || '作者姓名'} —— {author || t('tools.quoteCard.defaultAuthor')}
</QuoteAuthor> </QuoteAuthor>
</PreviewContainer> </PreviewContainer>
</ContentWrapper> </ContentWrapper>
......
import React, { useState, useRef, useEffect } from 'react'; import React, { useState, useRef } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { Title, Wrapper, Container, InputText, PreviewContainer, Preview } from '../js/SharedStyles'; import { marked } from 'marked';
import { useTranslation } from '../js/i18n'; import { useTranslation } from '../js/i18n';
import SEO from '../components/SEO'; import SEO from '../components/SEO';
import Marked from 'marked-react';
// 更新预设模板
const templates = [
{
name: 'simple',
bgColor: '#ffffff',
textColor: '#333333',
font: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
padding: '40px'
},
{
name: 'ai-style',
bgColor: 'linear-gradient(135deg, #6366F1 0%, #4F46E5 100%)',
textColor: '#ffffff',
font: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
padding: '40px'
},
{
name: 'dark',
bgColor: '#2d3748',
textColor: '#ffffff',
font: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
padding: '40px'
},
{
name: 'paper',
bgColor: '#fdf6e3',
textColor: '#333333',
font: 'Georgia, "Nimbus Roman No9 L", "Songti SC", serif',
padding: '40px'
},
{
name: 'minimal',
bgColor: '#f8f9fa',
textColor: '#1a1a1a',
font: '-apple-system, "SF Pro Text", sans-serif',
padding: '40px'
},
{
name: 'tech',
bgColor: 'linear-gradient(135deg, #0f172a 0%, #1e293b 100%)',
textColor: '#e2e8f0',
font: '"SF Mono", SFMono-Regular, Consolas, monospace',
padding: '40px'
}
];
const Container = styled.div`
min-height: 100vh;
background: linear-gradient(135deg, #f5f7ff 0%, #ffffff 100%);
padding: 2rem;
position: relative;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background:
linear-gradient(90deg, rgba(99, 102, 241, 0.05) 1px, transparent 1px),
linear-gradient(rgba(99, 102, 241, 0.05) 1px, transparent 1px);
background-size: 20px 20px;
pointer-events: none;
}
`;
const ContentWrapper = styled.div`
display: flex;
gap: 2rem;
max-width: 1400px;
margin: 0 auto;
position: relative;
z-index: 1;
@media (max-width: 768px) {
flex-direction: column;
}
`;
const InputContainer = styled.div`
flex: 1;
background: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(10px);
border-radius: 16px;
padding: 1.5rem;
box-shadow: 0 8px 32px rgba(99, 102, 241, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
display: flex;
flex-direction: column;
gap: 1rem;
`;
const TitleLabel = styled.h2`
font-size: 1.8rem;
margin-bottom: 1.5rem;
background: linear-gradient(135deg, #6366F1 0%, #4F46E5 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-weight: 700;
letter-spacing: -0.02em;
`;
const Section = styled.div`
display: flex;
flex-direction: column;
gap: 0.5rem;
`;
const Label = styled.label`
font-size: 1rem;
color: #333333;
`;
const TemplateGrid = styled.div`
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
`;
const TemplateItem = styled.button`
padding: 0.5rem 1rem;
background: ${props => props.selected ?
'linear-gradient(135deg, #6366F1 0%, #4F46E5 100%)' :
'rgba(255, 255, 255, 0.8)'
};
color: ${props => props.selected ? '#ffffff' : '#333333'};
border: 2px solid ${props => props.selected ? '#4F46E5' : 'rgba(99, 102, 241, 0.1)'};
border-radius: 8px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
&:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
border-color: rgba(99, 102, 241, 0.3);
}
${props => props.selected && `
&::after {
content: '✓';
position: absolute;
top: 4px;
right: 4px;
font-size: 12px;
color: #ffffff;
}
`}
`;
const MarkdownEditor = styled.textarea`
width: 100%;
height: 100px;
padding: 0.5rem;
border: 1px solid #dadce0;
border-radius: 4px;
font-size: 16px;
color: #333333;
resize: vertical;
`;
const DownloadButton = styled.button` const DownloadButton = styled.button`
padding: 8px 16px; background: linear-gradient(135deg, #6366F1 0%, #4F46E5 100%);
background-color: #3498db;
color: white; color: white;
border: none; border: none;
border-radius: 4px; padding: 1rem;
border-radius: 8px;
font-weight: 600;
cursor: pointer; cursor: pointer;
font-size: 14px; transition: all 0.3s ease;
transition: background-color 0.3s ease;
align-self: flex-end; align-self: flex-end;
margin-top: 10px; margin-top: 1rem;
&:hover { &:hover {
background-color: #2980b9; transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
} }
`; `;
const PreviewContainer = styled.div`
flex: 1;
background: ${(props) => props.bgColor || '#ffffff'};
padding: 2rem;
border-radius: 16px;
box-shadow: 0 8px 32px rgba(99, 102, 241, 0.1);
border: 1px solid rgba(99, 102, 241, 0.1);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 200px;
height: fit-content;
align-self: flex-start;
transition: all 0.3s ease;
margin-top: 1rem;
width: 100%;
&:hover {
transform: translateY(-5px);
box-shadow: 0 12px 24px rgba(99, 102, 241, 0.15);
}
@media (max-width: 768px) {
margin-top: 2rem;
width: 100%;
}
`;
const Preview = styled.div`
font-size: clamp(16px, 2.5vw, 24px);
margin-bottom: 16px;
color: ${(props) => props.$color || '#333333'};
text-align: center;
line-height: 1.5;
font-family: ${(props) => props.$fontFamily || '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'};
white-space: pre-wrap;
word-wrap: break-word;
width: 100%;
`;
function TextToImage() { function TextToImage() {
const { t } = useTranslation(); const { t } = useTranslation();
const [text, setText] = useState(''); const [text, setText] = useState('');
const [selectedTemplate, setSelectedTemplate] = useState(templates[0]);
const previewRef = useRef(null); const previewRef = useRef(null);
const formatText = (text) => { const formatText = (text) => {
return text return marked.parse(text, {
.replace(/^### (.*$)/gim, '<h4>$1</h4>') breaks: true,
.replace(/^## (.*$)/gim, '<h3>$1</h3>') gfm: true
.replace(/^# (.*$)/gim, '<h2>$1</h2>') });
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\n{2,}/g, '<br/><br/>')
.replace(/\n/g, '<br/>');
}; };
const handleDownload = async () => { const handleDownload = async () => {
...@@ -74,25 +280,64 @@ function TextToImage() { ...@@ -74,25 +280,64 @@ function TextToImage() {
title={t('tools.text2image.title')} title={t('tools.text2image.title')}
description={t('tools.text2image.description')} description={t('tools.text2image.description')}
/> />
<Wrapper>
<Title>{t('tools.text2image.title')}</Title>
<Container> <Container>
<InputText
placeholder={t('tools.text2image.inputPlaceholder')} <ContentWrapper>
<InputContainer>
<TitleLabel>{t('tools.text2image.title')}</TitleLabel>
{/* 模板选择 */}
<Section>
<Label>{t('tools.text2image.selectTemplate')}</Label>
<TemplateGrid>
{templates.map(template => (
<TemplateItem
key={template.name}
selected={template === selectedTemplate}
onClick={() => setSelectedTemplate(template)}
background={template.bgColor}
color={template.textColor}
>
{t(`tools.text2image.templates.${template.name}`)}
</TemplateItem>
))}
</TemplateGrid>
</Section>
{/* Markdown 编辑器 */}
<Section>
<Label>{t('tools.text2image.inputLabel')}</Label>
<MarkdownEditor
value={text} value={text}
onChange={(e) => setText(e.target.value)} onChange={(e) => setText(e.target.value)}
placeholder={t('tools.text2image.placeholder')}
/> />
<PreviewContainer> </Section>
<Preview
ref={previewRef}
dangerouslySetInnerHTML={{ __html: formatText(text) }}
/>
<DownloadButton onClick={handleDownload}> <DownloadButton onClick={handleDownload}>
{t('tools.text2image.downloadButton')} {t('tools.text2image.downloadButton')}
</DownloadButton> </DownloadButton>
</InputContainer>
<PreviewContainer
ref={previewRef}
bgColor={selectedTemplate.bgColor}
>
<div
style={{
padding: selectedTemplate.padding,
color: selectedTemplate.textColor,
fontFamily: selectedTemplate.font,
width: '100%'
}}
>
<Marked>
{text || t('tools.text2image.previewDefault')}
</Marked>
</div>
</PreviewContainer> </PreviewContainer>
</ContentWrapper>
</Container> </Container>
</Wrapper>
</> </>
); );
} }
......
This diff is collapsed.
...@@ -5,7 +5,7 @@ import SEO from '../components/SEO'; ...@@ -5,7 +5,7 @@ import SEO from '../components/SEO';
const tools = [ const tools = [
{ id: 'handwrite', icon: '/assets/icon/handwrite.png', path: '/handwriting' }, { id: 'handwrite', icon: '/assets/icon/handwrite.png', path: '/handwriting' },
{ id: 'quotecard', icon: '/assets/icon/quotecard.png', path: '/quote-card' }, { id: 'quoteCard', icon: '/assets/icon/quotecard.png', path: '/quote-card' },
{ id: 'text2image', icon: '/assets/icon/text2image.png', path: '/text2image' }, { id: 'text2image', icon: '/assets/icon/text2image.png', path: '/text2image' },
{ id: 'jsonFormatter', icon: '/assets/icon/json-format.png', path: '/json-formatter' }, { id: 'jsonFormatter', icon: '/assets/icon/json-format.png', path: '/json-formatter' },
{ id: 'urlEncodeDecode', icon: '/assets/icon/url-endecode.png', path: '/url-encode-and-decode' }, { id: 'urlEncodeDecode', icon: '/assets/icon/url-endecode.png', path: '/url-encode-and-decode' },
......
...@@ -5,7 +5,7 @@ import SEO from '../components/SEO'; ...@@ -5,7 +5,7 @@ import SEO from '../components/SEO';
const tools = [ const tools = [
{ id: 'handwrite', icon: '/assets/icon/handwrite.png', path: '/handwriting' }, { id: 'handwrite', icon: '/assets/icon/handwrite.png', path: '/handwriting' },
{ id: 'quotecard', icon: '/assets/icon/quotecard.png', path: '/quote-card' }, { id: 'quoteCard', icon: '/assets/icon/quotecard.png', path: '/quote-card' },
{ id: 'text2image', icon: '/assets/icon/text2image.png', path: '/text2image' }, { id: 'text2image', icon: '/assets/icon/text2image.png', path: '/text2image' },
]; ];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment