# 交互样本书架

选中书架上的一本笔记，即可打开并操作其中的交互样本。

## 试一试

选择书架上的笔记，试用其中的交互，再合上笔记返回书架。

## 交互细节

打开和关闭样本时，应清楚呈现书架上的笔记与其对应内容的关系。

## 各平台的操作方式

- iOS · 点按书脊打开笔记并体验示例。关闭后回到所选的书。
- Android · 点按书脊打开笔记并体验示例。关闭后回到所选的书。
- PC · 选择书架上的笔记，试用其中的交互，再合上笔记返回书架。

## 适用场景

在同一页集中陈列多种小型交互，让访客逐个体验。

## 实现要求

> 点击书脊时展开对应示例，关闭后将焦点还给该书。

## 来源与致谢

书架和笔记本插画均为 UI Motion Lab 原创。弹簧动效使用 Popmotion 11.0.5，HTML 文件中附有其 MIT 许可证声明。

- [Interaction Library](<https://library.jjangik.kr/>)
- [原版逐帧演示](<https://x.com/beamnxw/status/2108616740846420354>)
- [Popmotion 源代码](<https://github.com/Popmotion/popmotion/tree/adf681efd8568ada018ce68082dbd585f25c4c7d/packages/popmotion>)
- [Popmotion 的 MIT 许可证](<https://github.com/Popmotion/popmotion/blob/adf681efd8568ada018ce68082dbd585f25c4c7d/packages/popmotion/LICENSE.md>)

## 如何验证效果

从书架或文字列表中任选 Drawer、Spring 或 Stroke。书本跟随弹簧运动，刚度为 160，阻尼为 19，质量为 0.85。按每秒 30 帧计算，第 0 至 8 帧，封面从 −63° 转向读者；第 14 至 23 帧，封面翻开至 −94°；第 12 至 24 帧，内页逐渐显现。打开过程共 800 毫秒。放大示例后按两次 Esc，第一次返回笔记本，第二次将焦点移回打开它的控件。开启减少动态效果后，笔记本会直接打开。

## 独立 HTML 示例

将以下代码保存为 HTML 文件，用浏览器打开即可离线体验。

```html
<!doctype html>
<html lang="zh-Hans">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>交互样本书架 · 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>交互样本书架</h1><button type="button" class="quiet" id="view">列表视图</button></div>
  <div class="shelf" id="shelf" role="group" aria-label="示例笔记"></div>
  <div class="list" id="list" role="group" aria-label="示例列表" hidden></div>
  <noscript>请在浏览器中启用 JavaScript 以使用样本书架。</noscript>
</main>
<dialog id="detail" aria-labelledby="sample-title">
  <div class="sheet">
  <div class="detail-head"><span id="detail-label">示例笔记</span><button type="button" class="quiet" id="close" autofocus>关闭</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">放大</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">打开面板</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">让小球回弹</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">重新绘制</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:'抽屉面板', mark:'▤',description:'面板从屏幕右侧滑入。'},
    {id:'spring', title:'弹簧回弹', mark:'●',description:'小球略微越过目标，然后回弹停稳。'},
    {id:'draw', title:'路径描边', mark:'∿',description:'像用笔作画一样，从头到尾描出曲线。'}
  ]
  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 = '示例笔记'
    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 ? '书架视图' : '列表视图'
  }
  byId('close').onclick = () => dialog.close()
  content.addEventListener('click',() => {touched = true},true)
  function showZoom(zoomed) {
    dialog.classList.toggle('zoomed',zoomed)
    byId('zoom').textContent = zoomed ? '返回笔记' : '放大'
    byId('zoom').setAttribute('aria-pressed',String(zoomed))
    byId('detail-label').textContent = zoomed ? byId('sample-title').textContent : '示例笔记'
  }
  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 = '打开面板'
    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 ? '关闭面板' : '打开面板'
    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 ? '小球向右移动。' : '小球向左移动。'
  }
  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 = '线条已绘制完成。'
      else byId('status').textContent = ''
    })
  }
</script>
</body>
</html>
```
