building-html-canvases
它能做什么
本技能使用简单的网页代码,创建文档式或图形式的画布,例如报告、图表和绘图。适合需要在 PostHog 中放置可阅读页面或视觉作品、而非完整应用的人。
适用场景
- ✓当你希望把一份书面报告或文章以画布形式展示时。
- ✓当你希望在 PostHog 中放置图示、绘图或生成的图形的时候。
- ✓当画布主要是静态内容,不需要大量交互控件的时候。
技能链接
https://github.com/PostHog/posthog/blob/master/products/canvas/skills/building-html-canvases/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请制作一个画布,以简洁易读的报告形式展示我们的季度发现,并附上一张简单的图表。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会编写语义化的 HTML、样式和浏览器绘图代码,并包裹在 PostHog 要求的小型 React 外壳中。它还会清理动画和事件监听器,使画布在主题切换时运行良好。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Building HTML canvases
Some canvases are documents or graphics programs, not applications: a written report, a diagram, a generative-art piece, a WebGL scene. For these, semantic HTML, CSS, and direct browser APIs are the right tools — don't force Quill components or React state onto a static page.
The wrapper the current runtime requires
Every canvas keeps src/canvas.tsx as its mounted React entry component (default export, no
props). Keep the React layer as a thin shell and write the
experience in HTML/CSS/browser APIs inside it:
- A document is JSX that is effectively semantic HTML —
<article>, headings, lists, tables, figures — with a<style>block for typography and layout. Write real, specific copy. - A drawing/WebGL program renders a
<canvas>element and drives it imperatively from auseEffectvia a ref: get the 2D/WebGL context, run the setup and render loop there. - Clean up in the effect's return: cancel
requestAnimationFrameloops, remove listeners, and release contexts, so theme switches and remounts don't leak or double-run. - Mixing tiers is fine: a mostly static page can mount one interactive island, and a data board
can hand a chart's
<canvas>to imperative code while React owns the chrome.
The import allowlist still applies (react, react-dom, @posthog/quill, recharts, lucide-react,
dayjs) — browser globals (document, CanvasRenderingContext2D, WebGLRenderingContext,
requestAnimationFrame, IntersectionObserver, Web Audio, etc.) need no import. Three.js and
other npm graphics libraries are not yet loadable; write against raw WebGL or 2D canvas until the
build pipeline's dependency admission ships.
Styling and theme without Quill
- Size the outermost JSX/HTML element to the iframe viewport with
min-h-screenormin-height: 100vh, so it fills the viewport and grows past it as content demands. Do not useh-screenorheight: 100vhthere: a fixed viewport height caps a flex column, so tall children shrink and clip instead of scrolling. Do not useh-fullorheight: 100%on that root either: a published canvas's artifact shell gives itshtml,body, and#rootelements no explicit height, so percentage height collapses to the content height. Amin-heightroot is not a definite height, so a descendant's percentage height still collapses; give an intermediate wrapper an explicit height when a child must fill a box. - Use Tailwind utilities and/or a
<style>block (keyframes and complex selectors are fine). - The host toggles a
.darkclass on the document root when the user's PostHog theme changes. Define your colors as CSS variables under:root { … }with overrides underhtml.dark { … }, or use theme token utilities (bg-background,text-foreground,border-border) — never a light-only hardcoded color. - Give your own CSS variables a prefix (
--doc-bg,--doc-muted). Never reuse a platform token name: the bundled Quill stylesheet sets--background,--border,--card,--chrome,--input,--muted,--primary, and--fill-*on every element, so a:rootorhtml.darkvalue with one of those names never reaches any element. A page that colors its text with its own--mutedthen renders unreadable (pale text on a pale page). Validation rejects such a declaration withplatform_token_redeclared. - For canvas/WebGL drawing colors, read the resolved token at runtime
(
getComputedStyle(document.documentElement).getPropertyValue("--primary")) or your own CSS variables, and re-read on theme change if the scene is long-lived.
Rules that still apply
- PostHog data comes only through the
phbridge (seequerying-canvas-data), includingph.capturefor interaction analytics. Other requests and external styles, images, fonts, media, or frames require their exact public HTTPS origins incapabilities.network.originsand work only after publishing. Remote scripts and dynamic imports remain blocked. - A document that states PostHog numbers must make each one verifiable: an insight-backed number
links its saved insight through
ph.openExternal(URL from thegenerate-app-urlMCP tool, from a click); an ad-hocph.querynumber discloses the exact query that ran in a<details>element beside the claim — see "Verifiability" inquerying-canvas-data. - External links go through
ph.openExternal(url)(posthog.com origins only), from a user interaction. - Validate and publish through the c
常见问题
我需要了解 React 吗?
不太需要。React 部分只是一个很薄的包装,其余部分都是普通的 HTML、CSS 和浏览器代码。
它能显示 PostHog 的数据吗?
可以,通过 PostHog 的数据桥接,画布必须声明使用该桥接。
什么情况下这种方式不是最佳选择?
对于带有大量控件的交互式应用,React 与 Quill 的方式更为合适。
详情
作者的原始描述
Author a PostHog canvas with semantic HTML, CSS, and direct browser APIs — documents, articles, generative graphics, 2D canvas and WebGL experiences, and focused experiments where React components add no useful structure. Use after building-canvases has routed a canvas request to a plain-HTML/browser-API implementation. Covers the thin component wrapper the current runtime requires, styling and theming without Quill, drawing surfaces, and animation/cleanup patterns.
repo: PostHog/posthog
热度
- GitHub 星标
- 41k
- 排名
- #6839
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
depot-ci
41k帮你的智能体设置并运行 Depot CI 工作流(GitHub Actions 的替代方案),包括迁移现有工作流和读取运行日志。
depot-container-builds
41k帮你的智能体在 Depot 的远程构建器上构建 Docker 镜像,包括多平台镜像、推送到镜像仓库,以及修复构建失败。
depot-github-runners
41k帮你的智能体把 GitHub Actions 任务迁移到 Depot 托管的运行器上,选择运行器规格和标签,并排查运行器设置问题。
editing-agents-md
41k帮你的智能体判断某条规则应写入 AGENTS.md 还是 CLAUDE.md,并以不会让文件臃肿的方式写下,确保规则真正生效。