惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
F
Full Disclosure
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
G
Google Developers Blog
C
Check Point Blog
GbyAI
GbyAI
A
About on SuperTechFans
V
Vulnerabilities – Threatpost
T
The Blog of Author Tim Ferriss
T
Tor Project blog
AWS News Blog
AWS News Blog
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
MongoDB | Blog
MongoDB | Blog
Latest news
Latest news
aimingoo的专栏
aimingoo的专栏
U
Unit 42
Y
Y Combinator Blog
P
Privacy International News Feed
Cisco Talos Blog
Cisco Talos Blog
S
Securelist
S
Schneier on Security
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Attack and Defense Labs
Attack and Defense Labs
P
Proofpoint News Feed
C
Cisco Blogs
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
P
Privacy & Cybersecurity Law Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
罗磊的独立博客
Cloudbric
Cloudbric
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
HTML-in-Canvas Feels Fake Until You Try to Build With It
Sara Loera · 2026-05-14 · via DEV Community

HTML-in-Canvas feels fake the first time it works.

Real DOM.

Real CSS.

Real layout.

Inside canvas.

You write a tiny canvas.onpaint, call drawElementImage(), and the browser just… does it. Your styled HTML is suddenly part of a canvas frame.

Beautiful.

Then you try to build an actual app.

Now you have multiple surfaces, resize logic, export timing, React unmounts, cleanup, invalidation, and the classic:

wait, is this number CSS pixels or canvas pixels?

That's the part where the cool browser primitive turns into lifecycle work.

So I built Prism.


First: what is HTML-in-Canvas?

The WICG HTML-in-Canvas proposal lets a canvas render real HTML elements directly.

Not screenshots.

Not html2canvas.

Not SVG foreignObject.

Actual DOM, painted into a canvas frame by the browser.

A tiny example looks like this:

<canvas id="canvas" layoutsubtree>
  <div id="panel" style="width: 400px; height: 200px">
    <h2>Real HTML</h2>
    <p>Real CSS. Real fonts. Real layout.</p>
  </div>
</canvas>

Enter fullscreen mode Exit fullscreen mode

const canvas = document.getElementById("canvas");
const panel = document.getElementById("panel");
const ctx = canvas.getContext("2d");
if (!ctx) throw new Error("2d context unavailable");

canvas.onpaint = () => {
  ctx.drawElementImage(panel, 0, 0);
};

canvas.requestPaint();

Enter fullscreen mode Exit fullscreen mode

The rough shape is:

  • layoutsubtree opts canvas children into layout.
  • drawElementImage() draws a child element into the canvas.
  • onpaint fires when the browser says the canvas subtree needs painting.

For one surface, it is almost suspiciously nice.

But apps are never one surface.


The part that gets messy

With the raw API, your app has to answer a bunch of boring-but-important questions:

  • Which DOM elements are canvas surfaces?
  • Who updates their bounds?
  • Who asks the browser for a new paint?
  • What happens when a component unmounts?
  • What happens when the runtime is destroyed?
  • How do you wait for a paint-ready frame before export?
  • How do you keep CSS pixels and backing-store pixels straight?

A single React component can already start to look like this:

useEffect(() => {
  const canvas = canvasRef.current;
  const scene = sceneRef.current; // the DOM element to draw
  const ctx = canvas?.getContext("2d");
  if (!canvas || !ctx || !scene) return;

  canvas.onpaint = () => {
    ctx.reset();
    ctx.drawElementImage(scene, 0, 0);
  };

  // Simplified: uses CSS pixels for backing-store size.
  // In production, use DPR-aware sizing via devicePixelContentBoxSize
  // or multiply contentRect dimensions by devicePixelRatio.
  const resizeObserver = new ResizeObserver(([entry]) => {
    canvas.width = Math.round(entry.contentRect.width);
    canvas.height = Math.round(entry.contentRect.height);
    canvas.requestPaint();
  });

  resizeObserver.observe(canvas);
  canvas.requestPaint();

  return () => {
    resizeObserver.disconnect();
    canvas.onpaint = null;
  };
}, []);

Enter fullscreen mode Exit fullscreen mode

That is not terrible.

It is also not the app I wanted to write.

Now add export. Add multiple DOM surfaces. Add transform sync. Add pointer interaction. Add route changes. Add a framework. Add "why is this blank PNG happening only sometimes?"

That is where Prism comes in.


What Prism is

Prism is a native-first HTML-in-Canvas runtime for managed DOM surfaces in canvas applications.

It does not replace your renderer.

Your app still owns the scene, drawing model, animation loop, state, data, interactions, and visual decisions.

Prism owns the DOM-surface lifecycle:

your app owns:
  scene, rendering, animation, state, interaction

Prism owns:
  surface registration, bounds, invalidation,
  paint readiness, coordinate helpers, cleanup

Enter fullscreen mode Exit fullscreen mode

Install it:

pnpm add @synthesisengineering/prism

Enter fullscreen mode Exit fullscreen mode

Use it like this:

import { CanvasRuntime } from "@synthesisengineering/prism";

const runtime = new CanvasRuntime(canvas, { backend: "auto" });

const surface = runtime.registerSurface(element, {
  bounds: { x: 0, y: 0, width: 320, height: 180 }
});

runtime.onPaint(({ drawSurface }) => {
  drawSurface(surface);
});

runtime.start();

Enter fullscreen mode Exit fullscreen mode

That is the core idea.

The DOM stays DOM.

The canvas stays canvas.

Prism manages the boundary.


The shift: DOM as source material

The important part is not that Prism makes prettier pixels than hand-written canvas.

You can make beautiful things with Canvas 2D, SVG, WebGL, shaders, and all the usual tricks.

The important part is that the source material can stay DOM.

Your labels can be real HTML.

Your typography can stay CSS.

Your icons can stay SVG.

Your React components can stay React components.

Prism lets the canvas treat those DOM-authored pieces as managed surfaces.

So instead of rewriting every styled element as canvas drawing code, you can author the visual source with the browser's layout engine and compose it inside canvas.

The browser gives us the primitive.

Prism provides an app lifecycle.


Use case 1: data visualization

One example is Prism Atlantic.

Prism Atlantic App

It uses real NOAA/NHC HURDAT2 Atlantic storm-track data from 2000–2025. The canvas draws the storm paths. Prism manages the HTML/CSS surfaces: title, overview, legend, tooltip, detail panel, caption, and export button.

Open Prism Atlantic →

The app owns the data visualization. Prism owns the surface lifecycle.

import { CanvasRuntime } from "@synthesisengineering/prism";

const runtime = new CanvasRuntime(canvas, { backend: "auto" });

const tooltip = runtime.registerSurface(tooltipEl, {
  bounds: { x: 0, y: 0, width: 280, height: 120 }
});

const legend = runtime.registerSurface(legendEl, {
  bounds: { x: 20, y: 20, width: 200, height: 400 }
});

runtime.onPaint(({ ctx, drawSurface }) => {
  ctx.save();
  ctx.scale(runtime.pixelRatio, runtime.pixelRatio);
  drawStormTracks(ctx);
  ctx.restore();
  drawSurface(tooltip);
  drawSurface(legend);
});

runtime.start();

Enter fullscreen mode Exit fullscreen mode

The export path is the part I really wanted to get right.

With Prism, you wait for fonts, then wait for one Prism-owned paint pass, then use the normal canvas API:

await document.fonts.ready;
await runtime.paintOnce();

const blob = await new Promise<Blob>((resolve, reject) => {
  canvas.toBlob((value) => {
    if (!value) {
      reject(new Error("Canvas export failed."));
      return;
    }
    resolve(value);
  }, "image/png");
});

Enter fullscreen mode Exit fullscreen mode

paintOnce() does not export anything by itself.

It just answers: has Prism completed a paint-ready frame?

Then canvas.toBlob() does the export.

No screenshot library. No html2canvas. No foreignObject export path.


Use case 2: React components as canvas surfaces

Another example is React Composer Lite.

Prism React Composer Lite

It shows React-authored HTML/CSS components as movable, transformable, exportable canvas surfaces.

The trick is not to let React and Prism fight over ownership.

React owns component state.

Prism owns surface registration and cleanup.

The pattern is:

  1. Create the runtime once.
  2. Register the DOM node once for a runtime/element pair.
  3. Update bounds through surface.setBounds().
  4. Destroy and dispose on unmount.
import { useEffect, useRef, useState } from "react";
import type { RefObject } from "react";
import { CanvasRuntime } from "@synthesisengineering/prism";
import type { CanvasSurface } from "@synthesisengineering/prism";

type SurfaceBounds = {
  x: number;
  y: number;
  width: number;
  height: number;
};

export function usePrismRuntime(
  canvas: HTMLCanvasElement | null
): CanvasRuntime | null {
  const [runtime, setRuntime] = useState<CanvasRuntime | null>(null);

  useEffect(() => {
    if (!canvas) {
      setRuntime(null);
      return;
    }

    const nextRuntime = new CanvasRuntime(canvas, { backend: "auto" });
    nextRuntime.start();
    setRuntime(nextRuntime);

    return () => {
      setRuntime(null);
      nextRuntime.destroy();
    };
  }, [canvas]);

  return runtime;
}

export function usePrismSurface(
  runtime: CanvasRuntime | null,
  elementRef: RefObject<HTMLElement | null>,
  bounds: SurfaceBounds
) {
  const surfaceRef = useRef<CanvasSurface | null>(null);

  useEffect(() => {
    const element = elementRef.current;
    if (!runtime || !element) return;

    const surface = runtime.registerSurface(element, { bounds });
    surfaceRef.current = surface;

    return () => {
      surface.dispose();
      surfaceRef.current = null;
    };
    // Register once for this runtime/element pair.
    // Bounds updates are handled by the effect below.
  }, [runtime, elementRef]);

  useEffect(() => {
    surfaceRef.current?.setBounds(bounds);
  }, [bounds.x, bounds.y, bounds.width, bounds.height]);

  return surfaceRef;
}

Enter fullscreen mode Exit fullscreen mode

The important detail: usePrismRuntime returns state, not a ref, so downstream usePrismSurface re-runs correctly when the runtime is ready. Bounds updates do not require re-registering the surface — register once, then update through surface.setBounds().

The boundary is clean:

  • React renders normal components.
  • Prism registers those DOM nodes as surfaces on mount.
  • Canvas composes them into a frame.
  • Cleanup happens when components unmount.

Your React components do not need to become canvas drawing code.

They can stay React components.


Use case 3: DOM as creative material

The third example is Prism Atelier.

Prism Prism Atelier

This one is less practical and more fun.

It uses DOM-authored HTML/CSS/SVG as visual material. A real DOM surface is registered once, then drawn repeatedly inside the canvas paint pass with transforms, opacity, shadows, blend modes, and pointer-driven motion.

Open Prism Atelier →

The source can be a normal element:

<div id="type-surface" class="type-surface">PRISM</div>

Enter fullscreen mode Exit fullscreen mode

Then Prism turns it into a reusable canvas surface:

const surface = runtime.registerSurface(typeEl, {
  bounds: { x: -380, y: -105, width: 760, height: 210 }
});

Enter fullscreen mode Exit fullscreen mode

And the app can compose it:

runtime.onPaint(({ ctx, drawSurface }) => {
  // runtime.canvas.width/height are backing-store pixels (CSS pixels × devicePixelRatio).
  // Surface bounds passed to registerSurface/setBounds are CSS pixels — keep them separate.
  ctx.fillStyle = "#07070a";
  ctx.fillRect(0, 0, runtime.canvas.width, runtime.canvas.height);

  const count = 35;
  const radius = 220 * runtime.pixelRatio;
  const cx = runtime.canvas.width / 2;
  const cy = runtime.canvas.height / 2;

  for (let i = 0; i < count; i += 1) {
    const t = i / count;
    const angle = t * Math.PI * 2 + rotation;

    ctx.save();
    ctx.translate(
      cx + Math.cos(angle) * radius,
      cy + Math.sin(angle) * radius
    );
    ctx.rotate(angle);
    ctx.globalAlpha = 1 - t * 0.65;
    drawSurface(surface);
    ctx.restore();
  }
});

Enter fullscreen mode Exit fullscreen mode

You could hand-roll something like this with the raw API.

But then you own the browser paint hooks, bounds, invalidation, readiness, and cleanup yourself.

Prism makes the DOM surface reusable as canvas material without making your app coordinate raw onpaint, requestPaint(), and drawElementImage() directly.


The coordinate-space footgun

One thing Prism makes explicit is coordinate space.

Surface bounds are CSS pixels:

surface.setBounds({
  x: 24,
  y: 32,
  width: 360,
  height: 220
});

Enter fullscreen mode Exit fullscreen mode

Direct canvas drawing uses backing-store pixels.

So Prism exposes helpers:

const point = runtime.cssPointToCanvasPixels({ x: 24, y: 32 });
const size = runtime.cssLengthToCanvasPixels(12);

Enter fullscreen mode Exit fullscreen mode

This sounds boring until it saves you from the classic "everything is offset and blurry on my display" bug.

Boring runtime helpers are good, actually.


An agent skill is included

One thing I care about: Prism should be hard to misuse, even when an AI coding agent is writing the first draft.

So Prism ships with an agent skill:

npx skills add synthesiseng/prism --skill prism-runtime

Enter fullscreen mode Exit fullscreen mode

The skill teaches agents the Prism runtime contract:

  • import from @synthesisengineering/prism
  • register DOM nodes as surfaces
  • draw surfaces inside onPaint()
  • wait for document.fonts.ready and runtime.paintOnce() before export
  • avoid html2canvas, dom-to-image, raw drawElementImage(), and deep imports

That last part matters.

Without guidance, agents tend to reach for screenshot libraries or raw platform APIs. The skill keeps them on the Prism path.


The renderer boundary

Prism can sit alongside renderers like Three.js because it does not try to own the scene. Today, the documented API remains 2D-first; renderer-specific integrations are future-facing.

That boundary is the design:

  • the renderer owns the scene
  • the app owns state and interaction
  • Prism owns DOM-surface lifecycle

The point is not to turn Prism into a renderer.

The point is to let renderers use real DOM surfaces without every app rebuilding the same lifecycle layer.


The honest caveats

Prism is still early.

Native fidelity currently requires Chromium with:

chrome://flags/#canvas-draw-element

Enter fullscreen mode Exit fullscreen mode

Prism detects native support and can fall back to a compatibility path, but fallback is lower fidelity. It is not equivalent to native HTML rendering.

This is alpha software: 0.1.0-alpha.8.

The current public API is 2D-first. WebGL, WebGPU, Three.js, Pixi, and Phaser integrations are future-facing, not the current public API center.

Prism is not a renderer, UI kit, design tool, app framework, charting library, or game engine.

It is a runtime for managed DOM surfaces in canvas applications.

That is the whole point.


Try it

Docs and examples: runprism.dev

Source: github.com/synthesiseng/prism

Live examples:

Install:

pnpm add @synthesisengineering/prism

Enter fullscreen mode Exit fullscreen mode

Agent skill:

npx skills add synthesiseng/prism --skill prism-runtime

Enter fullscreen mode Exit fullscreen mode

Feedback welcome from people building canvas-heavy apps, visual tools, data viz, editors, and creative systems.