Motion & effects / Animated graphics

Line-Art Process Diagram

Monochrome green line illustration of a digestion simulator: a capsule followed by six glass beakers in progressively darker green fill, joined by dotted arrow paths with 'Acid' and 'Pancreatic Juice' labels, and an italic figure caption.

Rebuilt from seed.com/approach in the Verdant Lab Editorial style.

npx shadcn@latest add https://justyoink.it/r/verdant-lab-editorial/blocks/line-diagram-process.json

Looks exactly like seed.com: brings its fonts and colours, namespaced so your own theme stays untouched.

Usage

Props: caption, capsuleLabel, stages (x, fill, label lines), outputLabel, topLabelA, topLabelB. The dotted connectors and vessels draw in on scroll via DrawSvg; renders standalone with defaults.

components/line-diagram-process.tsx
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react";
type Stage = { label: string[]; x: number; fill: string; level?: boolean };

export default function LineArtProcessDiagram({
  caption = "Fig. 2 — A bench-scale model of the digestive tract moves a sample through six linked vessels, each tuned to mimic temperature, acidity, enzymes and transit time for that stage.",
  capsuleLabel = ["Test", "Capsule"],
  stages = [
    { label: ["Gastric", "Vessel"], x: 130, fill: "var(--color-lemongrass)" },
    { label: ["Upper", "Duct"], x: 264, fill: "var(--color-lemongrass)" },
    { label: ["Stage", "Three"], x: 398, fill: "var(--color-faded-green)" },
    { label: ["Stage", "Four"], x: 534, fill: "var(--color-faded-green)" },
    { label: ["Stage", "Five"], x: 668, fill: "var(--color-faded-green)" },
  ] as Stage[],
  outputLabel = ["Output"],
  topLabelA = "Acid",
  topLabelB = ["Enzyme", "Mix"],
}: {
  caption?: string;
  capsuleLabel?: string[];
  stages?: Stage[];
  outputLabel?: string[];
  topLabelA?: string;
  topLabelB?: string[];
}) {
  const stroke = "var(--color-ink)";
  const Beaker = ({ x, fill }: { x: number; fill: string }) => (
    <g stroke={stroke} strokeWidth="1.2">
      <path d={`M${x} 110 V222 a42 11 0 0 0 84 0 V110`} fill="var(--color-surface)" />
      <ellipse cx={x + 42} cy={110} rx={42} ry={11} fill="var(--color-canvas)" />
      <path d={`M${x} 148 V222 a42 11 0 0 0 84 0 V148 a42 11 0 0 1 -84 0z`} fill={fill} />
      <path d={`M${x} 148 a42 11 0 0 0 84 0`} fill="none" />
    </g>
  );
  const xs = [-1, ...stages.map((s) => s.x)];
  return (
    <figure className="w-full bg-canvas px-4 py-10 font-sans text-ink md:px-10">
      <Reveal from="up">
        <div className="mx-auto max-w-[900px]">
          <DrawSvg duration={1800} stagger={140} fillAfter>
            <svg viewBox="0 0 900 295" className="h-auto w-full" role="img" aria-label="Diagram of a capsule passing through five vessels to an output tank">
              <g fill="none" stroke={stroke} strokeWidth="1" strokeDasharray="2 3">
                <path d="M32 108 V90 a10 10 0 0 1 10 -10 H112 a10 10 0 0 1 10 10 V118" />
                <path d="M172 118 V90 a10 10 0 0 1 10 -10 H246 a10 10 0 0 1 10 10 V118" />
                <path d="M306 118 V90 a10 10 0 0 1 10 -10 H380 a10 10 0 0 1 10 10 V118" />
                <path d="M440 118 V90 a10 10 0 0 1 10 -10 H516 a10 10 0 0 1 10 10 V118" />
                <path d="M574 118 V90 a10 10 0 0 1 10 -10 H650 a10 10 0 0 1 10 10 V118" />
                <path d="M708 118 V90 a10 10 0 0 1 10 -10 H820 a10 10 0 0 1 10 10 V118" />
                <path d="M172 40 V118" />
              </g>
              <g fontSize="12" fill={stroke} textAnchor="middle">
                <text x="172" y="28">{topLabelA}</text>
                <text x="308" y="12">{topLabelB[0]}</text>
                <text x="308" y="30">{topLabelB[1]}</text>
              </g>
              <rect x="20" y="140" width="24" height="56" rx="12" fill={stroke} />
              <path d="M20 170 H44" stroke="var(--color-canvas)" />
              {stages.map((s) => (
                <Beaker key={s.x} x={s.x - 100} fill={s.fill} />
              ))}
              <g stroke={stroke} strokeWidth="1.2">
                <path d="M800 142 V218 a56 14 0 0 1 -112 0 V142" fill="#4a6b24" transform="translate(0 0)" />
                <ellipse cx="744" cy="142" rx="56" ry="14" fill="#4a6b24" />
              </g>
              <g fontSize="12" fill={stroke} textAnchor="middle">
                {capsuleLabel.map((t, i) => (<text key={t} x="32" y={262 + i * 22}>{t}</text>))}
                {stages.map((s) => s.label.map((t, i) => (<text key={s.x + t} x={s.x - 58} y={262 + i * 22}>{t}</text>)))}
                {outputLabel.map((t, i) => (<text key={t} x="744" y={262 + i * 22}>{t}</text>))}
              </g>
            </svg>
          </DrawSvg>
        </div>
      </Reveal>
      <figcaption className="mx-auto mt-8 max-w-[1110px] text-caption text-ink">
        <em>{caption}</em>
      </figcaption>
    </figure>
  );
}

// ---- Yoink motion (inlined, no dependencies): Reveal, DrawSvg ----

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

type YkRevealFrom = "up" | "down" | "left" | "right" | "scale" | "blur" | "none";

/** Fades content in as it scrolls into view. */
function Reveal({
  children,
  from = "up",
  delay = 0,
  duration = 700,
  distance = 24,
  once = true,
  as = "div",
  className,
  style,
}: {
  children?: ReactNode;
  from?: YkRevealFrom;
  delay?: number;
  duration?: number;
  distance?: number;
  once?: boolean;
  as?: ElementType;
  className?: string;
  style?: CSSProperties;
}) {
  const Tag = as;
  const ref = useRef<HTMLElement>(null);
  const state = useYkReveal(ref, once);
  const hidden = state === "hidden";
  const offset = {
    up: `translate3d(0, ${distance}px, 0)`,
    down: `translate3d(0, ${-distance}px, 0)`,
    left: `translate3d(${-distance}px, 0, 0)`,
    right: `translate3d(${distance}px, 0, 0)`,
    scale: "scale(0.94)",
    blur: `translate3d(0, ${distance / 2}px, 0)`,
    none: "none",
  }[from];
  const t = `${duration}ms ${YK_EASE} ${delay}ms`;
  return (
    <Tag
      ref={ref}
      className={className}
      style={{
        ...style,
        ...(hidden && { opacity: 0, transform: offset, filter: from === "blur" ? "blur(12px)" : undefined }),
        ...(state === "shown" && { transition: `opacity ${t}, transform ${t}, filter ${t}` }),
      }}
    >
      {children}
    </Tag>
  );
}

/** Draws the strokes of an inline SVG (lines, icons, diagrams) when it scrolls into view. */
function DrawSvg({
  children,
  duration = 1600,
  stagger = 120,
  delay = 0,
  fillAfter = true,
  className,
  style,
}: {
  children?: ReactNode;
  duration?: number;
  stagger?: number;
  delay?: number;
  /** fade fills in once their outline is drawn */
  fillAfter?: boolean;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  const state = useYkReveal(ref);
  useYkLayoutEffect(() => {
    if (state === "idle" || !ref.current) return;
    const shapes = Array.from(ref.current.querySelectorAll("path, line, polyline, polygon, circle, ellipse, rect")) as SVGGeometryElement[];
    shapes.forEach((el, i) => {
      if (typeof el.getTotalLength !== "function") return;
      const len = Math.ceil(el.getTotalLength() || 0);
      if (!len) return;
      if (state === "hidden") {
        Object.assign(el.style, { transition: "none", strokeDasharray: `${len}`, strokeDashoffset: `${len}`, fillOpacity: fillAfter ? "0" : "" });
        return;
      }
      const d = delay + i * stagger;
      Object.assign(el.style, {
        transition: `stroke-dashoffset ${duration}ms ${YK_EASE} ${d}ms, fill-opacity 600ms ease ${d + duration * 0.6}ms`,
        strokeDashoffset: "0",
        fillOpacity: "",
      });
    });
  }, [state]);
  return (
    <div ref={ref} className={className} style={style}>
      {children}
    </div>
  );
}

Quality checks

Automated, in a real browser · 4d ago
—

More from Verdant Lab Editorial

The whole style →

Center-Focus Video Story Carousel

Carousels

Hairline Plus Accordion

Accordions

Frosted Glass Photo Hero

Heroes

Offer Popup Dialog

Dialogs & modals

Timeline Benefit Tiles

Feature sections

Glass Panel Annotated Capsule

Feature sections