Skip to content

Add embeddable HTML export from the dial#1

Open
pzep1 wants to merge 1 commit into
lenxism:mainfrom
pzep1:feat/embed-export
Open

Add embeddable HTML export from the dial#1
pzep1 wants to merge 1 commit into
lenxism:mainfrom
pzep1:feat/embed-export

Conversation

@pzep1
Copy link
Copy Markdown

@pzep1 pzep1 commented May 7, 2026

Summary

Adds an Export action to the dial that downloads a single self-contained HTML file capturing the live, interactive dither system — not a still frame.

A first attempt at PNG/SVG export ended up just being a screenshot of whatever happened to be on the canvas at viewport size, which missed the point: the artifact of this project is the mouse-reactive particle animation, not a frozen image. This export packages that animation as a portable, embeddable file.

What gets exported

A ~20 KB standalone dither-embed-<timestamp>.html containing:

  • The dither algorithms (Floyd-Steinberg, Bayer, blue noise) and rounded-square mask
  • The particle system (mouse force field, click shockwaves, easing)
  • Render loop + ResizeObserver-driven rebuilds
  • The current dial config baked in as a CONFIG object
  • The source image inlined as a base64 data URL

No external requests, no dependencies. Open it directly or drop in an iframe:

<iframe src="dither-embed-...html" style="width:100%;height:600px;border:0"></iframe>

Implementation

  • src/lib/embed-runtime.ts — vanilla-JS port of dither-algorithms, image-processing, and particle-system, wrapped in a single runDitherEmbed(CONFIG) function. The function's source is stringified via Function.prototype.toString() and inlined into the exported HTML by buildEmbedHTML(). Also exposes imageSrcToDataUrl() for embedding the current image.
  • src/components/particle-canvas.tsx — new export: { type: "action" } entry in the dial, an exportArtwork callback that fetches the current image, builds the HTML, and triggers a download. Uses an exportRef to avoid the closure ordering issue with useDialKit's onAction.

Test plan

  • Click Export in the dial — a dither-embed-<timestamp>.html file downloads
  • Open the downloaded file directly in a browser — it renders, animates, and reacts to the cursor / clicks
  • Resize the window — the dot grid rebuilds at the new size
  • Verify the inlined config matches whatever you had set in the dial at export time
  • Drop the file into an iframe on another page — it works without any external requests

🤖 Generated with Claude Code

Adds an "Export" action to the useDialKit panel that downloads a single
self-contained HTML file (~20 KB) capturing the live, mouse-reactive
system rather than a still frame.

The exported file inlines the dither algorithms, particle physics
(mouse force field, click shockwaves), render loop, current dial
configuration, and the source image as a base64 data URL. No external
dependencies — open it directly or drop it in an iframe:

  <iframe src="dither-embed-...html" style="width:100%;height:600px;border:0"></iframe>

Implementation:
- src/lib/embed-runtime.ts — vanilla-JS port of the dither/particle
  modules wrapped in a single function whose source is stringified at
  build time and inlined into the exported HTML
- src/components/particle-canvas.tsx — new "export" dial action,
  exportArtwork callback, downloadBlob helper

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

@pzep1 is attempting to deploy a commit to the leo-6143's projects Team on Vercel.

A member of the Team first needs to authorize it.

@pzep1
Copy link
Copy Markdown
Author

pzep1 commented May 7, 2026

thanks for OSSing this btw, been fun to play with! I thought maybe its useful for others to have it make a html embeddable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant