Skip to content

A Claude Code skill that reverse-engineers any animation frame by frame, then proves the copy moves the same.

Play the Clerk cards on touch screens

NiazMorshed2007151fd42ad820
diff --git a/site/public/examples/clerk-bento/index.html b/site/public/examples/clerk-bento/index.html
index c0ee37e..55df7b4 100644
--- a/site/public/examples/clerk-bento/index.html
+++ b/site/public/examples/clerk-bento/index.html
@@ -14,6 +14,17 @@
const card = params.get("card");
if (card) document.documentElement.dataset.card = card;
if (card && params.has("embed")) document.documentElement.dataset.embed = "";
+ // without &embed on a screen narrower than the card (a phone), the card is scaled down to fit
+ if (card && !params.has("embed")) {
+ const root = document.documentElement;
+ const fit = () => {
+ const z = Math.min(1, (innerWidth - 32) / parseFloat(getComputedStyle(root).getPropertyValue("--card-w")));
+ root.style.setProperty("--fit", z);
+ root.toggleAttribute("data-fit", z < 1);
+ };
+ fit();
+ addEventListener("resize", fit);
+ }
</script>
<script type="module" src="./src/bento.js"></script>
</head>
diff --git a/site/public/examples/clerk-bento/src/bento.css b/site/public/examples/clerk-bento/src/bento.css
index 31fd5d6..8ce1dac 100644
--- a/site/public/examples/clerk-bento/src/bento.css
+++ b/site/public/examples/clerk-bento/src/bento.css
@@ -144,6 +144,7 @@ button, input, select, textarea { font: inherit; color: inherit; background-colo
.clerk-card {
position: relative;
isolation: isolate;
+ -webkit-tap-highlight-color: transparent; /* touch screens toggle a card on tap (bento.js) */
display: flex;
flex-direction: column;
border-radius: 16px;
@@ -240,6 +241,10 @@ html[data-card="passwords"] .clerk-card--passwords,
html[data-card="api-keys"] .clerk-card--api-keys,
html[data-card="clerk-cli"] .clerk-card--clerk-cli { display: flex; height: 100%; }
+/* ?card=<slug> on a screen narrower than the card: scaled to fit, 16px from the sides (index.html sets --fit) */
+html[data-fit] .clerk-bento { padding: 24px 0; }
+html[data-fit] .clerk-bento__stack { zoom: var(--fit); margin: 0 auto; }
+
/* ?card=<slug>&embed: the card 24px from every edge, no scrolling (the reanimate site shows it in an iframe) */
html[data-embed] { overflow: hidden; }
html[data-embed] .clerk-bento { padding: 24px 0; }
diff --git a/site/public/examples/clerk-bento/src/bento.js b/site/public/examples/clerk-bento/src/bento.js
index 59798e2..3297b27 100644
--- a/site/public/examples/clerk-bento/src/bento.js
+++ b/site/public/examples/clerk-bento/src/bento.js
@@ -10,6 +10,11 @@
// With ?card=<slug> only that card's widget is mounted.
// Progress for recorders: each slot gets data-widget-state="loading" → "mounted" | "static" | "empty" |
// "error"; when every slot has settled, <html data-widgets="ready"> and window.clerkBento.ready resolves.
+//
+// Touch screens (an addition, clerk.com has none): the cards follow react-aria's useHover, which ignores touch,
+// so on a phone they would never play. Where nothing can hover, a card plays while at least half of it is on
+// screen, stops once it has left, and a tap toggles it. The shell sends the card the events a mouse would and
+// sets .is-hovered for the CSS group-hover parts, so the widgets themselves are unchanged.
const WIDGETS = new URL("./widgets/", import.meta.url);
@@ -77,3 +82,22 @@ const ready = Promise.allSettled(slots.map(mountWidget)).then(() => {
document.documentElement.dataset.widgets = "ready";
});
window.clerkBento = { ready };
+
+function playOnScreen(card) {
+ let on = false;
+ const set = (v) => {
+ if (v === on) return;
+ on = v;
+ card.classList.toggle("is-hovered", v);
+ card.dispatchEvent(new PointerEvent(v ? "pointerenter" : "pointerleave", { pointerType: "mouse", isPrimary: true }));
+ card.dispatchEvent(new MouseEvent(v ? "mouseenter" : "mouseleave"));
+ };
+ // iOS sends a real mouseenter on tap and mouseleave on the next tap elsewhere; only the shell's count here
+ for (const type of ["mouseenter", "mouseleave"]) card.addEventListener(type, (e) => e.isTrusted && e.stopImmediatePropagation(), true);
+ new IntersectionObserver(([e]) => (e.intersectionRatio >= 0.5 ? set(true) : !e.isIntersecting && set(false)), { threshold: [0, 0.5] }).observe(card);
+ card.addEventListener("click", () => set(!on));
+}
+
+if (matchMedia("(hover: none)").matches) {
+ ready.then(() => slots.forEach((s) => s.dataset.widgetState === "mounted" && playOnScreen(s.closest(".clerk-card"))));
+}
diff --git a/site/public/examples/clerk-bento/src/widgets/api-keys.css b/site/public/examples/clerk-bento/src/widgets/api-keys.css
index 08747c4..8a2d8c1 100644
--- a/site/public/examples/clerk-bento/src/widgets/api-keys.css
+++ b/site/public/examples/clerk-bento/src/widgets/api-keys.css
@@ -248,3 +248,7 @@
.clerk-card--api-keys:hover .ak-sheen { opacity: 1; transition-duration: 1s; }
.clerk-card--api-keys:hover .ak-pill__text { color: #fff; }
}
+/* touch screens: bento.js sets .is-hovered while the card plays */
+.clerk-card--api-keys.is-hovered .ak-lid::before { opacity: 0; transition-duration: 0.5s; }
+.clerk-card--api-keys.is-hovered .ak-sheen { opacity: 1; transition-duration: 1s; }
+.clerk-card--api-keys.is-hovered .ak-pill__text { color: #fff; }
diff --git a/site/public/examples/clerk-bento/src/widgets/fraud.css b/site/public/examples/clerk-bento/src/widgets/fraud.css
index 6849e33..c124a3b 100644
--- a/site/public/examples/clerk-bento/src/widgets/fraud.css
+++ b/site/public/examples/clerk-bento/src/widgets/fraud.css
@@ -108,3 +108,5 @@
@media (hover: hover) {
.clerk-card--fraud:hover .fr-text { color: #fff; }
}
+/* touch screens: bento.js sets .is-hovered while the card plays */
+.clerk-card--fraud.is-hovered .fr-text { color: #fff; }
diff --git a/site/public/examples/clerk-bento/src/widgets/session-management.css b/site/public/examples/clerk-bento/src/widgets/session-management.css
index 88706a5..cb12989 100644
--- a/site/public/examples/clerk-bento/src/widgets/session-management.css
+++ b/site/public/examples/clerk-bento/src/widgets/session-management.css
@@ -224,3 +224,10 @@
box-shadow: inset 0 0 0 1px var(--color-gray-700);
}
}
+/* touch screens: bento.js sets .is-hovered while the card plays */
+.clerk-card--session-management.is-hovered .sm-lid::before { opacity: 0; transition-duration: 0.5s; }
+.clerk-card--session-management.is-hovered .sm-sheen { opacity: 1; transition-duration: 1s; }
+.clerk-card--session-management.is-hovered .sm-button {
+ color: #fff;
+ box-shadow: inset 0 0 0 1px var(--color-gray-700);
+}
diff --git a/site/src/app/globals.css b/site/src/app/globals.css
index 6c63d12..a02145e 100644
--- a/site/src/app/globals.css
+++ b/site/src/app/globals.css
@@ -134,6 +134,9 @@ ul.list li + li { margin-top: 8px; }
.figure__caption--pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.livecard { display: flex; justify-content: center; overflow: hidden; border-radius: 10px; background: #131316; }
.livecard iframe { flex: none; border: 0; transform-origin: top center; }
+/* a card plays on hover, or on touch screens while it's on screen and on tap (clerk-bento/src/bento.js) */
+@media (hover: hover) { .on-touch { display: none; } }
+@media (hover: none) { .on-hover { display: none; } }
.sheet { display: block; width: 100%; height: auto; border-radius: 10px; box-shadow: 0 0 0 1px var(--rule); }
diff --git a/site/src/app/page.tsx b/site/src/app/page.tsx
index d429a03..de2c15e 100644
--- a/site/src/app/page.tsx
+++ b/site/src/app/page.tsx
@@ -195,7 +195,7 @@ export default function Home() {
<Section id="examples" n={5} title="Examples">
<p>
- Hover a clerk.com card to play it; the copies use the free Geist font, so only the lettering differs. For stripe.com and workos.com, the original plays on the left and the copy on the
+ Hover a clerk.com card to play it, or on a phone just scroll to it. The copies use the free Geist font, so only the lettering differs. For stripe.com and workos.com, the original plays on the left and the copy on the
right.
</p>
<nav className="strip" aria-label="Examples">
@@ -227,7 +227,8 @@ export default function Home() {
<LiveCard src={`${e.live}&embed`} width={e.show.width} height={e.show.height} label={`${e.title}, the copy, running live`} />
<figcaption className="figure__caption">
<span>
- the copy, hover it ·{" "}
+ the copy, <span className="on-hover">hover it</span>
+ <span className="on-touch">tap it</span> ·{" "}
<a href={e.live} target="_blank" rel="noreferrer">
open on its own ↗
</a>
diff --git a/site/src/components/LiveCard.tsx b/site/src/components/LiveCard.tsx
index 7f7949d..a40facf 100644
--- a/site/src/components/LiveCard.tsx
+++ b/site/src/components/LiveCard.tsx
@@ -2,8 +2,8 @@
import { useEffect, useRef, useState } from "react";
-// The clone itself, running in the page: hover it to play. Shown at its real size, scaled down only
-// when the column is narrower.
+// The clone itself, running in the page: hover it to play (touch screens play it while it's on screen).
+// Shown at its real size, scaled down only when the column is narrower.
export function LiveCard({ src, width, height, label }: { src: string; width: number; height: number; label: string }) {
const box = useRef<HTMLDivElement>(null);