Back to the library

Undraw — retract on undo

Variant: Retract on undo

A pencilled arrow from a margin note to the phrase it glosses, taken back by Undo. Undo is the act played backwards, so the stroke leaves by the road it came in on: drawing and retracting are one dashoffset moving in opposite directions, and the arrow shrinks back into the note, never off the far end. Undo is also a stack. The head went down last, so it comes off first, folding into its own tip, and the shaft cannot start home while the head still points at the word. The way out is ease-out and a touch quicker than the way in, because undo answers a keypress and must move on the first frame; the curve’s long tail lands your eye on the margin note, the one thing undo should leave you looking at. The phrase gives its ink back the moment the head starts to leave, not when the line finishes, since the link ended on release. Reach for it on annotation layers, whiteboards and drawing tools, anywhere undo removes something the user watched being made.

svgline-drawingtransitiontextloop

The source

A complete HTML document. Paste it into an empty .html file and it plays — no stylesheet, script, font, or image to fetch.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Undraw — retract on undo</title>
    <style>
      :root {
        /* Neutrals — fixed, never remixed. */
        --ivory: #faf9f5;
        --paper: #ffffff;
        --oat: #e3dacc;
        --slate: #141413;

        /* Knobs — the remix API. A knob exists iff declared here and used below. */
        --hue: 38.8;
        --lift: 0;
        --chroma: 1;
        --round: 1;
        --speed: 1;

        /* Accents — derived from the knobs with the family's offsets baked in,
           so one hue roll moves them together. Defaults reproduce the original hex. */
        --clay: oklch(calc(0.6724 + var(--lift)) calc(0.1308 * var(--chroma)) var(--hue));
        --clay-d: oklch(calc(0.5797 + var(--lift)) calc(0.127 * var(--chroma)) var(--hue));
        --olive: oklch(
          calc(0.6118 + var(--lift)) calc(0.0713 * var(--chroma)) calc(var(--hue) + 88.3)
        );
        --rust: oklch(
          calc(0.5408 + var(--lift)) calc(0.1357 * var(--chroma)) calc(var(--hue) - 10.3)
        );

        /* Clock — 4.8s, shared by the whole undraw family (1% = 48ms).
           624ms of pen and 144ms of arrowhead on the way in; on undo, 120ms of
           arrowhead and 552ms of shaft on the way out. The exit is never slower
           than the entrance: undo that takes longer than the act feels like a
           penalty for changing your mind. */
        --cycle: 4.8s;
        --t: calc(var(--cycle) / var(--speed));

        --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
        /* A hand's stroke — it gathers speed off the page and slows into the
           target. The family's pen stroke, wherever one is drawn. */
        --ease-accent: cubic-bezier(0.45, 0, 0.4, 1);

        --_ink: color-mix(in srgb, var(--slate) 80%, transparent);
        --_muted: color-mix(in srgb, var(--slate) 52%, transparent);
      }

      * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }

      body {
        min-height: 100vh;
        display: grid;
        place-items: center;
        padding: clamp(10px, 3vw, 28px);
        background: var(--ivory);
        font-family:
          system-ui,
          -apple-system,
          'Segoe UI',
          Roboto,
          sans-serif;
      }

      .card {
        width: min(380px, 92vw);
        border: 1px solid var(--oat);
        border-radius: calc(14px * var(--round));
        background: var(--paper);
      }

      .card svg {
        display: block;
        width: 100%;
        height: auto;
      }

      .body {
        font-size: 13.5px;
        fill: var(--_ink);
      }

      .term {
        font-weight: 600;
        animation: term var(--t) infinite;
      }

      .margin-rule {
        stroke: var(--oat);
        stroke-width: 1;
      }

      .note {
        font-size: 12.5px;
        font-style: italic;
        fill: var(--_muted);
      }

      /* One dash the length of the path, parked past its start. A falling
         offset grows the stroke out of its origin; the same offset rising again
         shrinks it back into that origin, tip first. Draw and undo are one
         property moving in opposite directions, which is the claim being made:
         undo is the act played backwards, not a different act. Parked at 102,
         not 100 — at exactly 100 the round cap still paints a speck. */
      .shaft,
      .head {
        fill: none;
        stroke: var(--clay);
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
        stroke-dasharray: 100 200;
        stroke-dashoffset: 102;
      }

      .shaft {
        animation: shaft var(--t) infinite;
      }

      .head {
        animation: head var(--t) infinite;
      }

      /* Out: the hand curve, because a pen is drawing. Back: ease-out, because
         undo is a response to a keypress and has to move on the first frame.
         The fast start pulls the tip off the word at once; the long tail lands
         the eye on the margin note, which is where the annotation came from
         and the one thing undo should leave you looking at. */
      @keyframes shaft {
        0%,
        5% {
          stroke-dashoffset: 102;
          animation-timing-function: var(--ease-accent);
        }
        18%,
        54.5% {
          stroke-dashoffset: 0;
          animation-timing-function: var(--ease-out);
        }
        66%,
        100% {
          stroke-dashoffset: 102;
        }
      }

      /* The arrowhead is drawn last, so it is undone first. Undo is a stack:
         the head is the newest thing on the page and the shaft cannot start
         retracting while it still points at the word. Both barbs start at the
         tip, so the head folds into the point the shaft leaves from. */
      @keyframes head {
        0%,
        18% {
          stroke-dashoffset: 102;
          animation-timing-function: var(--ease-out);
        }
        21%,
        52% {
          stroke-dashoffset: 0;
          animation-timing-function: var(--ease-out);
        }
        54.5%,
        100% {
          stroke-dashoffset: 102;
        }
      }

      /* The word belongs to the annotation only while the arrow points at it:
         it takes the ink when the head lands and gives it back the moment the
         head starts to leave, not when the shaft finishes — undo has already
         happened by then. */
      @keyframes term {
        0%,
        21% {
          fill: var(--_ink);
          animation-timing-function: ease;
        }
        24.75%,
        52% {
          fill: var(--clay-d);
          animation-timing-function: ease;
        }
        55.75%,
        100% {
          fill: var(--_ink);
        }
      }

      .chip {
        transform-box: fill-box;
        transform-origin: center;
        animation: press var(--t) infinite;
      }

      .chip rect {
        fill: var(--paper);
        stroke: var(--oat);
        stroke-width: 1;
        animation: press-fill var(--t) infinite;
      }

      .chip text {
        font-size: 12px;
        font-weight: 500;
        fill: var(--_ink);
        text-anchor: middle;
      }

      /* 48ms down, 144ms back. The head starts leaving 48ms into the release,
         the way a button commits on the way up — so the press is visibly the
         cause and not a coincidence. */
      @keyframes press {
        0%,
        50% {
          transform: scale(1);
          animation-timing-function: var(--ease-out);
        }
        51% {
          transform: scale(0.95);
          animation-timing-function: var(--ease-out);
        }
        54%,
        100% {
          transform: scale(1);
        }
      }

      @keyframes press-fill {
        0%,
        50% {
          fill: var(--paper);
          animation-timing-function: ease;
        }
        51% {
          fill: var(--oat);
          animation-timing-function: ease;
        }
        57%,
        100% {
          fill: var(--paper);
        }
      }

      @media (prefers-reduced-motion: reduce) {
        /* The same score on a clock twice as slow: every keyframe scales
           together, so the alignments the comments rely on still hold. */
        :root {
          --t: calc(var(--cycle) * 2 / var(--speed));
        }

        /* Travel is what is removed. The arrow is present or absent as a whole,
           crossfading on the same frames it would have finished drawing and
           started retracting, so the word's ink and the press still line up. */
        .shaft,
        .head {
          stroke-dashoffset: 0;
          animation: arrow-calm var(--t) infinite;
        }

        .chip {
          animation: none;
        }

        @keyframes arrow-calm {
          0%,
          10% {
            opacity: 0;
            animation-timing-function: ease;
          }
          21%,
          52% {
            opacity: 1;
            animation-timing-function: ease;
          }
          60%,
          100% {
            opacity: 0;
          }
        }
      }
    </style>
  </head>
  <body>
    <div class="card">
      <svg
        viewBox="0 0 300 150"
        role="img"
        aria-label="A pencilled arrow draws from a margin note to the words reading rooms; Undo is pressed and the arrow retracts, head first, back into the note it came from"
      >
        <text class="body" x="20" y="40">The 1911 survey lists</text>
        <text class="body" x="20" y="62">
          <tspan class="term">reading rooms</tspan>
        </text>
        <text class="body" x="20" y="84">on four floors;</text>
        <text class="body" x="20" y="106">two are closed.</text>

        <line class="margin-rule" x1="190" y1="24" x2="190" y2="134" />
        <text class="note" x="200" y="124">see p. 214</text>

        <path class="shaft" pathLength="100" d="M 212 110 C 206 82, 166 62, 120 61" />
        <path class="head" pathLength="100" d="M 120 61 L 127 56.5" />
        <path class="head" pathLength="100" d="M 120 61 L 127 65.5" />

        <g class="chip">
          <rect x="200" y="20" width="60" height="22" rx="11" />
          <text x="230" y="35.5">Undo</text>
        </g>
      </svg>
    </div>
  </body>
</html>

The variant family

Same idea, one axis moved. Compare them side by side before you commit.