Loading...
Loading...
Compare original and translation side by side
| Purpose | Complexity | Dependencies | Example |
|---|---|---|---|
| Static demo | Low | None | Product mockup, landing page |
| Interactive widget | Medium | None or Alpine.js | Calculator, form builder |
| Data visualization | Medium-High | D3.js or Chart.js | Dashboard, chart explorer |
| Prototype | Medium | Alpine.js or Petite-Vue | Clickable UI prototype |
| Utility tool | Medium-High | Varies | JSON formatter, color picker |
| Generative art | Medium | None | Canvas animation, pattern generator |
| Presentation | Medium | None or Mermaid | Slide deck, diagram viewer |
| 用途 | 复杂度 | 依赖 | 示例 |
|---|---|---|---|
| 静态演示 | 低 | 无 | 产品模型、落地页 |
| 交互组件 | 中等 | 无或Alpine.js | 计算器、表单生成器 |
| 数据可视化 | 中高 | D3.js或Chart.js | 仪表盘、图表浏览器 |
| 原型 | 中等 | Alpine.js或Petite-Vue | 可点击UI原型 |
| 实用工具 | 中高 | 依场景而定 | JSON格式化工具、拾色器 |
| 生成艺术 | 中等 | 无 | Canvas动画、图案生成器 |
| 演示文稿 | 中等 | 无或Mermaid | 幻灯片、图表查看器 |
| Constraint | Single-File | Multi-File |
|---|---|---|
| Easy sharing (email, paste) | Yes | No |
| File size < 100KB | Yes | Either |
| Multiple pages/views | Possible (SPA) | Better |
| Team collaboration | Difficult | Better |
| Offline use | Yes (self-contained) | Needs bundling |
| SEO requirements | N/A | N/A (artifacts are tools) |
| 约束条件 | 单文件 | 多文件 |
|---|---|---|
| 易于分享(邮件、粘贴) | 是 | 否 |
| 文件大小 < 100KB | 是 | 均可 |
| 多页面/多视图 | 可实现(SPA) | 更适合 |
| 团队协作 | 难度高 | 更适合 |
| 离线使用 | 是(自包含) | 需要打包 |
| SEO要求 | 不适用 | 不适用(产出物为工具类) |
| Need | Recommended | CDN URL | Size |
|---|---|---|---|
| Lightweight reactivity | Alpine.js | | ~15KB |
| Minimal Vue-like | Petite-Vue | | ~6KB |
| Charts | Chart.js | | ~65KB |
| Data visualization | D3.js | | ~90KB |
| Diagrams | Mermaid | | ~120KB |
| CSS framework (proto) | Tailwind Play CDN | | Runtime |
| Icons | Lucide | | On-demand |
| No dependency needed | Vanilla JS | N/A | 0KB |
| 需求 | 推荐方案 | CDN URL | 大小 |
|---|---|---|---|
| 轻量级响应式 | Alpine.js | | ~15KB |
| 类Vue的轻量方案 | Petite-Vue | | ~6KB |
| 图表 | Chart.js | | ~65KB |
| 数据可视化 | D3.js | | ~90KB |
| 流程图/图表 | Mermaid | | ~120KB |
| CSS框架(原型用) | Tailwind Play CDN | | 运行时加载 |
| 图标 | Lucide | | 按需加载 |
| 无需依赖 | Vanilla JS | N/A | 0KB |
| Rule | Rationale |
|---|---|
Pin to major version ( | Prevent breaking changes |
| Maximum 3 CDN dependencies | Keep artifacts lightweight |
Add | Security against CDN compromise |
| Provide graceful degradation | Work if CDN fails |
| Prefer smaller alternatives | Alpine over React, Petite-Vue over Vue |
| 规则 | 原因 |
|---|---|
固定主版本号( | 避免出现破坏性变更 |
| 最多使用3个CDN依赖 | 保持产出物轻量 |
添加 | 防范CDN被篡改的安全风险 |
| 提供优雅降级方案 | CDN加载失败时仍可正常运行 |
| 优先选择更小的替代方案 | 优先用Alpine而非React,用Petite-Vue而非Vue |
<style><style><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>[Artifact Title]</title>
<style>
/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Design Tokens */
:root {
--color-bg: #ffffff;
--color-text: #1a1a2e;
--color-primary: #3b82f6;
--color-border: #e2e8f0;
--radius: 0.5rem;
--space: 1rem;
--font: system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
:root {
--color-bg: #0f172a;
--color-text: #e2e8f0;
--color-primary: #60a5fa;
--color-border: #334155;
}
}
/* Base Styles */
body {
font-family: var(--font);
background: var(--color-bg);
color: var(--color-text);
line-height: 1.6;
}
/* Component Styles */
/* ... */
</style>
</head>
<body>
<!-- Semantic HTML content -->
<script>
// Application logic
(function() {
'use strict';
// ...
})();
</script>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>[Artifact Title]</title>
<style>
/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Design Tokens */
:root {
--color-bg: #ffffff;
--color-text: #1a1a2e;
--color-primary: #3b82f6;
--color-border: #e2e8f0;
--radius: 0.5rem;
--space: 1rem;
--font: system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
:root {
--color-bg: #0f172a;
--color-text: #e2e8f0;
--color-primary: #60a5fa;
--color-border: #334155;
}
}
/* Base Styles */
body {
font-family: var(--font);
background: var(--color-bg);
color: var(--color-text);
line-height: 1.6;
}
/* Component Styles */
/* ... */
</style>
</head>
<body>
<!-- Semantic HTML content -->
<script>
// Application logic
(function() {
'use strict';
// ...
})();
</script>
</body>
</html>.container {
width: min(100% - 2rem, 1200px);
margin-inline: auto;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
gap: var(--space);
}.container {
width: min(100% - 2rem, 1200px);
margin-inline: auto;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
gap: var(--space);
}/* Base: mobile */
.layout { display: flex; flex-direction: column; }
/* Tablet and up */
@media (min-width: 768px) {
.layout { flex-direction: row; }
.sidebar { width: 280px; flex-shrink: 0; }
}/* Base: mobile */
.layout { display: flex; flex-direction: column; }
/* Tablet and up */
@media (min-width: 768px) {
.layout { flex-direction: row; }
.sidebar { width: 280px; flex-shrink: 0; }
}| Layer | Purpose | Requirement |
|---|---|---|
| HTML | Content accessible and meaningful | Works without CSS or JS |
| CSS | Visual presentation and layout | Works without JS |
| JavaScript | Enhanced interactivity | Adds dynamic behavior |
| 层级 | 用途 | 要求 |
|---|---|---|
| HTML | 内容可访问、有意义 | 无CSS或JS时仍可正常使用 |
| CSS | 视觉呈现和布局 | 无JS时仍可正常使用 |
| JavaScript | 增强交互能力 | 添加动态行为 |
// Check before using modern APIs
if ('IntersectionObserver' in window) {
// Use lazy loading
} else {
// Load all images immediately
}
if (CSS.supports('backdrop-filter', 'blur(10px)')) {
element.classList.add('glass-effect');
}// Check before using modern APIs
if ('IntersectionObserver' in window) {
// Use lazy loading
} else {
// Load all images immediately
}
if (CSS.supports('backdrop-filter', 'blur(10px)')) {
element.classList.add('glass-effect');
}function createStore(initialState) {
let state = { ...initialState };
const listeners = new Set();
return {
getState: () => ({ ...state }),
setState(updates) {
state = { ...state, ...updates };
listeners.forEach(fn => fn(state));
},
subscribe(fn) {
listeners.add(fn);
return () => listeners.delete(fn);
},
};
}function createStore(initialState) {
let state = { ...initialState };
const listeners = new Set();
return {
getState: () => ({ ...state }),
setState(updates) {
state = { ...state, ...updates };
listeners.forEach(fn => fn(state));
},
subscribe(fn) {
listeners.add(fn);
return () => listeners.delete(fn);
},
};
}function syncStateWithURL(store) {
const params = new URLSearchParams(location.search);
for (const [key, value] of params) {
store.setState({ [key]: JSON.parse(value) });
}
store.subscribe(state => {
const params = new URLSearchParams();
Object.entries(state).forEach(([k, v]) => params.set(k, JSON.stringify(v)));
history.replaceState(null, '', `?${params}`);
});
}function syncStateWithURL(store) {
const params = new URLSearchParams(location.search);
for (const [key, value] of params) {
store.setState({ [key]: JSON.parse(value) });
}
store.subscribe(state => {
const params = new URLSearchParams();
Object.entries(state).forEach(([k, v]) => params.set(k, JSON.stringify(v)));
history.replaceState(null, '', `?${params}`);
});
}| Format | Use Case | Method |
|---|---|---|
| Single HTML file | Sharing, embedding | Self-contained |
| HTML + assets | Complex artifacts | Separate CSS/JS files |
| Data URL | Inline embedding | |
| Screenshot/PNG | Documentation | |
| Print/report | |
| 格式 | 使用场景 | 实现方式 |
|---|---|---|
| 单HTML文件 | 分享、嵌入 | 自包含 |
| HTML + 资源文件 | 复杂产出物 | 分离CSS/JS文件 |
| Data URL | 内联嵌入 | |
| 截图/PNG | 文档 | |
| 打印/报告 | 搭配打印样式使用 |
<!DOCTYPE html>langprefers-color-scheme<!DOCTYPE html>langprefers-color-scheme| Anti-Pattern | Why It Is Wrong | What to Do Instead |
|---|---|---|
| React/Vue/Angular in single-file artifact | Massive overhead for simple interactions | Use Alpine.js or vanilla JS |
| Heavy framework from CDN for simple UI | Slow load, wasted bandwidth | Match dependency weight to need |
| Inline styles instead of CSS custom properties | Cannot theme, cannot dark-mode | Use CSS custom properties (tokens) |
| No error handling on user input | Crashes on bad input | Validate and provide feedback |
| Fixed pixel dimensions | Breaks on mobile, tablets | Use responsive units (%, rem, vw) |
Missing | Mobile renders desktop-zoomed | Always include viewport meta tag |
Blocking | Delays page rendering | Use |
| No IIFE wrapper for script | Global scope pollution | Wrap in |
| Hardcoded colors without tokens | Cannot switch themes | Use CSS custom properties |
| 反模式 | 错误原因 | 替代方案 |
|---|---|---|
| 在单文件产出物中使用React/Vue/Angular | 简单交互的开销过大 | 使用Alpine.js或Vanilla JS |
| 为简单UI从CDN引入重型框架 | 加载慢、浪费带宽 | 依赖权重匹配需求 |
| 用内联样式代替CSS自定义属性 | 无法实现主题切换、无法适配深色模式 | 使用CSS自定义属性(设计令牌) |
| 未对用户输入做错误处理 | 输入异常时会崩溃 | 做校验并给出反馈 |
| 固定像素尺寸 | 在手机、平板上显示异常 | 使用响应式单位(%、rem、vw) |
缺少 | 移动端会以桌面端缩放比例渲染 | 始终添加viewport元标签 |
在 | 延迟页面渲染 | 使用 |
| 脚本未做IIFE包裹 | 污染全局作用域 | 用 |
| 硬编码颜色未使用设计令牌 | 无法切换主题 | 使用CSS自定义属性 |
| Skill | Integration |
|---|---|
| Style selection and UX guidelines |
| Design tokens for consistent theming |
| Canvas/SVG visualizations within artifacts |
| Complex component patterns |
| Mobile-responsive artifact design |
| Artifact scope is defined during planning |
| 技能 | 集成方式 |
|---|---|
| 样式选择和UX规范 |
| 提供设计令牌实现统一主题 |
| 产出物中的Canvas/SVG可视化 |
| 复杂组件模式 |
| 产出物的移动端响应式设计 |
| 产出物范围在规划阶段定义 |