create-canvas

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create canvas

创建画布

Build a freeform workspace for exploration and iteration through conversation. The model changes content in source files. The canvas makes that content live, named, movable, and easy to reference.
通过对话构建用于探索和迭代的自由形式工作区。模型通过修改源文件来变更内容。画布让这些内容具备实时呈现、可命名、可移动且易于引用的特性。

Start with the project

从项目开始

  • Read repository rules, routes, component APIs, themes, design tokens, and tests.
  • Look for an existing canvas before creating another.
  • Use the project's framework, components, typography, design tokens, themes, and access controls.
  • Respect restrictions on edits, commands, and browser access.
  • Ask before changing scope, adding dependencies, changing shared code, or exposing the canvas publicly.
  • If safe isolation is unclear, ask before proceeding. Never mount an unsafe preview.
  • Choose sensible defaults for other decisions. Do not ask the user to repeat clear requests.
  • Keep canvas code together. Separate camera and placement logic from previews, test data, and their registry. Do not build a framework.
  • Start with one safe live preview, a readable label, and a separate move handle. Make sure that it mounts.
  • Add the registry and requested content next. Then add copying, camera controls, existing themes, and saved layout.
  • 阅读仓库规则、路由、组件 API、主题、设计令牌和测试。
  • 创建另一个画布前,先查找是否已有可用的 Canvas。
  • 使用项目的框架、组件、排版、设计令牌、主题和访问控制。
  • 遵守针对编辑、命令执行和浏览器访问的限制。
  • 更改范围、添加依赖项、修改共享代码或公开 Canvas 前,先征求同意。
  • 如果安全隔离不明确,先询问后再继续。绝不挂载不安全的预览。
  • 其他决策采用合理默认值。不要要求用户重复已经明确说明的请求。
  • 将 Canvas 代码集中在一起。将相机和放置逻辑与预览、测试数据及其注册表分离。不要构建框架。
  • 从一个安全的实时预览、可读的标签和独立的移动句柄开始。确保它能够成功挂载。
  • 接下来添加注册表和请求的内容。然后添加复制、相机控制、现有主题和布局保存功能。

Keep content in source

将内容保留在源代码中

A registry is a typed list of canvas items. Each entry defines a stable ID, unique readable name, component, safe test data, initial position, and dimensions.
  • Keep the registry easy to find. Adding an item must not require changes to the camera or gesture code.
  • Add, duplicate, rename, and remove items through source edits. Do not add runtime editor controls or delete shortcuts.
  • Keep membership, names, dimensions, and implementations in source. Browser storage must not create or hide items.
  • Never evaluate stored strings or model responses as code at runtime.
  • Update the existing workspace for follow-up requests. Preserve names, IDs, positions, and unrelated experiments.
  • If a reference is ambiguous, ask which item the user means.
  • For “try another version,” preserve the original. Give each variation a new ID, unique readable name, and independent state.
  • For “change this version,” update that item in place. Rename it only when asked.
  • For removal requests, remove only the requested registry entry. Preserve shared components and unrelated work.
  • When comparing one feature, keep other data, content, dimensions, and the global theme the same.
  • For broader alternatives, name the layout differences. Do not create a full variant matrix unless requested.
  • Place additions in nearby empty space using measured bounds. Reveal them with the camera without rearranging existing items or resetting the view.
  • Preserve positions after content expansion, resizing, and reload. Allow intentional overlap. Keep move handles accessible when items overlap.
注册表是一个类型化的 Canvas 项目列表。每个条目定义稳定的 ID、唯一且易读的名称、组件、安全的测试数据、初始位置和尺寸。
  • 让注册表易于查找。添加项目不应要求修改相机或手势代码。
  • 通过源代码修改来添加、复制、重命名和移除项目。不要添加运行时编辑控件或删除快捷键。
  • 将成员关系、名称、尺寸和实现保留在源代码中。浏览器存储不得创建或隐藏项目。
  • 绝不在运行时将存储的字符串或模型响应作为代码求值。
  • 针对后续请求更新现有工作区。保留名称、ID、位置和无关实验。
  • 如果引用存在歧义,询问用户指的是哪个项目。
  • 对于“try another version”,保留原始版本。为每个变体提供新的 ID、唯一且易读的名称以及独立状态。
  • 对于“change this version”,原地更新该项目。除非用户要求,否则不要重命名。
  • 对于移除请求,只移除指定的注册表条目。保留共享组件和无关工作。
  • 比较某项功能时,保持其他数据、内容、尺寸和全局主题不变。
  • 对于更广泛的替代方案,说明布局差异。除非用户要求,否则不要创建完整的变体矩阵。
  • 使用测量所得的边界,将新增项目放在附近的空白区域。通过相机使其显现,不要重新排列现有项目或重置视图。
  • 在内容扩展、调整尺寸和重新加载后保留位置。允许有意重叠。项目重叠时,保持移动句柄可访问。

Keep the workspace quiet

保持工作区简洁

  • Fill the viewport with a plain background, subtle preview boundaries, and minimal fixed controls.
  • Use each preview's intended dimensions. Do not stretch content into oversized frames.
  • Do not add decorative cards, banners, or background patterns.
  • Put each name above its preview, such as
    Pricing card · compact
    . Do not use vague names or opaque IDs as labels.
  • Give the name button behavior without button styling or a separate copy button.
  • Copy the exact name on click, Enter, Space, or touch. Do not copy an ID, code, or URL.
  • Explain copying on hover and keyboard focus. Hover alone must not copy. Touch activation must not require hover.
  • Use the clipboard API when available. Announce brief “Copied” feedback only after success. Keep the name visible during feedback.
  • If clipboard access fails or is unavailable, offer selectable text. Do not crash or claim success.
  • Put a visible move handle beside the label. The label copies without dragging. The handle moves the item, not its body.
  • Convert pointer movement to canvas coordinates at the current zoom.
  • Support keyboard movement on the focused handle. Provide visible focus and accessible instructions.
  • Use
    cursor: default
    on canvas navigation surfaces and handles, including during gestures.
  • Preserve native text, link, input, and resize cursors inside previews. Do not apply cursor rules to all descendants.
  • Include pan, zoom, fit-all, reset-camera, one global theme selector, and saved layout.
  • Use the existing theme API for light, dark, and named themes. Apply the same theme to canvas controls, previews, menus, and dialogs.
  • Do not invent themes or add per-preview themes. If themes are unsupported, omit the selector and explain why.
  • If portal themes fail through public APIs, report the limit.
  • Unless requested, omit resizing, width presets, comparison arrangements, drawing, connectors, catalogs, property editors, multi-selection, snapping, and undo/redo.
  • For requested mobile or desktop previews, define their dimensions in the registry.
  • 使用朴素背景填满视口,配合低调的预览边界和精简的固定控件。
  • 使用每个预览的预期尺寸。不要将内容拉伸到过大的框架中。
  • 不要添加装饰性卡片、横幅或背景图案。
  • 将每个名称放在其预览上方,例如
    Pricing card · compact
    。不要使用模糊名称或不透明的 ID 作为标签。
  • 让名称具备按钮行为,但不添加按钮样式或单独的复制按钮。
  • 点击、按 Enter、按 Space 或触摸时复制完整名称。不要复制 ID、代码或 URL。
  • 在悬停和键盘聚焦时说明复制操作。悬停本身不得触发复制。触摸激活不得依赖悬停。
  • 可用时使用 Clipboard API。仅在成功后显示简短的“已复制”反馈。反馈期间保持名称可见。
  • 如果剪贴板访问失败或不可用,提供可选中的文本。不要崩溃,也不要虚假声称操作成功。
  • 在标签旁放置可见的移动句柄。标签只负责复制,不触发拖动。句柄用于移动项目,而不是其主体。
  • 按当前缩放比例将指针移动转换为 Canvas 坐标。
  • 支持通过聚焦的句柄进行键盘移动。提供可见焦点样式和无障碍说明。
  • 在 Canvas 导航表面和句柄上使用
    cursor: default
    ,包括手势执行期间。
  • 保留预览内部针对文本、链接、输入和调整大小操作的原生光标。不要将光标规则应用于所有后代元素。
  • 包含平移、缩放、全部适配、重置相机、一个全局主题选择器以及布局保存功能。
  • 使用现有主题 API 支持浅色、深色和命名主题。将相同主题应用于 Canvas 控件、预览、菜单和对话框。
  • 不要杜撰主题,也不要添加单个预览专属的主题。如果不支持主题,则省略选择器并说明原因。
  • 如果通过公共 API 无法应用 Portal 主题,应报告该限制。
  • 除非用户要求,否则省略调整尺寸、宽度预设、对比布局、绘图、连接线、目录、属性编辑器、多选、吸附以及撤销/重做功能。
  • 对于要求提供移动端或桌面端预览的情况,在注册表中定义其尺寸。

Preserve live content

保留实时内容

  • Reuse production components through public APIs. Do not change their source, exports, hooks, or styles to support the canvas.
  • Keep production components independent of canvas code.
  • Keep experiments local to the canvas. Move them into production only when asked.
  • Before mounting, use synthetic data, mock services, safe providers, and existing callbacks to prevent real requests and writes.
  • Never use personal data or production credentials.
  • If safe isolation is unavailable, omit the preview and explain why. An iframe or separate document alone does not provide isolation.
  • Preserve clicking, typing, text selection, shortcuts, focus, nested scrolling, and touch input.
  • Preserve the real behavior of disabled and read-only examples.
  • Do not remount previews or erase input when moving items, copying names, changing themes, or changing the camera.
  • Preview drafts do not need to survive reload.
  • Keep portals in their native roots at screen-space size. Let the library manage positioning and modal focus.
  • Use public container APIs only when needed. Make sure that portal alignment and clickable areas work at different zoom levels.
  • If transforms break portals, report the limit or propose a separate preview document.
  • Do not patch libraries, browser APIs, preview DOM, or portal roots.
  • Define navigation in the canvas host, including links in portals. Do not change component links or router internals.
  • Canvas-item links reveal their target instead of scrolling the page.
  • Other navigation must not perform real project actions or silently lose the workspace.
  • 通过公共 API 复用生产组件。不要为了支持 Canvas 而修改其源代码、导出项、Hooks 或样式。
  • 保持生产组件与 Canvas 代码相互独立。
  • 将实验限制在 Canvas 内部。除非用户要求,否则不要将其移入生产环境。
  • 挂载前,使用合成数据、模拟服务、安全 Provider 和现有回调,避免触发真实请求与写入。
  • 绝不使用个人数据或生产凭据。
  • 如果无法实现安全隔离,则省略预览并说明原因。iframe 或单独的 document 本身并不能提供隔离。
  • 保留点击、输入、文本选择、快捷键、焦点、嵌套滚动和触摸输入行为。
  • 保留禁用和只读示例的真实行为。
  • 移动项目、复制名称、切换主题或调整相机时,不要重新挂载预览或清除输入。
  • 预览草稿无需在重新加载后保留。
  • 让 Portal 保持在其原生根节点中,并采用屏幕空间尺寸。由库负责定位和模态焦点管理。
  • 仅在必要时使用公共容器 API。确保 Portal 对齐和可点击区域在不同缩放级别下正常工作。
  • 如果变换破坏 Portal,请报告该限制或提出使用独立预览文档的方案。
  • 不要对库、浏览器 API、预览 DOM 或 Portal 根节点进行补丁式修改。
  • 在 Canvas 宿主中定义导航,包括 Portal 中的链接。不要修改组件链接或 Router 内部实现。
  • Canvas 项目链接应呈现目标内容,而不是滚动页面。
  • 其他导航不得触发真实项目操作,也不得悄然丢失工作区。

Keep gestures separate from preview input

将手势处理与预览输入分离

  • Support mouse drag to pan from empty space.
  • Support Ctrl/Meta + wheel and trackpad pinch to zoom over empty space and previews.
  • Keep the canvas point under the pointer fixed during wheel or pinch zoom.
  • Provide zoom-in and zoom-out buttons and keyboard controls. Center their zoom on the viewport.
  • Zoom smoothly in both directions without jumps or drift. Preserve item positions and preview state.
  • Support touch pan and pinch where the browser permits them.
  • Support keyboard camera navigation when the canvas shell has focus.
  • Show visible keyboard focus on all canvas controls.
  • Keep accessible fit-all and reset-camera controls fixed and reachable when items are offscreen.
  • Run fit-all after layout settles. Fit the actual bounds, including each title, handle, and boundary. Do not rearrange items.
  • Reset only the camera. Preserve membership, positions, themes, and drafts.
  • Support Space + primary-button drag and middle-button drag to pan anywhere on the canvas, including over previews.
  • Give explicit pan gestures priority over item movement and name copying.
  • After a pan, do not activate controls, copy labels, follow links, or trigger middle-click autoscroll.
  • If an interactive control or editable region has focus, do not arm Space-to-pan.
  • Preserve Space activation of buttons and labels. Preserve preview arrow keys, Escape, and undo.
  • Keep modal portals outside canvas gesture handling. Preserve their focus, backdrop behavior, and native controls.
  • Support two-finger trackpad pan over empty space and previews.
  • If a nested scroll area can scroll in the gesture direction, let it scroll. Otherwise, pan the canvas.
  • Give modified-wheel and pinch zoom priority over scroll routing. Keep other portal scrolling native.
  • Restrict event cancellation and touch restrictions to owned gestures. Do not disable native input across preview content.
  • Use one finger to move items through their handles. Preserve ordinary one-finger preview interactions.
  • Support two-finger canvas pan and pinch without breaking native preview gestures. Report browser limits instead of disabling preview touch.
  • Track which gesture owns each interaction. Clear held keys on cancellation, window blur, and hidden tabs.
  • Handle changes in pointer count, pointer cancellation, and lost pointer capture.
  • On teardown, release captures and clean up listeners, observers, timers, and animation frames.
  • While the route is active, apply
    overscroll-behavior-x: none
    to the document viewport and canvas scroll boundary.
  • Block Chrome horizontal history swipes. An inner wrapper alone does not guarantee prevention.
  • Restore prior document styles on teardown. Preserve nested horizontal scrolling, Back/Forward controls, and navigation shortcuts.
  • Do not trap history with
    pushState
    , patch browser APIs, or leave permanent global handlers.
  • Prevent native page scrolling from moving the canvas. Reveal offscreen keyboard focus through camera movement instead.
  • Require finite, bounded camera coordinates, item positions, and zoom.
  • Combine pointer and wheel updates into at most one transform write per animation frame.
  • Keep active gesture values outside component-wide React state. Camera movement must not rerender previews.
  • Update only canvas-owned wrappers. Do not change preview DOM or layout-affecting positions during gestures.
  • Cache measured bounds. Refresh them together when content, dimensions, or layout changes.
  • Ignore temporary rendering placeholders when measuring content bounds.
  • Do not measure every preview each frame or alternate layout reads and writes.
  • Save after gestures or with a bounded debounce. Do not write storage on every pointer event.
  • On teardown, safely flush pending saves when possible.
  • Prevent expensive effects, permanent per-preview compositing hints, and full-canvas work for one item's movement.
  • Add virtualization or memoization only with profiling evidence. Offscreen unmounting can lose input and break focus or portals.
  • 支持从空白区域按住鼠标拖动来平移 Canvas。
  • 支持在空白区域和预览上方使用 Ctrl/Meta + 滚轮以及触控板捏合进行缩放。
  • 缩放时,保持指针下的 Canvas 点固定不动。
  • 提供放大和缩小按钮以及键盘控制。以视口为中心执行这些缩放操作。
  • 双向缩放应平滑进行,不得出现跳动或漂移。保留项目位置和预览状态。
  • 在浏览器允许的情况下支持触摸平移和捏合。
  • Canvas 外壳获得焦点时,支持键盘控制相机。
  • 所有 Canvas 控件都要显示可见的键盘焦点。
  • 保持全部适配和重置相机控件固定可见,即使项目位于屏幕外也能访问。
  • 在布局稳定后执行全部适配。根据实际边界进行适配,其中包括每个标题、移动句柄和边界。不要重新排列项目。
  • 只重置相机。保留成员关系、位置、主题和草稿。
  • 支持 Space + 主鼠标按钮拖动以及中键拖动,在 Canvas 任意位置(包括预览上方)进行平移。
  • 明确的平移手势优先于项目移动和名称复制。
  • 平移后,不要激活控件、复制标签、跟随链接或触发中键点击自动滚动。
  • 如果可交互控件或可编辑区域已获得焦点,则不要启用 Space 平移。
  • 保留通过 Space 激活按钮和标签的行为。也保留预览中的方向键、Escape 和撤销操作。
  • 将模态 Portal 排除在 Canvas 手势处理范围之外。保留其焦点、背景遮罩行为和原生控件。
  • 支持在空白区域和预览上方使用双指触控板进行平移。
  • 如果嵌套滚动区域可以沿手势方向滚动,则让其滚动;否则平移 Canvas。
  • 带修饰键的滚轮和捏合缩放优先于滚动路由。保持其他 Portal 滚动行为原生化。
  • 仅对 Canvas 自身拥有的手势限制事件取消和触摸行为。不要在预览内容中禁用原生输入。
  • 使用单指通过句柄移动项目。保留预览中普通的单指交互行为。
  • 支持双指 Canvas 平移和捏合,同时不破坏原生预览手势。报告浏览器限制,不要因此禁用预览触摸交互。
  • 跟踪每个交互由哪种手势负责。在手势取消、窗口失去焦点和标签页隐藏时清除按住的按键。
  • 处理指针数量变化、指针取消和指针捕获丢失。
  • 卸载时,释放指针捕获并清理事件监听器、观察器、定时器和动画帧。
  • 路由处于活动状态时,对文档视口和 Canvas 滚动边界应用
    overscroll-behavior-x: none
    。
  • 阻止 Chrome 的横向历史滑动。仅使用内部容器无法保证阻止该行为。
  • 卸载时恢复文档原有样式。保留嵌套水平滚动、Back/Forward 控件和导航快捷键。
  • 不要使用
    pushState
    困住历史记录,不要修改浏览器 API,也不要遗留永久性的全局事件处理器。
  • 防止原生页面滚动带动 Canvas 移动。对于屏幕外获得键盘焦点的元素,应通过移动相机使其显现。
  • 要求相机坐标、项目位置和缩放比例均为有限且有明确边界的数值。
  • 将指针和滚轮更新合并为每个动画帧最多一次 transform 写入。
  • 将活动手势的值保存在组件级 React state 之外。相机移动不得重新渲染预览。
  • 只更新 Canvas 自身拥有的容器。不要在手势期间修改预览 DOM 或影响布局的位置。
  • 缓存测量所得的边界。当内容、尺寸或布局变化时,统一刷新这些边界。
  • 测量内容边界时,忽略临时渲染占位元素。
  • 不要每帧测量所有预览,也不要交替执行布局读取和写入。
  • 在手势结束后保存,或使用带上限的防抖方式保存。不要在每个指针事件上写入存储。
  • 卸载时,在可能的情况下安全刷新待处理的保存任务。
  • 避免昂贵的 effect、永久性的单预览合成提示,以及因移动单个项目而对整个 Canvas 执行工作。
  • 仅在有性能分析依据时添加虚拟化或记忆化。卸载屏幕外项目可能导致输入丢失,并破坏焦点或 Portal。

Save layout, not content

保存布局,不保存内容

  • Save only the camera, supported theme preference, and positions keyed by stable registry ID.
  • Use a small versioned document under a project-specific and canvas-specific key.
  • Respect existing app preferences and unrelated theme configuration. Do not create a competing theme preference.
  • Apply the same numeric limits to saved layout. Use project conventions to validate IDs, supported themes, document size, and position counts.
  • Render every current registry entry. Apply valid saved positions and ignore stale IDs.
  • Always show new entries. Use current source names and dimensions immediately.
  • Handle malformed data, unavailable storage, and quota errors without breaking the canvas.
  • For known older formats, retain only valid camera values, themes, and positions for current IDs.
  • Discard saved membership, names, dimensions, duplicates, and hidden or removed state. For unknown versions, use safe defaults.
  • Never store or deserialize executable components, secrets, tokens, account data, or form contents.
  • Unless explicitly requested, do not save preview drafts or interaction history.
  • 仅保存相机、受支持的主题偏好,以及按稳定注册表 ID 索引的位置。
  • 使用项目专属且 Canvas 专属的键,保存一份小型且带版本号的文档。
  • 尊重现有应用偏好和无关的主题配置。不要创建相互竞争的主题偏好。
  • 对已保存布局应用相同的数值限制。使用项目约定验证 ID、受支持主题、文档大小和位置数量。
  • 渲染当前注册表中的每个条目。应用有效的已保存位置,并忽略失效的 ID。
  • 始终显示新条目。立即使用当前源代码中的名称和尺寸。
  • 处理数据格式错误、存储不可用和配额错误,不要因此破坏 Canvas。
  • 对于已知的旧格式,仅为当前 ID 保留有效的相机值、主题和位置。
  • 丢弃已保存的成员关系、名称、尺寸、重复项以及隐藏或移除状态。对于未知版本,使用安全默认值。
  • 绝不存储或反序列化可执行组件、机密信息、令牌、账户数据或表单内容。
  • 除非用户明确要求,否则不要保存预览草稿或交互历史。

Test and report honestly

如实测试和报告

Run repository-required checks. Make sure that the route mounts, imports resolve, and the console shows no errors. Inspect the diff for unintended production changes.
For a new canvas or controller changes, test every behavior above. For content-only changes, test affected behaviors without rebuilding the controller. Include several zoom levels, viewport sizes, and reloads with an existing saved layout.
Use a supported device for touch tests. Use actual trackpad input and a real history entry for Chrome history-swipe tests.
Test zoom in both directions over empty space and previews. Make sure that the zoom anchor stays fixed without jumps or drift. Test buttons and keyboard zoom around the viewport center. Test trackpad pan over preview content and nested scroll areas, including their scroll limits.
Only report a test as passed if you ran it. Compilation and source review do not prove browser behavior. Report unavailable device tests and browser limits.
Before claiming smooth performance, profile a representative populated canvas, not one empty example. Record the preview count, browser, device, and measurements during pan, zoom, and movement. Investigate long tasks, repeated layout, synchronous storage writes, and preview rerenders. Report observed stalls and untested cases. A preview-only edit does not require rebuilding or profiling an unchanged controller.
Finish with a short report that includes these details:
  • Changed: Paths, purpose, local experiments, shared component changes, and exact names of new previews.
  • Checks run: Tests that you ran and their results.
  • Not working or not tested: Limits, omissions, and reasons.
  • Decisions made: Defaults that you chose without asking.
运行仓库要求的检查。确保路由能够挂载、导入能够解析,并且控制台没有错误。检查 diff 中是否存在意外的生产代码变更。
对于新建 Canvas 或修改控制器的情况,测试上述每项行为。对于仅修改内容的情况,在不重新构建控制器的前提下测试受影响的行为。测试应涵盖多个缩放级别、视口尺寸,以及使用现有已保存布局进行重新加载的场景。
使用受支持的设备进行触摸测试。测试 Chrome 历史滑动时,使用真实的触控板输入和真实历史记录条目。
在空白区域和预览上方分别测试双向缩放。确保缩放锚点保持固定,不出现跳动或漂移。测试围绕视口中心执行的按钮和键盘缩放。测试在预览内容和嵌套滚动区域上方使用触控板平移,包括达到其滚动边界的情况。
只有实际运行过的测试才能报告为通过。编译和源代码审查无法证明浏览器行为。报告无法进行的设备测试和浏览器限制。
在声称性能流畅之前,应对一个具有代表性且包含实际内容的 Canvas 进行性能分析,而不是只分析一个空白示例。记录预览数量、浏览器、设备,以及平移、缩放和移动过程中的测量数据。调查长任务、重复布局、同步存储写入和预览重新渲染。报告观察到的卡顿和未经测试的情况。仅修改预览时,无需重新构建或分析未发生变化的控制器。
最后提供一份简短报告,其中包括以下内容:
  • 已更改:路径、用途、局部实验、共享组件变更,以及新预览的准确名称。
  • 已运行的检查:已运行的测试及其结果。
  • 未工作或未测试的部分:限制、遗漏及其原因。
  • 已作出的决策:未经询问而选择的默认设置。