notemend 0.1.13 → 0.1.15

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,121 +1,73 @@
1
- import{categoryOf as $e}from"../store/categories.mjs";import{stateOf as q,STATE_LABEL as ia}from"../store/status.mjs";import{agentLabel as ra,agentName as Ds,agentOwner as Nt,handleOf as la,held as da,stageOf as we,threadOf as ca,toAgent as K,workingOn as Os}from"../store/thread.mjs";import{api as C,canvasCopy as ua,host as ma,imageUrl as pa}from"./api";import{DEVTOOLS_DEVICES as Ps}from"../devtools-devices.mjs";import{drawDevice as ga,pageTints as ha,inkFor as js}from"./devices";import{recentLogs as fa}from"./logs";import{inspectors as ba}from"./inspect";import{anchors as ya,clean as wt}from"./anchor";import{bars as va,fieldMenus as $a}from"./field-menu";function Na(p){const R=p.breakpoints,hn=p.categories,Ee=(R.find(t=>!Number.isFinite(t.max))??R[0]).id,Ct=t=>R.find(e=>t>=e.min&&t<=e.max)?.id??Ee,ot=t=>t.breakpoint||Ee,Xt=t=>p.devices.find(e=>e.id===t),w=ua,J=(t,e)=>{w||localStorage.setItem(t,e)},Se=t=>t.replace(/\/+$/,"")||"/";let _=Se(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 fn=document.querySelector(".dt-grid-btn"),Zt=document.querySelector(".dt-grid-overlay"),bn="dt-grid",Le=t=>{Zt.hidden=!t,fn.setAttribute("aria-pressed",String(t)),J(bn,t?"1":"0"),P({grid:t})};fn.addEventListener("click",()=>Le(Zt.hidden===!0));const yn=document.querySelector(".dt-pages-name"),vn=()=>{let t=null;for(const s of document.querySelectorAll(".dt-pages a"))Se(new URL(s.href).pathname)===_?(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();yn.textContent=n||e||yn.textContent};vn();const $n=[...document.querySelectorAll(".devtools details")];let Te=!1;const Bt=()=>{const t=$n.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=$n.some(e=>e.open&&!e.contains(t.target))&&Bt().length>0},!0),addEventListener("blur",Bt);const Et=document.querySelector(".dt-pad-overlay"),wn="dt-inspect",Fs=[".devtools",".dt-pad-overlay",".dt-grid-overlay",".dt-frame",".dt-history",".dt-review",".dt-field-menu",...p.ignore].join(", "),Me=[".devtools",".dt-notes-overlay",".dt-history",".dt-frame",".dt-review",".dt-field-menu",'[aria-modal="true"]',...p.ignore].join(", "),xe={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 at="",ke=0;const{spacer:Ks,drawPads:Ws,drawSize:_s,drawType:Us,drawColor:zs,drawBorder:Vs}=ba(Et),En=t=>{ke||(ke=requestAnimationFrame(()=>{ke=0,Et.hidden=!0;let e=document.elementFromPoint(t.clientX,t.clientY);if(Et.hidden=!1,!e||e.closest(Fs)){Et.innerHTML="";return}t.altKey&&e.parentElement&&e.parentElement!==document.body&&(e=e.parentElement),at==="sizes"?_s(e):at==="type"?Us(e):at==="color"?zs(e):at==="border"?Vs(e):Ws(t.altKey?e:Ks(e))}))},Qt=t=>{at=t;for(const[e,n]of Object.entries(xe))n.setAttribute("aria-pressed",String(e===t));J(wn,t),P({inspect:t}),Et.hidden=!t,Et.innerHTML="",t?document.addEventListener("mousemove",En):document.removeEventListener("mousemove",En)};for(const[t,e]of Object.entries(xe))e.addEventListener("click",()=>{t!==at&&mt(!1),Qt(at===t?"":t)});const Sn=document.querySelector(".dt-notes-btn"),He=[...document.querySelectorAll(".dt-bp")],te=document.querySelector(".dt-history-btn"),W=document.querySelector(".dt-history"),Ae=document.querySelector(".dt-studio-btn"),T=document.querySelector(".dt-device"),Ln=document.querySelector(".dt-shell"),qt=document.querySelector('.dt-chrome[data-at="top"]'),ee=document.querySelector('.dt-chrome[data-at="bottom"]'),Rt=document.querySelector(".dt-ruler"),G=document.querySelector(".dt-devices"),ht=document.querySelector(".dt-notes-hi"),Ys=ht.querySelector(".dt-hi-box"),Tn=ht.querySelector(".dt-hi-tag"),Js=[...document.querySelectorAll(".dt-frame-handle")],Mn=document.querySelector(".dt-frame-size"),Ne=document.querySelector(".dt-frame-rotate"),It=document.querySelector(".dt-frame-bars"),B=document.querySelector(".dt-frame"),M=B.querySelector("iframe"),Ce=document.querySelector(".dt-notes-count"),f=document.querySelector(".dt-notes-overlay"),xn=".devtools, .dt-tab, .dt-notes-overlay, .dt-history, .dt-frame, .dt-review";for(const t of document.querySelectorAll(xn))for(const e of["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend","click","focusin","focusout"])t.addEventListener(e,n=>n.stopPropagation());const kn="dt-notes";let b=[],A=!1,v=null,c=null,Be=0,U="",z=[],x=null,I=[];const ne=(t=c)=>!!(t&&(t.text?.trim()||t.images?.length)),V=()=>{c&&ne()&&I.push(c),c=null};let Dt=null,it=null;const Hn=()=>`dt-draft:${_}${w?":canvas":""}`;let St=Hn(),se=0;const qe=()=>{if(!c&&!I.length&&!U){localStorage.removeItem(St);return}const t={draft:c,parked:I,reply:U?{for:Dt,text:U}:null};try{localStorage.setItem(St,JSON.stringify(t))}catch{const e=n=>({...n,images:void 0});try{localStorage.setItem(St,JSON.stringify({...t,draft:c&&e(c),parked:I.map(e)}))}catch{}}},ft=()=>{clearTimeout(se),se=setTimeout(qe,200)};addEventListener("pagehide",()=>{clearTimeout(se),qe()});let X=localStorage.getItem("dt-resolved")!=="0";const Gs=[[/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"]],Zs=()=>{const t=navigator.userAgent,e=a=>a.find(([l])=>l.test(t)),n=e(Gs),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 ")},dt=()=>Ct(innerWidth),oe=()=>it??dt(),Ot=()=>{const t=oe();for(const e of He)e.setAttribute("aria-pressed",String(e.dataset.bp===t))},{cssPath:Qs,poolOf:to,contextOf:eo,resolveEl:Y,anchorOf:Z}=ya(),An=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 ae=[];const Re=t=>{for(const e of ae)e.play();ae=[];for(let e=t;e&&e!==document.body;e=e.parentElement)for(const n of e.getAnimations())n.playState==="running"&&(n.pause(),ae.push(n))},Nn=()=>{if(c)return Y(c);const t=v!=null?b.find(n=>n.id===v):null;if(!t)return null;const e=Z(t);return e&&!e.off?Y(t):null},Cn=t=>t?new Date(t).toLocaleString(void 0,{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}):"",Pt='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M4 6h12M8 6V4.2h4V6M6.6 6l.55 9.8h5.7L13.4 6"/></svg>',jt='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M4.8 10.4 8.2 13.8l7-7.6" stroke-linejoin="round"/></svg>',Ie='<svg viewBox="0 0 20 20" width="12" height="12" aria-hidden="true"><path d="M12.6 4.4l3 3-8.4 8.4H4.2v-3z" stroke-linejoin="round"/></svg>',ie='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M5.4 5.4l9.2 9.2M14.6 5.4l-9.2 9.2"/></svg>',no='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M12 5l-5 5 5 5" stroke-linejoin="round"/></svg>',so='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M8 5l5 5-5 5" stroke-linejoin="round"/></svg>',oo='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M4.5 8.5h7.5a3.5 3.5 0 0 1 0 7H8.5M7.5 5.5l-3 3 3 3" stroke-linejoin="round"/></svg>',Lt=t=>`<svg viewBox="0 0 24 24" width="${t}" height="${t}" aria-hidden="true" class="dt-claude"><path d="m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z"/></svg>`,Ft=()=>p.me?`agent:${p.me.email}`:"claude",ao=()=>(p.team??[]).filter(t=>t.email!==p.me?.email),De=()=>[...p.me?(p.team??[]).filter(t=>t.email===p.me.email):[],...ao()],Bn=(t,e,n=!1)=>{const s=K(t)?"agent":t?"person":"";return`<span class="dt-hand" role="radiogroup" aria-label="Who takes it">${[...De().length||s==="person"?[["person",_n,"A person"]]:[],["agent",Lt(12),n?"Waits for the studio to approve it":"An agent \u2014 approves it for AI"]].map(([a,l,u])=>a===s?`<span class="dt-hand-stop dt-hand-stop--${a} is-on" role="radio" aria-checked="true" title="${u}">${lo(t,e,a)}</span>`:`<button type="button" class="dt-hand-stop dt-hand-stop--${a}" role="radio" aria-checked="false" data-act="hand" data-v="${a}"${e?` data-id="${e}"`:""} title="${u}"${a==="agent"&&n?" disabled":""}>${l}</button>`).join("")}</span>`},io=(t,e)=>{const n=re(),s=e==="agent"?K(n)?n:Ft():e==="person"?n&&!K(n)&&De().some(l=>l.email===n)?n:De()[0]?.email??"":"";if(!t){if(!c)return;c.assignee=s,c.stage=K(s)?"approved":c.stage==="review"?"review":"new";try{localStorage.setItem("nm-for",s)}catch{}ft(),h();return}const o=b.find(l=>l.id===t),a=K(s)?"approved":o&&we(o)==="review"?"review":"new";rt(l=>l.map(u=>u.id===t?{...u,assignee:s||void 0,stage:a}:u),()=>C("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,assignee:s||null,stage:a})}),K(s)?"Approving it for the agent":"Reassigning")},re=()=>{try{return localStorage.getItem("nm-for")??Ft()}catch{return Ft()}},Kt=t=>K(t)?"#d97757":t?"#0d99ff":"#717171",Oe=t=>t===p.me?.email?"you":p.team?.find(e=>e.email===t)?.name||t.split("@")[0],le=t=>t?p.team?.find(e=>e.email===t):void 0,qn=t=>g((wt(t??"")[0]??"?").toUpperCase()),Rn=(t,e,n="dt-face")=>t?`<img class="${n}" src="${g(t)}" alt="">`:`<b class="${n}" aria-hidden="true">${qn(e)}</b>`,ro=t=>{const e=le(t.by);return e||t.byName?Rn(e?.avatar_url,e?.name||t.byName||t.by):""},In=t=>{const e=le(t);return e?` data-face="${g(e.avatar_url??"")}" data-initial="${qn(e.name||e.email)}"`:""},ct=(t,e)=>ra(t,e,Oe),Dn=t=>{const e=le(t)?.avatar_url;return e?`;--face:url(&quot;${g(e)}&quot;)`:""},On=t=>le(t)?.avatar_url?" data-face":"",lo=(t,e,n)=>{const s=(r,m,E=!1)=>`<option value="${g(r)}" data-c="${Kt(r)}"${In(Nt(r)??(K(r)?null:r))}${Nt(r)?" data-agent":""}${E?" data-sep":""}${t===r?" selected":""}>${g(m)}</option>`,o=(p.team??[]).filter(r=>r.email!==p.me?.email),a=n!=="person",l=n!=="agent",u=o.filter(r=>!p.studio||p.studio.includes(r.email)),i=Nt(t)&&t!==Ft()&&!u.some(r=>`agent:${r.email}`===t)?s(t,`${Oe(Nt(t))}'s agent`):"";return`<label class="dt-field" title="Who it is for"><span class="dt-field-box"${On(Nt(t)??(K(t)?null:t))} style="--cat:${Kt(t)}${Dn(Nt(t)??(K(t)?null:t))}"><select class="dt-for-select"${e?` data-id="${e}"`:""} aria-label="Who this is for">
2
- ${a&&p.me?s(Ft(),"My agent"):""}
3
- ${a?u.map(r=>s(`agent:${r.email}`,`${(r.name||r.email).split(" ")[0]}'s agent`)).join("")+i:""}
4
- ${a?s("claude",p.me?"Any agent \u2014 the shared queue":"AI agent",!!p.me):""}
5
- ${n?"":s("","Nobody")}
6
- ${l&&p.me?s(p.me.email,`${p.me.name||p.me.email} (you)`):""}
7
- ${l?o.map(r=>s(r.email,r.name||r.email)).join(""):""}${l&&t&&!K(t)&&t!==p.me?.email&&!o.some(r=>r.email===t)?s(t,Oe(t)):""}
8
- </select></span></label>`},Pn=t=>{const e=wt(t?.textContent).replace(/\s+/g," ");return e&&e.length<=2e3?e:""},co=t=>`<div class="dt-suggest dt-suggest--read"><del>${g(t.from)}</del><ins>${g(t.to)}</ins></div>`,jn=t=>wt(t)?`<span class="dt-note-info" data-tip="${g(wt(t))}"
9
- ><svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="10" cy="10" r="7.4"/><path d="M10 9.2v4.4M10 6.4v.6"/></svg></span>`:"",Fn=(t,e)=>`<label class="dt-field" title="Type"><span class="dt-field-box" style="--cat:${$e(t).color}"><select class="dt-cat-select"${e?` data-id="${e}"`:""} aria-label="Type">${hn.map(n=>`<option value="${n.id}" data-c="${n.color}"${n.id===t?" selected":""}>${n.label}</option>`).join("")}</select></span></label>`,Kn=[["open","Open","#0d99ff"],["progress","In progress","#f5a623"],["review","Needs review","#8e4ec6"],["done","Resolved","#30a46c"]],uo=t=>t.status==="done"?"done":Os(t)||we(t)==="progress"?"progress":we(t)==="review"?"review":"open",mo=t=>{const e=uo(t);return`<label class="dt-field" title="Status"><span class="dt-field-box" style="--cat:${Kn.find(n=>n[0]===e)[2]}"><select class="dt-status-select" data-id="${t.id}" aria-label="Status">${Kn.map(([n,s,o])=>`<option value="${n}" data-c="${o}"${n===e?" selected":""}>${s}</option>`).join("")}</select></span></label>`},po=(t,e)=>{const n=b.find(a=>a.id===t);if(!n)return;if(e==="done"){Tt(t,!0);return}const s=e==="open"?K(n.assignee)?"approved":"new":e,o=n.status==="done"?{status:"open",doneBy:null}:{};rt(a=>a.map(l=>l.id===t?{...l,...o,stage:s}:l),()=>C("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,...o,stage:s})}),"Setting the status")},de=[["low","Low","#30a46c",1],["normal","Mid","#f5c451",2],["high","High","#ff5a00",3],["urgent","Urgent","#e5484d",4]],Wn=(t,e)=>{const n=Math.max(0,de.findIndex(u=>u[0]===t)),[,s,o,a]=de[n],l=de[(n+1)%de.length];return`<button type="button" class="dt-prio" style="--cat:${o}" data-act="prio" data-v="${l[0]}"${e?` data-id="${e}"`:""} title="Priority: ${s} \u2014 click for ${l[1]}" aria-label="Priority ${s}">${va(a,o)}<span>${s}</span></button>`},_n='<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>',go='<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>',Un=(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?_n:go}</button>`,ho=()=>(p.team??[]).filter(t=>!p.studio||p.studio.includes(t.email)),fo=t=>{const e=t||p.lead||"",n=ho();return n.length?`<label class="dt-field" title="Who it is for"><span class="dt-field-box"${On(e)} style="--cat:${Kt(e||"x@x")}${Dn(e)}"><select class="dt-for-select" aria-label="Who this is for">
11
- ${n.map(s=>`<option value="${g(s.email)}" data-c="${Kt(s.email)}"${In(s.email)}${e===s.email?" selected":""}>${g(s.name||s.email)}</option>`).join("")}
12
- </select></span></label>`:""},zn='<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>',bo=!1,yo=!1,Vn='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M3 1.8v8.4L10 6z"/></svg>',vo='<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>',$o=t=>`${Math.floor(t/60)}:${String(Math.floor(t%60)).padStart(2,"0")}`,wo=(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 u=n.querySelector(".dt-voice-track i"),i=n.querySelector(".dt-voice-time"),r=()=>Number.isFinite(s.duration)?s.duration:0;s.addEventListener("timeupdate",()=>{u.style.width=`${r()?Math.min(100,s.currentTime/r()*100):0}%`,i.textContent=$o(s.currentTime)}),s.addEventListener("play",()=>{o.innerHTML=vo,o.setAttribute("aria-label","Pause"),n.classList.add("is-playing")}),s.addEventListener("pause",()=>{o.innerHTML=Vn,o.setAttribute("aria-label","Play the voice note"),n.classList.remove("is-playing")}),s.addEventListener("ended",()=>{s.currentTime=0})}const a=()=>{if(e){const u=n.querySelector(".dt-voice-track").getBoundingClientRect();Number.isFinite(s.duration)&&(s.currentTime=Math.max(0,Math.min(1,(e.clientX-u.left)/u.width))*s.duration);return}if(!s.paused){s.pause();return}f.querySelectorAll(".dt-voice audio").forEach(u=>{u!==s&&u.pause()}),s.play().catch(()=>{})};if(Number.isFinite(s.duration)||s.readyState<1){s.readyState<1?s.addEventListener("loadedmetadata",()=>Number.isFinite(s.duration)?a():l(),{once:!0}):a();return}l();function l(){s.addEventListener("timeupdate",()=>{s.currentTime=0,a()},{once:!0}),s.currentTime=1e9}},Pe=t=>t.startsWith("data:audio/")||/(^|\/)voice-[^/?]*\.(webm|m4a)(\?|$)/i.test(t),Yn=t=>t.startsWith("data:video/")||/\.webm(\?|$)/i.test(t),Jn=new Map,Eo=t=>{if(!t.startsWith("data:"))return t;let e=Jn.get(t);if(!e){const[n,s]=t.split(",",2);e=URL.createObjectURL(new Blob([Uint8Array.from(atob(s),o=>o.charCodeAt(0))],{type:n.slice(5).split(";")[0]})),Jn.set(t,e)}return e},So=(t,e)=>`<span class="dt-voice"><button type="button" class="dt-voice-play" data-act="voice" aria-label="Play the voice note">${Vn}</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="${Eo(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">${zn}</button>`}</span>`,Gn=(t,e,n=t)=>Pe(n)?So(t,e):`<span class="dt-shot${Yn(n)?" dt-shot--video":""}">${Yn(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">${zn}</button>`}</span>`,Xn=(t=[],e)=>t.length?`<div class="dt-note-shots">${t.map(n=>{const s=n.split("/").pop(),o=pa(s);return Gn(o,e===void 0?void 0:`data-id="${e}" data-img="${g(s)}"`,s)}).join("")}</div>`:"",Zn=(t=[])=>t.length?`<div class="dt-note-shots">${t.map((e,n)=>Gn(e,`data-i="${n}"`)).join("")}</div>`:"",Lo='<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>',To='<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>',Mo=!!navigator.mediaDevices?.getDisplayMedia&&typeof MediaRecorder<"u";let bt=null;const xo=async t=>{if(bt){bt.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(r=>MediaRecorder.isTypeSupported(r));if(!o){for(const r of e.getTracks())r.stop();O("This browser cannot record WebM video.");return}const a=new MediaRecorder(s,{mimeType:o,videoBitsPerSecond:6e5,audioBitsPerSecond:32e3}),l=[],u=!!Number(t?.dataset.id);a.ondataavailable=r=>{r.data.size&&l.push(r.data)};const i=setTimeout(()=>{a.state!=="inactive"&&a.stop()},3e4);a.onstop=async()=>{clearTimeout(i);for(const E of[...e.getTracks(),...n?.getTracks()??[]])E.stop();bt=null;const r=new Blob(l,{type:"video/webm"});if(r.size>32e5){O("That recording is too big to send \u2014 keep it shorter."),h();return}const m=await new Promise(E=>{const d=new FileReader;d.onload=()=>E(String(d.result)),d.readAsDataURL(r)});u?z.push(m):c&&(c.images??=[]).push(m),h()},e.getVideoTracks()[0]?.addEventListener("ended",()=>{a.state!=="inactive"&&a.stop()}),bt=a,a.start(1e3),h()},ko='<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>',Ho='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="m5 10.5 3.2 3L15 6.5"/></svg>',Ao=90,je=32,No=()=>!!p.voice&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<"u";let ce=!1;const Co=async(t,e)=>{if(ce||!t)return;const n=Number(t.dataset.id)||0;ce=!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(y){ce=!1,e.classList.remove("is-asking");const F=y?.name;O(F==="NotAllowedError"?"The microphone is blocked for this site \u2014 allow it from the icon left of the address, then try again.":F==="NotFoundError"?"No microphone found \u2014 plug one in or pick it in the system settings.":F==="NotReadableError"?"The microphone is busy in another app \u2014 close it there and try again.":`The microphone did not start: ${y?.message||F||"unknown error"}`);return}e.classList.remove("is-asking");const o=()=>f.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">${Pt}</button><span class="dt-rec-time"><i></i><b>0:00</b></span><span class="dt-rec-wave">${"<i></i>".repeat(je)}</span><button type="button" class="dt-rec-done" title="Done \u2014 write it out" aria-label="Done">${Ho}</button>`;const l=a.querySelector("b"),u=[...a.querySelectorAll(".dt-rec-wave i")],i=new AudioContext,r=i.createAnalyser();r.fftSize=512,i.createMediaStreamSource(s).connect(r);const m=new Uint8Array(r.fftSize),E=[],d=new MediaRecorder(s,{audioBitsPerSecond:32e3}),$=[],H=Date.now();let k=!0;const et=setInterval(()=>{const y=o();y&&a.parentElement!==y&&y.appendChild(a),r.getByteTimeDomainData(m);let F=0;for(const gt of m)F+=((gt-128)/128)**2;E.push(Math.min(1,Math.sqrt(F/m.length)*4));const nt=E.slice(-je);u.forEach((gt,mn)=>{const pn=nt[mn-(je-nt.length)];gt.style.transform=`scaleY(${Math.max(.1,pn??0).toFixed(2)})`,gt.classList.toggle("is-empty",pn===void 0)});const st=Math.floor((Date.now()-H)/1e3);l.textContent=`${Math.floor(st/60)}:${String(st%60).padStart(2,"0")}`,st>=Ao&&d.state!=="inactive"&&d.stop()},90),S=y=>{k=y,d.state!=="inactive"&&d.stop()};a.querySelector(".dt-rec-x").addEventListener("click",y=>{y.stopPropagation(),S(!1)}),a.querySelector(".dt-rec-done").addEventListener("click",y=>{y.stopPropagation(),S(!0)}),a.addEventListener("keydown",y=>{y.key==="Escape"&&(y.stopPropagation(),S(!1))}),d.ondataavailable=y=>{y.data.size&&$.push(y.data)},d.onstop=async()=>{if(clearInterval(et),s.getTracks().forEach(nt=>nt.stop()),i.close().catch(()=>{}),a.remove(),ce=!1,!k)return;const y=new Blob($,{type:d.mimeType||"audio/webm"}),F=await new Promise(nt=>{const st=new FileReader;st.onload=()=>nt(String(st.result)),st.readAsDataURL(y)});n?z.push(F):c&&(c.images??=[]).push(F),h(),o()?.querySelector("textarea")?.focus()},d.start(1e3),o()?.appendChild(a),a.querySelector(".dt-rec-done").focus()},Qn="\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>',qo=async t=>{const e=t.closest(".dt-note"),s=(e?.hasAttribute("data-draft")?c?.images??[]:z)[Number(t.dataset.i)];if(!s||t.classList.contains("is-asking"))return;t.classList.add("is-asking");const o=await C("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){O(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 l=e?.querySelector("textarea.dt-note-input, textarea.dt-note-reply-input");l&&(l.value=l.value.trim()?`${l.value.trimEnd()} ${a.text}`:a.text,l.dispatchEvent(new Event("input",{bubbles:!0})),l.focus())},Ro='<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>',ts=(t,e,n,s,o="",a="")=>`<div class="dt-note-foot"><div class="dt-compose">
13
- <textarea class="${t}" rows="1" placeholder="${e}">${g(n)}</textarea>
1
+ import{categoryIcon as ds,categoryOf as De}from"../store/categories.mjs";import{stateOf as rt}from"../store/status.mjs";import{DOCS as kt,STEP_RAYS as Yo,agentHandles as cs,agentMentioned as us,agentName as Vo,agentOwner as Jo,agentStep as Gt,docOf as ps,docSlug as Go,handleOf as Xo,held as Qo,stageOf as lt,threadOf as ms,toAgent as F,workingOn as Ie}from"../store/thread.mjs";import{api as L,canvasCopy as Zo,host as ta,imageUrl as ea}from"./api";import{recentLogs as na}from"./logs";import{inspectors as sa}from"./inspect";import{anchors as oa,clean as ft}from"./anchor";import{bars as aa,fieldMenus as ia}from"./field-menu";import{AGENT_MARK as gs,CLAUDE_MARK as xt,CROSS as Pe,PENCIL as fs,TICK as Xt,TRASH as Fe,UNDO as hs,esc as u,stamp as ra}from"./markup";import{canvas as la}from"./canvas";import{historyHtml as da}from"./panel";import{review as ca}from"./review";import{turbo as ua}from"./turbo";function xa(c){const dt=c.breakpoints,je=c.categories,Qt=(dt.find(t=>!Number.isFinite(t.max))??dt[0]).id,_e=t=>dt.find(e=>t>=e.min&&t<=e.max)?.id??Qt,J=t=>t.breakpoint||Qt,bs=t=>c.devices.find(e=>e.id===t),E=Zo,G=(t,e)=>{E||localStorage.setItem(t,e)},Zt=t=>t.replace(/\/+$/,"")||"/";let j=Zt(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 Ke=document.querySelector(".dt-grid-btn"),At=document.querySelector(".dt-grid-overlay"),We="dt-grid",te=t=>{At.hidden=!t,Ke.setAttribute("aria-pressed",String(t)),G(We,t?"1":"0"),B({grid:t})};Ke.addEventListener("click",()=>te(At.hidden===!0));const Ue=document.querySelector(".dt-pages-name"),ze=()=>{let t=null;for(const s of document.querySelectorAll(".dt-pages a"))Zt(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();Ue.textContent=n||e||Ue.textContent};ze();const Ye=[...document.querySelectorAll(".devtools details")];let ee=!1;const ht=()=>{const t=Ye.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]=ht();e&&(e.querySelector("summary")?.focus(),t.preventDefault(),t.stopImmediatePropagation())},!0),document.addEventListener("pointerdown",t=>{ee=Ye.some(e=>e.open&&!e.contains(t.target))&&ht().length>0},!0),addEventListener("blur",ht);const ct=document.querySelector(".dt-pad-overlay"),Ve="dt-inspect",ys=[".devtools",".dt-pad-overlay",".dt-grid-overlay",".dt-frame",".dt-history",".dt-review",".dt-field-menu",...c.ignore].join(", "),ne=[".devtools",".dt-notes-overlay",".dt-history",".dt-frame",".dt-review",".dt-field-menu",'[aria-modal="true"]',...c.ignore].join(", "),se={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 _="",oe=0;const{spacer:vs,drawPads:$s,drawSize:ws,drawType:Es,drawColor:Ss,drawBorder:Ts}=sa(ct),Je=t=>{oe||(oe=requestAnimationFrame(()=>{oe=0,ct.hidden=!0;let e=document.elementFromPoint(t.clientX,t.clientY);if(ct.hidden=!1,!e||e.closest(ys)){ct.innerHTML="";return}t.altKey&&e.parentElement&&e.parentElement!==document.body&&(e=e.parentElement),_==="sizes"?ws(e):_==="type"?Es(e):_==="color"?Ss(e):_==="border"?Ts(e):$s(t.altKey?e:vs(e))}))},Ht=t=>{_=t;for(const[e,n]of Object.entries(se))n.setAttribute("aria-pressed",String(e===t));G(Ve,t),B({inspect:t}),ct.hidden=!t,ct.innerHTML="",t?document.addEventListener("mousemove",Je):document.removeEventListener("mousemove",Je)};for(const[t,e]of Object.entries(se))e.addEventListener("click",()=>{t!==_&&Q(!1),Ht(_===t?"":t)});const Ge=document.querySelector(".dt-notes-btn"),ae=[...document.querySelectorAll(".dt-bp")],Ct=document.querySelector(".dt-history-btn"),H=document.querySelector(".dt-history"),ie=document.querySelector(".dt-studio-btn"),re=document.querySelector(".dt-devices"),nt=document.querySelector(".dt-notes-hi"),Ms=nt.querySelector(".dt-hi-box"),Xe=nt.querySelector(".dt-hi-tag"),st=document.querySelector(".dt-frame"),Nt=st.querySelector("iframe"),le=document.querySelector(".dt-notes-count"),h=document.querySelector(".dt-notes-overlay"),Qe=".devtools, .dt-tab, .dt-notes-overlay, .dt-history, .dt-frame",Ze=t=>{for(const e of["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend","click","focusin","focusout"])t.addEventListener(e,n=>n.stopPropagation())};document.querySelectorAll(Qe).forEach(Ze);const tn="dt-notes";let b=[],x=!1,$=null,l=null,de=0,R="",O=[],T=null,A=[];const Rt=(t=l)=>!!(t&&(t.text?.trim()||t.images?.length)),K=()=>{l&&Rt()&&A.push(l),l=null};let bt=null,ce=null;const en=()=>`dt-draft:${j}${E?":canvas":""}`;let ut=en(),Ot=0;const ue=()=>{if(!l&&!A.length&&!R){localStorage.removeItem(ut);return}const t={draft:l,parked:A,reply:R?{for:bt,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(Ot),Ot=setTimeout(ue,200)};addEventListener("pagehide",()=>{clearTimeout(Ot),ue()});let W=localStorage.getItem("dt-resolved")!=="0";const Ls=[[/Edg\/(\d+)/,"Edge"],[/OPR\/(\d+)/,"Opera"],[/Firefox\/(\d+)/,"Firefox"],[/Chrome\/(\d+)/,"Chrome"],[/Version\/(\d+).*Safari/,"Safari"]],ks=[[/iPhone|iPad/,"iOS"],[/Android/,"Android"],[/Mac OS X/,"macOS"],[/Windows/,"Windows"],[/Linux/,"Linux"]],xs=()=>{const t=navigator.userAgent,e=a=>a.find(([i])=>i.test(t)),n=e(Ls),s=e(ks),o=n?n[0].exec(t)?.[1]:null;return[n?`${n[1]}${o?" "+o:""}`:"unknown browser",s?.[1]].filter(Boolean).join(" \xB7 ")},pe=()=>_e(innerWidth),Bt=()=>ce??pe(),nn=()=>{const t=Bt();for(const e of ae)e.setAttribute("aria-pressed",String(e.dataset.bp===t))},{cssPath:As,poolOf:Hs,contextOf:Cs,resolveEl:q,anchorOf:Ns}=oa(),qt=new Map,D=t=>{qt.size||requestAnimationFrame(()=>qt.clear());let e=qt.get(t);return e===void 0&&(e=Ns(t),qt.set(t,e)),e},sn=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 me=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))},on=()=>{if(l)return q(l);const t=$!=null?b.find(n=>n.id===$):null;if(!t)return null;const e=D(t);return e&&!e.off?q(t):null},Rs="claude",Os=()=>(c.team??[]).filter(t=>t.email!==c.me?.email),It=()=>[...c.me?(c.team??[]).filter(t=>t.email===c.me.email):[],...Os()],Bs='<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=F(t)?"agent":t?"person":"nobody",o=vt(s==="person"?t:an());return`<span class="dt-hand" role="radiogroup" aria-label="Who takes it">${[["person",o?Ft(o.avatar_url,o.name||o.email):wt,s==="person"?`${Pt(t)==="you"?"You":Pt(t)} \u2014 pick someone else`:o?`Give it to ${o.email===c.me?.email?"me":o.name||o.email}`:"A person"],["nobody",Bs,"Nobody \u2014 not anyone's yet"],["agent",xt(12),n?"Waits for the studio to approve it":s==="agent"?"Claude does it":"Give it to Claude"]].map(([i,d,p])=>i===s?`<span class="dt-hand-stop dt-hand-stop--${i} is-on" role="radio" aria-checked="true" data-tip="${u(p)}" aria-label="${u(p)}">${i==="person"?_s(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="${u(p)}" aria-label="${u(p)}"${i==="agent"&&n?" disabled":""}>${d}</button>`).join("")}</span>`},an=()=>{const t=Ps();return t&&!F(t)&&It().some(e=>e.email===t)?t:It()[0]?.email??""},Ds=()=>{const t=h.querySelector(".dt-hand .dt-hand-stop.is-on");return t?{rect:t.getBoundingClientRect(),ghost:t.cloneNode(!0)}:void 0},rn="cubic-bezier(0.32, 0.72, 0, 1)",ln=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()),Ee=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:rn});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:rn});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"})},Is=(t,e)=>{const n=Ee>performance.now()?void 0:Ds(),s=e==="agent"?Rs:e==="person"?an():e==="me"?c.me?.email??"":"";if(!t){if(!l)return;if(l.assignee=s,l.stage=F(s)?"approved":!l.stage||l.stage==="approved"?"new":l.stage,e==="person")try{localStorage.setItem("nm-for",s)}catch{}ot(),f(),ln(n);return}const o=b.find(d=>d.id===t);if(o&&Ie(o)&&!F(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=F(s)?"approved":a==="approved"?"new":a;I(d=>d.map(p=>p.id===t?{...p,assignee:s||void 0,stage:i}:p),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,assignee:s||null,stage:i})}),F(s)?"Approving it for the agent":"Reassigning"),ln(n)},Ps=()=>{try{return localStorage.getItem("nm-for")??""}catch{return""}},yt=t=>F(t)?"#d97757":t?"#0d99ff":"#717171",Pt=t=>t===c.me?.email?"you":c.team?.find(e=>e.email===t)?.name||t.split("@")[0],vt=t=>t?c.team?.find(e=>e.email===t):void 0,dn=t=>{const e=ft(t??"").split(/\s+/).filter(Boolean);return u(((e[0]?.[0]??"?")+(e.length>1?e[e.length-1][0]:"")).toUpperCase())},Ft=(t,e,n="dt-face")=>t?`<img class="${n}" src="${u(t)}" alt="">`:`<b class="${n}" aria-hidden="true">${dn(e)}</b>`,Fs=t=>{const e=vt(t.by);return e||t.byName?Ft(e?.avatar_url,e?.name||t.byName||t.by):""},cn=t=>{const e=vt(t);return e?` data-face="${u(e.avatar_url??"")}" data-initial="${dn(e.name||e.email)}"`:""},at=(t,e)=>Vo(t),un=t=>{const e=vt(t);return e?Ft(e.avatar_url,e.name||e.email):""},js=t=>{const e=vt(t)?.agent_avatar_url;return e?`<img class="dt-face" src="${u(e)}" alt="">`:`<b class="dt-face dt-face--ai" aria-hidden="true">${xt(12)}</b>`},_s=(t,e)=>{const n=(o,a)=>`<option value="${u(o)}" data-c="${yt(o)}"${cn(o||null)}${t===o?" selected":""}>${u(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:${yt(t)}">${un(t||null)||wt}<select class="dt-for-select"${e?` data-id="${e}"`:""} aria-label="Who does it">
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,Pt(t)):""}
4
+ </select></span></label>`},pn=t=>{const e=ft(t?.textContent).replace(/\s+/g," ");return e&&e.length<=2e3?e:""},Ks=t=>`<div class="dt-suggest dt-suggest--read"><del>${u(t.from)}</del><ins>${u(t.to)}</ins></div>`,mn=(t,e)=>{const n=String(t??"").replace(/\s*>\s*/g," \u203A ").slice(-160);return u([n,ft(e??"")&&`\u201C${ft(e).slice(0,80)}\u201D`].filter(Boolean).join(" \xB7 "))},Ws='<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>',Us=(t,e)=>{const n=De(t);return`<label class="dt-field dt-field--bare" data-tip="Type: ${u(n.label)}"><span class="dt-field-box">${ds(n)}<span class="dt-field-label">${u(n.label)}</span>${Ws}<select class="dt-cat-select"${e?` data-id="${e}"`:""} aria-label="Type">${je.map(s=>`<option value="${s.id}" data-c="${s.color}" data-icon="${u(ds(s))}" data-hint="${u(s.hint)}"${s.id===t?" selected":""}>${s.label}</option>`).join("")}</select></span></label>`},$t=[["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>`},gn=t=>Ie(t)||lt(t)==="progress"?"progress":lt(t)==="review"?"review":lt(t)==="waiting"?"waiting":"new",fn={queued:"new",working:"progress",stuck:"progress",asks:"waiting",review:"review",held:"new"},hn=(t,e)=>{const[,,n,s]=$t.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>`},zs=t=>{const e=Gt(t);if(t.status==="done"&&e!=="review")return hn("done","Resolved");if(e&&fn[e]){const a=fn[e];return hn(a,$t.find(i=>i[0]===a)[1])}const n=gn(t),[,,s,o]=$t.find(a=>a[0]===n);return`<label class="dt-field" title="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">${$t.map(([a,i,d,p])=>`<option value="${a}" data-c="${d}" data-icon="${u(ge(d,p))}"${a===n?" selected":""}>${i}</option>`).join("")}</select></span></label>`},Ys=(t,e)=>{const n=b.find(o=>o.id===t);if(!n)return;const s=e==="new"?F(n.assignee)?"approved":"new":e;I(o=>o.map(a=>a.id===t?{...a,stage:s}:a),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,stage:s})}),"Setting the status")},jt=[["low","Low","#30a46c",1],["normal","Mid","#f5c451",2],["high","High","#ff5a00",3],["urgent","Urgent","#e5484d",4]],Vs=(t,e)=>{const n=Math.max(0,jt.findIndex(d=>d[0]===t)),[,s,o,a]=jt[n],i=jt[(n+1)%jt.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}">${aa(a,o)}<span>${s}</span></button>`},fe=()=>!!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?"":Vs(t,n)}${Us(De(e).id,n)}</span>${c.client||fe()?"":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>',Js='<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">${Js}</span><select class="dt-more-select"${e?` data-id="${e}"`:""} aria-label="More">
5
+ <option value="" hidden selected></option>
6
+ ${c.client?"":`<option value="team" data-icon="${u(yn)}"${t?"":" data-on"}>Team only</option>
7
+ <option value="client" data-icon="${u(wt)}"${t?" data-on":""}>Team and client</option>`}
8
+ <option value="${e?"rm":"discard"}" data-icon="${u(Fe)}" 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>',pa=(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>`,Gs=()=>(c.team??[]).filter(t=>!c.studio||c.studio.includes(t.email)),Xs=t=>{const e=t||c.lead||"",n=Gs();if(!n.length)return"";const s=un(e);return`<label class="dt-field" title="Who it is for"><span class="dt-field-box${s?" dt-field-box--face":""}" style="--cat:${yt(e||"x@x")}">${s}<select class="dt-for-select" aria-label="Who this is for">
11
+ ${n.map(o=>`<option value="${u(o.email)}" data-c="${yt(o.email)}"${cn(o.email)}${e===o.email?" selected":""}>${u(o.name||o.email)}</option>`).join("")}
12
+ </select></span></label>`},he='<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>',Qs=!1,Zs=!1,wn='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M3 1.8v8.4L10 6z"/></svg>',to='<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>',eo=t=>`${Math.floor(t/60)}:${String(Math.floor(t%60)).padStart(2,"0")}`,no=(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"),p=n.querySelector(".dt-voice-time"),m=()=>Number.isFinite(s.duration)?s.duration:0;s.addEventListener("timeupdate",()=>{d.style.transform=`scaleX(${m()?Math.min(1,s.currentTime/m()):0})`,p.textContent=eo(s.currentTime)}),s.addEventListener("play",()=>{o.innerHTML=to,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}},be=t=>t.startsWith("data:audio/")||/(^|\/)voice-[^/?]*\.(webm|m4a)(\?|$)/i.test(t),En=t=>t.startsWith("data:video/")||/\.webm(\?|$)/i.test(t),Et=new Map,so=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},oo=(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="${so(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">${ho}</button>`}${e===void 0?"":`<button class="dt-voice-rm" data-act="unshot" ${e} aria-label="Remove the recording" title="Remove the recording">${he}</button>`}</span>`,ao=(t,e,n)=>`<span class="dt-shot dt-doc">${t.startsWith("data:")?`<span class="dt-doc-name">${Ln}${u(e)}</span>`:`<a class="dt-doc-name" href="${t}" target="_blank" rel="noreferrer">${Ln}${u(e)}</a>`}${n===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${n} aria-label="Remove">${he}</button>`}</span>`,Sn=(t,e,n=t)=>ps(n)?ao(t,ps(n),e):be(n)?oo(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">${he}</button>`}</span>`,Tn=(t=[],e)=>t.length?`<div class="dt-note-shots">${t.map(n=>{const s=n.split("/").pop(),o=ea(s);return Sn(o,e===void 0?void 0:`data-id="${e}" data-img="${u(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>',io='<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>',ro='<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>',lo=!!navigator.mediaDevices?.getDisplayMedia&&typeof MediaRecorder<"u";let it=null;const co=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(m=>MediaRecorder.isTypeSupported(m));if(!o){for(const m of e.getTracks())m.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=m=>{m.data.size&&i.push(m.data)};const p=setTimeout(()=>{a.state!=="inactive"&&a.stop()},3e4);a.onstop=async()=>{clearTimeout(p);for(const y of[...e.getTracks(),...n?.getTracks()??[]])y.stop();it=null;const m=new Blob(i,{type:"video/webm"});if(m.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(m)});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()},uo='<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>',po='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="m5 10.5 3.2 3L15 6.5"/></svg>',mo=90,ye=32,go=()=>!!c.voice&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<"u";let _t=!1;const fo=async(t,e)=>{if(_t||!t)return;const n=Number(t.dataset.id)||0;_t=!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){_t=!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">${Fe}</button><span class="dt-rec-time"><i></i><b>0:00</b></span><span class="dt-rec-wave">${"<i></i>".repeat(ye)}</span><button type="button" class="dt-rec-done" title="Done \u2014 write it out" aria-label="Done">${po}</button>`;const i=a.querySelector("b"),d=[...a.querySelectorAll(".dt-rec-wave i")],p=new AudioContext,m=p.createAnalyser();m.fftSize=512,p.createMediaStreamSource(s).connect(m);const r=new Uint8Array(m.fftSize),y=[],g=new MediaRecorder(s,{audioBitsPerSecond:32e3}),w=[],M=Date.now();let C=!0;const Z=setInterval(()=>{const S=o();S&&a.parentElement!==S&&S.appendChild(a),m.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(-ye);d.forEach((V,Jt)=>{const et=Y[Jt-(ye-Y.length)];V.style.transform=`scaleY(${Math.max(.1,et??0).toFixed(2)})`,V.classList.toggle("is-empty",et===void 0)});const N=Math.floor((Date.now()-M)/1e3);i.textContent=`${Math.floor(N/60)}:${String(N%60).padStart(2,"0")}`,N>=mo&&g.state!=="inactive"&&g.stop()},90),tt=S=>{C=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()),p.close().catch(()=>{}),a.remove(),_t=!1,!C)return;const S=new Blob(w,{type:g.mimeType||"audio/webm"}),v=await new Promise(Y=>{const N=new FileReader;N.onload=()=>Y(String(N.result)),N.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",ho='<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>',bo=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,yo=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&&ms(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())},vo='<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>',$o='<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}">${u(n)}</textarea>
14
14
  ${o}
15
15
  <div class="dt-compose-bar">
16
- <span class="dt-compose-tools"><button class="dt-attach" data-act="attach" title="Attach a screenshot \u2014 or paste or drop one">${Ro}</button>
17
- ${a}${yo&&Mo?`<button class="dt-record${bt?" is-on":""}" data-act="record" title="${bt?"Stop recording":"Record the screen, up to 30 seconds"}">${bt?"Stop":Lo}</button>`:""}${No()?`<button class="dt-attach" data-act="speak" title="Speak \u2014 sent with its words as a voice note">${ko}</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">${$o}</button>
17
+ ${a}${Zs&&lo?`<button class="dt-record${it?" is-on":""}" data-act="record" title="${it?"Stop recording":"Record the screen, up to 30 seconds"}">${it?"Stop":io}</button>`:""}${go()?`<button class="dt-attach" data-act="speak" title="Speak \u2014 sent with its words as a voice note">${uo}</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>`,Fe=(t,e)=>(t||"element")+(e?.[0]?"."+e[0]:""),es=()=>I.map((t,e)=>({i:e,el:Fe(t.tag,t.classes),text:wt(t.text??""),shots:t.images?.length??0,orphan:!Z(t)}));let Ke=[],ns="";const Io=(t,e)=>t!=="claude"?"":`<button class="dt-note-state" data-act="reopen" data-id="${e}"
22
- title="Resolved by ${g((n=>ct(n?.doneAgent,n?.doneFor))(b.find(n=>n.id===e)))} \u2014 click to clear">${Lt(13)}</button>`,ss=(t,e)=>{const n=t==="done";return`${Io(t,e)}<button data-act="${n?"reopen":"done"}" data-id="${e}"
23
- class="dt-note-resolve${n?" is-on":""}" title="${n?"Reopen":t==="claude"?"Looks right \u2014 mark it resolved":"Resolve"}">${jt}</button>`},Do=async(t,e)=>{const n=e?b.find(o=>o.id===t):void 0,s=n?await Ze(Y(n)):null;return C("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})})},rt=async(t,e,n)=>{const s=b,o=Q;b=t(b),Q=t(Q),h();const a=await e().catch(()=>null);if(!a?.ok){b=s,Q=o,h(),O(`${n} did not go through${a?` (${a.status})`:""}.`);return}he()},Tt=(t,e)=>rt(n=>n.map(s=>s.id===t?{...s,status:e?"done":"open",doneBy:e?"you":null}:s),()=>Do(t,e),e?"Resolving":"Reopening"),os=t=>rt(e=>e.filter(n=>n.id!==t),()=>C(`comments?id=${t}`,{method:"DELETE"}),"Deleting"),g=t=>t.replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]),Oo=t=>{const e=b.filter(o=>ot(o)===t),n=e.filter(o=>q(o)==="open").length,s=e.filter(o=>q(o)==="claude").length;Ce.innerHTML=n?String(n):s?Lt(9):"\u2713",Ce.dataset.state=n?"open":s?"claude":"done",Ce.hidden=e.length===0},h=()=>{if(ft(),w){const i=es(),r=JSON.stringify(i);r!==ns&&(ns=r,parent.postMessage({dt:!0,drafts:i},location.origin))}Ot(),v!==Dt&&(U="",z=[],Dt=v),x&&x.id!==v&&(x=null);const t=oe();if(Oo(t),!A){f.innerHTML="",Re(null);return}const e=t;let n="";const s=b.filter(i=>ot(i)===e&&(X||q(i)!=="done"));for(const i of s){const r=Z(i);if(!r&&v!==i.id)continue;const m=q(i),E=m==="done",d=!r,$=r??{x:0,y:0},H=$e(i.category),k=Os(i);if(d||(n+=`<button class="dt-pin dt-pin--${m}${k?" dt-pin--working":""}${m==="open"&&we(i)==="review"?" dt-pin--review":""}" data-id="${i.id}"${r?.off?` data-off="${r.off}"`:""} aria-label="Comment ${i.id}, ${m==="open"?"open":m==="claude"?`resolved by ${g(ct(i.doneAgent,i.doneFor))}`:"resolved"}" aria-expanded="${v===i.id}"
24
- style="left:${$.x}px;top:${$.y}px;--cat:${H.color}"
25
- title="${g(i.text.slice(0,80))} \xB7 ${H.label}${k?` \xB7 ${g(ct(k.agent,k.by))} is on it`:""}${m==="claude"?` \xB7 resolved by ${g(ct(i.doneAgent,i.doneFor))} \u2014 tick to confirm`:m==="done"?" \xB7 resolved":""}">${m==="done"?"\u2713":m==="claude"?Lt(11):ro(i)}</button>`),v===i.id){const et=ca(i);n+=`<div class="dt-note${d?" dt-note--orphan":""}" data-id="${i.id}" role="dialog" aria-label="Comment ${i.id}"
26
- style="left:${$.x}px;top:${$.y}px">
21
+ </div></div>`,ve=(t,e)=>(t||"element")+(e?.[0]?"."+e[0]:""),An=()=>A.map((t,e)=>({i:e,el:ve(t.tag,t.classes),text:ft(t.text??""),shots:t.images?.length??0,orphan:!D(t)}));let $e=[],Hn="";const z=t=>{const e=t.working;return at(e?.agent,e?.by??Jo(t.assignee))},Cn=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`},Kt=(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 ${Cn(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]},wo=t=>{const e=Gt(t);if(!e)return c.client||fe()||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">${gs(13,0)}</button>`;const n=gs(13,Yo[e]);return e==="review"?`<button class="dt-note-state dt-step--review" data-act="reopen" data-id="${t.id}" data-tip="${u(Kt(t,e))}" aria-label="${u(Kt(t,e))}">${n}</button>`:`<span class="dt-note-state dt-step--${e}" data-tip="${u(Kt(t,e))}" role="img" aria-label="${u(Kt(t,e))}">${n}</span>`},Nn=t=>{const e=rt(t),n=e==="done";return`${wo(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"}">${Xt}</button>`},ma='<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>',Eo=t=>t?new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"",So=t=>{if(c.client)return"";const e=Gt(t),n={act:"hand",v:"me",icon:wt,tip:c.me?"Take it myself":"Take it off Claude"},s={act:"reopen",icon:hs,tip:"Reopen"},o=[{act:"done",icon:Xt,tip:"Looks right \u2014 resolve it",main:!0},{act:"sendback",icon:hs,tip:"Send it back \u2014 say what is wrong below"}],a=t.working,i=!F(t.assignee)&&t.assignee?t.assignee===c.me?.email?"You":Pt(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 ${Cn(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 ${Eo(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>${u(d.title)}</b></span>${d.acts.map(p=>`<button type="button" class="dt-step-act${p.main?" is-main":""}" data-act="${p.act}" data-id="${t.id}"${p.v?` data-v="${p.v}"`:""} data-tip="${u(p.tip)}" aria-label="${u(p.tip)}">${p.icon}</button>`).join("")}${d.live?'<i class="dt-step-live" aria-hidden="true"></i>':""}</div>`:""},To=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})})},I=async(t,e,n)=>{const s=b,o=pt;b=t(b),pt=t(pt),f();const a=await e().catch(()=>null);if(!a?.ok){b=s,pt=o,f(),k(`${n} did not go through${a?` (${a.status})`:""}.`);return}Yt()},St=(t,e)=>I(n=>n.map(s=>s.id===t?{...s,status:e?"done":"open",doneBy:e?"you":null}:s),()=>To(t,e),e?"Resolving":"Reopening"),we=t=>I(e=>e.filter(n=>n.id!==t),()=>L(`comments?id=${t}`,{method:"DELETE"}),"Deleting"),Mo=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;le.innerHTML=n?String(n):s?xt(9):"\u2713",le.dataset.state=n?"open":s?"claude":"done",le.hidden=e.length===0};let Ee=0,Rn;const f=()=>{const t=Ee-performance.now();if(t>0){clearTimeout(Rn),Rn=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))}nn(),$!==bt&&(R="",O=[],bt=$),T&&T.id!==$&&(T=null);const e=Bt();if(Mo(e),!x){h.innerHTML="",me(null);return}const n=e;let s="";const o=b.filter(r=>J(r)===n&&(W||rt(r)!=="done"));for(const r of o){const y=D(r);if(!y&&$!==r.id)continue;const g=rt(r),w=g==="done",M=!y,C=y??{x:0,y:0},Z=De(r.category),tt=Ie(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 ${u(at(r.doneAgent,r.doneFor))}`:"resolved"}" aria-expanded="${$===r.id}"
23
+ style="left:${C.x}px;top:${C.y}px;--cat:${Z.color};--ring:${$t.find(S=>S[0]===gn(r))[2]}"
24
+ title="${u(r.text.slice(0,80))} \xB7 ${Z.label}${tt?` \xB7 ${u(at(tt.agent,tt.by))} is on it`:""}${g==="claude"?` \xB7 resolved by ${u(at(r.doneAgent,r.doneFor))} \u2014 tick to confirm`:g==="done"?" \xB7 resolved":""}">${g==="done"?"\u2713":g==="claude"?xt(11):Fs(r)}</button>`),$===r.id){const S=ms(r);s+=`<div class="dt-note${M?" dt-note--orphan":""}" data-id="${r.id}" role="dialog" aria-label="Comment ${r.id}"
25
+ style="left:${C.x}px;top:${C.y}px">
27
26
  <div class="dt-note-bar">
28
- <span class="dt-note-el">${p.client?`Comment #${jo(i)}`:g(Fe(i.tag,i.classes))}</span>
29
- ${jn(i.label)}
27
+ <span class="dt-note-el"${c.client?"":` data-tip="${mn(r.selector,r.label)}"`}>${c.client?`Comment #${ko(r)}`:u(ve(r.tag,r.classes))}</span>
30
28
  <span class="dt-note-tools">
31
- ${ss(m,i.id)}
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
+ ${Nn(r)}
32
31
  <i class="dt-note-sep"></i>
33
- ${p.client?"":Un(i.shared,i.id)}
34
- <button data-act="rm" data-id="${i.id}" title="Delete this thread">${Pt}</button>
35
- <button data-act="close" data-id="${i.id}" title="Close">${ie}</button>
32
+ ${vn(r.shared,r.id)}
33
+ <button data-act="close" data-id="${r.id}" data-tip="Close" aria-label="Close">${Pe}</button>
36
34
  </span>
37
35
  </div>
38
- ${k?`<p class="dt-note-working"><i></i>${g(ct(k.agent,k.by))} is on it</p>`:""}
39
- ${d?'<p class="dt-note-orphan">The element this was pinned to is not on the page right now.</p>':""}
40
- ${(()=>{const S=Fn($e(i.category).id,i.id)+(p.client?"":mo(i))+(i.host&&i.host!==location.host?`<span class="dt-note-host" title="Written on ${g(i.host)}">${g(i.host)}</span>`:"");return S?`<div class="dt-note-meta">${S}</div>`:""})()}
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?"":zs(r))+(r.host&&r.host!==location.host?`<span class="dt-note-host" title="Written on ${u(r.host)}">${u(r.host)}</span>`:"");return v?`<div class="dt-note-meta">${v}</div>`:""})()}
41
38
  <div class="dt-note-thread">
42
- ${et.map((S,y)=>{const F=y===0?null:S.at??null,nt=S.author==="you"&&(!S.by||S.by===p.me?.email),st=nt&&x?.id===i.id&&x.at===F,gt=p.team?.find(gn=>gn.email===S.by),mn=S.author==="claude"?ct(S.agent,S.by):nt?"You":gt?.name||S.byName||S.by||"You",Is=`<div class="dt-msg-head">${gt?.avatar_url?`<img class="dt-msg-face" src="${g(gt.avatar_url)}" alt="">`:""}<b>${g(mn)}</b><time>${Cn(S.at)}</time>${nt&&!st?`<button class="dt-msg-edit" data-act="edit" data-id="${i.id}" data-at="${g(F??"")}" title="Edit">${Ie}</button>`:""}</div>`;return st?`<div class="dt-msg">${Is}<div class="dt-compose">
43
- <textarea class="dt-note-edit-input" rows="1">${g(x.text)}</textarea>
44
- ${Xn(S.images.filter(gn=>!x.drop.includes(gn.split("/").pop())),i.id)}
39
+ ${S.map((v,Y)=>{const N=Y===0?null:v.at??null,V=v.author==="you"&&(!v.by||v.by===c.me?.email),Jt=V&&T?.id===r.id&&T.at===N,et=c.team?.find(qe=>qe.email===v.by),Wo=v.author==="claude"?at(v.agent,v.by):V?"You":et?.name||v.byName||v.by||"You",Uo=v.author==="claude"?et?.agent_avatar_url?`<img class="dt-msg-face" src="${u(et.agent_avatar_url)}" alt="">`:`<span class="dt-msg-face dt-msg-ai">${xt(11)}</span>`:et?.avatar_url?`<img class="dt-msg-face" src="${u(et.avatar_url)}" alt="">`:"",Be=`${r.id}:${v.at??"0"}`,rs=U.get(Be),zo=!V&&c.voice&&v.text?`<button class="dt-msg-edit${U.has(Be)?" is-on":""}" data-act="translate" data-id="${r.id}" data-at="${u(v.at??"0")}" title="${U.has(Be)?"Show the original":"Translate into your language"}">${vo}</button>`:"",ls=`<div class="dt-msg-head">${Uo}<b>${u(Wo)}</b><time>${ra(v.at)}</time>${zo}${V&&!Jt?`<button class="dt-msg-edit" data-act="edit" data-id="${r.id}" data-at="${u(N??"")}" title="Edit">${fs}</button>${N?`<button class="dt-msg-edit" data-act="unsay" data-id="${r.id}" data-at="${u(N)}" title="Delete">${Fe}</button>`:""}`:""}</div>`;return Jt?`<div class="dt-msg">${ls}<div class="dt-compose">
40
+ <textarea class="dt-note-edit-input" rows="1">${u(T.text)}</textarea>
41
+ ${Tn(v.images.filter(qe=>!T.drop.includes(qe.split("/").pop())),r.id)}
45
42
  <div class="dt-compose-bar">
46
43
  <button class="dt-edit-cancel" data-act="edit-cancel">Cancel</button>
47
- <button class="dt-send${x.text.trim()?" is-ready":""}" data-act="edit-save" title="Save (Enter)">${jt}</button>
44
+ <button class="dt-send${T.text.trim()?" is-ready":""}" data-act="edit-save" title="Save (Enter)">${Xt}</button>
48
45
  </div>
49
- </div></div>`:`<div class="dt-msg" data-msg="${i.id}:${g(S.at??"0")}">${Is}<p>${g(S.text)}</p>${y===0&&i.suggest?co(i.suggest):""}${Xn(S.images)}</div>`}).join("")}
46
+ </div></div>`:`<div class="dt-msg" data-msg="${r.id}:${u(v.at??"0")}">${ls}<p${rs===null?' class="is-asking"':""}>${Po(rs||v.text)}</p>${Y===0&&r.suggest?Ks(r.suggest):""}${Tn(v.images)}</div>`}).join("")}
50
47
  </div>
51
- ${ts("dt-note-reply-input","Reply",U,`data-act="reply" data-id="${i.id}"`,Zn(z))}
52
- ${p.client?"":`<div class="dt-prio-row">${Wn(i.priority,i.id)}${Bn(i.assignee??"",i.id,da(i))}</div>`}
53
- </div>`}}I.forEach((i,r)=>{const m=Z(i);m&&(n+=`<button class="dt-pin dt-pin--draft" data-parked="${r}" data-act="draft-open" data-i="${r}"
54
- style="left:${m.x}px;top:${m.y}px" title="Draft, not sent \u2014 click to finish it">${Ie}</button>`)});const o=c&&Z(c);if(c){const i=o?.x??0,r=o?.y??0;n+=`${o?`<span class="dt-pin dt-pin--draft" data-draft style="left:${i}px;top:${r}px"></span>`:""}
55
- <div class="dt-note${o?"":" dt-note--orphan"}" data-draft style="left:${i}px;top:${r}px">
48
+ ${So(r)}
49
+ ${xn("dt-note-reply-input",Gt(r)==="asks"?`Answer ${u(z(r))}`:"Reply",R,`data-act="reply" data-id="${r.id}"`,Mn(O))}
50
+ ${bn(r.priority,r.category,r.id,r.assignee??"",Qo(r))}
51
+ </div>`}}A.forEach((r,y)=>{const g=D(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">${fs}</button>`)});const a=l&&D(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">
56
54
  <div class="dt-note-bar">
57
- <span class="dt-note-el">${p.client?"New comment":g(Fe(c.tag,c.classes))}</span>
58
- ${jn(c.label)}
59
- ${ne()?'<span class="dt-note-draft">Draft</span>':""}
55
+ <span class="dt-note-el"${c.client?"":` data-tip="${mn(l.selector,l.label)}"`}>${c.client?"New comment":u(ve(l.tag,l.classes))}</span>
56
+ ${Rt()?'<span class="dt-note-draft">Draft</span>':""}
60
57
  <span class="dt-note-tools">
61
- ${p.client?"":Un(c.shared)}
62
- <button data-act="discard" title="Discard this draft">${Pt}</button>
63
- <button data-act="cancel" title="Close \u2014 the draft stays">${ie}</button>
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">${Pe}</button>
64
61
  </span>
65
62
  </div>
66
- ${o?"":'<p class="dt-note-orphan">The element this was pinned to is not on the page right now.</p>'}
67
- ${(()=>{const m=o?Y(c):null,E=m&&b.find(d=>d.id>0&&q(d)==="open"&&Y(d)===m);return E?`<p class="dt-note-twin">Already open here: \u201C${g(E.text.slice(0,60))}${E.text.length>60?"\u2026":""}\u201D <button data-act="twin" data-id="${E.id}">Open it</button></p>`:""})()}
68
- <div class="dt-note-meta">${Fn(c.category)}${p.client?fo(c.assignee):""}</div>
69
- ${c.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">${ie}</button></span>
70
- <span class="dt-suggest-was">Now: <del>${g(c.suggest.from.slice(0,160))}${c.suggest.from.length>160?"\u2026":""}</del></span>
71
- <textarea class="dt-suggest-input" rows="2" placeholder="Type how it should read" aria-label="How it should read">${g(c.suggest.to)}</textarea>
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${u(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">${Xs(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">${Pe}</button></span>
67
+ <span class="dt-suggest-was">Now: <del>${u(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">${u(l.suggest.to)}</textarea>
72
69
  <span class="dt-suggest-hint">Change the words in the box \u2014 the agent puts in exactly what you write.</span></div>`:""}
73
- ${ts("dt-note-input",c.suggest?"Why (optional)":"Comment",c.text??"",'data-act="save"',Zn(c.images),bo&&!c.suggest&&Pn(o?Y(c):null)?`<button class="dt-attach" data-act="suggest" title="Rewrite this text: start from its current words and change them">${To}</button>`:"")}
74
- ${p.client?"":`<div class="dt-prio-row">${Wn(c.priority)}${Bn(c.assignee??re())}</div>`}
75
- </div>`}const a=new Map([...f.querySelectorAll(".dt-note[data-id] .dt-note-thread")].map(i=>[i.closest(".dt-note").dataset.id,{top:i.scrollTop,end:i.scrollTop+i.clientHeight>=i.scrollHeight-4}])),l=new Set([...f.querySelectorAll("[data-msg]")].map(i=>i.dataset.msg));f.innerHTML=n;for(const i of f.querySelectorAll(".dt-note[data-id] .dt-note-thread")){const r=i.closest(".dt-note").dataset.id,m=a.get(r);if(!m)continue;const E=[...i.querySelectorAll("[data-msg]")].filter(d=>!l.has(d.dataset.msg));for(const d of E)d.classList.add("dt-msg--new");i.scrollTop=m.end&&E.length?i.scrollHeight:m.top}for(const i of f.querySelectorAll(".dt-note")){const r=i.getBoundingClientRect();r.bottom>innerHeight-8&&(i.dataset.flip="1"),r.right>innerWidth-8&&(i.dataset.flipx="1")}as(e),Re(Nn()),ut();for(const i of f.querySelectorAll(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input"))tn(i);const u=f.querySelector(".dt-note-input");u&&(u.focus(),u.setSelectionRange(u.value.length,u.value.length))},Po=()=>{let t=!1;for(const e of f.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&&Z(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),n&&An(Y(n))&&(t=!0)}for(const e of f.querySelectorAll("[data-draft], [data-parked]")){if(e.classList.contains("dt-note--orphan"))continue;const n=e.dataset.parked?I[Number(e.dataset.parked)]:c,s=n&&Z(n);if(!s){e.style.visibility="hidden";continue}e.style.visibility="",e.style.left=`${s.x}px`,e.style.top=`${s.y}px`}if(!ae.length&&(c||v!=null)){const e=Nn();e&&An(e)&&Re(e)}t&&ut()},jo=t=>b.filter(e=>ot(e)===ot(t)).findIndex(e=>e.id===t.id)+1,as=t=>{if(W.hidden)return;const e=b.filter(d=>ot(d)===t),n=new Map(e.map((d,$)=>[d.id,$+1])),s={open:[],claude:[],done:[]};for(const d of e)s[q(d)].push(d);const o=d=>{const $=(d.replies?.length??0)+(d.note?1:0),H=$e(d.category),k=q(d),et=k==="claude",S=!Z(d),y=d.replies?.length?d.replies[d.replies.length-1]:d.note?{author:"claude",text:d.note}:{author:"you",text:d.text};return`<div class="dt-hist-row is-${k}${S?" is-orphan":""}">
76
- <button class="dt-hist-go" data-go="${d.id}">
77
- <span class="dt-hist-n" style="--cat:${H.color}">${et?Lt(8):""}</span>
78
- <span class="dt-hist-body">
79
- <span class="dt-hist-id">#${n.get(d.id)}<em>${H.label}</em>${et?`<b class="dt-hist-claude" data-unmark="${d.id}" role="button" tabindex="0" title="Resolved by ${g(ct(d.doneAgent,d.doneFor))} \u2014 click to clear: back to open">${Lt(9)}${g(Ds(d.doneAgent))}<i aria-hidden="true">\xD7</i></b>`:""}${S?'<b class="dt-hist-orphan" title="The element this was pinned to is not on the page right now">no pin</b>':""}</span>
80
- <span class="dt-hist-text">${y.author==="claude"?`<b>${g(ct(y.agent,y.by))}:</b> `:""}${g(y.text)}</span>
81
- <span class="dt-hist-meta">${Cn(d.updatedAt||d.createdAt)}${d.device?` \xB7 ${g(d.device)}`:d.browser?` \xB7 ${g(d.browser)}`:""}${$?` \xB7 ${$} repl${$===1?"y":"ies"}`:""}</span>
82
- </span>
83
- </button>
84
- <span class="dt-note-tools dt-hist-tools">${ss(k,d.id)}<i class="dt-note-sep"></i
85
- ><button data-rm="${d.id}" title="Delete this comment">${Pt}</button></span>
86
- </div>`},a=R.find(d=>d.id===t),l=R.map(d=>{const $=b.filter(H=>ot(H)===d.id&&q(H)!=="done");return{band:d,open:$.filter(H=>q(H)==="open").length,total:$.length}}).filter(d=>d.total&&d.band.id!==t),u=l.length?`<i class="dt-hist-sep"></i><div class="dt-hist-bands">${l.map(({band:d,open:$,total:H})=>`<button data-bp="${d.id}" data-state="${$?"open":"claude"}"
87
- title="${d.label}: ${$} open \xB7 ${H-$} to check"
88
- ><svg viewBox="0 0 20 20" width="11" height="11" aria-hidden="true">${d.icon}</svg><i>${H}</i></button>`).join("")}</div>`:"",r=["open","claude","done"].filter(d=>s[d].length&&(d!=="done"||X)),m=B.hidden?es():Ke,E=d=>`<div class="dt-hist-row is-draft">
89
- <button class="dt-hist-go" data-draft-go="${d.i}">
90
- <span class="dt-hist-n">${Ie}</span>
91
- <span class="dt-hist-body">
92
- <span class="dt-hist-id">${g(d.el)}${d.orphan?'<b class="dt-hist-orphan" title="The element this was pinned to is not on the page right now">no pin</b>':""}</span>
93
- <span class="dt-hist-text">${d.text?g(d.text):`${d.shots} screenshot${d.shots===1?"":"s"}`}</span>
94
- </span>
95
- </button>
96
- <span class="dt-note-tools dt-hist-tools"><button data-draft-rm="${d.i}" title="Discard this draft">${Pt}</button></span>
97
- </div>`;W.innerHTML=`<div class="dt-hist-head">
98
- <span class="dt-hist-here" title="${a?.label??t}"
99
- ><svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true">${a?.icon??""}</svg></span>
100
- <span class="dt-hist-title">Comments</span>
101
- ${u}
102
- ${yt().length&&!w?`<button class="dt-review-btn" data-review aria-label="Check all ${yt().length} ${yt().length===1?"fix":"fixes"}" data-tip="${yt().length} ${yt().length===1?"fix waits":"fixes wait"} for a look across every page \u2014 walk through them">${jt}${yt().length}</button>`:""}
103
- <button class="dt-hist-refresh" data-refresh aria-label="Reload comments from the file">
104
- <svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M16 10a6 6 0 1 1-1.8-4.3"/><path d="M16.3 3.4v3.4h-3.4"/></svg>
105
- </button>
106
- <button class="dt-hist-fold" data-fold aria-label="Collapse or expand the panel">
107
- <svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M5.5 8.5 10 12.5l4.5-4"/></svg>
108
- </button>
109
- </div>`+(r.length||m.length?`<div class="dt-hist-list">${m.length?`<p class="dt-hist-group">Drafts<em>${m.length}</em></p>${m.map(E).join("")}`:""}${r.map(d=>`<p class="dt-hist-group">${ia[d]}<em>${s[d].length}</em></p>`+s[d].map(o).join("")).join("")}</div>`:`<p class="dt-hist-empty">${s.done.length?"Everything here is resolved.":"No comments at this breakpoint yet. Click anything on the page to leave one."}</p>`)+`<div class="dt-hist-foot">
110
- <button class="dt-hist-resolved" data-resolved role="switch" aria-checked="${X}"
111
- ><svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="10" cy="10" r="7.5"/><path d="M6.8 10.2 9 12.4l4-4.4" stroke-linejoin="round"/></svg
112
- ><span>Show resolved</span><kbd>R</kbd><i class="dt-hist-switch" aria-hidden="true"></i></button>
113
- </div>`},We=t=>W.toggleAttribute("data-collapsed",t);W.addEventListener("click",async t=>{const e=t.target.closest("[data-refresh]");if(e){e.dataset.spin="1",await he(),setTimeout(()=>delete e.dataset.spin,500);return}if(W.hasAttribute("data-collapsed")&&t.target.closest(".dt-hist-head")){We(!1);return}if(t.target.closest("[data-fold]")){We(!W.hasAttribute("data-collapsed"));return}const n=t.target.closest(".dt-hist-bands [data-bp]");if(n){rn(n.dataset.bp);return}const s=t.target.closest("[data-draft-go], [data-draft-rm]");if(s){const r=s.dataset.draftRm!==void 0,m=Number(r?s.dataset.draftRm:s.dataset.draftGo);B.hidden?r?is(m):Ue(m):P(r?{dropDraft:m}:{openDraft:m});return}const o=t.target.closest("[data-unmark]");if(o){t.stopPropagation(),await Tt(Number(o.dataset.unmark),!1);return}const a=t.target.closest(".dt-hist-tools [data-act]");if(a){await Tt(Number(a.dataset.id),a.dataset.act==="done");return}const l=t.target.closest("[data-rm]");if(l){v=null,await os(Number(l.dataset.rm));return}if(t.target.closest("[data-review]")){Fo();return}if(t.target.closest("[data-resolved]")){Ye(!X);return}const u=t.target.closest("[data-go]");if(!u)return;const i=Number(u.dataset.go);if(!B.hidden){P({open:i});return}_e(i)});const _e=t=>{v=t,V(),h();const e=b.find(s=>s.id===t),n=e&&Z(e);n?scrollTo({top:scrollY+n.y-innerHeight/2,behavior:"smooth"}):e&&Y(e)?.scrollIntoView({block:"center",behavior:"smooth"}),f.querySelector(`.dt-pin[data-id="${t}"]`)?.animate([{transform:"scale(1)"},{transform:"scale(1.5)"},{transform:"scale(1)"}],400)},Ue=t=>{const[e]=I.splice(t,1);if(!e)return;V(),c=e,v=null;const n=Z(e);n&&(n.y<0||n.y>innerHeight)&&scrollTo({top:scrollY+n.y-innerHeight/3,behavior:"instant"}),h()},is=t=>{I.splice(t,1),h()},ze="nm-review",ue=()=>{try{return JSON.parse(sessionStorage.getItem(ze)||"null")}catch{return null}},Mt=t=>{try{t?sessionStorage.setItem(ze,JSON.stringify(t)):sessionStorage.removeItem(ze)}catch{}},D=document.createElement("div");D.className="dt-review",D.setAttribute("role","region"),D.setAttribute("aria-label","Checking fixes"),D.hidden=!0,w||document.body.append(D);const yt=()=>Q.filter(t=>q(t)==="claude"),Fo=()=>{const t=yt().sort((e,n)=>+(n.route===_)-+(e.route===_)||String(e.route).localeCompare(String(n.route))||e.id-n.id).map(e=>e.id);t.length&&(Mt({ids:t,i:0}),me())},me=()=>{const t=ue();if(!t||w){D.hidden=!0;return}for(;t.i<t.ids.length&&q(Q.find(s=>s.id===t.ids[t.i])??{status:"done"})!=="claude";)t.i++;if(t.i>=t.ids.length){Mt(null),D.hidden=!0,O("Every fix is checked.");return}Mt(t);const e=Q.find(s=>s.id===t.ids[t.i]);if(e.route&&e.route!==_){location.assign(e.route+location.search);return}if(A||mt(!0),ot(e)!==oe()){rn(ot(e));for(const s of[600,1500])setTimeout(()=>P({open:e.id}),s)}else _e(e.id);const n=t.ids.slice(0,t.i).some(s=>q(Q.find(o=>o.id===s)??{status:"done"})==="claude");D.innerHTML=`<b><span class="dt-review-dot" aria-hidden="true"></span>Check fixes</b>
114
- <span class="dt-review-nav"><button data-r="prev" aria-label="Previous fix" data-tip="Previous \xB7 \u2190"${n?"":" disabled"}>${no}</button>
115
- <span class="dt-review-n">${t.i+1} of ${t.ids.length}</span>
116
- <button data-r="skip" aria-label="Next fix" data-tip="Next \xB7 \u2192">${so}</button></span>
117
- <span class="dt-review-text">${g(wt(e.text).slice(0,90))}</span>
118
- <button data-r="ok" class="dt-review-ok" aria-label="Looks right \u2014 mark it resolved" data-tip="Looks right \u2014 resolve it">${jt}</button>
119
- <button data-r="no" aria-label="Reopen" data-tip="Not yet \u2014 reopen it">${oo}</button>
120
- <button data-r="stop" aria-label="Stop checking" data-tip="Stop checking">${ie}</button>`,D.hidden=!1};D.addEventListener("click",async t=>{const e=t.target.closest("[data-r]"),n=ue();if(!e||!n)return;if(e.dataset.r==="stop"){Mt(null),D.hidden=!0;return}if(e.dataset.r==="prev"){rs();return}const s=n.ids[n.i];Mt({...n,i:n.i+1});const o=e.dataset.r==="ok"?Tt(s,!0):e.dataset.r==="no"?Tt(s,!1):null;me(),await o});const rs=()=>{const t=ue();if(t){for(let e=t.i-1;e>=0;e--)if(q(Q.find(n=>n.id===t.ids[e])??{status:"done"})==="claude"){Mt({...t,i:e}),me();return}}};document.addEventListener("keydown",t=>{D.hidden||t.metaKey||t.ctrlKey||t.altKey||t.key!=="ArrowLeft"&&t.key!=="ArrowRight"||t.target.closest?.("input, textarea, select, [contenteditable]")||(t.preventDefault(),t.key==="ArrowLeft"?rs():D.querySelector('[data-r="skip"]')?.click())});const Ko=t=>{W.hidden=!t,te.setAttribute("aria-pressed",String(t)),J("dt-history",t?"1":"0"),h()},Ve=document.querySelector(".dt-resolved-btn"),Ye=t=>{X=t,Ve.setAttribute("aria-pressed",String(t)),J("dt-resolved",t?"1":"0"),P({resolved:t}),h(),pe()};Ve.addEventListener("click",()=>Ye(!X)),Ve.setAttribute("aria-pressed",String(X)),te.addEventListener("click",()=>{const t=W.hidden===!0;t&&!A&&mt(!0),t&&We(!1),Ko(t)});const ut=()=>{Be||!A||(Be=requestAnimationFrame(()=>{Be=0,Po()}))},ls=new MutationObserver(t=>{t.every(e=>e.target.closest?.(".dt-notes-overlay"))||ut()}),ds=new ResizeObserver(()=>ut());let Q=[];const cs=t=>{Q=t;const e=()=>({open:0,claude:0,done:0}),n={};for(const u of t){const i=q(u),r=n[u.route??""]??={...e(),bands:{}};r[i]++;const m=ot(u);(r.bands[m]??=e())[i]++}const s=["open","claude","done"],o={open:"open",claude:"resolved by an agent, to check",done:"resolved"},a=u=>s.map(i=>[i,i==="done"&&!X?0:u[i]]),l=u=>a(u).reduce((i,[,r])=>i+r,0);for(const u of document.querySelectorAll(".dt-pages a")){const i=u.querySelector(".dt-pages-n");if(!i)continue;const r=n[new URL(u.href).pathname.replace(/\/+$/,"")||"/"];for(const d of R){const $=r?.bands[d.id];for(const[H,k]of a($??e())){const et=i.querySelector(`[data-bp="${d.id}"][data-state="${H}"]`);et.hidden=!k,k&&(et.querySelector("i").textContent=String(k),et.title=`${d.label}: ${k} ${o[H]}`)}}const m=r?l(r):0;i.hidden=!m;const E=r?R.filter(d=>r.bands[d.id]&&l(r.bands[d.id])).map(d=>`${d.label} ${l(r.bands[d.id])}`).join(" \xB7 "):"";i.title=m?`${r.open} open \xB7 ${r.claude} resolved by an agent, to check \xB7 ${r.done} resolved
121
- ${E}`:""}},Wt=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"):[]})),pe=async()=>{try{cs(Wt((await(await C("comments")).json()).comments)),!W.hidden&&!w&&h()}catch{}};let _t=null,Ut=null;const vt=document.querySelector(".dt-turbo"),Je="/notemend:turbo",zt=()=>{const t=!!_t&&Date.now()-Date.parse(_t.at)<18e4,e=t?Ut?.paused?"paused":"on":"none",n=t?Ds(_t.agent):"",s=e==="none"?`Turbo is off. Run ${Je} in Claude Code and comments for the agent are taken as they land \u2014 click to copy it`:e==="on"?`Turbo on: ${n} takes comments for the agent as they land \u2014 click to pause`:`Turbo paused: ${n} is listening but waits \u2014 click to resume`;vt.dataset.state=e,vt.dataset.tip=s,vt.setAttribute("aria-label",s),vt.setAttribute("aria-checked",String(e==="on")),w&&(vt.hidden=!0)};setInterval(zt,3e4),vt.addEventListener("click",async()=>{const t=vt.dataset.state;if(t==="none"){await navigator.clipboard?.writeText(Je).catch(()=>{}),O(`Copied ${Je} \u2014 paste it in Claude Code`);return}const e=t==="on"?"off":"on";Ut={paused:e==="off"},zt();try{const n=await C("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({turbo:e})});if(!n.ok)throw new Error(String(n.status));O(e==="off"?"Turbo paused":"Turbo on")}catch{Ut={paused:e==="on"},zt(),O("Could not switch turbo \u2014 try again")}});let ge="",Ge=!1;const Vt=async()=>{if(!(document.hidden||Ge)){Ge=!0;try{const t=await C(`comments${ge?`?since=${ge}`:""}`);if(t.status!==200)return;const e=await t.json();ge=e.version??"",_t=e.listening??null,Ut=e.turbo??null,zt();const n=Wt(e.comments);cs(n);const s=n.filter(o=>o.route===_);if(JSON.stringify(s)===JSON.stringify(b))return;if(f.contains(document.activeElement)&&document.activeElement.matches("textarea, input")){ge="",setTimeout(Vt,5e3);return}b=s,h(),P({reload:!0})}catch{}finally{Ge=!1}}},$t=async()=>{try{const e=await(await C(`comments?route=${encodeURIComponent(_)}`)).json();b=Wt(e.comments),_t=e.listening??null,Ut=e.turbo??null,zt()}catch{b=[]}h()};let Xe=0;const us=t=>{Xe||(Xe=requestAnimationFrame(()=>{Xe=0;const e=t.target;if(!A||e.closest(Me)){ht.hidden=!0;return}ht.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(ht.hidden=!1,!n)return;const s=n.getBoundingClientRect();Ys.style.cssText=`left:${s.left}px;top:${s.top}px;width:${s.width}px;height:${s.height}px`,Tn.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)}`,Tn.style.cssText=`left:${s.left}px;top:${Math.max(2,s.top-20)}px`}))},ms=t=>{if(!(t.key!=="Escape"||t.isComposing)){if(t.preventDefault(),x){x=null,h();return}if(c){V(),h();return}if(v!==null){v=null,h();return}mt(!1)}},ps=["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend"],gs=t=>{t.target.closest?.(Me)||t.stopPropagation()},hs=t=>{if(t.target.closest(Me))return;if(t.preventDefault(),t.stopPropagation(),Te){Te=!1;return}if(!getSelection()?.isCollapsed)return;f.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(f.hidden=!1,!n)return;V();const s=n.getBoundingClientRect(),o=n.tagName.toLowerCase(),a=[...n.classList].filter(l=>!/^(astro|svelte|css)-/.test(l)).slice(0,2);c={selector:Qs(n),tag:o,classes:a,nth:to({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:wt(n.textContent||"").slice(0,60),ctx:eo(n),category:hn[0].id},bs.set(c,Ze(n)),v=null,ht.hidden=!0,h()},Wo=2200,_o=900*1024,fs=8*1024*1024,Uo=1200,zo=1600,Ze=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,l]=(getComputedStyle(e).color.match(/[\d.]+/g)??["0","0","0"]).map(Number);s=.299*o+.587*a+.114*l>140?"#111":"#fff"}try{const{domToWebp:o}=await import("modern-screenshot"),a=Math.min(devicePixelRatio||1,2,Uo/n.width,zo/n.height),l=await Promise.race([o(e,{scale:a,quality:.8,timeout:4e3,backgroundColor:s,filter:u=>!(u instanceof Element&&u.closest(xn))}),new Promise(u=>setTimeout(()=>u(null),8e3))]);return l&&l.length<fs?l:null}catch{return null}},bs=new WeakMap,O=t=>{const e=document.createElement("div");e.className="dt-toast",e.textContent=t,document.body.append(e),setTimeout(()=>e.remove(),2800)},Vo=t=>new Promise(e=>{const n=new FileReader;n.onload=()=>e(String(n.result)),n.readAsDataURL(t)}),Yo=async t=>{const e=await createImageBitmap(t),n=Math.min(1,Wo/Math.max(e.width,e.height));if(n===1&&t.size<=_o)return e.close(),Vo(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)},Qe=async(t,e)=>{const n=[];for(const s of t){let o;try{o=await Yo(s)}catch{O("That image could not be read.");continue}if(o.length>fs){O("Screenshot is too large even after shrinking.");continue}n.push(o)}if(n.length){if(!Number(e?.dataset.id)){c&&((c.images??=[]).push(...n),h());return}z.push(...n),h(),vs(".dt-note-reply-input")}},ys=t=>[...t??[]].filter(e=>e.kind==="file"&&e.type.startsWith("image/")).map(e=>e.getAsFile()).filter(Boolean);f.addEventListener("paste",t=>{const e=ys(t.clipboardData?.items);e.length&&(t.preventDefault(),Qe(e,t.target.closest(".dt-note")))}),f.addEventListener("dragover",t=>{t.target.closest(".dt-note")&&(t.preventDefault(),t.target.closest(".dt-note").querySelector(".dt-compose")?.setAttribute("data-drop",""))}),f.addEventListener("dragleave",t=>{t.target.closest(".dt-note")?.querySelector(".dt-compose")?.removeAttribute("data-drop")}),f.addEventListener("drop",t=>{const e=t.target.closest(".dt-note");if(!e)return;t.preventDefault(),e.querySelector(".dt-compose")?.removeAttribute("data-drop");const n=ys(t.dataTransfer?.items);n.length&&Qe(n,e)});const vs=t=>{const e=f.querySelector(t);e?.focus(),e?.setSelectionRange(e.value.length,e.value.length)},$s=()=>{vs(".dt-note-edit-input"),f.querySelector(".dt-msg .dt-compose")?.scrollIntoView({block:"nearest"})},tn=t=>{t.style.overflowY="hidden",t.style.height="auto",t.style.height=`${t.scrollHeight}px`,t.style.overflowY=t.scrollHeight>t.clientHeight?"auto":"hidden"},Jo=t=>/(?:^|\s)@([^\s@]*)$/.exec(t.value.slice(0,t.selectionStart??t.value.length)),Go=t=>{t.closest(".dt-compose").querySelector(".dt-mentions")?.remove();const n=Jo(t);if(!n||!p.team?.length)return;const s=n[1].toLowerCase(),o=p.team.filter(a=>[a.name,a.nickname,a.email].some(l=>l?.toLowerCase().startsWith(s))).slice(0,5);o.length&&t.insertAdjacentHTML("afterend",`<div class="dt-mentions" role="listbox" aria-label="Mention someone">${o.map((a,l)=>`<button type="button" role="option" aria-selected="${l===0}" data-act="mention" data-handle="${g(la(a))}">${Rn(a.avatar_url,a.name||a.email)}${g(a.name||a.email)}${a.name?` <span>${g(a.email)}</span>`:""}</button>`).join("")}</div>`)},ws=(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()},Xo=(t,e)=>{if(!t){c&&(c.category=e),h();return}rt(n=>n.map(s=>s.id===t?{...s,category:e}:s),()=>C("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,category:e})}),"Changing the type")};$a(f,g,jt),f.addEventListener("change",t=>{const e=t.target.closest(".dt-cat-select");if(e){Xo(Number(e.dataset.id)||0,e.value);return}const n=t.target.closest(".dt-status-select");if(n){po(Number(n.dataset.id),n.value);return}const s=t.target.closest(".dt-for-select");if(!s)return;s.parentElement?.style.setProperty("--cat",Kt(s.value));const o=Number(s.dataset.id);if(o){const a=s.value||null;rt(l=>l.map(u=>u.id===o?{...u,assignee:a??void 0}:u),()=>C("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:o,assignee:a})}),"Reassigning");return}if(c){c.assignee=s.value;try{localStorage.setItem("nm-for",s.value)}catch{}ft()}}),f.addEventListener("input",t=>{const e=t.target.closest(".dt-suggest-input");if(e&&c?.suggest){c.suggest.to=e.value,ft(),tn(e);return}const n=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");n&&(Go(n),n.classList.contains("dt-note-input")?c&&(c.text=n.value):n.classList.contains("dt-note-edit-input")?x&&(x.text=n.value):U=n.value,ft(),n.closest(".dt-compose")?.querySelector(".dt-send")?.classList.toggle("is-ready",n.value.trim()!==""),tn(n))}),f.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(),ws(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())}),f.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"){const o=e.dataset.v==="1";s?rt(a=>a.map(l=>l.id===s?{...l,shared:o||void 0}:l),()=>C("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,shared:o})}),o?"Sharing with the client":"Keeping it to the team"):c&&(c.shared=o||void 0,ft(),h());return}if(n==="prio"){const o=e.dataset.v||null;s?rt(a=>a.map(l=>l.id===s?{...l,priority:o??void 0}:l),()=>C("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,priority:o})}),"Setting the priority"):c&&(c.priority=o??void 0,ft(),h());return}if(n==="mention"){const o=e.closest(".dt-compose")?.querySelector("textarea");o&&ws(o,e.dataset.handle);return}if(!n){if(v=v===s?null:s,v!=null&&e.dataset.off){const o=b.find(l=>l.id===s);(o&&Y(o))?.scrollIntoView({block:"nearest",inline:"center",behavior:"smooth"})}V(),h();return}if(n==="record"){xo(e.closest(".dt-note"));return}if(n==="speak"){Co(e.closest(".dt-note"),e);return}if(n==="voice-write"){qo(e);return}if(n==="voice"||n==="voice-seek"){wo(e,n==="voice-seek"?t:null);return}if(n==="attach"){const o=Object.assign(document.createElement("input"),{type:"file",accept:"image/*",multiple:!0}),a=e.closest(".dt-note");o.addEventListener("change",()=>{o.files?.length&&Qe([...o.files],a)}),o.click();return}if(n==="unshot"){s?x&&x.drop.push(e.dataset.img):(e.closest("[data-draft]")?c?.images??[]:z).splice(Number(e.dataset.i),1),h(),x&&$s();return}if(n==="edit"){const o=b.find(u=>u.id===s),a=e.dataset.at||null,l=a?o?.replies?.find(u=>u.at===a)?.text:o?.text;if(l===void 0)return;x={id:s,at:a,text:l,drop:[]},h(),$s();return}if(n==="edit-cancel"){x=null,h();return}if(n==="edit-save"){const o=x;if(!o)return;const a=o.text.trim();if(!a){f.querySelector(".dt-note-edit-input")?.focus();return}x=null;const l=u=>o.drop.includes(u.split("/").pop());await rt(u=>u.map(i=>i.id!==o.id?i:{...i,...o.at==null?{text:a}:{replies:(i.replies??[]).map(r=>r.at===o.at?{...r,text:a}:r)},images:(i.images??[]).filter(r=>!l(r))}),()=>C("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(u=>(u.ok||(x=o),u)),"Saving the edit");return}if(n==="cancel"){V(),h();return}if(n==="twin"){V(),v=Number(e.dataset.id),h();return}if(n==="discard"){c=null,h();return}if(n==="draft-open"){Ue(Number(e.dataset.i));return}if(n==="close"){v=null,h();return}if(n==="suggest"&&c){const o=Pn(Y(c));c.suggest={from:o,to:o},h();const a=f.querySelector(".dt-suggest-input");a?.focus(),a?.select();return}if(n==="unsuggest"&&c){c.suggest=null,h();return}if(n==="save"){if(!c)return;const o=c.suggest&&c.suggest.to.trim()!==c.suggest.from?{from:c.suggest.from,to:c.suggest.to.trim()}:null,a=f.querySelector(".dt-note-input").value.trim()||(o?"Change the text":"")||(c.images?.some(Pe)?Qn:"");if(!a){f.querySelector(".dt-note-input")?.focus();return}const l=c,u=bs.get(l)??Ze(Y(l)),i={...l,route:_,text:a,suggest:o,assignee:p.client?l.assignee||p.lead||void 0:l.assignee??re(),shared:p.client?!0:l.shared===!0,stage:p.client?"new":l.stage??(K(l.assignee??re())?"approved":"new"),breakpoint:dt(),browser:Zs(),device:w?Es:"",viewport:{w:innerWidth,h:innerHeight},logs:fa(),host:location.host},r={...l,id:-Date.now(),text:a,route:_,status:"open",note:"",doneBy:null,breakpoint:i.breakpoint,replies:[],images:[],createdAt:new Date().toISOString(),...o?{suggest:o}:{},by:p.me?.email,byName:p.me?.name};b=[...b,r],c=null,h();const m=await u,E=await C("comments",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...i,...m?{before:m}:{}})});if(!E.ok){b=b.filter($=>$!==r),c=l,h(),O(`Comment was not saved (${E.status}).`);return}const d=Wt([await E.json().catch(()=>null)])[0];b=b.map($=>$===r&&d?d:$),h(),he();return}if(n==="reply"){const o=f.querySelector(".dt-note-reply-input"),a=o.value.trim()||(z.some(Pe)?Qn:"");if(!a){o.focus();return}const l=z;U="",z=[];const u=b;b=b.map(m=>m.id===s?{...m,replies:[...m.replies??[],{author:"you",text:a,at:new Date().toISOString(),by:p.me?.email}]}:m),h();const i=await C("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,reply:a,images:l})});if(!i.ok){b=u,U=a,z=l,h(),O(`Reply was not sent (${i.status}).`);return}const r=Wt([await i.json().catch(()=>null)])[0];r&&(b=b.map(m=>m.id===r.id?r:m),h()),he();return}if(n==="hand"){io(s,e.dataset.v);return}v=null,n==="rm"?await os(s):await Tt(s,n==="done")});let Yt="overlay",xt="",Es="";const P=t=>{B.hidden||M.contentWindow?.postMessage({dt:!0,...t},location.origin)},Zo=()=>({notes:A,grid:!Zt.hidden,inspect:at,resolved:X,scrollbar:Yt,device:xt});addEventListener("message",t=>{if(t.origin!==location.origin||!t.data?.dt)return;const e=t.data;if(!w&&t.source===M.contentWindow){if(e.key){Bs(e.key[0],e.key[1])?.run();return}if(e.closeMenus){Bt();return}if(e.drafts){Ke=e.drafts,as(oe());return}}if(w&&typeof e.openDraft=="number"){Ue(e.openDraft);return}if(w&&typeof e.dropDraft=="number"){is(e.dropDraft);return}if(w&&typeof e.device=="string"&&(Es=e.device),w&&e.scrollbar&&document.documentElement.classList.toggle("dt-sb-classic",e.scrollbar==="classic"),e.hello&&t.source===M.contentWindow){P(Zo());return}typeof e.notes=="boolean"&&e.notes!==A&&mt(e.notes,!1),typeof e.open=="number"&&_e(e.open),typeof e.grid=="boolean"&&e.grid===Zt.hidden&&Le(e.grid),typeof e.inspect=="string"&&e.inspect!==at&&Qt(e.inspect),typeof e.resolved=="boolean"&&e.resolved!==X&&Ye(e.resolved),e.reload&&($t(),pe())});const he=async()=>{await $t(),pe(),P({reload:!0}),w&&parent.postMessage({dt:!0,reload:!0},location.origin)},mt=(t,e=!0)=>{if(A=t,Sn.setAttribute("aria-pressed",String(t)),t?!w&&W.hidden&&localStorage.getItem("dt-history")!=="0"&&(W.hidden=!1,te.setAttribute("aria-pressed","true")):(W.hidden=!0,te.setAttribute("aria-pressed","false")),J(kn,t?"1":"0"),P({notes:t}),w&&e&&parent.postMessage({dt:!0,notes:t},location.origin),f.hidden=!t||!B.hidden,document.documentElement.classList.toggle("dt-noting",t),t){Qt(""),document.addEventListener("click",hs,!0);for(const n of ps)document.addEventListener(n,gs,!0);document.addEventListener("keydown",ms),document.addEventListener("mousemove",us),addEventListener("scroll",ut,!0),addEventListener("resize",ut),ls.observe(document.body,{childList:!0,subtree:!0,characterData:!0}),ds.observe(document.body),$t()}else{V(),v=null,document.removeEventListener("click",hs,!0);for(const n of ps)document.removeEventListener(n,gs,!0);document.removeEventListener("keydown",ms),document.removeEventListener("mousemove",us),ht.hidden=!0,removeEventListener("scroll",ut,!0),removeEventListener("resize",ut),ls.disconnect(),ds.disconnect(),f.innerHTML=""}},fe="dt-w",en="dt-canvas",kt="dt-device";let pt=localStorage.getItem(en)==="1",L=localStorage.getItem(kt)||"";L&&!Xt(L)&&(L="",localStorage.setItem(kt,""));let N=Number(localStorage.getItem(fe))||0;const Ss="dt-emu";let j=(()=>{try{return JSON.parse(localStorage.getItem(Ss)||"null")}catch{return null}})();const be=()=>j?Ps.find(t=>t.id===j.id)??null:null,Qo=()=>{const t=be();return t?j.turned?{w:t.h,h:t.w}:{w:t.w,h:t.h}:null};let Jt=localStorage.getItem("dt-bars-min")==="1";const Ht=t=>{j=t,J(Ss,t?JSON.stringify(t):"")},nn=t=>{Mn.textContent=t,B.style.setProperty("--dt-badge-w",`${Mn.offsetWidth}px`)},Ls=t=>{if(!t){Rt.innerHTML="";return}let e="";for(let n=0;n<=t;n+=50)e+=`<span class="dt-tick${n%200===0?" is-major":""}" style="left:${n}px"></span>`;for(const n of R)for(const s of[n.min,n.max])s>0&&Number.isFinite(s)&&s<=t&&(e+=`<span class="dt-edge" style="left:${s}px" title="${n.label} edge"></span>`);Rt.innerHTML=e,Rt.style.width=`${t}px`},sn=()=>{const t=parseFloat(T.style.width)||0,e=parseFloat(T.style.height)||0;if(!t||!e){T.style.transform="",delete T.dataset.scaled;return}const n=L||j?Math.min(1,(innerWidth-80)/t,(innerHeight-120)/e):Math.min(1,(innerWidth-80)/t);T.style.transform=n<1?`scale(${n})`:"",T.dataset.scaled=n<1?String(Math.round(n*100)):""},ta=t=>Ps.find(e=>e.w===t.w&&e.h===t.h&&e.cutout?.shape==="pill")?.cutout,ye=()=>{try{return M.contentDocument}catch{return null}},Ts=()=>ye()?.title.split("\u2014").pop()?.trim()||"",on=()=>{const t=ye(),e=L?Xt(L):null;if(!t?.body||!e)return;const n=ha(t),s=e.browser==="chrome-android"?n.theme||"rgb(255, 255, 255)":n.top,o=e.browser==="chrome-android"?"rgb(255, 255, 255)":n.bottom;T.style.setProperty("--dt-top",s),T.style.setProperty("--dt-top-ink",js(s)),T.style.setProperty("--dt-bottom",o),T.style.setProperty("--dt-bottom-ink",js(o));const a=qt.querySelector(".dt-win-tab > span");a&&(a.textContent=Ts()||location.host)};let an=0;M.addEventListener("load",()=>{ye()&&(on(),M.contentWindow?.addEventListener("scroll",()=>{an||(an=requestAnimationFrame(()=>{an=0,on()}))},{passive:!0}))});for(const t of[qt,ee])t.addEventListener("click",e=>{const n=e.target.closest("[data-nav]")?.dataset.nav;if(n)try{const s=M.contentWindow?.navigation;if(!ye()||!s)throw new Error("foreign");n==="back"?s.canGoBack&&s.back():n==="fwd"?s.canGoForward&&s.forward():s.reload()}catch{(n==="reload"||n==="back")&&(M.src=location.href)}});It.addEventListener("click",()=>{Jt=!Jt,J("dt-bars-min",Jt?"1":"0"),lt()});const lt=()=>{if(w)return;const t=L?Xt(L)??null:null;if(L&&!t&&(L="",localStorage.setItem(kt,"")),!t&&!pt){B.hidden=!0,M.removeAttribute("src"),document.documentElement.classList.remove("dt-framing"),f.hidden=!A,Rt.innerHTML="",Ot(),Ne.hidden=!0,It.hidden=!0,it=null,xt="",Ke=[],Ot(),dn(),A?$t():h();return}if(B.hidden=!1,document.documentElement.classList.add("dt-framing"),f.hidden=!0,M.src||(M.src=location.href),t){const e=ga(t,{host:location.host,title:Ts(),now:new Date,min:Jt,cutout:ta(t)}),{screen:n}=e;B.dataset.mode="device",T.dataset.shell=t.shell,T.dataset.browser=t.browser,T.style.width=`${e.footprint.w}px`,T.style.height=`${e.footprint.h}px`,T.style.setProperty("--dt-r",`${n.r}px`),T.style.setProperty("--dt-rb",`${n.rb}px`),Ln.innerHTML=e.shell;const s=(l,u,i,r)=>{l.innerHTML=r,l.style.cssText=`left:${n.x}px;top:${u}px;width:${n.w}px;height:${i}px`};s(qt,n.y,e.topH,e.top),s(ee,n.y+n.h-e.bottomH,e.bottomH,e.bottom);const o=n.h-e.topH-e.bottomH;M.style.position="absolute",M.style.left=`${n.x}px`,M.style.top=`${n.y+e.topH}px`,M.style.width=`${n.w}px`,M.style.height=`${o}px`,Rt.innerHTML="";const a=Jt&&e.canMinimize;Yt=e.scrollbar,xt=`${t.label}${a?" \xB7 bars folded":""}`,it=Ct(t.w),P({notes:A,scrollbar:Yt,device:xt}),It.hidden=!e.canMinimize,It.setAttribute("aria-pressed",String(a)),nn(`${t.label} \xB7 page ${t.w}\xD7${o} of ${t.w}\xD7${t.h}${a?" \xB7 bars folded":""} \xB7 ${R.find(l=>l.id===it)?.label??""}`),on()}else{const e=Qo();e||Ht(null);const n=e?.w||N||R.find(a=>a.id===dt()).ideal;N=n,B.dataset.mode="canvas",delete T.dataset.shell,delete T.dataset.browser,Ln.innerHTML=qt.innerHTML=ee.innerHTML="",qt.style.cssText=ee.style.cssText="",It.hidden=!0,Yt="overlay",T.style.width=`${n}px`,T.style.height=`${e?.h??innerHeight-84}px`,M.style.position="",M.style.left=M.style.top="",M.style.width="100%",M.style.height="100%",Ls(n),P({notes:A});const s=R.find(a=>a.id===Ct(n)),o=be();xt=o?`${o.label}${j?.turned?" \xB7 landscape":""}`:"",P({scrollbar:Yt,device:xt}),nn(o&&e?`${o.label} \xB7 ${e.w}\xD7${e.h} \xB7 ${s.label}`:`${n}px \xB7 ${s.label}`),it=Ct(n)}Ne.hidden=!(be()?.rotates&&!t),dn(),sn(),Ot(),A?$t():h()},rn=t=>{const e=R.find(n=>n.id===t);L="",localStorage.setItem(kt,""),Ht(null),pt=t!==Ee,N=pt?e.ideal:0,it=pt?t:null,localStorage.setItem(en,pt?"1":"0"),localStorage.setItem(fe,String(N)),v=null,V(),lt()};for(const t of He)t.addEventListener("click",()=>rn(t.dataset.bp));for(const t of document.querySelectorAll("[data-device]"))t.addEventListener("click",()=>{L=t.dataset.device===L?"":t.dataset.device,localStorage.setItem(kt,L),G.open=!1,lt()});for(const t of document.querySelectorAll("[data-emu]"))t.addEventListener("click",()=>{const e=j?.id===t.dataset.emu&&!L;L="",localStorage.setItem(kt,""),Ht(e?null:{id:t.dataset.emu,turned:!1}),pt=!e,N=0,localStorage.setItem(en,pt?"1":"0"),it=null,v=null,V(),G.open=!1,lt()});Ne.addEventListener("click",()=>{j&&(Ht({...j,turned:!j.turned}),v=null,V(),lt())});const Ms=[...G.querySelectorAll("[data-tab]")],ea=[...G.querySelectorAll("[data-panel]")],xs=t=>{for(const e of Ms)e.setAttribute("aria-selected",String(e.dataset.tab===t));for(const e of ea)e.hidden=e.dataset.panel!==t;J("dt-devices-tab",t)};for(const t of Ms)t.addEventListener("click",()=>xs(t.dataset.tab));xs(localStorage.getItem("dt-devices-tab")==="devtools"?"devtools":"preview");const ln=G.querySelector(".dt-emu-search");ln.addEventListener("input",()=>{const t=ln.value.trim().toLowerCase();let e=null,n=!1;const s=()=>{e&&(e.hidden=!n)};for(const o of ln.parentElement.children){if(o.classList.contains("dt-devices-group")){s(),e=o,n=!1;continue}o.dataset.emu&&(o.hidden=!!t&&!o.textContent.toLowerCase().includes(t),n||=!o.hidden)}s()});const na=G.querySelector(".dt-devices-name");function dn(){for(const e of G.querySelectorAll("[data-device]"))e.setAttribute("aria-pressed",String(e.dataset.device===L));const t=!L&&!B.hidden?j?.id:void 0;for(const e of G.querySelectorAll("[data-emu]"))e.setAttribute("aria-pressed",String(e.dataset.emu===t));na.textContent=L&&Xt(L)?.label||t&&be()?.label||"Device"}const cn=t=>R.find(e=>e.id===t),sa=t=>{const e=cn(it??dt());return Math.max(e.min||320,Math.min(Number.isFinite(e.max)?e.max:2560,Math.round(t)))};for(const t of Js){const e=t.dataset.edge==="l"?-1:1;t.addEventListener("pointerdown",n=>{if(L)return;n.preventDefault(),j&&(Ht(null),lt()),t.setPointerCapture(n.pointerId);const s=n.clientX,o=N,a=Number(T.dataset.scaled||100)/100;B.dataset.dragging="1";const l=i=>{N=sa(o+e*(i.clientX-s)*2/a),T.style.width=`${N}px`,Ls(N),nn(`${N}px \xB7 ${cn(Ct(N)).label}`),sn()},u=()=>{t.removeEventListener("pointermove",l),t.removeEventListener("pointerup",u),delete B.dataset.dragging,localStorage.setItem(fe,String(N)),lt()};t.addEventListener("pointermove",l),t.addEventListener("pointerup",u)}),t.addEventListener("dblclick",()=>{if(L)return;Ht(null);const n=cn(it??dt()),s=[n.min||320,Number.isFinite(n.max)?n.max:n.ideal];N=Math.abs(N-s[0])<Math.abs(N-s[1])?s[0]:s[1],localStorage.setItem(fe,String(N)),lt()})}let ks=dt();addEventListener("resize",()=>{Ot(),dt()!==ks&&(ks=dt(),h()),B.hidden||(!L&&!j&&(T.style.height=`${innerHeight-84}px`),sn())});const Hs="dt-studio",As=t=>{Ae.setAttribute("aria-pressed",String(t)),document.documentElement.classList.toggle("dt-no-studio",!t),J(Hs,t?"1":"0")};Ae.addEventListener("click",()=>As(Ae.getAttribute("aria-pressed")!=="true")),As(localStorage.getItem(Hs)!=="0"),Sn.addEventListener("click",()=>mt(!A));const At=document.querySelector(".devtools"),Gt=document.querySelector(".dt-tab"),Ns=t=>{At.toggleAttribute("data-collapsed",t),Gt.toggleAttribute("data-collapsed",t),Gt.setAttribute("aria-expanded",String(!t)),Gt.setAttribute("aria-label",t?"Show the bar":"Hide the bar");for(const e of At.querySelectorAll(".dt-group"))e.inert=t;t&&Bt(),J("dt-collapsed",t?"1":"0")};Gt.addEventListener("click",()=>Ns(!At.hasAttribute("data-collapsed")));const un=document.querySelector(".dt-keys"),tt=t=>()=>At.querySelector(t)?.click(),Cs=t=>()=>{const e=[...document.querySelectorAll(".dt-pages a")];e[e.findIndex(n=>n.hasAttribute("aria-current"))+t]?.click()},ve=[{group:"Comments",code:"KeyC",hint:"C",label:"Comment mode",el:".dt-notes-btn",run:tt(".dt-notes-btn")},{group:"Comments",code:"KeyC",shift:!0,hint:"\u21E7C",label:"Comments panel",el:".dt-history-btn",run:tt(".dt-history-btn")},{group:"Comments",code:"KeyR",hint:"R",label:"Show resolved",el:".dt-resolved-btn",run:tt(".dt-resolved-btn")},{group:"Inspect",code:"KeyG",hint:"G",label:"Grid",el:".dt-grid-btn",run:tt(".dt-grid-btn")},{group:"Inspect",code:"KeyP",hint:"P",label:"Spacing",el:".dt-pad-btn",run:tt(".dt-pad-btn")},{group:"Inspect",code:"KeyS",hint:"S",label:"Size",el:".dt-size-btn",run:tt(".dt-size-btn")},{group:"Inspect",code:"KeyT",hint:"T",label:"Typography",el:".dt-type-btn",run:tt(".dt-type-btn")},{group:"Inspect",code:"KeyO",hint:"O",label:"Color",el:".dt-color-btn",run:tt(".dt-color-btn")},{group:"Inspect",code:"KeyB",hint:"B",label:"Border & radius",el:".dt-border-btn",run:tt(".dt-border-btn")},...p.sanity?[{group:"Inspect",code:"KeyE",hint:"E",label:"Sanity overlay",el:".dt-studio-btn",run:tt(".dt-studio-btn")}]:[],...He.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:()=>{G.open=!G.open}},{group:"View",code:"BracketLeft",hint:"[",label:"Previous page",run:Cs(-1)},{group:"View",code:"BracketRight",hint:"]",label:"Next page",run:Cs(1)},{group:"View",code:"Backslash",hint:"\\",label:"Hide the bar",run:()=>Gt.click()},{group:"View",code:"Slash",shift:!0,hint:"?",label:"This list",el:".dt-keys summary",run:()=>{un.open=!un.open}}].filter(t=>!p.client||t.group!=="Inspect"),Bs=(t,e)=>ve.find(n=>n.code===t&&!n.shift==!e),oa=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(p.shortcuts){for(const e of ve){const n=e.el&&At.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>${g(e)}</span><kbd>${g(n)}</kbd></div>`;if(un.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(ve.map(e=>e.group))].map(e=>`<p class="dt-devices-group">${e}</p>`+ve.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||oa(e.target))return;const n=Bs(e.code,e.shiftKey);n&&(e.preventDefault(),w?parent.postMessage({dt:!0,key:[e.code,e.shiftKey]},location.origin):n.run())}),w){const e=()=>parent.postMessage({dt:!0,closeMenus:!0},location.origin);document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",n=>{n.key==="Escape"&&e()})}}if(!w){Ns(localStorage.getItem("dt-collapsed")==="1"),requestAnimationFrame(()=>requestAnimationFrame(()=>At.setAttribute("data-ready",""))),pt||L?lt():dn(),Le(localStorage.getItem(bn)==="1");const t=localStorage.getItem(wn);t&&t in xe&&Qt(t),mt(localStorage.getItem(kn)==="1")}const qs=()=>{try{const t=JSON.parse(localStorage.getItem(St)||"null");I=(t?.parked??[]).filter(e=>ne(e)),t?.draft&&document.querySelector(t.draft.selector)?(c=t.draft,!A&&!w&&mt(!0)):ne(t?.draft)&&I.push(t.draft),t?.reply?.text&&(U=t.reply.text,Dt=v=t.reply.for??null),(c||I.length||U)&&h()}catch{localStorage.removeItem(St)}};qs();const Rs=()=>setTimeout(()=>{const t=Se(location.pathname);t!==_&&(clearTimeout(se),qe(),_=t,St=Hn(),c=null,I=[],U="",Dt=null,v=null,x=null,b=[],vn(),qs(),$t())});for(const t of["pushState","replaceState"]){const e=window.history[t];window.history[t]=function(...n){e.apply(this,n),Rs()}}addEventListener("popstate",Rs),A||$t(),pe().then(()=>{ue()&&me()}),document.addEventListener("visibilitychange",()=>{document.hidden||Vt()}),addEventListener("focus",Vt),addEventListener("notemend:changed",()=>{w||Vt()});let aa=0;w||setInterval(()=>{(!ma.live||++aa%6===0)&&Vt()},2e4),w&&parent.postMessage({dt:!0,hello:!0},location.origin)}export{Na as run};
70
+ ${xn("dt-note-input",l.suggest?"Why (optional)":"Comment",l.text??"",'data-act="save"',Mn(l.images),Qs&&!l.suggest&&pn(a?q(l):null)?`<button class="dt-attach" data-act="suggest" title="Rewrite this text: start from its current words and change them">${ro}</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)),p=h.contains(document.activeElement)&&document.activeElement.matches(".dt-note-reply-input");h.innerHTML=s,p&&zt(".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")}On(n),me(on()),X();for(const r of h.querySelectorAll(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input"))Re(r);const m=h.querySelector(".dt-note-input");m&&(m.focus(),m.setSelectionRange(m.value.length,m.value.length))},Lo=()=>{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&&D(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),sn(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&&D(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=on();e&&sn(e)&&me(e)}t&&X()},ko=t=>b.filter(e=>J(e)===J(t)).findIndex(e=>e.id===t.id)+1,On=t=>{H.hidden||(H.innerHTML=da({bp:t,notes:b,breakpoints:dt,bandOfNote:J,orphan:e=>!D(e),whoseAgent:at,statusTools:Nn,showResolved:W,drafts:st.hidden?An():$e,checks:E?0:Le.toCheck().length}))},Se=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 Yt(),setTimeout(()=>delete e.dataset.spin,500);return}if(H.hasAttribute("data-collapsed")&&t.target.closest(".dt-hist-head")){Se(!1);return}if(t.target.closest("[data-fold]")){Se(!H.hasAttribute("data-collapsed"));return}const n=t.target.closest(".dt-hist-bands [data-bp]");if(n){Qn(n.dataset.bp);return}const s=t.target.closest("[data-draft-go], [data-draft-rm]");if(s){const m=s.dataset.draftRm!==void 0,r=Number(m?s.dataset.draftRm:s.dataset.draftGo);st.hidden?m?Bn(r):Me(r):B(m?{dropDraft:r}:{openDraft:r});return}const o=t.target.closest("[data-unmark]");if(o){t.stopPropagation(),await St(Number(o.dataset.unmark),!1);return}const a=t.target.closest(".dt-hist-tools [data-act]");if(a){await St(Number(a.dataset.id),a.dataset.act==="done");return}const i=t.target.closest("[data-rm]");if(i){$=null,await we(Number(i.dataset.rm));return}if(t.target.closest("[data-review]")){Le.start();return}if(t.target.closest("[data-resolved]")){xe(!W);return}const d=t.target.closest("[data-go]");if(!d)return;const p=Number(d.dataset.go);if(!st.hidden){B({open:p});return}Te(p)});const Te=t=>{$=t,K(),f();const e=b.find(s=>s.id===t),n=e&&D(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)},Me=t=>{const[e]=A.splice(t,1);if(!e)return;K(),l=e,$=null;const n=D(e);n&&(n.y<0||n.y>innerHeight)&&scrollTo({top:scrollY+n.y-innerHeight/3,behavior:"instant"}),f()},Bn=t=>{A.splice(t,1),f()},Le=ca({inFrame:E,everything:()=>pt,route:()=>j,settle:St,keepIn:Ze,toast:t=>k(t),open:t=>{if(x||Q(!0),J(t)!==Bt()){Qn(J(t));for(const e of[600,1500])setTimeout(()=>B({open:t.id}),e)}else Te(t.id)}}),xo=t=>{H.hidden=!t,Ct.setAttribute("aria-pressed",String(t)),G("dt-history",t?"1":"0"),f()},ke=document.querySelector(".dt-resolved-btn"),xe=t=>{W=t,ke.setAttribute("aria-pressed",String(t)),G("dt-resolved",t?"1":"0"),B({resolved:t}),f(),Wt()};ke.addEventListener("click",()=>xe(!W)),ke.setAttribute("aria-pressed",String(W)),Ct.addEventListener("click",()=>{const t=H.hidden===!0;t&&!x&&Q(!0),t&&Se(!1),xo(t)});const X=()=>{de||!x||(de=requestAnimationFrame(()=>{de=0,Lo()}))},qn=new MutationObserver(t=>{t.every(e=>e.target.closest?.(".dt-notes-overlay"))||X()}),Dn=new ResizeObserver(()=>X());let pt=[];const In=t=>{pt=t;const e=()=>({open:0,claude:0,done:0}),n={};for(const d of t){const p=rt(d),m=n[d.route??""]??={...e(),bands:{}};m[p]++;const r=J(d);(m.bands[r]??=e())[p]++}const s=["open","claude","done"],o={open:"open",claude:"resolved by an agent, to check",done:"resolved"},a=d=>s.map(p=>[p,p==="done"&&!W?0:d[p]]),i=d=>a(d).reduce((p,[,m])=>p+m,0);for(const d of document.querySelectorAll(".dt-pages a")){const p=d.querySelector(".dt-pages-n");if(!p)continue;const m=n[new URL(d.href).pathname.replace(/\/+$/,"")||"/"];for(const g of dt){const w=m?.bands[g.id];for(const[M,C]of a(w??e())){const Z=p.querySelector(`[data-bp="${g.id}"][data-state="${M}"]`);Z.hidden=!C,C&&(Z.querySelector("i").textContent=String(C),Z.title=`${g.label}: ${C} ${o[M]}`)}}const r=m?i(m):0;p.hidden=!r;const y=m?dt.filter(g=>m.bands[g.id]&&i(m.bands[g.id])).map(g=>`${g.label} ${i(m.bands[g.id])}`).join(" \xB7 "):"";p.title=r?`${m.open} open \xB7 ${m.claude} resolved by an agent, to check \xB7 ${m.done} resolved
73
+ ${y}`:""}},Tt=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"):[]})),Wt=async()=>{try{In(Tt((await(await L("comments")).json()).comments)),!H.hidden&&!E&&f()}catch{}},Pn=ua(E,t=>k(t));let Ut="",Ae=!1;const Mt=async()=>{if(!(document.hidden||Ae)){Ae=!0;try{const t=await L(`comments${Ut?`?since=${Ut}`:""}`);if(t.status!==200)return;const e=await t.json();Ut=e.version??"",Pn(e);const n=Tt(e.comments);In(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")){Ut="",setTimeout(Mt,5e3);return}b=s,f(),B({reload:!0})}catch{}finally{Ae=!1}}},mt=async()=>{try{const e=await(await L(`comments?route=${encodeURIComponent(j)}`)).json();b=Tt(e.comments),Pn(e)}catch{b=[]}f()};let He=0;const Fn=t=>{He||(He=requestAnimationFrame(()=>{He=0;const e=t.target;if(!x||e.closest(ne)){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();Ms.style.cssText=`left:${s.left}px;top:${s.top}px;width:${s.width}px;height:${s.height}px`,Xe.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)}`,Xe.style.cssText=`left:${s.left}px;top:${Math.max(2,s.top-20)}px`}))},jn=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)}},_n=["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend"],Kn=t=>{t.target.closest?.(ne)||t.stopPropagation()},Wn=t=>{if(t.target.closest(ne))return;if(t.preventDefault(),t.stopPropagation(),ee){ee=!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:As(n),tag:o,classes:a,nth:Hs({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:ft(n.textContent||"").slice(0,60),ctx:Cs(n),category:je[0].id},zn.set(l,Ce(n)),$=null,nt.hidden=!0,f()},Ao=2200,Ho=900*1024,Un=8*1024*1024,Co=3*1024*1024,No=1200,Ro=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,No/n.width,Ro/n.height),i=await Promise.race([o(e,{scale:a,quality:.8,timeout:4e3,backgroundColor:s,filter:d=>!(d instanceof Element&&d.closest(Qe))}),new Promise(d=>setTimeout(()=>d(null),8e3))]);return i&&i.length<Un?i:null}catch{return null}},zn=new WeakMap,k=t=>{const e=document.createElement("div");e.className="dt-toast",e.textContent=t,document.body.append(e),setTimeout(()=>e.remove(),2800)},Oo=t=>new Promise(e=>{const n=new FileReader;n.onload=()=>e(String(n.result)),n.readAsDataURL(t)}),Bo=async t=>{const e=await createImageBitmap(t),n=Math.min(1,Ao/Math.max(e.width,e.height));if(n===1&&t.size<=Ho)return e.close(),Oo(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)},Ne=async(t,e)=>{const n=[];for(const s of t){let o;const a=Object.keys(kt).find(i=>kt[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,p)=>{const m=new FileReader;m.onload=()=>d(String(m.result).split(",")[1]),m.onerror=p,m.readAsDataURL(s)}).catch(()=>"");i?n.push(`data:${kt[a]};name=${Go(s.name)||"document"};base64,${i}`):k(`${s.name} could not be read.`);continue}try{o=await Bo(s)}catch{k("That image could not be read.");continue}if(o.length>Un){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(),zt(".dt-note-reply-input")}},Yn=t=>[...t??[]].filter(e=>e.kind==="file"&&(e.type.startsWith("image/")||Object.values(kt).includes(e.type))).map(e=>e.getAsFile()).filter(Boolean);h.addEventListener("paste",t=>{const e=Yn(t.clipboardData?.items);e.length&&(t.preventDefault(),Ne(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=Yn(t.dataTransfer?.items);n.length&&Ne(n,e)});const zt=t=>{const e=h.querySelector(t);e?.focus(),e?.setSelectionRange(e.value.length,e.value.length)},Vn=()=>{zt(".dt-note-edit-input"),h.querySelector(".dt-msg .dt-compose")?.scrollIntoView({block:"nearest"})},Re=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)),Do=()=>c.client||fe()?[]:cs(),Io=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=Do().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="${u(Xo(i))}">${Ft(i.avatar_url,i.name||i.email)}<span class="dt-mention-who"><b>${u(i.name||i.email)}</b>${i.name?`<span>${u(i.email)}</span>`:""}</span></button>`),...a.map(i=>`<button type="button" role="option" data-act="mention" data-handle="${u(i.handle)}">${js(i.owner)}<span class="dt-mention-who"><b>${u(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>`)},Po=t=>{const e=[...(c.team??[]).flatMap(s=>[s.name,s.nickname,s.email]),...cs().map(s=>s.handle)].filter(s=>!!s).sort((s,o)=>o.length-s.length).map(s=>u(s).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),n=u(t);return e.length?n.replace(new RegExp(`@(?:${e.join("|")})(?![\\p{L}\\p{N}_.-])`,"giu"),s=>`<span class="dt-at">${s}</span>`):n},Jn=(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()},Fo=(t,e)=>{if(!t){l&&(l.category=e),f();return}I(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")};ia(h,u,Xt);const Gn=(t,e)=>{t?I(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"?Gn(d,i==="client"):i==="rm"&&confirm("Delete this thread and its replies? This cannot be undone.")?($=null,we(d)):i==="discard"&&(l=null,f());return}const n=t.target.closest(".dt-cat-select");if(n){Fo(Number(n.dataset.id)||0,n.value);return}const s=t.target.closest(".dt-status-select");if(s){Ys(Number(s.dataset.id),s.value);return}const o=t.target.closest(".dt-for-select");if(!o)return;o.parentElement?.style.setProperty("--cat",yt(o.value));const a=Number(o.dataset.id);if(a){const i=o.value||null;I(d=>d.map(p=>p.id===a?{...p,assignee:i??void 0}:p),()=>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(),Re(e);return}const n=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");n&&(Io(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()!==""),Re(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(),Jn(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"){Gn(s,e.dataset.v==="1");return}if(n==="prio"){const o=e.dataset.v||null;s?I(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&&Jn(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"){co(e.closest(".dt-note"));return}if(n==="speak"){fo(e.closest(".dt-note"),e);return}if(n==="voice-write"){bo(e);return}if(n==="voice"||n==="voice-seek"){no(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(kt)}`,multiple:!0}),a=e.closest(".dt-note");o.addEventListener("change",()=>{o.files?.length&&Ne([...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&&Vn();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(),Vn();return}if(n==="edit-cancel"){T=null,f();return}if(n==="translate"){yo(s,e.dataset.at);return}if(n==="unsay"){const o=e.dataset.at;if(!confirm("Delete this reply?"))return;await I(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 I(d=>d.map(p=>p.id!==o.id?p:{...p,...o.at==null?{text:a}:{replies:(p.replies??[]).map(m=>m.at===o.at?{...m,text:a}:m)},images:(p.images??[]).filter(m=>!i(m))}),()=>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"){Me(Number(e.dataset.i));return}if(n==="close"){$=null,f();return}if(n==="suggest"&&l){const o=pn(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(be)?kn:"");if(!a){h.querySelector(".dt-note-input")?.focus();return}const i=l,d=c.client?null:us(a,It()),p=zn.get(i)??Ce(q(i)),m={...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??(F(i.assignee)?"approved":"new"),breakpoint:pe(),browser:xs(),device:E?Xn:"",viewport:{w:innerWidth,h:innerHeight},logs:na(),host:location.host},r={...i,id:-Date.now(),text:a,route:j,status:"open",note:"",doneBy:null,breakpoint:m.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 p,g=await L("comments",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...m,...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=Tt([await g.json().catch(()=>null)])[0];b=b.map(M=>M===r&&w?w:M),f(),Yt();return}if(n==="reply"){const o=h.querySelector(".dt-note-reply-input"),a=o.value.trim()||(O.some(be)?kn:"");if(!a){o.focus();return}const i=O;R="",O=[];const d=b,p=c.client?null:us(a,It()),m=b.find(w=>w.id===s),r=p&&m&&(p!==m.assignee||lt(m)!=="approved"||m.status==="done")?{assignee:p,stage:"approved",...m.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=Tt([await y.json().catch(()=>null)])[0];g&&(b=b.map(w=>w.id===g.id?g:w),f()),Yt();return}if(n==="hand"){Is(s,e.dataset.v);return}if(n==="sendback"){await St(s,!1),zt(".dt-note-reply-input");return}$=null,n==="rm"?await we(s):await St(s,n==="done")});let Xn="";const B=t=>{st.hidden||Nt.contentWindow?.postMessage({dt:!0,...t},location.origin)},jo=()=>({notes:x,grid:!At.hidden,inspect:_,resolved:W,...Zn.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){os(e.key[0],e.key[1])?.run();return}if(e.closeMenus){ht();return}if(e.drafts){$e=e.drafts,On(Bt());return}}if(E&&typeof e.openDraft=="number"){Me(e.openDraft);return}if(E&&typeof e.dropDraft=="number"){Bn(e.dropDraft);return}if(E&&typeof e.device=="string"&&(Xn=e.device),E&&e.scrollbar&&document.documentElement.classList.toggle("dt-sb-classic",e.scrollbar==="classic"),e.hello&&t.source===Nt.contentWindow){B(jo());return}typeof e.notes=="boolean"&&e.notes!==x&&Q(e.notes,!1),typeof e.open=="number"&&Te(e.open),typeof e.grid=="boolean"&&e.grid===At.hidden&&te(e.grid),typeof e.inspect=="string"&&e.inspect!==_&&Ht(e.inspect),typeof e.resolved=="boolean"&&e.resolved!==W&&xe(e.resolved),e.reload&&(mt(),Wt())});const Yt=async()=>{await mt(),Wt(),B({reload:!0}),E&&parent.postMessage({dt:!0,reload:!0},location.origin)},Q=(t,e=!0)=>{if(x=t,Ge.setAttribute("aria-pressed",String(t)),t?!E&&H.hidden&&localStorage.getItem("dt-history")!=="0"&&(H.hidden=!1,Ct.setAttribute("aria-pressed","true")):(H.hidden=!0,Ct.setAttribute("aria-pressed","false")),G(tn,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){Ht(""),document.addEventListener("click",Wn,!0);for(const n of _n)document.addEventListener(n,Kn,!0);document.addEventListener("keydown",jn),document.addEventListener("mousemove",Fn),addEventListener("scroll",X,!0),addEventListener("resize",X),qn.observe(document.body,{childList:!0,subtree:!0,characterData:!0}),Dn.observe(document.body),mt()}else{K(),$=null,document.removeEventListener("click",Wn,!0);for(const n of _n)document.removeEventListener(n,Kn,!0);document.removeEventListener("keydown",jn),document.removeEventListener("mousemove",Fn),nt.hidden=!0,removeEventListener("scroll",X,!0),removeEventListener("resize",X),qn.disconnect(),Dn.disconnect(),h.innerHTML=""}},{pickBp:Qn,...Zn}=la({cfg:c,inFrame:E,persist:G,frame:st,frameEl:Nt,devicesMenu:re,bpBtns:ae,notesOverlay:h,WIDE:Qt,bpOf:_e,currentBp:pe,deviceById:bs,notesOn:()=>x,filter:()=>ce,filterTo:t=>{ce=t},dropFrameDrafts:()=>{$e=[]},putAway:()=>{$=null,K()},tellFrame:B,syncBpButtons:nn,render:()=>f(),reread:()=>{x?mt():f()}}),ts="dt-studio",es=t=>{ie.setAttribute("aria-pressed",String(t)),document.documentElement.classList.toggle("dt-no-studio",!t),G(ts,t?"1":"0")};ie.addEventListener("click",()=>es(ie.getAttribute("aria-pressed")!=="true")),es(localStorage.getItem(ts)!=="0"),Ge.addEventListener("click",()=>Q(!x));const gt=document.querySelector(".devtools"),Lt=document.querySelector(".dt-tab"),ns=t=>{gt.toggleAttribute("data-collapsed",t),Lt.toggleAttribute("data-collapsed",t),Lt.setAttribute("aria-expanded",String(!t)),Lt.setAttribute("aria-label",t?"Show the bar":"Hide the bar");for(const e of gt.querySelectorAll(".dt-group"))e.inert=t;t&&ht(),G("dt-collapsed",t?"1":"0")};Lt.addEventListener("click",()=>ns(!gt.hasAttribute("data-collapsed")));const Oe=document.querySelector(".dt-keys"),P=t=>()=>gt.querySelector(t)?.click(),ss=t=>()=>{const e=[...document.querySelectorAll(".dt-pages a")];e[e.findIndex(n=>n.hasAttribute("aria-current"))+t]?.click()},Vt=[{group:"Comments",code:"KeyC",hint:"C",label:"Comment mode",el:".dt-notes-btn",run:P(".dt-notes-btn")},{group:"Comments",code:"KeyC",shift:!0,hint:"\u21E7C",label:"Comments panel",el:".dt-history-btn",run:P(".dt-history-btn")},{group:"Comments",code:"KeyR",hint:"R",label:"Show resolved",el:".dt-resolved-btn",run:P(".dt-resolved-btn")},{group:"Inspect",code:"KeyG",hint:"G",label:"Grid",el:".dt-grid-btn",run:P(".dt-grid-btn")},{group:"Inspect",code:"KeyP",hint:"P",label:"Spacing",el:".dt-pad-btn",run:P(".dt-pad-btn")},{group:"Inspect",code:"KeyS",hint:"S",label:"Size",el:".dt-size-btn",run:P(".dt-size-btn")},{group:"Inspect",code:"KeyT",hint:"T",label:"Typography",el:".dt-type-btn",run:P(".dt-type-btn")},{group:"Inspect",code:"KeyO",hint:"O",label:"Color",el:".dt-color-btn",run:P(".dt-color-btn")},{group:"Inspect",code:"KeyB",hint:"B",label:"Border & radius",el:".dt-border-btn",run:P(".dt-border-btn")},...c.sanity?[{group:"Inspect",code:"KeyE",hint:"E",label:"Sanity overlay",el:".dt-studio-btn",run:P(".dt-studio-btn")}]:[],...ae.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:()=>{re.open=!re.open}},{group:"View",code:"BracketLeft",hint:"[",label:"Previous page",run:ss(-1)},{group:"View",code:"BracketRight",hint:"]",label:"Next page",run:ss(1)},{group:"View",code:"Backslash",hint:"\\",label:"Hide the bar",run:()=>Lt.click()},{group:"View",code:"Slash",shift:!0,hint:"?",label:"This list",el:".dt-keys summary",run:()=>{Oe.open=!Oe.open}}].filter(t=>!c.client||t.group!=="Inspect"),os=(t,e)=>Vt.find(n=>n.code===t&&!n.shift==!e),_o=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 Vt){const n=e.el&&gt.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>${u(e)}</span><kbd>${u(n)}</kbd></div>`;if(Oe.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(Vt.map(e=>e.group))].map(e=>`<p class="dt-devices-group">${e}</p>`+Vt.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||_o(e.target))return;const n=os(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){ns(localStorage.getItem("dt-collapsed")==="1"),requestAnimationFrame(()=>requestAnimationFrame(()=>gt.setAttribute("data-ready",""))),Zn.restore(),te(localStorage.getItem(We)==="1");const t=localStorage.getItem(Ve);t&&t in se&&Ht(t),Q(localStorage.getItem(tn)==="1")}const as=()=>{try{const t=JSON.parse(localStorage.getItem(ut)||"null");A=(t?.parked??[]).filter(e=>Rt(e)),t?.draft&&document.querySelector(t.draft.selector)?(l=t.draft,!x&&!E&&Q(!0)):Rt(t?.draft)&&A.push(t.draft),t?.reply?.text&&(R=t.reply.text,bt=$=t.reply.for??null),(l||A.length||R)&&f()}catch{localStorage.removeItem(ut)}};as();const is=()=>setTimeout(()=>{const t=Zt(location.pathname);t!==j&&(clearTimeout(Ot),ue(),j=t,ut=en(),l=null,A=[],R="",bt=null,$=null,T=null,b=[],ze(),as(),mt())});for(const t of["pushState","replaceState"]){const e=window.history[t];window.history[t]=function(...n){e.apply(this,n),is()}}addEventListener("popstate",is),x||mt(),Wt().then(Le.resume),document.addEventListener("visibilitychange",()=>{document.hidden||Mt()}),addEventListener("focus",Mt),addEventListener("notemend:changed",()=>{E||Mt()});let Ko=0;E||setInterval(()=>{(!ta.live||++Ko%6===0)&&Mt()},2e4),E&&parent.postMessage({dt:!0,hello:!0},location.origin)}export{xa as run};