# Sample Shelf

Each notebook on a shelf opens an interactive sample of its own.

## Try it

Choose a notebook, try the sample inside, then return to the shelf.

## Interaction details

Keep the connection between the book on the shelf and the open sample visible as visitors move between them.

## Platform controls

- iOS · Tap a book spine, try the sample in the open notebook, and close it to return to the book you chose.
- Android · Tap a book spine, try the sample in the open notebook, and close it to return to the book you chose.
- PC · Choose a notebook, try the sample inside, then return to the shelf.

## Where to use it

Libraries or portfolios where visitors explore a few demonstrations at a time.

## Implementation prompt

> Make the notebooks accessible by touch and keyboard and return visitors to the book they opened.

## Sources and credits

The shelf and notebook artwork were made for UI Motion Lab. The interactive spring uses Popmotion 11.0.5. Its MIT license notice is included in the HTML.

- [Interaction Library](<https://library.jjangik.kr/>)
- [Original frame-based demonstration](<https://x.com/beamnxw/status/2108616740846420354>)
- [Popmotion source](<https://github.com/Popmotion/popmotion/tree/adf681efd8568ada018ce68082dbd585f25c4c7d/packages/popmotion>)
- [Popmotion MIT license](<https://github.com/Popmotion/popmotion/blob/adf681efd8568ada018ce68082dbd585f25c4c7d/packages/popmotion/LICENSE.md>)

## Checking the behavior

Choose Drawer, Spring or Stroke from the shelf or the text list. The book follows a spring with stiffness 160, damping 19 and mass 0.85. At 30 fps, its cover turns from −63° to face the reader over frames 0–8, then opens to −94° over frames 14–23. The pages appear over frames 12–24. The complete opening lasts 800 ms. Enlarge the sample and press Escape twice to return first to the notebook and then to the item that opened it. Reduced motion goes straight to the open state.

## Standalone HTML

Save the code below as an HTML file and open it in your browser. The example works offline.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Sample Shelf · UI Motion Lab</title>
<script>
  const settings = new URLSearchParams(location.search)
  document.documentElement.classList.toggle('embed', settings.get('embed') === '1')
  document.documentElement.classList.toggle('reduce', settings.get('reduce') === '1')
</script>
<style>
  :root {
    color-scheme: light;
    --paper:#f6f5f0; --ink:#24242b; --violet:#7255db; --lilac:#e4def7;
    --orange:#fd734e; --mint:#d3e7dd; --line:#d7d5cc;
    font-family:Inter,Pretendard,"Apple SD Gothic Neo","Malgun Gothic",sans-serif;
    background:var(--paper); color:var(--ink);
  }
  * {box-sizing:border-box}
  body {margin:0}
  button {color:inherit;font:inherit;cursor:pointer}
  button:focus-visible {outline:3px solid #4c34ad;outline-offset:3px}
  [hidden] {display:none!important}
  .brand {display:flex;align-items:center;gap:9px;font-size:14px;font-weight:720;border-bottom:1px solid var(--line);padding:14px clamp(16px,5vw,55px)}
  .logo {position:relative;display:inline-grid;place-content:center;background:var(--ink);color:white;width:32px;height:32px;border-radius:8px;font-size:26px;line-height:1;letter-spacing:-2px}
  .logo i {position:absolute;right:1px;top:0;color:var(--orange);font:700 12px/1 sans-serif}
  .embed .brand {display:none}
  main {margin:0 auto;max-width:850px;padding:clamp(16px,4.5vw,50px)}
  .heading {display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:16px}
  h1,h2,p {margin:0}
  h1 {font-size:clamp(22px,4vw,37px);letter-spacing:-.065em}
  .quiet {border:1px solid #a6a49e;background:transparent;padding:8px 13px;border-radius:999px;font-size:12px;font-weight:650}
  .shelf {
    display:flex;align-items:flex-end;justify-content:center;gap:clamp(3px,.6vw,7px);
    min-height:clamp(175px,41vh,360px);padding:18px 12px 0;
    border-bottom:9px solid #4c3328;background:
      linear-gradient(0deg,#231f1e80,transparent 14%),
      linear-gradient(118deg,transparent 4%,#f7ddaa24 27%,transparent 58%),
      radial-gradient(ellipse at 43% 25%,#736657,#393630 85%);
    box-shadow:inset 0 8px 18px #211a1a4f,0 2px #231b18,0 7px 8px #352d251a;overflow:visible;
  }
  .shelf button {align-self:flex-end;display:flex;align-items:center;flex-direction:column;justify-content:space-between;position:relative;
    width:clamp(55px,10vw,87px);height:clamp(147px,30vh,250px);padding:13px 7px 15px;border:1px solid rgba(36,36,43,.45);
    border-radius:5px 7px 1px 2px;transform-origin:center bottom;transform:rotate(var(--lean,0deg));
    box-shadow:inset 1px 0 #ffffff44,inset -3px 0 #0004,5px 2px 5px #19140e66;
    transition:transform .24s cubic-bezier(.2,.7,.22,1)}
  .shelf button:nth-child(2) {height:clamp(160px,33vh,275px)}
  .shelf button:nth-child(3) {height:clamp(136px,27vh,230px)}
  .drawer {--cover:#222c29;--type:#f0e4c5;--lean:-3deg}
  .spring {--cover:#ae4532;--type:#ffebca}
  .draw {--cover:#cfbf92;--type:#322a1b;--lean:5deg}
  .shelf button,.front {background:
    linear-gradient(90deg,#130e0c60,transparent 12%,#ffffff12 26%,transparent 84%,#120d0c36),
    repeating-linear-gradient(0deg,transparent 0 2px,#ffffff0a 2px 3px),
    repeating-linear-gradient(90deg,transparent 0 2px,#00000009 2px 3px),
    var(--cover);color:var(--type)}
  .shelf button::before {content:"";position:absolute;inset:7px 5px 6px;border-block:3px double currentColor;opacity:.58;pointer-events:none}
  .spine-title {writing-mode:vertical-rl;font-size:clamp(15px,2.4vw,20px);font-weight:720;letter-spacing:.07em}
  .symbol {display:inline-grid;place-content:center;width:1.3em;height:1.3em;line-height:1;font-family:Arial,sans-serif;font-size:23px;font-weight:bold}
  .shelf button:focus-visible {transform:translateY(-5px) scale(1.035)}
  @media (hover:hover) {.shelf button:hover {transform:translateY(-5px) scale(1.035)}}
  .shelf button[aria-expanded=true] {visibility:hidden}
  .list {display:grid;border-top:1px solid var(--ink)}
  .list button {text-align:left;display:flex;align-items:center;gap:12px;border:0;border-bottom:1px solid var(--line);padding:14px 4px;background:transparent;font-weight:650}
  .list .symbol {background:var(--cover);color:var(--type);border-radius:3px;font-size:17px;width:32px;height:36px}
  .list .arrow {margin-left:auto}
  dialog {position:fixed;inset:0;margin:0;padding:8px 13px;color:var(--ink);border:0;background:transparent;width:100%;height:100%;max-width:none;max-height:none;overflow:auto}
  dialog[open] {display:grid;place-items:center}
  .sheet {--reveal:1;width:min(620px,100%);position:relative;isolation:isolate}
  .sheet::before {content:"";inset:0;position:absolute;z-index:-1;border:1px solid var(--ink);border-radius:6px;background:var(--paper);box-shadow:0 12px 48px #24242b3d;opacity:var(--reveal)}
  dialog::backdrop {background:rgba(36,36,43,.28)}
  .detail-head {display:flex;align-items:center;justify-content:space-between;padding:10px 14px;border-bottom:1px solid var(--line);font-size:12px;font-weight:650}
  .note {display:grid;grid-template-columns:1fr 1fr;align-items:stretch;padding:clamp(10px,2.3vw,18px)}
  .binding {position:relative;min-height:150px;perspective:700px}
  .paper,.flight {position:absolute;inset:0}
  .paper {display:flex;flex-direction:column;justify-content:center;gap:9px;padding:clamp(10px,2.8vw,26px);border-right:1px solid #bbb8af;background:linear-gradient(to left,#d8d5ca,#efece1 7%,#f5f2e8 95%);border-radius:3px;opacity:var(--reveal)}
  .paper p {font-size:clamp(11px,1.8vw,14px);line-height:1.6;word-break:keep-all}
  .flight {transform-origin:top left;perspective:650px;pointer-events:none}
  .front {display:grid;place-items:center;width:100%;height:100%;border:1px solid #39393969;border-radius:3px 6px 4px 2px;transform-origin:left center;backface-visibility:hidden}
  .front .symbol {font-size:clamp(27px,5vw,43px)}
  .content {min-width:0;display:flex;flex-direction:column;align-items:stretch;justify-content:center;padding:clamp(10px,2.8vw,26px);background:linear-gradient(to right,#e4e0d5,#f9f7f0 6%)}
  .zoom {align-self:flex-end;border:0;padding:2px 0;background:none;text-decoration:underline;text-underline-offset:3px;font-size:11px}
  dialog.zoomed .binding {display:none}
  dialog.zoomed .note {grid-template-columns:1fr}
  dialog.zoomed .content {background:transparent}
  dialog.zoomed .demo {height:clamp(60px,29vh,190px)}
  h2 {font-size:clamp(18px,3.8vw,29px);letter-spacing:-.055em}
  .demo {margin:10px 0;position:relative;overflow:hidden;display:grid;place-items:center;height:clamp(54px,12vh,92px);border-radius:5px;background:#e8e6de}
  .interact {border:0;border-radius:999px;background:var(--ink);color:white;padding:8px 14px;font-size:12px;font-weight:650;min-height:34px}
  .mini-drawer {position:absolute;right:0;inset-block:0;width:55%;border-left:1px solid var(--ink);background:var(--lilac);transform:translateX(100%);display:grid;align-content:center;gap:6px;padding-inline:12px}
  .mini-drawer i {display:block;height:3px;background:#63588d}
  .mini-drawer i:last-child {width:62%}
  .drawer-base {width:62%;height:38%;border:1px solid #96938a;border-radius:4px}
  .track {width:72%;height:2px;background:#aaa59b;position:relative}
  .ball {position:absolute;display:block;width:21px;height:21px;border-radius:50%;background:var(--orange);border:1px solid var(--ink);top:50%;left:0;transform:translate(-50%,-50%)}
  .example[data-example="spring"] .demo {background:linear-gradient(#ede9dc 68%,#e3dece 69%,#f5f1e6)}
  .track {height:1px;background:#867c68;box-shadow:0 1px #ffffff94}
  .ball {width:23px;height:23px;border:1px solid #8c382b;background:radial-gradient(circle at 30% 25%,#fbbd87,#c05a3a 43%,#773828 92%);box-shadow:3px 5px 5px -3px #482b1e99}
  .demo svg {width:80%;height:80%;fill:none;stroke:var(--ink);stroke-width:4;stroke-linecap:round;stroke-linejoin:round}
  .demo svg path {stroke-dasharray:1;stroke-dashoffset:0}
  .sr {position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
  @media(max-width:420px) {.note {grid-template-columns:43% 57%;padding:8px}.binding {min-height:120px}.detail-head {padding:8px 12px}.heading {margin-bottom:9px}}
  @media(max-height:320px) {main {padding:10px 14px}.heading {margin-bottom:6px}h1 {font-size:19px}.shelf {min-height:115px;padding-top:7px}.shelf button,.shelf button:nth-child(2),.shelf button:nth-child(3) {height:95px;padding:6px}.shelf button:nth-child(2){height:105px}.spine-title {font-size:12px}.symbol {font-size:15px}.note {padding:9px 14px}.binding {min-height:85px}.detail-head {padding:4px 12px}.demo {height:43px;margin:5px 0}.brand {padding:5px 14px}}
  @media(prefers-reduced-motion:reduce) {.shelf button {transition:none!important;transform:none!important}}
  .reduce .shelf button {transition:none!important;transform:none!important}
</style>
</head>
<body>
<header class="brand"><span class="logo" aria-hidden="true">m<i>↗</i></span> UI Motion Lab</header>
<main>
  <div class="heading"><h1>Sample Shelf</h1><button type="button" class="quiet" id="view">List view</button></div>
  <div class="shelf" id="shelf" role="group" aria-label="Sample notebook"></div>
  <div class="list" id="list" role="group" aria-label="Sample list" hidden></div>
  <noscript>Enable JavaScript in your browser to use the sample shelf.</noscript>
</main>
<dialog id="detail" aria-labelledby="sample-title">
  <div class="sheet">
  <div class="detail-head"><span id="detail-label">Sample notebook</span><button type="button" class="quiet" id="close" autofocus>Close</button></div>
  <div class="note">
    <div class="binding" id="binding"><div class="paper"><h2 id="sample-title"></h2><p id="description"></p></div><div class="flight" aria-hidden="true"><div class="front"><span class="symbol"></span></div></div></div>
    <div class="content">
      <button type="button" class="zoom" id="zoom" aria-pressed="false">Enlarge</button>
      <section class="example" data-example="drawer">
        <div class="demo" aria-hidden="true"><span class="drawer-base"></span><div class="mini-drawer"><i></i><i></i></div></div>
        <button type="button" class="interact" id="drawer-action" aria-pressed="false">Open panel</button>
      </section>
      <section class="example" data-example="spring" hidden>
        <div class="demo" aria-hidden="true"><div class="track"><span class="ball"></span></div></div>
        <button type="button" class="interact" id="spring-action">Bounce ball</button>
      </section>
      <section class="example" data-example="draw" hidden>
        <div class="demo" aria-hidden="true"><svg viewBox="0 0 180 68"><path pathLength="1" d="M8 56 C 32 56 36 11 59 13 S 86 69 105 47 S 132 5 148 21 Q 160 32 172 15"/></svg></div>
        <button type="button" class="interact" id="draw-action">Draw again</button>
      </section>
      <span role="status" class="sr" id="status"></span>
    </div>
  </div>
  </div>
</dialog>
<script>/*! Popmotion 11.0.5 · https://github.com/Popmotion/popmotion/tree/adf681efd8568ada018ce68082dbd585f25c4c7d

The MIT License (MIT)

Copyright © 2019 Framer BV

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

hey-listen 1.0.8 · https://github.com/Popmotion/hey-listen

MIT License

Copyright (c) 2018 Popmotion

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var MotionLabFrames=(()=>{var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var _=(e,n)=>{for(var t in n)R(e,t,{get:n[t],enumerable:!0})},j=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of K(n))!L.call(e,o)&&o!==t&&R(e,o,{get:()=>n[o],enumerable:!(r=B(n,o))||r.enumerable});return e};var z=e=>j(R({},"__esModule",{value:!0}),e);var Z={};_(Z,{interpolate:()=>Y,spring:()=>X});var q=function(){};var O=(e,n,t)=>Math.min(Math.max(t,e),n);var w=.001,G=.01,F=10,I=.05,C=1;function T({duration:e=800,bounce:n=.25,velocity:t=0,mass:r=1}){let o,c;q(e<=F*1e3,"Spring duration must be 10 seconds or less");let i=1-n;i=O(I,C,i),e=O(G,F,e/1e3),i<1?(o=s=>{let g=s*i,p=g*e,M=g-t,d=S(s,i),v=Math.exp(-p);return w-M/d*v},c=s=>{let p=s*i*e,M=p*t+t,d=Math.pow(i,2)*Math.pow(s,2)*e,v=Math.exp(-p),b=S(Math.pow(s,2),i);return(-o(s)+w>0?-1:1)*((M-d)*v)/b}):(o=s=>{let g=Math.exp(-s*e),p=(s-t)*e+1;return-w+g*p},c=s=>{let g=Math.exp(-s*e),p=(t-s)*(e*e);return g*p});let x=5/e,f=J(o,c,x);if(e=e*1e3,isNaN(f))return{stiffness:100,damping:10,duration:e};{let s=Math.pow(f,2)*r;return{stiffness:s,damping:i*2*Math.sqrt(r*s),duration:e}}}var H=12;function J(e,n,t){let r=t;for(let o=1;o<H;o++)r=r-e(r)/n(r);return r}function S(e,n){return e*Math.sqrt(1-n*n)}var Q=["duration","bounce"],U=["stiffness","damping","mass"];function k(e,n){return n.some(t=>e[t]!==void 0)}function W(e){let n={velocity:0,stiffness:100,damping:10,mass:1,isResolvedFromDuration:!1,...e};if(!k(e,U)&&k(e,Q)){let t=T(e);n={...n,...t,velocity:0,mass:1},n.isResolvedFromDuration=!0}return n}function D({from:e=0,to:n=1,restSpeed:t=2,restDelta:r,...o}){let c={done:!1,value:e},{stiffness:i,damping:x,mass:f,velocity:s,duration:g,isResolvedFromDuration:p}=W(o),M=V,d=V;function v(){let b=s?-(s/1e3):0,l=n-e,m=x/(2*Math.sqrt(i*f)),u=Math.sqrt(i/f)/1e3;if(r===void 0&&(r=Math.min(Math.abs(n-e)/100,.4)),m<1){let a=S(u,m);M=h=>{let y=Math.exp(-m*u*h);return n-y*((b+m*u*l)/a*Math.sin(a*h)+l*Math.cos(a*h))},d=h=>{let y=Math.exp(-m*u*h);return m*u*y*(Math.sin(a*h)*(b+m*u*l)/a+l*Math.cos(a*h))-y*(Math.cos(a*h)*(b+m*u*l)-a*l*Math.sin(a*h))}}else if(m===1)M=a=>n-Math.exp(-u*a)*(l+(b+u*l)*a);else{let a=u*Math.sqrt(m*m-1);M=h=>{let y=Math.exp(-m*u*h),A=Math.min(a*h,300);return n-y*((b+m*u*l)*Math.sinh(A)+a*l*Math.cosh(A))/a}}}return v(),{next:b=>{let l=M(b);if(p)c.done=b>=g;else{let m=d(b)*1e3,u=Math.abs(m)<=t,a=Math.abs(n-l)<=r;c.done=u&&a}return c.value=c.done?n:l,c},flipTarget:()=>{s=-s,[e,n]=[n,e],v()}}}D.needsInterpolation=(e,n)=>typeof e=="string"||typeof n=="string";var V=e=>0;var N=(e,n,t)=>-t*e+t*n+e;var P=(e,n,t)=>{let r=n-e;return r===0?1:(t-e)/r};var E=new Map;function X({fps:e,frame:n,durationInFrames:t,config:r={}}){if(n<=0)return 0;if(t!==void 0&&n>=t)return 1;let{mass:o=1,stiffness:c=100,damping:i=10}=r,x=[o,c,i].join("/"),f=E.get(x);if(!f){let g=D({from:0,to:1,mass:o,stiffness:c,damping:i,restSpeed:.012,restDelta:.002}),p=0;for(;p<1e4&&!g.next(p).done;)p+=8;f={curve:g,settledAt:p},E.set(x,f)}let s=t===void 0?n*1e3/e:n*f.settledAt/t;return f.curve.next(s).value}function Y(e,n,t,r={}){let o=n.length-1;if(r.extrapolateLeft==="clamp"&&e<=n[0])return t[0];if(r.extrapolateRight==="clamp"&&e>=n[o])return t[o];let c=n.findIndex((x,f)=>f>0&&x>=e),i=c<0?o:c;return N(t[i-1],t[i],P(n[i-1],n[i],e))}return z(Z);})();</script>
<script>
  const samples = [
    {id:'drawer', title:'Drawer', mark:'▤',description:'A panel slides in from the right edge of the screen.'},
    {id:'spring', title:'Spring', mark:'●',description:'The ball overshoots its target slightly and then settles.'},
    {id:'draw', title:'Stroke', mark:'∿',description:'Trace the curve from start to finish as if drawing with a pen.'}
  ]
  const byId = (id) => document.getElementById(id)
  const dialog = byId('detail')
  const binding = byId('binding')
  const flight = binding.querySelector('.flight')
  const cover = binding.querySelector('.front')
  const content = dialog.querySelector('.content')
  const reduced = matchMedia('(prefers-reduced-motion: reduce)')
  const frames = window.MotionLabFrames
  const clamp = {extrapolateLeft:'clamp',extrapolateRight:'clamp'}
  const requests = {entry:0,sample:0}
  let origin = null
  let drawerOpen = false
  let drawerPosition = 0
  let ballRight = false
  let touched = false

  function play(channel, duration, paint) {
    cancelAnimationFrame(requests[channel])
    if (settings.get('reduce') === '1' || reduced.matches) {
      paint(duration)
      return
    }
    const start = performance.now()
    paint(0)
    function tick(now) {
      const frame = Math.max(0,Math.min((now - start) * 30 / 1000,duration))
      paint(frame)
      if (frame < duration) requests[channel] = requestAnimationFrame(tick)
    }
    requests[channel] = requestAnimationFrame(tick)
  }
  function openNote(button, sample) {
    if (dialog.open) return
    origin = button
    touched = false
    const source = (button.closest('#list') ? button.querySelector('.symbol') : button).getBoundingClientRect()
    button.setAttribute('aria-expanded','true')
    binding.className = 'binding ' + sample.id
    cover.querySelector('.symbol').textContent = sample.mark
    byId('sample-title').textContent = sample.title
    byId('description').textContent = sample.description
    byId('detail-label').textContent = 'Sample notebook'
    byId('status').textContent = ''
    dialog.querySelectorAll('[data-example]').forEach(section => {
      section.hidden = section.dataset.example !== sample.id
    })
    dialog.showModal()
    const dest = binding.getBoundingClientRect()
    let previewStarted = false
    play('entry',24,frame => {
      const position = frame >= 15 ? 1 : frames.spring({fps:30,frame,durationInFrames:15,config:{mass:.85,damping:19,stiffness:160}})
      const distance = 1 - position
      const dx = (source.x - dest.x) * distance
      const dy = (source.y - dest.y) * distance
      const sx = 1 + (source.width / dest.width - 1) * distance
      const sy = 1 + (source.height / dest.height - 1) * distance
      flight.style.transform = 'translate('+dx+'px,'+dy+'px) scale('+sx+','+sy+')'
      const angle = frames.interpolate(frame,[0,8,14,23],[-63,0,0,-94],clamp)
      cover.style.transform = 'rotateY('+angle+'deg)'
      const reveal = frames.interpolate(frame,[12,24],[0,1],clamp)
      dialog.querySelector('.sheet').style.setProperty('--reveal',reveal)
      dialog.querySelector('.detail-head').style.opacity = reveal
      content.style.opacity = reveal
      content.style.transform = 'translateY('+((1-reveal)*6)+'px)'
      if (!previewStarted && frame >= 15 && !touched) {
        previewStarted = true
        preview(sample.id)
      }
    })
  }
  function noteButton(sample,isList) {
    const button = document.createElement('button')
    button.type = 'button'
    button.className = sample.id
    button.setAttribute('aria-haspopup','dialog')
    button.setAttribute('aria-expanded','false')
    button.setAttribute('aria-controls','detail')
    const mark = document.createElement('span')
    mark.className = 'symbol'
    mark.setAttribute('aria-hidden','true')
    mark.textContent = sample.mark
    const title = document.createElement('span')
    title.textContent = sample.title
    button.append(mark,title)
    if (isList) {
      const arrow = document.createElement('span')
      arrow.textContent = '↗'
      arrow.className = 'arrow'
      arrow.setAttribute('aria-hidden','true')
      button.append(arrow)
    } else {
      title.className = 'spine-title'
    }
    button.addEventListener('click',() => openNote(button,sample))
    return button
  }
  for (const sample of samples) {
    byId('shelf').append(noteButton(sample,false))
    byId('list').append(noteButton(sample,true))
  }
  byId('view').onclick = () => {
    const toList = byId('list').hidden
    byId('shelf').hidden = toList
    byId('list').hidden = !toList
    byId('view').textContent = toList ? 'Shelf view' : 'List view'
  }
  byId('close').onclick = () => dialog.close()
  content.addEventListener('click',() => {touched = true},true)
  function showZoom(zoomed) {
    dialog.classList.toggle('zoomed',zoomed)
    byId('zoom').textContent = zoomed ? 'Back to note' : 'Enlarge'
    byId('zoom').setAttribute('aria-pressed',String(zoomed))
    byId('detail-label').textContent = zoomed ? byId('sample-title').textContent : 'Sample notebook'
  }
  byId('zoom').onclick = () => showZoom(!dialog.classList.contains('zoomed'))
  dialog.addEventListener('cancel',event => {
    if (dialog.classList.contains('zoomed')) {
      event.preventDefault()
      showZoom(false)
      byId('zoom').focus()
    }
  })
  function preview(id) {
    play('sample',26,frame => {
      if (id === 'drawer') {
        drawerPosition = frames.interpolate(frame,[0,8,16,26],[0,.85,.85,0],clamp)
        dialog.querySelector('.mini-drawer').style.transform = 'translateX('+((1-drawerPosition)*100)+'%)'
      } else if (id === 'spring') {
        const forward = frame < 13
        const progress = frames.spring({fps:30,frame:forward ? frame : frame-13,durationInFrames:13,config:{damping:10,stiffness:130}})
        const travel = frame === 26 ? 0 : 80*(forward ? progress : 1-progress)
        dialog.querySelector('.ball').style.left = travel+'%'
      } else {
        dialog.querySelector('path').style.strokeDashoffset = frames.interpolate(frame,[0,19],[1,0],clamp)
      }
    })
  }
  dialog.addEventListener('close',() => {
    cancelAnimationFrame(requests.entry)
    cancelAnimationFrame(requests.sample)
    drawerOpen = false
    drawerPosition = 0
    ballRight = false
    showZoom(false)
    byId('drawer-action').setAttribute('aria-pressed','false')
    byId('drawer-action').textContent = 'Open panel'
    dialog.querySelector('.mini-drawer').style.transform = ''
    dialog.querySelector('.ball').style.left = ''
    dialog.querySelector('path').style.strokeDashoffset = ''
    if (origin) {
      origin.setAttribute('aria-expanded','false')
      origin.focus({preventScroll:true})
      origin = null
    }
  })
  byId('drawer-action').onclick = () => {
    drawerOpen = !drawerOpen
    const from = drawerPosition
    const to = drawerOpen ? 1 : 0
    byId('drawer-action').textContent = drawerOpen ? 'Close panel' : 'Open panel'
    byId('drawer-action').setAttribute('aria-pressed',String(drawerOpen))
    play('sample',11,frame => {
      const progress = frame === 11 ? 1 : frames.spring({fps:30,frame,durationInFrames:11,config:{damping:23}})
      drawerPosition = from + (to-from)*progress
      dialog.querySelector('.mini-drawer').style.transform = 'translateX('+((1-drawerPosition)*100)+'%)'
    })
  }
  byId('spring-action').onclick = () => {
    const ball = dialog.querySelector('.ball')
    const from = parseFloat(ball.style.left) || 0
    ballRight = !ballRight
    const to = ballRight ? 100 : 0
    play('sample',24,frame => {
      const progress = frame === 24 ? 1 : frames.spring({fps:30,frame,durationInFrames:24,config:{mass:.8,damping:8,stiffness:135}})
      ball.style.left = (from + (to-from)*progress)+'%'
    })
    byId('status').textContent = ballRight ? 'The ball moves to the right.' : 'The ball moves to the left.'
  }
  byId('draw-action').onclick = () => {
    play('sample',19,frame => {
      dialog.querySelector('path').style.strokeDashoffset = frames.interpolate(frame,[0,19],[1,0],clamp)
      if (frame === 19) byId('status').textContent = 'Line complete.'
      else byId('status').textContent = ''
    })
  }
</script>
</body>
</html>
```
