"添加前端模板和运行代码模块"

This commit is contained in:
Codex
2026-06-01 13:43:09 +08:00
parent 24045274ad
commit 8092c4b1f8
587 changed files with 99761 additions and 0 deletions

View File

@@ -0,0 +1,473 @@
/* 全局样式重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.App {
min-height: 100vh;
color: #333;
}
/* 头部样式 */
.main-header {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
padding: 1rem 2rem;
box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
position: sticky;
top: 0;
z-index: 100;
}
.main-header .title {
font-size: 1.5rem;
font-weight: 700;
color: #4a5568;
margin-bottom: 0.5rem;
}
.navigation .nav-list {
display: flex;
list-style: none;
gap: 2rem;
}
.nav-link {
text-decoration: none;
color: #4a5568;
font-weight: 500;
transition: color 0.3s ease;
}
.nav-link:hover {
color: #667eea;
}
/* 主要内容区域 */
.main-content {
padding: 2rem;
max-width: 1200px;
margin: 0 auto;
}
/* 英雄区域 */
.hero-section {
text-align: center;
padding: 4rem 0;
margin-bottom: 3rem;
}
.hero-content {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
border-radius: 20px;
padding: 3rem;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.hero-title {
font-size: 3rem;
font-weight: 800;
color: white;
margin-bottom: 1.5rem;
text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}
.hero-description {
font-size: 1.2rem;
color: rgba(255, 255, 255, 0.9);
margin-bottom: 2rem;
line-height: 1.6;
}
.hero-buttons {
display: flex;
gap: 1rem;
justify-content: center;
flex-wrap: wrap;
}
.hero-btn {
padding: 0.75rem 2rem;
border: none;
border-radius: 50px;
font-weight: 600;
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-block;
}
.hero-btn.primary {
background: linear-gradient(45deg, #ff6b6b, #ee5a24);
color: white;
box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}
.hero-btn.secondary {
background: rgba(255, 255, 255, 0.2);
color: white;
border: 2px solid rgba(255, 255, 255, 0.3);
}
.hero-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
/* 计数器组件 */
.counter-container {
background: white;
border-radius: 15px;
padding: 2rem;
margin: 2rem 0;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
text-align: center;
}
.counter-container h2 {
margin-bottom: 1.5rem;
color: #4a5568;
}
.counter-display {
font-size: 2rem;
font-weight: 700;
color: #667eea;
margin-bottom: 2rem;
padding: 1rem;
background: #f7fafc;
border-radius: 10px;
}
.counter-buttons {
display: flex;
gap: 1rem;
justify-content: center;
flex-wrap: wrap;
}
.counter-btn {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 10px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
min-width: 80px;
}
.counter-btn.increment {
background: linear-gradient(45deg, #48bb78, #38a169);
color: white;
}
.counter-btn.decrement {
background: linear-gradient(45deg, #f56565, #e53e3e);
color: white;
}
.counter-btn.reset {
background: linear-gradient(45deg, #a0aec0, #718096);
color: white;
}
.counter-btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
/* 特性区域 */
.features-section {
margin: 3rem 0;
}
.section-title {
text-align: center;
font-size: 2.5rem;
font-weight: 700;
color: white;
margin-bottom: 3rem;
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
padding: 0 1rem;
}
.feature-card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
border-radius: 15px;
padding: 2rem;
text-align: center;
border: 1px solid rgba(255, 255, 255, 0.2);
transition: all 0.3s ease;
}
.feature-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
background: rgba(255, 255, 255, 0.15);
}
.feature-icon {
font-size: 3rem;
margin-bottom: 1rem;
}
.feature-title {
font-size: 1.5rem;
font-weight: 600;
color: white;
margin-bottom: 1rem;
}
.feature-description {
color: rgba(255, 255, 255, 0.9);
line-height: 1.6;
}
/* 动态内容区域 */
.dynamic-section {
background: white;
border-radius: 15px;
padding: 2rem;
margin: 2rem 0;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}
.dynamic-controls {
display: flex;
gap: 1rem;
margin-bottom: 2rem;
flex-wrap: wrap;
}
.toggle-btn, .add-item-btn {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 10px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.toggle-btn {
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
}
.add-item-btn {
background: linear-gradient(45deg, #48bb78, #38a169);
color: white;
}
.dynamic-content {
animation: fadeIn 0.3s ease-in;
}
.items-list {
list-style: none;
}
.list-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem 1rem;
margin-bottom: 0.5rem;
background: #f7fafc;
border-radius: 8px;
border-left: 4px solid #667eea;
}
.item-text {
font-weight: 500;
}
.remove-btn {
background: #f56565;
color: white;
border: none;
border-radius: 50%;
width: 24px;
height: 24px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease;
}
.remove-btn:hover {
background: #e53e3e;
transform: scale(1.1);
}
/* 表单区域 */
.form-section {
background: white;
border-radius: 15px;
padding: 2rem;
margin: 2rem 0;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}
.contact-form {
max-width: 500px;
margin: 0 auto;
}
.form-group {
margin-bottom: 1.5rem;
}
.form-label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
color: #4a5568;
}
.form-input, .form-textarea {
width: 100%;
padding: 0.75rem;
border: 2px solid #e2e8f0;
border-radius: 8px;
font-size: 1rem;
transition: border-color 0.3s ease;
font-family: inherit;
}
.form-input:focus, .form-textarea:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.form-textarea {
resize: vertical;
min-height: 100px;
}
.submit-btn {
width: 100%;
padding: 0.75rem;
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.submit-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
/* 页脚 */
.main-footer {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
text-align: center;
padding: 2rem;
color: white;
border-top: 1px solid rgba(255, 255, 255, 0.2);
}
/* 动画 */
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* 响应式设计 */
@media (max-width: 768px) {
.main-content {
padding: 1rem;
}
.hero-title {
font-size: 2rem;
}
.hero-content {
padding: 2rem 1rem;
}
.hero-buttons {
flex-direction: column;
align-items: center;
}
.hero-btn {
width: 200px;
}
.features-grid {
grid-template-columns: 1fr;
gap: 1rem;
}
.counter-buttons {
flex-direction: column;
align-items: center;
}
.dynamic-controls {
flex-direction: column;
}
.navigation .nav-list {
flex-direction: column;
gap: 0.5rem;
}
}
/* 设计模式高亮样式(当启用设计模式时显示) */
[data-source-info]:hover {
outline: 2px dashed #667eea !important;
outline-offset: 2px !important;
cursor: pointer !important;
position: relative !important;
}
[data-source-info]:hover::after {
content: attr(data-source-info);
position: absolute;
bottom: 100%;
left: 0;
background: #333;
color: white;
padding: 0.5rem;
border-radius: 4px;
font-size: 0.8rem;
white-space: nowrap;
z-index: 1000;
opacity: 0;
animation: fadeIn 0.3s ease-in forwards;
}

View File

@@ -0,0 +1,310 @@
import React, { useState } from 'react';
import './App.css';
// 函数组件示例
function HeaderComponent() {
return (
<header className='main-header' data-component='header'>
<h1 className='title' data-element='main-title'>
Vite Design Mode Plugin Demo
</h1>
<nav className='navigation' data-component='nav'>
<ul className='nav-list'>
<li>
<a href='#features' className='nav-link'>
Features
</a>
</li>
<li>
<a href='#examples' className='nav-link'>
Examples
</a>
</li>
<li>
<a href='#docs' className='nav-link'>
Documentation
</a>
</li>
</ul>
</nav>
</header>
);
}
// 类组件示例
class CounterComponent extends React.Component<{ initial?: number }> {
state = {
count: this.props.initial || 0,
};
render() {
return (
<div className='counter-container' data-component='counter'>
<h2 data-element='counter-title'></h2>
<div className='counter-display'>
<span className='counter-value' data-element='counter-value'>
: {this.state.count}
</span>
</div>
<div className='counter-buttons'>
<button
className='counter-btn increment'
onClick={() => this.setState({ count: this.state.count + 1 })}
data-action='increment'
>
+1
</button>
<button
className='counter-btn decrement'
onClick={() => this.setState({ count: this.state.count - 1 })}
data-action='decrement'
>
-1
</button>
<button
className='counter-btn reset'
onClick={() => this.setState({ count: 0 })}
data-action='reset'
>
</button>
</div>
</div>
);
}
}
// 复杂嵌套组件示例
function FeatureSection() {
const features = [
{
id: 'source-mapping',
title: '源码映射',
description: '自动注入源码位置信息到DOM元素',
icon: '🗺️',
},
{
id: 'ast-analysis',
title: 'AST分析',
description: '基于Babel AST的精确组件识别',
icon: '🔍',
},
{
id: 'hot-reload',
title: '热更新',
description: '与Vite开发服务器无缝集成',
icon: '⚡',
},
];
return (
<section className='features-section' data-section='features'>
<h2 className='section-title' data-element='section-title'>
</h2>
<div className='features-grid'>
{features.map(feature => (
<div
key={feature.id}
className='feature-card'
data-feature={feature.id}
>
<div className='feature-icon' data-element='feature-icon'>
{feature.icon}
</div>
<h3 className='feature-title' data-element='feature-title'>
{feature.title}
</h3>
<p
className='feature-description'
data-element='feature-description'
>
{feature.description}
</p>
</div>
))}
</div>
</section>
);
}
// 动态内容示例
function DynamicContent() {
const [isVisible, setIsVisible] = useState(false);
const [items, setItems] = useState(['项目1', '项目2', '项目3']);
return (
<div className='dynamic-section' data-section='dynamic'>
<h2 className='section-title' data-element='dynamic-title'>
</h2>
<div className='dynamic-controls'>
<button
className='toggle-btn'
onClick={() => setIsVisible(!isVisible)}
data-action='toggle-visibility'
>
{isVisible ? '隐藏' : '显示'}
</button>
<button
className='add-item-btn'
onClick={() => setItems([...items, `项目${items.length + 1}`])}
data-action='add-item'
>
</button>
</div>
{isVisible && (
<div className='dynamic-content' data-element='dynamic-list'>
<ul className='items-list'>
{items.map((item, index) => (
<li key={index} className='list-item' data-item={index}>
<span className='item-text'>{item}</span>
<button
className='remove-btn'
onClick={() => setItems(items.filter((_, i) => i !== index))}
data-action='remove-item'
>
×
</button>
</li>
))}
</ul>
</div>
)}
</div>
);
}
// 表单组件示例
function ContactForm() {
const [formData, setFormData] = useState({
name: '',
email: '',
message: '',
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
alert(`表单提交成功!\n姓名: ${formData.name}\n邮箱: ${formData.email}`);
};
const handleChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => {
setFormData({
...formData,
[e.target.name]: e.target.value,
});
};
return (
<section className='form-section' data-section='contact'>
<h2 className='section-title' data-element='form-title'>
</h2>
<form
className='contact-form'
onSubmit={handleSubmit}
data-form='contact'
>
<div className='form-group'>
<label htmlFor='name' className='form-label'>
</label>
<input
type='text'
id='name'
name='name'
value={formData.name}
onChange={handleChange}
className='form-input'
data-element='name-input'
required
/>
</div>
<div className='form-group'>
<label htmlFor='email' className='form-label'>
</label>
<input
type='email'
id='email'
name='email'
value={formData.email}
onChange={handleChange}
className='form-input'
data-element='email-input'
required
/>
</div>
<div className='form-group'>
<label htmlFor='message' className='form-label'>
</label>
<textarea
id='message'
name='message'
value={formData.message}
onChange={handleChange}
className='form-textarea'
data-element='message-textarea'
rows={4}
required
/>
</div>
<button type='submit' className='submit-btn' data-action='submit-form'>
</button>
</form>
</section>
);
}
// 主应用组件
function App() {
return (
<div className='App' data-appdev-component='App'>
<HeaderComponent />
<main className='main-content'>
<section className='hero-section' data-section='hero'>
<div className='hero-content'>
<h1 className='hero-title' data-element='hero-title'>
Vite Plugin AppDev Design Mode
</h1>
<p className='hero-description' data-element='hero-description'>
Vite插件React开发者提供源码映射和可视化编辑功能
</p>
<div className='hero-buttons'>
<button className='hero-btn primary' data-action='get-started'>
使
</button>
<button className='hero-btn secondary' data-action='view-docs'>
</button>
</div>
</div>
</section>
<CounterComponent initial={5} />
<FeatureSection />
<DynamicContent />
<ContactForm />
</main>
<footer className='main-footer' data-component='footer'>
<p className='footer-text' data-element='footer-text'>
© 2024 Vite Plugin AppDev Design Mode. All rights reserved.
</p>
</footer>
</div>
);
}
export default App;

View File

@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);