Zach’s ugly mug (his face) Zach Leat­herman

The Squirminal Web Component

1k 00 October 28, 2023
🚾Web Component@zachleat/squirminal

Squirminal incrementally reveals text inside any arbitrary DOM element structure.

0%
Versions
Monthly publishes sparkline for @zachleat/squirminal, ranging 0 to 8 21 versions in
3.0.1
Audit
0 reports
0 deps
Issues
0
PRs
0

A lightweight structural-only zero-dependency web component to progressively animate to reveal HTML content. I believe the name came from an awkward portmanteau of squirmy and terminal.

This one is a few years old (but I am currently cataloguing my web components) and was developed to fake an antique terminal for the web-based CLI used in the Your Year on Netlify project.

Screenshot image for https://squirminal.zachleat.dev/

Features

  • Works with prefers-reduced-motion
  • Works without JavaScript (fallback to full content)
  • Add a blinking cursor via <squirm-inal cursor>
  • Autoplay (only when visible) via <squirm-inal autoplay>
  • Works with text nodes inside any arbitrary HTML content.

Better than Before

When I worked on the slide deck for my Smashing Conference talk in 2021, I developed a similar mechanism to do this, but in a much less efficient way: each syntax highlighted character was wrapped in an additional wrapper element on the server!

I wrote about this in Queue Code—“Live” Code without Errors and you can play around with it on the demo below:

Screenshot image for https://queuecode.zachleat.dev/

That approach leaned heavily into server rendering unnecessarily—the whole point of this effect required client interaction and the fallback experience was the original content in its entirety.

Lessons learned

Squirminal is a better approach that doesn’t require expensive DOM modification on the server and is much more powerful—it can work with any arbitrary HTML content (e.g. lists, images, tables, etc—it’s not limited to syntax highlighted text) and leaves the original content intact and unmodified before or without JavaScript.

There is an important lesson here—in this case the best progressive enhancement compromise involved less server rendering! Ultimately this use case and interaction required clientside interactivity, so it was okay to lean into that a bit more—while still building on a good progressive enhancement baseline.

This was an important reminder to me that progressive enhancement is a continuum of possible solutions—and it’s important to adjust where your solution lives on that continuum as needed and for your individual requirements (and hopefully your tools don’t force you into a corner before you can make those decisions).

Demos

class MyComponent extends HTMLElement {
	connectedCallback() {
		// web component stuff
		// web component stuff
		// web component stuff
		// web component stuff
		// web component stuff
		// web component stuff
		// web component stuff
		// web component stuff
	}
}
if("customElements" in window) {
	customElements.define("my-component", MyComponent);
}

In the wild

Live Site Walkthrough

Here’s a demo screencast I recorded of my personal Your Year on Netlify flow.

Watch on YouTube: Walkthrough of the Your Year On Netlify Microsite

< Older
browser-window Web Component
Newer >
A new Eleventy mascot from David Neal!

Zach Leatherman IndieWeb Avatar for https://zachleat.com/is a builder for the web at Font Awesome and the creator of Build Awesome (née IndieWeb Avatar for https://www.11ty.devEleventy/11ty), an award-winning open source website generator. He measures website performance with speedlify and at one point became too fixated on web fonts. He has given 89 talks in nine different countries at events like Beyond Tellerrand, Smashing Conference, Jamstack Conf, CSSConf, and The White House. Formerly part of CloudCannon, Netlify, Filament Group, NEJS CONF, and NebraskaJS. Learn more about Zach »

Shamelessly plug your related post

These are webmentions via the IndieWeb and webmention.io.

Sharing on social media?

This is what will show up when you share this post on Social Media:

How did you do this? I automated my Open Graph images. (Peer behind the curtain at the test page)