`;
document.body.appendChild(sb);
sb.addEventListener('pointerdown',e=>e.stopPropagation());
/* ---- 内容 ---- */
const sbTxt=x=>x?[x.title,x.sub,...(x.tags||[])].join(' '):'';
function objText(o){return (o.u[0]==='s'?sbTxt(byId(o.id)):[o.name||'',...o.items.map(i=>sbTxt(byId(i)))].join(' ')).toLowerCase();}
function objUses(o){return o.u[0]==='s'?[useOf(byId(o.id))]:o.items.map(i=>useOf(byId(i)));}
const isNoteId=id=>{const x=byId(id);return !x||x.sticky;};
const USES=['首页','邮件','商品页','评价','社媒','品牌'];
/* 每种用途有几样:桌上单张的 + 文件夹、一叠里面的;便签不算 */
function useItems(use){const out=[];for(const o of S)if(!isNoteId(o.id)&&useOf(byId(o.id))===use)out.push({o,id:o.id});for(const c of C)for(const id of c.items)if(!isNoteId(id)&&useOf(byId(id))===use)out.push({o:c,id});return out;}
const bDate=b=>b.d||(b.d=`${new Date().getMonth()+1}月${new Date().getDate()}日`);
/* 缩略图:把桌上的真东西复制一份,缩小摆进去 */
function cloneOf(el){const k=el.cloneNode(true);k.removeAttribute('data-u');k.querySelectorAll('[data-u]').forEach(n=>n.removeAttribute('data-u'));k.querySelectorAll('[contenteditable]').forEach(n=>n.removeAttribute('contenteditable'));
k.classList.remove('held','press','sel','dimq','free','near','fopen','toolhover','aware');k.style.translate='';k.style.opacity='';return k;}
function boardThumb(b,[W,H]){const box=document.createElement('div');box.className='tm';box.style.width=W+'px';box.style.height=H+'px';
const k=Math.min(W/b.w,H/b.h),w=document.createElement('div');w.className='w';Object.assign(w.style,{width:b.w+'px',height:b.h+'px',transform:`translate(${(W-b.w*k)/2}px,${(H-b.h*k)/2}px) scale(${k})`});
for(const m of bMembers(b).sort((p,q)=>(p.o.zi||0)-(q.o.zi||0))){const c=cloneOf(m.el);c.style.left=(m.o.x-b.x)+'px';c.style.top=(m.o.y-b.y)+'px';w.appendChild(c);}
box.appendChild(w);return box;}
function useThumb(use,[W,H]){const box=document.createElement('div');box.className='tm g';box.style.width=W+'px';box.style.height=H+'px';
const els=[];for(const o of S)if(els.length<4&&!isNoteId(o.id)&&useOf(byId(o.id))===use){const el=elOf(o.u);if(el)els.push(el);}
for(const c of C)if(els.length<4&&c.items.some(id=>!isNoteId(id)&&useOf(byId(id))===use)){const el=elOf(c.u);if(el)els.push(el);}
const cw=(W-6)/2,ch=(H-6)/2;for(let i=0;i<4;i++){const cell=document.createElement('div');const el=els[i];
if(el){const ew=el.offsetWidth||100,eh=el.offsetHeight||80,k=Math.min(cw/ew,ch/eh)*.92,w=document.createElement('div');w.className='w';
Object.assign(w.style,{width:ew+'px',height:eh+'px',transform:`translate(${(cw-ew*k)/2}px,${(ch-eh*k)/2}px) scale(${k})`});const c=cloneOf(el);Object.assign(c.style,{left:'0px',top:'0px',scale:'1',rotate:'0deg'});c.style.setProperty('--z',1);c.style.setProperty('--r','0deg');w.appendChild(c);cell.appendChild(w);}
box.appendChild(cell);}
return box;}
function rowEl(key,name,meta,thumb,dot){const it=document.createElement('div');it.className='it';it.dataset.key=key;it.appendChild(thumb);
const tx=document.createElement('div');tx.className='tx';tx.innerHTML=`${esc(name)}${dot?``:''}${esc(meta)}`;it.appendChild(tx);
if(SB.on===key||key==='p:'+(PCUR&&PCUR.id)||SB.use===key.slice(2)&&key.startsWith('u:'))it.classList.add('on');it.title=name;return it;}
/* 展开后碰到下面的工具栏,就整条停在它上面 */
function sbFitBottom(){const sh=document.getElementById('shelf');if(!sh)return;const r=sh.getBoundingClientRect();sb.style.bottom=r.left<16+SBO+12?(innerHeight-r.top+12)+'px':'';}
addEventListener('resize',()=>sbFitBottom());
function sbRender(){sbFitBottom();sb.querySelectorAll('.sw button').forEach(b=>b.classList.toggle('on',b.dataset.t===SB.tab));
const ls=sb.querySelector('.ls'),h=sb.querySelector('h4'),q=SB.q;ls.innerHTML='';
if(SB.tab==='proj'){const L=PAGES.slice().reverse().filter(p=>!q||pageText(p).includes(q));
h.textContent=q?`找到 ${L.length} 个项目`:`全部项目 · ${PAGES.length}`;
if(!q){const t=document.createElement('div');t.className='tm';t.style.width=SBT[0]+'px';t.style.height=SBT[1]+'px';t.textContent='+';const nw=rowEl('new','新项目','开一页空桌面',t);nw.classList.add('nw');ls.appendChild(nw);}
for(const p of L)ls.appendChild(rowEl('p:'+p.id,p.name,`${pageCount(p)} 样 · ${p.d}`,pageThumb(p,SBT)));
if(q&&!L.length)ls.innerHTML='
没有对得上的项目
';fitThumbs(ls);}
else{h.textContent='按用途';
for(const u of USES){let L=useItems(u);if(q)L=L.filter(x=>sbTxt(byId(x.id)).toLowerCase().includes(q));if(q&&!L.length)continue;ls.appendChild(rowEl('u:'+u,u,`${L.length} 样`,useThumb(u,SBT),USE[u]));}
if(!ls.children.length)ls.innerHTML='