notemend 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/client/run.js CHANGED
@@ -1,73 +1,74 @@
1
- import{categoryIcon as cs,categoryOf as Ie}from"../store/categories.mjs";import{stateOf as rt}from"../store/status.mjs";import{DOCS as Lt,STEP_RAYS as Vo,agentHandles as us,agentMentioned as ps,agentName as Jo,agentOwner as Go,agentStep as Jt,docOf as ms,docSlug as Xo,handleOf as Qo,held as Zo,stageOf as lt,threadOf as gs,toAgent as D,workingOn as Pe}from"../store/thread.mjs";import{api as L,canvasCopy as ta,host as ea,imageUrl as na}from"./api";import{recentLogs as sa}from"./logs";import{inspectors as oa}from"./inspect";import{anchors as aa,clean as ht}from"./anchor";import{bars as ia,fieldMenus as ra}from"./field-menu";import{AGENT_MARK as fs,CLAUDE_MARK as kt,CROSS as Fe,PENCIL as hs,TICK as Gt,TRASH as je,UNDO as bs,esc as m,stamp as la}from"./markup";import{canvas as da}from"./canvas";import{historyHtml as ca}from"./panel";import{review as ua}from"./review";import{turbo as pa}from"./turbo";function Ha(c){const dt=c.breakpoints,_e=c.categories,Xt=(dt.find(t=>!Number.isFinite(t.max))??dt[0]).id,Ke=t=>dt.find(e=>t>=e.min&&t<=e.max)?.id??Xt,J=t=>t.breakpoint||Xt,ys=t=>c.devices.find(e=>e.id===t),E=ta,G=(t,e)=>{E||localStorage.setItem(t,e)},Qt=t=>t.replace(/\/+$/,"")||"/";let j=Qt(location.pathname);for(const t of document.querySelectorAll(".devtools .dt-icon[title]"))t.dataset.tip=t.title,t.getAttribute("aria-label")||t.setAttribute("aria-label",t.title),t.removeAttribute("title");const We=document.querySelector(".dt-grid-btn"),xt=document.querySelector(".dt-grid-overlay"),Ue="dt-grid",Zt=t=>{xt.hidden=!t,We.setAttribute("aria-pressed",String(t)),G(Ue,t?"1":"0"),B({grid:t})};We.addEventListener("click",()=>Zt(xt.hidden===!0));const ze=document.querySelector(".dt-pages-name"),Ye=()=>{let t=null;for(const s of document.querySelectorAll(".dt-pages a"))Qt(new URL(s.href).pathname)===j?(s.setAttribute("aria-current","page"),t=s):s.removeAttribute("aria-current");const e=document.title.split("\u2014").pop()?.trim(),n=t?.querySelector(".dt-menu-label")?.textContent?.trim();ze.textContent=n||e||ze.textContent};Ye();const Ve=[...document.querySelectorAll(".devtools details")];let te=!1;const bt=()=>{const t=Ve.filter(e=>e.open);for(const e of t)e.open=!1;return t};document.addEventListener("keydown",t=>{if(t.key!=="Escape")return;const[e]=bt();e&&(e.querySelector("summary")?.focus(),t.preventDefault(),t.stopImmediatePropagation())},!0),document.addEventListener("pointerdown",t=>{te=Ve.some(e=>e.open&&!e.contains(t.target))&&bt().length>0},!0),addEventListener("blur",bt);const ct=document.querySelector(".dt-pad-overlay"),Je="dt-inspect",vs=[".devtools",".dt-pad-overlay",".dt-grid-overlay",".dt-frame",".dt-history",".dt-review",".dt-field-menu",...c.ignore].join(", "),ee=[".devtools",".dt-notes-overlay",".dt-history",".dt-frame",".dt-review",".dt-field-menu",'[aria-modal="true"]',...c.ignore].join(", "),ne={pads:document.querySelector(".dt-pad-btn"),sizes:document.querySelector(".dt-size-btn"),type:document.querySelector(".dt-type-btn"),color:document.querySelector(".dt-color-btn"),border:document.querySelector(".dt-border-btn")};let _="",se=0;const{spacer:$s,drawPads:ws,drawSize:Es,drawType:Ss,drawColor:Ts,drawBorder:Ms}=oa(ct),Ge=t=>{se||(se=requestAnimationFrame(()=>{se=0,ct.hidden=!0;let e=document.elementFromPoint(t.clientX,t.clientY);if(ct.hidden=!1,!e||e.closest(vs)){ct.innerHTML="";return}t.altKey&&e.parentElement&&e.parentElement!==document.body&&(e=e.parentElement),_==="sizes"?Es(e):_==="type"?Ss(e):_==="color"?Ts(e):_==="border"?Ms(e):ws(t.altKey?e:$s(e))}))},At=t=>{_=t;for(const[e,n]of Object.entries(ne))n.setAttribute("aria-pressed",String(e===t));G(Je,t),B({inspect:t}),ct.hidden=!t,ct.innerHTML="",t?document.addEventListener("mousemove",Ge):document.removeEventListener("mousemove",Ge)};for(const[t,e]of Object.entries(ne))e.addEventListener("click",()=>{t!==_&&Q(!1),At(_===t?"":t)});const Xe=document.querySelector(".dt-notes-btn"),oe=[...document.querySelectorAll(".dt-bp")],Ht=document.querySelector(".dt-history-btn"),H=document.querySelector(".dt-history"),ae=document.querySelector(".dt-studio-btn"),ie=document.querySelector(".dt-devices"),nt=document.querySelector(".dt-notes-hi"),Ls=nt.querySelector(".dt-hi-box"),Qe=nt.querySelector(".dt-hi-tag"),st=document.querySelector(".dt-frame"),Nt=st.querySelector("iframe"),re=document.querySelector(".dt-notes-count"),h=document.querySelector(".dt-notes-overlay"),Ze=".devtools, .dt-tab, .dt-notes-overlay, .dt-history, .dt-frame",tn=t=>{for(const e of["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend","click","focusin","focusout"])t.addEventListener(e,n=>n.stopPropagation())};document.querySelectorAll(Ze).forEach(tn);const en="dt-notes";let b=[],x=!1,$=null,l=null,le=0,R="",O=[],T=null,A=[];const Ct=(t=l)=>!!(t&&(t.text?.trim()||t.images?.length)),K=()=>{l&&Ct()&&A.push(l),l=null};let yt=null,de=null;const nn=()=>`dt-draft:${j}${E?":canvas":""}`;let ut=nn(),Rt=0;const ce=()=>{if(!l&&!A.length&&!R){localStorage.removeItem(ut);return}const t={draft:l,parked:A,reply:R?{for:yt,text:R}:null};try{localStorage.setItem(ut,JSON.stringify(t))}catch{const e=n=>({...n,images:void 0});try{localStorage.setItem(ut,JSON.stringify({...t,draft:l&&e(l),parked:A.map(e)}))}catch{}}},ot=()=>{clearTimeout(Rt),Rt=setTimeout(ce,200)};addEventListener("pagehide",()=>{clearTimeout(Rt),ce()});let W=localStorage.getItem("dt-resolved")!=="0";const ks=[[/Edg\/(\d+)/,"Edge"],[/OPR\/(\d+)/,"Opera"],[/Firefox\/(\d+)/,"Firefox"],[/Chrome\/(\d+)/,"Chrome"],[/Version\/(\d+).*Safari/,"Safari"]],xs=[[/iPhone|iPad/,"iOS"],[/Android/,"Android"],[/Mac OS X/,"macOS"],[/Windows/,"Windows"],[/Linux/,"Linux"]],As=()=>{const t=navigator.userAgent,e=a=>a.find(([i])=>i.test(t)),n=e(ks),s=e(xs),o=n?n[0].exec(t)?.[1]:null;return[n?`${n[1]}${o?" "+o:""}`:"unknown browser",s?.[1]].filter(Boolean).join(" \xB7 ")},ue=()=>Ke(innerWidth),Ot=()=>de??ue(),sn=()=>{const t=Ot();for(const e of oe)e.setAttribute("aria-pressed",String(e.dataset.bp===t))},{cssPath:Hs,poolOf:Ns,contextOf:Cs,resolveEl:q,anchorOf:Rs}=aa(),Bt=new Map,I=t=>{Bt.size||requestAnimationFrame(()=>Bt.clear());let e=Bt.get(t);return e===void 0&&(e=Rs(t),Bt.set(t,e)),e},on=t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if(e.getAnimations().some(n=>n.playState==="running"))return!0;return!1};let Dt=[];const pe=t=>{for(const e of Dt)e.play();Dt=[];for(let e=t;e&&e!==document.body;e=e.parentElement)for(const n of e.getAnimations())n.playState==="running"&&(n.pause(),Dt.push(n))},an=()=>{if(l)return q(l);const t=$!=null?b.find(n=>n.id===$):null;if(!t)return null;const e=I(t);return e&&!e.off?q(t):null},Os="claude",Bs=()=>(c.team??[]).filter(t=>t.email!==c.me?.email),qt=()=>[...c.me?(c.team??[]).filter(t=>t.email===c.me.email):[],...Bs()],Ds='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><circle cx="10" cy="10" r="6.5" stroke-dasharray="2.4 2.4"/></svg>',qs=(t,e,n=!1)=>{const s=D(t)?"agent":t?"person":"nobody",o=$t(s==="person"?t:rn());return`<span class="dt-hand" role="radiogroup" aria-label="Who takes it">${[["person",o?Pt(o.avatar_url,o.name||o.email):wt,s==="person"?`${It(t)==="you"?"You":It(t)} \u2014 pick someone else`:o?`Give it to ${o.email===c.me?.email?"me":o.name||o.email}`:"A person"],["nobody",Ds,"Nobody \u2014 not anyone's yet"],["agent",kt(12),n?"Waits for the studio to approve it":s==="agent"?"Claude does it":"Give it to Claude"]].map(([i,d,u])=>i===s?`<span class="dt-hand-stop dt-hand-stop--${i} is-on" role="radio" aria-checked="true" data-tip="${m(u)}" aria-label="${m(u)}">${i==="person"?Ks(t,e):d}</span>`:`<button type="button" class="dt-hand-stop dt-hand-stop--${i}" role="radio" aria-checked="false" data-act="hand" data-v="${i}"${e?` data-id="${e}"`:""} data-tip="${m(u)}" aria-label="${m(u)}"${i==="agent"&&n?" disabled":""}>${d}</button>`).join("")}</span>`},rn=()=>{const t=Fs();return t&&!D(t)&&qt().some(e=>e.email===t)?t:qt()[0]?.email??""},Is=()=>{const t=h.querySelector(".dt-hand .dt-hand-stop.is-on");return t?{rect:t.getBoundingClientRect(),ghost:t.cloneNode(!0)}:void 0},ln="cubic-bezier(0.32, 0.72, 0, 1)",dn=t=>{const e=h.querySelector(".dt-hand .dt-hand-stop.is-on");if(!t||!e||matchMedia("(prefers-reduced-motion: reduce)").matches)return;const n=e.getBoundingClientRect(),s=document.createElement("span");s.className="dt-hand dt-hand-ghost",s.style.cssText=`left:${t.rect.left}px;top:${t.rect.top}px;width:${t.rect.width}px;height:${t.rect.height}px`,t.ghost.querySelectorAll("select").forEach(o=>o.tabIndex=-1),s.append(t.ghost),h.append(s),s.animate([{opacity:1,filter:"blur(0)"},{opacity:0,filter:"blur(2px)"}],{duration:120,easing:"ease-out",fill:"forwards"}).finished.then(()=>s.remove(),()=>s.remove()),Se=performance.now()+480,e.animate([{transform:`translateX(${t.rect.left-n.left}px)`,width:`${t.rect.width}px`},{transform:"none",width:`${n.width}px`}],{duration:460,easing:ln});for(const o of e.children)o.animate([{opacity:0,transform:"scale(0.92)",filter:"blur(3px)"},{opacity:0,transform:"scale(0.92)",filter:"blur(3px)",offset:.4},{opacity:1,transform:"none",filter:"blur(0)"}],{duration:460,easing:ln});for(const o of e.parentElement?.querySelectorAll("button.dt-hand-stop")??[])o.animate([{opacity:0},{opacity:1}],{duration:300,delay:140,easing:"ease-out",fill:"backwards"})},Ps=(t,e)=>{const n=Se>performance.now()?void 0:Is(),s=e==="agent"?Os:e==="person"?rn():e==="me"?c.me?.email??"":"";if(!t){if(!l)return;if(l.assignee=s,l.stage=D(s)?"approved":!l.stage||l.stage==="approved"?"new":l.stage,e==="person")try{localStorage.setItem("nm-for",s)}catch{}ot(),f(),dn(n);return}const o=b.find(d=>d.id===t);if(o&&Pe(o)&&!D(s)&&!confirm("Claude is still working on this \u2014 it may finish its changes after you take it. Take it anyway?"))return;const a=o?lt(o):"new",i=D(s)?"approved":a==="approved"?"new":a;P(d=>d.map(u=>u.id===t?{...u,assignee:s||void 0,stage:i}:u),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,assignee:s||null,stage:i})}),D(s)?"Approving it for the agent":"Reassigning"),dn(n)},Fs=()=>{try{return localStorage.getItem("nm-for")??""}catch{return""}},vt=t=>D(t)?"#d97757":t?"#0d99ff":"#717171",It=t=>t===c.me?.email?"you":c.team?.find(e=>e.email===t)?.name||t.split("@")[0],$t=t=>t?c.team?.find(e=>e.email===t):void 0,cn=t=>{const e=ht(t??"").split(/\s+/).filter(Boolean);return m(((e[0]?.[0]??"?")+(e.length>1?e[e.length-1][0]:"")).toUpperCase())},Pt=(t,e,n="dt-face")=>t?`<img class="${n}" src="${m(t)}" alt="">`:`<b class="${n}" aria-hidden="true">${cn(e)}</b>`,js=t=>{const e=$t(t.by);return e||t.byName?Pt(e?.avatar_url,e?.name||t.byName||t.by):""},un=t=>{const e=$t(t);return e?` data-face="${m(e.avatar_url??"")}" data-initial="${cn(e.name||e.email)}"`:""},at=(t,e)=>Jo(t),pn=t=>{const e=$t(t);return e?Pt(e.avatar_url,e.name||e.email):""},_s=t=>{const e=$t(t)?.agent_avatar_url;return e?`<img class="dt-face" src="${m(e)}" alt="">`:`<b class="dt-face dt-face--ai" aria-hidden="true">${kt(12)}</b>`},Ks=(t,e)=>{const n=(o,a)=>`<option value="${m(o)}" data-c="${vt(o)}"${un(o||null)}${t===o?" selected":""}>${m(a)}</option>`,s=(c.team??[]).filter(o=>o.email!==c.me?.email);return`<label class="dt-field dt-field--knob"><span class="dt-field-box dt-field-box--face" style="--cat:${vt(t)}">${pn(t||null)||wt}<select class="dt-for-select"${e?` data-id="${e}"`:""} aria-label="Who does it">
1
+ import{categoryIcon as As,categoryOf as de}from"../store/categories.mjs";import{stateOf as P}from"../store/status.mjs";import{DOCS as Dt,agentHandles as Hs,agentMentioned as Ns,agentName as lo,agentOwner as co,agentStep as Z,docOf as Cs,docSlug as uo,handleOf as po,held as mo,stageOf as U,threadOf as It,toAgent as j,workingOn as Ge}from"../store/thread.mjs";import{api as L,canvasCopy as go,host as fo,imageUrl as ho}from"./api";import{recentLogs as bo}from"./logs";import{inspectors as yo}from"./inspect";import{anchors as vo,clean as wt}from"./anchor";import{bars as $o,fieldMenus as wo}from"./field-menu";import{AGENT_MARK as Rs,CLAUDE_MARK as Et,CROSS as Xe,PENCIL as Os,TICK as St,TRASH as Qe,UNDO as Ze,esc as p,stamp as qs}from"./markup";import{canvas as Eo}from"./canvas";import{historyHtml as So}from"./panel";import{review as To}from"./review";import{turbo as Mo}from"./turbo";function Ko(c){const pt=c.breakpoints,tn=c.categories,ce=(pt.find(t=>!Number.isFinite(t.max))??pt[0]).id,en=t=>pt.find(e=>t>=e.min&&t<=e.max)?.id??ce,tt=t=>t.breakpoint||ce,Bs=t=>c.devices.find(e=>e.id===t),E=go,O=(t,e)=>{E||localStorage.setItem(t,e)},ue=t=>t.replace(/\/+$/,"")||"/";let z=ue(location.pathname);for(const t of document.querySelectorAll(".devtools .dt-icon[title]"))t.dataset.tip=t.title,t.getAttribute("aria-label")||t.setAttribute("aria-label",t.title),t.removeAttribute("title");const nn=document.querySelector(".dt-grid-btn"),Pt=document.querySelector(".dt-grid-overlay"),sn="dt-grid",pe=t=>{Pt.hidden=!t,nn.setAttribute("aria-pressed",String(t)),O(sn,t?"1":"0"),D({grid:t})};nn.addEventListener("click",()=>pe(Pt.hidden===!0));const an=document.querySelector(".dt-pages-name"),on=()=>{let t=null;for(const s of document.querySelectorAll(".dt-pages a"))ue(new URL(s.href).pathname)===z?(s.setAttribute("aria-current","page"),t=s):s.removeAttribute("aria-current");const e=document.title.split("\u2014").pop()?.trim(),n=t?.querySelector(".dt-menu-label")?.textContent?.trim();an.textContent=n||e||an.textContent};on();const rn=[...document.querySelectorAll(".devtools details")];let me=!1;const Tt=()=>{const t=rn.filter(e=>e.open);for(const e of t)e.open=!1;return t};document.addEventListener("keydown",t=>{if(t.key!=="Escape")return;const[e]=Tt();e&&(e.querySelector("summary")?.focus(),t.preventDefault(),t.stopImmediatePropagation())},!0),document.addEventListener("pointerdown",t=>{me=rn.some(e=>e.open&&!e.contains(t.target))&&Tt().length>0},!0),addEventListener("blur",Tt);const mt=document.querySelector(".dt-pad-overlay"),ln="dt-inspect",Ds=[".devtools",".dt-pad-overlay",".dt-grid-overlay",".dt-frame",".dt-history",".dt-review",".dt-field-menu",...c.ignore].join(", "),ge=[".devtools",".dt-notes-overlay",".dt-history",".dt-frame",".dt-review",".dt-field-menu",'[aria-modal="true"]',...c.ignore].join(", "),fe={pads:document.querySelector(".dt-pad-btn"),sizes:document.querySelector(".dt-size-btn"),type:document.querySelector(".dt-type-btn"),color:document.querySelector(".dt-color-btn"),border:document.querySelector(".dt-border-btn")};let Y="",he=0;const{spacer:Is,drawPads:Ps,drawSize:js,drawType:Fs,drawColor:_s,drawBorder:Ks}=yo(mt),dn=t=>{he||(he=requestAnimationFrame(()=>{he=0,mt.hidden=!0;let e=document.elementFromPoint(t.clientX,t.clientY);if(mt.hidden=!1,!e||e.closest(Ds)){mt.innerHTML="";return}t.altKey&&e.parentElement&&e.parentElement!==document.body&&(e=e.parentElement),Y==="sizes"?js(e):Y==="type"?Fs(e):Y==="color"?_s(e):Y==="border"?Ks(e):Ps(t.altKey?e:Is(e))}))},jt=t=>{Y=t;for(const[e,n]of Object.entries(fe))n.setAttribute("aria-pressed",String(e===t));O(ln,t),D({inspect:t}),mt.hidden=!t,mt.innerHTML="",t?document.addEventListener("mousemove",dn):document.removeEventListener("mousemove",dn)};for(const[t,e]of Object.entries(fe))e.addEventListener("click",()=>{t!==Y&&nt(!1),jt(Y===t?"":t)});const cn=document.querySelector(".dt-notes-btn"),be=[...document.querySelectorAll(".dt-bp")],Ft=document.querySelector(".dt-history-btn"),x=document.querySelector(".dt-history"),ye=document.querySelector(".dt-studio-btn"),ve=document.querySelector(".dt-devices"),ot=document.querySelector(".dt-notes-hi"),Ws=ot.querySelector(".dt-hi-box"),un=ot.querySelector(".dt-hi-tag"),it=document.querySelector(".dt-frame"),_t=it.querySelector("iframe"),$e=document.querySelector(".dt-notes-count"),b=document.querySelector(".dt-notes-overlay"),pn=".devtools, .dt-tab, .dt-notes-overlay, .dt-history, .dt-frame",mn=t=>{for(const e of["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend","click","focusin","focusout"])t.addEventListener(e,n=>n.stopPropagation())};document.querySelectorAll(pn).forEach(mn);const gn="dt-notes";let y=[],H=!1,$=null,d=null,we=0,q="",B=[],T=null,N=[];const Kt=(t=d)=>!!(t&&(t.text?.trim()||t.images?.length)),V=()=>{d&&Kt()&&N.push(d),d=null};let Mt=null,Ee=null;const fn=()=>`dt-draft:${z}${E?":canvas":""}`;let gt=fn(),Wt=0;const Se=()=>{if(!d&&!N.length&&!q){localStorage.removeItem(gt);return}const t={draft:d,parked:N,reply:q?{for:Mt,text:q}:null};try{localStorage.setItem(gt,JSON.stringify(t))}catch{const e=n=>({...n,images:void 0});try{localStorage.setItem(gt,JSON.stringify({...t,draft:d&&e(d),parked:N.map(e)}))}catch{}}},rt=()=>{clearTimeout(Wt),Wt=setTimeout(Se,200)};addEventListener("pagehide",()=>{clearTimeout(Wt),Se()});let J=localStorage.getItem("dt-resolved")!=="0";const C={q:"",menu:!1,view:["me","agent"].includes(localStorage.getItem("dt-view")??"")?localStorage.getItem("dt-view"):"all",sort:localStorage.getItem("dt-sort")==="unread"?"unread":"new"},Us=[[/Edg\/(\d+)/,"Edge"],[/OPR\/(\d+)/,"Opera"],[/Firefox\/(\d+)/,"Firefox"],[/Chrome\/(\d+)/,"Chrome"],[/Version\/(\d+).*Safari/,"Safari"]],zs=[[/iPhone|iPad/,"iOS"],[/Android/,"Android"],[/Mac OS X/,"macOS"],[/Windows/,"Windows"],[/Linux/,"Linux"]],Ys=()=>{const t=navigator.userAgent,e=o=>o.find(([i])=>i.test(t)),n=e(Us),s=e(zs),a=n?n[0].exec(t)?.[1]:null;return[n?`${n[1]}${a?" "+a:""}`:"unknown browser",s?.[1]].filter(Boolean).join(" \xB7 ")},Te=()=>en(innerWidth),lt=()=>Ee??Te(),hn=()=>{const t=lt();for(const e of be)e.setAttribute("aria-pressed",String(e.dataset.bp===t))},{cssPath:Vs,poolOf:Js,contextOf:Gs,resolveEl:F,anchorOf:Xs}=vo(),Ut=new Map,_=t=>{Ut.size||requestAnimationFrame(()=>Ut.clear());let e=Ut.get(t);return e===void 0&&(e=Xs(t),Ut.set(t,e)),e},bn=t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if(e.getAnimations().some(n=>n.playState==="running"))return!0;return!1};let zt=[];const Me=t=>{for(const e of zt)e.play();zt=[];for(let e=t;e&&e!==document.body;e=e.parentElement)for(const n of e.getAnimations())n.playState==="running"&&(n.pause(),zt.push(n))},yn=()=>{if(d)return F(d);const t=$!=null?y.find(n=>n.id===$):null;if(!t)return null;const e=_(t);return e&&!e.off?F(t):null},Qs="claude",Zs=()=>(c.team??[]).filter(t=>t.email!==c.me?.email),Lt=()=>[...c.me?(c.team??[]).filter(t=>t.email===c.me.email):[],...Zs()],vn='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><circle cx="10" cy="10" r="6.5" stroke-dasharray="2.4 2.4"/></svg>',ta=(t,e,n=!1)=>{const s=j(t)?"agent":t?"person":"nobody",a=xt(s==="person"?t:$n());return`<span class="dt-hand" role="radiogroup" aria-label="Who takes it">${[["person",a?Vt(a.avatar_url,a.name||a.email):At,s==="person"?`${Yt(t)==="you"?"You":Yt(t)} \u2014 pick someone else`:a?`Give it to ${a.email===c.me?.email?"me":a.name||a.email}`:"A person"],["nobody",vn,"Anyone \u2014 nobody has taken it yet"],["agent",Et(12),n?"Waits for the studio to approve it":s==="agent"?"Claude does it":"Give it to Claude"]].map(([i,l,u])=>i===s?`<span class="dt-hand-stop dt-hand-stop--${i} is-on" role="radio" aria-checked="true" data-tip="${p(u)}" aria-label="${p(u)}">${i==="person"?ia(t,e):l}</span>`:`<button type="button" class="dt-hand-stop dt-hand-stop--${i}" role="radio" aria-checked="false" data-act="hand" data-v="${i}"${e?` data-id="${e}"`:""} data-tip="${p(u)}" aria-label="${p(u)}"${i==="agent"&&n?" disabled":""}>${l}</button>`).join("")}</span>`},$n=()=>{const t=sa();return t&&!j(t)&&Lt().some(e=>e.email===t)?t:Lt()[0]?.email??""},ea=()=>{const t=b.querySelector(".dt-hand .dt-hand-stop.is-on");return t?{rect:t.getBoundingClientRect(),ghost:t.cloneNode(!0)}:void 0},wn="cubic-bezier(0.32, 0.72, 0, 1)",En=t=>{const e=b.querySelector(".dt-hand .dt-hand-stop.is-on");if(!t||!e||matchMedia("(prefers-reduced-motion: reduce)").matches)return;const n=e.getBoundingClientRect(),s=document.createElement("span");s.className="dt-hand dt-hand-ghost",s.style.cssText=`left:${t.rect.left}px;top:${t.rect.top}px;width:${t.rect.width}px;height:${t.rect.height}px`,t.ghost.querySelectorAll("select").forEach(a=>a.tabIndex=-1),s.append(t.ghost),b.append(s),s.animate([{opacity:1,filter:"blur(0)"},{opacity:0,filter:"blur(2px)"}],{duration:120,easing:"ease-out",fill:"forwards"}).finished.then(()=>s.remove(),()=>s.remove()),qe=performance.now()+480,e.animate([{transform:`translateX(${t.rect.left-n.left}px)`,width:`${t.rect.width}px`},{transform:"none",width:`${n.width}px`}],{duration:460,easing:wn});for(const a of e.children)a.animate([{opacity:0,transform:"scale(0.92)",filter:"blur(3px)"},{opacity:0,transform:"scale(0.92)",filter:"blur(3px)",offset:.4},{opacity:1,transform:"none",filter:"blur(0)"}],{duration:460,easing:wn});for(const a of e.parentElement?.querySelectorAll("button.dt-hand-stop")??[])a.animate([{opacity:0},{opacity:1}],{duration:300,delay:140,easing:"ease-out",fill:"backwards"})},na=(t,e)=>{const n=qe>performance.now()?void 0:ea(),s=e==="agent"?Qs:e==="person"?$n():e==="me"?c.me?.email??"":"";if(!t){if(!d)return;if(d.assignee=s,d.stage=j(s)?"approved":!d.stage||d.stage==="approved"?"new":d.stage,e==="person")try{localStorage.setItem("nm-for",s)}catch{}rt(),f(),En(n);return}const a=y.find(l=>l.id===t);if(a&&Ge(a)&&!j(s)&&!confirm("Claude is still working on this \u2014 it may finish its changes after you take it. Take it anyway?"))return;const o=a?U(a):"new",i=j(s)?"approved":o==="approved"?"new":o;K(l=>l.map(u=>u.id===t?{...u,assignee:s||void 0,stage:i}:u),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,assignee:s||null,stage:i})}),j(s)?"Approving it for the agent":"Reassigning"),En(n)},sa=()=>{try{return localStorage.getItem("nm-for")??""}catch{return""}},kt=t=>j(t)?"#d97757":t?"#0d99ff":"#717171",Yt=t=>t===c.me?.email?"you":c.team?.find(e=>e.email===t)?.name||t.split("@")[0],xt=t=>t?c.team?.find(e=>e.email===t):void 0,Sn=t=>{const e=wt(t??"").split(/\s+/).filter(Boolean);return p(((e[0]?.[0]??"?")+(e.length>1?e[e.length-1][0]:"")).toUpperCase())},Vt=(t,e,n="dt-face")=>t?`<img class="${n}" src="${p(t)}" alt="">`:`<b class="${n}" aria-hidden="true">${Sn(e)}</b>`,Tn=t=>{const e=xt(t.by);return e||t.byName?Vt(e?.avatar_url,e?.name||t.byName||t.by):""},Mn=t=>`var(--dt-avatar-${[...t].reduce((e,n)=>e*31+n.charCodeAt(0)>>>0,7)%8+1})`,Ln={queued:"var(--dt-new)",working:"var(--dt-progress)",asks:"var(--dt-waiting)",stuck:"var(--dt-stuck)",review:"var(--dt-review)",done:"var(--dt-accepted)"},ft=(()=>{try{return JSON.parse(localStorage.getItem("dt-seen")||"{}")}catch{return{}}})(),kn=()=>{try{O("dt-seen",JSON.stringify(ft))}catch{}},xn=t=>{const e=It(t);if(!(t.id in ft))return ft[t.id]=e.length,kn(),!1;const n=e[e.length-1];return e.length>ft[t.id]&&!(n?.author==="you"&&(!n.by||n.by===c.me?.email))},aa=t=>{const e=It(t).length;ft[t.id]!==e&&(ft[t.id]=e,kn())},Le=t=>{const e=xt(t);return e?` data-face="${p(e.avatar_url??"")}" data-initial="${Sn(e.name||e.email)}"`:""},dt=(t,e)=>lo(t),An=t=>{const e=xt(t);return e?Vt(e.avatar_url,e.name||e.email):""},oa=t=>{const e=xt(t)?.agent_avatar_url;return e?`<img class="dt-face" src="${p(e)}" alt="">`:`<b class="dt-face dt-face--ai" aria-hidden="true">${Et(12)}</b>`},ia=(t,e)=>{const n=(a,o)=>`<option value="${p(a)}" data-c="${kt(a)}"${Le(a||null)}${t===a?" selected":""}>${p(o)}</option>`,s=(c.team??[]).filter(a=>a.email!==c.me?.email);return`<label class="dt-field dt-field--knob"><span class="dt-field-box dt-field-box--face" style="--cat:${kt(t)}">${An(t||null)||At}<select class="dt-for-select"${e?` data-id="${e}"`:""} aria-label="Who does it">
2
2
  ${c.me?n(c.me.email,`Me \xB7 ${c.me.name||c.me.email}`):""}
3
- ${s.map(o=>n(o.email,o.name||o.email)).join("")}${t&&t!==c.me?.email&&!s.some(o=>o.email===t)?n(t,It(t)):""}
4
- </select></span></label>`},mn=t=>{const e=ht(t?.textContent).replace(/\s+/g," ");return e&&e.length<=2e3?e:""},Ws=t=>`<div class="dt-suggest dt-suggest--read"><del>${m(t.from)}</del><ins>${m(t.to)}</ins></div>`,gn=(t,e)=>{const n=String(t??"").replace(/\s*>\s*/g," \u203A ").slice(-160);return m([n,ht(e??"")&&`\u201C${ht(e).slice(0,80)}\u201D`].filter(Boolean).join(" \xB7 "))},Us='<svg class="dt-chev" viewBox="0 0 12 12" width="9" height="9" aria-hidden="true"><path d="M3 4.5 6 7.5 9 4.5"/></svg>',zs=(t,e)=>{const n=Ie(t);return`<label class="dt-field dt-field--bare" data-tip="Type: ${m(n.label)}"><span class="dt-field-box">${cs(n)}<span class="dt-field-label">${m(n.label)}</span>${Us}<select class="dt-cat-select"${e?` data-id="${e}"`:""} aria-label="Type">${_e.map(s=>`<option value="${s.id}" data-c="${s.color}" data-icon="${m(cs(s))}"${s.id===t?" selected":""}>${s.label}</option>`).join("")}</select></span></label>`},me=[["new","New","#0d99ff",.25],["progress","In progress","#f5a623",.5],["review","Needs review","#8e4ec6",.75],["waiting","Waiting","#e93d82",.875]],ge=(t,e)=>{const s=2*Math.PI*e,o=8+3.3*Math.sin(s),a=8-3.3*Math.cos(s),i=`<path d="M8 8V${8-3.3}A${3.3} ${3.3} 0 ${e>.5?1:0} 1 ${o.toFixed(2)} ${a.toFixed(2)}Z" fill="${t}"/>`;return`<svg class="dt-stage-icon" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><rect x="3.2" y="3.2" width="9.6" height="9.6" rx="2.4" transform="rotate(45 8 8)" fill="none" stroke="${t}" stroke-width="1.5"/>${i}</svg>`},fn=t=>Pe(t)||lt(t)==="progress"?"progress":lt(t)==="review"?"review":lt(t)==="waiting"?"waiting":"new",fe={queued:"new",working:"progress",stuck:"progress",asks:"waiting",review:"review",held:"new"},ma=(t,e)=>{const[,,n,s]=me.find(o=>o[0]===t)??["","","#30a46c",1];return`<span class="dt-status-chip" style="--cat:${n}" data-tip="${t==="done"?"Resolved":"Set by Claude's step"}">${ge(n,s)}<span>${e}</span></span>`},hn=[...me,["done","Resolved","#30a46c",1]],Ys=t=>{const e=Jt(t),n=t.status==="done"&&e!=="review"?"done":e&&fe[e]?fe[e]:fn(t),[,,s,o]=hn.find(a=>a[0]===n);return`<label class="dt-field" data-tip="${e&&fe[e]?"Follows Claude \u2014 or pick one":"Status"}"><span class="dt-field-box dt-field-box--icon" style="--cat:${s}">${ge(s,o)}<select class="dt-status-select" data-id="${t.id}" aria-label="Status">${hn.map(([a,i,d,u])=>`<option value="${a}" data-c="${d}" data-icon="${m(ge(d,u))}"${a===n?" selected":""}>${i}</option>`).join("")}</select></span></label>`},Vs=(t,e)=>{const n=b.find(a=>a.id===t);if(!n)return;if(e==="done"){pt(t,!0);return}const s=e==="new"?D(n.assignee)?"approved":"new":e,o=n.status==="done"?{status:"open",doneBy:null}:{};P(a=>a.map(i=>i.id===t?{...i,...o,stage:s}:i),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,...o,stage:s})}),"Setting the status")},Ft=[["low","Low","#30a46c",1],["normal","Mid","#f5c451",2],["high","High","#ff5a00",3],["urgent","Urgent","#e5484d",4]],Js=(t,e)=>{const n=Math.max(0,Ft.findIndex(d=>d[0]===t)),[,s,o,a]=Ft[n],i=Ft[(n+1)%Ft.length];return`<button type="button" class="dt-prio" style="--cat:${o}" data-act="prio" data-v="${i[0]}"${e?` data-id="${e}"`:""} data-tip="Priority: ${s} \u2014 click for ${i[1]}" aria-label="Priority ${s}">${ia(a,o)}<span>${s}</span></button>`},he=()=>!!c.me&&/@guest\.notemend\.com$/i.test(c.me.email),bn=(t,e,n,s,o=!1)=>`<div class="dt-prio-row"><span class="dt-meta">${c.client?"":Js(t,n)}${zs(Ie(e).id,n)}</span>${c.client||he()?"":qs(s,n,o)}</div>`,wt='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="10" cy="6.8" r="3"/><path d="M4.2 16.5c.6-3 3-4.8 5.8-4.8s5.2 1.8 5.8 4.8" stroke-linejoin="round"/></svg>',yn='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="10" cy="6.8" r="3"/><path d="M4.2 16.5c.6-3 3-4.8 5.8-4.8s5.2 1.8 5.8 4.8" stroke-linejoin="round"/><path d="M3.5 3.5l13 13"/></svg>',Gs='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><circle cx="5" cy="10" r="1.1" fill="currentColor" stroke="none"/><circle cx="10" cy="10" r="1.1" fill="currentColor" stroke="none"/><circle cx="15" cy="10" r="1.1" fill="currentColor" stroke="none"/></svg>',vn=(t,e)=>`<label class="dt-more" data-tip="More"><span aria-hidden="true">${Gs}</span><select class="dt-more-select"${e?` data-id="${e}"`:""} aria-label="More">
3
+ ${s.map(a=>n(a.email,a.name||a.email)).join("")}${t&&t!==c.me?.email&&!s.some(a=>a.email===t)?n(t,Yt(t)):""}
4
+ </select></span></label>`},Hn=t=>{const e=wt(t?.textContent).replace(/\s+/g," ");return e&&e.length<=2e3?e:""},ra=t=>`<div class="dt-suggest dt-suggest--read"><del>${p(t.from)}</del><ins>${p(t.to)}</ins></div>`,Nn=(t,e)=>{const n=String(t??"").replace(/\s*>\s*/g," \u203A ").slice(-160);return p([n,wt(e??"")&&`\u201C${wt(e).slice(0,80)}\u201D`].filter(Boolean).join(" \xB7 "))},la='<svg class="dt-chev" viewBox="0 0 12 12" width="9" height="9" aria-hidden="true"><path d="M3 4.5 6 7.5 9 4.5"/></svg>',da=(t,e)=>{const n=de(t);return`<label class="dt-field dt-field--bare" data-tip="Type: ${p(n.label)}"><span class="dt-field-box">${As(n)}<span class="dt-field-label">${p(n.label)}</span>${la}<select class="dt-cat-select"${e?` data-id="${e}"`:""} aria-label="Type">${tn.map(s=>`<option value="${s.id}" data-c="${s.color}" data-icon="${p(As(s))}"${s.id===t?" selected":""}>${s.label}</option>`).join("")}</select></span></label>`},Jt=[["new","New","#0d99ff",.25],["progress","In progress","#f5a623",.5],["review","Needs review","#8e4ec6",.75],["waiting","Waiting","#e93d82",.875],["accepted","Accepted","#30a46c",.95]],ke=(t,e)=>{const s=2*Math.PI*e,a=8+3.3*Math.sin(s),o=8-3.3*Math.cos(s),i=`<path d="M8 8V${8-3.3}A${3.3} ${3.3} 0 ${e>.5?1:0} 1 ${a.toFixed(2)} ${o.toFixed(2)}Z" fill="${t}"/>`;return`<svg class="dt-stage-icon" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><rect x="3.2" y="3.2" width="9.6" height="9.6" rx="2.4" transform="rotate(45 8 8)" fill="none" stroke="${t}" stroke-width="1.5"/>${i}</svg>`},Gt=t=>U(t)==="accepted"?"accepted":Ge(t)||U(t)==="progress"?"progress":U(t)==="review"?"review":U(t)==="waiting"?"waiting":"new",Xt={queued:"new",working:"progress",stuck:"progress",asks:"waiting",review:"review",held:"new",done:"accepted"},Lo=(t,e)=>{const[,,n,s]=Jt.find(a=>a[0]===t)??["","","#30a46c",1];return`<span class="dt-status-chip" style="--cat:${n}" data-tip="${t==="done"?"Resolved":"Set by Claude's step"}">${ke(n,s)}<span>${e}</span></span>`},Cn=[...Jt,["done","Resolved","#30a46c",1]],ca=t=>{const e=Z(t),n=t.status==="done"&&e!=="review"?"done":e&&Xt[e]?Xt[e]:Gt(t),[,,s,a]=Cn.find(o=>o[0]===n);return`<label class="dt-field" data-tip="${e&&Xt[e]?"Follows Claude \u2014 or pick one":"Status"}"><span class="dt-field-box dt-field-box--icon" style="--cat:${s}">${ke(s,a)}<select class="dt-status-select" data-id="${t.id}" aria-label="Status">${Cn.map(([o,i,l,u])=>`<option value="${o}" data-c="${l}" data-icon="${p(ke(l,u))}"${o===n?" selected":""}>${i}</option>`).join("")}</select></span></label>`},Rn=(t,e)=>{const n=y.find(o=>o.id===t);if(!n)return;if(e==="done"){ht(t,!0);return}const s=e==="new"?j(n.assignee)?"approved":"new":e,a=n.status==="done"?{status:"open",doneBy:null}:{};K(o=>o.map(i=>i.id===t?{...i,...a,stage:s}:i),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,...a,stage:s})}),"Setting the status")},Qt=[["low","Low","#30a46c",1],["normal","Mid","#f5c451",2],["high","High","#ff5a00",3],["urgent","Urgent","#e5484d",4]],ua=(t,e)=>{const n=Math.max(0,Qt.findIndex(l=>l[0]===t)),[,s,a,o]=Qt[n],i=Qt[(n+1)%Qt.length];return`<button type="button" class="dt-prio" style="--cat:${a}" data-act="prio" data-v="${i[0]}"${e?` data-id="${e}"`:""} data-tip="Priority: ${s} \u2014 click for ${i[1]}" aria-label="Priority ${s}">${$o(o,a)}<span>${s}</span></button>`},Zt=()=>!!c.me&&/@guest\.notemend\.com$/i.test(c.me.email),On=(t,e,n,s,a=!1)=>`<div class="dt-prio-row"><span class="dt-meta">${c.client?"":ua(t,n)}${da(de(e).id,n)}</span>${c.client||Zt()?"":ta(s,n,a)}</div>`,At='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="10" cy="6.8" r="3"/><path d="M4.2 16.5c.6-3 3-4.8 5.8-4.8s5.2 1.8 5.8 4.8" stroke-linejoin="round"/></svg>',pa='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="8.5" cy="6.8" r="3"/><path d="M2.8 16.5c.6-3 3-4.8 5.7-4.8 1.3 0 2.5.4 3.5 1.1M15.5 11v5M13 13.5h5" stroke-linejoin="round"/></svg>',qn='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="10" cy="6.8" r="3"/><path d="M4.2 16.5c.6-3 3-4.8 5.8-4.8s5.2 1.8 5.8 4.8" stroke-linejoin="round"/><path d="M3.5 3.5l13 13"/></svg>',ma='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><circle cx="5" cy="10" r="1.1" fill="currentColor" stroke="none"/><circle cx="10" cy="10" r="1.1" fill="currentColor" stroke="none"/><circle cx="15" cy="10" r="1.1" fill="currentColor" stroke="none"/></svg>',Bn=(t,e)=>`<label class="dt-more" data-tip="More"><span aria-hidden="true">${ma}</span><select class="dt-more-select"${e?` data-id="${e}"`:""} aria-label="More">
5
5
  <option value="" hidden selected></option>
6
- ${c.client?"":`<option value="team" data-icon="${m(yn)}"${t?"":" data-on"}>Team only</option>
7
- <option value="client" data-icon="${m(wt)}"${t?" data-on":""}>Team and client</option>`}
8
- <option value="${e?"rm":"discard"}" data-icon="${m(je)}" data-danger${c.client?"":" data-sep"}>${e?"Delete thread":"Discard draft"}</option>
9
- </select></label>`,$n='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M2 10s3-5.5 8-5.5S18 10 18 10s-3 5.5-8 5.5S2 10 2 10z"/><circle cx="10" cy="10" r="2.3"/></svg>',ga=(t,e)=>`<button type="button" class="dt-share${t?" is-on":""}" data-act="share" data-v="${t?"":"1"}"${e?` data-id="${e}"`:""}
10
- aria-pressed="${!!t}" title="${t?"Shared with the client \u2014 click to keep it to the team":"Team only \u2014 click to share it with the client"}">${t?wt:yn}</button>`,Xs=()=>(c.team??[]).filter(t=>!c.studio||c.studio.includes(t.email)),Qs=t=>{const e=t||c.lead||"",n=Xs();if(!n.length)return"";const s=pn(e);return`<label class="dt-field" title="Who it is for"><span class="dt-field-box${s?" dt-field-box--face":""}" style="--cat:${vt(e||"x@x")}">${s}<select class="dt-for-select" aria-label="Who this is for">
11
- ${n.map(o=>`<option value="${m(o.email)}" data-c="${vt(o.email)}"${un(o.email)}${e===o.email?" selected":""}>${m(o.name||o.email)}</option>`).join("")}
12
- </select></span></label>`},be='<svg viewBox="0 0 20 20" width="9" height="9" aria-hidden="true"><path d="M5.5 5.5l9 9M14.5 5.5l-9 9"/></svg>',Zs=!1,to=!1,wn='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M3 1.8v8.4L10 6z"/></svg>',eo='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M2.5 1.5h2.5v9H2.5zM7 1.5h2.5v9H7z"/></svg>',no=t=>`${Math.floor(t/60)}:${String(Math.floor(t%60)).padStart(2,"0")}`,so=(t,e)=>{const n=t.closest(".dt-voice"),s=n.querySelector("audio"),o=n.querySelector(".dt-voice-play");if(!s.dataset.wired){s.dataset.wired="1";const d=n.querySelector(".dt-voice-track i"),u=n.querySelector(".dt-voice-time"),p=()=>Number.isFinite(s.duration)?s.duration:0;s.addEventListener("timeupdate",()=>{d.style.transform=`scaleX(${p()?Math.min(1,s.currentTime/p()):0})`,u.textContent=no(s.currentTime)}),s.addEventListener("play",()=>{o.innerHTML=eo,o.setAttribute("aria-label","Pause"),n.classList.add("is-playing")}),s.addEventListener("pause",()=>{o.innerHTML=wn,o.setAttribute("aria-label","Play the voice note"),n.classList.remove("is-playing")}),s.addEventListener("ended",()=>{s.currentTime=0})}const a=()=>{if(e){const d=n.querySelector(".dt-voice-track").getBoundingClientRect();Number.isFinite(s.duration)&&(s.currentTime=Math.max(0,Math.min(1,(e.clientX-d.left)/d.width))*s.duration);return}if(!s.paused){s.pause();return}h.querySelectorAll(".dt-voice audio").forEach(d=>{d!==s&&d.pause()}),s.play().catch(()=>{})};if(Number.isFinite(s.duration)||s.readyState<1){s.readyState<1?s.addEventListener("loadedmetadata",()=>Number.isFinite(s.duration)?a():i(),{once:!0}):a();return}i();function i(){s.addEventListener("timeupdate",()=>{s.currentTime=0,a()},{once:!0}),s.currentTime=1e9}},ye=t=>t.startsWith("data:audio/")||/(^|\/)voice-[^/?]*\.(webm|m4a)(\?|$)/i.test(t),En=t=>t.startsWith("data:video/")||/\.webm(\?|$)/i.test(t),Et=new Map,oo=t=>{if(!t.startsWith("data:"))return t;let e=Et.get(t);if(!e){const[n,s]=t.split(",",2);if(e=URL.createObjectURL(new Blob([Uint8Array.from(atob(s),o=>o.charCodeAt(0))],{type:n.slice(5).split(";")[0]})),Et.set(t,e),Et.size>8){const[o,a]=Et.entries().next().value;URL.revokeObjectURL(a),Et.delete(o)}}return e},ao=(t,e)=>`<span class="dt-voice"><button type="button" class="dt-voice-play" data-act="voice" aria-label="Play the voice note">${wn}</button><button type="button" class="dt-voice-track" data-act="voice-seek" aria-label="Jump"><i></i></button><span class="dt-voice-time">0:00</span><audio src="${oo(t)}" preload="metadata"></audio>${e===void 0?"":`<button class="dt-voice-rm" data-act="voice-write" ${e} aria-label="Write it out" title="Write it out \u2014 its words go in the box">${bo}</button>`}${e===void 0?"":`<button class="dt-voice-rm" data-act="unshot" ${e} aria-label="Remove the recording" title="Remove the recording">${be}</button>`}</span>`,io=(t,e,n)=>`<span class="dt-shot dt-doc">${t.startsWith("data:")?`<span class="dt-doc-name">${Ln}${m(e)}</span>`:`<a class="dt-doc-name" href="${t}" target="_blank" rel="noreferrer">${Ln}${m(e)}</a>`}${n===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${n} aria-label="Remove">${be}</button>`}</span>`,Sn=(t,e,n=t)=>ms(n)?io(t,ms(n),e):ye(n)?ao(t,e):`<span class="dt-shot${En(n)?" dt-shot--video":""}">${En(n)?`<video src="${t}" controls preload="metadata" playsinline></video>`:`<a href="${t}" target="_blank"><img src="${t}" alt="" loading="lazy" /></a>`}${e===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${e} aria-label="Remove">${be}</button>`}</span>`,Tn=(t=[],e)=>t.length?`<div class="dt-note-shots">${t.map(n=>{const s=n.split("/").pop(),o=na(s);return Sn(o,e===void 0?void 0:`data-id="${e}" data-img="${m(s)}"`,s)}).join("")}</div>`:"",Mn=(t=[])=>t.length?`<div class="dt-note-shots">${t.map((e,n)=>Sn(e,`data-i="${n}"`)).join("")}</div>`:"",Ln='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M11.5 2.5H6a1.5 1.5 0 0 0-1.5 1.5v12A1.5 1.5 0 0 0 6 17.5h8a1.5 1.5 0 0 0 1.5-1.5V6.5z"/><path d="M11.5 2.5v4h4"/></svg>',ro='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="2.5" y="5.5" width="11" height="9" rx="2"/><path d="m13.5 9 4-2.5v7l-4-2.5"/></svg>',lo='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><path d="M3.5 5.5h8M7.5 5.5v10M11 15.5l5-5 1.5 1.5-5 5H11z" stroke-linejoin="round"/></svg>',co=!!navigator.mediaDevices?.getDisplayMedia&&typeof MediaRecorder<"u";let it=null;const uo=async t=>{if(it){it.stop();return}let e;try{e=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:12},audio:!1})}catch{return}const n=await navigator.mediaDevices.getUserMedia({audio:!0}).catch(()=>null),s=new MediaStream([...e.getVideoTracks(),...n?.getAudioTracks()??[]]),o=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm"].find(p=>MediaRecorder.isTypeSupported(p));if(!o){for(const p of e.getTracks())p.stop();k("This browser cannot record WebM video.");return}const a=new MediaRecorder(s,{mimeType:o,videoBitsPerSecond:6e5,audioBitsPerSecond:32e3}),i=[],d=!!Number(t?.dataset.id);a.ondataavailable=p=>{p.data.size&&i.push(p.data)};const u=setTimeout(()=>{a.state!=="inactive"&&a.stop()},3e4);a.onstop=async()=>{clearTimeout(u);for(const y of[...e.getTracks(),...n?.getTracks()??[]])y.stop();it=null;const p=new Blob(i,{type:"video/webm"});if(p.size>32e5){k("That recording is too big to send \u2014 keep it shorter."),f();return}const r=await new Promise(y=>{const g=new FileReader;g.onload=()=>y(String(g.result)),g.readAsDataURL(p)});d?O.push(r):l&&(l.images??=[]).push(r),f()},e.getVideoTracks()[0]?.addEventListener("ended",()=>{a.state!=="inactive"&&a.stop()}),it=a,a.start(1e3),f()},po='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="7.5" y="3" width="5" height="9" rx="2.5"/><path d="M5 9.5a5 5 0 0 0 10 0M10 14.5V17"/></svg>',mo='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="m5 10.5 3.2 3L15 6.5"/></svg>',go=90,ve=32,fo=()=>!!c.voice&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<"u";let jt=!1;const ho=async(t,e)=>{if(jt||!t)return;const n=Number(t.dataset.id)||0;jt=!0,e.classList.add("is-asking"),e.title="Waiting for the microphone \u2014 allow it in the browser";let s;try{s=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(S){jt=!1,e.classList.remove("is-asking");const v=S?.name;k(v==="NotAllowedError"?"The microphone is blocked for this site \u2014 allow it from the icon left of the address, then try again.":v==="NotFoundError"?"No microphone found \u2014 plug one in or pick it in the system settings.":v==="NotReadableError"?"The microphone is busy in another app \u2014 close it there and try again.":`The microphone did not start: ${S?.message||v||"unknown error"}`);return}e.classList.remove("is-asking");const o=()=>h.querySelector(n?`.dt-note[data-id="${n}"] .dt-compose`:".dt-note[data-draft] .dt-compose"),a=document.createElement("div");a.className="dt-rec",a.innerHTML=`<button type="button" class="dt-rec-x" title="Discard (Esc)" aria-label="Discard">${je}</button><span class="dt-rec-time"><i></i><b>0:00</b></span><span class="dt-rec-wave">${"<i></i>".repeat(ve)}</span><button type="button" class="dt-rec-done" title="Done \u2014 write it out" aria-label="Done">${mo}</button>`;const i=a.querySelector("b"),d=[...a.querySelectorAll(".dt-rec-wave i")],u=new AudioContext,p=u.createAnalyser();p.fftSize=512,u.createMediaStreamSource(s).connect(p);const r=new Uint8Array(p.fftSize),y=[],g=new MediaRecorder(s,{audioBitsPerSecond:32e3}),w=[],M=Date.now();let N=!0;const Z=setInterval(()=>{const S=o();S&&a.parentElement!==S&&S.appendChild(a),p.getByteTimeDomainData(r);let v=0;for(const V of r)v+=((V-128)/128)**2;y.push(Math.min(1,Math.sqrt(v/r.length)*4));const Y=y.slice(-ve);d.forEach((V,Vt)=>{const et=Y[Vt-(ve-Y.length)];V.style.transform=`scaleY(${Math.max(.1,et??0).toFixed(2)})`,V.classList.toggle("is-empty",et===void 0)});const C=Math.floor((Date.now()-M)/1e3);i.textContent=`${Math.floor(C/60)}:${String(C%60).padStart(2,"0")}`,C>=go&&g.state!=="inactive"&&g.stop()},90),tt=S=>{N=S,g.state!=="inactive"&&g.stop()};a.querySelector(".dt-rec-x").addEventListener("click",S=>{S.stopPropagation(),tt(!1)}),a.querySelector(".dt-rec-done").addEventListener("click",S=>{S.stopPropagation(),tt(!0)}),a.addEventListener("keydown",S=>{S.key==="Escape"&&(S.stopPropagation(),tt(!1))}),g.ondataavailable=S=>{S.data.size&&w.push(S.data)},g.onstop=async()=>{if(clearInterval(Z),s.getTracks().forEach(Y=>Y.stop()),u.close().catch(()=>{}),a.remove(),jt=!1,!N)return;const S=new Blob(w,{type:g.mimeType||"audio/webm"}),v=await new Promise(Y=>{const C=new FileReader;C.onload=()=>Y(String(C.result)),C.readAsDataURL(S)});n?O.push(v):l&&(l.images??=[]).push(v),f(),o()?.querySelector("textarea")?.focus()},g.start(1e3),o()?.appendChild(a),a.querySelector(".dt-rec-done").focus()},kn="\u{1F3A4} Voice note",bo='<svg viewBox="0 0 20 20" width="12" height="12" aria-hidden="true"><rect x="2.5" y="4.5" width="15" height="11" rx="2"/><path d="M6 11.5h3M11 11.5h3M6 8.5h8"/></svg>',yo=async t=>{const e=t.closest(".dt-note"),s=(e?.hasAttribute("data-draft")?l?.images??[]:O)[Number(t.dataset.i)];if(!s||t.classList.contains("is-asking"))return;t.classList.add("is-asking");const o=await L("transcribe",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({audio:s})}).catch(()=>null),a=o?await o.json().catch(()=>({})):{};if(t.classList.remove("is-asking"),!o?.ok||!a.text){k(a.error||(o?.ok?"Didn't hear any words in it.":"Could not make out the words \u2014 try again, or type it."));return}const i=e?.querySelector("textarea.dt-note-input, textarea.dt-note-reply-input");i&&(i.value=i.value.trim()?`${i.value.trimEnd()} ${a.text}`:a.text,i.dispatchEvent(new Event("input",{bubbles:!0})),i.focus())},U=new Map,vo=async(t,e)=>{const n=`${t}:${e}`;if(U.has(n)){U.delete(n),f();return}const s=b.find(d=>d.id===t),o=s&&gs(s).find(d=>(d.at??"0")===e);if(!o?.text)return;U.set(n,null),f();const a=await L("translate",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:o.text,to:navigator.language||"en"})}).catch(()=>null),i=a?await a.json().catch(()=>({})):{};U.has(n)&&(a?.ok&&i.text?U.set(n,i.text):(U.delete(n),k(i.error||"Could not translate it \u2014 try again.")),f())},$o='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M3 5h8M7 3v2m2 0c-.6 3.2-2.8 6-6 7.5M5.5 8.5c.8 1.6 2.2 2.9 4 3.8M10.5 17l3.25-7.5L17 17m-5.5-2h4.5"/></svg>',wo='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="3" y="4" width="14" height="12" rx="2"/><circle cx="7.5" cy="8.5" r="1.4"/><path d="m3.5 14.5 4-4 3 3 2-2 4 4"/></svg>',xn=(t,e,n,s,o="",a="")=>`<div class="dt-note-foot"><div class="dt-compose">
13
- <textarea class="${t}" rows="1" placeholder="${e}">${m(n)}</textarea>
14
- ${o}
6
+ ${c.client?"":`<option value="team" data-icon="${p(qn)}"${t?"":" data-on"}>Team only</option>
7
+ <option value="client" data-icon="${p(At)}"${t?" data-on":""}>Team and client</option>`}
8
+ <option value="${e?"rm":"discard"}" data-icon="${p(Qe)}" data-danger${c.client?"":" data-sep"}>${e?"Delete thread":"Discard draft"}</option>
9
+ </select></label>`,Dn='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M2 10s3-5.5 8-5.5S18 10 18 10s-3 5.5-8 5.5S2 10 2 10z"/><circle cx="10" cy="10" r="2.3"/></svg>',ko=(t,e)=>`<button type="button" class="dt-share${t?" is-on":""}" data-act="share" data-v="${t?"":"1"}"${e?` data-id="${e}"`:""}
10
+ aria-pressed="${!!t}" title="${t?"Shared with the client \u2014 click to keep it to the team":"Team only \u2014 click to share it with the client"}">${t?At:qn}</button>`,ga=()=>(c.team??[]).filter(t=>!c.studio||c.studio.includes(t.email)),fa=t=>{const e=t||c.lead||"",n=ga();if(!n.length)return"";const s=An(e);return`<label class="dt-field" title="Who it is for"><span class="dt-field-box${s?" dt-field-box--face":""}" style="--cat:${kt(e||"x@x")}">${s}<select class="dt-for-select" aria-label="Who this is for">
11
+ ${n.map(a=>`<option value="${p(a.email)}" data-c="${kt(a.email)}"${Le(a.email)}${e===a.email?" selected":""}>${p(a.name||a.email)}</option>`).join("")}
12
+ </select></span></label>`},xe='<svg viewBox="0 0 20 20" width="9" height="9" aria-hidden="true"><path d="M5.5 5.5l9 9M14.5 5.5l-9 9"/></svg>',ha=!1,ba=!1,In='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M3 1.8v8.4L10 6z"/></svg>',ya='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M2.5 1.5h2.5v9H2.5zM7 1.5h2.5v9H7z"/></svg>',va=t=>`${Math.floor(t/60)}:${String(Math.floor(t%60)).padStart(2,"0")}`,$a=(t,e)=>{const n=t.closest(".dt-voice"),s=n.querySelector("audio"),a=n.querySelector(".dt-voice-play");if(!s.dataset.wired){s.dataset.wired="1";const l=n.querySelector(".dt-voice-track i"),u=n.querySelector(".dt-voice-time"),m=()=>Number.isFinite(s.duration)?s.duration:0;s.addEventListener("timeupdate",()=>{l.style.transform=`scaleX(${m()?Math.min(1,s.currentTime/m()):0})`,u.textContent=va(s.currentTime)}),s.addEventListener("play",()=>{a.innerHTML=ya,a.setAttribute("aria-label","Pause"),n.classList.add("is-playing")}),s.addEventListener("pause",()=>{a.innerHTML=In,a.setAttribute("aria-label","Play the voice note"),n.classList.remove("is-playing")}),s.addEventListener("ended",()=>{s.currentTime=0})}const o=()=>{if(e){const l=n.querySelector(".dt-voice-track").getBoundingClientRect();Number.isFinite(s.duration)&&(s.currentTime=Math.max(0,Math.min(1,(e.clientX-l.left)/l.width))*s.duration);return}if(!s.paused){s.pause();return}b.querySelectorAll(".dt-voice audio").forEach(l=>{l!==s&&l.pause()}),s.play().catch(()=>{})};if(Number.isFinite(s.duration)||s.readyState<1){s.readyState<1?s.addEventListener("loadedmetadata",()=>Number.isFinite(s.duration)?o():i(),{once:!0}):o();return}i();function i(){s.addEventListener("timeupdate",()=>{s.currentTime=0,o()},{once:!0}),s.currentTime=1e9}},Ae=t=>t.startsWith("data:audio/")||/(^|\/)voice-[^/?]*\.(webm|m4a)(\?|$)/i.test(t),Pn=t=>t.startsWith("data:video/")||/\.webm(\?|$)/i.test(t),Ht=new Map,wa=t=>{if(!t.startsWith("data:"))return t;let e=Ht.get(t);if(!e){const[n,s]=t.split(",",2);if(e=URL.createObjectURL(new Blob([Uint8Array.from(atob(s),a=>a.charCodeAt(0))],{type:n.slice(5).split(";")[0]})),Ht.set(t,e),Ht.size>8){const[a,o]=Ht.entries().next().value;URL.revokeObjectURL(o),Ht.delete(a)}}return e},Ea=(t,e)=>`<span class="dt-voice"><button type="button" class="dt-voice-play" data-act="voice" aria-label="Play the voice note">${In}</button><button type="button" class="dt-voice-track" data-act="voice-seek" aria-label="Jump"><i></i></button><span class="dt-voice-time">0:00</span><audio src="${wa(t)}" preload="metadata"></audio>${e===void 0?"":`<button class="dt-voice-rm" data-act="voice-write" ${e} aria-label="Write it out" title="Write it out \u2014 its words go in the box">${Ra}</button>`}${e===void 0?"":`<button class="dt-voice-rm" data-act="unshot" ${e} aria-label="Remove the recording" title="Remove the recording">${xe}</button>`}</span>`,Sa=(t,e,n)=>`<span class="dt-shot dt-doc">${t.startsWith("data:")?`<span class="dt-doc-name">${_n}${p(e)}</span>`:`<a class="dt-doc-name" href="${t}" target="_blank" rel="noreferrer">${_n}${p(e)}</a>`}${n===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${n} aria-label="Remove">${xe}</button>`}</span>`,jn=(t,e,n=t)=>Cs(n)?Sa(t,Cs(n),e):Ae(n)?Ea(t,e):`<span class="dt-shot${Pn(n)?" dt-shot--video":""}">${Pn(n)?`<video src="${t}" controls preload="metadata" playsinline></video>`:`<a href="${t}" target="_blank"><img src="${t}" alt="" loading="lazy" /></a>`}${e===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${e} aria-label="Remove">${xe}</button>`}</span>`,He=(t=[],e)=>t.length?`<div class="dt-note-shots">${t.map(n=>{const s=n.split("/").pop(),a=ho(s);return jn(a,e===void 0?void 0:`data-id="${e}" data-img="${p(s)}"`,s)}).join("")}</div>`:"",Fn=(t=[])=>t.length?`<div class="dt-note-shots">${t.map((e,n)=>jn(e,`data-i="${n}"`)).join("")}</div>`:"",_n='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M11.5 2.5H6a1.5 1.5 0 0 0-1.5 1.5v12A1.5 1.5 0 0 0 6 17.5h8a1.5 1.5 0 0 0 1.5-1.5V6.5z"/><path d="M11.5 2.5v4h4"/></svg>',Ta='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="2.5" y="5.5" width="11" height="9" rx="2"/><path d="m13.5 9 4-2.5v7l-4-2.5"/></svg>',Ma='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><path d="M3.5 5.5h8M7.5 5.5v10M11 15.5l5-5 1.5 1.5-5 5H11z" stroke-linejoin="round"/></svg>',La=!!navigator.mediaDevices?.getDisplayMedia&&typeof MediaRecorder<"u";let ct=null;const ka=async t=>{if(ct){ct.stop();return}let e;try{e=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:12},audio:!1})}catch{return}const n=await navigator.mediaDevices.getUserMedia({audio:!0}).catch(()=>null),s=new MediaStream([...e.getVideoTracks(),...n?.getAudioTracks()??[]]),a=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm"].find(m=>MediaRecorder.isTypeSupported(m));if(!a){for(const m of e.getTracks())m.stop();A("This browser cannot record WebM video.");return}const o=new MediaRecorder(s,{mimeType:a,videoBitsPerSecond:6e5,audioBitsPerSecond:32e3}),i=[],l=!!Number(t?.dataset.id);o.ondataavailable=m=>{m.data.size&&i.push(m.data)};const u=setTimeout(()=>{o.state!=="inactive"&&o.stop()},3e4);o.onstop=async()=>{clearTimeout(u);for(const h of[...e.getTracks(),...n?.getTracks()??[]])h.stop();ct=null;const m=new Blob(i,{type:"video/webm"});if(m.size>32e5){A("That recording is too big to send \u2014 keep it shorter."),f();return}const r=await new Promise(h=>{const g=new FileReader;g.onload=()=>h(String(g.result)),g.readAsDataURL(m)});l?B.push(r):d&&(d.images??=[]).push(r),f()},e.getVideoTracks()[0]?.addEventListener("ended",()=>{o.state!=="inactive"&&o.stop()}),ct=o,o.start(1e3),f()},xa='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="7.5" y="3" width="5" height="9" rx="2.5"/><path d="M5 9.5a5 5 0 0 0 10 0M10 14.5V17"/></svg>',Aa='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="m5 10.5 3.2 3L15 6.5"/></svg>',Ha=90,Ne=32,Na=()=>!!c.voice&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<"u";let te=!1;const Ca=async(t,e)=>{if(te||!t)return;const n=Number(t.dataset.id)||0;te=!0,e.classList.add("is-asking"),e.title="Waiting for the microphone \u2014 allow it in the browser";let s;try{s=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(S){te=!1,e.classList.remove("is-asking");const k=S?.name;A(k==="NotAllowedError"?"The microphone is blocked for this site \u2014 allow it from the icon left of the address, then try again.":k==="NotFoundError"?"No microphone found \u2014 plug one in or pick it in the system settings.":k==="NotReadableError"?"The microphone is busy in another app \u2014 close it there and try again.":`The microphone did not start: ${S?.message||k||"unknown error"}`);return}e.classList.remove("is-asking");const a=()=>b.querySelector(n?`.dt-note[data-id="${n}"] .dt-compose`:".dt-note[data-draft] .dt-compose"),o=document.createElement("div");o.className="dt-rec",o.innerHTML=`<button type="button" class="dt-rec-x" title="Discard (Esc)" aria-label="Discard">${Qe}</button><span class="dt-rec-time"><i></i><b>0:00</b></span><span class="dt-rec-wave">${"<i></i>".repeat(Ne)}</span><button type="button" class="dt-rec-done" title="Done \u2014 write it out" aria-label="Done">${Aa}</button>`;const i=o.querySelector("b"),l=[...o.querySelectorAll(".dt-rec-wave i")],u=new AudioContext,m=u.createAnalyser();m.fftSize=512,u.createMediaStreamSource(s).connect(m);const r=new Uint8Array(m.fftSize),h=[],g=new MediaRecorder(s,{audioBitsPerSecond:32e3}),w=[],M=Date.now();let R=!0;const st=setInterval(()=>{const S=a();S&&o.parentElement!==S&&S.appendChild(o),m.getByteTimeDomainData(r);let k=0;for(const v of r)k+=((v-128)/128)**2;h.push(Math.min(1,Math.sqrt(k/r.length)*4));const I=h.slice(-Ne);l.forEach((v,qt)=>{const ut=I[qt-(Ne-I.length)];v.style.transform=`scaleY(${Math.max(.1,ut??0).toFixed(2)})`,v.classList.toggle("is-empty",ut===void 0)});const Q=Math.floor((Date.now()-M)/1e3);i.textContent=`${Math.floor(Q/60)}:${String(Q%60).padStart(2,"0")}`,Q>=Ha&&g.state!=="inactive"&&g.stop()},90),at=S=>{R=S,g.state!=="inactive"&&g.stop()};o.querySelector(".dt-rec-x").addEventListener("click",S=>{S.stopPropagation(),at(!1)}),o.querySelector(".dt-rec-done").addEventListener("click",S=>{S.stopPropagation(),at(!0)}),o.addEventListener("keydown",S=>{S.key==="Escape"&&(S.stopPropagation(),at(!1))}),g.ondataavailable=S=>{S.data.size&&w.push(S.data)},g.onstop=async()=>{if(clearInterval(st),s.getTracks().forEach(I=>I.stop()),u.close().catch(()=>{}),o.remove(),te=!1,!R)return;const S=new Blob(w,{type:g.mimeType||"audio/webm"}),k=await new Promise(I=>{const Q=new FileReader;Q.onload=()=>I(String(Q.result)),Q.readAsDataURL(S)});n?B.push(k):d&&(d.images??=[]).push(k),f(),a()?.querySelector("textarea")?.focus()},g.start(1e3),a()?.appendChild(o),o.querySelector(".dt-rec-done").focus()},Kn="\u{1F3A4} Voice note",Ra='<svg viewBox="0 0 20 20" width="12" height="12" aria-hidden="true"><rect x="2.5" y="4.5" width="15" height="11" rx="2"/><path d="M6 11.5h3M11 11.5h3M6 8.5h8"/></svg>',Oa=async t=>{const e=t.closest(".dt-note"),s=(e?.hasAttribute("data-draft")?d?.images??[]:B)[Number(t.dataset.i)];if(!s||t.classList.contains("is-asking"))return;t.classList.add("is-asking");const a=await L("transcribe",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({audio:s})}).catch(()=>null),o=a?await a.json().catch(()=>({})):{};if(t.classList.remove("is-asking"),!a?.ok||!o.text){A(o.error||(a?.ok?"Didn't hear any words in it.":"Could not make out the words \u2014 try again, or type it."));return}const i=e?.querySelector("textarea.dt-note-input, textarea.dt-note-reply-input");i&&(i.value=i.value.trim()?`${i.value.trimEnd()} ${o.text}`:o.text,i.dispatchEvent(new Event("input",{bubbles:!0})),i.focus())},G=new Map,qa=async(t,e)=>{const n=`${t}:${e}`;if(G.has(n)){G.delete(n),f();return}const s=y.find(l=>l.id===t),a=s&&It(s).find(l=>(l.at??"0")===e);if(!a?.text)return;G.set(n,null),f();const o=await L("translate",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:a.text,to:navigator.language||"en"})}).catch(()=>null),i=o?await o.json().catch(()=>({})):{};G.has(n)&&(o?.ok&&i.text?G.set(n,i.text):(G.delete(n),A(i.error||"Could not translate it \u2014 try again.")),f())},Ba='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M3 5h8M7 3v2m2 0c-.6 3.2-2.8 6-6 7.5M5.5 8.5c.8 1.6 2.2 2.9 4 3.8M10.5 17l3.25-7.5L17 17m-5.5-2h4.5"/></svg>',Da='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="3" y="4" width="14" height="12" rx="2"/><circle cx="7.5" cy="8.5" r="1.4"/><path d="m3.5 14.5 4-4 3 3 2-2 4 4"/></svg>',Wn=(t,e,n,s,a="",o="")=>`<div class="dt-note-foot"><div class="dt-compose">
13
+ <textarea class="${t}" rows="1" placeholder="${e}">${p(n)}</textarea>
14
+ ${a}
15
15
  <div class="dt-compose-bar">
16
- <span class="dt-compose-tools"><button class="dt-attach" data-act="attach" title="Attach a screenshot, a PDF or a Word file \u2014 or paste or drop one">${wo}</button>
17
- ${a}${to&&co?`<button class="dt-record${it?" is-on":""}" data-act="record" title="${it?"Stop recording":"Record the screen, up to 30 seconds"}">${it?"Stop":ro}</button>`:""}${fo()?`<button class="dt-attach" data-act="speak" title="Speak \u2014 sent with its words as a voice note">${po}</button>`:""}</span>
16
+ <span class="dt-compose-tools"><button class="dt-attach" data-act="attach" title="Attach a screenshot, a PDF or a Word file \u2014 or paste or drop one">${Da}</button>
17
+ ${o}${ba&&La?`<button class="dt-record${ct?" is-on":""}" data-act="record" title="${ct?"Stop recording":"Record the screen, up to 30 seconds"}">${ct?"Stop":Ta}</button>`:""}${Na()?`<button class="dt-attach" data-act="speak" title="Speak \u2014 sent with its words as a voice note">${xa}</button>`:""}</span>
18
18
  <button class="dt-send${n.trim()?" is-ready":""}" ${s} title="Send (Enter)"
19
19
  ><svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M10 15.5v-11M5.5 9 10 4.5 14.5 9"/></svg></button>
20
20
  </div>
21
- </div></div>`,$e=(t,e)=>(t||"element")+(e?.[0]?"."+e[0]:""),An=()=>A.map((t,e)=>({i:e,el:$e(t.tag,t.classes),text:ht(t.text??""),shots:t.images?.length??0,orphan:!I(t)}));let we=[],Hn="";const z=t=>{const e=t.working;return at(e?.agent,e?.by??Go(t.assignee))},Nn=t=>{const e=Math.max(1,Math.round((Date.now()-Date.parse(t??""))/6e4)||1);return e<60?`${e} min`:`${Math.round(e/60)} h`},_t=(t,e)=>{const n=t.working;return{held:"From a guest \u2014 waits for the studio to approve it",queued:`Queued for ${z(t)} \u2014 it takes it on its next run`,asks:`${z(t)} is waiting for your answer`,working:`${z(t)} is on it \xB7 ${Nn(n?.at)}`,stuck:`${z(t)} went quiet \u2014 its next run takes it again`,review:`Resolved by ${at(t.doneAgent,t.doneFor)} \u2014 click to clear`,done:"Resolved"}[e]},Eo=t=>{const e=Jt(t);if(!e)return c.client||he()||t.status==="done"?"":`<button class="dt-note-state dt-step--none" data-act="hand" data-v="agent" data-id="${t.id}" data-tip="Hand to Claude" aria-label="Hand to Claude">${fs(13,0)}</button>`;const n=fs(13,Vo[e]);return e==="review"?`<button class="dt-note-state dt-step--review" data-act="reopen" data-id="${t.id}" data-tip="${m(_t(t,e))}" aria-label="${m(_t(t,e))}">${n}</button>`:`<span class="dt-note-state dt-step--${e}" data-tip="${m(_t(t,e))}" role="img" aria-label="${m(_t(t,e))}">${n}</span>`},Cn=t=>{const e=rt(t),n=e==="done";return`${Eo(t)}<button data-act="${n?"reopen":"done"}" data-id="${t.id}"
22
- class="dt-note-resolve${n?" is-on":""}" title="${n?"Reopen":e==="claude"?"Looks right \u2014 mark it resolved":"Resolve"}">${Gt}</button>`},fa='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M4.5 10h11M11 5.5l4.5 4.5-4.5 4.5" stroke-linejoin="round"/></svg>',So=t=>t?new Date(t).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}):"",To=t=>{if(c.client)return"";const e=Jt(t),n={act:"hand",v:"me",icon:wt,tip:c.me?"Take it myself":"Take it off Claude"},s={act:"reopen",icon:bs,tip:"Reopen"},o=[{act:"done",icon:Gt,tip:"Looks right \u2014 resolve it",main:!0},{act:"sendback",icon:bs,tip:"Send it back \u2014 say what is wrong below"}],a=t.working,i=!D(t.assignee)&&t.assignee?t.assignee===c.me?.email?"You":It(t.assignee):"",d=e==="queued"?{step:e,title:`Queued for ${z(t)}`,acts:[n]}:e==="working"?{step:e,title:`${z(t)} is working`,acts:[n],live:!0}:e==="asks"?{step:e,title:`${z(t)} asks`,acts:[]}:e==="stuck"?{step:e,title:`${z(t)} silent for ${Nn(a?.at)}`,acts:[n]}:e==="review"?{step:e,title:"Done \u2014 check it",acts:o}:t.status==="done"?{step:"done",title:`Accepted${t.confirmedAt?` \xB7 ${So(t.confirmedAt)}`:""}`,acts:[s]}:lt(t)==="review"&&i?{step:"review",title:`${i} ${i==="You"?"say":"says"} done \u2014 check it`,acts:o}:null;return d?`<div class="dt-step dt-step--${d.step}"><span class="dt-step-text"><b>${m(d.title)}</b></span>${d.acts.map(u=>`<button type="button" class="dt-step-act${u.main?" is-main":""}" data-act="${u.act}" data-id="${t.id}"${u.v?` data-v="${u.v}"`:""} data-tip="${m(u.tip)}" aria-label="${m(u.tip)}">${u.icon}</button>`).join("")}${d.live?'<i class="dt-step-live" aria-hidden="true"></i>':""}</div>`:""},Mo=async(t,e)=>{const n=e?b.find(o=>o.id===t):void 0,s=n?await Ce(q(n)):null;return L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(e?{id:t,status:"done",doneBy:"you",...s?{after:s}:{}}:{id:t,status:"open",doneBy:null,stage:Rn(b.find(o=>o.id===t))})})},P=async(t,e,n)=>{const s=b,o=mt;b=t(b),mt=t(mt),f();const a=await e().catch(()=>null);if(!a?.ok){b=s,mt=o,f(),k(`${n} did not go through${a?` (${a.status})`:""}.`);return}zt()},Rn=t=>t?D(t.assignee)?"approved":t.assignee?"progress":"new":"new",pt=(t,e)=>P(n=>n.map(s=>s.id===t?{...s,status:e?"done":"open",doneBy:e?"you":null,...e?{}:{stage:Rn(s),reopenedAt:new Date().toISOString()}}:s),()=>Mo(t,e),e?"Resolving":"Reopening"),Ee=t=>P(e=>e.filter(n=>n.id!==t),()=>L(`comments?id=${t}`,{method:"DELETE"}),"Deleting"),Lo=t=>{const e=b.filter(o=>J(o)===t),n=e.filter(o=>rt(o)==="open").length,s=e.filter(o=>rt(o)==="claude").length;re.innerHTML=n?String(n):s?kt(9):"\u2713",re.dataset.state=n?"open":s?"claude":"done",re.hidden=e.length===0};let Se=0,On;const f=()=>{const t=Se-performance.now();if(t>0){clearTimeout(On),On=setTimeout(f,t);return}if(ot(),E){const r=An(),y=JSON.stringify(r);y!==Hn&&(Hn=y,parent.postMessage({dt:!0,drafts:r},location.origin))}sn(),$!==yt&&(R="",O=[],yt=$),T&&T.id!==$&&(T=null);const e=Ot();if(Lo(e),!x){h.innerHTML="",pe(null);return}const n=e;let s="";const o=b.filter(r=>J(r)===n&&(W||rt(r)!=="done"||r.id===$));for(const r of o){const y=I(r);if(!y&&$!==r.id)continue;const g=rt(r),w=g==="done",M=!y,N=y??{x:0,y:0},Z=Ie(r.category),tt=Pe(r);if(M||(s+=`<button class="dt-pin dt-pin--${g}${tt?" dt-pin--working":""}${g==="open"&&lt(r)==="review"?" dt-pin--review":""}" data-id="${r.id}"${y?.off?` data-off="${y.off}"`:""} aria-label="Comment ${r.id}, ${g==="open"?"open":g==="claude"?`resolved by ${m(at(r.doneAgent,r.doneFor))}`:"resolved"}" aria-expanded="${$===r.id}"
23
- style="left:${N.x}px;top:${N.y}px;--cat:${Z.color};--ring:${me.find(S=>S[0]===fn(r))[2]}"
24
- title="${m(r.text.slice(0,80))} \xB7 ${Z.label}${tt?` \xB7 ${m(at(tt.agent,tt.by))} is on it`:""}${g==="claude"?` \xB7 resolved by ${m(at(r.doneAgent,r.doneFor))} \u2014 tick to confirm`:g==="done"?" \xB7 resolved":""}">${g==="done"?"\u2713":g==="claude"?kt(11):js(r)}</button>`),$===r.id){const S=gs(r);s+=`<div class="dt-note${M?" dt-note--orphan":""}" data-id="${r.id}" role="dialog" aria-label="Comment ${r.id}"
25
- style="left:${N.x}px;top:${N.y}px">
21
+ </div></div>`,Ce=(t,e)=>(t||"element")+(e?.[0]?"."+e[0]:""),Un=()=>N.map((t,e)=>({i:e,el:Ce(t.tag,t.classes),text:wt(t.text??""),shots:t.images?.length??0,orphan:!_(t)}));let Re=[],zn="";const X=t=>{const e=t.working;return dt(e?.agent,e?.by??co(t.assignee))},Yn=t=>{const e=Math.max(1,Math.round((Date.now()-Date.parse(t??""))/6e4)||1);return e<60?`${e} min`:`${Math.round(e/60)} h`},ee=(t,e)=>{const n=t.working;return{held:"From a guest \u2014 waits for the studio to approve it",queued:`Queued for ${X(t)} \u2014 it takes it on its next run`,asks:`${X(t)} is waiting for your answer`,working:`${X(t)} is on it \xB7 ${Yn(n?.at)}`,stuck:`${X(t)} went quiet \u2014 its next run takes it again`,review:`Resolved by ${dt(t.doneAgent,t.doneFor)} \u2014 click to clear`,done:"Resolved"}[e]},Ia=t=>{const e=Z(t);if(!e)return c.client||Zt()||t.status==="done"?"":`<button class="dt-note-state dt-step--none" data-act="hand" data-v="agent" data-id="${t.id}" data-tip="Hand to Claude" aria-label="Hand to Claude">${Rs(13,0)}</button>`;const n=Rs(13,12);return e==="review"?`<button class="dt-note-state dt-step--review" data-act="reopen" data-id="${t.id}" data-tip="${p(ee(t,e))}" aria-label="${p(ee(t,e))}">${n}</button>`:`<span class="dt-note-state dt-step--${e}" data-tip="${p(ee(t,e))}" role="img" aria-label="${p(ee(t,e))}">${n}</span>`},Vn=t=>{const e=P(t),n=e==="done";return`${Ia(t)}<button data-act="${n?"reopen":"done"}" data-id="${t.id}"
22
+ class="dt-note-resolve${n?" is-on":""}" title="${n?"Reopen":e==="claude"?"Looks right \u2014 mark it resolved":"Resolve"}">${St}</button>`},xo='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M4.5 10h11M11 5.5l4.5 4.5-4.5 4.5" stroke-linejoin="round"/></svg>',Pa=t=>t?new Date(t).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}):"",ja=t=>{if(c.client)return"";const e=Z(t),n={act:"hand",v:"me",icon:At,tip:c.me?"Take it myself":"Take it off Claude"},s={act:"reopen",icon:Ze,tip:"Reopen"},a=[{act:"accept",icon:St,tip:"Looks right \u2014 accept it",main:!0},{act:"sendback",icon:Ze,tip:"Send it back \u2014 say what is wrong below"}],o=t.working,i=!j(t.assignee)&&t.assignee?t.assignee===c.me?.email?"You":Yt(t.assignee):"",l=e==="queued"?{step:e,title:`Queued for ${X(t)}`,acts:[n]}:e==="working"?{step:e,title:`${X(t)} is working`,acts:[n],live:!0}:e==="asks"?{step:e,title:`${X(t)} asks`,acts:[]}:e==="stuck"?{step:e,title:`${X(t)} silent for ${Yn(o?.at)}`,acts:[n]}:e==="review"?null:t.status!=="done"&&U(t)==="accepted"?{step:"done",title:`Accepted${t.acceptedAt?` \xB7 ${Pa(t.acceptedAt)}`:""}`,acts:[{...s,act:"sendback",tip:"Send it back"}]}:U(t)==="review"&&i?{step:"review",title:`${i} ${i==="You"?"say":"says"} done \u2014 check it`,acts:a}:!e&&!t.assignee&&t.status!=="done"&&c.me&&!Zt()?{step:"anyone",title:"Anyone can take it",acts:[{act:"hand",v:"me",icon:St,tip:"Take it myself",main:!0,text:"Take"},{act:"give",icon:pa,tip:"Give it to someone",pick:!0}]}:null;return l?`<div class="dt-step dt-step--${l.step}">${l.step==="anyone"?vn:""}<span class="dt-step-text"><b>${p(l.title)}</b></span>${l.acts.map(u=>u.pick?`<label class="dt-step-act" data-tip="${p(u.tip)}">${u.icon}<select class="dt-for-select" data-id="${t.id}" aria-label="${p(u.tip)}"><option value="" selected hidden></option>${Lt().map(m=>`<option value="${p(m.email)}"${Le(m.email)}>${p(m.email===c.me?.email?`Me \xB7 ${m.name||m.email}`:m.name||m.email)}</option>`).join("")}</select></label>`:`<button type="button" class="dt-step-act${u.main?" is-main":""}${u.text?" has-text":""}" data-act="${u.act}" data-id="${t.id}"${u.v?` data-v="${u.v}"`:""} data-tip="${p(u.tip)}" aria-label="${p(u.tip)}">${u.icon}${u.text?`<span>${p(u.text)}</span>`:""}</button>`).join("")}${l.live?'<i class="dt-step-live" aria-hidden="true"></i>':""}</div>`:""},Fa=async(t,e)=>{const n=e?y.find(a=>a.id===t):void 0,s=n?await We(F(n)):null;return L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(e?{id:t,status:"done",doneBy:"you",...s?{after:s}:{}}:{id:t,status:"open",doneBy:null,stage:Jn(y.find(a=>a.id===t))})})},K=async(t,e,n)=>{const s=y,a=yt;y=t(y),yt=t(yt),f();const o=await e().catch(()=>null);if(!o?.ok){y=s,yt=a,f(),A(`${n} did not go through${o?` (${o.status})`:""}.`);return}oe()},Jn=t=>t?j(t.assignee)?"approved":t.assignee?"progress":"new":"new",ht=(t,e)=>K(n=>n.map(s=>s.id===t?{...s,status:e?"done":"open",doneBy:e?"you":null,...e?{}:{stage:Jn(s),reopenedAt:new Date().toISOString()}}:s),()=>Fa(t,e),e?"Resolving":"Reopening"),Oe=t=>K(e=>e.filter(n=>n.id!==t),()=>L(`comments?id=${t}`,{method:"DELETE"}),"Deleting"),_a=t=>{const e=y.filter(a=>tt(a)===t),n=e.filter(a=>P(a)==="open").length,s=e.filter(a=>P(a)==="claude").length;$e.innerHTML=n?String(n):s?Et(9):"\u2713",$e.dataset.state=n?"open":s?"claude":"done",$e.hidden=e.length===0};let qe=0,Gn;const f=()=>{const t=qe-performance.now();if(t>0){clearTimeout(Gn),Gn=setTimeout(f,t);return}if(rt(),E){const r=Un(),h=JSON.stringify(r);h!==zn&&(zn=h,parent.postMessage({dt:!0,drafts:r},location.origin))}hn(),$!==Mt&&(q="",B=[],Mt=$),T&&T.id!==$&&(T=null);const e=lt();if(_a(e),!H){b.innerHTML="",Me(null);return}const n=e;let s="";const a=y.filter(r=>tt(r)===n&&(J||P(r)!=="done"||r.id===$));for(const r of a){const h=_(r);if(!h&&$!==r.id)continue;const g=P(r),w=g==="done",M=!h,R=h??{x:0,y:0},st=de(r.category),at=Ge(r),S=g==="done"?null:Z(r),k=S?Ln[S]??"":"";if($===r.id&&aa(r),M||(s+=`<button class="dt-pin dt-pin--${g}${k?" dt-pin--agent":""}${at?" dt-pin--working":""}${g==="open"&&U(r)==="review"?" dt-pin--review":""}" data-id="${r.id}"${h?.off?` data-off="${h.off}"`:""} aria-label="Comment ${r.id}, ${g==="open"?"open":g==="claude"?`resolved by ${p(dt(r.doneAgent,r.doneFor))}`:"resolved"}" aria-expanded="${$===r.id}"
23
+ style="left:${R.x}px;top:${R.y}px;--cat:${st.color};--ring:${Jt.find(I=>I[0]===Gt(r))[2]};--hue:${Mn(r.by||r.byName||"")}${k?`;--step-c:${k}`:""}"
24
+ title="${p(r.text.slice(0,80))} \xB7 ${st.label}${at?` \xB7 ${p(dt(at.agent,at.by))} is on it`:""}${g==="claude"?` \xB7 resolved by ${p(dt(r.doneAgent,r.doneFor))} \u2014 tick to confirm`:g==="done"?" \xB7 resolved":""}">${g==="done"?"\u2713":k?Et(11):Tn(r)}${g!=="done"&&$!==r.id&&xn(r)?'<i class="dt-pin-new" aria-label="New messages"></i>':""}</button>`),$===r.id){const I=It(r),Q=Z(r)==="review"&&!c.client?I.map(v=>v.author).lastIndexOf("claude"):-1;s+=`<div class="dt-note${M?" dt-note--orphan":""}" data-id="${r.id}" role="dialog" aria-label="Comment ${r.id}"
25
+ style="left:${R.x}px;top:${R.y}px">
26
26
  <div class="dt-note-bar">
27
- <span class="dt-note-el"${c.client?"":` data-tip="${gn(r.selector,r.label)}"`}>${c.client?`Comment #${xo(r)}`:m($e(r.tag,r.classes))}</span>
27
+ <span class="dt-note-el"${c.client?"":` data-tip="${Nn(r.selector,r.label)}"`}>${c.client?`Comment #${Wa(r)}`:p(Ce(r.tag,r.classes))}</span>
28
28
  <span class="dt-note-tools">
29
- ${!c.client&&r.shared?`<span class="dt-note-eye" data-tip="The client sees this thread" role="img" aria-label="The client sees this thread">${$n}</span>`:""}
30
- ${Cn(r)}
29
+ ${!c.client&&r.shared?`<span class="dt-note-eye" data-tip="The client sees this thread" role="img" aria-label="The client sees this thread">${Dn}</span>`:""}
30
+ ${Vn(r)}
31
31
  <i class="dt-note-sep"></i>
32
- ${vn(r.shared,r.id)}
33
- <button data-act="close" data-id="${r.id}" data-tip="Close" aria-label="Close">${Fe}</button>
32
+ ${Bn(r.shared,r.id)}
33
+ <button data-act="close" data-id="${r.id}" data-tip="Close" aria-label="Close">${Xe}</button>
34
34
  </span>
35
35
  </div>
36
36
  ${M?'<p class="dt-note-orphan">The element this was pinned to is not on the page right now.</p>':""}
37
- ${(()=>{const v=(c.client?"":Ys(r))+(r.host&&r.host!==location.host?`<span class="dt-note-host" title="Written on ${m(r.host)}">${m(r.host)}</span>`:"");return v?`<div class="dt-note-meta">${v}</div>`:""})()}
37
+ ${(()=>{const v=(c.client?"":ca(r))+(r.host&&r.host!==location.host?`<span class="dt-note-host" title="Written on ${p(r.host)}">${p(r.host)}</span>`:"");return v?`<div class="dt-note-meta">${v}</div>`:""})()}
38
38
  <div class="dt-note-thread">
39
- ${S.map((v,Y)=>{const C=Y===0?null:v.at??null,V=v.author==="you"&&(!v.by||v.by===c.me?.email),Vt=V&&T?.id===r.id&&T.at===C,et=c.team?.find(qe=>qe.email===v.by),Uo=v.author==="claude"?at(v.agent,v.by):V?"You":et?.name||v.byName||v.by||"You",zo=v.author==="claude"?et?.agent_avatar_url?`<img class="dt-msg-face" src="${m(et.agent_avatar_url)}" alt="">`:`<span class="dt-msg-face dt-msg-ai">${kt(11)}</span>`:et?.avatar_url?`<img class="dt-msg-face" src="${m(et.avatar_url)}" alt="">`:"",De=`${r.id}:${v.at??"0"}`,ls=U.get(De),Yo=!V&&c.voice&&v.text?`<button class="dt-msg-edit${U.has(De)?" is-on":""}" data-act="translate" data-id="${r.id}" data-at="${m(v.at??"0")}" title="${U.has(De)?"Show the original":"Translate into your language"}">${$o}</button>`:"",ds=`<div class="dt-msg-head">${zo}<b>${m(Uo)}</b><time>${la(v.at)}</time>${Yo}${V&&!Vt?`<button class="dt-msg-edit" data-act="edit" data-id="${r.id}" data-at="${m(C??"")}" title="Edit">${hs}</button>${C?`<button class="dt-msg-edit" data-act="unsay" data-id="${r.id}" data-at="${m(C)}" title="Delete">${je}</button>`:""}`:""}</div>`;return Vt?`<div class="dt-msg">${ds}<div class="dt-compose">
40
- <textarea class="dt-note-edit-input" rows="1">${m(T.text)}</textarea>
41
- ${Tn(v.images.filter(qe=>!T.drop.includes(qe.split("/").pop())),r.id)}
39
+ ${I.map((v,qt)=>{const ut=qt===0?null:v.at??null,re=v.author==="you"&&(!v.by||v.by===c.me?.email),Ts=re&&T?.id===r.id&&T.at===ut,Bt=c.team?.find(Je=>Je.email===v.by),Ms=v.author==="claude"?dt(v.agent,v.by):re?"You":Bt?.name||v.byName||v.by||"You",Ls=v.author==="claude"?Bt?.agent_avatar_url?`<img class="dt-msg-face" src="${p(Bt.agent_avatar_url)}" alt="">`:`<span class="dt-msg-face dt-msg-ai">${Et(11)}</span>`:Bt?.avatar_url?`<img class="dt-msg-face" src="${p(Bt.avatar_url)}" alt="">`:"",Ve=`${r.id}:${v.at??"0"}`,le=G.get(Ve),ks=!re&&c.voice&&v.text?`<button class="dt-msg-edit${G.has(Ve)?" is-on":""}" data-act="translate" data-id="${r.id}" data-at="${p(v.at??"0")}" title="${G.has(Ve)?"Show the original":"Translate into your language"}">${Ba}</button>`:"",xs=`<div class="dt-msg-head">${Ls}<b>${p(Ms)}</b><time>${qs(v.at)}</time>${ks}${re&&!Ts?`<button class="dt-msg-edit" data-act="edit" data-id="${r.id}" data-at="${p(ut??"")}" title="Edit">${Os}</button>${ut?`<button class="dt-msg-edit" data-act="unsay" data-id="${r.id}" data-at="${p(ut)}" title="Delete">${Qe}</button>`:""}`:""}</div>`;return qt===Q?`<div class="dt-msg dt-msg--done" data-msg="${r.id}:${p(v.at??"0")}"><div class="dt-msg-head">${Ls}<b>${p(Ms)} fixed it</b><time>${qs(v.at)}</time>${ks}</div><p${le===null?' class="is-asking"':""}>${us(le||v.text)}</p>${He(v.images)}
40
+ <div class="dt-done-acts"><button type="button" class="dt-done-act is-main" data-act="accept" data-id="${r.id}">${St}Looks right</button><button type="button" class="dt-done-act" data-act="sendback" data-id="${r.id}">${Ze}Send back</button></div></div>`:Ts?`<div class="dt-msg">${xs}<div class="dt-compose">
41
+ <textarea class="dt-note-edit-input" rows="1">${p(T.text)}</textarea>
42
+ ${He(v.images.filter(Je=>!T.drop.includes(Je.split("/").pop())),r.id)}
42
43
  <div class="dt-compose-bar">
43
44
  <button class="dt-edit-cancel" data-act="edit-cancel">Cancel</button>
44
- <button class="dt-send${T.text.trim()?" is-ready":""}" data-act="edit-save" title="Save (Enter)">${Gt}</button>
45
+ <button class="dt-send${T.text.trim()?" is-ready":""}" data-act="edit-save" title="Save (Enter)">${St}</button>
45
46
  </div>
46
- </div></div>`:`<div class="dt-msg" data-msg="${r.id}:${m(v.at??"0")}">${ds}<p${ls===null?' class="is-asking"':""}>${Fo(ls||v.text)}</p>${Y===0&&r.suggest?Ws(r.suggest):""}${Tn(v.images)}</div>`}).join("")}
47
+ </div></div>`:`<div class="dt-msg" data-msg="${r.id}:${p(v.at??"0")}">${xs}<p${le===null?' class="is-asking"':""}>${us(le||v.text)}</p>${qt===0&&r.suggest?ra(r.suggest):""}${He(v.images)}</div>`}).join("")}
47
48
  </div>
48
- ${To(r)}
49
- ${xn("dt-note-reply-input",Jt(r)==="asks"?`Answer ${m(z(r))}`:"Reply",R,`data-act="reply" data-id="${r.id}"`,Mn(O))}
50
- ${bn(r.priority,r.category,r.id,r.assignee??"",Zo(r))}
51
- </div>`}}A.forEach((r,y)=>{const g=I(r);g&&(s+=`<button class="dt-pin dt-pin--draft" data-parked="${y}" data-act="draft-open" data-i="${y}"
52
- style="left:${g.x}px;top:${g.y}px" title="Draft, not sent \u2014 click to finish it">${hs}</button>`)});const a=l&&I(l);if(l){const r=a?.x??0,y=a?.y??0;s+=`${a?`<span class="dt-pin dt-pin--draft" data-draft style="left:${r}px;top:${y}px"></span>`:""}
53
- <div class="dt-note${a?"":" dt-note--orphan"}" data-draft style="left:${r}px;top:${y}px">
49
+ ${ja(r)}
50
+ ${Wn("dt-note-reply-input",Z(r)==="asks"?`Answer ${p(X(r))}`:"Reply",q,`data-act="reply" data-id="${r.id}"`,Fn(B))}
51
+ ${On(r.priority,r.category,r.id,r.assignee??"",mo(r))}
52
+ </div>`}}N.forEach((r,h)=>{const g=_(r);g&&(s+=`<button class="dt-pin dt-pin--draft" data-parked="${h}" data-act="draft-open" data-i="${h}"
53
+ style="left:${g.x}px;top:${g.y}px" title="Draft, not sent \u2014 click to finish it">${Os}</button>`)});const o=d&&_(d);if(d){const r=o?.x??0,h=o?.y??0;s+=`${o?`<span class="dt-pin dt-pin--draft" data-draft style="left:${r}px;top:${h}px"></span>`:""}
54
+ <div class="dt-note${o?"":" dt-note--orphan"}" data-draft style="left:${r}px;top:${h}px">
54
55
  <div class="dt-note-bar">
55
- <span class="dt-note-el"${c.client?"":` data-tip="${gn(l.selector,l.label)}"`}>${c.client?"New comment":m($e(l.tag,l.classes))}</span>
56
- ${Ct()?'<span class="dt-note-draft">Draft</span>':""}
56
+ <span class="dt-note-el"${c.client?"":` data-tip="${Nn(d.selector,d.label)}"`}>${c.client?"New comment":p(Ce(d.tag,d.classes))}</span>
57
+ ${Kt()?'<span class="dt-note-draft">Draft</span>':""}
57
58
  <span class="dt-note-tools">
58
- ${!c.client&&l.shared?`<span class="dt-note-eye" data-tip="The client will see this thread" role="img" aria-label="The client will see this thread">${$n}</span>`:""}
59
- ${vn(l.shared)}
60
- <button data-act="cancel" data-tip="Close \u2014 the draft stays" aria-label="Close">${Fe}</button>
59
+ ${!c.client&&d.shared?`<span class="dt-note-eye" data-tip="The client will see this thread" role="img" aria-label="The client will see this thread">${Dn}</span>`:""}
60
+ ${Bn(d.shared)}
61
+ <button data-act="cancel" data-tip="Close \u2014 the draft stays" aria-label="Close">${Xe}</button>
61
62
  </span>
62
63
  </div>
63
- ${a?"":'<p class="dt-note-orphan">The element this was pinned to is not on the page right now.</p>'}
64
- ${(()=>{const g=a?q(l):null,w=g&&b.find(M=>M.id>0&&rt(M)==="open"&&q(M)===g);return w?`<p class="dt-note-twin">Already open here: \u201C${m(w.text.slice(0,60))}${w.text.length>60?"\u2026":""}\u201D <button data-act="twin" data-id="${w.id}">Open it</button></p>`:""})()}
65
- ${c.client?`<div class="dt-note-meta">${Qs(l.assignee)}</div>`:""}
66
- ${l.suggest?`<div class="dt-suggest"><span class="dt-suggest-head">New wording for this text<button data-act="unsuggest" title="Keep the text as it is">${Fe}</button></span>
67
- <span class="dt-suggest-was">Now: <del>${m(l.suggest.from.slice(0,160))}${l.suggest.from.length>160?"\u2026":""}</del></span>
68
- <textarea class="dt-suggest-input" rows="2" placeholder="Type how it should read" aria-label="How it should read">${m(l.suggest.to)}</textarea>
64
+ ${o?"":'<p class="dt-note-orphan">The element this was pinned to is not on the page right now.</p>'}
65
+ ${(()=>{const g=o?F(d):null,w=g&&y.find(M=>M.id>0&&P(M)==="open"&&F(M)===g);return w?`<p class="dt-note-twin">Already open here: \u201C${p(w.text.slice(0,60))}${w.text.length>60?"\u2026":""}\u201D <button data-act="twin" data-id="${w.id}">Open it</button></p>`:""})()}
66
+ ${c.client?`<div class="dt-note-meta">${fa(d.assignee)}</div>`:""}
67
+ ${d.suggest?`<div class="dt-suggest"><span class="dt-suggest-head">New wording for this text<button data-act="unsuggest" title="Keep the text as it is">${Xe}</button></span>
68
+ <span class="dt-suggest-was">Now: <del>${p(d.suggest.from.slice(0,160))}${d.suggest.from.length>160?"\u2026":""}</del></span>
69
+ <textarea class="dt-suggest-input" rows="2" placeholder="Type how it should read" aria-label="How it should read">${p(d.suggest.to)}</textarea>
69
70
  <span class="dt-suggest-hint">Change the words in the box \u2014 the agent puts in exactly what you write.</span></div>`:""}
70
- ${xn("dt-note-input",l.suggest?"Why (optional)":"Comment",l.text??"",'data-act="save"',Mn(l.images),Zs&&!l.suggest&&mn(a?q(l):null)?`<button class="dt-attach" data-act="suggest" title="Rewrite this text: start from its current words and change them">${lo}</button>`:"")}
71
- ${bn(l.priority,l.category,void 0,l.assignee??"")}
72
- </div>`}const i=new Map([...h.querySelectorAll(".dt-note[data-id] .dt-note-thread")].map(r=>[r.closest(".dt-note").dataset.id,{top:r.scrollTop,end:r.scrollTop+r.clientHeight>=r.scrollHeight-4}])),d=new Set([...h.querySelectorAll("[data-msg]")].map(r=>r.dataset.msg)),u=h.contains(document.activeElement)&&document.activeElement.matches(".dt-note-reply-input");h.innerHTML=s,u&&Ut(".dt-note-reply-input");for(const r of h.querySelectorAll(".dt-note[data-id] .dt-note-thread")){const y=r.closest(".dt-note").dataset.id,g=i.get(y);if(!g)continue;const w=[...r.querySelectorAll("[data-msg]")].filter(M=>!d.has(M.dataset.msg));for(const M of w)M.classList.add("dt-msg--new");r.scrollTop=g.end&&w.length?r.scrollHeight:g.top}for(const r of h.querySelectorAll(".dt-note")){const y=r.getBoundingClientRect();y.bottom>innerHeight-8&&(r.dataset.flip="1"),y.right>innerWidth-8&&(r.dataset.flipx="1")}Bn(n),pe(an()),X();for(const r of h.querySelectorAll(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input"))Oe(r);const p=h.querySelector(".dt-note-input");p&&(p.focus(),p.setSelectionRange(p.value.length,p.value.length))},ko=()=>{let t=!1;for(const e of h.querySelectorAll(".dt-pin[data-id], .dt-note[data-id]")){if(e.classList.contains("dt-note--orphan"))continue;const n=b.find(o=>o.id===Number(e.dataset.id)),s=n&&I(n);if(!s){e.style.visibility="hidden";continue}e.style.visibility="",e.style.left=`${s.x}px`,e.style.top=`${s.y}px`,e.classList.contains("dt-pin")&&(s.off?e.dataset.off=s.off:delete e.dataset.off),on(s.el)&&(t=!0)}for(const e of h.querySelectorAll("[data-draft], [data-parked]")){if(e.classList.contains("dt-note--orphan"))continue;const n=e.dataset.parked?A[Number(e.dataset.parked)]:l,s=n&&I(n);if(!s){e.style.visibility="hidden";continue}e.style.visibility="",e.style.left=`${s.x}px`,e.style.top=`${s.y}px`}if(!Dt.length&&(l||$!=null)){const e=an();e&&on(e)&&pe(e)}t&&X()},xo=t=>b.filter(e=>J(e)===J(t)).findIndex(e=>e.id===t.id)+1,Bn=t=>{H.hidden||(H.innerHTML=ca({bp:t,notes:b,breakpoints:dt,bandOfNote:J,orphan:e=>!I(e),whoseAgent:at,statusTools:Cn,showResolved:W,drafts:st.hidden?An():we,checks:E?0:ke.toCheck().length}))},Te=t=>H.toggleAttribute("data-collapsed",t);H.addEventListener("click",async t=>{const e=t.target.closest("[data-refresh]");if(e){e.dataset.spin="1",await zt(),setTimeout(()=>delete e.dataset.spin,500);return}if(H.hasAttribute("data-collapsed")&&t.target.closest(".dt-hist-head")){Te(!1);return}if(t.target.closest("[data-fold]")){Te(!H.hasAttribute("data-collapsed"));return}const n=t.target.closest(".dt-hist-bands [data-bp]");if(n){Zn(n.dataset.bp);return}const s=t.target.closest("[data-draft-go], [data-draft-rm]");if(s){const p=s.dataset.draftRm!==void 0,r=Number(p?s.dataset.draftRm:s.dataset.draftGo);st.hidden?p?Dn(r):Le(r):B(p?{dropDraft:r}:{openDraft:r});return}const o=t.target.closest("[data-unmark]");if(o){t.stopPropagation(),await pt(Number(o.dataset.unmark),!1);return}const a=t.target.closest(".dt-hist-tools [data-act]");if(a){await pt(Number(a.dataset.id),a.dataset.act==="done");return}const i=t.target.closest("[data-rm]");if(i){$=null,await Ee(Number(i.dataset.rm));return}if(t.target.closest("[data-review]")){ke.start();return}if(t.target.closest("[data-resolved]")){Ae(!W);return}const d=t.target.closest("[data-go]");if(!d)return;const u=Number(d.dataset.go);if(!st.hidden){B({open:u});return}Me(u)});const Me=t=>{$=t,K(),f();const e=b.find(s=>s.id===t),n=e&&I(e);n?scrollTo({top:scrollY+n.y-innerHeight/2,behavior:"smooth"}):e&&q(e)?.scrollIntoView({block:"center",behavior:"smooth"}),matchMedia("(prefers-reduced-motion: reduce)").matches||h.querySelector(`.dt-pin[data-id="${t}"]`)?.animate([{transform:"scale(1)"},{transform:"scale(1.5)"},{transform:"scale(1)"}],400)},Le=t=>{const[e]=A.splice(t,1);if(!e)return;K(),l=e,$=null;const n=I(e);n&&(n.y<0||n.y>innerHeight)&&scrollTo({top:scrollY+n.y-innerHeight/3,behavior:"instant"}),f()},Dn=t=>{A.splice(t,1),f()},ke=ua({inFrame:E,everything:()=>mt,route:()=>j,settle:pt,keepIn:tn,toast:t=>k(t),open:t=>{if(x||Q(!0),J(t)!==Ot()){Zn(J(t));for(const e of[600,1500])setTimeout(()=>B({open:t.id}),e)}else Me(t.id)}}),Ao=t=>{H.hidden=!t,Ht.setAttribute("aria-pressed",String(t)),G("dt-history",t?"1":"0"),f()},xe=document.querySelector(".dt-resolved-btn"),Ae=t=>{W=t,xe.setAttribute("aria-pressed",String(t)),G("dt-resolved",t?"1":"0"),B({resolved:t}),f(),Kt()};xe.addEventListener("click",()=>Ae(!W)),xe.setAttribute("aria-pressed",String(W)),Ht.addEventListener("click",()=>{const t=H.hidden===!0;t&&!x&&Q(!0),t&&Te(!1),Ao(t)});const X=()=>{le||!x||(le=requestAnimationFrame(()=>{le=0,ko()}))},qn=new MutationObserver(t=>{t.every(e=>e.target.closest?.(".dt-notes-overlay"))||X()}),In=new ResizeObserver(()=>X());let mt=[];const Pn=t=>{mt=t;const e=()=>({open:0,claude:0,done:0}),n={};for(const d of t){const u=rt(d),p=n[d.route??""]??={...e(),bands:{}};p[u]++;const r=J(d);(p.bands[r]??=e())[u]++}const s=["open","claude","done"],o={open:"open",claude:"resolved by an agent, to check",done:"resolved"},a=d=>s.map(u=>[u,u==="done"&&!W?0:d[u]]),i=d=>a(d).reduce((u,[,p])=>u+p,0);for(const d of document.querySelectorAll(".dt-pages a")){const u=d.querySelector(".dt-pages-n");if(!u)continue;const p=n[new URL(d.href).pathname.replace(/\/+$/,"")||"/"];for(const g of dt){const w=p?.bands[g.id];for(const[M,N]of a(w??e())){const Z=u.querySelector(`[data-bp="${g.id}"][data-state="${M}"]`);Z.hidden=!N,N&&(Z.querySelector("i").textContent=String(N),Z.title=`${g.label}: ${N} ${o[M]}`)}}const r=p?i(p):0;u.hidden=!r;const y=p?dt.filter(g=>p.bands[g.id]&&i(p.bands[g.id])).map(g=>`${g.label} ${i(p.bands[g.id])}`).join(" \xB7 "):"";u.title=r?`${p.open} open \xB7 ${p.claude} resolved by an agent, to check \xB7 ${p.done} resolved
73
- ${y}`:""}},St=t=>(Array.isArray(t)?t:[]).filter(e=>e&&Number.isInteger(Number(e.id))&&typeof e.text=="string").map(e=>({...e,id:Number(e.id),rx:Number(e.rx)||0,ry:Number(e.ry)||0,route:typeof e.route=="string"&&/^\/(?![\/\\])/.test(e.route)?e.route:"/",replies:Array.isArray(e.replies)?e.replies.filter(n=>typeof n?.text=="string"):[],images:Array.isArray(e.images)?e.images.filter(n=>typeof n=="string"):[]})),Kt=async()=>{try{Pn(St((await(await L("comments")).json()).comments)),!H.hidden&&!E&&f()}catch{}},Fn=pa(E,t=>k(t));let Wt="",He=!1;const Tt=async()=>{if(!(document.hidden||He)){He=!0;try{const t=await L(`comments${Wt?`?since=${Wt}`:""}`);if(t.status!==200)return;const e=await t.json();Wt=e.version??"",Fn(e);const n=St(e.comments);Pn(n);const s=n.filter(o=>o.route===j);if(JSON.stringify(s)===JSON.stringify(b))return;if(h.contains(document.activeElement)&&document.activeElement.matches("textarea, input")){Wt="",setTimeout(Tt,5e3);return}b=s,f(),B({reload:!0})}catch{}finally{He=!1}}},gt=async()=>{try{const e=await(await L(`comments?route=${encodeURIComponent(j)}`)).json();b=St(e.comments),Fn(e)}catch{b=[]}f()};let Ne=0;const jn=t=>{Ne||(Ne=requestAnimationFrame(()=>{Ne=0;const e=t.target;if(!x||e.closest(ee)){nt.hidden=!0;return}nt.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(nt.hidden=!1,!n)return;const s=n.getBoundingClientRect();Ls.style.cssText=`left:${s.left}px;top:${s.top}px;width:${s.width}px;height:${s.height}px`,Qe.textContent=n.tagName.toLowerCase()+([...n.classList].find(o=>!/^(astro|svelte)-/.test(o))?"."+[...n.classList].find(o=>!/^(astro|svelte)-/.test(o)):"")+` ${Math.round(s.width)}\xD7${Math.round(s.height)}`,Qe.style.cssText=`left:${s.left}px;top:${Math.max(2,s.top-20)}px`}))},_n=t=>{if(!(t.key!=="Escape"||t.isComposing)){if(t.preventDefault(),T){T=null,f();return}if(l){K(),f();return}if($!==null){$=null,f();return}Q(!1)}},Kn=["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend"],Wn=t=>{t.target.closest?.(ee)||t.stopPropagation()},Un=t=>{if(t.target.closest(ee))return;if(t.preventDefault(),t.stopPropagation(),te){te=!1;return}if(!getSelection()?.isCollapsed)return;h.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(h.hidden=!1,!n)return;K();const s=n.getBoundingClientRect(),o=n.tagName.toLowerCase(),a=[...n.classList].filter(i=>!/^(astro|svelte|css)-/.test(i)).slice(0,2);l={selector:Hs(n),tag:o,classes:a,nth:Ns({tag:o,classes:a}).indexOf(n),rx:s.width?(t.clientX-s.left)/s.width:.5,ry:s.height?(t.clientY-s.top)/s.height:.5,label:ht(n.textContent||"").slice(0,60),ctx:Cs(n),category:_e[0].id},Yn.set(l,Ce(n)),$=null,nt.hidden=!0,f()},Ho=2200,No=900*1024,zn=8*1024*1024,Co=3*1024*1024,Ro=1200,Oo=1600,Ce=async t=>{let e=t instanceof HTMLElement?t:null;for(let o=0;e&&o<4&&e.parentElement&&e.parentElement!==document.body;o++){const a=e.getBoundingClientRect();if(a.width>=360&&a.height>=140)break;e=e.parentElement}const n=e?.getBoundingClientRect();if(!e||!n?.width||!n.height)return null;let s="";for(let o=e;o&&!s;o=o.parentElement){const a=getComputedStyle(o).backgroundColor;a&&a!=="transparent"&&!/rgba\(.*,\s*0\)$/.test(a)&&(s=a)}if(!s){const[o,a,i]=(getComputedStyle(e).color.match(/[\d.]+/g)??["0","0","0"]).map(Number);s=.299*o+.587*a+.114*i>140?"#111":"#fff"}try{const{domToWebp:o}=await import("modern-screenshot"),a=Math.min(devicePixelRatio||1,2,Ro/n.width,Oo/n.height),i=await Promise.race([o(e,{scale:a,quality:.8,timeout:4e3,backgroundColor:s,filter:d=>!(d instanceof Element&&d.closest(Ze))}),new Promise(d=>setTimeout(()=>d(null),8e3))]);return i&&i.length<zn?i:null}catch{return null}},Yn=new WeakMap,k=t=>{const e=document.createElement("div");e.className="dt-toast",e.textContent=t,document.body.append(e),setTimeout(()=>e.remove(),2800)},Bo=t=>new Promise(e=>{const n=new FileReader;n.onload=()=>e(String(n.result)),n.readAsDataURL(t)}),Do=async t=>{const e=await createImageBitmap(t),n=Math.min(1,Ho/Math.max(e.width,e.height));if(n===1&&t.size<=No)return e.close(),Bo(t);const s=document.createElement("canvas");return s.width=Math.round(e.width*n),s.height=Math.round(e.height*n),s.getContext("2d").drawImage(e,0,0,s.width,s.height),e.close(),s.toDataURL("image/jpeg",.85)},Re=async(t,e)=>{const n=[];for(const s of t){let o;const a=Object.keys(Lt).find(i=>Lt[i]===s.type||s.name.toLowerCase().endsWith(`.${i}`));if(a){if(s.size>Co){k(`${s.name} is over 3 MB \u2014 send a link to it instead.`);continue}const i=await new Promise((d,u)=>{const p=new FileReader;p.onload=()=>d(String(p.result).split(",")[1]),p.onerror=u,p.readAsDataURL(s)}).catch(()=>"");i?n.push(`data:${Lt[a]};name=${Xo(s.name)||"document"};base64,${i}`):k(`${s.name} could not be read.`);continue}try{o=await Do(s)}catch{k("That image could not be read.");continue}if(o.length>zn){k("Screenshot is too large even after shrinking.");continue}n.push(o)}if(n.length){if(!Number(e?.dataset.id)){l&&((l.images??=[]).push(...n),f());return}O.push(...n),f(),Ut(".dt-note-reply-input")}},Vn=t=>[...t??[]].filter(e=>e.kind==="file"&&(e.type.startsWith("image/")||Object.values(Lt).includes(e.type))).map(e=>e.getAsFile()).filter(Boolean);h.addEventListener("paste",t=>{const e=Vn(t.clipboardData?.items);e.length&&(t.preventDefault(),Re(e,t.target.closest(".dt-note")))}),h.addEventListener("dragover",t=>{t.target.closest(".dt-note")&&(t.preventDefault(),t.target.closest(".dt-note").querySelector(".dt-compose")?.setAttribute("data-drop",""))}),h.addEventListener("dragleave",t=>{t.target.closest(".dt-note")?.querySelector(".dt-compose")?.removeAttribute("data-drop")}),h.addEventListener("drop",t=>{const e=t.target.closest(".dt-note");if(!e)return;t.preventDefault(),e.querySelector(".dt-compose")?.removeAttribute("data-drop");const n=Vn(t.dataTransfer?.items);n.length&&Re(n,e)});const Ut=t=>{const e=h.querySelector(t);e?.focus(),e?.setSelectionRange(e.value.length,e.value.length)},Jn=()=>{Ut(".dt-note-edit-input"),h.querySelector(".dt-msg .dt-compose")?.scrollIntoView({block:"nearest"})},Oe=t=>{t.style.overflowY="hidden",t.style.height="auto",t.style.height=`${t.scrollHeight}px`,t.style.overflowY=t.scrollHeight>t.clientHeight?"auto":"hidden"},qo=t=>/(?:^|\s)@([^\s@]*)$/.exec(t.value.slice(0,t.selectionStart??t.value.length)),Io=()=>c.client||he()?[]:us(),Po=t=>{t.closest(".dt-compose").querySelector(".dt-mentions")?.remove();const n=qo(t);if(!n)return;const s=n[1].toLowerCase(),o=(c.team??[]).filter(i=>[i.name,i.nickname,i.email].some(d=>d?.toLowerCase().startsWith(s))).slice(0,5),a=Io().filter(i=>i.handle.toLowerCase().startsWith(s)||!!s&&"agent".startsWith(s)||!!s&&"claude".startsWith(s)).slice(0,4);!o.length&&!a.length||t.insertAdjacentHTML("afterend",`<div class="dt-mentions" role="listbox" aria-label="Mention someone">${[...o.map(i=>`<button type="button" role="option" data-act="mention" data-handle="${m(Qo(i))}">${Pt(i.avatar_url,i.name||i.email)}<span class="dt-mention-who"><b>${m(i.name||i.email)}</b>${i.name?`<span>${m(i.email)}</span>`:""}</span></button>`),...a.map(i=>`<button type="button" role="option" data-act="mention" data-handle="${m(i.handle)}">${_s(i.owner)}<span class="dt-mention-who"><b>${m(i.handle)}</b><span>${i.owner?"Hands it to this agent":"The shared queue \u2014 any agent takes it"}</span></span></button>`)].map((i,d)=>i.replace('role="option"',`role="option" aria-selected="${d===0}"`)).join("")}</div>`)},Fo=t=>{const e=[...(c.team??[]).flatMap(s=>[s.name,s.nickname,s.email]),...us().map(s=>s.handle)].filter(s=>!!s).sort((s,o)=>o.length-s.length).map(s=>m(s).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),n=m(t);return e.length?n.replace(new RegExp(`@(?:${e.join("|")})(?![\\p{L}\\p{N}_.-])`,"giu"),s=>`<span class="dt-at">${s}</span>`):n},Gn=(t,e)=>{const n=t.selectionStart??t.value.length,s=t.value.slice(0,n).lastIndexOf("@");t.value=`${t.value.slice(0,s)}@${e} ${t.value.slice(n)}`,t.selectionStart=t.selectionEnd=s+e.length+2,t.closest(".dt-compose")?.querySelector(".dt-mentions")?.remove(),t.dispatchEvent(new Event("input",{bubbles:!0})),t.focus()},jo=(t,e)=>{if(!t){l&&(l.category=e),f();return}P(n=>n.map(s=>s.id===t?{...s,category:e}:s),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,category:e})}),"Changing the type")};ra(h,m,Gt);const Xn=(t,e)=>{t?P(n=>n.map(s=>s.id===t?{...s,shared:e||void 0}:s),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,shared:e})}),e?"Sharing with the client":"Keeping it to the team"):l&&(l.shared=e||void 0,ot(),f())};h.addEventListener("change",t=>{const e=t.target.closest(".dt-more-select");if(e){const i=e.value,d=Number(e.dataset.id)||0;e.value="",i==="team"||i==="client"?Xn(d,i==="client"):i==="rm"&&confirm("Delete this thread and its replies? This cannot be undone.")?($=null,Ee(d)):i==="discard"&&(l=null,f());return}const n=t.target.closest(".dt-cat-select");if(n){jo(Number(n.dataset.id)||0,n.value);return}const s=t.target.closest(".dt-status-select");if(s){Vs(Number(s.dataset.id),s.value);return}const o=t.target.closest(".dt-for-select");if(!o)return;o.parentElement?.style.setProperty("--cat",vt(o.value));const a=Number(o.dataset.id);if(a){const i=o.value||null;P(d=>d.map(u=>u.id===a?{...u,assignee:i??void 0}:u),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:a,assignee:i})}),"Reassigning");return}if(l){l.assignee=o.value;try{localStorage.setItem("nm-for",o.value)}catch{}ot()}}),h.addEventListener("input",t=>{const e=t.target.closest(".dt-suggest-input");if(e&&l?.suggest){l.suggest.to=e.value,ot(),Oe(e);return}const n=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");n&&(Po(n),n.classList.contains("dt-note-input")?l&&(l.text=n.value):n.classList.contains("dt-note-edit-input")?T&&(T.text=n.value):R=n.value,ot(),n.closest(".dt-compose")?.querySelector(".dt-send")?.classList.toggle("is-ready",n.value.trim()!==""),Oe(n))}),h.addEventListener("keydown",t=>{const e=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");if(!e)return;const n=e.closest(".dt-compose")?.querySelector(".dt-mentions button");if(n&&(t.key==="Enter"||t.key==="Tab")&&!t.isComposing){t.preventDefault(),Gn(e,n.dataset.handle);return}if(n&&t.key==="Escape"){t.stopPropagation(),n.parentElement.remove();return}t.key!=="Enter"||t.shiftKey||t.isComposing||(t.preventDefault(),e.closest(".dt-compose")?.querySelector(".dt-send")?.click())}),h.addEventListener("click",async t=>{const e=t.target.closest("button");if(!e)return;const n=e.dataset.act,s=Number(e.dataset.id);if(n==="share"){Xn(s,e.dataset.v==="1");return}if(n==="prio"){const o=e.dataset.v||null;s?P(a=>a.map(i=>i.id===s?{...i,priority:o??void 0}:i),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,priority:o})}),"Setting the priority"):l&&(l.priority=o??void 0,ot(),f());return}if(n==="mention"){const o=e.closest(".dt-compose")?.querySelector("textarea");o&&Gn(o,e.dataset.handle);return}if(!n){if($=$===s?null:s,$!=null&&e.dataset.off){const o=b.find(i=>i.id===s);(o&&q(o))?.scrollIntoView({block:"nearest",inline:"center",behavior:"smooth"})}K(),f();return}if(n==="record"){uo(e.closest(".dt-note"));return}if(n==="speak"){ho(e.closest(".dt-note"),e);return}if(n==="voice-write"){yo(e);return}if(n==="voice"||n==="voice-seek"){so(e,n==="voice-seek"?t:null);return}if(n==="attach"){const o=Object.assign(document.createElement("input"),{type:"file",accept:`image/*,.pdf,.doc,.docx,${Object.values(Lt)}`,multiple:!0}),a=e.closest(".dt-note");o.addEventListener("change",()=>{o.files?.length&&Re([...o.files],a)}),o.click();return}if(n==="unshot"){s?T&&T.drop.push(e.dataset.img):(e.closest("[data-draft]")?l?.images??[]:O).splice(Number(e.dataset.i),1),f(),T&&Jn();return}if(n==="edit"){const o=b.find(d=>d.id===s),a=e.dataset.at||null,i=a?o?.replies?.find(d=>d.at===a)?.text:o?.text;if(i===void 0)return;T={id:s,at:a,text:i,drop:[]},f(),Jn();return}if(n==="edit-cancel"){T=null,f();return}if(n==="translate"){vo(s,e.dataset.at);return}if(n==="unsay"){const o=e.dataset.at;if(!confirm("Delete this reply?"))return;await P(a=>a.map(i=>i.id!==s?i:{...i,replies:(i.replies??[]).map(d=>d.at===o?{...d,text:"",deleted:!0}:d)}),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,unsay:o})}),"Deleting the reply");return}if(n==="edit-save"){const o=T;if(!o)return;const a=o.text.trim();if(!a){h.querySelector(".dt-note-edit-input")?.focus();return}T=null;const i=d=>o.drop.includes(d.split("/").pop());await P(d=>d.map(u=>u.id!==o.id?u:{...u,...o.at==null?{text:a}:{replies:(u.replies??[]).map(p=>p.at===o.at?{...p,text:a}:p)},images:(u.images??[]).filter(p=>!i(p))}),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:o.id,edit:{at:o.at,text:a},...o.drop.length?{removeImage:o.drop}:{}})}).then(d=>(d.ok||(T=o),d)),"Saving the edit");return}if(n==="cancel"){K(),f();return}if(n==="twin"){K(),$=Number(e.dataset.id),f();return}if(n==="discard"){l=null,f();return}if(n==="draft-open"){Le(Number(e.dataset.i));return}if(n==="close"){$=null,f();return}if(n==="suggest"&&l){const o=mn(q(l));l.suggest={from:o,to:o},f();const a=h.querySelector(".dt-suggest-input");a?.focus(),a?.select();return}if(n==="unsuggest"&&l){l.suggest=null,f();return}if(n==="save"){if(!l)return;const o=l.suggest&&l.suggest.to.trim()!==l.suggest.from?{from:l.suggest.from,to:l.suggest.to.trim()}:null,a=h.querySelector(".dt-note-input").value.trim()||(o?"Change the text":"")||(l.images?.some(ye)?kn:"");if(!a){h.querySelector(".dt-note-input")?.focus();return}const i=l,d=c.client?null:ps(a,qt()),u=Yn.get(i)??Ce(q(i)),p={...i,route:j,text:a,suggest:o,assignee:c.client?i.assignee||c.lead||void 0:d??(i.assignee||void 0),shared:c.client?!0:i.shared===!0,stage:c.client?"new":d?"approved":i.stage??(D(i.assignee)?"approved":"new"),breakpoint:ue(),browser:As(),device:E?Qn:"",viewport:{w:innerWidth,h:innerHeight},logs:sa(),host:location.host},r={...i,id:-Date.now(),text:a,route:j,status:"open",note:"",doneBy:null,breakpoint:p.breakpoint,replies:[],images:[],createdAt:new Date().toISOString(),...o?{suggest:o}:{},by:c.me?.email,byName:c.me?.name};b=[...b,r],l=null,f();const y=await u,g=await L("comments",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...p,...y?{before:y}:{}})});if(!g.ok){b=b.filter(M=>M!==r),l=i,f(),k(`Comment was not saved (${g.status}).`);return}const w=St([await g.json().catch(()=>null)])[0];b=b.map(M=>M===r&&w?w:M),f(),zt();return}if(n==="reply"){const o=h.querySelector(".dt-note-reply-input"),a=o.value.trim()||(O.some(ye)?kn:"");if(!a){o.focus();return}const i=O;R="",O=[];const d=b,u=c.client?null:ps(a,qt()),p=b.find(w=>w.id===s),r=u&&p&&(u!==p.assignee||lt(p)!=="approved"||p.status==="done")?{assignee:u,stage:"approved",...p.status==="done"?{status:"open",doneBy:null}:{}}:{};b=b.map(w=>w.id===s?{...w,...r,replies:[...w.replies??[],{author:"you",text:a,at:new Date().toISOString(),by:c.me?.email}]}:w),f();const y=await L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,reply:a,images:i,...r})});if(!y.ok){b=d,R=a,O=i,f(),k(`Reply was not sent (${y.status}).`);return}const g=St([await y.json().catch(()=>null)])[0];g&&(b=b.map(w=>w.id===g.id?g:w),f()),zt();return}if(n==="hand"){Ps(s,e.dataset.v);return}if(n==="sendback"){await pt(s,!1),Ut(".dt-note-reply-input");return}e.classList.contains("dt-step-act")||($=null),n==="rm"?await Ee(s):await pt(s,n==="done")});let Qn="";const B=t=>{st.hidden||Nt.contentWindow?.postMessage({dt:!0,...t},location.origin)},_o=()=>({notes:x,grid:!xt.hidden,inspect:_,resolved:W,...ts.look()});addEventListener("message",t=>{if(t.origin!==location.origin||!t.data?.dt)return;const e=t.data;if(!E&&t.source===Nt.contentWindow){if(e.key){as(e.key[0],e.key[1])?.run();return}if(e.closeMenus){bt();return}if(e.drafts){we=e.drafts,Bn(Ot());return}}if(E&&typeof e.openDraft=="number"){Le(e.openDraft);return}if(E&&typeof e.dropDraft=="number"){Dn(e.dropDraft);return}if(E&&typeof e.device=="string"&&(Qn=e.device),E&&e.scrollbar&&document.documentElement.classList.toggle("dt-sb-classic",e.scrollbar==="classic"),e.hello&&t.source===Nt.contentWindow){B(_o());return}typeof e.notes=="boolean"&&e.notes!==x&&Q(e.notes,!1),typeof e.open=="number"&&Me(e.open),typeof e.grid=="boolean"&&e.grid===xt.hidden&&Zt(e.grid),typeof e.inspect=="string"&&e.inspect!==_&&At(e.inspect),typeof e.resolved=="boolean"&&e.resolved!==W&&Ae(e.resolved),e.reload&&(gt(),Kt())});const zt=async()=>{await gt(),Kt(),B({reload:!0}),E&&parent.postMessage({dt:!0,reload:!0},location.origin)},Q=(t,e=!0)=>{if(x=t,Xe.setAttribute("aria-pressed",String(t)),t?!E&&H.hidden&&localStorage.getItem("dt-history")!=="0"&&(H.hidden=!1,Ht.setAttribute("aria-pressed","true")):(H.hidden=!0,Ht.setAttribute("aria-pressed","false")),G(en,t?"1":"0"),B({notes:t}),E&&e&&parent.postMessage({dt:!0,notes:t},location.origin),h.hidden=!t||!st.hidden,document.documentElement.classList.toggle("dt-noting",t),t){At(""),document.addEventListener("click",Un,!0);for(const n of Kn)document.addEventListener(n,Wn,!0);document.addEventListener("keydown",_n),document.addEventListener("mousemove",jn),addEventListener("scroll",X,!0),addEventListener("resize",X),qn.observe(document.body,{childList:!0,subtree:!0,characterData:!0}),In.observe(document.body),gt()}else{K(),$=null,document.removeEventListener("click",Un,!0);for(const n of Kn)document.removeEventListener(n,Wn,!0);document.removeEventListener("keydown",_n),document.removeEventListener("mousemove",jn),nt.hidden=!0,removeEventListener("scroll",X,!0),removeEventListener("resize",X),qn.disconnect(),In.disconnect(),h.innerHTML=""}},{pickBp:Zn,...ts}=da({cfg:c,inFrame:E,persist:G,frame:st,frameEl:Nt,devicesMenu:ie,bpBtns:oe,notesOverlay:h,WIDE:Xt,bpOf:Ke,currentBp:ue,deviceById:ys,notesOn:()=>x,filter:()=>de,filterTo:t=>{de=t},dropFrameDrafts:()=>{we=[]},putAway:()=>{$=null,K()},tellFrame:B,syncBpButtons:sn,render:()=>f(),reread:()=>{x?gt():f()}}),es="dt-studio",ns=t=>{ae.setAttribute("aria-pressed",String(t)),document.documentElement.classList.toggle("dt-no-studio",!t),G(es,t?"1":"0")};ae.addEventListener("click",()=>ns(ae.getAttribute("aria-pressed")!=="true")),ns(localStorage.getItem(es)!=="0"),Xe.addEventListener("click",()=>Q(!x));const ft=document.querySelector(".devtools"),Mt=document.querySelector(".dt-tab"),ss=t=>{ft.toggleAttribute("data-collapsed",t),Mt.toggleAttribute("data-collapsed",t),Mt.setAttribute("aria-expanded",String(!t)),Mt.setAttribute("aria-label",t?"Show the bar":"Hide the bar");for(const e of ft.querySelectorAll(".dt-group"))e.inert=t;t&&bt(),G("dt-collapsed",t?"1":"0")};Mt.addEventListener("click",()=>ss(!ft.hasAttribute("data-collapsed")));const Be=document.querySelector(".dt-keys"),F=t=>()=>ft.querySelector(t)?.click(),os=t=>()=>{const e=[...document.querySelectorAll(".dt-pages a")];e[e.findIndex(n=>n.hasAttribute("aria-current"))+t]?.click()},Yt=[{group:"Comments",code:"KeyC",hint:"C",label:"Comment mode",el:".dt-notes-btn",run:F(".dt-notes-btn")},{group:"Comments",code:"KeyC",shift:!0,hint:"\u21E7C",label:"Comments panel",el:".dt-history-btn",run:F(".dt-history-btn")},{group:"Comments",code:"KeyR",hint:"R",label:"Show resolved",el:".dt-resolved-btn",run:F(".dt-resolved-btn")},{group:"Inspect",code:"KeyG",hint:"G",label:"Grid",el:".dt-grid-btn",run:F(".dt-grid-btn")},{group:"Inspect",code:"KeyP",hint:"P",label:"Spacing",el:".dt-pad-btn",run:F(".dt-pad-btn")},{group:"Inspect",code:"KeyS",hint:"S",label:"Size",el:".dt-size-btn",run:F(".dt-size-btn")},{group:"Inspect",code:"KeyT",hint:"T",label:"Typography",el:".dt-type-btn",run:F(".dt-type-btn")},{group:"Inspect",code:"KeyO",hint:"O",label:"Color",el:".dt-color-btn",run:F(".dt-color-btn")},{group:"Inspect",code:"KeyB",hint:"B",label:"Border & radius",el:".dt-border-btn",run:F(".dt-border-btn")},...c.sanity?[{group:"Inspect",code:"KeyE",hint:"E",label:"Sanity overlay",el:".dt-studio-btn",run:F(".dt-studio-btn")}]:[],...oe.slice(0,9).map((t,e)=>({group:"Breakpoints",code:`Digit${e+1}`,hint:String(e+1),label:t.dataset.tip??t.title,el:`.dt-bp[data-bp="${t.dataset.bp}"]`,run:()=>t.click()})),{group:"View",code:"KeyD",hint:"D",label:"Devices",run:()=>{ie.open=!ie.open}},{group:"View",code:"BracketLeft",hint:"[",label:"Previous page",run:os(-1)},{group:"View",code:"BracketRight",hint:"]",label:"Next page",run:os(1)},{group:"View",code:"Backslash",hint:"\\",label:"Hide the bar",run:()=>Mt.click()},{group:"View",code:"Slash",shift:!0,hint:"?",label:"This list",el:".dt-keys summary",run:()=>{Be.open=!Be.open}}].filter(t=>!c.client||t.group!=="Inspect"),as=(t,e)=>Yt.find(n=>n.code===t&&!n.shift==!e),Ko=t=>t instanceof HTMLElement&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)||!!t.closest('[role="menu"], [role="listbox"], [role="dialog"][aria-modal="true"], [role="combobox"]'));if(c.shortcuts){for(const e of Yt){const n=e.el&&ft.querySelector(e.el);n&&(n.dataset.tip=`${n.dataset.tip??e.label} \xB7 ${e.hint}`,n.setAttribute("aria-keyshortcuts",e.hint.startsWith("\u21E7")?`Shift+${e.hint.slice(1)}`:e.hint))}const t=(e,n)=>`<div class="dt-key-row"><span>${m(e)}</span><kbd>${m(n)}</kbd></div>`;if(Be.querySelector(".dt-keys-menu").innerHTML='<p class="dt-menu-note">One key, no modifier, in any keyboard layout. Not while you type.</p>'+[...new Set(Yt.map(e=>e.group))].map(e=>`<p class="dt-devices-group">${e}</p>`+Yt.filter(n=>n.group===e).map(n=>t(n.label,n.hint)).join("")).join("")+'<p class="dt-devices-group">In a comment</p>'+t("Send","Enter")+t("New line","\u21E7Enter")+t("Close, cancel, back out","Esc"),document.addEventListener("keydown",e=>{if(e.repeat||e.isComposing||e.metaKey||e.ctrlKey||e.altKey||e.defaultPrevented||Ko(e.target))return;const n=as(e.code,e.shiftKey);n&&(e.preventDefault(),E?parent.postMessage({dt:!0,key:[e.code,e.shiftKey]},location.origin):n.run())}),E){const e=()=>parent.postMessage({dt:!0,closeMenus:!0},location.origin);document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",n=>{n.key==="Escape"&&e()})}}if(!E){ss(localStorage.getItem("dt-collapsed")==="1"),requestAnimationFrame(()=>requestAnimationFrame(()=>ft.setAttribute("data-ready",""))),ts.restore(),Zt(localStorage.getItem(Ue)==="1");const t=localStorage.getItem(Je);t&&t in ne&&At(t),Q(localStorage.getItem(en)==="1")}const is=()=>{try{const t=JSON.parse(localStorage.getItem(ut)||"null");A=(t?.parked??[]).filter(e=>Ct(e)),t?.draft&&document.querySelector(t.draft.selector)?(l=t.draft,!x&&!E&&Q(!0)):Ct(t?.draft)&&A.push(t.draft),t?.reply?.text&&(R=t.reply.text,yt=$=t.reply.for??null),(l||A.length||R)&&f()}catch{localStorage.removeItem(ut)}};is();const rs=()=>setTimeout(()=>{const t=Qt(location.pathname);t!==j&&(clearTimeout(Rt),ce(),j=t,ut=nn(),l=null,A=[],R="",yt=null,$=null,T=null,b=[],Ye(),is(),gt())});for(const t of["pushState","replaceState"]){const e=window.history[t];window.history[t]=function(...n){e.apply(this,n),rs()}}addEventListener("popstate",rs),x||gt(),Kt().then(ke.resume),document.addEventListener("visibilitychange",()=>{document.hidden||Tt()}),addEventListener("focus",Tt),addEventListener("notemend:changed",()=>{E||Tt()});let Wo=0;E||setInterval(()=>{(!ea.live||++Wo%6===0)&&Tt()},2e4),E&&parent.postMessage({dt:!0,hello:!0},location.origin)}export{Ha as run};
71
+ ${Wn("dt-note-input",d.suggest?"Why (optional)":"Comment",d.text??"",'data-act="save"',Fn(d.images),ha&&!d.suggest&&Hn(o?F(d):null)?`<button class="dt-attach" data-act="suggest" title="Rewrite this text: start from its current words and change them">${Ma}</button>`:"")}
72
+ ${On(d.priority,d.category,void 0,d.assignee??"")}
73
+ </div>`}const i=new Map([...b.querySelectorAll(".dt-note[data-id] .dt-note-thread")].map(r=>[r.closest(".dt-note").dataset.id,{top:r.scrollTop,end:r.scrollTop+r.clientHeight>=r.scrollHeight-4}])),l=new Set([...b.querySelectorAll("[data-msg]")].map(r=>r.dataset.msg)),u=b.contains(document.activeElement)&&document.activeElement.matches(".dt-note-reply-input");b.innerHTML=s,u&&ae(".dt-note-reply-input");for(const r of b.querySelectorAll(".dt-note[data-id] .dt-note-thread")){const h=r.closest(".dt-note").dataset.id,g=i.get(h);if(!g)continue;const w=[...r.querySelectorAll("[data-msg]")].filter(M=>!l.has(M.dataset.msg));for(const M of w)M.classList.add("dt-msg--new");r.scrollTop=g.end&&w.length?r.scrollHeight:g.top}for(const r of b.querySelectorAll(".dt-note")){const h=r.getBoundingClientRect();h.bottom>innerHeight-8&&(r.dataset.flip="1"),h.right>innerWidth-8&&(r.dataset.flipx="1")}Nt(n),Me(yn()),et();for(const r of b.querySelectorAll(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input"))ze(r);const m=b.querySelector(".dt-note-input");m&&(m.focus(),m.setSelectionRange(m.value.length,m.value.length))},Ka=()=>{let t=!1;for(const e of b.querySelectorAll(".dt-pin[data-id], .dt-note[data-id]")){if(e.classList.contains("dt-note--orphan"))continue;const n=y.find(a=>a.id===Number(e.dataset.id)),s=n&&_(n);if(!s){e.style.visibility="hidden";continue}e.style.visibility="",e.style.left=`${s.x}px`,e.style.top=`${s.y}px`,e.classList.contains("dt-pin")&&(s.off?e.dataset.off=s.off:delete e.dataset.off),bn(s.el)&&(t=!0)}for(const e of b.querySelectorAll("[data-draft], [data-parked]")){if(e.classList.contains("dt-note--orphan"))continue;const n=e.dataset.parked?N[Number(e.dataset.parked)]:d,s=n&&_(n);if(!s){e.style.visibility="hidden";continue}e.style.visibility="",e.style.left=`${s.x}px`,e.style.top=`${s.y}px`}if(!zt.length&&(d||$!=null)){const e=yn();e&&bn(e)&&Me(e)}t&&et()},Wa=t=>y.filter(e=>tt(e)===tt(t)).findIndex(e=>e.id===t.id)+1,Nt=t=>{if(!x.hidden&&(x.innerHTML=So({bp:t,notes:y,breakpoints:pt,bandOfNote:tt,orphan:e=>!_(e),whoseAgent:dt,statusTools:Vn,showResolved:J,drafts:it.hidden?Un():Re,checks:E?0:Pe.toCheck().length,marker:za,find:C,forMe:Ua,forAgent:e=>!!Z(e)&&P(e)!=="done",unread:xn}),bt)){const e=x.querySelector("[data-hist-q]");e?.focus(),e?.setSelectionRange(bt.at,bt.at),bt=null}};let bt=null;const Ua=t=>{if(P(t)==="done"||!c.me)return!1;if(t.assignee===c.me.email||P(t)==="claude"||U(t)==="review"&&t.assignee!==c.me.email)return!0;const e=(c.me.name||c.me.email).split(/[\s@]/)[0].toLowerCase();return It(t).some(n=>n.text.toLowerCase().includes("@"+e))},za=t=>{if(P(t)==="done")return'<span class="dt-hist-n"></span>';const n=Ln[Z(t)??""];if(n)return`<span class="dt-hist-face dt-hist-face--agent" style="--step-c:${n}">${Et(10)}</span>`;const s=Tn(t);return s?`<span class="dt-hist-face" style="--ring:${Jt.find(a=>a[0]===Gt(t))[2]};--hue:${Mn(t.by||t.byName||"")}">${s}</span>`:`<span class="dt-hist-n" style="--cat:${de(t.category).color}"></span>`},Be=t=>x.toggleAttribute("data-collapsed",t);x.addEventListener("input",t=>{const e=t.target.closest("[data-hist-q]");e&&(C.q=e.value,bt={at:e.selectionStart??e.value.length},Nt(lt()))}),x.addEventListener("click",async t=>{const e=t.target.closest("[data-refresh]");if(e){e.dataset.spin="1",await oe(),setTimeout(()=>delete e.dataset.spin,500);return}if(x.hasAttribute("data-collapsed")&&t.target.closest(".dt-hist-head")){Be(!1);return}if(t.target.closest("[data-fold]")){Be(!x.hasAttribute("data-collapsed"));return}const n=t.target.closest(".dt-hist-bands [data-bp]");if(n){fs(n.dataset.bp);return}const s=t.target.closest("[data-hist-filter], [data-hist-view], [data-hist-sort], [data-hist-clear]");if(s){s.dataset.histView?(C.view=s.dataset.histView,O("dt-view",C.view),C.menu=!1):s.dataset.histSort?(C.sort=s.dataset.histSort,O("dt-sort",C.sort),C.menu=!1):s.hasAttribute("data-hist-clear")?(C.q="",bt={at:0}):C.menu=!C.menu,Nt(lt());return}C.menu&&!t.target.closest(".dt-hist-menu")&&(C.menu=!1,Nt(lt()));const a=t.target.closest("[data-draft-go], [data-draft-rm]");if(a){const r=a.dataset.draftRm!==void 0,h=Number(r?a.dataset.draftRm:a.dataset.draftGo);it.hidden?r?Xn(h):Ie(h):D(r?{dropDraft:h}:{openDraft:h});return}const o=t.target.closest("[data-unmark]");if(o){t.stopPropagation(),await ht(Number(o.dataset.unmark),!1);return}const i=t.target.closest(".dt-hist-tools [data-act]");if(i){await ht(Number(i.dataset.id),i.dataset.act==="done");return}const l=t.target.closest("[data-rm]");if(l){$=null,await Oe(Number(l.dataset.rm));return}if(t.target.closest("[data-review]")){Pe.start();return}if(t.target.closest("[data-resolved]")){Fe(!J);return}const u=t.target.closest("[data-go]");if(!u)return;const m=Number(u.dataset.go);if(!it.hidden){D({open:m});return}De(m)});const De=t=>{$=t,V(),f();const e=y.find(s=>s.id===t),n=e&&_(e);n?scrollTo({top:scrollY+n.y-innerHeight/2,behavior:"smooth"}):e&&F(e)?.scrollIntoView({block:"center",behavior:"smooth"}),matchMedia("(prefers-reduced-motion: reduce)").matches||b.querySelector(`.dt-pin[data-id="${t}"]`)?.animate([{transform:"scale(1)"},{transform:"scale(1.5)"},{transform:"scale(1)"}],400)},Ie=t=>{const[e]=N.splice(t,1);if(!e)return;V(),d=e,$=null;const n=_(e);n&&(n.y<0||n.y>innerHeight)&&scrollTo({top:scrollY+n.y-innerHeight/3,behavior:"instant"}),f()},Xn=t=>{N.splice(t,1),f()},Pe=To({inFrame:E,everything:()=>yt,route:()=>z,settle:ht,keepIn:mn,toast:t=>A(t),open:t=>{if(H||nt(!0),tt(t)!==lt()){fs(tt(t));for(const e of[600,1500])setTimeout(()=>D({open:t.id}),e)}else De(t.id)}}),Ya=t=>{x.hidden=!t,Ft.setAttribute("aria-pressed",String(t)),O("dt-history",t?"1":"0"),f()},je=document.querySelector(".dt-resolved-btn"),Fe=t=>{J=t,je.setAttribute("aria-pressed",String(t)),O("dt-resolved",t?"1":"0"),D({resolved:t}),f(),ne()};je.addEventListener("click",()=>Fe(!J)),je.setAttribute("aria-pressed",String(J)),Ft.addEventListener("click",()=>{const t=x.hidden===!0;t&&!H&&nt(!0),t&&Be(!1),Ya(t)});const et=()=>{we||!H||(we=requestAnimationFrame(()=>{we=0,Ka()}))},Qn=new MutationObserver(t=>{t.every(e=>e.target.closest?.(".dt-notes-overlay"))||et()}),Zn=new ResizeObserver(()=>et());let yt=[];const ts=t=>{yt=t;const e=()=>({new:0,progress:0,review:0,waiting:0,accepted:0,done:0}),n={};for(const l of t){const u=P(l),m=Z(l),r=u==="done"?"done":u==="claude"?"review":m&&Xt[m]||Gt(l),h=n[l.route??""]??={...e(),bands:{}};h[r]++;const g=tt(l);(h.bands[g]??=e())[r]++}const s=["new","progress","review","waiting","accepted","done"],a={new:"new",progress:"in progress",review:"to review",waiting:"waiting",accepted:"accepted",done:"resolved"},o=l=>s.map(u=>[u,u==="done"&&!J?0:l[u]]),i=l=>o(l).reduce((u,[,m])=>u+m,0);for(const l of document.querySelectorAll(".dt-pages a")){const u=l.querySelector(".dt-pages-n");if(!u)continue;const m=n[new URL(l.href).pathname.replace(/\/+$/,"")||"/"];for(const g of pt){const w=m?.bands[g.id];for(const[M,R]of o(w??e())){const st=u.querySelector(`[data-bp="${g.id}"][data-state="${M}"]`);st.hidden=!R,R&&(st.querySelector("i").textContent=String(R),st.title=`${g.label}: ${R} ${a[M]}`)}}const r=m?i(m):0;u.hidden=!r;const h=m?pt.filter(g=>m.bands[g.id]&&i(m.bands[g.id])).map(g=>`${g.label} ${i(m.bands[g.id])}`).join(" \xB7 "):"";u.title=r?`${s.filter(g=>m[g]).map(g=>`${m[g]} ${a[g]}`).join(" \xB7 ")}
74
+ ${h}`:""}},Ct=t=>(Array.isArray(t)?t:[]).filter(e=>e&&Number.isInteger(Number(e.id))&&typeof e.text=="string").map(e=>({...e,id:Number(e.id),rx:Number(e.rx)||0,ry:Number(e.ry)||0,route:typeof e.route=="string"&&/^\/(?![\/\\])/.test(e.route)?e.route:"/",replies:Array.isArray(e.replies)?e.replies.filter(n=>typeof n?.text=="string"):[],images:Array.isArray(e.images)?e.images.filter(n=>typeof n=="string"):[]})),ne=async()=>{try{ts(Ct((await(await L("comments")).json()).comments)),!x.hidden&&!E&&f()}catch{}},es=Mo(E,t=>A(t));let se="",_e=!1;const Rt=async()=>{if(!(document.hidden||_e)){_e=!0;try{const t=await L(`comments${se?`?since=${se}`:""}`);if(t.status!==200)return;const e=await t.json();se=e.version??"",es(e);const n=Ct(e.comments);ts(n);const s=n.filter(a=>a.route===z);if(JSON.stringify(s)===JSON.stringify(y))return;if(b.contains(document.activeElement)&&document.activeElement.matches("textarea, input")){se="",setTimeout(Rt,5e3);return}y=s,f(),D({reload:!0})}catch{}finally{_e=!1}}},vt=async()=>{try{const e=await(await L(`comments?route=${encodeURIComponent(z)}`)).json();y=Ct(e.comments),es(e)}catch{y=[]}f()};let Ke=0;const ns=t=>{Ke||(Ke=requestAnimationFrame(()=>{Ke=0;const e=t.target;if(!H||e.closest(ge)){ot.hidden=!0;return}ot.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(ot.hidden=!1,!n)return;const s=n.getBoundingClientRect();Ws.style.cssText=`left:${s.left}px;top:${s.top}px;width:${s.width}px;height:${s.height}px`,un.textContent=n.tagName.toLowerCase()+([...n.classList].find(a=>!/^(astro|svelte)-/.test(a))?"."+[...n.classList].find(a=>!/^(astro|svelte)-/.test(a)):"")+` ${Math.round(s.width)}\xD7${Math.round(s.height)}`,un.style.cssText=`left:${s.left}px;top:${Math.max(2,s.top-20)}px`}))},ss=t=>{if(!(t.key!=="Escape"||t.isComposing)){if(t.preventDefault(),T){T=null,f();return}if(d){V(),f();return}if($!==null){$=null,f();return}nt(!1)}},as=["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend"],os=t=>{t.target.closest?.(ge)||t.stopPropagation()},is=t=>{if(t.target.closest(ge))return;if(t.preventDefault(),t.stopPropagation(),me){me=!1;return}if(!getSelection()?.isCollapsed)return;b.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(b.hidden=!1,!n)return;V();const s=n.getBoundingClientRect(),a=n.tagName.toLowerCase(),o=[...n.classList].filter(i=>!/^(astro|svelte|css)-/.test(i)).slice(0,2);d={selector:Vs(n),tag:a,classes:o,nth:Js({tag:a,classes:o}).indexOf(n),rx:s.width?(t.clientX-s.left)/s.width:.5,ry:s.height?(t.clientY-s.top)/s.height:.5,label:wt(n.textContent||"").slice(0,60),ctx:Gs(n),category:tn[0].id},ls.set(d,We(n)),$=null,ot.hidden=!0,f()},Va=2200,Ja=900*1024,rs=8*1024*1024,Ga=3*1024*1024,Xa=1200,Qa=1600,We=async t=>{let e=t instanceof HTMLElement?t:null;for(let a=0;e&&a<4&&e.parentElement&&e.parentElement!==document.body;a++){const o=e.getBoundingClientRect();if(o.width>=360&&o.height>=140)break;e=e.parentElement}const n=e?.getBoundingClientRect();if(!e||!n?.width||!n.height)return null;let s="";for(let a=e;a&&!s;a=a.parentElement){const o=getComputedStyle(a).backgroundColor;o&&o!=="transparent"&&!/rgba\(.*,\s*0\)$/.test(o)&&(s=o)}if(!s){const[a,o,i]=(getComputedStyle(e).color.match(/[\d.]+/g)??["0","0","0"]).map(Number);s=.299*a+.587*o+.114*i>140?"#111":"#fff"}try{const{domToWebp:a}=await import("modern-screenshot"),o=Math.min(devicePixelRatio||1,2,Xa/n.width,Qa/n.height),i=await Promise.race([a(e,{scale:o,quality:.8,timeout:4e3,backgroundColor:s,filter:l=>!(l instanceof Element&&l.closest(pn))}),new Promise(l=>setTimeout(()=>l(null),8e3))]);return i&&i.length<rs?i:null}catch{return null}},ls=new WeakMap,A=t=>{const e=document.createElement("div");e.className="dt-toast",e.textContent=t,document.body.append(e),setTimeout(()=>e.remove(),2800)},Za=t=>new Promise(e=>{const n=new FileReader;n.onload=()=>e(String(n.result)),n.readAsDataURL(t)}),to=async t=>{const e=await createImageBitmap(t),n=Math.min(1,Va/Math.max(e.width,e.height));if(n===1&&t.size<=Ja)return e.close(),Za(t);const s=document.createElement("canvas");return s.width=Math.round(e.width*n),s.height=Math.round(e.height*n),s.getContext("2d").drawImage(e,0,0,s.width,s.height),e.close(),s.toDataURL("image/jpeg",.85)},Ue=async(t,e)=>{const n=[];for(const s of t){let a;const o=Object.keys(Dt).find(i=>Dt[i]===s.type||s.name.toLowerCase().endsWith(`.${i}`));if(o){if(s.size>Ga){A(`${s.name} is over 3 MB \u2014 send a link to it instead.`);continue}const i=await new Promise((l,u)=>{const m=new FileReader;m.onload=()=>l(String(m.result).split(",")[1]),m.onerror=u,m.readAsDataURL(s)}).catch(()=>"");i?n.push(`data:${Dt[o]};name=${uo(s.name)||"document"};base64,${i}`):A(`${s.name} could not be read.`);continue}try{a=await to(s)}catch{A("That image could not be read.");continue}if(a.length>rs){A("Screenshot is too large even after shrinking.");continue}n.push(a)}if(n.length){if(!Number(e?.dataset.id)){d&&((d.images??=[]).push(...n),f());return}B.push(...n),f(),ae(".dt-note-reply-input")}},ds=t=>[...t??[]].filter(e=>e.kind==="file"&&(e.type.startsWith("image/")||Object.values(Dt).includes(e.type))).map(e=>e.getAsFile()).filter(Boolean);b.addEventListener("paste",t=>{const e=ds(t.clipboardData?.items);e.length&&(t.preventDefault(),Ue(e,t.target.closest(".dt-note")))}),b.addEventListener("dragover",t=>{t.target.closest(".dt-note")&&(t.preventDefault(),t.target.closest(".dt-note").querySelector(".dt-compose")?.setAttribute("data-drop",""))}),b.addEventListener("dragleave",t=>{t.target.closest(".dt-note")?.querySelector(".dt-compose")?.removeAttribute("data-drop")}),b.addEventListener("drop",t=>{const e=t.target.closest(".dt-note");if(!e)return;t.preventDefault(),e.querySelector(".dt-compose")?.removeAttribute("data-drop");const n=ds(t.dataTransfer?.items);n.length&&Ue(n,e)});const ae=t=>{const e=b.querySelector(t);e?.focus(),e?.setSelectionRange(e.value.length,e.value.length)},cs=()=>{ae(".dt-note-edit-input"),b.querySelector(".dt-msg .dt-compose")?.scrollIntoView({block:"nearest"})},ze=t=>{t.style.overflowY="hidden",t.style.height="auto",t.style.height=`${t.scrollHeight}px`,t.style.overflowY=t.scrollHeight>t.clientHeight?"auto":"hidden"},eo=t=>/(?:^|\s)@([^\s@]*)$/.exec(t.value.slice(0,t.selectionStart??t.value.length)),no=()=>c.client||Zt()?[]:Hs(),so=t=>{t.closest(".dt-compose").querySelector(".dt-mentions")?.remove();const n=eo(t);if(!n)return;const s=n[1].toLowerCase(),a=(c.team??[]).filter(i=>[i.name,i.nickname,i.email].some(l=>l?.toLowerCase().startsWith(s))).slice(0,5),o=no().filter(i=>i.handle.toLowerCase().startsWith(s)||!!s&&"agent".startsWith(s)||!!s&&"claude".startsWith(s)).slice(0,4);!a.length&&!o.length||t.insertAdjacentHTML("afterend",`<div class="dt-mentions" role="listbox" aria-label="Mention someone">${[...a.map(i=>`<button type="button" role="option" data-act="mention" data-handle="${p(po(i))}">${Vt(i.avatar_url,i.name||i.email)}<span class="dt-mention-who"><b>${p(i.name||i.email)}</b>${i.name?`<span>${p(i.email)}</span>`:""}</span></button>`),...o.map(i=>`<button type="button" role="option" data-act="mention" data-handle="${p(i.handle)}">${oa(i.owner)}<span class="dt-mention-who"><b>${p(i.handle)}</b><span>${i.owner?"Hands it to this agent":"The shared queue \u2014 any agent takes it"}</span></span></button>`)].map((i,l)=>i.replace('role="option"',`role="option" aria-selected="${l===0}"`)).join("")}</div>`)},us=t=>{const e=[...(c.team??[]).flatMap(s=>[s.name,s.nickname,s.email]),...Hs().map(s=>s.handle)].filter(s=>!!s).sort((s,a)=>a.length-s.length).map(s=>p(s).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),n=p(t);return e.length?n.replace(new RegExp(`@(?:${e.join("|")})(?![\\p{L}\\p{N}_.-])`,"giu"),s=>`<span class="dt-at">${s}</span>`):n},ps=(t,e)=>{const n=t.selectionStart??t.value.length,s=t.value.slice(0,n).lastIndexOf("@");t.value=`${t.value.slice(0,s)}@${e} ${t.value.slice(n)}`,t.selectionStart=t.selectionEnd=s+e.length+2,t.closest(".dt-compose")?.querySelector(".dt-mentions")?.remove(),t.dispatchEvent(new Event("input",{bubbles:!0})),t.focus()},ao=(t,e)=>{if(!t){d&&(d.category=e),f();return}K(n=>n.map(s=>s.id===t?{...s,category:e}:s),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,category:e})}),"Changing the type")};wo(b,p,St);const ms=(t,e)=>{t?K(n=>n.map(s=>s.id===t?{...s,shared:e||void 0}:s),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,shared:e})}),e?"Sharing with the client":"Keeping it to the team"):d&&(d.shared=e||void 0,rt(),f())};b.addEventListener("change",t=>{const e=t.target.closest(".dt-more-select");if(e){const i=e.value,l=Number(e.dataset.id)||0;e.value="",i==="team"||i==="client"?ms(l,i==="client"):i==="rm"&&confirm("Delete this thread and its replies? This cannot be undone.")?($=null,Oe(l)):i==="discard"&&(d=null,f());return}const n=t.target.closest(".dt-cat-select");if(n){ao(Number(n.dataset.id)||0,n.value);return}const s=t.target.closest(".dt-status-select");if(s){Rn(Number(s.dataset.id),s.value);return}const a=t.target.closest(".dt-for-select");if(!a)return;a.parentElement?.style.setProperty("--cat",kt(a.value));const o=Number(a.dataset.id);if(o){const i=a.value||null;K(l=>l.map(u=>u.id===o?{...u,assignee:i??void 0}:u),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:o,assignee:i})}),"Reassigning");return}if(d){d.assignee=a.value;try{localStorage.setItem("nm-for",a.value)}catch{}rt()}}),b.addEventListener("input",t=>{const e=t.target.closest(".dt-suggest-input");if(e&&d?.suggest){d.suggest.to=e.value,rt(),ze(e);return}const n=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");n&&(so(n),n.classList.contains("dt-note-input")?d&&(d.text=n.value):n.classList.contains("dt-note-edit-input")?T&&(T.text=n.value):q=n.value,rt(),n.closest(".dt-compose")?.querySelector(".dt-send")?.classList.toggle("is-ready",n.value.trim()!==""),ze(n))}),b.addEventListener("keydown",t=>{const e=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");if(!e)return;const n=e.closest(".dt-compose")?.querySelector(".dt-mentions button");if(n&&(t.key==="Enter"||t.key==="Tab")&&!t.isComposing){t.preventDefault(),ps(e,n.dataset.handle);return}if(n&&t.key==="Escape"){t.stopPropagation(),n.parentElement.remove();return}t.key!=="Enter"||t.shiftKey||t.isComposing||(t.preventDefault(),e.closest(".dt-compose")?.querySelector(".dt-send")?.click())}),b.addEventListener("click",async t=>{const e=t.target.closest("button");if(!e)return;const n=e.dataset.act,s=Number(e.dataset.id);if(n==="share"){ms(s,e.dataset.v==="1");return}if(n==="prio"){const a=e.dataset.v||null;s?K(o=>o.map(i=>i.id===s?{...i,priority:a??void 0}:i),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,priority:a})}),"Setting the priority"):d&&(d.priority=a??void 0,rt(),f());return}if(n==="mention"){const a=e.closest(".dt-compose")?.querySelector("textarea");a&&ps(a,e.dataset.handle);return}if(!n){if($=$===s?null:s,$!=null&&e.dataset.off){const a=y.find(i=>i.id===s);(a&&F(a))?.scrollIntoView({block:"nearest",inline:"center",behavior:"smooth"})}V(),f();return}if(n==="record"){ka(e.closest(".dt-note"));return}if(n==="speak"){Ca(e.closest(".dt-note"),e);return}if(n==="voice-write"){Oa(e);return}if(n==="voice"||n==="voice-seek"){$a(e,n==="voice-seek"?t:null);return}if(n==="attach"){const a=Object.assign(document.createElement("input"),{type:"file",accept:`image/*,.pdf,.doc,.docx,${Object.values(Dt)}`,multiple:!0}),o=e.closest(".dt-note");a.addEventListener("change",()=>{a.files?.length&&Ue([...a.files],o)}),a.click();return}if(n==="unshot"){s?T&&T.drop.push(e.dataset.img):(e.closest("[data-draft]")?d?.images??[]:B).splice(Number(e.dataset.i),1),f(),T&&cs();return}if(n==="edit"){const a=y.find(l=>l.id===s),o=e.dataset.at||null,i=o?a?.replies?.find(l=>l.at===o)?.text:a?.text;if(i===void 0)return;T={id:s,at:o,text:i,drop:[]},f(),cs();return}if(n==="edit-cancel"){T=null,f();return}if(n==="translate"){qa(s,e.dataset.at);return}if(n==="unsay"){const a=e.dataset.at;if(!confirm("Delete this reply?"))return;await K(o=>o.map(i=>i.id!==s?i:{...i,replies:(i.replies??[]).map(l=>l.at===a?{...l,text:"",deleted:!0}:l)}),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,unsay:a})}),"Deleting the reply");return}if(n==="edit-save"){const a=T;if(!a)return;const o=a.text.trim();if(!o){b.querySelector(".dt-note-edit-input")?.focus();return}T=null;const i=l=>a.drop.includes(l.split("/").pop());await K(l=>l.map(u=>u.id!==a.id?u:{...u,...a.at==null?{text:o}:{replies:(u.replies??[]).map(m=>m.at===a.at?{...m,text:o}:m)},images:(u.images??[]).filter(m=>!i(m))}),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:a.id,edit:{at:a.at,text:o},...a.drop.length?{removeImage:a.drop}:{}})}).then(l=>(l.ok||(T=a),l)),"Saving the edit");return}if(n==="cancel"){V(),f();return}if(n==="twin"){V(),$=Number(e.dataset.id),f();return}if(n==="discard"){d=null,f();return}if(n==="draft-open"){Ie(Number(e.dataset.i));return}if(n==="close"){$=null,f();return}if(n==="suggest"&&d){const a=Hn(F(d));d.suggest={from:a,to:a},f();const o=b.querySelector(".dt-suggest-input");o?.focus(),o?.select();return}if(n==="unsuggest"&&d){d.suggest=null,f();return}if(n==="save"){if(!d)return;const a=d.suggest&&d.suggest.to.trim()!==d.suggest.from?{from:d.suggest.from,to:d.suggest.to.trim()}:null,o=b.querySelector(".dt-note-input").value.trim()||(a?"Change the text":"")||(d.images?.some(Ae)?Kn:"");if(!o){b.querySelector(".dt-note-input")?.focus();return}const i=d,l=c.client?null:Ns(o,Lt()),u=ls.get(i)??We(F(i)),m={...i,route:z,text:o,suggest:a,assignee:c.client?i.assignee||c.lead||void 0:l??(i.assignee||void 0),shared:c.client?!0:i.shared===!0,stage:c.client?"new":l?"approved":i.stage??(j(i.assignee)?"approved":"new"),breakpoint:Te(),browser:Ys(),device:E?gs:"",viewport:{w:innerWidth,h:innerHeight},logs:bo(),host:location.host},r={...i,id:-Date.now(),text:o,route:z,status:"open",note:"",doneBy:null,breakpoint:m.breakpoint,replies:[],images:[],createdAt:new Date().toISOString(),...a?{suggest:a}:{},by:c.me?.email,byName:c.me?.name};y=[...y,r],d=null,f();const h=await u,g=await L("comments",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...m,...h?{before:h}:{}})});if(!g.ok){y=y.filter(M=>M!==r),d=i,f(),A(`Comment was not saved (${g.status}).`);return}const w=Ct([await g.json().catch(()=>null)])[0];y=y.map(M=>M===r&&w?w:M),f(),oe();return}if(n==="reply"){const a=b.querySelector(".dt-note-reply-input"),o=a.value.trim()||(B.some(Ae)?Kn:"");if(!o){a.focus();return}const i=B;q="",B=[];const l=y,u=c.client?null:Ns(o,Lt()),m=y.find(w=>w.id===s),r=u&&m&&(u!==m.assignee||U(m)!=="approved"||m.status==="done")?{assignee:u,stage:"approved",...m.status==="done"?{status:"open",doneBy:null}:{}}:{};y=y.map(w=>w.id===s?{...w,...r,replies:[...w.replies??[],{author:"you",text:o,at:new Date().toISOString(),by:c.me?.email}]}:w),f();const h=await L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,reply:o,images:i,...r})});if(!h.ok){y=l,q=o,B=i,f(),A(`Reply was not sent (${h.status}).`);return}const g=Ct([await h.json().catch(()=>null)])[0];g&&(y=y.map(w=>w.id===g.id?g:w),f()),oe();return}if(n==="hand"){na(s,e.dataset.v);return}if(n==="sendback"){await ht(s,!1),ae(".dt-note-reply-input");return}if(n==="accept"){Rn(s,"accepted");return}e.classList.contains("dt-step-act")||($=null),n==="rm"?await Oe(s):await ht(s,n==="done")});let gs="";const D=t=>{it.hidden||_t.contentWindow?.postMessage({dt:!0,...t},location.origin)},oo=()=>({notes:H,grid:!Pt.hidden,inspect:Y,resolved:J,...hs.look()});addEventListener("message",t=>{if(t.origin!==location.origin||!t.data?.dt)return;const e=t.data;if(!E&&t.source===_t.contentWindow){if(e.key){ws(e.key[0],e.key[1])?.run();return}if(e.closeMenus){Tt();return}if(e.drafts){Re=e.drafts,Nt(lt());return}}if(E&&typeof e.openDraft=="number"){Ie(e.openDraft);return}if(E&&typeof e.dropDraft=="number"){Xn(e.dropDraft);return}if(E&&typeof e.device=="string"&&(gs=e.device),E&&e.scrollbar&&document.documentElement.classList.toggle("dt-sb-classic",e.scrollbar==="classic"),e.hello&&t.source===_t.contentWindow){D(oo());return}typeof e.notes=="boolean"&&e.notes!==H&&nt(e.notes,!1),typeof e.open=="number"&&De(e.open),typeof e.grid=="boolean"&&e.grid===Pt.hidden&&pe(e.grid),typeof e.inspect=="string"&&e.inspect!==Y&&jt(e.inspect),typeof e.resolved=="boolean"&&e.resolved!==J&&Fe(e.resolved),e.reload&&(vt(),ne())});const oe=async()=>{await vt(),ne(),D({reload:!0}),E&&parent.postMessage({dt:!0,reload:!0},location.origin)},nt=(t,e=!0)=>{if(H=t,cn.setAttribute("aria-pressed",String(t)),t?!E&&x.hidden&&localStorage.getItem("dt-history")!=="0"&&(x.hidden=!1,Ft.setAttribute("aria-pressed","true")):(x.hidden=!0,Ft.setAttribute("aria-pressed","false")),O(gn,t?"1":"0"),D({notes:t}),E&&e&&parent.postMessage({dt:!0,notes:t},location.origin),b.hidden=!t||!it.hidden,document.documentElement.classList.toggle("dt-noting",t),t){jt(""),document.addEventListener("click",is,!0);for(const n of as)document.addEventListener(n,os,!0);document.addEventListener("keydown",ss),document.addEventListener("mousemove",ns),addEventListener("scroll",et,!0),addEventListener("resize",et),Qn.observe(document.body,{childList:!0,subtree:!0,characterData:!0}),Zn.observe(document.body),vt()}else{V(),$=null,document.removeEventListener("click",is,!0);for(const n of as)document.removeEventListener(n,os,!0);document.removeEventListener("keydown",ss),document.removeEventListener("mousemove",ns),ot.hidden=!0,removeEventListener("scroll",et,!0),removeEventListener("resize",et),Qn.disconnect(),Zn.disconnect(),b.innerHTML=""}},{pickBp:fs,...hs}=Eo({cfg:c,inFrame:E,persist:O,frame:it,frameEl:_t,devicesMenu:ve,bpBtns:be,notesOverlay:b,WIDE:ce,bpOf:en,currentBp:Te,deviceById:Bs,notesOn:()=>H,filter:()=>Ee,filterTo:t=>{Ee=t},dropFrameDrafts:()=>{Re=[]},putAway:()=>{$=null,V()},tellFrame:D,syncBpButtons:hn,render:()=>f(),reread:()=>{H?vt():f()}}),bs="dt-studio",ys=t=>{ye.setAttribute("aria-pressed",String(t)),document.documentElement.classList.toggle("dt-no-studio",!t),O(bs,t?"1":"0")};ye.addEventListener("click",()=>ys(ye.getAttribute("aria-pressed")!=="true")),ys(localStorage.getItem(bs)!=="0"),cn.addEventListener("click",()=>nt(!H));const $t=document.querySelector(".devtools"),Ot=document.querySelector(".dt-tab"),vs=t=>{$t.toggleAttribute("data-collapsed",t),Ot.toggleAttribute("data-collapsed",t),Ot.setAttribute("aria-expanded",String(!t)),Ot.setAttribute("aria-label",t?"Show the bar":"Hide the bar");for(const e of $t.querySelectorAll(".dt-group"))e.inert=t;t&&Tt(),O("dt-collapsed",t?"1":"0")};Ot.addEventListener("click",()=>vs(!$t.hasAttribute("data-collapsed")));const Ye=document.querySelector(".dt-keys"),W=t=>()=>$t.querySelector(t)?.click(),$s=t=>()=>{const e=[...document.querySelectorAll(".dt-pages a")];e[e.findIndex(n=>n.hasAttribute("aria-current"))+t]?.click()},ie=[{group:"Comments",code:"KeyC",hint:"C",label:"Comment mode",el:".dt-notes-btn",run:W(".dt-notes-btn")},{group:"Comments",code:"KeyC",shift:!0,hint:"\u21E7C",label:"Comments panel",el:".dt-history-btn",run:W(".dt-history-btn")},{group:"Comments",code:"KeyR",hint:"R",label:"Show resolved",el:".dt-resolved-btn",run:W(".dt-resolved-btn")},{group:"Inspect",code:"KeyG",hint:"G",label:"Grid",el:".dt-grid-btn",run:W(".dt-grid-btn")},{group:"Inspect",code:"KeyP",hint:"P",label:"Spacing",el:".dt-pad-btn",run:W(".dt-pad-btn")},{group:"Inspect",code:"KeyS",hint:"S",label:"Size",el:".dt-size-btn",run:W(".dt-size-btn")},{group:"Inspect",code:"KeyT",hint:"T",label:"Typography",el:".dt-type-btn",run:W(".dt-type-btn")},{group:"Inspect",code:"KeyO",hint:"O",label:"Color",el:".dt-color-btn",run:W(".dt-color-btn")},{group:"Inspect",code:"KeyB",hint:"B",label:"Border & radius",el:".dt-border-btn",run:W(".dt-border-btn")},...c.sanity?[{group:"Inspect",code:"KeyE",hint:"E",label:"Sanity overlay",el:".dt-studio-btn",run:W(".dt-studio-btn")}]:[],...be.slice(0,9).map((t,e)=>({group:"Breakpoints",code:`Digit${e+1}`,hint:String(e+1),label:t.dataset.tip??t.title,el:`.dt-bp[data-bp="${t.dataset.bp}"]`,run:()=>t.click()})),{group:"View",code:"KeyD",hint:"D",label:"Devices",run:()=>{ve.open=!ve.open}},{group:"View",code:"BracketLeft",hint:"[",label:"Previous page",run:$s(-1)},{group:"View",code:"BracketRight",hint:"]",label:"Next page",run:$s(1)},{group:"View",code:"Backslash",hint:"\\",label:"Hide the bar",run:()=>Ot.click()},{group:"View",code:"Slash",shift:!0,hint:"?",label:"This list",el:".dt-keys summary",run:()=>{Ye.open=!Ye.open}}].filter(t=>!c.client||t.group!=="Inspect"),ws=(t,e)=>ie.find(n=>n.code===t&&!n.shift==!e),io=t=>t instanceof HTMLElement&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)||!!t.closest('[role="menu"], [role="listbox"], [role="dialog"][aria-modal="true"], [role="combobox"]'));if(c.shortcuts){for(const e of ie){const n=e.el&&$t.querySelector(e.el);n&&(n.dataset.tip=`${n.dataset.tip??e.label} \xB7 ${e.hint}`,n.setAttribute("aria-keyshortcuts",e.hint.startsWith("\u21E7")?`Shift+${e.hint.slice(1)}`:e.hint))}const t=(e,n)=>`<div class="dt-key-row"><span>${p(e)}</span><kbd>${p(n)}</kbd></div>`;if(Ye.querySelector(".dt-keys-menu").innerHTML='<p class="dt-menu-note">One key, no modifier, in any keyboard layout. Not while you type.</p>'+[...new Set(ie.map(e=>e.group))].map(e=>`<p class="dt-devices-group">${e}</p>`+ie.filter(n=>n.group===e).map(n=>t(n.label,n.hint)).join("")).join("")+'<p class="dt-devices-group">In a comment</p>'+t("Send","Enter")+t("New line","\u21E7Enter")+t("Close, cancel, back out","Esc"),document.addEventListener("keydown",e=>{if(e.repeat||e.isComposing||e.metaKey||e.ctrlKey||e.altKey||e.defaultPrevented||io(e.target))return;const n=ws(e.code,e.shiftKey);n&&(e.preventDefault(),E?parent.postMessage({dt:!0,key:[e.code,e.shiftKey]},location.origin):n.run())}),E){const e=()=>parent.postMessage({dt:!0,closeMenus:!0},location.origin);document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",n=>{n.key==="Escape"&&e()})}}if(!E){vs(localStorage.getItem("dt-collapsed")==="1"),requestAnimationFrame(()=>requestAnimationFrame(()=>$t.setAttribute("data-ready",""))),hs.restore(),pe(localStorage.getItem(sn)==="1");const t=localStorage.getItem(ln);t&&t in fe&&jt(t),nt(localStorage.getItem(gn)==="1")}const Es=()=>{try{const t=JSON.parse(localStorage.getItem(gt)||"null");N=(t?.parked??[]).filter(e=>Kt(e)),t?.draft&&document.querySelector(t.draft.selector)?(d=t.draft,!H&&!E&&nt(!0)):Kt(t?.draft)&&N.push(t.draft),t?.reply?.text&&(q=t.reply.text,Mt=$=t.reply.for??null),(d||N.length||q)&&f()}catch{localStorage.removeItem(gt)}};Es();const Ss=()=>setTimeout(()=>{const t=ue(location.pathname);t!==z&&(clearTimeout(Wt),Se(),z=t,gt=fn(),d=null,N=[],q="",Mt=null,$=null,T=null,y=[],on(),Es(),vt())});for(const t of["pushState","replaceState"]){const e=window.history[t];window.history[t]=function(...n){e.apply(this,n),Ss()}}addEventListener("popstate",Ss),H||vt(),ne().then(Pe.resume),document.addEventListener("visibilitychange",()=>{document.hidden||Rt()}),addEventListener("focus",Rt),addEventListener("notemend:changed",()=>{E||Rt()});let ro=0;E||setInterval(()=>{(!fo.live||++ro%6===0)&&Rt()},2e4),E&&parent.postMessage({dt:!0,hello:!0},location.origin)}export{Ko as run};