Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Fuobe FX: before and after cards on /fx and the Fuobe FX menu

Adarsh3ba7d0ab5c5b
diff --git a/src/app/fx-compare.css b/src/app/fx-compare.css
new file mode 100644
index 00000000..afd78d75
--- /dev/null
+++ b/src/app/fx-compare.css
@@ -0,0 +1,284 @@
+/*
+ * Fuobe FX's before/after cards (components/fx/fx-compare.tsx). The divider's place is one variable, --fxc-pos, set by
+ * the pointer (once a frame) or a key: the after is cut there with clip-path and the hairline moves by transform, so a
+ * hover never lays anything out. States are data attributes on the card: data-show (rest, after, before: a tap),
+ * data-hover (a mouse over it), data-follow (the divider is under the mouse: no easing), data-armed (its hover files
+ * are asked for), data-ready (they came). In @layer components, so a
+ * card's own utilities (its size, its corners) win.
+ */
+@layer components {
+ .fxc {
+ --fxc-pos: 35%;
+ --fxc-ease: cubic-bezier(0.2, 0, 0, 1);
+ --fxc-check-a: oklch(0.94 0 0);
+ --fxc-check-b: oklch(0.99 0 0);
+ position: relative;
+ display: block;
+ overflow: hidden;
+ isolation: isolate;
+ background: var(--muted);
+ contain: paint;
+ -webkit-user-select: none;
+ user-select: none;
+ -webkit-tap-highlight-color: transparent;
+ }
+ .dark .fxc {
+ --fxc-check-a: oklch(0.27 0.003 286);
+ --fxc-check-b: oklch(0.22 0.003 286);
+ }
+ .fxc img {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ -webkit-user-drag: none;
+ }
+
+ /* The after, cut at the divider. */
+ .fxc-after {
+ position: absolute;
+ inset: 0;
+ clip-path: inset(0 0 0 var(--fxc-pos));
+ transition: clip-path 260ms var(--fxc-ease);
+ }
+ .fxc[data-follow] .fxc-after,
+ .fxc[data-follow] .fxc-line {
+ transition: none;
+ }
+ /* A cut-out sits on a transparency checkerboard. */
+ .fxc[data-fxc="matte"] .fxc-after {
+ background: repeating-conic-gradient(var(--fxc-check-a) 0 25%, var(--fxc-check-b) 0 50%) 0 0 / 14px 14px;
+ }
+
+ /* The divider: a full-width layer shifted by --fxc-pos, with a hairline at its left edge. */
+ .fxc-line {
+ position: absolute;
+ inset: 0;
+ pointer-events: none;
+ transform: translateX(var(--fxc-pos));
+ transition: transform 260ms var(--fxc-ease), opacity 160ms;
+ }
+ .fxc-line::before {
+ content: "";
+ position: absolute;
+ inset-block: 0;
+ left: -0.75px;
+ width: 1.5px;
+ background: white;
+ box-shadow: 0 0 4px rgb(0 0 0 / 40%);
+ }
+ .fxc[data-show="after"] .fxc-line,
+ .fxc[data-show="before"] .fxc-line {
+ opacity: 0;
+ }
+
+ /* "Before" and "After": tiny, on a glass chip; the side a tap shows is the one lit. */
+ .fxc-tag {
+ position: absolute;
+ top: 6px;
+ z-index: 2;
+ padding: 0 5px;
+ border-radius: 4px;
+ background: rgb(0 0 0 / 52%);
+ color: rgb(255 255 255 / 92%);
+ font-size: 10px;
+ line-height: 16px;
+ font-weight: 500;
+ letter-spacing: 0.01em;
+ pointer-events: none;
+ -webkit-backdrop-filter: blur(6px);
+ backdrop-filter: blur(6px);
+ transition: opacity 160ms;
+ }
+ .fxc-tag[data-side="before"] {
+ left: 6px;
+ }
+ .fxc-tag[data-side="after"] {
+ right: 6px;
+ }
+ .fxc[data-show="after"] .fxc-tag[data-side="before"],
+ .fxc[data-show="before"] .fxc-tag[data-side="after"] {
+ opacity: 0;
+ }
+
+ /* Loupe: a lens under the mouse, the soft before detail on its left half and the sharp after on its right. */
+ .fxc-lens {
+ --fxc-lens: 104px;
+ position: absolute;
+ top: 0;
+ left: 0;
+ z-index: 3;
+ width: var(--fxc-lens);
+ height: var(--fxc-lens);
+ margin: calc(var(--fxc-lens) / -2) 0 0 calc(var(--fxc-lens) / -2);
+ border-radius: 50%;
+ overflow: hidden;
+ background: var(--muted);
+ box-shadow:
+ 0 0 0 1.5px white,
+ 0 6px 18px rgb(0 0 0 / 35%);
+ pointer-events: none;
+ opacity: 0;
+ scale: 0.92;
+ transform: translate(var(--fxc-x, 0px), var(--fxc-y, 0px));
+ transition: opacity 140ms, scale 140ms;
+ }
+ .fxc[data-ready][data-hover] .fxc-lens,
+ .fxc[data-ready][data-show="after"] .fxc-lens {
+ opacity: 1;
+ scale: 1;
+ }
+ .fxc-lens-detail {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: calc(var(--fxc-lens) * 2);
+ height: calc(var(--fxc-lens) * 2);
+ transform: translate(var(--fxc-dx, 0px), var(--fxc-dy, 0px));
+ }
+ .fxc .fxc-lens-detail img {
+ object-fit: fill;
+ }
+ .fxc-lens-detail[data-side="after"] {
+ clip-path: inset(0 0 0 calc(var(--fxc-lens) / 2 - var(--fxc-dx, 0px)));
+ }
+ .fxc-lens::after {
+ content: "";
+ position: absolute;
+ inset-block: 0;
+ left: calc(50% - 0.5px);
+ width: 1px;
+ background: rgb(255 255 255 / 85%);
+ }
+
+ /*
+ * Reframe: the wide still with the tall crop's box outlined; the outside dims on hover or a tap. The still fills a card
+ * of any shape (the menu's cards get shorter on a short window) and keeps the box in view: as wide as the card or as
+ * tall as it, whichever covers it, shifted to centre the box where the still allows.
+ */
+ .fxc[data-fxc="reframe"] {
+ container-type: size;
+ }
+ .fxc-wide {
+ --fxc-w: max(100cqw, 177.7778cqh);
+ --fxc-h: max(100cqh, 56.25cqw);
+ position: absolute;
+ width: var(--fxc-w);
+ height: var(--fxc-h);
+ left: clamp(calc(100cqw - var(--fxc-w)), calc(50cqw - var(--fxc-cx) * var(--fxc-w)), 0px);
+ top: clamp(calc(100cqh - var(--fxc-h)), calc(50cqh - var(--fxc-cy) * var(--fxc-h)), 0px);
+ }
+ .fxc-rect,
+ .fxc-shade {
+ left: var(--fxc-rx);
+ top: var(--fxc-ry);
+ width: var(--fxc-rw);
+ height: var(--fxc-rh);
+ }
+ .fxc-rect .fxc-tag {
+ top: auto;
+ bottom: 6px;
+ left: 50%;
+ translate: -50% 0;
+ }
+ .fxc-rect,
+ .fxc-shade {
+ position: absolute;
+ z-index: 1;
+ pointer-events: none;
+ }
+ .fxc-rect {
+ outline: 1.5px solid white;
+ outline-offset: -0.75px;
+ border-radius: 2px;
+ }
+ /* The box itself, clear, with everything around it shaded (its shadow reaches past the card, which clips it). */
+ .fxc-shade {
+ box-shadow: 0 0 0 100vmax rgb(0 0 0 / 58%);
+ opacity: 0.32;
+ transition: opacity 220ms var(--fxc-ease);
+ }
+ .fxc[data-hover] .fxc-shade,
+ .fxc[data-show="after"] .fxc-shade {
+ opacity: 1;
+ }
+
+ /* Strip: a flipbook of the output's frames, stepped while a mouse is over it (or after a tap); frame 1 at rest. */
+ .fxc-strip {
+ position: absolute;
+ inset: 0;
+ overflow: hidden;
+ opacity: 0;
+ }
+ .fxc[data-ready] .fxc-strip {
+ opacity: 1;
+ }
+ .fxc .fxc-strip img {
+ width: calc(100% * var(--fxc-frames, 6));
+ max-width: none;
+ right: auto;
+ object-fit: fill;
+ transform: translateX(var(--fxc-shift, 0%));
+ }
+ .fxc[data-ready][data-hover] .fxc-strip img,
+ .fxc[data-ready][data-show="after"] .fxc-strip img {
+ animation: fxc-flip var(--fxc-flip, 1.1s) steps(var(--fxc-frames, 6), jump-none) infinite;
+ }
+ @keyframes fxc-flip {
+ from {
+ transform: translateX(0%);
+ }
+ to {
+ transform: translateX(var(--fxc-last, -83.3333%));
+ }
+ }
+ /* Its frames as ticks along the bottom: the first lit at rest, all of them while it plays. */
+ .fxc-ticks {
+ position: absolute;
+ left: 8px;
+ right: 8px;
+ bottom: 7px;
+ z-index: 2;
+ display: flex;
+ gap: 3px;
+ pointer-events: none;
+ }
+ .fxc-ticks i {
+ flex: 1;
+ height: 2px;
+ border-radius: 1px;
+ background: rgb(255 255 255 / 38%);
+ box-shadow: 0 0 3px rgb(0 0 0 / 30%);
+ }
+ .fxc-ticks i:first-child,
+ .fxc[data-ready][data-hover] .fxc-ticks i,
+ .fxc[data-ready][data-show="after"] .fxc-ticks i {
+ background: white;
+ }
+
+ /* Less motion: nothing eases or plays by itself; a tap or a key still shows the other side (a still frame for a strip). */
+ @media (prefers-reduced-motion: reduce) {
+ .fxc-after,
+ .fxc-line,
+ .fxc-tag,
+ .fxc-lens,
+ .fxc-shade {
+ transition: none;
+ }
+ .fxc[data-ready][data-hover] .fxc-strip img,
+ .fxc[data-ready][data-show="after"] .fxc-strip img {
+ animation: none;
+ }
+ /* A tap shows the last frame, still; a hover alone shows nothing new. */
+ .fxc[data-ready][data-show="after"] .fxc-strip img {
+ transform: translateX(var(--fxc-last, -83.3333%));
+ }
+ .fxc[data-ready][data-hover]:not([data-show="after"]) .fxc-ticks i:not(:first-child) {
+ background: rgb(255 255 255 / 38%);
+ }
+ .fxc[data-hover]:not([data-show="after"]) .fxc-shade {
+ opacity: 0.32;
+ }
+ }
+}
diff --git a/src/app/globals.css b/src/app/globals.css
index f52e9125..cf3e5461 100644
--- a/src/app/globals.css
+++ b/src/app/globals.css
@@ -5,6 +5,7 @@
@import "./nav-subs.css";
@import "./motion.css";
@import "./tab-row.css";
+@import "./fx-compare.css";
@custom-variant dark (&:is(.dark *));
/* Hover for the app frame's controls: like hover:, but only while the mouse leads (nav-states.css), so a control under a
diff --git a/src/components/fx/fx-card.tsx b/src/components/fx/fx-card.tsx
new file mode 100644
index 00000000..81edf125
--- /dev/null
+++ b/src/components/fx/fx-card.tsx
@@ -0,0 +1,21 @@
+import { CardPending, IntentLink } from "@/components/intent-link";
+import { StudioName } from "@/components/home/home-islands";
+import { FxCompare } from "@/components/fx/fx-compare";
+import type { FxView } from "@/lib/fx-compare";
+
+/**
+ * A Fuobe FX item's card with its before and after (FxCompare) in place of a cover: the same frame, name and line as a
+ * studio's card beside it. The focused card's arrow keys move its divider; a finger's tap on the picture shows the
+ * other side, and the name opens the page.
+ */
+export function FxCard({ href, label, line, view, sizes }: { href: string; label: string; line: string; view: FxView; sizes: string }) {
+ return (
+ <IntentLink href={href} className="group/studio flex min-w-0 flex-col gap-2 rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring">
+ <span className="relative isolate block aspect-[4/3] overflow-hidden rounded-lg bg-muted">
+ <FxCompare view={view} sizes={sizes} keys className="absolute inset-0" />
+ <CardPending />
+ </span>
+ <StudioName label={label} line={line} />
+ </IntentLink>
+ );
+}
diff --git a/src/components/fx/fx-compare.tsx b/src/components/fx/fx-compare.tsx
new file mode 100644
index 00000000..96fda20b
--- /dev/null
+++ b/src/components/fx/fx-compare.tsx
@@ -0,0 +1,285 @@
+"use client";
+
+import { useEffect, useRef, useState } from "react";
+import {
+ FX_REST,
+ followsPointer,
+ fxLoupeSources,
+ fxSources,
+ fxStripSrc,
+ fxWideSources,
+ hoverFiles,
+ keyPos,
+ LENS,
+ LENS_DETAIL,
+ lensHome,
+ loupePan,
+ nextShow,
+ posAt,
+ reframeVars,
+ showPos,
+ stripFrames,
+ stripShift,
+ tapToggles,
+ type FxShow,
+ type FxView,
+} from "@/lib/fx-compare";
+import { reducedMotion } from "@/lib/ui-motion";
+import { cn } from "@/lib/utils";
+
+/*
+ * A Fuobe FX item's before and after, as its card's picture (the /fx page, the Fuobe FX menu). Stills only, at rest a
+ * still split with a hairline and tiny "Before" and "After" tags (fx-compare.css draws every state):
+ * pair, depth a mouse moves the divider; the after (a depth pass for depth) is cut there
+ * matte the same, the cut-out on a transparency checkerboard
+ * loupe a lens under the mouse: the soft before detail on its left, the sharp after on its right
+ * reframe the wide still with the tall crop's box outlined; the outside dims under the mouse
+ * strip frame 1; under the mouse, the output's frames as a flipbook
+ * A finger's tap shows the after, the next the before (the card's name still opens the page). With reduced motion the
+ * divider stays put and nothing plays: a tap still toggles. `keys`: the arrow keys on the focused card (its link) move
+ * the divider, step the flipbook or show the crop (off in the menu, whose arrow keys move between links).
+ *
+ * The pointer only sets CSS variables, once a frame: a hover never lays anything out. The lens's details and the
+ * flipbook's frames are asked for only once the card is pointed at, tapped or keyed.
+ */
+
+interface Props {
+ view: FxView;
+ /** The box's width for the srcsets (the 480 or the 960 copy). */
+ sizes: string;
+ /** Load at rest at once (a menu about to open) instead of when it comes near the screen. */
+ eager?: boolean;
+ keys?: boolean;
+ className?: string;
+}
+
+/** One side at its two sizes, AVIF first, else WebP. */
+function Side({ view, side, sizes, eager }: { view: FxView; side: "before" | "after"; sizes: string; eager?: boolean }) {
+ const s = fxSources(view, side);
+ return (
+ <picture>
+ <source type="image/avif" srcSet={s.avif} sizes={sizes} />
+ <img src={s.src} srcSet={s.webp} sizes={sizes} width={480} height={360} alt="" loading={eager ? "eager" : "lazy"} decoding="async" draggable={false} />
+ </picture>
+ );
+}
+
+function Tags() {
+ return (
+ <>
+ <span className="fxc-tag" data-side="before">
+ Before
+ </span>
+ <span className="fxc-tag" data-side="after">
+ After
+ </span>
+ </>
+ );
+}
+
+export function FxCompare({ view, sizes, eager, keys, className }: Props) {
+ const ref = useRef<HTMLSpanElement>(null);
+ const [show, setShow] = useState<FxShow>("rest");
+ /** Its hover files are asked for (the lens's details, the flipbook's frames). */
+ const [armed, setArmed] = useState(false);
+ const [ready, setReady] = useState(false);
+ const loaded = useRef(0);
+ const pos = useRef(FX_REST);
+ const at = useRef<{ x: number; y: number } | null>(null);
+ const raf = useRef(0);
+ const pointer = useRef("mouse");
+ const stripAt = useRef(0);
+ const showRef = useRef(show);
+ const kind = view.kind;
+ const divides = kind === "pair" || kind === "depth" || kind === "matte" || kind === "loupe";
+ const extra = hoverFiles(view).length;
+ const frames = stripFrames(view);
+
+ const setPos = (n: number) => {
+ pos.current = n;
+ ref.current?.style.setProperty("--fxc-pos", `${n}%`);
+ };
+ const arm = () => {
+ if (extra) setArmed(true);
+ };
+ const oneLoaded = () => {
+ loaded.current += 1;
+ if (loaded.current >= extra) setReady(true);
+ };
+
+ // A tap's side: the divider goes all the way (or back to rest); the lens sits over the loupe's own place.
+ useEffect(() => {
+ showRef.current = show;
+ const el = ref.current;
+ if (!el) return;
+ if (divides) setPos(showPos(show));
+ if (kind === "loupe" && show === "after") {
+ const [x, y] = lensHome(view.loupe, el.clientWidth, el.clientHeight);
+ const [dx, dy] = loupePan(0.5, 0.5, LENS_DETAIL, LENS);
+ el.style.setProperty("--fxc-x", `${x}px`);
+ el.style.setProperty("--fxc-y", `${y}px`);
+ el.style.setProperty("--fxc-dx", `${dx}px`);
+ el.style.setProperty("--fxc-dy", `${dy}px`);
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- only a new side moves it
+ }, [show]);
+
+ // The arrow keys on the focused card (its link), where its list doesn't use them itself.
+ useEffect(() => {
+ const el = ref.current;
+ const card = keys ? el?.closest("a") : null;
+ if (!el || !card) return;
+ const onKey = (e: KeyboardEvent) => {
+ if (e.altKey || e.ctrlKey || e.metaKey || (e.key !== "ArrowLeft" && e.key !== "ArrowRight")) return;
+ e.preventDefault();
+ if (extra) setArmed(true);
+ if (kind === "strip") {
+ stripAt.current = Math.min(frames - 1, Math.max(0, stripAt.current + (e.key === "ArrowRight" ? 1 : -1)));
+ el.style.setProperty("--fxc-shift", `${stripShift(stripAt.current, frames)}%`);
+ } else if (kind === "reframe") setShow(e.key === "ArrowRight" ? "after" : "rest");
+ else {
+ const next = keyPos(pos.current, e.key, e.shiftKey);
+ if (next !== null) setPos(next);
+ }
+ };
+ card.addEventListener("keydown", onKey);
+ return () => card.removeEventListener("keydown", onKey);
+ }, [keys, kind, extra, frames]);
+
+ useEffect(() => () => cancelAnimationFrame(raf.current), []);
+
+ /** The pointer's latest place, applied once a frame: the divider, or the lens and its detail. */
+ const apply = () => {
+ raf.current = 0;
+ const el = ref.current;
+ const p = at.current;
+ if (!el || !p) return;
+ const r = el.getBoundingClientRect();
+ if (kind === "loupe") {
+ const x = p.x - r.left;
+ const y = p.y - r.top;
+ const [dx, dy] = loupePan(x / r.width, y / r.height, LENS_DETAIL, LENS);
+ el.style.setProperty("--fxc-x", `${x}px`);
+ el.style.setProperty("--fxc-y", `${y}px`);
+ el.style.setProperty("--fxc-dx", `${dx}px`);
+ el.style.setProperty("--fxc-dy", `${dy}px`);
+ } else if (divides) setPos(posAt(p.x, r.left, r.width));
+ };
+
+ const onPointerEnter = (e: React.PointerEvent) => {
+ pointer.current = e.pointerType;
+ if (!followsPointer(e.pointerType, reducedMotion())) return;
+ const el = ref.current!;
+ arm();
+ if (showRef.current !== "rest") setShow("rest");
+ el.dataset.hover = "";
+ if (kind !== "loupe" && divides) el.dataset.follow = "";
+ };
+ const onPointerMove = (e: React.PointerEvent) => {
+ if (!followsPointer(e.pointerType, reducedMotion()) || !divides) return;
+ const el = ref.current!;
+ if (el.dataset.hover === undefined) onPointerEnter(e);
+ at.current = { x: e.clientX, y: e.clientY };
+ if (!raf.current) raf.current = requestAnimationFrame(apply);
+ };
+ const onPointerLeave = () => {
+ const el = ref.current;
+ if (!el) return;
+ cancelAnimationFrame(raf.current);
+ raf.current = 0;
+ delete el.dataset.hover;
+ delete el.dataset.follow;
+ if (divides) setPos(showPos(showRef.current));
+ };
+
+ return (
+ <span
+ ref={ref}
+ aria-hidden
+ data-fxc={kind}
+ data-fx-id={view.id}
+ data-show={show}
+ data-armed={armed ? "" : undefined}
+ data-ready={ready ? "" : undefined}
+ className={cn("fxc", className)}
+ style={
+ kind === "reframe"
+ ? (reframeVars(view.rect) as React.CSSProperties)
+ : kind === "strip"
+ ? ({ "--fxc-frames": frames, "--fxc-last": `${stripShift(frames - 1, frames)}%` } as React.CSSProperties)
+ : undefined
+ }
+ onPointerEnter={onPointerEnter}
+ onPointerMove={onPointerMove}
+ onPointerLeave={onPointerLeave}
+ onPointerDown={(e) => {
+ pointer.current = e.pointerType;
+ }}
+ onClick={(e) => {
+ // A finger's tap shows the other side; the card's name opens its page. A mouse's click opens it as ever.
+ if (!tapToggles(pointer.current)) return;
+ e.preventDefault();
+ arm();
+ setShow((s) => nextShow(s));
+ }}
+ >
+ {kind === "reframe" ? (
+ <span className="fxc-wide">
+ {/* eslint-disable-next-line @next/next/no-img-element -- versioned static still */}
+ <img
+ src={fxWideSources(view).src}
+ srcSet={fxWideSources(view).webp}
+ sizes={sizes}
+ width={480}
+ height={270}
+ alt=""
+ loading={eager ? "eager" : "lazy"}
+ decoding="async"
+ draggable={false}
+ />
+ <span className="fxc-shade" />
+ <span className="fxc-rect">
+ <span className="fxc-tag">9:16</span>
+ </span>
+ </span>
+ ) : kind === "strip" ? (
+ <>
+ <Side view={view} side="before" sizes={sizes} eager={eager} />
+ {armed && (
+ <span className="fxc-strip">
+ {/* eslint-disable-next-line @next/next/no-img-element -- the flipbook's frames, asked for on hover only */}
+ <img src={fxStripSrc(view)} width={480 * frames} height={360} alt="" decoding="async" draggable={false} onLoad={oneLoaded} onError={oneLoaded} />
+ </span>
+ )}
+ <span className="fxc-ticks">
+ {Array.from({ length: frames }, (_, i) => (
+ <i key={i} />
+ ))}
+ </span>
+ </>
+ ) : (
+ <>
+ <Side view={view} side="before" sizes={sizes} eager={eager} />
+ <span className="fxc-after">
+ <Side view={view} side="after" sizes={sizes} eager={eager} />
+ </span>
+ <span className="fxc-line" />
+ <Tags />
+ {kind === "loupe" && armed && (
+ <span className="fxc-lens">
+ {(["before", "after"] as const).map((side) => {
+ const s = fxLoupeSources(view, side);
+ return (
+ <span key={side} className="fxc-lens-detail" data-side={side}>
+ {/* eslint-disable-next-line @next/next/no-img-element -- the lens's detail, asked for on hover only */}
+ <img src={s.src} srcSet={s.srcSet} sizes={`${LENS_DETAIL}px`} width={240} height={240} alt="" decoding="async" draggable={false} onLoad={oneLoaded} onError={oneLoaded} />
+ </span>
+ );
+ })}
+ </span>
+ )}
+ </>
+ )}
+ </span>
+ );
+}
diff --git a/src/components/home/home-sections.tsx b/src/components/home/home-sections.tsx
index 23873ea8..13b22333 100644
--- a/src/components/home/home-sections.tsx
+++ b/src/components/home/home-sections.tsx
@@ -3,6 +3,7 @@ import { Fragment } from "react";
import { ArrowRight, AudioLines, Box, CalendarClock, ImageIcon, ListChecks, Plug, ScanEye, Sparkles, TextCursorInput, Undo2, Video, Zap, type LucideIcon } from "lucide-react";
import { GitHubMark } from "@/components/github-mark";
import { BeforeAfter } from "@/components/home/before-after";
+import { FxCard } from "@/components/fx/fx-card";
import {
AssistAction,
AssistExamples,
@@ -33,6 +34,7 @@ import { staggered, type AutoPlay } from "@/lib/preview-playback";
import { cn } from "@/lib/utils";
import { plainTagline } from "@/lib/plain-tagline";
import type { PresetCardData } from "@/lib/preset-cards";
+import type { FxView } from "@/lib/fx-compare";
/*
* Home's sections under the wall. Server components: their words, numbers and links ship as HTML, and only the
@@ -354,6 +356,8 @@ export interface Destination {
line: string;
card?: HomeShowcase["studios"][number]["card"];
drawn?: "live";
+ /** A Fuobe FX item's before and after, shown in place of its cover (FxCard). */
+ fx?: FxView;
}
/** A pill under the cards: its name, and its icon from the navigation. */
@@ -413,7 +417,9 @@ export function DestinationsSection({
}) {
const items = cards.map((s, i) => (
<div key={s.href} className={grid ? "min-w-0" : cn(RAIL_ITEM, sm !== undefined && i >= sm && "sm:max-lg:hidden")}>
- {s.card ? (
+ {s.fx ? (
+ <FxCard href={s.href} label={s.label} line={s.line} view={s.fx} sizes={grid ? GRID_SIZES : STUDIO_SIZES} />
+ ) : s.card ? (
<StudioCard
href={s.href}
label={s.label}
diff --git a/src/components/nav/mega-panel.tsx b/src/components/nav/mega-panel.tsx
index 45cba091..74a08c64 100644
--- a/src/components/nav/mega-panel.tsx
+++ b/src/components/nav/mega-panel.tsx
@@ -8,7 +8,8 @@ import { Kbd } from "@/components/ui/kbd";
import { MEGA_AREAS, ROW_CAPS, studiosMenu, TILE_COLS, type MegaColumn, type MegaId, type MegaItem, type MegaModel } from "@/lib/mega-menus";
import { isNew, subParent, type ViewerKind } from "@/lib/nav-model";
import { cn } from "@/lib/utils";
-import { CoverThumb } from "./cover-thumb";
+import { FxCompare } from "@/components/fx/fx-compare";
+import { COVER_SIZES, CoverThumb } from "./cover-thumb";
import { useMegaMenu } from "./mega-data";
import { megaCurrent, MegaSkeleton } from "./mega-launcher";
import { useViewerKind } from "./nav-ui";
@@ -49,6 +50,12 @@ export function trackSizes(span: number, inset = 0): string {
return `(min-width: 1680px) ${Math.floor(((1680 - 108) * span) / 6) + extra}px, calc((100vw - 108px) * ${span} / 6 + ${extra}px)`;
}
+/** A lead card's picture box: 4:3 of the column, its height on the 4 px grid, shorter on a short window. */
+const LEAD_BOX = "h-[round(down,75cqw,4px)] rounded-none md:max-lg:max-h-[round(down,max(56px,calc(100dvh_-_460px)),4px)]";
+const LEAD_MAX = "max-h-[round(down,max(64px,calc(100dvh_-_592px)),4px)]";
+/** Under the owner's New board button (Canvas). */
+const LEAD_MAX_BELOW = "max-h-[round(down,max(64px,calc(100dvh_-_640px)),4px)]";
+
/**
* A column's first card: its cover, name and one line. `row` 1 under the owner's New board (Canvas), its cover shorter by
* that button. The cover's height is rounded down to the 4 px grid (a 4:3 box of a fractional column width would put
@@ -65,18 +72,20 @@ export function LeadCard({ e, col, row = 0, span = 1, current, inside, now, clas
data-active={inside ? "" : undefined}
className={cn("nav-row group/lead flex flex-col overflow-hidden rounded-[14px] border bg-card text-card-foreground [container-type:inline-size]", className)}
>
- <CoverThumb
- id={e.navCover}
- cover={e.cover}
- size="lead"
- icon={e.icon}
- eager
- sizes={span > 1 ? trackSizes(span, 2) : undefined}
- className={cn(
- "h-[round(down,75cqw,4px)] rounded-none md:max-lg:max-h-[round(down,max(56px,calc(100dvh_-_460px)),4px)]",
- row ? "max-h-[round(down,max(64px,calc(100dvh_-_640px)),4px)]" : "max-h-[round(down,max(64px,calc(100dvh_-_592px)),4px)]",
- )}
- />
+ {/* A Fuobe FX item shows its before and after (the menu's arrow keys stay the menu's: keys off). */}
+ {e.fx ? (
+ <FxCompare view={e.fx} sizes={span > 1 ? trackSizes(span, 2) : COVER_SIZES.lead.sizes} eager className={cn("w-full shrink-0", LEAD_BOX, row ? LEAD_MAX_BELOW : LEAD_MAX)} />
+ ) : (
+ <CoverThumb
+ id={e.navCover}
+ cover={e.cover}
+ size="lead"
+ icon={e.icon}
+ eager
+ sizes={span > 1 ? trackSizes(span, 2) : undefined}
+ className={cn(LEAD_BOX, row ? LEAD_MAX_BELOW : LEAD_MAX)}
+ />
+ )}
<span className="nav-mark-start flex min-w-0 flex-col gap-0.5 px-[11px] pt-2.5 pb-3 md:max-lg:py-2">
<span className="flex min-w-0 items-center gap-1.5">
<span className="truncate text-[14px] leading-[18px] font-semibold md:max-lg:text-[13px]">{e.label}</span>
diff --git a/src/lib/area-showcase.ts b/src/lib/area-showcase.ts
index 4d3cfbda..9fee28a7 100644
--- a/src/lib/area-showcase.ts
+++ b/src/lib/area-showcase.ts
@@ -7,6 +7,7 @@ import "server-only";
import { cacheLife } from "next/cache";
import { APPS, EFFECTS, MOTIONS } from "@/lib/catalog";
import { FX_SECTIONS, fxCardable, fxCover, isFxApp } from "@/lib/fx-tools";
+import { fxView, type FxView } from "@/lib/fx-compare";
import { HOME_EFFECTS, HOME_MOTIONS, HOME_STUDIOS, homeCard, homeShowcase, presetHref, type HomeFacts } from "@/lib/home-showcase";
import { areaCount, areaSections, cardsToShow, PILL_ONLY, rankCards, type AreaId } from "@/lib/nav-areas";
import { entry, NAV_ENTRIES, subLabel, visibleTo, type NavEntry, type ViewerKind } from "@/lib/nav-model";
@@ -24,6 +25,8 @@ export interface AreaCard {
/** Its cover, as Home's cards get it. */
card?: PresetCardData;
drawn?: AreaDrawn;
+ /** A Fuobe FX item's before and after, shown in place of its cover (the items with a pair: fx-pairs.generated.ts). */
+ fx?: FxView;
}
export interface AreaPill {
@@ -236,7 +239,9 @@ export async function fxShowcase() {
// A mode is named with its studio ("Genjutsu · Insert"), so it reads apart from the studios beside it.
const parent = entry(id)?.parent;
const label = parent && entry(parent) ? `${entry(parent)!.label} · ${it.label}` : it.label;
- return { id: it.id, href: it.href, label, line: it.line, card: homeCard(it.cover!) };
+ // An item with a before and after shows them in place of its cover (the cover still ranks it: premium first).
+ const fx = fxView(id);
+ return { id: it.id, href: it.href, label, line: it.line, card: homeCard(it.cover!), ...(fx && { fx }) };
}),
pills: s.pills.map(pillOf),
ownerPills: ownerOnly.map(pillOf),
diff --git a/src/lib/fx-compare.ts b/src/lib/fx-compare.ts
new file mode 100644
index 00000000..135ef643
--- /dev/null
+++ b/src/lib/fx-compare.ts
@@ -0,0 +1,136 @@
+/**
+ * Fuobe FX's before/after cards, as data and pure helpers (no DOM), so the card component (components/fx/fx-compare.tsx),
+ * the server's page and menu, and the tests share them. An item's pair files are in public/previews/fx/<id>/
+ * (fx-pairs.generated.ts says what each holds); an item without a pair keeps its own cover.
+ */
+import { FX_PAIRS, fxPairSrc, type FxPair } from "./fx-pairs.generated";
+
+/** An item's pair as a card takes it (serializable: the page and the menu file carry it). */
+export interface FxView extends FxPair {
+ id: string;
+}
+
+/** The pair a card shows for an FX item, or undefined: it keeps its own cover. */
+export function fxView(id: string): FxView | undefined {
+ const p = FX_PAIRS[id];
+ return p ? { id, ...p } : undefined;
+}
+
+/** Where the divider rests: the before on the left 35 %, the after on the right 65 %. */
+export const FX_REST = 35;
+
+/** How far one arrow key moves the divider (Shift: a bigger step). */
+export const FX_STEP = 5;
+export const FX_BIG_STEP = 25;
+
+export const clampPos = (n: number) => Math.min(100, Math.max(0, n));
+
+/** The divider's place (0 to 100) under a pointer at clientX in a box from `left`, `width` wide. */
+export function posAt(clientX: number, left: number, width: number): number {
+ if (!(width > 0)) return FX_REST;
+ return clampPos(((clientX - left) / width) * 100);
+}
+
+/** Where an arrow key moves the divider from `pos`; null for any other key (it keeps its usual job). */
+export function keyPos(pos: number, key: string, shift = false): number | null {
+ const step = shift ? FX_BIG_STEP : FX_STEP;
+ if (key === "ArrowLeft") return clampPos(pos - step);
+ if (key === "ArrowRight") return clampPos(pos + step);
+ return null;
+}
+
+/**
+ * What a card shows: at rest (the split, frame 1, the box outlined), or after a tap on a touch screen "after" (the whole
+ * after; the flipbook playing; the outside dimmed; the loupe out) and then "before", each tap the other.
+ */
+export type FxShow = "rest" | "after" | "before";
+
+export const nextShow = (s: FxShow): FxShow => (s === "after" ? "before" : "after");
+
+/** The divider's place for what is shown: the split at rest, all after (0) or all before (100). */
+export const showPos = (s: FxShow, rest = FX_REST) => (s === "after" ? 0 : s === "before" ? 100 : rest);
+
+/** Whether a card's divider follows the pointer: a mouse, and motion allowed. A finger taps; reduced motion stays still. */
+export const followsPointer = (pointerType: string, reduced: boolean) => pointerType === "mouse" && !reduced;
+
+/** Whether a tap toggles the card instead of opening its page: a touch screen's finger or pen. */
+export const tapToggles = (pointerType: string) => pointerType === "touch" || pointerType === "pen";
+
+/** A side's files: AVIF and WebP srcsets (480 and 960 px wide), and the 480 px WebP as the fallback src. */
+export interface FxSources {
+ avif: string;
+ webp: string;
+ src: string;
+}
+
+export function fxSources(v: FxView, side: "before" | "after"): FxSources {
+ const at = (f: string) => fxPairSrc(v.id, f)!;
+ return {
+ avif: `${at(`${side}.480.avif`)} 480w, ${at(`${side}.960.avif`)} 960w`,
+ webp: `${at(`${side}.480.webp`)} 480w, ${at(`${side}.960.webp`)} 960w`,
+ src: at(`${side}.480.webp`),
+ };
+}
+
+/** Reframe's 16:9 still (WebP only). */
+export function fxWideSources(v: FxView): { webp: string; src: string } {
+ const at = (f: string) => fxPairSrc(v.id, f)!;
+ return { webp: `${at("wide.480.webp")} 480w, ${at("wide.960.webp")} 960w`, src: at("wide.480.webp") };
+}
+
+/** The loupe's detail of one side: 240 px, and 480 px for a 2x screen. */
+export function fxLoupeSources(v: FxView, side: "before" | "after"): { srcSet: string; src: string } {
+ const at = (f: string) => fxPairSrc(v.id, f)!;
+ return { srcSet: `${at(`${side}.loupe.webp`)} 240w, ${at(`${side}.loupe2x.webp`)} 480w`, src: at(`${side}.loupe.webp`) };
+}
+
+/** The flipbook's sprite: the output's frames side by side, 480x360 each. */
+export const fxStripSrc = (v: FxView) => fxPairSrc(v.id, "strip.webp")!;
+
+/** How many frames a strip has (6 unless it says). */
+export const stripFrames = (v: FxView) => v.frames ?? 6;
+
+/** A frame of the strip as the sprite's shift (a fraction of its own width, so a CSS translateX percentage). */
+export const stripShift = (frame: number, frames: number) => -(Math.min(Math.max(0, Math.round(frame)), frames - 1) / frames) * 100;
+
+/** The files a card loads at rest, before anyone points at it (what the menu's first open costs). */
+export function restFiles(v: FxView): string[] {
+ if (v.kind === "reframe") return ["wide.480.webp"];
+ if (v.kind === "strip") return ["before.480.avif"];
+ return ["before.480.avif", "after.480.avif"];
+}
+
+/** The files a card loads only once it is pointed at or tapped (the loupe's details, the flipbook's sprite). */
+export function hoverFiles(v: FxView): string[] {
+ if (v.kind === "loupe") return ["before.loupe.webp", "after.loupe.webp"];
+ if (v.kind === "strip") return ["strip.webp"];
+ return [];
+}
+
+/**
+ * Reframe's layout as CSS variables: the crop's box (percent of the wide still) and its centre (fractions), which the
+ * stylesheet uses to fill a card of any shape with the still and keep the box in view, centred where it can be.
+ */
+export function reframeVars(rect: readonly [number, number, number, number] | undefined): Record<string, string> {
+ const [x, y, w, h] = rect ?? [0.34, 0, 0.32, 1];
+ const pct = (n: number) => `${Math.round(n * 1000000) / 10000}%`;
+ const frac = (n: number) => String(Math.round(n * 10000) / 10000);
+ return { "--fxc-rx": pct(x), "--fxc-ry": pct(y), "--fxc-rw": pct(w), "--fxc-rh": pct(h), "--fxc-cx": frac(x + w / 2), "--fxc-cy": frac(y + h / 2) };
+}
+
+/** The loupe's lens and its detail (CSS px): the detail is twice the lens, panned with the pointer. */
+export const LENS = 104;
+export const LENS_DETAIL = LENS * 2;
+
+/** Where the lens sits after a tap (no pointer to follow): over the loupe's own place in the frame, in px of a w x h card. */
+export function lensHome(loupe: readonly [number, number, number, number] | undefined, w: number, h: number): [number, number] {
+ const [x, y, lw, lh] = loupe ?? [0.4, 0.4, 0.2, 0.2];
+ return [Math.round((x + lw / 2) * w), Math.round((y + lh / 2) * h)];
+}
+
+/** The loupe's detail panned with the pointer: its shift (px) so the pointer's place in the card is that place in the detail. */
+export function loupePan(u: number, v: number, detail: number, lens: number): [number, number] {
+ const k = Math.max(0, detail - lens);
+ const c = (n: number) => Math.min(1, Math.max(0, n));
+ return [-Math.round(c(u) * k), -Math.round(c(v) * k)];
+}
diff --git a/src/lib/mega-menus.server.ts b/src/lib/mega-menus.server.ts
index 997258c4..1f442a9e 100644
--- a/src/lib/mega-menus.server.ts
+++ b/src/lib/mega-menus.server.ts
@@ -25,6 +25,7 @@ import { templateStillSources } from "@/lib/template-hd";
import { MENU_LINES } from "@/lib/menu-lines";
import { fxSections } from "@/lib/area-showcase";
import { FX_SECTIONS, fxCover, isFxApp } from "@/lib/fx-tools";
+import { fxView } from "@/lib/fx-compare";
import { entry } from "@/lib/nav-model";
/** A column of a preset menu: its name, its phone chip, and the catalog categories it holds. */
@@ -259,6 +260,7 @@ function fxMenuItem(id: string): MegaItem | undefined {
const mine = fxCover(id);
const own = mine ? presetMegaCover(mine) : undefined;
const nav = own ? undefined : (mine ?? e.cover);
+ const fx = fxView(id);
return {
id,
href: e.href,
@@ -268,6 +270,7 @@ function fxMenuItem(id: string): MegaItem | undefined {
icon: e.icon,
...(own && { cover: own }),
...(nav && { navCover: nav }),
+ ...(fx && { fx }),
...(e.short && { short: e.short }),
...(e.newUntil && { newUntil: e.newUntil }),
};
@@ -299,7 +302,8 @@ export function fxMenu(): MegaModel {
.map(named);
// The lead card is the first with a picture (a section of pills only leads with its first tool that has one).
const lead = items.find((x) => x.cover || x.navCover) ?? items[0];
- const rest = items.filter((x) => x !== lead);
+ // Rows show their small cover: only the lead card shows a before and after, so only it carries one.
+ const rest = items.filter((x) => x !== lead).map((x) => (x.fx ? { ...x, fx: undefined } : x));
return { id: s.id, label: s.title, chip: FX_SECTIONS.find((x) => x.id === s.id)!.chip, ...(lead && { lead }), rows: rest.slice(0, ROW_CAPS.tall) };
}),
};
diff --git a/src/lib/mega-menus.ts b/src/lib/mega-menus.ts
index 6abf6bae..f8578d47 100644
--- a/src/lib/mega-menus.ts
+++ b/src/lib/mega-menus.ts
@@ -5,6 +5,7 @@
* covers (mega-menus.server.ts) and fetched as small static files (/nav-menus/<id>) the first time a menu warms.
*/
import type { CoverFraming } from "./cover-framing";
+import type { FxView } from "./fx-compare";
import { area } from "./nav-areas";
import type { StillSources } from "./preset-hd";
import { entriesFor, launcherColumns, studioCount, studioSubs, STUDIO_SUBS, subLabel, subParent, type NavEntry, type NavIconName, type ViewerKind } from "./nav-model";
@@ -46,6 +47,8 @@ export interface MegaItem {
cover?: MegaCover;
/** Its cover as a preset id the nav's covers resolve (Studios: useNavCover). */
navCover?: string;
+ /** A Fuobe FX item's before and after: its lead card shows them in place of the cover (rows and tiles keep the cover). */
+ fx?: FxView;
/** Shown on the muted fill when there is no cover. */
icon?: NavIconName;
/** A phone tile's name (12 characters at most). */
diff --git a/tests/fx-compare.test.ts b/tests/fx-compare.test.ts
new file mode 100644
index 00000000..2e5ebd11
--- /dev/null
+++ b/tests/fx-compare.test.ts
@@ -0,0 +1,195 @@
+import fs from "node:fs";
+import path from "node:path";
+import { describe, expect, it, vi } from "vitest";
+import {
+ FX_REST,
+ followsPointer,
+ fxLoupeSources,
+ fxSources,
+ fxStripSrc,
+ fxView,
+ fxWideSources,
+ hoverFiles,
+ keyPos,
+ LENS,
+ LENS_DETAIL,
+ lensHome,
+ loupePan,
+ nextShow,
+ posAt,
+ reframeVars,
+ restFiles,
+ showPos,
+ stripShift,
+ tapToggles,
+} from "@/lib/fx-compare";
+import { FX_PAIRS } from "@/lib/fx-pairs.generated";
+import { fxSections, fxShowcase } from "@/lib/area-showcase";
+import { fxMenu } from "@/lib/mega-menus.server";
+import { megaItems, packMenu, unpackMenu } from "@/lib/mega-menus";
+
+// area-showcase.ts caches its showcases (next/cache), which only a build provides.
+vi.mock("next/cache", () => ({ cacheLife: () => {} }));
+
+const file = (url: string) => path.join(process.cwd(), "public", url.split("?")[0]);
+const css = fs.readFileSync(path.join(process.cwd(), "src", "app", "fx-compare.css"), "utf8");
+
+describe("Fuobe FX before/after cards: the pairs", () => {
+ it("gives an item with a pair its view, and none to an item without one (it keeps its cover)", () => {
+ expect(fxView("video-tools-depth")).toMatchObject({ id: "video-tools-depth", kind: "depth" });
+ expect(fxView("upscale-hdr")).toBeUndefined();
+ expect(fxView("no-such-item")).toBeUndefined();
+ });
+
+ it("points every source at a file that exists, versioned, AVIF and WebP at both sizes", () => {
+ for (const id of Object.keys(FX_PAIRS)) {
+ const v = fxView(id)!;
+ const urls: string[] = [];
+ if (v.kind === "reframe") urls.push(...fxWideSources(v).webp.split(", ").map((s) => s.split(" ")[0]));
+ for (const side of ["before", "after"] as const) {
+ const s = fxSources(v, side);
+ expect(s.avif, id).toMatch(/\.480\.avif\?v=[0-9a-f]{8} 480w, .+\.960\.avif\?v=[0-9a-f]{8} 960w$/);
+ urls.push(s.src, ...[s.avif, s.webp].flatMap((x) => x.split(", ").map((y) => y.split(" ")[0])));
+ if (v.kind === "loupe") urls.push(...fxLoupeSources(v, side).srcSet.split(", ").map((y) => y.split(" ")[0]));
+ }
+ if (v.kind === "strip") urls.push(fxStripSrc(v));
+ for (const u of urls) {
+ expect(u, id).toContain(`?v=${v.v}`);
+ expect(fs.existsSync(file(u)), u).toBe(true);
+ }
+ }
+ });
+
+ it("loads only stills at rest, and the lens's details or the flipbook only once pointed at", () => {
+ for (const id of Object.keys(FX_PAIRS)) {
+ const v = fxView(id)!;
+ for (const f of [...restFiles(v), ...hoverFiles(v)]) expect(fs.existsSync(path.join(process.cwd(), "public", "previews", "fx", id, f)), `${id} ${f}`).toBe(true);
+ expect(restFiles(v).some((f) => f.startsWith("strip") || f.includes("loupe")), id).toBe(false);
+ }
+ expect(hoverFiles(fxView("upscale")!)).toEqual(["before.loupe.webp", "after.loupe.webp"]);
+ expect(hoverFiles(fxView("extend")!)).toEqual(["strip.webp"]);
+ expect(restFiles(fxView("extend")!)).toEqual(["before.480.avif"]);
+ expect(restFiles(fxView("reframe")!)).toEqual(["wide.480.webp"]);
+ expect(hoverFiles(fxView("genjutsu")!)).toEqual([]);
+ });
+});
+
+describe("Fuobe FX before/after cards: the divider", () => {
+ it("rests at a 35/65 split, and a tap shows all of one side, then the other", () => {
+ expect(FX_REST).toBe(35);
+ expect(showPos("rest")).toBe(35);
+ expect(nextShow("rest")).toBe("after");
+ expect(nextShow("after")).toBe("before");
+ expect(nextShow("before")).toBe("after");
+ expect(showPos("after")).toBe(0);
+ expect(showPos("before")).toBe(100);
+ });
+
+ it("follows the pointer inside the card, clamped to its edges", () => {
+ expect(posAt(150, 100, 200)).toBe(25);
+ expect(posAt(50, 100, 200)).toBe(0);
+ expect(posAt(400, 100, 200)).toBe(100);
+ expect(posAt(150, 100, 0)).toBe(FX_REST);
+ });
+
+ it("moves with the arrow keys (Shift: further), and leaves other keys alone", () => {
+ expect(keyPos(35, "ArrowLeft")).toBe(30);
+ expect(keyPos(35, "ArrowRight")).toBe(40);
+ expect(keyPos(35, "ArrowRight", true)).toBe(60);
+ expect(keyPos(2, "ArrowLeft")).toBe(0);
+ expect(keyPos(99, "ArrowRight", true)).toBe(100);
+ expect(keyPos(35, "ArrowUp")).toBeNull();
+ expect(keyPos(35, "Enter")).toBeNull();
+ });
+
+ it("follows a mouse only, never with reduced motion; a finger or pen taps", () => {
+ expect(followsPointer("mouse", false)).toBe(true);
+ expect(followsPointer("mouse", true)).toBe(false);
+ expect(followsPointer("touch", false)).toBe(false);
+ expect(followsPointer("pen", false)).toBe(false);
+ expect(tapToggles("touch")).toBe(true);
+ expect(tapToggles("pen")).toBe(true);
+ expect(tapToggles("mouse")).toBe(false);
+ });
+});
+
+describe("Fuobe FX before/after cards: loupe, reframe, flipbook", () => {
+ it("pans the lens's detail with the pointer, within the detail", () => {
+ expect(LENS_DETAIL).toBe(LENS * 2);
+ expect(loupePan(0, 0, 208, 104).map(Math.abs)).toEqual([0, 0]);
+ expect(loupePan(1, 1, 208, 104)).toEqual([-104, -104]);
+ expect(loupePan(0.5, 2, 208, 104)).toEqual([-52, -104]);
+ expect(loupePan(0.5, 0.5, 100, 104).map(Math.abs)).toEqual([0, 0]);
+ });
+
+ it("puts a tapped lens over the loupe's own place", () => {
+ const v = fxView("upscale")!;
+ const [x, y, w, h] = v.loupe!;
+ expect(lensHome(v.loupe, 400, 300)).toEqual([Math.round((x + w / 2) * 400), Math.round((y + h / 2) * 300)]);
+ });
+
+ it("outlines the 9:16 box from its rect", () => {
+ const v = fxView("reframe")!;
+ const vars = reframeVars(v.rect);
+ const [x, , w] = v.rect!;
+ expect(vars["--fxc-rx"]).toBe(`${Math.round(x * 1000000) / 10000}%`);
+ expect(vars["--fxc-rw"]).toBe(`${Math.round(w * 1000000) / 10000}%`);
+ expect(Number(vars["--fxc-cx"])).toBeCloseTo(x + w / 2, 3);
+ // A pair without its rect still draws a centred box rather than failing.
+ expect(reframeVars(undefined)["--fxc-cx"]).toBe("0.5");
+ });
+
+ it("steps the flipbook frame by frame, the last at five sixths of the sprite", () => {
+ expect(stripShift(0, 6)).toBe(-0);
+ expect(stripShift(1, 6)).toBeCloseTo(-16.6667, 3);
+ expect(stripShift(5, 6)).toBeCloseTo(-83.3333, 3);
+ expect(stripShift(9, 6)).toBeCloseTo(-83.3333, 3);
+ expect(stripShift(-2, 6)).toBe(-0);
+ });
+
+ it("plays the flipbook in steps on hover only, and nothing plays or eases with reduced motion", () => {
+ expect(css).toMatch(/animation: fxc-flip [^;]*steps\(var\(--fxc-frames, 6\), jump-none\)/);
+ // Only under data-hover or a tap's data-show, never at rest.
+ const rules = [...css.matchAll(/([^{}]+)\{[^{}]*animation: fxc-flip/g)].map((m) => m[1]);
+ expect(rules.length).toBeGreaterThan(0);
+ for (const r of rules) for (const sel of r.split(",")) expect(sel).toMatch(/data-hover|data-show="after"/);
+ const reduced = css.slice(css.indexOf("@media (prefers-reduced-motion: reduce)"));
+ expect(reduced).toMatch(/animation: none/);
+ expect(reduced).toMatch(/transition: none/);
+ });
+
+ it("moves the divider by clip-path and transform only (no layout)", () => {
+ expect(css).toMatch(/\.fxc-after \{[^}]*clip-path: inset\(0 0 0 var\(--fxc-pos\)\)/);
+ expect(css).toMatch(/\.fxc-line \{[^}]*transform: translateX\(var\(--fxc-pos\)\)/);
+ });
+});
+
+describe("Fuobe FX before/after cards: where they show", () => {
+ it("gives /fx cards with a pair their before and after; the rest keep their cover, in the same order", async () => {
+ const { sections } = await fxShowcase();
+ const ids = fxSections(undefined);
+ let paired = 0;
+ for (const s of sections) {
+ expect(s.cards.map((c) => c.id)).toEqual(ids.find((x) => x.id === s.id)!.cards);
+ for (const c of s.cards) {
+ if (FX_PAIRS[c.id]) {
+ paired += 1;
+ expect(c.fx?.id, c.id).toBe(c.id);
+ } else {
+ expect(c.fx, c.id).toBeUndefined();
+ expect(c.card, c.id).toBeDefined();
+ }
+ }
+ }
+ expect(paired).toBeGreaterThan(0);
+ });
+
+ it("gives the menu's lead cards their pair, through the menu file, and keeps rows on their small covers", () => {
+ const m = unpackMenu(JSON.parse(JSON.stringify(packMenu(fxMenu()))));
+ const leads = m.columns.map((c) => c.lead).filter((l) => !!l);
+ expect(leads.some((l) => l!.fx)).toBe(true);
+ for (const l of leads) expect(!!l!.fx, l!.id).toBe(!!FX_PAIRS[l!.id]);
+ for (const c of m.columns) for (const r of c.rows) expect(r.fx, r.id).toBeUndefined();
+ expect(megaItems(m).length).toBe(megaItems(fxMenu()).length);
+ });
+});