@popmelt.com/core 0.7.6 → 0.7.7

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/dist/index.mjs CHANGED
@@ -1,26 +1,26 @@
1
1
  "use client";
2
- import{createContext as Cm,useCallback as Ht,useContext as Em,useEffect as Et,useMemo as to,useRef as qt,useState as ht}from"react";import{useCallback as ka,useEffect as Yc,useSyncExternalStore as Vc}from"react";var dn="http://localhost:1111";function Wc(){return typeof window<"u"?window.__POPMELT_PROJECT_ID__??null:null}function jc(e={}){let t=Wc();if(!t)return e;let n=new Headers(e.headers);return n.set("X-Popmelt-Project-Id",t),{...e,headers:n}}function ho(e,t={}){return fetch(e,jc(t))}function yn(e,t={},n=15e3){let o=new AbortController;t.signal&&t.signal.addEventListener("abort",()=>o.abort());let r=setTimeout(()=>o.abort(),n);return ho(e,{...t,signal:o.signal}).finally(()=>clearTimeout(r))}async function pa(e=dn){try{let t=await yn(`${e}/capabilities`,{},5e3);return t.ok?await t.json():null}catch{return null}}async function yo(e=dn){try{let t=new AbortController,n=setTimeout(()=>t.abort(),2e3),o=await ho(`${e}/status`,{signal:t.signal});return clearTimeout(n),o.ok?await o.json():null}catch{return null}}async function ua(e){try{let t=new AbortController,n=setTimeout(()=>t.abort(),500),o=await ho(`http://localhost:${e}/status`,{signal:t.signal});return clearTimeout(n),o.ok?await o.json():null}catch{return null}}async function Gc(e){return yo(e)}async function fa(e,t){if(e&&e!=="http://localhost:1111")try{let c=new URL(e),u=await Gc(e);if(!u&&!t)return null;if(!(!u&&t)){if(!(u&&t&&u.projectId!==t)){if(u?.projectId&&!t)return null;if(u)return{url:e,port:parseInt(c.port,10)||1111,projectId:u.projectId}}}}catch{if(!t)return null}let i=typeof window<"u"?window.location.origin:null,s=await ua(1111);if(s){if(t&&s.projectId===t)return{url:"http://localhost:1111",port:1111,projectId:s.projectId};if(s.devOrigin&&i&&s.devOrigin===i&&(t||!s.projectId))return{url:"http://localhost:1111",port:1111,projectId:s.projectId}}let a=Array.from({length:8},(c,u)=>{let d=1112+u;return ua(d).then(g=>g?{status:g,port:d}:null)}),l=(await Promise.all(a)).filter(c=>c!==null),p=[];s&&p.push({port:1111,devOrigin:s.devOrigin,projectId:s.projectId});for(let c of l)p.push({port:c.port,devOrigin:c.status.devOrigin,projectId:c.status.projectId});if(t){let c=p.find(u=>u.projectId===t);if(c)return{url:`http://localhost:${c.port}`,port:c.port,projectId:c.projectId}}if(i){let c=p.find(u=>u.devOrigin===i&&(t||!u.projectId));if(c)return{url:`http://localhost:${c.port}`,port:c.port,projectId:c.projectId}}return p.length===1&&!p[0].projectId?{url:`http://localhost:${p[0].port}`,port:p[0].port,projectId:p[0].projectId}:null}async function Xr(e=dn,t,n=-1){try{let o=await yn(`${e}/jobs/${t}/events?afterSeq=${n}`,{},5e3);return o.ok?await o.json():null}catch{return null}}async function ga(e,t,n=dn,o,r,i,s,a){let l=new FormData;if(e instanceof Map){let c=!0;for(let[u,d]of e){let g=encodeURIComponent(u);l.append(`screenshot-${g}`,d,`screenshot-${g}.webp`),c&&(l.append("screenshot",d,"screenshot.webp"),c=!1)}c&&l.append("screenshot",new Blob([],{type:"image/webp"}),"screenshot.webp")}else l.append("screenshot",e,"screenshot.webp");if(l.append("feedback",t),o&&l.append("color",o),r&&l.append("provider",r),i&&l.append("model",i),a&&l.append("sourceId",a),s)for(let[c,u]of s)for(let d=0;d<u.length;d++)l.append(`image-${c}-${d}`,u[d],`image-${c}-${d}.webp`);let p=await yn(`${n}/send`,{method:"POST",body:l},3e4);if(!p.ok){let c=await p.text();throw new Error(`Bridge returned ${p.status}: ${c}`)}return p.json()}async function ma(e,t=dn){let n=await yn(`${t}/model/component`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})},1e4);if(!n.ok){let o=await n.text();throw new Error(`Bridge returned ${n.status}: ${o}`)}return n.json()}async function ha(e,t=dn){let n=await yn(`${t}/model/component`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})},1e4);if(!n.ok){let o=await n.text();throw new Error(`Bridge returned ${n.status}: ${o}`)}return n.json()}async function Vi(e,t,n=dn){let o=await yn(`${n}/model/token`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,value:t})},1e4);if(!o.ok){let r=await o.text();throw new Error(`Bridge returned ${o.status}: ${r}`)}return o.json()}async function ya(e,t=dn){let n=await yn(`${t}/model/token`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})},1e4);if(!n.ok){let o=await n.text();throw new Error(`Bridge returned ${n.status}: ${o}`)}return n.json()}async function ur(e=dn){try{let t=await yn(`${e}/model`,{},5e3);return t.ok?(await t.json()).model??null:null}catch{return null}}async function ba(e=dn){let t=await yn(`${e}/evals`,{},5e3);return t.ok?t.json():{version:1,updatedAt:0,cases:[]}}async function qr(e,t,n=dn){let o=await yn(`${n}/evals/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)},5e3);return o.ok?(await o.json()).eval??null:null}function va(e,t,n=dn){return qr(e,{status:t},n)}async function xa(e,t,n,o=dn,r,i,s){let a=new FormData;a.append("screenshot",t,"eval-run.webp"),a.append("feedback",JSON.stringify(n)),r&&a.append("provider",r),i&&a.append("model",i),s&&a.append("sourceId",s);let l=await yn(`${o}/evals/${encodeURIComponent(e)}/run`,{method:"POST",body:a},3e4);if(!l.ok){let p=await l.text();throw new Error(`Bridge returned ${l.status}: ${p}`)}return l.json()}function Jc(e){return new Promise(t=>setTimeout(t,e))}async function Ui(e=dn,t,n=15e3){let o=Date.now();try{let s=await yn(`${e}/restart`,{method:"POST"},5e3);if(!s.ok){let a=await s.text().catch(()=>"");return{ok:!1,error:a?`Bridge restart returned ${s.status}: ${a}`:`Bridge restart returned ${s.status}`,elapsedMs:Date.now()-o}}}catch(s){return{ok:!1,error:s instanceof Error?s.message:"Bridge restart request failed",elapsedMs:Date.now()-o}}let r=null;for(;Date.now()-o<n;)if(await Jc(350),r=await yo(e),!!r?.ok&&!(t&&r.version!==t))return{ok:!0,status:r,elapsedMs:Date.now()-o};return{ok:!1,error:`Bridge did not come back${t?` with version ${t}`:""} within ${Math.round(n/1e3)}s`,status:r,elapsedMs:Date.now()-o}}async function Sa(e=dn){return(await Ui(e)).ok}async function wa(e=dn,t,n){let o=await yn(`${e}/model/synthesize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,model:n})},1e4);if(!o.ok){let r=await o.text();throw new Error(`Bridge returned ${o.status}: ${r}`)}return o.json()}async function Ca(e=dn,t,n){let o=await yn(`${e}/evals/synthesize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,model:n})},1e4);if(!o.ok){let r=await o.text();throw new Error(`Bridge returned ${o.status}: ${r}`)}return o.json()}async function Ea(e,t,n=dn,o,r,i,s,a){let l;if(s&&s.length>0){let p=new FormData,c=new Blob([new Uint8Array([137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,1,0,0,0,1,8,6,0,0,0,31,21,196,137,0,0,0,10,73,68,65,84,120,156,98,0,0,0,2,0,1,229,39,222,252,0,0,0,0,73,69,78,68,174,66,96,130])],{type:"image/png"});p.append("screenshot",c,"screenshot.png"),p.append("feedback",JSON.stringify({threadId:e,reply:t,color:o,provider:r,model:i,sourceId:a}));for(let u=0;u<s.length;u++)p.append(`image-reply-${u}`,s[u],`reply-image-${u}.webp`);l=await yn(`${n}/reply`,{method:"POST",body:p},3e4)}else l=await yn(`${n}/reply`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({threadId:e,reply:t,color:o,provider:r,model:i,sourceId:a})},3e4);if(!l.ok){let p=await l.text();throw new Error(`Bridge returned ${l.status}: ${p}`)}return l.json()}var Xi=typeof import.meta<"u"?import.meta.hot:void 0,ni=Xi?.data?.sourceId??(typeof localStorage<"u"&&localStorage.getItem("popmelt-source-id"))??(typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2));Xi?.data&&(Xi.data.sourceId=ni);try{typeof localStorage<"u"&&localStorage.setItem("popmelt-source-id",ni)}catch{}function oi(){return ni}var qi=typeof import.meta<"u"?import.meta.hot:void 0,Wo=qi?.data,Uc={isConnected:!1,status:"disconnected",jobResponses:{},jobThinking:{},activeJobIds:[],activeJobThreads:{},currentResponse:"",currentThinking:"",events:[],activeJobId:null,lastCompletedJobId:null,lastResponseText:null,lastThreadId:null,lastErrorByJob:{},pendingQuestions:[],incrementalResolutions:[],capabilitiesVersion:0},gr=Wo?.store??{...Uc},Qr=Wo?.listeners??new Set,$o=Wo?.activeEs??null,Zi=Wo?.activeBridgeUrl??null,Fo=null,ei=Wo?.connectionGeneration??0;qi?.data&&Object.defineProperties(qi.data,{store:{get:()=>gr,configurable:!0},listeners:{get:()=>Qr,configurable:!0},activeEs:{get:()=>$o,configurable:!0},activeBridgeUrl:{get:()=>Zi,configurable:!0},connectionGeneration:{get:()=>ei,configurable:!0},discoveredBridgeUrl:{get:()=>Io,configurable:!0},discoveredBridgeProjectId:{get:()=>bo,configurable:!0}});var ti=new Set,fr=new Map,Ro={};function zo(e,t){if(!e)return!1;if(ti.has(e)){let o=fr.get(e);return o||(o=[],fr.set(e,o)),o.push({type:t.type??"",data:t}),!0}let n=Ro[e];return n!==void 0&&typeof t.seq=="number"&&t.seq<=n}async function Kc(e,t,n){let o=()=>n!==ei;for(let r of t){if(o())return;ti.add(r),fr.set(r,[])}await Promise.all(t.map(async r=>{try{let i=await Xr(e,r);if(o())return;let s=fr.get(r)??[];if(i){if(en(a=>{let l={...a.jobResponses,[r]:i.accumulated.response},p={...a.jobThinking,[r]:i.accumulated.thinking},c=[...a.events];for(let u of i.events)u.type==="done"||u.type==="error"||c.push({type:u.type,data:u,timestamp:Date.now()});return{...a,jobResponses:l,jobThinking:p,currentResponse:r===a.activeJobId?i.accumulated.response:a.currentResponse,currentThinking:r===a.activeJobId?i.accumulated.thinking:a.currentThinking,events:c}}),Ro[r]=i.currentSeq,!i.jobActive){let a=i.events.find(l=>l.type==="done"||l.type==="error");a&&Ki(a.type,a,r)}for(let a of s)typeof a.data.seq=="number"&&a.data.seq<=i.currentSeq||Ki(a.type,a.data,r)}else for(let a of s)Ki(a.type,a.data,r)}finally{ti.delete(r),fr.delete(r)}}))}function Ki(e,t,n){if(e==="delta"){let o=t.text||"";en(r=>({...r,jobResponses:{...r.jobResponses,[n]:(r.jobResponses[n]||"")+o},currentResponse:n===r.activeJobId?r.currentResponse+o:r.currentResponse,events:[...r.events,{type:"delta",data:t,timestamp:Date.now()}]}))}else if(e==="thinking"){let o=t.text||"";en(r=>({...r,jobThinking:{...r.jobThinking,[n]:(r.jobThinking[n]||"")+o},currentThinking:n===r.activeJobId?r.currentThinking+o:r.currentThinking,events:[...r.events,{type:"thinking",data:t,timestamp:Date.now()}]}))}else if(e==="done")delete Ro[n],en(o=>{let r=o.activeJobIds.filter(p=>p!==n),i={...o.jobResponses},s={...o.jobThinking},a=i[n];delete i[n],delete s[n];let l=n===o.activeJobId?r.length>0?r[r.length-1]:null:o.activeJobId;return{...o,activeJobIds:r,activeJobId:l,jobResponses:i,jobThinking:s,lastCompletedJobId:n,lastResponseText:a||o.currentResponse||t.responseText||null,lastThreadId:t.threadId??null,...n===o.activeJobId?{currentResponse:l&&i[l]||"",currentThinking:l&&s[l]||""}:{},events:[...o.events,{type:"done",data:t,timestamp:Date.now()}]}});else if(e==="error"){delete Ro[n];let o=t.message??"";en(r=>{let i=r.activeJobIds.filter(a=>a!==n),s=i.length>0?r.status:"error";return{...r,status:s,activeJobIds:i,lastCompletedJobId:n,lastErrorByJob:o?{...r.lastErrorByJob,[n]:o}:r.lastErrorByJob,events:[...r.events,{type:"error",data:t,timestamp:Date.now()}]}})}else en(o=>({...o,events:[...o.events,{type:e,data:t,timestamp:Date.now()}]}))}var Io=Wo?.discoveredBridgeUrl??null,bo=Wo?.discoveredBridgeProjectId??null,pr=null,Zr=null;async function Xc(e,t){return Io&&(t?bo===t:!bo)?Io:(!t&&bo&&(Io=null,bo=null),t&&bo&&bo!==t&&(Io=null,bo=null),pr&&Zr===(t??null)||(Zr=t??null,pr=fa(e,t).then(n=>(Io=n?.url??null,bo=n?.projectId??t??null,pr=null,Zr=null,Io)).catch(()=>(pr=null,Zr=null,null))),pr)}function Ma(){return Io}function Ta(){return gr}function qc(e){return Qr.add(e),()=>{Qr.delete(e)}}function en(e){gr=e(gr);for(let t of Qr)t()}function Zc(){return typeof window<"u"?window.__POPMELT_PROJECT_ID__??null:null}function Ia(e){if($o&&$o.readyState!==EventSource.CLOSED&&Zi===e)return;$o&&($o.close(),$o=null),Fo&&(clearTimeout(Fo),Fo=null),Zi=e;let t=++ei,n=new URLSearchParams({sourceId:ni}),o=Zc();o&&n.set("projectId",o);let r=new EventSource(`${e}/events?${n.toString()}`);$o=r;let i=()=>t!==ei;r.addEventListener("connected",()=>{i()||yo(e).then(s=>{if(i())return;let a=s?.activeJobs??(s?.activeJob?[s.activeJob]:[]),l=new Set(a.map(x=>x.id)),p=s?.recentJobs??[],c=new Map(p.map(x=>[x.id,x])),u=a.length>0;en(x=>{let h={...x.lastErrorByJob},I=x.activeJobIds.filter(F=>!l.has(F));for(let F of I){let M=c.get(F);M?.status==="error"&&M.error&&(h[F]=M.error)}let O=x.activeJobIds.filter(F=>l.has(F));for(let F of l)O.includes(F)||O.push(F);let P={};for(let F of a)F.threadId&&(P[F.id]=F.threadId);return{...x,isConnected:!0,status:u?"streaming":I.length>0||x.status==="disconnected"?"idle":x.status,activeJobId:u?a[a.length-1].id:O.length>0?O[O.length-1]:null,activeJobIds:O,activeJobThreads:P,lastErrorByJob:h,lastCompletedJobId:I.length>0?I[I.length-1]:x.lastCompletedJobId}});let d=gr.activeJobIds.filter(x=>!l.has(x)),g=[...Array.from(l),...d];g.length>0&&Kc(e,g,t).catch(()=>{})})}),r.addEventListener("job_started",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;if(zo(l,a))return;let p=a.threadId;en(c=>({...c,status:"streaming",activeJobId:l,activeJobIds:c.activeJobIds.includes(l)?c.activeJobIds:[...c.activeJobIds,l],activeJobThreads:p?{...c.activeJobThreads,[l]:p}:c.activeJobThreads,jobResponses:{...c.jobResponses,[l]:c.jobResponses[l]??""},jobThinking:{...c.jobThinking,[l]:c.jobThinking[l]??""},currentResponse:c.jobResponses[l]??"",currentThinking:c.jobThinking[l]??"",lastResponseText:null,lastThreadId:null,events:[...c.events,{type:"job_started",data:a,timestamp:Date.now()}]}))}),r.addEventListener("delta",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;if(zo(l,a))return;let p=a.text||"";en(c=>({...c,jobResponses:l?{...c.jobResponses,[l]:(c.jobResponses[l]||"")+p}:c.jobResponses,currentResponse:!l||l===c.activeJobId?c.currentResponse+p:c.currentResponse,events:[...c.events,{type:"delta",data:a,timestamp:Date.now()}]}))}),r.addEventListener("thinking",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;if(zo(l,a))return;let p=a.text||"";en(c=>({...c,jobThinking:l?{...c.jobThinking,[l]:(c.jobThinking[l]||"")+p}:c.jobThinking,currentThinking:!l||l===c.activeJobId?c.currentThinking+p:c.currentThinking,events:[...c.events,{type:"thinking",data:a,timestamp:Date.now()}]}))}),r.addEventListener("tool_use",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;zo(l,a)||en(p=>({...p,events:[...p.events,{type:"tool_use",data:a,timestamp:Date.now()}]}))}),r.addEventListener("done",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;zo(l,a)||(l&&delete Ro[l],en(p=>{let c=l?p.activeJobIds.filter(I=>I!==l):p.activeJobIds,u={...p.jobResponses},d={...p.jobThinking},g={...p.activeJobThreads},x=l?u[l]:void 0;l&&(delete u[l],delete d[l],delete g[l]);let h=l===p.activeJobId?c.length>0?c[c.length-1]:null:p.activeJobId;return{...p,activeJobIds:c,activeJobId:h,jobResponses:u,jobThinking:d,lastCompletedJobId:l??p.activeJobId,lastResponseText:x||p.currentResponse||a.responseText||null,lastThreadId:a.threadId??null,...l===p.activeJobId?{currentResponse:h&&u[h]||"",currentThinking:h&&d[h]||""}:{},events:[...p.events,{type:"done",data:a,timestamp:Date.now()}]}}))}),r.addEventListener("question",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;zo(l,a)||en(p=>({...p,pendingQuestions:[...p.pendingQuestions,{jobId:a.jobId,threadId:a.threadId,question:a.question,annotationIds:a.annotationIds,timestamp:Date.now()}],events:[...p.events,{type:"question",data:a,timestamp:Date.now()}]}))}),r.addEventListener("capabilities_changed",()=>{i()||en(s=>({...s,capabilitiesVersion:s.capabilitiesVersion+1}))}),r.addEventListener("queue_drained",()=>{if(!i()){for(let s of Object.keys(Ro))delete Ro[s];ti.clear(),fr.clear(),en(s=>({...s,status:s.status==="error"?"error":"idle",activeJobId:null,activeJobIds:[],activeJobThreads:{},currentResponse:"",currentThinking:"",jobResponses:{},jobThinking:{},lastErrorByJob:{},incrementalResolutions:[]}))}}),r.addEventListener("error",s=>{if(!i()){if(r.readyState===EventSource.CLOSED)en(a=>({...a,isConnected:!1,status:"disconnected"})),Fo&&(clearTimeout(Fo),Fo=null),Fo=setTimeout(()=>{yo(e).then(a=>{a&&Ia(e)})},5e3);else if(s instanceof MessageEvent){let a=JSON.parse(s.data),l=a.jobId??null;if(zo(l??void 0,a))return;l&&delete Ro[l];let p=a.message??"";en(c=>{let u=l?c.activeJobIds.filter(g=>g!==l):c.activeJobIds,d=u.length>0?c.status:"error";return{...c,status:d,activeJobIds:u,lastCompletedJobId:l??c.activeJobId,lastErrorByJob:l&&p?{...c.lastErrorByJob,[l]:p}:c.lastErrorByJob,events:[...c.events,{type:"error",data:a,timestamp:Date.now()}]}})}}}),r.onerror=()=>{i()||r.readyState===EventSource.CLOSED&&en(s=>({...s,isConnected:!1,status:"disconnected"}))}}function Ra(e="http://localhost:1111",t=!0,n){let o=Vc(qc,Ta,Ta);Yc(()=>{t&&Xc(e,n).then(s=>{s&&yo(s).then(a=>{a&&Ia(s)})})},[e,t,n]);let r=ka(()=>{en(()=>({...gr,events:[],currentResponse:"",currentThinking:"",jobResponses:{},jobThinking:{},lastResponseText:null,lastThreadId:null,lastErrorByJob:{},incrementalResolutions:[]}))},[]),i=ka(s=>{en(a=>({...a,pendingQuestions:a.pendingQuestions.filter(l=>l.threadId!==s)}))},[]);return{...o,clearEvents:r,dismissQuestion:i}}import{useEffect as Qc,useReducer as ed}from"react";var td={isAnnotating:!1,activeTool:"inspector",activeColor:"oklch(0.628 0.258 29)",strokeWidth:3,annotations:[],undoStack:[],redoStack:[],currentPath:[],selectedAnnotationIds:[],lastSelectedId:null,inspectedElement:null,styleModifications:[],spacingTokenChanges:[],spacingTokenMods:[]};function ri(){return Math.random().toString(36).substring(2,9)}function La(e){return e.status?e:e.captured?{...e,status:"in_flight"}:{...e,status:"pending"}}function En(e){return{...e,undoStack:[...e.undoStack,{annotations:e.annotations,styleModifications:e.styleModifications,spacingTokenMods:e.spacingTokenMods}],redoStack:[]}}function nd(e,t){return{...e,isAnnotating:t}}function od(e,t){return{...e,activeTool:t,inspectedElement:null}}function rd(e,t){return{...e,activeColor:t}}function id(e,t){return{...e,strokeWidth:t}}function sd(e,t){return{...e,currentPath:[t]}}function ad(e,t){return{...e,currentPath:[...e.currentPath,t]}}function ld(e){return{...e,currentPath:[]}}function cd(e,t){if(e.currentPath.length<2&&e.activeTool!=="text")return{...e,currentPath:[]};let n={id:ri(),type:e.activeTool,points:e.currentPath,color:e.activeColor,strokeWidth:e.strokeWidth,timestamp:Date.now(),status:"pending",pathname:typeof window<"u"?window.location.pathname:"/",groupId:t?.groupId,elements:t?.elements};return{...En(e),annotations:[...e.annotations,n],currentPath:[]}}function dd(e,t){let n={id:t.id??ri(),type:"text",points:[t.point],text:t.text,fontSize:t.fontSize||12,color:e.activeColor,strokeWidth:e.strokeWidth,timestamp:Date.now(),status:"pending",pathname:typeof window<"u"?window.location.pathname:"/",groupId:t.groupId,linkedSelector:t.linkedSelector,linkedAnchor:t.linkedAnchor,elements:t.elements,...t.imageCount?{imageCount:t.imageCount}:{}};return{...t.groupId?e:En(e),annotations:[...e.annotations,n]}}function ud(e,t){return{...En(e),annotations:e.annotations.map(o=>o.id===t.id?{...o,text:t.text,...t.imageCount!=null?{imageCount:t.imageCount}:{}}:o)}}function pd(e,t){return{...e,annotations:e.annotations.map(n=>n.id===t.id?{...n,fontSize:Math.max(12,Math.min(72,t.fontSize))}:n)}}function fd(e,t){let n=En(e),r=e.annotations.find(i=>i.id===t.id)?.groupId;return{...n,annotations:e.annotations.filter(i=>i.id!==t.id&&!(r&&i.groupId===r))}}function gd(e,t){let n=t.saveUndo?En(e):e,r=e.annotations.find(i=>i.id===t.id)?.groupId;return{...n,annotations:e.annotations.map(i=>{if(!(i.id===t.id||r&&i.groupId===r))return i;let a=t.delta.x,l=t.delta.y;return{...i,points:i.points.map(p=>({x:p.x+a,y:p.y+l}))}})}}function md(e,t){let n=t.saveUndo?En(e):e,o=e.annotations.find(s=>s.id===t.id);if(!o||o.type==="text"||o.points.length<2)return e;let r=0,i=0;if(o.type==="rectangle"&&o.groupId){let s=t.points,a=Math.min(s[0].x,s[1].x),l=Math.max(s[0].y,s[1].y),p=o.points[0],c=o.points[o.points.length-1],u=Math.min(p.x,c.x),d=Math.max(p.y,c.y);r=a-u,i=l-d}return{...n,annotations:e.annotations.map(s=>s.id===t.id?{...s,points:t.points}:o.groupId&&s.groupId===o.groupId&&s.type==="text"?{...s,points:s.points.map(a=>({x:a.x+r,y:a.y+i}))}:s)}}function hd(e,t){return{...En(e),annotations:[...e.annotations,...t.annotations.map(La)]}}function yd(e,t){let n=new Set,o=[];for(let r of t.annotations)n.has(r.id)||(n.add(r.id),o.push(La(r)));return{...e,annotations:o}}function bd(e){if(e.undoStack.length===0)return e;let t=e.undoStack[e.undoStack.length-1];return{...e,annotations:t?.annotations||[],styleModifications:t?.styleModifications||[],spacingTokenMods:t?.spacingTokenMods||[],undoStack:e.undoStack.slice(0,-1),redoStack:[...e.redoStack,{annotations:e.annotations,styleModifications:e.styleModifications,spacingTokenMods:e.spacingTokenMods}]}}function vd(e){if(e.redoStack.length===0)return e;let t=e.redoStack[e.redoStack.length-1];return{...e,annotations:t?.annotations||[],styleModifications:t?.styleModifications||[],spacingTokenMods:t?.spacingTokenMods||[],redoStack:e.redoStack.slice(0,-1),undoStack:[...e.undoStack,{annotations:e.annotations,styleModifications:e.styleModifications,spacingTokenMods:e.spacingTokenMods}]}}function xd(e,t){let{id:n,addToSelection:o}=t;if(n===null)return{...e,selectedAnnotationIds:[],lastSelectedId:null};if(o)if(e.selectedAnnotationIds.includes(n)){let i=e.selectedAnnotationIds.filter(s=>s!==n);return{...e,selectedAnnotationIds:i,lastSelectedId:i.length>0?i[i.length-1]:null}}else return{...e,selectedAnnotationIds:[...e.selectedAnnotationIds,n],lastSelectedId:n};return{...e,selectedAnnotationIds:[n],lastSelectedId:n}}function Sd(e,t){let n=new Set;for(let o of e.selectedAnnotationIds){let r=e.annotations.find(i=>i.id===o);r?.groupId&&n.add(r.groupId)}return{...e,annotations:e.annotations.map(o=>{let r=e.selectedAnnotationIds.includes(o.id),i=o.groupId&&n.has(o.groupId);return!r&&!i?o:{...o,color:t.color}})}}function wd(e){return{...e,annotations:e.annotations.map(t=>({...t,captured:!0,status:t.status==="pending"||!t.status?"in_flight":t.status})),styleModifications:e.styleModifications.map(t=>({...t,captured:!0})),spacingTokenChanges:e.spacingTokenChanges.map(t=>({...t,captured:!0}))}}function Cd(e){return{...e,annotations:[],undoStack:[],redoStack:[],currentPath:[],selectedAnnotationIds:[],lastSelectedId:null,spacingTokenChanges:[],spacingTokenMods:[]}}function Ed(e,t){return{...e,inspectedElement:t}}function kd(e,t){let{selector:n,element:o,property:r,original:i,modified:s}=t,a=e.styleModifications.findIndex(l=>l.selector===n);if(i===s&&a<0)return e;if(a>=0){let l=e.styleModifications[a];if(l.captured){let g=En(e),x=g.styleModifications.map((h,I)=>I===a?{...h,changes:[{property:r,original:i,modified:s}],captured:!1}:h);return{...g,styleModifications:x}}let p=l.changes.findIndex(g=>g.property===r),c,u=e;if(p>=0){let g=l.changes[p];s===g.original?c=l.changes.filter((x,h)=>h!==p):c=l.changes.map((x,h)=>h===p?{...x,modified:s}:x)}else{if(i===s)return e;u=En(e),c=[...l.changes,{property:r,original:i,modified:s}]}if(c.length===0)return{...u,styleModifications:u.styleModifications.filter((g,x)=>x!==a)};let d=u.styleModifications.map((g,x)=>x===a?{...g,changes:c}:g);return{...u,styleModifications:d}}else{let l=En(e),p={selector:n,element:o,changes:[{property:r,original:i,modified:s}]};return{...l,styleModifications:[...l.styleModifications,p]}}}function Td(e,t){let{selector:n,durableSelector:o,element:r,changes:i}=t,s=i.filter(p=>p.original!==p.modified);if(s.length===0)return e;let a=En(e),l=a.styleModifications.findIndex(p=>p.selector===n);if(l>=0){let p=a.styleModifications[l],c=p.captured?[]:[...p.changes];for(let u of s){let d=c.findIndex(g=>g.property===u.property);d>=0?u.modified===c[d].original?c=c.filter((g,x)=>x!==d):c=c.map((g,x)=>x===d?{...g,modified:u.modified}:g):c.push(u)}return c.length===0?{...a,styleModifications:a.styleModifications.filter((u,d)=>d!==l)}:{...a,styleModifications:a.styleModifications.map((u,d)=>d===l?{...u,changes:c,captured:!1}:u)}}else return{...a,styleModifications:[...a.styleModifications,{selector:n,durableSelector:o,element:r,changes:s}]}}function Md(e,t){let{selector:n,property:o}=t,r=En(e),i=r.styleModifications.map(s=>s.selector!==n?s:{...s,changes:s.changes.filter(a=>a.property!==o)}).filter(s=>s.changes.length>0);return{...r,styleModifications:i}}function Id(e){return e.styleModifications.length===0?{...e,inspectedElement:null}:{...En(e),styleModifications:[],inspectedElement:null}}function Rd(e,t){return{...e,styleModifications:t}}function Ld(e,t){let{updates:n}=t,o=new Map(n.map(r=>[r.id,r]));return{...e,annotations:e.annotations.map(r=>{let i=o.get(r.id);return i?{...r,points:[i.point,...r.points.slice(1)],...i.linkedAnchor?{linkedAnchor:i.linkedAnchor}:{}}:r})}}function Ad(e,t){let n=new Set(t.ids);return{...e,annotations:e.annotations.map(o=>n.has(o.id)?{...o,status:t.status}:o)}}function Pd(e,t){let n=new Set(t.ids),o=new Set;for(let r of e.annotations)n.has(r.id)&&r.groupId&&o.add(r.groupId);return{...e,annotations:e.annotations.map(r=>n.has(r.id)||r.groupId&&o.has(r.groupId)?{...r,threadId:t.threadId}:r)}}function Dd(e,t){let n=new Set(t.ids),o=new Set;for(let r of e.annotations)n.has(r.id)&&r.groupId&&o.add(r.groupId);return{...e,annotations:e.annotations.map(r=>n.has(r.id)||r.groupId&&o.has(r.groupId)?{...r,status:"waiting_input",question:t.question,threadId:t.threadId}:r)}}function Od(e,t){let n=new Map(t.resolutions.map(r=>[r.annotationId,r])),o=new Map;for(let r of e.annotations){let i=n.get(r.id);i&&r.groupId&&o.set(r.groupId,i)}return{...e,annotations:e.annotations.map(r=>{let i=n.get(r.id)||(r.groupId?o.get(r.groupId):void 0);return i?{...r,status:i.status,resolutionSummary:i.summary,scope:i.finalScope??i.inferredScope??null,replyCount:(r.replyCount??0)+1,question:void 0,threadId:r.threadId||t.threadId}:r})}}function Bd(e,t){let{linkedSelectors:n,styleSelectors:o}=t,r=new Set(n),i=new Set(o),s=new Set,a=new Set;for(let d of e.annotations)d.linkedSelector&&r.has(d.linkedSelector)&&(s.add(d.id),d.groupId&&a.add(d.groupId));for(let d of e.annotations)d.groupId&&a.has(d.groupId)&&s.add(d.id);let l=e.annotations.filter(d=>!s.has(d.id)),p=e.styleModifications.filter(d=>!i.has(d.selector));if(l.length===e.annotations.length&&p.length===e.styleModifications.length)return e;let c=e.selectedAnnotationIds.filter(d=>!s.has(d)),u=e.inspectedElement&&i.has(e.inspectedElement.info.selector)?null:e.inspectedElement;return{...e,annotations:l,styleModifications:p,selectedAnnotationIds:c,lastSelectedId:c.length>0?c[c.length-1]:null,inspectedElement:u}}function Hd(e,t){let n=e.spacingTokenChanges.findIndex(o=>o.tokenPath===t.tokenPath);return n>=0?{...e,spacingTokenChanges:e.spacingTokenChanges.map((o,r)=>r===n?t:o)}:{...e,spacingTokenChanges:[...e.spacingTokenChanges,t]}}function _d(e,t){return{...e,spacingTokenChanges:t}}function Nd(e,t){let n=En(e),o=e.spacingTokenMods.findIndex(i=>i.tokenPath===t.tokenPath),r;if(o>=0){let i=e.spacingTokenMods[o],s={...t,originalValue:i.originalValue,originalPx:i.originalPx};r=e.spacingTokenMods.map((a,l)=>l===o?s:a)}else r=[...e.spacingTokenMods,t];return{...n,spacingTokenMods:r}}function Fd(e,t){let n=En(e),o=e.spacingTokenMods.findIndex(l=>l.tokenPath===t.tokenPath),r=o>=0?e.spacingTokenMods[o].originalValue:t.originalValue,i=o>=0?e.spacingTokenMods[o].originalPx:parseFloat(t.originalValue)||0,s={tokenPath:t.tokenPath,originalValue:r,currentValue:"__deleted__",targets:o>=0?e.spacingTokenMods[o].targets:[],originalPx:i,currentPx:0},a;return o>=0?a=e.spacingTokenMods.map((l,p)=>p===o?s:l):a=[...e.spacingTokenMods,s],{...n,spacingTokenMods:a}}var zd={SET_ANNOTATING:nd,SET_TOOL:od,SET_COLOR:rd,SET_STROKE_WIDTH:id,START_PATH:sd,CONTINUE_PATH:ad,CANCEL_PATH:ld,FINISH_PATH:cd,ADD_TEXT:dd,UPDATE_TEXT:ud,UPDATE_TEXT_SIZE:pd,DELETE_ANNOTATION:fd,MOVE_ANNOTATION:gd,RESIZE_ANNOTATION:md,PASTE_ANNOTATIONS:hd,RESTORE_ANNOTATIONS:yd,UNDO:bd,REDO:vd,SELECT_ANNOTATION:xd,UPDATE_ANNOTATION_COLOR:Sd,MARK_CAPTURED:wd,CLEAR:Cd,SELECT_ELEMENT:Ed,MODIFY_STYLE:kd,MODIFY_STYLES_BATCH:Td,CLEAR_STYLE:Md,CLEAR_ALL_STYLES:Id,RESTORE_STYLE_MODIFICATIONS:Rd,UPDATE_LINKED_POSITIONS:Ld,CLEANUP_ORPHANED:Bd,SET_ANNOTATION_STATUS:Ad,SET_ANNOTATION_THREAD:Pd,SET_ANNOTATION_QUESTION:Dd,APPLY_RESOLUTIONS:Od,ADD_SPACING_TOKEN_CHANGE:Hd,RESTORE_SPACING_TOKEN_CHANGES:_d,MODIFY_SPACING_TOKEN:Nd,DELETE_SPACING_TOKEN:Fd};function $d(e,t){let n=zd[t.type];return n?n(e,t.payload):e}function Aa(){let[e,t]=ed($d,td);return Qc(()=>{let n=o=>{(o.metaKey||o.ctrlKey)&&o.key==="z"&&(o.preventDefault(),o.shiftKey?t({type:"REDO"}):t({type:"UNDO"}))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[]),[e,t]}import{useSyncExternalStore as Wd}from"react";if(typeof window<"u"&&!window.__popmeltPathPatch){window.__popmeltPathPatch=!0;for(let e of["pushState","replaceState"]){let t=History.prototype[e];History.prototype[e]=function(...n){let o=window.location.pathname;t.apply(this,n),window.dispatchEvent(new CustomEvent("popmelt:locationchange",{detail:{prevPath:o}}))}}}function jd(e){return window.addEventListener("popstate",e),window.addEventListener("popmelt:locationchange",e),()=>{window.removeEventListener("popstate",e),window.removeEventListener("popmelt:locationchange",e)}}function Gd(){return window.location.pathname}function mr(){return Wd(jd,Gd,()=>"/")}var Pa="popmelt-toolbar-snap-position";function jo(e){return e.startsWith("top-")}function Go(e){return e.endsWith("-right")}function Hr(e){return e.endsWith("-center")}function Da(){try{let e=localStorage.getItem(Pa);if(e&&Jd(e))return e}catch{}return"bottom-right"}function Oa(e){try{localStorage.setItem(Pa,e)}catch{}}function Jd(e){return["bottom-right","bottom-center","bottom-left","top-right","top-center","top-left"].includes(e)}function Ba(e,t,n){let o=jo(e)?16:n-16-54;return Hr(e)?{position:"fixed",top:o,left:t/2,transform:"translateX(-50%)"}:Go(e)?{position:"fixed",top:o,right:16,left:"auto"}:{position:"fixed",top:o,left:16,right:"auto"}}function Ha(e,t,n){let r=jo(e)?{top:82}:{bottom:82},i;return Hr(e)?i={left:t/2,transform:"translateX(-50%)"}:Go(e)?i={right:16}:i={left:16},{position:"fixed",...r,...i}}function _a(e,t,n){let o=jo(e),r=o?{top:78}:{bottom:78},i,s;return Hr(e)?(i={left:"50%",transform:"translateX(-50%)"},s="center"):Go(e)?(i={right:16},s="flex-end"):(i={left:16},s="flex-start"),{position:"fixed",...r,...i,zIndex:9999,display:"flex",flexDirection:"column",alignItems:s}}function ii(e){let t=jo(e),n=Go(e)||Hr(e);return{position:"fixed",top:t&&n?82:16,right:16,bottom:!t&&n?82:16}}function Na(e,t,n){let r=jo(e),i,s;Go(e)||Hr(e)?(i=t-16,s=i-326):(s=16,i=s+326);let a=r?82:n-16-54-12;return{left:s,right:i,y:a}}var Fa=["top-left","top-center","top-right","bottom-left","bottom-center","bottom-right"];import{domToCanvas as Yd}from"modern-screenshot";function Qi(e){let t=document.createElement("canvas").getContext("2d");return t?(t.fillStyle=e,t.fillStyle):"#888888"}function es(e,t=[],n,o){let r=new Map,i=[];for(let a of e)if(a.groupId){let l=r.get(a.groupId)||[];l.push(a),r.set(a.groupId,l)}else i.push(a);let s=[];for(let[a,l]of r){let p=l.find(u=>u.type!=="text"),c=l.find(u=>u.type==="text");if(p){let u=p.linkedSelector||c?.linkedSelector,d=c?.imageCount||p.imageCount,g=p.pathname||c?.pathname;s.push({id:p.id,type:p.type,instruction:c?.text,...u?{linkedSelector:u}:{},...g?{pathname:g}:{},elements:p.elements||[],...d?{imageCount:d}:{}})}}for(let a of i)s.push({id:a.id,type:a.type,instruction:a.type==="text"?a.text:void 0,...a.linkedSelector?{linkedSelector:a.linkedSelector}:{},...a.pathname?{pathname:a.pathname}:{},elements:a.elements||[],...a.imageCount?{imageCount:a.imageCount}:{}});return{timestamp:new Date().toISOString(),url:window.location.href,viewport:{width:window.innerWidth,height:window.innerHeight},scrollPosition:{x:window.scrollX,y:window.scrollY},annotations:s,styleModifications:t,...n?{inspectedElement:n}:{},...o&&o.length>0?{spacingTokenChanges:o}:{}}}function Vd(e){if(!e.points||e.points.length===0)return null;let t=e.points.map(o=>o.x),n=e.points.map(o=>o.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Ud(e,t){if(e.length===0)return[];let n=e.map(c=>({annotation:c,bounds:Vd(c)})).filter(c=>c.bounds!==null);if(n.length===0)return[];n.sort((c,u)=>c.bounds.minY-u.bounds.minY);let o=Math.min(...n.map(c=>c.bounds.minY)),r=Math.max(...n.map(c=>c.bounds.maxY));if(r-o<=t){let c=(o+r)/2,u=Math.max(0,c-t/2);return[{top:u,bottom:u+t,annotations:e}]}let i=[],s=50,a=Math.max(0,o-s),l=[],p=a;for(let{annotation:c,bounds:u}of n){let d=u.maxY+s;if(d-a<=t)l.push(c),p=Math.max(p,d);else{if(l.length>0){let g=(a+p)/2,x=Math.max(0,g-t/2);i.push({top:x,bottom:x+t,annotations:l})}a=Math.max(0,u.minY-s),l=[c],p=u.maxY+s}}if(l.length>0){let c=(a+p)/2,u=Math.max(0,c-t/2);i.push({top:u,bottom:u+t,annotations:l})}return i}function Kd(e){let t=new Map;for(let n of e)if(n.linkedSelector)try{let o=document.querySelector(n.linkedSelector);if(o){let r=o.getBoundingClientRect();t.set(n.id,{x:r.left+window.scrollX,y:r.top+window.scrollY,width:r.width,height:r.height})}}catch{}return t}function Xd(e,t,n,o,r){if(e.save(),e.scale(o,o),r)for(let i of t){let s=r.get(i.id);if(!s)continue;let a=s.y-n;e.fillStyle=i.color,e.globalAlpha=.05,e.fillRect(s.x,a,s.width,s.height),e.globalAlpha=1,e.strokeStyle=i.color,e.lineWidth=1,e.setLineDash([2,4]),e.strokeRect(s.x,a,s.width,s.height),e.setLineDash([])}for(let i of t){let s=i.points.map(a=>({x:a.x,y:a.y-n}));switch(e.strokeStyle=i.color,e.fillStyle=i.color,e.lineWidth=i.strokeWidth,e.lineCap="round",e.lineJoin="round",i.type){case"freehand":if(s.length<2)break;e.beginPath(),e.moveTo(s[0].x,s[0].y);for(let a=1;a<s.length;a++)e.lineTo(s[a].x,s[a].y);e.stroke();break;case"line":if(s.length<2)break;e.beginPath(),e.moveTo(s[0].x,s[0].y),e.lineTo(s[s.length-1].x,s[s.length-1].y),e.stroke();break;case"rectangle":{if(s.length<2)break;let a=s[0],l=s[s.length-1],p=Math.min(a.x,l.x),c=Math.min(a.y,l.y),u=Math.abs(l.x-a.x),d=Math.abs(l.y-a.y);e.strokeRect(p,c,u,d);break}case"circle":{if(s.length<2)break;let a=s[0],l=s[s.length-1],p=(a.x+l.x)/2,c=(a.y+l.y)/2,u=Math.abs(l.x-a.x)/2,d=Math.abs(l.y-a.y)/2;e.beginPath(),e.ellipse(p,c,u,d,0,0,Math.PI*2),e.stroke();break}case"text":{if(!i.text||s.length<1)break;let a=s[0],l=i.fontSize||16;e.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,e.fillStyle=i.color;let c=(i.imageCount&&i.imageCount>0?`[${i.imageCount} image${i.imageCount>1?"s":""}] ${i.text}`:i.text).split(`
3
- `),u=l*1.2,d=4,g=0;for(let x of c)g=Math.max(g,e.measureText(x).width);e.fillRect(a.x-d,a.y-d,g+d*2,c.length*u+d*2),e.fillStyle="#ffffff",c.forEach((x,h)=>{e.fillText(x,a.x,a.y+l+h*u)});break}}}e.restore()}async function hr(e,t,n=[],o){try{let r=o?.dpr??(window.devicePixelRatio||1),i=window.innerWidth,s=window.innerHeight,a=n.filter(u=>(u.status??"pending")==="pending");console.log("[Screenshot] Starting capture with",a.length,"active annotations (filtered",n.length-a.length,"captured)");let l=Kd(a),p=Ud(a,s);if(p.length===0){let u=await za(e,[],window.scrollY,i,s,r,l);return u?[u]:[]}let c=[];for(let u=0;u<p.length;u++){let d=p[u],g=await za(e,d.annotations,d.top,i,s,r,l);g?c.push(g):console.warn(`[Screenshot] Region ${u+1} failed to capture`)}return console.log("[Screenshot] Capture complete"),c}catch(r){return console.error("[Screenshot] Capture failed:",r),[]}}async function za(e,t,n,o,r,i,s){try{let a=getComputedStyle(document.documentElement).backgroundColor,p=await Yd(e,{filter:d=>!(d instanceof HTMLElement&&(d.id==="devtools-canvas"||d.id==="devtools-toolbar"||d.id==="devtools-scrim"||d.dataset.devtools!==void 0)),scale:i,backgroundColor:a&&a!=="rgba(0, 0, 0, 0)"&&a!=="transparent"?a:"#ffffff",width:o,height:r,style:{transform:`translate(${-window.scrollX}px, ${-n}px)`}}),c=document.createElement("canvas");c.width=o*i,c.height=r*i;let u=c.getContext("2d");return u?(u.drawImage(p,0,0,o*i,r*i,0,0,o*i,r*i),Xd(u,t,n,i,s),new Promise(d=>{c.toBlob(g=>d(g),"image/webp",.8)})):null}catch(a){return console.error("Region capture failed:",a),null}}async function _r(e){if(e.length===0)return null;if(e.length===1)return e[0];let t=await Promise.all(e.map(a=>new Promise((l,p)=>{let c=new Image;c.onload=()=>l(c),c.onerror=p,c.src=URL.createObjectURL(a)}))),n=t[0].width,o=t.reduce((a,l)=>a+l.height,0),r=document.createElement("canvas");r.width=n,r.height=o;let i=r.getContext("2d");if(!i)return null;let s=0;for(let a of t)i.drawImage(a,0,s),s+=a.height,URL.revokeObjectURL(a.src);return new Promise(a=>{r.toBlob(l=>a(l),"image/webp",.8)})}async function $a(e,t,n){try{let o=Array.isArray(e)?e:[e];if(o.length===0)return!1;let r=await _r(o);if(!r)return!1;let i=r;if(r.type!=="image/png"){let p=new Image,c=URL.createObjectURL(r);await new Promise(d=>{p.onload=()=>d(),p.src=c}),URL.revokeObjectURL(c);let u=document.createElement("canvas");u.width=p.naturalWidth,u.height=p.naturalHeight,u.getContext("2d").drawImage(p,0,0),i=await new Promise(d=>u.toBlob(g=>d(g),"image/png"))}let s={"image/png":i},a=t&&t.length>0,l=n&&n.length>0;if(a||l){let p=t?t.filter(c=>(c.status??"pending")==="pending"):[];if(p.length>0||l){let c=es(p,n||[]),u=new Blob([JSON.stringify(c,null,2)],{type:"text/plain"});s["text/plain"]=u}}return await navigator.clipboard.write([new ClipboardItem(s)]),!0}catch(o){return console.warn("Clipboard write failed:",o),!1}}var si="0.7.6";import{useCallback as nn,useEffect as hn,useMemo as Ii,useRef as Ut,useState as ut}from"react";import{useCallback as vr,useRef as Zd}from"react";function ts(e,t,n,o){if(t.length<2)return;let r=t[0],i=t[t.length-1];if(!r||!i)return;let s=(r.x+i.x)/2,a=(r.y+i.y)/2,l=Math.abs(i.x-r.x)/2,p=Math.abs(i.y-r.y)/2;e.beginPath(),e.strokeStyle=n,e.lineWidth=o,e.ellipse(s,a,l,p,0,0,Math.PI*2),e.stroke()}function ns(e,t,n,o){if(t.length<2)return;let r=t[0],i=t[t.length-1];if(!(!r||!i)){e.beginPath(),e.strokeStyle=n,e.lineWidth=o,e.lineCap="round",e.lineJoin="round",e.moveTo(r.x,r.y);for(let s=1;s<t.length-1;s++){let a=t[s],l=t[s+1];if(!a||!l)continue;let p=(a.x+l.x)/2,c=(a.y+l.y)/2;e.quadraticCurveTo(a.x,a.y,p,c)}e.lineTo(i.x,i.y),e.stroke()}}function os(e,t,n,o){if(t.length<2)return;let r=t[0],i=t[t.length-1];!r||!i||(e.beginPath(),e.strokeStyle=n,e.lineWidth=o,e.lineCap="round",e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke())}function rs(e,t,n,o){if(t.length<2)return;let r=t[0],i=t[t.length-1];if(!r||!i)return;let s=Math.min(r.x,i.x),a=Math.min(r.y,i.y),l=Math.abs(i.x-r.x),p=Math.abs(i.y-r.y);e.beginPath(),e.strokeStyle=n,e.lineWidth=o,e.lineCap="round",e.lineJoin="round",e.strokeRect(s,a,l,p)}var Vt='"JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace';function qd(e,t,n){if(!t||e.measureText(t).width<=n)return[t];let o=t.split(/\s+/),r=[],i="";for(let s of o){let a=i?i+" "+s:s;i&&e.measureText(a).width>n?(r.push(i),i=s):i=a}return i&&r.push(i),r.length>0?r:[t]}function yr(e){let t=window.innerWidth-e-16;return Math.max(60,Math.min(400,t))}function Wa(e,t,n){let o=[];for(let r of t)o.push(...qd(e,r,n));return o}function br(e,t,n){if(e.measureText(t).width<=n)return t;let o="\u2026";for(let r=t.length-1;r>0;r--){let i=t.slice(0,r)+o;if(e.measureText(i).width<=n)return i}return o}function ja(e,t,n,o,r=12,i,s){if(!n)return;let a=r*1.4,l=n.replace(/\n/g," "),p=i!==void 0?i+". "+l:l;e.font=`${r}px ${Vt}`,e.textBaseline="middle";let c=s!==void 0?Math.min(400,Math.max(60,window.innerWidth-s-16)):400,u=br(e,p,c),d=e.measureText(u).width;e.fillStyle=o,e.fillRect(t.x-4,t.y-4,d+8,a+8),e.fillStyle="#ffffff",e.fillText(u,t.x,t.y+a/2)}var Ga=11,is=4,Qd=`600 ${Ga}px system-ui, -apple-system, sans-serif`;function ss(e,t,n){return e.map(o=>({x:o.x-t,y:o.y-n}))}function eu(e,t,n,o,r,i){let s=String(o);e.font=Qd;let l=e.measureText(s).width+is*2,p=Ga+is*2,c=t-l/2,u=n+i/2+2;e.fillStyle=r,e.fillRect(c,u,l,p),e.fillStyle="#ffffff",e.textBaseline="middle",e.fillText(s,c+is,u+p/2)}function tu(e,t){if(e.points.length<2&&e.type!=="text")return null;switch(e.type){case"rectangle":case"freehand":{let n,o;if(e.type==="freehand")n=Math.min(...e.points.map(r=>r.x)),o=Math.max(...e.points.map(r=>r.y));else{let r=e.points[0],i=e.points[e.points.length-1];n=Math.min(r.x,i.x),o=Math.max(r.y,i.y)}return{x:n,y:o}}case"circle":{let n=e.points[0],o=e.points[e.points.length-1],r=Math.min(n.x,o.x),i=(Math.min(n.y,o.y)+Math.max(n.y,o.y))/2;return{x:r,y:i}}case"line":{let n=e.points[0],o=e.points[e.points.length-1],r=n.y>o.y?n:o;return{x:r.x,y:r.y}}default:return null}}function Ja(){let e=Zd(null),t=vr(()=>{let a=e.current;if(!a)return;let l=a.getContext("2d");l&&l.clearRect(0,0,a.width,a.height)},[]),n=vr((a,l,p)=>{let c=e.current;if(!c)return;let u=c.getContext("2d");if(!u)return;let g=(a.status??(a.captured?"in_flight":"pending"))==="pending"||p?a.color:"#999999";switch(a.type){case"freehand":ns(u,a.points,g,a.strokeWidth);break;case"line":os(u,a.points,g,a.strokeWidth);break;case"rectangle":rs(u,a.points,g,a.strokeWidth);break;case"circle":ts(u,a.points,g,a.strokeWidth);break;case"text":a.text&&a.points[0]&&ja(u,a.points[0],a.text,g,a.fontSize,l,a.points[0].x);break}},[]),o=vr((a,l,p,c)=>{let u=e.current;if(!u||a.length<2)return;let d=u.getContext("2d");if(d)switch(l){case"freehand":ns(d,a,p,c);break;case"line":os(d,a,p,c);break;case"rectangle":rs(d,a,p,c);break;case"circle":ts(d,a,p,c);break}},[]),r=vr((a,l)=>{let p=e.current;if(!p||a.points.length<2)return;let c=p.getContext("2d");if(c){if(c.fillStyle="#ffffff",c.strokeStyle=a.color,c.lineWidth=1.5,a.type==="line"){let u=a.points[0],d=a.points[a.points.length-1];[u,d].forEach(g=>{c.beginPath(),c.arc(g.x,g.y,l/2,0,Math.PI*2),c.fill(),c.stroke()});return}if(a.type==="circle"){let u=a.points[0],d=a.points[a.points.length-1],g=Math.min(u.x,d.x),x=Math.max(u.x,d.x),h=Math.min(u.y,d.y),I=Math.max(u.y,d.y),O=(g+x)/2,P=(h+I)/2;[{x:O,y:h},{x:O,y:I},{x:g,y:P},{x,y:P}].forEach(M=>{c.beginPath(),c.rect(M.x-l/2,M.y-l/2,l,l),c.fill(),c.stroke()});return}if(a.type==="rectangle"||a.type==="freehand"){let u,d,g,x;if(a.type==="freehand")u=Math.min(...a.points.map(I=>I.x)),d=Math.max(...a.points.map(I=>I.x)),g=Math.min(...a.points.map(I=>I.y)),x=Math.max(...a.points.map(I=>I.y));else{let I=a.points[0],O=a.points[a.points.length-1];u=Math.min(I.x,O.x),d=Math.max(I.x,O.x),g=Math.min(I.y,O.y),x=Math.max(I.y,O.y)}[{x:u,y:g},{x:d,y:g},{x:u,y:x},{x:d,y:x}].forEach(I=>{c.beginPath(),c.rect(I.x-l/2,I.y-l/2,l,l),c.fill(),c.stroke()})}}},[]),i=vr((a,l,p,c,u,d,g,x=0,h=0,I,O)=>{if(t(),a.forEach(P=>{let F={...P,points:ss(P.points,x,h)},M=I?.get(P.id),D=O?.has(P.id)??!1;n(F,M,D)}),l.length>0){let P=ss(l,x,h);o(P,p,c,u)}if(d&&d.length>0&&g){let F=e.current?.getContext("2d");for(let M of d){let D=a.find(J=>J.id===M);if(D){let J={...D,points:ss(D.points,x,h)};if(r(J,g),F&&D.type!=="text"&&I&&!(D.groupId&&a.some(C=>C.groupId===D.groupId&&C.type==="text"))){let C=I.get(D.id);if(C!==void 0){let S=tu(J,g);if(S){let y=(D.status??(D.captured?"in_flight":"pending"))==="pending"?D.color:"#999999";eu(F,S.x,S.y,C,y,g)}}}}}}},[t,n,o,r]),s=vr(()=>{let a=e.current;if(!a)return;let l=window.devicePixelRatio||1;a.width=window.innerWidth*l,a.height=window.innerHeight*l;let p=a.getContext("2d");p&&p.scale(l,l)},[]);return{canvasRef:e,clearCanvas:t,drawAnnotation:n,drawCurrentPath:o,redrawAll:i,resizeCanvas:s}}import{useEffect as nu,useRef as ou}from"react";function Ya(){let e=ou({shift:!1,cmd:!1});return nu(()=>{let t=r=>{r.key==="Shift"&&(e.current.shift=!0),(r.key==="Meta"||r.key==="Control")&&(e.current.cmd=!0)},n=r=>{r.key==="Shift"&&(e.current.shift=!1),(r.key==="Meta"||r.key==="Control")&&(e.current.cmd=!1)},o=()=>{e.current={shift:!1,cmd:!1}};return window.addEventListener("keydown",t,!0),window.addEventListener("keyup",n,!0),window.addEventListener("blur",o),()=>{window.removeEventListener("keydown",t,!0),window.removeEventListener("keyup",n,!0),window.removeEventListener("blur",o)}},[]),e}import{useEffect as ru}from"react";function Va(e,t,n,o,r){ru(()=>{let i=s=>{if(e){if(e.linkedSelector)return;s.preventDefault(),s.stopPropagation();let l=s.deltaY>0?-2:2;t(p=>p?{...p,fontSize:Math.max(12,Math.min(72,p.fontSize+l))}:null);return}if(!n)return;s.preventDefault();let a=o.find(l=>l.id===n);if(a&&a.type==="text"&&!a.linkedSelector){let l=a.fontSize||12,p=s.deltaY>0?-2:2;r({type:"UPDATE_TEXT_SIZE",payload:{id:n,fontSize:l+p}})}};return window.addEventListener("wheel",i,{passive:!1}),()=>{window.removeEventListener("wheel",i)}},[n,e,o,r,t])}import{useCallback as ll,useEffect as bi,useRef as cl,useState as $r}from"react";function ai(e){let t=Object.keys(e).find(r=>r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$"));if(!t)return null;let n=e[t],o=[];for(;n;){let r=n.type,i=r?.displayName||r?.name;i&&typeof i=="string"&&/^[A-Z]/.test(i)&&!i.startsWith("_")&&i!=="Fragment"&&o.unshift(i),n=n.return}return o.length>0?{name:o[o.length-1],path:o}:null}function as(e){let t=Object.keys(e).find(r=>r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$"));if(!t)return[];let n=e[t],o=[];for(;n;){let r=n.type,i=typeof r=="function"||typeof r=="object"?r?.displayName||r?.name:null;i&&typeof i=="string"&&/^[A-Z]/.test(i)&&!i.startsWith("_")&&i!=="Fragment"&&o.push({name:i,fiber:n}),n=n.return}return o.reverse(),o}function li(e){let t=e,n=new Set;for(;t&&!n.has(t);){if(n.add(t),t.stateNode instanceof Element)return t.stateNode;t.child?t=t.child:t=null}return null}function Ua(e){if(e.id)return`#${e.id}`;let t=e.tagName.toLowerCase(),n=Array.from(e.classList).slice(0,3).join(".");return n?`${t}.${n}`:t}function Dn(e){if(e.id&&!e.id.startsWith("radix-")&&!e.id.startsWith(":"))return`#${CSS.escape(e.id)}`;let t=[],n=e;for(;n&&n!==document.documentElement;){let o=n.tagName.toLowerCase();if(n.id&&!n.id.startsWith("radix-")&&!n.id.startsWith(":")){t.unshift(`#${CSS.escape(n.id)}`);break}let r=Array.from(n.classList).filter(s=>!s.startsWith("_")&&s.length<30).slice(0,2);r.length>0&&(o+="."+r.map(s=>CSS.escape(s)).join("."));let i=n.parentElement;if(i){let s=Array.from(i.children).filter(a=>a.tagName===n.tagName);if(s.length>1){let a=s.indexOf(n)+1;o+=`:nth-of-type(${a})`}}t.unshift(o),n=i}return t.join(" > ")}function kn(e){try{return document.querySelector(e)}catch{return null}}function ci(e,t=0){let n=as(e);if(n.length===0)return null;let o=n.map(l=>l.name),r=n.length-1,i=Math.max(0,Math.min(n.length-1,r-t)),s=n[i],a=li(s.fiber)??e;return{name:s.name,path:o,depthIndex:i,rootElement:a}}function Ka(e,t){let n=as(e),o=t.toLowerCase(),r=-1;for(let i=n.length-1;i>=0;i--){let s=n[i].name;if(s===t){let a=li(n[i].fiber)??e;return{name:t,path:n.map(l=>l.name),depthIndex:i,rootElement:a}}if(r===-1){let a=s.toLowerCase();(a.length>=4&&o.includes(a)||o.length>=4&&a.includes(o))&&(r=i)}}if(r>=0){let i=li(n[r].fiber)??e;return{name:t,path:n.map(s=>s.name),depthIndex:r,rootElement:i}}return null}function xr(e){let t=Sr(),n=[],o=new Set,r=t.currentNode;for(;r=t.nextNode();){let i=Ka(r,e);i&&!o.has(i.rootElement)&&(o.add(i.rootElement),n.push(i))}return n}function ls(e){let t=new Map;if(e.size===0)return t;let n=new Set(e),o=Sr(),r=new Set,i=o.currentNode;for(;(i=o.nextNode())&&n.size>0;)for(let s of n){let a=Ka(i,s);if(!a||r.has(a.rootElement))continue;r.add(a.rootElement);let l=a.rootElement.getBoundingClientRect();t.set(s,l.top+window.scrollY),n.delete(s);break}for(let s of n)t.set(s,1/0);return t}function Sr(){return document.createTreeWalker(document.body,NodeFilter.SHOW_ELEMENT,{acceptNode(e){return e.closest("#devtools-toolbar, #devtools-canvas, #devtools-scrim, [data-popmelt-panel]")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function Tn(e){let t={selector:Ua(e),tagName:e.tagName.toLowerCase()};e.id&&(t.id=e.id),e.classList.length>0&&(t.className=Array.from(e.classList).join(" "));let n=Xa(e);n&&n.length>0&&n.length<200&&(t.textContent=n);let o={};for(let s of e.attributes)s.name.startsWith("data-")&&(o[s.name]=s.value);Object.keys(o).length>0&&(t.dataAttributes=o);let r=ai(e);r&&(t.reactComponent=r.name);let i=iu(e);return i&&(t.context=i),t}function Xa(e){let t="";for(let n of e.childNodes)n.nodeType===Node.TEXT_NODE&&(t+=n.textContent||"");return t.trim()}function Jo(e,t){let n=document.elementsFromPoint(e,t);for(let o of n)if(o instanceof HTMLElement&&!(o.id==="devtools-canvas"||o.id==="devtools-toolbar"||o.id==="devtools-scrim")&&!o.closest("#devtools-toolbar")&&!(o.dataset.devtools||o.closest("[data-devtools]"))&&!["html","body"].includes(o.tagName.toLowerCase()))return o;return null}function iu(e){let t=e.parentElement,n=["section","article","nav","aside","header","footer","main"];for(;t&&t!==document.body;){let o=t.tagName.toLowerCase();if(n.includes(o)&&t.id)return`${o}#${t.id}`;if(t.id&&!t.id.startsWith("radix-")&&!t.id.startsWith(":"))return`${o}#${t.id}`;t=t.parentElement}return null}function qa(e){let t=new Set,n=[],o=window.scrollX,r=window.scrollY,i=[{x:(e.minX+e.maxX)/2,y:(e.minY+e.maxY)/2},{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.minX,y:e.maxY},{x:e.maxX,y:e.maxY}];for(let s of i){let a=s.x-o,l=s.y-r;if(a<0||l<0||a>window.innerWidth||l>window.innerHeight)continue;let p=Jo(a,l);p&&!t.has(p)&&(t.add(p),n.push(Tn(p)))}return n.slice(0,3)}function cs(e){if(e.length===0)return[];let t=e.map(o=>o.x),n=e.map(o=>o.y);return qa({minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)})}function tn(e,t){return e.style.getPropertyValue(t)!==""}function su(e,t=30){if(e<=0)return[];let n=[],o=Sr(),r=.5,i=o.currentNode;for(;(i=o.nextNode())&&n.length<t;){let s=i,a=s.getBoundingClientRect();if(a.bottom<-50||a.top>window.innerHeight+50||a.right<-50||a.left>window.innerWidth+50||a.width<1||a.height<1)continue;let l=getComputedStyle(s);!tn(s,"padding-top")&&Math.abs((parseFloat(l.paddingTop)||0)-e)<r&&n.push({element:s,property:"padding-top"}),!tn(s,"padding-bottom")&&Math.abs((parseFloat(l.paddingBottom)||0)-e)<r&&n.length<t&&n.push({element:s,property:"padding-bottom"}),!tn(s,"padding-left")&&Math.abs((parseFloat(l.paddingLeft)||0)-e)<r&&n.length<t&&n.push({element:s,property:"padding-left"}),!tn(s,"padding-right")&&Math.abs((parseFloat(l.paddingRight)||0)-e)<r&&n.length<t&&n.push({element:s,property:"padding-right"}),!tn(s,"margin-top")&&Math.abs((parseFloat(l.marginTop)||0)-e)<r&&n.length<t&&n.push({element:s,property:"margin-top"}),!tn(s,"margin-bottom")&&Math.abs((parseFloat(l.marginBottom)||0)-e)<r&&n.length<t&&n.push({element:s,property:"margin-bottom"}),!tn(s,"margin-left")&&Math.abs((parseFloat(l.marginLeft)||0)-e)<r&&n.length<t&&n.push({element:s,property:"margin-left"}),!tn(s,"margin-right")&&Math.abs((parseFloat(l.marginRight)||0)-e)<r&&n.length<t&&n.push({element:s,property:"margin-right"});let p=l.display;if((p.includes("flex")||p.includes("grid"))&&n.length<t){let c=tn(s,"gap"),u=parseFloat(l.gap)||0,d=parseFloat(l.rowGap)||0,g=parseFloat(l.columnGap)||0;!c&&Math.abs(u-e)<r?n.push({element:s,property:"gap"}):!tn(s,"row-gap")&&Math.abs(d-e)<r?n.push({element:s,property:"row-gap"}):!tn(s,"column-gap")&&Math.abs(g-e)<r&&n.push({element:s,property:"column-gap"})}}return n}function ds(e,t=30){if(e<=0)return[];let n=[],o=Sr(),r=.5,i=o.currentNode;for(;(i=o.nextNode())&&n.length<t;){let s=i,a=s.getBoundingClientRect();if(a.bottom<-50||a.top>window.innerHeight+50||a.right<-50||a.left>window.innerWidth+50||a.width<1||a.height<1)continue;let l=getComputedStyle(s),p=parseFloat(l.borderTopWidth)||0,c=parseFloat(l.borderRightWidth)||0,u=parseFloat(l.borderBottomWidth)||0,d=parseFloat(l.borderLeftWidth)||0,g=s.clientWidth,x=s.clientHeight,h=parseFloat(l.paddingTop)||0;!tn(s,"padding-top")&&Math.abs(h-e)<r&&n.push({x:a.left+d,y:a.top+p,width:g,height:e,direction:"vertical",property:"padding-top"});let I=parseFloat(l.paddingBottom)||0;!tn(s,"padding-bottom")&&Math.abs(I-e)<r&&n.length<t&&n.push({x:a.left+d,y:a.top+p+x-e,width:g,height:e,direction:"vertical",property:"padding-bottom"});let O=parseFloat(l.paddingLeft)||0;!tn(s,"padding-left")&&Math.abs(O-e)<r&&n.length<t&&n.push({x:a.left+d,y:a.top+p,width:e,height:x,direction:"horizontal",property:"padding-left"});let P=parseFloat(l.paddingRight)||0;!tn(s,"padding-right")&&Math.abs(P-e)<r&&n.length<t&&n.push({x:a.left+d+g-e,y:a.top+p,width:e,height:x,direction:"horizontal",property:"padding-right"});let F=parseFloat(l.marginTop)||0;!tn(s,"margin-top")&&Math.abs(F-e)<r&&n.length<t&&n.push({x:a.left,y:a.top-e,width:a.width,height:e,direction:"vertical",property:"margin-top"});let M=parseFloat(l.marginBottom)||0;!tn(s,"margin-bottom")&&Math.abs(M-e)<r&&n.length<t&&n.push({x:a.left,y:a.bottom,width:a.width,height:e,direction:"vertical",property:"margin-bottom"});let D=parseFloat(l.marginLeft)||0;!tn(s,"margin-left")&&Math.abs(D-e)<r&&n.length<t&&n.push({x:a.left-e,y:a.top,width:e,height:a.height,direction:"horizontal",property:"margin-left"});let J=parseFloat(l.marginRight)||0;!tn(s,"margin-right")&&Math.abs(J-e)<r&&n.length<t&&n.push({x:a.right,y:a.top,width:e,height:a.height,direction:"horizontal",property:"margin-right"});let ee=l.display;if((ee.includes("flex")||ee.includes("grid"))&&n.length<t&&!tn(s,"gap")){let S=Array.from(s.children).filter(A=>{let y=getComputedStyle(A);return y.display!=="none"&&y.position!=="absolute"&&y.position!=="fixed"});if(S.length>=2)for(let A=0;A<S.length-1&&n.length<t;A++){let y=S[A].getBoundingClientRect(),T=S[A+1].getBoundingClientRect(),L=T.top-y.bottom;Math.abs(L-e)<r&&L>.5&&n.push({x:Math.min(y.left,T.left),y:y.bottom,width:Math.max(y.right,T.right)-Math.min(y.left,T.left),height:L,direction:"vertical",property:"gap"});let ce=T.left-y.right;Math.abs(ce-e)<r&&ce>.5&&n.push({x:y.right,y:Math.min(y.top,T.top),width:ce,height:Math.max(y.bottom,T.bottom)-Math.min(y.top,T.top),direction:"horizontal",property:"gap"})}}}return n}function di(e){return typeof e=="string"?{value:e}:e}var Qa={gap:["gap","row-gap","column-gap"],padding:["padding-top","padding-bottom","padding-left","padding-right"],margin:["margin-top","margin-bottom","margin-left","margin-right"]};function Za(e,t){let n=Qa[t];return n?n.includes(e):!1}function au(e,t){let n=e.split(/\s+/);for(let o of n){if(o===t)return!0;let r=o.lastIndexOf(":");if(r>=0&&o.slice(r+1)===t)return!0}return!1}function lu(e){let t=e.lastIndexOf(":"),n=t>=0?e.slice(t+1):e,o=n.indexOf("-");if(o<0)return null;let r=n.slice(0,o),i={gap:"gap","gap-x":"column-gap","gap-y":"row-gap",p:"padding",pt:"padding-top",pb:"padding-bottom",pl:"padding-left",pr:"padding-right",px:"padding-left",py:"padding-top",m:"margin",mt:"margin-top",mb:"margin-bottom",ml:"margin-left",mr:"margin-right",mx:"margin-left",my:"margin-top"},s=n.slice(0,n.indexOf("-",o+1)>0?n.indexOf("-",o+1):o);return i[s]??i[r]??null}function us(e,t=30){let n=parseFloat(e.value);if(isNaN(n)||n<=0)return[];if(e.bindings&&e.bindings.length>0){let r=[],i=Sr(),s=i.currentNode;for(;(s=i.nextNode())&&r.length<t;){let a=s,l=a.getBoundingClientRect();if(l.bottom<-50||l.top>window.innerHeight+50||l.right<-50||l.left>window.innerWidth+50||l.width<1||l.height<1)continue;let p=a.className;if(typeof p=="string")for(let c of e.bindings){if(!au(p,c))continue;let u=lu(c);if(u&&!(e.property&&!Za(u,e.property))){r.push({element:a,property:u});break}}}return r}let o=su(n,t*2);return e.property?o.filter(r=>Za(r.property,e.property)).slice(0,t):o.slice(0,t)}function ps(e,t=30){let n=us(e,t),o=[];for(let r of n){let i=r.element,s=i.getBoundingClientRect(),a=getComputedStyle(i),l=parseFloat(a.borderTopWidth)||0,p=parseFloat(a.borderRightWidth)||0,c=parseFloat(a.borderLeftWidth)||0,u=i.clientWidth,d=i.clientHeight;switch(r.property){case"padding-top":{let g=parseFloat(a.paddingTop)||0;o.push({x:s.left+c,y:s.top+l,width:u,height:g,direction:"vertical",property:r.property});break}case"padding-bottom":{let g=parseFloat(a.paddingBottom)||0;o.push({x:s.left+c,y:s.top+l+d-g,width:u,height:g,direction:"vertical",property:r.property});break}case"padding-left":{let g=parseFloat(a.paddingLeft)||0;o.push({x:s.left+c,y:s.top+l,width:g,height:d,direction:"horizontal",property:r.property});break}case"padding-right":{let g=parseFloat(a.paddingRight)||0;o.push({x:s.left+c+u-g,y:s.top+l,width:g,height:d,direction:"horizontal",property:r.property});break}case"margin-top":{let g=parseFloat(a.marginTop)||0;o.push({x:s.left,y:s.top-g,width:s.width,height:g,direction:"vertical",property:r.property});break}case"margin-bottom":{let g=parseFloat(a.marginBottom)||0;o.push({x:s.left,y:s.bottom,width:s.width,height:g,direction:"vertical",property:r.property});break}case"margin-left":{let g=parseFloat(a.marginLeft)||0;o.push({x:s.left-g,y:s.top,width:g,height:s.height,direction:"horizontal",property:r.property});break}case"margin-right":{let g=parseFloat(a.marginRight)||0;o.push({x:s.right,y:s.top,width:g,height:s.height,direction:"horizontal",property:r.property});break}case"gap":case"row-gap":case"column-gap":{let g=Array.from(i.children).filter(x=>{let h=getComputedStyle(x);return h.display!=="none"&&h.position!=="absolute"&&h.position!=="fixed"});for(let x=0;x<g.length-1&&o.length<t;x++){let h=g[x].getBoundingClientRect(),I=g[x+1].getBoundingClientRect(),O=I.top-h.bottom;O>.5&&o.push({x:Math.min(h.left,I.left),y:h.bottom,width:Math.max(h.right,I.right)-Math.min(h.left,I.left),height:O,direction:"vertical",property:"gap"});let P=I.left-h.right;P>.5&&o.push({x:h.right,y:Math.min(h.top,I.top),width:P,height:Math.max(h.bottom,I.bottom)-Math.min(h.top,I.top),direction:"horizontal",property:"gap"})}break}}}return o}function el(e,t){let n=new Set,o=Nr(t);for(let r of e){let i=nl[r.property];if(!i)continue;let s=r.element.className;if(typeof s=="string")for(let a of i){let l=`${a}-${o}`;for(let p of s.split(/\s+/)){let c=p.lastIndexOf(":"),u=c>=0?p.slice(c+1):p;if(u===l){n.add(u);break}}}}return[...n]}function tl(e){let t=new Set;for(let n of e)for(let[o,r]of Object.entries(Qa))if(r.includes(n.property)){t.add(o);break}if(t.size===1)return[...t][0]}function fs(e,t,n){if(t===n)return e;let o=Nr(t),r=Nr(n);return e.map(i=>{let s=i.lastIndexOf("-");if(s<0)return i;let a=i.slice(0,s),l=i.slice(s+1);return l===o||l===`[${t}px]`?`${a}-${r}`:i})}var cu={0:"0",1:"px",2:"0.5",4:"1",6:"1.5",8:"2",12:"3",16:"4",20:"5",24:"6",28:"7",32:"8",40:"10",48:"12",64:"16",80:"20",96:"24"};function Nr(e){return cu[e]??`[${e}px]`}var nl={"padding-top":["pt","py","p"],"padding-bottom":["pb","py","p"],"padding-left":["pl","px","p"],"padding-right":["pr","px","p"],"margin-top":["mt","my","m"],"margin-bottom":["mb","my","m"],"margin-left":["ml","mx","m"],"margin-right":["mr","mx","m"],gap:["gap"],"row-gap":["gap-y","gap"],"column-gap":["gap-x","gap"]};function du(e,t,n,o){let r=nl[t];if(!r)return null;let i=Nr(n);for(let s of r){let a=new RegExp("(?:^|\\s)((?:[\\w-]+:)*"+s+"-(?:"+uu(i)+"|\\["+n+"px\\]))(?:\\s|$)"),l=e.match(a);if(l?.[1]){let p=Nr(o),c=l[1].lastIndexOf(":"),u=c>=0?l[1].slice(0,c+1):"";return{matched:l[1],suggested:`${u}${s}-${p}`}}}return null}function uu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ol(e,t,n){let o=new Set,r=[];for(let i of e){let s=Dn(i.element),a=`${s}::${i.property}`;if(o.has(a))continue;o.add(a);let l=ai(i.element),p=i.element.className||"",c=du(p,i.property,t,n);r.push({selector:s,reactComponent:l?.name,className:p,property:i.property,matchedClass:c?.matched,suggestedClass:c?.suggested})}return r}function ui(e,t){return window.getComputedStyle(e).getPropertyValue(t)}function pi(e,t){if(e instanceof HTMLElement){let o=e.style.getPropertyValue(t);if(o)return o}let n=t.replace(/-([a-z])/g,(o,r)=>r.toUpperCase());try{for(let o of document.styleSheets)try{let r=o.cssRules||o.rules;for(let i of r)if(i instanceof CSSStyleRule&&e.matches(i.selectorText)){let s=i.style.getPropertyValue(t);if(s)return s;let a=i.style[n];if(a)return a}}catch{}}catch{}return null}function fi(e){let t=window.getComputedStyle(e).display;return t==="flex"||t==="inline-flex"||t==="grid"||t==="inline-grid"}function Yo(e){let t=window.getComputedStyle(e);return{row:parseFloat(t.rowGap)||0,column:parseFloat(t.columnGap)||0}}function pu(e){let t=[];for(let n of e){let o=t.find(r=>r.axis!==n.axis?!1:n.axis==="row"?Math.abs(r.y-n.y)<2&&Math.abs(r.h-n.h)<2:Math.abs(r.x-n.x)<2&&Math.abs(r.w-n.w)<2);if(o)if(n.axis==="row"){let r=Math.min(o.x,n.x),i=Math.max(o.x+o.w,n.x+n.w);o.x=r,o.w=i-r}else{let r=Math.min(o.y,n.y),i=Math.max(o.y+o.h,n.y+n.h);o.y=r,o.h=i-r}else t.push({...n})}return t}function vo(e){let t=Array.from(e.children).filter(l=>{if(!(l instanceof HTMLElement))return!1;let p=window.getComputedStyle(l);return p.display!=="none"&&p.position!=="absolute"&&p.position!=="fixed"});if(t.length<2)return[];let n=[],o=e.getBoundingClientRect(),i=window.getComputedStyle(e).flexDirection,s=i==="column"||i==="column-reverse",a=6;for(let l=0;l<t.length-1;l++){let p=t[l].getBoundingClientRect(),c=t[l+1].getBoundingClientRect();if(c.left>p.right+.5&&n.push({axis:"column",x:p.right,y:o.top,w:c.left-p.right,h:o.height}),c.top>p.bottom+.5&&n.push({axis:"row",x:o.left,y:p.bottom,w:o.width,h:c.top-p.bottom}),!(c.left>p.right+.5)&&!(c.top>p.bottom+.5))if(s){let u=(p.bottom+c.top)/2;n.push({axis:"row",x:o.left,y:u-a/2,w:o.width,h:a})}else{let u=(p.right+c.left)/2;n.push({axis:"column",x:u-a/2,y:o.top,w:a,h:o.height})}}return pu(n)}function gs(e,t){let n=window.getComputedStyle(e),o=n.display;if(o!=="flex"&&o!=="inline-flex")return!1;let r=n.justifyContent;if(r!=="space-between"&&r!=="space-around"&&r!=="space-evenly"&&r!=="stretch")return!1;let i=n.flexDirection;return!(t!==(i==="column"||i==="column-reverse"?"row":"column")||parseFloat(t==="row"?n.rowGap:n.columnGap)>0)}function wr(e){let t=window.getComputedStyle(e);return{top:parseFloat(t.paddingTop)||0,right:parseFloat(t.paddingRight)||0,bottom:parseFloat(t.paddingBottom)||0,left:parseFloat(t.paddingLeft)||0}}function Vo(e){let t=window.getComputedStyle(e);return{"top-left":parseFloat(t.borderTopLeftRadius)||0,"top-right":parseFloat(t.borderTopRightRadius)||0,"bottom-right":parseFloat(t.borderBottomRightRadius)||0,"bottom-left":parseFloat(t.borderBottomLeftRadius)||0}}function ms(e){for(let t of e.childNodes)if(t.nodeType===Node.TEXT_NODE&&(t.textContent||"").trim().length>0)return!0;return!1}function Cr(e){let t=document.createRange(),n=!1;for(let c of e.childNodes)c.nodeType===Node.TEXT_NODE&&(c.textContent||"").trim().length>0&&(n||(t.setStart(c,0),n=!0),t.setEnd(c,c.textContent?.length??0));if(!n)return null;let o=t.getBoundingClientRect(),r=window.getComputedStyle(e),i=parseFloat(r.fontSize)||16,s=parseFloat(r.lineHeight);isNaN(s)&&(s=i*1.2);let a=Math.max(1,t.getClientRects().length),l=Math.max(o.height,a*s),p=(l-o.height)/2;return new DOMRect(o.x,o.y-p,o.width,l)}function Fr(e){let t=window.getComputedStyle(e),n=parseFloat(t.fontSize)||16,o=parseFloat(t.lineHeight);return isNaN(o)&&(o=n*1.2),{fontSize:n,lineHeight:o}}function Ve(e,t,n){e instanceof HTMLElement&&e.style.setProperty(t,n,"important")}function rl(e,t,n){e instanceof HTMLElement&&e.style.removeProperty(t)}function gi(e){for(let t of e){let n=kn(t.selector);if(!n&&t.durableSelector&&(n=kn(t.durableSelector),n)){let o=t.selector.match(/\[data-pm="([^"]+)"\]/)?.[1];o&&n.setAttribute("data-pm",o)}if(n)for(let o of t.changes)Ve(n,o.property,o.modified)}}function mi(e){for(let t of e){let n=kn(t.selector);if(n)for(let o of t.changes)rl(n,o.property,o.original)}}function sl(e,t,n,o){if(e)for(let r of e){if(r instanceof CSSGroupingRule){sl(r.cssRules,t,n,o);continue}if(r instanceof CSSStyleRule){let i=r.selectorText.toLowerCase();(i===":root"||i==="html"||i==="*"||i.includes(":root"))&&fu(r.style,t,n,o)}}}function fu(e,t,n,o){for(let r=0;r<e.length;r++){let i=e[r];if(i?.startsWith("--")){if(n.has(i))continue;n.add(i);let s=t.getPropertyValue(i).trim();al(s)&&o.push({name:i,value:s,usage:`var(${i})`})}}}var hi=null,gu=5e3;function hs(){if(hi&&Date.now()-hi.timestamp<gu)return hi.variables;let e=[],t=new Set,n=getComputedStyle(document.documentElement);try{for(let i of document.styleSheets)try{sl(i.cssRules||i.rules,n,t,e)}catch{}}catch{}let o=document.documentElement.style;for(let i=0;i<o.length;i++){let s=o[i];if(s?.startsWith("--")&&!t.has(s)){t.add(s);let a=n.getPropertyValue(s).trim();al(a)&&e.push({name:s,value:a,usage:`var(${s})`})}}let r=e.sort((i,s)=>i.name.localeCompare(s.name));return hi={variables:r,timestamp:Date.now()},r}function al(e){if(!e)return!1;let t=e.toLowerCase().trim();return!!(/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)||t.startsWith("rgb")||t.startsWith("hsl")||t.startsWith("oklch")||t.startsWith("oklab")||t.startsWith("lch")||t.startsWith("lab")||["transparent","currentcolor","inherit","white","black","red","green","blue","yellow","orange","purple","pink","gray","grey"].includes(t))}function Er(e,t){let n=t.match(/var\((--[^,)]+)(?:,\s*([^)]+))?\)/);if(n){let o=n[1],r=n[2];return getComputedStyle(document.documentElement).getPropertyValue(o).trim()||r||t}return t}function zr(e,t){if(!e)return null;let n=il(e);if(!n)return null;for(let o of t){let r=il(o.value);if(r&&n===r)return o}return null}function il(e){if(!e)return null;let t=e.trim().toLowerCase();if(t.startsWith("oklch(")){let n=t.match(/oklch\(\s*([\d.]+%?)\s+([\d.]+%?)\s+([\d.]+)/);if(n){let o=n[1].endsWith("%")?parseFloat(n[1])/100:parseFloat(n[1]),r=n[2].endsWith("%")?parseFloat(n[2])/100:parseFloat(n[2]),i=parseFloat(n[3]);o=Math.round(o*100)/100,r=Math.round(r*1e3)/1e3;let s=Math.round(i);return`oklch(${o} ${r} ${s})`}}if(t.startsWith("rgb")){let n=t.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/);if(n)return`rgb(${n[1]},${n[2]},${n[3]})`}return t.startsWith("#")?t.length===4?`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`:t.slice(0,7):t}import{Fragment as Uo,jsx as ct,jsxs as Un}from"react/jsx-runtime";var Fn=22,Lo=12,mu=3,hu=250,yi=["reviewing","considering","thinking","zhuzhing","iterating","tweaking","reflecting","noodling","pondering","finessing","polishing","riffing"],yu=3e3;function bu({left:e,top:t,avoidBottom:n,style:o,children:r,...i}){let s=e+Lo,a=t+Lo,l=n!==void 0?`${n}px`:"100vh";return ct("div",{"data-devtools":"badge-hit-area",...i,style:{position:"fixed",left:e,top:t,padding:Lo,...o},children:ct("div",{style:{transform:`translate(min(0px, calc(100vw - ${s}px - 100%)), min(0px, calc(${l} - ${a}px - 100%)))`},children:r})})}function dl({annotations:e,supersededAnnotations:t,inFlightIds:n,activeIds:o,queuePositions:r,scrollX:i,scrollY:s,annotationGroupMap:a,onViewThread:l,onSelectAnnotation:p,onHoverAnnotation:c,canvasRef:u}){let[d,g]=$r(0),[x,h]=$r(()=>Math.floor(Math.random()*yi.length)),I=!!(n&&n.size>0);bi(()=>{if(!I)return;let C=setInterval(()=>{g(A=>(A+1)%mu)},hu),S=setInterval(()=>{h(A=>(A+1)%yi.length)},yu);return()=>{clearInterval(C),clearInterval(S)}},[I]);let O=[];for(let C of e){if(C.type!=="text"||!C.text||!C.points[0]||t.has(C))continue;let S=C.groupId?e.filter(je=>je.groupId===C.groupId):[C],A=C.status??"pending",y=S.reduce((je,X)=>je+(X.replyCount??0),0),T=je=>je==="resolved"&&y===0,L=!!(n&&(n.has(C.id)||S.some(je=>n.has(je.id))))||C.status==="in_flight"||S.some(je=>je.status==="in_flight")||T(C.status)||S.some(je=>T(je.status)),ce=S.some(je=>je.status==="resolved"&&(je.replyCount??0)>0||je.status==="needs_review"),We=S.some(je=>je.threadId);if(!L&&A!=="resolved"&&A!=="needs_review"&&!ce&&!We)continue;let be=C.threadId||S.find(je=>je.threadId)?.threadId,j=A==="needs_review"||S.some(je=>je.status==="needs_review"),se=C.points[0],_=C.fontSize||12,he=_*1.4,fe=a.get(C.id),Ae=C.text.replace(/\n/g," "),De=fe!==void 0?fe+". "+Ae:Ae,ze=u?.current?.getContext("2d")??document.createElement("canvas").getContext("2d");if(!ze)continue;ze.font=`${_}px ${Vt}`;let de=se.x-i,Ee=yr(de),Ge=br(ze,De,Ee),Qe=ze.measureText(Ge).width,pt=L&&!!o&&!o.has(C.id)&&!S.some(je=>o.has(je.id));O.push({id:C.id,threadId:be,linkedSelector:C.linkedSelector||S.find(je=>je.linkedSelector)?.linkedSelector,x:se.x+Qe+4,y:se.y-4,size:he+8,color:C.color,isInFlight:L,isQueued:pt,queuePosition:void 0,isNeedsReview:j,replyCount:y})}let P=O.filter(C=>C.isQueued);if(P.length>0&&P.forEach((C,S)=>{C.queuePosition=r?.get(C.id)??`(${S+1}/${P.length})`}),O.length===0)return null;let F=2,M=u?.current?.getContext("2d")??document.createElement("canvas").getContext("2d"),D=O.map(C=>{let S;C.isQueued?S=C.queuePosition?`queued ${C.queuePosition}`:"queued":C.isInFlight?S=yi[x]??"thinking":C.replyCount>0?S=`${C.replyCount} ${C.replyCount===1?"reply":"replies"}`:S="Cancelled";let A=!C.isQueued,y=A?11:0,T=A?4:0,L=S.length*7.2;return M&&(M.font=`12px ${Vt}`,L=M.measureText(S).width),4+y+T+L+4}),J=typeof window<"u"?window.innerHeight:9999,ee=[];for(let C=0;C<O.length;C++){let S=O[C].y-s,A=Math.min(S,J-Fn),y=A+Fn,L=O[C].x-i;for(let ce=0;ce<C;ce++){let We=O[ce].y-s,be=Math.min(We,J-Fn),j=be+Fn;if(!(A<j&&y>be))continue;let _=ee[ce]+D[ce];L<_+F&&(L=_+F)}ee.push(L)}return ct(Uo,{children:O.map((C,S)=>{let A=!!C.threadId;return ct(bu,{left:ee[S]-Lo,top:C.y-s-Lo,onMouseDown:A?y=>y.stopPropagation():void 0,onClick:A?y=>{if(y.stopPropagation(),p?.(C.id),l?.(C.threadId),C.linkedSelector)try{let T=document.querySelector(C.linkedSelector);if(T){let L=T.getBoundingClientRect();(L.bottom<0||L.top>window.innerHeight)&&T.scrollIntoView({behavior:"smooth",block:"center"})}}catch{}}:void 0,onMouseEnter:c?()=>c(C.id):void 0,onMouseLeave:c?()=>c(null):void 0,style:{pointerEvents:A?"auto":"none",cursor:A?"pointer":void 0,zIndex:9999},children:ct("div",{"data-devtools":"annotation-badge",style:{height:C.size,display:"flex",alignItems:"center",backgroundColor:C.color,fontFamily:Vt,fontSize:12,color:"#ffffff",userSelect:"none",padding:`0 ${4}px`,gap:4,whiteSpace:"nowrap"},children:C.isQueued?Un("span",{style:{opacity:.5,color:"inherit"},children:["queued",C.queuePosition?` ${C.queuePosition}`:""]}):C.isInFlight?Un(Uo,{children:[ct("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"currentColor",style:{verticalAlign:"middle"},children:d===1?Un(Uo,{children:[ct("circle",{cx:"7",cy:"7",r:"2"}),ct("circle",{cx:"17",cy:"7",r:"2"}),ct("circle",{cx:"7",cy:"17",r:"2"}),ct("circle",{cx:"17",cy:"17",r:"2"})]}):Un(Uo,{children:[ct("circle",{cx:"12",cy:"6",r:"2"}),ct("circle",{cx:"6",cy:"12",r:"2"}),ct("circle",{cx:"18",cy:"12",r:"2"}),ct("circle",{cx:"12",cy:"18",r:"2"})]})}),ct("span",{style:{opacity:.7,color:"inherit"},children:yi[x]})]}):Un(Uo,{children:[C.isNeedsReview?ct("span",{style:{fontWeight:700,color:"inherit"},children:"?"}):ct("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:ct("polyline",{points:"4 12 10 18 20 6"})}),ct("span",{style:{opacity:.7,color:"inherit"},children:C.replyCount>0?`${C.replyCount} ${C.replyCount===1?"reply":"replies"}`:"Cancelled"})]})})},C.id)})})}function ys({inFlightSelectorColors:e,animated:t=!0}){let[n,o]=$r([]);return bi(()=>{if(e.size===0){o([]);return}let r=null,i=()=>{let l=[];for(let[p,c]of e){let u=kn(p);if(!u)continue;let d=u.getBoundingClientRect();l.push({selector:p,top:d.top,left:d.left,width:d.width,height:d.height,color:c})}o(l)},s=()=>{r&&cancelAnimationFrame(r),r=requestAnimationFrame(i)};i(),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s,!0);let a=new MutationObserver(s);return a.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class"]}),()=>{window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s,!0),a.disconnect(),r&&cancelAnimationFrame(r)}},[e]),n.length===0?null:Un(Uo,{children:[t&&ct("style",{children:"@keyframes popmelt-march { to { stroke-dashoffset: -6; } }"}),n.map(r=>ct("div",{"data-devtools":"marching-ants",style:{position:"fixed",top:r.top,left:r.left,width:r.width,height:r.height,pointerEvents:"none",zIndex:9995,overflow:"visible"},children:ct("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible"},children:ct("rect",{x:"0.5",y:"0.5",width:Math.max(0,r.width-1),height:Math.max(0,r.height-1),fill:"none",stroke:r.color,strokeWidth:"1",strokeDasharray:"2 4",style:t?{animation:"popmelt-march 0.5s steps(2) infinite"}:void 0})})},r.selector))]})}function ul({annotations:e,supersededAnnotations:t,scrollX:n,scrollY:o,onReply:r,annotationGroupMap:i,canvasRef:s,onHoverAnnotation:a}){let l=e.filter(u=>t.has(u)?!1:u.status==="waiting_input"&&u.question&&u.threadId);if(l.length===0)return null;let p=new Set,c=[];for(let u of l){if(!u.threadId||p.has(u.threadId))continue;p.add(u.threadId);let d=u.type==="text"?u:e.find(g=>g.groupId&&g.groupId===u.groupId&&g.type==="text")||u;if(d.type==="text"&&d.text&&d.points[0]){let g=d.points[0],x=d.fontSize||12,h=x*1.4,I=i.get(d.id),O=d.text.replace(/\n/g," "),P=I!==void 0?I+". "+O:O,M=document.createElement("canvas").getContext("2d");if(!M)continue;M.font=`${x}px ${Vt}`;let D=g.x-n,J=yr(D),ee=br(M,P,J),C=M.measureText(ee).width;c.push({annotation:u,x:g.x+C+4,y:g.y-4,size:h+8})}}return c.length===0?null:ct(Uo,{children:c.map(({annotation:u,x:d,y:g,size:x})=>ct(vu,{annotation:u,x:d-n,y:g-o,size:x,onReply:r,onHoverAnnotation:a},`question-${u.threadId}`))})}function vu({annotation:e,x:t,y:n,size:o,onReply:r,onHoverAnnotation:i}){let[s,a]=$r(!1),[l,p]=$r(""),c=cl(null),u=cl(null);bi(()=>{s&&c.current&&c.current.focus()},[s]),bi(()=>{if(!s)return;let I=P=>{u.current&&!P.composedPath().includes(u.current)&&a(!1)},O=P=>{P.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",I),document.addEventListener("keydown",O),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",O)}},[s]);let d=ll(()=>{!l.trim()||!e.threadId||(r(e.threadId,l.trim()),p(""),a(!1))},[l,e.threadId,r]),g=ll(I=>{I.key==="Enter"&&(I.metaKey||I.ctrlKey)&&(I.preventDefault(),d())},[d]),x=s?t:t-Lo,h=s?n:n-Lo;return Un("div",{ref:u,"data-devtools":"question-badge",onMouseEnter:i?()=>i(e.id):void 0,onMouseLeave:i?()=>i(null):void 0,style:{position:"fixed",left:`max(0px, ${x}px)`,top:`max(0px, ${h}px)`,padding:s?0:Lo,transform:`translate(min(0px, calc(100vw - max(0px, ${x}px) - 100%)), min(0px, calc(100vh - max(0px, ${h}px) - 100%)))`,zIndex:s?10002:9999,pointerEvents:"auto",cursor:s?void 0:"pointer"},children:[!s&&Un("div",{onClick:()=>a(!0),style:{height:o,display:"flex",alignItems:"center",backgroundColor:e.color,padding:`0 ${4}px`,gap:4,fontFamily:Vt,fontSize:12,color:"#ffffff",whiteSpace:"nowrap"},children:[Un("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[ct("line",{x1:"12",y1:"3",x2:"12",y2:"9"}),ct("line",{x1:"12",y1:"15",x2:"12",y2:"21"}),ct("line",{x1:"3",y1:"12",x2:"9",y2:"12"}),ct("line",{x1:"15",y1:"12",x2:"21",y2:"12"})]}),ct("span",{style:{opacity:.7},children:"reply?"})]}),s&&Un("div",{style:{minWidth:260,maxWidth:360,backgroundColor:"#eaeaea",fontFamily:Vt,fontSize:12,color:"#1f2937",border:"1px solid rgba(0, 0, 0, 0.1)"},children:[ct("div",{style:{padding:`${6}px ${8}px`,lineHeight:1.4},children:e.question}),Un("div",{style:{padding:`0 ${4}px ${4}px`},children:[ct("textarea",{ref:c,value:l,onChange:I=>p(I.target.value),onKeyDown:g,placeholder:"Type your reply...",style:{width:"100%",minHeight:40,padding:4,fontSize:12,fontFamily:Vt,backgroundColor:"rgba(0, 0, 0, 0.04)",color:"#1f2937",border:"1px solid rgba(0, 0, 0, 0.1)",borderRadius:0,outline:"none",resize:"vertical",lineHeight:1.4,boxSizing:"border-box"}}),ct("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:4},children:ct("button",{onClick:d,disabled:!l.trim(),style:{padding:"4px 12px",fontSize:11,fontFamily:Vt,fontWeight:600,backgroundColor:l.trim()?e.color:"rgba(0,0,0,0.1)",color:l.trim()?"#ffffff":"rgba(0,0,0,0.3)",border:"none",cursor:l.trim()?"pointer":"default"},children:"Send \u2318\u23CE"})})]})]})]})}function vi(e){let t=new Set,n=new Map;for(let i of e){if(!i.linkedSelector)continue;let s=n.get(i.linkedSelector)||[];s.push(i),n.set(i.linkedSelector,s)}let o=new Set,r=new Set;for(let i of n.values()){if(i.length<=1){i[0]?.groupId&&r.add(i[0].groupId);continue}i.sort((a,l)=>l.timestamp-a.timestamp);let s=i[0];s.groupId&&r.add(s.groupId);for(let a=1;a<i.length;a++){let l=i[a];t.add(l),l.groupId&&o.add(l.groupId)}}for(let i of e)i.groupId&&o.has(i.groupId)&&!r.has(i.groupId)&&t.add(i);return t}import{useEffect as pl,useLayoutEffect as xu,useState as fl}from"react";import{jsx as bs,jsxs as ml}from"react/jsx-runtime";function Su(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}var gl=["top-left","top-right","bottom-right","bottom-left"];function hl({element:e,radius:t,accentColor:n,hoveredCorner:o,draggingCorner:r,cursorViewport:i}){let[s,a]=fl(null),[l,p]=fl(!1);if(pl(()=>{let O=M=>{(M.key==="Meta"||M.key==="Control")&&p(!0)},P=M=>{(M.key==="Meta"||M.key==="Control")&&p(!1)},F=()=>p(!1);return window.addEventListener("keydown",O,!0),window.addEventListener("keyup",P,!0),window.addEventListener("blur",F),()=>{window.removeEventListener("keydown",O,!0),window.removeEventListener("keyup",P,!0),window.removeEventListener("blur",F)}},[]),pl(()=>{if(!e){a(null);return}let O=()=>{a(e.getBoundingClientRect())};return O(),window.addEventListener("scroll",O,{passive:!0}),window.addEventListener("resize",O,{passive:!0}),()=>{window.removeEventListener("scroll",O),window.removeEventListener("resize",O)}},[e]),xu(()=>{e&&a(e.getBoundingClientRect())},[e,t["top-left"],t["top-right"],t["bottom-right"],t["bottom-left"]]),!s)return null;let c=s.width,u=s.height,d=Su(n,.2),g={"top-left":{x:0,y:t["top-left"]},"top-right":{x:c,y:t["top-right"]},"bottom-right":{x:c,y:u-t["bottom-right"]},"bottom-left":{x:0,y:u-t["bottom-left"]}},x=new Set,h=r??o;if(h)if(l)x.add(h);else for(let O of gl)x.add(O);let I={position:"fixed",top:s.top,left:s.left,width:c,height:u,pointerEvents:"none",zIndex:9996,overflow:"visible"};return ml("div",{"data-devtools":"border-radius-handles",style:I,children:[ml("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:`0 0 ${c} ${u}`,children:[bs("rect",{x:"0.5",y:"0.5",width:Math.max(0,c-1),height:Math.max(0,u-1),fill:"none",stroke:d,strokeWidth:"1"}),gl.map(O=>{let P=g[O],F=x.has(O);return bs("circle",{cx:P.x,cy:P.y,r:O===(r??o)?3:2.5,fill:n,stroke:"#ffffff",strokeWidth:O===(r??o)?4:2,paintOrder:"stroke"},O)})]}),i&&h&&(()=>{let O=Math.round(t[h]);return bs("div",{style:{position:"fixed",left:i.x+8,top:i.y-28,background:n,color:"#fff",fontSize:11,fontWeight:600,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1,padding:"4px 4px",borderRadius:0,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9997},children:O})})()]})}import{useEffect as wu,useState as Cu}from"react";function Ko(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);if(n)return`oklch(${n[1]} / ${t})`;let o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(o){let r=parseInt(o[1],16),i=parseInt(o[2],16),s=parseInt(o[3],16);return`rgba(${r}, ${i}, ${s}, ${t})`}return`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}import{Fragment as Eu,jsx as vs,jsxs as Wr}from"react/jsx-runtime";function so({element:e,isSelected:t=!1,elementInfo:n,color:o="#3b82f6",annotationNumber:r,changeCount:i,hideTooltip:s=!1}){let[a,l]=Cu(null);if(wu(()=>{if(!e){l(null);return}let D=()=>{let J=e.getBoundingClientRect();l(J)};return D(),window.addEventListener("scroll",D,{passive:!0}),window.addEventListener("resize",D,{passive:!0}),()=>{window.removeEventListener("scroll",D),window.removeEventListener("resize",D)}},[e]),!a||!e)return null;let p={position:"fixed",top:a.top,left:a.left,width:a.width,height:a.height,pointerEvents:"none",zIndex:9996,backgroundColor:Ko(o,.05),overflow:"visible"},c=e.tagName.toLowerCase(),u=e.id?`#${e.id}`:"",d=e.classList.length>0?"."+Array.from(e.classList).slice(0,2).join("."):"",g=n?.reactComponent,x=g?`<${g}> ${c}${u}${d}`:`${c}${u}${d}`,h=22,I=a.height>=window.innerHeight,O=I?0:a.top>=h?a.top-h:a.bottom,P=I?{position:"absolute",top:8,left:8,zIndex:9997,display:"flex",alignItems:"center",gap:6,backgroundColor:o,color:"#fff",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',padding:"4px 8px",borderRadius:0,pointerEvents:"none",whiteSpace:"nowrap",maxWidth:400}:{position:"fixed",top:O,left:a.left,zIndex:9997,display:"flex",alignItems:"center",gap:6,backgroundColor:o,color:"#fff",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',padding:"4px 8px",borderRadius:0,pointerEvents:"none",whiteSpace:"nowrap",maxWidth:400},M=!s&&Wr("div",{"data-devtools":"tooltip",style:P,children:[r!==void 0&&Wr("span",{children:[r,"."]}),vs("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,minWidth:0},children:x}),i!==void 0&&i>0&&Wr("span",{style:{opacity:.8},children:["(",i," ",i===1?"change":"changes",")"]})]});return Wr(Eu,{children:[Wr("div",{"data-devtools":"highlight",style:p,children:[vs("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},children:vs("rect",{x:"0.5",y:"0.5",width:Math.max(0,a.width-1),height:Math.max(0,a.height-1),fill:"none",stroke:o,strokeWidth:"1",...!t&&{strokeDasharray:"2 4"}})}),I&&M]}),!I&&M]})}import{useEffect as yl,useLayoutEffect as ku,useState as xs}from"react";import{jsx as xo,jsxs as ws}from"react/jsx-runtime";function Ss(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}function Cs({element:e,gap:t,accentColor:n,hoveredAxis:o,draggingAxis:r,cursorViewport:i,isAutoGap:s=!1,refreshKey:a=0}){let[l,p]=xs(null),[c,u]=xs([]),[d,g]=xs(!1);if(yl(()=>{let C=y=>{(y.key==="Meta"||y.key==="Control")&&g(!0)},S=y=>{(y.key==="Meta"||y.key==="Control")&&g(!1)},A=()=>g(!1);return window.addEventListener("keydown",C,!0),window.addEventListener("keyup",S,!0),window.addEventListener("blur",A),()=>{window.removeEventListener("keydown",C,!0),window.removeEventListener("keyup",S,!0),window.removeEventListener("blur",A)}},[]),yl(()=>{if(!e){p(null),u([]);return}let C=()=>{p(e.getBoundingClientRect()),u(vo(e))};return C(),window.addEventListener("scroll",C,{passive:!0}),window.addEventListener("resize",C,{passive:!0}),()=>{window.removeEventListener("scroll",C),window.removeEventListener("resize",C)}},[e]),ku(()=>{e&&(p(e.getBoundingClientRect()),u(vo(e)))},[e,t.row,t.column,a]),!l||c.length===0)return null;let x=l.width,h=l.height,I="pm-gap-stripe-pattern",O=Ss(n,.25),P=Ss(n,.1),F=Ss(n,.2),M=8,D=2,J={position:"fixed",top:l.top,left:l.left,width:x,height:h,pointerEvents:"none",zIndex:9996,overflow:"visible"},ee=r??o;return ws("div",{"data-devtools":"gap-handles",style:J,children:[ws("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:`0 0 ${x} ${h}`,children:[xo("defs",{children:xo("pattern",{id:I,patternUnits:"userSpaceOnUse",width:"4",height:"4",patternTransform:"rotate(45)",children:xo("line",{x1:"0",y1:"0",x2:"0",y2:"4",stroke:O,strokeWidth:"1.5"})})}),xo("rect",{x:"0.5",y:"0.5",width:Math.max(0,x-1),height:Math.max(0,h-1),fill:"none",stroke:F,strokeWidth:"1"}),c.map((C,S)=>{let A=C.x-l.left,y=C.y-l.top,T=C.w,L=C.h,ce=d?C.axis===ee:!0;return(C.axis==="row"?t.row:t.column)===0?null:ws("g",{opacity:ce?1:.6,children:[xo("rect",{x:A,y,width:T,height:L,fill:P}),xo("rect",{x:A,y,width:T,height:L,fill:`url(#${I})`})]},S)}),ee&&(()=>{let C=c.filter(fe=>fe.axis===ee);if(C.length===0)return null;let S=C[0];if(i&&C.length>1){let fe=1/0;for(let Ae of C){let De=Ae.x+Ae.w/2,ze=Ae.y+Ae.h/2,de=Math.abs(i.x-De)+Math.abs(i.y-ze);de<fe&&(fe=de,S=Ae)}}let A=S.x-l.left,y=S.y-l.top,T=S.w,L=S.h,ce=A+T/2,We=y+L/2;if(s)return xo("circle",{cx:ce,cy:We,r:1.5,fill:n,stroke:"#ffffff",strokeWidth:4,paintOrder:"stroke"});let be=ee==="column",j=be?D:M,se=be?M:D,_=ce-j/2,he=We-se/2;return xo("rect",{x:_,y:he,width:j,height:se,fill:n,stroke:"#ffffff",strokeWidth:4,paintOrder:"stroke"})})()]}),i&&ee&&(()=>{let C=s?"auto":String(Math.round(ee==="row"?t.row:t.column));return xo("div",{style:{position:"fixed",left:i.x+8,top:i.y-28,background:n,color:"#fff",fontSize:11,fontWeight:600,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1,padding:"4px 4px",borderRadius:0,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9997},children:C})})()]})}import{useCallback as Lu,useEffect as Au,useState as Pu}from"react";import{useEffect as Tu,useState as bl}from"react";var Mu=3,Iu=250,Es=["reviewing","considering","thinking","zhuzhing","iterating","tweaking","reflecting","noodling","pondering","finessing","polishing","riffing"],Ru=3e3;function vl(e){let[t,n]=bl(0),[o,r]=bl(()=>Math.floor(Math.random()*Es.length));return Tu(()=>{if(!e)return;let i=setInterval(()=>n(a=>(a+1)%Mu),Iu),s=setInterval(()=>r(a=>(a+1)%Es.length),Ru);return()=>{clearInterval(i),clearInterval(s)}},[e]),{charIndex:t,word:Es[o]}}import{Fragment as ks,jsx as On,jsxs as kr}from"react/jsx-runtime";function Du(e){let{element:t}=e,n=t.tagName,o=t.id?`#${t.id}`:"",r=t.className?"."+t.className.split(" ").slice(0,2).join("."):"",i=t.reactComponent;return i?`<${i}> ${n}${o}${r}`:`${n}${o}${r}`}var xl=22,Ts=12;function Ou({left:e,top:t,avoidBottom:n,style:o,children:r,...i}){let s=n!==void 0?`${n}px`:"100vh";return On("div",{"data-devtools":"badge-hit-area",...i,style:{position:"fixed",left:`max(0px, ${e}px)`,top:`max(0px, ${t}px)`,padding:Ts,transform:`translate(min(0px, calc(100vw - max(0px, ${e}px) - 100%)), min(0px, calc(${s} - max(0px, ${t}px) - 100%)))`,...o},children:r})}function Sl({styleModifications:e,isInspecting:t,accentColor:n,annotationGroupCount:o,dispatch:r,inFlightSelectors:i,toolbarRef:s,onHoverSelector:a}){let[l,p]=Pu([]),c=i&&i.size>0,{charIndex:u,word:d}=vl(!!c);Au(()=>{if(t){p([]);return}let P=null,F=()=>{let J=[];e.forEach((ee,C)=>{let S=kn(ee.selector);if(!S)return;let A=S.getBoundingClientRect();J.push({selector:ee.selector,modIndex:C,top:A.top>=xl?A.top-xl:A.bottom,left:A.left,label:Du(ee),changeCount:ee.changes.length,annotationNumber:o+C+1})}),p(J)},M=()=>{P&&cancelAnimationFrame(P),P=requestAnimationFrame(F)};F(),window.addEventListener("scroll",M,!0),window.addEventListener("resize",M,!0);let D=new MutationObserver(M);return D.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class"]}),window.addEventListener("load",M),document.fonts.ready.then(M),()=>{window.removeEventListener("scroll",M,!0),window.removeEventListener("resize",M,!0),window.removeEventListener("load",M),D.disconnect(),P&&cancelAnimationFrame(P)}},[e,t,o]);let g=Lu(P=>{let F=e[P];if(!F)return;let M=kn(F.selector);M&&(r({type:"SELECT_ANNOTATION",payload:{id:null}}),r({type:"SET_TOOL",payload:"inspector"}),r({type:"SELECT_ELEMENT",payload:{el:M,info:F.element}}))},[e,r]);if(l.length===0)return null;let x=s?.current?.getBoundingClientRect(),h=x?x.top-8:void 0,I={display:"flex",alignItems:"center",gap:6,backgroundColor:n,color:"#fff",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',padding:"4px 8px",borderRadius:0,whiteSpace:"nowrap",maxWidth:400},O={overflow:"hidden",textOverflow:"ellipsis",flex:1,minWidth:0};return On(ks,{children:l.map(P=>{let F=i?.has(P.selector);return On(Ou,{left:P.left-Ts,top:P.top-Ts,avoidBottom:h,onClick:()=>g(P.modIndex),onMouseEnter:a?()=>a(P.selector):void 0,onMouseLeave:a?()=>a(null):void 0,style:{zIndex:1e4,cursor:"pointer",pointerEvents:"auto"},children:kr("div",{"data-devtools":"badge",style:{...I,backgroundColor:F?"#999999":n},children:[kr("span",{children:[P.annotationNumber,"."]}),On("span",{style:O,children:P.label}),kr("span",{style:{opacity:.8},children:["(",P.changeCount," ",P.changeCount===1?"change":"changes",")"]}),F&&kr("span",{style:{opacity:.8,marginLeft:4,display:"inline-flex",alignItems:"center",gap:4},children:[On("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"currentColor",style:{verticalAlign:"middle"},children:u===1?kr(ks,{children:[On("circle",{cx:"7",cy:"7",r:"2"}),On("circle",{cx:"17",cy:"7",r:"2"}),On("circle",{cx:"7",cy:"17",r:"2"}),On("circle",{cx:"17",cy:"17",r:"2"})]}):kr(ks,{children:[On("circle",{cx:"12",cy:"6",r:"2"}),On("circle",{cx:"6",cy:"12",r:"2"}),On("circle",{cx:"18",cy:"12",r:"2"}),On("circle",{cx:"12",cy:"18",r:"2"})]})}),d]})]})},P.selector)})})}import{useEffect as Bu,useState as Hu}from"react";import{Fragment as Nu,jsx as wl}from"react/jsx-runtime";function _u(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}function Cl({styleModifications:e,accentColor:t}){let[n,o]=Hu([]);if(Bu(()=>{let i=null,s=()=>{let p=[];for(let c of e){let u=kn(c.selector);if(!u)continue;let d=u.getBoundingClientRect();if(d.width===0&&d.height===0)continue;let g=Vo(u);p.push({selector:c.selector,top:d.top,left:d.left,width:d.width,height:d.height,borderRadius:`${g["top-left"]}px ${g["top-right"]}px ${g["bottom-right"]}px ${g["bottom-left"]}px`})}o(p)},a=()=>{i&&cancelAnimationFrame(i),i=requestAnimationFrame(s)};s(),window.addEventListener("scroll",a,{passive:!0}),window.addEventListener("resize",a,{passive:!0});let l=new MutationObserver(a);return l.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class"]}),()=>{window.removeEventListener("scroll",a),window.removeEventListener("resize",a),l.disconnect(),i&&cancelAnimationFrame(i)}},[e]),n.length===0)return null;let r=_u(t,.2);return wl(Nu,{children:n.map(i=>{let s={position:"fixed",top:i.top,left:i.left,width:i.width,height:i.height,pointerEvents:"none",zIndex:9995,border:`1px solid ${r}`,borderRadius:i.borderRadius,boxSizing:"border-box"};return wl("div",{"data-devtools":"mod-border",style:s},i.selector)})})}import{useEffect as El,useLayoutEffect as Fu,useState as kl}from"react";import{jsx as Ao,jsxs as Is}from"react/jsx-runtime";function Ms(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}var zu={top:"bottom",bottom:"top",left:"right",right:"left"};function Rs({element:e,padding:t,accentColor:n,hoveredSide:o,draggingSide:r,cursorViewport:i,refreshKey:s}){let[a,l]=kl(null),[p,c]=kl(!1);if(El(()=>{let T=We=>{(We.key==="Meta"||We.key==="Control")&&c(!0)},L=We=>{(We.key==="Meta"||We.key==="Control")&&c(!1)},ce=()=>c(!1);return window.addEventListener("keydown",T,!0),window.addEventListener("keyup",L,!0),window.addEventListener("blur",ce),()=>{window.removeEventListener("keydown",T,!0),window.removeEventListener("keyup",L,!0),window.removeEventListener("blur",ce)}},[]),El(()=>{if(!e){l(null);return}let T=()=>{l(e.getBoundingClientRect())};return T(),window.addEventListener("scroll",T,{passive:!0}),window.addEventListener("resize",T,{passive:!0}),()=>{window.removeEventListener("scroll",T),window.removeEventListener("resize",T)}},[e]),Fu(()=>{e&&l(e.getBoundingClientRect())},[e,t.top,t.right,t.bottom,t.left,s]),!a)return null;let u=a.width,d=a.height,{top:g,right:x,bottom:h,left:I}=t,O="pm-stripe-pattern",P=Ms(n,.25),F=Ms(n,.1),M=Ms(n,.2),D=8,J=2,ee={position:"fixed",top:a.top,left:a.left,width:u,height:d,pointerEvents:"none",zIndex:9996,overflow:"visible"},C=["top","right","bottom","left"],S={top:`0,0 ${u},0 ${u-x},${g} ${I},${g}`,right:`${u},0 ${u},${d} ${u-x},${d-h} ${u-x},${g}`,bottom:`0,${d} ${I},${d-h} ${u-x},${d-h} ${u},${d}`,left:`0,0 ${I},${g} ${I},${d-h} 0,${d}`},A={top:{x:u/2-D/2,y:g/2-J/2,w:D,h:J},bottom:{x:u/2-D/2,y:d-h/2-J/2,w:D,h:J},left:{x:I/2-J/2,y:d/2-D/2,w:J,h:D},right:{x:u-x/2-J/2,y:d/2-D/2,w:J,h:D}},y=new Set;return r?y.add(r):o&&(y.add(o),p||y.add(zu[o])),Is("div",{"data-devtools":"padding-handles",style:ee,children:[Is("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:`0 0 ${u} ${d}`,children:[Ao("defs",{children:Ao("pattern",{id:O,patternUnits:"userSpaceOnUse",width:"4",height:"4",patternTransform:"rotate(45)",children:Ao("line",{x1:"0",y1:"0",x2:"0",y2:"4",stroke:P,strokeWidth:"1.5"})})}),Ao("rect",{x:"0.5",y:"0.5",width:Math.max(0,u-1),height:Math.max(0,d-1),fill:"none",stroke:M,strokeWidth:"1"}),C.map(T=>{if(t[T]<=0)return null;let ce=y.has(T);return Is("g",{opacity:ce?1:.6,children:[Ao("polygon",{points:S[T],fill:F}),Ao("polygon",{points:S[T],fill:`url(#${O})`})]},T)}),C.map(T=>{let L=A[T],ce=y.has(T);return Ao("rect",{x:L.x,y:L.y,width:L.w,height:L.h,fill:n,stroke:"#ffffff",strokeWidth:ce?4:2,paintOrder:"stroke"},`handle-${T}`)})]}),i&&(o||r)&&(()=>{let L=Math.round(t[r??o]);return Ao("div",{style:{position:"fixed",left:i.x+8,top:i.y-28,background:n,color:"#fff",fontSize:11,fontWeight:600,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1,padding:"4px 4px",borderRadius:0,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9997},children:L})})()]})}import{useCallback as ao,useEffect as $n,useMemo as Mi,useRef as An,useState as pn}from"react";import{Check as Ti,ChevronDown as _s,MoveHorizontal as _l,Shrink as up}from"lucide-react";var $u="data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPScxMicgaGVpZ2h0PScxMic+PGRlZnM+PHBhdHRlcm4gaWQ9J2QnIHdpZHRoPSc0JyBoZWlnaHQ9JzQnIHBhdHRlcm5Vbml0cz0ndXNlclNwYWNlT25Vc2UnPjxwYXRoIGQ9J00tMSwxIGwyLC0yIE0wLDQgbDQsLTQgTTMsNSBsMiwtMicgc3Ryb2tlPSdibGFjaycgc3Ryb2tlLXdpZHRoPScuNScvPjwvcGF0dGVybj48L2RlZnM+PHJlY3Qgd2lkdGg9JzEyJyBoZWlnaHQ9JzEyJyBmaWxsPSd1cmwoI2QpJy8+PC9zdmc+",Po={borderWidth:3,borderStyle:"solid",borderImage:`url("${$u}") 4 / 1.9 / 0 round`};function xi({color:e="rgb(0,0,0)",animated:t=!1}={}){let n=`<svg xmlns='http://www.w3.org/2000/svg' width='5' height='5'><path d='M-1,1 l2,-2 M0,5 l5,-5 M4,6 l2,-2' stroke='${e}' stroke-width='.75'/></svg>`;return{position:"absolute",inset:-3,padding:5,backgroundImage:`url("data:image/svg+xml,${encodeURIComponent(n)}")`,backgroundSize:"5px 5px",WebkitMask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",WebkitMaskComposite:"xor",mask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",maskComposite:"exclude",pointerEvents:"none",...t?{animation:"popmelt-border-march 0.8s linear infinite"}:{}}}var Si={"font-size":["rem","px","em"],"line-height":["","rem","px","em"],"letter-spacing":["rem","px","em"],gap:["rem","px","em"],"column-gap":["rem","px","em"],"row-gap":["rem","px","em"],padding:["rem","px","em","%"],margin:["rem","px","em","%"],width:["rem","px","%","em"],height:["rem","px","%","em"],"min-width":["rem","px","%","em"],"max-width":["rem","px","%","em"],"min-height":["rem","px","%","em"],"max-height":["rem","px","%","em"],"border-width":["px","rem","em"],"border-radius":["rem","px","%","em"]};function Tr(e){return Si[e]?.[0]??"px"}function Do(e){let t=e.match(/^([\d.-]+)(.*)$/);return t?{num:parseFloat(t[1]),unit:t[2]||""}:{num:0,unit:""}}function wi(e,t,n,o){let r=e.trim();if(!r)return"";let i=r.match(/^(-?[\d.]+)\s*(rem|em|px|%)$/i);if(i)return`${parseFloat(i[1])}${i[2].toLowerCase()}`;let s=parseFloat(r);if(!isNaN(s)){if(o){let{unit:a}=Do(n);return`${s}${a||Tr(t)}`}return`${s}${Tr(t)}`}return r}function Ls(e,t){if(!t||t==="px")return e;if(t==="rem"){let n=parseFloat(getComputedStyle(document.documentElement).fontSize)||16;return Math.round(e/n*1e3)/1e3}return e}import{useCallback as Wu,useEffect as ju,useRef as Tl,useState as Gu}from"react";import{Plus as Ml,X as Ju}from"lucide-react";import{jsx as Ln,jsxs as Xo}from"react/jsx-runtime";var Ci=[{name:"blur",label:"Blur",unit:"px",defaultValue:10,min:0,max:100,step:1},{name:"brightness",label:"Brightness",unit:"",defaultValue:1,min:0,max:3,step:.05},{name:"contrast",label:"Contrast",unit:"",defaultValue:1,min:0,max:3,step:.05},{name:"saturate",label:"Saturate",unit:"",defaultValue:1,min:0,max:3,step:.05},{name:"grayscale",label:"Grayscale",unit:"",defaultValue:0,min:0,max:1,step:.05},{name:"sepia",label:"Sepia",unit:"",defaultValue:0,min:0,max:1,step:.05},{name:"invert",label:"Invert",unit:"",defaultValue:0,min:0,max:1,step:.05},{name:"hue-rotate",label:"Hue Rotate",unit:"deg",defaultValue:0,min:0,max:360,step:1},{name:"opacity",label:"Opacity",unit:"",defaultValue:1,min:0,max:1,step:.05}];function Yu(e){if(!e||e==="none")return[];let t=[],n=/([\w-]+)\(([^)]+)\)/g,o;for(;(o=n.exec(e))!==null;){let r=o[1],i=o[2],s=parseFloat(i);isNaN(s)||t.push({name:r,value:s})}return t}function As(e){return e.length===0?"none":e.map(t=>{let o=Ci.find(r=>r.name===t.name)?.unit??"";return`${t.name}(${t.value}${o})`}).join(" ")}function Il({value:e,onChange:t,accentColor:n,modified:o,panelContentRef:r}){let i=Yu(e),[s,a]=Gu(!1),l=Tl(null),p=Tl(null);ju(()=>{if(!s)return;let F=M=>{l.current&&!M.composedPath().includes(l.current)&&a(!1)};return document.addEventListener("mousedown",F,!0),()=>document.removeEventListener("mousedown",F,!0)},[s]);let c=Ci.filter(F=>!i.some(M=>M.name===F.name)),u=F=>{let M=[...i,{name:F.name,value:F.defaultValue}];t(As(M)),a(!1)},d=F=>{let M=i.filter((D,J)=>J!==F);t(As(M))},g=(F,M)=>{let D=i.map((J,ee)=>ee===F?{...J,value:M}:J);t(As(D))},x={width:"100%",padding:"4px 8px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',border:"none",borderRadius:2,outline:"none",backgroundColor:"transparent"},h=Wu(F=>{if(!p.current)return{position:"fixed",top:0,left:0};let M=p.current.getBoundingClientRect(),D=r?.current?.getBoundingClientRect(),J=F*24+8;return{position:"fixed",...window.innerHeight-M.bottom<J?{bottom:window.innerHeight-M.top+2}:{top:M.bottom+2},left:D?D.left+4:M.left,width:D?D.width-8:140,zIndex:10001}},[r]),I={backgroundColor:"rgba(255, 255, 255, 0.95)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:"1px solid rgba(0,0,0,0.1)",borderRadius:4,padding:"4px 0",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},O={display:"block",width:"100%",padding:"4px 10px",border:"none",backgroundColor:"transparent",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#334155",cursor:"pointer",textAlign:"left"},P=F=>Ln("div",{ref:l,style:{...h(F.length),...I},children:F.map(M=>Ln("button",{type:"button",onClick:()=>u(M),style:O,onMouseEnter:D=>{D.currentTarget.style.backgroundColor="rgba(0,0,0,0.05)"},onMouseLeave:D=>{D.currentTarget.style.backgroundColor="transparent"},children:M.label},M.name))});return i.length===0?Xo("div",{children:[Xo("div",{style:{display:"flex",alignItems:"center",gap:4},children:[Ln(So,{modified:!1,children:Ln("input",{type:"text",value:"",placeholder:"\u2014",readOnly:!0,style:{...x,color:"#999",cursor:"default"}})}),Ln("button",{ref:p,type:"button",onClick:()=>a(!s),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",borderRadius:2,backgroundColor:"transparent",color:"#94a3b8",cursor:"pointer",flexShrink:0},children:Ln(Ml,{size:12})})]}),s&&P(Ci)]}):Xo("div",{style:{display:"flex",flexDirection:"column",gap:4,position:"relative"},children:[i.map((F,M)=>{let D=Ci.find(J=>J.name===F.name);return D?Xo("div",{style:{display:"flex",alignItems:"center",gap:4},children:[Ln("span",{style:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:o?n:"#94a3b8",fontWeight:o?600:400,width:56,flexShrink:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:D.label}),Ln(So,{modified:o,children:Xo("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"0 4px"},children:[Ln("input",{type:"range",min:D.min,max:D.max,step:D.step,value:F.value,onChange:J=>g(M,parseFloat(J.target.value)),style:{flex:1,height:2,appearance:"none",WebkitAppearance:"none",background:`linear-gradient(to right, ${n} ${(F.value-D.min)/(D.max-D.min)*100}%, rgba(0,0,0,0.1) ${(F.value-D.min)/(D.max-D.min)*100}%)`,borderRadius:1,outline:"none",cursor:"pointer"}}),Ln("input",{type:"number",min:D.min,max:D.max,step:D.step,value:D.unit==="px"||D.unit==="deg"?Math.round(F.value):Math.round(F.value*100)/100,onChange:J=>g(M,parseFloat(J.target.value)||0),style:{...x,width:44,padding:"2px 4px",textAlign:"right",flexShrink:0}}),D.unit&&Ln("span",{style:{fontSize:9,color:"#94a3b8",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',flexShrink:0,width:16},children:D.unit})]})}),Ln("button",{type:"button",onClick:()=>d(M),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,padding:0,border:"none",borderRadius:2,backgroundColor:"transparent",color:"#94a3b8",cursor:"pointer",flexShrink:0},children:Ln(Ju,{size:10})})]},F.name):null}),c.length>0&&Xo("div",{children:[Xo("button",{ref:p,type:"button",onClick:()=>a(!s),style:{display:"flex",alignItems:"center",gap:4,padding:"2px 4px",border:"none",borderRadius:2,backgroundColor:"transparent",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#94a3b8",cursor:"pointer"},children:[Ln(Ml,{size:10}),"Add filter"]}),s&&P(c)]})]})}import{useCallback as Xn,useEffect as Xu,useRef as Ei,useState as Rl}from"react";import{AlignHorizontalSpaceAround as qu,AlignVerticalSpaceAround as Zu,Columns3 as Qu,Grid2x2 as ep,RectangleHorizontal as tp,Rows3 as np,UnfoldHorizontal as Ll,UnfoldVertical as Al}from"lucide-react";import{useCallback as Vu,useEffect as Uu,useRef as jr}from"react";import{jsx as Ku}from"react/jsx-runtime";var Ps=[0,1,2,4,8,12,16,20,24,28,32];function Mr({value:e,onChange:t,onPreview:n,onScrubEnd:o,onReset:r,isModified:i,accentColor:s,defaultUnit:a="rem",snapSteps:l,color:p,style:c,children:u}){let d=jr(null),g=jr(null),x=jr(r),h=jr(i),I=jr(!1);x.current=r,h.current=i,Uu(()=>{let P=M=>{let D=g.current;if(!D)return;D.hasMoved=!0,I.current=M.shiftKey;let J=D.unit==="rem"||D.unit==="em"?.1:1;D.accum+=M.movementX*J;let ee=Math.max(0,Math.round((D.startValue+D.accum)*10)/10);if(M.shiftKey&&l){let C=D.unit==="rem"||D.unit==="em"?parseFloat(getComputedStyle(document.documentElement).fontSize)||16:1,S=D.unit==="rem"||D.unit==="em"?ee*C:ee,A=l[l.length-1];for(let y=0;y<l.length-1;y++){let T=l[y],L=l[y+1];if(S<=(T+L)/2){A=T;break}if(S<L){A=L;break}}S>l[l.length-1]&&(A=Math.round(S/8)*8),ee=D.unit==="rem"||D.unit==="em"?Math.round(A/C*1e3)/1e3:A}n?.(`${ee}${D.unit}`)},F=()=>{let M=g.current;if(!M)return;let D=Math.max(0,Math.round((M.startValue+M.accum)*10)/10);if(I.current&&l){let ee=M.unit==="rem"||M.unit==="em"?parseFloat(getComputedStyle(document.documentElement).fontSize)||16:1,C=M.unit==="rem"||M.unit==="em"?D*ee:D,S=l[l.length-1];for(let A=0;A<l.length-1;A++){let y=l[A],T=l[A+1];if(C<=(y+T)/2){S=y;break}if(C<T){S=T;break}}C>l[l.length-1]&&(S=Math.round(C/8)*8),D=M.unit==="rem"||M.unit==="em"?Math.round(S/ee*1e3)/1e3:S}let J=M.hasMoved&&D!==M.startValue;g.current=null,document.exitPointerLock(),J?t(`${D}${M.unit}`):M.hasMoved?n?.(`${M.startValue}${M.unit}`):h.current&&x.current&&x.current(),o?.()};return document.addEventListener("mousemove",P),document.addEventListener("mouseup",F),()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",F)}},[t,n,o]);let O=Vu(P=>{if(P.button!==0)return;P.preventDefault();let F=Do(e),M=F.unit&&F.unit!=="px"?F.unit:a;g.current={startValue:F.num,unit:M,accum:0,hasMoved:!1},d.current?.requestPointerLock()},[e,a]);return Ku("span",{ref:d,onMouseDown:O,title:i?"Click to reset \xB7 Drag to scrub":"Drag to scrub",style:{color:i?s||"#3b82f6":p||"#999",padding:"0 4px",display:"flex",alignItems:"center",cursor:"ew-resize",...c},children:u})}import{Fragment as Ds,jsx as Te,jsxs as sn}from"react/jsx-runtime";function op({gridCols:e,gridRows:t,gridModified:n,accentColor:o,onColsChange:r,onRowsChange:i}){return Te(Bn,{style:{width:100},children:sn("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"8px 4px"},children:[Te("input",{type:"number",min:1,max:12,value:e,onChange:s=>r(parseInt(s.target.value)||1),style:{...un,width:32,textAlign:"center",padding:2}}),Te("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:n?o:"#999",fontWeight:n?600:400,fontSize:11,margin:"0 4px"},children:"\xD7"}),Te("input",{type:"number",min:1,max:12,value:t,onChange:s=>i(parseInt(s.target.value)||1),style:{...un,width:32,textAlign:"center",padding:2}})]})})}function Pl({element:e,getValue:t,getOriginalValue:n,handleChange:o,isModified:r,onResetProperty:i,isCollapsed:s,onToggle:a,sectionHeaderStyle:l,activeDropdown:p,onDropdownChange:c,panelContentRef:u,accentColor:d,onFieldHover:g,preferredUnit:x,onUnitCycle:h}){let I=c,O=t("display"),P=t("flex-direction"),F=Dl(O,P),M=O==="flex"||O==="inline-flex",D=O==="grid",J=M||D,ee=P==="column"||P==="column-reverse",C=t("width"),S=t("height"),A=r("width")?C:pi(e,"width"),y=r("height")?S:pi(e,"height"),T=Os(C,A),L=Os(S,y),ce=t("min-width"),We=t("max-width"),be=t("min-height"),j=t("max-height"),se=Ir(t("padding")),_=t("gap"),he=t("row-gap"),fe=t("column-gap"),Ae=t("grid-template-columns"),De=t("grid-template-rows"),ze=t("overflow"),de=Ae.split(/\s+/).filter(U=>U&&U!=="none").length||1,Ee=De.split(/\s+/).filter(U=>U&&U!=="none").length||1,[Ge,Qe]=Rl(!1),pt=p!==null,je=pt||Ge,X=pt?.3:Ge?.65:1,Z=({mode:U,icon:Me,active:He})=>Te("button",{type:"button",onClick:()=>Ol(U,o),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:"6px 8px",border:"none",borderRadius:2,backgroundColor:He?Ko(d,.15):"transparent",color:He?d:"#64748b",cursor:"pointer",fontSize:14},children:Me}),Se=(U,Me,He)=>{He==="fixed"?o(U,Me):o(U,ki(He,Me))},Je=U=>{let Me=Ir(t("padding")),He=U||"0";o("padding",`${Me.top} ${He} ${Me.bottom} ${He}`)},lt=U=>{let Me=Ir(t("padding")),He=U||"0";o("padding",`${He} ${Me.right} ${He} ${Me.left}`)},[ke,nt]=Rl({}),ot=Xn((U,Me)=>He=>{Me(He),nt(Pt=>({...Pt,[U]:He}))},[]),rt=Xn(U=>{nt(Me=>{let He={...Me};return delete He[U],He})},[]),Lt=Xn(U=>{let Me=Ir(t("padding"));Ve(e,"padding",`${Me.top} ${U} ${Me.bottom} ${U}`)},[e,t]),yt=Xn(U=>{let Me=Ir(t("padding"));Ve(e,"padding",`${U} ${Me.right} ${U} ${Me.left}`)},[e,t]),ne=Xn(U=>Me=>{Ve(e,U,Me)},[e]),te=ee?"row":"column",ge=te==="row"?"row-gap":"column-gap",Pe=ge==="row-gap"?he||_:fe||_,et=r(ge)||r("gap"),Re=Xn(()=>{let Me=vo(e).find(Pt=>Pt.axis===te);if(Me)return te==="row"?Me.h:Me.w;let He=Yo(e);return te==="row"?He.row:He.column},[e,te]),Nt=Xn(()=>{let U=t("justify-content");return U==="space-between"?"between":U==="space-around"||U==="space-evenly"?"around":"fixed"},[t])(),xn=Xn((U,Me)=>{if(U==="fixed"){let He=Math.max(0,Math.round(Re()*1e3)/1e3),Pt=Me||(He>0?`${He}px`:"8px");o("justify-content","normal"),o(ge,Pt);return}o("justify-content",U==="between"?"space-between":"space-around"),o(ge,"0px")},[ge,Re,o]),Pn=Xn(U=>{if(Nt!=="fixed"){xn("fixed",U);return}o(ge,U)},[xn,Nt,ge,o]),At=Xn(U=>{Ve(e,"justify-content","normal"),Ve(e,ge,U)},[e,ge]),xt=U=>U==="center"?1:U==="flex-end"||U==="end"?2:0,Kt=xt(t("justify-content")),ft=xt(t("align-items")),Jt=ee?ft:Kt,tt=ee?Kt:ft,Gn=Ei(null),on=Ei({x:0,y:0}),Mn=Ei({col:Jt,row:tt});Mn.current={col:Jt,row:tt};let no=Xn((U,Me)=>{let He=["flex-start","center","flex-end"];ee?(o("justify-content",He[Me]),o("align-items",He[U])):(o("justify-content",He[U]),o("align-items",He[Me]))},[ee,o]),oo=Ei(no);oo.current=no,Xu(()=>{let Me=He=>{let Pt=Gn.current;if(!Pt||!He.composedPath().includes(Pt))return;He.preventDefault(),He.stopPropagation(),on.current.x+=He.deltaX,on.current.y+=He.deltaY;let{col:Xe,row:Oe}=Mn.current,St=!1;Math.abs(on.current.x)>=30&&(Xe=Math.max(0,Math.min(2,Xe+(on.current.x>0?1:-1))),on.current.x=0,on.current.y=0,St=!0),!St&&Math.abs(on.current.y)>=30&&(Oe=Math.max(0,Math.min(2,Oe+(on.current.y>0?1:-1))),on.current.x=0,on.current.y=0,St=!0),St&&(Xe!==Mn.current.col||Oe!==Mn.current.row)&&oo.current(Xe,Oe)};return document.addEventListener("wheel",Me,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",Me,{capture:!0})},[]);let qe=()=>Te("div",{ref:Gn,onMouseEnter:()=>{Qe(!0),u.current&&(u.current.style.overflowY="hidden")},onMouseLeave:()=>{Qe(!1),u.current&&(u.current.style.overflowY="auto")},style:{width:56,height:56,backgroundColor:zn,borderRadius:2,display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gridTemplateRows:"repeat(3, 1fr)",padding:6,gap:2,touchAction:"none"},children:[0,1,2].map(U=>[0,1,2].map(Me=>Te("button",{type:"button",onClick:()=>no(Me,U),style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",border:"none",backgroundColor:"transparent",cursor:"pointer",padding:0},children:Me===Jt&&U===tt?Te("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",style:{flexShrink:0},children:Me===0?sn(Ds,{children:[Te("rect",{x:"1",y:"1.5",width:"8",height:"1.2",rx:"0.5",fill:d}),Te("rect",{x:"1",y:"4.4",width:"5",height:"1.2",rx:"0.5",fill:d}),Te("rect",{x:"1",y:"7.3",width:"7",height:"1.2",rx:"0.5",fill:d})]}):Me===1?sn(Ds,{children:[Te("rect",{x:"1",y:"1.5",width:"8",height:"1.2",rx:"0.5",fill:d}),Te("rect",{x:"2.5",y:"4.4",width:"5",height:"1.2",rx:"0.5",fill:d}),Te("rect",{x:"1.5",y:"7.3",width:"7",height:"1.2",rx:"0.5",fill:d})]}):sn(Ds,{children:[Te("rect",{x:"1",y:"1.5",width:"8",height:"1.2",rx:"0.5",fill:d}),Te("rect",{x:"4",y:"4.4",width:"5",height:"1.2",rx:"0.5",fill:d}),Te("rect",{x:"2",y:"7.3",width:"7",height:"1.2",rx:"0.5",fill:d})]})}):Te("div",{style:{width:5,height:5,borderRadius:"50%",backgroundColor:"#aaa"}})},`${U}-${Me}`)))}),st=r("grid-template-columns")||r("grid-template-rows");return sn("div",{style:{borderBottom:"1px solid rgba(0,0,0,0.08)"},children:[Te("div",{style:l,children:Te("span",{children:J?"Auto layout":"Layout"})}),sn("div",{style:{padding:"8px 12px"},children:[sn("div",{style:{display:"flex",gap:2,marginBottom:8,backgroundColor:zn,borderRadius:2,padding:2,opacity:X,transition:"opacity 150ms ease"},children:[Te(Z,{mode:"block",icon:Te(tp,{size:16}),active:F==="block"}),Te(Z,{mode:"flex-col",icon:Te(np,{size:16}),active:F==="flex-col"}),Te(Z,{mode:"flex-row",icon:Te(Qu,{size:16}),active:F==="flex-row"}),Te(Z,{mode:"grid",icon:Te(ep,{size:16}),active:F==="grid"})]}),sn("div",{style:{display:"flex",gap:4,marginBottom:8},children:[Te(Bs,{label:"W",property:"width",cssValue:T==="fixed"?C:`${Math.round(e.getBoundingClientRect().width)}px`,mode:T,onValueChange:U=>o("width",U),onModeChange:U=>{if(U==="fixed"){let Me=e.getBoundingClientRect();o("width",`${Math.round(Me.width)}px`)}else o("width",ki(U,C))},modified:r("width"),dimmed:pt&&p!=="width",dropdownOpen:p==="width",onDropdownChange:U=>I(U?"width":null),panelContentRef:u,accentColor:d,onReset:()=>i("width"),minValue:ce!=="none"&&ce!=="0px"&&ce!=="auto"?ce:"",maxValue:We!=="none"&&We!=="auto"?We:"",onMinChange:U=>o("min-width",U||"0"),onMaxChange:U=>o("max-width",U||"none"),onMinReset:()=>i("min-width"),onMaxReset:()=>i("max-width"),minModified:r("min-width"),maxModified:r("max-width")}),Te(Bs,{label:"H",property:"height",cssValue:L==="fixed"?S:`${Math.round(e.getBoundingClientRect().height)}px`,mode:L,onValueChange:U=>o("height",U),onModeChange:U=>{if(U==="fixed"){let Me=e.getBoundingClientRect();o("height",`${Math.round(Me.height)}px`)}else o("height",ki(U,S))},modified:r("height"),dimmed:pt&&p!=="height",dropdownOpen:p==="height",onDropdownChange:U=>I(U?"height":null),panelContentRef:u,minValue:be!=="none"&&be!=="0px"&&be!=="auto"?be:"",maxValue:j!=="none"&&j!=="auto"?j:"",onMinChange:U=>o("min-height",U||"0"),onMaxChange:U=>o("max-height",U||"none"),onMinReset:()=>i("min-height"),onMaxReset:()=>i("max-height"),minModified:r("min-height"),maxModified:r("max-height"),accentColor:d,onReset:()=>i("height")})]}),M&&sn("div",{onMouseEnter:()=>g?.("gap"),onMouseLeave:()=>g?.("element"),style:{display:"flex",gap:8,marginBottom:8},children:[Te("div",{style:{opacity:pt?.3:1,transition:"opacity 150ms ease"},children:qe()}),sn("div",{style:{flex:1,opacity:X,transition:"opacity 150ms ease"},children:[Te("div",{onClick:et?()=>{i(ge),i("gap")}:void 0,title:et?"Click to reset":void 0,style:{fontSize:9,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:et?d:"#999",fontWeight:et?600:400,marginBottom:2,cursor:et?"pointer":"default"},children:"Gap"}),Te("div",{style:{display:"flex",gap:2,marginBottom:4,backgroundColor:zn,borderRadius:2,padding:2},children:["fixed","between","around"].map(U=>{let Me=Nt===U;return Te("button",{type:"button",onClick:()=>xn(U),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:"4px 6px",border:"none",borderRadius:2,backgroundColor:Me?Ko(d,.15):"transparent",color:Me?d:"#64748b",cursor:"pointer",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',fontWeight:Me?600:400,textTransform:"capitalize"},children:U},U)})}),Te(Bn,{dimmed:pt,children:sn("div",{style:{display:"flex",alignItems:"center"},children:[Te(Mr,{value:Pe,onChange:U=>{rt("gap"),Pn(U)},onPreview:ot("gap",At),onScrubEnd:()=>rt("gap"),onReset:()=>{i(ge),i("gap")},isModified:et,accentColor:d,defaultUnit:x,children:P==="column"||P==="column-reverse"?Te(Al,{size:12,strokeWidth:et?2.5:1.5}):Te(Ll,{size:12,strokeWidth:et?2.5:1.5})}),Te(qn,{property:ge,value:ke.gap||(Nt==="fixed"?Pe:`${Math.max(0,Math.round(Re()*1e3)/1e3)}px`),onChange:U=>Pn(U),isModified:et||"gap"in ke,style:{...un,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:x,onUnitCycle:h})]})})]})]}),D&&sn("div",{onMouseEnter:()=>g?.("gap"),onMouseLeave:()=>g?.("element"),style:{display:"flex",gap:8,marginBottom:8,opacity:X,transition:"opacity 150ms ease"},children:[Te(op,{gridCols:de,gridRows:Ee,gridModified:st,accentColor:d,onColsChange:U=>o("grid-template-columns",`repeat(${U}, 1fr)`),onRowsChange:U=>o("grid-template-rows",`repeat(${U}, 1fr)`)}),sn("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[Te(Bn,{dimmed:pt,children:sn("div",{style:{display:"flex",alignItems:"center"},children:[Te(Mr,{value:fe||_,onChange:U=>{rt("column-gap"),o("column-gap",U)},onPreview:ot("column-gap",ne("column-gap")),onScrubEnd:()=>rt("column-gap"),onReset:()=>i("column-gap"),isModified:r("column-gap"),accentColor:d,defaultUnit:x,children:Te(Ll,{size:12,strokeWidth:r("column-gap")?2.5:1.5})}),Te(qn,{property:"column-gap",value:ke["column-gap"]||fe||_,onChange:U=>o("column-gap",U),isModified:r("column-gap")||"column-gap"in ke,placeholder:"col",style:{...un,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:x,onUnitCycle:h})]})}),Te(Bn,{dimmed:pt,children:sn("div",{style:{display:"flex",alignItems:"center"},children:[Te(Mr,{value:he||_,onChange:U=>{rt("row-gap"),o("row-gap",U)},onPreview:ot("row-gap",ne("row-gap")),onScrubEnd:()=>rt("row-gap"),onReset:()=>i("row-gap"),isModified:r("row-gap"),accentColor:d,defaultUnit:x,children:Te(Al,{size:12,strokeWidth:r("row-gap")?2.5:1.5})}),Te(qn,{property:"row-gap",value:ke["row-gap"]||he||_,onChange:U=>o("row-gap",U),isModified:r("row-gap")||"row-gap"in ke,placeholder:"row",style:{...un,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:x,onUnitCycle:h})]})})]})]}),J&&sn("div",{onMouseEnter:()=>g?.("padding"),onMouseLeave:()=>g?.("element"),style:{display:"flex",gap:4,marginBottom:8,opacity:X,transition:"opacity 150ms ease"},children:[Te(Bn,{style:{flex:1},dimmed:pt,children:sn("div",{style:{display:"flex",alignItems:"center"},children:[Te(Mr,{value:se.left,onChange:U=>{rt("padding-h"),Je(U)},onPreview:ot("padding-h",Lt),onScrubEnd:()=>rt("padding-h"),onReset:()=>i("padding"),isModified:r("padding"),accentColor:d,defaultUnit:x,snapSteps:Ps,children:Te(qu,{size:12,strokeWidth:r("padding")?2.5:1.5})}),Te(qn,{property:"padding",value:ke["padding-h"]||se.left,onChange:U=>Je(U),isModified:r("padding")||"padding-h"in ke,placeholder:"H pad",style:{...un,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:x,onUnitCycle:h})]})}),Te(Bn,{style:{flex:1},dimmed:pt,children:sn("div",{style:{display:"flex",alignItems:"center"},children:[Te(Mr,{value:se.top,onChange:U=>{rt("padding-v"),lt(U)},onPreview:ot("padding-v",yt),onScrubEnd:()=>rt("padding-v"),onReset:()=>i("padding"),isModified:r("padding"),accentColor:d,defaultUnit:x,snapSteps:Ps,children:Te(Zu,{size:12,strokeWidth:r("padding")?2.5:1.5})}),Te(qn,{property:"padding",value:ke["padding-v"]||se.top,onChange:U=>lt(U),isModified:r("padding")||"padding-v"in ke,placeholder:"V pad",style:{...un,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:x,onUnitCycle:h})]})})]}),sn("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#64748b",opacity:X,transition:"opacity 150ms ease"},children:[Te("input",{type:"checkbox",checked:ze==="hidden",onChange:U=>o("overflow",U.target.checked?"hidden":"visible"),style:{margin:0,accentColor:d}}),"Clip content"]})]})]})}import{AlignCenter as rp,AlignJustify as ip,AlignLeft as sp,AlignRight as ap,Baseline as lp,ChevronDown as cp,WholeWord as dp}from"lucide-react";import{jsx as Ct,jsxs as wo}from"react/jsx-runtime";var Bl={100:"Thin",200:"Extra Light",300:"Light",400:"Regular",500:"Medium",600:"Semi Bold",700:"Bold",800:"Extra Bold",900:"Black"};function Hl({element:e,getValue:t,handleChange:n,isModified:o,onResetProperty:r,isCollapsed:i,onToggle:s,sectionHeaderStyle:a,accentColor:l,colorVariables:p,activeColorDropdown:c,onColorDropdownChange:u,panelContentRef:d,preferredUnit:g,onUnitCycle:x}){let h=t("font-family"),I=t("font-size"),O=t("font-weight"),P=t("line-height"),F=t("letter-spacing"),M=t("text-align"),D=t("color"),J=String(O),ee=Bl[J]||J,C=Er(e,D),S=D.includes("var(")?null:zr(C,p),A=({align:T,icon:L})=>{let ce=M===T;return Ct("button",{type:"button",onClick:()=>n("text-align",T),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:"6px 8px",border:"none",borderRadius:2,backgroundColor:ce?Ko(l,.15):"transparent",color:ce?l:"#64748b",cursor:"pointer"},children:L})},y=h.split(",")[0]?.trim().replace(/^["']|["']$/g,"")||"System";return wo("div",{style:{borderBottom:"1px solid rgba(0,0,0,0.08)"},children:[Ct("div",{style:a,children:Ct("span",{children:"Typography"})}),wo("div",{style:{padding:"8px 12px",display:"flex",flexDirection:"column",gap:4},children:[Ct(Bn,{children:wo("div",{style:{display:"flex",alignItems:"center",padding:"6px 8px"},children:[Ct("input",{type:"text",value:h,onChange:T=>n("font-family",T.target.value),style:{...un,flex:1,minWidth:0,padding:0,fontWeight:o("font-family")?600:400,color:o("font-family")?l:"inherit"},title:h}),Ct(cp,{size:12,style:{color:"#999",flexShrink:0,marginLeft:4}})]})}),wo("div",{style:{display:"flex",gap:4},children:[Ct(Bn,{style:{flex:1},children:Ct("select",{value:J,onChange:T=>n("font-weight",T.target.value),style:{...un,padding:"6px 8px",paddingLeft:4,paddingRight:20,cursor:"pointer",fontWeight:o("font-weight")?600:400,color:o("font-weight")?l:"inherit"},children:Object.entries(Bl).map(([T,L])=>Ct("option",{value:T,children:L},T))})}),Ct(Bn,{style:{flex:1},children:Ct("div",{style:{display:"flex",alignItems:"center",position:"relative"},children:Ct(qn,{property:"font-size",value:I,onChange:T=>n("font-size",T),isModified:o("font-size"),min:1,max:999,style:{...un,padding:"6px 8px",paddingRight:24,fontWeight:o("font-size")?600:400,color:o("font-size")?l:"inherit"},unitStyle:{position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999"},preferredUnit:g,onUnitCycle:x})})})]}),wo("div",{style:{display:"flex",gap:4},children:[Ct(Bn,{style:{flex:1},children:wo("div",{style:{display:"flex",alignItems:"center",padding:"6px 8px",gap:4},children:[Ct(lp,{size:12,style:{color:o("line-height")?l:"#999",flexShrink:0}}),Ct(qn,{property:"line-height",value:P,onChange:T=>n("line-height",T),isModified:o("line-height"),step:.1,min:0,placeholder:"Auto",style:{...un,flex:1,minWidth:0,padding:0,fontWeight:o("line-height")?600:400,color:o("line-height")?l:"inherit"},showUnit:!1})]})}),Ct(Bn,{style:{flex:1},children:wo("div",{style:{display:"flex",alignItems:"center",padding:"6px 8px",gap:4},children:[Ct(dp,{size:12,style:{color:o("letter-spacing")?l:"#999",flexShrink:0}}),Ct(qn,{property:"letter-spacing",value:F,onChange:T=>n("letter-spacing",T),isModified:o("letter-spacing"),step:.1,placeholder:"\u2014",style:{...un,flex:1,minWidth:0,padding:0,fontWeight:o("letter-spacing")?600:400,color:o("letter-spacing")?l:"inherit"},showUnit:!1})]})})]}),wo("div",{style:{display:"flex",gap:2,backgroundColor:zn,borderRadius:2,padding:2},children:[Ct(A,{align:"left",icon:Ct(sp,{size:14})}),Ct(A,{align:"center",icon:Ct(rp,{size:14})}),Ct(A,{align:"right",icon:Ct(ap,{size:14})}),Ct(A,{align:"justify",icon:Ct(ip,{size:14})})]}),wo("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0"},children:[Ct("span",{onClick:o("color")?()=>r("color"):void 0,title:o("color")?"Click to reset":void 0,style:{fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:o("color")?l:"#64748b",fontWeight:o("color")?600:400,cursor:o("color")?"pointer":"default",width:40,flexShrink:0},children:"Color"}),Ct("div",{style:{flex:1,minWidth:0},children:Ct(Hs,{value:D,resolvedValue:C,colorVariables:p,matchingVariable:S,onChange:T=>n("color",T),accentColor:l,modified:o("color"),panelContentRef:d,isDropdownOpen:c==="color",onDropdownChange:T=>u(T?"color":null)})})]})]})]})}import{Fragment as fp,jsx as ye,jsxs as zt}from"react/jsx-runtime";var Nl=[{name:"Background",properties:[{property:"background-color",label:"Color",type:"color"},{property:"opacity",label:"Opacity",type:"number",step:.1,min:0,max:1}]},{name:"Borders",properties:[{property:"border-width",label:"Width",type:"number",min:0,max:20},{property:"border-color",label:"Color",type:"color"},{property:"border-radius",label:"Radius",type:"number",min:0,max:100},{property:"border-style",label:"Style",type:"select",options:["none","solid","dashed","dotted","double"]}]},{name:"Effects",properties:[{property:"box-shadow",label:"Box Shadow",type:"text"},{property:"backdrop-filter",label:"Backdrop Filter",type:"backdrop-filter"},{property:"transform",label:"Transform",type:"text"}]}];function pp(e,t){let n=t.trim().toLowerCase();switch(e){case"opacity":return n==="1";case"border-width":return n==="0px"||n==="0"||n==="medium";case"border-radius":return n==="0px"||n==="0";case"border-style":return n==="none";case"box-shadow":return n==="none";case"backdrop-filter":return n==="none"||n==="";case"letter-spacing":return n==="normal"||n==="0px"||n==="0";case"background-color":return n==="rgba(0, 0, 0, 0)"||n==="transparent";default:return!1}}function Os(e,t){return!t||e==="auto"||e==="fit-content"||e==="max-content"||e==="min-content"?"hug":e==="100%"||t==="100%"?"fill":"fixed"}function ki(e,t){switch(e){case"hug":return"fit-content";case"fill":return"100%";case"fixed":{let n=Do(t);if(typeof n.num=="number"&&!isNaN(n.num)){let o=n.unit==="%"?"px":n.unit||"px";return`${n.num}${o}`}return"auto"}}}function Ir(e){let t=e.split(/\s+/).filter(Boolean);return t.length===1?{top:t[0],right:t[0],bottom:t[0],left:t[0]}:t.length===2?{top:t[0],right:t[1],bottom:t[0],left:t[1]}:t.length===3?{top:t[0],right:t[1],bottom:t[2],left:t[1]}:t.length>=4?{top:t[0],right:t[1],bottom:t[2],left:t[3]}:{top:"0px",right:"0px",bottom:"0px",left:"0px"}}function Dl(e,t){return e==="grid"?"grid":e==="flex"||e==="inline-flex"?t==="column"||t==="column-reverse"?"flex-col":"flex-row":"block"}function Ol(e,t){switch(e){case"block":t("display","block");break;case"flex-row":t("display","flex"),t("flex-direction","row");break;case"flex-col":t("display","flex"),t("flex-direction","column");break;case"grid":t("display","grid");break}}var zn="rgba(0, 0, 0, 0.04)",un={width:"100%",padding:"4px 8px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',border:"none",borderRadius:2,outline:"none",backgroundColor:"transparent"};function Bs({label:e,property:t,cssValue:n,mode:o,onValueChange:r,onModeChange:i,modified:s,dimmed:a,dropdownOpen:l,onDropdownChange:p,panelContentRef:c,accentColor:u="#3b82f6",onReset:d,minValue:g,maxValue:x,onMinChange:h,onMaxChange:I,onMinReset:O,onMaxReset:P,minModified:F,maxModified:M}){let D=Do(n),J=s?D.unit||Tr(t):Tr(t),ee=!s&&D.unit&&D.unit!==J?Ls(D.num,J):D.num,[C,S]=pn(!1),[A,y]=pn(String(ee)),[T,L]=pn(!1),ce=An(null),We=An(null),be=An(null),j=An(!1);$n(()=>{C||y(String(ee))},[ee,C]),$n(()=>{if(!l)return;let de=Ge=>{We.current&&!Ge.composedPath().includes(We.current)&&be.current&&!Ge.composedPath().includes(be.current)&&p?.(!1)},Ee=Ge=>{Ge.key==="Escape"&&p?.(!1)};return document.addEventListener("mousedown",de),document.addEventListener("keydown",Ee),()=>{document.removeEventListener("mousedown",de),document.removeEventListener("keydown",Ee)}},[l,p]),$n(()=>{C&&ce.current&&(ce.current.focus(),ce.current.select())},[C]);let se=()=>{let de=wi(A,t,n,s);r(de||`${Math.max(0,parseFloat(A)||0)}${J}`),S(!1)},_=()=>{if(j.current){j.current=!1;return}se()},he=de=>{if(de.key==="Enter"){se();return}if(de.key==="Escape"){j.current=!0,y(String(ee)),S(!1);return}if(de.key==="ArrowUp"||de.key==="ArrowDown"){de.preventDefault();let Ee=de.key==="ArrowUp"?1:-1,Ge=de.shiftKey?8:de.altKey?.1:1,Qe=parseFloat(A)||0,pt=Math.round(Math.max(0,Qe+Ee*Ge)*1e3)/1e3;y(String(pt)),r(`${pt}${J}`)}},fe={fixed:"Fixed",hug:"Hug",fill:"Fill"},Ae={fixed:ye(_l,{size:12}),hug:ye(up,{size:12}),fill:ye(_l,{size:12})},De=()=>{p?.(!l)},ze=()=>{if(!be.current||!c?.current)return{position:"absolute",top:"100%",left:-4,right:-4,width:"calc(100% + 8px)",marginTop:4};let de=be.current.getBoundingClientRect(),Ee=c.current.getBoundingClientRect();return{position:"fixed",top:de.bottom+4,left:Ee.left+4,width:Ee.width-8}};return zt("div",{ref:be,onMouseEnter:()=>L(!0),onMouseLeave:()=>L(!1),style:{flex:1,display:"flex",alignItems:"center",position:"relative",borderRadius:2,border:"1px solid",borderColor:C?u:T?"rgba(0,0,0,0.15)":"transparent",backgroundColor:zn,transition:"border-color 100ms ease, opacity 150ms ease",opacity:a?.3:1},children:[ye("span",{onClick:s&&d?d:void 0,title:s?"Click to reset":void 0,style:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:s?u:"#999",fontWeight:s?600:400,padding:"0 8px",flexShrink:0,cursor:s?"pointer":"default"},children:e}),o==="fixed"?C?ye("input",{ref:ce,type:"text",inputMode:"numeric",value:A,onChange:de=>y(de.target.value),onKeyDown:he,onBlur:_,style:{...un,flex:1,minWidth:0,padding:"4px 2px"}}):ye("span",{onClick:()=>S(!0),style:{flex:1,padding:"4px 2px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',cursor:"text"},children:ee}):ye("span",{style:{flex:1}}),zt("button",{type:"button",onClick:De,style:{display:"flex",alignItems:"center",gap:2,padding:"4px 8px",border:"none",outline:"none",backgroundColor:"transparent",color:"#999",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',cursor:"pointer",flexShrink:0},children:[fe[o],ye(_s,{size:12})]}),l&&zt("div",{ref:We,style:{...ze(),backgroundColor:"#eaeaea",border:"1px solid rgba(0,0,0,0.1)",borderRadius:0,zIndex:10001,overflow:"hidden",fontSize:12,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'},children:[zt("button",{type:"button",onClick:()=>{i("fixed"),p?.(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",outline:"none",backgroundColor:o==="fixed"?"#f1f5f9":"transparent",color:"#1e293b",fontWeight:o==="fixed"?600:400,cursor:"pointer",textAlign:"left"},children:[Ae.fixed,zt("span",{children:["Fixed ",t," (",n,")"]}),o==="fixed"&&ye(Ti,{size:14,style:{marginLeft:"auto"}})]}),zt("button",{type:"button",onClick:()=>{i("hug"),p?.(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",outline:"none",backgroundColor:o==="hug"?"#f1f5f9":"transparent",color:"#1e293b",fontWeight:o==="hug"?600:400,cursor:"pointer",textAlign:"left"},children:[Ae.hug,ye("span",{children:"Hug contents"}),o==="hug"&&ye(Ti,{size:14,style:{marginLeft:"auto"}})]}),zt("button",{type:"button",onClick:()=>{i("fill"),p?.(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",outline:"none",backgroundColor:o==="fill"?"#f1f5f9":"transparent",color:"#1e293b",fontWeight:o==="fill"?600:400,cursor:"pointer",textAlign:"left"},children:[Ae.fill,ye("span",{children:"Fill container"}),o==="fill"&&ye(Ti,{size:14,style:{marginLeft:"auto"}})]}),ye("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",margin:"4px 0"}}),zt("div",{style:{padding:"8px 12px",display:"flex",flexDirection:"column",gap:4},children:[zt("div",{style:{display:"flex",alignItems:"center",backgroundColor:zn,borderRadius:2,padding:"4px 8px"},children:[ye("span",{onClick:F?de=>{de.stopPropagation(),O?.()}:void 0,title:F?"Click to reset":void 0,style:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:F?u:"#999",fontWeight:F?600:400,marginRight:8,flexShrink:0,cursor:F?"pointer":"default"},children:"Min"}),ye("input",{type:"text",value:g||"",placeholder:"\u2014",onChange:de=>h?.(de.target.value),onClick:de=>de.stopPropagation(),style:{...un,flex:1,minWidth:0,padding:0,textAlign:"right",color:F?u:"inherit",fontWeight:F?600:400}})]}),zt("div",{style:{display:"flex",alignItems:"center",backgroundColor:zn,borderRadius:2,padding:"4px 8px"},children:[ye("span",{onClick:M?de=>{de.stopPropagation(),P?.()}:void 0,title:M?"Click to reset":void 0,style:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:M?u:"#999",fontWeight:M?600:400,marginRight:8,flexShrink:0,cursor:M?"pointer":"default"},children:"Max"}),ye("input",{type:"text",value:x||"",placeholder:"\u2014",onChange:de=>I?.(de.target.value),onClick:de=>de.stopPropagation(),style:{...un,flex:1,minWidth:0,padding:0,textAlign:"right",color:M?u:"inherit",fontWeight:M?600:400}})]})]})]})]})}function Bn({children:e,style:t,dimmed:n}){let[o,r]=pn(!1);return ye("div",{onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{position:"relative",borderRadius:2,border:"1px solid",borderColor:o?"rgba(0,0,0,0.15)":"transparent",backgroundColor:zn,transition:"border-color 100ms ease, opacity 150ms ease",opacity:n?.3:1,...t},children:e})}function So({children:e}){let[t,n]=pn(!1);return ye("div",{onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),style:{position:"relative",borderRadius:2,border:"1px solid",borderColor:t?"rgba(0,0,0,0.15)":"transparent",backgroundColor:zn,transition:"border-color 100ms ease"},children:e})}function qn({property:e,value:t,onChange:n,isModified:o=!1,step:r=1,min:i,max:s,style:a,placeholder:l,showUnit:p=!0,unitStyle:c,preferredUnit:u,onUnitCycle:d}){let g=Do(t),x=Tr(e),h=Si[e],O=u&&h&&h.includes(u)?u:x,P=o&&g.unit||O,F=!o&&g.unit&&g.unit!==P?Ls(g.num,P):g.num,[M,D]=pn(!1),[J,ee]=pn(""),C=_=>{D(!0),ee(String(F||"")),requestAnimationFrame(()=>_.target.select())},S=()=>{if(D(!1),J.trim()){let _=wi(J,e,t,o);_&&n(_)}},A=_=>{let he=_.target.value;ee(he);let fe=he.trim(),Ae=fe.match(/^(-?[\d.]+)\s*(rem|em|px|%)$/i),De=fe.match(/^(-?[\d.]+)$/);if(Ae){let ze=parseFloat(Ae[1]);isNaN(ze)||n(`${ze}${Ae[2].toLowerCase()}`)}else if(De){let ze=parseFloat(De[1]);isNaN(ze)||n(`${ze}${P}`)}},y=_=>{if(_.key==="Enter"){if(J.trim()){let he=wi(J,e,t,o);he&&n(he)}_.target.blur();return}if(_.key==="ArrowUp"||_.key==="ArrowDown"){_.preventDefault();let he=_.shiftKey?10:_.altKey?.1:1,fe=(_.key==="ArrowUp"?1:-1)*r*he,Ae=parseFloat(J)||F||0,De=Math.round((Ae+fe)*1e3)/1e3;i!==void 0&&(De=Math.max(i,De)),s!==void 0&&(De=Math.min(s,De)),ee(String(De)),n(`${De}${P}`)}},T=/^-?[\d.]/.test(t.trim()),L=M?J:T?String(F):"",We=M&&/\s*(rem|em|px|%)\s*$/i.test(J)?"":P,be=d&&(We==="rem"||We==="px"),j={fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",pointerEvents:"none"},se={...c??j,pointerEvents:"auto",cursor:"pointer"};return zt(fp,{children:[ye("input",{type:"text",inputMode:"decimal",value:L,onFocus:C,onBlur:S,onChange:A,onKeyDown:y,placeholder:l,style:a}),p&&We&&ye("span",{style:be?se:c??j,onClick:be?d:void 0,title:be?"Click to switch units":void 0,children:We})]})}function Hs({value:e,resolvedValue:t,colorVariables:n,matchingVariable:o,onChange:r,accentColor:i="#3b82f6",modified:s,panelContentRef:a,isDropdownOpen:l,onDropdownChange:p}){let[c,u]=pn(!1),d=e,[g,x]=pn(d),[h,I]=pn(!1),[O,P]=pn(!1),[F,M]=pn(!1),D=An(null),J=An(null),ee=An(null),C=l!==void 0?l:h,S=p||I,A=ao(()=>{if(!ee.current)return{position:"fixed",top:0,left:0,width:200};let _=ee.current.getBoundingClientRect();if(a?.current){let he=a.current.getBoundingClientRect();return{position:"fixed",top:_.bottom+4,left:he.left+4,width:he.width-8}}return{position:"fixed",top:_.bottom+4,left:_.left,width:_.width}},[a]);$n(()=>{c||x(e)},[e,c]),$n(()=>{if(!C&&!O)return;let _=fe=>{ee.current&&!fe.composedPath().includes(ee.current)&&(S(!1),P(!1))},he=fe=>{fe.key==="Escape"&&(S(!1),P(!1))};return document.addEventListener("mousedown",_),document.addEventListener("keydown",he),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",he)}},[C,O]),$n(()=>{c&&D.current&&(D.current.focus(),D.current.select())},[c]);let y=Mi(()=>{if(!g||g.startsWith("#")||g.startsWith("rgb")||g.startsWith("hsl")||g.startsWith("oklch"))return[];let _=g.toLowerCase();return n.filter(he=>he.name.toLowerCase().includes(_)||he.usage.toLowerCase().includes(_)).slice(0,8)},[g,n]),T=()=>{r(g),u(!1),P(!1)},L=_=>{x(_),_.includes("var")||_.includes("--")||_.length>0&&!_.startsWith("#")?P(!0):P(!1)},ce=_=>{x(_.value),r(_.value),S(!1),P(!1),u(!1)},We=()=>{setTimeout(()=>{!C&&!O&&T()},150)},be=_=>{_.key==="Enter"?T():_.key==="Escape"&&(x(e),u(!1),P(!1))},j=Mi(()=>{let _=t.trim().toLowerCase();if(_.startsWith("#"))return _.length===4?`#${_[1]}${_[1]}${_[2]}${_[2]}${_[3]}${_[3]}`:_.slice(0,7);let he=_.match(/rgba?\((\d+),?\s*(\d+),?\s*(\d+)/);if(he){let Ae=parseInt(he[1],10).toString(16).padStart(2,"0"),De=parseInt(he[2],10).toString(16).padStart(2,"0"),ze=parseInt(he[3],10).toString(16).padStart(2,"0");return`#${Ae}${De}${ze}`}let fe=_.match(/oklch\(\s*([\d.]+)/);if(fe){let Ae=Math.max(0,Math.min(1,parseFloat(fe[1]))),De=Math.round(Ae*255).toString(16).padStart(2,"0");return`#${De}${De}${De}`}return"#000000"},[t]);return zt("div",{ref:ee,onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{position:"relative",borderRadius:2,border:"1px solid",borderColor:c?i:F?"rgba(0,0,0,0.15)":"transparent",backgroundColor:zn,transition:"border-color 100ms ease",overflow:"hidden"},children:[zt("div",{style:{display:"flex",alignItems:"center",minWidth:0},children:[zt("div",{style:{position:"relative",marginLeft:8,flexShrink:0},children:[ye("input",{type:"color",value:j,onChange:_=>{let he=_.target.value;x(he),r(he)},style:{width:12,height:12,padding:0,border:"none",cursor:"pointer",opacity:0,position:"absolute",top:0,left:0}}),ye("div",{style:{width:12,height:12,borderRadius:2,backgroundColor:t,border:"1px solid rgba(0,0,0,0.1)",pointerEvents:"none"}})]}),c?ye("input",{ref:D,type:"text",value:g,onChange:_=>L(_.target.value),onKeyDown:be,onBlur:We,style:{...un,flex:1,minWidth:0}}):ye("span",{onClick:()=>u(!0),style:{flex:1,minWidth:0,padding:"4px 8px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',cursor:"text",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:s?i:"inherit"},title:d,children:d}),n.length>0&&ye("button",{type:"button",onClick:()=>S(!C),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:24,border:"none",background:"none",cursor:"pointer",color:"#999",flexShrink:0},children:ye(_s,{size:12})})]}),O&&y.length>0&&ye("div",{style:{...A(),backgroundColor:"#eaeaea",border:"1px solid rgba(0,0,0,0.1)",borderRadius:0,zIndex:10001,maxHeight:200,overflowY:"auto",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'},children:y.map(_=>zt("button",{type:"button",onClick:()=>ce(_),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",backgroundColor:"transparent",color:"#1e293b",cursor:"pointer",textAlign:"left",fontSize:12},children:[ye("div",{style:{width:14,height:14,borderRadius:2,backgroundColor:_.value,border:"1px solid rgba(0,0,0,0.1)",flexShrink:0}}),ye("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:_.name})]},_.name))}),C&&ye("div",{ref:J,style:{...A(),backgroundColor:"#eaeaea",border:"1px solid rgba(0,0,0,0.1)",borderRadius:0,zIndex:10001,maxHeight:280,overflowY:"auto",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'},children:n.map(_=>zt("button",{type:"button",onClick:()=>ce(_),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",backgroundColor:o?.usage===_.usage||e===_.value?"#f1f5f9":"transparent",color:"#1e293b",fontWeight:o?.usage===_.usage||e===_.value?600:400,cursor:"pointer",textAlign:"left",fontSize:12},children:[ye("div",{style:{width:14,height:14,borderRadius:2,backgroundColor:_.value,border:"1px solid rgba(0,0,0,0.1)",flexShrink:0}}),ye("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:_.name}),(o?.usage===_.usage||e===_.value)&&ye(Ti,{size:14,style:{marginLeft:"auto",flexShrink:0}})]},_.name))})]})}function Fl({element:e,elementInfo:t,selector:n,styleModifications:o,dispatch:r,onClose:i,onHover:s,accentColor:a="#3b82f6",toolbarRef:l}){let p=An(null),c=An(null),[u,d]=pn(()=>{try{return!!localStorage.getItem("devtools-panel-position")}catch{return!1}});$n(()=>{if(u)return;let X=setTimeout(()=>d(!0),50);return()=>clearTimeout(X)},[u]);let[g,x]=pn(null),[h,I]=pn(null),O=g!==null||h!==null,[P,F]=pn("rem"),M=ao(()=>{F(X=>X==="rem"?"px":"rem")},[]),D=An(new Map),[J,ee]=pn(""),C=Mi(()=>hs(),[]);$n(()=>{let X=Z=>{if(Z.key!=="Escape")return;let Se=document.activeElement;Se&&p.current?.contains(Se)||i()};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[i]);let S=An({top:0,left:0,maxHeight:400}),[,A]=pn(0),y="devtools-panel-position",T=An({x:0,y:0}),L=An(null),ce=An(!1);$n(()=>{try{let X=localStorage.getItem(y);if(X){let Z=JSON.parse(X);typeof Z.top=="number"&&typeof Z.left=="number"&&(ce.current=!0,S.current={...S.current,top:Z.top,left:Z.left})}}catch{}},[]),$n(()=>{let X=Se=>{let Je=L.current;if(!Je)return;let lt=Je.startOffsetX+(Se.clientX-Je.startX),ke=Je.startOffsetY+(Se.clientY-Je.startY),nt=280,ot=16,rt=Math.max(ot,Math.min(window.innerWidth-nt-ot,S.current.left+lt)),Lt=Math.max(ot,S.current.top+ke);T.current={x:rt-S.current.left,y:Lt-S.current.top};let yt=p.current,ne=yt?.parentElement;if(!ne)return;ne.style.top=`${Lt}px`,ne.style.left=`${rt}px`;let te=l?.current?.getBoundingClientRect(),ge=window.innerHeight-16;te&&rt+nt>te.left&&(ge=te.top-8);let Pe=Math.max(0,Lt),et=Math.max(200,ge-Pe);yt&&(yt.style.maxHeight=`${et}px`)},Z=()=>{if(!L.current)return;let Se=S.current.top+T.current.y,Je=S.current.left+T.current.x;S.current={...S.current,top:Se,left:Je},T.current={x:0,y:0},ce.current=!0;try{localStorage.setItem(y,JSON.stringify({top:Se,left:Je}))}catch{}L.current=null};return window.addEventListener("mousemove",X),window.addEventListener("mouseup",Z),()=>{window.removeEventListener("mousemove",X),window.removeEventListener("mouseup",Z)}},[]);let We=ao(X=>{X.button!==0||X.target.closest("button")||(X.preventDefault(),L.current={startX:X.clientX,startY:X.clientY,startOffsetX:T.current.x,startOffsetY:T.current.y})},[]);$n(()=>{T.current={x:0,y:0};let X=(Je=!1)=>{let lt=p.current,ke=280,nt=8,ot,rt;if(ce.current)ot=S.current.top,rt=S.current.left;else{let ge=e.getBoundingClientRect();rt=ge.right+nt,ot=ge.top,rt+ke>window.innerWidth-nt&&(rt=ge.left-ke-nt),rt<nt&&(rt=Math.max(nt,(window.innerWidth-ke)/2))}let Lt=l?.current?.getBoundingClientRect(),yt=window.innerHeight-16;Lt&&rt+ke>Lt.left&&(yt=Lt.top-nt);let ne=Math.max(0,ot),te=Math.max(200,yt-ne);if(S.current={top:ot,left:rt,maxHeight:te},Je&&lt){let ge=lt.parentElement;ge&&!ce.current&&(ge.style.top=`${ot+T.current.y}px`,ge.style.left=`${rt+T.current.x}px`),lt.style.maxHeight=`${te}px`}else A(ge=>ge+1)};X(!1);let Z=()=>X(!0),Se=()=>X(!1);return window.addEventListener("scroll",Z,{passive:!0}),window.addEventListener("resize",Se,{passive:!0}),()=>{window.removeEventListener("scroll",Z),window.removeEventListener("resize",Se)}},[e]),$n(()=>{let X=p.current;if(!X)return;let Z=Se=>{let Je=c.current;if(!Je){Se.preventDefault();return}let{scrollTop:lt,scrollHeight:ke,clientHeight:nt}=Je,ot=lt<=0&&Se.deltaY<0,rt=lt+nt>=ke&&Se.deltaY>0;(ot||rt)&&Se.preventDefault()};return X.addEventListener("wheel",Z,{passive:!1}),()=>X.removeEventListener("wheel",Z)},[]);let be=Mi(()=>o.find(X=>X.selector===n),[o,n]),j=ao(X=>{let Z=be?.changes.find(Se=>Se.property===X);return Z?Z.modified:ui(e,X)},[e,be]),se=ao((X,Z)=>{if(!X.includes("color"))return Z;let Se=Z.trim(),lt=C.find(ke=>ke.usage===Se||ke.name===Se)?.value||Se;return Er(e,lt)},[C,e]),_=ao(X=>{if(D.current.has(X))return D.current.get(X);let Z=be?.changes.find(Je=>Je.property===X);if(Z)return Z.original;let Se=ui(e,X);return D.current.set(X,Se),Se},[e,be]),he=ao((X,Z)=>{let Se=_(X),Je=se(X,Z);Ve(e,X,Je),X==="backdrop-filter"&&Ve(e,"-webkit-backdrop-filter",Je),r({type:"MODIFY_STYLE",payload:{selector:n,element:t,property:X,original:Se,modified:Je}})},[e,n,t,r,se,_]),fe=ao(X=>{o.find(Je=>Je.selector===n)?.changes.find(Je=>Je.property===X)&&e instanceof HTMLElement&&(e.style.removeProperty(X),r({type:"CLEAR_STYLE",payload:{selector:n,property:X}}),D.current.delete(X))},[e,n,o,r]),Ae=ao(()=>{let X=J.split(";").map(Z=>Z.trim()).filter(Z=>Z);for(let Z of X){let Se=Z.indexOf(":");if(Se>0){let Je=Z.slice(0,Se).trim(),lt=Z.slice(Se+1).trim();Je&&lt&&he(Je,lt)}}ee("")},[J,he]),De=ao(X=>be?.changes.some(Z=>Z.property===X)??!1,[be]),ze=X=>{let Z=j(X.property),Se=De(X.property),Je=!Se&&pp(X.property,Z),lt={width:"100%",padding:"4px 8px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',border:"none",borderRadius:2,outline:"none",backgroundColor:"transparent"};if(Je&&X.type!=="backdrop-filter")return ye(So,{modified:!1,children:ye("input",{type:"text",value:"",placeholder:"\u2014",onFocus:()=>{},onChange:ke=>he(X.property,ke.target.value),style:{...lt,color:"#999"}})});switch(X.type){case"color":{let ke=Er(e,Z),nt=Z.includes("var(")?null:zr(ke,C);return ye(Hs,{value:Z,resolvedValue:ke,colorVariables:C,matchingVariable:nt,onChange:ot=>he(X.property,ot),accentColor:a,modified:Se,panelContentRef:c,isDropdownOpen:h===X.property,onDropdownChange:ot=>I(ot?X.property:null)})}case"number":{if(!!Si[X.property])return ye(So,{modified:Se,children:ye(qn,{property:X.property,value:Z,onChange:ot=>he(X.property,ot),isModified:Se,min:X.min,max:X.max,step:X.step||1,style:{...lt,paddingRight:32},unitStyle:{position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999"},preferredUnit:P,onUnitCycle:M})});let{num:nt}=Do(Z);return ye(So,{modified:Se,children:ye("input",{type:"number",value:nt,min:X.min,max:X.max,step:X.step||1,onChange:ot=>he(X.property,ot.target.value),style:lt})})}case"select":return ye(So,{modified:Se,children:zt("div",{style:{position:"relative",display:"flex",alignItems:"center"},children:[ye("select",{value:Z,onChange:ke=>he(X.property,ke.target.value),style:{...lt,cursor:"pointer",paddingLeft:4,paddingRight:24,appearance:"none",WebkitAppearance:"none"},children:X.options?.map(ke=>ye("option",{value:ke,children:ke},ke))}),ye("div",{style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",pointerEvents:"none",color:"#999",display:"flex",alignItems:"center"},children:ye(_s,{size:12})})]})});case"spacing":return ye(So,{modified:Se,children:ye("input",{type:"text",value:Z,onChange:ke=>he(X.property,ke.target.value),placeholder:"e.g., 10px or 10px 20px",style:lt})});case"backdrop-filter":return ye(Il,{value:Z,onChange:ke=>he(X.property,ke),accentColor:a,modified:Se,panelContentRef:c});default:return ye(So,{modified:Se,children:ye("input",{type:"text",value:Z,onChange:ke=>he(X.property,ke.target.value),style:lt})})}},de=t.reactComponent||t.tagName,Ee={position:"fixed",top:S.current.top,left:S.current.left,width:280,maxHeight:S.current.maxHeight,backgroundColor:"#eaeaea",borderWidth:3,borderStyle:"solid",borderColor:"transparent",boxSizing:"content-box",zIndex:10002,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',fontSize:12,overflow:"visible",display:"flex",flexDirection:"column",opacity:u?1:0,transition:"opacity 150ms ease"},Ge={display:"flex",alignItems:"center",justifyContent:"space-between",margin:4,padding:"4px 5px 4px 10px",backgroundColor:a,color:"#ffffff",cursor:L.current?"grabbing":"grab",userSelect:"none",WebkitUserSelect:"none"},Qe={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 12px 6px",userSelect:"none",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',fontWeight:600,color:"#475569"},pt={display:"flex",alignItems:"center",padding:"4px 12px",gap:8},je={width:80,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#64748b",flexShrink:0};return ye("div",{"data-devtools":"panel-wrapper",style:{position:"fixed",top:S.current.top+T.current.y,left:S.current.left+T.current.x,zIndex:10002,pointerEvents:"none"},children:zt("div",{ref:p,"data-devtools":"panel",style:{...Ee,position:"relative",top:0,left:0,zIndex:0,pointerEvents:"auto"},onMouseEnter:()=>s?.("element"),onMouseLeave:()=>s?.(null),children:[ye("div",{"aria-hidden":"true",style:xi()}),zt("div",{style:Ge,onMouseDown:We,children:[ye("div",{style:{display:"flex",alignItems:"center",gap:3,overflow:"hidden",minWidth:0},children:ye("span",{style:{fontWeight:600,fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:de})}),ye("button",{type:"button",onClick:i,title:"Close",style:{background:"none",border:"none",cursor:"pointer",fontSize:16,color:"#ffffff",padding:"0 4px",lineHeight:1,flexShrink:0},children:"\xD7"})]}),zt("div",{ref:c,style:{flex:1,overflowY:"auto",margin:"0 3px 3px"},children:[ye("div",{style:{opacity:h?.3:1,transition:"opacity 150ms ease"},children:ye(Pl,{element:e,getValue:j,getOriginalValue:_,handleChange:he,isModified:De,onResetProperty:fe,isCollapsed:!1,onToggle:()=>{},sectionHeaderStyle:Qe,activeDropdown:g,onDropdownChange:x,panelContentRef:c,accentColor:a,onFieldHover:s,preferredUnit:P,onUnitCycle:M})}),ye("div",{style:{opacity:g?.3:1,transition:"opacity 150ms ease"},children:ye(Hl,{element:e,getValue:j,handleChange:he,isModified:De,onResetProperty:fe,isCollapsed:!1,onToggle:()=>{},sectionHeaderStyle:Qe,accentColor:a,colorVariables:C,activeColorDropdown:h,onColorDropdownChange:I,panelContentRef:c,preferredUnit:P,onUnitCycle:M})}),Nl.map((X,Z)=>{let Se=Z===Nl.length-1,Je=h&&X.properties.some(ke=>ke.property===h);return zt("div",{style:{borderBottom:Se?"none":"1px solid rgba(0,0,0,0.08)",opacity:O&&!Je?.3:1,transition:"opacity 150ms ease"},children:[ye("div",{style:Qe,children:ye("span",{children:X.name})}),ye("div",{style:{padding:"4px 0"},children:X.properties.map(ke=>{let nt=De(ke.property),ot=Je&&ke.property!==h;return zt("div",{style:{...pt,opacity:ot?.3:1,transition:"opacity 150ms ease"},children:[ye("span",{onClick:nt?()=>fe(ke.property):void 0,title:nt?"Click to reset":void 0,style:{...je,color:nt?a:"#64748b",fontWeight:nt?600:400,cursor:nt?"pointer":"default"},children:ke.label}),ye("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:ze(ke)})]},ke.property)})})]},X.name)}),zt("div",{style:{opacity:O?.3:1,transition:"opacity 150ms ease"},children:[ye("div",{style:Qe,children:ye("span",{children:"Raw CSS"})}),zt("div",{style:{padding:"8px 12px"},children:[ye("textarea",{value:J,onChange:X=>ee(X.target.value),placeholder:"property: value; ...",style:{width:"100%",height:60,padding:8,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',border:"1px solid rgba(0,0,0,0.1)",borderRadius:2,resize:"vertical",outline:"none"}}),J.trim()&&ye("button",{type:"button",onClick:Ae,style:{marginTop:4,padding:"4px 8px",width:"100%",fontSize:11,border:"none",borderRadius:2,backgroundColor:a,color:"#fff",cursor:"pointer",opacity:J.trim()?1:.5},children:"Apply"})]})]})]})]})})}import{useEffect as gp,useLayoutEffect as mp,useState as hp}from"react";import{Fragment as xp,jsx as qo,jsxs as vp}from"react/jsx-runtime";var Ns=["flex-start","center","flex-end"],Fs=["flex-start","center","flex-end"];function yp(e){return e==="normal"||e==="flex-start"||e==="start"?"flex-start":e==="flex-end"||e==="end"?"flex-end":e==="center"?"center":null}function bp(e){return e==="normal"||e==="stretch"||e==="flex-start"||e==="start"?"flex-start":e==="flex-end"||e==="end"?"flex-end":e==="center"?"center":null}function zl(e){let t=Array.from(e.children);if(t.length===0)return null;let n=1/0,o=1/0,r=-1/0,i=-1/0;for(let s of t){let a=s.getBoundingClientRect();a.width===0&&a.height===0||(a.top<n&&(n=a.top),a.left<o&&(o=a.left),a.bottom>r&&(r=a.bottom),a.right>i&&(i=a.right))}return n===1/0?null:new DOMRect(o,n,i-o,r-n)}function $l({element:e,modifier:t,accentColor:n,refreshKey:o=0}){let[r,i]=hp(null);if(gp(()=>{if(!e){i(null);return}let h=()=>i(zl(e));return h(),window.addEventListener("scroll",h,{passive:!0}),window.addEventListener("resize",h,{passive:!0}),()=>{window.removeEventListener("scroll",h),window.removeEventListener("resize",h)}},[e]),mp(()=>{e&&i(zl(e))},[e,o]),!r)return null;let s=r,a=window.getComputedStyle(e),l=a.display;if(l!=="flex"&&l!=="inline-flex")return null;let p=a.flexDirection,c=p==="column"||p==="column-reverse"?"vertical":"horizontal",u=c==="horizontal"?"vertical":"horizontal",d=[];if(t==="shift"){let h=yp(a.justifyContent);if(h){let I=Ns.indexOf(h);c==="horizontal"?(I>0&&d.push("left"),I<Ns.length-1&&d.push("right")):(I>0&&d.push("up"),I<Ns.length-1&&d.push("down"))}}else{let h=bp(a.alignItems);if(h){let I=Fs.indexOf(h);u==="horizontal"?(I>0&&d.push("left"),I<Fs.length-1&&d.push("right")):(I>0&&d.push("up"),I<Fs.length-1&&d.push("down"))}}if(d.length===0)return null;let g=14,x=7;return qo(xp,{children:d.map(h=>{let I,O;switch(h){case"right":I=s.right+g,O=s.top+s.height/2;break;case"left":I=s.left-g,O=s.top+s.height/2;break;case"down":I=s.left+s.width/2,O=s.bottom+g;break;case"up":I=s.left+s.width/2,O=s.top-g;break}let P=h==="right"?0:h==="left"?180:h==="down"?90:-90,F={position:"fixed",left:I-x,top:O-x,width:x*2,height:x*2,pointerEvents:"none",zIndex:9997};return qo("div",{"data-devtools":"swipe-hint",style:F,children:qo("svg",{width:x*2,height:x*2,viewBox:"-7 -7 14 14",style:{overflow:"visible"},children:vp("g",{transform:`rotate(${P})`,children:[qo("line",{x1:"-5",y1:"0",x2:"3",y2:"0",stroke:"#fff",strokeWidth:"4",strokeLinecap:"round"}),qo("polyline",{points:"0,-4 5,0 0,4",fill:"none",stroke:"#fff",strokeWidth:"4",strokeLinecap:"round",strokeLinejoin:"round"}),qo("line",{x1:"-5",y1:"0",x2:"3",y2:"0",stroke:n,strokeWidth:"1.5",strokeLinecap:"round"}),qo("polyline",{points:"0,-4 5,0 0,4",fill:"none",stroke:n,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})},h)})})}import{useEffect as Sp,useLayoutEffect as wp,useState as Cp}from"react";import{jsx as zs,jsxs as $s}from"react/jsx-runtime";function Ep(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}function Wl({element:e,fontSize:t,lineHeight:n,accentColor:o,hoveredProperty:r,draggingProperty:i,cursorViewport:s}){let[a,l]=Cp(null);if(Sp(()=>{if(!e){l(null);return}let O=()=>{l(Cr(e))};return O(),window.addEventListener("scroll",O,{passive:!0}),window.addEventListener("resize",O,{passive:!0}),()=>{window.removeEventListener("scroll",O),window.removeEventListener("resize",O)}},[e]),wp(()=>{e&&l(Cr(e))},[e,t,n]),!a)return null;let p=a.width,c=a.height,u=Ep(o,.2),d=i??r,g=8,x=2,h={position:"fixed",top:a.top,left:a.left,width:p,height:c,pointerEvents:"none",zIndex:9996,overflow:"visible"},I=O=>O==="font-size"?`${Math.round(t)}`:(t>0?n/t:1.2).toFixed(2).replace(/\.?0+$/,"");return $s("div",{"data-devtools":"text-handles",style:h,children:[$s("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:`0 0 ${p} ${c}`,children:[zs("rect",{x:"0.5",y:"0.5",width:Math.max(0,p-1),height:Math.max(0,c-1),fill:"none",stroke:u,strokeWidth:"1"}),(d==="font-size"||!d)&&zs("rect",{x:p-x/2,y:c/2-g/2,width:x,height:g,fill:o,stroke:"#ffffff",strokeWidth:d==="font-size"?4:2,paintOrder:"stroke"}),(d==="line-height"||!d)&&zs("rect",{x:p/2-g/2,y:c-x/2,width:g,height:x,fill:o,stroke:"#ffffff",strokeWidth:d==="line-height"?4:2,paintOrder:"stroke"})]}),s&&d&&(()=>{let O=d==="font-size"?"Aa":"Lh",P=I(d);return $s("div",{style:{position:"fixed",left:s.x+8,top:s.y-28,background:o,color:"#fff",fontSize:11,fontWeight:600,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1,padding:"4px 4px",borderRadius:0,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9997},children:[O," ",P]})})()]})}import{Fragment as Lr,jsx as it,jsxs as Rr}from"react/jsx-runtime";var jl=8,Ws=[0,1,2,4,8,12,16,20,24,28,32],js="devtools-active-text";function Gl(e,t,n=0,o,r){let i=e.left+window.scrollX+4,s=t==="top-left"?e.top+window.scrollY-Fn-n*Fn+4:e.bottom+window.scrollY+4-1+n*Fn,a=window.scrollY+4,l=window.scrollY+window.innerHeight-Fn-4,p=90,c=!1;if(o&&r!==void 0){let u=o.getBoundingClientRect();if(e.left+4+r+4+p>u.left){let g=window.scrollY+u.top-Fn-4;g<l&&(l=g,c=!0)}}return s<a?s=e.top+window.scrollY+4:s>l&&(s=c?l:Math.max(e.top+window.scrollY+4,l)),{x:i,y:s}}function Jl({state:e,dispatch:t,onScreenshot:n,inFlightAnnotationIds:o,activeAnnotationIds:r,queuePositionMap:i,inFlightStyleSelectors:s,inFlightSelectorColors:a,onAttachImages:l,onReply:p,onViewThread:c,onCloseThread:u,onModelComponentsAdd:d,onModelComponentFocus:g,onModelComponentHover:x,modelComponentNames:h,modelPanelHoveredComponent:I,modelSpacingTokenHover:O,highlightedAnnotationIds:P,focusedThreadAnnotationId:F,externalCanvasRef:M,toolbarRef:D}){let{canvasRef:J,redrawAll:ee,resizeCanvas:C}=Ja(),S=nn(f=>{J.current=f,M&&(M.current=f)},[M,J]),A=Ut(!1);hn(()=>{let f=J.current;if(!f)return;let b=()=>{A.current&&(A.current=!1,f.style.pointerEvents="")},R=m=>{m.button===0&&A.current&&b()};return window.addEventListener("mousedown",R),()=>window.removeEventListener("mousedown",R)},[J]);let[y,T]=ut(!1),[L,ce]=ut(()=>{if(typeof window>"u")return null;try{let f=localStorage.getItem(js);return f?JSON.parse(f):null}catch{return null}}),[We,be]=ut(null),[j,se]=ut(null),[_,he]=ut(null),fe=Ut(null),Ae=Ut(null),De=Ut({x:0,y:0}),ze=Ut([]),de=Ut(0),[Ee,Ge]=ut(null),[Qe,pt]=ut(new Map),je=Ut(0),X=Ut(null),[Z,Se]=ut(null),[Je,lt]=ut(null),[ke,nt]=ut(null),[ot,rt]=ut(null),Lt=Ut({isDragging:!1,side:null,startX:0,startY:0,original:{top:0,right:0,bottom:0,left:0},element:null,elementInfo:null,selector:null,durableSelector:null}),[yt,ne]=ut(null),[te,ge]=ut(null),[Pe,et]=ut(null),[Re,_t]=ut(null),Nt=Ut({x:0,y:0}),[xn,Pn]=ut({x:0,y:0}),At=Ut({isDragging:!1,hasMoved:!1,axis:null,startX:0,startY:0,originalRow:0,originalColumn:0,element:null,elementInfo:null,selector:null,durableSelector:null,isAuto:!1,originalJustifyContent:"",visualGap:0}),[xt,Kt]=ut(null),[ft,Jt]=ut(null),[tt,Gn]=ut(null),[on,Mn]=ut(!1),[no,oo]=ut(0),[qe,st]=ut(null),fn=Ut({isDragging:!1,corner:null,startY:0,original:{"top-left":0,"top-right":0,"bottom-right":0,"bottom-left":0},maxRadius:0,element:null,elementInfo:null,selector:null,durableSelector:null}),[U,Me]=ut(null),[He,Pt]=ut(null),[Xe,Oe]=ut(null),St=Ut({isDragging:!1,property:null,startX:0,startY:0,originalFontSize:0,originalLineHeight:0,originalRatio:1.2,element:null,elementInfo:null,selector:null,durableSelector:null}),[$t,gn]=ut(null),[rn,po]=ut(null),[Wt,ko]=ut(null),fo=Ya(),ir=Ut(a);ir.current=a;let Jn=nn(f=>{let b=ir.current;if(!b||b.size===0)return!1;for(let R of b.keys())try{if(f.matches(R))return!0}catch{}return!1},[]),Sn=Ut(e);Sn.current=e;let ro=Ut(L);ro.current=L;let Yn=Ut([]),Ft=Ut(n);Ft.current=n;let[wt,jt]=ut(null),Gt=e.selectedAnnotationIds;Yn.current=Gt;let wn=nn((f,b=!1)=>{t({type:"SELECT_ANNOTATION",payload:{id:f,addToSelection:b}})},[t]),io=nn(()=>{t({type:"SELECT_ANNOTATION",payload:{id:null}})},[t]),[In,To]=ut(null),[Zt,sr]=ut({x:window.scrollX,y:window.scrollY});hn(()=>(C(),window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)),[C]),hn(()=>{let f=()=>{sr({x:window.scrollX,y:window.scrollY})};return window.addEventListener("scroll",f,{passive:!0}),()=>window.removeEventListener("scroll",f)},[]),hn(()=>{L?localStorage.setItem(js,JSON.stringify(L)):localStorage.removeItem(js)},[L]),Va(L,ce,We,e.annotations,t);let Vn=Ut(Ee);Vn.current=Ee,hn(()=>{if(e.activeTool!=="model"||!e.isAnnotating)return;let f=b=>{if(!b.altKey||!Vn.current)return;b.preventDefault();let R=b.deltaY>0?-1:1;je.current=Math.max(0,je.current+R);let m=X.current;if(m){let k=ci(m,je.current);Ge(k)}};return window.addEventListener("wheel",f,{passive:!1}),()=>window.removeEventListener("wheel",f)},[e.activeTool,e.isAnnotating]),hn(()=>{e.activeTool!=="model"&&(Ge(null),pt(new Map),je.current=0,X.current=null)},[e.activeTool]),hn(()=>{let f=Ee?.name??null,b=f&&h?.has(f)?f:null;x?.(b)},[Ee,h,x]);let[Nn,ar]=ut(null);hn(()=>{if(!I){ar(null);return}let f=xr(I.name),b=I.instanceIndex;ar(f[b%f.length]??null)},[I]);let[Mo,Ho]=ut([]);hn(()=>{if(!O){Ho([]);return}O.token?.bindings?.length?Ho(ps(O.token)):Ho(ds(O.px))},[O]);let lr=Ut(null),cr=Ut(null);lr.current=xt,cr.current=ft,hn(()=>{let f=["flex-start","center","flex-end"],b=["flex-start","center","flex-end"],m=null,k=!1,E=null,$=null,B=(le,Ye)=>{let Ne=Jo(le,Ye);for(;Ne&&Ne!==document.documentElement;){let Yt=window.getComputedStyle(Ne).display;if(Yt==="flex"||Yt==="inline-flex")return Ne;Ne=Ne.parentElement}return null},G=le=>{let Ye=window.getComputedStyle(le).flexDirection;return Ye==="column"||Ye==="column-reverse"?"vertical":"horizontal"},K=le=>{let Ye=le.getAttribute("data-pm");return Ye||(Ye=Math.random().toString(36).substring(2,8),le.setAttribute("data-pm",Ye)),{selector:`[data-pm="${Ye}"]`,durableSelector:Dn(le)}},w=()=>{k=!0,m&&clearTimeout(m),m=setTimeout(()=>{k=!1,m=null},300)},W=(le,Ye,Bt)=>{let Ne=G(le);if(Ye===Ne){let Cn=window.getComputedStyle(le).justifyContent,vt=Cn==="normal"||Cn==="flex-start"||Cn==="start"?"flex-start":Cn==="flex-end"||Cn==="end"?"flex-end":Cn==="center"?"center":null;if(!vt)return;let _o=f.indexOf(vt)+Bt;if(_o<0||_o>=f.length)return;let mo=f[_o],{selector:No,durableSelector:Yi}=K(le);Ve(le,"justify-content",mo),t({type:"MODIFY_STYLES_BATCH",payload:{selector:No,durableSelector:Yi,element:Tn(le),changes:[{property:"justify-content",original:Cn,modified:mo}]}})}else{let Cn=window.getComputedStyle(le).flexDirection,vt=Ne==="horizontal"?"column":"row",{selector:go,durableSelector:_o}=K(le);Ve(le,"flex-direction",vt),t({type:"MODIFY_STYLES_BATCH",payload:{selector:go,durableSelector:_o,element:Tn(le),changes:[{property:"flex-direction",original:Cn,modified:vt}]}})}oo(Yt=>Yt+1)},Y=(le,Ye,Bt)=>{let Yt=G(le)==="horizontal"?"vertical":"horizontal";if(Ye!==Yt)return;let vt=window.getComputedStyle(le).alignItems,go=vt==="normal"||vt==="stretch"||vt==="flex-start"||vt==="start"?"flex-start":vt==="flex-end"||vt==="end"?"flex-end":vt==="center"?"center":null;if(!go)return;let mo=b.indexOf(go)+Bt;if(mo<0||mo>=b.length)return;let No=b[mo],{selector:Yi,durableSelector:zc}=K(le);Ve(le,"align-items",No),t({type:"MODIFY_STYLES_BATCH",payload:{selector:Yi,durableSelector:zc,element:Tn(le),changes:[{property:"align-items",original:vt,modified:No}]}}),oo($c=>$c+1)},V=20,me=null,Ce=null,Le=0,gt=(le,Ye,Bt)=>{let Ne=B(Ye,Bt);st(Ne?{modifier:le,target:Ne}:null)},mt=le=>{if(!(e.activeTool!=="hand"||!e.isAnnotating)){if(le.key==="Shift"&&!le.altKey){let Ye=Nt.current;gt("shift",Ye.x,Ye.y)}else if(le.key==="Alt"&&!le.shiftKey){let Ye=Nt.current;gt("alt",Ye.x,Ye.y)}}},bt=le=>{if(e.activeTool!=="hand"||!e.isAnnotating)return;let Ye=le.shiftKey&&!le.altKey,Bt=le.altKey&&!le.shiftKey;if(!Ye&&!Bt||le.buttons!==0){me=null,Ce=null,Le=0,E=null,$=null,st(null);return}if(E===null&&(E=le.clientX,$=le.clientY,gt(Ye?"shift":"alt",le.clientX,le.clientY)),k)return;me===null&&(me=le.clientX,Ce=le.clientY,Le=0);let Ne=le.clientX-me,Yt=le.clientY-Ce,Cn=Math.abs(Ne)>=Math.abs(Yt)?Ne:Yt;if(Math.abs(Cn)>3){let No=Cn>0?1:-1;if(Le!==0&&No!==Le){me=le.clientX,Ce=le.clientY,Le=0;return}Le=No}if(Math.abs(Ne)<V&&Math.abs(Yt)<V)return;let vt=B(E,$);if(!vt)return;let go=Math.abs(Ne)>=Math.abs(Yt)?"horizontal":"vertical",mo=(go==="horizontal"?Ne:Yt)>0?1:-1;me=null,Ce=null,Le=0,Ye?W(vt,go,mo):Y(vt,go,mo),w()},Ot=le=>{(le.key==="Shift"||le.key==="Alt")&&(E=null,$=null,me=null,Ce=null,Le=0,st(null))},dt=()=>{st(null),me=null,Ce=null,Le=0};return window.addEventListener("keydown",mt),window.addEventListener("mousemove",bt),window.addEventListener("mousedown",dt),window.addEventListener("keyup",Ot),()=>{window.removeEventListener("keydown",mt),window.removeEventListener("mousemove",bt),window.removeEventListener("mousedown",dt),window.removeEventListener("keyup",Ot),m&&clearTimeout(m)}},[e.activeTool,e.isAnnotating,t]),hn(()=>{let f=b=>{if(b.key==="Escape"){if(ro.current)return;if(e.activeTool==="model"&&Qe.size>0){b.preventDefault(),pt(new Map);return}if(Yn.current.length>0){b.preventDefault(),io();return}}if(b.key==="Enter"&&e.activeTool==="model"&&Qe.size>0&&d){b.preventDefault();let E=[...Qe.keys()].filter($=>!h?.has($));E.length>0&&d(E),pt(new Map);return}if((b.metaKey||b.ctrlKey)&&b.key==="v"&&ze.current.length>0&&!ro.current){b.preventDefault(),de.current++;let E=de.current*20,B=ze.current[0]?.groupId?Math.random().toString(36).substring(2,9):void 0,G=ze.current.map(w=>({...w,id:Math.random().toString(36).substring(2,9),groupId:w.groupId?B:void 0,timestamp:Date.now(),points:w.points.map(W=>({x:W.x+E,y:W.y+E}))}));t({type:"PASTE_ANNOTATIONS",payload:{annotations:G}});let K=G.find(w=>w.type!=="text")||G[0];K&&wn(K.id);return}let R=Yn.current;if(R.length===0||ro.current)return;let m=b.composedPath?.()[0]??b.target,k=m?.tagName;if(!(k==="INPUT"||k==="TEXTAREA"||m?.isContentEditable)&&(b.key==="Delete"||b.key==="Backspace")){if(b.preventDefault(),u){let E=Sn.current.annotations;for(let $ of R){let B=E.find(K=>K.id===$);if(!B)continue;let G=B.threadId||B.groupId&&E.find(K=>K.groupId===B.groupId&&K.threadId)?.threadId;G&&u(G)}}for(let E of R)t({type:"DELETE_ANNOTATION",payload:{id:E}});io()}};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[t,io,wn,e.activeTool,Qe,h,d,u]);let H=mr(),z=Ii(()=>e.annotations.filter(f=>!f.pathname||f.pathname===H),[e.annotations,H]),Q=Ii(()=>vi(e.annotations),[e.annotations]),oe=Ii(()=>{let f=new Map,b=new Set,R=1,m=[...e.annotations].sort((k,E)=>k.timestamp-E.timestamp);for(let k of m)if(!Q.has(k))if(k.groupId){if(!b.has(k.groupId)){b.add(k.groupId);let E=e.annotations.filter($=>$.groupId===k.groupId);for(let $ of E)f.set($.id,R);R++}}else f.set(k.id,R),R++;return f},[e.annotations,Q]),ue=Ii(()=>{if(Gt.length===0)return null;let f=new Map;for(let b of Gt){let R=e.annotations.find(k=>k.id===b);if(!R)continue;let m=R.groupId?e.annotations.filter(k=>k.groupId===R.groupId):[R];for(let k of m)if(k.linkedSelector&&!a?.has(k.linkedSelector)){let E=k.color||e.activeColor;f.set(k.linkedSelector,E)}}return f.size>0?f:null},[Gt,e.annotations,e.activeColor,a]);hn(()=>{let f=z.filter(b=>!(Q.has(b)||L&&!L.isNew&&b.id===L.id));ee(f,e.currentPath,e.activeTool,e.activeColor,e.strokeWidth,Gt,jl,Zt.x,Zt.y,oe,P)},[z,e.currentPath,e.activeTool,e.activeColor,e.strokeWidth,ee,L,Gt,Zt,oe,Q,P]),hn(()=>{if(j){let f=Math.random().toString(36).substring(2,9);ce({id:f,point:j.point,text:"",fontSize:12,isNew:!0,groupId:j.groupId}),se(null)}},[j]),hn(()=>{_&&(ce({id:Math.random().toString(36).substring(2,9),point:_.point,text:"",fontSize:12,isNew:!0,linkedSelector:_.linkedSelector,linkedAnchor:_.linkedAnchor,elements:_.elements}),he(null))},[_]);let xe=Ut(null),we=L?.id??null;hn(()=>{we&&fe.current?requestAnimationFrame(()=>{let f=fe.current;if(!f||(f.focus(),Ae.current===we))return;Ae.current=we;let b=ro.current;if(b){if(xe.current!==null){let R=Math.min(xe.current,f.value.length);f.setSelectionRange(R,R);return}if(!b.isNew&&b.clickPoint){let R=J.current;if(!R)return;let m=R.getContext("2d");if(!m)return;m.font=`${b.fontSize}px ${Vt}`;let k=b.fontSize*1.4,E=b.text.split(`
4
- `),$=b.clickPoint.y-b.point.y,B=Math.max(0,Math.min(E.length-1,Math.floor($/k))),G=b.clickPoint.x-b.point.x,K=E[B]||"",w=0;for(let Y=0;Y<=K.length;Y++){let V=m.measureText(K.substring(0,Y)).width;if(V>G){let me=Y>0?m.measureText(K.substring(0,Y-1)).width:0;w=G-me<V-G?Y-1:Y;break}w=Y}let W=w;for(let Y=0;Y<B;Y++)W+=(E[Y]?.length||0)+1;f.setSelectionRange(W,W)}}}):(Ae.current=null,xe.current=null)},[we,J]);let ae=nn(f=>{let b=J.current;if(!b)return{x:0,y:0};let R=b.getBoundingClientRect(),m,k;if("touches"in f&&f.touches[0])m=f.touches[0].clientX,k=f.touches[0].clientY;else if("clientX"in f)m=f.clientX,k=f.clientY;else return{x:0,y:0};return{x:m-R.left+window.scrollX,y:k-R.top+window.scrollY}},[J]),at=nn((f,b,R,m)=>{let k=R.x-b.x,E=R.y-b.y,$=k*k+E*E;if($===0)return Math.sqrt((f.x-b.x)**2+(f.y-b.y)**2)<=m;let B=Math.max(0,Math.min(1,((f.x-b.x)*k+(f.y-b.y)*E)/$)),G=b.x+B*k,K=b.y+B*E;return Math.sqrt((f.x-G)**2+(f.y-K)**2)<=m},[]),It=nn(f=>{for(let R=z.length-1;R>=0;R--){let m=z[R];if(!m||Q.has(m))continue;let k=(m.strokeWidth||3)+4;switch(m.type){case"text":{if(!m.points[0]||!m.text)continue;let E=m.points[0],$=m.fontSize||12,B=J.current;if(B){let G=B.getContext("2d");if(G){G.font=`${$}px ${Vt}`;let K=m.text.replace(/\n/g," "),w=E.x-Zt.x,W=yr(w),Y=br(G,K,W),V=G.measureText(Y).width,me=$*1.4;if(f.x>=E.x-4-4&&f.x<=E.x+V+4+4&&f.y>=E.y-4-4&&f.y<=E.y+me+4+4)return m}}break}case"rectangle":{if(m.points.length<2)continue;let E=m.points[0],$=m.points[m.points.length-1],B=Math.min(E.x,$.x),G=Math.max(E.x,$.x),K=Math.min(E.y,$.y),w=Math.max(E.y,$.y),W=at(f,{x:B,y:K},{x:G,y:K},k),Y=at(f,{x:B,y:w},{x:G,y:w},k),V=at(f,{x:B,y:K},{x:B,y:w},k),me=at(f,{x:G,y:K},{x:G,y:w},k);if(W||Y||V||me)return m;break}case"circle":{if(m.points.length<2)continue;let E=m.points[0],$=m.points[m.points.length-1],B=(E.x+$.x)/2,G=(E.y+$.y)/2,K=Math.abs($.x-E.x)/2,w=Math.abs($.y-E.y)/2,W=f.x-B,Y=f.y-G,V=Math.sqrt((W/K)**2+(Y/w)**2);if(Math.abs(V-1)*Math.max(K,w)<=k)return m;break}case"line":{if(m.points.length<2)continue;let E=m.points[0],$=m.points[m.points.length-1];if(at(f,E,$,k))return m;break}case"freehand":{if(m.points.length<2)continue;for(let E=0;E<m.points.length-1;E++){let $=m.points[E],B=m.points[E+1];if(at(f,$,B,k))return m}break}}}return null},[z,J,at,Q,Zt.x]),ln=nn(f=>{let b=It(f);return b?.type==="text"?b:null},[It]),cn=nn(f=>{if(Gt.length===0)return null;let b=jl/2+4;for(let R of Gt){let m=e.annotations.find(k=>k.id===R);if(!(!m||m.points.length<2)){if(m.type==="line"){let k=m.points[0],E=m.points[m.points.length-1];if(Math.sqrt((f.x-k.x)**2+(f.y-k.y)**2)<=b)return{handle:"start",annotationId:R};if(Math.sqrt((f.x-E.x)**2+(f.y-E.y)**2)<=b)return{handle:"end",annotationId:R};continue}if(m.type==="circle"){let k=m.points[0],E=m.points[m.points.length-1],$=Math.min(k.x,E.x),B=Math.max(k.x,E.x),G=Math.min(k.y,E.y),K=Math.max(k.y,E.y),w=($+B)/2,W=(G+K)/2,Y=[{handle:"top",x:w,y:G},{handle:"bottom",x:w,y:K},{handle:"left",x:$,y:W},{handle:"right",x:B,y:W}];for(let{handle:V,x:me,y:Ce}of Y)if(Math.sqrt((f.x-me)**2+(f.y-Ce)**2)<=b)return{handle:V,annotationId:R};continue}if(m.type==="rectangle"||m.type==="freehand"){let k=m.points[0],E=m.points[m.points.length-1],$,B,G,K;m.type==="freehand"?($=Math.min(...m.points.map(W=>W.x)),B=Math.max(...m.points.map(W=>W.x)),G=Math.min(...m.points.map(W=>W.y)),K=Math.max(...m.points.map(W=>W.y))):($=Math.min(k.x,E.x),B=Math.max(k.x,E.x),G=Math.min(k.y,E.y),K=Math.max(k.y,E.y));let w=[{corner:"topLeft",x:$,y:G},{corner:"topRight",x:B,y:G},{corner:"bottomLeft",x:$,y:K},{corner:"bottomRight",x:B,y:K}];for(let{corner:W,x:Y,y:V}of w)if(Math.sqrt((f.x-Y)**2+(f.y-V)**2)<=b)return{handle:W,annotationId:R}}}}return null},[Gt,e.annotations]);hn(()=>{let f=b=>{if(De.current={x:b.clientX+window.scrollX,y:b.clientY+window.scrollY},!L){let R=ln(De.current);be(R?.id||null)}};return window.addEventListener("mousemove",f),()=>window.removeEventListener("mousemove",f)},[L,ln]);let Ke=nn(()=>{if(!L)return;let f=L.images?.length||0;if(L.text.trim()||f>0)if(L.isNew){let b=ri();t({type:"ADD_TEXT",payload:{point:L.point,text:L.text||(f>0?`[${f} image${f>1?"s":""}]`:""),fontSize:L.fontSize,id:b,groupId:L.groupId,linkedSelector:L.linkedSelector,linkedAnchor:L.linkedAnchor,elements:L.elements,...f>0?{imageCount:f}:{}}}),f>0&&L.images&&l&&l(b,L.images)}else t({type:"UPDATE_TEXT",payload:{id:L.id,text:L.text||(f>0?`[${f} image${f>1?"s":""}]`:""),...f>0?{imageCount:f}:{}}}),f>0&&L.images&&l&&l(L.id,L.images);else L.isNew||t({type:"DELETE_ANNOTATION",payload:{id:L.id}});ce(null)},[L,t,l]),Dt=nn(f=>{for(let b=0;b<Ws.length-1;b++){let R=Ws[b],m=Ws[b+1];if(f<=(R+m)/2)return R;if(f<m)return m}return Math.round(f/8)*8},[]),Rn=nn((f,b,R,m)=>{let k=R.top+Math.max(m.top,4),E=R.bottom-Math.max(m.bottom,4),$=R.left+Math.max(m.left,4),B=R.right-Math.max(m.right,4);if(f<R.left||f>R.right||b<R.top||b>R.bottom)return null;let G=b<k,K=b>E,w=f<$,W=f>B;return G&&w?m.top>=m.left?"top":"left":G&&W?m.top>=m.right?"top":"right":K&&w?m.bottom>=m.left?"bottom":"left":K&&W?m.bottom>=m.right?"bottom":"right":G?"top":K?"bottom":w?"left":W?"right":null},[]),mn=nn(f=>{if(!e.isAnnotating)return;if(e.inspectedElement&&e.activeTool==="hand"&&!("button"in f&&f.button===2)){f.preventDefault(),f.stopPropagation(),t({type:"SELECT_ELEMENT",payload:null});return}let b=ae(f),R="shiftKey"in f&&f.shiftKey;if(e.activeTool==="inspector"){if("button"in f&&f.button===2)return;if(Z&&!Jn(Z)){let E=e.annotations.find(Le=>{if(!Le.linkedSelector||!Le.threadId)return!1;try{return Z.matches(Le.linkedSelector)}catch{return!1}});if(E?.threadId&&c){c(E.threadId),requestAnimationFrame(()=>{document.querySelector("[data-popmelt-shadow-host]")?.shadowRoot?.querySelector("[data-popmelt-reply]")?.focus()});return}let $=Tn(Z),B=Dn(Z),G=Z.getBoundingClientRect(),K=Z.getAttribute("data-pm");K||(K=Math.random().toString(36).substring(2,8),Z.setAttribute("data-pm",K));let w=`[data-pm="${K}"]`,W=e.styleModifications.some(Le=>{try{return Z.matches(Le.selector)}catch{return!1}}),Y=e.annotations.filter(Le=>{if(!Le.linkedSelector)return!1;try{return Z.matches(Le.linkedSelector)}catch{return!1}}).length,V=(W?1:0)+Y,me=G.top>=Fn*(1+V)?"top-left":"bottom-left",Ce=Gl(G,me,V,D?.current);he({point:Ce,linkedSelector:w,linkedAnchor:me,elements:[{...$,selector:B}]})}return}if(e.activeTool==="model"){if("button"in f&&f.button===2)return;if(Ee){let E=Ee.name;if(h?.has(E)){g?.(E);return}"shiftKey"in f&&f.shiftKey?pt(B=>{let G=new Map(B);return G.has(E)?G.delete(E):G.set(E,Ee),G}):Qe.size===1&&Qe.has(E)?(d&&d([E]),pt(new Map)):pt(new Map([[E,Ee]]))}return}if(e.activeTool==="hand"&&xt&&ft){let E=xt,$=E.getAttribute("data-pm");$||($=Math.random().toString(36).substring(2,8),E.setAttribute("data-pm",$));let B=Dn(E),G=`[data-pm="${$}"]`,K=Tn(E),w=Yo(E),W=b.x-window.scrollX,Y=b.y-window.scrollY,V=on,me=window.getComputedStyle(E).justifyContent,Ce=0;if(V){let gt=vo(E).find(mt=>mt.axis===ft);Ce=gt?ft==="column"?gt.w:gt.h:0}Ve(E,"transition","none"),At.current={isDragging:!0,hasMoved:!1,axis:ft,startX:W,startY:Y,originalRow:V?Ce:w.row,originalColumn:V?Ce:w.column,element:E,elementInfo:{...K,selector:G},selector:G,durableSelector:B,isAuto:V,originalJustifyContent:me,visualGap:Ce},Gn({axis:ft,row:V?Ce:w.row,column:V?Ce:w.column});return}if(e.activeTool==="hand"&&$t&&rn){let E=$t,$=E.getAttribute("data-pm");$||($=Math.random().toString(36).substring(2,8),E.setAttribute("data-pm",$));let B=`[data-pm="${$}"]`,G=Tn(E),{fontSize:K,lineHeight:w}=Fr(E),W=K>0?w/K:1.2,Y=b.x-window.scrollX,V=b.y-window.scrollY;Ve(E,"transition","none");let me=Dn(E);St.current={isDragging:!0,property:rn,startX:Y,startY:V,originalFontSize:K,originalLineHeight:w,originalRatio:W,element:E,elementInfo:{...G,selector:B},selector:B,durableSelector:me},ko({property:rn,fontSize:K,lineHeight:w});return}if(e.activeTool==="hand"&&U&&He){let E=U,$=E.getAttribute("data-pm");$||($=Math.random().toString(36).substring(2,8),E.setAttribute("data-pm",$));let B=`[data-pm="${$}"]`,G=Dn(E),K=Tn(E),w=Vo(E),W=E.getBoundingClientRect(),Y=Math.floor(W.height/2),V=b.y-window.scrollY;Ve(E,"transition","none"),fn.current={isDragging:!0,corner:He,startY:V,original:w,maxRadius:Y,element:E,elementInfo:{...K,selector:B},selector:B,durableSelector:G},Oe({corner:He,radius:{...w}});return}if(e.activeTool==="hand"&&yt&&te){let E=yt,$=E.getAttribute("data-pm");$||($=Math.random().toString(36).substring(2,8),E.setAttribute("data-pm",$));let B=`[data-pm="${$}"]`,G=Dn(E),K=Tn(E),w=wr(E),W=b.x-window.scrollX,Y=b.y-window.scrollY;Ve(E,"transition","none"),Lt.current={isDragging:!0,side:te,startX:W,startY:Y,original:w,element:E,elementInfo:{...K,selector:B},selector:B,durableSelector:G},_t({side:te,padding:{...w}});return}let m=cn(b);if(m){let E=e.annotations.find($=>$.id===m.annotationId);if(E&&E.type!=="text"&&(E.status??"pending")==="pending"){To({annotationId:m.annotationId,handle:m.handle,startPoint:b,originalPoints:[...E.points],hasMoved:!1});return}}let k=It(b);if(k&&k.points[0]){if(L&&Ke(),k.type!=="text"?(wn(k.id,R),k.color&&t({type:"SET_COLOR",payload:k.color})):R||io(),c){let E=k.threadId||(k.groupId?e.annotations.find($=>$.groupId===k.groupId&&$.threadId)?.threadId:void 0);E&&c(E)}jt({annotation:k,startPoint:b,hasMoved:!1});return}if(R||io(),e.activeTool==="text"){L&&Ke();let E=Math.random().toString(36).substring(2,9);ce({id:E,point:b,text:"",fontSize:12,isNew:!0});return}T(!0),t({type:"START_PATH",payload:b})},[e.isAnnotating,e.activeTool,e.inspectedElement,e.annotations,L,Gt,Z,yt,te,U,He,xt,ft,on,$t,rn,Ee,Qe,h,d,g,c,ae,It,cn,t,wn,io,Ke]),Qt=nn(f=>{let b=ae(f);if(e.activeTool==="inspector"&&e.isAnnotating){let R=b.x-window.scrollX,m=b.y-window.scrollY,k=Jo(R,m),E=k&&Jn(k)?null:k;E!==Z&&(Se(E),lt(E?Tn(E):null));return}if(e.activeTool==="model"&&e.isAnnotating){let R=b.x-window.scrollX,m=b.y-window.scrollY,k=Jo(R,m);if(k!==X.current&&(X.current=k,je.current=0),k){let E=ci(k,je.current);Ge(E)}else Ge(null);return}if(e.activeTool==="hand"&&e.isAnnotating){let R=b.x-window.scrollX,m=b.y-window.scrollY;Nt.current={x:R,y:m},Pn({x:R,y:m});let k=fo.current.cmd,E=fo.current.shift;if(At.current.isDragging){let B=At.current,G=B.element;if(!G)return;if(!B.hasMoved){let Y=Math.abs(R-B.startX),V=Math.abs(m-B.startY);if(Y<=2&&V<=2)return;B.hasMoved=!0,B.isAuto&&(Ve(G,"justify-content","normal"),Ve(G,"row-gap",`${B.visualGap}px`),Ve(G,"column-gap",`${B.visualGap}px`),Mn(!1))}let K=B.axis,w=B.originalRow,W=B.originalColumn;if(K==="column"){let Y=R-B.startX;W=B.originalColumn+Y,k||(w=B.originalRow+Y)}else{let Y=m-B.startY;w=B.originalRow+Y,k||(W=B.originalColumn+Y)}w=Math.max(0,w),W=Math.max(0,W),E&&(w=Dt(w),W=Dt(W)),w=Math.round(w),W=Math.round(W),Ve(G,"row-gap",`${w}px`),Ve(G,"column-gap",`${W}px`),Gn({axis:K,row:w,column:W});return}if(fn.current.isDragging){let B=fn.current,G=B.element;if(!G)return;let K=m-B.startY,w=B.corner,W=B.original,Y={...W};if(k){let V=W[w]+K;V=Math.max(0,Math.min(B.maxRadius,V)),E&&(V=Dt(V)),V=Math.round(V),Y[w]=V}else{let V=W[w]+K;V=Math.max(0,Math.min(B.maxRadius,V)),E&&(V=Dt(V)),V=Math.round(V),Y={"top-left":V,"top-right":V,"bottom-right":V,"bottom-left":V}}Ve(G,"border-top-left-radius",`${Y["top-left"]}px`),Ve(G,"border-top-right-radius",`${Y["top-right"]}px`),Ve(G,"border-bottom-right-radius",`${Y["bottom-right"]}px`),Ve(G,"border-bottom-left-radius",`${Y["bottom-left"]}px`),Oe({corner:w,radius:Y});return}if(St.current.isDragging){let B=St.current,G=B.element;if(!G)return;let K=B.property,w=B.originalFontSize,W=B.originalLineHeight,Y=[8,10,11,12,13,14,16,18,20,22,24,28,32,36,40,48,56,64,72,80,96];if(K==="font-size"){let me=R-B.startX;w=B.originalFontSize+me,w=Math.max(1,w)}else{let me=m-B.startY;W=B.originalLineHeight+me,W=Math.max(w,W)}if(E)if(K==="font-size"){let me=Y[0],Ce=Math.abs(w-me);for(let Le of Y){let gt=Math.abs(w-Le);gt<Ce&&(me=Le,Ce=gt)}w=me}else{let me=w>0?W/w:1.2,Ce=Math.round(me*2)/2;W=w*Math.max(1,Ce)}w=Math.round(w),W=Math.round(W*10)/10,Ve(G,"font-size",`${w}px`);let V=w>0?Math.round(W/w*1e3)/1e3:1.2;Ve(G,"line-height",`${V}`),ko({property:K,fontSize:w,lineHeight:W});return}if(Lt.current.isDragging){let B=Lt.current,G=B.element;if(!G)return;let K=B.side,w=B.original,W=w.top,Y=w.right,V=w.bottom,me=w.left;if(K==="top"){let Ce=B.startY-m;W=w.top+Ce,k||(V=w.bottom+Ce)}else if(K==="bottom"){let Ce=m-B.startY;V=w.bottom+Ce,k||(W=w.top+Ce)}else if(K==="left"){let Ce=B.startX-R;me=w.left+Ce,k||(Y=w.right+Ce)}else if(K==="right"){let Ce=R-B.startX;Y=w.right+Ce,k||(me=w.left+Ce)}W=Math.max(0,W),Y=Math.max(0,Y),V=Math.max(0,V),me=Math.max(0,me),E&&(W=Dt(W),Y=Dt(Y),V=Dt(V),me=Dt(me)),W=Math.round(W),Y=Math.round(Y),V=Math.round(V),me=Math.round(me),Ve(G,"padding",`${W}px ${Y}px ${V}px ${me}px`),_t({side:K,padding:{top:W,right:Y,bottom:V,left:me}});return}let $=Jo(R,m);for(;$&&$.tagName==="A";)$=$.parentElement;{let G=[];$&&G.push($),U&&U!==$&&G.push(U);let K=null,w=16,W=null;for(let Y of G){let V=Y.getBoundingClientRect(),me=Vo(Y),Ce=[["top-left",V.left,V.top+me["top-left"]],["top-right",V.right,V.top+me["top-right"]],["bottom-right",V.right,V.bottom-me["bottom-right"]],["bottom-left",V.left,V.bottom-me["bottom-left"]]];for(let[Le,gt,mt]of Ce){let bt=Math.hypot(R-gt,m-mt);bt<w&&(w=bt,K=Le,W=Y)}}if(K&&W){Me(W),Pt(K),yt&&ne(null),te&&ge(null),xt&&Kt(null),ft&&Jt(null),Mn(!1),$t&&gn(null),rn&&po(null);return}}U&&Me(null),He&&Pt(null);{let B=[];$&&fi($)&&B.push($);let G=$?.parentElement??null;for(;G&&G!==document.body&&B.length<3;)fi(G)&&B.push(G),G=G.parentElement;for(let K of B){let W=vo(K).find(Y=>R>=Y.x&&R<=Y.x+Y.w&&m>=Y.y&&m<=Y.y+Y.h);if(W){Kt(K),Jt(W.axis),Mn(gs(K,W.axis)),yt&&ne(null),te&&ge(null),$t&&gn(null),rn&&po(null);return}}}xt&&Kt(null),ft&&Jt(null),Mn(!1);{let G=[];$&&G.push($),$t&&$t!==$&&G.push($t);let K=null,w=1/0,W=null;for(let Y of G){if(!ms(Y))continue;let V=Cr(Y);if(!V)continue;let me=R>=V.left&&R<=V.right&&m>=V.top&&m<=V.bottom,Ce=[["font-size",V.right,V.top+V.height/2],["line-height",V.left+V.width/2,V.bottom]];for(let[Le,gt,mt]of Ce){let bt=Math.hypot(R-gt,m-mt);(me||bt<12)&&bt<w&&(w=bt,K=Le,W=Y)}}K&&W?(gn(W),po(K)):($t&&gn(null),rn&&po(null))}if($!==yt&&ne($),$){let B=wr($),G=$.getBoundingClientRect(),K=Rn(R,m,G,B);ge(K)}else ge(null);return}if(In){let{handle:R,originalPoints:m,hasMoved:k}=In,E=e.annotations.find(w=>w.id===In.annotationId);if(!E)return;let $="metaKey"in f,B=$&&(f.metaKey||f.ctrlKey),G=$&&f.shiftKey,K;if(E.type==="line"){let w=m[0],W=m[m.length-1];R==="start"?K=[b,W]:K=[w,b]}else if(E.type==="freehand"){let w=Math.min(...m.map(Ne=>Ne.x)),W=Math.max(...m.map(Ne=>Ne.x)),Y=Math.min(...m.map(Ne=>Ne.y)),V=Math.max(...m.map(Ne=>Ne.y)),me=(w+W)/2,Ce=(Y+V)/2,Le=W-w||1,gt=V-Y||1,mt=Le/gt,bt=w,Ot=W,dt=Y,le=V;switch(R){case"topLeft":bt=b.x,dt=b.y;break;case"topRight":Ot=b.x,dt=b.y;break;case"bottomLeft":bt=b.x,le=b.y;break;case"bottomRight":Ot=b.x,le=b.y;break}if(B)switch(R){case"topLeft":Ot=W+(w-bt),le=V+(Y-dt);break;case"topRight":bt=w-(Ot-W),le=V+(Y-dt);break;case"bottomLeft":Ot=W+(w-bt),dt=Y-(le-V);break;case"bottomRight":bt=w-(Ot-W),dt=Y-(le-V);break}if(G){let Ne=Ot-bt,Yt=le-dt;if(Math.abs(Ne/Yt)>mt){let vt=Math.abs(Yt)*mt*Math.sign(Ne);R==="topLeft"||R==="bottomLeft"?bt=Ot-vt:Ot=bt+vt}else{let vt=Math.abs(Ne)/mt*Math.sign(Yt);R==="topLeft"||R==="topRight"?dt=le-vt:le=dt+vt}}let Ye=Ot-bt||1,Bt=le-dt||1;K=m.map(Ne=>({x:bt+(Ne.x-w)/Le*Ye,y:dt+(Ne.y-Y)/gt*Bt}))}else if(E.type==="circle"){let w=m[0],W=m[m.length-1],Y=Math.min(w.x,W.x),V=Math.max(w.x,W.x),me=Math.min(w.y,W.y),Ce=Math.max(w.y,W.y),Le=(Y+V)/2,gt=(me+Ce)/2,mt=V-Y,bt=Ce-me,Ot=Y,dt=V,le=me,Ye=Ce;switch(R){case"top":if(le=b.y,B&&(Ye=gt+(gt-b.y)),G){let Ne=(Ye-le)*(mt/bt)/2;Ot=Le-Ne,dt=Le+Ne}break;case"bottom":if(Ye=b.y,B&&(le=gt-(b.y-gt)),G){let Ne=(Ye-le)*(mt/bt)/2;Ot=Le-Ne,dt=Le+Ne}break;case"left":if(Ot=b.x,B&&(dt=Le+(Le-b.x)),G){let Ne=(dt-Ot)*(bt/mt)/2;le=gt-Ne,Ye=gt+Ne}break;case"right":if(dt=b.x,B&&(Ot=Le-(b.x-Le)),G){let Ne=(dt-Ot)*(bt/mt)/2;le=gt-Ne,Ye=gt+Ne}break}K=[{x:Ot,y:le},{x:dt,y:Ye}]}else{let w=m[0],W=m[m.length-1],Y=Math.min(w.x,W.x),V=Math.max(w.x,W.x),me=Math.min(w.y,W.y),Ce=Math.max(w.y,W.y),Le=(Y+V)/2,gt=(me+Ce)/2,mt=V-Y||1,bt=Ce-me||1,Ot=mt/bt,dt=Y,le=V,Ye=me,Bt=Ce;switch(R){case"topLeft":dt=b.x,Ye=b.y;break;case"topRight":le=b.x,Ye=b.y;break;case"bottomLeft":dt=b.x,Bt=b.y;break;case"bottomRight":le=b.x,Bt=b.y;break}if(B)switch(R){case"topLeft":le=V+(Y-dt),Bt=Ce+(me-Ye);break;case"topRight":dt=Y-(le-V),Bt=Ce+(me-Ye);break;case"bottomLeft":le=V+(Y-dt),Ye=me-(Bt-Ce);break;case"bottomRight":dt=Y-(le-V),Ye=me-(Bt-Ce);break}if(G){let Ne=le-dt,Yt=Bt-Ye;if(Math.abs(Ne/Yt)>Ot){let vt=Math.abs(Yt)*Ot*Math.sign(Ne);R==="topLeft"||R==="bottomLeft"?dt=le-vt:le=dt+vt}else{let vt=Math.abs(Ne)/Ot*Math.sign(Yt);R==="topLeft"||R==="topRight"?Ye=Bt-vt:Bt=Ye+vt}}K=[{x:dt,y:Ye},{x:le,y:Bt}]}t({type:"RESIZE_ANNOTATION",payload:{id:In.annotationId,points:K,saveUndo:!k}}),k||To({...In,hasMoved:!0});return}if(wt&&(wt.annotation.status??"pending")==="pending"){let R=b.x-wt.startPoint.x,m=b.y-wt.startPoint.y;if((Math.abs(R)>2||Math.abs(m)>2)&&!wt.hasMoved)jt({...wt,hasMoved:!0,startPoint:b}),t({type:"MOVE_ANNOTATION",payload:{id:wt.annotation.id,delta:{x:R,y:m},saveUndo:!0}});else if(wt.hasMoved){let E=b.x-wt.startPoint.x,$=b.y-wt.startPoint.y;jt({...wt,startPoint:b}),t({type:"MOVE_ANNOTATION",payload:{id:wt.annotation.id,delta:{x:E,y:$}}})}return}!y||!e.isAnnotating||t({type:"CONTINUE_PATH",payload:b})},[y,e.isAnnotating,e.activeTool,wt,In,Z,yt,te,U,He,xt,ft,$t,rn,ae,t,Dt,Rn]),dr=nn(f=>{if(St.current.isDragging){let m=St.current,k=m.element;if(k&&m.selector&&m.elementInfo&&Wt){k instanceof HTMLElement&&(k.style.removeProperty("font-size"),k.style.removeProperty("line-height"),k.style.removeProperty("transition"));let E=[];if(m.originalFontSize!==Wt.fontSize&&(Ve(k,"font-size",`${Wt.fontSize}px`),E.push({property:"font-size",original:`${m.originalFontSize}px`,modified:`${Wt.fontSize}px`})),m.originalLineHeight!==Wt.lineHeight){let $=m.originalFontSize>0?Math.round(m.originalLineHeight/m.originalFontSize*1e3)/1e3:1.2,B=Wt.fontSize>0?Math.round(Wt.lineHeight/Wt.fontSize*1e3)/1e3:1.2;Ve(k,"line-height",`${B}`),E.push({property:"line-height",original:`${$}`,modified:`${B}`})}E.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:m.selector,durableSelector:m.durableSelector??void 0,element:m.elementInfo,changes:E}})}St.current={isDragging:!1,property:null,startX:0,startY:0,originalFontSize:0,originalLineHeight:0,originalRatio:1.2,element:null,elementInfo:null,selector:null,durableSelector:null},ko(null);return}if(At.current.isDragging){let m=At.current,k=m.element,E="button"in f&&f.button===2;if(!m.hasMoved&&!E&&k&&m.selector&&m.elementInfo){k instanceof HTMLElement&&k.style.removeProperty("transition");let $=["space-between","space-around","stretch","normal"],B=m.originalJustifyContent||"normal",G=$.indexOf(B),K=$[(G+1)%$.length],w=[];K==="normal"?(Ve(k,"justify-content","normal"),w.push({property:"justify-content",original:m.originalJustifyContent,modified:"normal"})):K==="stretch"?(Ve(k,"justify-content",K),Ve(k,"row-gap","8px"),Ve(k,"column-gap","8px"),w.push({property:"justify-content",original:m.originalJustifyContent||"normal",modified:K}),m.originalRow!==8&&w.push({property:"row-gap",original:`${m.originalRow}px`,modified:"8px"}),m.originalColumn!==8&&w.push({property:"column-gap",original:`${m.originalColumn}px`,modified:"8px"})):(k instanceof HTMLElement&&(k.style.removeProperty("row-gap"),k.style.removeProperty("column-gap")),Ve(k,"justify-content",K),w.push({property:"justify-content",original:m.originalJustifyContent||"normal",modified:K}),m.originalRow>0&&w.push({property:"row-gap",original:`${m.originalRow}px`,modified:"0px"}),m.originalColumn>0&&w.push({property:"column-gap",original:`${m.originalColumn}px`,modified:"0px"})),w.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:m.selector,durableSelector:m.durableSelector??void 0,element:m.elementInfo,changes:w}})}else if(m.hasMoved&&k&&m.selector&&m.elementInfo&&tt){k instanceof HTMLElement&&(k.style.removeProperty("row-gap"),k.style.removeProperty("column-gap"),k.style.removeProperty("transition"));let $=[];m.isAuto?(k instanceof HTMLElement&&k.style.removeProperty("justify-content"),Ve(k,"justify-content","normal"),Ve(k,"row-gap",`${tt.row}px`),Ve(k,"column-gap",`${tt.column}px`),$.push({property:"justify-content",original:m.originalJustifyContent,modified:"normal"}),$.push({property:"row-gap",original:"0px",modified:`${tt.row}px`}),$.push({property:"column-gap",original:"0px",modified:`${tt.column}px`})):(m.originalRow!==tt.row&&(Ve(k,"row-gap",`${tt.row}px`),$.push({property:"row-gap",original:`${m.originalRow}px`,modified:`${tt.row}px`})),m.originalColumn!==tt.column&&(Ve(k,"column-gap",`${tt.column}px`),$.push({property:"column-gap",original:`${m.originalColumn}px`,modified:`${tt.column}px`}))),$.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:m.selector,durableSelector:m.durableSelector??void 0,element:m.elementInfo,changes:$}})}At.current={isDragging:!1,hasMoved:!1,axis:null,startX:0,startY:0,originalRow:0,originalColumn:0,element:null,elementInfo:null,selector:null,durableSelector:null,isAuto:!1,originalJustifyContent:"",visualGap:0},Gn(null);return}if(fn.current.isDragging){let m=fn.current,k=m.element;if(k&&m.selector&&m.elementInfo&&Xe){k instanceof HTMLElement&&(k.style.removeProperty("border-top-left-radius"),k.style.removeProperty("border-top-right-radius"),k.style.removeProperty("border-bottom-right-radius"),k.style.removeProperty("border-bottom-left-radius"),k.style.removeProperty("transition"));let E=["top-left","top-right","bottom-right","bottom-left"],$={"top-left":"border-top-left-radius","top-right":"border-top-right-radius","bottom-right":"border-bottom-right-radius","bottom-left":"border-bottom-left-radius"},B=[];for(let G of E)m.original[G]!==Xe.radius[G]&&(Ve(k,$[G],`${Xe.radius[G]}px`),B.push({property:$[G],original:`${m.original[G]}px`,modified:`${Xe.radius[G]}px`}));B.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:m.selector,durableSelector:m.durableSelector??void 0,element:m.elementInfo,changes:B}})}fn.current={isDragging:!1,corner:null,startY:0,original:{"top-left":0,"top-right":0,"bottom-right":0,"bottom-left":0},maxRadius:0,element:null,elementInfo:null,selector:null,durableSelector:null},Oe(null);return}if(Lt.current.isDragging){let m=Lt.current,k=m.element,E=m.selector,$=m.elementInfo;if(k&&E&&$&&Re){let B=m.original,G=Re.padding;k instanceof HTMLElement&&(k.style.removeProperty("padding"),k.style.removeProperty("transition"));let K=[],w=[{prop:"padding-top",origVal:B.top,newVal:G.top},{prop:"padding-right",origVal:B.right,newVal:G.right},{prop:"padding-bottom",origVal:B.bottom,newVal:G.bottom},{prop:"padding-left",origVal:B.left,newVal:G.left}];for(let{prop:W,origVal:Y,newVal:V}of w)Y!==V&&(Ve(k,W,`${V}px`),K.push({property:W,original:`${Y}px`,modified:`${V}px`}));K.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:E,durableSelector:m.durableSelector??void 0,element:$,changes:K}})}Lt.current={isDragging:!1,side:null,startX:0,startY:0,original:{top:0,right:0,bottom:0,left:0},element:null,elementInfo:null,selector:null,durableSelector:null},_t(null);return}if(In){To(null);return}if(wt){if(!wt.hasMoved&&wt.annotation.type==="text"&&(wt.annotation.status??"pending")==="pending"){let m=ae(f);ce({id:wt.annotation.id,point:wt.annotation.points[0],text:wt.annotation.text||"",fontSize:wt.annotation.fontSize||12,isNew:!1,clickPoint:m,groupId:wt.annotation.groupId})}jt(null);return}if(!y)return;let b=5;if(e.currentPath.length>=2){let m=e.currentPath[0],k=e.currentPath[e.currentPath.length-1],E=Math.abs(k.x-m.x),$=Math.abs(k.y-m.y);if((e.activeTool==="line"?Math.sqrt(E*E+$*$)<b:E<b&&$<b)&&["rectangle","circle","line"].includes(e.activeTool)){T(!1),t({type:"CANCEL_PATH"});return}}let R=cs(e.currentPath);if(e.activeTool==="rectangle"&&e.currentPath.length>=2){let m=e.currentPath[0],k=e.currentPath[e.currentPath.length-1],E=Math.min(m.x,k.x),$=Math.max(m.y,k.y),B=e.strokeWidth/2,G=Math.random().toString(36).substring(2,9);se({point:{x:E-B+4,y:$+B+4},groupId:G}),T(!1),t({type:"FINISH_PATH",payload:{groupId:G,elements:R}});return}T(!1),t({type:"FINISH_PATH",payload:{elements:R}})},[y,wt,In,Re,Xe,tt,Wt,ae,t,e.activeTool,e.currentPath,e.strokeWidth]),ji=nn(f=>{let b=f.target.value;xe.current=f.target.selectionStart,ce(R=>R&&{...R,text:b})},[]),Gi=nn(f=>{f.key==="Escape"?ce(null):f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),Ke())},[Ke]),Ji=nn(f=>{if(!L)return;let b=f.clipboardData.items,R=[];for(let m=0;m<b.length;m++){let k=b[m];if(k.type.startsWith("image/")){let E=k.getAsFile();E&&R.push(E)}}R.length>0&&(f.preventDefault(),ce(m=>m?{...m,images:[...m.images||[],...R]}:null))},[L]),Kr=nn(f=>{if(!e.isAnnotating)return;if(e.activeTool==="hand"){f.preventDefault();let R=yt||xt||U||$t;if(R&&!Jn(R)){let m=Tn(R),k=Dn(R);t({type:"SELECT_ELEMENT",payload:{el:R,info:{...m,selector:k}}})}return}f.preventDefault();let b=J.current;b&&(A.current=!0,b.style.pointerEvents="none",setTimeout(()=>{A.current&&(A.current=!1,b.style.pointerEvents="")},4e3))},[e.activeTool,e.isAnnotating,yt,xt,U,$t,t,Jn,J]);hn(()=>{let f=z.filter($=>$.linkedSelector);if(f.length===0)return;let b=null,R=document.createElement("canvas").getContext("2d"),m=()=>{let $=[];for(let B of f){let G=document.querySelector(B.linkedSelector);if(!G&&B.elements?.[0]?.selector&&B.linkedSelector.startsWith("[data-pm=")){try{G=document.querySelector(B.elements[0].selector)}catch{}if(G){let mt=B.linkedSelector.match(/data-pm="([^"]+)"/)?.[1];mt&&G.setAttribute("data-pm",mt)}}if(!G)continue;let K=G.getBoundingClientRect(),w=e.styleModifications.some(mt=>{try{return G.matches(mt.selector)}catch{return!1}}),W=f.filter(mt=>mt.id!==B.id&&mt.timestamp<B.timestamp&&mt.linkedSelector===B.linkedSelector).length,Y=(w?1:0)+W,V;if(B.text&&R){let mt=B.fontSize||12;R.font=`${mt}px ${Vt}`,V=Math.max(...B.text.split(`
5
- `).map(bt=>R.measureText(bt).width))}let me=K.top>=Fn*(1+Y)?"top-left":"bottom-left",Ce=Gl(K,me,Y,D?.current,V),Le=B.points[0],gt=me!==B.linkedAnchor;Le&&(gt||Math.abs(Ce.x-Le.x)>1||Math.abs(Ce.y-Le.y)>1)&&$.push({id:B.id,point:Ce,linkedAnchor:gt?me:void 0})}$.length>0&&t({type:"UPDATE_LINKED_POSITIONS",payload:{updates:$}})},k=()=>{b&&cancelAnimationFrame(b),b=requestAnimationFrame(m)};m(),window.addEventListener("scroll",k,!0),window.addEventListener("resize",k,!0),window.addEventListener("load",k),document.fonts.ready.then(k);let E=new MutationObserver(k);return E.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class"]}),()=>{window.removeEventListener("scroll",k,!0),window.removeEventListener("resize",k,!0),window.removeEventListener("load",k),E.disconnect(),b&&cancelAnimationFrame(b)}},[z,t]);let v=()=>{if(!e.isAnnotating)return"default";if(In){let{handle:f}=In;return f==="start"||f==="end"?"move":f==="top"||f==="bottom"?"ns-resize":f==="left"||f==="right"?"ew-resize":f==="topLeft"||f==="bottomRight"?"nwse-resize":"nesw-resize"}if(e.activeTool==="text")return"text";if(e.activeTool==="hand"){let f=tt?.axis??ft;if(f==="row")return"ns-resize";if(f==="column")return"ew-resize";if(Xe||He)return"ns-resize";let b=Wt?.property??rn;if(b==="font-size")return"ew-resize";if(b==="line-height")return"ns-resize";let R=Re?.side??te;return R==="top"||R==="bottom"?"ns-resize":R==="left"||R==="right"?"ew-resize":"default"}return"crosshair"},N={position:"fixed",top:0,left:0,width:"100vw",height:"100vh",zIndex:9998,pointerEvents:e.isAnnotating?"auto":"none",visibility:e.isAnnotating?"visible":"hidden",cursor:v()},ie=nn(()=>{let f=J.current;if(!f||!L)return{width:100,height:12*1.4,isWrapped:!1};let b=f.getContext("2d");if(!b)return{width:100,height:L.fontSize*1.4,isWrapped:!1};b.font=`${L.fontSize}px ${Vt}`;let m=b.measureText("Type here...").width,k=L.text.split(`
6
- `),E=k.length>0?Math.max(m,...k.map(w=>b.measureText(w||" ").width)):m,$=L.point.x-Zt.x,B=yr($);if(E>B){let w=Wa(b,k,B),W=Math.min(B,Math.max(m,...w.map(V=>b.measureText(V).width))),Y=Math.max(1,w.length)*L.fontSize*1.4;return{width:W,height:Y,isWrapped:!0}}let K=Math.max(1,k.length)*L.fontSize*1.4;return{width:E,height:K,isWrapped:!1}},[L,J,Zt.x])(),Ie=L?Math.max(1,L.text.split(`
7
- `).length)*L.fontSize*1.4+8:0,_e=ie.height+8,$e=ie.isWrapped?_e-Ie:0,ve=L?{position:"fixed",left:L.point.x-4-Zt.x,top:L.point.y-4-Zt.y-$e,zIndex:9999,width:ie.width+8,height:_e,padding:4,fontSize:L.fontSize,fontFamily:Vt,color:"#ffffff",backgroundColor:e.activeColor,border:"none",borderRadius:0,outline:"none",boxShadow:"none",lineHeight:1.4,resize:"none",overflow:"hidden",whiteSpace:ie.isWrapped?"pre-wrap":"pre",wordBreak:ie.isWrapped?"break-word":void 0}:{};return Rr(Lr,{children:[it("canvas",{ref:S,id:"devtools-canvas",style:N,onMouseDown:mn,onMouseMove:Qt,onMouseUp:f=>dr(f),onMouseLeave:f=>{dr(f),Se(null),lt(null)},onTouchStart:mn,onTouchMove:Qt,onTouchEnd:f=>dr(f),onContextMenu:Kr}),L&&Rr(Lr,{children:[it("style",{children:"#devtools-text-input::placeholder { color: rgba(255, 255, 255, 0.5); }"}),it("textarea",{id:"devtools-text-input",ref:fe,value:L.text,onChange:ji,onKeyDown:Gi,onPaste:Ji,onBlur:Ke,placeholder:"Type here...",style:ve}),L.images&&L.images.length>0&&Rr("div",{"data-devtools":!0,style:{position:"fixed",left:L.point.x-4-Zt.x,top:L.point.y-4-Zt.y-20,zIndex:1e4,fontSize:11,fontFamily:"system-ui, sans-serif",color:"#fff",backgroundColor:"rgba(0,0,0,0.7)",padding:"2px 6px",borderRadius:3,whiteSpace:"nowrap"},children:[L.images.length," image",L.images.length>1?"s":""," attached"]})]}),e.isAnnotating&&e.activeTool!=="hand"&&e.styleModifications.length>0&&it(Sl,{styleModifications:e.styleModifications,isInspecting:!!e.inspectedElement,accentColor:e.activeColor,annotationGroupCount:new Set(z.map(f=>f.groupId||f.id)).size,dispatch:t,inFlightSelectors:s,toolbarRef:D,onHoverSelector:rt}),e.activeTool==="hand"&&e.isAnnotating&&e.styleModifications.length>0&&it(Cl,{styleModifications:e.styleModifications,accentColor:e.activeColor}),e.isAnnotating&&it(dl,{annotations:z,supersededAnnotations:Q,inFlightIds:o,activeIds:r,queuePositions:i,scrollX:Zt.x,scrollY:Zt.y,annotationGroupMap:oe,onViewThread:c,onSelectAnnotation:wn,onHoverAnnotation:nt,canvasRef:J}),e.isAnnotating&&p&&it(ul,{annotations:z,supersededAnnotations:Q,scrollX:Zt.x,scrollY:Zt.y,onReply:p,annotationGroupMap:oe,canvasRef:J,onHoverAnnotation:nt}),e.isAnnotating&&a&&a.size>0&&it(ys,{inFlightSelectorColors:a}),e.isAnnotating&&ue&&it(ys,{inFlightSelectorColors:ue,animated:!1}),e.activeTool==="hand"&&e.isAnnotating&&(tt?At.current.element:xt)&&it(Cs,{element:tt?At.current.element:xt,gap:tt?{row:tt.row,column:tt.column}:Yo(xt),accentColor:e.activeColor,hoveredAxis:ft,draggingAxis:tt?.axis??null,cursorViewport:xn,isAutoGap:on,refreshKey:no}),e.activeTool==="hand"&&e.isAnnotating&&qe&&it($l,{element:qe.target,modifier:qe.modifier,accentColor:e.activeColor,refreshKey:no}),e.activeTool==="hand"&&e.isAnnotating&&!qe&&(Xe?fn.current.element:U)&&it(hl,{element:Xe?fn.current.element:U,radius:Xe?.radius??Vo(U),accentColor:e.activeColor,hoveredCorner:He,draggingCorner:Xe?.corner??null,cursorViewport:xn}),e.activeTool==="hand"&&e.isAnnotating&&!qe&&(Wt?St.current.element:$t)&&it(Wl,{element:Wt?St.current.element:$t,fontSize:Wt?.fontSize??Fr($t).fontSize,lineHeight:Wt?.lineHeight??Fr($t).lineHeight,accentColor:e.activeColor,hoveredProperty:rn,draggingProperty:Wt?.property??null,cursorViewport:xn}),e.activeTool==="hand"&&e.isAnnotating&&!qe&&(Re?Lt.current.element:yt)&&it(Rs,{element:Re?Lt.current.element:yt,padding:Re?.padding??wr(yt),accentColor:e.activeColor,hoveredSide:te,draggingSide:Re?.side??null,cursorViewport:xn,refreshKey:Wt?Wt.fontSize+Wt.lineHeight*1e3:0}),e.activeTool==="inspector"&&e.isAnnotating&&it(Lr,{children:Z&&!e.inspectedElement&&(()=>{let f=L?.linkedSelector||_?.linkedSelector;if(f)try{if(Z.matches(f))return null}catch{}let b=!!_||!!L?.linkedSelector||z.some(R=>{if(!R.linkedSelector)return!1;try{return Z.matches(R.linkedSelector)}catch{return!1}});return it(so,{element:Z,isSelected:!1,elementInfo:Je,color:e.activeColor,hideTooltip:b})})()}),(L?.linkedSelector||_?.linkedSelector)&&(()=>{let f=L?.linkedSelector||_?.linkedSelector;if(!f)return null;let b=null;try{b=document.querySelector(f)}catch{}return b?it(so,{element:b,isSelected:!0,color:e.activeColor,hideTooltip:!0}):null})(),F&&(()=>{let f=e.annotations.find(m=>m.id===F);if(!f?.linkedSelector)return null;let b=null;try{b=document.querySelector(f.linkedSelector)}catch{}if(!b)return null;let R=!!(o&&o.has(f.id));return it(so,{element:b,isSelected:!R,color:f.color,hideTooltip:!0})})(),ke&&(()=>{let f=e.annotations.find(k=>k.id===ke);if(!f?.linkedSelector)return null;let b=null;try{b=document.querySelector(f.linkedSelector)}catch{}if(!b)return null;let R=f.groupId?e.annotations.filter(k=>k.groupId===f.groupId):[f],m=!!(o&&R.some(k=>o.has(k.id)));return it(so,{element:b,isSelected:!m,color:f.color,hideTooltip:!0})})(),ot&&(()=>{let f=null;try{f=document.querySelector(ot)}catch{}if(!f)return null;let b=!!(s&&s.has(ot));return it(so,{element:f,isSelected:!b,color:e.activeColor,hideTooltip:!0})})(),e.activeTool==="model"&&e.isAnnotating&&Qe.size>0&&[...Qe.entries()].map(([f,b])=>it(so,{element:b.rootElement,isSelected:!0,elementInfo:{selector:"",tagName:b.rootElement.tagName.toLowerCase(),reactComponent:f},color:"#8b5cf6"},f)),e.activeTool==="model"&&e.isAnnotating&&Nn&&it(so,{element:Nn.rootElement,isSelected:!0,elementInfo:{selector:"",tagName:Nn.rootElement.tagName.toLowerCase(),reactComponent:Nn.name},color:"#22c55e"}),e.activeTool==="model"&&e.isAnnotating&&Mo.length>0&&Mo.map((f,b)=>it("div",{style:{position:"absolute",left:f.x,top:f.y,width:f.width,height:f.height,backgroundColor:"rgba(255, 0, 0, 0.08)",pointerEvents:"none",zIndex:9998},children:f.direction==="vertical"?Rr(Lr,{children:[it("div",{style:{position:"absolute",left:"50%",top:0,width:6,height:1,backgroundColor:"#FF0000",transform:"translateX(-50%)"}}),it("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,backgroundColor:"#FF0000",transform:"translateX(-50%)"}}),it("div",{style:{position:"absolute",left:"50%",bottom:0,width:6,height:1,backgroundColor:"#FF0000",transform:"translateX(-50%)"}}),it("div",{style:{position:"absolute",left:"calc(50% + 6px)",top:f.height<16?-6:"50%",transform:f.height<16?"none":"translateY(-50%)",fontSize:11,fontWeight:600,color:"#fff",backgroundColor:"#FF0000",padding:"2px 4px",whiteSpace:"nowrap",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1},children:Math.round(f.height)})]}):Rr(Lr,{children:[it("div",{style:{position:"absolute",left:0,top:"50%",width:1,height:6,backgroundColor:"#FF0000",transform:"translateY(-50%)"}}),it("div",{style:{position:"absolute",left:0,right:0,top:"50%",height:1,backgroundColor:"#FF0000",transform:"translateY(-50%)"}}),it("div",{style:{position:"absolute",right:0,top:"50%",width:1,height:6,backgroundColor:"#FF0000",transform:"translateY(-50%)"}}),it("div",{style:{position:"absolute",left:f.width<30?0:"50%",top:(f.width<30,void 0),bottom:"calc(50% + 4px)",transform:f.width<30?"none":"translateX(-50%)",fontSize:11,fontWeight:600,color:"#fff",backgroundColor:"#FF0000",padding:"2px 4px",whiteSpace:"nowrap",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1},children:Math.round(f.width)})]})},b)),e.activeTool==="model"&&e.isAnnotating&&Ee&&it(so,{element:Ee.rootElement,isSelected:!1,elementInfo:{selector:"",tagName:Ee.rootElement.tagName.toLowerCase(),reactComponent:Ee.name},color:h?.has(Ee.name)?"#22c55e":"#8b5cf6"}),e.activeTool==="hand"&&e.isAnnotating&&e.inspectedElement&&Rr(Lr,{children:[Pe&&Pe!=="padding"&&Pe!=="gap"&&(()=>{let f=new Set(z.map(B=>B.groupId||B.id)).size,b=e.inspectedElement.info.selector,R=e.styleModifications.findIndex(B=>B.selector===b),m=R>=0?f+R+1:f+e.styleModifications.length+1,k=e.styleModifications.find(B=>B.selector===b),E=k?.changes.length??0,$=!!k?.captured;return it(so,{element:e.inspectedElement.el,isSelected:!0,elementInfo:e.inspectedElement.info,color:$?"#999999":e.activeColor,annotationNumber:m,changeCount:E})})(),Pe==="padding"&&it(Rs,{element:e.inspectedElement.el,padding:wr(e.inspectedElement.el),accentColor:e.activeColor,hoveredSide:null,draggingSide:null}),Pe==="gap"&&it(Cs,{element:e.inspectedElement.el,gap:Yo(e.inspectedElement.el),accentColor:e.activeColor,hoveredAxis:null,draggingAxis:null}),it(Fl,{element:e.inspectedElement.el,elementInfo:e.inspectedElement.info,selector:e.inspectedElement.info.selector,styleModifications:e.styleModifications,dispatch:t,onClose:()=>t({type:"SELECT_ELEMENT",payload:null}),onHover:et,accentColor:e.activeColor,toolbarRef:D})]})]})}import{useCallback as _n,useEffect as an,useMemo as tr,useRef as Rt,useState as nr}from"react";import{Check as Jf,Circle as Yf,Component as Vf,Fingerprint as Uf,Hand as Kf,MessageCircle as Xf,Pen as qf,RefreshCw as Zf,Slash as Qf,Square as eg,Trash2 as tg,Type as ng}from"lucide-react";import{useEffect as Yl,useRef as Vl}from"react";function Ul(e,t,n,o,r){let i=Vl(0),s=Vl(t.annotations);Yl(()=>{if(!n.current||!e)return;s.current=t.annotations;let a=t.annotations.length;a>0&&(a>=i.current||!o)&&(localStorage.setItem(r.annotations,JSON.stringify(t.annotations)),i.current=a)},[t.annotations,e,o,n,r]),Yl(()=>{n.current&&(localStorage.setItem(r.expanded,String(e)),e&&(localStorage.setItem(r.styleMods,JSON.stringify(t.styleModifications)),localStorage.setItem(r.spacingChanges,JSON.stringify(t.spacingTokenChanges)),localStorage.setItem(r.tool,t.activeTool),localStorage.setItem(r.color,t.activeColor),localStorage.setItem(r.stroke,String(t.strokeWidth)),t.inspectedElement?localStorage.setItem(r.inspected,JSON.stringify({selector:t.inspectedElement.info.selector,info:t.inspectedElement.info})):localStorage.removeItem(r.inspected)))},[e,t.styleModifications,t.spacingTokenChanges,t.activeTool,t.activeColor,t.strokeWidth,t.inspectedElement,n,r])}import{useCallback as bn,useEffect as Zo,useMemo as Gs,useRef as Gr,useState as lo}from"react";import{Fragment as Jp,jsx as kt,jsxs as Zn}from"react/jsx-runtime";var kp={width:340,backgroundColor:"#eaeaea",...Po,boxSizing:"content-box",zIndex:10001,display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12,color:"#1f2937",padding:12,pointerEvents:"auto"},Tp=(e,t)=>({width:"100%",border:"1px solid rgba(0,0,0,0.12)",background:t?"rgba(0,0,0,0.04)":"rgba(0,0,0,0.02)",cursor:e?"default":"pointer",fontFamily:"inherit",fontSize:11,fontWeight:600,padding:"5px 8px",color:e?"#9ca3af":"#6b7280"}),Mp=e=>({border:0,background:"transparent",color:e?"#111827":"#6b7280",cursor:"pointer",fontFamily:"inherit",fontSize:10,fontWeight:700,padding:0,textTransform:"uppercase"}),Js={border:"1px solid rgba(0,0,0,0.12)",background:"rgba(0,0,0,0.02)",cursor:"pointer",fontFamily:"inherit",fontSize:10,fontWeight:650,color:"#6b7280",padding:"6px 8px",flex:1},Ri={...Js,borderColor:"#111827",background:"#111827",color:"#ffffff"},Ip={...Ri,cursor:"default",opacity:.55},Ys={display:"block",width:"100%",border:0,background:"transparent",boxSizing:"border-box",color:"inherit",cursor:"text",font:"inherit",lineHeight:1.25,margin:0,padding:0,textAlign:"left"},Rp={...Ys,appearance:"none",resize:"none",overflow:"hidden",outline:"none"},Zl={...Ys,fontWeight:700,fontSize:11,lineHeight:1.35},Lp={...Zl,appearance:"none",resize:"none",overflow:"hidden",outline:"none"},Kl={display:"grid",gridTemplateColumns:"12px minmax(0, 1fr)",columnGap:4,alignItems:"start",marginBottom:5},Ap={pass:"#2f855a",fail:"#c53030",needs_review:"#6b7280"},Pp={pass:"\u2611",fail:"\u2612",needs_review:"\u25A1"},Dp=e=>e?e.charAt(0).toUpperCase()+e.slice(1):"Eval",Op=[{id:"pending",label:"Pending"},{id:"approved",label:"Approved"},{id:"rejected",label:"Rejected"}],Xl="popmelt-eval-active-status",Bp=e=>e==="pending"||e==="approved"||e==="rejected";function Ql({bridgeUrl:e,refreshKey:t,onMouseEnter:n,onMouseLeave:o,onSynthesize:r,isSynthesizing:i,onRunEval:s,onViewRunThread:a,runningEvalIds:l=[],snapPosition:p="bottom-right"}){let c=Gr(null),u=i||!r,[d,g]=lo({version:1,updatedAt:0,cases:[]}),[x,h]=lo(!0),[I,O]=lo(()=>{if(typeof window>"u")return"pending";try{let S=window.localStorage.getItem(Xl);return Bp(S)?S:"pending"}catch{return"pending"}});Zo(()=>{let S=c.current;if(!S)return;let A=n,y=o;return A&&S.addEventListener("mouseenter",A),y&&S.addEventListener("mouseleave",y),()=>{A&&S.removeEventListener("mouseenter",A),y&&S.removeEventListener("mouseleave",y)}},[n,o]);let P=bn(()=>{e&&(h(!0),ba(e).then(S=>{g(S),h(!1)}).catch(()=>h(!1)))},[e]);Zo(()=>{P()},[P,t]),Zo(()=>{try{window.localStorage.setItem(Xl,I)}catch{}},[I]);let F=bn((S,A)=>{e&&(g(y=>({...y,cases:y.cases.map(T=>T.id===S?{...T,status:A}:T)})),va(S,A,e).then(y=>{y||P()}).catch(P))},[e,P]),M=bn((S,A)=>{if(!e)return;let y=A.map(T=>T.trim()).filter(Boolean);y.length!==0&&(g(T=>({...T,cases:T.cases.map(L=>L.id===S?{...L,assertions:y}:L)})),qr(S,{assertions:y},e).then(T=>{T||P()}).catch(P))},[e,P]),D=bn((S,A)=>{if(!e)return;let y=A.trim();y&&(g(T=>({...T,cases:T.cases.map(L=>L.id===S?{...L,title:y}:L)})),qr(S,{title:y},e).then(T=>{T||P()}).catch(P))},[e,P]),J=Gs(()=>{let S=d.cases.filter(T=>T.status==="pending"),A=d.cases.filter(T=>T.status==="approved"),y=d.cases.filter(T=>T.status==="rejected");return{pending:S,approved:A,rejected:y}},[d.cases]),ee=J[I],C=Gs(()=>{let S=new Map,A=[...d.runs??[]].sort((y,T)=>T.completedAt-y.completedAt);for(let y of A)S.has(y.evalId)||S.set(y.evalId,y);return S},[d.runs]);return Zn("div",{ref:c,style:{...kp,...ii(p)},children:[Zn("div",{style:{display:"flex",alignItems:"center",gap:6,fontWeight:700,fontSize:13,marginBottom:6},children:[kt("span",{children:"Evals"}),kt("code",{style:{fontSize:10,fontWeight:500,backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",color:"#6b7280"},children:"E"})]}),kt("button",{type:"button",disabled:u,onClick:r,style:Tp(u,i),children:i?"Synthesizing...":"Synthesize"}),kt("div",{style:{display:"flex",gap:12,marginTop:8},children:Op.map(S=>kt(Fp,{active:I===S.id,label:`${S.label} ${J[S.id].length}`,onClick:()=>O(S.id)},S.id))}),kt("div",{style:{marginTop:10,flex:1,minHeight:0,overflowY:"auto",display:"flex",flexDirection:"column",gap:10},children:x?kt("div",{style:{color:"#9ca3af",fontSize:11},children:"Loading..."}):d.cases.length===0?kt("div",{style:{color:"#9ca3af",fontSize:11,lineHeight:1.5},children:"No inferred evals yet."}):ee.length===0?Zn("div",{style:{color:"#9ca3af",fontSize:11,lineHeight:1.5},children:["No ",I," evals."]}):kt(Hp,{cases:ee,latestRunsByEvalId:C,runningEvalIds:l,onStatus:F,onRun:s,onViewRunThread:a,onTitleChange:D,onAssertionsChange:M})})]})}function Hp({cases:e,latestRunsByEvalId:t,runningEvalIds:n,onStatus:o,onRun:r,onViewRunThread:i,onTitleChange:s,onAssertionsChange:a}){return kt("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.map(l=>{let p=new Set([...l.sourceDecisionIds,...l.sourceThreadIds]).size,c=p>0?`, ${p} ${p===1?"mention":"mentions"}`:"",u=t.get(l.id),d=n.includes(l.id);return Zn("div",{style:{border:"1px solid rgba(0,0,0,0.08)",background:"rgba(255,255,255,0.35)",padding:8},children:[Zn("div",{children:[kt(zp,{value:l.title,onCommit:g=>s(l.id,g)}),Zn("div",{style:{color:"#9ca3af",fontSize:10,marginTop:2},children:[Dp(l.category),c]})]}),kt("div",{style:{marginTop:6,color:"#374151",fontSize:11,lineHeight:1.25},children:kt(Gp,{assertions:l.assertions,latestRun:u,onChange:g=>a(l.id,g)})}),kt(Np,{item:l,latestRun:u,isRunning:d,onStatus:o,onRun:r,onViewRunThread:i})]},l.id)})})}function _p(e){let t=e.assertionResults.length;if(t===0)return e.status==="pass"?"Pass":"Review";let n=e.assertionResults.reduce((r,i)=>(r[i.status]+=1,r),{pass:0,fail:0,needs_review:0}),o=n.fail+n.needs_review;return o===0?`${n.pass||t} Pass`:`Review ${o||t}`}function Np({item:e,latestRun:t,isRunning:n,onStatus:o,onRun:r,onViewRunThread:i}){if(e.status==="pending")return Zn("div",{style:{display:"flex",gap:6,marginTop:8},children:[kt("button",{type:"button",style:Js,onClick:()=>o(e.id,"rejected"),children:"Reject"}),kt("button",{type:"button",style:Ri,onClick:()=>o(e.id,"approved"),children:"Accept"})]});if(e.status==="approved"){let s=n||!r;return Zn("div",{style:{display:"flex",gap:6,marginTop:8},children:[t?.threadId&&i&&kt("button",{type:"button",style:Js,onClick:()=>i(t.threadId),children:_p(t)}),kt("button",{type:"button",disabled:s,style:s?Ip:Ri,onClick:()=>r?.(e),children:n?"Running...":"Run"})]})}return kt("div",{style:{display:"flex",gap:6,marginTop:8},children:kt("button",{type:"button",style:Ri,onClick:()=>o(e.id,"approved"),children:"Approve"})})}function Fp({active:e,label:t,onClick:n}){let[o,r]=lo(!1);return kt("button",{type:"button",style:Mp(e||o),onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),onClick:n,children:t})}function zp({value:e,onCommit:t}){let[n,o]=lo(!1),[r,i]=lo(e),s=Gr(null);Zo(()=>{n||i(e)},[n,e]),Zo(()=>{if(!n)return;let c=s.current;c&&(c.focus(),c.select(),c.style.height="auto",c.style.height=`${c.scrollHeight}px`)},[n]);let a=bn(()=>{let c=r.trim();o(!1),c&&c!==e?t(c):i(e)},[r,t,e]),l=bn(()=>{i(e),o(!1)},[e]),p=bn(c=>{c.key==="Enter"?(c.preventDefault(),a()):c.key==="Escape"&&(c.preventDefault(),l())},[l,a]);return n?kt("textarea",{ref:s,rows:1,value:r,onChange:c=>{i(c.target.value),c.currentTarget.style.height="auto",c.currentTarget.style.height=`${c.currentTarget.scrollHeight}px`},onBlur:a,onKeyDown:p,style:Lp}):kt("button",{type:"button",onClick:()=>o(!0),style:Zl,children:e})}function $p(e){return e.map(t=>t.trim()).filter(Boolean)}function Wp(e,t){return e.length===t.length&&e.every((n,o)=>n===t[o])}function ql(e){e.style.height="auto",e.style.height=`${e.scrollHeight}px`}function jp(e){let t=window.getComputedStyle(e),n=Number.parseFloat(t.lineHeight)||Number.parseFloat(t.fontSize)*1.2||16,o=document.createElement("div"),r=document.createElement("span"),i=document.createElement("span");o.style.position="fixed",o.style.visibility="hidden",o.style.pointerEvents="none",o.style.left="-9999px",o.style.top="0",o.style.width=`${e.clientWidth}px`,o.style.boxSizing=t.boxSizing,o.style.font=t.font,o.style.letterSpacing=t.letterSpacing,o.style.lineHeight=t.lineHeight,o.style.padding=t.padding,o.style.border=t.border,o.style.whiteSpace="pre-wrap",o.style.overflowWrap="break-word",o.style.wordBreak=t.wordBreak;let s=e.selectionStart??0;o.textContent=e.value.slice(0,s),r.textContent="\u200B",o.appendChild(r),o.appendChild(document.createTextNode(e.value.slice(s)||"\u200B")),i.textContent="\u200B",o.appendChild(i),document.body.appendChild(o);let a=Math.max(0,Math.round(r.offsetTop/n)),l=Math.max(0,Math.round(i.offsetTop/n));return o.remove(),{lineIndex:a,lastLineIndex:l}}function Gp({assertions:e,latestRun:t,onChange:n}){let[o,r]=lo(null),[i,s]=lo(e),[a,l]=lo(null),[p,c]=lo(0),u=Gr([]),d=Gr(null),g=Gr(!1),x=o!==null,h=x?i.length+1:i.length,I=Gs(()=>{let A=new Map;for(let y of t?.assertionResults??[])A.set(y.assertion.trim(),y);return A},[t]);Zo(()=>{x||s(e)},[e,x]),Zo(()=>{if(a===null)return;let A=requestAnimationFrame(()=>{let y=u.current[a];if(y){if(y.focus(),d.current==="select"&&y.value)y.select();else if(d.current==="start")y.setSelectionRange(0,0);else if(d.current==="end"){let T=y.value.length;y.setSelectionRange(T,T)}d.current=null,ql(y)}});return()=>cancelAnimationFrame(A)},[a,p,h]);let O=bn((A,y=null)=>{d.current=y,r(A),l(A),c(T=>T+1)},[]),P=bn(A=>{let y=$p(A);return y.length===0?(s(e),e):(s(y),Wp(y,e)||n(y),y)},[e,n]),F=bn(A=>{O(A,"select")},[O]),M=bn((A,y)=>{s(T=>{let L=[...T];if(A>=L.length){if(y.length===0)return L;L.push(y)}else L[A]=y;return L})},[]),D=bn((A,y)=>{let T=[...i],ce=(A<T.length?T[A]??"":"").trim();if(A>=T.length){let j=y?.focusPlaceholder?T.length:y?.focusIndex;j!==void 0?O(j,y?.focusMode):(r(null),l(null));return}if(!ce){if(y?.deleteEmpty){T.splice(A,1);let j=P(T),se=y.focusPlaceholder?j.length:y.focusIndex;if(se!==void 0){let _=Math.min(se,j.length);O(_)}else r(null),l(null)}else T[A]=e[A]??"",s(T),y?.focusIndex!==void 0?O(y.focusIndex,y.focusMode):(r(null),l(null));return}T[A]=ce;let We=P(T),be=y?.focusPlaceholder?We.length:y?.focusIndex;if(be!==void 0){let j=Math.min(be,We.length);O(j,y?.focusMode)}else r(null),l(null)},[e,i,P,O]),J=bn(()=>{s(e),r(null),l(null)},[e]),ee=bn((A,y)=>{let T=y.currentTarget.value,L=y.currentTarget.selectionStart,ce=y.currentTarget.selectionEnd,We=L===ce;if((y.key==="ArrowUp"||y.key==="ArrowDown")&&We){let{lineIndex:be,lastLineIndex:j}=jp(y.currentTarget);if(y.key==="ArrowUp"&&be===0&&A>0){y.preventDefault(),g.current=!0,D(A,{focusIndex:A-1,focusMode:"end",deleteEmpty:!1});return}if(y.key==="ArrowDown"&&be===j&&A<h-1){y.preventDefault(),g.current=!0,D(A,{focusIndex:A+1,focusMode:"start",deleteEmpty:!1});return}}if(y.key==="Backspace"&&T.length===0){y.preventDefault(),g.current=!0;let be=[...i],j=A-1;if(A<be.length){be.splice(A,1);let se=P(be);if(j>=0){let _=Math.min(j,se.length-1);O(_,"end")}else r(null),l(null)}else j>=0&&O(j,"end");return}y.key==="Enter"?(y.preventDefault(),D(A,{focusPlaceholder:y.metaKey||y.ctrlKey,deleteEmpty:!0})):y.key==="Escape"&&(y.preventDefault(),J())},[J,D,i,P,O,h]),C=bn((A,y)=>{if(g.current){g.current=!1;return}let T=u.current.findIndex(L=>L===y.relatedTarget);D(A,{deleteEmpty:!1,focusIndex:T>=0?T:void 0})},[D]),S=bn((A,y)=>{y.preventDefault(),o!==null?(g.current=!0,D(o,{focusIndex:A,focusMode:"select",deleteEmpty:!1})):O(A,"select")},[D,o,O]);return Zn(Jp,{children:[kt("style",{children:`
2
+ import{createContext as th,useCallback as zt,useContext as nh,useEffect as It,useMemo as po,useRef as nn,useState as St}from"react";import{useCallback as Va,useEffect as gd,useSyncExternalStore as md}from"react";var bn="http://localhost:1111";function dd(){return typeof window<"u"?window.__POPMELT_PROJECT_ID__??null:null}function ud(e={}){let t=dd();if(!t)return e;let n=new Headers(e.headers);return n.set("X-Popmelt-Project-Id",t),{...e,headers:n}}function Ro(e,t={}){return fetch(e,ud(t))}function In(e,t={},n=15e3){let o=new AbortController;t.signal&&t.signal.addEventListener("abort",()=>o.abort());let r=setTimeout(()=>o.abort(),n);return Ro(e,{...t,signal:o.signal}).finally(()=>clearTimeout(r))}async function Da(e=bn){try{let t=await In(`${e}/capabilities`,{},5e3);return t.ok?await t.json():null}catch{return null}}async function Lo(e=bn){try{let t=new AbortController,n=setTimeout(()=>t.abort(),2e3),o=await Ro(`${e}/status`,{signal:t.signal});return clearTimeout(n),o.ok?await o.json():null}catch{return null}}async function Ba(e){try{let t=new AbortController,n=setTimeout(()=>t.abort(),500),o=await Ro(`http://localhost:${e}/status`,{signal:t.signal});return clearTimeout(n),o.ok?await o.json():null}catch{return null}}async function pd(e){return Lo(e)}async function Oa(e,t){if(e&&e!=="http://localhost:1111")try{let c=new URL(e),p=await pd(e);if(!p&&!t)return null;if(!(!p&&t)){if(!(p&&t&&p.projectId!==t)){if(p?.projectId&&!t)return null;if(p)return{url:e,port:parseInt(c.port,10)||1111,projectId:p.projectId}}}}catch{if(!t)return null}let i=typeof window<"u"?window.location.origin:null,s=await Ba(1111);if(s){if(t&&s.projectId===t)return{url:"http://localhost:1111",port:1111,projectId:s.projectId};if(s.devOrigin&&i&&s.devOrigin===i&&(t||!s.projectId))return{url:"http://localhost:1111",port:1111,projectId:s.projectId}}let a=Array.from({length:8},(c,p)=>{let u=1112+p;return Ba(u).then(m=>m?{status:m,port:u}:null)}),l=(await Promise.all(a)).filter(c=>c!==null),d=[];s&&d.push({port:1111,devOrigin:s.devOrigin,projectId:s.projectId});for(let c of l)d.push({port:c.port,devOrigin:c.status.devOrigin,projectId:c.status.projectId});if(t){let c=d.find(p=>p.projectId===t);if(c)return{url:`http://localhost:${c.port}`,port:c.port,projectId:c.projectId}}if(i){let c=d.find(p=>p.devOrigin===i&&(t||!p.projectId));if(c)return{url:`http://localhost:${c.port}`,port:c.port,projectId:c.projectId}}return d.length===1&&!d[0].projectId?{url:`http://localhost:${d[0].port}`,port:d[0].port,projectId:d[0].projectId}:null}async function bi(e=bn,t,n=-1){try{let o=await In(`${e}/jobs/${t}/events?afterSeq=${n}`,{},5e3);return o.ok?await o.json():null}catch{return null}}async function _a(e,t,n=bn,o,r,i,s,a){let l=new FormData;if(e instanceof Map){let c=!0;for(let[p,u]of e){let m=encodeURIComponent(p);l.append(`screenshot-${m}`,u,`screenshot-${m}.webp`),c&&(l.append("screenshot",u,"screenshot.webp"),c=!1)}c&&l.append("screenshot",new Blob([],{type:"image/webp"}),"screenshot.webp")}else l.append("screenshot",e,"screenshot.webp");if(l.append("feedback",t),o&&l.append("color",o),r&&l.append("provider",r),i&&l.append("model",i),a&&l.append("sourceId",a),s)for(let[c,p]of s)for(let u=0;u<p.length;u++)l.append(`image-${c}-${u}`,p[u],`image-${c}-${u}.webp`);let d=await In(`${n}/send`,{method:"POST",body:l},3e4);if(!d.ok){let c=await d.text();throw new Error(`Bridge returned ${d.status}: ${c}`)}return d.json()}async function Ha(e,t=bn){let n=await In(`${t}/model/component`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})},1e4);if(!n.ok){let o=await n.text();throw new Error(`Bridge returned ${n.status}: ${o}`)}return n.json()}async function Na(e,t=bn){let n=await In(`${t}/model/component`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})},1e4);if(!n.ok){let o=await n.text();throw new Error(`Bridge returned ${n.status}: ${o}`)}return n.json()}async function fs(e,t,n=bn){let o=await In(`${n}/model/token`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,value:t})},1e4);if(!o.ok){let r=await o.text();throw new Error(`Bridge returned ${o.status}: ${r}`)}return o.json()}async function Fa(e,t=bn){let n=await In(`${t}/model/token`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})},1e4);if(!n.ok){let o=await n.text();throw new Error(`Bridge returned ${n.status}: ${o}`)}return n.json()}async function Cr(e=bn){try{let t=await In(`${e}/model`,{},5e3);return t.ok?(await t.json()).model??null:null}catch{return null}}async function za(e=bn){let t=await In(`${e}/evals`,{},5e3);return t.ok?t.json():{version:1,updatedAt:0,cases:[]}}async function vi(e,t,n=bn){let o=await In(`${n}/evals/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)},5e3);return o.ok?(await o.json()).eval??null:null}function $a(e,t,n=bn){return vi(e,{status:t},n)}async function Wa(e,t,n,o=bn,r,i,s){let a=new FormData;a.append("screenshot",t,"eval-run.webp"),a.append("feedback",JSON.stringify(n)),r&&a.append("provider",r),i&&a.append("model",i),s&&a.append("sourceId",s);let l=await In(`${o}/evals/${encodeURIComponent(e)}/run`,{method:"POST",body:a},3e4);if(!l.ok){let d=await l.text();throw new Error(`Bridge returned ${l.status}: ${d}`)}return l.json()}function fd(e){return new Promise(t=>setTimeout(t,e))}async function gs(e=bn,t,n=15e3){let o=Date.now();try{let s=await In(`${e}/restart`,{method:"POST"},5e3);if(!s.ok){let a=await s.text().catch(()=>"");return{ok:!1,error:a?`Bridge restart returned ${s.status}: ${a}`:`Bridge restart returned ${s.status}`,elapsedMs:Date.now()-o}}}catch(s){return{ok:!1,error:s instanceof Error?s.message:"Bridge restart request failed",elapsedMs:Date.now()-o}}let r=null;for(;Date.now()-o<n;)if(await fd(350),r=await Lo(e),!!r?.ok&&!(t&&r.version!==t))return{ok:!0,status:r,elapsedMs:Date.now()-o};return{ok:!1,error:`Bridge did not come back${t?` with version ${t}`:""} within ${Math.round(n/1e3)}s`,status:r,elapsedMs:Date.now()-o}}async function ja(e=bn){return(await gs(e)).ok}async function Ga(e=bn,t,n){let o=await In(`${e}/model/synthesize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,model:n})},1e4);if(!o.ok){let r=await o.text();throw new Error(`Bridge returned ${o.status}: ${r}`)}return o.json()}async function Ja(e=bn,t,n){let o=await In(`${e}/evals/synthesize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,model:n})},1e4);if(!o.ok){let r=await o.text();throw new Error(`Bridge returned ${o.status}: ${r}`)}return o.json()}async function Ya(e,t,n=bn,o,r,i,s,a){let l;if(s&&s.length>0){let d=new FormData,c=new Blob([new Uint8Array([137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,1,0,0,0,1,8,6,0,0,0,31,21,196,137,0,0,0,10,73,68,65,84,120,156,98,0,0,0,2,0,1,229,39,222,252,0,0,0,0,73,69,78,68,174,66,96,130])],{type:"image/png"});d.append("screenshot",c,"screenshot.png"),d.append("feedback",JSON.stringify({threadId:e,reply:t,color:o,provider:r,model:i,sourceId:a}));for(let p=0;p<s.length;p++)d.append(`image-reply-${p}`,s[p],`reply-image-${p}.webp`);l=await In(`${n}/reply`,{method:"POST",body:d},3e4)}else l=await In(`${n}/reply`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({threadId:e,reply:t,color:o,provider:r,model:i,sourceId:a})},3e4);if(!l.ok){let d=await l.text();throw new Error(`Bridge returned ${l.status}: ${d}`)}return l.json()}var tn=globalThis.__POPMELT_BRIDGE_CONNECTION__??(globalThis.__POPMELT_BRIDGE_CONNECTION__={}),Ei=tn.sourceId??(typeof localStorage<"u"?localStorage.getItem("popmelt-source-id"):null)??(typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2));tn.sourceId=Ei;try{typeof localStorage<"u"&&localStorage.setItem("popmelt-source-id",Ei)}catch{}function Ti(){return Ei}var hd={isConnected:!1,status:"disconnected",jobResponses:{},jobThinking:{},activeJobIds:[],activeJobThreads:{},currentResponse:"",currentThinking:"",events:[],activeJobId:null,lastCompletedJobId:null,lastResponseText:null,lastThreadId:null,lastErrorByJob:{},pendingQuestions:[],incrementalResolutions:[],capabilitiesVersion:0},sr=tn.store??{...hd};tn.store=sr;var wi=tn.listeners??new Set;tn.listeners=wi;var or=tn.activeEs??null,ms=tn.activeBridgeUrl??null,rr=null,Si=tn.connectionGeneration??0,Ci=new Set,Tr=new Map,Wo={};function ir(e,t){if(!e)return!1;if(Ci.has(e)){let o=Tr.get(e);return o||(o=[],Tr.set(e,o)),o.push({type:t.type??"",data:t}),!0}let n=Wo[e];return n!==void 0&&typeof t.seq=="number"&&t.seq<=n}async function yd(e,t,n){let o=()=>n!==Si;for(let r of t){if(o())return;Ci.add(r),Tr.set(r,[])}await Promise.all(t.map(async r=>{try{let i=await bi(e,r);if(o())return;let s=Tr.get(r)??[];if(i){if(cn(a=>{let l={...a.jobResponses,[r]:i.accumulated.response},d={...a.jobThinking,[r]:i.accumulated.thinking},c=[...a.events];for(let p of i.events)p.type==="done"||p.type==="error"||c.push({type:p.type,data:p,timestamp:Date.now()});return{...a,jobResponses:l,jobThinking:d,currentResponse:r===a.activeJobId?i.accumulated.response:a.currentResponse,currentThinking:r===a.activeJobId?i.accumulated.thinking:a.currentThinking,events:c}}),Wo[r]=i.currentSeq,!i.jobActive){let a=i.events.find(l=>l.type==="done"||l.type==="error");a&&hs(a.type,a,r)}for(let a of s)typeof a.data.seq=="number"&&a.data.seq<=i.currentSeq||hs(a.type,a.data,r)}else for(let a of s)hs(a.type,a.data,r)}finally{Ci.delete(r),Tr.delete(r)}}))}function hs(e,t,n){if(e==="delta"){let o=t.text||"";cn(r=>({...r,jobResponses:{...r.jobResponses,[n]:(r.jobResponses[n]||"")+o},currentResponse:n===r.activeJobId?r.currentResponse+o:r.currentResponse,events:[...r.events,{type:"delta",data:t,timestamp:Date.now()}]}))}else if(e==="thinking"){let o=t.text||"";cn(r=>({...r,jobThinking:{...r.jobThinking,[n]:(r.jobThinking[n]||"")+o},currentThinking:n===r.activeJobId?r.currentThinking+o:r.currentThinking,events:[...r.events,{type:"thinking",data:t,timestamp:Date.now()}]}))}else if(e==="done")delete Wo[n],cn(o=>{let r=o.activeJobIds.filter(d=>d!==n),i={...o.jobResponses},s={...o.jobThinking},a=i[n];delete i[n],delete s[n];let l=n===o.activeJobId?r.length>0?r[r.length-1]:null:o.activeJobId;return{...o,activeJobIds:r,activeJobId:l,jobResponses:i,jobThinking:s,lastCompletedJobId:n,lastResponseText:a||o.currentResponse||t.responseText||null,lastThreadId:t.threadId??null,...n===o.activeJobId?{currentResponse:l&&i[l]||"",currentThinking:l&&s[l]||""}:{},events:[...o.events,{type:"done",data:t,timestamp:Date.now()}]}});else if(e==="error"){delete Wo[n];let o=t.message??"";cn(r=>{let i=r.activeJobIds.filter(a=>a!==n),s=i.length>0?r.status:"error";return{...r,status:s,activeJobIds:i,lastCompletedJobId:n,lastErrorByJob:o?{...r.lastErrorByJob,[n]:o}:r.lastErrorByJob,events:[...r.events,{type:"error",data:t,timestamp:Date.now()}]}})}else cn(o=>({...o,events:[...o.events,{type:e,data:t,timestamp:Date.now()}]}))}var mo=tn.discoveredBridgeUrl??null,so=tn.discoveredBridgeProjectId??null,Er=null,xi=null;async function bd(e,t){return mo&&(t?so===t:!so)?mo:(!t&&so&&(mo=null,so=null,tn.discoveredBridgeUrl=mo,tn.discoveredBridgeProjectId=so),t&&so&&so!==t&&(mo=null,so=null,tn.discoveredBridgeUrl=mo,tn.discoveredBridgeProjectId=so),Er&&xi===(t??null)||(xi=t??null,Er=Oa(e,t).then(n=>(mo=n?.url??null,so=n?.projectId??t??null,tn.discoveredBridgeUrl=mo,tn.discoveredBridgeProjectId=so,Er=null,xi=null,mo)).catch(()=>(Er=null,xi=null,null))),Er)}function Ka(){return mo}function Ua(){return sr}function vd(e){return wi.add(e),()=>{wi.delete(e)}}function cn(e){sr=e(sr),tn.store=sr;for(let t of wi)t()}function xd(){return typeof window<"u"?window.__POPMELT_PROJECT_ID__??null:null}function Xa(e){if(or&&or.readyState!==EventSource.CLOSED&&ms===e)return;or&&(or.close(),or=null,tn.activeEs=null),rr&&(clearTimeout(rr),rr=null),ms=e,tn.activeBridgeUrl=ms;let t=++Si;tn.connectionGeneration=Si;let n=new URLSearchParams({sourceId:Ei}),o=xd();o&&n.set("projectId",o);let r=new EventSource(`${e}/events?${n.toString()}`);or=r,tn.activeEs=or;let i=()=>t!==Si;r.addEventListener("connected",()=>{i()||Lo(e).then(s=>{if(i())return;let a=s?.activeJobs??(s?.activeJob?[s.activeJob]:[]),l=new Set(a.map(v=>v.id)),d=s?.recentJobs??[],c=new Map(d.map(v=>[v.id,v])),p=a.length>0;cn(v=>{let b={...v.lastErrorByJob},I=v.activeJobIds.filter(C=>!l.has(C));for(let C of I){let k=c.get(C);k?.status==="error"&&k.error&&(b[C]=k.error)}let P=v.activeJobIds.filter(C=>l.has(C));for(let C of l)P.includes(C)||P.push(C);let N={};for(let C of a)C.threadId&&(N[C.id]=C.threadId);return{...v,isConnected:!0,status:p?"streaming":I.length>0||v.status==="disconnected"?"idle":v.status,activeJobId:p?a[a.length-1].id:P.length>0?P[P.length-1]:null,activeJobIds:P,activeJobThreads:N,lastErrorByJob:b,lastCompletedJobId:I.length>0?I[I.length-1]:v.lastCompletedJobId}});let u=sr.activeJobIds.filter(v=>!l.has(v)),m=[...Array.from(l),...u];m.length>0&&yd(e,m,t).catch(()=>{})})}),r.addEventListener("job_started",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;if(ir(l,a))return;let d=a.threadId;cn(c=>({...c,status:"streaming",activeJobId:l,activeJobIds:c.activeJobIds.includes(l)?c.activeJobIds:[...c.activeJobIds,l],activeJobThreads:d?{...c.activeJobThreads,[l]:d}:c.activeJobThreads,jobResponses:{...c.jobResponses,[l]:c.jobResponses[l]??""},jobThinking:{...c.jobThinking,[l]:c.jobThinking[l]??""},currentResponse:c.jobResponses[l]??"",currentThinking:c.jobThinking[l]??"",lastResponseText:null,lastThreadId:null,events:[...c.events,{type:"job_started",data:a,timestamp:Date.now()}]}))}),r.addEventListener("delta",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;if(ir(l,a))return;let d=a.text||"";cn(c=>({...c,jobResponses:l?{...c.jobResponses,[l]:(c.jobResponses[l]||"")+d}:c.jobResponses,currentResponse:!l||l===c.activeJobId?c.currentResponse+d:c.currentResponse,events:[...c.events,{type:"delta",data:a,timestamp:Date.now()}]}))}),r.addEventListener("thinking",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;if(ir(l,a))return;let d=a.text||"";cn(c=>({...c,jobThinking:l?{...c.jobThinking,[l]:(c.jobThinking[l]||"")+d}:c.jobThinking,currentThinking:!l||l===c.activeJobId?c.currentThinking+d:c.currentThinking,events:[...c.events,{type:"thinking",data:a,timestamp:Date.now()}]}))}),r.addEventListener("tool_use",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;ir(l,a)||cn(d=>({...d,events:[...d.events,{type:"tool_use",data:a,timestamp:Date.now()}]}))}),r.addEventListener("done",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;ir(l,a)||(l&&delete Wo[l],cn(d=>{let c=l?d.activeJobIds.filter(I=>I!==l):d.activeJobIds,p={...d.jobResponses},u={...d.jobThinking},m={...d.activeJobThreads},v=l?p[l]:void 0;l&&(delete p[l],delete u[l],delete m[l]);let b=l===d.activeJobId?c.length>0?c[c.length-1]:null:d.activeJobId;return{...d,activeJobIds:c,activeJobId:b,jobResponses:p,jobThinking:u,lastCompletedJobId:l??d.activeJobId,lastResponseText:v||d.currentResponse||a.responseText||null,lastThreadId:a.threadId??null,...l===d.activeJobId?{currentResponse:b&&p[b]||"",currentThinking:b&&u[b]||""}:{},events:[...d.events,{type:"done",data:a,timestamp:Date.now()}]}}))}),r.addEventListener("question",s=>{if(i())return;let a=JSON.parse(s.data),l=a.jobId;ir(l,a)||cn(d=>({...d,pendingQuestions:[...d.pendingQuestions,{jobId:a.jobId,threadId:a.threadId,question:a.question,annotationIds:a.annotationIds,timestamp:Date.now()}],events:[...d.events,{type:"question",data:a,timestamp:Date.now()}]}))}),r.addEventListener("capabilities_changed",()=>{i()||cn(s=>({...s,capabilitiesVersion:s.capabilitiesVersion+1}))}),r.addEventListener("queue_drained",()=>{if(!i()){for(let s of Object.keys(Wo))delete Wo[s];Ci.clear(),Tr.clear(),cn(s=>({...s,status:s.status==="error"?"error":"idle",activeJobId:null,activeJobIds:[],activeJobThreads:{},currentResponse:"",currentThinking:"",jobResponses:{},jobThinking:{},lastErrorByJob:{},incrementalResolutions:[]}))}}),r.addEventListener("error",s=>{if(!i()){if(r.readyState===EventSource.CLOSED)cn(a=>({...a,isConnected:!1,status:"disconnected"})),rr&&(clearTimeout(rr),rr=null),rr=setTimeout(()=>{Lo(e).then(a=>{a&&Xa(e)})},5e3);else if(s instanceof MessageEvent){let a=JSON.parse(s.data),l=a.jobId??null;if(ir(l??void 0,a))return;l&&delete Wo[l];let d=a.message??"";cn(c=>{let p=l?c.activeJobIds.filter(m=>m!==l):c.activeJobIds,u=p.length>0?c.status:"error";return{...c,status:u,activeJobIds:p,lastCompletedJobId:l??c.activeJobId,lastErrorByJob:l&&d?{...c.lastErrorByJob,[l]:d}:c.lastErrorByJob,events:[...c.events,{type:"error",data:a,timestamp:Date.now()}]}})}}}),r.onerror=()=>{i()||r.readyState===EventSource.CLOSED&&cn(s=>({...s,isConnected:!1,status:"disconnected"}))}}function qa(e="http://localhost:1111",t=!0,n){let o=md(vd,Ua,Ua);gd(()=>{t&&bd(e,n).then(s=>{s&&Lo(s).then(a=>{a&&Xa(s)})})},[e,t,n]);let r=Va(()=>{cn(()=>({...sr,events:[],currentResponse:"",currentThinking:"",jobResponses:{},jobThinking:{},lastResponseText:null,lastThreadId:null,lastErrorByJob:{},incrementalResolutions:[]}))},[]),i=Va(s=>{cn(a=>({...a,pendingQuestions:a.pendingQuestions.filter(l=>l.threadId!==s)}))},[]);return{...o,clearEvents:r,dismissQuestion:i}}import{useEffect as Sd,useReducer as wd}from"react";var Cd={isAnnotating:!1,activeTool:"inspector",activeColor:"oklch(0.628 0.258 29)",strokeWidth:3,annotations:[],undoStack:[],redoStack:[],currentPath:[],selectedAnnotationIds:[],lastSelectedId:null,inspectedElement:null,styleModifications:[],spacingTokenChanges:[],spacingTokenMods:[]};function ki(){return Math.random().toString(36).substring(2,9)}function Za(e){return e.status?e:e.captured?{...e,status:"in_flight"}:{...e,status:"pending"}}function Bn(e){return{...e,undoStack:[...e.undoStack,{annotations:e.annotations,styleModifications:e.styleModifications,spacingTokenMods:e.spacingTokenMods}],redoStack:[]}}function Ed(e,t){return{...e,isAnnotating:t}}function Td(e,t){return{...e,activeTool:t,inspectedElement:null}}function kd(e,t){return{...e,activeColor:t}}function Md(e,t){return{...e,strokeWidth:t}}function Id(e,t){return{...e,currentPath:[t]}}function Rd(e,t){return{...e,currentPath:[...e.currentPath,t]}}function Ld(e){return{...e,currentPath:[]}}function Ad(e,t){if(e.currentPath.length<2&&e.activeTool!=="text")return{...e,currentPath:[]};let n={id:ki(),type:e.activeTool,points:e.currentPath,color:e.activeColor,strokeWidth:e.strokeWidth,timestamp:Date.now(),status:"pending",pathname:typeof window<"u"?window.location.pathname:"/",groupId:t?.groupId,elements:t?.elements};return{...Bn(e),annotations:[...e.annotations,n],currentPath:[]}}function Pd(e,t){let n={id:t.id??ki(),type:"text",points:[t.point],text:t.text,fontSize:t.fontSize||12,color:e.activeColor,strokeWidth:e.strokeWidth,timestamp:Date.now(),status:"pending",pathname:typeof window<"u"?window.location.pathname:"/",groupId:t.groupId,linkedSelector:t.linkedSelector,linkedAnchor:t.linkedAnchor,elements:t.elements,...t.imageCount?{imageCount:t.imageCount}:{}};return{...t.groupId?e:Bn(e),annotations:[...e.annotations,n]}}function Bd(e,t){return{...Bn(e),annotations:e.annotations.map(o=>o.id===t.id?{...o,text:t.text,...t.imageCount!=null?{imageCount:t.imageCount}:{}}:o)}}function Dd(e,t){return{...e,annotations:e.annotations.map(n=>n.id===t.id?{...n,fontSize:Math.max(12,Math.min(72,t.fontSize))}:n)}}function Od(e,t){let n=Bn(e),r=e.annotations.find(i=>i.id===t.id)?.groupId;return{...n,annotations:e.annotations.filter(i=>i.id!==t.id&&!(r&&i.groupId===r))}}function _d(e,t){let n=t.saveUndo?Bn(e):e,r=e.annotations.find(i=>i.id===t.id)?.groupId;return{...n,annotations:e.annotations.map(i=>{if(!(i.id===t.id||r&&i.groupId===r))return i;let a=t.delta.x,l=t.delta.y;return{...i,points:i.points.map(d=>({x:d.x+a,y:d.y+l}))}})}}function Hd(e,t){let n=t.saveUndo?Bn(e):e,o=e.annotations.find(s=>s.id===t.id);if(!o||o.type==="text"||o.points.length<2)return e;let r=0,i=0;if(o.type==="rectangle"&&o.groupId){let s=t.points,a=Math.min(s[0].x,s[1].x),l=Math.max(s[0].y,s[1].y),d=o.points[0],c=o.points[o.points.length-1],p=Math.min(d.x,c.x),u=Math.max(d.y,c.y);r=a-p,i=l-u}return{...n,annotations:e.annotations.map(s=>s.id===t.id?{...s,points:t.points}:o.groupId&&s.groupId===o.groupId&&s.type==="text"?{...s,points:s.points.map(a=>({x:a.x+r,y:a.y+i}))}:s)}}function Nd(e,t){return{...Bn(e),annotations:[...e.annotations,...t.annotations.map(Za)]}}function Fd(e,t){let n=new Set,o=[];for(let r of t.annotations)n.has(r.id)||(n.add(r.id),o.push(Za(r)));return{...e,annotations:o}}function zd(e){if(e.undoStack.length===0)return e;let t=e.undoStack[e.undoStack.length-1];return{...e,annotations:t?.annotations||[],styleModifications:t?.styleModifications||[],spacingTokenMods:t?.spacingTokenMods||[],undoStack:e.undoStack.slice(0,-1),redoStack:[...e.redoStack,{annotations:e.annotations,styleModifications:e.styleModifications,spacingTokenMods:e.spacingTokenMods}]}}function $d(e){if(e.redoStack.length===0)return e;let t=e.redoStack[e.redoStack.length-1];return{...e,annotations:t?.annotations||[],styleModifications:t?.styleModifications||[],spacingTokenMods:t?.spacingTokenMods||[],redoStack:e.redoStack.slice(0,-1),undoStack:[...e.undoStack,{annotations:e.annotations,styleModifications:e.styleModifications,spacingTokenMods:e.spacingTokenMods}]}}function Wd(e,t){let{id:n,addToSelection:o}=t;if(n===null)return{...e,selectedAnnotationIds:[],lastSelectedId:null};if(o)if(e.selectedAnnotationIds.includes(n)){let i=e.selectedAnnotationIds.filter(s=>s!==n);return{...e,selectedAnnotationIds:i,lastSelectedId:i.length>0?i[i.length-1]:null}}else return{...e,selectedAnnotationIds:[...e.selectedAnnotationIds,n],lastSelectedId:n};return{...e,selectedAnnotationIds:[n],lastSelectedId:n}}function jd(e,t){let n=new Set;for(let o of e.selectedAnnotationIds){let r=e.annotations.find(i=>i.id===o);r?.groupId&&n.add(r.groupId)}return{...e,annotations:e.annotations.map(o=>{let r=e.selectedAnnotationIds.includes(o.id),i=o.groupId&&n.has(o.groupId);return!r&&!i?o:{...o,color:t.color}})}}function Gd(e){let t=typeof window<"u"?window.location.pathname:"/";return{...e,annotations:e.annotations.map(n=>({...n,captured:!0,status:n.status==="pending"||!n.status?"in_flight":n.status})),styleModifications:e.styleModifications.map(n=>!n.pathname||n.pathname===t?{...n,captured:!0}:n),spacingTokenChanges:e.spacingTokenChanges.map(n=>({...n,captured:!0}))}}function Jd(e){return{...e,annotations:[],undoStack:[],redoStack:[],currentPath:[],selectedAnnotationIds:[],lastSelectedId:null,spacingTokenChanges:[],spacingTokenMods:[]}}function Yd(e,t){return{...e,inspectedElement:t}}function Vd(e,t){let{selector:n,element:o,property:r,original:i,modified:s}=t,a=typeof window<"u"?window.location.pathname:"/",l=e.styleModifications.findIndex(d=>d.selector===n&&(!d.pathname||d.pathname===a));if(i===s&&l<0)return e;if(l>=0){let d=e.styleModifications[l];if(d.captured){let v=Bn(e),b=v.styleModifications.map((I,P)=>P===l?{...I,changes:[{property:r,original:i,modified:s}],captured:!1,pathname:a}:I);return{...v,styleModifications:b}}let c=d.changes.findIndex(v=>v.property===r),p,u=e;if(c>=0){let v=d.changes[c];s===v.original?p=d.changes.filter((b,I)=>I!==c):p=d.changes.map((b,I)=>I===c?{...b,modified:s}:b)}else{if(i===s)return e;u=Bn(e),p=[...d.changes,{property:r,original:i,modified:s}]}if(p.length===0)return{...u,styleModifications:u.styleModifications.filter((v,b)=>b!==l)};let m=u.styleModifications.map((v,b)=>b===l?{...v,changes:p}:v);return{...u,styleModifications:m}}else{let d=Bn(e),c={selector:n,element:o,changes:[{property:r,original:i,modified:s}],pathname:a};return{...d,styleModifications:[...d.styleModifications,c]}}}function Ud(e,t){let{selector:n,durableSelector:o,element:r,changes:i}=t,s=typeof window<"u"?window.location.pathname:"/",a=i.filter(c=>c.original!==c.modified);if(a.length===0)return e;let l=Bn(e),d=l.styleModifications.findIndex(c=>c.selector===n&&(!c.pathname||c.pathname===s));if(d>=0){let c=l.styleModifications[d],p=c.captured?[]:[...c.changes];for(let u of a){let m=p.findIndex(v=>v.property===u.property);m>=0?u.modified===p[m].original?p=p.filter((v,b)=>b!==m):p=p.map((v,b)=>b===m?{...v,modified:u.modified}:v):p.push(u)}return p.length===0?{...l,styleModifications:l.styleModifications.filter((u,m)=>m!==d)}:{...l,styleModifications:l.styleModifications.map((u,m)=>m===d?{...u,changes:p,captured:!1,pathname:s}:u)}}else return{...l,styleModifications:[...l.styleModifications,{selector:n,durableSelector:o,element:r,changes:a,pathname:s}]}}function Kd(e,t){let{selector:n,property:o}=t,r=typeof window<"u"?window.location.pathname:"/",i=Bn(e),s=i.styleModifications.map(a=>a.selector!==n||a.pathname&&a.pathname!==r?a:{...a,changes:a.changes.filter(l=>l.property!==o)}).filter(a=>a.changes.length>0);return{...i,styleModifications:s}}function Xd(e){return e.styleModifications.length===0?{...e,inspectedElement:null}:{...Bn(e),styleModifications:[],inspectedElement:null}}function qd(e,t){return{...e,styleModifications:t}}function Zd(e,t){let{updates:n}=t,o=new Map(n.map(r=>[r.id,r]));return{...e,annotations:e.annotations.map(r=>{let i=o.get(r.id);return i?{...r,points:[i.point,...r.points.slice(1)],...i.linkedAnchor?{linkedAnchor:i.linkedAnchor}:{}}:r})}}function Qd(e,t){let n=new Set(t.ids);return{...e,annotations:e.annotations.map(o=>n.has(o.id)?{...o,status:t.status}:o)}}function eu(e,t){let n=new Set(t.ids),o=new Set;for(let r of e.annotations)n.has(r.id)&&r.groupId&&o.add(r.groupId);return{...e,annotations:e.annotations.map(r=>n.has(r.id)||r.groupId&&o.has(r.groupId)?{...r,threadId:t.threadId}:r)}}function tu(e,t){let n=new Set(t.ids),o=new Set;for(let r of e.annotations)n.has(r.id)&&r.groupId&&o.add(r.groupId);return{...e,annotations:e.annotations.map(r=>n.has(r.id)||r.groupId&&o.has(r.groupId)?{...r,status:"waiting_input",question:t.question,threadId:t.threadId}:r)}}function nu(e,t){let n=new Map(t.resolutions.map(r=>[r.annotationId,r])),o=new Map;for(let r of e.annotations){let i=n.get(r.id);i&&r.groupId&&o.set(r.groupId,i)}return{...e,annotations:e.annotations.map(r=>{let i=n.get(r.id)||(r.groupId?o.get(r.groupId):void 0);return i?{...r,status:i.status,resolutionSummary:i.summary,scope:i.finalScope??i.inferredScope??null,replyCount:(r.replyCount??0)+1,question:void 0,threadId:r.threadId||t.threadId}:r})}}function ou(e,t){let{linkedSelectors:n,styleSelectors:o}=t,r=new Set(n),i=new Set(o),s=typeof window<"u"?window.location.pathname:"/",a=new Set,l=new Set;for(let m of e.annotations)m.linkedSelector&&r.has(m.linkedSelector)&&(a.add(m.id),m.groupId&&l.add(m.groupId));for(let m of e.annotations)m.groupId&&l.has(m.groupId)&&a.add(m.id);let d=e.annotations.filter(m=>!a.has(m.id)),c=e.styleModifications.filter(m=>!i.has(m.selector)||m.pathname&&m.pathname!==s);if(d.length===e.annotations.length&&c.length===e.styleModifications.length)return e;let p=e.selectedAnnotationIds.filter(m=>!a.has(m)),u=e.inspectedElement&&i.has(e.inspectedElement.info.selector)?null:e.inspectedElement;return{...e,annotations:d,styleModifications:c,selectedAnnotationIds:p,lastSelectedId:p.length>0?p[p.length-1]:null,inspectedElement:u}}function ru(e,t){let n=e.spacingTokenChanges.findIndex(o=>o.tokenPath===t.tokenPath);return n>=0?{...e,spacingTokenChanges:e.spacingTokenChanges.map((o,r)=>r===n?t:o)}:{...e,spacingTokenChanges:[...e.spacingTokenChanges,t]}}function iu(e,t){return{...e,spacingTokenChanges:t}}function su(e,t){let n=Bn(e),o=e.spacingTokenMods.findIndex(i=>i.tokenPath===t.tokenPath),r;if(o>=0){let i=e.spacingTokenMods[o],s={...t,originalValue:i.originalValue,originalPx:i.originalPx};r=e.spacingTokenMods.map((a,l)=>l===o?s:a)}else r=[...e.spacingTokenMods,t];return{...n,spacingTokenMods:r}}function au(e,t){let n=Bn(e),o=e.spacingTokenMods.findIndex(l=>l.tokenPath===t.tokenPath),r=o>=0?e.spacingTokenMods[o].originalValue:t.originalValue,i=o>=0?e.spacingTokenMods[o].originalPx:parseFloat(t.originalValue)||0,s={tokenPath:t.tokenPath,originalValue:r,currentValue:"__deleted__",targets:o>=0?e.spacingTokenMods[o].targets:[],originalPx:i,currentPx:0},a;return o>=0?a=e.spacingTokenMods.map((l,d)=>d===o?s:l):a=[...e.spacingTokenMods,s],{...n,spacingTokenMods:a}}var lu={SET_ANNOTATING:Ed,SET_TOOL:Td,SET_COLOR:kd,SET_STROKE_WIDTH:Md,START_PATH:Id,CONTINUE_PATH:Rd,CANCEL_PATH:Ld,FINISH_PATH:Ad,ADD_TEXT:Pd,UPDATE_TEXT:Bd,UPDATE_TEXT_SIZE:Dd,DELETE_ANNOTATION:Od,MOVE_ANNOTATION:_d,RESIZE_ANNOTATION:Hd,PASTE_ANNOTATIONS:Nd,RESTORE_ANNOTATIONS:Fd,UNDO:zd,REDO:$d,SELECT_ANNOTATION:Wd,UPDATE_ANNOTATION_COLOR:jd,MARK_CAPTURED:Gd,CLEAR:Jd,SELECT_ELEMENT:Yd,MODIFY_STYLE:Vd,MODIFY_STYLES_BATCH:Ud,CLEAR_STYLE:Kd,CLEAR_ALL_STYLES:Xd,RESTORE_STYLE_MODIFICATIONS:qd,UPDATE_LINKED_POSITIONS:Zd,CLEANUP_ORPHANED:ou,SET_ANNOTATION_STATUS:Qd,SET_ANNOTATION_THREAD:eu,SET_ANNOTATION_QUESTION:tu,APPLY_RESOLUTIONS:nu,ADD_SPACING_TOKEN_CHANGE:ru,RESTORE_SPACING_TOKEN_CHANGES:iu,MODIFY_SPACING_TOKEN:su,DELETE_SPACING_TOKEN:au};function cu(e,t){let n=lu[t.type];return n?n(e,t.payload):e}function Qa(){let[e,t]=wd(cu,Cd);return Sd(()=>{let n=o=>{(o.metaKey||o.ctrlKey)&&o.key==="z"&&(o.preventDefault(),o.shiftKey?t({type:"REDO"}):t({type:"UNDO"}))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[]),[e,t]}import{useSyncExternalStore as du}from"react";if(typeof window<"u"&&!window.__popmeltPathPatch){window.__popmeltPathPatch=!0;for(let e of["pushState","replaceState"]){let t=History.prototype[e];History.prototype[e]=function(...n){let o=window.location.pathname;t.apply(this,n),window.dispatchEvent(new CustomEvent("popmelt:locationchange",{detail:{prevPath:o}}))}}}function uu(e){return window.addEventListener("popstate",e),window.addEventListener("popmelt:locationchange",e),()=>{window.removeEventListener("popstate",e),window.removeEventListener("popmelt:locationchange",e)}}function pu(){return window.location.pathname}function kr(){return du(uu,pu,()=>"/")}var el="popmelt-toolbar-snap-position";function ar(e){return e.startsWith("top-")}function lr(e){return e.endsWith("-right")}function qr(e){return e.endsWith("-center")}function tl(){try{let e=localStorage.getItem(el);if(e&&fu(e))return e}catch{}return"bottom-right"}function nl(e){try{localStorage.setItem(el,e)}catch{}}function fu(e){return["bottom-right","bottom-center","bottom-left","top-right","top-center","top-left"].includes(e)}function ol(e,t,n){let o=ar(e)?16:n-16-54;return qr(e)?{position:"fixed",top:o,left:t/2,transform:"translateX(-50%)"}:lr(e)?{position:"fixed",top:o,right:16,left:"auto"}:{position:"fixed",top:o,left:16,right:"auto"}}function rl(e,t,n){let r=ar(e)?{top:82}:{bottom:82},i;return qr(e)?i={left:t/2,transform:"translateX(-50%)"}:lr(e)?i={right:16}:i={left:16},{position:"fixed",...r,...i}}function il(e,t,n){let o=ar(e),r=o?{top:78}:{bottom:78},i,s;return qr(e)?(i={left:"50%",transform:"translateX(-50%)"},s="center"):lr(e)?(i={right:16},s="flex-end"):(i={left:16},s="flex-start"),{position:"fixed",...r,...i,zIndex:9999,display:"flex",flexDirection:"column",alignItems:s}}function Mi(e){let t=ar(e),n=lr(e)||qr(e);return{position:"fixed",top:t&&n?82:16,right:16,bottom:!t&&n?82:16}}function sl(e,t,n){let r=ar(e),i,s;lr(e)||qr(e)?(i=t-16,s=i-326):(s=16,i=s+326);let a=r?82:n-16-54-12;return{left:s,right:i,y:a}}var al=["top-left","top-center","top-right","bottom-left","bottom-center","bottom-right"];function Ii(e){let t=Object.keys(e).find(r=>r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$"));if(!t)return null;let n=e[t],o=[];for(;n;){let r=n.type,i=r?.displayName||r?.name;i&&typeof i=="string"&&/^[A-Z]/.test(i)&&!i.startsWith("_")&&i!=="Fragment"&&o.unshift(i),n=n.return}return o.length>0?{name:o[o.length-1],path:o}:null}function ys(e){let t=Object.keys(e).find(r=>r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$"));if(!t)return[];let n=e[t],o=[];for(;n;){let r=n.type,i=typeof r=="function"||typeof r=="object"?r?.displayName||r?.name:null;i&&typeof i=="string"&&/^[A-Z]/.test(i)&&!i.startsWith("_")&&i!=="Fragment"&&o.push({name:i,fiber:n}),n=n.return}return o.reverse(),o}function Ri(e){let t=e,n=new Set;for(;t&&!n.has(t);){if(n.add(t),t.stateNode instanceof Element)return t.stateNode;t.child?t=t.child:t=null}return null}function ll(e){if(e.id)return`#${e.id}`;let t=e.tagName.toLowerCase(),n=Array.from(e.classList).slice(0,3).join(".");return n?`${t}.${n}`:t}function jn(e){if(e.id&&!e.id.startsWith("radix-")&&!e.id.startsWith(":"))return`#${CSS.escape(e.id)}`;let t=[],n=e;for(;n&&n!==document.documentElement;){let o=n.tagName.toLowerCase();if(n.id&&!n.id.startsWith("radix-")&&!n.id.startsWith(":")){t.unshift(`#${CSS.escape(n.id)}`);break}let r=Array.from(n.classList).filter(s=>!s.startsWith("_")&&s.length<30).slice(0,2);r.length>0&&(o+="."+r.map(s=>CSS.escape(s)).join("."));let i=n.parentElement;if(i){let s=Array.from(i.children).filter(a=>a.tagName===n.tagName);if(s.length>1){let a=s.indexOf(n)+1;o+=`:nth-of-type(${a})`}}t.unshift(o),n=i}return t.join(" > ")}function En(e){try{return document.querySelector(e)}catch{return null}}function Li(e,t=0){let n=ys(e);if(n.length===0)return null;let o=n.map(l=>l.name),r=n.length-1,i=Math.max(0,Math.min(n.length-1,r-t)),s=n[i],a=Ri(s.fiber)??e;return{name:s.name,path:o,depthIndex:i,rootElement:a}}function cl(e,t){let n=ys(e),o=t.toLowerCase(),r=-1;for(let i=n.length-1;i>=0;i--){let s=n[i].name;if(s===t){let a=Ri(n[i].fiber)??e;return{name:t,path:n.map(l=>l.name),depthIndex:i,rootElement:a}}if(r===-1){let a=s.toLowerCase();(a.length>=4&&o.includes(a)||o.length>=4&&a.includes(o))&&(r=i)}}if(r>=0){let i=Ri(n[r].fiber)??e;return{name:t,path:n.map(s=>s.name),depthIndex:r,rootElement:i}}return null}function Mr(e){let t=Ir(),n=[],o=new Set,r=t.currentNode;for(;r=t.nextNode();){let i=cl(r,e);i&&!o.has(i.rootElement)&&(o.add(i.rootElement),n.push(i))}return n}function bs(e){let t=new Map;if(e.size===0)return t;let n=new Set(e),o=Ir(),r=new Set,i=o.currentNode;for(;(i=o.nextNode())&&n.size>0;)for(let s of n){let a=cl(i,s);if(!a||r.has(a.rootElement))continue;r.add(a.rootElement);let l=a.rootElement.getBoundingClientRect();t.set(s,l.top+window.scrollY),n.delete(s);break}for(let s of n)t.set(s,1/0);return t}function Ir(){return document.createTreeWalker(document.body,NodeFilter.SHOW_ELEMENT,{acceptNode(e){return e.closest("#devtools-toolbar, #devtools-canvas, #devtools-scrim, [data-popmelt-panel]")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function Dn(e){let t={selector:ll(e),tagName:e.tagName.toLowerCase()};e.id&&(t.id=e.id),e.classList.length>0&&(t.className=Array.from(e.classList).join(" "));let n=dl(e);n&&n.length>0&&n.length<200&&(t.textContent=n);let o={};for(let s of e.attributes)s.name.startsWith("data-")&&(o[s.name]=s.value);Object.keys(o).length>0&&(t.dataAttributes=o);let r=Ii(e);r&&(t.reactComponent=r.name);let i=gu(e);return i&&(t.context=i),t}function dl(e){let t="";for(let n of e.childNodes)n.nodeType===Node.TEXT_NODE&&(t+=n.textContent||"");return t.trim()}function cr(e,t){let n=document.elementsFromPoint(e,t);for(let o of n)if(o instanceof HTMLElement&&!(o.id==="devtools-canvas"||o.id==="devtools-toolbar"||o.id==="devtools-scrim")&&!o.closest("#devtools-toolbar")&&!(o.dataset.devtools||o.closest("[data-devtools]"))&&!["html","body"].includes(o.tagName.toLowerCase()))return o;return null}function gu(e){let t=e.parentElement,n=["section","article","nav","aside","header","footer","main"];for(;t&&t!==document.body;){let o=t.tagName.toLowerCase();if(n.includes(o)&&t.id)return`${o}#${t.id}`;if(t.id&&!t.id.startsWith("radix-")&&!t.id.startsWith(":"))return`${o}#${t.id}`;t=t.parentElement}return null}function ul(e){let t=new Set,n=[],o=window.scrollX,r=window.scrollY,i=[{x:(e.minX+e.maxX)/2,y:(e.minY+e.maxY)/2},{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.minX,y:e.maxY},{x:e.maxX,y:e.maxY}];for(let s of i){let a=s.x-o,l=s.y-r;if(a<0||l<0||a>window.innerWidth||l>window.innerHeight)continue;let d=cr(a,l);d&&!t.has(d)&&(t.add(d),n.push(Dn(d)))}return n.slice(0,3)}function vs(e){if(e.length===0)return[];let t=e.map(o=>o.x),n=e.map(o=>o.y);return ul({minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)})}function dn(e,t){return e.style.getPropertyValue(t)!==""}function mu(e,t=30){if(e<=0)return[];let n=[],o=Ir(),r=.5,i=o.currentNode;for(;(i=o.nextNode())&&n.length<t;){let s=i,a=s.getBoundingClientRect();if(a.bottom<-50||a.top>window.innerHeight+50||a.right<-50||a.left>window.innerWidth+50||a.width<1||a.height<1)continue;let l=getComputedStyle(s);!dn(s,"padding-top")&&Math.abs((parseFloat(l.paddingTop)||0)-e)<r&&n.push({element:s,property:"padding-top"}),!dn(s,"padding-bottom")&&Math.abs((parseFloat(l.paddingBottom)||0)-e)<r&&n.length<t&&n.push({element:s,property:"padding-bottom"}),!dn(s,"padding-left")&&Math.abs((parseFloat(l.paddingLeft)||0)-e)<r&&n.length<t&&n.push({element:s,property:"padding-left"}),!dn(s,"padding-right")&&Math.abs((parseFloat(l.paddingRight)||0)-e)<r&&n.length<t&&n.push({element:s,property:"padding-right"}),!dn(s,"margin-top")&&Math.abs((parseFloat(l.marginTop)||0)-e)<r&&n.length<t&&n.push({element:s,property:"margin-top"}),!dn(s,"margin-bottom")&&Math.abs((parseFloat(l.marginBottom)||0)-e)<r&&n.length<t&&n.push({element:s,property:"margin-bottom"}),!dn(s,"margin-left")&&Math.abs((parseFloat(l.marginLeft)||0)-e)<r&&n.length<t&&n.push({element:s,property:"margin-left"}),!dn(s,"margin-right")&&Math.abs((parseFloat(l.marginRight)||0)-e)<r&&n.length<t&&n.push({element:s,property:"margin-right"});let d=l.display;if((d.includes("flex")||d.includes("grid"))&&n.length<t){let c=dn(s,"gap"),p=parseFloat(l.gap)||0,u=parseFloat(l.rowGap)||0,m=parseFloat(l.columnGap)||0;!c&&Math.abs(p-e)<r?n.push({element:s,property:"gap"}):!dn(s,"row-gap")&&Math.abs(u-e)<r?n.push({element:s,property:"row-gap"}):!dn(s,"column-gap")&&Math.abs(m-e)<r&&n.push({element:s,property:"column-gap"})}}return n}function xs(e,t=30){if(e<=0)return[];let n=[],o=Ir(),r=.5,i=o.currentNode;for(;(i=o.nextNode())&&n.length<t;){let s=i,a=s.getBoundingClientRect();if(a.bottom<-50||a.top>window.innerHeight+50||a.right<-50||a.left>window.innerWidth+50||a.width<1||a.height<1)continue;let l=getComputedStyle(s),d=parseFloat(l.borderTopWidth)||0,c=parseFloat(l.borderRightWidth)||0,p=parseFloat(l.borderBottomWidth)||0,u=parseFloat(l.borderLeftWidth)||0,m=s.clientWidth,v=s.clientHeight,b=parseFloat(l.paddingTop)||0;!dn(s,"padding-top")&&Math.abs(b-e)<r&&n.push({x:a.left+u,y:a.top+d,width:m,height:e,direction:"vertical",property:"padding-top"});let I=parseFloat(l.paddingBottom)||0;!dn(s,"padding-bottom")&&Math.abs(I-e)<r&&n.length<t&&n.push({x:a.left+u,y:a.top+d+v-e,width:m,height:e,direction:"vertical",property:"padding-bottom"});let P=parseFloat(l.paddingLeft)||0;!dn(s,"padding-left")&&Math.abs(P-e)<r&&n.length<t&&n.push({x:a.left+u,y:a.top+d,width:e,height:v,direction:"horizontal",property:"padding-left"});let N=parseFloat(l.paddingRight)||0;!dn(s,"padding-right")&&Math.abs(N-e)<r&&n.length<t&&n.push({x:a.left+u+m-e,y:a.top+d,width:e,height:v,direction:"horizontal",property:"padding-right"});let C=parseFloat(l.marginTop)||0;!dn(s,"margin-top")&&Math.abs(C-e)<r&&n.length<t&&n.push({x:a.left,y:a.top-e,width:a.width,height:e,direction:"vertical",property:"margin-top"});let k=parseFloat(l.marginBottom)||0;!dn(s,"margin-bottom")&&Math.abs(k-e)<r&&n.length<t&&n.push({x:a.left,y:a.bottom,width:a.width,height:e,direction:"vertical",property:"margin-bottom"});let E=parseFloat(l.marginLeft)||0;!dn(s,"margin-left")&&Math.abs(E-e)<r&&n.length<t&&n.push({x:a.left-e,y:a.top,width:e,height:a.height,direction:"horizontal",property:"margin-left"});let $=parseFloat(l.marginRight)||0;!dn(s,"margin-right")&&Math.abs($-e)<r&&n.length<t&&n.push({x:a.right,y:a.top,width:e,height:a.height,direction:"horizontal",property:"margin-right"});let Q=l.display;if((Q.includes("flex")||Q.includes("grid"))&&n.length<t&&!dn(s,"gap")){let M=Array.from(s.children).filter(B=>{let f=getComputedStyle(B);return f.display!=="none"&&f.position!=="absolute"&&f.position!=="fixed"});if(M.length>=2)for(let B=0;B<M.length-1&&n.length<t;B++){let f=M[B].getBoundingClientRect(),g=M[B+1].getBoundingClientRect(),j=g.top-f.bottom;Math.abs(j-e)<r&&j>.5&&n.push({x:Math.min(f.left,g.left),y:f.bottom,width:Math.max(f.right,g.right)-Math.min(f.left,g.left),height:j,direction:"vertical",property:"gap"});let fe=g.left-f.right;Math.abs(fe-e)<r&&fe>.5&&n.push({x:f.right,y:Math.min(f.top,g.top),width:fe,height:Math.max(f.bottom,g.bottom)-Math.min(f.top,g.top),direction:"horizontal",property:"gap"})}}}return n}function Ai(e){return typeof e=="string"?{value:e}:e}var fl={gap:["gap","row-gap","column-gap"],padding:["padding-top","padding-bottom","padding-left","padding-right"],margin:["margin-top","margin-bottom","margin-left","margin-right"]};function pl(e,t){let n=fl[t];return n?n.includes(e):!1}function hu(e,t){let n=e.split(/\s+/);for(let o of n){if(o===t)return!0;let r=o.lastIndexOf(":");if(r>=0&&o.slice(r+1)===t)return!0}return!1}function yu(e){let t=e.lastIndexOf(":"),n=t>=0?e.slice(t+1):e,o=n.indexOf("-");if(o<0)return null;let r=n.slice(0,o),i={gap:"gap","gap-x":"column-gap","gap-y":"row-gap",p:"padding",pt:"padding-top",pb:"padding-bottom",pl:"padding-left",pr:"padding-right",px:"padding-left",py:"padding-top",m:"margin",mt:"margin-top",mb:"margin-bottom",ml:"margin-left",mr:"margin-right",mx:"margin-left",my:"margin-top"},s=n.slice(0,n.indexOf("-",o+1)>0?n.indexOf("-",o+1):o);return i[s]??i[r]??null}function Ss(e,t=30){let n=parseFloat(e.value);if(isNaN(n)||n<=0)return[];if(e.bindings&&e.bindings.length>0){let r=[],i=Ir(),s=i.currentNode;for(;(s=i.nextNode())&&r.length<t;){let a=s,l=a.getBoundingClientRect();if(l.bottom<-50||l.top>window.innerHeight+50||l.right<-50||l.left>window.innerWidth+50||l.width<1||l.height<1)continue;let d=a.className;if(typeof d=="string")for(let c of e.bindings){if(!hu(d,c))continue;let p=yu(c);if(p&&!(e.property&&!pl(p,e.property))){r.push({element:a,property:p});break}}}return r}let o=mu(n,t*2);return e.property?o.filter(r=>pl(r.property,e.property)).slice(0,t):o.slice(0,t)}function ws(e,t=30){let n=Ss(e,t),o=[];for(let r of n){let i=r.element,s=i.getBoundingClientRect(),a=getComputedStyle(i),l=parseFloat(a.borderTopWidth)||0,d=parseFloat(a.borderRightWidth)||0,c=parseFloat(a.borderLeftWidth)||0,p=i.clientWidth,u=i.clientHeight;switch(r.property){case"padding-top":{let m=parseFloat(a.paddingTop)||0;o.push({x:s.left+c,y:s.top+l,width:p,height:m,direction:"vertical",property:r.property});break}case"padding-bottom":{let m=parseFloat(a.paddingBottom)||0;o.push({x:s.left+c,y:s.top+l+u-m,width:p,height:m,direction:"vertical",property:r.property});break}case"padding-left":{let m=parseFloat(a.paddingLeft)||0;o.push({x:s.left+c,y:s.top+l,width:m,height:u,direction:"horizontal",property:r.property});break}case"padding-right":{let m=parseFloat(a.paddingRight)||0;o.push({x:s.left+c+p-m,y:s.top+l,width:m,height:u,direction:"horizontal",property:r.property});break}case"margin-top":{let m=parseFloat(a.marginTop)||0;o.push({x:s.left,y:s.top-m,width:s.width,height:m,direction:"vertical",property:r.property});break}case"margin-bottom":{let m=parseFloat(a.marginBottom)||0;o.push({x:s.left,y:s.bottom,width:s.width,height:m,direction:"vertical",property:r.property});break}case"margin-left":{let m=parseFloat(a.marginLeft)||0;o.push({x:s.left-m,y:s.top,width:m,height:s.height,direction:"horizontal",property:r.property});break}case"margin-right":{let m=parseFloat(a.marginRight)||0;o.push({x:s.right,y:s.top,width:m,height:s.height,direction:"horizontal",property:r.property});break}case"gap":case"row-gap":case"column-gap":{let m=Array.from(i.children).filter(v=>{let b=getComputedStyle(v);return b.display!=="none"&&b.position!=="absolute"&&b.position!=="fixed"});for(let v=0;v<m.length-1&&o.length<t;v++){let b=m[v].getBoundingClientRect(),I=m[v+1].getBoundingClientRect(),P=I.top-b.bottom;P>.5&&o.push({x:Math.min(b.left,I.left),y:b.bottom,width:Math.max(b.right,I.right)-Math.min(b.left,I.left),height:P,direction:"vertical",property:"gap"});let N=I.left-b.right;N>.5&&o.push({x:b.right,y:Math.min(b.top,I.top),width:N,height:Math.max(b.bottom,I.bottom)-Math.min(b.top,I.top),direction:"horizontal",property:"gap"})}break}}}return o}function gl(e,t){let n=new Set,o=Zr(t);for(let r of e){let i=hl[r.property];if(!i)continue;let s=r.element.className;if(typeof s=="string")for(let a of i){let l=`${a}-${o}`;for(let d of s.split(/\s+/)){let c=d.lastIndexOf(":"),p=c>=0?d.slice(c+1):d;if(p===l){n.add(p);break}}}}return[...n]}function ml(e){let t=new Set;for(let n of e)for(let[o,r]of Object.entries(fl))if(r.includes(n.property)){t.add(o);break}if(t.size===1)return[...t][0]}function Cs(e,t,n){if(t===n)return e;let o=Zr(t),r=Zr(n);return e.map(i=>{let s=i.lastIndexOf("-");if(s<0)return i;let a=i.slice(0,s),l=i.slice(s+1);return l===o||l===`[${t}px]`?`${a}-${r}`:i})}var bu={0:"0",1:"px",2:"0.5",4:"1",6:"1.5",8:"2",12:"3",16:"4",20:"5",24:"6",28:"7",32:"8",40:"10",48:"12",64:"16",80:"20",96:"24"};function Zr(e){return bu[e]??`[${e}px]`}var hl={"padding-top":["pt","py","p"],"padding-bottom":["pb","py","p"],"padding-left":["pl","px","p"],"padding-right":["pr","px","p"],"margin-top":["mt","my","m"],"margin-bottom":["mb","my","m"],"margin-left":["ml","mx","m"],"margin-right":["mr","mx","m"],gap:["gap"],"row-gap":["gap-y","gap"],"column-gap":["gap-x","gap"]};function vu(e,t,n,o){let r=hl[t];if(!r)return null;let i=Zr(n);for(let s of r){let a=new RegExp("(?:^|\\s)((?:[\\w-]+:)*"+s+"-(?:"+xu(i)+"|\\["+n+"px\\]))(?:\\s|$)"),l=e.match(a);if(l?.[1]){let d=Zr(o),c=l[1].lastIndexOf(":"),p=c>=0?l[1].slice(0,c+1):"";return{matched:l[1],suggested:`${p}${s}-${d}`}}}return null}function xu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function yl(e,t,n){let o=new Set,r=[];for(let i of e){let s=jn(i.element),a=`${s}::${i.property}`;if(o.has(a))continue;o.add(a);let l=Ii(i.element),d=i.element.className||"",c=vu(d,i.property,t,n);r.push({selector:s,reactComponent:l?.name,className:d,property:i.property,matchedClass:c?.matched,suggestedClass:c?.suggested})}return r}function Pi(e,t){return window.getComputedStyle(e).getPropertyValue(t)}function Bi(e,t){if(e instanceof HTMLElement){let o=e.style.getPropertyValue(t);if(o)return o}let n=t.replace(/-([a-z])/g,(o,r)=>r.toUpperCase());try{for(let o of document.styleSheets)try{let r=o.cssRules||o.rules;for(let i of r)if(i instanceof CSSStyleRule&&e.matches(i.selectorText)){let s=i.style.getPropertyValue(t);if(s)return s;let a=i.style[n];if(a)return a}}catch{}}catch{}return null}function Di(e){let t=window.getComputedStyle(e).display;return t==="flex"||t==="inline-flex"||t==="grid"||t==="inline-grid"}function dr(e){let t=window.getComputedStyle(e);return{row:parseFloat(t.rowGap)||0,column:parseFloat(t.columnGap)||0}}function Su(e){let t=[];for(let n of e){let o=t.find(r=>r.axis!==n.axis?!1:n.axis==="row"?Math.abs(r.y-n.y)<2&&Math.abs(r.h-n.h)<2:Math.abs(r.x-n.x)<2&&Math.abs(r.w-n.w)<2);if(o)if(n.axis==="row"){let r=Math.min(o.x,n.x),i=Math.max(o.x+o.w,n.x+n.w);o.x=r,o.w=i-r}else{let r=Math.min(o.y,n.y),i=Math.max(o.y+o.h,n.y+n.h);o.y=r,o.h=i-r}else t.push({...n})}return t}function Ao(e){let t=Array.from(e.children).filter(l=>{if(!(l instanceof HTMLElement))return!1;let d=window.getComputedStyle(l);return d.display!=="none"&&d.position!=="absolute"&&d.position!=="fixed"});if(t.length<2)return[];let n=[],o=e.getBoundingClientRect(),i=window.getComputedStyle(e).flexDirection,s=i==="column"||i==="column-reverse",a=6;for(let l=0;l<t.length-1;l++){let d=t[l].getBoundingClientRect(),c=t[l+1].getBoundingClientRect();if(c.left>d.right+.5&&n.push({axis:"column",x:d.right,y:o.top,w:c.left-d.right,h:o.height}),c.top>d.bottom+.5&&n.push({axis:"row",x:o.left,y:d.bottom,w:o.width,h:c.top-d.bottom}),!(c.left>d.right+.5)&&!(c.top>d.bottom+.5))if(s){let p=(d.bottom+c.top)/2;n.push({axis:"row",x:o.left,y:p-a/2,w:o.width,h:a})}else{let p=(d.right+c.left)/2;n.push({axis:"column",x:p-a/2,y:o.top,w:a,h:o.height})}}return Su(n)}function Es(e,t){let n=window.getComputedStyle(e),o=n.display;if(o!=="flex"&&o!=="inline-flex")return!1;let r=n.justifyContent;if(r!=="space-between"&&r!=="space-around"&&r!=="space-evenly"&&r!=="stretch")return!1;let i=n.flexDirection;return!(t!==(i==="column"||i==="column-reverse"?"row":"column")||parseFloat(t==="row"?n.rowGap:n.columnGap)>0)}function Rr(e){let t=window.getComputedStyle(e);return{top:parseFloat(t.paddingTop)||0,right:parseFloat(t.paddingRight)||0,bottom:parseFloat(t.paddingBottom)||0,left:parseFloat(t.paddingLeft)||0}}function ur(e){let t=window.getComputedStyle(e);return{"top-left":parseFloat(t.borderTopLeftRadius)||0,"top-right":parseFloat(t.borderTopRightRadius)||0,"bottom-right":parseFloat(t.borderBottomRightRadius)||0,"bottom-left":parseFloat(t.borderBottomLeftRadius)||0}}function Ts(e){for(let t of e.childNodes)if(t.nodeType===Node.TEXT_NODE&&(t.textContent||"").trim().length>0)return!0;return!1}function Lr(e){let t=document.createRange(),n=!1;for(let c of e.childNodes)c.nodeType===Node.TEXT_NODE&&(c.textContent||"").trim().length>0&&(n||(t.setStart(c,0),n=!0),t.setEnd(c,c.textContent?.length??0));if(!n)return null;let o=t.getBoundingClientRect(),r=window.getComputedStyle(e),i=parseFloat(r.fontSize)||16,s=parseFloat(r.lineHeight);isNaN(s)&&(s=i*1.2);let a=Math.max(1,t.getClientRects().length),l=Math.max(o.height,a*s),d=(l-o.height)/2;return new DOMRect(o.x,o.y-d,o.width,l)}function Qr(e){let t=window.getComputedStyle(e),n=parseFloat(t.fontSize)||16,o=parseFloat(t.lineHeight);return isNaN(o)&&(o=n*1.2),{fontSize:n,lineHeight:o}}function Ve(e,t,n){e instanceof HTMLElement&&e.style.setProperty(t,n,"important")}function bl(e,t,n){e instanceof HTMLElement&&e.style.removeProperty(t)}function Oi(e){for(let t of e){let n=En(t.selector);if(!n&&t.durableSelector&&(n=En(t.durableSelector),n)){let o=t.selector.match(/\[data-pm="([^"]+)"\]/)?.[1];o&&n.setAttribute("data-pm",o)}if(n)for(let o of t.changes)Ve(n,o.property,o.modified)}}function _i(e){for(let t of e){let n=En(t.selector);if(n)for(let o of t.changes)bl(n,o.property,o.original)}}function xl(e,t,n,o){if(e)for(let r of e){if(r instanceof CSSGroupingRule){xl(r.cssRules,t,n,o);continue}if(r instanceof CSSStyleRule){let i=r.selectorText.toLowerCase();(i===":root"||i==="html"||i==="*"||i.includes(":root"))&&wu(r.style,t,n,o)}}}function wu(e,t,n,o){for(let r=0;r<e.length;r++){let i=e[r];if(i?.startsWith("--")){if(n.has(i))continue;n.add(i);let s=t.getPropertyValue(i).trim();Sl(s)&&o.push({name:i,value:s,usage:`var(${i})`})}}}var Hi=null,Cu=5e3;function ks(){if(Hi&&Date.now()-Hi.timestamp<Cu)return Hi.variables;let e=[],t=new Set,n=getComputedStyle(document.documentElement);try{for(let i of document.styleSheets)try{xl(i.cssRules||i.rules,n,t,e)}catch{}}catch{}let o=document.documentElement.style;for(let i=0;i<o.length;i++){let s=o[i];if(s?.startsWith("--")&&!t.has(s)){t.add(s);let a=n.getPropertyValue(s).trim();Sl(a)&&e.push({name:s,value:a,usage:`var(${s})`})}}let r=e.sort((i,s)=>i.name.localeCompare(s.name));return Hi={variables:r,timestamp:Date.now()},r}function Sl(e){if(!e)return!1;let t=e.toLowerCase().trim();return!!(/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)||t.startsWith("rgb")||t.startsWith("hsl")||t.startsWith("oklch")||t.startsWith("oklab")||t.startsWith("lch")||t.startsWith("lab")||["transparent","currentcolor","inherit","white","black","red","green","blue","yellow","orange","purple","pink","gray","grey"].includes(t))}function Ar(e,t){let n=t.match(/var\((--[^,)]+)(?:,\s*([^)]+))?\)/);if(n){let o=n[1],r=n[2];return getComputedStyle(document.documentElement).getPropertyValue(o).trim()||r||t}return t}function ei(e,t){if(!e)return null;let n=vl(e);if(!n)return null;for(let o of t){let r=vl(o.value);if(r&&n===r)return o}return null}function vl(e){if(!e)return null;let t=e.trim().toLowerCase();if(t.startsWith("oklch(")){let n=t.match(/oklch\(\s*([\d.]+%?)\s+([\d.]+%?)\s+([\d.]+)/);if(n){let o=n[1].endsWith("%")?parseFloat(n[1])/100:parseFloat(n[1]),r=n[2].endsWith("%")?parseFloat(n[2])/100:parseFloat(n[2]),i=parseFloat(n[3]);o=Math.round(o*100)/100,r=Math.round(r*1e3)/1e3;let s=Math.round(i);return`oklch(${o} ${r} ${s})`}}if(t.startsWith("rgb")){let n=t.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/);if(n)return`rgb(${n[1]},${n[2]},${n[3]})`}return t.startsWith("#")?t.length===4?`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`:t.slice(0,7):t}import{domToCanvas as Eu}from"modern-screenshot";var wl="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";function Tu(e){if(typeof window>"u")return!1;try{let t=new URL(e,window.location.href);return t.protocol!=="http:"&&t.protocol!=="https:"?!1:t.origin!==window.location.origin}catch{return!1}}function Ms(e){let t=document.createElement("canvas").getContext("2d");return t?(t.fillStyle=e,t.fillStyle):"#888888"}function Is(e,t=[],n,o){let r=new Map,i=[];for(let a of e)if(a.groupId){let l=r.get(a.groupId)||[];l.push(a),r.set(a.groupId,l)}else i.push(a);let s=[];for(let[a,l]of r){let d=l.find(p=>p.type!=="text"),c=l.find(p=>p.type==="text");if(d){let p=d.linkedSelector||c?.linkedSelector,u=c?.imageCount||d.imageCount,m=d.pathname||c?.pathname;s.push({id:d.id,type:d.type,instruction:c?.text,...p?{linkedSelector:p}:{},...m?{pathname:m}:{},elements:d.elements||[],...u?{imageCount:u}:{}})}}for(let a of i)s.push({id:a.id,type:a.type,instruction:a.type==="text"?a.text:void 0,...a.linkedSelector?{linkedSelector:a.linkedSelector}:{},...a.pathname?{pathname:a.pathname}:{},elements:a.elements||[],...a.imageCount?{imageCount:a.imageCount}:{}});return{timestamp:new Date().toISOString(),url:window.location.href,viewport:{width:window.innerWidth,height:window.innerHeight},scrollPosition:{x:window.scrollX,y:window.scrollY},annotations:s,styleModifications:t,...n?{inspectedElement:n}:{},...o&&o.length>0?{spacingTokenChanges:o}:{}}}function ku(e){if(!e.points||e.points.length===0)return null;let t=e.points.map(o=>o.x),n=e.points.map(o=>o.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Mu(e,t){if(e.length===0)return[];let n=e.map(c=>({annotation:c,bounds:ku(c)})).filter(c=>c.bounds!==null);if(n.length===0)return[];n.sort((c,p)=>c.bounds.minY-p.bounds.minY);let o=Math.min(...n.map(c=>c.bounds.minY)),r=Math.max(...n.map(c=>c.bounds.maxY));if(r-o<=t){let c=(o+r)/2,p=Math.max(0,c-t/2);return[{top:p,bottom:p+t,annotations:e}]}let i=[],s=50,a=Math.max(0,o-s),l=[],d=a;for(let{annotation:c,bounds:p}of n){let u=p.maxY+s;if(u-a<=t)l.push(c),d=Math.max(d,u);else{if(l.length>0){let m=(a+d)/2,v=Math.max(0,m-t/2);i.push({top:v,bottom:v+t,annotations:l})}a=Math.max(0,p.minY-s),l=[c],d=p.maxY+s}}if(l.length>0){let c=(a+d)/2,p=Math.max(0,c-t/2);i.push({top:p,bottom:p+t,annotations:l})}return i}function Iu(e){let t=new Map;for(let n of e)if(n.linkedSelector)try{let o=document.querySelector(n.linkedSelector);if(o){let r=o.getBoundingClientRect();t.set(n.id,{x:r.left+window.scrollX,y:r.top+window.scrollY,width:r.width,height:r.height})}}catch{}return t}function Ru(e,t,n,o,r){if(e.save(),e.scale(o,o),r)for(let i of t){let s=r.get(i.id);if(!s)continue;let a=s.y-n;e.fillStyle=i.color,e.globalAlpha=.05,e.fillRect(s.x,a,s.width,s.height),e.globalAlpha=1,e.strokeStyle=i.color,e.lineWidth=1,e.setLineDash([2,4]),e.strokeRect(s.x,a,s.width,s.height),e.setLineDash([])}for(let i of t){let s=i.points.map(a=>({x:a.x,y:a.y-n}));switch(e.strokeStyle=i.color,e.fillStyle=i.color,e.lineWidth=i.strokeWidth,e.lineCap="round",e.lineJoin="round",i.type){case"freehand":if(s.length<2)break;e.beginPath(),e.moveTo(s[0].x,s[0].y);for(let a=1;a<s.length;a++)e.lineTo(s[a].x,s[a].y);e.stroke();break;case"line":if(s.length<2)break;e.beginPath(),e.moveTo(s[0].x,s[0].y),e.lineTo(s[s.length-1].x,s[s.length-1].y),e.stroke();break;case"rectangle":{if(s.length<2)break;let a=s[0],l=s[s.length-1],d=Math.min(a.x,l.x),c=Math.min(a.y,l.y),p=Math.abs(l.x-a.x),u=Math.abs(l.y-a.y);e.strokeRect(d,c,p,u);break}case"circle":{if(s.length<2)break;let a=s[0],l=s[s.length-1],d=(a.x+l.x)/2,c=(a.y+l.y)/2,p=Math.abs(l.x-a.x)/2,u=Math.abs(l.y-a.y)/2;e.beginPath(),e.ellipse(d,c,p,u,0,0,Math.PI*2),e.stroke();break}case"text":{if(!i.text||s.length<1)break;let a=s[0],l=i.fontSize||16;e.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,e.fillStyle=i.color;let c=(i.imageCount&&i.imageCount>0?`[${i.imageCount} image${i.imageCount>1?"s":""}] ${i.text}`:i.text).split(`
3
+ `),p=l*1.2,u=4,m=0;for(let v of c)m=Math.max(m,e.measureText(v).width);e.fillRect(a.x-u,a.y-u,m+u*2,c.length*p+u*2),e.fillStyle="#ffffff",c.forEach((v,b)=>{e.fillText(v,a.x,a.y+l+b*p)});break}}}e.restore()}async function Pr(e,t,n=[],o){try{let r=o?.dpr??(window.devicePixelRatio||1),i=window.innerWidth,s=window.innerHeight,a=n.filter(p=>(p.status??"pending")==="pending");console.log("[Screenshot] Starting capture with",a.length,"active annotations (filtered",n.length-a.length,"captured)");let l=Iu(a),d=Mu(a,s);if(d.length===0){let p=await Cl(e,[],window.scrollY,i,s,r,l);return p?[p]:[]}let c=[];for(let p=0;p<d.length;p++){let u=d[p],m=await Cl(e,u.annotations,u.top,i,s,r,l);m?c.push(m):console.warn(`[Screenshot] Region ${p+1} failed to capture`)}return console.log("[Screenshot] Capture complete"),c}catch(r){return console.error("[Screenshot] Capture failed:",r),[]}}async function Cl(e,t,n,o,r,i,s){try{let a=getComputedStyle(document.documentElement).backgroundColor,d=await Eu(e,{filter:u=>!(u instanceof HTMLElement&&(u.id==="devtools-canvas"||u.id==="devtools-toolbar"||u.id==="devtools-scrim"||u.dataset.devtools!==void 0)),scale:i,backgroundColor:a&&a!=="rgba(0, 0, 0, 0)"&&a!=="transparent"?a:"#ffffff",width:o,height:r,style:{transform:`translate(${-window.scrollX}px, ${-n}px)`},fetchFn:async u=>Tu(u)?wl:!1,fetch:{placeholderImage:wl}}),c=document.createElement("canvas");c.width=o*i,c.height=r*i;let p=c.getContext("2d");return p?(p.drawImage(d,0,0,o*i,r*i,0,0,o*i,r*i),Ru(p,t,n,i,s),new Promise(u=>{c.toBlob(m=>u(m),"image/webp",.8)})):null}catch(a){return console.error("Region capture failed:",a),null}}async function ti(e){if(e.length===0)return null;if(e.length===1)return e[0];let t=await Promise.all(e.map(a=>new Promise((l,d)=>{let c=new Image;c.onload=()=>l(c),c.onerror=d,c.src=URL.createObjectURL(a)}))),n=t[0].width,o=t.reduce((a,l)=>a+l.height,0),r=document.createElement("canvas");r.width=n,r.height=o;let i=r.getContext("2d");if(!i)return null;let s=0;for(let a of t)i.drawImage(a,0,s),s+=a.height,URL.revokeObjectURL(a.src);return new Promise(a=>{r.toBlob(l=>a(l),"image/webp",.8)})}async function El(e,t,n){try{let o=Array.isArray(e)?e:[e];if(o.length===0)return!1;let r=await ti(o);if(!r)return!1;let i=r;if(r.type!=="image/png"){let d=new Image,c=URL.createObjectURL(r);await new Promise(u=>{d.onload=()=>u(),d.src=c}),URL.revokeObjectURL(c);let p=document.createElement("canvas");p.width=d.naturalWidth,p.height=d.naturalHeight,p.getContext("2d").drawImage(d,0,0),i=await new Promise(u=>p.toBlob(m=>u(m),"image/png"))}let s={"image/png":i},a=t&&t.length>0,l=n&&n.length>0;if(a||l){let d=t?t.filter(c=>(c.status??"pending")==="pending"):[];if(d.length>0||l){let c=Is(d,n||[]),p=new Blob([JSON.stringify(c,null,2)],{type:"text/plain"});s["text/plain"]=p}}return await navigator.clipboard.write([new ClipboardItem(s)]),!0}catch(o){return console.warn("Clipboard write failed:",o),!1}}var Ni="0.7.7";import{useCallback as on,useEffect as Tn,useMemo as Wr,useRef as Ft,useState as xt}from"react";import{useCallback as Br,useRef as Pu}from"react";function Rs(e,t,n,o){if(t.length<2)return;let r=t[0],i=t[t.length-1];if(!r||!i)return;let s=(r.x+i.x)/2,a=(r.y+i.y)/2,l=Math.abs(i.x-r.x)/2,d=Math.abs(i.y-r.y)/2;e.beginPath(),e.strokeStyle=n,e.lineWidth=o,e.ellipse(s,a,l,d,0,0,Math.PI*2),e.stroke()}function Ls(e,t,n,o){if(t.length<2)return;let r=t[0],i=t[t.length-1];if(!(!r||!i)){e.beginPath(),e.strokeStyle=n,e.lineWidth=o,e.lineCap="round",e.lineJoin="round",e.moveTo(r.x,r.y);for(let s=1;s<t.length-1;s++){let a=t[s],l=t[s+1];if(!a||!l)continue;let d=(a.x+l.x)/2,c=(a.y+l.y)/2;e.quadraticCurveTo(a.x,a.y,d,c)}e.lineTo(i.x,i.y),e.stroke()}}function As(e,t,n,o){if(t.length<2)return;let r=t[0],i=t[t.length-1];!r||!i||(e.beginPath(),e.strokeStyle=n,e.lineWidth=o,e.lineCap="round",e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke())}function Ps(e,t,n,o){if(t.length<2)return;let r=t[0],i=t[t.length-1];if(!r||!i)return;let s=Math.min(r.x,i.x),a=Math.min(r.y,i.y),l=Math.abs(i.x-r.x),d=Math.abs(i.y-r.y);e.beginPath(),e.strokeStyle=n,e.lineWidth=o,e.lineCap="round",e.lineJoin="round",e.strokeRect(s,a,l,d)}var vn='"JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace';function Lu(e,t,n){if(!t||e.measureText(t).width<=n)return[t];let o=t.split(/\s+/),r=[],i="";for(let s of o){let a=i?i+" "+s:s;i&&e.measureText(a).width>n?(r.push(i),i=s):i=a}return i&&r.push(i),r.length>0?r:[t]}function ni(e){let t=window.innerWidth-e-16;return Math.max(60,Math.min(400,t))}function Tl(e,t,n){let o=[];for(let r of t)o.push(...Lu(e,r,n));return o}function oi(e,t,n){if(e.measureText(t).width<=n)return t;let o="\u2026";for(let r=t.length-1;r>0;r--){let i=t.slice(0,r)+o;if(e.measureText(i).width<=n)return i}return o}function Au(e,t,n){if(e===void 0||t===void 0||n.avoidLeft===void 0&&n.avoidRight===void 0)return!0;let o=typeof window<"u"?window.innerWidth:9999,r=n.avoidLeft??0,i=n.avoidRight??o;return e+t>r&&e<i}function Bs(e,t,n,o,r){let i=typeof window<"u"?window.innerHeight:9999,s=0,a=i;n&&Au(o,r,n)&&(s=n.avoidTop??s,a=n.avoidBottom??a);let l=Math.max(s,a-t);return Math.max(s,Math.min(e,l))}function Ds(e,t=12,n,o){let r=t*1.4+8,i=e.y-4,s=e.x-4,a=Bs(i,r,n,s,o);return a===i?e:{...e,y:a+4}}function kl(e,t,n,o,r=12,i,s,a){if(!n)return;let l=r*1.4,d=n.replace(/\n/g," "),c=i!==void 0?i+". "+d:d;e.font=`${r}px ${vn}`,e.textBaseline="middle";let p=s!==void 0?Math.min(400,Math.max(60,window.innerWidth-s-16)):400,u=oi(e,c,p),m=e.measureText(u).width,v=Ds(t,r,a,m+8);e.fillStyle=o,e.fillRect(v.x-4,v.y-4,m+8,l+8),e.fillStyle="#ffffff",e.fillText(u,v.x,v.y+l/2)}var Ml=11,Os=4,Bu=`600 ${Ml}px system-ui, -apple-system, sans-serif`;function _s(e,t,n){return e.map(o=>({x:o.x-t,y:o.y-n}))}function Du(e,t,n,o,r,i){let s=String(o);e.font=Bu;let l=e.measureText(s).width+Os*2,d=Ml+Os*2,c=t-l/2,p=n+i/2+2;e.fillStyle=r,e.fillRect(c,p,l,d),e.fillStyle="#ffffff",e.textBaseline="middle",e.fillText(s,c+Os,p+d/2)}function Ou(e,t){if(e.points.length<2&&e.type!=="text")return null;switch(e.type){case"rectangle":case"freehand":{let n,o;if(e.type==="freehand")n=Math.min(...e.points.map(r=>r.x)),o=Math.max(...e.points.map(r=>r.y));else{let r=e.points[0],i=e.points[e.points.length-1];n=Math.min(r.x,i.x),o=Math.max(r.y,i.y)}return{x:n,y:o}}case"circle":{let n=e.points[0],o=e.points[e.points.length-1],r=Math.min(n.x,o.x),i=(Math.min(n.y,o.y)+Math.max(n.y,o.y))/2;return{x:r,y:i}}case"line":{let n=e.points[0],o=e.points[e.points.length-1],r=n.y>o.y?n:o;return{x:r.x,y:r.y}}default:return null}}function Il(){let e=Pu(null),t=Br(()=>{let a=e.current;if(!a)return;let l=a.getContext("2d");l&&l.clearRect(0,0,a.width,a.height)},[]),n=Br((a,l,d,c)=>{let p=e.current;if(!p)return;let u=p.getContext("2d");if(!u)return;let v=(a.status??(a.captured?"in_flight":"pending"))==="pending"||d?a.color:"#999999";switch(a.type){case"freehand":Ls(u,a.points,v,a.strokeWidth);break;case"line":As(u,a.points,v,a.strokeWidth);break;case"rectangle":Ps(u,a.points,v,a.strokeWidth);break;case"circle":Rs(u,a.points,v,a.strokeWidth);break;case"text":a.text&&a.points[0]&&kl(u,a.points[0],a.text,v,a.fontSize,l,a.points[0].x,c);break}},[]),o=Br((a,l,d,c)=>{let p=e.current;if(!p||a.length<2)return;let u=p.getContext("2d");if(u)switch(l){case"freehand":Ls(u,a,d,c);break;case"line":As(u,a,d,c);break;case"rectangle":Ps(u,a,d,c);break;case"circle":Rs(u,a,d,c);break}},[]),r=Br((a,l)=>{let d=e.current;if(!d||a.points.length<2)return;let c=d.getContext("2d");if(c){if(c.fillStyle="#ffffff",c.strokeStyle=a.color,c.lineWidth=1.5,a.type==="line"){let p=a.points[0],u=a.points[a.points.length-1];[p,u].forEach(m=>{c.beginPath(),c.arc(m.x,m.y,l/2,0,Math.PI*2),c.fill(),c.stroke()});return}if(a.type==="circle"){let p=a.points[0],u=a.points[a.points.length-1],m=Math.min(p.x,u.x),v=Math.max(p.x,u.x),b=Math.min(p.y,u.y),I=Math.max(p.y,u.y),P=(m+v)/2,N=(b+I)/2;[{x:P,y:b},{x:P,y:I},{x:m,y:N},{x:v,y:N}].forEach(k=>{c.beginPath(),c.rect(k.x-l/2,k.y-l/2,l,l),c.fill(),c.stroke()});return}if(a.type==="rectangle"||a.type==="freehand"){let p,u,m,v;if(a.type==="freehand")p=Math.min(...a.points.map(I=>I.x)),u=Math.max(...a.points.map(I=>I.x)),m=Math.min(...a.points.map(I=>I.y)),v=Math.max(...a.points.map(I=>I.y));else{let I=a.points[0],P=a.points[a.points.length-1];p=Math.min(I.x,P.x),u=Math.max(I.x,P.x),m=Math.min(I.y,P.y),v=Math.max(I.y,P.y)}[{x:p,y:m},{x:u,y:m},{x:p,y:v},{x:u,y:v}].forEach(I=>{c.beginPath(),c.rect(I.x-l/2,I.y-l/2,l,l),c.fill(),c.stroke()})}}},[]),i=Br((a,l,d,c,p,u,m,v=0,b=0,I,P,N)=>{if(t(),a.forEach(C=>{let k={...C,points:_s(C.points,v,b)},E=I?.get(C.id),$=P?.has(C.id)??!1;n(k,E,$,N)}),l.length>0){let C=_s(l,v,b);o(C,d,c,p)}if(u&&u.length>0&&m){let k=e.current?.getContext("2d");for(let E of u){let $=a.find(Q=>Q.id===E);if($){let Q={...$,points:_s($.points,v,b)};if(r(Q,m),k&&$.type!=="text"&&I&&!($.groupId&&a.some(M=>M.groupId===$.groupId&&M.type==="text"))){let M=I.get($.id);if(M!==void 0){let B=Ou(Q,m);if(B){let g=($.status??($.captured?"in_flight":"pending"))==="pending"?$.color:"#999999";Du(k,B.x,B.y,M,g,m)}}}}}}},[t,n,o,r]),s=Br(()=>{let a=e.current;if(!a)return;let l=window.devicePixelRatio||1;a.width=window.innerWidth*l,a.height=window.innerHeight*l;let d=a.getContext("2d");d&&d.scale(l,l)},[]);return{canvasRef:e,clearCanvas:t,drawAnnotation:n,drawCurrentPath:o,redrawAll:i,resizeCanvas:s}}import{useEffect as _u,useRef as Hu}from"react";function Rl(){let e=Hu({shift:!1,cmd:!1});return _u(()=>{let t=r=>{r.key==="Shift"&&(e.current.shift=!0),(r.key==="Meta"||r.key==="Control")&&(e.current.cmd=!0)},n=r=>{r.key==="Shift"&&(e.current.shift=!1),(r.key==="Meta"||r.key==="Control")&&(e.current.cmd=!1)},o=()=>{e.current={shift:!1,cmd:!1}};return window.addEventListener("keydown",t,!0),window.addEventListener("keyup",n,!0),window.addEventListener("blur",o),()=>{window.removeEventListener("keydown",t,!0),window.removeEventListener("keyup",n,!0),window.removeEventListener("blur",o)}},[]),e}import{useEffect as Nu}from"react";function Ll(e,t,n,o,r){Nu(()=>{let i=s=>{if(e){if(e.linkedSelector)return;s.preventDefault(),s.stopPropagation();let l=s.deltaY>0?-2:2;t(d=>d?{...d,fontSize:Math.max(12,Math.min(72,d.fontSize+l))}:null);return}if(!n)return;s.preventDefault();let a=o.find(l=>l.id===n);if(a&&a.type==="text"&&!a.linkedSelector){let l=a.fontSize||12,d=s.deltaY>0?-2:2;r({type:"UPDATE_TEXT_SIZE",payload:{id:n,fontSize:l+d}})}};return window.addEventListener("wheel",i,{passive:!1}),()=>{window.removeEventListener("wheel",i)}},[n,e,o,r,t])}import{useEffect as Ns,useRef as Fu,useState as Fs}from"react";import{Fragment as ri,jsx as Ut,jsxs as Or}from"react/jsx-runtime";var jo=22,ii=12,Dr=8,zu=3,$u=250,Fi=["reviewing","considering","thinking","zhuzhing","iterating","tweaking","reflecting","noodling","pondering","finessing","polishing","riffing"],Wu=3e3;function ju(e){let t=e?.current?.getBoundingClientRect();return!t||typeof window>"u"?{}:t.top<window.innerHeight/2?{avoidTop:t.bottom+Dr,avoidLeft:t.left-Dr,avoidRight:t.right+Dr}:{avoidBottom:t.top-Dr,avoidLeft:t.left-Dr,avoidRight:t.right+Dr}}function Gu(e,t,n){if(n.avoidLeft===void 0&&n.avoidRight===void 0)return!0;let o=typeof window<"u"?window.innerWidth:9999,r=n.avoidLeft??0,i=n.avoidRight??o;return e+t>r&&e<i}function Hs(e,t,n){return Gu(t,n,e)?e:{}}function Ju(e,t,n){let o=n.avoidTop!==void 0?`${n.avoidTop}px`:"0px",r=n.avoidBottom!==void 0?`${n.avoidBottom}px`:"100vh";return`translate(min(0px, calc(100vw - ${e} - 100%)), min(max(0px, calc(${o} - ${t})), calc(${r} - ${t} - 100%)))`}function Al(e,t,n){if(n.avoidTop===void 0&&n.avoidBottom===void 0)return e;let o=typeof window<"u"?window.innerHeight:9999,r=n.avoidTop??0,i=n.avoidBottom??o,s=Math.max(r,i-t);return Math.max(r,Math.min(e,s))}function Yu({left:e,top:t,scrollX:n,scrollY:o,avoidTop:r,avoidBottom:i,style:s,children:a,...l}){let d=`calc(${e}px - var(--popmelt-scroll-x, ${n}px))`,c=`calc(${t}px - var(--popmelt-scroll-y, ${o}px))`,p=`calc(${e+ii}px - var(--popmelt-scroll-x, ${n}px))`,u=`calc(${t+ii}px - var(--popmelt-scroll-y, ${o}px))`;return Ut("div",{"data-devtools":"badge-hit-area",...l,style:{position:"fixed",left:0,top:0,padding:ii,...s,transform:`translate3d(${d}, ${c}, 0)`,willChange:"transform"},children:Ut("div",{style:{transform:Ju(p,u,{avoidTop:r,avoidBottom:i})},children:a})})}function Pl({annotations:e,supersededAnnotations:t,inFlightIds:n,activeIds:o,queuePositions:r,scrollX:i,scrollY:s,annotationGroupMap:a,onViewThread:l,onSelectAnnotation:d,onHoverAnnotation:c,canvasRef:p,toolbarRef:u}){let m=Fu(null),[v,b]=Fs(0),[I,P]=Fs(()=>Math.floor(Math.random()*Fi.length)),N=!!(n&&n.size>0);Ns(()=>{if(!N)return;let f=setInterval(()=>{b(j=>(j+1)%zu)},$u),g=setInterval(()=>{P(j=>(j+1)%Fi.length)},Wu);return()=>{clearInterval(f),clearInterval(g)}},[N]),Ns(()=>{let f=m.current;if(!f)return;let g=null,j=()=>{g=null,f.style.setProperty("--popmelt-scroll-x",`${window.scrollX}px`),f.style.setProperty("--popmelt-scroll-y",`${window.scrollY}px`)},fe=()=>{g===null&&(g=window.requestAnimationFrame(j))};return j(),window.addEventListener("scroll",fe,{passive:!0}),window.addEventListener("resize",fe),()=>{window.removeEventListener("scroll",fe),window.removeEventListener("resize",fe),g!==null&&window.cancelAnimationFrame(g)}},[]);let C=[];for(let f of e){if(f.type!=="text"||!f.text||!f.points[0]||t.has(f))continue;let g=f.groupId?e.filter(ie=>ie.groupId===f.groupId):[f],j=f.status??"pending",fe=g.reduce((ie,Ne)=>ie+(Ne.replyCount??0),0),Re=!!(n&&(n.has(f.id)||g.some(ie=>n.has(ie.id))))||f.status==="in_flight"||g.some(ie=>ie.status==="in_flight"),le=g.some(ie=>ie.status==="resolved"&&(ie.replyCount??0)>0||ie.status==="needs_review"),Ce=g.some(ie=>ie.threadId);if(!Re&&j!=="resolved"&&j!=="needs_review"&&!le&&!Ce)continue;let Ee=f.threadId||g.find(ie=>ie.threadId)?.threadId,K=j==="needs_review"||g.some(ie=>ie.status==="needs_review"),O=j==="waiting_input"||g.some(ie=>ie.status==="waiting_input"),Z=f.points[0],pe=f.fontSize||12,Le=pe*1.4,_e=a.get(f.id),ge=f.text.replace(/\n/g," "),lt=_e!==void 0?_e+". "+ge:ge,Xe=p?.current?.getContext("2d")??document.createElement("canvas").getContext("2d");if(!Xe)continue;Xe.font=`${pe}px ${vn}`;let ce=Z.x-i,Ae=ni(ce),ft=oi(Xe,lt,Ae),G=Xe.measureText(ft).width,se=Re&&!!o&&!o.has(f.id)&&!g.some(ie=>o.has(ie.id));C.push({id:f.id,threadId:Ee,linkedSelector:f.linkedSelector||g.find(ie=>ie.linkedSelector)?.linkedSelector,x:Z.x+G+4,y:Z.y-4,size:Le+8,color:f.color,isInFlight:Re,isQueued:se,queuePosition:void 0,isNeedsReview:K,isQuestion:O,replyCount:fe})}let k=C.filter(f=>f.isQueued);if(k.length>0&&k.forEach((f,g)=>{f.queuePosition=r?.get(f.id)??`(${g+1}/${k.length})`}),C.length===0)return null;let E=2,$=p?.current?.getContext("2d")??document.createElement("canvas").getContext("2d"),Q=C.map(f=>{let g;f.isQueued?g=f.queuePosition?`queued ${f.queuePosition}`:"queued":f.isInFlight?g=Fi[I]??"thinking":f.isQuestion?g="? Question":f.replyCount>0?g=`${f.replyCount} ${f.replyCount===1?"reply":"replies"}`:g="View";let j=!f.isQueued,fe=j?11:0,Re=j?4:0,le=g.length*7.2;return $&&($.font=`12px ${vn}`,le=$.measureText(g).width),4+fe+Re+le+4}),V=ju(u),M=[];for(let f=0;f<C.length;f++){let g=C[f].y-s,j=C[f].x-i,fe=Hs(V,j,Q[f]),Re=Al(g,C[f].size,fe),le=Re+C[f].size,Ce=j;for(let Ee=0;Ee<f;Ee++){let K=C[Ee].y-s,O=Hs(V,M[Ee],Q[Ee]),Z=Al(K,C[Ee].size,O),pe=Z+C[Ee].size;if(!(Re<pe&&le>Z))continue;let _e=M[Ee]+Q[Ee];Ce<_e+E&&(Ce=_e+E)}M.push(Ce)}let B={position:"fixed",inset:0,pointerEvents:"none",zIndex:9999,"--popmelt-scroll-x":`${i}px`,"--popmelt-scroll-y":`${s}px`};return Ut("div",{ref:m,"data-devtools":"annotation-badge-layer",style:B,children:C.map((f,g)=>{let j=!!f.threadId,fe=Hs(V,M[g],Q[g]);return Ut(Yu,{left:M[g]+i-ii,top:f.y-ii,scrollX:i,scrollY:s,avoidTop:fe.avoidTop,avoidBottom:fe.avoidBottom,onMouseDown:j?Re=>Re.stopPropagation():void 0,onClick:j?Re=>{if(Re.stopPropagation(),d?.(f.id),l?.(f.threadId),f.linkedSelector)try{let le=document.querySelector(f.linkedSelector);if(le){let Ce=le.getBoundingClientRect();(Ce.bottom<0||Ce.top>window.innerHeight)&&le.scrollIntoView({behavior:"smooth",block:"center"})}}catch{}}:void 0,onMouseEnter:c?()=>c(f.id):void 0,onMouseLeave:c?()=>c(null):void 0,style:{pointerEvents:j?"auto":"none",cursor:j?"pointer":void 0,zIndex:9999},children:Ut("div",{"data-devtools":"annotation-badge",style:{height:f.size,display:"flex",alignItems:"center",backgroundColor:f.color,fontFamily:vn,fontSize:12,color:"#ffffff",userSelect:"none",padding:`0 ${4}px`,gap:4,whiteSpace:"nowrap"},children:f.isQueued?Or("span",{style:{opacity:.5,color:"inherit"},children:["queued",f.queuePosition?` ${f.queuePosition}`:""]}):f.isInFlight?Or(ri,{children:[Ut("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"currentColor",style:{verticalAlign:"middle"},children:v===1?Or(ri,{children:[Ut("circle",{cx:"7",cy:"7",r:"2"}),Ut("circle",{cx:"17",cy:"7",r:"2"}),Ut("circle",{cx:"7",cy:"17",r:"2"}),Ut("circle",{cx:"17",cy:"17",r:"2"})]}):Or(ri,{children:[Ut("circle",{cx:"12",cy:"6",r:"2"}),Ut("circle",{cx:"6",cy:"12",r:"2"}),Ut("circle",{cx:"18",cy:"12",r:"2"}),Ut("circle",{cx:"12",cy:"18",r:"2"})]})}),Ut("span",{style:{opacity:.7,color:"inherit"},children:Fi[I]})]}):Or(ri,{children:[f.isQuestion||f.isNeedsReview?Ut("span",{style:{fontWeight:700,color:"inherit"},children:"?"}):Ut("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:Ut("polyline",{points:"4 12 10 18 20 6"})}),Ut("span",{style:{opacity:.7,color:"inherit"},children:f.isQuestion?"Question":f.replyCount>0?`${f.replyCount} ${f.replyCount===1?"reply":"replies"}`:"View"})]})})},f.id)})})}function zs({inFlightSelectorColors:e,animated:t=!0}){let[n,o]=Fs([]);return Ns(()=>{if(e.size===0){o([]);return}let r=null,i=()=>{let l=[];for(let[d,c]of e){let p=En(d);if(!p)continue;let u=p.getBoundingClientRect();l.push({selector:d,top:u.top,left:u.left,width:u.width,height:u.height,color:c})}o(l)},s=()=>{r&&cancelAnimationFrame(r),r=requestAnimationFrame(i)};i(),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s,!0);let a=new MutationObserver(s);return a.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class"]}),()=>{window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s,!0),a.disconnect(),r&&cancelAnimationFrame(r)}},[e]),n.length===0?null:Or(ri,{children:[t&&Ut("style",{children:"@keyframes popmelt-march { to { stroke-dashoffset: -6; } }"}),n.map(r=>Ut("div",{"data-devtools":"marching-ants",style:{position:"fixed",top:r.top,left:r.left,width:r.width,height:r.height,pointerEvents:"none",zIndex:9995,overflow:"visible"},children:Ut("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible"},children:Ut("rect",{x:"0.5",y:"0.5",width:Math.max(0,r.width-1),height:Math.max(0,r.height-1),fill:"none",stroke:r.color,strokeWidth:"1",strokeDasharray:"2 4",style:t?{animation:"popmelt-march 0.5s steps(2) infinite"}:void 0})})},r.selector))]})}function zi(e){let t=new Set,n=new Map;for(let i of e){if(!i.linkedSelector)continue;let s=n.get(i.linkedSelector)||[];s.push(i),n.set(i.linkedSelector,s)}let o=new Set,r=new Set;for(let i of n.values()){if(i.length<=1){i[0]?.groupId&&r.add(i[0].groupId);continue}i.sort((a,l)=>l.timestamp-a.timestamp);let s=i[0];s.groupId&&r.add(s.groupId);for(let a=1;a<i.length;a++){let l=i[a];t.add(l),l.groupId&&o.add(l.groupId)}}for(let i of e)i.groupId&&o.has(i.groupId)&&!r.has(i.groupId)&&t.add(i);return t}import{useEffect as Bl,useLayoutEffect as Vu,useState as Dl}from"react";import{jsx as $s,jsxs as _l}from"react/jsx-runtime";function Uu(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}var Ol=["top-left","top-right","bottom-right","bottom-left"];function Hl({element:e,radius:t,accentColor:n,hoveredCorner:o,draggingCorner:r,cursorViewport:i}){let[s,a]=Dl(null),[l,d]=Dl(!1);if(Bl(()=>{let P=k=>{(k.key==="Meta"||k.key==="Control")&&d(!0)},N=k=>{(k.key==="Meta"||k.key==="Control")&&d(!1)},C=()=>d(!1);return window.addEventListener("keydown",P,!0),window.addEventListener("keyup",N,!0),window.addEventListener("blur",C),()=>{window.removeEventListener("keydown",P,!0),window.removeEventListener("keyup",N,!0),window.removeEventListener("blur",C)}},[]),Bl(()=>{if(!e){a(null);return}let P=()=>{a(e.getBoundingClientRect())};return P(),window.addEventListener("scroll",P,{passive:!0}),window.addEventListener("resize",P,{passive:!0}),()=>{window.removeEventListener("scroll",P),window.removeEventListener("resize",P)}},[e]),Vu(()=>{e&&a(e.getBoundingClientRect())},[e,t["top-left"],t["top-right"],t["bottom-right"],t["bottom-left"]]),!s)return null;let c=s.width,p=s.height,u=Uu(n,.2),m={"top-left":{x:0,y:t["top-left"]},"top-right":{x:c,y:t["top-right"]},"bottom-right":{x:c,y:p-t["bottom-right"]},"bottom-left":{x:0,y:p-t["bottom-left"]}},v=new Set,b=r??o;if(b)if(l)v.add(b);else for(let P of Ol)v.add(P);let I={position:"fixed",top:s.top,left:s.left,width:c,height:p,pointerEvents:"none",zIndex:9996,overflow:"visible"};return _l("div",{"data-devtools":"border-radius-handles",style:I,children:[_l("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:`0 0 ${c} ${p}`,children:[$s("rect",{x:"0.5",y:"0.5",width:Math.max(0,c-1),height:Math.max(0,p-1),fill:"none",stroke:u,strokeWidth:"1"}),Ol.map(P=>{let N=m[P],C=v.has(P);return $s("circle",{cx:N.x,cy:N.y,r:P===(r??o)?3:2.5,fill:n,stroke:"#ffffff",strokeWidth:P===(r??o)?4:2,paintOrder:"stroke"},P)})]}),i&&b&&(()=>{let P=Math.round(t[b]);return $s("div",{style:{position:"fixed",left:i.x+8,top:i.y-28,background:n,color:"#fff",fontSize:11,fontWeight:600,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1,padding:"4px 4px",borderRadius:0,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9997},children:P})})()]})}import{useEffect as Ku,useState as Xu}from"react";function pr(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);if(n)return`oklch(${n[1]} / ${t})`;let o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(o){let r=parseInt(o[1],16),i=parseInt(o[2],16),s=parseInt(o[3],16);return`rgba(${r}, ${i}, ${s}, ${t})`}return`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}import{Fragment as qu,jsx as Ws,jsxs as _r}from"react/jsx-runtime";function yo({element:e,isSelected:t=!1,elementInfo:n,color:o="#3b82f6",annotationNumber:r,changeCount:i,hideTooltip:s=!1}){let[a,l]=Xu(null);if(Ku(()=>{if(!e){l(null);return}let E=()=>{let $=e.getBoundingClientRect();l($)};return E(),window.addEventListener("scroll",E,{passive:!0}),window.addEventListener("resize",E,{passive:!0}),()=>{window.removeEventListener("scroll",E),window.removeEventListener("resize",E)}},[e]),!a||!e)return null;let d={position:"fixed",top:a.top,left:a.left,width:a.width,height:a.height,pointerEvents:"none",zIndex:9996,overflow:"visible"},c=e.tagName.toLowerCase(),p=e.id?`#${e.id}`:"",u=e.classList.length>0?"."+Array.from(e.classList).slice(0,2).join("."):"",m=n?.reactComponent,v=m?`<${m}> ${c}${p}${u}`:`${c}${p}${u}`,b=22,I=a.height>=window.innerHeight,P=I?0:a.top>=b?a.top-b:a.bottom,N=I?{position:"absolute",top:8,left:8,zIndex:9997,display:"flex",alignItems:"center",gap:6,backgroundColor:o,color:"#fff",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',padding:"4px 8px",borderRadius:0,pointerEvents:"none",whiteSpace:"nowrap",maxWidth:400}:{position:"fixed",top:P,left:a.left,zIndex:9997,display:"flex",alignItems:"center",gap:6,backgroundColor:o,color:"#fff",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',padding:"4px 8px",borderRadius:0,pointerEvents:"none",whiteSpace:"nowrap",maxWidth:400},k=!s&&_r("div",{"data-devtools":"tooltip",style:N,children:[r!==void 0&&_r("span",{children:[r,"."]}),Ws("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,minWidth:0},children:v}),i!==void 0&&i>0&&_r("span",{style:{opacity:.8},children:["(",i," ",i===1?"change":"changes",")"]})]});return _r(qu,{children:[_r("div",{"data-devtools":"highlight",style:d,children:[_r("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},children:[Ws("rect",{x:"2.5",y:"2.5",width:Math.max(0,a.width-5),height:Math.max(0,a.height-5),fill:pr(o,.05),stroke:"none"}),Ws("rect",{x:"0.5",y:"0.5",width:Math.max(0,a.width-1),height:Math.max(0,a.height-1),fill:"none",stroke:o,strokeWidth:"1",...!t&&{strokeDasharray:"2 4"}})]}),I&&k]}),!I&&k]})}import{useEffect as Nl,useLayoutEffect as Zu,useState as js}from"react";import{jsx as Po,jsxs as Js}from"react/jsx-runtime";function Gs(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}function Ys({element:e,gap:t,accentColor:n,hoveredAxis:o,draggingAxis:r,cursorViewport:i,isAutoGap:s=!1,refreshKey:a=0}){let[l,d]=js(null),[c,p]=js([]),[u,m]=js(!1);if(Nl(()=>{let V=f=>{(f.key==="Meta"||f.key==="Control")&&m(!0)},M=f=>{(f.key==="Meta"||f.key==="Control")&&m(!1)},B=()=>m(!1);return window.addEventListener("keydown",V,!0),window.addEventListener("keyup",M,!0),window.addEventListener("blur",B),()=>{window.removeEventListener("keydown",V,!0),window.removeEventListener("keyup",M,!0),window.removeEventListener("blur",B)}},[]),Nl(()=>{if(!e){d(null),p([]);return}let V=()=>{d(e.getBoundingClientRect()),p(Ao(e))};return V(),window.addEventListener("scroll",V,{passive:!0}),window.addEventListener("resize",V,{passive:!0}),()=>{window.removeEventListener("scroll",V),window.removeEventListener("resize",V)}},[e]),Zu(()=>{e&&(d(e.getBoundingClientRect()),p(Ao(e)))},[e,t.row,t.column,a]),!l||c.length===0)return null;let v=l.width,b=l.height,I="pm-gap-stripe-pattern",P=Gs(n,.25),N=Gs(n,.1),C=Gs(n,.2),k=8,E=2,$={position:"fixed",top:l.top,left:l.left,width:v,height:b,pointerEvents:"none",zIndex:9996,overflow:"visible"},Q=r??o;return Js("div",{"data-devtools":"gap-handles",style:$,children:[Js("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:`0 0 ${v} ${b}`,children:[Po("defs",{children:Po("pattern",{id:I,patternUnits:"userSpaceOnUse",width:"4",height:"4",patternTransform:"rotate(45)",children:Po("line",{x1:"0",y1:"0",x2:"0",y2:"4",stroke:P,strokeWidth:"1.5"})})}),Po("rect",{x:"0.5",y:"0.5",width:Math.max(0,v-1),height:Math.max(0,b-1),fill:"none",stroke:C,strokeWidth:"1"}),c.map((V,M)=>{let B=V.x-l.left,f=V.y-l.top,g=V.w,j=V.h,fe=u?V.axis===Q:!0;return(V.axis==="row"?t.row:t.column)===0?null:Js("g",{opacity:fe?1:.6,children:[Po("rect",{x:B,y:f,width:g,height:j,fill:N}),Po("rect",{x:B,y:f,width:g,height:j,fill:`url(#${I})`})]},M)}),Q&&(()=>{let V=c.filter(Z=>Z.axis===Q);if(V.length===0)return null;let M=V[0];if(i&&V.length>1){let Z=1/0;for(let pe of V){let Le=pe.x+pe.w/2,_e=pe.y+pe.h/2,ge=Math.abs(i.x-Le)+Math.abs(i.y-_e);ge<Z&&(Z=ge,M=pe)}}let B=M.x-l.left,f=M.y-l.top,g=M.w,j=M.h,fe=B+g/2,Re=f+j/2;if(s)return Po("circle",{cx:fe,cy:Re,r:1.5,fill:n,stroke:"#ffffff",strokeWidth:4,paintOrder:"stroke"});let le=Q==="column",Ce=le?E:k,Ee=le?k:E,K=fe-Ce/2,O=Re-Ee/2;return Po("rect",{x:K,y:O,width:Ce,height:Ee,fill:n,stroke:"#ffffff",strokeWidth:4,paintOrder:"stroke"})})()]}),i&&Q&&(()=>{let V=s?"auto":String(Math.round(Q==="row"?t.row:t.column));return Po("div",{style:{position:"fixed",left:i.x+8,top:i.y-28,background:n,color:"#fff",fontSize:11,fontWeight:600,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1,padding:"4px 4px",borderRadius:0,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9997},children:V})})()]})}import{useCallback as op,useEffect as rp,useState as ip}from"react";import{useEffect as Qu,useState as Fl}from"react";var ep=3,tp=250,Vs=["reviewing","considering","thinking","zhuzhing","iterating","tweaking","reflecting","noodling","pondering","finessing","polishing","riffing"],np=3e3;function zl(e){let[t,n]=Fl(0),[o,r]=Fl(()=>Math.floor(Math.random()*Vs.length));return Qu(()=>{if(!e)return;let i=setInterval(()=>n(a=>(a+1)%ep),tp),s=setInterval(()=>r(a=>(a+1)%Vs.length),np);return()=>{clearInterval(i),clearInterval(s)}},[e]),{charIndex:t,word:Vs[o]}}import{Fragment as Us,jsx as Fn,jsxs as Hr}from"react/jsx-runtime";function sp(e){let{element:t}=e,n=t.tagName,o=t.id?`#${t.id}`:"",r=t.className?"."+t.className.split(" ").slice(0,2).join("."):"",i=t.reactComponent;return i?`<${i}> ${n}${o}${r}`:`${n}${o}${r}`}var $l=22,si=12,$i=8;function ap(e,t,n){if(n.avoidLeft===void 0&&n.avoidRight===void 0)return!0;let o=typeof window<"u"?window.innerWidth:9999,r=n.avoidLeft??0,i=n.avoidRight??o;return e+t>r&&e<i}function lp(e,t,n){return ap(t,n,e)?e:{}}function cp(e){let t=`(${e.changeCount} ${e.changeCount===1?"change":"changes"})`;return Math.min(400,44+e.label.length*7.2+t.length*7.2)}function dp(e,t,n,o){let r=n!==void 0?`${n}px`:"0px",i=o!==void 0?`${o}px`:"100vh";return`translate(min(0px, calc(100vw - max(0px, ${e}px) - 100%)), min(max(0px, calc(${r} - max(0px, ${t}px))), calc(${i} - max(0px, ${t}px) - 100%)))`}function up({left:e,top:t,avoidTop:n,avoidBottom:o,style:r,children:i,...s}){let a=e+si,l=t+si;return Fn("div",{"data-devtools":"badge-hit-area",...s,style:{position:"fixed",left:`max(0px, ${e}px)`,top:`max(0px, ${t}px)`,padding:si,...r},children:Fn("div",{style:{transform:dp(a,l,n,o)},children:i})})}function Wl({styleModifications:e,isInspecting:t,accentColor:n,annotationGroupCount:o,dispatch:r,inFlightSelectors:i,toolbarRef:s,onHoverSelector:a}){let[l,d]=ip([]),c=i&&i.size>0,{charIndex:p,word:u}=zl(!!c);rp(()=>{if(t){d([]);return}let C=null,k=()=>{let Q=[];e.forEach((V,M)=>{let B=En(V.selector);if(!B)return;let f=B.getBoundingClientRect();Q.push({selector:V.selector,modIndex:M,top:f.top>=$l?f.top-$l:f.bottom,left:f.left,label:sp(V),changeCount:V.changes.length,annotationNumber:o+M+1})}),d(Q)},E=()=>{C&&cancelAnimationFrame(C),C=requestAnimationFrame(k)};k(),window.addEventListener("scroll",E,!0),window.addEventListener("resize",E,!0);let $=new MutationObserver(E);return $.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class"]}),window.addEventListener("load",E),document.fonts.ready.then(E),()=>{window.removeEventListener("scroll",E,!0),window.removeEventListener("resize",E,!0),window.removeEventListener("load",E),$.disconnect(),C&&cancelAnimationFrame(C)}},[e,t,o]);let m=op(C=>{let k=e[C];if(!k)return;let E=En(k.selector);E&&(r({type:"SELECT_ANNOTATION",payload:{id:null}}),r({type:"SET_TOOL",payload:"inspector"}),r({type:"SELECT_ELEMENT",payload:{el:E,info:k.element}}))},[e,r]);if(l.length===0)return null;let v=s?.current?.getBoundingClientRect(),b=v?v.top<window.innerHeight/2:!1,I=v?{avoidTop:b?v.bottom+$i:void 0,avoidBottom:b?void 0:v.top-$i,avoidLeft:v.left-$i,avoidRight:v.right+$i}:{},P={display:"flex",alignItems:"center",gap:6,backgroundColor:n,color:"#fff",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',padding:"4px 8px",borderRadius:0,whiteSpace:"nowrap",maxWidth:400},N={overflow:"hidden",textOverflow:"ellipsis",flex:1,minWidth:0};return Fn(Us,{children:l.map(C=>{let k=i?.has(C.selector),E=lp(I,C.left,cp(C));return Fn(up,{left:C.left-si,top:C.top-si,avoidTop:E.avoidTop,avoidBottom:E.avoidBottom,onClick:()=>m(C.modIndex),onMouseEnter:a?()=>a(C.selector):void 0,onMouseLeave:a?()=>a(null):void 0,style:{zIndex:1e4,cursor:"pointer",pointerEvents:"auto"},children:Hr("div",{"data-devtools":"badge",style:{...P,backgroundColor:k?"#999999":n},children:[Hr("span",{children:[C.annotationNumber,"."]}),Fn("span",{style:N,children:C.label}),Hr("span",{style:{opacity:.8},children:["(",C.changeCount," ",C.changeCount===1?"change":"changes",")"]}),k&&Hr("span",{style:{opacity:.8,marginLeft:4,display:"inline-flex",alignItems:"center",gap:4},children:[Fn("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"currentColor",style:{verticalAlign:"middle"},children:p===1?Hr(Us,{children:[Fn("circle",{cx:"7",cy:"7",r:"2"}),Fn("circle",{cx:"17",cy:"7",r:"2"}),Fn("circle",{cx:"7",cy:"17",r:"2"}),Fn("circle",{cx:"17",cy:"17",r:"2"})]}):Hr(Us,{children:[Fn("circle",{cx:"12",cy:"6",r:"2"}),Fn("circle",{cx:"6",cy:"12",r:"2"}),Fn("circle",{cx:"18",cy:"12",r:"2"}),Fn("circle",{cx:"12",cy:"18",r:"2"})]})}),u]})]})},C.selector)})})}import{useEffect as pp,useState as fp}from"react";import{Fragment as mp,jsx as jl}from"react/jsx-runtime";function gp(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}function Gl({styleModifications:e,accentColor:t}){let[n,o]=fp([]);if(pp(()=>{let i=null,s=()=>{let d=[];for(let c of e){let p=En(c.selector);if(!p)continue;let u=p.getBoundingClientRect();if(u.width===0&&u.height===0)continue;let m=ur(p);d.push({selector:c.selector,top:u.top,left:u.left,width:u.width,height:u.height,borderRadius:`${m["top-left"]}px ${m["top-right"]}px ${m["bottom-right"]}px ${m["bottom-left"]}px`})}o(d)},a=()=>{i&&cancelAnimationFrame(i),i=requestAnimationFrame(s)};s(),window.addEventListener("scroll",a,{passive:!0}),window.addEventListener("resize",a,{passive:!0});let l=new MutationObserver(a);return l.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class"]}),()=>{window.removeEventListener("scroll",a),window.removeEventListener("resize",a),l.disconnect(),i&&cancelAnimationFrame(i)}},[e]),n.length===0)return null;let r=gp(t,.2);return jl(mp,{children:n.map(i=>{let s={position:"fixed",top:i.top,left:i.left,width:i.width,height:i.height,pointerEvents:"none",zIndex:9995,border:`1px solid ${r}`,borderRadius:i.borderRadius,boxSizing:"border-box"};return jl("div",{"data-devtools":"mod-border",style:s},i.selector)})})}import{useEffect as Jl,useLayoutEffect as hp,useState as Yl}from"react";import{jsx as Go,jsxs as Xs}from"react/jsx-runtime";function Ks(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}var yp={top:"bottom",bottom:"top",left:"right",right:"left"};function qs({element:e,padding:t,accentColor:n,hoveredSide:o,draggingSide:r,cursorViewport:i,refreshKey:s}){let[a,l]=Yl(null),[d,c]=Yl(!1);if(Jl(()=>{let g=Re=>{(Re.key==="Meta"||Re.key==="Control")&&c(!0)},j=Re=>{(Re.key==="Meta"||Re.key==="Control")&&c(!1)},fe=()=>c(!1);return window.addEventListener("keydown",g,!0),window.addEventListener("keyup",j,!0),window.addEventListener("blur",fe),()=>{window.removeEventListener("keydown",g,!0),window.removeEventListener("keyup",j,!0),window.removeEventListener("blur",fe)}},[]),Jl(()=>{if(!e){l(null);return}let g=()=>{l(e.getBoundingClientRect())};return g(),window.addEventListener("scroll",g,{passive:!0}),window.addEventListener("resize",g,{passive:!0}),()=>{window.removeEventListener("scroll",g),window.removeEventListener("resize",g)}},[e]),hp(()=>{e&&l(e.getBoundingClientRect())},[e,t.top,t.right,t.bottom,t.left,s]),!a)return null;let p=a.width,u=a.height,{top:m,right:v,bottom:b,left:I}=t,P="pm-stripe-pattern",N=Ks(n,.25),C=Ks(n,.1),k=Ks(n,.2),E=8,$=2,Q={position:"fixed",top:a.top,left:a.left,width:p,height:u,pointerEvents:"none",zIndex:9996,overflow:"visible"},V=["top","right","bottom","left"],M={top:`0,0 ${p},0 ${p-v},${m} ${I},${m}`,right:`${p},0 ${p},${u} ${p-v},${u-b} ${p-v},${m}`,bottom:`0,${u} ${I},${u-b} ${p-v},${u-b} ${p},${u}`,left:`0,0 ${I},${m} ${I},${u-b} 0,${u}`},B={top:{x:p/2-E/2,y:m/2-$/2,w:E,h:$},bottom:{x:p/2-E/2,y:u-b/2-$/2,w:E,h:$},left:{x:I/2-$/2,y:u/2-E/2,w:$,h:E},right:{x:p-v/2-$/2,y:u/2-E/2,w:$,h:E}},f=new Set;return r?f.add(r):o&&(f.add(o),d||f.add(yp[o])),Xs("div",{"data-devtools":"padding-handles",style:Q,children:[Xs("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:`0 0 ${p} ${u}`,children:[Go("defs",{children:Go("pattern",{id:P,patternUnits:"userSpaceOnUse",width:"4",height:"4",patternTransform:"rotate(45)",children:Go("line",{x1:"0",y1:"0",x2:"0",y2:"4",stroke:N,strokeWidth:"1.5"})})}),Go("rect",{x:"0.5",y:"0.5",width:Math.max(0,p-1),height:Math.max(0,u-1),fill:"none",stroke:k,strokeWidth:"1"}),V.map(g=>{if(t[g]<=0)return null;let fe=f.has(g);return Xs("g",{opacity:fe?1:.6,children:[Go("polygon",{points:M[g],fill:C}),Go("polygon",{points:M[g],fill:`url(#${P})`})]},g)}),V.map(g=>{let j=B[g],fe=f.has(g);return Go("rect",{x:j.x,y:j.y,width:j.w,height:j.h,fill:n,stroke:"#ffffff",strokeWidth:fe?4:2,paintOrder:"stroke"},`handle-${g}`)})]}),i&&(o||r)&&(()=>{let j=Math.round(t[r??o]);return Go("div",{style:{position:"fixed",left:i.x+8,top:i.y-28,background:n,color:"#fff",fontSize:11,fontWeight:600,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1,padding:"4px 4px",borderRadius:0,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9997},children:j})})()]})}import{useCallback as bo,useEffect as qn,useMemo as Ki,useRef as $n,useState as Sn}from"react";import{Check as Ui,ChevronDown as ia,MoveHorizontal as rc,Shrink as Wp}from"lucide-react";var bp="data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPScxMicgaGVpZ2h0PScxMic+PGRlZnM+PHBhdHRlcm4gaWQ9J2QnIHdpZHRoPSc0JyBoZWlnaHQ9JzQnIHBhdHRlcm5Vbml0cz0ndXNlclNwYWNlT25Vc2UnPjxwYXRoIGQ9J00tMSwxIGwyLC0yIE0wLDQgbDQsLTQgTTMsNSBsMiwtMicgc3Ryb2tlPSdibGFjaycgc3Ryb2tlLXdpZHRoPScuNScvPjwvcGF0dGVybj48L2RlZnM+PHJlY3Qgd2lkdGg9JzEyJyBoZWlnaHQ9JzEyJyBmaWxsPSd1cmwoI2QpJy8+PC9zdmc+",Nr={borderWidth:3,borderStyle:"solid",borderImage:`url("${bp}") 4 / 1.9 / 0 round`};function Wi({color:e="rgb(0,0,0)",animated:t=!1}={}){let n=`<svg xmlns='http://www.w3.org/2000/svg' width='5' height='5'><path d='M-1,1 l2,-2 M0,5 l5,-5 M4,6 l2,-2' stroke='${e}' stroke-width='.75'/></svg>`;return{position:"absolute",inset:-3,padding:5,backgroundImage:`url("data:image/svg+xml,${encodeURIComponent(n)}")`,backgroundSize:"5px 5px",WebkitMask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",WebkitMaskComposite:"xor",mask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",maskComposite:"exclude",pointerEvents:"none",...t?{animation:"popmelt-border-march 0.8s linear infinite"}:{}}}var ji={"font-size":["rem","px","em"],"line-height":["","rem","px","em"],"letter-spacing":["rem","px","em"],gap:["rem","px","em"],"column-gap":["rem","px","em"],"row-gap":["rem","px","em"],padding:["rem","px","em","%"],margin:["rem","px","em","%"],width:["rem","px","%","em"],height:["rem","px","%","em"],"min-width":["rem","px","%","em"],"max-width":["rem","px","%","em"],"min-height":["rem","px","%","em"],"max-height":["rem","px","%","em"],"border-width":["px","rem","em"],"border-radius":["rem","px","%","em"]};function Fr(e){return ji[e]?.[0]??"px"}function Jo(e){let t=e.match(/^([\d.-]+)(.*)$/);return t?{num:parseFloat(t[1]),unit:t[2]||""}:{num:0,unit:""}}function Gi(e,t,n,o){let r=e.trim();if(!r)return"";let i=r.match(/^(-?[\d.]+)\s*(rem|em|px|%)$/i);if(i)return`${parseFloat(i[1])}${i[2].toLowerCase()}`;let s=parseFloat(r);if(!isNaN(s)){if(o){let{unit:a}=Jo(n);return`${s}${a||Fr(t)}`}return`${s}${Fr(t)}`}return r}function Zs(e,t){if(!t||t==="px")return e;if(t==="rem"){let n=parseFloat(getComputedStyle(document.documentElement).fontSize)||16;return Math.round(e/n*1e3)/1e3}return e}import{useCallback as vp,useEffect as xp,useRef as Vl,useState as Sp}from"react";import{Plus as Ul,X as wp}from"lucide-react";import{jsx as zn,jsxs as fr}from"react/jsx-runtime";var Ji=[{name:"blur",label:"Blur",unit:"px",defaultValue:10,min:0,max:100,step:1},{name:"brightness",label:"Brightness",unit:"",defaultValue:1,min:0,max:3,step:.05},{name:"contrast",label:"Contrast",unit:"",defaultValue:1,min:0,max:3,step:.05},{name:"saturate",label:"Saturate",unit:"",defaultValue:1,min:0,max:3,step:.05},{name:"grayscale",label:"Grayscale",unit:"",defaultValue:0,min:0,max:1,step:.05},{name:"sepia",label:"Sepia",unit:"",defaultValue:0,min:0,max:1,step:.05},{name:"invert",label:"Invert",unit:"",defaultValue:0,min:0,max:1,step:.05},{name:"hue-rotate",label:"Hue Rotate",unit:"deg",defaultValue:0,min:0,max:360,step:1},{name:"opacity",label:"Opacity",unit:"",defaultValue:1,min:0,max:1,step:.05}];function Cp(e){if(!e||e==="none")return[];let t=[],n=/([\w-]+)\(([^)]+)\)/g,o;for(;(o=n.exec(e))!==null;){let r=o[1],i=o[2],s=parseFloat(i);isNaN(s)||t.push({name:r,value:s})}return t}function Qs(e){return e.length===0?"none":e.map(t=>{let o=Ji.find(r=>r.name===t.name)?.unit??"";return`${t.name}(${t.value}${o})`}).join(" ")}function Kl({value:e,onChange:t,accentColor:n,modified:o,panelContentRef:r}){let i=Cp(e),[s,a]=Sp(!1),l=Vl(null),d=Vl(null);xp(()=>{if(!s)return;let C=k=>{l.current&&!k.composedPath().includes(l.current)&&a(!1)};return document.addEventListener("mousedown",C,!0),()=>document.removeEventListener("mousedown",C,!0)},[s]);let c=Ji.filter(C=>!i.some(k=>k.name===C.name)),p=C=>{let k=[...i,{name:C.name,value:C.defaultValue}];t(Qs(k)),a(!1)},u=C=>{let k=i.filter((E,$)=>$!==C);t(Qs(k))},m=(C,k)=>{let E=i.map(($,Q)=>Q===C?{...$,value:k}:$);t(Qs(E))},v={width:"100%",padding:"4px 8px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',border:"none",borderRadius:2,outline:"none",backgroundColor:"transparent"},b=vp(C=>{if(!d.current)return{position:"fixed",top:0,left:0};let k=d.current.getBoundingClientRect(),E=r?.current?.getBoundingClientRect(),$=C*24+8;return{position:"fixed",...window.innerHeight-k.bottom<$?{bottom:window.innerHeight-k.top+2}:{top:k.bottom+2},left:E?E.left+4:k.left,width:E?E.width-8:140,zIndex:10001}},[r]),I={backgroundColor:"rgba(255, 255, 255, 0.95)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:"1px solid rgba(0,0,0,0.1)",borderRadius:4,padding:"4px 0",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},P={display:"block",width:"100%",padding:"4px 10px",border:"none",backgroundColor:"transparent",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#334155",cursor:"pointer",textAlign:"left"},N=C=>zn("div",{ref:l,style:{...b(C.length),...I},children:C.map(k=>zn("button",{type:"button",onClick:()=>p(k),style:P,onMouseEnter:E=>{E.currentTarget.style.backgroundColor="rgba(0,0,0,0.05)"},onMouseLeave:E=>{E.currentTarget.style.backgroundColor="transparent"},children:k.label},k.name))});return i.length===0?fr("div",{children:[fr("div",{style:{display:"flex",alignItems:"center",gap:4},children:[zn(Bo,{modified:!1,children:zn("input",{type:"text",value:"",placeholder:"\u2014",readOnly:!0,style:{...v,color:"#999",cursor:"default"}})}),zn("button",{ref:d,type:"button",onClick:()=>a(!s),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",borderRadius:2,backgroundColor:"transparent",color:"#94a3b8",cursor:"pointer",flexShrink:0},children:zn(Ul,{size:12})})]}),s&&N(Ji)]}):fr("div",{style:{display:"flex",flexDirection:"column",gap:4,position:"relative"},children:[i.map((C,k)=>{let E=Ji.find($=>$.name===C.name);return E?fr("div",{style:{display:"flex",alignItems:"center",gap:4},children:[zn("span",{style:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:o?n:"#94a3b8",fontWeight:o?600:400,width:56,flexShrink:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:E.label}),zn(Bo,{modified:o,children:fr("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"0 4px"},children:[zn("input",{type:"range",min:E.min,max:E.max,step:E.step,value:C.value,onChange:$=>m(k,parseFloat($.target.value)),style:{flex:1,height:2,appearance:"none",WebkitAppearance:"none",background:`linear-gradient(to right, ${n} ${(C.value-E.min)/(E.max-E.min)*100}%, rgba(0,0,0,0.1) ${(C.value-E.min)/(E.max-E.min)*100}%)`,borderRadius:1,outline:"none",cursor:"pointer"}}),zn("input",{type:"number",min:E.min,max:E.max,step:E.step,value:E.unit==="px"||E.unit==="deg"?Math.round(C.value):Math.round(C.value*100)/100,onChange:$=>m(k,parseFloat($.target.value)||0),style:{...v,width:44,padding:"2px 4px",textAlign:"right",flexShrink:0}}),E.unit&&zn("span",{style:{fontSize:9,color:"#94a3b8",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',flexShrink:0,width:16},children:E.unit})]})}),zn("button",{type:"button",onClick:()=>u(k),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,padding:0,border:"none",borderRadius:2,backgroundColor:"transparent",color:"#94a3b8",cursor:"pointer",flexShrink:0},children:zn(wp,{size:10})})]},C.name):null}),c.length>0&&fr("div",{children:[fr("button",{ref:d,type:"button",onClick:()=>a(!s),style:{display:"flex",alignItems:"center",gap:4,padding:"2px 4px",border:"none",borderRadius:2,backgroundColor:"transparent",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#94a3b8",cursor:"pointer"},children:[zn(Ul,{size:10}),"Add filter"]}),s&&N(c)]})]})}import{useCallback as ao,useEffect as Mp,useRef as Yi,useState as Xl}from"react";import{AlignHorizontalSpaceAround as Ip,AlignVerticalSpaceAround as Rp,Columns3 as Lp,Grid2x2 as Ap,RectangleHorizontal as Pp,Rows3 as Bp,UnfoldHorizontal as ql,UnfoldVertical as Zl}from"lucide-react";import{useCallback as Ep,useEffect as Tp,useRef as ai}from"react";import{jsx as kp}from"react/jsx-runtime";var ea=[0,1,2,4,8,12,16,20,24,28,32];function zr({value:e,onChange:t,onPreview:n,onScrubEnd:o,onReset:r,isModified:i,accentColor:s,defaultUnit:a="rem",snapSteps:l,color:d,style:c,children:p}){let u=ai(null),m=ai(null),v=ai(r),b=ai(i),I=ai(!1);v.current=r,b.current=i,Tp(()=>{let N=k=>{let E=m.current;if(!E)return;E.hasMoved=!0,I.current=k.shiftKey;let $=E.unit==="rem"||E.unit==="em"?.1:1;E.accum+=k.movementX*$;let Q=Math.max(0,Math.round((E.startValue+E.accum)*10)/10);if(k.shiftKey&&l){let V=E.unit==="rem"||E.unit==="em"?parseFloat(getComputedStyle(document.documentElement).fontSize)||16:1,M=E.unit==="rem"||E.unit==="em"?Q*V:Q,B=l[l.length-1];for(let f=0;f<l.length-1;f++){let g=l[f],j=l[f+1];if(M<=(g+j)/2){B=g;break}if(M<j){B=j;break}}M>l[l.length-1]&&(B=Math.round(M/8)*8),Q=E.unit==="rem"||E.unit==="em"?Math.round(B/V*1e3)/1e3:B}n?.(`${Q}${E.unit}`)},C=()=>{let k=m.current;if(!k)return;let E=Math.max(0,Math.round((k.startValue+k.accum)*10)/10);if(I.current&&l){let Q=k.unit==="rem"||k.unit==="em"?parseFloat(getComputedStyle(document.documentElement).fontSize)||16:1,V=k.unit==="rem"||k.unit==="em"?E*Q:E,M=l[l.length-1];for(let B=0;B<l.length-1;B++){let f=l[B],g=l[B+1];if(V<=(f+g)/2){M=f;break}if(V<g){M=g;break}}V>l[l.length-1]&&(M=Math.round(V/8)*8),E=k.unit==="rem"||k.unit==="em"?Math.round(M/Q*1e3)/1e3:M}let $=k.hasMoved&&E!==k.startValue;m.current=null,document.exitPointerLock(),$?t(`${E}${k.unit}`):k.hasMoved?n?.(`${k.startValue}${k.unit}`):b.current&&v.current&&v.current(),o?.()};return document.addEventListener("mousemove",N),document.addEventListener("mouseup",C),()=>{document.removeEventListener("mousemove",N),document.removeEventListener("mouseup",C)}},[t,n,o]);let P=Ep(N=>{if(N.button!==0)return;N.preventDefault();let C=Jo(e),k=C.unit&&C.unit!=="px"?C.unit:a;m.current={startValue:C.num,unit:k,accum:0,hasMoved:!1},u.current?.requestPointerLock()},[e,a]);return kp("span",{ref:u,onMouseDown:P,title:i?"Click to reset \xB7 Drag to scrub":"Drag to scrub",style:{color:i?s||"#3b82f6":d||"#999",padding:"0 4px",display:"flex",alignItems:"center",cursor:"ew-resize",...c},children:p})}import{Fragment as ta,jsx as De,jsxs as mn}from"react/jsx-runtime";function Dp({gridCols:e,gridRows:t,gridModified:n,accentColor:o,onColsChange:r,onRowsChange:i}){return De(Gn,{style:{width:100},children:mn("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"8px 4px"},children:[De("input",{type:"number",min:1,max:12,value:e,onChange:s=>r(parseInt(s.target.value)||1),style:{...xn,width:32,textAlign:"center",padding:2}}),De("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:n?o:"#999",fontWeight:n?600:400,fontSize:11,margin:"0 4px"},children:"\xD7"}),De("input",{type:"number",min:1,max:12,value:t,onChange:s=>i(parseInt(s.target.value)||1),style:{...xn,width:32,textAlign:"center",padding:2}})]})})}function Ql({element:e,getValue:t,getOriginalValue:n,handleChange:o,isModified:r,onResetProperty:i,isCollapsed:s,onToggle:a,sectionHeaderStyle:l,activeDropdown:d,onDropdownChange:c,panelContentRef:p,accentColor:u,onFieldHover:m,preferredUnit:v,onUnitCycle:b}){let I=c,P=t("display"),N=t("flex-direction"),C=ec(P,N),k=P==="flex"||P==="inline-flex",E=P==="grid",$=k||E,Q=N==="column"||N==="column-reverse",V=t("width"),M=t("height"),B=r("width")?V:Bi(e,"width"),f=r("height")?M:Bi(e,"height"),g=na(V,B),j=na(M,f),fe=t("min-width"),Re=t("max-width"),le=t("min-height"),Ce=t("max-height"),Ee=$r(t("padding")),K=t("gap"),O=t("row-gap"),Z=t("column-gap"),pe=t("grid-template-columns"),Le=t("grid-template-rows"),_e=t("overflow"),ge=pe.split(/\s+/).filter(U=>U&&U!=="none").length||1,lt=Le.split(/\s+/).filter(U=>U&&U!=="none").length||1,[Xe,ce]=Xl(!1),Ae=d!==null,ft=Ae||Xe,G=Ae?.3:Xe?.65:1,se=({mode:U,icon:Te,active:Ue})=>De("button",{type:"button",onClick:()=>tc(U,o),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:"6px 8px",border:"none",borderRadius:2,backgroundColor:Ue?pr(u,.15):"transparent",color:Ue?u:"#64748b",cursor:"pointer",fontSize:14},children:Te}),ie=(U,Te,Ue)=>{Ue==="fixed"?o(U,Te):o(U,Vi(Ue,Te))},Ne=U=>{let Te=$r(t("padding")),Ue=U||"0";o("padding",`${Te.top} ${Ue} ${Te.bottom} ${Ue}`)},rt=U=>{let Te=$r(t("padding")),Ue=U||"0";o("padding",`${Ue} ${Te.right} ${Ue} ${Te.left}`)},[Ie,et]=Xl({}),it=ao((U,Te)=>Ue=>{Te(Ue),et(ht=>({...ht,[U]:Ue}))},[]),qe=ao(U=>{et(Te=>{let Ue={...Te};return delete Ue[U],Ue})},[]),Rt=ao(U=>{let Te=$r(t("padding"));Ve(e,"padding",`${Te.top} ${U} ${Te.bottom} ${U}`)},[e,t]),Kt=ao(U=>{let Te=$r(t("padding"));Ve(e,"padding",`${U} ${Te.right} ${U} ${Te.left}`)},[e,t]),Dt=ao(U=>Te=>{Ve(e,U,Te)},[e]),Ge=Q?"row":"column",W=Ge==="row"?"row-gap":"column-gap",ye=W==="row-gap"?O||K:Z||K,Se=r(W)||r("gap"),He=ao(()=>{let Te=Ao(e).find(ht=>ht.axis===Ge);if(Te)return Ge==="row"?Te.h:Te.w;let Ue=dr(e);return Ge==="row"?Ue.row:Ue.column},[e,Ge]),tt=ao(()=>{let U=t("justify-content");return U==="space-between"?"between":U==="space-around"||U==="space-evenly"?"around":"fixed"},[t])(),Gt=ao((U,Te)=>{if(U==="fixed"){let Ue=Math.max(0,Math.round(He()*1e3)/1e3),ht=Te||(Ue>0?`${Ue}px`:"8px");o("justify-content","normal"),o(W,ht);return}o("justify-content",U==="between"?"space-between":"space-around"),o(W,"0px")},[W,He,o]),Jt=ao(U=>{if(tt!=="fixed"){Gt("fixed",U);return}o(W,U)},[Gt,tt,W,o]),Bt=ao(U=>{Ve(e,"justify-content","normal"),Ve(e,W,U)},[e,W]),un=U=>U==="center"?1:U==="flex-end"||U==="end"?2:0,gt=un(t("justify-content")),Lt=un(t("align-items")),st=Q?Lt:gt,Yt=Q?gt:Lt,eo=Yi(null),sn=Yi({x:0,y:0}),Un=Yi({col:st,row:Yt});Un.current={col:st,row:Yt};let fo=ao((U,Te)=>{let Ue=["flex-start","center","flex-end"];Q?(o("justify-content",Ue[Te]),o("align-items",Ue[U])):(o("justify-content",Ue[U]),o("align-items",Ue[Te]))},[Q,o]),On=Yi(fo);On.current=fo,Mp(()=>{let Te=Ue=>{let ht=eo.current;if(!ht||!Ue.composedPath().includes(ht))return;Ue.preventDefault(),Ue.stopPropagation(),sn.current.x+=Ue.deltaX,sn.current.y+=Ue.deltaY;let{col:mt,row:Pe}=Un.current,ct=!1;Math.abs(sn.current.x)>=30&&(mt=Math.max(0,Math.min(2,mt+(sn.current.x>0?1:-1))),sn.current.x=0,sn.current.y=0,ct=!0),!ct&&Math.abs(sn.current.y)>=30&&(Pe=Math.max(0,Math.min(2,Pe+(sn.current.y>0?1:-1))),sn.current.x=0,sn.current.y=0,ct=!0),ct&&(mt!==Un.current.col||Pe!==Un.current.row)&&On.current(mt,Pe)};return document.addEventListener("wheel",Te,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",Te,{capture:!0})},[]);let nt=()=>De("div",{ref:eo,onMouseEnter:()=>{ce(!0),p.current&&(p.current.style.overflowY="hidden")},onMouseLeave:()=>{ce(!1),p.current&&(p.current.style.overflowY="auto")},style:{width:56,height:56,backgroundColor:Xn,borderRadius:2,display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gridTemplateRows:"repeat(3, 1fr)",padding:6,gap:2,touchAction:"none"},children:[0,1,2].map(U=>[0,1,2].map(Te=>De("button",{type:"button",onClick:()=>fo(Te,U),style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",border:"none",backgroundColor:"transparent",cursor:"pointer",padding:0},children:Te===st&&U===Yt?De("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",style:{flexShrink:0},children:Te===0?mn(ta,{children:[De("rect",{x:"1",y:"1.5",width:"8",height:"1.2",rx:"0.5",fill:u}),De("rect",{x:"1",y:"4.4",width:"5",height:"1.2",rx:"0.5",fill:u}),De("rect",{x:"1",y:"7.3",width:"7",height:"1.2",rx:"0.5",fill:u})]}):Te===1?mn(ta,{children:[De("rect",{x:"1",y:"1.5",width:"8",height:"1.2",rx:"0.5",fill:u}),De("rect",{x:"2.5",y:"4.4",width:"5",height:"1.2",rx:"0.5",fill:u}),De("rect",{x:"1.5",y:"7.3",width:"7",height:"1.2",rx:"0.5",fill:u})]}):mn(ta,{children:[De("rect",{x:"1",y:"1.5",width:"8",height:"1.2",rx:"0.5",fill:u}),De("rect",{x:"4",y:"4.4",width:"5",height:"1.2",rx:"0.5",fill:u}),De("rect",{x:"2",y:"7.3",width:"7",height:"1.2",rx:"0.5",fill:u})]})}):De("div",{style:{width:5,height:5,borderRadius:"50%",backgroundColor:"#aaa"}})},`${U}-${Te}`)))}),at=r("grid-template-columns")||r("grid-template-rows");return mn("div",{style:{borderBottom:"1px solid rgba(0,0,0,0.08)"},children:[De("div",{style:l,children:De("span",{children:$?"Auto layout":"Layout"})}),mn("div",{style:{padding:"8px 12px"},children:[mn("div",{style:{display:"flex",gap:2,marginBottom:8,backgroundColor:Xn,borderRadius:2,padding:2,opacity:G,transition:"opacity 150ms ease"},children:[De(se,{mode:"block",icon:De(Pp,{size:16}),active:C==="block"}),De(se,{mode:"flex-col",icon:De(Bp,{size:16}),active:C==="flex-col"}),De(se,{mode:"flex-row",icon:De(Lp,{size:16}),active:C==="flex-row"}),De(se,{mode:"grid",icon:De(Ap,{size:16}),active:C==="grid"})]}),mn("div",{style:{display:"flex",gap:4,marginBottom:8},children:[De(oa,{label:"W",property:"width",cssValue:g==="fixed"?V:`${Math.round(e.getBoundingClientRect().width)}px`,mode:g,onValueChange:U=>o("width",U),onModeChange:U=>{if(U==="fixed"){let Te=e.getBoundingClientRect();o("width",`${Math.round(Te.width)}px`)}else o("width",Vi(U,V))},modified:r("width"),dimmed:Ae&&d!=="width",dropdownOpen:d==="width",onDropdownChange:U=>I(U?"width":null),panelContentRef:p,accentColor:u,onReset:()=>i("width"),minValue:fe!=="none"&&fe!=="0px"&&fe!=="auto"?fe:"",maxValue:Re!=="none"&&Re!=="auto"?Re:"",onMinChange:U=>o("min-width",U||"0"),onMaxChange:U=>o("max-width",U||"none"),onMinReset:()=>i("min-width"),onMaxReset:()=>i("max-width"),minModified:r("min-width"),maxModified:r("max-width")}),De(oa,{label:"H",property:"height",cssValue:j==="fixed"?M:`${Math.round(e.getBoundingClientRect().height)}px`,mode:j,onValueChange:U=>o("height",U),onModeChange:U=>{if(U==="fixed"){let Te=e.getBoundingClientRect();o("height",`${Math.round(Te.height)}px`)}else o("height",Vi(U,M))},modified:r("height"),dimmed:Ae&&d!=="height",dropdownOpen:d==="height",onDropdownChange:U=>I(U?"height":null),panelContentRef:p,minValue:le!=="none"&&le!=="0px"&&le!=="auto"?le:"",maxValue:Ce!=="none"&&Ce!=="auto"?Ce:"",onMinChange:U=>o("min-height",U||"0"),onMaxChange:U=>o("max-height",U||"none"),onMinReset:()=>i("min-height"),onMaxReset:()=>i("max-height"),minModified:r("min-height"),maxModified:r("max-height"),accentColor:u,onReset:()=>i("height")})]}),k&&mn("div",{onMouseEnter:()=>m?.("gap"),onMouseLeave:()=>m?.("element"),style:{display:"flex",gap:8,marginBottom:8},children:[De("div",{style:{opacity:Ae?.3:1,transition:"opacity 150ms ease"},children:nt()}),mn("div",{style:{flex:1,opacity:G,transition:"opacity 150ms ease"},children:[De("div",{onClick:Se?()=>{i(W),i("gap")}:void 0,title:Se?"Click to reset":void 0,style:{fontSize:9,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:Se?u:"#999",fontWeight:Se?600:400,marginBottom:2,cursor:Se?"pointer":"default"},children:"Gap"}),De("div",{style:{display:"flex",gap:2,marginBottom:4,backgroundColor:Xn,borderRadius:2,padding:2},children:["fixed","between","around"].map(U=>{let Te=tt===U;return De("button",{type:"button",onClick:()=>Gt(U),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:"4px 6px",border:"none",borderRadius:2,backgroundColor:Te?pr(u,.15):"transparent",color:Te?u:"#64748b",cursor:"pointer",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',fontWeight:Te?600:400,textTransform:"capitalize"},children:U},U)})}),De(Gn,{dimmed:Ae,children:mn("div",{style:{display:"flex",alignItems:"center"},children:[De(zr,{value:ye,onChange:U=>{qe("gap"),Jt(U)},onPreview:it("gap",Bt),onScrubEnd:()=>qe("gap"),onReset:()=>{i(W),i("gap")},isModified:Se,accentColor:u,defaultUnit:v,children:N==="column"||N==="column-reverse"?De(Zl,{size:12,strokeWidth:Se?2.5:1.5}):De(ql,{size:12,strokeWidth:Se?2.5:1.5})}),De(lo,{property:W,value:Ie.gap||(tt==="fixed"?ye:`${Math.max(0,Math.round(He()*1e3)/1e3)}px`),onChange:U=>Jt(U),isModified:Se||"gap"in Ie,style:{...xn,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:v,onUnitCycle:b})]})})]})]}),E&&mn("div",{onMouseEnter:()=>m?.("gap"),onMouseLeave:()=>m?.("element"),style:{display:"flex",gap:8,marginBottom:8,opacity:G,transition:"opacity 150ms ease"},children:[De(Dp,{gridCols:ge,gridRows:lt,gridModified:at,accentColor:u,onColsChange:U=>o("grid-template-columns",`repeat(${U}, 1fr)`),onRowsChange:U=>o("grid-template-rows",`repeat(${U}, 1fr)`)}),mn("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:4},children:[De(Gn,{dimmed:Ae,children:mn("div",{style:{display:"flex",alignItems:"center"},children:[De(zr,{value:Z||K,onChange:U=>{qe("column-gap"),o("column-gap",U)},onPreview:it("column-gap",Dt("column-gap")),onScrubEnd:()=>qe("column-gap"),onReset:()=>i("column-gap"),isModified:r("column-gap"),accentColor:u,defaultUnit:v,children:De(ql,{size:12,strokeWidth:r("column-gap")?2.5:1.5})}),De(lo,{property:"column-gap",value:Ie["column-gap"]||Z||K,onChange:U=>o("column-gap",U),isModified:r("column-gap")||"column-gap"in Ie,placeholder:"col",style:{...xn,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:v,onUnitCycle:b})]})}),De(Gn,{dimmed:Ae,children:mn("div",{style:{display:"flex",alignItems:"center"},children:[De(zr,{value:O||K,onChange:U=>{qe("row-gap"),o("row-gap",U)},onPreview:it("row-gap",Dt("row-gap")),onScrubEnd:()=>qe("row-gap"),onReset:()=>i("row-gap"),isModified:r("row-gap"),accentColor:u,defaultUnit:v,children:De(Zl,{size:12,strokeWidth:r("row-gap")?2.5:1.5})}),De(lo,{property:"row-gap",value:Ie["row-gap"]||O||K,onChange:U=>o("row-gap",U),isModified:r("row-gap")||"row-gap"in Ie,placeholder:"row",style:{...xn,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:v,onUnitCycle:b})]})})]})]}),$&&mn("div",{onMouseEnter:()=>m?.("padding"),onMouseLeave:()=>m?.("element"),style:{display:"flex",gap:4,marginBottom:8,opacity:G,transition:"opacity 150ms ease"},children:[De(Gn,{style:{flex:1},dimmed:Ae,children:mn("div",{style:{display:"flex",alignItems:"center"},children:[De(zr,{value:Ee.left,onChange:U=>{qe("padding-h"),Ne(U)},onPreview:it("padding-h",Rt),onScrubEnd:()=>qe("padding-h"),onReset:()=>i("padding"),isModified:r("padding"),accentColor:u,defaultUnit:v,snapSteps:ea,children:De(Ip,{size:12,strokeWidth:r("padding")?2.5:1.5})}),De(lo,{property:"padding",value:Ie["padding-h"]||Ee.left,onChange:U=>Ne(U),isModified:r("padding")||"padding-h"in Ie,placeholder:"H pad",style:{...xn,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:v,onUnitCycle:b})]})}),De(Gn,{style:{flex:1},dimmed:Ae,children:mn("div",{style:{display:"flex",alignItems:"center"},children:[De(zr,{value:Ee.top,onChange:U=>{qe("padding-v"),rt(U)},onPreview:it("padding-v",Kt),onScrubEnd:()=>qe("padding-v"),onReset:()=>i("padding"),isModified:r("padding"),accentColor:u,defaultUnit:v,snapSteps:ea,children:De(Rp,{size:12,strokeWidth:r("padding")?2.5:1.5})}),De(lo,{property:"padding",value:Ie["padding-v"]||Ee.top,onChange:U=>rt(U),isModified:r("padding")||"padding-v"in Ie,placeholder:"V pad",style:{...xn,flex:1,minWidth:0},unitStyle:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",padding:"0 8px"},preferredUnit:v,onUnitCycle:b})]})})]}),mn("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#64748b",opacity:G,transition:"opacity 150ms ease"},children:[De("input",{type:"checkbox",checked:_e==="hidden",onChange:U=>o("overflow",U.target.checked?"hidden":"visible"),style:{margin:0,accentColor:u}}),"Clip content"]})]})]})}import{AlignCenter as Op,AlignJustify as _p,AlignLeft as Hp,AlignRight as Np,Baseline as Fp,ChevronDown as zp,WholeWord as $p}from"lucide-react";import{jsx as Mt,jsxs as Do}from"react/jsx-runtime";var nc={100:"Thin",200:"Extra Light",300:"Light",400:"Regular",500:"Medium",600:"Semi Bold",700:"Bold",800:"Extra Bold",900:"Black"};function oc({element:e,getValue:t,handleChange:n,isModified:o,onResetProperty:r,isCollapsed:i,onToggle:s,sectionHeaderStyle:a,accentColor:l,colorVariables:d,activeColorDropdown:c,onColorDropdownChange:p,panelContentRef:u,preferredUnit:m,onUnitCycle:v}){let b=t("font-family"),I=t("font-size"),P=t("font-weight"),N=t("line-height"),C=t("letter-spacing"),k=t("text-align"),E=t("color"),$=String(P),Q=nc[$]||$,V=Ar(e,E),M=E.includes("var(")?null:ei(V,d),B=({align:g,icon:j})=>{let fe=k===g;return Mt("button",{type:"button",onClick:()=>n("text-align",g),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:"6px 8px",border:"none",borderRadius:2,backgroundColor:fe?pr(l,.15):"transparent",color:fe?l:"#64748b",cursor:"pointer"},children:j})},f=b.split(",")[0]?.trim().replace(/^["']|["']$/g,"")||"System";return Do("div",{style:{borderBottom:"1px solid rgba(0,0,0,0.08)"},children:[Mt("div",{style:a,children:Mt("span",{children:"Typography"})}),Do("div",{style:{padding:"8px 12px",display:"flex",flexDirection:"column",gap:4},children:[Mt(Gn,{children:Do("div",{style:{display:"flex",alignItems:"center",padding:"6px 8px"},children:[Mt("input",{type:"text",value:b,onChange:g=>n("font-family",g.target.value),style:{...xn,flex:1,minWidth:0,padding:0,fontWeight:o("font-family")?600:400,color:o("font-family")?l:"inherit"},title:b}),Mt(zp,{size:12,style:{color:"#999",flexShrink:0,marginLeft:4}})]})}),Do("div",{style:{display:"flex",gap:4},children:[Mt(Gn,{style:{flex:1},children:Mt("select",{value:$,onChange:g=>n("font-weight",g.target.value),style:{...xn,padding:"6px 8px",paddingLeft:4,paddingRight:20,cursor:"pointer",fontWeight:o("font-weight")?600:400,color:o("font-weight")?l:"inherit"},children:Object.entries(nc).map(([g,j])=>Mt("option",{value:g,children:j},g))})}),Mt(Gn,{style:{flex:1},children:Mt("div",{style:{display:"flex",alignItems:"center",position:"relative"},children:Mt(lo,{property:"font-size",value:I,onChange:g=>n("font-size",g),isModified:o("font-size"),min:1,max:999,style:{...xn,padding:"6px 8px",paddingRight:24,fontWeight:o("font-size")?600:400,color:o("font-size")?l:"inherit"},unitStyle:{position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999"},preferredUnit:m,onUnitCycle:v})})})]}),Do("div",{style:{display:"flex",gap:4},children:[Mt(Gn,{style:{flex:1},children:Do("div",{style:{display:"flex",alignItems:"center",padding:"6px 8px",gap:4},children:[Mt(Fp,{size:12,style:{color:o("line-height")?l:"#999",flexShrink:0}}),Mt(lo,{property:"line-height",value:N,onChange:g=>n("line-height",g),isModified:o("line-height"),step:.1,min:0,placeholder:"Auto",style:{...xn,flex:1,minWidth:0,padding:0,fontWeight:o("line-height")?600:400,color:o("line-height")?l:"inherit"},showUnit:!1})]})}),Mt(Gn,{style:{flex:1},children:Do("div",{style:{display:"flex",alignItems:"center",padding:"6px 8px",gap:4},children:[Mt($p,{size:12,style:{color:o("letter-spacing")?l:"#999",flexShrink:0}}),Mt(lo,{property:"letter-spacing",value:C,onChange:g=>n("letter-spacing",g),isModified:o("letter-spacing"),step:.1,placeholder:"\u2014",style:{...xn,flex:1,minWidth:0,padding:0,fontWeight:o("letter-spacing")?600:400,color:o("letter-spacing")?l:"inherit"},showUnit:!1})]})})]}),Do("div",{style:{display:"flex",gap:2,backgroundColor:Xn,borderRadius:2,padding:2},children:[Mt(B,{align:"left",icon:Mt(Hp,{size:14})}),Mt(B,{align:"center",icon:Mt(Op,{size:14})}),Mt(B,{align:"right",icon:Mt(Np,{size:14})}),Mt(B,{align:"justify",icon:Mt(_p,{size:14})})]}),Do("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0"},children:[Mt("span",{onClick:o("color")?()=>r("color"):void 0,title:o("color")?"Click to reset":void 0,style:{fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:o("color")?l:"#64748b",fontWeight:o("color")?600:400,cursor:o("color")?"pointer":"default",width:40,flexShrink:0},children:"Color"}),Mt("div",{style:{flex:1,minWidth:0},children:Mt(ra,{value:E,resolvedValue:V,colorVariables:d,matchingVariable:M,onChange:g=>n("color",g),accentColor:l,modified:o("color"),panelContentRef:u,isDropdownOpen:c==="color",onDropdownChange:g=>p(g?"color":null)})})]})]})]})}import{Fragment as Gp,jsx as be,jsxs as jt}from"react/jsx-runtime";var ic=[{name:"Background",properties:[{property:"background-color",label:"Color",type:"color"},{property:"opacity",label:"Opacity",type:"number",step:.1,min:0,max:1}]},{name:"Borders",properties:[{property:"border-width",label:"Width",type:"number",min:0,max:20},{property:"border-color",label:"Color",type:"color"},{property:"border-radius",label:"Radius",type:"number",min:0,max:100},{property:"border-style",label:"Style",type:"select",options:["none","solid","dashed","dotted","double"]}]},{name:"Effects",properties:[{property:"box-shadow",label:"Box Shadow",type:"text"},{property:"backdrop-filter",label:"Backdrop Filter",type:"backdrop-filter"},{property:"transform",label:"Transform",type:"text"}]}];function jp(e,t){let n=t.trim().toLowerCase();switch(e){case"opacity":return n==="1";case"border-width":return n==="0px"||n==="0"||n==="medium";case"border-radius":return n==="0px"||n==="0";case"border-style":return n==="none";case"box-shadow":return n==="none";case"backdrop-filter":return n==="none"||n==="";case"letter-spacing":return n==="normal"||n==="0px"||n==="0";case"background-color":return n==="rgba(0, 0, 0, 0)"||n==="transparent";default:return!1}}function na(e,t){return!t||e==="auto"||e==="fit-content"||e==="max-content"||e==="min-content"?"hug":e==="100%"||t==="100%"?"fill":"fixed"}function Vi(e,t){switch(e){case"hug":return"fit-content";case"fill":return"100%";case"fixed":{let n=Jo(t);if(typeof n.num=="number"&&!isNaN(n.num)){let o=n.unit==="%"?"px":n.unit||"px";return`${n.num}${o}`}return"auto"}}}function $r(e){let t=e.split(/\s+/).filter(Boolean);return t.length===1?{top:t[0],right:t[0],bottom:t[0],left:t[0]}:t.length===2?{top:t[0],right:t[1],bottom:t[0],left:t[1]}:t.length===3?{top:t[0],right:t[1],bottom:t[2],left:t[1]}:t.length>=4?{top:t[0],right:t[1],bottom:t[2],left:t[3]}:{top:"0px",right:"0px",bottom:"0px",left:"0px"}}function ec(e,t){return e==="grid"?"grid":e==="flex"||e==="inline-flex"?t==="column"||t==="column-reverse"?"flex-col":"flex-row":"block"}function tc(e,t){switch(e){case"block":t("display","block");break;case"flex-row":t("display","flex"),t("flex-direction","row");break;case"flex-col":t("display","flex"),t("flex-direction","column");break;case"grid":t("display","grid");break}}var Xn="rgba(0, 0, 0, 0.04)",xn={width:"100%",padding:"4px 8px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',border:"none",borderRadius:2,outline:"none",backgroundColor:"transparent"};function oa({label:e,property:t,cssValue:n,mode:o,onValueChange:r,onModeChange:i,modified:s,dimmed:a,dropdownOpen:l,onDropdownChange:d,panelContentRef:c,accentColor:p="#3b82f6",onReset:u,minValue:m,maxValue:v,onMinChange:b,onMaxChange:I,onMinReset:P,onMaxReset:N,minModified:C,maxModified:k}){let E=Jo(n),$=s?E.unit||Fr(t):Fr(t),Q=!s&&E.unit&&E.unit!==$?Zs(E.num,$):E.num,[V,M]=Sn(!1),[B,f]=Sn(String(Q)),[g,j]=Sn(!1),fe=$n(null),Re=$n(null),le=$n(null),Ce=$n(!1);qn(()=>{V||f(String(Q))},[Q,V]),qn(()=>{if(!l)return;let ge=Xe=>{Re.current&&!Xe.composedPath().includes(Re.current)&&le.current&&!Xe.composedPath().includes(le.current)&&d?.(!1)},lt=Xe=>{Xe.key==="Escape"&&d?.(!1)};return document.addEventListener("mousedown",ge),document.addEventListener("keydown",lt),()=>{document.removeEventListener("mousedown",ge),document.removeEventListener("keydown",lt)}},[l,d]),qn(()=>{V&&fe.current&&(fe.current.focus(),fe.current.select())},[V]);let Ee=()=>{let ge=Gi(B,t,n,s);r(ge||`${Math.max(0,parseFloat(B)||0)}${$}`),M(!1)},K=()=>{if(Ce.current){Ce.current=!1;return}Ee()},O=ge=>{if(ge.key==="Enter"){Ee();return}if(ge.key==="Escape"){Ce.current=!0,f(String(Q)),M(!1);return}if(ge.key==="ArrowUp"||ge.key==="ArrowDown"){ge.preventDefault();let lt=ge.key==="ArrowUp"?1:-1,Xe=ge.shiftKey?8:ge.altKey?.1:1,ce=parseFloat(B)||0,Ae=Math.round(Math.max(0,ce+lt*Xe)*1e3)/1e3;f(String(Ae)),r(`${Ae}${$}`)}},Z={fixed:"Fixed",hug:"Hug",fill:"Fill"},pe={fixed:be(rc,{size:12}),hug:be(Wp,{size:12}),fill:be(rc,{size:12})},Le=()=>{d?.(!l)},_e=()=>{if(!le.current||!c?.current)return{position:"absolute",top:"100%",left:-4,right:-4,width:"calc(100% + 8px)",marginTop:4};let ge=le.current.getBoundingClientRect(),lt=c.current.getBoundingClientRect();return{position:"fixed",top:ge.bottom+4,left:lt.left+4,width:lt.width-8}};return jt("div",{ref:le,onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),style:{flex:1,display:"flex",alignItems:"center",position:"relative",borderRadius:2,border:"1px solid",borderColor:V?p:g?"rgba(0,0,0,0.15)":"transparent",backgroundColor:Xn,transition:"border-color 100ms ease, opacity 150ms ease",opacity:a?.3:1},children:[be("span",{onClick:s&&u?u:void 0,title:s?"Click to reset":void 0,style:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:s?p:"#999",fontWeight:s?600:400,padding:"0 8px",flexShrink:0,cursor:s?"pointer":"default"},children:e}),o==="fixed"?V?be("input",{ref:fe,type:"text",inputMode:"numeric",value:B,onChange:ge=>f(ge.target.value),onKeyDown:O,onBlur:K,style:{...xn,flex:1,minWidth:0,padding:"4px 2px"}}):be("span",{onClick:()=>M(!0),style:{flex:1,padding:"4px 2px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',cursor:"text"},children:Q}):be("span",{style:{flex:1}}),jt("button",{type:"button",onClick:Le,style:{display:"flex",alignItems:"center",gap:2,padding:"4px 8px",border:"none",outline:"none",backgroundColor:"transparent",color:"#999",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',cursor:"pointer",flexShrink:0},children:[Z[o],be(ia,{size:12})]}),l&&jt("div",{ref:Re,style:{..._e(),backgroundColor:"#eaeaea",border:"1px solid rgba(0,0,0,0.1)",borderRadius:0,zIndex:10001,overflow:"hidden",fontSize:12,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'},children:[jt("button",{type:"button",onClick:()=>{i("fixed"),d?.(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",outline:"none",backgroundColor:o==="fixed"?"#f1f5f9":"transparent",color:"#1e293b",fontWeight:o==="fixed"?600:400,cursor:"pointer",textAlign:"left"},children:[pe.fixed,jt("span",{children:["Fixed ",t," (",n,")"]}),o==="fixed"&&be(Ui,{size:14,style:{marginLeft:"auto"}})]}),jt("button",{type:"button",onClick:()=>{i("hug"),d?.(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",outline:"none",backgroundColor:o==="hug"?"#f1f5f9":"transparent",color:"#1e293b",fontWeight:o==="hug"?600:400,cursor:"pointer",textAlign:"left"},children:[pe.hug,be("span",{children:"Hug contents"}),o==="hug"&&be(Ui,{size:14,style:{marginLeft:"auto"}})]}),jt("button",{type:"button",onClick:()=>{i("fill"),d?.(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",outline:"none",backgroundColor:o==="fill"?"#f1f5f9":"transparent",color:"#1e293b",fontWeight:o==="fill"?600:400,cursor:"pointer",textAlign:"left"},children:[pe.fill,be("span",{children:"Fill container"}),o==="fill"&&be(Ui,{size:14,style:{marginLeft:"auto"}})]}),be("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",margin:"4px 0"}}),jt("div",{style:{padding:"8px 12px",display:"flex",flexDirection:"column",gap:4},children:[jt("div",{style:{display:"flex",alignItems:"center",backgroundColor:Xn,borderRadius:2,padding:"4px 8px"},children:[be("span",{onClick:C?ge=>{ge.stopPropagation(),P?.()}:void 0,title:C?"Click to reset":void 0,style:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:C?p:"#999",fontWeight:C?600:400,marginRight:8,flexShrink:0,cursor:C?"pointer":"default"},children:"Min"}),be("input",{type:"text",value:m||"",placeholder:"\u2014",onChange:ge=>b?.(ge.target.value),onClick:ge=>ge.stopPropagation(),style:{...xn,flex:1,minWidth:0,padding:0,textAlign:"right",color:C?p:"inherit",fontWeight:C?600:400}})]}),jt("div",{style:{display:"flex",alignItems:"center",backgroundColor:Xn,borderRadius:2,padding:"4px 8px"},children:[be("span",{onClick:k?ge=>{ge.stopPropagation(),N?.()}:void 0,title:k?"Click to reset":void 0,style:{fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:k?p:"#999",fontWeight:k?600:400,marginRight:8,flexShrink:0,cursor:k?"pointer":"default"},children:"Max"}),be("input",{type:"text",value:v||"",placeholder:"\u2014",onChange:ge=>I?.(ge.target.value),onClick:ge=>ge.stopPropagation(),style:{...xn,flex:1,minWidth:0,padding:0,textAlign:"right",color:k?p:"inherit",fontWeight:k?600:400}})]})]})]})]})}function Gn({children:e,style:t,dimmed:n}){let[o,r]=Sn(!1);return be("div",{onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{position:"relative",borderRadius:2,border:"1px solid",borderColor:o?"rgba(0,0,0,0.15)":"transparent",backgroundColor:Xn,transition:"border-color 100ms ease, opacity 150ms ease",opacity:n?.3:1,...t},children:e})}function Bo({children:e}){let[t,n]=Sn(!1);return be("div",{onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),style:{position:"relative",borderRadius:2,border:"1px solid",borderColor:t?"rgba(0,0,0,0.15)":"transparent",backgroundColor:Xn,transition:"border-color 100ms ease"},children:e})}function lo({property:e,value:t,onChange:n,isModified:o=!1,step:r=1,min:i,max:s,style:a,placeholder:l,showUnit:d=!0,unitStyle:c,preferredUnit:p,onUnitCycle:u}){let m=Jo(t),v=Fr(e),b=ji[e],P=p&&b&&b.includes(p)?p:v,N=o&&m.unit||P,C=!o&&m.unit&&m.unit!==N?Zs(m.num,N):m.num,[k,E]=Sn(!1),[$,Q]=Sn(""),V=K=>{E(!0),Q(String(C||"")),requestAnimationFrame(()=>K.target.select())},M=()=>{if(E(!1),$.trim()){let K=Gi($,e,t,o);K&&n(K)}},B=K=>{let O=K.target.value;Q(O);let Z=O.trim(),pe=Z.match(/^(-?[\d.]+)\s*(rem|em|px|%)$/i),Le=Z.match(/^(-?[\d.]+)$/);if(pe){let _e=parseFloat(pe[1]);isNaN(_e)||n(`${_e}${pe[2].toLowerCase()}`)}else if(Le){let _e=parseFloat(Le[1]);isNaN(_e)||n(`${_e}${N}`)}},f=K=>{if(K.key==="Enter"){if($.trim()){let O=Gi($,e,t,o);O&&n(O)}K.target.blur();return}if(K.key==="ArrowUp"||K.key==="ArrowDown"){K.preventDefault();let O=K.shiftKey?10:K.altKey?.1:1,Z=(K.key==="ArrowUp"?1:-1)*r*O,pe=parseFloat($)||C||0,Le=Math.round((pe+Z)*1e3)/1e3;i!==void 0&&(Le=Math.max(i,Le)),s!==void 0&&(Le=Math.min(s,Le)),Q(String(Le)),n(`${Le}${N}`)}},g=/^-?[\d.]/.test(t.trim()),j=k?$:g?String(C):"",Re=k&&/\s*(rem|em|px|%)\s*$/i.test($)?"":N,le=u&&(Re==="rem"||Re==="px"),Ce={fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999",pointerEvents:"none"},Ee={...c??Ce,pointerEvents:"auto",cursor:"pointer"};return jt(Gp,{children:[be("input",{type:"text",inputMode:"decimal",value:j,onFocus:V,onBlur:M,onChange:B,onKeyDown:f,placeholder:l,style:a}),d&&Re&&be("span",{style:le?Ee:c??Ce,onClick:le?u:void 0,title:le?"Click to switch units":void 0,children:Re})]})}function ra({value:e,resolvedValue:t,colorVariables:n,matchingVariable:o,onChange:r,accentColor:i="#3b82f6",modified:s,panelContentRef:a,isDropdownOpen:l,onDropdownChange:d}){let[c,p]=Sn(!1),u=e,[m,v]=Sn(u),[b,I]=Sn(!1),[P,N]=Sn(!1),[C,k]=Sn(!1),E=$n(null),$=$n(null),Q=$n(null),V=l!==void 0?l:b,M=d||I,B=bo(()=>{if(!Q.current)return{position:"fixed",top:0,left:0,width:200};let K=Q.current.getBoundingClientRect();if(a?.current){let O=a.current.getBoundingClientRect();return{position:"fixed",top:K.bottom+4,left:O.left+4,width:O.width-8}}return{position:"fixed",top:K.bottom+4,left:K.left,width:K.width}},[a]);qn(()=>{c||v(e)},[e,c]),qn(()=>{if(!V&&!P)return;let K=Z=>{Q.current&&!Z.composedPath().includes(Q.current)&&(M(!1),N(!1))},O=Z=>{Z.key==="Escape"&&(M(!1),N(!1))};return document.addEventListener("mousedown",K),document.addEventListener("keydown",O),()=>{document.removeEventListener("mousedown",K),document.removeEventListener("keydown",O)}},[V,P]),qn(()=>{c&&E.current&&(E.current.focus(),E.current.select())},[c]);let f=Ki(()=>{if(!m||m.startsWith("#")||m.startsWith("rgb")||m.startsWith("hsl")||m.startsWith("oklch"))return[];let K=m.toLowerCase();return n.filter(O=>O.name.toLowerCase().includes(K)||O.usage.toLowerCase().includes(K)).slice(0,8)},[m,n]),g=()=>{r(m),p(!1),N(!1)},j=K=>{v(K),K.includes("var")||K.includes("--")||K.length>0&&!K.startsWith("#")?N(!0):N(!1)},fe=K=>{v(K.value),r(K.value),M(!1),N(!1),p(!1)},Re=()=>{setTimeout(()=>{!V&&!P&&g()},150)},le=K=>{K.key==="Enter"?g():K.key==="Escape"&&(v(e),p(!1),N(!1))},Ce=Ki(()=>{let K=t.trim().toLowerCase();if(K.startsWith("#"))return K.length===4?`#${K[1]}${K[1]}${K[2]}${K[2]}${K[3]}${K[3]}`:K.slice(0,7);let O=K.match(/rgba?\((\d+),?\s*(\d+),?\s*(\d+)/);if(O){let pe=parseInt(O[1],10).toString(16).padStart(2,"0"),Le=parseInt(O[2],10).toString(16).padStart(2,"0"),_e=parseInt(O[3],10).toString(16).padStart(2,"0");return`#${pe}${Le}${_e}`}let Z=K.match(/oklch\(\s*([\d.]+)/);if(Z){let pe=Math.max(0,Math.min(1,parseFloat(Z[1]))),Le=Math.round(pe*255).toString(16).padStart(2,"0");return`#${Le}${Le}${Le}`}return"#000000"},[t]);return jt("div",{ref:Q,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),style:{position:"relative",borderRadius:2,border:"1px solid",borderColor:c?i:C?"rgba(0,0,0,0.15)":"transparent",backgroundColor:Xn,transition:"border-color 100ms ease",overflow:"hidden"},children:[jt("div",{style:{display:"flex",alignItems:"center",minWidth:0},children:[jt("div",{style:{position:"relative",marginLeft:8,flexShrink:0},children:[be("input",{type:"color",value:Ce,onChange:K=>{let O=K.target.value;v(O),r(O)},style:{width:12,height:12,padding:0,border:"none",cursor:"pointer",opacity:0,position:"absolute",top:0,left:0}}),be("div",{style:{width:12,height:12,borderRadius:2,backgroundColor:t,border:"1px solid rgba(0,0,0,0.1)",pointerEvents:"none"}})]}),c?be("input",{ref:E,type:"text",value:m,onChange:K=>j(K.target.value),onKeyDown:le,onBlur:Re,style:{...xn,flex:1,minWidth:0}}):be("span",{onClick:()=>p(!0),style:{flex:1,minWidth:0,padding:"4px 8px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',cursor:"text",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:s?i:"inherit"},title:u,children:u}),n.length>0&&be("button",{type:"button",onClick:()=>M(!V),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:24,border:"none",background:"none",cursor:"pointer",color:"#999",flexShrink:0},children:be(ia,{size:12})})]}),P&&f.length>0&&be("div",{style:{...B(),backgroundColor:"#eaeaea",border:"1px solid rgba(0,0,0,0.1)",borderRadius:0,zIndex:10001,maxHeight:200,overflowY:"auto",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'},children:f.map(K=>jt("button",{type:"button",onClick:()=>fe(K),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",backgroundColor:"transparent",color:"#1e293b",cursor:"pointer",textAlign:"left",fontSize:12},children:[be("div",{style:{width:14,height:14,borderRadius:2,backgroundColor:K.value,border:"1px solid rgba(0,0,0,0.1)",flexShrink:0}}),be("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:K.name})]},K.name))}),V&&be("div",{ref:$,style:{...B(),backgroundColor:"#eaeaea",border:"1px solid rgba(0,0,0,0.1)",borderRadius:0,zIndex:10001,maxHeight:280,overflowY:"auto",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'},children:n.map(K=>jt("button",{type:"button",onClick:()=>fe(K),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"10px 12px",border:"none",backgroundColor:o?.usage===K.usage||e===K.value?"#f1f5f9":"transparent",color:"#1e293b",fontWeight:o?.usage===K.usage||e===K.value?600:400,cursor:"pointer",textAlign:"left",fontSize:12},children:[be("div",{style:{width:14,height:14,borderRadius:2,backgroundColor:K.value,border:"1px solid rgba(0,0,0,0.1)",flexShrink:0}}),be("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:K.name}),(o?.usage===K.usage||e===K.value)&&be(Ui,{size:14,style:{marginLeft:"auto",flexShrink:0}})]},K.name))})]})}function sc({element:e,elementInfo:t,selector:n,styleModifications:o,dispatch:r,onClose:i,onHover:s,accentColor:a="#3b82f6",toolbarRef:l}){let d=$n(null),c=$n(null),[p,u]=Sn(()=>{try{return!!localStorage.getItem("devtools-panel-position")}catch{return!1}});qn(()=>{if(p)return;let G=setTimeout(()=>u(!0),50);return()=>clearTimeout(G)},[p]);let[m,v]=Sn(null),[b,I]=Sn(null),P=m!==null||b!==null,[N,C]=Sn("rem"),k=bo(()=>{C(G=>G==="rem"?"px":"rem")},[]),E=$n(new Map),[$,Q]=Sn(""),V=Ki(()=>ks(),[]);qn(()=>{let G=se=>{if(se.key!=="Escape")return;let ie=document.activeElement;ie&&d.current?.contains(ie)||i()};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[i]);let M=$n({top:0,left:0,maxHeight:400}),[,B]=Sn(0),f="devtools-panel-position",g=$n({x:0,y:0}),j=$n(null),fe=$n(!1);qn(()=>{try{let G=localStorage.getItem(f);if(G){let se=JSON.parse(G);typeof se.top=="number"&&typeof se.left=="number"&&(fe.current=!0,M.current={...M.current,top:se.top,left:se.left})}}catch{}},[]),qn(()=>{let G=ie=>{let Ne=j.current;if(!Ne)return;let rt=Ne.startOffsetX+(ie.clientX-Ne.startX),Ie=Ne.startOffsetY+(ie.clientY-Ne.startY),et=280,it=16,qe=Math.max(it,Math.min(window.innerWidth-et-it,M.current.left+rt)),Rt=Math.max(it,M.current.top+Ie);g.current={x:qe-M.current.left,y:Rt-M.current.top};let Kt=d.current,Dt=Kt?.parentElement;if(!Dt)return;Dt.style.top=`${Rt}px`,Dt.style.left=`${qe}px`;let Ge=l?.current?.getBoundingClientRect(),W=window.innerHeight-16;Ge&&qe+et>Ge.left&&(W=Ge.top-8);let ye=Math.max(0,Rt),Se=Math.max(200,W-ye);Kt&&(Kt.style.maxHeight=`${Se}px`)},se=()=>{if(!j.current)return;let ie=M.current.top+g.current.y,Ne=M.current.left+g.current.x;M.current={...M.current,top:ie,left:Ne},g.current={x:0,y:0},fe.current=!0;try{localStorage.setItem(f,JSON.stringify({top:ie,left:Ne}))}catch{}j.current=null};return window.addEventListener("mousemove",G),window.addEventListener("mouseup",se),()=>{window.removeEventListener("mousemove",G),window.removeEventListener("mouseup",se)}},[]);let Re=bo(G=>{G.button!==0||G.target.closest("button")||(G.preventDefault(),j.current={startX:G.clientX,startY:G.clientY,startOffsetX:g.current.x,startOffsetY:g.current.y})},[]);qn(()=>{g.current={x:0,y:0};let G=(Ne=!1)=>{let rt=d.current,Ie=280,et=8,it,qe;if(fe.current)it=M.current.top,qe=M.current.left;else{let W=e.getBoundingClientRect();qe=W.right+et,it=W.top,qe+Ie>window.innerWidth-et&&(qe=W.left-Ie-et),qe<et&&(qe=Math.max(et,(window.innerWidth-Ie)/2))}let Rt=l?.current?.getBoundingClientRect(),Kt=window.innerHeight-16;Rt&&qe+Ie>Rt.left&&(Kt=Rt.top-et);let Dt=Math.max(0,it),Ge=Math.max(200,Kt-Dt);if(M.current={top:it,left:qe,maxHeight:Ge},Ne&&rt){let W=rt.parentElement;W&&!fe.current&&(W.style.top=`${it+g.current.y}px`,W.style.left=`${qe+g.current.x}px`),rt.style.maxHeight=`${Ge}px`}else B(W=>W+1)};G(!1);let se=()=>G(!0),ie=()=>G(!1);return window.addEventListener("scroll",se,{passive:!0}),window.addEventListener("resize",ie,{passive:!0}),()=>{window.removeEventListener("scroll",se),window.removeEventListener("resize",ie)}},[e]),qn(()=>{let G=d.current;if(!G)return;let se=ie=>{let Ne=c.current;if(!Ne){ie.preventDefault();return}let{scrollTop:rt,scrollHeight:Ie,clientHeight:et}=Ne,it=rt<=0&&ie.deltaY<0,qe=rt+et>=Ie&&ie.deltaY>0;(it||qe)&&ie.preventDefault()};return G.addEventListener("wheel",se,{passive:!1}),()=>G.removeEventListener("wheel",se)},[]);let le=Ki(()=>o.find(G=>G.selector===n),[o,n]),Ce=bo(G=>{let se=le?.changes.find(ie=>ie.property===G);return se?se.modified:Pi(e,G)},[e,le]),Ee=bo((G,se)=>{if(!G.includes("color"))return se;let ie=se.trim(),rt=V.find(Ie=>Ie.usage===ie||Ie.name===ie)?.value||ie;return Ar(e,rt)},[V,e]),K=bo(G=>{if(E.current.has(G))return E.current.get(G);let se=le?.changes.find(Ne=>Ne.property===G);if(se)return se.original;let ie=Pi(e,G);return E.current.set(G,ie),ie},[e,le]),O=bo((G,se)=>{let ie=K(G),Ne=Ee(G,se);Ve(e,G,Ne),G==="backdrop-filter"&&Ve(e,"-webkit-backdrop-filter",Ne),r({type:"MODIFY_STYLE",payload:{selector:n,element:t,property:G,original:ie,modified:Ne}})},[e,n,t,r,Ee,K]),Z=bo(G=>{o.find(Ne=>Ne.selector===n)?.changes.find(Ne=>Ne.property===G)&&e instanceof HTMLElement&&(e.style.removeProperty(G),r({type:"CLEAR_STYLE",payload:{selector:n,property:G}}),E.current.delete(G))},[e,n,o,r]),pe=bo(()=>{let G=$.split(";").map(se=>se.trim()).filter(se=>se);for(let se of G){let ie=se.indexOf(":");if(ie>0){let Ne=se.slice(0,ie).trim(),rt=se.slice(ie+1).trim();Ne&&rt&&O(Ne,rt)}}Q("")},[$,O]),Le=bo(G=>le?.changes.some(se=>se.property===G)??!1,[le]),_e=G=>{let se=Ce(G.property),ie=Le(G.property),Ne=!ie&&jp(G.property,se),rt={width:"100%",padding:"4px 8px",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',border:"none",borderRadius:2,outline:"none",backgroundColor:"transparent"};if(Ne&&G.type!=="backdrop-filter")return be(Bo,{modified:!1,children:be("input",{type:"text",value:"",placeholder:"\u2014",onFocus:()=>{},onChange:Ie=>O(G.property,Ie.target.value),style:{...rt,color:"#999"}})});switch(G.type){case"color":{let Ie=Ar(e,se),et=se.includes("var(")?null:ei(Ie,V);return be(ra,{value:se,resolvedValue:Ie,colorVariables:V,matchingVariable:et,onChange:it=>O(G.property,it),accentColor:a,modified:ie,panelContentRef:c,isDropdownOpen:b===G.property,onDropdownChange:it=>I(it?G.property:null)})}case"number":{if(!!ji[G.property])return be(Bo,{modified:ie,children:be(lo,{property:G.property,value:se,onChange:it=>O(G.property,it),isModified:ie,min:G.min,max:G.max,step:G.step||1,style:{...rt,paddingRight:32},unitStyle:{position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",fontSize:10,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#999"},preferredUnit:N,onUnitCycle:k})});let{num:et}=Jo(se);return be(Bo,{modified:ie,children:be("input",{type:"number",value:et,min:G.min,max:G.max,step:G.step||1,onChange:it=>O(G.property,it.target.value),style:rt})})}case"select":return be(Bo,{modified:ie,children:jt("div",{style:{position:"relative",display:"flex",alignItems:"center"},children:[be("select",{value:se,onChange:Ie=>O(G.property,Ie.target.value),style:{...rt,cursor:"pointer",paddingLeft:4,paddingRight:24,appearance:"none",WebkitAppearance:"none"},children:G.options?.map(Ie=>be("option",{value:Ie,children:Ie},Ie))}),be("div",{style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",pointerEvents:"none",color:"#999",display:"flex",alignItems:"center"},children:be(ia,{size:12})})]})});case"spacing":return be(Bo,{modified:ie,children:be("input",{type:"text",value:se,onChange:Ie=>O(G.property,Ie.target.value),placeholder:"e.g., 10px or 10px 20px",style:rt})});case"backdrop-filter":return be(Kl,{value:se,onChange:Ie=>O(G.property,Ie),accentColor:a,modified:ie,panelContentRef:c});default:return be(Bo,{modified:ie,children:be("input",{type:"text",value:se,onChange:Ie=>O(G.property,Ie.target.value),style:rt})})}},ge=t.reactComponent||t.tagName,lt={position:"fixed",top:M.current.top,left:M.current.left,width:280,maxHeight:M.current.maxHeight,backgroundColor:"#eaeaea",borderWidth:3,borderStyle:"solid",borderColor:"transparent",boxSizing:"content-box",zIndex:10002,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',fontSize:12,overflow:"visible",display:"flex",flexDirection:"column",opacity:p?1:0,transition:"opacity 150ms ease"},Xe={display:"flex",alignItems:"center",justifyContent:"space-between",margin:4,padding:"4px 5px 4px 10px",backgroundColor:a,color:"#ffffff",cursor:j.current?"grabbing":"grab",userSelect:"none",WebkitUserSelect:"none"},ce={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 12px 6px",userSelect:"none",fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',fontWeight:600,color:"#475569"},Ae={display:"flex",alignItems:"center",padding:"4px 12px",gap:8},ft={width:80,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',color:"#64748b",flexShrink:0};return be("div",{"data-devtools":"panel-wrapper",style:{position:"fixed",top:M.current.top+g.current.y,left:M.current.left+g.current.x,zIndex:10002,pointerEvents:"none"},children:jt("div",{ref:d,"data-devtools":"panel",style:{...lt,position:"relative",top:0,left:0,zIndex:0,pointerEvents:"auto"},onMouseEnter:()=>s?.("element"),onMouseLeave:()=>s?.(null),children:[be("div",{"aria-hidden":"true",style:Wi()}),jt("div",{style:Xe,onMouseDown:Re,children:[be("div",{style:{display:"flex",alignItems:"center",gap:3,overflow:"hidden",minWidth:0},children:be("span",{style:{fontWeight:600,fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:ge})}),be("button",{type:"button",onClick:i,title:"Close",style:{background:"none",border:"none",cursor:"pointer",fontSize:16,color:"#ffffff",padding:"0 4px",lineHeight:1,flexShrink:0},children:"\xD7"})]}),jt("div",{ref:c,style:{flex:1,overflowY:"auto",margin:"0 3px 3px"},children:[be("div",{style:{opacity:b?.3:1,transition:"opacity 150ms ease"},children:be(Ql,{element:e,getValue:Ce,getOriginalValue:K,handleChange:O,isModified:Le,onResetProperty:Z,isCollapsed:!1,onToggle:()=>{},sectionHeaderStyle:ce,activeDropdown:m,onDropdownChange:v,panelContentRef:c,accentColor:a,onFieldHover:s,preferredUnit:N,onUnitCycle:k})}),be("div",{style:{opacity:m?.3:1,transition:"opacity 150ms ease"},children:be(oc,{element:e,getValue:Ce,handleChange:O,isModified:Le,onResetProperty:Z,isCollapsed:!1,onToggle:()=>{},sectionHeaderStyle:ce,accentColor:a,colorVariables:V,activeColorDropdown:b,onColorDropdownChange:I,panelContentRef:c,preferredUnit:N,onUnitCycle:k})}),ic.map((G,se)=>{let ie=se===ic.length-1,Ne=b&&G.properties.some(Ie=>Ie.property===b);return jt("div",{style:{borderBottom:ie?"none":"1px solid rgba(0,0,0,0.08)",opacity:P&&!Ne?.3:1,transition:"opacity 150ms ease"},children:[be("div",{style:ce,children:be("span",{children:G.name})}),be("div",{style:{padding:"4px 0"},children:G.properties.map(Ie=>{let et=Le(Ie.property),it=Ne&&Ie.property!==b;return jt("div",{style:{...Ae,opacity:it?.3:1,transition:"opacity 150ms ease"},children:[be("span",{onClick:et?()=>Z(Ie.property):void 0,title:et?"Click to reset":void 0,style:{...ft,color:et?a:"#64748b",fontWeight:et?600:400,cursor:et?"pointer":"default"},children:Ie.label}),be("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:_e(Ie)})]},Ie.property)})})]},G.name)}),jt("div",{style:{opacity:P?.3:1,transition:"opacity 150ms ease"},children:[be("div",{style:ce,children:be("span",{children:"Raw CSS"})}),jt("div",{style:{padding:"8px 12px"},children:[be("textarea",{value:$,onChange:G=>Q(G.target.value),placeholder:"property: value; ...",style:{width:"100%",height:60,padding:8,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',border:"1px solid rgba(0,0,0,0.1)",borderRadius:2,resize:"vertical",outline:"none"}}),$.trim()&&be("button",{type:"button",onClick:pe,style:{marginTop:4,padding:"4px 8px",width:"100%",fontSize:11,border:"none",borderRadius:2,backgroundColor:a,color:"#fff",cursor:"pointer",opacity:$.trim()?1:.5},children:"Apply"})]})]})]})]})})}import{useEffect as Jp,useLayoutEffect as Yp,useState as Vp}from"react";import{Fragment as qp,jsx as gr,jsxs as Xp}from"react/jsx-runtime";var sa=["flex-start","center","flex-end"],aa=["flex-start","center","flex-end"];function Up(e){return e==="normal"||e==="flex-start"||e==="start"?"flex-start":e==="flex-end"||e==="end"?"flex-end":e==="center"?"center":null}function Kp(e){return e==="normal"||e==="stretch"||e==="flex-start"||e==="start"?"flex-start":e==="flex-end"||e==="end"?"flex-end":e==="center"?"center":null}function ac(e){let t=Array.from(e.children);if(t.length===0)return null;let n=1/0,o=1/0,r=-1/0,i=-1/0;for(let s of t){let a=s.getBoundingClientRect();a.width===0&&a.height===0||(a.top<n&&(n=a.top),a.left<o&&(o=a.left),a.bottom>r&&(r=a.bottom),a.right>i&&(i=a.right))}return n===1/0?null:new DOMRect(o,n,i-o,r-n)}function lc({element:e,modifier:t,accentColor:n,refreshKey:o=0}){let[r,i]=Vp(null);if(Jp(()=>{if(!e){i(null);return}let b=()=>i(ac(e));return b(),window.addEventListener("scroll",b,{passive:!0}),window.addEventListener("resize",b,{passive:!0}),()=>{window.removeEventListener("scroll",b),window.removeEventListener("resize",b)}},[e]),Yp(()=>{e&&i(ac(e))},[e,o]),!r)return null;let s=r,a=window.getComputedStyle(e),l=a.display;if(l!=="flex"&&l!=="inline-flex")return null;let d=a.flexDirection,c=d==="column"||d==="column-reverse"?"vertical":"horizontal",p=c==="horizontal"?"vertical":"horizontal",u=[];if(t==="shift"){let b=Up(a.justifyContent);if(b){let I=sa.indexOf(b);c==="horizontal"?(I>0&&u.push("left"),I<sa.length-1&&u.push("right")):(I>0&&u.push("up"),I<sa.length-1&&u.push("down"))}}else{let b=Kp(a.alignItems);if(b){let I=aa.indexOf(b);p==="horizontal"?(I>0&&u.push("left"),I<aa.length-1&&u.push("right")):(I>0&&u.push("up"),I<aa.length-1&&u.push("down"))}}if(u.length===0)return null;let m=14,v=7;return gr(qp,{children:u.map(b=>{let I,P;switch(b){case"right":I=s.right+m,P=s.top+s.height/2;break;case"left":I=s.left-m,P=s.top+s.height/2;break;case"down":I=s.left+s.width/2,P=s.bottom+m;break;case"up":I=s.left+s.width/2,P=s.top-m;break}let N=b==="right"?0:b==="left"?180:b==="down"?90:-90,C={position:"fixed",left:I-v,top:P-v,width:v*2,height:v*2,pointerEvents:"none",zIndex:9997};return gr("div",{"data-devtools":"swipe-hint",style:C,children:gr("svg",{width:v*2,height:v*2,viewBox:"-7 -7 14 14",style:{overflow:"visible"},children:Xp("g",{transform:`rotate(${N})`,children:[gr("line",{x1:"-5",y1:"0",x2:"3",y2:"0",stroke:"#fff",strokeWidth:"4",strokeLinecap:"round"}),gr("polyline",{points:"0,-4 5,0 0,4",fill:"none",stroke:"#fff",strokeWidth:"4",strokeLinecap:"round",strokeLinejoin:"round"}),gr("line",{x1:"-5",y1:"0",x2:"3",y2:"0",stroke:n,strokeWidth:"1.5",strokeLinecap:"round"}),gr("polyline",{points:"0,-4 5,0 0,4",fill:"none",stroke:n,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})},b)})})}import{useEffect as Zp,useLayoutEffect as Qp,useState as ef}from"react";import{jsx as la,jsxs as ca}from"react/jsx-runtime";function tf(e,t){let n=e.match(/^oklch\(([^)]+)\)$/i);return n?`oklch(${n[1]} / ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}function cc({element:e,fontSize:t,lineHeight:n,accentColor:o,hoveredProperty:r,draggingProperty:i,cursorViewport:s}){let[a,l]=ef(null);if(Zp(()=>{if(!e){l(null);return}let P=()=>{l(Lr(e))};return P(),window.addEventListener("scroll",P,{passive:!0}),window.addEventListener("resize",P,{passive:!0}),()=>{window.removeEventListener("scroll",P),window.removeEventListener("resize",P)}},[e]),Qp(()=>{e&&l(Lr(e))},[e,t,n]),!a)return null;let d=a.width,c=a.height,p=tf(o,.2),u=i??r,m=8,v=2,b={position:"fixed",top:a.top,left:a.left,width:d,height:c,pointerEvents:"none",zIndex:9996,overflow:"visible"},I=P=>P==="font-size"?`${Math.round(t)}`:(t>0?n/t:1.2).toFixed(2).replace(/\.?0+$/,"");return ca("div",{"data-devtools":"text-handles",style:b,children:[ca("svg",{style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:`0 0 ${d} ${c}`,children:[la("rect",{x:"0.5",y:"0.5",width:Math.max(0,d-1),height:Math.max(0,c-1),fill:"none",stroke:p,strokeWidth:"1"}),(u==="font-size"||!u)&&la("rect",{x:d-v/2,y:c/2-m/2,width:v,height:m,fill:o,stroke:"#ffffff",strokeWidth:u==="font-size"?4:2,paintOrder:"stroke"}),(u==="line-height"||!u)&&la("rect",{x:d/2-m/2,y:c-v/2,width:m,height:v,fill:o,stroke:"#ffffff",strokeWidth:u==="line-height"?4:2,paintOrder:"stroke"})]}),s&&u&&(()=>{let P=u==="font-size"?"Aa":"Lh",N=I(u);return ca("div",{style:{position:"fixed",left:s.x+8,top:s.y-28,background:o,color:"#fff",fontSize:11,fontWeight:600,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1,padding:"4px 4px",borderRadius:0,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9997},children:[P," ",N]})})()]})}import{Fragment as Jr,jsx as pt,jsxs as Gr}from"react/jsx-runtime";var dc=8,da=[0,1,2,4,8,12,16,20,24,28,32],jr=8,ua="devtools-active-text";function nf(e){let t=e?.getBoundingClientRect();return!t||typeof window>"u"?{}:t.top<window.innerHeight/2?{avoidTop:t.bottom+jr,avoidLeft:t.left-jr,avoidRight:t.right+jr}:{avoidBottom:t.top-jr,avoidLeft:t.left-jr,avoidRight:t.right+jr}}function uc(e,t,n=0,o,r,i=90){let s=e.left+window.scrollX+4,a=t==="top-left"?e.top+window.scrollY-jo-n*jo+4:e.bottom+window.scrollY+4-1+n*jo,l=window.scrollY+4,d=window.scrollY+window.innerHeight-jo-4,c=null;if(o&&r!==void 0){let p=o.getBoundingClientRect(),u=e.left+4;if(u+r+8+i>p.left&&u<p.right)if(p.top<window.innerHeight/2){let b=window.scrollY+p.bottom+4;b>l&&(l=b,c="top")}else{let b=window.scrollY+p.top-jo-4;b<d&&(d=b,c="bottom")}}return l>d&&(d=l),a<l?a=c==="top"?l:e.top+window.scrollY+4:a>d&&(a=c==="bottom"?d:Math.max(e.top+window.scrollY+4,d)),{x:s,y:a}}function pc({state:e,dispatch:t,onScreenshot:n,inFlightAnnotationIds:o,activeAnnotationIds:r,queuePositionMap:i,inFlightStyleSelectors:s,inFlightSelectorColors:a,onAttachImages:l,onViewThread:d,onCloseThread:c,onModelComponentsAdd:p,onModelComponentFocus:u,onModelComponentHover:m,modelComponentNames:v,modelPanelHoveredComponent:b,modelSpacingTokenHover:I,highlightedAnnotationIds:P,focusedThreadAnnotationId:N,externalCanvasRef:C,toolbarRef:k}){let{canvasRef:E,redrawAll:$,resizeCanvas:Q}=Il(),V=on(h=>{E.current=h,C&&(C.current=h)},[C,E]),M=Ft(!1);Tn(()=>{let h=E.current;if(!h)return;let x=()=>{M.current&&(M.current=!1,h.style.pointerEvents="")},_=y=>{y.button===0&&M.current&&x()};return window.addEventListener("mousedown",_),()=>window.removeEventListener("mousedown",_)},[E]);let[B,f]=xt(!1),[g,j]=xt(()=>{if(typeof window>"u")return null;try{let h=localStorage.getItem(ua);return h?JSON.parse(h):null}catch{return null}}),[fe,Re]=xt(null),[le,Ce]=xt(null),[Ee,K]=xt(null),O=Ft(null),Z=Ft(null),pe=Ft({x:0,y:0}),Le=Ft([]),_e=Ft(0),[ge,lt]=xt(null),[Xe,ce]=xt(new Map),Ae=Ft(0),ft=Ft(null),[G,se]=xt(null),[ie,Ne]=xt(null),[rt,Ie]=xt(null),[et,it]=xt(null),qe=Ft({isDragging:!1,side:null,startX:0,startY:0,original:{top:0,right:0,bottom:0,left:0},element:null,elementInfo:null,selector:null,durableSelector:null}),[Rt,Kt]=xt(null),[Dt,Ge]=xt(null),[W,ye]=xt(null),[Se,He]=xt(null),$t=Ft({x:0,y:0}),[tt,Gt]=xt({x:0,y:0}),Jt=Ft({isDragging:!1,hasMoved:!1,axis:null,startX:0,startY:0,originalRow:0,originalColumn:0,element:null,elementInfo:null,selector:null,durableSelector:null,isAuto:!1,originalJustifyContent:"",visualGap:0}),[Bt,un]=xt(null),[gt,Lt]=xt(null),[st,Yt]=xt(null),[eo,sn]=xt(!1),[Un,fo]=xt(0),[On,nt]=xt(null),at=Ft({isDragging:!1,corner:null,startY:0,original:{"top-left":0,"top-right":0,"bottom-right":0,"bottom-left":0},maxRadius:0,element:null,elementInfo:null,selector:null,durableSelector:null}),[Xt,U]=xt(null),[Te,Ue]=xt(null),[ht,mt]=xt(null),Pe=Ft({isDragging:!1,property:null,startX:0,startY:0,originalFontSize:0,originalLineHeight:0,originalRatio:1.2,element:null,elementInfo:null,selector:null,durableSelector:null}),[ct,to]=xt(null),[qt,_n]=xt(null),[Wt,Ho]=xt(null),Uo=Rl(),wo=Ft(a);wo.current=a;let No=on(h=>{let x=wo.current;if(!x||x.size===0)return!1;for(let _ of x.keys())try{if(h.matches(_))return!0}catch{}return!1},[]),Ko=Ft(e);Ko.current=e;let an=Ft(g);an.current=g;let Xo=Ft([]),Co=Ft(n);Co.current=n;let[Je,no]=xt(null),Ct=e.selectedAnnotationIds;Xo.current=Ct;let kn=on((h,x=!1)=>{t({type:"SELECT_ANNOTATION",payload:{id:h,addToSelection:x}})},[t]),yn=on(()=>{t({type:"SELECT_ANNOTATION",payload:{id:null}})},[t]),[An,qo]=xt(null),oo=Ft({x:window.scrollX,y:window.scrollY}),ro=Ft(null),Kn=Ft(null),[Zt,io]=xt(oo.current);Tn(()=>(Q(),window.addEventListener("resize",Q),()=>window.removeEventListener("resize",Q)),[Q]),Tn(()=>{g?localStorage.setItem(ua,JSON.stringify(g)):localStorage.removeItem(ua)},[g]),Ll(g,j,fe,e.annotations,t);let Zo=Ft(ge);Zo.current=ge,Tn(()=>{if(e.activeTool!=="model"||!e.isAnnotating)return;let h=x=>{if(!x.altKey||!Zo.current)return;x.preventDefault();let _=x.deltaY>0?-1:1;Ae.current=Math.max(0,Ae.current+_);let y=ft.current;if(y){let w=Li(y,Ae.current);lt(w)}};return window.addEventListener("wheel",h,{passive:!1}),()=>window.removeEventListener("wheel",h)},[e.activeTool,e.isAnnotating]),Tn(()=>{e.activeTool!=="model"&&(lt(null),ce(new Map),Ae.current=0,ft.current=null)},[e.activeTool]),Tn(()=>{let h=ge?.name??null,x=h&&v?.has(h)?h:null;m?.(x)},[ge,v,m]);let[Fo,zo]=xt(null);Tn(()=>{if(!b){zo(null);return}let h=Mr(b.name),x=b.instanceIndex;zo(h[x%h.length]??null)},[b]);let[Qo,$o]=xt([]);Tn(()=>{if(!I){$o([]);return}I.token?.bindings?.length?$o(ws(I.token)):$o(xs(I.px))},[I]);let A=Ft(null),F=Ft(null);A.current=Bt,F.current=gt,Tn(()=>{let h=["flex-start","center","flex-end"],x=["flex-start","center","flex-end"],y=null,w=!1,T=null,H=null,L=(de,je)=>{let ze=cr(de,je);for(;ze&&ze!==document.documentElement;){let en=window.getComputedStyle(ze).display;if(en==="flex"||en==="inline-flex")return ze;ze=ze.parentElement}return null},z=de=>{let je=window.getComputedStyle(de).flexDirection;return je==="column"||je==="column-reverse"?"vertical":"horizontal"},X=de=>{let je=de.getAttribute("data-pm");return je||(je=Math.random().toString(36).substring(2,8),de.setAttribute("data-pm",je)),{selector:`[data-pm="${je}"]`,durableSelector:jn(de)}},D=()=>{w=!0,y&&clearTimeout(y),y=setTimeout(()=>{w=!1,y=null},300)},J=(de,je,Nt)=>{let ze=z(de);if(je===ze){let Pn=window.getComputedStyle(de).justifyContent,Tt=Pn==="normal"||Pn==="flex-start"||Pn==="start"?"flex-start":Pn==="flex-end"||Pn==="end"?"flex-end":Pn==="center"?"center":null;if(!Tt)return;let tr=h.indexOf(Tt)+Nt;if(tr<0||tr>=h.length)return;let Io=h[tr],{selector:nr,durableSelector:ps}=X(de);Ve(de,"justify-content",Io),t({type:"MODIFY_STYLES_BATCH",payload:{selector:nr,durableSelector:ps,element:Dn(de),changes:[{property:"justify-content",original:Pn,modified:Io}]}})}else{let Pn=window.getComputedStyle(de).flexDirection,Tt=ze==="horizontal"?"column":"row",{selector:Mo,durableSelector:tr}=X(de);Ve(de,"flex-direction",Tt),t({type:"MODIFY_STYLES_BATCH",payload:{selector:Mo,durableSelector:tr,element:Dn(de),changes:[{property:"flex-direction",original:Pn,modified:Tt}]}})}fo(en=>en+1)},q=(de,je,Nt)=>{let en=z(de)==="horizontal"?"vertical":"horizontal";if(je!==en)return;let Tt=window.getComputedStyle(de).alignItems,Mo=Tt==="normal"||Tt==="stretch"||Tt==="flex-start"||Tt==="start"?"flex-start":Tt==="flex-end"||Tt==="end"?"flex-end":Tt==="center"?"center":null;if(!Mo)return;let Io=x.indexOf(Mo)+Nt;if(Io<0||Io>=x.length)return;let nr=x[Io],{selector:ps,durableSelector:ld}=X(de);Ve(de,"align-items",nr),t({type:"MODIFY_STYLES_BATCH",payload:{selector:ps,durableSelector:ld,element:Dn(de),changes:[{property:"align-items",original:Tt,modified:nr}]}}),fo(cd=>cd+1)},Y=20,xe=null,Me=null,Ze=0,dt=(de,je,Nt)=>{let ze=L(je,Nt);nt(ze?{modifier:de,target:ze}:null)},Qe=de=>{if(!(e.activeTool!=="hand"||!e.isAnnotating)){if(de.key==="Shift"&&!de.altKey){let je=$t.current;dt("shift",je.x,je.y)}else if(de.key==="Alt"&&!de.shiftKey){let je=$t.current;dt("alt",je.x,je.y)}}},wt=de=>{if(e.activeTool!=="hand"||!e.isAnnotating)return;let je=de.shiftKey&&!de.altKey,Nt=de.altKey&&!de.shiftKey;if(!je&&!Nt||de.buttons!==0){xe=null,Me=null,Ze=0,T=null,H=null,nt(null);return}if(T===null&&(T=de.clientX,H=de.clientY,dt(je?"shift":"alt",de.clientX,de.clientY)),w)return;xe===null&&(xe=de.clientX,Me=de.clientY,Ze=0);let ze=de.clientX-xe,en=de.clientY-Me,Pn=Math.abs(ze)>=Math.abs(en)?ze:en;if(Math.abs(Pn)>3){let nr=Pn>0?1:-1;if(Ze!==0&&nr!==Ze){xe=de.clientX,Me=de.clientY,Ze=0;return}Ze=nr}if(Math.abs(ze)<Y&&Math.abs(en)<Y)return;let Tt=L(T,H);if(!Tt)return;let Mo=Math.abs(ze)>=Math.abs(en)?"horizontal":"vertical",Io=(Mo==="horizontal"?ze:en)>0?1:-1;xe=null,Me=null,Ze=0,je?J(Tt,Mo,Io):q(Tt,Mo,Io),D()},Ht=de=>{(de.key==="Shift"||de.key==="Alt")&&(T=null,H=null,xe=null,Me=null,Ze=0,nt(null))},bt=()=>{nt(null),xe=null,Me=null,Ze=0};return window.addEventListener("keydown",Qe),window.addEventListener("mousemove",wt),window.addEventListener("mousedown",bt),window.addEventListener("keyup",Ht),()=>{window.removeEventListener("keydown",Qe),window.removeEventListener("mousemove",wt),window.removeEventListener("mousedown",bt),window.removeEventListener("keyup",Ht),y&&clearTimeout(y)}},[e.activeTool,e.isAnnotating,t]),Tn(()=>{let h=x=>{if(x.key==="Escape"){if(an.current)return;if(e.activeTool==="model"&&Xe.size>0){x.preventDefault(),ce(new Map);return}if(Xo.current.length>0){x.preventDefault(),yn();return}}if(x.key==="Enter"&&e.activeTool==="model"&&Xe.size>0&&p){x.preventDefault();let T=[...Xe.keys()].filter(H=>!v?.has(H));T.length>0&&p(T),ce(new Map);return}if((x.metaKey||x.ctrlKey)&&x.key==="v"&&Le.current.length>0&&!an.current){x.preventDefault(),_e.current++;let T=_e.current*20,L=Le.current[0]?.groupId?Math.random().toString(36).substring(2,9):void 0,z=Le.current.map(D=>({...D,id:Math.random().toString(36).substring(2,9),groupId:D.groupId?L:void 0,timestamp:Date.now(),points:D.points.map(J=>({x:J.x+T,y:J.y+T}))}));t({type:"PASTE_ANNOTATIONS",payload:{annotations:z}});let X=z.find(D=>D.type!=="text")||z[0];X&&kn(X.id);return}let _=Xo.current;if(_.length===0||an.current)return;let y=x.composedPath?.()[0]??x.target,w=y?.tagName;if(!(w==="INPUT"||w==="TEXTAREA"||y?.isContentEditable)&&(x.key==="Delete"||x.key==="Backspace")){if(x.preventDefault(),c){let T=Ko.current.annotations;for(let H of _){let L=T.find(X=>X.id===H);if(!L)continue;let z=L.threadId||L.groupId&&T.find(X=>X.groupId===L.groupId&&X.threadId)?.threadId;z&&c(z)}}for(let T of _)t({type:"DELETE_ANNOTATION",payload:{id:T}});yn()}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t,yn,kn,e.activeTool,Xe,v,p,c]);let oe=kr(),re=Wr(()=>e.annotations.filter(h=>!h.pathname||h.pathname===oe),[e.annotations,oe]),ne=Wr(()=>e.styleModifications.filter(h=>!h.pathname||h.pathname===oe),[e.styleModifications,oe]),we=nf(k?.current),Be=we.avoidTop,ve=we.avoidBottom,ut=we.avoidLeft,Et=we.avoidRight,Vt=Wr(()=>zi(e.annotations),[e.annotations]),pn=Wr(()=>{let h=new Map,x=new Set,_=1,y=[...e.annotations].sort((w,T)=>w.timestamp-T.timestamp);for(let w of y)if(!Vt.has(w))if(w.groupId){if(!x.has(w.groupId)){x.add(w.groupId);let T=e.annotations.filter(H=>H.groupId===w.groupId);for(let H of T)h.set(H.id,_);_++}}else h.set(w.id,_),_++;return h},[e.annotations,Vt]),ot=Wr(()=>{if(Ct.length===0)return null;let h=new Map;for(let x of Ct){let _=e.annotations.find(w=>w.id===x);if(!_)continue;let y=_.groupId?e.annotations.filter(w=>w.groupId===_.groupId):[_];for(let w of y)if(w.linkedSelector&&!a?.has(w.linkedSelector)){let T=w.color||e.activeColor;h.set(w.linkedSelector,T)}}return h.size>0?h:null},[Ct,e.annotations,e.activeColor,a]),wn=Wr(()=>re.filter(h=>!(Vt.has(h)||g&&!g.isNew&&h.id===g.id)),[re,Vt,g]),Cn=on((h=oo.current)=>{$(wn,e.currentPath,e.activeTool,e.activeColor,e.strokeWidth,Ct,dc,h.x,h.y,pn,P,we)},[wn,e.currentPath,e.activeTool,e.activeColor,e.strokeWidth,Ct,$,pn,P,Be,ve,ut,Et]);Tn(()=>{Cn(oo.current)},[Cn]),Tn(()=>{let h=()=>{let x={x:window.scrollX,y:window.scrollY};oo.current=x,ro.current===null&&(ro.current=window.requestAnimationFrame(()=>{ro.current=null;let _=oo.current;if(Cn(_),an.current){io(y=>y.x===_.x&&y.y===_.y?y:_);return}Kn.current!==null&&window.clearTimeout(Kn.current),Kn.current=window.setTimeout(()=>{Kn.current=null;let y=oo.current;io(w=>w.x===y.x&&w.y===y.y?w:y)},80)}))};return window.addEventListener("scroll",h,{passive:!0}),()=>{window.removeEventListener("scroll",h),ro.current!==null&&(window.cancelAnimationFrame(ro.current),ro.current=null),Kn.current!==null&&(window.clearTimeout(Kn.current),Kn.current=null)}},[Cn]),Tn(()=>{if(le){let h=Math.random().toString(36).substring(2,9);j({id:h,point:le.point,text:"",fontSize:12,isNew:!0,groupId:le.groupId}),Ce(null)}},[le]),Tn(()=>{Ee&&(j({id:Math.random().toString(36).substring(2,9),point:Ee.point,text:"",fontSize:12,isNew:!0,linkedSelector:Ee.linkedSelector,linkedAnchor:Ee.linkedAnchor,elements:Ee.elements}),K(null))},[Ee]);let fn=Ft(null),Mn=g?.id??null;Tn(()=>{Mn&&O.current?requestAnimationFrame(()=>{let h=O.current;if(!h||(h.focus(),Z.current===Mn))return;Z.current=Mn;let x=an.current;if(x){if(fn.current!==null){let _=Math.min(fn.current,h.value.length);h.setSelectionRange(_,_);return}if(!x.isNew&&x.clickPoint){let _=E.current;if(!_)return;let y=_.getContext("2d");if(!y)return;y.font=`${x.fontSize}px ${vn}`;let w=x.fontSize*1.4,T=x.text.split(`
4
+ `),H=x.clickPoint.y-x.point.y,L=Math.max(0,Math.min(T.length-1,Math.floor(H/w))),z=x.clickPoint.x-x.point.x,X=T[L]||"",D=0;for(let q=0;q<=X.length;q++){let Y=y.measureText(X.substring(0,q)).width;if(Y>z){let xe=q>0?y.measureText(X.substring(0,q-1)).width:0;D=z-xe<Y-z?q-1:q;break}D=q}let J=D;for(let q=0;q<L;q++)J+=(T[q]?.length||0)+1;h.setSelectionRange(J,J)}}}):(Z.current=null,fn.current=null)},[Mn,E]);let Hn=on(h=>{let x=E.current;if(!x)return{x:0,y:0};let _=x.getBoundingClientRect(),y,w;if("touches"in h&&h.touches[0])y=h.touches[0].clientX,w=h.touches[0].clientY;else if("clientX"in h)y=h.clientX,w=h.clientY;else return{x:0,y:0};return{x:y-_.left+window.scrollX,y:w-_.top+window.scrollY}},[E]),go=on((h,x,_,y)=>{let w=_.x-x.x,T=_.y-x.y,H=w*w+T*T;if(H===0)return Math.sqrt((h.x-x.x)**2+(h.y-x.y)**2)<=y;let L=Math.max(0,Math.min(1,((h.x-x.x)*w+(h.y-x.y)*T)/H)),z=x.x+L*w,X=x.y+L*T;return Math.sqrt((h.x-z)**2+(h.y-X)**2)<=y},[]),wr=on(h=>{for(let _=re.length-1;_>=0;_--){let y=re[_];if(!y||Vt.has(y))continue;let w=(y.strokeWidth||3)+4;switch(y.type){case"text":{if(!y.points[0]||!y.text)continue;let T=y.points[0],H=y.fontSize||12,L=E.current;if(L){let z=L.getContext("2d");if(z){z.font=`${H}px ${vn}`;let X=y.text.replace(/\n/g," "),D=T.x-Zt.x,J=ni(D),q=oi(z,X,J),Y=z.measureText(q).width,xe=H*1.4,Me={x:T.x-Zt.x,y:T.y-Zt.y},Ze=Ds(Me,H,we,Y+8),dt={x:Ze.x+Zt.x,y:Ze.y+Zt.y};if(h.x>=dt.x-4-4&&h.x<=dt.x+Y+4+4&&h.y>=dt.y-4-4&&h.y<=dt.y+xe+4+4)return y}}break}case"rectangle":{if(y.points.length<2)continue;let T=y.points[0],H=y.points[y.points.length-1],L=Math.min(T.x,H.x),z=Math.max(T.x,H.x),X=Math.min(T.y,H.y),D=Math.max(T.y,H.y),J=go(h,{x:L,y:X},{x:z,y:X},w),q=go(h,{x:L,y:D},{x:z,y:D},w),Y=go(h,{x:L,y:X},{x:L,y:D},w),xe=go(h,{x:z,y:X},{x:z,y:D},w);if(J||q||Y||xe)return y;break}case"circle":{if(y.points.length<2)continue;let T=y.points[0],H=y.points[y.points.length-1],L=(T.x+H.x)/2,z=(T.y+H.y)/2,X=Math.abs(H.x-T.x)/2,D=Math.abs(H.y-T.y)/2,J=h.x-L,q=h.y-z,Y=Math.sqrt((J/X)**2+(q/D)**2);if(Math.abs(Y-1)*Math.max(X,D)<=w)return y;break}case"line":{if(y.points.length<2)continue;let T=y.points[0],H=y.points[y.points.length-1];if(go(h,T,H,w))return y;break}case"freehand":{if(y.points.length<2)continue;for(let T=0;T<y.points.length-1;T++){let H=y.points[T],L=y.points[T+1];if(go(h,H,L,w))return y}break}}}return null},[re,E,go,Vt,Zt.x,Zt.y,Be,ve,ut,Et]),gi=on(h=>{let x=wr(h);return x?.type==="text"?x:null},[wr]),mi=on(h=>{if(Ct.length===0)return null;let x=dc/2+4;for(let _ of Ct){let y=e.annotations.find(w=>w.id===_);if(!(!y||y.points.length<2)){if(y.type==="line"){let w=y.points[0],T=y.points[y.points.length-1];if(Math.sqrt((h.x-w.x)**2+(h.y-w.y)**2)<=x)return{handle:"start",annotationId:_};if(Math.sqrt((h.x-T.x)**2+(h.y-T.y)**2)<=x)return{handle:"end",annotationId:_};continue}if(y.type==="circle"){let w=y.points[0],T=y.points[y.points.length-1],H=Math.min(w.x,T.x),L=Math.max(w.x,T.x),z=Math.min(w.y,T.y),X=Math.max(w.y,T.y),D=(H+L)/2,J=(z+X)/2,q=[{handle:"top",x:D,y:z},{handle:"bottom",x:D,y:X},{handle:"left",x:H,y:J},{handle:"right",x:L,y:J}];for(let{handle:Y,x:xe,y:Me}of q)if(Math.sqrt((h.x-xe)**2+(h.y-Me)**2)<=x)return{handle:Y,annotationId:_};continue}if(y.type==="rectangle"||y.type==="freehand"){let w=y.points[0],T=y.points[y.points.length-1],H,L,z,X;y.type==="freehand"?(H=Math.min(...y.points.map(J=>J.x)),L=Math.max(...y.points.map(J=>J.x)),z=Math.min(...y.points.map(J=>J.y)),X=Math.max(...y.points.map(J=>J.y))):(H=Math.min(w.x,T.x),L=Math.max(w.x,T.x),z=Math.min(w.y,T.y),X=Math.max(w.y,T.y));let D=[{corner:"topLeft",x:H,y:z},{corner:"topRight",x:L,y:z},{corner:"bottomLeft",x:H,y:X},{corner:"bottomRight",x:L,y:X}];for(let{corner:J,x:q,y:Y}of D)if(Math.sqrt((h.x-q)**2+(h.y-Y)**2)<=x)return{handle:J,annotationId:_}}}}return null},[Ct,e.annotations]);Tn(()=>{let h=x=>{if(pe.current={x:x.clientX+window.scrollX,y:x.clientY+window.scrollY},!g){let _=gi(pe.current);Re(_?.id||null)}};return window.addEventListener("mousemove",h),()=>window.removeEventListener("mousemove",h)},[g,gi]);let Eo=on(()=>{if(!g)return;let h=g.images?.length||0;if(g.text.trim()||h>0)if(g.isNew){let x=ki();t({type:"ADD_TEXT",payload:{point:g.point,text:g.text||(h>0?`[${h} image${h>1?"s":""}]`:""),fontSize:g.fontSize,id:x,groupId:g.groupId,linkedSelector:g.linkedSelector,linkedAnchor:g.linkedAnchor,elements:g.elements,...h>0?{imageCount:h}:{}}}),h>0&&g.images&&l&&l(x,g.images)}else t({type:"UPDATE_TEXT",payload:{id:g.id,text:g.text||(h>0?`[${h} image${h>1?"s":""}]`:""),...h>0?{imageCount:h}:{}}}),h>0&&g.images&&l&&l(g.id,g.images);else g.isNew||t({type:"DELETE_ANNOTATION",payload:{id:g.id}});j(null)},[g,t,l]),S=on(h=>{for(let x=0;x<da.length-1;x++){let _=da[x],y=da[x+1];if(h<=(_+y)/2)return _;if(h<y)return y}return Math.round(h/8)*8},[]),R=on((h,x,_,y)=>{let w=_.top+Math.max(y.top,4),T=_.bottom-Math.max(y.bottom,4),H=_.left+Math.max(y.left,4),L=_.right-Math.max(y.right,4);if(h<_.left||h>_.right||x<_.top||x>_.bottom)return null;let z=x<w,X=x>T,D=h<H,J=h>L;return z&&D?y.top>=y.left?"top":"left":z&&J?y.top>=y.right?"top":"right":X&&D?y.bottom>=y.left?"bottom":"left":X&&J?y.bottom>=y.right?"bottom":"right":z?"top":X?"bottom":D?"left":J?"right":null},[]),te=on(h=>{if(!e.isAnnotating)return;if(e.inspectedElement&&e.activeTool==="hand"&&!("button"in h&&h.button===2)){h.preventDefault(),h.stopPropagation(),t({type:"SELECT_ELEMENT",payload:null});return}let x=Hn(h),_="shiftKey"in h&&h.shiftKey;if(e.activeTool==="inspector"){if("button"in h&&h.button===2)return;if(G&&!No(G)){let T=e.annotations.find(Qe=>{if(!Qe.linkedSelector||!Qe.threadId)return!1;try{return G.matches(Qe.linkedSelector)}catch{return!1}});if(T?.threadId&&d){d(T.threadId),requestAnimationFrame(()=>{document.querySelector("[data-popmelt-shadow-host]")?.shadowRoot?.querySelector("[data-popmelt-reply]")?.focus()});return}let H=Dn(G),L=jn(G),z=G.getBoundingClientRect(),X=G.getAttribute("data-pm");X||(X=Math.random().toString(36).substring(2,8),G.setAttribute("data-pm",X));let D=`[data-pm="${X}"]`,J=ne.some(Qe=>{try{return G.matches(Qe.selector)}catch{return!1}}),q=e.annotations.filter(Qe=>{if(!Qe.linkedSelector)return!1;try{return G.matches(Qe.linkedSelector)}catch{return!1}}).length,Y=(J?1:0)+q,xe=z.top>=jo*(1+Y)?"top-left":"bottom-left",Me=E.current?.getContext("2d")??document.createElement("canvas").getContext("2d"),Ze;Me&&(Me.font=`12px ${vn}`,Ze=Me.measureText("Type here...").width);let dt=uc(z,xe,Y,k?.current,Ze,0);K({point:dt,linkedSelector:D,linkedAnchor:xe,elements:[{...H,selector:L}]})}return}if(e.activeTool==="model"){if("button"in h&&h.button===2)return;if(ge){let T=ge.name;if(v?.has(T)){u?.(T);return}"shiftKey"in h&&h.shiftKey?ce(L=>{let z=new Map(L);return z.has(T)?z.delete(T):z.set(T,ge),z}):Xe.size===1&&Xe.has(T)?(p&&p([T]),ce(new Map)):ce(new Map([[T,ge]]))}return}if(e.activeTool==="hand"&&Bt&&gt){let T=Bt,H=T.getAttribute("data-pm");H||(H=Math.random().toString(36).substring(2,8),T.setAttribute("data-pm",H));let L=jn(T),z=`[data-pm="${H}"]`,X=Dn(T),D=dr(T),J=x.x-window.scrollX,q=x.y-window.scrollY,Y=eo,xe=window.getComputedStyle(T).justifyContent,Me=0;if(Y){let dt=Ao(T).find(Qe=>Qe.axis===gt);Me=dt?gt==="column"?dt.w:dt.h:0}Ve(T,"transition","none"),Jt.current={isDragging:!0,hasMoved:!1,axis:gt,startX:J,startY:q,originalRow:Y?Me:D.row,originalColumn:Y?Me:D.column,element:T,elementInfo:{...X,selector:z},selector:z,durableSelector:L,isAuto:Y,originalJustifyContent:xe,visualGap:Me},Yt({axis:gt,row:Y?Me:D.row,column:Y?Me:D.column});return}if(e.activeTool==="hand"&&ct&&qt){let T=ct,H=T.getAttribute("data-pm");H||(H=Math.random().toString(36).substring(2,8),T.setAttribute("data-pm",H));let L=`[data-pm="${H}"]`,z=Dn(T),{fontSize:X,lineHeight:D}=Qr(T),J=X>0?D/X:1.2,q=x.x-window.scrollX,Y=x.y-window.scrollY;Ve(T,"transition","none");let xe=jn(T);Pe.current={isDragging:!0,property:qt,startX:q,startY:Y,originalFontSize:X,originalLineHeight:D,originalRatio:J,element:T,elementInfo:{...z,selector:L},selector:L,durableSelector:xe},Ho({property:qt,fontSize:X,lineHeight:D});return}if(e.activeTool==="hand"&&Xt&&Te){let T=Xt,H=T.getAttribute("data-pm");H||(H=Math.random().toString(36).substring(2,8),T.setAttribute("data-pm",H));let L=`[data-pm="${H}"]`,z=jn(T),X=Dn(T),D=ur(T),J=T.getBoundingClientRect(),q=Math.floor(J.height/2),Y=x.y-window.scrollY;Ve(T,"transition","none"),at.current={isDragging:!0,corner:Te,startY:Y,original:D,maxRadius:q,element:T,elementInfo:{...X,selector:L},selector:L,durableSelector:z},mt({corner:Te,radius:{...D}});return}if(e.activeTool==="hand"&&Rt&&Dt){let T=Rt,H=T.getAttribute("data-pm");H||(H=Math.random().toString(36).substring(2,8),T.setAttribute("data-pm",H));let L=`[data-pm="${H}"]`,z=jn(T),X=Dn(T),D=Rr(T),J=x.x-window.scrollX,q=x.y-window.scrollY;Ve(T,"transition","none"),qe.current={isDragging:!0,side:Dt,startX:J,startY:q,original:D,element:T,elementInfo:{...X,selector:L},selector:L,durableSelector:z},He({side:Dt,padding:{...D}});return}let y=mi(x);if(y){let T=e.annotations.find(H=>H.id===y.annotationId);if(T&&T.type!=="text"&&(T.status??"pending")==="pending"){qo({annotationId:y.annotationId,handle:y.handle,startPoint:x,originalPoints:[...T.points],hasMoved:!1});return}}let w=wr(x);if(w&&w.points[0]){if(g&&Eo(),w.type!=="text"?(kn(w.id,_),w.color&&t({type:"SET_COLOR",payload:w.color})):_||yn(),d){let T=w.threadId||(w.groupId?e.annotations.find(H=>H.groupId===w.groupId&&H.threadId)?.threadId:void 0);T&&d(T)}no({annotation:w,startPoint:x,hasMoved:!1});return}if(_||yn(),e.activeTool==="text"){g&&Eo();let T=Math.random().toString(36).substring(2,9);j({id:T,point:x,text:"",fontSize:12,isNew:!0});return}f(!0),t({type:"START_PATH",payload:x})},[e.isAnnotating,e.activeTool,e.inspectedElement,e.annotations,g,Ct,G,Rt,Dt,Xt,Te,Bt,gt,eo,ct,qt,ge,Xe,v,p,u,d,Hn,wr,mi,t,kn,yn,Eo]),ae=on(h=>{let x=Hn(h);if(e.activeTool==="inspector"&&e.isAnnotating){let _=x.x-window.scrollX,y=x.y-window.scrollY,w=cr(_,y),T=w&&No(w)?null:w;T!==G&&(se(T),Ne(T?Dn(T):null));return}if(e.activeTool==="model"&&e.isAnnotating){let _=x.x-window.scrollX,y=x.y-window.scrollY,w=cr(_,y);if(w!==ft.current&&(ft.current=w,Ae.current=0),w){let T=Li(w,Ae.current);lt(T)}else lt(null);return}if(e.activeTool==="hand"&&e.isAnnotating){let _=x.x-window.scrollX,y=x.y-window.scrollY;$t.current={x:_,y},Gt({x:_,y});let w=Uo.current.cmd,T=Uo.current.shift;if(Jt.current.isDragging){let L=Jt.current,z=L.element;if(!z)return;if(!L.hasMoved){let q=Math.abs(_-L.startX),Y=Math.abs(y-L.startY);if(q<=2&&Y<=2)return;L.hasMoved=!0,L.isAuto&&(Ve(z,"justify-content","normal"),Ve(z,"row-gap",`${L.visualGap}px`),Ve(z,"column-gap",`${L.visualGap}px`),sn(!1))}let X=L.axis,D=L.originalRow,J=L.originalColumn;if(X==="column"){let q=_-L.startX;J=L.originalColumn+q,w||(D=L.originalRow+q)}else{let q=y-L.startY;D=L.originalRow+q,w||(J=L.originalColumn+q)}D=Math.max(0,D),J=Math.max(0,J),T&&(D=S(D),J=S(J)),D=Math.round(D),J=Math.round(J),Ve(z,"row-gap",`${D}px`),Ve(z,"column-gap",`${J}px`),Yt({axis:X,row:D,column:J});return}if(at.current.isDragging){let L=at.current,z=L.element;if(!z)return;let X=y-L.startY,D=L.corner,J=L.original,q={...J};if(w){let Y=J[D]+X;Y=Math.max(0,Math.min(L.maxRadius,Y)),T&&(Y=S(Y)),Y=Math.round(Y),q[D]=Y}else{let Y=J[D]+X;Y=Math.max(0,Math.min(L.maxRadius,Y)),T&&(Y=S(Y)),Y=Math.round(Y),q={"top-left":Y,"top-right":Y,"bottom-right":Y,"bottom-left":Y}}Ve(z,"border-top-left-radius",`${q["top-left"]}px`),Ve(z,"border-top-right-radius",`${q["top-right"]}px`),Ve(z,"border-bottom-right-radius",`${q["bottom-right"]}px`),Ve(z,"border-bottom-left-radius",`${q["bottom-left"]}px`),mt({corner:D,radius:q});return}if(Pe.current.isDragging){let L=Pe.current,z=L.element;if(!z)return;let X=L.property,D=L.originalFontSize,J=L.originalLineHeight,q=[8,10,11,12,13,14,16,18,20,22,24,28,32,36,40,48,56,64,72,80,96];if(X==="font-size"){let xe=_-L.startX;D=L.originalFontSize+xe,D=Math.max(1,D)}else{let xe=y-L.startY;J=L.originalLineHeight+xe,J=Math.max(D,J)}if(T)if(X==="font-size"){let xe=q[0],Me=Math.abs(D-xe);for(let Ze of q){let dt=Math.abs(D-Ze);dt<Me&&(xe=Ze,Me=dt)}D=xe}else{let xe=D>0?J/D:1.2,Me=Math.round(xe*2)/2;J=D*Math.max(1,Me)}D=Math.round(D),J=Math.round(J*10)/10,Ve(z,"font-size",`${D}px`);let Y=D>0?Math.round(J/D*1e3)/1e3:1.2;Ve(z,"line-height",`${Y}`),Ho({property:X,fontSize:D,lineHeight:J});return}if(qe.current.isDragging){let L=qe.current,z=L.element;if(!z)return;let X=L.side,D=L.original,J=D.top,q=D.right,Y=D.bottom,xe=D.left;if(X==="top"){let Me=L.startY-y;J=D.top+Me,w||(Y=D.bottom+Me)}else if(X==="bottom"){let Me=y-L.startY;Y=D.bottom+Me,w||(J=D.top+Me)}else if(X==="left"){let Me=L.startX-_;xe=D.left+Me,w||(q=D.right+Me)}else if(X==="right"){let Me=_-L.startX;q=D.right+Me,w||(xe=D.left+Me)}J=Math.max(0,J),q=Math.max(0,q),Y=Math.max(0,Y),xe=Math.max(0,xe),T&&(J=S(J),q=S(q),Y=S(Y),xe=S(xe)),J=Math.round(J),q=Math.round(q),Y=Math.round(Y),xe=Math.round(xe),Ve(z,"padding",`${J}px ${q}px ${Y}px ${xe}px`),He({side:X,padding:{top:J,right:q,bottom:Y,left:xe}});return}let H=cr(_,y);for(;H&&H.tagName==="A";)H=H.parentElement;{let z=[];H&&z.push(H),Xt&&Xt!==H&&z.push(Xt);let X=null,D=16,J=null;for(let q of z){let Y=q.getBoundingClientRect(),xe=ur(q),Me=[["top-left",Y.left,Y.top+xe["top-left"]],["top-right",Y.right,Y.top+xe["top-right"]],["bottom-right",Y.right,Y.bottom-xe["bottom-right"]],["bottom-left",Y.left,Y.bottom-xe["bottom-left"]]];for(let[Ze,dt,Qe]of Me){let wt=Math.hypot(_-dt,y-Qe);wt<D&&(D=wt,X=Ze,J=q)}}if(X&&J){U(J),Ue(X),Rt&&Kt(null),Dt&&Ge(null),Bt&&un(null),gt&&Lt(null),sn(!1),ct&&to(null),qt&&_n(null);return}}Xt&&U(null),Te&&Ue(null);{let L=[];H&&Di(H)&&L.push(H);let z=H?.parentElement??null;for(;z&&z!==document.body&&L.length<3;)Di(z)&&L.push(z),z=z.parentElement;for(let X of L){let J=Ao(X).find(q=>_>=q.x&&_<=q.x+q.w&&y>=q.y&&y<=q.y+q.h);if(J){un(X),Lt(J.axis),sn(Es(X,J.axis)),Rt&&Kt(null),Dt&&Ge(null),ct&&to(null),qt&&_n(null);return}}}Bt&&un(null),gt&&Lt(null),sn(!1);{let z=[];H&&z.push(H),ct&&ct!==H&&z.push(ct);let X=null,D=1/0,J=null;for(let q of z){if(!Ts(q))continue;let Y=Lr(q);if(!Y)continue;let xe=_>=Y.left&&_<=Y.right&&y>=Y.top&&y<=Y.bottom,Me=[["font-size",Y.right,Y.top+Y.height/2],["line-height",Y.left+Y.width/2,Y.bottom]];for(let[Ze,dt,Qe]of Me){let wt=Math.hypot(_-dt,y-Qe);(xe||wt<12)&&wt<D&&(D=wt,X=Ze,J=q)}}X&&J?(to(J),_n(X)):(ct&&to(null),qt&&_n(null))}if(H!==Rt&&Kt(H),H){let L=Rr(H),z=H.getBoundingClientRect(),X=R(_,y,z,L);Ge(X)}else Ge(null);return}if(An){let{handle:_,originalPoints:y,hasMoved:w}=An,T=e.annotations.find(D=>D.id===An.annotationId);if(!T)return;let H="metaKey"in h,L=H&&(h.metaKey||h.ctrlKey),z=H&&h.shiftKey,X;if(T.type==="line"){let D=y[0],J=y[y.length-1];_==="start"?X=[x,J]:X=[D,x]}else if(T.type==="freehand"){let D=Math.min(...y.map(ze=>ze.x)),J=Math.max(...y.map(ze=>ze.x)),q=Math.min(...y.map(ze=>ze.y)),Y=Math.max(...y.map(ze=>ze.y)),xe=(D+J)/2,Me=(q+Y)/2,Ze=J-D||1,dt=Y-q||1,Qe=Ze/dt,wt=D,Ht=J,bt=q,de=Y;switch(_){case"topLeft":wt=x.x,bt=x.y;break;case"topRight":Ht=x.x,bt=x.y;break;case"bottomLeft":wt=x.x,de=x.y;break;case"bottomRight":Ht=x.x,de=x.y;break}if(L)switch(_){case"topLeft":Ht=J+(D-wt),de=Y+(q-bt);break;case"topRight":wt=D-(Ht-J),de=Y+(q-bt);break;case"bottomLeft":Ht=J+(D-wt),bt=q-(de-Y);break;case"bottomRight":wt=D-(Ht-J),bt=q-(de-Y);break}if(z){let ze=Ht-wt,en=de-bt;if(Math.abs(ze/en)>Qe){let Tt=Math.abs(en)*Qe*Math.sign(ze);_==="topLeft"||_==="bottomLeft"?wt=Ht-Tt:Ht=wt+Tt}else{let Tt=Math.abs(ze)/Qe*Math.sign(en);_==="topLeft"||_==="topRight"?bt=de-Tt:de=bt+Tt}}let je=Ht-wt||1,Nt=de-bt||1;X=y.map(ze=>({x:wt+(ze.x-D)/Ze*je,y:bt+(ze.y-q)/dt*Nt}))}else if(T.type==="circle"){let D=y[0],J=y[y.length-1],q=Math.min(D.x,J.x),Y=Math.max(D.x,J.x),xe=Math.min(D.y,J.y),Me=Math.max(D.y,J.y),Ze=(q+Y)/2,dt=(xe+Me)/2,Qe=Y-q,wt=Me-xe,Ht=q,bt=Y,de=xe,je=Me;switch(_){case"top":if(de=x.y,L&&(je=dt+(dt-x.y)),z){let ze=(je-de)*(Qe/wt)/2;Ht=Ze-ze,bt=Ze+ze}break;case"bottom":if(je=x.y,L&&(de=dt-(x.y-dt)),z){let ze=(je-de)*(Qe/wt)/2;Ht=Ze-ze,bt=Ze+ze}break;case"left":if(Ht=x.x,L&&(bt=Ze+(Ze-x.x)),z){let ze=(bt-Ht)*(wt/Qe)/2;de=dt-ze,je=dt+ze}break;case"right":if(bt=x.x,L&&(Ht=Ze-(x.x-Ze)),z){let ze=(bt-Ht)*(wt/Qe)/2;de=dt-ze,je=dt+ze}break}X=[{x:Ht,y:de},{x:bt,y:je}]}else{let D=y[0],J=y[y.length-1],q=Math.min(D.x,J.x),Y=Math.max(D.x,J.x),xe=Math.min(D.y,J.y),Me=Math.max(D.y,J.y),Ze=(q+Y)/2,dt=(xe+Me)/2,Qe=Y-q||1,wt=Me-xe||1,Ht=Qe/wt,bt=q,de=Y,je=xe,Nt=Me;switch(_){case"topLeft":bt=x.x,je=x.y;break;case"topRight":de=x.x,je=x.y;break;case"bottomLeft":bt=x.x,Nt=x.y;break;case"bottomRight":de=x.x,Nt=x.y;break}if(L)switch(_){case"topLeft":de=Y+(q-bt),Nt=Me+(xe-je);break;case"topRight":bt=q-(de-Y),Nt=Me+(xe-je);break;case"bottomLeft":de=Y+(q-bt),je=xe-(Nt-Me);break;case"bottomRight":bt=q-(de-Y),je=xe-(Nt-Me);break}if(z){let ze=de-bt,en=Nt-je;if(Math.abs(ze/en)>Ht){let Tt=Math.abs(en)*Ht*Math.sign(ze);_==="topLeft"||_==="bottomLeft"?bt=de-Tt:de=bt+Tt}else{let Tt=Math.abs(ze)/Ht*Math.sign(en);_==="topLeft"||_==="topRight"?je=Nt-Tt:Nt=je+Tt}}X=[{x:bt,y:je},{x:de,y:Nt}]}t({type:"RESIZE_ANNOTATION",payload:{id:An.annotationId,points:X,saveUndo:!w}}),w||qo({...An,hasMoved:!0});return}if(Je&&(Je.annotation.status??"pending")==="pending"){let _=x.x-Je.startPoint.x,y=x.y-Je.startPoint.y;if((Math.abs(_)>2||Math.abs(y)>2)&&!Je.hasMoved)no({...Je,hasMoved:!0,startPoint:x}),t({type:"MOVE_ANNOTATION",payload:{id:Je.annotation.id,delta:{x:_,y},saveUndo:!0}});else if(Je.hasMoved){let T=x.x-Je.startPoint.x,H=x.y-Je.startPoint.y;no({...Je,startPoint:x}),t({type:"MOVE_ANNOTATION",payload:{id:Je.annotation.id,delta:{x:T,y:H}}})}return}!B||!e.isAnnotating||t({type:"CONTINUE_PATH",payload:x})},[B,e.isAnnotating,e.activeTool,Je,An,G,Rt,Dt,Xt,Te,Bt,gt,ct,qt,Hn,t,S,R]),he=on(h=>{if(Pe.current.isDragging){let y=Pe.current,w=y.element;if(w&&y.selector&&y.elementInfo&&Wt){w instanceof HTMLElement&&(w.style.removeProperty("font-size"),w.style.removeProperty("line-height"),w.style.removeProperty("transition"));let T=[];if(y.originalFontSize!==Wt.fontSize&&(Ve(w,"font-size",`${Wt.fontSize}px`),T.push({property:"font-size",original:`${y.originalFontSize}px`,modified:`${Wt.fontSize}px`})),y.originalLineHeight!==Wt.lineHeight){let H=y.originalFontSize>0?Math.round(y.originalLineHeight/y.originalFontSize*1e3)/1e3:1.2,L=Wt.fontSize>0?Math.round(Wt.lineHeight/Wt.fontSize*1e3)/1e3:1.2;Ve(w,"line-height",`${L}`),T.push({property:"line-height",original:`${H}`,modified:`${L}`})}T.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:y.selector,durableSelector:y.durableSelector??void 0,element:y.elementInfo,changes:T}})}Pe.current={isDragging:!1,property:null,startX:0,startY:0,originalFontSize:0,originalLineHeight:0,originalRatio:1.2,element:null,elementInfo:null,selector:null,durableSelector:null},Ho(null);return}if(Jt.current.isDragging){let y=Jt.current,w=y.element,T="button"in h&&h.button===2;if(!y.hasMoved&&!T&&w&&y.selector&&y.elementInfo){w instanceof HTMLElement&&w.style.removeProperty("transition");let H=["space-between","space-around","stretch","normal"],L=y.originalJustifyContent||"normal",z=H.indexOf(L),X=H[(z+1)%H.length],D=[];X==="normal"?(Ve(w,"justify-content","normal"),D.push({property:"justify-content",original:y.originalJustifyContent,modified:"normal"})):X==="stretch"?(Ve(w,"justify-content",X),Ve(w,"row-gap","8px"),Ve(w,"column-gap","8px"),D.push({property:"justify-content",original:y.originalJustifyContent||"normal",modified:X}),y.originalRow!==8&&D.push({property:"row-gap",original:`${y.originalRow}px`,modified:"8px"}),y.originalColumn!==8&&D.push({property:"column-gap",original:`${y.originalColumn}px`,modified:"8px"})):(w instanceof HTMLElement&&(w.style.removeProperty("row-gap"),w.style.removeProperty("column-gap")),Ve(w,"justify-content",X),D.push({property:"justify-content",original:y.originalJustifyContent||"normal",modified:X}),y.originalRow>0&&D.push({property:"row-gap",original:`${y.originalRow}px`,modified:"0px"}),y.originalColumn>0&&D.push({property:"column-gap",original:`${y.originalColumn}px`,modified:"0px"})),D.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:y.selector,durableSelector:y.durableSelector??void 0,element:y.elementInfo,changes:D}})}else if(y.hasMoved&&w&&y.selector&&y.elementInfo&&st){w instanceof HTMLElement&&(w.style.removeProperty("row-gap"),w.style.removeProperty("column-gap"),w.style.removeProperty("transition"));let H=[];y.isAuto?(w instanceof HTMLElement&&w.style.removeProperty("justify-content"),Ve(w,"justify-content","normal"),Ve(w,"row-gap",`${st.row}px`),Ve(w,"column-gap",`${st.column}px`),H.push({property:"justify-content",original:y.originalJustifyContent,modified:"normal"}),H.push({property:"row-gap",original:"0px",modified:`${st.row}px`}),H.push({property:"column-gap",original:"0px",modified:`${st.column}px`})):(y.originalRow!==st.row&&(Ve(w,"row-gap",`${st.row}px`),H.push({property:"row-gap",original:`${y.originalRow}px`,modified:`${st.row}px`})),y.originalColumn!==st.column&&(Ve(w,"column-gap",`${st.column}px`),H.push({property:"column-gap",original:`${y.originalColumn}px`,modified:`${st.column}px`}))),H.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:y.selector,durableSelector:y.durableSelector??void 0,element:y.elementInfo,changes:H}})}Jt.current={isDragging:!1,hasMoved:!1,axis:null,startX:0,startY:0,originalRow:0,originalColumn:0,element:null,elementInfo:null,selector:null,durableSelector:null,isAuto:!1,originalJustifyContent:"",visualGap:0},Yt(null);return}if(at.current.isDragging){let y=at.current,w=y.element;if(w&&y.selector&&y.elementInfo&&ht){w instanceof HTMLElement&&(w.style.removeProperty("border-top-left-radius"),w.style.removeProperty("border-top-right-radius"),w.style.removeProperty("border-bottom-right-radius"),w.style.removeProperty("border-bottom-left-radius"),w.style.removeProperty("transition"));let T=["top-left","top-right","bottom-right","bottom-left"],H={"top-left":"border-top-left-radius","top-right":"border-top-right-radius","bottom-right":"border-bottom-right-radius","bottom-left":"border-bottom-left-radius"},L=[];for(let z of T)y.original[z]!==ht.radius[z]&&(Ve(w,H[z],`${ht.radius[z]}px`),L.push({property:H[z],original:`${y.original[z]}px`,modified:`${ht.radius[z]}px`}));L.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:y.selector,durableSelector:y.durableSelector??void 0,element:y.elementInfo,changes:L}})}at.current={isDragging:!1,corner:null,startY:0,original:{"top-left":0,"top-right":0,"bottom-right":0,"bottom-left":0},maxRadius:0,element:null,elementInfo:null,selector:null,durableSelector:null},mt(null);return}if(qe.current.isDragging){let y=qe.current,w=y.element,T=y.selector,H=y.elementInfo;if(w&&T&&H&&Se){let L=y.original,z=Se.padding;w instanceof HTMLElement&&(w.style.removeProperty("padding"),w.style.removeProperty("transition"));let X=[],D=[{prop:"padding-top",origVal:L.top,newVal:z.top},{prop:"padding-right",origVal:L.right,newVal:z.right},{prop:"padding-bottom",origVal:L.bottom,newVal:z.bottom},{prop:"padding-left",origVal:L.left,newVal:z.left}];for(let{prop:J,origVal:q,newVal:Y}of D)q!==Y&&(Ve(w,J,`${Y}px`),X.push({property:J,original:`${q}px`,modified:`${Y}px`}));X.length>0&&t({type:"MODIFY_STYLES_BATCH",payload:{selector:T,durableSelector:y.durableSelector??void 0,element:H,changes:X}})}qe.current={isDragging:!1,side:null,startX:0,startY:0,original:{top:0,right:0,bottom:0,left:0},element:null,elementInfo:null,selector:null,durableSelector:null},He(null);return}if(An){qo(null);return}if(Je){if(!Je.hasMoved&&Je.annotation.type==="text"&&(Je.annotation.status??"pending")==="pending"){let y=Hn(h);j({id:Je.annotation.id,point:Je.annotation.points[0],text:Je.annotation.text||"",fontSize:Je.annotation.fontSize||12,isNew:!1,clickPoint:y,groupId:Je.annotation.groupId})}no(null);return}if(!B)return;let x=5;if(e.currentPath.length>=2){let y=e.currentPath[0],w=e.currentPath[e.currentPath.length-1],T=Math.abs(w.x-y.x),H=Math.abs(w.y-y.y);if((e.activeTool==="line"?Math.sqrt(T*T+H*H)<x:T<x&&H<x)&&["rectangle","circle","line"].includes(e.activeTool)){f(!1),t({type:"CANCEL_PATH"});return}}let _=vs(e.currentPath);if(e.activeTool==="rectangle"&&e.currentPath.length>=2){let y=e.currentPath[0],w=e.currentPath[e.currentPath.length-1],T=Math.min(y.x,w.x),H=Math.max(y.y,w.y),L=e.strokeWidth/2,z=Math.random().toString(36).substring(2,9);Ce({point:{x:T-L+4,y:H+L+4},groupId:z}),f(!1),t({type:"FINISH_PATH",payload:{groupId:z,elements:_}});return}f(!1),t({type:"FINISH_PATH",payload:{elements:_}})},[B,Je,An,Se,ht,st,Wt,Hn,t,e.activeTool,e.currentPath,e.strokeWidth]),ke=on(h=>{let x=h.target.value;fn.current=h.target.selectionStart,j(_=>_&&{..._,text:x})},[]),Oe=on(h=>{h.key==="Escape"?j(null):h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),Eo())},[Eo]),me=on(h=>{if(!g)return;let x=h.clipboardData.items,_=[];for(let y=0;y<x.length;y++){let w=x[y];if(w.type.startsWith("image/")){let T=w.getAsFile();T&&_.push(T)}}_.length>0&&(h.preventDefault(),j(y=>y?{...y,images:[...y.images||[],..._]}:null))},[g]),We=on(h=>{if(!e.isAnnotating)return;if(e.activeTool==="hand"){h.preventDefault();let _=Rt||Bt||Xt||ct;if(_&&!No(_)){let y=Dn(_),w=jn(_);t({type:"SELECT_ELEMENT",payload:{el:_,info:{...y,selector:w}}})}return}h.preventDefault();let x=E.current;x&&(M.current=!0,x.style.pointerEvents="none",setTimeout(()=>{M.current&&(M.current=!1,x.style.pointerEvents="")},4e3))},[e.activeTool,e.isAnnotating,Rt,Bt,Xt,ct,t,No,E]);Tn(()=>{let h=re.filter(H=>H.linkedSelector);if(h.length===0)return;let x=null,_=document.createElement("canvas").getContext("2d"),y=()=>{let H=[];for(let L of h){let z=document.querySelector(L.linkedSelector);if(!z&&L.elements?.[0]?.selector&&L.linkedSelector.startsWith("[data-pm=")){try{z=document.querySelector(L.elements[0].selector)}catch{}if(z){let Qe=L.linkedSelector.match(/data-pm="([^"]+)"/)?.[1];Qe&&z.setAttribute("data-pm",Qe)}}if(!z)continue;let X=z.getBoundingClientRect(),D=ne.some(Qe=>{try{return z.matches(Qe.selector)}catch{return!1}}),J=h.filter(Qe=>Qe.id!==L.id&&Qe.timestamp<L.timestamp&&Qe.linkedSelector===L.linkedSelector).length,q=(D?1:0)+J,Y;if(L.text&&_){let Qe=L.fontSize||12;_.font=`${Qe}px ${vn}`,Y=Math.max(...L.text.split(`
5
+ `).map(wt=>_.measureText(wt).width))}let xe=X.top>=jo*(1+q)?"top-left":"bottom-left",Me=uc(X,xe,q,k?.current,Y),Ze=L.points[0],dt=xe!==L.linkedAnchor;Ze&&(dt||Math.abs(Me.x-Ze.x)>1||Math.abs(Me.y-Ze.y)>1)&&H.push({id:L.id,point:Me,linkedAnchor:dt?xe:void 0})}H.length>0&&t({type:"UPDATE_LINKED_POSITIONS",payload:{updates:H}})},w=()=>{x&&cancelAnimationFrame(x),x=requestAnimationFrame(y)};y(),window.addEventListener("scroll",w,!0),window.addEventListener("resize",w,!0),window.addEventListener("load",w),document.fonts.ready.then(w);let T=new MutationObserver(w);return T.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class"]}),()=>{window.removeEventListener("scroll",w,!0),window.removeEventListener("resize",w,!0),window.removeEventListener("load",w),T.disconnect(),x&&cancelAnimationFrame(x)}},[re,t]);let ln=()=>{if(!e.isAnnotating)return"default";if(An){let{handle:h}=An;return h==="start"||h==="end"?"move":h==="top"||h==="bottom"?"ns-resize":h==="left"||h==="right"?"ew-resize":h==="topLeft"||h==="bottomRight"?"nwse-resize":"nesw-resize"}if(e.activeTool==="text")return"text";if(e.activeTool==="hand"){let h=st?.axis??gt;if(h==="row")return"ns-resize";if(h==="column")return"ew-resize";if(ht||Te)return"ns-resize";let x=Wt?.property??qt;if(x==="font-size")return"ew-resize";if(x==="line-height")return"ns-resize";let _=Se?.side??Dt;return _==="top"||_==="bottom"?"ns-resize":_==="left"||_==="right"?"ew-resize":"default"}return"crosshair"},yt={position:"fixed",top:0,left:0,width:"100vw",height:"100vh",zIndex:9998,pointerEvents:e.isAnnotating?"auto":"none",visibility:e.isAnnotating?"visible":"hidden",cursor:ln()},Wn=on(()=>{let h=E.current;if(!h||!g)return{width:100,height:12*1.4,isWrapped:!1};let x=h.getContext("2d");if(!x)return{width:100,height:g.fontSize*1.4,isWrapped:!1};x.font=`${g.fontSize}px ${vn}`;let y=x.measureText("Type here...").width,w=g.text.split(`
6
+ `),T=w.length>0?Math.max(y,...w.map(D=>x.measureText(D||" ").width)):y,H=g.point.x-Zt.x,L=ni(H);if(T>L){let D=Tl(x,w,L),J=Math.min(L,Math.max(y,...D.map(Y=>x.measureText(Y).width))),q=Math.max(1,D.length)*g.fontSize*1.4;return{width:J,height:q,isWrapped:!0}}let X=Math.max(1,w.length)*g.fontSize*1.4;return{width:T,height:X,isWrapped:!1}},[g,E,Zt.x])(),er=g?Math.max(1,g.text.split(`
7
+ `).length)*g.fontSize*1.4+8:0,To=Wn.height+8,ds=Wn.isWrapped?To-er:0,us=g?g.point.y-4-Zt.y-ds:0,hi=g?g.point.x-4-Zt.x:0,ko=Wn.width+8,Xr=g?Bs(us,To,we,hi,ko):0,Ye=g?{position:"fixed",left:hi,top:Xr,zIndex:9999,width:ko,height:To,padding:4,fontSize:g.fontSize,fontFamily:vn,color:"#ffffff",backgroundColor:e.activeColor,border:"none",borderRadius:0,outline:"none",boxShadow:"none",lineHeight:1.4,resize:"none",overflow:"hidden",whiteSpace:Wn.isWrapped?"pre-wrap":"pre",wordBreak:Wn.isWrapped?"break-word":void 0}:{},Qt=h=>h?e.annotations.find(x=>x.id===h)?.linkedSelector??null:null,gn=(h,x)=>{if(!x)return!1;try{return h.matches(x)}catch{return!1}},Nn=[g?.linkedSelector,Ee?.linkedSelector,Qt(N),Qt(rt),et].filter(Boolean),yi=h=>Nn.some(x=>gn(h,x));return Gr(Jr,{children:[pt("canvas",{ref:V,id:"devtools-canvas",style:yt,onMouseDown:te,onMouseMove:ae,onMouseUp:h=>he(h),onMouseLeave:h=>{he(h),se(null),Ne(null)},onTouchStart:te,onTouchMove:ae,onTouchEnd:h=>he(h),onContextMenu:We}),g&&Gr(Jr,{children:[pt("style",{children:"#devtools-text-input::placeholder { color: rgba(255, 255, 255, 0.5); }"}),pt("textarea",{id:"devtools-text-input",ref:O,value:g.text,onChange:ke,onKeyDown:Oe,onPaste:me,onBlur:Eo,placeholder:"Type here...",style:Ye}),g.images&&g.images.length>0&&Gr("div",{"data-devtools":!0,style:{position:"fixed",left:g.point.x-4-Zt.x,top:g.point.y-4-Zt.y-20,zIndex:1e4,fontSize:11,fontFamily:"system-ui, sans-serif",color:"#fff",backgroundColor:"rgba(0,0,0,0.7)",padding:"2px 6px",borderRadius:3,whiteSpace:"nowrap"},children:[g.images.length," image",g.images.length>1?"s":""," attached"]})]}),e.isAnnotating&&e.activeTool!=="hand"&&ne.length>0&&pt(Wl,{styleModifications:ne,isInspecting:!!e.inspectedElement,accentColor:e.activeColor,annotationGroupCount:new Set(re.map(h=>h.groupId||h.id)).size,dispatch:t,inFlightSelectors:s,toolbarRef:k,onHoverSelector:it}),e.activeTool==="hand"&&e.isAnnotating&&ne.length>0&&pt(Gl,{styleModifications:ne,accentColor:e.activeColor}),e.isAnnotating&&pt(Pl,{annotations:re,supersededAnnotations:Vt,inFlightIds:o,activeIds:r,queuePositions:i,scrollX:Zt.x,scrollY:Zt.y,annotationGroupMap:pn,onViewThread:d,onSelectAnnotation:kn,onHoverAnnotation:Ie,canvasRef:E,toolbarRef:k}),e.isAnnotating&&a&&a.size>0&&pt(zs,{inFlightSelectorColors:a}),e.isAnnotating&&ot&&pt(zs,{inFlightSelectorColors:ot,animated:!1}),e.activeTool==="hand"&&e.isAnnotating&&(st?Jt.current.element:Bt)&&pt(Ys,{element:st?Jt.current.element:Bt,gap:st?{row:st.row,column:st.column}:dr(Bt),accentColor:e.activeColor,hoveredAxis:gt,draggingAxis:st?.axis??null,cursorViewport:tt,isAutoGap:eo,refreshKey:Un}),e.activeTool==="hand"&&e.isAnnotating&&On&&pt(lc,{element:On.target,modifier:On.modifier,accentColor:e.activeColor,refreshKey:Un}),e.activeTool==="hand"&&e.isAnnotating&&!On&&(ht?at.current.element:Xt)&&pt(Hl,{element:ht?at.current.element:Xt,radius:ht?.radius??ur(Xt),accentColor:e.activeColor,hoveredCorner:Te,draggingCorner:ht?.corner??null,cursorViewport:tt}),e.activeTool==="hand"&&e.isAnnotating&&!On&&(Wt?Pe.current.element:ct)&&pt(cc,{element:Wt?Pe.current.element:ct,fontSize:Wt?.fontSize??Qr(ct).fontSize,lineHeight:Wt?.lineHeight??Qr(ct).lineHeight,accentColor:e.activeColor,hoveredProperty:qt,draggingProperty:Wt?.property??null,cursorViewport:tt}),e.activeTool==="hand"&&e.isAnnotating&&!On&&(Se?qe.current.element:Rt)&&pt(qs,{element:Se?qe.current.element:Rt,padding:Se?.padding??Rr(Rt),accentColor:e.activeColor,hoveredSide:Dt,draggingSide:Se?.side??null,cursorViewport:tt,refreshKey:Wt?Wt.fontSize+Wt.lineHeight*1e3:0}),e.activeTool==="inspector"&&e.isAnnotating&&pt(Jr,{children:G&&!e.inspectedElement&&(()=>{if(yi(G))return null;let h=!!Ee||!!g?.linkedSelector||re.some(x=>{if(!x.linkedSelector)return!1;try{return G.matches(x.linkedSelector)}catch{return!1}});return pt(yo,{element:G,isSelected:!1,elementInfo:ie,color:e.activeColor,hideTooltip:h})})()}),(g?.linkedSelector||Ee?.linkedSelector)&&(()=>{let h=g?.linkedSelector||Ee?.linkedSelector;if(!h)return null;let x=null;try{x=document.querySelector(h)}catch{}return x?pt(yo,{element:x,isSelected:!0,color:e.activeColor,hideTooltip:!0}):null})(),N&&(()=>{let h=e.annotations.find(y=>y.id===N);if(!h?.linkedSelector)return null;let x=null;try{x=document.querySelector(h.linkedSelector)}catch{}if(!x)return null;let _=!!(o&&o.has(h.id));return pt(yo,{element:x,isSelected:!_,color:h.color,hideTooltip:!0})})(),rt&&(()=>{let h=e.annotations.find(w=>w.id===rt);if(!h?.linkedSelector)return null;let x=null;try{x=document.querySelector(h.linkedSelector)}catch{}if(!x)return null;let _=h.groupId?e.annotations.filter(w=>w.groupId===h.groupId):[h],y=!!(o&&_.some(w=>o.has(w.id)));return pt(yo,{element:x,isSelected:!y,color:h.color,hideTooltip:!0})})(),et&&(()=>{let h=null;try{h=document.querySelector(et)}catch{}if(!h)return null;let x=!!(s&&s.has(et));return pt(yo,{element:h,isSelected:!x,color:e.activeColor,hideTooltip:!0})})(),e.activeTool==="model"&&e.isAnnotating&&Xe.size>0&&[...Xe.entries()].map(([h,x])=>pt(yo,{element:x.rootElement,isSelected:!0,elementInfo:{selector:"",tagName:x.rootElement.tagName.toLowerCase(),reactComponent:h},color:"#8b5cf6"},h)),e.activeTool==="model"&&e.isAnnotating&&Fo&&pt(yo,{element:Fo.rootElement,isSelected:!0,elementInfo:{selector:"",tagName:Fo.rootElement.tagName.toLowerCase(),reactComponent:Fo.name},color:"#22c55e"}),e.activeTool==="model"&&e.isAnnotating&&Qo.length>0&&Qo.map((h,x)=>pt("div",{style:{position:"absolute",left:h.x,top:h.y,width:h.width,height:h.height,backgroundColor:"rgba(255, 0, 0, 0.08)",pointerEvents:"none",zIndex:9998},children:h.direction==="vertical"?Gr(Jr,{children:[pt("div",{style:{position:"absolute",left:"50%",top:0,width:6,height:1,backgroundColor:"#FF0000",transform:"translateX(-50%)"}}),pt("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,backgroundColor:"#FF0000",transform:"translateX(-50%)"}}),pt("div",{style:{position:"absolute",left:"50%",bottom:0,width:6,height:1,backgroundColor:"#FF0000",transform:"translateX(-50%)"}}),pt("div",{style:{position:"absolute",left:"calc(50% + 6px)",top:h.height<16?-6:"50%",transform:h.height<16?"none":"translateY(-50%)",fontSize:11,fontWeight:600,color:"#fff",backgroundColor:"#FF0000",padding:"2px 4px",whiteSpace:"nowrap",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1},children:Math.round(h.height)})]}):Gr(Jr,{children:[pt("div",{style:{position:"absolute",left:0,top:"50%",width:1,height:6,backgroundColor:"#FF0000",transform:"translateY(-50%)"}}),pt("div",{style:{position:"absolute",left:0,right:0,top:"50%",height:1,backgroundColor:"#FF0000",transform:"translateY(-50%)"}}),pt("div",{style:{position:"absolute",right:0,top:"50%",width:1,height:6,backgroundColor:"#FF0000",transform:"translateY(-50%)"}}),pt("div",{style:{position:"absolute",left:h.width<30?0:"50%",top:(h.width<30,void 0),bottom:"calc(50% + 4px)",transform:h.width<30?"none":"translateX(-50%)",fontSize:11,fontWeight:600,color:"#fff",backgroundColor:"#FF0000",padding:"2px 4px",whiteSpace:"nowrap",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:1},children:Math.round(h.width)})]})},x)),e.activeTool==="model"&&e.isAnnotating&&ge&&pt(yo,{element:ge.rootElement,isSelected:!1,elementInfo:{selector:"",tagName:ge.rootElement.tagName.toLowerCase(),reactComponent:ge.name},color:v?.has(ge.name)?"#22c55e":"#8b5cf6"}),e.activeTool==="hand"&&e.isAnnotating&&e.inspectedElement&&Gr(Jr,{children:[W&&W!=="padding"&&W!=="gap"&&(()=>{let h=new Set(re.map(L=>L.groupId||L.id)).size,x=e.inspectedElement.info.selector,_=ne.findIndex(L=>L.selector===x),y=_>=0?h+_+1:h+ne.length+1,w=ne.find(L=>L.selector===x),T=w?.changes.length??0,H=!!w?.captured;return pt(yo,{element:e.inspectedElement.el,isSelected:!0,elementInfo:e.inspectedElement.info,color:H?"#999999":e.activeColor,annotationNumber:y,changeCount:T})})(),W==="padding"&&pt(qs,{element:e.inspectedElement.el,padding:Rr(e.inspectedElement.el),accentColor:e.activeColor,hoveredSide:null,draggingSide:null}),W==="gap"&&pt(Ys,{element:e.inspectedElement.el,gap:dr(e.inspectedElement.el),accentColor:e.activeColor,hoveredAxis:null,draggingAxis:null}),pt(sc,{element:e.inspectedElement.el,elementInfo:e.inspectedElement.info,selector:e.inspectedElement.info.selector,styleModifications:ne,dispatch:t,onClose:()=>t({type:"SELECT_ELEMENT",payload:null}),onHover:ye,accentColor:e.activeColor,toolbarRef:k})]})]})}import{useCallback as Yn,useEffect as hn,useMemo as br,useRef as Ot,useState as vr}from"react";import{Check as Cg,Circle as Eg,Component as Tg,Fingerprint as kg,Hand as Mg,MessageCircle as Ig,Pen as Rg,RefreshCw as Lg,Slash as Ag,Square as Pg,Trash2 as Bg,Type as Dg}from"lucide-react";import{useEffect as fc,useRef as gc}from"react";function mc(e,t,n,o,r){let i=gc(0),s=gc(t.annotations);fc(()=>{if(!n.current||!e)return;s.current=t.annotations;let a=t.annotations.length;a>0&&(a>=i.current||!o)&&(localStorage.setItem(r.annotations,JSON.stringify(t.annotations)),i.current=a)},[t.annotations,e,o,n,r]),fc(()=>{n.current&&(localStorage.setItem(r.expanded,String(e)),e&&(localStorage.setItem(r.styleMods,JSON.stringify(t.styleModifications)),localStorage.setItem(r.spacingChanges,JSON.stringify(t.spacingTokenChanges)),localStorage.setItem(r.tool,t.activeTool),localStorage.setItem(r.color,t.activeColor),localStorage.setItem(r.stroke,String(t.strokeWidth)),t.inspectedElement?localStorage.setItem(r.inspected,JSON.stringify({selector:t.inspectedElement.info.selector,info:t.inspectedElement.info})):localStorage.removeItem(r.inspected)))},[e,t.styleModifications,t.spacingTokenChanges,t.activeTool,t.activeColor,t.strokeWidth,t.inspectedElement,n,r])}import{useCallback as Rn,useEffect as mr,useMemo as pa,useRef as li,useState as vo}from"react";import{Fragment as Ef,jsx as At,jsxs as co}from"react/jsx-runtime";var of={width:340,backgroundColor:"#eaeaea",...Nr,boxSizing:"content-box",zIndex:10001,display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12,color:"#1f2937",padding:12,pointerEvents:"auto"},rf=(e,t)=>({width:"100%",border:"1px solid rgba(0,0,0,0.12)",background:t?"rgba(0,0,0,0.04)":"rgba(0,0,0,0.02)",cursor:e?"default":"pointer",fontFamily:"inherit",fontSize:11,fontWeight:600,padding:"5px 8px",color:e?"#9ca3af":"#6b7280"}),sf=e=>({border:0,background:"transparent",color:e?"#111827":"#6b7280",cursor:"pointer",fontFamily:"inherit",fontSize:10,fontWeight:700,padding:0,textTransform:"uppercase"}),fa={border:"1px solid rgba(0,0,0,0.12)",background:"rgba(0,0,0,0.02)",cursor:"pointer",fontFamily:"inherit",fontSize:10,fontWeight:650,color:"#6b7280",padding:"6px 8px",flex:1},Xi={...fa,borderColor:"#111827",background:"#111827",color:"#ffffff"},af={...Xi,cursor:"default",opacity:.55},ga={display:"block",width:"100%",border:0,background:"transparent",boxSizing:"border-box",color:"inherit",cursor:"text",font:"inherit",lineHeight:1.25,margin:0,padding:0,textAlign:"left"},lf={...ga,appearance:"none",resize:"none",overflow:"hidden",outline:"none"},vc={...ga,fontWeight:700,fontSize:11,lineHeight:1.35},cf={...vc,appearance:"none",resize:"none",overflow:"hidden",outline:"none"},hc={display:"grid",gridTemplateColumns:"12px minmax(0, 1fr)",columnGap:4,alignItems:"start",marginBottom:5},df={pass:"#2f855a",fail:"#c53030",needs_review:"#6b7280"},uf={pass:"\u2611",fail:"\u2612",needs_review:"\u25A1"},pf=e=>e?e.charAt(0).toUpperCase()+e.slice(1):"Eval",ff=[{id:"pending",label:"Pending"},{id:"approved",label:"Approved"},{id:"rejected",label:"Rejected"}],yc="popmelt-eval-active-status",gf=e=>e==="pending"||e==="approved"||e==="rejected";function xc({bridgeUrl:e,refreshKey:t,onMouseEnter:n,onMouseLeave:o,onSynthesize:r,isSynthesizing:i,onRunEval:s,onViewRunThread:a,runningEvalIds:l=[],snapPosition:d="bottom-right"}){let c=li(null),p=i||!r,[u,m]=vo({version:1,updatedAt:0,cases:[]}),[v,b]=vo(!0),[I,P]=vo(()=>{if(typeof window>"u")return"pending";try{let M=window.localStorage.getItem(yc);return gf(M)?M:"pending"}catch{return"pending"}});mr(()=>{let M=c.current;if(!M)return;let B=n,f=o;return B&&M.addEventListener("mouseenter",B),f&&M.addEventListener("mouseleave",f),()=>{B&&M.removeEventListener("mouseenter",B),f&&M.removeEventListener("mouseleave",f)}},[n,o]);let N=Rn(()=>{e&&(b(!0),za(e).then(M=>{m(M),b(!1)}).catch(()=>b(!1)))},[e]);mr(()=>{N()},[N,t]),mr(()=>{try{window.localStorage.setItem(yc,I)}catch{}},[I]);let C=Rn((M,B)=>{e&&(m(f=>({...f,cases:f.cases.map(g=>g.id===M?{...g,status:B}:g)})),$a(M,B,e).then(f=>{f||N()}).catch(N))},[e,N]),k=Rn((M,B)=>{if(!e)return;let f=B.map(g=>g.trim()).filter(Boolean);f.length!==0&&(m(g=>({...g,cases:g.cases.map(j=>j.id===M?{...j,assertions:f}:j)})),vi(M,{assertions:f},e).then(g=>{g||N()}).catch(N))},[e,N]),E=Rn((M,B)=>{if(!e)return;let f=B.trim();f&&(m(g=>({...g,cases:g.cases.map(j=>j.id===M?{...j,title:f}:j)})),vi(M,{title:f},e).then(g=>{g||N()}).catch(N))},[e,N]),$=pa(()=>{let M=u.cases.filter(g=>g.status==="pending"),B=u.cases.filter(g=>g.status==="approved"),f=u.cases.filter(g=>g.status==="rejected");return{pending:M,approved:B,rejected:f}},[u.cases]),Q=$[I],V=pa(()=>{let M=new Map,B=[...u.runs??[]].sort((f,g)=>g.completedAt-f.completedAt);for(let f of B)M.has(f.evalId)||M.set(f.evalId,f);return M},[u.runs]);return co("div",{ref:c,style:{...of,...Mi(d)},children:[co("div",{style:{display:"flex",alignItems:"center",gap:6,fontWeight:700,fontSize:13,marginBottom:6},children:[At("span",{children:"Evals"}),At("code",{style:{fontSize:10,fontWeight:500,backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",color:"#6b7280"},children:"E"})]}),At("button",{type:"button",disabled:p,onClick:r,style:rf(p,i),children:i?"Synthesizing...":"Synthesize"}),At("div",{style:{display:"flex",gap:12,marginTop:8},children:ff.map(M=>At(bf,{active:I===M.id,label:`${M.label} ${$[M.id].length}`,onClick:()=>P(M.id)},M.id))}),At("div",{style:{marginTop:10,flex:1,minHeight:0,overflowY:"auto",display:"flex",flexDirection:"column",gap:10},children:v?At("div",{style:{color:"#9ca3af",fontSize:11},children:"Loading..."}):u.cases.length===0?At("div",{style:{color:"#9ca3af",fontSize:11,lineHeight:1.5},children:"No inferred evals yet."}):Q.length===0?co("div",{style:{color:"#9ca3af",fontSize:11,lineHeight:1.5},children:["No ",I," evals."]}):At(mf,{cases:Q,latestRunsByEvalId:V,runningEvalIds:l,onStatus:C,onRun:s,onViewRunThread:a,onTitleChange:E,onAssertionsChange:k})})]})}function mf({cases:e,latestRunsByEvalId:t,runningEvalIds:n,onStatus:o,onRun:r,onViewRunThread:i,onTitleChange:s,onAssertionsChange:a}){return At("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.map(l=>{let d=new Set([...l.sourceDecisionIds,...l.sourceThreadIds]).size,c=d>0?`, ${d} ${d===1?"mention":"mentions"}`:"",p=t.get(l.id),u=n.includes(l.id);return co("div",{style:{border:"1px solid rgba(0,0,0,0.08)",background:"rgba(255,255,255,0.35)",padding:8},children:[co("div",{children:[At(vf,{value:l.title,onCommit:m=>s(l.id,m)}),co("div",{style:{color:"#9ca3af",fontSize:10,marginTop:2},children:[pf(l.category),c]})]}),At("div",{style:{marginTop:6,color:"#374151",fontSize:11,lineHeight:1.25},children:At(Cf,{assertions:l.assertions,latestRun:p,onChange:m=>a(l.id,m)})}),At(yf,{item:l,latestRun:p,isRunning:u,onStatus:o,onRun:r,onViewRunThread:i})]},l.id)})})}function hf(e){let t=e.assertionResults.length;if(t===0)return e.status==="pass"?"Pass":"Review";let n=e.assertionResults.reduce((r,i)=>(r[i.status]+=1,r),{pass:0,fail:0,needs_review:0}),o=n.fail+n.needs_review;return o===0?`${n.pass||t} Pass`:`Review ${o||t}`}function yf({item:e,latestRun:t,isRunning:n,onStatus:o,onRun:r,onViewRunThread:i}){if(e.status==="pending")return co("div",{style:{display:"flex",gap:6,marginTop:8},children:[At("button",{type:"button",style:fa,onClick:()=>o(e.id,"rejected"),children:"Reject"}),At("button",{type:"button",style:Xi,onClick:()=>o(e.id,"approved"),children:"Accept"})]});if(e.status==="approved"){let s=n||!r;return co("div",{style:{display:"flex",gap:6,marginTop:8},children:[t?.threadId&&i&&At("button",{type:"button",style:fa,onClick:()=>i(t.threadId),children:hf(t)}),At("button",{type:"button",disabled:s,style:s?af:Xi,onClick:()=>r?.(e),children:n?"Running...":"Run"})]})}return At("div",{style:{display:"flex",gap:6,marginTop:8},children:At("button",{type:"button",style:Xi,onClick:()=>o(e.id,"approved"),children:"Approve"})})}function bf({active:e,label:t,onClick:n}){let[o,r]=vo(!1);return At("button",{type:"button",style:sf(e||o),onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),onClick:n,children:t})}function vf({value:e,onCommit:t}){let[n,o]=vo(!1),[r,i]=vo(e),s=li(null);mr(()=>{n||i(e)},[n,e]),mr(()=>{if(!n)return;let c=s.current;c&&(c.focus(),c.select(),c.style.height="auto",c.style.height=`${c.scrollHeight}px`)},[n]);let a=Rn(()=>{let c=r.trim();o(!1),c&&c!==e?t(c):i(e)},[r,t,e]),l=Rn(()=>{i(e),o(!1)},[e]),d=Rn(c=>{c.key==="Enter"?(c.preventDefault(),a()):c.key==="Escape"&&(c.preventDefault(),l())},[l,a]);return n?At("textarea",{ref:s,rows:1,value:r,onChange:c=>{i(c.target.value),c.currentTarget.style.height="auto",c.currentTarget.style.height=`${c.currentTarget.scrollHeight}px`},onBlur:a,onKeyDown:d,style:cf}):At("button",{type:"button",onClick:()=>o(!0),style:vc,children:e})}function xf(e){return e.map(t=>t.trim()).filter(Boolean)}function Sf(e,t){return e.length===t.length&&e.every((n,o)=>n===t[o])}function bc(e){e.style.height="auto",e.style.height=`${e.scrollHeight}px`}function wf(e){let t=window.getComputedStyle(e),n=Number.parseFloat(t.lineHeight)||Number.parseFloat(t.fontSize)*1.2||16,o=document.createElement("div"),r=document.createElement("span"),i=document.createElement("span");o.style.position="fixed",o.style.visibility="hidden",o.style.pointerEvents="none",o.style.left="-9999px",o.style.top="0",o.style.width=`${e.clientWidth}px`,o.style.boxSizing=t.boxSizing,o.style.font=t.font,o.style.letterSpacing=t.letterSpacing,o.style.lineHeight=t.lineHeight,o.style.padding=t.padding,o.style.border=t.border,o.style.whiteSpace="pre-wrap",o.style.overflowWrap="break-word",o.style.wordBreak=t.wordBreak;let s=e.selectionStart??0;o.textContent=e.value.slice(0,s),r.textContent="\u200B",o.appendChild(r),o.appendChild(document.createTextNode(e.value.slice(s)||"\u200B")),i.textContent="\u200B",o.appendChild(i),document.body.appendChild(o);let a=Math.max(0,Math.round(r.offsetTop/n)),l=Math.max(0,Math.round(i.offsetTop/n));return o.remove(),{lineIndex:a,lastLineIndex:l}}function Cf({assertions:e,latestRun:t,onChange:n}){let[o,r]=vo(null),[i,s]=vo(e),[a,l]=vo(null),[d,c]=vo(0),p=li([]),u=li(null),m=li(!1),v=o!==null,b=v?i.length+1:i.length,I=pa(()=>{let B=new Map;for(let f of t?.assertionResults??[])B.set(f.assertion.trim(),f);return B},[t]);mr(()=>{v||s(e)},[e,v]),mr(()=>{if(a===null)return;let B=requestAnimationFrame(()=>{let f=p.current[a];if(f){if(f.focus(),u.current==="select"&&f.value)f.select();else if(u.current==="start")f.setSelectionRange(0,0);else if(u.current==="end"){let g=f.value.length;f.setSelectionRange(g,g)}u.current=null,bc(f)}});return()=>cancelAnimationFrame(B)},[a,d,b]);let P=Rn((B,f=null)=>{u.current=f,r(B),l(B),c(g=>g+1)},[]),N=Rn(B=>{let f=xf(B);return f.length===0?(s(e),e):(s(f),Sf(f,e)||n(f),f)},[e,n]),C=Rn(B=>{P(B,"select")},[P]),k=Rn((B,f)=>{s(g=>{let j=[...g];if(B>=j.length){if(f.length===0)return j;j.push(f)}else j[B]=f;return j})},[]),E=Rn((B,f)=>{let g=[...i],fe=(B<g.length?g[B]??"":"").trim();if(B>=g.length){let Ce=f?.focusPlaceholder?g.length:f?.focusIndex;Ce!==void 0?P(Ce,f?.focusMode):(r(null),l(null));return}if(!fe){if(f?.deleteEmpty){g.splice(B,1);let Ce=N(g),Ee=f.focusPlaceholder?Ce.length:f.focusIndex;if(Ee!==void 0){let K=Math.min(Ee,Ce.length);P(K)}else r(null),l(null)}else g[B]=e[B]??"",s(g),f?.focusIndex!==void 0?P(f.focusIndex,f.focusMode):(r(null),l(null));return}g[B]=fe;let Re=N(g),le=f?.focusPlaceholder?Re.length:f?.focusIndex;if(le!==void 0){let Ce=Math.min(le,Re.length);P(Ce,f?.focusMode)}else r(null),l(null)},[e,i,N,P]),$=Rn(()=>{s(e),r(null),l(null)},[e]),Q=Rn((B,f)=>{let g=f.currentTarget.value,j=f.currentTarget.selectionStart,fe=f.currentTarget.selectionEnd,Re=j===fe;if((f.key==="ArrowUp"||f.key==="ArrowDown")&&Re){let{lineIndex:le,lastLineIndex:Ce}=wf(f.currentTarget);if(f.key==="ArrowUp"&&le===0&&B>0){f.preventDefault(),m.current=!0,E(B,{focusIndex:B-1,focusMode:"end",deleteEmpty:!1});return}if(f.key==="ArrowDown"&&le===Ce&&B<b-1){f.preventDefault(),m.current=!0,E(B,{focusIndex:B+1,focusMode:"start",deleteEmpty:!1});return}}if(f.key==="Backspace"&&g.length===0){f.preventDefault(),m.current=!0;let le=[...i],Ce=B-1;if(B<le.length){le.splice(B,1);let Ee=N(le);if(Ce>=0){let K=Math.min(Ce,Ee.length-1);P(K,"end")}else r(null),l(null)}else Ce>=0&&P(Ce,"end");return}f.key==="Enter"?(f.preventDefault(),E(B,{focusPlaceholder:f.metaKey||f.ctrlKey,deleteEmpty:!0})):f.key==="Escape"&&(f.preventDefault(),$())},[$,E,i,N,P,b]),V=Rn((B,f)=>{if(m.current){m.current=!1;return}let g=p.current.findIndex(j=>j===f.relatedTarget);E(B,{deleteEmpty:!1,focusIndex:g>=0?g:void 0})},[E]),M=Rn((B,f)=>{f.preventDefault(),o!==null?(m.current=!0,E(o,{focusIndex:B,focusMode:"select",deleteEmpty:!1})):P(B,"select")},[E,o,P]);return co(Ef,{children:[At("style",{children:`
8
8
  .popmelt-eval-assertion-input::placeholder {
9
9
  color: #aaa;
10
10
  opacity: 1;
11
11
  }
12
- `}),Array.from({length:h},(A,y)=>{let T=i[y]??"",L=x&&y>=i.length,ce=o===y||L,be=(L?void 0:I.get(T.trim()))?.status,j=be?Ap[be]:"#374151",se=be?Pp[be]:"\u25A1",_=be?{color:j}:{},he=be?{color:j}:{};return ce?Zn("div",{style:Kl,children:[kt("span",{style:_,children:se}),kt("textarea",{className:"popmelt-eval-assertion-input",ref:fe=>{u.current[y]=fe},rows:1,value:T,placeholder:L?"cmd+enter to add new assertion":void 0,onFocus:()=>r(y),onChange:fe=>{M(y,fe.target.value),ql(fe.currentTarget)},onBlur:fe=>C(y,fe),onKeyDown:fe=>ee(y,fe),style:{...Rp,...he}})]},`assertion-${y}`):Zn("div",{style:Kl,children:[kt("span",{style:_,children:se}),kt("button",{type:"button",onMouseDown:fe=>S(y,fe),onClick:()=>F(y),style:{...Ys,...he},children:T})]},`assertion-${y}`)})]})}import{Component as df,createElement as uf,useCallback as Oi,useEffect as Oo,useRef as Qo,useState as Hn}from"react";import{Link2 as pf}from"lucide-react";var Yp={colors:[],fonts:[],typeScale:[],spacing:[],radii:[],shadows:[],other:[],references:{}},Vp=/^#[0-9a-fA-F]{3,8}$/,Up=/^(?:rgba?|hsla?|oklch|oklab|lch|lab)\(/,Kp=new Set(["transparent","currentcolor","inherit","white","black","red","green","blue","yellow","orange","purple","pink","gray","grey","cyan","magenta","brown","navy","teal","maroon","olive","silver","aqua","fuchsia","lime"]);function tc(e){let t=e.trim().toLowerCase();return Vp.test(t)||Up.test(t)||Kp.has(t)}var Xp=/^-?\d+(\.\d+)?(px|rem|em|%)$/;function Vs(e){return Xp.test(e.trim())}var ec=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]);function qp(e){let t=e.trim().toLowerCase();return!!(ec.has(t)||t.includes(",")&&t.split(",").some(n=>ec.has(n.trim().replace(/['"]/g,""))))}function Zp(e){let t=e.trim().toLowerCase(),n=t.match(/\d+(\.\d+)?px/g);return!!(n&&n.length>=2&&(tc(t.replace(/[^#()\w,.\s/%]/g,"").split(/\s+/).pop()||"")||t.includes("rgb")||t.includes("hsl")||t.includes("#")))}var Qp=/(?:^--(color|bg|fg|accent|border-color|text-color|surface|background|foreground))|(?:-(color|bg|fg)$)/i,ef=/^--(font-family|font|ff|family)/i,tf=/^--(font-size|text-size|fs|text-(?:xs|sm|base|md|lg|xl|2xl|3xl|4xl|5xl))/i,nf=/^--(space|gap|padding|margin|inset)/i,of=/^--(radius|rounded|br|border-radius)/i,rf=/^--(shadow|elevation|drop-shadow)/i;function nc(e,t){let n=e.toLowerCase();return rf.test(n)?"shadows":of.test(n)?"radii":ef.test(n)?"fonts":tf.test(n)&&Vs(t)?"typeScale":Qp.test(n)||tc(t)?"colors":qp(t)?"fonts":Zp(t)?"shadows":nf.test(n)&&Vs(t)||Vs(t)?"spacing":"other"}function oc(e,t,n,o){if(e)for(let r of e){if(r instanceof CSSGroupingRule){oc(r.cssRules,t,n,o);continue}if(r instanceof CSSStyleRule){let i=r.selectorText.toLowerCase();(i===":root"||i==="html"||i==="*"||i.includes(":root"))&&sf(r.style,t,n,o)}}}var rc=/var\((--[^,)]+)/;function sf(e,t,n,o){for(let r=0;r<e.length;r++){let i=e[r];if(!i?.startsWith("--")||n.has(i))continue;n.add(i);let s=t.getPropertyValue(i).trim();if(!s)continue;let a=nc(i,s);o[a].push([i,s]);let p=e.getPropertyValue(i).trim().match(rc);p&&(o.references[i]=p[1])}}function Li(e){let t=e.trim().match(/^(-?\d+(?:\.\d+)?)/);return t?parseFloat(t[1]):null}function Pi(e){let t=e.trim().toLowerCase(),n=t.match(/oklch\(\s*([\d.]+%?)/);if(n){let i=n[1];return i.endsWith("%")?parseFloat(i)/100:parseFloat(i)}let o=t.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/);if(o){let[i,s,a]=[parseInt(o[1],10),parseInt(o[2],10),parseInt(o[3],10)];return(.2126*i+.7152*s+.0722*a)/255}let r=t.match(/hsla?\(\s*[\d.]+[,\s]+[\d.]+%?[,\s]+([\d.]+)%?/);if(r)return parseFloat(r[1])/100;if(t.startsWith("#")){let i=t.slice(1);(i.length===3||i.length===4)&&(i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]);let s=parseInt(i.slice(0,2),16),a=parseInt(i.slice(2,4),16),l=parseInt(i.slice(4,6),16);if(!isNaN(s))return(.2126*s+.7152*a+.0722*l)/255}return null}function ic(e){return e==="colors"?(t,n)=>{let o=Pi(t[1]),r=Pi(n[1]);return o!==null&&r!==null?o-r:t[0].localeCompare(n[0])}:e==="typeScale"||e==="spacing"||e==="radii"?(t,n)=>{let o=Li(t[1]),r=Li(n[1]);return o!==null&&r!==null?o-r:t[0].localeCompare(n[0])}:e==="other"?(t,n)=>{let o=Li(t[1]),r=Li(n[1]);return o!==null&&r!==null?o-r:t[0].localeCompare(n[0])}:(t,n)=>t[0].localeCompare(n[0])}function af(e){let t=e.replace(/^--/,"");t=t.replace(/^(?:color|clr)-/,"");let n=t.split("-");return n.length>1&&/^\d+$/.test(n[n.length-1])&&n.pop(),n.join("-")}function sc(e){let t=new Map;for(let r of e){let i=af(r[0]),s=t.get(i);s||(s=[],t.set(i,s)),s.push(r)}let n=ic("colors");for(let r of t.values())r.sort(n);let o=[...t.entries()];return o.sort((r,i)=>{let s=Pi(r[1][0][1])??0,a=Pi(i[1][0][1])??0;return s-a}),o}var lf=["colors","fonts","typeScale","spacing","radii","shadows","other"],Ai=null,cf=5e3;function ac(){if(typeof document>"u")return Yp;if(Ai&&Date.now()-Ai.timestamp<cf)return Ai.tokens;let e={colors:[],fonts:[],typeScale:[],spacing:[],radii:[],shadows:[],other:[],references:{}},t=new Set,n=getComputedStyle(document.documentElement);try{for(let r of document.styleSheets)try{oc(r.cssRules||r.rules,n,t,e)}catch{}}catch{}let o=document.documentElement.style;for(let r=0;r<o.length;r++){let i=o[r];if(!i?.startsWith("--")||t.has(i))continue;t.add(i);let s=n.getPropertyValue(i).trim();if(!s)continue;let a=nc(i,s);e[a].push([i,s]);let p=o.getPropertyValue(i).trim().match(rc);p&&(e.references[i]=p[1])}for(let r of lf)e[r].sort(ic(r));return Ai={tokens:e,timestamp:Date.now()},e}import{Fragment as er,jsx as Be,jsxs as Xt}from"react/jsx-runtime";var lc="popmelt-library-tab",ff=/^#[0-9a-fA-F]{3,8}$/,gf=/^(?:rgba?|hsla?|oklch)\([^)]+\)$/,mf=new Set(["black","white","red","blue","green","yellow","orange","purple","pink","gray","grey","cyan","magenta","brown","navy","teal","maroon","olive","silver","aqua","fuchsia","lime"]),hf=/^-?\d+(\.\d+)?(px|rem|em|%)$/;function dc(e){let t=e.trim();return ff.test(t)||gf.test(t)||mf.has(t.toLowerCase())}function yf(e){return hf.test(e.trim())}function bf(e){let t=e.trim().match(/^(-?\d+(?:\.\d+)?)px$/);return t?parseFloat(t[1]):null}function uc(e,t=""){if(e==null)return[];if(typeof e!="object")return[[t,String(e)]];if(Array.isArray(e))return[[t,e.map(String).join(", ")]];let n=[];for(let[o,r]of Object.entries(e)){let i=t?`${t}.${o}`:o;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){let s=r;typeof s.value=="string"?n.push([i,s.value]):n.push(...uc(r,i))}else n.push([i,Array.isArray(r)?r.map(String).join(", "):String(r??"")])}return n}function vf(e){return e.length===0?"generic":e.filter(([,o])=>dc(o)).length>e.length/2?"colors":e.filter(([,o])=>yf(o)).length>e.length/2?"spacing":"generic"}var xf={width:300,backgroundColor:"#eaeaea",...Po,boxSizing:"content-box",zIndex:10001,display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12,color:"#1f2937",padding:12,pointerEvents:"auto"},pc={border:"none",background:"none",cursor:"pointer",fontFamily:"inherit",fontSize:11,fontWeight:600,padding:"2px 0",color:"#9ca3af"},Sf={...pc,color:"#1f2937",borderBottom:"1.5px solid #1f2937"};function wf({varName:e,value:t,reference:n}){return Be("div",{title:n?`${e} \u2192 ${n}
13
- ${t}`:`${e}: ${t}`,style:{width:28,height:28,backgroundColor:t,outline:"1px solid rgba(0,0,0,0.08)",outlineOffset:-1,position:"relative"},children:n&&Be(pf,{size:10,strokeWidth:2.5,style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",filter:"drop-shadow(0 0 1px rgba(0,0,0,0.5))"}})})}function fc({entries:e,references:t}){let n=[],o=[];for(let i of e)dc(i[1])?n.push(i):o.push(i);let r=sc(n);return Xt(er,{children:[r.map(([i,s])=>Xt("div",{style:{marginBottom:4},children:[Xt("div",{style:{fontSize:10,color:"#9ca3af",marginBottom:2},children:[i,s.length>1?` (${s.length})`:""]}),Be("div",{style:{display:"flex",flexWrap:"wrap",gap:2},children:s.map(([a,l])=>Be(wf,{varName:a,value:l,reference:t[a]},a))})]},i)),o.length>0&&Be(Bi,{entries:o})]})}var Di=[0,1,2,4,8,12,16,20,24,28,32];function Cf(e){if(e<=32){let t=Di[0],n=Math.abs(e-t);for(let o=1;o<Di.length;o++){let r=Math.abs(e-Di[o]);r<n&&(t=Di[o],n=r)}return t}return Math.round(e/8)*8}function Ef({label:e,value:t,px:n,tokenPath:o,rawToken:r,onHover:i,onModify:s,onDelete:a}){let[l,p]=Hn(!1),[c,u]=Hn(null),d=Qo(!1),g=Qo(0),x=Qo(0),h=Qo([]),I=c!==null?c:n,O=c!==null?`${c}px`:t,P=c!==null,F=Oi(D=>{D.preventDefault(),d.current=!0,g.current=D.clientX,x.current=n;let J=di(r);h.current=us(J);let ee=S=>{let A=S.clientX-g.current,y=Math.max(0,Math.round(x.current+A));S.shiftKey&&(y=Cf(y));for(let T of h.current)T.element.style.setProperty(T.property,y+"px","important");u(y),i?.({name:e,px:y,token:J})},C=()=>{window.removeEventListener("mousemove",ee),window.removeEventListener("mouseup",C),document.body.style.cursor="",d.current=!1,u(S=>{if(S!==null&&S!==n&&s){let A=di(r),y=A.bindings&&A.bindings.length>0,T;if(y){let be=fs(A.bindings,x.current,S);T=JSON.stringify({...A,value:`${S}px`,bindings:be})}else{let be=el(h.current,x.current),j=tl(h.current);if(be.length>0){let se=fs(be,x.current,S);T=JSON.stringify({value:`${S}px`,property:j,bindings:se})}else T=`${S}px`}let L=typeof r=="string"?r:JSON.stringify(r),ce=h.current.map(be=>({selector:Dn(be.element),property:be.property})),We=ol(h.current,x.current,S);s({tokenPath:o,originalValue:L,currentValue:T,targets:ce,originalPx:x.current,currentPx:S},{id:Math.random().toString(36).substring(2,9),tokenPath:o,tokenName:e,originalPx:x.current,newPx:S,affectedElements:We})}return S})};document.body.style.cursor="ew-resize",window.addEventListener("mousemove",ee),window.addEventListener("mouseup",C)},[n,e,o,r,i,s]),M=di(r);return Xt("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:11,padding:"1px 0",cursor:"ew-resize",userSelect:"none"},onMouseEnter:()=>{d.current||(p(!0),i?.({name:e,px:I,token:M}))},onMouseLeave:()=>{d.current||(p(!1),i?.(null))},onMouseDown:F,children:[Be("span",{style:{color:l||P?"#FF0000":"#9ca3af"},children:e}),Xt("span",{style:{display:"flex",alignItems:"center",gap:4},children:[Be("span",{style:{color:l||P?"#FF0000":"#6b7280",fontWeight:600},children:O}),a&&l&&!P&&Be("button",{type:"button",title:"Remove token",onMouseDown:D=>{D.stopPropagation();let J=typeof r=="string"?r:JSON.stringify(r);a(o,J)},style:{border:"none",background:"none",cursor:"pointer",padding:0,fontSize:10,lineHeight:1,color:"#9ca3af"},onMouseEnter:D=>{D.currentTarget.style.color="#FF0000"},onMouseLeave:D=>{D.currentTarget.style.color="#9ca3af"},children:"\u2715"})]})]})}function kf({entries:e,categoryKey:t,rawTokens:n,onHover:o,onModify:r,onDelete:i}){let s=[],a=[];for(let l of e){let p=bf(l[1]);p!==null?s.push([l[0],l[1],p]):a.push(l)}return Xt(er,{children:[s.length>0&&Be("div",{style:{display:"flex",flexDirection:"column",gap:2},children:s.map(([l,p,c])=>{let u=l.split(".").pop(),d=n?Tf(n,l):p,g=d&&typeof d=="object"&&"value"in d?d:p;return Be(Ef,{label:u,value:p,px:c,tokenPath:`tokens.${t}.${l}`,rawToken:g,onHover:o,onModify:r,onDelete:i},l)})}),a.length>0&&Be(Bi,{entries:a})]})}function Tf(e,t){let n=t.split("."),o=e;for(let r of n){if(o==null||typeof o!="object")return;o=o[r]}return o}function Bi({entries:e}){return Be("div",{style:{display:"flex",flexDirection:"column",gap:3},children:e.map(([t,n])=>Xt("div",{style:{fontSize:11},children:[Be("div",{style:{color:"#9ca3af",fontSize:10,marginBottom:1},children:t}),Be("div",{style:{color:"#1f2937",lineHeight:1.4,paddingLeft:8},children:n})]},t))})}function Mf({entries:e,categoryKey:t,rawTokens:n,onSpacingHover:o,onModifyToken:r,onDeleteToken:i}){let s=vf(e);return s==="colors"?Be(fc,{entries:e}):s==="spacing"?Be(kf,{entries:e,categoryKey:t,rawTokens:n,onHover:o,onModify:r,onDelete:i}):Be(Bi,{entries:e})}function If(e){let t=e.toLowerCase(),n=null,o=document.createTreeWalker(document.body,NodeFilter.SHOW_ELEMENT,{acceptNode(i){return i.closest("#devtools-toolbar, #devtools-canvas, #devtools-scrim, [data-popmelt-panel]")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=o.currentNode;for(;r=o.nextNode();){let i=r,s=Object.keys(i).find(l=>l.startsWith("__reactFiber$")||l.startsWith("__reactInternalInstance$"));if(!s)continue;let a=i[s];for(;a;){let l=a.type,p=typeof l=="function"||typeof l=="object"?l?.displayName||l?.name:null;if(typeof p=="string"){let c=p.toLowerCase();if(c===t){let u={...a.memoizedProps};return delete u.ref,{type:l,props:u}}if(!n){if(c.length>=4&&t.includes(c)){let u={...a.memoizedProps};delete u.ref,n={type:l,props:u}}else if(t.length>=4&&c.includes(t)){let u={...a.memoizedProps};delete u.ref,n={type:l,props:u}}}}a=a.return}}return n}var Us=class extends df{constructor(){super(...arguments);this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(){this.props.onError()}render(){return this.state.hasError?null:this.props.children}},gc="popmelt-principles-collapsed";function Rf(){try{let e=localStorage.getItem(gc);if(e)return new Set(JSON.parse(e))}catch{}return new Set}function Lf(e){try{localStorage.setItem(gc,JSON.stringify([...e]))}catch{}}function Af({id:e,label:t,count:n,children:o,collapsed:r,onToggle:i}){return Xt("div",{style:{marginBottom:14},children:[Xt("div",{onClick:()=>i(e),style:{fontWeight:700,fontSize:11,color:"#6b7280",letterSpacing:"0.05em",marginBottom:r?0:6,cursor:"pointer",display:"flex",alignItems:"center",gap:4,userSelect:"none"},children:[Be("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:10,fontSize:9,color:"#9ca3af",transform:r?"rotate(-90deg)":"rotate(0deg)"},children:"\u25BC"}),t,Be("span",{style:{fontWeight:400,color:"#9ca3af"},children:n})]}),!r&&o]})}var Pf={colors:"Colors",fonts:"Fonts",typeScale:"Type Scale",spacing:"Spacing",radii:"Radii",shadows:"Shadows",other:"Other"},cc=["colors","fonts","typeScale","spacing","radii","shadows","other"];function Df(){let[e,t]=Hn(null),[n,o]=Hn(Rf);Oo(()=>{t(ac())},[]);let r=Oi(s=>{o(a=>{let l=new Set(a);return l.has(s)?l.delete(s):l.add(s),Lf(l),l})},[]);return e?cc.some(s=>e[s].length>0)?Be(er,{children:cc.map(s=>{let a=e[s];return a.length===0?null:Be(Af,{id:s,label:Pf[s],count:a.length,collapsed:n.has(s),onToggle:r,children:s==="colors"?Be(fc,{entries:a,references:e.references}):Be(Bi,{entries:a})},s)})}):Be("div",{style:{color:"#9ca3af",fontSize:11},children:"No :root tokens found."}):null}function Of({rules:e,onSynthesize:t,isSynthesizing:n}){if(!e||e.length===0)return Be("div",{style:{color:"#9ca3af",fontSize:11},children:"No rules defined yet."});if(!e.some(i=>typeof i=="object"&&i!==null&&"scope"in i))return Be(er,{children:e.map((i,s)=>Xt("div",{style:{display:"flex",gap:6,marginBottom:4,lineHeight:1.4,fontSize:11},children:[Xt("span",{style:{color:"#9ca3af",flexShrink:0},children:[s+1,"."]}),Be("span",{children:typeof i=="string"?i:i.text})]},s))});let r=new Map;for(let i of e)if(typeof i=="string")r.has("general")||r.set("general",[]),r.get("general").push({id:"",text:i});else{let s=i.scope||"general";r.has(s)||r.set(s,[]),r.get(s).push({id:i.id,text:i.text})}return Xt(er,{children:[t&&Be("button",{type:"button",disabled:n,onClick:t,style:{width:"100%",border:"1px solid rgba(0,0,0,0.12)",background:n?"rgba(0,0,0,0.04)":"rgba(0,0,0,0.02)",cursor:n?"default":"pointer",fontFamily:"inherit",fontSize:11,fontWeight:600,padding:"5px 8px",marginBottom:10,color:n?"#9ca3af":"#6b7280"},children:n?"Synthesizing\u2026":"Synthesize"}),Array.from(r.entries()).map(([i,s])=>Xt("div",{style:{marginBottom:10},children:[Be("div",{style:{fontWeight:700,fontSize:10,color:"#6b7280",letterSpacing:"0.05em",textTransform:"uppercase",marginBottom:4},children:i}),s.map((a,l)=>Xt("div",{style:{display:"flex",gap:6,marginBottom:3,lineHeight:1.4,fontSize:11},children:[Be("span",{style:{color:"#9ca3af",flexShrink:0},children:"\u2022"}),Be("span",{children:a.text})]},a.id||l))]},i))]})}function Bf({name:e,value:t,selected:n,highlighted:o,onRemove:r,onHover:i}){let[s,a]=Hn(!1),[l,p]=Hn(!1),c=Qo(null),u=Qo(0),[d,g]=Hn(0),[x,h]=Hn(0),I=uc(t),O=I.find(([S])=>S==="description")?.[1];Oo(()=>{if(!l&&!o){g(0),h(0),u.current=0;return}let S=xr(e);g(S.length)},[l,o,e]),Oo(()=>{n&&c.current&&c.current.scrollIntoView({behavior:"smooth",block:"nearest"})},[n]);let P=n||o||l,F=n?"139,92,246":"34,197,94",M=n?"#8b5cf6":"#22c55e",D=P?`rgba(${F},0.06)`:void 0,J=P?`inset 0 0 0 1.5px rgba(${F},0.35)`:void 0,ee=o||l,C=Oi(()=>{let S=xr(e);if(S.length===0)return;let A=u.current%S.length;S[A].rootElement.scrollIntoView({behavior:"smooth",block:"center"}),h(A),u.current=A+1,i?.({name:e,instanceIndex:A})},[e,i]);return Xt("div",{ref:c,onClick:C,onMouseEnter:()=>{p(!0),i?.({name:e,instanceIndex:0})},onMouseLeave:()=>{p(!1),i?.(null)},style:{marginBottom:8,background:D,padding:6,boxShadow:J,cursor:"pointer"},children:[Xt("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[Xt("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6},children:[Be("div",{style:{fontWeight:700,fontSize:11,letterSpacing:"0.05em",padding:"2px 6px",backgroundColor:ee?M:"transparent",color:ee?"#fff":"#6b7280"},children:e}),ee&&d>1&&Xt("span",{style:{fontSize:10,fontWeight:600,color:"#9ca3af"},children:[x+1,"/",d]})]}),r&&l&&Be("button",{type:"button",title:"Remove from model",onClick:S=>{S.stopPropagation(),r(e)},style:{border:"none",background:"none",cursor:"pointer",padding:"0 2px",fontSize:14,lineHeight:1,color:"#9ca3af",marginTop:-4},onMouseEnter:S=>{S.currentTarget.style.color="#FF0000"},onMouseLeave:S=>{S.currentTarget.style.color="#9ca3af"},children:"\u2715"})]}),O&&Be("div",{style:{fontSize:11,color:ee?"#1f2937":"#9ca3af",marginBottom:6,lineHeight:1.4},children:O}),s?Be(Mf,{entries:I.filter(([S])=>S!=="description"),categoryKey:""}):Be(Hf,{name:e,onNotFound:()=>a(!0),entries:I})]})}function Hf({name:e,onNotFound:t}){let[n,o]=Hn(null),[r,i]=Hn(!1);return Oo(()=>{let s=If(e);s||t(),o(s),i(!0)},[e,t]),!r||!n?null:Be(Us,{onError:t,children:Be("div",{"data-popmelt-panel":!0,onClick:s=>{s.preventDefault(),s.stopPropagation()},style:{width:"100%",overflowY:"auto",overflowX:"hidden",maxHeight:150,padding:"1rem",outline:"1px solid rgba(0,0,0,0.06)",backgroundColor:"rgb(250,250,250)",boxSizing:"border-box",marginBottom:4,display:"flex",flexDirection:"column",justifyContent:"stretch",alignItems:"center",contain:"layout paint",position:"relative",isolation:"isolate"},children:Be("div",{style:{zoom:.5,pointerEvents:"none"},children:uf(n.type,n.props)})})})}function _f({components:e,selectedComponent:t,hoveredComponent:n,onRemove:o,onHover:r}){if(!e||Object.keys(e).length===0)return Be("div",{style:{color:"#9ca3af",fontSize:11},children:"No component patterns defined yet."});let i=new Set(Object.keys(e)),s=ls(i),a=Object.entries(e).sort(([l],[p])=>(s.get(l)??1/0)-(s.get(p)??1/0));return Be(er,{children:a.map(([l,p])=>Be(Bf,{name:l,value:p,selected:t===l,highlighted:n===l,onRemove:o,onHover:r},l))})}function mc({bridgeUrl:e,modelRefreshKey:t,onMouseEnter:n,onMouseLeave:o,selectedComponent:r,hoveredComponent:i,onComponentHover:s,onSpacingTokenHover:a,onModifySpacingToken:l,onDeleteSpacingToken:p,onComponentAdded:c,onComponentRemoved:u,onSynthesizeRules:d,isSynthesizing:g,snapPosition:x="bottom-right"}){let[h,I]=Hn(void 0),[O,P]=Hn(!0),[F,M]=Hn(()=>{try{let y=localStorage.getItem(lc);if(y==="patterns"||y==="principles"||y==="rules")return y}catch{}return"patterns"});Oo(()=>{ur(e).then(y=>{I(y),P(!1)})},[e,t]),Oo(()=>{try{localStorage.setItem(lc,F)}catch{}},[F]),Oo(()=>{r&&(M("patterns"),ur(e).then(y=>{y&&I(y)}))},[r,e]);let D=Oi(y=>{I(T=>{if(!T?.components)return T;let{[y]:L,...ce}=T.components;return{...T,components:ce}}),u?.(y)},[u]),J=h?.components,ee=h?.rules,C=J&&Object.keys(J).length>0,S=ee&&ee.length>0,A=Qo(null);return Oo(()=>{let y=A.current;if(!y)return;let T=n,L=o;return T&&y.addEventListener("mouseenter",T),L&&y.addEventListener("mouseleave",L),()=>{T&&y.removeEventListener("mouseenter",T),L&&y.removeEventListener("mouseleave",L)}},[n,o]),Xt("div",{ref:A,style:{...xf,...ii(x)},children:[Xt("div",{style:{display:"flex",alignItems:"center",gap:6,fontWeight:700,fontSize:13,marginBottom:6},children:[Be("span",{children:"Model"}),Be("code",{style:{fontSize:10,fontWeight:500,backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",color:"#6b7280"},children:"M"})]}),Be("div",{style:{display:"flex",gap:12,marginBottom:10,borderBottom:"1px solid rgba(0,0,0,0.08)",paddingBottom:6},children:["patterns","principles","rules"].map(y=>Be("button",{type:"button",style:F===y?Sf:pc,onClick:()=>M(y),children:y.charAt(0).toUpperCase()+y.slice(1)},y))}),Be("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:F==="principles"?Be(Df,{}):O?Be("div",{style:{color:"#9ca3af",fontSize:11},children:"Loading..."}):!h||!C&&!S?Be("div",{style:{color:"#9ca3af",lineHeight:1.5},children:"No design model yet. Pattern-scoped annotations will build one automatically."}):Xt(er,{children:[F==="patterns"&&Be(_f,{components:J,selectedComponent:r,hoveredComponent:i,onRemove:D,onHover:s}),F==="rules"&&Be(Of,{rules:ee,onSynthesize:d,isSynthesizing:g})]})})]})}import{jsx as Co}from"react/jsx-runtime";var Nf="M 233.959793 800.214905 L 468.644287 668.536987 L 472.590637 657.100647 L 468.644287 650.738403 L 457.208069 650.738403 L 417.986633 648.322144 L 283.892639 644.69812 L 167.597321 639.865845 L 54.926208 633.825623 L 26.577238 627.785339 L 3.3e-05 592.751709 L 2.73832 575.27533 L 26.577238 559.248352 L 60.724873 562.228149 L 136.187973 567.382629 L 249.422867 575.194763 L 331.570496 580.026978 L 453.261841 592.671082 L 472.590637 592.671082 L 475.328857 584.859009 L 468.724915 580.026978 L 463.570557 575.194763 L 346.389313 495.785217 L 219.543671 411.865906 L 153.100723 363.543762 L 117.181267 339.060425 L 99.060455 316.107361 L 91.248367 266.01355 L 123.865784 230.093994 L 167.677887 233.073853 L 178.872513 236.053772 L 223.248367 270.201477 L 318.040283 343.570496 L 441.825592 434.738342 L 459.946411 449.798706 L 467.194672 444.64447 L 468.080597 441.020203 L 459.946411 427.409485 L 392.617493 305.718323 L 320.778564 181.932983 L 288.80542 130.630859 L 280.348999 99.865845 C 277.369171 87.221436 275.194641 76.590698 275.194641 63.624268 L 312.322174 13.20813 L 332.8591 6.604126 L 382.389313 13.20813 L 403.248352 31.328979 L 434.013519 101.71814 L 483.865753 212.537048 L 561.181274 363.221497 L 583.812134 407.919434 L 595.892639 449.315491 L 600.40271 461.959839 L 608.214783 461.959839 L 608.214783 454.711609 L 614.577271 369.825623 L 626.335632 265.61084 L 637.771851 131.516846 L 641.718201 93.745117 L 660.402832 48.483276 L 697.530334 24.000122 L 726.52356 37.852417 L 750.362549 72 L 747.060486 94.067139 L 732.886047 186.201416 L 705.100708 330.52356 L 686.979919 427.167847 L 697.530334 427.167847 L 709.61084 415.087341 L 758.496704 350.174561 L 840.644348 247.490051 L 876.885925 206.738342 L 919.167847 161.71814 L 946.308838 140.29541 L 997.61084 140.29541 L 1035.38269 196.429626 L 1018.469849 254.416199 L 965.637634 321.422852 L 921.825562 378.201538 L 859.006714 462.765259 L 819.785278 530.41626 L 823.409424 535.812073 L 832.75177 534.92627 L 974.657776 504.724915 L 1051.328979 490.872559 L 1142.818848 475.167786 L 1184.214844 494.496582 L 1188.724854 514.147644 L 1172.456421 554.335693 L 1074.604126 578.496765 L 959.838989 601.449829 L 788.939636 641.879272 L 786.845764 643.409485 L 789.261841 646.389343 L 866.255127 653.637634 L 899.194702 655.409424 L 979.812134 655.409424 L 1129.932861 666.604187 L 1169.154419 692.537109 L 1192.671265 724.268677 L 1188.724854 748.429688 L 1128.322144 779.194641 L 1046.818848 759.865845 L 856.590759 714.604126 L 791.355774 698.335754 L 782.335693 698.335754 L 782.335693 703.731567 L 836.69812 756.885986 L 936.322205 846.845581 L 1061.073975 962.81897 L 1067.436279 991.490112 L 1051.409424 1014.120911 L 1034.496704 1011.704712 L 924.885986 929.234924 L 882.604126 892.107544 L 786.845764 811.48999 L 780.483276 811.48999 L 780.483276 819.946289 L 802.550415 852.241699 L 919.087341 1027.409424 L 925.127625 1081.127686 L 916.671204 1098.604126 L 886.469849 1109.154419 L 853.288696 1103.114136 L 785.073914 1007.355835 L 714.684631 899.516785 L 657.906067 802.872498 L 650.979858 806.81897 L 617.476624 1167.704834 L 601.771851 1186.147705 L 565.530212 1200 L 535.328857 1177.046997 L 519.302124 1139.919556 L 535.328857 1066.550537 L 554.657776 970.792053 L 570.362488 894.68457 L 584.536926 800.134277 L 592.993347 768.724976 L 592.429626 766.630859 L 585.503479 767.516968 L 514.22821 865.369263 L 405.825531 1011.865906 L 320.053711 1103.677979 L 299.516815 1111.812256 L 263.919525 1093.369263 L 267.221497 1060.429688 L 287.114136 1031.114136 L 405.825531 880.107361 L 477.422913 786.52356 L 523.651062 732.483276 L 523.328918 724.671265 L 520.590698 724.671265 L 205.288605 929.395935 L 149.154434 936.644409 L 124.993355 914.01355 L 127.973183 876.885986 L 139.409409 864.80542 L 234.201385 799.570435 L 233.879227 799.8927 Z",Ff="M60.8734,57.2556v-14.9432c0-1.2586.4722-2.2029,1.5728-2.8314l30.0443-17.3023c4.0899-2.3593,8.9662-3.4599,13.9988-3.4599,18.8759,0,30.8307,14.6289,30.8307,30.2006,0,1.1007,0,2.3593-.158,3.6178l-31.1446-18.2467c-1.8872-1.1006-3.7754-1.1006-5.6629,0l-39.4812,22.9651ZM131.0276,115.4561v-35.7074c0-2.2028-.9446-3.7756-2.8318-4.8763l-39.481-22.9651,12.8982-7.3934c1.1007-.6285,2.0453-.6285,3.1458,0l30.0441,17.3024c8.6523,5.0341,14.4708,15.7296,14.4708,26.1107,0,11.9539-7.0769,22.965-18.2461,27.527v.0021ZM51.593,83.9964l-12.8982-7.5497c-1.1007-.6285-1.5728-1.5728-1.5728-2.8314v-34.6048c0-16.8303,12.8982-29.5722,30.3585-29.5722,6.607,0,12.7403,2.2029,17.9324,6.1349l-30.987,17.9324c-1.8871,1.1007-2.8314,2.6735-2.8314,4.8764v45.6159l-.0014-.0015ZM79.3562,100.0403l-18.4829-10.3811v-22.0209l18.4829-10.3811,18.4812,10.3811v22.0209l-18.4812,10.3811ZM91.2319,147.8591c-6.607,0-12.7403-2.2031-17.9324-6.1344l30.9866-17.9333c1.8872-1.1005,2.8318-2.6728,2.8318-4.8759v-45.616l13.0564,7.5498c1.1005.6285,1.5723,1.5728,1.5723,2.8314v34.6051c0,16.8297-13.0564,29.5723-30.5147,29.5723v.001ZM53.9522,112.7822l-30.0443-17.3024c-8.652-5.0343-14.471-15.7296-14.471-26.1107,0-12.1119,7.2356-22.9652,18.403-27.5272v35.8634c0,2.2028.9443,3.7756,2.8314,4.8763l39.3248,22.8068-12.8982,7.3938c-1.1007.6287-2.045.6287-3.1456,0ZM52.2229,138.5791c-17.7745,0-30.8306-13.3713-30.8306-29.8871,0-1.2585.1578-2.5169.3143-3.7754l30.987,17.9323c1.8871,1.1005,3.7757,1.1005,5.6628,0l39.4811-22.807v14.9435c0,1.2585-.4721,2.2021-1.5728,2.8308l-30.0443,17.3025c-4.0898,2.359-8.9662,3.4605-13.9989,3.4605h.0014ZM91.2319,157.296c19.0327,0,34.9188-13.5272,38.5383-31.4594,17.6164-4.562,28.9425-21.0779,28.9425-37.908,0-11.0112-4.719-21.7066-13.2133-29.4143.7867-3.3035,1.2595-6.607,1.2595-9.909,0-22.4929-18.2471-39.3247-39.3251-39.3247-4.2461,0-8.3363.6285-12.4262,2.045-7.0792-6.9213-16.8318-11.3254-27.5271-11.3254-19.0331,0-34.9191,13.5268-38.5384,31.4591C11.3255,36.0212,0,52.5373,0,69.3675c0,11.0112,4.7184,21.7065,13.2125,29.4142-.7865,3.3035-1.2586,6.6067-1.2586,9.9092,0,22.4923,18.2466,39.3241,39.3248,39.3241,4.2462,0,8.3362-.6277,12.426-2.0441,7.0776,6.921,16.8302,11.3251,27.5271,11.3251Z",zf="M29.8768 25.3531C30.9809 25.3531 31.876 26.2481 31.876 27.3522V31.3505C31.876 32.4545 30.9809 33.3496 29.8768 33.3496C28.7727 33.3496 27.8777 32.4545 27.8777 31.3505V27.3522C27.8777 26.2481 28.7727 25.3531 29.8768 25.3531ZM19.8812 25.3531C20.9852 25.3531 21.8803 26.2481 21.8803 27.3522V31.3505C21.8803 32.4545 20.9852 33.3496 19.8812 33.3496C18.7771 33.3496 17.882 32.4545 17.882 31.3505V27.3522C17.882 26.2481 18.7771 25.3531 19.8812 25.3531ZM24.8601 40.8772C36.974 40.8772 46.9603 33.8278 48.6801 30.8403C48.8058 30.6218 48.8464 30.3723 48.8464 30.1202V24.8018C48.8464 24.5813 48.8124 24.3622 48.7308 24.1574C47.9871 22.2899 46.0394 19.5773 43.5257 18.8495C43.1925 17.994 42.6989 16.7433 42.2384 15.8201C42.3154 15.1138 42.3426 14.3853 42.3426 13.6492C42.3426 10.99 41.7789 8.65743 40.0805 6.92044C39.2872 6.10915 38.3028 5.48684 37.1355 5.01903C34.3398 2.74775 30.2723 0.837036 24.8169 0.837036C19.3616 0.837036 15.3805 2.74775 12.5847 5.01903C11.4174 5.48684 10.433 6.10915 9.63975 6.92044C7.9413 8.65743 7.37764 10.99 7.37764 13.6492C7.37764 14.3853 7.40477 15.1138 7.48186 15.8201C7.02133 16.7433 6.52774 17.994 6.19449 18.8495C3.68082 19.5773 1.73309 22.2899 0.989389 24.1574C0.907813 24.3622 0.873779 24.5813 0.873779 24.8018V30.1202C0.873779 30.3723 0.914376 30.6218 1.04014 30.8403C2.75994 33.8278 12.7462 40.8772 24.8601 40.8772ZM26.485 13.0046C26.4 12.3422 26.3595 11.749 26.3584 11.2191L26.3584 11.1772C26.361 9.63975 26.6971 8.63938 27.2339 8.02499C27.9156 7.2448 29.3246 6.64707 32.2941 6.96844C35.3026 7.29402 36.9842 8.04072 37.9376 9.01574C38.8606 9.95971 39.3455 11.372 39.3455 13.6492C39.3455 16.0687 38.9969 17.4982 38.2302 18.3678C37.5012 19.1946 36.0656 19.8674 32.9214 19.8674C30.5041 19.8674 29.1221 19.0812 28.2386 17.9939C27.2899 16.8264 26.7559 15.1161 26.485 13.0046ZM23.2353 13.0046C23.3203 12.3422 23.3607 11.749 23.3619 11.2191L23.3619 11.1772C23.3592 9.63974 23.0232 8.63937 22.4863 8.02498C21.8046 7.24479 20.3957 6.64707 17.4261 6.96843C14.4176 7.29402 12.736 8.04071 11.7826 9.01573C10.8596 9.9597 10.3747 11.372 10.3747 13.6492C10.3747 16.0687 10.7234 17.4982 11.49 18.3677C12.219 19.1946 13.6546 19.8674 16.7989 19.8674C19.2161 19.8674 20.5981 19.0812 21.4816 17.9939C22.4304 16.8264 22.9643 15.1161 23.2353 13.0046ZM25.2042 18.8676L25.0543 18.8676C24.8715 18.8678 24.6005 18.868 24.516 18.8676C24.3045 19.2218 24.0693 19.5618 23.8075 19.884C22.2697 21.7764 19.9741 22.8644 16.7988 22.8644C13.3524 22.8644 10.8266 22.1471 9.24196 20.3498C9.15187 20.2476 9.07125 20.1406 9.07125 20.1406L8.87613 20.3498V33.5049C11.7429 35.0628 17.8959 37.8586 24.8601 37.8586C31.8243 37.8586 37.9773 35.0628 40.8441 33.5049V20.3498L40.649 20.1406C40.649 20.1406 40.5829 20.231 40.4783 20.3498C38.8936 22.1471 36.3678 22.8644 32.9214 22.8644C29.7461 22.8644 27.4506 21.7764 25.9127 19.884C25.6509 19.5618 25.4157 19.2218 25.2042 18.8676Z";function $f({size:e=16,style:t}){return Co("svg",{width:e,height:e,viewBox:"0 0 1200 1200",fill:"currentColor",stroke:"none",style:{flexShrink:0,...t},children:Co("path",{d:Nf})})}function Wf({size:e=16,style:t}){return Co("svg",{width:e,height:e,viewBox:"0 0 158.7128 157.296",fill:"currentColor",stroke:"none",style:{flexShrink:0,...t},children:Co("path",{d:Ff})})}function jf({size:e=16,style:t}){return Co("svg",{width:e,height:e,viewBox:"0 0 49.7202 40.0402",fill:"currentColor",stroke:"none",style:{flexShrink:0,...t},children:Co("path",{d:zf,fillRule:"evenodd",clipRule:"evenodd"})})}function Jr({provider:e,size:t=16,style:n}){return e==="codex"?Co(Wf,{size:t,style:n}):e==="copilot"?Co(jf,{size:t,style:n}):Co($f,{size:t,style:n})}var Hi=[{id:"claude-opus-4-6",label:"Opus 4.6",source:"static"},{id:"claude-sonnet-4-6",label:"Sonn 4.6",source:"static"}],_i=[{id:"gpt-5.4",label:"GPT 5.4",source:"static"},{id:"gpt-5.3-codex",label:"Codex 5.3",source:"static"},{id:"gpt-5.3-codex-spark",label:"Spark 5.3",source:"static"}],Ks=[{id:"",label:"Default",source:"static"}];var Gf=[...Hi,..._i,...Ks];function Xs(e,t){if(t==="copilot"&&!e)return"Copilot";if(!e)return t==="codex"?"Codex":"Claude Code";let n=Gf.find(o=>o.id===e);return n?n.label:e.replace(/-\d{8,}$/,"")}import{jsx as yc}from"react/jsx-runtime";var Wn={iconDefault:"#1f2937",iconActive:"#1f2937",bgActive:"#dedede",bgHover:"#e2e2e2",separator:"#e5e7eb"};function Eo({children:e,active:t,siblingActive:n,disabled:o,onClick:r,title:i}){let s=()=>o?.4:n&&!t?.5:1,a={position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:0,border:"none",cursor:o?"default":"pointer",transition:"background-color 150ms ease, color 150ms ease, transform 100ms ease, opacity 150ms ease",backgroundColor:t?Wn.bgActive:"transparent",color:t?Wn.iconActive:Wn.iconDefault,opacity:s()};return yc("button",{type:"button",onClick:o?void 0:r,title:i,disabled:o,style:a,onMouseEnter:l=>{o||(l.currentTarget.style.opacity="1",t||(l.currentTarget.style.backgroundColor=Wn.bgHover))},onMouseLeave:l=>{o||(l.currentTarget.style.opacity=String(s()),t||(l.currentTarget.style.backgroundColor="transparent"))},onMouseDown:l=>{o||(l.currentTarget.style.transform="scale(0.95)")},onMouseUp:l=>{o||(l.currentTarget.style.transform="scale(1)")},children:e})}function hc(){return yc("div",{style:{width:1,height:20,backgroundColor:"rgba(0, 0, 0, 0.05)",margin:"0 8px"}})}import{Fragment as Yr,jsx as pe,jsxs as Tt}from"react/jsx-runtime";function og(e,t){if(e<=0)return[];if(e<=4)return Array.from({length:e},(r,i)=>({key:`model-${i}`,index:i,active:i===t}));let n=e-1,o=r=>({key:`model-${r}`,index:r,active:r===t});return t===0?[o(0),o(1),o(2),{key:"overflow-after",overflow:!0}]:t===1?[{key:"overflow-before",overflow:!0},o(1),o(2),{key:"overflow-after",overflow:!0}]:t===n-1?[{key:"overflow-before",overflow:!0},o(n-2),o(n-1),o(n)]:t===n?[{key:"overflow-before",overflow:!0},o(n-2),o(n-1),o(n)]:t%2===0?[{key:"overflow-before",overflow:!0},o(t-1),o(t),{key:"overflow-after",overflow:!0}]:[{key:"overflow-before",overflow:!0},o(t),o(t+1),{key:"overflow-after",overflow:!0}]}var or=[{type:"rectangle",icon:eg,label:"Rectangle",shortcut:"R"},{type:"circle",icon:Yf,label:"Oval",shortcut:"O"},{type:"line",icon:Qf,label:"Line",shortcut:"L"},{type:"freehand",icon:qf,label:"Pen",shortcut:"P"}],rg=new Set(or.map(e=>e.type));function ig(e,t,n,o,r,i,s,a){let l=(e-r)*(o-i)-(n-r)*(t-i),p=(e-s)*(i-a)-(r-s)*(t-a),c=(e-n)*(a-o)-(s-n)*(t-o),u=l<0||p<0||c<0,d=l>0||p>0||c>0;return!(u&&d)}function sg(e="bottom-right"){return Na(e,window.innerWidth,window.innerHeight)}var ag=[{type:"text",icon:ng,label:"Text",shortcut:"T"}],bc={inspector:{name:"Comment",desc:"Pin feedback to specific elements on the page.",usage:["Click any element to attach a comment","Type your note, then hand off to your AI","Your AI may ask clarifying questions","Replies get threaded"],keys:[{key:"C",desc:"Select tool"},{key:"Click",desc:"Pin comment to element"},{key:"Esc",desc:"Deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},hand:{name:"Handle",desc:"Quickly finetune layout and typescale.",usage:["Edges \u2192 padding","Between items \u2192 spacing","Corners \u2192 rounding","Right of text \u2192 font size","Below text \u2192 line height","Click a spacing handle to cycle distribution","Right-click \u2192 inspect element styles"],keys:[{key:"H",desc:"Select tool"},{key:"Shift",desc:"Snap to scale"},{key:"\u2325 + swipe",desc:"Cycle justify / flip direction"},{key:"\u21E7 + swipe",desc:"Cycle align-items"},{key:"Right-click",desc:"Inspect styles"},{key:"Esc",desc:"Deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},rectangle:{name:"Rectangle",desc:"Draw rectangular highlights to mark areas of interest.",usage:["Click and drag to draw","Cycle between shapes with the dot selector"],keys:[{key:"R",desc:"Rectangle"},{key:"O",desc:"Oval"},{key:"L",desc:"Line"},{key:"P",desc:"Pen"},{key:"Esc",desc:"Cancel or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},circle:{name:"Oval",desc:"Draw oval highlights to mark areas of interest.",usage:["Click and drag to draw","Cycle between shapes with the dot selector"],keys:[{key:"O",desc:"Oval"},{key:"R",desc:"Rectangle"},{key:"L",desc:"Line"},{key:"P",desc:"Pen"},{key:"Esc",desc:"Cancel or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},line:{name:"Line",desc:"Draw line annotations to point at or connect elements.",usage:["Click and drag to draw","Cycle between shapes with the dot selector"],keys:[{key:"L",desc:"Line"},{key:"R",desc:"Rectangle"},{key:"O",desc:"Oval"},{key:"P",desc:"Pen"},{key:"Esc",desc:"Cancel or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},freehand:{name:"Pen",desc:"Draw freehand paths to annotate freely.",usage:["Click and drag to draw","Cycle between shapes with the dot selector"],keys:[{key:"P",desc:"Pen"},{key:"R",desc:"Rectangle"},{key:"O",desc:"Oval"},{key:"L",desc:"Line"},{key:"Esc",desc:"Cancel or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},text:{name:"Text",desc:"Place text labels anywhere on the page.",usage:["Click to place, then start typing","Click away or press Enter to finish","Scroll while hovering a label to resize it"],keys:[{key:"T",desc:"Select tool"},{key:"Esc",desc:"Cancel text or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},model:{name:"Model",desc:"Promote components into the local design model.",usage:["Hover to highlight component boundaries","Scroll to walk up/down the component tree","Click to add to model.json","Green = already in model"],keys:[{key:"M",desc:"Select tool"},{key:"Scroll",desc:"Walk tree depth"},{key:"Click",desc:"Promote component"},{key:"Esc",desc:"Deselect"}]},eval:{name:"Evals",desc:"Synthesize inferred evals from design history.",usage:["Infer evals from annotations","Reject, refine, or approve proposals"],keys:[{key:"E",desc:"Select tool"},{key:"Esc",desc:"Deselect"}]},counter:{name:"Annotations",desc:"Click to cycle, scroll to change color, long press to reset.",usage:[],keys:[{key:"Click",desc:"Cycle annotations"},{key:"Scroll",desc:"Change color"},{key:"Hold",desc:"Reset to red"}]},clear:{name:"Clear",desc:"Remove all annotations and style changes.",usage:[],keys:[{key:"\u2318 \u232B",desc:"Clear all"},{key:"\u232B",desc:"Delete selected annotation"},{key:"\u2318 Z",desc:"Undo"},{key:"\u2318 \u21E7 Z",desc:"Redo"}]},collapse:{name:"Popmelt",desc:`Comment and zhuzh, then hand off.
12
+ `}),Array.from({length:b},(B,f)=>{let g=i[f]??"",j=v&&f>=i.length,fe=o===f||j,le=(j?void 0:I.get(g.trim()))?.status,Ce=le?df[le]:"#374151",Ee=le?uf[le]:"\u25A1",K=le?{color:Ce}:{},O=le?{color:Ce}:{};return fe?co("div",{style:hc,children:[At("span",{style:K,children:Ee}),At("textarea",{className:"popmelt-eval-assertion-input",ref:Z=>{p.current[f]=Z},rows:1,value:g,placeholder:j?"cmd+enter to add new assertion":void 0,onFocus:()=>r(f),onChange:Z=>{k(f,Z.target.value),bc(Z.currentTarget)},onBlur:Z=>V(f,Z),onKeyDown:Z=>Q(f,Z),style:{...lf,...O}})]},`assertion-${f}`):co("div",{style:hc,children:[At("span",{style:K,children:Ee}),At("button",{type:"button",onMouseDown:Z=>M(f,Z),onClick:()=>C(f),style:{...ga,...O},children:g})]},`assertion-${f}`)})]})}import{Component as Wf,createElement as jf,useCallback as ts,useEffect as Yo,useRef as hr,useState as Jn}from"react";import{Link2 as Gf}from"lucide-react";var Tf={colors:[],fonts:[],typeScale:[],spacing:[],radii:[],shadows:[],other:[],references:{}},kf=/^#[0-9a-fA-F]{3,8}$/,Mf=/^(?:rgba?|hsla?|oklch|oklab|lch|lab)\(/,If=new Set(["transparent","currentcolor","inherit","white","black","red","green","blue","yellow","orange","purple","pink","gray","grey","cyan","magenta","brown","navy","teal","maroon","olive","silver","aqua","fuchsia","lime"]);function wc(e){let t=e.trim().toLowerCase();return kf.test(t)||Mf.test(t)||If.has(t)}var Rf=/^-?\d+(\.\d+)?(px|rem|em|%)$/;function ma(e){return Rf.test(e.trim())}var Sc=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]);function Lf(e){let t=e.trim().toLowerCase();return!!(Sc.has(t)||t.includes(",")&&t.split(",").some(n=>Sc.has(n.trim().replace(/['"]/g,""))))}function Af(e){let t=e.trim().toLowerCase(),n=t.match(/\d+(\.\d+)?px/g);return!!(n&&n.length>=2&&(wc(t.replace(/[^#()\w,.\s/%]/g,"").split(/\s+/).pop()||"")||t.includes("rgb")||t.includes("hsl")||t.includes("#")))}var Pf=/(?:^--(color|bg|fg|accent|border-color|text-color|surface|background|foreground))|(?:-(color|bg|fg)$)/i,Bf=/^--(font-family|font|ff|family)/i,Df=/^--(font-size|text-size|fs|text-(?:xs|sm|base|md|lg|xl|2xl|3xl|4xl|5xl))/i,Of=/^--(space|gap|padding|margin|inset)/i,_f=/^--(radius|rounded|br|border-radius)/i,Hf=/^--(shadow|elevation|drop-shadow)/i;function Cc(e,t){let n=e.toLowerCase();return Hf.test(n)?"shadows":_f.test(n)?"radii":Bf.test(n)?"fonts":Df.test(n)&&ma(t)?"typeScale":Pf.test(n)||wc(t)?"colors":Lf(t)?"fonts":Af(t)?"shadows":Of.test(n)&&ma(t)||ma(t)?"spacing":"other"}function Ec(e,t,n,o){if(e)for(let r of e){if(r instanceof CSSGroupingRule){Ec(r.cssRules,t,n,o);continue}if(r instanceof CSSStyleRule){let i=r.selectorText.toLowerCase();(i===":root"||i==="html"||i==="*"||i.includes(":root"))&&Nf(r.style,t,n,o)}}}var Tc=/var\((--[^,)]+)/;function Nf(e,t,n,o){for(let r=0;r<e.length;r++){let i=e[r];if(!i?.startsWith("--")||n.has(i))continue;n.add(i);let s=t.getPropertyValue(i).trim();if(!s)continue;let a=Cc(i,s);o[a].push([i,s]);let d=e.getPropertyValue(i).trim().match(Tc);d&&(o.references[i]=d[1])}}function qi(e){let t=e.trim().match(/^(-?\d+(?:\.\d+)?)/);return t?parseFloat(t[1]):null}function Qi(e){let t=e.trim().toLowerCase(),n=t.match(/oklch\(\s*([\d.]+%?)/);if(n){let i=n[1];return i.endsWith("%")?parseFloat(i)/100:parseFloat(i)}let o=t.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/);if(o){let[i,s,a]=[parseInt(o[1],10),parseInt(o[2],10),parseInt(o[3],10)];return(.2126*i+.7152*s+.0722*a)/255}let r=t.match(/hsla?\(\s*[\d.]+[,\s]+[\d.]+%?[,\s]+([\d.]+)%?/);if(r)return parseFloat(r[1])/100;if(t.startsWith("#")){let i=t.slice(1);(i.length===3||i.length===4)&&(i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]);let s=parseInt(i.slice(0,2),16),a=parseInt(i.slice(2,4),16),l=parseInt(i.slice(4,6),16);if(!isNaN(s))return(.2126*s+.7152*a+.0722*l)/255}return null}function kc(e){return e==="colors"?(t,n)=>{let o=Qi(t[1]),r=Qi(n[1]);return o!==null&&r!==null?o-r:t[0].localeCompare(n[0])}:e==="typeScale"||e==="spacing"||e==="radii"?(t,n)=>{let o=qi(t[1]),r=qi(n[1]);return o!==null&&r!==null?o-r:t[0].localeCompare(n[0])}:e==="other"?(t,n)=>{let o=qi(t[1]),r=qi(n[1]);return o!==null&&r!==null?o-r:t[0].localeCompare(n[0])}:(t,n)=>t[0].localeCompare(n[0])}function Ff(e){let t=e.replace(/^--/,"");t=t.replace(/^(?:color|clr)-/,"");let n=t.split("-");return n.length>1&&/^\d+$/.test(n[n.length-1])&&n.pop(),n.join("-")}function Mc(e){let t=new Map;for(let r of e){let i=Ff(r[0]),s=t.get(i);s||(s=[],t.set(i,s)),s.push(r)}let n=kc("colors");for(let r of t.values())r.sort(n);let o=[...t.entries()];return o.sort((r,i)=>{let s=Qi(r[1][0][1])??0,a=Qi(i[1][0][1])??0;return s-a}),o}var zf=["colors","fonts","typeScale","spacing","radii","shadows","other"],Zi=null,$f=5e3;function Ic(){if(typeof document>"u")return Tf;if(Zi&&Date.now()-Zi.timestamp<$f)return Zi.tokens;let e={colors:[],fonts:[],typeScale:[],spacing:[],radii:[],shadows:[],other:[],references:{}},t=new Set,n=getComputedStyle(document.documentElement);try{for(let r of document.styleSheets)try{Ec(r.cssRules||r.rules,n,t,e)}catch{}}catch{}let o=document.documentElement.style;for(let r=0;r<o.length;r++){let i=o[r];if(!i?.startsWith("--")||t.has(i))continue;t.add(i);let s=n.getPropertyValue(i).trim();if(!s)continue;let a=Cc(i,s);e[a].push([i,s]);let d=o.getPropertyValue(i).trim().match(Tc);d&&(e.references[i]=d[1])}for(let r of zf)e[r].sort(kc(r));return Zi={tokens:e,timestamp:Date.now()},e}import{Fragment as yr,jsx as Fe,jsxs as rn}from"react/jsx-runtime";var Rc="popmelt-library-tab",Jf=/^#[0-9a-fA-F]{3,8}$/,Yf=/^(?:rgba?|hsla?|oklch)\([^)]+\)$/,Vf=new Set(["black","white","red","blue","green","yellow","orange","purple","pink","gray","grey","cyan","magenta","brown","navy","teal","maroon","olive","silver","aqua","fuchsia","lime"]),Uf=/^-?\d+(\.\d+)?(px|rem|em|%)$/;function Ac(e){let t=e.trim();return Jf.test(t)||Yf.test(t)||Vf.has(t.toLowerCase())}function Kf(e){return Uf.test(e.trim())}function Xf(e){let t=e.trim().match(/^(-?\d+(?:\.\d+)?)px$/);return t?parseFloat(t[1]):null}function Pc(e,t=""){if(e==null)return[];if(typeof e!="object")return[[t,String(e)]];if(Array.isArray(e))return[[t,e.map(String).join(", ")]];let n=[];for(let[o,r]of Object.entries(e)){let i=t?`${t}.${o}`:o;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){let s=r;typeof s.value=="string"?n.push([i,s.value]):n.push(...Pc(r,i))}else n.push([i,Array.isArray(r)?r.map(String).join(", "):String(r??"")])}return n}function qf(e){return e.length===0?"generic":e.filter(([,o])=>Ac(o)).length>e.length/2?"colors":e.filter(([,o])=>Kf(o)).length>e.length/2?"spacing":"generic"}var Zf={width:300,backgroundColor:"#eaeaea",...Nr,boxSizing:"content-box",zIndex:10001,display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12,color:"#1f2937",padding:12,pointerEvents:"auto"},Bc={border:"none",background:"none",cursor:"pointer",fontFamily:"inherit",fontSize:11,fontWeight:600,padding:"2px 0",color:"#9ca3af"},Qf={...Bc,color:"#1f2937",borderBottom:"1.5px solid #1f2937"};function eg({varName:e,value:t,reference:n}){return Fe("div",{title:n?`${e} \u2192 ${n}
13
+ ${t}`:`${e}: ${t}`,style:{width:28,height:28,backgroundColor:t,outline:"1px solid rgba(0,0,0,0.08)",outlineOffset:-1,position:"relative"},children:n&&Fe(Gf,{size:10,strokeWidth:2.5,style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",filter:"drop-shadow(0 0 1px rgba(0,0,0,0.5))"}})})}function Dc({entries:e,references:t}){let n=[],o=[];for(let i of e)Ac(i[1])?n.push(i):o.push(i);let r=Mc(n);return rn(yr,{children:[r.map(([i,s])=>rn("div",{style:{marginBottom:4},children:[rn("div",{style:{fontSize:10,color:"#9ca3af",marginBottom:2},children:[i,s.length>1?` (${s.length})`:""]}),Fe("div",{style:{display:"flex",flexWrap:"wrap",gap:2},children:s.map(([a,l])=>Fe(eg,{varName:a,value:l,reference:t[a]},a))})]},i)),o.length>0&&Fe(ns,{entries:o})]})}var es=[0,1,2,4,8,12,16,20,24,28,32];function tg(e){if(e<=32){let t=es[0],n=Math.abs(e-t);for(let o=1;o<es.length;o++){let r=Math.abs(e-es[o]);r<n&&(t=es[o],n=r)}return t}return Math.round(e/8)*8}function ng({label:e,value:t,px:n,tokenPath:o,rawToken:r,onHover:i,onModify:s,onDelete:a}){let[l,d]=Jn(!1),[c,p]=Jn(null),u=hr(!1),m=hr(0),v=hr(0),b=hr([]),I=c!==null?c:n,P=c!==null?`${c}px`:t,N=c!==null,C=ts(E=>{E.preventDefault(),u.current=!0,m.current=E.clientX,v.current=n;let $=Ai(r);b.current=Ss($);let Q=M=>{let B=M.clientX-m.current,f=Math.max(0,Math.round(v.current+B));M.shiftKey&&(f=tg(f));for(let g of b.current)g.element.style.setProperty(g.property,f+"px","important");p(f),i?.({name:e,px:f,token:$})},V=()=>{window.removeEventListener("mousemove",Q),window.removeEventListener("mouseup",V),document.body.style.cursor="",u.current=!1,p(M=>{if(M!==null&&M!==n&&s){let B=Ai(r),f=B.bindings&&B.bindings.length>0,g;if(f){let le=Cs(B.bindings,v.current,M);g=JSON.stringify({...B,value:`${M}px`,bindings:le})}else{let le=gl(b.current,v.current),Ce=ml(b.current);if(le.length>0){let Ee=Cs(le,v.current,M);g=JSON.stringify({value:`${M}px`,property:Ce,bindings:Ee})}else g=`${M}px`}let j=typeof r=="string"?r:JSON.stringify(r),fe=b.current.map(le=>({selector:jn(le.element),property:le.property})),Re=yl(b.current,v.current,M);s({tokenPath:o,originalValue:j,currentValue:g,targets:fe,originalPx:v.current,currentPx:M},{id:Math.random().toString(36).substring(2,9),tokenPath:o,tokenName:e,originalPx:v.current,newPx:M,affectedElements:Re})}return M})};document.body.style.cursor="ew-resize",window.addEventListener("mousemove",Q),window.addEventListener("mouseup",V)},[n,e,o,r,i,s]),k=Ai(r);return rn("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:11,padding:"1px 0",cursor:"ew-resize",userSelect:"none"},onMouseEnter:()=>{u.current||(d(!0),i?.({name:e,px:I,token:k}))},onMouseLeave:()=>{u.current||(d(!1),i?.(null))},onMouseDown:C,children:[Fe("span",{style:{color:l||N?"#FF0000":"#9ca3af"},children:e}),rn("span",{style:{display:"flex",alignItems:"center",gap:4},children:[Fe("span",{style:{color:l||N?"#FF0000":"#6b7280",fontWeight:600},children:P}),a&&l&&!N&&Fe("button",{type:"button",title:"Remove token",onMouseDown:E=>{E.stopPropagation();let $=typeof r=="string"?r:JSON.stringify(r);a(o,$)},style:{border:"none",background:"none",cursor:"pointer",padding:0,fontSize:10,lineHeight:1,color:"#9ca3af"},onMouseEnter:E=>{E.currentTarget.style.color="#FF0000"},onMouseLeave:E=>{E.currentTarget.style.color="#9ca3af"},children:"\u2715"})]})]})}function og({entries:e,categoryKey:t,rawTokens:n,onHover:o,onModify:r,onDelete:i}){let s=[],a=[];for(let l of e){let d=Xf(l[1]);d!==null?s.push([l[0],l[1],d]):a.push(l)}return rn(yr,{children:[s.length>0&&Fe("div",{style:{display:"flex",flexDirection:"column",gap:2},children:s.map(([l,d,c])=>{let p=l.split(".").pop(),u=n?rg(n,l):d,m=u&&typeof u=="object"&&"value"in u?u:d;return Fe(ng,{label:p,value:d,px:c,tokenPath:`tokens.${t}.${l}`,rawToken:m,onHover:o,onModify:r,onDelete:i},l)})}),a.length>0&&Fe(ns,{entries:a})]})}function rg(e,t){let n=t.split("."),o=e;for(let r of n){if(o==null||typeof o!="object")return;o=o[r]}return o}function ns({entries:e}){return Fe("div",{style:{display:"flex",flexDirection:"column",gap:3},children:e.map(([t,n])=>rn("div",{style:{fontSize:11},children:[Fe("div",{style:{color:"#9ca3af",fontSize:10,marginBottom:1},children:t}),Fe("div",{style:{color:"#1f2937",lineHeight:1.4,paddingLeft:8},children:n})]},t))})}function ig({entries:e,categoryKey:t,rawTokens:n,onSpacingHover:o,onModifyToken:r,onDeleteToken:i}){let s=qf(e);return s==="colors"?Fe(Dc,{entries:e}):s==="spacing"?Fe(og,{entries:e,categoryKey:t,rawTokens:n,onHover:o,onModify:r,onDelete:i}):Fe(ns,{entries:e})}function sg(e){let t=e.toLowerCase(),n=null,o=document.createTreeWalker(document.body,NodeFilter.SHOW_ELEMENT,{acceptNode(i){return i.closest("#devtools-toolbar, #devtools-canvas, #devtools-scrim, [data-popmelt-panel]")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=o.currentNode;for(;r=o.nextNode();){let i=r,s=Object.keys(i).find(l=>l.startsWith("__reactFiber$")||l.startsWith("__reactInternalInstance$"));if(!s)continue;let a=i[s];for(;a;){let l=a.type,d=typeof l=="function"||typeof l=="object"?l?.displayName||l?.name:null;if(typeof d=="string"){let c=d.toLowerCase();if(c===t){let p={...a.memoizedProps};return delete p.ref,{type:l,props:p}}if(!n){if(c.length>=4&&t.includes(c)){let p={...a.memoizedProps};delete p.ref,n={type:l,props:p}}else if(t.length>=4&&c.includes(t)){let p={...a.memoizedProps};delete p.ref,n={type:l,props:p}}}}a=a.return}}return n}var ha=class extends Wf{constructor(){super(...arguments);this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(){this.props.onError()}render(){return this.state.hasError?null:this.props.children}},Oc="popmelt-principles-collapsed";function ag(){try{let e=localStorage.getItem(Oc);if(e)return new Set(JSON.parse(e))}catch{}return new Set}function lg(e){try{localStorage.setItem(Oc,JSON.stringify([...e]))}catch{}}function cg({id:e,label:t,count:n,children:o,collapsed:r,onToggle:i}){return rn("div",{style:{marginBottom:14},children:[rn("div",{onClick:()=>i(e),style:{fontWeight:700,fontSize:11,color:"#6b7280",letterSpacing:"0.05em",marginBottom:r?0:6,cursor:"pointer",display:"flex",alignItems:"center",gap:4,userSelect:"none"},children:[Fe("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:10,fontSize:9,color:"#9ca3af",transform:r?"rotate(-90deg)":"rotate(0deg)"},children:"\u25BC"}),t,Fe("span",{style:{fontWeight:400,color:"#9ca3af"},children:n})]}),!r&&o]})}var dg={colors:"Colors",fonts:"Fonts",typeScale:"Type Scale",spacing:"Spacing",radii:"Radii",shadows:"Shadows",other:"Other"},Lc=["colors","fonts","typeScale","spacing","radii","shadows","other"];function ug(){let[e,t]=Jn(null),[n,o]=Jn(ag);Yo(()=>{t(Ic())},[]);let r=ts(s=>{o(a=>{let l=new Set(a);return l.has(s)?l.delete(s):l.add(s),lg(l),l})},[]);return e?Lc.some(s=>e[s].length>0)?Fe(yr,{children:Lc.map(s=>{let a=e[s];return a.length===0?null:Fe(cg,{id:s,label:dg[s],count:a.length,collapsed:n.has(s),onToggle:r,children:s==="colors"?Fe(Dc,{entries:a,references:e.references}):Fe(ns,{entries:a})},s)})}):Fe("div",{style:{color:"#9ca3af",fontSize:11},children:"No :root tokens found."}):null}function pg({rules:e,onSynthesize:t,isSynthesizing:n}){if(!e||e.length===0)return Fe("div",{style:{color:"#9ca3af",fontSize:11},children:"No rules defined yet."});if(!e.some(i=>typeof i=="object"&&i!==null&&"scope"in i))return Fe(yr,{children:e.map((i,s)=>rn("div",{style:{display:"flex",gap:6,marginBottom:4,lineHeight:1.4,fontSize:11},children:[rn("span",{style:{color:"#9ca3af",flexShrink:0},children:[s+1,"."]}),Fe("span",{children:typeof i=="string"?i:i.text})]},s))});let r=new Map;for(let i of e)if(typeof i=="string")r.has("general")||r.set("general",[]),r.get("general").push({id:"",text:i});else{let s=i.scope||"general";r.has(s)||r.set(s,[]),r.get(s).push({id:i.id,text:i.text})}return rn(yr,{children:[t&&Fe("button",{type:"button",disabled:n,onClick:t,style:{width:"100%",border:"1px solid rgba(0,0,0,0.12)",background:n?"rgba(0,0,0,0.04)":"rgba(0,0,0,0.02)",cursor:n?"default":"pointer",fontFamily:"inherit",fontSize:11,fontWeight:600,padding:"5px 8px",marginBottom:10,color:n?"#9ca3af":"#6b7280"},children:n?"Synthesizing\u2026":"Synthesize"}),Array.from(r.entries()).map(([i,s])=>rn("div",{style:{marginBottom:10},children:[Fe("div",{style:{fontWeight:700,fontSize:10,color:"#6b7280",letterSpacing:"0.05em",textTransform:"uppercase",marginBottom:4},children:i}),s.map((a,l)=>rn("div",{style:{display:"flex",gap:6,marginBottom:3,lineHeight:1.4,fontSize:11},children:[Fe("span",{style:{color:"#9ca3af",flexShrink:0},children:"\u2022"}),Fe("span",{children:a.text})]},a.id||l))]},i))]})}function fg({name:e,value:t,selected:n,highlighted:o,onRemove:r,onHover:i}){let[s,a]=Jn(!1),[l,d]=Jn(!1),c=hr(null),p=hr(0),[u,m]=Jn(0),[v,b]=Jn(0),I=Pc(t),P=I.find(([M])=>M==="description")?.[1];Yo(()=>{if(!l&&!o){m(0),b(0),p.current=0;return}let M=Mr(e);m(M.length)},[l,o,e]),Yo(()=>{n&&c.current&&c.current.scrollIntoView({behavior:"smooth",block:"nearest"})},[n]);let N=n||o||l,C=n?"139,92,246":"34,197,94",k=n?"#8b5cf6":"#22c55e",E=N?`rgba(${C},0.06)`:void 0,$=N?`inset 0 0 0 1.5px rgba(${C},0.35)`:void 0,Q=o||l,V=ts(()=>{let M=Mr(e);if(M.length===0)return;let B=p.current%M.length;M[B].rootElement.scrollIntoView({behavior:"smooth",block:"center"}),b(B),p.current=B+1,i?.({name:e,instanceIndex:B})},[e,i]);return rn("div",{ref:c,onClick:V,onMouseEnter:()=>{d(!0),i?.({name:e,instanceIndex:0})},onMouseLeave:()=>{d(!1),i?.(null)},style:{marginBottom:8,background:E,padding:6,boxShadow:$,cursor:"pointer"},children:[rn("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[rn("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6},children:[Fe("div",{style:{fontWeight:700,fontSize:11,letterSpacing:"0.05em",padding:"2px 6px",backgroundColor:Q?k:"transparent",color:Q?"#fff":"#6b7280"},children:e}),Q&&u>1&&rn("span",{style:{fontSize:10,fontWeight:600,color:"#9ca3af"},children:[v+1,"/",u]})]}),r&&l&&Fe("button",{type:"button",title:"Remove from model",onClick:M=>{M.stopPropagation(),r(e)},style:{border:"none",background:"none",cursor:"pointer",padding:"0 2px",fontSize:14,lineHeight:1,color:"#9ca3af",marginTop:-4},onMouseEnter:M=>{M.currentTarget.style.color="#FF0000"},onMouseLeave:M=>{M.currentTarget.style.color="#9ca3af"},children:"\u2715"})]}),P&&Fe("div",{style:{fontSize:11,color:Q?"#1f2937":"#9ca3af",marginBottom:6,lineHeight:1.4},children:P}),s?Fe(ig,{entries:I.filter(([M])=>M!=="description"),categoryKey:""}):Fe(gg,{name:e,onNotFound:()=>a(!0),entries:I})]})}function gg({name:e,onNotFound:t}){let[n,o]=Jn(null),[r,i]=Jn(!1);return Yo(()=>{let s=sg(e);s||t(),o(s),i(!0)},[e,t]),!r||!n?null:Fe(ha,{onError:t,children:Fe("div",{"data-popmelt-panel":!0,onClick:s=>{s.preventDefault(),s.stopPropagation()},style:{width:"100%",overflowY:"auto",overflowX:"hidden",maxHeight:150,padding:"1rem",outline:"1px solid rgba(0,0,0,0.06)",backgroundColor:"rgb(250,250,250)",boxSizing:"border-box",marginBottom:4,display:"flex",flexDirection:"column",justifyContent:"stretch",alignItems:"center",contain:"layout paint",position:"relative",isolation:"isolate"},children:Fe("div",{style:{zoom:.5,pointerEvents:"none"},children:jf(n.type,n.props)})})})}function mg({components:e,selectedComponent:t,hoveredComponent:n,onRemove:o,onHover:r}){if(!e||Object.keys(e).length===0)return Fe("div",{style:{color:"#9ca3af",fontSize:11},children:"No component patterns defined yet."});let i=new Set(Object.keys(e)),s=bs(i),a=Object.entries(e).sort(([l],[d])=>(s.get(l)??1/0)-(s.get(d)??1/0));return Fe(yr,{children:a.map(([l,d])=>Fe(fg,{name:l,value:d,selected:t===l,highlighted:n===l,onRemove:o,onHover:r},l))})}function _c({bridgeUrl:e,modelRefreshKey:t,onMouseEnter:n,onMouseLeave:o,selectedComponent:r,hoveredComponent:i,onComponentHover:s,onSpacingTokenHover:a,onModifySpacingToken:l,onDeleteSpacingToken:d,onComponentAdded:c,onComponentRemoved:p,onSynthesizeRules:u,isSynthesizing:m,snapPosition:v="bottom-right"}){let[b,I]=Jn(void 0),[P,N]=Jn(!0),[C,k]=Jn(()=>{try{let f=localStorage.getItem(Rc);if(f==="patterns"||f==="principles"||f==="rules")return f}catch{}return"patterns"});Yo(()=>{Cr(e).then(f=>{I(f),N(!1)})},[e,t]),Yo(()=>{try{localStorage.setItem(Rc,C)}catch{}},[C]),Yo(()=>{r&&(k("patterns"),Cr(e).then(f=>{f&&I(f)}))},[r,e]);let E=ts(f=>{I(g=>{if(!g?.components)return g;let{[f]:j,...fe}=g.components;return{...g,components:fe}}),p?.(f)},[p]),$=b?.components,Q=b?.rules,V=$&&Object.keys($).length>0,M=Q&&Q.length>0,B=hr(null);return Yo(()=>{let f=B.current;if(!f)return;let g=n,j=o;return g&&f.addEventListener("mouseenter",g),j&&f.addEventListener("mouseleave",j),()=>{g&&f.removeEventListener("mouseenter",g),j&&f.removeEventListener("mouseleave",j)}},[n,o]),rn("div",{ref:B,style:{...Zf,...Mi(v)},children:[rn("div",{style:{display:"flex",alignItems:"center",gap:6,fontWeight:700,fontSize:13,marginBottom:6},children:[Fe("span",{children:"Model"}),Fe("code",{style:{fontSize:10,fontWeight:500,backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",color:"#6b7280"},children:"M"})]}),Fe("div",{style:{display:"flex",gap:12,marginBottom:10,borderBottom:"1px solid rgba(0,0,0,0.08)",paddingBottom:6},children:["patterns","principles","rules"].map(f=>Fe("button",{type:"button",style:C===f?Qf:Bc,onClick:()=>k(f),children:f.charAt(0).toUpperCase()+f.slice(1)},f))}),Fe("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:C==="principles"?Fe(ug,{}):P?Fe("div",{style:{color:"#9ca3af",fontSize:11},children:"Loading..."}):!b||!V&&!M?Fe("div",{style:{color:"#9ca3af",lineHeight:1.5},children:"No design model yet. Pattern-scoped annotations will build one automatically."}):rn(yr,{children:[C==="patterns"&&Fe(mg,{components:$,selectedComponent:r,hoveredComponent:i,onRemove:E,onHover:s}),C==="rules"&&Fe(pg,{rules:Q,onSynthesize:u,isSynthesizing:m})]})})]})}import{jsx as Oo}from"react/jsx-runtime";var hg="M 233.959793 800.214905 L 468.644287 668.536987 L 472.590637 657.100647 L 468.644287 650.738403 L 457.208069 650.738403 L 417.986633 648.322144 L 283.892639 644.69812 L 167.597321 639.865845 L 54.926208 633.825623 L 26.577238 627.785339 L 3.3e-05 592.751709 L 2.73832 575.27533 L 26.577238 559.248352 L 60.724873 562.228149 L 136.187973 567.382629 L 249.422867 575.194763 L 331.570496 580.026978 L 453.261841 592.671082 L 472.590637 592.671082 L 475.328857 584.859009 L 468.724915 580.026978 L 463.570557 575.194763 L 346.389313 495.785217 L 219.543671 411.865906 L 153.100723 363.543762 L 117.181267 339.060425 L 99.060455 316.107361 L 91.248367 266.01355 L 123.865784 230.093994 L 167.677887 233.073853 L 178.872513 236.053772 L 223.248367 270.201477 L 318.040283 343.570496 L 441.825592 434.738342 L 459.946411 449.798706 L 467.194672 444.64447 L 468.080597 441.020203 L 459.946411 427.409485 L 392.617493 305.718323 L 320.778564 181.932983 L 288.80542 130.630859 L 280.348999 99.865845 C 277.369171 87.221436 275.194641 76.590698 275.194641 63.624268 L 312.322174 13.20813 L 332.8591 6.604126 L 382.389313 13.20813 L 403.248352 31.328979 L 434.013519 101.71814 L 483.865753 212.537048 L 561.181274 363.221497 L 583.812134 407.919434 L 595.892639 449.315491 L 600.40271 461.959839 L 608.214783 461.959839 L 608.214783 454.711609 L 614.577271 369.825623 L 626.335632 265.61084 L 637.771851 131.516846 L 641.718201 93.745117 L 660.402832 48.483276 L 697.530334 24.000122 L 726.52356 37.852417 L 750.362549 72 L 747.060486 94.067139 L 732.886047 186.201416 L 705.100708 330.52356 L 686.979919 427.167847 L 697.530334 427.167847 L 709.61084 415.087341 L 758.496704 350.174561 L 840.644348 247.490051 L 876.885925 206.738342 L 919.167847 161.71814 L 946.308838 140.29541 L 997.61084 140.29541 L 1035.38269 196.429626 L 1018.469849 254.416199 L 965.637634 321.422852 L 921.825562 378.201538 L 859.006714 462.765259 L 819.785278 530.41626 L 823.409424 535.812073 L 832.75177 534.92627 L 974.657776 504.724915 L 1051.328979 490.872559 L 1142.818848 475.167786 L 1184.214844 494.496582 L 1188.724854 514.147644 L 1172.456421 554.335693 L 1074.604126 578.496765 L 959.838989 601.449829 L 788.939636 641.879272 L 786.845764 643.409485 L 789.261841 646.389343 L 866.255127 653.637634 L 899.194702 655.409424 L 979.812134 655.409424 L 1129.932861 666.604187 L 1169.154419 692.537109 L 1192.671265 724.268677 L 1188.724854 748.429688 L 1128.322144 779.194641 L 1046.818848 759.865845 L 856.590759 714.604126 L 791.355774 698.335754 L 782.335693 698.335754 L 782.335693 703.731567 L 836.69812 756.885986 L 936.322205 846.845581 L 1061.073975 962.81897 L 1067.436279 991.490112 L 1051.409424 1014.120911 L 1034.496704 1011.704712 L 924.885986 929.234924 L 882.604126 892.107544 L 786.845764 811.48999 L 780.483276 811.48999 L 780.483276 819.946289 L 802.550415 852.241699 L 919.087341 1027.409424 L 925.127625 1081.127686 L 916.671204 1098.604126 L 886.469849 1109.154419 L 853.288696 1103.114136 L 785.073914 1007.355835 L 714.684631 899.516785 L 657.906067 802.872498 L 650.979858 806.81897 L 617.476624 1167.704834 L 601.771851 1186.147705 L 565.530212 1200 L 535.328857 1177.046997 L 519.302124 1139.919556 L 535.328857 1066.550537 L 554.657776 970.792053 L 570.362488 894.68457 L 584.536926 800.134277 L 592.993347 768.724976 L 592.429626 766.630859 L 585.503479 767.516968 L 514.22821 865.369263 L 405.825531 1011.865906 L 320.053711 1103.677979 L 299.516815 1111.812256 L 263.919525 1093.369263 L 267.221497 1060.429688 L 287.114136 1031.114136 L 405.825531 880.107361 L 477.422913 786.52356 L 523.651062 732.483276 L 523.328918 724.671265 L 520.590698 724.671265 L 205.288605 929.395935 L 149.154434 936.644409 L 124.993355 914.01355 L 127.973183 876.885986 L 139.409409 864.80542 L 234.201385 799.570435 L 233.879227 799.8927 Z",yg="M60.8734,57.2556v-14.9432c0-1.2586.4722-2.2029,1.5728-2.8314l30.0443-17.3023c4.0899-2.3593,8.9662-3.4599,13.9988-3.4599,18.8759,0,30.8307,14.6289,30.8307,30.2006,0,1.1007,0,2.3593-.158,3.6178l-31.1446-18.2467c-1.8872-1.1006-3.7754-1.1006-5.6629,0l-39.4812,22.9651ZM131.0276,115.4561v-35.7074c0-2.2028-.9446-3.7756-2.8318-4.8763l-39.481-22.9651,12.8982-7.3934c1.1007-.6285,2.0453-.6285,3.1458,0l30.0441,17.3024c8.6523,5.0341,14.4708,15.7296,14.4708,26.1107,0,11.9539-7.0769,22.965-18.2461,27.527v.0021ZM51.593,83.9964l-12.8982-7.5497c-1.1007-.6285-1.5728-1.5728-1.5728-2.8314v-34.6048c0-16.8303,12.8982-29.5722,30.3585-29.5722,6.607,0,12.7403,2.2029,17.9324,6.1349l-30.987,17.9324c-1.8871,1.1007-2.8314,2.6735-2.8314,4.8764v45.6159l-.0014-.0015ZM79.3562,100.0403l-18.4829-10.3811v-22.0209l18.4829-10.3811,18.4812,10.3811v22.0209l-18.4812,10.3811ZM91.2319,147.8591c-6.607,0-12.7403-2.2031-17.9324-6.1344l30.9866-17.9333c1.8872-1.1005,2.8318-2.6728,2.8318-4.8759v-45.616l13.0564,7.5498c1.1005.6285,1.5723,1.5728,1.5723,2.8314v34.6051c0,16.8297-13.0564,29.5723-30.5147,29.5723v.001ZM53.9522,112.7822l-30.0443-17.3024c-8.652-5.0343-14.471-15.7296-14.471-26.1107,0-12.1119,7.2356-22.9652,18.403-27.5272v35.8634c0,2.2028.9443,3.7756,2.8314,4.8763l39.3248,22.8068-12.8982,7.3938c-1.1007.6287-2.045.6287-3.1456,0ZM52.2229,138.5791c-17.7745,0-30.8306-13.3713-30.8306-29.8871,0-1.2585.1578-2.5169.3143-3.7754l30.987,17.9323c1.8871,1.1005,3.7757,1.1005,5.6628,0l39.4811-22.807v14.9435c0,1.2585-.4721,2.2021-1.5728,2.8308l-30.0443,17.3025c-4.0898,2.359-8.9662,3.4605-13.9989,3.4605h.0014ZM91.2319,157.296c19.0327,0,34.9188-13.5272,38.5383-31.4594,17.6164-4.562,28.9425-21.0779,28.9425-37.908,0-11.0112-4.719-21.7066-13.2133-29.4143.7867-3.3035,1.2595-6.607,1.2595-9.909,0-22.4929-18.2471-39.3247-39.3251-39.3247-4.2461,0-8.3363.6285-12.4262,2.045-7.0792-6.9213-16.8318-11.3254-27.5271-11.3254-19.0331,0-34.9191,13.5268-38.5384,31.4591C11.3255,36.0212,0,52.5373,0,69.3675c0,11.0112,4.7184,21.7065,13.2125,29.4142-.7865,3.3035-1.2586,6.6067-1.2586,9.9092,0,22.4923,18.2466,39.3241,39.3248,39.3241,4.2462,0,8.3362-.6277,12.426-2.0441,7.0776,6.921,16.8302,11.3251,27.5271,11.3251Z",bg="M29.8768 25.3531C30.9809 25.3531 31.876 26.2481 31.876 27.3522V31.3505C31.876 32.4545 30.9809 33.3496 29.8768 33.3496C28.7727 33.3496 27.8777 32.4545 27.8777 31.3505V27.3522C27.8777 26.2481 28.7727 25.3531 29.8768 25.3531ZM19.8812 25.3531C20.9852 25.3531 21.8803 26.2481 21.8803 27.3522V31.3505C21.8803 32.4545 20.9852 33.3496 19.8812 33.3496C18.7771 33.3496 17.882 32.4545 17.882 31.3505V27.3522C17.882 26.2481 18.7771 25.3531 19.8812 25.3531ZM24.8601 40.8772C36.974 40.8772 46.9603 33.8278 48.6801 30.8403C48.8058 30.6218 48.8464 30.3723 48.8464 30.1202V24.8018C48.8464 24.5813 48.8124 24.3622 48.7308 24.1574C47.9871 22.2899 46.0394 19.5773 43.5257 18.8495C43.1925 17.994 42.6989 16.7433 42.2384 15.8201C42.3154 15.1138 42.3426 14.3853 42.3426 13.6492C42.3426 10.99 41.7789 8.65743 40.0805 6.92044C39.2872 6.10915 38.3028 5.48684 37.1355 5.01903C34.3398 2.74775 30.2723 0.837036 24.8169 0.837036C19.3616 0.837036 15.3805 2.74775 12.5847 5.01903C11.4174 5.48684 10.433 6.10915 9.63975 6.92044C7.9413 8.65743 7.37764 10.99 7.37764 13.6492C7.37764 14.3853 7.40477 15.1138 7.48186 15.8201C7.02133 16.7433 6.52774 17.994 6.19449 18.8495C3.68082 19.5773 1.73309 22.2899 0.989389 24.1574C0.907813 24.3622 0.873779 24.5813 0.873779 24.8018V30.1202C0.873779 30.3723 0.914376 30.6218 1.04014 30.8403C2.75994 33.8278 12.7462 40.8772 24.8601 40.8772ZM26.485 13.0046C26.4 12.3422 26.3595 11.749 26.3584 11.2191L26.3584 11.1772C26.361 9.63975 26.6971 8.63938 27.2339 8.02499C27.9156 7.2448 29.3246 6.64707 32.2941 6.96844C35.3026 7.29402 36.9842 8.04072 37.9376 9.01574C38.8606 9.95971 39.3455 11.372 39.3455 13.6492C39.3455 16.0687 38.9969 17.4982 38.2302 18.3678C37.5012 19.1946 36.0656 19.8674 32.9214 19.8674C30.5041 19.8674 29.1221 19.0812 28.2386 17.9939C27.2899 16.8264 26.7559 15.1161 26.485 13.0046ZM23.2353 13.0046C23.3203 12.3422 23.3607 11.749 23.3619 11.2191L23.3619 11.1772C23.3592 9.63974 23.0232 8.63937 22.4863 8.02498C21.8046 7.24479 20.3957 6.64707 17.4261 6.96843C14.4176 7.29402 12.736 8.04071 11.7826 9.01573C10.8596 9.9597 10.3747 11.372 10.3747 13.6492C10.3747 16.0687 10.7234 17.4982 11.49 18.3677C12.219 19.1946 13.6546 19.8674 16.7989 19.8674C19.2161 19.8674 20.5981 19.0812 21.4816 17.9939C22.4304 16.8264 22.9643 15.1161 23.2353 13.0046ZM25.2042 18.8676L25.0543 18.8676C24.8715 18.8678 24.6005 18.868 24.516 18.8676C24.3045 19.2218 24.0693 19.5618 23.8075 19.884C22.2697 21.7764 19.9741 22.8644 16.7988 22.8644C13.3524 22.8644 10.8266 22.1471 9.24196 20.3498C9.15187 20.2476 9.07125 20.1406 9.07125 20.1406L8.87613 20.3498V33.5049C11.7429 35.0628 17.8959 37.8586 24.8601 37.8586C31.8243 37.8586 37.9773 35.0628 40.8441 33.5049V20.3498L40.649 20.1406C40.649 20.1406 40.5829 20.231 40.4783 20.3498C38.8936 22.1471 36.3678 22.8644 32.9214 22.8644C29.7461 22.8644 27.4506 21.7764 25.9127 19.884C25.6509 19.5618 25.4157 19.2218 25.2042 18.8676Z";function vg({size:e=16,style:t}){return Oo("svg",{width:e,height:e,viewBox:"0 0 1200 1200",fill:"currentColor",stroke:"none",style:{flexShrink:0,...t},children:Oo("path",{d:hg})})}function xg({size:e=16,style:t}){return Oo("svg",{width:e,height:e,viewBox:"0 0 158.7128 157.296",fill:"currentColor",stroke:"none",style:{flexShrink:0,...t},children:Oo("path",{d:yg})})}function Sg({size:e=16,style:t}){return Oo("svg",{width:e,height:e,viewBox:"0 0 49.7202 40.0402",fill:"currentColor",stroke:"none",style:{flexShrink:0,...t},children:Oo("path",{d:bg,fillRule:"evenodd",clipRule:"evenodd"})})}function ci({provider:e,size:t=16,style:n}){return e==="codex"?Oo(xg,{size:t,style:n}):e==="copilot"?Oo(Sg,{size:t,style:n}):Oo(vg,{size:t,style:n})}var os=[{id:"claude-opus-4-6",label:"Opus 4.6",source:"static"},{id:"claude-sonnet-4-6",label:"Sonn 4.6",source:"static"}],rs=[{id:"gpt-5.4",label:"GPT 5.4",source:"static"},{id:"gpt-5.3-codex",label:"Codex 5.3",source:"static"},{id:"gpt-5.3-codex-spark",label:"Spark 5.3",source:"static"}],ya=[{id:"",label:"Default",source:"static"}];var wg=[...os,...rs,...ya];function ba(e,t){if(t==="copilot"&&!e)return"Copilot";if(!e)return t==="codex"?"Codex":"Claude Code";let n=wg.find(o=>o.id===e);return n?n.label:e.replace(/-\d{8,}$/,"")}import{jsx as Nc}from"react/jsx-runtime";var Zn={iconDefault:"#1f2937",iconActive:"#1f2937",bgActive:"#dedede",bgHover:"#e2e2e2",separator:"#e5e7eb"};function _o({children:e,active:t,siblingActive:n,disabled:o,onClick:r,title:i}){let s=()=>o?.4:n&&!t?.5:1,a={position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:0,border:"none",cursor:o?"default":"pointer",transition:"background-color 150ms ease, color 150ms ease, transform 100ms ease, opacity 150ms ease",backgroundColor:t?Zn.bgActive:"transparent",color:t?Zn.iconActive:Zn.iconDefault,opacity:s()};return Nc("button",{type:"button",onClick:o?void 0:r,title:i,disabled:o,style:a,onMouseEnter:l=>{o||(l.currentTarget.style.opacity="1",t||(l.currentTarget.style.backgroundColor=Zn.bgHover))},onMouseLeave:l=>{o||(l.currentTarget.style.opacity=String(s()),t||(l.currentTarget.style.backgroundColor="transparent"))},onMouseDown:l=>{o||(l.currentTarget.style.transform="scale(0.95)")},onMouseUp:l=>{o||(l.currentTarget.style.transform="scale(1)")},children:e})}function Hc(){return Nc("div",{style:{width:1,height:20,backgroundColor:"rgba(0, 0, 0, 0.05)",margin:"0 8px"}})}import{Fragment as di,jsx as ue,jsxs as Pt}from"react/jsx-runtime";function Og(e,t){if(e<=0)return[];if(e<=4)return Array.from({length:e},(r,i)=>({key:`model-${i}`,index:i,active:i===t}));let n=e-1,o=r=>({key:`model-${r}`,index:r,active:r===t});return t===0?[o(0),o(1),o(2),{key:"overflow-after",overflow:!0}]:t===1?[{key:"overflow-before",overflow:!0},o(1),o(2),{key:"overflow-after",overflow:!0}]:t===n-1?[{key:"overflow-before",overflow:!0},o(n-2),o(n-1),o(n)]:t===n?[{key:"overflow-before",overflow:!0},o(n-2),o(n-1),o(n)]:t%2===0?[{key:"overflow-before",overflow:!0},o(t-1),o(t),{key:"overflow-after",overflow:!0}]:[{key:"overflow-before",overflow:!0},o(t),o(t+1),{key:"overflow-after",overflow:!0}]}var xr=[{type:"rectangle",icon:Pg,label:"Rectangle",shortcut:"R"},{type:"circle",icon:Eg,label:"Oval",shortcut:"O"},{type:"line",icon:Ag,label:"Line",shortcut:"L"},{type:"freehand",icon:Rg,label:"Pen",shortcut:"P"}],_g=new Set(xr.map(e=>e.type));function Hg(e,t,n,o,r,i,s,a){let l=(e-r)*(o-i)-(n-r)*(t-i),d=(e-s)*(i-a)-(r-s)*(t-a),c=(e-n)*(a-o)-(s-n)*(t-o),p=l<0||d<0||c<0,u=l>0||d>0||c>0;return!(p&&u)}function Ng(e="bottom-right"){return sl(e,window.innerWidth,window.innerHeight)}var Fg=[{type:"text",icon:Dg,label:"Text",shortcut:"T"}],Fc={inspector:{name:"Comment",desc:"Pin feedback to specific elements on the page.",usage:["Click any element to attach a comment","Type your note, then hand off to your AI","Your AI may ask clarifying questions","Replies get threaded"],keys:[{key:"C",desc:"Select tool"},{key:"Click",desc:"Pin comment to element"},{key:"Esc",desc:"Deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},hand:{name:"Handle",desc:"Quickly finetune layout and typescale.",usage:["Edges \u2192 padding","Between items \u2192 spacing","Corners \u2192 rounding","Right of text \u2192 font size","Below text \u2192 line height","Click a spacing handle to cycle distribution","Right-click \u2192 inspect element styles"],keys:[{key:"H",desc:"Select tool"},{key:"Shift",desc:"Snap to scale"},{key:"\u2325 + swipe",desc:"Cycle justify / flip direction"},{key:"\u21E7 + swipe",desc:"Cycle align-items"},{key:"Right-click",desc:"Inspect styles"},{key:"Esc",desc:"Deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},rectangle:{name:"Rectangle",desc:"Draw rectangular highlights to mark areas of interest.",usage:["Click and drag to draw","Cycle between shapes with the dot selector"],keys:[{key:"R",desc:"Rectangle"},{key:"O",desc:"Oval"},{key:"L",desc:"Line"},{key:"P",desc:"Pen"},{key:"Esc",desc:"Cancel or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},circle:{name:"Oval",desc:"Draw oval highlights to mark areas of interest.",usage:["Click and drag to draw","Cycle between shapes with the dot selector"],keys:[{key:"O",desc:"Oval"},{key:"R",desc:"Rectangle"},{key:"L",desc:"Line"},{key:"P",desc:"Pen"},{key:"Esc",desc:"Cancel or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},line:{name:"Line",desc:"Draw line annotations to point at or connect elements.",usage:["Click and drag to draw","Cycle between shapes with the dot selector"],keys:[{key:"L",desc:"Line"},{key:"R",desc:"Rectangle"},{key:"O",desc:"Oval"},{key:"P",desc:"Pen"},{key:"Esc",desc:"Cancel or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},freehand:{name:"Pen",desc:"Draw freehand paths to annotate freely.",usage:["Click and drag to draw","Cycle between shapes with the dot selector"],keys:[{key:"P",desc:"Pen"},{key:"R",desc:"Rectangle"},{key:"O",desc:"Oval"},{key:"L",desc:"Line"},{key:"Esc",desc:"Cancel or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},text:{name:"Text",desc:"Place text labels anywhere on the page.",usage:["Click to place, then start typing","Click away or press Enter to finish","Scroll while hovering a label to resize it"],keys:[{key:"T",desc:"Select tool"},{key:"Esc",desc:"Cancel text or deselect"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]},model:{name:"Model",desc:"Promote components into the local design model.",usage:["Hover to highlight component boundaries","Scroll to walk up/down the component tree","Click to add to model.json","Green = already in model"],keys:[{key:"M",desc:"Select tool"},{key:"Scroll",desc:"Walk tree depth"},{key:"Click",desc:"Promote component"},{key:"Esc",desc:"Deselect"}]},eval:{name:"Evals",desc:"Synthesize inferred evals from design history.",usage:["Infer evals from annotations","Reject, refine, or approve proposals"],keys:[{key:"E",desc:"Select tool"},{key:"Esc",desc:"Deselect"}]},counter:{name:"Annotations",desc:"Click to cycle, scroll to change color, long press to reset.",usage:[],keys:[{key:"Click",desc:"Cycle annotations"},{key:"Scroll",desc:"Change color"},{key:"Hold",desc:"Reset to red"}]},clear:{name:"Clear",desc:"Remove all annotations and style changes.",usage:[],keys:[{key:"\u2318 \u232B",desc:"Clear all"},{key:"\u232B",desc:"Delete selected annotation"},{key:"\u2318 Z",desc:"Undo"},{key:"\u2318 \u21E7 Z",desc:"Redo"}]},collapse:{name:"Popmelt",desc:`Comment and zhuzh, then hand off.
14
14
 
15
- Your AI gets the visual and technical context it needs to act.`,usage:[],keys:[{key:"\u2318\u2318",desc:"Toggle toolbar"}]}},lg={zIndex:9999,display:"flex",alignItems:"center",backgroundColor:"#eaeaea",borderWidth:3,borderStyle:"solid",borderColor:"transparent",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",cursor:"pointer",overflow:"visible",boxSizing:"content-box",transition:"none"},qs="devtools-toolbar-expanded",Zs="devtools-annotations",Qs="devtools-style-modifications",ea="devtools-active-tool",vc="devtools-active-color",xc="devtools-stroke-width",Sc="devtools-inspected-element",ta="devtools-spacing-changes",cg={expanded:qs,annotations:Zs,styleMods:Qs,spacingChanges:ta,tool:ea,color:vc,stroke:xc,inspected:Sc};function wc({state:e,dispatch:t,onScreenshot:n,onSendToClaude:o,hasActiveJobs:r,activeJobColor:i,onCrosshairHover:s,onClear:a,provider:l="claude",onProviderChange:p,availableProviders:c,modelIndex:u=0,modelCount:d=2,modelLabel:g="Opus 4.6",onModelChange:x,onViewThread:h,isThreadPanelOpen:I,mcpStatus:O,bridgeUrl:P,isBridgeConnected:F,packageVersion:M,bridgeVersion:D,bridgeRestartState:J="idle",bridgeRestartMessage:ee,onBridgeRestart:C,modelSelectedComponent:S,modelCanvasHoveredComponent:A,onModelComponentHover:y,onSpacingTokenHover:T,onModifySpacingToken:L,onDeleteSpacingToken:ce,modelRefreshKey:We,evalRefreshKey:be,onModelComponentAdded:j,onModelComponentRemoved:se,onSynthesizeRules:_,isSynthesizing:he,onSynthesizeEvals:fe,isSynthesizingEvals:Ae,onRunEval:De,onViewEvalRunThread:ze,runningEvalIds:de,onMouseEnter:Ee,toolbarRef:Ge,snapPosition:Qe="bottom-right",onSnapPositionChange:pt}){let[je,X]=nr(()=>typeof window<"u"?{w:window.innerWidth,h:window.innerHeight}:{w:1920,h:1080});an(()=>{let H=()=>X({w:window.innerWidth,h:window.innerHeight});return window.addEventListener("resize",H),()=>window.removeEventListener("resize",H)},[]);let[Z,Se]=nr(()=>typeof window>"u"?!1:localStorage.getItem(qs)==="true"),[Je,lt]=nr(0),ke=Rt(0),nt=Rt(0),ot=Rt(e.isAnnotating),rt=Rt(!1),Lt=Rt(typeof window<"u"?localStorage.getItem(ea):null),yt=Rt(typeof window<"u"?localStorage.getItem(vc):null),ne=Rt(typeof window<"u"?localStorage.getItem(xc):null),[te,ge]=nr(null),Pe=Rt(!1),et=Rt(null),Re=Rt(null),_t=Rt(null),[Nt,xn]=nr([]),Pn=Rt({x:0,y:0}),At=Rt(null),xt=Rt(null),Kt=Rt(null),ft=_n(()=>{At.current=null,xt.current=null,Kt.current&&(clearTimeout(Kt.current),Kt.current=null)},[]),Jt=_n(H=>{Re.current&&(clearTimeout(Re.current),Re.current=null),Pe.current?(At.current=H,xt.current={...Pn.current},Kt.current&&clearTimeout(Kt.current),Kt.current=setTimeout(()=>{At.current&&(ge(At.current),ft())},300)):(et.current&&clearTimeout(et.current),et.current=setTimeout(()=>{Pe.current=!0,ge(H),et.current=null},500))},[ft]),tt=_n(()=>{ft(),et.current&&(clearTimeout(et.current),et.current=null),Re.current=setTimeout(()=>{Pe.current=!1,ge(null)},150)},[ft]);an(()=>{let H=_t.current;if(!H)return;let z=()=>{ft(),Re.current&&(clearTimeout(Re.current),Re.current=null)},Q=()=>{Re.current=setTimeout(()=>{Pe.current=!1,ge(null)},150)};return H.addEventListener("mouseenter",z),H.addEventListener("mouseleave",Q),()=>{H.removeEventListener("mouseenter",z),H.removeEventListener("mouseleave",Q)}},[te,ft]),an(()=>{if(te!=="counter"||!P)return;let H=!1;return ho(`${P}/threads/recent?limit=5`).then(z=>z.ok?z.json():[]).then(z=>{H||xn(z)}).catch(()=>{}),()=>{H=!0}},[te,P]);let Gn=_n(H=>{if(Pn.current={x:H.clientX,y:H.clientY},At.current&&xt.current){let z=xt.current,Q=sg(Qe);ig(H.clientX,H.clientY,z.x,z.y,Q.left,Q.y,Q.right,Q.y)||(ge(At.current),ft())}},[ft,Qe]),on=tr(()=>{let H=(c??[]).map(z=>z==="claude"?"Claude":z==="codex"?"Codex":z==="copilot"?"Copilot":z);return{name:"AI Model",desc:H.length>1?`${H.join(" and ")} are available.`:H.length===1?`Connected to ${H[0]}.`:"No AI providers detected.",usage:H.length>1?["Click the logo to switch between providers","Click the model name to switch tiers"]:["Click the model name to switch tiers"],keys:H.length>1?[{key:"Click",desc:"Switch"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]:[{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]}},[c]),Mn=tr(()=>{let H=c&&c.length>0?c:["claude","codex","copilot"],z=H.indexOf(l);return H[(z>=0?z+1:0)%H.length]??l},[c,l]),no=tr(()=>og(d,u),[d,u]);Ul(Z,e,rt,!!r,cg),an(()=>{let H=new URLSearchParams(window.location.search);if(!H.has("popmelt"))return;let z=document.createElement("style");z.textContent="nextjs-portal, vite-error-overlay { display: none !important; }",document.head.appendChild(z);let Q=parseInt(H.get("popmelt")||"0",10)||0,oe=()=>{Se(!0),t({type:"SET_TOOL",payload:"inspector"}),t({type:"SET_ANNOTATING",payload:!0})};if(Q>0){let ue=setTimeout(oe,Q);return()=>clearTimeout(ue)}oe()},[]),an(()=>{if(localStorage.getItem(qs)==="true"&&!e.isAnnotating){if(Z||Se(!0),t({type:"SET_TOOL",payload:Lt.current||"inspector"}),t({type:"SET_ANNOTATING",payload:!0}),yt.current&&t({type:"SET_COLOR",payload:yt.current}),ne.current){let ae=parseFloat(ne.current);isNaN(ae)||t({type:"SET_STROKE_WIDTH",payload:ae})}let Q=localStorage.getItem(Zs);if(Q)try{let ae=JSON.parse(Q);if(Array.isArray(ae)&&ae.length>0){for(let at of ae)(at.status==="waiting_input"||at.status==="in_flight")&&(at.status=at.threadId?"resolved":"pending");t({type:"RESTORE_ANNOTATIONS",payload:{annotations:ae}})}}catch{}let oe=localStorage.getItem(Qs);if(oe)try{let ae=JSON.parse(oe);Array.isArray(ae)&&ae.length>0&&(t({type:"RESTORE_STYLE_MODIFICATIONS",payload:ae}),gi(ae))}catch{}let ue=localStorage.getItem(ta);if(ue)try{let ae=JSON.parse(ue);Array.isArray(ae)&&ae.length>0&&t({type:"RESTORE_SPACING_TOKEN_CHANGES",payload:ae})}catch{}let xe=localStorage.getItem(Sc);if(xe)try{let{selector:ae,info:at}=JSON.parse(xe);if(ae){let It=kn(ae);if(It){let ln=at||{...Tn(It),selector:ae};t({type:"SELECT_ELEMENT",payload:{el:It,info:ln}})}}}catch{}let we=sessionStorage.getItem("popmelt-pending-focus");if(we){sessionStorage.removeItem("popmelt-pending-focus");try{let{annotationId:ae}=JSON.parse(we);if(ae){let at=Q?JSON.parse(Q)??[]:[];requestAnimationFrame(()=>{t({type:"SELECT_ANNOTATION",payload:{id:ae}});let It=at.find(ln=>ln.id===ae);if(It){let cn=(It.groupId?at.filter(Ke=>Ke.groupId===It.groupId):[It]).flatMap(Ke=>Ke.points);if(cn.length>0){let Ke=Math.min(...cn.map(Qt=>Qt.x)),Dt=Math.max(...cn.map(Qt=>Qt.x)),Rn=Math.min(...cn.map(Qt=>Qt.y)),mn=Math.max(...cn.map(Qt=>Qt.y));window.scrollTo({left:(Ke+Dt)/2-window.innerWidth/2,top:(Rn+mn)/2-window.innerHeight/2,behavior:"smooth"})}}})}}catch{}}}let z=sessionStorage.getItem("popmelt-pending-thread");if(z){sessionStorage.removeItem("popmelt-pending-thread");try{let{threadId:Q,selector:oe,preview:ue}=JSON.parse(z);Q&&requestAnimationFrame(()=>{if(oe)try{let xe=document.querySelector(oe);if(xe){let we=xe.getBoundingClientRect(),ae=Math.random().toString(36).slice(2,9);t({type:"ADD_TEXT",payload:{id:ae,point:{x:we.left+we.width,y:we.top},text:ue||"[thread]",linkedSelector:oe,linkedAnchor:"top-left"}}),t({type:"SET_ANNOTATION_THREAD",payload:{ids:[ae],threadId:Q}}),t({type:"SET_ANNOTATION_STATUS",payload:{ids:[ae],status:"resolved"}})}}catch{}h&&h(Q)})}catch{}}return rt.current=!0,()=>{rt.current=!1}},[]);let oo=Rt(e.styleModifications);an(()=>{let H=oo.current,z=e.styleModifications;H!==z&&(mi(H),gi(z),oo.current=z)},[e.styleModifications]),an(()=>{let H=ot.current;ot.current=e.isAnnotating,H&&!e.isAnnotating&&Z&&Se(!1)},[e.isAnnotating,Z]);let qe=Rt(Z);qe.current=Z,an(()=>{let H=Q=>{if(Q.key==="Meta"||Q.key==="Control"){let oe=Date.now();if(oe-ke.current<300){if(nt.current++,nt.current>=2){if(qe.current)t({type:"SET_ANNOTATING",payload:!1}),Se(!1);else{let we=localStorage.getItem(ea);t({type:"SET_TOOL",payload:we||"inspector"}),t({type:"SET_ANNOTATING",payload:!0}),Se(!0)}nt.current=0}}else nt.current=1;ke.current=oe}else nt.current=0},z=Q=>{Q.key!=="Meta"&&Q.key!=="Control"&&(nt.current=0)};return window.addEventListener("keydown",H),window.addEventListener("keyup",z),()=>{window.removeEventListener("keydown",H),window.removeEventListener("keyup",z)}},[t]);let st=_n(H=>{ft(),t({type:"SET_TOOL",payload:H}),e.isAnnotating||t({type:"SET_ANNOTATING",payload:!0}),Pe.current=!1,ge(null),et.current&&(clearTimeout(et.current),et.current=null),Re.current&&(clearTimeout(Re.current),Re.current=null)},[t,e.isAnnotating,ft]),fn=_n(async()=>{window.focus(),await n()},[n]),U=_n(async()=>{o&&await o()},[o]),Me=_n(()=>{t({type:"SET_ANNOTATING",payload:!1}),Se(!1)},[t]),He=_n(()=>{mi(e.styleModifications),document.querySelectorAll("[data-pm]").forEach(H=>H.removeAttribute("data-pm")),t({type:"CLEAR"}),t({type:"CLEAR_ALL_STYLES"}),localStorage.removeItem(Zs),localStorage.removeItem(Qs),localStorage.removeItem(ta),Gt(null),a?.()},[t,e.styleModifications,a]),[Pt,Xe]=nr(()=>{if(yt.current){let H=yt.current.match(/oklch\([^)]*\s+([\d.]+)\s*\)/);if(H?.[1])return parseFloat(H[1])}return 29}),Oe=Rt(null),St=Rt(null),$t=Rt(!1),gn=_n(H=>{let z=H.match(/oklch\([^)]*\s+([\d.]+)\s*\)/);return z&&z[1]?parseFloat(z[1]):null},[]);an(()=>{$t.current=!0;let H=`oklch(0.628 0.258 ${Pt})`;t({type:"SET_COLOR",payload:H}),requestAnimationFrame(()=>{$t.current=!1})},[Pt,t]),an(()=>{if($t.current)return;let H=gn(e.activeColor);H!==null&&Math.abs(H-Pt)>.5&&Xe(H)},[e.activeColor,gn,Pt]);let rn=Rt(null);an(()=>{if(r&&i){let H=gn(i);H!==null&&Math.abs(H-Pt)>.5&&(rn.current===null&&(rn.current=Pt),Xe(H))}else rn.current!==null&&(Xe(rn.current),rn.current=null)},[r,i,gn]);let po=e.annotations.length>0;an(()=>{let H=St.current;if(!H||!po)return;let z=Q=>{Q.preventDefault(),Q.stopPropagation();let oe=Q.deltaY>0?-1:1,ue=((Pt+oe)%360+360)%360,xe=`oklch(0.628 0.258 ${ue})`;Xe(ue),e.selectedAnnotationIds.length>0&&t({type:"UPDATE_ANNOTATION_COLOR",payload:{id:e.lastSelectedId||e.selectedAnnotationIds[0],color:xe}})};return H.addEventListener("wheel",z,{passive:!1}),()=>H.removeEventListener("wheel",z)},[po,e.selectedAnnotationIds,e.lastSelectedId,Pt,t]);let Wt=Rt(!1),ko=Rt(0);an(()=>{let H=e.annotations.some(oe=>!oe.status||oe.status==="pending"),z=Wt.current;Wt.current=H;let Q=ko.current===0&&e.annotations.length>0;if(ko.current=e.annotations.length,(z&&!H||Q&&!H)&&e.annotations.length>0){let oe=e.annotations.map(ue=>gn(ue.color)).filter(ue=>ue!==null);if(oe.length>0){let ue=0,xe=-1;for(let we=0;we<360;we++){let ae=Math.min(...oe.map(at=>{let It=Math.abs(we-at);return Math.min(It,360-It)}));ae>xe&&(xe=ae,ue=we)}Xe(ue)}}},[e.annotations,gn]);let fo=Rt(!1),ir=_n(()=>{fo.current=!1,Oe.current=setTimeout(()=>{fo.current=!0,Xe(29)},500)},[]),Jn=_n(()=>{Oe.current&&(clearTimeout(Oe.current),Oe.current=null)},[]);an(()=>()=>{Oe.current&&clearTimeout(Oe.current),Kt.current&&clearTimeout(Kt.current)},[]);let Sn=mr(),ro=tr(()=>e.annotations.filter(H=>!H.pathname||H.pathname===Sn),[e.annotations,Sn]),Yn=tr(()=>vi(e.annotations),[e.annotations]),Ft=tr(()=>{let H=[],z=new Set,Q=[...e.annotations].sort((oe,ue)=>oe.timestamp-ue.timestamp);for(let oe of Q)if(!Yn.has(oe))if(oe.groupId){if(!z.has(oe.groupId)){z.add(oe.groupId);let ue=e.annotations.filter(ae=>ae.groupId===oe.groupId&&!Yn.has(ae)),xe=ue.find(ae=>ae.type!=="text")||ue[0],we=Math.min(...ue.map(ae=>ae.timestamp));H.push({id:xe.id,pathname:oe.pathname,annotations:ue,timestamp:we})}}else H.push({id:oe.id,pathname:oe.pathname,annotations:[oe],timestamp:oe.timestamp});return H},[e.annotations,Yn]),wt=tr(()=>Ft.filter(H=>!H.pathname||H.pathname===Sn),[Ft,Sn]),[jt,Gt]=nr(null),wn=Ft.length+e.styleModifications.length;an(()=>{(wn===0||jt!==null&&jt>=wn)&&Gt(null)},[wn,jt]),an(()=>{if(e.selectedAnnotationIds.length===0&&!e.inspectedElement){Gt(null);return}if(e.selectedAnnotationIds.length>0){let H=e.selectedAnnotationIds[0],z=Ft.findIndex(Q=>Q.id===H||Q.annotations.some(oe=>oe.id===H));z>=0&&z!==jt&&Gt(z)}},[e.selectedAnnotationIds,e.inspectedElement,Ft]);let io=_n(()=>{if(wn===0)return;let H;if(jt===null?H=0:jt+1>=wn?H=null:H=jt+1,Gt(H),H===null){t({type:"SELECT_ANNOTATION",payload:{id:null}}),t({type:"SELECT_ELEMENT",payload:null});return}if(H<Ft.length){let z=Ft[H];if(!(!z.pathname||z.pathname===Sn)){sessionStorage.setItem("popmelt-pending-focus",JSON.stringify({annotationId:z.id,pathname:z.pathname})),window.location.href=z.pathname;return}t({type:"SELECT_ELEMENT",payload:null}),t({type:"SELECT_ANNOTATION",payload:{id:z.id}});let oe=z.annotations.find(Ke=>Ke.type!=="text")||z.annotations[0];if(z.annotations.some(Ke=>Ke.linkedSelector))t({type:"SET_TOOL",payload:"inspector"});else if(oe?.type&&oe.type!=="text"&&oe.type!=="inspector"){t({type:"SET_TOOL",payload:oe.type});let Ke=or.findIndex(Dt=>Dt.type===oe.type);Ke>=0&&lt(Ke)}if(oe?.color){t({type:"SET_COLOR",payload:oe.color});let Ke=gn(oe.color);Ke!==null&&Xe(Ke)}let xe=z.annotations.flatMap(Ke=>Ke.points);if(xe.length===0)return;let we=Math.min(...xe.map(Ke=>Ke.x)),ae=Math.max(...xe.map(Ke=>Ke.x)),at=Math.min(...xe.map(Ke=>Ke.y)),It=Math.max(...xe.map(Ke=>Ke.y)),ln=(we+ae)/2,cn=(at+It)/2;if(window.scrollTo({left:ln-window.innerWidth/2,top:cn-window.innerHeight/2,behavior:"smooth"}),I&&h){let Ke=z.annotations.find(Dt=>Dt.threadId)?.threadId;Ke&&h(Ke)}}else{let z=H-Ft.length,Q=e.styleModifications[z];if(!Q)return;let oe=kn(Q.selector);if(!oe)return;t({type:"SELECT_ANNOTATION",payload:{id:null}}),t({type:"SET_TOOL",payload:"inspector"}),t({type:"SELECT_ELEMENT",payload:{el:oe,info:Q.element}});let ue=oe.getBoundingClientRect(),xe=ue.left+ue.width/2+window.scrollX,we=ue.top+ue.height/2+window.scrollY;window.scrollTo({left:xe-window.innerWidth/2,top:we-window.innerHeight/2,behavior:"smooth"})}},[Ft,Sn,e.styleModifications,wn,jt,t,gn,I,h]);an(()=>{if(!Z)return;let H=z=>{let Q=document.activeElement;for(;Q?.shadowRoot?.activeElement;)Q=Q.shadowRoot.activeElement;if(Q?.tagName==="INPUT"||Q?.tagName==="TEXTAREA"||Q?.isContentEditable)return;if((z.metaKey||z.ctrlKey)&&z.key==="Enter"){o&&(e.annotations.length>0||e.styleModifications.length>0||e.spacingTokenChanges.filter(xe=>!xe.captured).length>0)&&(z.preventDefault(),U());return}if((z.metaKey||z.ctrlKey)&&(z.key==="c"||z.key==="C"||z.code==="KeyC")){let xe=window.getSelection();if(xe&&xe.toString().length>0)return;(e.annotations.length>0||e.styleModifications.length>0)&&(z.preventDefault(),window.focus(),fn());return}if((z.metaKey||z.ctrlKey)&&(z.key==="Backspace"||z.key==="Delete")){z.preventDefault(),He();return}if(z.metaKey||z.ctrlKey||z.altKey)return;let oe={p:"freehand",l:"line",r:"rectangle",o:"circle",t:"text",c:"inspector",h:"hand",e:"eval"};if(z.key.toLowerCase()==="m"){z.preventDefault(),st("model");return}let ue=oe[z.key.toLowerCase()];if(ue){z.preventDefault();let xe=or.findIndex(we=>we.type===ue);xe>=0&&lt(xe),st(ue)}};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[Z,st,fn,U,o,He,e.annotations.length,e.styleModifications.length,e.spacingTokenChanges,te]);let In=Ba(Qe,je.w,je.h),To={...lg,...In,borderRadius:0,padding:Z?"0 8px":"0",width:Z?"auto":48,height:48,gap:0,justifyContent:Z?"flex-start":"center"},Zt=pe("div",{style:xi({color:r&&i?i:"rgb(0,0,0)",animated:!!r})}),sr=F===!1?"rgba(239, 68, 68, 0.4)":r&&i?i:Wn.iconActive,Vn=!!(M&&D&&M!==D),Nn=J==="restarting"||!C&&!P,ar=J==="error"?"#dc2626":J==="ok"?Wn.iconDefault:Vn?"#b45309":Wn.iconDefault,Mo=J==="restarting"?"Restarting":J==="error"?"Restart failed":J==="ok"?"Restarted":Vn?"Update bridge":null,Ho=ee??(Vn?`Bridge ${D} is older than package ${M}. Restart bridge.`:D?`Bridge ${D}. Restart bridge.`:"Restart bridge"),lr=Rt(null);an(()=>{if(!Z)return;let H=lr.current;if(!H)return;let z=()=>{s?.(!0),Jt("collapse")},Q=()=>{s?.(!1),tt()};return H.addEventListener("mouseenter",z),H.addEventListener("mouseleave",Q),()=>{H.removeEventListener("mouseenter",z),H.removeEventListener("mouseleave",Q)}},[Z,r,s,Jt,tt]);let cr=Rt(null);return an(()=>{if(Z)return;let H=cr.current;if(!H)return;let z=H.querySelector("[data-popmelt-logo]"),Q=()=>{H.style.opacity="1",!r&&z&&(z.style.fill="#000"),Ee?.()},oe=()=>{H.style.opacity=r?"1":"0.5",!r&&z&&(z.style.fill="none")};return H.addEventListener("mouseenter",Q),H.addEventListener("mouseleave",oe),()=>{H.removeEventListener("mouseenter",Q),H.removeEventListener("mouseleave",oe)}},[Z,r,Ee]),Z?Tt(Yr,{children:[pe("style",{children:`
15
+ Your AI gets the visual and technical context it needs to act.`,usage:[],keys:[{key:"\u2318\u2318",desc:"Toggle toolbar"}]}},zg={zIndex:9999,display:"flex",alignItems:"center",backgroundColor:"#eaeaea",borderWidth:3,borderStyle:"solid",borderColor:"transparent",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",cursor:"pointer",overflow:"visible",boxSizing:"content-box",transition:"none"},va="devtools-toolbar-expanded",xa="devtools-annotations",Sa="devtools-style-modifications",wa="devtools-active-tool",zc="devtools-active-color",$c="devtools-stroke-width",Wc="devtools-inspected-element",Ca="devtools-spacing-changes",$g={expanded:va,annotations:xa,styleMods:Sa,spacingChanges:Ca,tool:wa,color:zc,stroke:$c,inspected:Wc};function jc({state:e,dispatch:t,onScreenshot:n,onSendToClaude:o,hasActiveJobs:r,activeJobColor:i,onCrosshairHover:s,onClear:a,provider:l="claude",onProviderChange:d,availableProviders:c,modelIndex:p=0,modelCount:u=2,modelLabel:m="Opus 4.6",onModelChange:v,onViewThread:b,isThreadPanelOpen:I,mcpStatus:P,bridgeUrl:N,isBridgeConnected:C,packageVersion:k,bridgeVersion:E,bridgeRestartState:$="idle",bridgeRestartMessage:Q,onBridgeRestart:V,modelSelectedComponent:M,modelCanvasHoveredComponent:B,onModelComponentHover:f,onSpacingTokenHover:g,onModifySpacingToken:j,onDeleteSpacingToken:fe,modelRefreshKey:Re,evalRefreshKey:le,onModelComponentAdded:Ce,onModelComponentRemoved:Ee,onSynthesizeRules:K,isSynthesizing:O,onSynthesizeEvals:Z,isSynthesizingEvals:pe,onRunEval:Le,onViewEvalRunThread:_e,runningEvalIds:ge,onMouseEnter:lt,toolbarRef:Xe,snapPosition:ce="bottom-right",onSnapPositionChange:Ae}){let[ft,G]=vr(()=>typeof window<"u"?{w:window.innerWidth,h:window.innerHeight}:{w:1920,h:1080});hn(()=>{let A=()=>G({w:window.innerWidth,h:window.innerHeight});return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[]);let[se,ie]=vr(()=>typeof window>"u"?!1:localStorage.getItem(va)==="true"),[Ne,rt]=vr(0),Ie=Ot(0),et=Ot(0),it=Ot(e.isAnnotating),qe=Ot(!1),Rt=Ot(typeof window<"u"?localStorage.getItem(wa):null),Kt=Ot(typeof window<"u"?localStorage.getItem(zc):null),Dt=Ot(typeof window<"u"?localStorage.getItem($c):null),[Ge,W]=vr(null),ye=Ot(!1),Se=Ot(null),He=Ot(null),$t=Ot(null),[tt,Gt]=vr([]),Jt=Ot({x:0,y:0}),Bt=Ot(null),un=Ot(null),gt=Ot(null),Lt=Yn(()=>{Bt.current=null,un.current=null,gt.current&&(clearTimeout(gt.current),gt.current=null)},[]),st=Yn(A=>{He.current&&(clearTimeout(He.current),He.current=null),ye.current?(Bt.current=A,un.current={...Jt.current},gt.current&&clearTimeout(gt.current),gt.current=setTimeout(()=>{Bt.current&&(W(Bt.current),Lt())},300)):(Se.current&&clearTimeout(Se.current),Se.current=setTimeout(()=>{ye.current=!0,W(A),Se.current=null},500))},[Lt]),Yt=Yn(()=>{Lt(),Se.current&&(clearTimeout(Se.current),Se.current=null),He.current=setTimeout(()=>{ye.current=!1,W(null)},150)},[Lt]);hn(()=>{let A=$t.current;if(!A)return;let F=()=>{Lt(),He.current&&(clearTimeout(He.current),He.current=null)},oe=()=>{He.current=setTimeout(()=>{ye.current=!1,W(null)},150)};return A.addEventListener("mouseenter",F),A.addEventListener("mouseleave",oe),()=>{A.removeEventListener("mouseenter",F),A.removeEventListener("mouseleave",oe)}},[Ge,Lt]),hn(()=>{if(Ge!=="counter"||!N)return;let A=!1;return Ro(`${N}/threads/recent?limit=5`).then(F=>F.ok?F.json():[]).then(F=>{A||Gt(F)}).catch(()=>{}),()=>{A=!0}},[Ge,N]);let eo=Yn(A=>{if(Jt.current={x:A.clientX,y:A.clientY},Bt.current&&un.current){let F=un.current,oe=Ng(ce);Hg(A.clientX,A.clientY,F.x,F.y,oe.left,oe.y,oe.right,oe.y)||(W(Bt.current),Lt())}},[Lt,ce]),sn=br(()=>{let A=(c??[]).map(F=>F==="claude"?"Claude":F==="codex"?"Codex":F==="copilot"?"Copilot":F);return{name:"AI Model",desc:A.length>1?`${A.join(" and ")} are available.`:A.length===1?`Connected to ${A[0]}.`:"No AI providers detected.",usage:A.length>1?["Click the logo to switch between providers","Click the model name to switch tiers"]:["Click the model name to switch tiers"],keys:A.length>1?[{key:"Click",desc:"Switch"},{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]:[{key:"\u2318 Enter",desc:"Hand off to your AI",accent:!0}]}},[c]),Un=br(()=>{let A=c&&c.length>0?c:["claude","codex","copilot"],F=A.indexOf(l);return A[(F>=0?F+1:0)%A.length]??l},[c,l]),fo=br(()=>Og(u,p),[u,p]);mc(se,e,qe,!!r,$g),hn(()=>{let A=new URLSearchParams(window.location.search);if(!A.has("popmelt"))return;let F=document.createElement("style");F.textContent="nextjs-portal, vite-error-overlay { display: none !important; }",document.head.appendChild(F);let oe=parseInt(A.get("popmelt")||"0",10)||0,re=()=>{ie(!0),t({type:"SET_TOOL",payload:"inspector"}),t({type:"SET_ANNOTATING",payload:!0})};if(oe>0){let ne=setTimeout(re,oe);return()=>clearTimeout(ne)}re()},[]),hn(()=>{if(localStorage.getItem(va)==="true"&&!e.isAnnotating){if(se||ie(!0),t({type:"SET_TOOL",payload:Rt.current||"inspector"}),t({type:"SET_ANNOTATING",payload:!0}),Kt.current&&t({type:"SET_COLOR",payload:Kt.current}),Dt.current){let ve=parseFloat(Dt.current);isNaN(ve)||t({type:"SET_STROKE_WIDTH",payload:ve})}let oe=localStorage.getItem(xa);if(oe)try{let ve=JSON.parse(oe);if(Array.isArray(ve)&&ve.length>0){for(let ut of ve)(ut.status==="waiting_input"||ut.status==="in_flight")&&(ut.status=ut.threadId?"resolved":"pending");t({type:"RESTORE_ANNOTATIONS",payload:{annotations:ve}})}}catch{}let re=localStorage.getItem(Sa);if(re)try{let ve=JSON.parse(re);Array.isArray(ve)&&ve.length>0&&(t({type:"RESTORE_STYLE_MODIFICATIONS",payload:ve}),Oi(ve))}catch{}let ne=localStorage.getItem(Ca);if(ne)try{let ve=JSON.parse(ne);Array.isArray(ve)&&ve.length>0&&t({type:"RESTORE_SPACING_TOKEN_CHANGES",payload:ve})}catch{}let we=localStorage.getItem(Wc);if(we)try{let{selector:ve,info:ut}=JSON.parse(we);if(ve){let Et=En(ve);if(Et){let Vt=ut||{...Dn(Et),selector:ve};t({type:"SELECT_ELEMENT",payload:{el:Et,info:Vt}})}}}catch{}let Be=sessionStorage.getItem("popmelt-pending-focus");if(Be){sessionStorage.removeItem("popmelt-pending-focus");try{let{annotationId:ve}=JSON.parse(Be);if(ve){let ut=oe?JSON.parse(oe)??[]:[];requestAnimationFrame(()=>{t({type:"SELECT_ANNOTATION",payload:{id:ve}});let Et=ut.find(Vt=>Vt.id===ve);if(Et){let pn=(Et.groupId?ut.filter(ot=>ot.groupId===Et.groupId):[Et]).flatMap(ot=>ot.points);if(pn.length>0){let ot=Math.min(...pn.map(Mn=>Mn.x)),wn=Math.max(...pn.map(Mn=>Mn.x)),Cn=Math.min(...pn.map(Mn=>Mn.y)),fn=Math.max(...pn.map(Mn=>Mn.y));window.scrollTo({left:(ot+wn)/2-window.innerWidth/2,top:(Cn+fn)/2-window.innerHeight/2,behavior:"smooth"})}}})}}catch{}}}let F=sessionStorage.getItem("popmelt-pending-thread");if(F){sessionStorage.removeItem("popmelt-pending-thread");try{let{threadId:oe,selector:re,preview:ne}=JSON.parse(F);oe&&requestAnimationFrame(()=>{if(re)try{let we=document.querySelector(re);if(we){let Be=we.getBoundingClientRect(),ve=Math.random().toString(36).slice(2,9);t({type:"ADD_TEXT",payload:{id:ve,point:{x:Be.left+Be.width,y:Be.top},text:ne||"[thread]",linkedSelector:re,linkedAnchor:"top-left"}}),t({type:"SET_ANNOTATION_THREAD",payload:{ids:[ve],threadId:oe}}),t({type:"SET_ANNOTATION_STATUS",payload:{ids:[ve],status:"resolved"}})}}catch{}b&&b(oe)})}catch{}}return qe.current=!0,()=>{qe.current=!1}},[]);let On=Ot(e.styleModifications);hn(()=>{let A=On.current,F=e.styleModifications;A!==F&&(_i(A),Oi(F),On.current=F)},[e.styleModifications]),hn(()=>{let A=it.current;it.current=e.isAnnotating,A&&!e.isAnnotating&&se&&ie(!1)},[e.isAnnotating,se]);let nt=Ot(se);nt.current=se,hn(()=>{let A=oe=>{if(oe.key==="Meta"||oe.key==="Control"){let re=Date.now();if(re-Ie.current<300){if(et.current++,et.current>=2){if(nt.current)t({type:"SET_ANNOTATING",payload:!1}),ie(!1);else{let Be=localStorage.getItem(wa);t({type:"SET_TOOL",payload:Be||"inspector"}),t({type:"SET_ANNOTATING",payload:!0}),ie(!0)}et.current=0}}else et.current=1;Ie.current=re}else et.current=0},F=oe=>{oe.key!=="Meta"&&oe.key!=="Control"&&(et.current=0)};return window.addEventListener("keydown",A),window.addEventListener("keyup",F),()=>{window.removeEventListener("keydown",A),window.removeEventListener("keyup",F)}},[t]);let at=Yn(A=>{Lt(),t({type:"SET_TOOL",payload:A}),e.isAnnotating||t({type:"SET_ANNOTATING",payload:!0}),ye.current=!1,W(null),Se.current&&(clearTimeout(Se.current),Se.current=null),He.current&&(clearTimeout(He.current),He.current=null)},[t,e.isAnnotating,Lt]),Xt=Yn(async()=>{window.focus(),await n()},[n]),U=Yn(async()=>{o&&await o()},[o]),Te=Yn(()=>{t({type:"SET_ANNOTATING",payload:!1}),ie(!1)},[t]),Ue=Yn(()=>{_i(e.styleModifications),document.querySelectorAll("[data-pm]").forEach(A=>A.removeAttribute("data-pm")),t({type:"CLEAR"}),t({type:"CLEAR_ALL_STYLES"}),localStorage.removeItem(xa),localStorage.removeItem(Sa),localStorage.removeItem(Ca),kn(null),a?.()},[t,e.styleModifications,a]),[ht,mt]=vr(()=>{if(Kt.current){let A=Kt.current.match(/oklch\([^)]*\s+([\d.]+)\s*\)/);if(A?.[1])return parseFloat(A[1])}return 29}),Pe=Ot(null),ct=Ot(null),to=Ot(!1),qt=Yn(A=>{let F=A.match(/oklch\([^)]*\s+([\d.]+)\s*\)/);return F&&F[1]?parseFloat(F[1]):null},[]);hn(()=>{to.current=!0;let A=`oklch(0.628 0.258 ${ht})`;t({type:"SET_COLOR",payload:A}),requestAnimationFrame(()=>{to.current=!1})},[ht,t]),hn(()=>{if(to.current)return;let A=qt(e.activeColor);A!==null&&Math.abs(A-ht)>.5&&mt(A)},[e.activeColor,qt,ht]);let _n=Ot(null);hn(()=>{if(r&&i){let A=qt(i);A!==null&&Math.abs(A-ht)>.5&&(_n.current===null&&(_n.current=ht),mt(A))}else _n.current!==null&&(mt(_n.current),_n.current=null)},[r,i,qt]);let Wt=e.annotations.length>0;hn(()=>{let A=ct.current;if(!A||!Wt)return;let F=oe=>{oe.preventDefault(),oe.stopPropagation();let re=oe.deltaY>0?-1:1,ne=((ht+re)%360+360)%360,we=`oklch(0.628 0.258 ${ne})`;mt(ne),e.selectedAnnotationIds.length>0&&t({type:"UPDATE_ANNOTATION_COLOR",payload:{id:e.lastSelectedId||e.selectedAnnotationIds[0],color:we}})};return A.addEventListener("wheel",F,{passive:!1}),()=>A.removeEventListener("wheel",F)},[Wt,e.selectedAnnotationIds,e.lastSelectedId,ht,t]);let Ho=Ot(!1),Uo=Ot(0);hn(()=>{let A=e.annotations.some(re=>!re.status||re.status==="pending"),F=Ho.current;Ho.current=A;let oe=Uo.current===0&&e.annotations.length>0;if(Uo.current=e.annotations.length,(F&&!A||oe&&!A)&&e.annotations.length>0){let re=e.annotations.map(ne=>qt(ne.color)).filter(ne=>ne!==null);if(re.length>0){let ne=0,we=-1;for(let Be=0;Be<360;Be++){let ve=Math.min(...re.map(ut=>{let Et=Math.abs(Be-ut);return Math.min(Et,360-Et)}));ve>we&&(we=ve,ne=Be)}mt(ne)}}},[e.annotations,qt]);let wo=Ot(!1),No=Yn(()=>{wo.current=!1,Pe.current=setTimeout(()=>{wo.current=!0,mt(29)},500)},[]),Ko=Yn(()=>{Pe.current&&(clearTimeout(Pe.current),Pe.current=null)},[]);hn(()=>()=>{Pe.current&&clearTimeout(Pe.current),gt.current&&clearTimeout(gt.current)},[]);let an=kr(),Xo=br(()=>e.annotations.filter(A=>!A.pathname||A.pathname===an),[e.annotations,an]),Co=br(()=>zi(e.annotations),[e.annotations]),Je=br(()=>{let A=[],F=new Set,oe=[...e.annotations].sort((re,ne)=>re.timestamp-ne.timestamp);for(let re of oe)if(!Co.has(re))if(re.groupId){if(!F.has(re.groupId)){F.add(re.groupId);let ne=e.annotations.filter(ve=>ve.groupId===re.groupId&&!Co.has(ve)),we=ne.find(ve=>ve.type!=="text")||ne[0],Be=Math.min(...ne.map(ve=>ve.timestamp));A.push({id:we.id,pathname:re.pathname,annotations:ne,timestamp:Be})}}else A.push({id:re.id,pathname:re.pathname,annotations:[re],timestamp:re.timestamp});return A},[e.annotations,Co]),no=br(()=>Je.filter(A=>!A.pathname||A.pathname===an),[Je,an]),[Ct,kn]=vr(null),yn=Je.length+e.styleModifications.length;hn(()=>{(yn===0||Ct!==null&&Ct>=yn)&&kn(null)},[yn,Ct]),hn(()=>{if(e.selectedAnnotationIds.length===0&&!e.inspectedElement){kn(null);return}if(e.selectedAnnotationIds.length>0){let A=e.selectedAnnotationIds[0],F=Je.findIndex(oe=>oe.id===A||oe.annotations.some(re=>re.id===A));F>=0&&F!==Ct&&kn(F)}},[e.selectedAnnotationIds,e.inspectedElement,Je]);let An=Yn(()=>{if(yn===0)return;let A;if(Ct===null?A=0:Ct+1>=yn?A=null:A=Ct+1,kn(A),A===null){t({type:"SELECT_ANNOTATION",payload:{id:null}}),t({type:"SELECT_ELEMENT",payload:null});return}if(A<Je.length){let F=Je[A];if(!(!F.pathname||F.pathname===an)){sessionStorage.setItem("popmelt-pending-focus",JSON.stringify({annotationId:F.id,pathname:F.pathname})),window.location.href=F.pathname;return}t({type:"SELECT_ELEMENT",payload:null}),t({type:"SELECT_ANNOTATION",payload:{id:F.id}});let re=F.annotations.find(ot=>ot.type!=="text")||F.annotations[0];if(F.annotations.some(ot=>ot.linkedSelector))t({type:"SET_TOOL",payload:"inspector"});else if(re?.type&&re.type!=="text"&&re.type!=="inspector"){t({type:"SET_TOOL",payload:re.type});let ot=xr.findIndex(wn=>wn.type===re.type);ot>=0&&rt(ot)}if(re?.color){t({type:"SET_COLOR",payload:re.color});let ot=qt(re.color);ot!==null&&mt(ot)}let we=F.annotations.flatMap(ot=>ot.points);if(we.length===0)return;let Be=Math.min(...we.map(ot=>ot.x)),ve=Math.max(...we.map(ot=>ot.x)),ut=Math.min(...we.map(ot=>ot.y)),Et=Math.max(...we.map(ot=>ot.y)),Vt=(Be+ve)/2,pn=(ut+Et)/2;if(window.scrollTo({left:Vt-window.innerWidth/2,top:pn-window.innerHeight/2,behavior:"smooth"}),I&&b){let ot=F.annotations.find(wn=>wn.threadId)?.threadId;ot&&b(ot)}}else{let F=A-Je.length,oe=e.styleModifications[F];if(!oe)return;let re=En(oe.selector);if(!re)return;t({type:"SELECT_ANNOTATION",payload:{id:null}}),t({type:"SET_TOOL",payload:"inspector"}),t({type:"SELECT_ELEMENT",payload:{el:re,info:oe.element}});let ne=re.getBoundingClientRect(),we=ne.left+ne.width/2+window.scrollX,Be=ne.top+ne.height/2+window.scrollY;window.scrollTo({left:we-window.innerWidth/2,top:Be-window.innerHeight/2,behavior:"smooth"})}},[Je,an,e.styleModifications,yn,Ct,t,qt,I,b]);hn(()=>{if(!se)return;let A=F=>{let oe=document.activeElement;for(;oe?.shadowRoot?.activeElement;)oe=oe.shadowRoot.activeElement;if(oe?.tagName==="INPUT"||oe?.tagName==="TEXTAREA"||oe?.isContentEditable)return;if((F.metaKey||F.ctrlKey)&&F.key==="Enter"){o&&(e.annotations.length>0||e.styleModifications.length>0||e.spacingTokenChanges.filter(we=>!we.captured).length>0)&&(F.preventDefault(),U());return}if((F.metaKey||F.ctrlKey)&&(F.key==="c"||F.key==="C"||F.code==="KeyC")){let we=window.getSelection();if(we&&we.toString().length>0)return;(e.annotations.length>0||e.styleModifications.length>0)&&(F.preventDefault(),window.focus(),Xt());return}if((F.metaKey||F.ctrlKey)&&(F.key==="Backspace"||F.key==="Delete")){F.preventDefault(),Ue();return}if(F.metaKey||F.ctrlKey||F.altKey)return;let re={p:"freehand",l:"line",r:"rectangle",o:"circle",t:"text",c:"inspector",h:"hand",e:"eval"};if(F.key.toLowerCase()==="m"){F.preventDefault(),at("model");return}let ne=re[F.key.toLowerCase()];if(ne){F.preventDefault();let we=xr.findIndex(Be=>Be.type===ne);we>=0&&rt(we),at(ne)}};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[se,at,Xt,U,o,Ue,e.annotations.length,e.styleModifications.length,e.spacingTokenChanges,Ge]);let qo=ol(ce,ft.w,ft.h),oo={...zg,...qo,borderRadius:0,padding:se?"0 8px":"0",width:se?"auto":48,height:48,gap:0,justifyContent:se?"flex-start":"center"},ro=ue("div",{style:Wi({color:r&&i?i:"rgb(0,0,0)",animated:!!r})}),Kn=C===!1?"rgba(239, 68, 68, 0.4)":r&&i?i:Zn.iconActive,Zt=!!(k&&E&&k!==E),io=$==="restarting"||!V&&!N,Zo=$==="error"?"#dc2626":$==="ok"?Zn.iconDefault:Zt?"#b45309":Zn.iconDefault,Fo=$==="restarting"?"Restarting":$==="error"?"Restart failed":$==="ok"?"Restarted":Zt?"Update bridge":null,zo=Q??(Zt?`Bridge ${E} is older than package ${k}. Restart bridge.`:E?`Bridge ${E}. Restart bridge.`:"Restart bridge"),Qo=Ot(null);hn(()=>{if(!se)return;let A=Qo.current;if(!A)return;let F=()=>{s?.(!0),st("collapse")},oe=()=>{s?.(!1),Yt()};return A.addEventListener("mouseenter",F),A.addEventListener("mouseleave",oe),()=>{A.removeEventListener("mouseenter",F),A.removeEventListener("mouseleave",oe)}},[se,r,s,st,Yt]);let $o=Ot(null);return hn(()=>{if(se)return;let A=$o.current;if(!A)return;let F=A.querySelector("[data-popmelt-logo]"),oe=()=>{A.style.opacity="1",!r&&F&&(F.style.fill="#000"),lt?.()},re=()=>{A.style.opacity=r?"1":"0.5",!r&&F&&(F.style.fill="none")};return A.addEventListener("mouseenter",oe),A.addEventListener("mouseleave",re),()=>{A.removeEventListener("mouseenter",oe),A.removeEventListener("mouseleave",re)}},[se,r,lt]),se?Pt(di,{children:[ue("style",{children:`
16
16
  @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
17
17
  @keyframes popmelt-border-march { to { background-position: 0 -5px; } }
18
- `}),pe("div",{id:"devtools-scrim",style:{position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.06)",zIndex:9997,pointerEvents:"none"}}),!I&&(te==="eval"||e.activeTool==="eval")&&pe(Ql,{bridgeUrl:P,refreshKey:be,snapPosition:Qe,onSynthesize:fe,isSynthesizing:Ae,onRunEval:De,onViewRunThread:ze,runningEvalIds:de,onMouseEnter:()=>{ft(),Re.current&&(clearTimeout(Re.current),Re.current=null)},onMouseLeave:e.activeTool==="eval"?void 0:tt}),!I&&(te==="model"||e.activeTool==="model")&&pe(mc,{bridgeUrl:P,selectedComponent:S,hoveredComponent:A,onComponentHover:y,onSpacingTokenHover:T,onModifySpacingToken:L,onDeleteSpacingToken:ce,modelRefreshKey:We,onComponentAdded:j,onComponentRemoved:se,onSynthesizeRules:_,isSynthesizing:he,snapPosition:Qe,onMouseEnter:()=>{ft(),Re.current&&(clearTimeout(Re.current),Re.current=null)},onMouseLeave:e.activeTool==="model"?void 0:tt}),te&&te!=="model"&&te!=="eval"&&(te==="provider"||bc[te])&&(()=>{let H=te==="provider"?on:bc[te];return Tt("div",{ref:_t,style:{...Ha(Qe,je.w,je.h),width:300,backgroundColor:"#eaeaea",...Po,boxSizing:"content-box",zIndex:10001,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12,color:"#1f2937",padding:12,...te!=="collapse"&&te!=="counter"?{pointerEvents:"none"}:{}},children:[te==="collapse"&&pe("div",{style:{marginBottom:10,width:"fit-content",color:Wn.iconDefault},children:pe("svg",{width:"48",height:"48",viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:pe("path",{d:"M11.1406 31.2559C11.2407 31.3875 11.351 31.5132 11.4697 31.6338L3.10449 40H2.39746L11.1406 31.2559ZM8.05371 40H7.34668L14.5498 32.7959C14.8554 32.7706 15.1541 32.7063 15.4414 32.6113L8.05371 40ZM18.2197 34.0762C18.3788 34.1569 18.5445 34.2272 18.7168 34.2861L13.0039 40H12.2969L18.2197 34.0762ZM17.9531 40H17.2461L26.1338 31.1113C26.438 31.0829 26.7427 31.0148 27.0439 30.9082L17.9531 40ZM40 22.9023L22.9033 40H22.1963L40 22.1953V22.9023ZM40 27.8525L27.8525 40H27.1455L40 27.1455V27.8525ZM40 32.8027L32.8027 40H32.0957L40 32.0957V32.8027ZM40 37.752L37.752 40H37.0449L40 37.0449V37.752ZM9.06543 28.3809C9.25255 28.4332 9.45183 28.4715 9.66504 28.4883L0 38.1543V37.4473L9.06543 28.3809ZM6.59375 25.9023C6.65822 26.0626 6.73171 26.2263 6.81445 26.3896L0 33.2041V32.4971L6.59375 25.9023ZM20.25 8.00293H20.249C21.5098 8.0286 22.7219 8.25094 23.8584 8.63672L23.8604 8.63574C23.8961 8.64787 23.9312 8.66145 23.9668 8.67383C24.0611 8.70686 24.1548 8.74106 24.248 8.77637C24.2915 8.79273 24.3357 8.80727 24.3789 8.82422L24.376 8.82617C27.6145 10.0955 30.1646 12.7301 31.3213 16.0234L31.3232 16.0225C31.3327 16.0493 31.3404 16.0766 31.3496 16.1035C31.7691 17.3256 32 18.6356 32 20C32 20.8726 31.9366 21.6706 31.7598 22.4902L31.7197 22.6328C31.6412 23.0066 31.5136 23.6108 31.3408 24.2217L31.3398 24.2246C31.2967 24.377 31.251 24.5299 31.2021 24.6797C30.9215 25.5403 30.5473 26.2998 30.0879 26.2998C29.7613 26.2996 29.5995 25.9674 29.4316 25.6221C29.2501 25.2487 29.0614 24.8605 28.6484 24.8604C27.8532 24.8604 27.2081 25.5046 27.208 26.2998V27.0771C27.2079 27.6079 26.9661 28.112 26.5205 28.4004C25.9146 28.7925 25.2357 28.6462 24.7959 28.2061L24.7949 28.208C24.7897 28.2028 24.7854 28.1967 24.7803 28.1914C24.7654 28.1761 24.7507 28.1606 24.7363 28.1445C24.7105 28.1156 24.6858 28.0857 24.6621 28.0547C24.6461 28.0339 24.6302 28.013 24.6152 27.9912C24.5931 27.9591 24.5726 27.9257 24.5527 27.8916C24.5392 27.8685 24.5261 27.8452 24.5137 27.8213C24.5093 27.8128 24.5043 27.8045 24.5 27.7959L24.501 27.7939C24.3932 27.5763 24.3282 27.3276 24.3281 27.0576V26.2998C24.328 25.5993 23.8278 25.0158 23.165 24.8867V24.8877C23.0752 24.8702 22.9826 24.8604 22.8877 24.8604C22.8446 24.8604 22.8019 24.8624 22.7598 24.8662C22.0247 24.9312 21.4483 25.5479 21.4482 26.2998C21.4482 26.9127 21.4608 27.5305 21.4736 28.1494L21.4951 29.3135C21.5 29.7013 21.5015 30.089 21.4971 30.4756C21.4874 31.3103 20.8426 32 20.0078 32C19.1732 31.9998 18.5292 31.3102 18.5195 30.4756C18.5159 30.1613 18.5176 29.8464 18.5205 29.5312V29.5322C18.5212 29.4593 18.5206 29.3864 18.5215 29.3135L18.5303 28.8154V28.8145C18.5343 28.5927 18.5384 28.371 18.543 28.1494C18.5558 27.5305 18.5684 28.1129 18.5684 27.5C18.5684 26.7047 17.9232 26.0596 17.1279 26.0596C16.907 26.0596 16.6978 26.1103 16.5107 26.1992C16.2161 26.3393 15.9767 26.5769 15.834 26.8701C15.8269 26.8846 15.8201 26.8993 15.8135 26.9141C15.7821 26.9845 15.7562 27.0579 15.7363 27.1338C15.7243 27.1798 15.7155 27.2267 15.708 27.2744C15.7012 27.3175 15.6953 27.361 15.6924 27.4053C15.6903 27.4366 15.6885 27.4681 15.6885 27.5V28.7383C15.6883 29.9234 14.4911 30.7248 13.4961 30.0811C13.0505 29.7926 12.8086 29.2886 12.8086 28.7578V26.2998C12.8086 25.9737 12.6984 25.674 12.5156 25.4326C12.4437 25.3381 12.3612 25.2521 12.2686 25.1777V25.1768C12.0219 24.9788 11.709 24.8604 11.3682 24.8604C10.9892 24.8604 10.8622 24.8872 10.7295 25.2295C10.5837 25.6055 10.4302 26 9.92773 26C9.33081 25.9996 8.95963 25.2403 8.71484 24.3799C8.5591 23.8325 8.45907 23.571 8.3623 23.0107C8.3501 22.9401 8.33284 22.8403 8.31738 22.7529C8.12812 21.9466 8.02043 21.1089 8.00293 20.249V20.25L8 20C8 19.8617 8.00317 19.724 8.00781 19.5869C8.00837 19.5703 8.00816 19.5537 8.00879 19.5371L8.00977 19.5352C8.0998 17.1716 8.87444 14.9844 10.1396 13.1631C10.1488 13.1499 10.1587 13.1372 10.168 13.124C12.255 10.1453 15.6582 8.15745 19.5352 8.00977L19.5371 8.00879C19.5537 8.00816 19.5703 8.00837 19.5869 8.00781C19.724 8.00317 19.8617 8 20 8L20.25 8.00293ZM5.72266 22.5303L0 28.2539V27.5469L5.62793 21.918C5.6553 22.1234 5.6868 22.3275 5.72266 22.5303ZM16.2637 26.8398L16.2617 26.8408C16.2784 26.8013 16.2954 26.7627 16.3135 26.7256C16.3203 26.7116 16.3275 26.6982 16.334 26.6855C16.3125 26.7277 16.289 26.7808 16.2637 26.8398ZM40 17.9531L33.9854 23.9668C34.051 23.6832 34.1043 23.4321 34.1445 23.2412L34.1641 23.1748L34.1865 23.0967L34.1963 23.0488L40 17.2461V17.9531ZM5.87012 16.7266C5.80321 17.0165 5.74649 17.3101 5.69727 17.6064L0 23.3047V22.5977L5.87012 16.7266ZM40 13.0039L34.4297 18.5732C34.409 18.3615 34.3832 18.1513 34.3535 17.9424L40 12.2969V13.0039ZM0 18.3555V17.6484L17.6484 0H18.3555L0 18.3555ZM40 8.05371L33.458 14.5947C33.3909 14.4277 33.3202 14.2625 33.2471 14.0986L40 7.34668V8.05371ZM0 13.4053V12.6982L12.6992 0H13.4062L0 13.4053ZM40 3.10352L31.6865 11.416C31.5868 11.2805 31.4851 11.1465 31.3809 11.0146L40 2.39648V3.10352ZM29.2881 8.86523C29.1595 8.75783 29.0288 8.65278 28.8965 8.5498L37.4473 0H38.1543L29.2881 8.86523ZM0 8.45508V7.74805L7.74805 0H8.45508L0 8.45508ZM26.2783 6.92578C26.1183 6.84878 25.9562 6.77534 25.793 6.7041L32.498 0H33.2051L26.2783 6.92578ZM17.6064 5.69727C17.3101 5.74649 17.0165 5.80321 16.7266 5.87012L22.5977 0H23.3047L17.6064 5.69727ZM22.5322 5.7207C22.3295 5.685 22.1254 5.65316 21.9199 5.62598L27.5469 0H28.2539L22.5322 5.7207ZM0 3.50586V2.79883L2.79883 0H3.50586L0 3.50586Z",fill:"currentColor"})})}),Tt("div",{style:{display:"flex",alignItems:"center",gap:6,fontWeight:700,fontSize:13,marginBottom:6},children:[pe("span",{children:H.name}),H.keys[0]&&pe("code",{style:{fontSize:10,fontWeight:500,backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",color:"#6b7280"},children:H.keys[0].key})]}),pe("div",{style:{color:"#6b7280",lineHeight:1.5,marginBottom:te==="collapse"?0:10},children:H.desc.split(`
18
+ `}),ue("div",{id:"devtools-scrim",style:{position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.06)",zIndex:9997,pointerEvents:"none"}}),!I&&(Ge==="eval"||e.activeTool==="eval")&&ue(xc,{bridgeUrl:N,refreshKey:le,snapPosition:ce,onSynthesize:Z,isSynthesizing:pe,onRunEval:Le,onViewRunThread:_e,runningEvalIds:ge,onMouseEnter:()=>{Lt(),He.current&&(clearTimeout(He.current),He.current=null)},onMouseLeave:e.activeTool==="eval"?void 0:Yt}),!I&&(Ge==="model"||e.activeTool==="model")&&ue(_c,{bridgeUrl:N,selectedComponent:M,hoveredComponent:B,onComponentHover:f,onSpacingTokenHover:g,onModifySpacingToken:j,onDeleteSpacingToken:fe,modelRefreshKey:Re,onComponentAdded:Ce,onComponentRemoved:Ee,onSynthesizeRules:K,isSynthesizing:O,snapPosition:ce,onMouseEnter:()=>{Lt(),He.current&&(clearTimeout(He.current),He.current=null)},onMouseLeave:e.activeTool==="model"?void 0:Yt}),Ge&&Ge!=="model"&&Ge!=="eval"&&(Ge==="provider"||Fc[Ge])&&(()=>{let A=Ge==="provider"?sn:Fc[Ge];return Pt("div",{ref:$t,style:{...rl(ce,ft.w,ft.h),width:300,backgroundColor:"#eaeaea",...Nr,boxSizing:"content-box",zIndex:10001,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12,color:"#1f2937",padding:12,...Ge!=="collapse"&&Ge!=="counter"?{pointerEvents:"none"}:{}},children:[Ge==="collapse"&&ue("div",{style:{marginBottom:10,width:"fit-content",color:Zn.iconDefault},children:ue("svg",{width:"48",height:"48",viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:ue("path",{d:"M11.1406 31.2559C11.2407 31.3875 11.351 31.5132 11.4697 31.6338L3.10449 40H2.39746L11.1406 31.2559ZM8.05371 40H7.34668L14.5498 32.7959C14.8554 32.7706 15.1541 32.7063 15.4414 32.6113L8.05371 40ZM18.2197 34.0762C18.3788 34.1569 18.5445 34.2272 18.7168 34.2861L13.0039 40H12.2969L18.2197 34.0762ZM17.9531 40H17.2461L26.1338 31.1113C26.438 31.0829 26.7427 31.0148 27.0439 30.9082L17.9531 40ZM40 22.9023L22.9033 40H22.1963L40 22.1953V22.9023ZM40 27.8525L27.8525 40H27.1455L40 27.1455V27.8525ZM40 32.8027L32.8027 40H32.0957L40 32.0957V32.8027ZM40 37.752L37.752 40H37.0449L40 37.0449V37.752ZM9.06543 28.3809C9.25255 28.4332 9.45183 28.4715 9.66504 28.4883L0 38.1543V37.4473L9.06543 28.3809ZM6.59375 25.9023C6.65822 26.0626 6.73171 26.2263 6.81445 26.3896L0 33.2041V32.4971L6.59375 25.9023ZM20.25 8.00293H20.249C21.5098 8.0286 22.7219 8.25094 23.8584 8.63672L23.8604 8.63574C23.8961 8.64787 23.9312 8.66145 23.9668 8.67383C24.0611 8.70686 24.1548 8.74106 24.248 8.77637C24.2915 8.79273 24.3357 8.80727 24.3789 8.82422L24.376 8.82617C27.6145 10.0955 30.1646 12.7301 31.3213 16.0234L31.3232 16.0225C31.3327 16.0493 31.3404 16.0766 31.3496 16.1035C31.7691 17.3256 32 18.6356 32 20C32 20.8726 31.9366 21.6706 31.7598 22.4902L31.7197 22.6328C31.6412 23.0066 31.5136 23.6108 31.3408 24.2217L31.3398 24.2246C31.2967 24.377 31.251 24.5299 31.2021 24.6797C30.9215 25.5403 30.5473 26.2998 30.0879 26.2998C29.7613 26.2996 29.5995 25.9674 29.4316 25.6221C29.2501 25.2487 29.0614 24.8605 28.6484 24.8604C27.8532 24.8604 27.2081 25.5046 27.208 26.2998V27.0771C27.2079 27.6079 26.9661 28.112 26.5205 28.4004C25.9146 28.7925 25.2357 28.6462 24.7959 28.2061L24.7949 28.208C24.7897 28.2028 24.7854 28.1967 24.7803 28.1914C24.7654 28.1761 24.7507 28.1606 24.7363 28.1445C24.7105 28.1156 24.6858 28.0857 24.6621 28.0547C24.6461 28.0339 24.6302 28.013 24.6152 27.9912C24.5931 27.9591 24.5726 27.9257 24.5527 27.8916C24.5392 27.8685 24.5261 27.8452 24.5137 27.8213C24.5093 27.8128 24.5043 27.8045 24.5 27.7959L24.501 27.7939C24.3932 27.5763 24.3282 27.3276 24.3281 27.0576V26.2998C24.328 25.5993 23.8278 25.0158 23.165 24.8867V24.8877C23.0752 24.8702 22.9826 24.8604 22.8877 24.8604C22.8446 24.8604 22.8019 24.8624 22.7598 24.8662C22.0247 24.9312 21.4483 25.5479 21.4482 26.2998C21.4482 26.9127 21.4608 27.5305 21.4736 28.1494L21.4951 29.3135C21.5 29.7013 21.5015 30.089 21.4971 30.4756C21.4874 31.3103 20.8426 32 20.0078 32C19.1732 31.9998 18.5292 31.3102 18.5195 30.4756C18.5159 30.1613 18.5176 29.8464 18.5205 29.5312V29.5322C18.5212 29.4593 18.5206 29.3864 18.5215 29.3135L18.5303 28.8154V28.8145C18.5343 28.5927 18.5384 28.371 18.543 28.1494C18.5558 27.5305 18.5684 28.1129 18.5684 27.5C18.5684 26.7047 17.9232 26.0596 17.1279 26.0596C16.907 26.0596 16.6978 26.1103 16.5107 26.1992C16.2161 26.3393 15.9767 26.5769 15.834 26.8701C15.8269 26.8846 15.8201 26.8993 15.8135 26.9141C15.7821 26.9845 15.7562 27.0579 15.7363 27.1338C15.7243 27.1798 15.7155 27.2267 15.708 27.2744C15.7012 27.3175 15.6953 27.361 15.6924 27.4053C15.6903 27.4366 15.6885 27.4681 15.6885 27.5V28.7383C15.6883 29.9234 14.4911 30.7248 13.4961 30.0811C13.0505 29.7926 12.8086 29.2886 12.8086 28.7578V26.2998C12.8086 25.9737 12.6984 25.674 12.5156 25.4326C12.4437 25.3381 12.3612 25.2521 12.2686 25.1777V25.1768C12.0219 24.9788 11.709 24.8604 11.3682 24.8604C10.9892 24.8604 10.8622 24.8872 10.7295 25.2295C10.5837 25.6055 10.4302 26 9.92773 26C9.33081 25.9996 8.95963 25.2403 8.71484 24.3799C8.5591 23.8325 8.45907 23.571 8.3623 23.0107C8.3501 22.9401 8.33284 22.8403 8.31738 22.7529C8.12812 21.9466 8.02043 21.1089 8.00293 20.249V20.25L8 20C8 19.8617 8.00317 19.724 8.00781 19.5869C8.00837 19.5703 8.00816 19.5537 8.00879 19.5371L8.00977 19.5352C8.0998 17.1716 8.87444 14.9844 10.1396 13.1631C10.1488 13.1499 10.1587 13.1372 10.168 13.124C12.255 10.1453 15.6582 8.15745 19.5352 8.00977L19.5371 8.00879C19.5537 8.00816 19.5703 8.00837 19.5869 8.00781C19.724 8.00317 19.8617 8 20 8L20.25 8.00293ZM5.72266 22.5303L0 28.2539V27.5469L5.62793 21.918C5.6553 22.1234 5.6868 22.3275 5.72266 22.5303ZM16.2637 26.8398L16.2617 26.8408C16.2784 26.8013 16.2954 26.7627 16.3135 26.7256C16.3203 26.7116 16.3275 26.6982 16.334 26.6855C16.3125 26.7277 16.289 26.7808 16.2637 26.8398ZM40 17.9531L33.9854 23.9668C34.051 23.6832 34.1043 23.4321 34.1445 23.2412L34.1641 23.1748L34.1865 23.0967L34.1963 23.0488L40 17.2461V17.9531ZM5.87012 16.7266C5.80321 17.0165 5.74649 17.3101 5.69727 17.6064L0 23.3047V22.5977L5.87012 16.7266ZM40 13.0039L34.4297 18.5732C34.409 18.3615 34.3832 18.1513 34.3535 17.9424L40 12.2969V13.0039ZM0 18.3555V17.6484L17.6484 0H18.3555L0 18.3555ZM40 8.05371L33.458 14.5947C33.3909 14.4277 33.3202 14.2625 33.2471 14.0986L40 7.34668V8.05371ZM0 13.4053V12.6982L12.6992 0H13.4062L0 13.4053ZM40 3.10352L31.6865 11.416C31.5868 11.2805 31.4851 11.1465 31.3809 11.0146L40 2.39648V3.10352ZM29.2881 8.86523C29.1595 8.75783 29.0288 8.65278 28.8965 8.5498L37.4473 0H38.1543L29.2881 8.86523ZM0 8.45508V7.74805L7.74805 0H8.45508L0 8.45508ZM26.2783 6.92578C26.1183 6.84878 25.9562 6.77534 25.793 6.7041L32.498 0H33.2051L26.2783 6.92578ZM17.6064 5.69727C17.3101 5.74649 17.0165 5.80321 16.7266 5.87012L22.5977 0H23.3047L17.6064 5.69727ZM22.5322 5.7207C22.3295 5.685 22.1254 5.65316 21.9199 5.62598L27.5469 0H28.2539L22.5322 5.7207ZM0 3.50586V2.79883L2.79883 0H3.50586L0 3.50586Z",fill:"currentColor"})})}),Pt("div",{style:{display:"flex",alignItems:"center",gap:6,fontWeight:700,fontSize:13,marginBottom:6},children:[ue("span",{children:A.name}),A.keys[0]&&ue("code",{style:{fontSize:10,fontWeight:500,backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",color:"#6b7280"},children:A.keys[0].key})]}),ue("div",{style:{color:"#6b7280",lineHeight:1.5,marginBottom:Ge==="collapse"?0:10},children:A.desc.split(`
19
19
 
20
- `).map((z,Q)=>pe("p",{style:{margin:0,marginTop:Q>0?8:0},children:z},Q))}),H.usage.map((z,Q)=>Tt("div",{style:{display:"flex",gap:6,marginBottom:3,lineHeight:1.4},children:[pe("span",{style:{color:"#9ca3af",flexShrink:0},children:"\u2013"}),pe("span",{children:z})]},Q)),te==="collapse"&&pt&&Tt("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:10,paddingTop:8},children:[pe("div",{style:{fontSize:10,color:"#9ca3af",marginBottom:6,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Position"}),pe("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:3,width:"fit-content"},children:Fa.map(z=>{let Q=z===Qe;return pe("button",{type:"button",onClick:()=>{ge(null),Pe.current=!1,ft(),pt(z)},title:z,style:{width:24,height:16,border:"none",cursor:"pointer",padding:0,backgroundColor:Q?"#1f2937":"rgba(0,0,0,0.08)",transition:"background-color 100ms ease"},onMouseEnter:oe=>{Q||(oe.currentTarget.style.backgroundColor="rgba(0,0,0,0.15)")},onMouseLeave:oe=>{Q||(oe.currentTarget.style.backgroundColor="rgba(0,0,0,0.08)")}},z)})})]}),te==="collapse"&&(()=>{let z=Object.entries(O??{}),Q=z.filter(([,we])=>we.found&&!we.disabled).map(([we])=>we.charAt(0).toUpperCase()+we.slice(1)),oe=z.filter(([,we])=>!we.found).map(([we])=>we);if(!P&&!C&&Q.length===0&&oe.length===0)return null;let ue=oe.map(we=>we.charAt(0).toUpperCase()+we.slice(1)),xe=[...Q,...ue];return Tt("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:10,paddingTop:8,display:"flex",alignItems:"center",gap:6,fontSize:11},children:[(C||P)&&pe("button",{type:"button",onClick:()=>{Nn||(C?C():Sa(P))},disabled:Nn,title:Ho,"aria-label":Mo??"Restart bridge",style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,border:"none",borderRadius:0,backgroundColor:Vn||J!=="idle"?"rgba(0,0,0,0.07)":"rgba(0,0,0,0.04)",color:ar,cursor:Nn?"default":"pointer",padding:0,opacity:Nn?.55:1,flexShrink:0},children:J==="ok"?pe(Jf,{size:14,strokeWidth:1.8}):pe(Zf,{size:13,strokeWidth:1.7,style:{animation:J==="restarting"?"spin 0.8s linear infinite":void 0}})}),Q.length>0?Tt("span",{style:{color:"#6b7280"},children:["Available in ",xe.join(", ")]}):oe.length>0?Tt("span",{style:{color:"#6b7280"},children:["Available in ",ue.join(", ")]}):null]})})(),H.keys.length>1&&pe("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:8,paddingTop:8,display:"flex",flexDirection:"column",gap:4},children:H.keys.slice(1).map((z,Q)=>Tt("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:z.accent?"#fff":"#6b7280"},children:[pe("code",{style:{fontSize:10,backgroundColor:z.accent?e.activeColor:"rgba(0,0,0,0.06)",color:z.accent?"#fff":void 0,padding:"1px 4px",whiteSpace:"nowrap"},children:z.key}),pe("span",{style:{color:z.accent?e.activeColor:void 0,fontWeight:z.accent?600:void 0},children:z.desc})]},Q))}),te==="counter"&&Ft.length>0&&(()=>{let z=pe("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:8,paddingTop:8},children:pe("div",{style:{fontSize:10,color:"#9ca3af",marginBottom:4,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Active"})}),Q=new Map;for(let xe of Ft){let we=xe.pathname||Sn;Q.has(we)||Q.set(we,[]),Q.get(we).push(xe)}let oe=[...Q.entries()],ue=oe.length>1;return Tt("div",{children:[z,pe("div",{style:{maxHeight:200,overflowY:"auto",scrollbarWidth:"thin"},children:oe.map(([xe,we])=>pe("div",{style:{marginBottom:ue?4:0},children:we.map(ae=>{let It=ae.annotations.find(Rn=>Rn.type==="text"&&Rn.text)?.text||`[${ae.annotations[0]?.type??"annotation"}]`,ln=e.selectedAnnotationIds.includes(ae.id),cn=Ft.indexOf(ae),Ke=cn+1,Dt=ae.annotations[0]?.color??e.activeColor;return Tt("div",{onClick:()=>{if(!(!ae.pathname||ae.pathname===Sn)){sessionStorage.setItem("popmelt-pending-focus",JSON.stringify({annotationId:ae.id,pathname:ae.pathname})),window.location.href=ae.pathname;return}if(Gt(cn),t({type:"SELECT_ELEMENT",payload:null}),t({type:"SELECT_ANNOTATION",payload:{id:ae.id}}),h){let mn=ae.annotations.find(Qt=>Qt.threadId)?.threadId;mn&&h(mn)}Pe.current=!1,ge(null)},style:{display:"flex",alignItems:"baseline",gap:4,padding:"2px 0",cursor:"pointer"},onMouseEnter:Rn=>{let mn=Rn.currentTarget.querySelector("[data-route-badge]");mn&&(mn.style.backgroundColor=Dt,mn.style.color="#fff")},onMouseLeave:Rn=>{if(ln)return;let mn=Rn.currentTarget.querySelector("[data-route-badge]");mn&&(mn.style.backgroundColor="rgba(0,0,0,0.06)",mn.style.color="#6b7280")},children:[Tt("code",{"data-route-badge":!0,style:{fontSize:10,color:ln?"#fff":"#6b7280",backgroundColor:ln?Dt:"rgba(0,0,0,0.06)",padding:"1px 4px",flexShrink:0,whiteSpace:"nowrap"},children:[Ke,". ",ue?xe:""]}),pe("span",{style:{fontSize:11,color:ln?"#1f2937":"#6b7280",fontWeight:ln?600:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:It})]},ae.id)})},xe))})]})})(),te==="counter"&&(()=>{let z=new Set(Ft.flatMap(ue=>ue.annotations.map(xe=>xe.threadId).filter(Boolean))),Q=Nt.filter(ue=>!z.has(ue.id));if(Q.length===0)return null;let oe=ue=>{let xe=Math.floor((Date.now()-ue)/1e3);if(xe<60)return"now";let we=Math.floor(xe/60);if(we<60)return`${we}m`;let ae=Math.floor(we/60);return ae<24?`${ae}h`:`${Math.floor(ae/24)}d`};return Tt("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:8,paddingTop:8},children:[pe("div",{style:{fontSize:10,color:"#9ca3af",marginBottom:4,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Recent"}),Q.map(ue=>Tt("div",{onClick:()=>{let xe=ue.elementIdentifiers[0];if(xe){let we=xe.indexOf(":"),ae=we>0&&xe[0]==="/",at=ae?xe.slice(0,we):void 0,It=ae?xe.slice(we+1):xe;if(!(!at||at===Sn)){sessionStorage.setItem("popmelt-pending-thread",JSON.stringify({threadId:ue.id,selector:It,preview:ue.preview})),window.location.href=at;return}try{let cn=document.querySelector(It);if(cn){let Ke=cn.getBoundingClientRect(),Dt=Math.random().toString(36).slice(2,9);t({type:"ADD_TEXT",payload:{id:Dt,point:{x:Ke.left+Ke.width,y:Ke.top},text:ue.preview,linkedSelector:It,linkedAnchor:"top-left"}}),t({type:"SET_ANNOTATION_THREAD",payload:{ids:[Dt],threadId:ue.id}}),t({type:"SET_ANNOTATION_STATUS",payload:{ids:[Dt],status:"resolved"}})}}catch{}}h&&h(ue.id),Pe.current=!1,ge(null)},style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,padding:"2px 0",cursor:"pointer",color:"#6b7280",fontSize:11},onMouseEnter:xe=>{xe.currentTarget.style.color="#1f2937"},onMouseLeave:xe=>{xe.currentTarget.style.color="#6b7280"},children:[pe("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:ue.preview}),pe("span",{style:{flexShrink:0,fontSize:10,color:"#9ca3af"},children:oe(ue.createdAt)})]},ue.id))]})})()]})})(),Tt("div",{ref:H=>{Ge&&(Ge.current=H)},id:"devtools-toolbar",style:To,onMouseEnter:Ee,onMouseMove:Gn,children:[Zt,Tt("div",{style:{display:"flex",flexDirection:"row",gap:4,alignItems:"center"},children:[pe("span",{onMouseEnter:()=>Jt("inspector"),onMouseLeave:tt,children:pe(Eo,{active:e.isAnnotating&&e.activeTool==="inspector",siblingActive:e.isAnnotating,onClick:()=>st("inspector"),children:pe(Xf,{size:20,strokeWidth:1.5})})}),pe("span",{onMouseEnter:()=>Jt("hand"),onMouseLeave:tt,children:pe(Eo,{active:e.isAnnotating&&e.activeTool==="hand",siblingActive:e.isAnnotating,onClick:()=>st("hand"),children:Tt("div",{style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:[pe(Kf,{size:20,strokeWidth:1.5}),e.styleModifications.filter(H=>!H.captured).length>0&&pe("div",{style:{position:"absolute",top:-7,right:-9,minWidth:14,height:14,borderRadius:0,backgroundColor:e.activeColor,color:"#fff",fontSize:9,fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 2px",lineHeight:1},children:e.styleModifications.filter(H=>!H.captured).length})]})})}),(()=>{let H=or[Je],z=H.icon,Q=e.isAnnotating&&rg.has(e.activeTool);return pe("span",{onMouseEnter:()=>Jt(H.type),onMouseLeave:tt,children:Tt("div",{style:{display:"flex",alignItems:"center",gap:0},children:[pe(Eo,{active:Q,siblingActive:e.isAnnotating,onClick:()=>st(H.type),children:pe(z,{size:20,strokeWidth:1.5})}),pe("button",{type:"button",onClick:()=>{let oe=(Je+1)%or.length;lt(oe),st(or[oe].type)},title:"Cycle shape tool",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,width:12,height:32,border:"none",background:"none",cursor:"pointer",padding:"0 2px",opacity:e.isAnnotating&&!Q?.5:1,transition:"opacity 150ms ease"},children:or.map((oe,ue)=>pe("div",{style:{width:3,height:3,borderRadius:"50%",backgroundColor:ue===Je?Wn.iconDefault:"rgba(0,0,0,0.2)",transition:"background-color 150ms ease"}},ue))})]})})})(),ag.map(({type:H,icon:z,label:Q,shortcut:oe})=>pe("span",{onMouseEnter:()=>Jt(H),onMouseLeave:tt,children:pe(Eo,{active:e.isAnnotating&&e.activeTool===H,siblingActive:e.isAnnotating,onClick:()=>st(H),children:pe(z,{size:20,strokeWidth:1.5})})},H)),pe("span",{onMouseEnter:()=>Jt("eval"),onMouseLeave:tt,children:pe(Eo,{active:e.isAnnotating&&e.activeTool==="eval",siblingActive:e.isAnnotating,onClick:()=>st("eval"),children:pe(Uf,{size:18,strokeWidth:1.5})})}),pe("span",{onMouseEnter:()=>Jt("model"),onMouseLeave:tt,children:pe(Eo,{active:e.isAnnotating&&e.activeTool==="model",siblingActive:e.isAnnotating,onClick:()=>st("model"),children:pe(Vf,{size:17,strokeWidth:1.5})})})]}),pe(hc,{}),Tt("div",{style:{display:"flex",flexDirection:"row",gap:4,alignItems:"center"},children:[(Ft.length>0||e.styleModifications.length>0||e.spacingTokenChanges.filter(H=>!H.captured).length>0)&&(()=>{let H=jt!==null&&jt<Ft.length?Ft[jt]:null,z=e.annotations.length>0&&e.annotations.every(ue=>ue.status&&ue.status!=="pending"),Q=jt!==null?H?.annotations.some(ue=>ue.status&&ue.status!=="pending")??!1:z,oe=`oklch(0.628 0.258 ${Pt})`;return pe("span",{onMouseEnter:()=>Jt("counter"),onMouseLeave:tt,children:pe("button",{ref:St,type:"button",onClick:()=>{if(fo.current){fo.current=!1;return}io()},onMouseDown:ir,onMouseUp:Jn,onMouseLeave:Jn,title:"",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,minWidth:20,height:20,padding:"0 8px",marginRight:4,border:"none",borderRadius:0,background:Q&&jt===null?"#999999":oe,cursor:"pointer",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:11,fontWeight:600,color:"#ffffff",transition:"background 150ms ease"},children:(()=>{let ue=Ft.length+e.styleModifications.length+e.spacingTokenChanges.filter(we=>!we.captured).length;if(jt!==null)return Tt(Yr,{children:[jt+1,Tt("span",{style:{opacity:.4,display:"flex",gap:4},children:[pe("span",{children:"/"}),pe("span",{children:ue})]})]});let xe=wt.length+e.styleModifications.length+e.spacingTokenChanges.filter(we=>!we.captured).length;return ue>xe?Tt(Yr,{children:[xe,Tt("span",{style:{opacity:.4,display:"flex",gap:4},children:[pe("span",{children:"/"}),pe("span",{children:ue})]})]}):ue})()})})})(),(e.annotations.length>0||e.styleModifications.length>0)&&pe("span",{onMouseEnter:()=>Jt("clear"),onMouseLeave:tt,children:pe(Eo,{siblingActive:e.isAnnotating,onClick:He,title:"Clear all (\u2318\u232B)",children:pe(tg,{size:17,strokeWidth:1.5})})}),p&&Tt(Yr,{children:[pe("div",{style:{width:1,height:20,backgroundColor:"rgba(0, 0, 0, 0.05)",margin:"0 2px"}}),pe("span",{onMouseEnter:()=>Jt("provider"),onMouseLeave:tt,style:{display:"contents"},children:Tt("div",{style:{display:"flex",alignItems:"center",gap:0},children:[pe(Eo,{onClick:()=>p(Mn),children:pe(Jr,{provider:l})}),Tt("button",{type:"button",onClick:()=>{let H=(u+1)%d;x?.(H)},style:{display:"flex",alignItems:"center",gap:6,height:32,border:"none",background:"none",cursor:"pointer",padding:"0 4px 0 0",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:10,fontWeight:500,color:Wn.iconDefault,whiteSpace:"nowrap"},children:[pe("span",{children:g}),pe("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:no.map(H=>pe("div",{style:{width:H.overflow?2:3,height:H.overflow?2:3,borderRadius:"50%",backgroundColor:H.active?Wn.iconDefault:"rgba(0,0,0,0.2)",opacity:H.overflow?.65:1,transition:"background-color 150ms ease, opacity 150ms ease"}},H.key))})]})]})})]}),pe("div",{ref:lr,style:{display:"inline-flex",cursor:"pointer"},children:pe("button",{type:"button",onClick:Me,title:"Collapse (\u2318\u2318)",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,border:"none",background:"none",padding:0,cursor:"inherit"},children:pe("svg",{"data-popmelt-logo":!0,width:"30",height:"30",viewBox:"0 0 40 40",fill:sr,stroke:"none",xmlns:"http://www.w3.org/2000/svg",children:pe("path",{d:"M20.25 8.00293H20.249C21.5098 8.0286 22.7219 8.25094 23.8584 8.63672L23.8604 8.63574C23.8961 8.64787 23.9312 8.66145 23.9668 8.67383C24.0611 8.70686 24.1548 8.74106 24.248 8.77637C24.2915 8.79273 24.3357 8.80727 24.3789 8.82422L24.376 8.82617C27.6145 10.0955 30.1646 12.7301 31.3213 16.0234L31.3232 16.0225C31.3327 16.0493 31.3404 16.0766 31.3496 16.1035C31.7691 17.3256 32 18.6356 32 20C32 20.8726 31.9366 21.6706 31.7598 22.4902L31.7197 22.6328C31.6412 23.0066 31.5136 23.6108 31.3408 24.2217L31.3398 24.2246C31.2967 24.377 31.251 24.5299 31.2021 24.6797C30.9215 25.5403 30.5473 26.2998 30.0879 26.2998C29.7613 26.2996 29.5995 25.9674 29.4316 25.6221C29.2501 25.2487 29.0614 24.8605 28.6484 24.8604C27.8532 24.8604 27.2081 25.5046 27.208 26.2998V27.0771C27.2079 27.6079 26.9661 28.112 26.5205 28.4004C25.9146 28.7925 25.2357 28.6462 24.7959 28.2061L24.7949 28.208C24.7897 28.2028 24.7854 28.1967 24.7803 28.1914C24.7654 28.1761 24.7507 28.1606 24.7363 28.1445C24.7105 28.1156 24.6858 28.0857 24.6621 28.0547C24.6461 28.0339 24.6302 28.013 24.6152 27.9912C24.5931 27.9591 24.5726 27.9257 24.5527 27.8916C24.5392 27.8685 24.5261 27.8452 24.5137 27.8213C24.5093 27.8128 24.5043 27.8045 24.5 27.7959L24.501 27.7939C24.3932 27.5763 24.3282 27.3276 24.3281 27.0576V26.2998C24.328 25.5993 23.8278 25.0158 23.165 24.8867V24.8877C23.0752 24.8702 22.9826 24.8604 22.8877 24.8604C22.8446 24.8604 22.8019 24.8624 22.7598 24.8662C22.0247 24.9312 21.4483 25.5479 21.4482 26.2998C21.4482 26.9127 21.4608 27.5305 21.4736 28.1494L21.4951 29.3135C21.5 29.7013 21.5015 30.089 21.4971 30.4756C21.4874 31.3103 20.8426 32 20.0078 32C19.1732 31.9998 18.5292 31.3102 18.5195 30.4756C18.5159 30.1613 18.5176 29.8464 18.5205 29.5312V29.5322C18.5212 29.4593 18.5206 29.3864 18.5215 29.3135L18.5303 28.8154V28.8145C18.5343 28.5927 18.5384 28.371 18.543 28.1494C18.5558 27.5305 18.5684 28.1129 18.5684 27.5C18.5684 26.7047 17.9232 26.0596 17.1279 26.0596C16.907 26.0596 16.6978 26.1103 16.5107 26.1992C16.2161 26.3393 15.9767 26.5769 15.834 26.8701C15.8269 26.8846 15.8201 26.8993 15.8135 26.9141C15.7821 26.9845 15.7562 27.0579 15.7363 27.1338C15.7243 27.1798 15.7155 27.2267 15.708 27.2744C15.7012 27.3175 15.6953 27.361 15.6924 27.4053C15.6903 27.4366 15.6885 27.4681 15.6885 27.5V28.7383C15.6883 29.9234 14.4911 30.7248 13.4961 30.0811C13.0505 29.7926 12.8086 29.2886 12.8086 28.7578V26.2998C12.8086 25.9737 12.6984 25.674 12.5156 25.4326C12.4437 25.3381 12.3612 25.2521 12.2686 25.1777V25.1768C12.0219 24.9788 11.709 24.8604 11.3682 24.8604C10.9892 24.8604 10.8622 24.8872 10.7295 25.2295C10.5837 25.6055 10.4302 26 9.92773 26C9.33081 25.9996 8.95963 25.2403 8.71484 24.3799C8.5591 23.8325 8.45907 23.571 8.3623 23.0107C8.3501 22.9401 8.33284 22.8403 8.31738 22.7529C8.12812 21.9466 8.02043 21.1089 8.00293 20.249V20.25L8 20C8 19.8617 8.00317 19.724 8.00781 19.5869C8.00837 19.5703 8.00816 19.5537 8.00879 19.5371L8.00977 19.5352C8.0998 17.1716 8.87444 14.9844 10.1396 13.1631C10.1488 13.1499 10.1587 13.1372 10.168 13.124C12.255 10.1453 15.6582 8.15745 19.5352 8.00977L19.5371 8.00879C19.5537 8.00816 19.5703 8.00837 19.5869 8.00781C19.724 8.00317 19.8617 8 20 8L20.25 8.00293Z"})})})})]})]})]}):Tt(Yr,{children:[pe("style",{children:`
20
+ `).map((F,oe)=>ue("p",{style:{margin:0,marginTop:oe>0?8:0},children:F},oe))}),A.usage.map((F,oe)=>Pt("div",{style:{display:"flex",gap:6,marginBottom:3,lineHeight:1.4},children:[ue("span",{style:{color:"#9ca3af",flexShrink:0},children:"\u2013"}),ue("span",{children:F})]},oe)),Ge==="collapse"&&Ae&&Pt("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:10,paddingTop:8},children:[ue("div",{style:{fontSize:10,color:"#9ca3af",marginBottom:6,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Position"}),ue("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:3,width:"fit-content"},children:al.map(F=>{let oe=F===ce;return ue("button",{type:"button",onClick:()=>{W(null),ye.current=!1,Lt(),Ae(F)},title:F,style:{width:24,height:16,border:"none",cursor:"pointer",padding:0,backgroundColor:oe?"#1f2937":"rgba(0,0,0,0.08)",transition:"background-color 100ms ease"},onMouseEnter:re=>{oe||(re.currentTarget.style.backgroundColor="rgba(0,0,0,0.15)")},onMouseLeave:re=>{oe||(re.currentTarget.style.backgroundColor="rgba(0,0,0,0.08)")}},F)})})]}),Ge==="collapse"&&(()=>{let F=Object.entries(P??{}),oe=F.filter(([,Be])=>Be.found&&!Be.disabled).map(([Be])=>Be.charAt(0).toUpperCase()+Be.slice(1)),re=F.filter(([,Be])=>!Be.found).map(([Be])=>Be);if(!N&&!V&&oe.length===0&&re.length===0)return null;let ne=re.map(Be=>Be.charAt(0).toUpperCase()+Be.slice(1)),we=[...oe,...ne];return Pt("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:10,paddingTop:8,display:"flex",alignItems:"center",gap:6,fontSize:11},children:[(V||N)&&ue("button",{type:"button",onClick:()=>{io||(V?V():ja(N))},disabled:io,title:zo,"aria-label":Fo??"Restart bridge",style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,border:"none",borderRadius:0,backgroundColor:Zt||$!=="idle"?"rgba(0,0,0,0.07)":"rgba(0,0,0,0.04)",color:Zo,cursor:io?"default":"pointer",padding:0,opacity:io?.55:1,flexShrink:0},children:$==="ok"?ue(Cg,{size:14,strokeWidth:1.8}):ue(Lg,{size:13,strokeWidth:1.7,style:{animation:$==="restarting"?"spin 0.8s linear infinite":void 0}})}),oe.length>0?Pt("span",{style:{color:"#6b7280"},children:["Available in ",we.join(", ")]}):re.length>0?Pt("span",{style:{color:"#6b7280"},children:["Available in ",ne.join(", ")]}):null]})})(),A.keys.length>1&&ue("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:8,paddingTop:8,display:"flex",flexDirection:"column",gap:4},children:A.keys.slice(1).map((F,oe)=>Pt("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:F.accent?"#fff":"#6b7280"},children:[ue("code",{style:{fontSize:10,backgroundColor:F.accent?e.activeColor:"rgba(0,0,0,0.06)",color:F.accent?"#fff":void 0,padding:"1px 4px",whiteSpace:"nowrap"},children:F.key}),ue("span",{style:{color:F.accent?e.activeColor:void 0,fontWeight:F.accent?600:void 0},children:F.desc})]},oe))}),Ge==="counter"&&Je.length>0&&(()=>{let F=ue("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:8,paddingTop:8},children:ue("div",{style:{fontSize:10,color:"#9ca3af",marginBottom:4,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Active"})}),oe=new Map;for(let we of Je){let Be=we.pathname||an;oe.has(Be)||oe.set(Be,[]),oe.get(Be).push(we)}let re=[...oe.entries()],ne=re.length>1;return Pt("div",{children:[F,ue("div",{style:{maxHeight:200,overflowY:"auto",scrollbarWidth:"thin"},children:re.map(([we,Be])=>ue("div",{style:{marginBottom:ne?4:0},children:Be.map(ve=>{let Et=ve.annotations.find(Cn=>Cn.type==="text"&&Cn.text)?.text||`[${ve.annotations[0]?.type??"annotation"}]`,Vt=e.selectedAnnotationIds.includes(ve.id),pn=Je.indexOf(ve),ot=pn+1,wn=ve.annotations[0]?.color??e.activeColor;return Pt("div",{onClick:()=>{if(!(!ve.pathname||ve.pathname===an)){sessionStorage.setItem("popmelt-pending-focus",JSON.stringify({annotationId:ve.id,pathname:ve.pathname})),window.location.href=ve.pathname;return}if(kn(pn),t({type:"SELECT_ELEMENT",payload:null}),t({type:"SELECT_ANNOTATION",payload:{id:ve.id}}),b){let fn=ve.annotations.find(Mn=>Mn.threadId)?.threadId;fn&&b(fn)}ye.current=!1,W(null)},style:{display:"flex",alignItems:"baseline",gap:4,padding:"2px 0",cursor:"pointer"},onMouseEnter:Cn=>{let fn=Cn.currentTarget.querySelector("[data-route-badge]");fn&&(fn.style.backgroundColor=wn,fn.style.color="#fff")},onMouseLeave:Cn=>{if(Vt)return;let fn=Cn.currentTarget.querySelector("[data-route-badge]");fn&&(fn.style.backgroundColor="rgba(0,0,0,0.06)",fn.style.color="#6b7280")},children:[Pt("code",{"data-route-badge":!0,style:{fontSize:10,color:Vt?"#fff":"#6b7280",backgroundColor:Vt?wn:"rgba(0,0,0,0.06)",padding:"1px 4px",flexShrink:0,whiteSpace:"nowrap"},children:[ot,". ",ne?we:""]}),ue("span",{style:{fontSize:11,color:Vt?"#1f2937":"#6b7280",fontWeight:Vt?600:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Et})]},ve.id)})},we))})]})})(),Ge==="counter"&&(()=>{let F=new Set(Je.flatMap(ne=>ne.annotations.map(we=>we.threadId).filter(Boolean))),oe=tt.filter(ne=>!F.has(ne.id));if(oe.length===0)return null;let re=ne=>{let we=Math.floor((Date.now()-ne)/1e3);if(we<60)return"now";let Be=Math.floor(we/60);if(Be<60)return`${Be}m`;let ve=Math.floor(Be/60);return ve<24?`${ve}h`:`${Math.floor(ve/24)}d`};return Pt("div",{style:{borderTop:"1px solid rgba(0,0,0,0.08)",marginTop:8,paddingTop:8},children:[ue("div",{style:{fontSize:10,color:"#9ca3af",marginBottom:4,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Recent"}),oe.map(ne=>Pt("div",{onClick:()=>{let we=ne.elementIdentifiers[0];if(we){let Be=we.indexOf(":"),ve=Be>0&&we[0]==="/",ut=ve?we.slice(0,Be):void 0,Et=ve?we.slice(Be+1):we;if(!(!ut||ut===an)){sessionStorage.setItem("popmelt-pending-thread",JSON.stringify({threadId:ne.id,selector:Et,preview:ne.preview})),window.location.href=ut;return}try{let pn=document.querySelector(Et);if(pn){let ot=pn.getBoundingClientRect(),wn=Math.random().toString(36).slice(2,9);t({type:"ADD_TEXT",payload:{id:wn,point:{x:ot.left+ot.width,y:ot.top},text:ne.preview,linkedSelector:Et,linkedAnchor:"top-left"}}),t({type:"SET_ANNOTATION_THREAD",payload:{ids:[wn],threadId:ne.id}}),t({type:"SET_ANNOTATION_STATUS",payload:{ids:[wn],status:"resolved"}})}}catch{}}b&&b(ne.id),ye.current=!1,W(null)},style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,padding:"2px 0",cursor:"pointer",color:"#6b7280",fontSize:11},onMouseEnter:we=>{we.currentTarget.style.color="#1f2937"},onMouseLeave:we=>{we.currentTarget.style.color="#6b7280"},children:[ue("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:ne.preview}),ue("span",{style:{flexShrink:0,fontSize:10,color:"#9ca3af"},children:re(ne.createdAt)})]},ne.id))]})})()]})})(),Pt("div",{ref:A=>{Xe&&(Xe.current=A)},id:"devtools-toolbar",style:oo,onMouseEnter:lt,onMouseMove:eo,children:[ro,Pt("div",{style:{display:"flex",flexDirection:"row",gap:4,alignItems:"center"},children:[ue("span",{onMouseEnter:()=>st("inspector"),onMouseLeave:Yt,children:ue(_o,{active:e.isAnnotating&&e.activeTool==="inspector",siblingActive:e.isAnnotating,onClick:()=>at("inspector"),children:ue(Ig,{size:20,strokeWidth:1.5})})}),ue("span",{onMouseEnter:()=>st("hand"),onMouseLeave:Yt,children:ue(_o,{active:e.isAnnotating&&e.activeTool==="hand",siblingActive:e.isAnnotating,onClick:()=>at("hand"),children:Pt("div",{style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:[ue(Mg,{size:20,strokeWidth:1.5}),e.styleModifications.filter(A=>!A.captured).length>0&&ue("div",{style:{position:"absolute",top:-7,right:-9,minWidth:14,height:14,borderRadius:0,backgroundColor:e.activeColor,color:"#fff",fontSize:9,fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 2px",lineHeight:1},children:e.styleModifications.filter(A=>!A.captured).length})]})})}),(()=>{let A=xr[Ne],F=A.icon,oe=e.isAnnotating&&_g.has(e.activeTool);return ue("span",{onMouseEnter:()=>st(A.type),onMouseLeave:Yt,children:Pt("div",{style:{display:"flex",alignItems:"center",gap:0},children:[ue(_o,{active:oe,siblingActive:e.isAnnotating,onClick:()=>at(A.type),children:ue(F,{size:20,strokeWidth:1.5})}),ue("button",{type:"button",onClick:()=>{let re=(Ne+1)%xr.length;rt(re),at(xr[re].type)},title:"Cycle shape tool",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,width:12,height:32,border:"none",background:"none",cursor:"pointer",padding:"0 2px",opacity:e.isAnnotating&&!oe?.5:1,transition:"opacity 150ms ease"},children:xr.map((re,ne)=>ue("div",{style:{width:3,height:3,borderRadius:"50%",backgroundColor:ne===Ne?Zn.iconDefault:"rgba(0,0,0,0.2)",transition:"background-color 150ms ease"}},ne))})]})})})(),Fg.map(({type:A,icon:F,label:oe,shortcut:re})=>ue("span",{onMouseEnter:()=>st(A),onMouseLeave:Yt,children:ue(_o,{active:e.isAnnotating&&e.activeTool===A,siblingActive:e.isAnnotating,onClick:()=>at(A),children:ue(F,{size:20,strokeWidth:1.5})})},A)),ue("span",{onMouseEnter:()=>st("eval"),onMouseLeave:Yt,children:ue(_o,{active:e.isAnnotating&&e.activeTool==="eval",siblingActive:e.isAnnotating,onClick:()=>at("eval"),children:ue(kg,{size:18,strokeWidth:1.5})})}),ue("span",{onMouseEnter:()=>st("model"),onMouseLeave:Yt,children:ue(_o,{active:e.isAnnotating&&e.activeTool==="model",siblingActive:e.isAnnotating,onClick:()=>at("model"),children:ue(Tg,{size:17,strokeWidth:1.5})})})]}),ue(Hc,{}),Pt("div",{style:{display:"flex",flexDirection:"row",gap:4,alignItems:"center"},children:[(Je.length>0||e.styleModifications.length>0||e.spacingTokenChanges.filter(A=>!A.captured).length>0)&&(()=>{let A=Ct!==null&&Ct<Je.length?Je[Ct]:null,F=e.annotations.length>0&&e.annotations.every(ne=>ne.status&&ne.status!=="pending"),oe=Ct!==null?A?.annotations.some(ne=>ne.status&&ne.status!=="pending")??!1:F,re=`oklch(0.628 0.258 ${ht})`;return ue("span",{onMouseEnter:()=>st("counter"),onMouseLeave:Yt,children:ue("button",{ref:ct,type:"button",onClick:()=>{if(wo.current){wo.current=!1;return}An()},onMouseDown:No,onMouseUp:Ko,onMouseLeave:Ko,title:"",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,minWidth:20,height:20,padding:"0 8px",marginRight:4,border:"none",borderRadius:0,background:oe&&Ct===null?"#999999":re,cursor:"pointer",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:11,fontWeight:600,color:"#ffffff",transition:"background 150ms ease"},children:(()=>{let ne=Je.length+e.styleModifications.length+e.spacingTokenChanges.filter(Be=>!Be.captured).length;if(Ct!==null)return Pt(di,{children:[Ct+1,Pt("span",{style:{opacity:.4,display:"flex",gap:4},children:[ue("span",{children:"/"}),ue("span",{children:ne})]})]});let we=no.length+e.styleModifications.length+e.spacingTokenChanges.filter(Be=>!Be.captured).length;return ne>we?Pt(di,{children:[we,Pt("span",{style:{opacity:.4,display:"flex",gap:4},children:[ue("span",{children:"/"}),ue("span",{children:ne})]})]}):ne})()})})})(),(e.annotations.length>0||e.styleModifications.length>0)&&ue("span",{onMouseEnter:()=>st("clear"),onMouseLeave:Yt,children:ue(_o,{siblingActive:e.isAnnotating,onClick:Ue,title:"Clear all (\u2318\u232B)",children:ue(Bg,{size:17,strokeWidth:1.5})})}),d&&Pt(di,{children:[ue("div",{style:{width:1,height:20,backgroundColor:"rgba(0, 0, 0, 0.05)",margin:"0 2px"}}),ue("span",{onMouseEnter:()=>st("provider"),onMouseLeave:Yt,style:{display:"contents"},children:Pt("div",{style:{display:"flex",alignItems:"center",gap:0},children:[ue(_o,{onClick:()=>d(Un),children:ue(ci,{provider:l})}),Pt("button",{type:"button",onClick:()=>{let A=(p+1)%u;v?.(A)},style:{display:"flex",alignItems:"center",gap:6,height:32,border:"none",background:"none",cursor:"pointer",padding:"0 4px 0 0",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:10,fontWeight:500,color:Zn.iconDefault,whiteSpace:"nowrap"},children:[ue("span",{children:m}),ue("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:fo.map(A=>ue("div",{style:{width:A.overflow?2:3,height:A.overflow?2:3,borderRadius:"50%",backgroundColor:A.active?Zn.iconDefault:"rgba(0,0,0,0.2)",opacity:A.overflow?.65:1,transition:"background-color 150ms ease, opacity 150ms ease"}},A.key))})]})]})})]}),ue("div",{ref:Qo,style:{display:"inline-flex",cursor:"pointer"},children:ue("button",{type:"button",onClick:Te,title:"Collapse (\u2318\u2318)",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,border:"none",background:"none",padding:0,cursor:"inherit"},children:ue("svg",{"data-popmelt-logo":!0,width:"30",height:"30",viewBox:"0 0 40 40",fill:Kn,stroke:"none",xmlns:"http://www.w3.org/2000/svg",children:ue("path",{d:"M20.25 8.00293H20.249C21.5098 8.0286 22.7219 8.25094 23.8584 8.63672L23.8604 8.63574C23.8961 8.64787 23.9312 8.66145 23.9668 8.67383C24.0611 8.70686 24.1548 8.74106 24.248 8.77637C24.2915 8.79273 24.3357 8.80727 24.3789 8.82422L24.376 8.82617C27.6145 10.0955 30.1646 12.7301 31.3213 16.0234L31.3232 16.0225C31.3327 16.0493 31.3404 16.0766 31.3496 16.1035C31.7691 17.3256 32 18.6356 32 20C32 20.8726 31.9366 21.6706 31.7598 22.4902L31.7197 22.6328C31.6412 23.0066 31.5136 23.6108 31.3408 24.2217L31.3398 24.2246C31.2967 24.377 31.251 24.5299 31.2021 24.6797C30.9215 25.5403 30.5473 26.2998 30.0879 26.2998C29.7613 26.2996 29.5995 25.9674 29.4316 25.6221C29.2501 25.2487 29.0614 24.8605 28.6484 24.8604C27.8532 24.8604 27.2081 25.5046 27.208 26.2998V27.0771C27.2079 27.6079 26.9661 28.112 26.5205 28.4004C25.9146 28.7925 25.2357 28.6462 24.7959 28.2061L24.7949 28.208C24.7897 28.2028 24.7854 28.1967 24.7803 28.1914C24.7654 28.1761 24.7507 28.1606 24.7363 28.1445C24.7105 28.1156 24.6858 28.0857 24.6621 28.0547C24.6461 28.0339 24.6302 28.013 24.6152 27.9912C24.5931 27.9591 24.5726 27.9257 24.5527 27.8916C24.5392 27.8685 24.5261 27.8452 24.5137 27.8213C24.5093 27.8128 24.5043 27.8045 24.5 27.7959L24.501 27.7939C24.3932 27.5763 24.3282 27.3276 24.3281 27.0576V26.2998C24.328 25.5993 23.8278 25.0158 23.165 24.8867V24.8877C23.0752 24.8702 22.9826 24.8604 22.8877 24.8604C22.8446 24.8604 22.8019 24.8624 22.7598 24.8662C22.0247 24.9312 21.4483 25.5479 21.4482 26.2998C21.4482 26.9127 21.4608 27.5305 21.4736 28.1494L21.4951 29.3135C21.5 29.7013 21.5015 30.089 21.4971 30.4756C21.4874 31.3103 20.8426 32 20.0078 32C19.1732 31.9998 18.5292 31.3102 18.5195 30.4756C18.5159 30.1613 18.5176 29.8464 18.5205 29.5312V29.5322C18.5212 29.4593 18.5206 29.3864 18.5215 29.3135L18.5303 28.8154V28.8145C18.5343 28.5927 18.5384 28.371 18.543 28.1494C18.5558 27.5305 18.5684 28.1129 18.5684 27.5C18.5684 26.7047 17.9232 26.0596 17.1279 26.0596C16.907 26.0596 16.6978 26.1103 16.5107 26.1992C16.2161 26.3393 15.9767 26.5769 15.834 26.8701C15.8269 26.8846 15.8201 26.8993 15.8135 26.9141C15.7821 26.9845 15.7562 27.0579 15.7363 27.1338C15.7243 27.1798 15.7155 27.2267 15.708 27.2744C15.7012 27.3175 15.6953 27.361 15.6924 27.4053C15.6903 27.4366 15.6885 27.4681 15.6885 27.5V28.7383C15.6883 29.9234 14.4911 30.7248 13.4961 30.0811C13.0505 29.7926 12.8086 29.2886 12.8086 28.7578V26.2998C12.8086 25.9737 12.6984 25.674 12.5156 25.4326C12.4437 25.3381 12.3612 25.2521 12.2686 25.1777V25.1768C12.0219 24.9788 11.709 24.8604 11.3682 24.8604C10.9892 24.8604 10.8622 24.8872 10.7295 25.2295C10.5837 25.6055 10.4302 26 9.92773 26C9.33081 25.9996 8.95963 25.2403 8.71484 24.3799C8.5591 23.8325 8.45907 23.571 8.3623 23.0107C8.3501 22.9401 8.33284 22.8403 8.31738 22.7529C8.12812 21.9466 8.02043 21.1089 8.00293 20.249V20.25L8 20C8 19.8617 8.00317 19.724 8.00781 19.5869C8.00837 19.5703 8.00816 19.5537 8.00879 19.5371L8.00977 19.5352C8.0998 17.1716 8.87444 14.9844 10.1396 13.1631C10.1488 13.1499 10.1587 13.1372 10.168 13.124C12.255 10.1453 15.6582 8.15745 19.5352 8.00977L19.5371 8.00879C19.5537 8.00816 19.5703 8.00837 19.5869 8.00781C19.724 8.00317 19.8617 8 20 8L20.25 8.00293Z"})})})})]})]})]}):Pt(di,{children:[ue("style",{children:`
21
21
  @keyframes popmelt-border-march { to { background-position: 0 -5px; } }
22
- `}),Tt("div",{ref:H=>{cr.current=H,Ge&&(Ge.current=H)},id:"devtools-toolbar",style:{...To,overflow:"visible",opacity:r?1:.5},children:[Zt,pe("button",{type:"button",style:{display:"flex",alignItems:"center",justifyContent:"center",width:48,height:48,border:"none",background:"none",cursor:"pointer",padding:0},onClick:()=>{Se(!0),t({type:"SET_TOOL",payload:"inspector"}),t({type:"SET_ANNOTATING",payload:!0})},onMouseEnter:()=>s?.(!0),onMouseLeave:()=>s?.(!1),title:"Open annotation toolbar (\u2318\u2318)",children:pe("svg",{"data-popmelt-logo":!0,width:"30",height:"30",viewBox:"0 0 40 40",fill:"none",stroke:sr,strokeWidth:"1",strokeLinejoin:"round",xmlns:"http://www.w3.org/2000/svg",children:pe("path",{d:"M20.25 8.00293H20.249C21.5098 8.0286 22.7219 8.25094 23.8584 8.63672L23.8604 8.63574C23.8961 8.64787 23.9312 8.66145 23.9668 8.67383C24.0611 8.70686 24.1548 8.74106 24.248 8.77637C24.2915 8.79273 24.3357 8.80727 24.3789 8.82422L24.376 8.82617C27.6145 10.0955 30.1646 12.7301 31.3213 16.0234L31.3232 16.0225C31.3327 16.0493 31.3404 16.0766 31.3496 16.1035C31.7691 17.3256 32 18.6356 32 20C32 20.8726 31.9366 21.6706 31.7598 22.4902L31.7197 22.6328C31.6412 23.0066 31.5136 23.6108 31.3408 24.2217L31.3398 24.2246C31.2967 24.377 31.251 24.5299 31.2021 24.6797C30.9215 25.5403 30.5473 26.2998 30.0879 26.2998C29.7613 26.2996 29.5995 25.9674 29.4316 25.6221C29.2501 25.2487 29.0614 24.8605 28.6484 24.8604C27.8532 24.8604 27.2081 25.5046 27.208 26.2998V27.0771C27.2079 27.6079 26.9661 28.112 26.5205 28.4004C25.9146 28.7925 25.2357 28.6462 24.7959 28.2061L24.7949 28.208C24.7897 28.2028 24.7854 28.1967 24.7803 28.1914C24.7654 28.1761 24.7507 28.1606 24.7363 28.1445C24.7105 28.1156 24.6858 28.0857 24.6621 28.0547C24.6461 28.0339 24.6302 28.013 24.6152 27.9912C24.5931 27.9591 24.5726 27.9257 24.5527 27.8916C24.5392 27.8685 24.5261 27.8452 24.5137 27.8213C24.5093 27.8128 24.5043 27.8045 24.5 27.7959L24.501 27.7939C24.3932 27.5763 24.3282 27.3276 24.3281 27.0576V26.2998C24.328 25.5993 23.8278 25.0158 23.165 24.8867V24.8877C23.0752 24.8702 22.9826 24.8604 22.8877 24.8604C22.8446 24.8604 22.8019 24.8624 22.7598 24.8662C22.0247 24.9312 21.4483 25.5479 21.4482 26.2998C21.4482 26.9127 21.4608 27.5305 21.4736 28.1494L21.4951 29.3135C21.5 29.7013 21.5015 30.089 21.4971 30.4756C21.4874 31.3103 20.8426 32 20.0078 32C19.1732 31.9998 18.5292 31.3102 18.5195 30.4756C18.5159 30.1613 18.5176 29.8464 18.5205 29.5312V29.5322C18.5212 29.4593 18.5206 29.3864 18.5215 29.3135L18.5303 28.8154V28.8145C18.5343 28.5927 18.5384 28.371 18.543 28.1494C18.5558 27.5305 18.5684 28.1129 18.5684 27.5C18.5684 26.7047 17.9232 26.0596 17.1279 26.0596C16.907 26.0596 16.6978 26.1103 16.5107 26.1992C16.2161 26.3393 15.9767 26.5769 15.834 26.8701C15.8269 26.8846 15.8201 26.8993 15.8135 26.9141C15.7821 26.9845 15.7562 27.0579 15.7363 27.1338C15.7243 27.1798 15.7155 27.2267 15.708 27.2744C15.7012 27.3175 15.6953 27.361 15.6924 27.4053C15.6903 27.4366 15.6885 27.4681 15.6885 27.5V28.7383C15.6883 29.9234 14.4911 30.7248 13.4961 30.0811C13.0505 29.7926 12.8086 29.2886 12.8086 28.7578V26.2998C12.8086 25.9737 12.6984 25.674 12.5156 25.4326C12.4437 25.3381 12.3612 25.2521 12.2686 25.1777V25.1768C12.0219 24.9788 11.709 24.8604 11.3682 24.8604C10.9892 24.8604 10.8622 24.8872 10.7295 25.2295C10.5837 25.6055 10.4302 26 9.92773 26C9.33081 25.9996 8.95963 25.2403 8.71484 24.3799C8.5591 23.8325 8.45907 23.571 8.3623 23.0107C8.3501 22.9401 8.33284 22.8403 8.31738 22.7529C8.12812 21.9466 8.02043 21.1089 8.00293 20.249V20.25L8 20C8 19.8617 8.00317 19.724 8.00781 19.5869C8.00837 19.5703 8.00816 19.5537 8.00879 19.5371L8.00977 19.5352C8.0998 17.1716 8.87444 14.9844 10.1396 13.1631C10.1488 13.1499 10.1587 13.1372 10.168 13.124C12.255 10.1453 15.6582 8.15745 19.5352 8.00977L19.5371 8.00879C19.5537 8.00816 19.5703 8.00837 19.5869 8.00781C19.724 8.00317 19.8617 8 20 8L20.25 8.00293Z"})})})]})]})}import{useCallback as dg,useEffect as Qn,useRef as Vr,useState as Ni}from"react";import{Fragment as kc,jsx as Mt,jsxs as Ar}from"react/jsx-runtime";function Cc(e){return e.status==="done"||e.status==="error"}var ug=24,pg=6,fg=ug-pg,gg=8,Ec={display:"flex",alignItems:"center",gap:3,padding:0,backgroundColor:"#eaeaea",...Po,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:11,whiteSpace:"nowrap",transition:"transform 200ms ease, opacity 200ms ease"};function mg(e){let t=e.filter(a=>a.type==="tool_use");if(t.length===0)return"Starting\u2026";let n=t[t.length-1],o=String(n.data.tool||""),r=n.data.file?String(n.data.file):null,i=r?r.split("/").pop()??r:null,s=n.data.content?String(n.data.content):null;switch(o){case"Read":return i?`Reading ${i}`:"Reading file";case"Edit":return i?`Editing ${i}`:"Editing file";case"Write":return i?`Writing ${i}`:"Writing file";case"Bash":{if(!s)return"Running command";let a=s.split(`
23
- `)[0].trim();return a.length<=40?a:a.slice(0,37)+"\u2026"}case"Glob":return"Searching files";case"Grep":return"Searching code";default:return o?`Using ${o}`:"Working\u2026"}}function hg(e){let t=e.replace(/^Error:\s*/i,"");return t.length>40?t.slice(0,37)+"...":t}function yg(e,t){if(e.some(i=>i.type==="question"&&i.data.jobId===t))return"Has a question";let o=new Set(["Edit","Write"]);return e.some(i=>i.type==="tool_use"&&i.data.jobId===t&&o.has(String(i.data.tool||"")))?"Applied changes":"Replied"}function bg({color:e}){let[t,n]=Ni(0);return Qn(()=>{let o=setInterval(()=>{n(r=>(r+1)%2)},250);return()=>clearInterval(o)},[]),Mt("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:e,style:{verticalAlign:"middle",flexShrink:0},children:t===1?Ar(kc,{children:[Mt("circle",{cx:"7",cy:"7",r:"2"}),Mt("circle",{cx:"17",cy:"7",r:"2"}),Mt("circle",{cx:"7",cy:"17",r:"2"}),Mt("circle",{cx:"17",cy:"17",r:"2"})]}):Ar(kc,{children:[Mt("circle",{cx:"12",cy:"6",r:"2"}),Mt("circle",{cx:"6",cy:"12",r:"2"}),Mt("circle",{cx:"18",cy:"12",r:"2"}),Mt("circle",{cx:"12",cy:"18",r:"2"})]})})}function vg({color:e}){return Mt("span",{style:{display:"inline-block",width:8,height:8,backgroundColor:e,opacity:.6}})}function xg({color:e}){return Mt("span",{style:{color:e,fontSize:12,lineHeight:1,width:10,display:"inline-block"},children:"\u2713"})}function Sg(){return Mt("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",backgroundColor:"#ef4444"}})}function wg({onCancel:e}){let t=Vr(null);return Qn(()=>{let n=t.current;if(!n)return;let o=s=>{s.stopPropagation(),e()},r=()=>{n.style.opacity="0.5"},i=()=>{n.style.opacity="0.7"};return n.addEventListener("click",o),n.addEventListener("mouseenter",r),n.addEventListener("mouseleave",i),()=>{n.removeEventListener("click",o),n.removeEventListener("mouseenter",r),n.removeEventListener("mouseleave",i)}},[e]),Mt("button",{ref:t,style:{background:"none",border:"none",cursor:"pointer",color:"#ffffff",opacity:.7,fontSize:14,padding:"0 2px",lineHeight:1},title:"Cancel",children:"\xD7"})}function Cg({onDismiss:e}){let t=Vr(null);return Qn(()=>{let n=t.current;if(!n)return;let o=s=>{s.stopPropagation(),e()},r=()=>{n.style.opacity="0.5"},i=()=>{n.style.opacity="0.7"};return n.addEventListener("click",o),n.addEventListener("mouseenter",r),n.addEventListener("mouseleave",i),()=>{n.removeEventListener("click",o),n.removeEventListener("mouseenter",r),n.removeEventListener("mouseleave",i)}},[e]),Mt("button",{ref:t,style:{background:"none",border:"none",cursor:"pointer",color:"#ffffff",opacity:.7,fontSize:14,padding:"0 2px",lineHeight:1},title:"Dismiss",children:"\xD7"})}function Tc({bridge:e,inFlightJobs:t,isVisible:n,onHover:o,clearSignal:r,onViewThread:i,onClickJob:s,onCancel:a,onHoverJob:l,isConnected:p,dismissedThreadIds:c,snapPosition:u="bottom-right"}){let[d,g]=Ni([]),[x,h]=Ni(!1),[I,O]=Ni(()=>typeof window<"u"?{w:window.innerWidth,h:window.innerHeight}:{w:1920,h:1080});Qn(()=>{let j=()=>O({w:window.innerWidth,h:window.innerHeight});return window.addEventListener("resize",j),()=>window.removeEventListener("resize",j)},[]);let P=_a(u,I.w,I.h);Qn(()=>{r>0&&g([])},[r]),Qn(()=>{!c||c.size===0||g(j=>{let se=j.filter(_=>!_.threadId||!c.has(_.threadId)||!Cc(_));return se.length===j.length?j:se})},[c]),Qn(()=>{g(j=>{let se=new Set(j.map(de=>de.jobId)),_=!1,he=j.map(de=>{let Ee=t[de.jobId];return Ee&&(!de.threadId||de.color==="#888")?(_=!0,{...de,threadId:de.threadId||Ee.threadId,color:de.color==="#888"?Ee.color:de.color}):de});for(let[de,Ee]of Object.entries(t))se.has(de)||(he.push({jobId:de,color:Ee.color,status:"queued",threadId:Ee.threadId}),_=!0);let fe=new Set(Object.keys(t)),Ae=new Set(e.activeJobIds),De=he.filter(de=>de.status!=="queued"?!0:fe.has(de.jobId)||Ae.has(de.jobId));De.length!==he.length&&(_=!0);let ze=new Set(De.map(de=>de.jobId));for(let de of e.activeJobIds)if(!ze.has(de)){let Ee=e.events.find(Ge=>Ge.type==="job_started"&&Ge.data.jobId===de);De.push({jobId:de,color:"#888",status:"working",threadId:Ee?.data?.threadId}),_=!0}return _?De:j})},[t,e.activeJobIds]),Qn(()=>{if(e.activeJobIds.length===0)return;let j=new Set(e.activeJobIds);g(se=>se.map(_=>j.has(_.jobId)&&_.status!=="done"&&_.status!=="error"?{..._,status:"working"}:_))},[e.activeJobIds]);let F=Vr(null);Qn(()=>{let j=e.lastCompletedJobId;if(!j||j===F.current)return;F.current=j;let se=e.events.find(ze=>ze.type==="error"&&(ze.data.jobId===j||e.status==="error")),_=!!se,he=_?void 0:yg(e.events,j),fe=se?String(se.data.message||""):void 0,Ae=se?!!se.data.cancelled:void 0,De=se?.data.threadId;g(ze=>{let de=ze.map(Ge=>Ge.jobId===j?{...Ge,status:_?"error":"done",doneLabel:he,errorMessage:fe,cancelled:Ae,threadId:Ge.threadId||De}:Ge);if(!c||c.size===0)return de;let Ee=de.filter(Ge=>!Ge.threadId||!c.has(Ge.threadId)||!Cc(Ge));return Ee.length===de.length?de:Ee})},[e.lastCompletedJobId,e.events,e.status,c]);let M=n&&(d.length>0||p===!1),D=Vr(null);Qn(()=>{if(!M)return;let j=D.current;if(!j)return;let se=()=>{h(!0),o(!0)},_=()=>{h(!1),o(!1),l?.(null)};return j.addEventListener("mouseenter",se),j.addEventListener("mouseleave",_),()=>{j.removeEventListener("mouseenter",se),j.removeEventListener("mouseleave",_)}},[M,o,l]);let J=Vr(new Map),ee=dg((j,se)=>{se?J.current.set(j,se):J.current.delete(j)},[]);if(Qn(()=>{if(!M)return;let j=[];for(let se of d){let _=J.current.get(se.jobId);if(_){if(s){let he=se.jobId,fe=()=>s(he);_.addEventListener("click",fe),j.push(()=>_.removeEventListener("click",fe))}if(l){let he=se.jobId,fe=()=>l(he),Ae=()=>l(null);_.addEventListener("mouseenter",fe),_.addEventListener("mouseleave",Ae),j.push(()=>{_.removeEventListener("mouseenter",fe),_.removeEventListener("mouseleave",Ae)})}}}return()=>j.forEach(se=>se())},[M,d,s,l]),!M)return null;let C={working:3,queued:2,error:1,done:0},S=[],A=new Map;for(let j of d){if(!j.threadId){S.push(j);continue}let se=A.get(j.threadId);(!se||C[j.status]>C[se.status]||C[j.status]===C[se.status])&&A.set(j.threadId,j)}for(let j of A.values())S.push(j);let y=S.filter(j=>j.status==="queued"),T=new Map;y.forEach((j,se)=>{T.set(j.jobId,`(${se+1}/${y.length})`)});let L=!x&&S.length>1,ce=jo(u),We=Go(u),be=ce?S:[...S].reverse();return Ar("div",{ref:D,style:P,"data-devtools":!0,children:[Mt("style",{children:"@keyframes popmelt-badge-march { to { background-position: 0 -5px; } }"}),be.map((j,se)=>{let _=se===S.length-1,he=S.length-1-se,fe=j.status==="working"?mg(e.events.filter(Ae=>Ae.data.jobId===j.jobId)):j.status==="queued"?`Queued ${T.get(j.jobId)??""}`:j.status==="done"?j.doneLabel||"Done":j.cancelled?"Cancelled":j.errorMessage?hg(j.errorMessage):"Error";return Mt("div",{style:{position:"relative",zIndex:S.length-se,marginBottom:L?_?0:-fg:_?0:gg,transform:L?`scale(${Math.max(.94,1-he*.02)})`:"scale(1)",opacity:1,transformOrigin:`${ce?"top":"bottom"} ${We?"right":"left"}`,transition:"margin-bottom 250ms ease, transform 250ms ease, opacity 250ms ease"},children:Ar("div",{ref:Ae=>ee(j.jobId,Ae),style:{...Ec,position:"relative",overflow:"visible",cursor:s?"pointer":void 0,...j.status==="working"&&{borderImage:"none",borderColor:"transparent"}},title:j.errorMessage||void 0,children:[j.status==="working"&&(()=>{let Ae=`<svg xmlns='http://www.w3.org/2000/svg' width='5' height='5'><path d='M-1,1 l2,-2 M0,5 l5,-5 M4,6 l2,-2' stroke='${j.color}' stroke-width='.75'/></svg>`;return Mt("div",{style:{position:"absolute",inset:-3,padding:5,backgroundImage:`url("data:image/svg+xml,${encodeURIComponent(Ae)}")`,backgroundSize:"5px 5px",WebkitMask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",WebkitMaskComposite:"xor",mask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",maskComposite:"exclude",pointerEvents:"none",animation:"popmelt-badge-march 0.8s linear infinite"}})})(),Ar("div",{style:{display:"flex",alignItems:"center",gap:3,padding:"3px 5px 3px 8px",margin:3,backgroundColor:j.status==="error"?"#ef4444":j.color,color:"#ffffff"},children:[j.status==="working"&&Mt(bg,{color:"#ffffff"}),j.status==="queued"&&Mt(vg,{color:"#ffffff"}),j.status==="done"&&Mt(xg,{color:"#ffffff"}),j.status==="error"&&Mt(Sg,{}),Mt("span",{style:{opacity:j.status==="queued"?.6:1,maxWidth:160,overflow:"hidden",textOverflow:"ellipsis"},children:fe}),j.status==="working"&&a&&Mt(wg,{onCancel:()=>a(j.jobId)}),(j.status==="done"||j.status==="error")&&Mt(Cg,{onDismiss:()=>g(Ae=>Ae.filter(De=>j.threadId?De.threadId!==j.threadId:De.jobId!==j.jobId))})]})]})},j.jobId)}),p===!1&&d.length>0&&Mt("div",{style:Ec,children:Ar("div",{style:{display:"flex",alignItems:"center",gap:3,padding:"3px 5px 3px 8px",margin:3,backgroundColor:"#f59e0b",color:"#ffffff"},children:[Mt("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",backgroundColor:"#ffffff",opacity:.6}}),Mt("span",{children:"Reconnecting\u2026"})]})})]})}import{Fragment as Tg,jsx as kg,jsxs as Mg}from"react/jsx-runtime";var Eg=`
22
+ `}),Pt("div",{ref:A=>{$o.current=A,Xe&&(Xe.current=A)},id:"devtools-toolbar",style:{...oo,overflow:"visible",opacity:r?1:.5},children:[ro,ue("button",{type:"button",style:{display:"flex",alignItems:"center",justifyContent:"center",width:48,height:48,border:"none",background:"none",cursor:"pointer",padding:0},onClick:()=>{ie(!0),t({type:"SET_TOOL",payload:"inspector"}),t({type:"SET_ANNOTATING",payload:!0})},onMouseEnter:()=>s?.(!0),onMouseLeave:()=>s?.(!1),title:"Open annotation toolbar (\u2318\u2318)",children:ue("svg",{"data-popmelt-logo":!0,width:"30",height:"30",viewBox:"0 0 40 40",fill:"none",stroke:Kn,strokeWidth:"1",strokeLinejoin:"round",xmlns:"http://www.w3.org/2000/svg",children:ue("path",{d:"M20.25 8.00293H20.249C21.5098 8.0286 22.7219 8.25094 23.8584 8.63672L23.8604 8.63574C23.8961 8.64787 23.9312 8.66145 23.9668 8.67383C24.0611 8.70686 24.1548 8.74106 24.248 8.77637C24.2915 8.79273 24.3357 8.80727 24.3789 8.82422L24.376 8.82617C27.6145 10.0955 30.1646 12.7301 31.3213 16.0234L31.3232 16.0225C31.3327 16.0493 31.3404 16.0766 31.3496 16.1035C31.7691 17.3256 32 18.6356 32 20C32 20.8726 31.9366 21.6706 31.7598 22.4902L31.7197 22.6328C31.6412 23.0066 31.5136 23.6108 31.3408 24.2217L31.3398 24.2246C31.2967 24.377 31.251 24.5299 31.2021 24.6797C30.9215 25.5403 30.5473 26.2998 30.0879 26.2998C29.7613 26.2996 29.5995 25.9674 29.4316 25.6221C29.2501 25.2487 29.0614 24.8605 28.6484 24.8604C27.8532 24.8604 27.2081 25.5046 27.208 26.2998V27.0771C27.2079 27.6079 26.9661 28.112 26.5205 28.4004C25.9146 28.7925 25.2357 28.6462 24.7959 28.2061L24.7949 28.208C24.7897 28.2028 24.7854 28.1967 24.7803 28.1914C24.7654 28.1761 24.7507 28.1606 24.7363 28.1445C24.7105 28.1156 24.6858 28.0857 24.6621 28.0547C24.6461 28.0339 24.6302 28.013 24.6152 27.9912C24.5931 27.9591 24.5726 27.9257 24.5527 27.8916C24.5392 27.8685 24.5261 27.8452 24.5137 27.8213C24.5093 27.8128 24.5043 27.8045 24.5 27.7959L24.501 27.7939C24.3932 27.5763 24.3282 27.3276 24.3281 27.0576V26.2998C24.328 25.5993 23.8278 25.0158 23.165 24.8867V24.8877C23.0752 24.8702 22.9826 24.8604 22.8877 24.8604C22.8446 24.8604 22.8019 24.8624 22.7598 24.8662C22.0247 24.9312 21.4483 25.5479 21.4482 26.2998C21.4482 26.9127 21.4608 27.5305 21.4736 28.1494L21.4951 29.3135C21.5 29.7013 21.5015 30.089 21.4971 30.4756C21.4874 31.3103 20.8426 32 20.0078 32C19.1732 31.9998 18.5292 31.3102 18.5195 30.4756C18.5159 30.1613 18.5176 29.8464 18.5205 29.5312V29.5322C18.5212 29.4593 18.5206 29.3864 18.5215 29.3135L18.5303 28.8154V28.8145C18.5343 28.5927 18.5384 28.371 18.543 28.1494C18.5558 27.5305 18.5684 28.1129 18.5684 27.5C18.5684 26.7047 17.9232 26.0596 17.1279 26.0596C16.907 26.0596 16.6978 26.1103 16.5107 26.1992C16.2161 26.3393 15.9767 26.5769 15.834 26.8701C15.8269 26.8846 15.8201 26.8993 15.8135 26.9141C15.7821 26.9845 15.7562 27.0579 15.7363 27.1338C15.7243 27.1798 15.7155 27.2267 15.708 27.2744C15.7012 27.3175 15.6953 27.361 15.6924 27.4053C15.6903 27.4366 15.6885 27.4681 15.6885 27.5V28.7383C15.6883 29.9234 14.4911 30.7248 13.4961 30.0811C13.0505 29.7926 12.8086 29.2886 12.8086 28.7578V26.2998C12.8086 25.9737 12.6984 25.674 12.5156 25.4326C12.4437 25.3381 12.3612 25.2521 12.2686 25.1777V25.1768C12.0219 24.9788 11.709 24.8604 11.3682 24.8604C10.9892 24.8604 10.8622 24.8872 10.7295 25.2295C10.5837 25.6055 10.4302 26 9.92773 26C9.33081 25.9996 8.95963 25.2403 8.71484 24.3799C8.5591 23.8325 8.45907 23.571 8.3623 23.0107C8.3501 22.9401 8.33284 22.8403 8.31738 22.7529C8.12812 21.9466 8.02043 21.1089 8.00293 20.249V20.25L8 20C8 19.8617 8.00317 19.724 8.00781 19.5869C8.00837 19.5703 8.00816 19.5537 8.00879 19.5371L8.00977 19.5352C8.0998 17.1716 8.87444 14.9844 10.1396 13.1631C10.1488 13.1499 10.1587 13.1372 10.168 13.124C12.255 10.1453 15.6582 8.15745 19.5352 8.00977L19.5371 8.00879C19.5537 8.00816 19.5703 8.00837 19.5869 8.00781C19.724 8.00317 19.8617 8 20 8L20.25 8.00293Z"})})})]})]})}import{useCallback as Gc,useEffect as uo,useMemo as Wg,useRef as ui,useState as is}from"react";import{Fragment as Vc,jsx as _t,jsxs as pi}from"react/jsx-runtime";function Jc(e){return e.status==="done"||e.status==="error"}var jg=20,Gg=6,Jg=jg-Gg,Yg=8,Yc={display:"flex",alignItems:"center",gap:3,padding:0,backgroundColor:"transparent",border:"none",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:11,whiteSpace:"nowrap",transition:"transform 200ms ease, opacity 200ms ease"};function Vg(e){let t=e.filter(a=>a.type==="tool_use");if(t.length===0)return"Starting\u2026";let n=t[t.length-1],o=String(n.data.tool||""),r=n.data.file?String(n.data.file):null,i=r?r.split("/").pop()??r:null,s=n.data.content?String(n.data.content):null;switch(o){case"Read":return i?`Reading ${i}`:"Reading file";case"Edit":return i?`Editing ${i}`:"Editing file";case"Write":return i?`Writing ${i}`:"Writing file";case"Bash":{if(!s)return"Running command";let a=s.split(`
23
+ `)[0].trim();return a.length<=40?a:a.slice(0,37)+"\u2026"}case"Glob":return"Searching files";case"Grep":return"Searching code";default:return o?`Using ${o}`:"Working\u2026"}}function Ug(e){let t=e.replace(/^Error:\s*/i,"");return t.length>40?t.slice(0,37)+"...":t}function Kg(e,t){if(e.some(i=>i.type==="question"&&i.data.jobId===t))return"Has a question";let o=new Set(["Edit","Write"]);return e.some(i=>i.type==="tool_use"&&i.data.jobId===t&&o.has(String(i.data.tool||"")))?"Applied changes":"Replied"}function Xg({color:e}){let[t,n]=is(0);return uo(()=>{let o=setInterval(()=>{n(r=>(r+1)%2)},250);return()=>clearInterval(o)},[]),_t("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:e,style:{verticalAlign:"middle",flexShrink:0},children:t===1?pi(Vc,{children:[_t("circle",{cx:"7",cy:"7",r:"2"}),_t("circle",{cx:"17",cy:"7",r:"2"}),_t("circle",{cx:"7",cy:"17",r:"2"}),_t("circle",{cx:"17",cy:"17",r:"2"})]}):pi(Vc,{children:[_t("circle",{cx:"12",cy:"6",r:"2"}),_t("circle",{cx:"6",cy:"12",r:"2"}),_t("circle",{cx:"18",cy:"12",r:"2"}),_t("circle",{cx:"12",cy:"18",r:"2"})]})})}function qg({color:e}){return _t("span",{style:{display:"inline-block",width:8,height:8,backgroundColor:e,opacity:.6}})}function Zg({color:e}){return _t("span",{style:{color:e,fontSize:12,lineHeight:1,width:10,display:"inline-block"},children:"\u2713"})}function Qg(){return _t("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",backgroundColor:"#ef4444"}})}function em({onCancel:e}){let t=ui(null);return uo(()=>{let n=t.current;if(!n)return;let o=s=>{s.stopPropagation(),e()},r=()=>{n.style.opacity="0.5"},i=()=>{n.style.opacity="0.7"};return n.addEventListener("click",o),n.addEventListener("mouseenter",r),n.addEventListener("mouseleave",i),()=>{n.removeEventListener("click",o),n.removeEventListener("mouseenter",r),n.removeEventListener("mouseleave",i)}},[e]),_t("button",{ref:t,style:{background:"none",border:"none",cursor:"pointer",color:"#ffffff",opacity:.7,fontSize:14,padding:"0 2px",lineHeight:1},title:"Cancel",children:"\xD7"})}function tm({onDismiss:e}){let t=ui(null);return uo(()=>{let n=t.current;if(!n)return;let o=s=>{s.stopPropagation(),e()},r=()=>{n.style.opacity="0.5"},i=()=>{n.style.opacity="0.7"};return n.addEventListener("click",o),n.addEventListener("mouseenter",r),n.addEventListener("mouseleave",i),()=>{n.removeEventListener("click",o),n.removeEventListener("mouseenter",r),n.removeEventListener("mouseleave",i)}},[e]),_t("button",{ref:t,style:{background:"none",border:"none",cursor:"pointer",color:"#ffffff",opacity:.7,fontSize:14,padding:"0 2px",lineHeight:1},title:"Dismiss",children:"\xD7"})}function Uc({bridge:e,inFlightJobs:t,isVisible:n,onHover:o,clearSignal:r,onViewThread:i,onClickJob:s,onCancel:a,onHoverJob:l,isConnected:d,dismissedThreadIds:c,snapPosition:p="bottom-right",currentPathname:u}){let[m,v]=is([]),[b,I]=is(!1),[P,N]=is(()=>typeof window<"u"?{w:window.innerWidth,h:window.innerHeight}:{w:1920,h:1080});uo(()=>{let O=()=>N({w:window.innerWidth,h:window.innerHeight});return window.addEventListener("resize",O),()=>window.removeEventListener("resize",O)},[]);let C=il(p,P.w,P.h);uo(()=>{r>0&&v([])},[r]),uo(()=>{!c||c.size===0||v(O=>{let Z=O.filter(pe=>!pe.threadId||!c.has(pe.threadId)||!Jc(pe));return Z.length===O.length?O:Z})},[c]),uo(()=>{v(O=>{let Z=new Set(O.map(ce=>ce.jobId)),pe=!1,Le=O.map(ce=>{let Ae=t[ce.jobId];return Ae&&(!ce.threadId||ce.color==="#888"||!ce.routePathnames&&Ae.routePathnames||ce.global==null&&Ae.global!=null)?(pe=!0,{...ce,threadId:ce.threadId||Ae.threadId,color:ce.color==="#888"?Ae.color:ce.color,routePathnames:ce.routePathnames??Ae.routePathnames,global:ce.global??Ae.global}):ce});for(let[ce,Ae]of Object.entries(t))Z.has(ce)||(Le.push({jobId:ce,color:Ae.color,status:"queued",threadId:Ae.threadId,routePathnames:Ae.routePathnames,global:Ae.global}),pe=!0);let _e=new Set(Object.keys(t)),ge=new Set(e.activeJobIds),lt=Le.filter(ce=>ce.status!=="queued"?!0:_e.has(ce.jobId)||ge.has(ce.jobId));lt.length!==Le.length&&(pe=!0);let Xe=new Set(lt.map(ce=>ce.jobId));for(let ce of e.activeJobIds)if(!Xe.has(ce)){let Ae=e.events.find(ft=>ft.type==="job_started"&&ft.data.jobId===ce);lt.push({jobId:ce,color:"#888",status:"working",threadId:Ae?.data?.threadId}),pe=!0}return pe?lt:O})},[t,e.activeJobIds]),uo(()=>{if(e.activeJobIds.length===0)return;let O=new Set(e.activeJobIds);v(Z=>Z.map(pe=>O.has(pe.jobId)&&pe.status!=="done"&&pe.status!=="error"?{...pe,status:"working"}:pe))},[e.activeJobIds]);let k=ui(null);uo(()=>{let O=e.lastCompletedJobId;if(!O||O===k.current)return;k.current=O;let Z=e.events.find(Xe=>Xe.type==="error"&&(Xe.data.jobId===O||e.status==="error")),pe=!!Z,Le=pe?void 0:Kg(e.events,O),_e=Z?String(Z.data.message||""):void 0,ge=Z?!!Z.data.cancelled:void 0,lt=Z?.data.threadId;v(Xe=>{let ce=Xe.map(ft=>ft.jobId===O?{...ft,status:pe?"error":"done",doneLabel:Le,errorMessage:_e,cancelled:ge,threadId:ft.threadId||lt}:ft);if(!c||c.size===0)return ce;let Ae=ce.filter(ft=>!ft.threadId||!c.has(ft.threadId)||!Jc(ft));return Ae.length===ce.length?ce:Ae})},[e.lastCompletedJobId,e.events,e.status,c]);let E=Gc(O=>O.global||!u||!O.routePathnames||O.routePathnames.length===0?!0:O.routePathnames.includes(u),[u]),$=Wg(()=>m.filter(E),[m,E]),Q=n&&($.length>0||d===!1),V=ui(null);uo(()=>{if(!Q)return;let O=V.current;if(!O)return;let Z=()=>{I(!0),o(!0)},pe=()=>{I(!1),o(!1),l?.(null)};return O.addEventListener("mouseenter",Z),O.addEventListener("mouseleave",pe),()=>{O.removeEventListener("mouseenter",Z),O.removeEventListener("mouseleave",pe)}},[Q,o,l]);let M=ui(new Map),B=Gc((O,Z)=>{Z?M.current.set(O,Z):M.current.delete(O)},[]);if(uo(()=>{if(!Q)return;let O=[];for(let Z of $){let pe=M.current.get(Z.jobId);if(pe){if(s){let Le=Z.jobId,_e=()=>s(Le);pe.addEventListener("click",_e),O.push(()=>pe.removeEventListener("click",_e))}if(l){let Le=Z.jobId,_e=()=>l(Le),ge=()=>l(null);pe.addEventListener("mouseenter",_e),pe.addEventListener("mouseleave",ge),O.push(()=>{pe.removeEventListener("mouseenter",_e),pe.removeEventListener("mouseleave",ge)})}}}return()=>O.forEach(Z=>Z())},[Q,$,s,l]),!Q)return null;let f={working:3,queued:2,error:1,done:0},g=[],j=new Map;for(let O of $){if(!O.threadId){g.push(O);continue}let Z=j.get(O.threadId);(!Z||f[O.status]>f[Z.status]||f[O.status]===f[Z.status])&&j.set(O.threadId,O)}for(let O of j.values())g.push(O);let fe=g.filter(O=>O.status==="queued"),Re=new Map;fe.forEach((O,Z)=>{Re.set(O.jobId,`(${Z+1}/${fe.length})`)});let le=!b&&g.length>1,Ce=ar(p),Ee=lr(p),K=Ce?g:[...g].reverse();return pi("div",{ref:V,style:C,"data-devtools":!0,children:[K.map((O,Z)=>{let pe=Z===g.length-1,Le=g.length-1-Z,_e=O.status==="working"?Vg(e.events.filter(ge=>ge.data.jobId===O.jobId)):O.status==="queued"?`Queued ${Re.get(O.jobId)??""}`:O.status==="done"?O.doneLabel||"Done":O.cancelled?"Cancelled":O.errorMessage?Ug(O.errorMessage):"Error";return _t("div",{style:{position:"relative",zIndex:g.length-Z,marginBottom:le?pe?0:-Jg:pe?0:Yg,transform:le?`scale(${Math.max(.94,1-Le*.02)})`:"scale(1)",opacity:1,transformOrigin:`${Ce?"top":"bottom"} ${Ee?"right":"left"}`,transition:"margin-bottom 250ms ease, transform 250ms ease, opacity 250ms ease"},children:_t("div",{ref:ge=>B(O.jobId,ge),style:{...Yc,position:"relative",overflow:"visible",cursor:s?"pointer":void 0},title:O.errorMessage||void 0,children:pi("div",{style:{display:"flex",alignItems:"center",gap:3,padding:"3px 5px 3px 8px",margin:0,backgroundColor:O.status==="error"?"#ef4444":O.color,color:"#ffffff"},children:[O.status==="working"&&_t(Xg,{color:"#ffffff"}),O.status==="queued"&&_t(qg,{color:"#ffffff"}),O.status==="done"&&_t(Zg,{color:"#ffffff"}),O.status==="error"&&_t(Qg,{}),_t("span",{style:{opacity:O.status==="queued"?.6:1,maxWidth:160,overflow:"hidden",textOverflow:"ellipsis"},children:_e}),O.status==="working"&&a&&_t(em,{onCancel:()=>a(O.jobId)}),(O.status==="done"||O.status==="error")&&_t(tm,{onDismiss:()=>v(ge=>ge.filter(lt=>O.threadId?lt.threadId!==O.threadId:lt.jobId!==O.jobId))})]})})},O.jobId)}),d===!1&&m.length>0&&_t("div",{style:Yc,children:pi("div",{style:{display:"flex",alignItems:"center",gap:3,padding:"3px 5px 3px 8px",margin:0,backgroundColor:"#f59e0b",color:"#ffffff"},children:[_t("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",backgroundColor:"#ffffff",opacity:.6}}),_t("span",{children:"Reconnecting\u2026"})]})})]})}import{Fragment as rm,jsx as om,jsxs as im}from"react/jsx-runtime";var nm=`
24
24
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
25
25
  :host {
26
26
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
@@ -49,9 +49,9 @@ Your AI gets the visual and technical context it needs to act.`,usage:[],keys:[{
49
49
  color: initial;
50
50
  -webkit-font-smoothing: auto;
51
51
  }
52
- `;function Mc({children:e}){return Mg(Tg,{children:[kg("style",{children:Eg}),e]})}import{useEffect as Ig,useLayoutEffect as Rg,useRef as Lg,useState as Ic}from"react";import{createPortal as Ag}from"react-dom";import{Fragment as Bg,jsx as Og,jsxs as Hg}from"react/jsx-runtime";function Pg(e){return e.tagName==="STYLE"||e.tagName==="LINK"&&e.rel==="stylesheet"}function Dg(e){let t=new Map,n=e.firstChild;function o(s){if(t.has(s)||s.hasAttribute("data-pm-mirror"))return;let a=s.cloneNode(!0);a.setAttribute("data-pm-mirror",""),e.insertBefore(a,n),t.set(s,a)}function r(s){let a=t.get(s);a&&(a.remove(),t.delete(s))}for(let s of document.querySelectorAll('link[rel="stylesheet"], style'))s.getRootNode()===document&&o(s);try{document.adoptedStyleSheets.length>0&&(e.adoptedStyleSheets=[...document.adoptedStyleSheets,...e.adoptedStyleSheets])}catch{}let i=new MutationObserver(s=>{for(let a of s)if(a.type==="childList"){for(let l of a.addedNodes)l instanceof Element&&Pg(l)&&o(l);for(let l of a.removedNodes)l instanceof Element&&r(l)}});return i.observe(document.head,{childList:!0}),document.body&&i.observe(document.body,{childList:!0}),()=>{i.disconnect();for(let s of t.values())s.remove();t.clear()}}function Rc({children:e}){let t=Lg(null),[n,o]=Ic(null),[r,i]=Ic(null);return Rg(()=>{let s=t.current;if(!s||s.shadowRoot)return;let a=s.attachShadow({mode:"open"}),l=document.createElement("div");l.setAttribute("data-popmelt-root",""),a.appendChild(l),o(a),i(l)},[]),Ig(()=>{if(n)return Dg(n)},[n]),Hg(Bg,{children:[Og("div",{ref:t,"data-popmelt-shadow-host":!0,style:{position:"absolute",width:0,height:0,overflow:"visible",zIndex:1e4}}),r&&Ag(e,r)]})}import{memo as jg,useCallback as Pr,useEffect as uo,useMemo as Lc,useRef as eo,useState as jn}from"react";import{jsx as Fe,jsxs as rr}from"react/jsx-runtime";var oa="ui-monospace, SFMono-Regular, Menlo, monospace",_g=0;function Ng({size:e=11}){let t=++_g,n=`pm-vs-m${t}`,o=`pm-vs-f0-${t}`,r=`pm-vs-f1-${t}`,i=`pm-vs-g${t}`;return rr("svg",{width:e,height:e,viewBox:"0 0 100 100",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{display:"inline",verticalAlign:"middle",marginLeft:3,flexShrink:0},children:[Fe("mask",{id:n,maskType:"alpha",maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"100",height:"100",children:Fe("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M70.9119 99.3171C72.4869 99.9307 74.2828 99.8914 75.8725 99.1264L96.4608 89.2197C98.6242 88.1787 100 85.9892 100 83.5872V16.4133C100 14.0113 98.6243 11.8218 96.4609 10.7808L75.8725 0.873756C73.7862 -0.130129 71.3446 0.11576 69.5135 1.44695C69.252 1.63711 69.0028 1.84943 68.769 2.08341L29.3551 38.0415L12.1872 25.0096C10.589 23.7965 8.35363 23.8959 6.86933 25.2461L1.36303 30.2549C-0.452552 31.9064 -0.454633 34.7627 1.35853 36.417L16.2471 50.0001L1.35853 63.5832C-0.454633 65.2374 -0.452552 68.0938 1.36303 69.7453L6.86933 74.7541C8.35363 76.1043 10.589 76.2037 12.1872 74.9905L29.3551 61.9587L68.769 97.9167C69.3925 98.5406 70.1246 99.0104 70.9119 99.3171ZM75.0152 27.2989L45.1091 50.0001L75.0152 72.7012V27.2989Z",fill:"white"})}),rr("g",{mask:`url(#${n})`,children:[Fe("path",{d:"M96.4614 10.7962L75.8569 0.875542C73.4719 -0.272773 70.6217 0.211611 68.75 2.08333L1.29858 63.5832C-0.515693 65.2373 -0.513607 68.0937 1.30308 69.7452L6.81272 74.754C8.29793 76.1042 10.5347 76.2036 12.1338 74.9905L93.3609 13.3699C96.086 11.3026 100 13.2462 100 16.6667V16.4275C100 14.0265 98.6246 11.8378 96.4614 10.7962Z",fill:"#0065A9"}),Fe("g",{filter:`url(#${o})`,children:Fe("path",{d:"M96.4614 89.2038L75.8569 99.1245C73.4719 100.273 70.6217 99.7884 68.75 97.9167L1.29858 36.4169C-0.515693 34.7627 -0.513607 31.9063 1.30308 30.2548L6.81272 25.246C8.29793 23.8958 10.5347 23.7964 12.1338 25.0095L93.3609 86.6301C96.086 88.6974 100 86.7538 100 83.3334V83.5726C100 85.9735 98.6246 88.1622 96.4614 89.2038Z",fill:"#007ACC"})}),Fe("g",{filter:`url(#${r})`,children:Fe("path",{d:"M75.8578 99.1263C73.4721 100.274 70.6219 99.7885 68.75 97.9166C71.0564 100.223 75 98.5895 75 95.3278V4.67213C75 1.41039 71.0564 -0.223106 68.75 2.08329C70.6219 0.211402 73.4721 -0.273666 75.8578 0.873633L96.4587 10.7807C98.6234 11.8217 100 14.0112 100 16.4132V83.5871C100 85.9891 98.6234 88.1786 96.4586 89.2196L75.8578 99.1263Z",fill:"#1F9CF0"})}),Fe("g",{style:{mixBlendMode:"overlay"},opacity:"0.25",children:Fe("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M70.8511 99.3171C72.4261 99.9306 74.2221 99.8913 75.8117 99.1264L96.4 89.2197C98.5634 88.1787 99.9392 85.9892 99.9392 83.5871V16.4133C99.9392 14.0112 98.5635 11.8217 96.4001 10.7807L75.8117 0.873695C73.7255 -0.13019 71.2838 0.115699 69.4527 1.44688C69.1912 1.63705 68.942 1.84937 68.7082 2.08335L29.2943 38.0414L12.1264 25.0096C10.5283 23.7964 8.29285 23.8959 6.80855 25.246L1.30225 30.2548C-0.513334 31.9064 -0.515415 34.7627 1.29775 36.4169L16.1863 50L1.29775 63.5832C-0.515415 65.2374 -0.513334 68.0937 1.30225 69.7452L6.80855 74.754C8.29285 76.1042 10.5283 76.2036 12.1264 74.9905L29.2943 61.9586L68.7082 97.9167C69.3317 98.5405 70.0638 99.0104 70.8511 99.3171ZM74.9544 27.2989L45.0483 50L74.9544 72.7012V27.2989Z",fill:`url(#${i})`})})]}),rr("defs",{children:[rr("filter",{id:o,x:"-8.39411",y:"15.8291",width:"116.727",height:"92.2456",filterUnits:"userSpaceOnUse",colorInterpolationFilters:"sRGB",children:[Fe("feFlood",{floodOpacity:"0",result:"BackgroundImageFix"}),Fe("feColorMatrix",{in:"SourceAlpha",type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"}),Fe("feOffset",{}),Fe("feGaussianBlur",{stdDeviation:"4.16667"}),Fe("feColorMatrix",{type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"}),Fe("feBlend",{mode:"overlay",in2:"BackgroundImageFix",result:"effect1_dropShadow"}),Fe("feBlend",{mode:"normal",in:"SourceGraphic",in2:"effect1_dropShadow",result:"shape"})]}),rr("filter",{id:r,x:"60.4167",y:"-8.07558",width:"47.9167",height:"116.151",filterUnits:"userSpaceOnUse",colorInterpolationFilters:"sRGB",children:[Fe("feFlood",{floodOpacity:"0",result:"BackgroundImageFix"}),Fe("feColorMatrix",{in:"SourceAlpha",type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"}),Fe("feOffset",{}),Fe("feGaussianBlur",{stdDeviation:"4.16667"}),Fe("feColorMatrix",{type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"}),Fe("feBlend",{mode:"overlay",in2:"BackgroundImageFix",result:"effect1_dropShadow"}),Fe("feBlend",{mode:"normal",in:"SourceGraphic",in2:"effect1_dropShadow",result:"shape"})]}),rr("linearGradient",{id:i,x1:"49.9392",y1:"0.257812",x2:"49.9392",y2:"99.7423",gradientUnits:"userSpaceOnUse",children:[Fe("stop",{stopColor:"white"}),Fe("stop",{offset:"1",stopColor:"white",stopOpacity:"0"})]})]})]})}var Fg=/^#[0-9a-fA-F]{3,8}$/,zg=/^(?:rgba?|hsla?|oklch)\([^)]+\)$/,$g=new Set(["black","white","red","blue","green","yellow","orange","purple","pink","gray","grey","cyan","magenta","brown","navy","teal","maroon","olive","silver","aqua","fuchsia","lime"]);function Wg(e){let t=e.trim();return Fg.test(t)||zg.test(t)||$g.has(t.toLowerCase())}function na(e,t){return Fe("span",{style:{display:"inline-block",width:10,height:10,backgroundColor:e,border:"1px solid rgba(0,0,0,0.15)",borderRadius:2,verticalAlign:"middle",marginRight:3}},t)}function Ur(e){let t=[],n=/(`[^`]+`)|(\*\*\*(.+?)\*\*\*)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_([^_]+?)_)|(\[([^\]]+)\]\(([^)]+)\))|(#[0-9a-fA-F]{3,8})(?![0-9a-fA-F])|((?:rgba?|hsla?|oklch)\([^)]+\))/g,o=0,r;for(;(r=n.exec(e))!==null;){if(r.index>o&&t.push(e.slice(o,r.index)),r[1]){let i=r[1].slice(1,-1);Wg(i)&&t.push(na(i,`sw-${r.index}`)),t.push(Fe("code",{style:{fontFamily:oa,fontSize:"0.9em",backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",borderRadius:2},children:i},r.index))}else if(r[3]!==void 0)t.push(Fe("strong",{children:Fe("em",{children:r[3]})},r.index));else if(r[5]!==void 0)t.push(Fe("strong",{children:r[5]},r.index));else if(r[7]!==void 0)t.push(Fe("em",{children:r[7]},r.index));else if(r[9]!==void 0)t.push(Fe("em",{children:r[9]},r.index));else if(r[11]!==void 0&&r[12]!==void 0){let i=r[12],s=!/^https?:\/\/|^mailto:/i.test(i),a=s?`vscode://file/${i}`:i;s?t.push(rr("a",{href:a,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline",whiteSpace:"nowrap",backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",borderRadius:2,fontFamily:oa,fontSize:"0.9em"},children:[r[11],Fe(Ng,{})]},r.index)):t.push(Fe("a",{href:a,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline"},children:r[11]},r.index))}else r[13]!==void 0?(t.push(na(r[13],`sw-${r.index}`)),t.push(r[13])):r[14]!==void 0&&(t.push(na(r[14],`sw-${r.index}`)),t.push(r[14]));o=r.index+r[0].length}return o<e.length&&t.push(e.slice(o)),t}function co(e){let t=e.split(`
53
- `),n=[],o=0;for(;o<t.length;){let r=t[o];if(r.trimStart().startsWith("```")){let l=[];for(o++;o<t.length&&!t[o].trimStart().startsWith("```");)l.push(t[o]),o++;o++,n.push(Fe("pre",{style:{fontFamily:oa,fontSize:"0.9em",lineHeight:1.4,backgroundColor:"rgba(0,0,0,0.04)",padding:"6px 8px",margin:"4px 0",overflowX:"auto",whiteSpace:"pre"},children:l.join(`
54
- `)},n.length));continue}if(/^(-{3,}|\*{3,}|_{3,})\s*$/.test(r)){n.push(Fe("hr",{style:{border:"none",borderTop:"1px solid rgba(0,0,0,0.1)",margin:"6px 0"}},n.length)),o++;continue}let i=r.match(/^(#{1,4})\s+(.+)/);if(i){let l=i[1].length,p={1:16,2:14,3:13,4:12};n.push(Fe("div",{style:{fontWeight:700,fontSize:p[l]??12,margin:"8px 0 2px"},children:Ur(i[2])},n.length)),o++;continue}if(r.trimStart().startsWith("|")&&r.trimEnd().endsWith("|")){let l=[];for(;o<t.length&&t[o].trimStart().startsWith("|")&&t[o].trimEnd().endsWith("|");)l.push(t[o]),o++;let p=I=>/^\|[\s\-:|]+\|$/.test(I),c=l.filter(I=>!p(I)),u=I=>I.split("|").slice(1,-1).map(O=>O.trim()),d=I=>/^\*\*.+\*\*$/.test(I)||/^__.+__$/.test(I),g=c.map(u),x=g.length>1&&g.slice(1).every(I=>I[0]&&d(I[0])),h=g.length>0&&g[0].every(I=>d(I));n.push(Fe("div",{style:{overflowX:"auto",margin:"4px 0",paddingBottom:4},children:Fe("table",{style:{borderCollapse:"separate",borderSpacing:0,fontSize:"0.95em",width:"max-content",minWidth:"100%"},children:Fe("tbody",{children:c.map((I,O)=>Fe("tr",{children:u(I).map((P,F)=>Fe(O===0?"th":"td",{style:{border:"1px solid rgba(0,0,0,0.1)",padding:"3px 6px",textAlign:"left",fontWeight:O===0?600:400,minWidth:60,whiteSpace:"nowrap",...F===0&&x||O===0&&h?{position:"sticky",...F===0&&x?{left:0}:{},...O===0&&h?{top:0}:{},background:"#fff",zIndex:F===0&&x&&O===0&&h?2:1}:{}},children:Ur(P)},F))},O))})})},n.length));continue}if(r.match(/^(\s*)([-*])\s+(.+)/)){let l=[];for(;o<t.length;){let p=t[o].match(/^\s*[-*]\s+(.+)/);if(p)l.push(p[1]),o++;else if(l.length>0&&t[o].match(/^\s+\S/)&&!t[o].match(/^\s*\d+\.\s/)&&!t[o].match(/^\s*[-*]\s+/))l[l.length-1]+=" "+t[o].trim(),o++;else break}n.push(Fe("ul",{style:{margin:0,paddingLeft:20,listStyleType:"disc",display:"flex",flexDirection:"column",gap:8},children:l.map((p,c)=>Fe("li",{children:Ur(p)},c))},n.length));continue}let a=r.match(/^(\s*)(\d+)\.\s+(.+)/);if(a){let l=a[1].length,p=parseInt(a[2],10)||1,c=[],u=null;for(;o<t.length;){let d=t[o],g=d.match(/^(\s*)(\d+)\.\s+(.+)/);if(g&&g[1].length===l)u=[g[3]],c.push(u),o++;else if(u&&d.trim()==="")o++;else if(c.length>0&&t[o].match(/^\s+\S/)&&!t[o].match(/^\s*\d+\.\s/)&&!t[o].match(/^\s*[-*]\s+/))u.push(t[o].trim()),o++;else if(u&&/^(Eval|Checks|Sources|Rationale|Prompt|Assertions?|Reason|Why|Expected|Notes?):/i.test(d.trim()))u.push(d.trim()),o++;else if(u&&u.length>1&&d.trim()&&!d.match(/^(#{1,4})\s+/)&&!d.trimStart().startsWith("|")&&!d.match(/^\s*[-*]\s+/)&&!d.match(/^\s*\d+\.\s+/)&&!/^(\*\*)?[A-Z][A-Za-z /&-]{2,40}(\*\*)?$/.test(d.trim()))u.push(d.trim()),o++;else break}n.push(Fe("ol",{start:p,style:{margin:0,paddingLeft:20,listStyleType:"decimal",display:"flex",flexDirection:"column",gap:8},children:c.map((d,g)=>Fe("li",{children:Fe("div",{style:{display:"flex",flexDirection:"column",gap:6},children:d.map((x,h)=>Fe("div",{children:Ur(x)},h))})},g))},n.length));continue}if(r.trim()===""){o++;continue}n.push(Fe("div",{children:Ur(r)},n.length)),o++}return Fe("div",{style:{display:"flex",flexDirection:"column",gap:8},children:n})}import{Fragment as Bo,jsx as q,jsxs as Ue}from"react/jsx-runtime";var Dc=400,vn=16,Oc=3,Gg=3,Bc=4,Jg=8,Yg="devtools-thread-panel-position",Dr=Dc+2*Oc+2*Bc,Vg=Dr+2*Gg;function ra(e="right"){return{top:vn,left:e==="left"?vn:window.innerWidth-Dr-vn}}function Ac(e,t,n){let o=n?.getBoundingClientRect(),r=2*Oc+2*Bc,i=window.innerHeight-vn-r;return o&&t+Vg>o.left&&(i=o.top-Jg-r),Math.max(200,i-Math.max(0,e))}var Ug={width:Dc,backgroundColor:"#eaeaea",borderWidth:3,borderStyle:"solid",borderColor:"transparent",boxSizing:"content-box",display:"flex",flexDirection:"column",overflow:"visible",padding:4,fontFamily:Vt,fontSize:12,color:"#1f2937",pointerEvents:"auto"},Kg={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 5px 4px 10px",margin:0,fontWeight:600,fontSize:12,overflow:"hidden"},Xg={flex:1,overflowY:"auto",padding:0,scrollbarWidth:"none"},qg=`
52
+ `;function Kc({children:e}){return im(rm,{children:[om("style",{children:nm}),e]})}import{useEffect as sm,useLayoutEffect as am,useRef as lm,useState as Xc}from"react";import{createPortal as cm}from"react-dom";import{Fragment as fm,jsx as pm,jsxs as gm}from"react/jsx-runtime";function dm(e){return e.tagName==="STYLE"||e.tagName==="LINK"&&e.rel==="stylesheet"}function um(e){let t=new Map,n=e.firstChild;function o(s){if(t.has(s)||s.hasAttribute("data-pm-mirror"))return;let a=s.cloneNode(!0);a.setAttribute("data-pm-mirror",""),e.insertBefore(a,n),t.set(s,a)}function r(s){let a=t.get(s);a&&(a.remove(),t.delete(s))}for(let s of document.querySelectorAll('link[rel="stylesheet"], style'))s.getRootNode()===document&&o(s);try{document.adoptedStyleSheets.length>0&&(e.adoptedStyleSheets=[...document.adoptedStyleSheets,...e.adoptedStyleSheets])}catch{}let i=new MutationObserver(s=>{for(let a of s)if(a.type==="childList"){for(let l of a.addedNodes)l instanceof Element&&dm(l)&&o(l);for(let l of a.removedNodes)l instanceof Element&&r(l)}});return i.observe(document.head,{childList:!0}),document.body&&i.observe(document.body,{childList:!0}),()=>{i.disconnect();for(let s of t.values())s.remove();t.clear()}}function qc({children:e}){let t=lm(null),[n,o]=Xc(null),[r,i]=Xc(null);return am(()=>{let s=t.current;if(!s||s.shadowRoot)return;let a=s.attachShadow({mode:"open"}),l=document.createElement("div");l.setAttribute("data-popmelt-root",""),a.appendChild(l),o(a),i(l)},[]),sm(()=>{if(n)return um(n)},[n]),gm(fm,{children:[pm("div",{ref:t,"data-popmelt-shadow-host":!0,style:{position:"absolute",width:0,height:0,overflow:"visible",zIndex:1e4}}),r&&cm(e,r)]})}import{memo as Sm,useCallback as Yr,useEffect as So,useMemo as Zc,useRef as Vn,useState as Qn}from"react";import{jsx as $e,jsxs as Sr}from"react/jsx-runtime";var Ta="ui-monospace, SFMono-Regular, Menlo, monospace",mm=0;function hm({size:e=11}){let t=++mm,n=`pm-vs-m${t}`,o=`pm-vs-f0-${t}`,r=`pm-vs-f1-${t}`,i=`pm-vs-g${t}`;return Sr("svg",{width:e,height:e,viewBox:"0 0 100 100",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{display:"inline",verticalAlign:"middle",marginLeft:3,flexShrink:0},children:[$e("mask",{id:n,maskType:"alpha",maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"100",height:"100",children:$e("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M70.9119 99.3171C72.4869 99.9307 74.2828 99.8914 75.8725 99.1264L96.4608 89.2197C98.6242 88.1787 100 85.9892 100 83.5872V16.4133C100 14.0113 98.6243 11.8218 96.4609 10.7808L75.8725 0.873756C73.7862 -0.130129 71.3446 0.11576 69.5135 1.44695C69.252 1.63711 69.0028 1.84943 68.769 2.08341L29.3551 38.0415L12.1872 25.0096C10.589 23.7965 8.35363 23.8959 6.86933 25.2461L1.36303 30.2549C-0.452552 31.9064 -0.454633 34.7627 1.35853 36.417L16.2471 50.0001L1.35853 63.5832C-0.454633 65.2374 -0.452552 68.0938 1.36303 69.7453L6.86933 74.7541C8.35363 76.1043 10.589 76.2037 12.1872 74.9905L29.3551 61.9587L68.769 97.9167C69.3925 98.5406 70.1246 99.0104 70.9119 99.3171ZM75.0152 27.2989L45.1091 50.0001L75.0152 72.7012V27.2989Z",fill:"white"})}),Sr("g",{mask:`url(#${n})`,children:[$e("path",{d:"M96.4614 10.7962L75.8569 0.875542C73.4719 -0.272773 70.6217 0.211611 68.75 2.08333L1.29858 63.5832C-0.515693 65.2373 -0.513607 68.0937 1.30308 69.7452L6.81272 74.754C8.29793 76.1042 10.5347 76.2036 12.1338 74.9905L93.3609 13.3699C96.086 11.3026 100 13.2462 100 16.6667V16.4275C100 14.0265 98.6246 11.8378 96.4614 10.7962Z",fill:"#0065A9"}),$e("g",{filter:`url(#${o})`,children:$e("path",{d:"M96.4614 89.2038L75.8569 99.1245C73.4719 100.273 70.6217 99.7884 68.75 97.9167L1.29858 36.4169C-0.515693 34.7627 -0.513607 31.9063 1.30308 30.2548L6.81272 25.246C8.29793 23.8958 10.5347 23.7964 12.1338 25.0095L93.3609 86.6301C96.086 88.6974 100 86.7538 100 83.3334V83.5726C100 85.9735 98.6246 88.1622 96.4614 89.2038Z",fill:"#007ACC"})}),$e("g",{filter:`url(#${r})`,children:$e("path",{d:"M75.8578 99.1263C73.4721 100.274 70.6219 99.7885 68.75 97.9166C71.0564 100.223 75 98.5895 75 95.3278V4.67213C75 1.41039 71.0564 -0.223106 68.75 2.08329C70.6219 0.211402 73.4721 -0.273666 75.8578 0.873633L96.4587 10.7807C98.6234 11.8217 100 14.0112 100 16.4132V83.5871C100 85.9891 98.6234 88.1786 96.4586 89.2196L75.8578 99.1263Z",fill:"#1F9CF0"})}),$e("g",{style:{mixBlendMode:"overlay"},opacity:"0.25",children:$e("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M70.8511 99.3171C72.4261 99.9306 74.2221 99.8913 75.8117 99.1264L96.4 89.2197C98.5634 88.1787 99.9392 85.9892 99.9392 83.5871V16.4133C99.9392 14.0112 98.5635 11.8217 96.4001 10.7807L75.8117 0.873695C73.7255 -0.13019 71.2838 0.115699 69.4527 1.44688C69.1912 1.63705 68.942 1.84937 68.7082 2.08335L29.2943 38.0414L12.1264 25.0096C10.5283 23.7964 8.29285 23.8959 6.80855 25.246L1.30225 30.2548C-0.513334 31.9064 -0.515415 34.7627 1.29775 36.4169L16.1863 50L1.29775 63.5832C-0.515415 65.2374 -0.513334 68.0937 1.30225 69.7452L6.80855 74.754C8.29285 76.1042 10.5283 76.2036 12.1264 74.9905L29.2943 61.9586L68.7082 97.9167C69.3317 98.5405 70.0638 99.0104 70.8511 99.3171ZM74.9544 27.2989L45.0483 50L74.9544 72.7012V27.2989Z",fill:`url(#${i})`})})]}),Sr("defs",{children:[Sr("filter",{id:o,x:"-8.39411",y:"15.8291",width:"116.727",height:"92.2456",filterUnits:"userSpaceOnUse",colorInterpolationFilters:"sRGB",children:[$e("feFlood",{floodOpacity:"0",result:"BackgroundImageFix"}),$e("feColorMatrix",{in:"SourceAlpha",type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"}),$e("feOffset",{}),$e("feGaussianBlur",{stdDeviation:"4.16667"}),$e("feColorMatrix",{type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"}),$e("feBlend",{mode:"overlay",in2:"BackgroundImageFix",result:"effect1_dropShadow"}),$e("feBlend",{mode:"normal",in:"SourceGraphic",in2:"effect1_dropShadow",result:"shape"})]}),Sr("filter",{id:r,x:"60.4167",y:"-8.07558",width:"47.9167",height:"116.151",filterUnits:"userSpaceOnUse",colorInterpolationFilters:"sRGB",children:[$e("feFlood",{floodOpacity:"0",result:"BackgroundImageFix"}),$e("feColorMatrix",{in:"SourceAlpha",type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"}),$e("feOffset",{}),$e("feGaussianBlur",{stdDeviation:"4.16667"}),$e("feColorMatrix",{type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"}),$e("feBlend",{mode:"overlay",in2:"BackgroundImageFix",result:"effect1_dropShadow"}),$e("feBlend",{mode:"normal",in:"SourceGraphic",in2:"effect1_dropShadow",result:"shape"})]}),Sr("linearGradient",{id:i,x1:"49.9392",y1:"0.257812",x2:"49.9392",y2:"99.7423",gradientUnits:"userSpaceOnUse",children:[$e("stop",{stopColor:"white"}),$e("stop",{offset:"1",stopColor:"white",stopOpacity:"0"})]})]})]})}var ym=/^#[0-9a-fA-F]{3,8}$/,bm=/^(?:rgba?|hsla?|oklch)\([^)]+\)$/,vm=new Set(["black","white","red","blue","green","yellow","orange","purple","pink","gray","grey","cyan","magenta","brown","navy","teal","maroon","olive","silver","aqua","fuchsia","lime"]);function xm(e){let t=e.trim();return ym.test(t)||bm.test(t)||vm.has(t.toLowerCase())}function Ea(e,t){return $e("span",{style:{display:"inline-block",width:10,height:10,backgroundColor:e,border:"1px solid rgba(0,0,0,0.15)",borderRadius:2,verticalAlign:"middle",marginRight:3}},t)}function fi(e){let t=[],n=/(`[^`]+`)|(\*\*\*(.+?)\*\*\*)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_([^_]+?)_)|(\[([^\]]+)\]\(([^)]+)\))|(#[0-9a-fA-F]{3,8})(?![0-9a-fA-F])|((?:rgba?|hsla?|oklch)\([^)]+\))/g,o=0,r;for(;(r=n.exec(e))!==null;){if(r.index>o&&t.push(e.slice(o,r.index)),r[1]){let i=r[1].slice(1,-1);xm(i)&&t.push(Ea(i,`sw-${r.index}`)),t.push($e("code",{style:{fontFamily:Ta,fontSize:"0.9em",backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",borderRadius:2},children:i},r.index))}else if(r[3]!==void 0)t.push($e("strong",{children:$e("em",{children:r[3]})},r.index));else if(r[5]!==void 0)t.push($e("strong",{children:r[5]},r.index));else if(r[7]!==void 0)t.push($e("em",{children:r[7]},r.index));else if(r[9]!==void 0)t.push($e("em",{children:r[9]},r.index));else if(r[11]!==void 0&&r[12]!==void 0){let i=r[12],s=!/^https?:\/\/|^mailto:/i.test(i),a=s?`vscode://file/${i}`:i;s?t.push(Sr("a",{href:a,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline",whiteSpace:"nowrap",backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",borderRadius:2,fontFamily:Ta,fontSize:"0.9em"},children:[r[11],$e(hm,{})]},r.index)):t.push($e("a",{href:a,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline"},children:r[11]},r.index))}else r[13]!==void 0?(t.push(Ea(r[13],`sw-${r.index}`)),t.push(r[13])):r[14]!==void 0&&(t.push(Ea(r[14],`sw-${r.index}`)),t.push(r[14]));o=r.index+r[0].length}return o<e.length&&t.push(e.slice(o)),t}function xo(e){let t=e.split(`
53
+ `),n=[],o=0;for(;o<t.length;){let r=t[o];if(r.trimStart().startsWith("```")){let l=[];for(o++;o<t.length&&!t[o].trimStart().startsWith("```");)l.push(t[o]),o++;o++,n.push($e("pre",{style:{fontFamily:Ta,fontSize:"0.9em",lineHeight:1.4,backgroundColor:"rgba(0,0,0,0.04)",padding:"6px 8px",margin:"4px 0",overflowX:"auto",whiteSpace:"pre"},children:l.join(`
54
+ `)},n.length));continue}if(/^(-{3,}|\*{3,}|_{3,})\s*$/.test(r)){n.push($e("hr",{style:{border:"none",borderTop:"1px solid rgba(0,0,0,0.1)",margin:"6px 0"}},n.length)),o++;continue}let i=r.match(/^(#{1,4})\s+(.+)/);if(i){let l=i[1].length,d={1:16,2:14,3:13,4:12};n.push($e("div",{style:{fontWeight:700,fontSize:d[l]??12,margin:"8px 0 2px"},children:fi(i[2])},n.length)),o++;continue}if(r.trimStart().startsWith("|")&&r.trimEnd().endsWith("|")){let l=[];for(;o<t.length&&t[o].trimStart().startsWith("|")&&t[o].trimEnd().endsWith("|");)l.push(t[o]),o++;let d=I=>/^\|[\s\-:|]+\|$/.test(I),c=l.filter(I=>!d(I)),p=I=>I.split("|").slice(1,-1).map(P=>P.trim()),u=I=>/^\*\*.+\*\*$/.test(I)||/^__.+__$/.test(I),m=c.map(p),v=m.length>1&&m.slice(1).every(I=>I[0]&&u(I[0])),b=m.length>0&&m[0].every(I=>u(I));n.push($e("div",{style:{overflowX:"auto",margin:"4px 0",paddingBottom:4},children:$e("table",{style:{borderCollapse:"separate",borderSpacing:0,fontSize:"0.95em",width:"max-content",minWidth:"100%"},children:$e("tbody",{children:c.map((I,P)=>$e("tr",{children:p(I).map((N,C)=>$e(P===0?"th":"td",{style:{border:"1px solid rgba(0,0,0,0.1)",padding:"3px 6px",textAlign:"left",fontWeight:P===0?600:400,minWidth:60,whiteSpace:"nowrap",...C===0&&v||P===0&&b?{position:"sticky",...C===0&&v?{left:0}:{},...P===0&&b?{top:0}:{},background:"#fff",zIndex:C===0&&v&&P===0&&b?2:1}:{}},children:fi(N)},C))},P))})})},n.length));continue}if(r.match(/^(\s*)([-*])\s+(.+)/)){let l=[];for(;o<t.length;){let d=t[o].match(/^\s*[-*]\s+(.+)/);if(d)l.push(d[1]),o++;else if(l.length>0&&t[o].match(/^\s+\S/)&&!t[o].match(/^\s*\d+\.\s/)&&!t[o].match(/^\s*[-*]\s+/))l[l.length-1]+=" "+t[o].trim(),o++;else break}n.push($e("ul",{style:{margin:0,paddingLeft:20,listStyleType:"disc",display:"flex",flexDirection:"column",gap:8},children:l.map((d,c)=>$e("li",{children:fi(d)},c))},n.length));continue}let a=r.match(/^(\s*)(\d+)\.\s+(.+)/);if(a){let l=a[1].length,d=parseInt(a[2],10)||1,c=[],p=null;for(;o<t.length;){let u=t[o],m=u.match(/^(\s*)(\d+)\.\s+(.+)/);if(m&&m[1].length===l)p=[m[3]],c.push(p),o++;else if(p&&u.trim()==="")o++;else if(c.length>0&&t[o].match(/^\s+\S/)&&!t[o].match(/^\s*\d+\.\s/)&&!t[o].match(/^\s*[-*]\s+/))p.push(t[o].trim()),o++;else if(p&&/^(Eval|Checks|Sources|Rationale|Prompt|Assertions?|Reason|Why|Expected|Notes?):/i.test(u.trim()))p.push(u.trim()),o++;else if(p&&p.length>1&&u.trim()&&!u.match(/^(#{1,4})\s+/)&&!u.trimStart().startsWith("|")&&!u.match(/^\s*[-*]\s+/)&&!u.match(/^\s*\d+\.\s+/)&&!/^(\*\*)?[A-Z][A-Za-z /&-]{2,40}(\*\*)?$/.test(u.trim()))p.push(u.trim()),o++;else break}n.push($e("ol",{start:d,style:{margin:0,paddingLeft:20,listStyleType:"decimal",display:"flex",flexDirection:"column",gap:8},children:c.map((u,m)=>$e("li",{children:$e("div",{style:{display:"flex",flexDirection:"column",gap:6},children:u.map((v,b)=>$e("div",{children:fi(v)},b))})},m))},n.length));continue}if(r.trim()===""){o++;continue}n.push($e("div",{children:fi(r)},n.length)),o++}return $e("div",{style:{display:"flex",flexDirection:"column",gap:8},children:n})}import{Fragment as Vo,jsx as ee,jsxs as Ke}from"react/jsx-runtime";var td=400,Ln=16,nd=3,wm=3,od=4,Cm=8,Em="devtools-thread-panel-position",Vr=td+2*nd+2*od,Tm=Vr+2*wm;function ka(e="right"){return{top:Ln,left:e==="left"?Ln:window.innerWidth-Vr-Ln}}function Qc(e,t,n){let o=n?.getBoundingClientRect(),r=2*nd+2*od,i=window.innerHeight-Ln-r;return o&&t+Tm>o.left&&(i=o.top-Cm-r),Math.max(200,i-Math.max(0,e))}var km={width:td,backgroundColor:"#eaeaea",borderWidth:3,borderStyle:"solid",borderColor:"transparent",boxSizing:"content-box",display:"flex",flexDirection:"column",overflow:"visible",padding:4,fontFamily:vn,fontSize:12,color:"#1f2937",pointerEvents:"auto"},Mm={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 5px 4px 10px",margin:0,fontWeight:600,fontSize:12,overflow:"hidden"},Im={flex:1,overflowY:"auto",padding:0,scrollbarWidth:"none"},Rm=`
55
55
  [data-devtools="thread-panel-messages"]:hover {
56
56
  scrollbar-width: thin !important;
57
57
  }
@@ -65,15 +65,15 @@ Your AI gets the visual and technical context it needs to act.`,usage:[],keys:[{
65
65
  background: rgba(0,0,0,0.15);
66
66
  border-radius: 3px;
67
67
  }
68
- `,Zg={borderTop:"1px solid rgba(0, 0, 0, 0.12)",display:"flex",alignItems:"center",gap:4,padding:"0 8px 0 10px"};function zi(e){return e.replace(/<resolution>[\s\S]*?<\/resolution>/g,"").replace(/<question>[\s\S]*?<\/question>/g,"").replace(/<plan>[\s\S]*?<\/plan>/g,"").replace(/<review>[\s\S]*?<\/review>/g,"").replace(/<novel>[\s\S]*?<\/novel>/g,"").replace(/<eval_proposals>[\s\S]*?<\/eval_proposals>/g,"").replace(/<eval_run_result>[\s\S]*?<\/eval_run_result>/g,"").replace(/<evals>[\s\S]*?<\/evals>/g,"").trim()}function Qg(e){return e.split(`
68
+ `,Lm={borderTop:"1px solid rgba(0, 0, 0, 0.12)",display:"flex",alignItems:"center",gap:4,padding:"0 8px 0 10px"};function as(e){return e.replace(/<resolution>[\s\S]*?<\/resolution>/g,"").replace(/<question>[\s\S]*?<\/question>/g,"").replace(/<plan>[\s\S]*?<\/plan>/g,"").replace(/<review>[\s\S]*?<\/review>/g,"").replace(/<novel>[\s\S]*?<\/novel>/g,"").replace(/<eval_proposals>[\s\S]*?<\/eval_proposals>/g,"").replace(/<eval_run_result>[\s\S]*?<\/eval_run_result>/g,"").replace(/<evals>[\s\S]*?<\/evals>/g,"").trim()}function Am(e){return e.split(`
69
69
  `).filter(t=>!/^\s*[☑☒□]\s*(pass|fail|needs[_ ]review)\b/i.test(t)).join(`
70
70
  `).replace(/\n{3,}/g,`
71
71
 
72
- `).trim()}function em(e){let t=e.match(/<novel>\s*([\s\S]*?)\s*<\/novel>/);if(!t?.[1])return[];try{let n=JSON.parse(t[1]);return Array.isArray(n)?n.filter(o=>{if(typeof o!="object"||o===null)return!1;let r=o;return typeof r.category=="string"&&typeof r.element=="string"&&typeof r.decision=="string"&&typeof r.reason=="string"}):[]}catch{return[]}}function tm(e){let t=e.match(/<eval_run_result>\s*([\s\S]*?)\s*<\/eval_run_result>/);if(!t?.[1])return null;try{let n=JSON.parse(t[1]);if(!n||typeof n!="object")return null;let o=n,r=o.status,i=r==="pass"||r==="fail"||r==="needs_review"?r:"needs_review",a=(Array.isArray(o.assertionResults)?o.assertionResults:[]).flatMap(l=>{if(!l||typeof l!="object")return[];let p=l,c=typeof p.assertion=="string"?p.assertion.trim():"";if(!c)return[];let u=p.status;return[{assertion:c,status:u==="pass"||u==="fail"||u==="needs_review"?u:"needs_review",summary:typeof p.summary=="string"?p.summary.trim():""}]});return{title:typeof o.title=="string"?o.title.trim():void 0,status:i,summary:typeof o.summary=="string"?o.summary.trim():"",assertionResults:a}}catch{return null}}function nm(e){return e?{title:e.title,status:e.status,summary:e.summary,assertionResults:e.assertionResults.map(t=>({assertion:t.assertion,status:t.status,summary:t.summary}))}:null}function om({result:e}){let t=e.assertionResults;if(t.length===0)return null;let n=e.status==="pass"?"Pass":e.status==="fail"?"Fail":"Needs review",o=e.status==="pass"?"#047857":e.status==="fail"?"#b91c1c":"#6b7280";return Ue("div",{style:{padding:"8px 16px",backgroundColor:"rgba(0, 0, 0, 0.03)",fontSize:11,lineHeight:1.35,color:"#374151"},children:[Ue("div",{style:{display:"flex",alignItems:"baseline",gap:6,marginBottom:7},children:[q("span",{style:{fontWeight:700,color:"#111827"},children:e.title??"Eval result"}),q("span",{style:{color:o,fontWeight:700,marginLeft:"auto"},children:n})]}),e.summary&&q("div",{style:{color:"#6b7280",marginBottom:8},children:e.summary}),q("div",{style:{display:"flex",flexDirection:"column",gap:6},children:t.map((r,i)=>{let s=r.status==="pass"?"\u2611":r.status==="fail"?"\u2612":"\u25A1",a=r.status==="pass"?"Pass":r.status==="fail"?"Fail":"Needs review",l=r.status==="pass"?"#047857":r.status==="fail"?"#b91c1c":"#6b7280",p=r.status==="needs_review"?"inherit":l;return Ue("div",{style:{display:"grid",gridTemplateColumns:"18px minmax(0, 1fr)",columnGap:5,alignItems:"start"},children:[q("span",{style:{color:l,fontSize:15,lineHeight:1},children:s}),Ue("div",{style:{minWidth:0},children:[q("div",{style:{color:p},children:r.assertion}),r.status==="needs_review"?Ue("div",{style:{marginTop:1,color:"#6b7280"},children:[q("span",{style:{color:l,fontWeight:700},children:a}),r.summary?Ue("span",{children:[": ",r.summary]}):null]}):r.summary?q("div",{style:{marginTop:1,color:"#6b7280"},children:r.summary}):null]})]},`${r.assertion}-${i}`)})})]})}function Pc(e){return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}var ia=["reviewing","considering","thinking","zhuzhing","iterating","tweaking","reflecting","noodling","pondering","finessing","polishing","riffing"],rm=3e3,im=250;function sm({color:e}){let[t,n]=jn(0),[o,r]=jn(()=>Math.floor(Math.random()*ia.length));return uo(()=>{let i=setInterval(()=>n(a=>(a+1)%2),im),s=setInterval(()=>r(a=>(a+1)%ia.length),rm);return()=>{clearInterval(i),clearInterval(s)}},[]),Ue("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[q("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:e,style:{verticalAlign:"middle",flexShrink:0},children:t===1?Ue(Bo,{children:[q("circle",{cx:"7",cy:"7",r:"2"}),q("circle",{cx:"17",cy:"7",r:"2"}),q("circle",{cx:"7",cy:"17",r:"2"}),q("circle",{cx:"17",cy:"17",r:"2"})]}):Ue(Bo,{children:[q("circle",{cx:"12",cy:"6",r:"2"}),q("circle",{cx:"6",cy:"12",r:"2"}),q("circle",{cx:"18",cy:"12",r:"2"}),q("circle",{cx:"12",cy:"18",r:"2"})]})}),q("span",{style:{fontSize:11,color:"#9ca3af",fontStyle:"italic"},children:ia[o]})]})}var $i=32,Fi={width:$i,height:$i,objectFit:"cover",cursor:"pointer",border:"1px solid rgba(0,0,0,0.1)"};function am(e){let t=/^`(\/[^`]*)`$/gm,n=[...e.matchAll(t)];if(n.length===0)return null;let o=[];for(let r=0;r<n.length;r++){let i=n[r],s=i[1],a=i.index+i[0].length,l=r+1<n.length?n[r+1].index:e.length,p=e.slice(a,l).trim();o.push({route:s,text:p})}return o}function lm(e,t){let n=[];if(e.replyImageUrls)for(let o of e.replyImageUrls){let r=o.startsWith("blob:")||o.startsWith("http")?o:`${t}${o}`;n.push({url:r,label:"pasted image"})}return n}function cm(e,t){let n=[];if(e.imageUrls)for(let[,o]of Object.entries(e.imageUrls))for(let r of o)n.push({url:`${t}${r}`,label:"pasted image"});return n}function dm({src:e,onClose:t}){return uo(()=>{let n=o=>{o.key==="Escape"&&(o.stopPropagation(),t())};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[t]),q("div",{onClick:t,style:{position:"fixed",inset:0,zIndex:1e5,backgroundColor:"rgba(0,0,0,0.8)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},children:q("img",{src:e,onClick:n=>n.stopPropagation(),style:{maxWidth:"90vw",maxHeight:"90vh",objectFit:"contain",cursor:"default",boxShadow:"0 4px 24px rgba(0,0,0,0.4)"}})})}function um(e){let t=String(e.data.tool||""),n=e.data.file?String(e.data.file):null,o=n?n.split("/").pop()??n:null,r=e.data.content?String(e.data.content):null;switch(t){case"Read":return o?`Reading ${o}`:"Reading file";case"Edit":return o?`Editing ${o}`:"Editing file";case"Write":return o?`Writing ${o}`:"Writing file";case"Bash":return r?pm(r):"Running command";case"Glob":return"Searching files";case"Grep":return"Searching code";case"WebFetch":return"Fetching page";case"WebSearch":return"Searching web";default:return t?`Using ${t}`:null}}function pm(e){let t=e.split(`
73
- `)[0].trim();return t.length<=60?t:t.slice(0,57)+"\u2026"}var fm=new Set(["Read","Glob","Grep","WebFetch","WebSearch"]),gm=new Set(["Edit","Write","Bash"]);function mm(e){let t=0,n=!1;for(let o of e){if(o.type!=="tool_use")continue;let r=String(o.data.tool||"");gm.has(r)?n=!0:fm.has(r)&&t++}return!n&&t>=3?"researching":n?"applying changes":null}function hm(e){let t=[];for(let n of e)if(n.type==="tool_use"){let o=um(n),r=String(n.data.tool||""),i=n.data.file?String(n.data.file):null,s=n.data.content?String(n.data.content):null,a=i??s??void 0;if(o){let l=t[t.length-1];l&&l.kind==="tool_group"&&l.tool===r?l.items.push({label:o,detail:a}):t.push({kind:"tool_group",tool:r,items:[{label:o,detail:a}]})}if(s&&i){let l=i.includes(".")?`.${i.split(".").pop().toLowerCase()}`:"",p=i.includes(".claude/plans/");t.push({kind:"file_content",file:i,content:s,ext:l,isPlan:p})}}else if(n.type==="delta"){let o=String(n.data.text||"");if(!o)continue;let r=t[t.length-1];r&&r.kind==="text"?r.text+=o:t.push({kind:"text",text:o})}else if(n.type==="thinking"){let o=String(n.data.text||"");if(!o)continue;let r=t[t.length-1];r&&r.kind==="thinking"?r.text+=o:t.push({kind:"thinking",text:o})}return t}function ym({file:e,content:t,ext:n,isPlan:o,onAccept:r}){let[i,s]=jn(o),a=e.split("/").pop()??e;return Ue("div",{style:{margin:"4px 0 4px 12px",border:"1px solid rgba(0,0,0,0.08)",backgroundColor:"rgba(255,255,255,0.6)",fontSize:11},children:[Ue("div",{onClick:()=>s(p=>!p),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 8px",cursor:"pointer",userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",color:"#374151"},children:[q("span",{style:{fontSize:9,color:"#9ca3af"},children:i?"\u25BC":"\u25B6"}),q("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a}),o&&q("span",{style:{fontSize:9,color:"#6366f1",fontFamily:"inherit"},children:"plan"})]}),i&&Ue(Bo,{children:[q("div",{style:{maxHeight:300,overflowY:"auto",padding:"6px 10px",borderTop:"1px solid rgba(0,0,0,0.06)",lineHeight:1.5,wordBreak:"break-word"},children:n===".md"?co(t):q("pre",{style:{margin:0,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:11,whiteSpace:"pre-wrap"},children:t})}),o&&r&&q("div",{style:{padding:"4px 8px",borderTop:"1px solid rgba(0,0,0,0.06)",display:"flex",justifyContent:"flex-end"},children:q("button",{onClick:p=>{p.stopPropagation(),r()},style:{background:"#111",color:"#fff",border:"none",padding:"4px 12px",fontSize:11,cursor:"pointer",fontFamily:"inherit"},children:"Accept"})})]})]})}function bm(e){let t=[];for(let n of e){let o=t[t.length-1];o&&o.val===n?o.count++:t.push({val:n,count:1})}return t.map(n=>n.count>1?`${n.val} (x${n.count})`:n.val)}function vm(e,t){switch(e){case"Bash":{let n=t.map(o=>(o.label||"").split(/\s/)[0]).filter(Boolean);return`Used Bash: ${bm(n).join(", ")}`}case"Read":return`Read: ${t.map(n=>n.label.replace(/^Reading /,"")).join(", ")}`;case"Edit":return`Edited: ${t.map(n=>n.label.replace(/^Editing /,"")).join(", ")}`;case"Write":return`Wrote: ${t.map(n=>n.label.replace(/^Writing /,"")).join(", ")}`;case"Grep":return t.length===1?"Searched code":`Searched code (${t.length})`;case"Glob":return t.length===1?"Searched files":`Searched files (${t.length})`;default:return`Used ${e}: ${t.map(n=>n.label).join(", ")}`}}var xm={fontSize:11,color:"#9ca3af",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:1.6};function Sm({label:e}){let t=e.indexOf(" ");return t===-1?q(Bo,{children:e}):Ue(Bo,{children:[q("b",{children:e.slice(0,t)}),e.slice(t)]})}function Hc({tool:e,items:t}){let[n,o]=jn(!1),r=t.length>1;return Ue("div",{style:xm,children:[Ue("div",{onClick:r?()=>o(i=>!i):void 0,style:{cursor:r?"pointer":"default",userSelect:"none",color:"#9ca3af"},children:[r&&q("span",{style:{fontSize:13,marginRight:4},children:n?"\u25BE":"\u25B8"}),vm(e,t)]}),n&&q("div",{style:{marginLeft:17},children:t.map((i,s)=>q("div",{children:q(Sm,{label:i.detail??i.label})},s))})]})}var wm=jg(function({msg:t,index:n,bridgeUrl:o,accentColor:r,onLightbox:i}){let s=t.role==="human";if(t.cancelled||t.error)return Ue("div",{"data-msg":!0,style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:[Ue("div",{style:{display:"flex",alignItems:"center",gap:4},children:[q("span",{style:{fontSize:11,color:t.error?"#dc2626":"#9ca3af",fontStyle:"italic"},children:t.error?"Error":"Cancelled"}),q("span",{style:{fontSize:10,color:"#9ca3af",marginLeft:"auto"},children:Pc(t.timestamp)})]}),t.error&&q("div",{style:{fontSize:12,color:"#6b7280",lineHeight:1.4},children:t.error})]},`${t.jobId}-${n}`);let a=s?null:nm(t.evalRun)??(t.responseText?tm(t.responseText):null),l=s?t.replyToQuestion||t.feedbackSummary||"(annotation)":a?"":zi(t.responseText||""),p=s?void 0:t.question,c=!s&&t.resolutions&&t.resolutions.length>0,u=!s&&t.segments&&t.segments.length>0,d=!s&&!u&&t.toolsUsed&&t.toolsUsed.length>0;return!l&&!p&&!c&&!u&&!a?null:Ue("div",{"data-msg":!0,style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:[Ue("div",{style:{display:"flex",alignItems:"center",gap:4},children:[!s&&q(Jr,{provider:t.provider,size:11,style:{color:"#6b7280"}}),q("span",{style:{fontWeight:600,fontSize:11,color:s?r:"#6b7280"},children:s?"You":Xs(t.model,t.provider)}),q("span",{style:{fontSize:10,color:"#9ca3af",marginLeft:"auto"},children:Pc(t.timestamp)})]}),s&&!t.replyToQuestion&&(()=>{let g=l?am(l):null;if(g&&t.screenshotUrls)return q("div",{style:{display:"flex",flexDirection:"column",gap:4},children:g.map((h,I)=>{let O=t.screenshotUrls?.[h.route],P=O?`${o}${O}`:null;return Ue("div",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[P?q("img",{src:P,title:h.route,style:{...Fi,flexShrink:0,marginTop:1},onClick:()=>i(P)}):q("div",{style:{width:$i,height:$i,flexShrink:0}}),Ue("div",{style:{lineHeight:1.5,wordBreak:"break-word",minWidth:0},children:[q("code",{style:{fontSize:10,backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px"},children:h.route}),h.text&&q("div",{style:{marginTop:2},children:co(h.text)})]})]},I)})});let x=t.screenshotUrl?`${o}${t.screenshotUrl}`:null;return x&&l?Ue("div",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[q("img",{src:x,title:"screenshot",style:{...Fi,flexShrink:0,marginTop:1},onClick:()=>i(x)}),q("div",{style:{lineHeight:1.5,wordBreak:"break-word",minWidth:0},children:l.includes(`
74
- `)?co(l):l})]}):l?q("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:l.includes(`
75
- `)?co(l):l}):null})(),s&&t.replyToQuestion&&l&&q("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:l.includes(`
76
- `)?co(l):l}),!s&&u&&t.segments.map((g,x)=>{if(g.kind==="tool_group")return q(Hc,{tool:g.tool,items:g.items},x);let h=a?Qg(zi(g.text)):zi(g.text);return h?q("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:co(h)},x):null}),!s&&!u&&l&&q("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:co(l)}),!s&&a&&q(om,{result:a}),s&&t.replyToQuestion&&(()=>{let g=lm(t,o);return g.length===0?null:q("div",{style:{display:"flex",gap:4,flexWrap:"wrap",marginTop:6},children:g.map((x,h)=>q("img",{src:x.url,title:x.label,style:Fi,onClick:()=>i(x.url)},h))})})(),s&&!t.replyToQuestion&&(()=>{let g=cm(t,o);return g.length===0?null:q("div",{style:{display:"flex",gap:4,flexWrap:"wrap",marginTop:6},children:g.map((x,h)=>q("img",{src:x.url,title:x.label,style:Fi,onClick:()=>i(x.url)},h))})})(),p&&q("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:co(p)}),(d||c)&&Ue("div",{style:{padding:"8px 16px",backgroundColor:"rgba(0, 0, 0, 0.03)",fontSize:11,lineHeight:1.5,color:"#374151"},children:[d&&q("div",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:10},children:t.toolsUsed.map((g,x)=>q("div",{children:g},x))}),c&&t.resolutions.map((g,x)=>{let h=g.finalScope??g.inferredScope;return Ue("div",{style:{marginTop:d?4:0},children:[q("span",{style:{color:g.status==="resolved"?"#10b981":"#f59e0b"},children:g.status==="resolved"?"Done":"Needs review"}),g.summary?` \u2014 ${g.summary}`:""]},x)})]}),!s&&t.responseText&&(()=>{let g=em(t.responseText);return g.length===0?null:q("div",{style:{padding:"8px 16px",backgroundColor:"rgba(0, 0, 0, 0.03)",fontSize:11,lineHeight:1.5,color:"#374151",marginTop:2},children:g.map((x,h)=>Ue("div",{style:{marginTop:h>0?6:0},children:[q("span",{style:{display:"inline-block",backgroundColor:"#8b5cf6",color:"#fff",fontSize:9,fontWeight:600,textTransform:"uppercase",padding:"1px 5px",borderRadius:3,marginRight:6,verticalAlign:"middle"},children:x.category}),q("strong",{children:x.element})," \u2014 ",x.decision,q("div",{style:{color:"#9ca3af",fontStyle:"italic",marginTop:1},children:x.reason})]},h))})})()]},`${t.jobId}-${n}`)});function _c({threadId:e,bridgeUrl:t,accentColor:n,isStreaming:o,isQueued:r,queuePosition:i,streamingEvents:s,onClose:a,onReply:l,onCancel:p,lastError:c,onMouseEnter:u,toolbarRef:d,currentModel:g,currentProvider:x,annotationNumber:h,annotationText:I,onOpenEvals:O,preferredSide:P="right",modal:F=!0}){let[M,D]=jn([]),[J,ee]=jn(!0),[C,S]=jn(""),[A,y]=jn([]),T=eo(!1),L=eo(null),[ce,We]=jn(!0),[be,j]=jn(0),[se,_]=jn(null),he=Pr(ne=>_(ne),[]),fe=eo(null),Ae=Pr((ne,te)=>{let ge=ne&&te.trim();fe.current&&(fe.current.style.opacity=ge?"0.65":"1"),L.current&&(L.current.style.borderTop=`1px solid ${ge?n:"rgba(0,0,0,0.12)"}`)},[n]),De=eo(null),ze=eo(null),de=eo(o),Ee=eo(ra(P)),Ge=eo({x:0,y:0}),Qe=eo(!1),pt=eo({x:0,y:0,offsetX:0,offsetY:0}),je=eo(P==="right"),[,X]=jn(0),Z=`${Yg}:${P}`;uo(()=>{try{let ne=localStorage.getItem(Z);if(ne){let te=JSON.parse(ne);if(typeof te.top=="number"&&typeof te.left=="number"){let ge=window.innerWidth-Dr-vn,Pe={top:Math.max(vn,Math.min(te.top,window.innerHeight-vn-200)),left:Math.max(vn,Math.min(te.left,ge))};je.current=Pe.left>=ge-2,Ee.current=Pe,X(et=>et+1)}}}catch{}},[Z]),uo(()=>{let ne=()=>{if(je.current)Ee.current=ra(P);else{let te=Ee.current,ge=window.innerWidth-Dr-vn;Ee.current={top:Math.max(vn,Math.min(te.top,window.innerHeight-vn-200)),left:Math.max(vn,Math.min(te.left,ge))}}X(te=>te+1)};return window.addEventListener("resize",ne,{passive:!0}),()=>window.removeEventListener("resize",ne)},[P]),uo(()=>{let ne=ze.current;if(!ne)return;let te=Re=>{Re.button!==0||Re.target.closest("button")||(Re.preventDefault(),Re.stopPropagation(),Qe.current=!0,pt.current={x:Re.clientX,y:Re.clientY,offsetX:Ge.current.x,offsetY:Ge.current.y})},ge=Re=>{if(!Qe.current)return;let _t=pt.current,Nt=_t.offsetX+(Re.clientX-_t.x),xn=_t.offsetY+(Re.clientY-_t.y),Pn=Math.max(vn,Math.min(window.innerWidth-Dr-vn,Ee.current.left+Nt)),At=Math.max(vn,Ee.current.top+xn);Ge.current={x:Pn-Ee.current.left,y:At-Ee.current.top};let xt=De.current;xt&&(xt.style.top=`${At}px`,xt.style.left=`${Pn}px`,xt.style.height=`${Ac(At,Pn,d?.current)}px`)},Pe=()=>{if(!Qe.current)return;let Re=Ee.current.top+Ge.current.y,_t=Ee.current.left+Ge.current.x;Ee.current={top:Re,left:_t},Ge.current={x:0,y:0};let Nt=window.innerWidth-Dr-vn;je.current=_t>=Nt-2;try{localStorage.setItem(Z,JSON.stringify({top:Re,left:_t}))}catch{}Qe.current=!1},et=()=>{Ee.current=ra(P),Ge.current={x:0,y:0},je.current=P==="right";try{localStorage.removeItem(Z)}catch{}X(Re=>Re+1)};return ne.addEventListener("mousedown",te),window.addEventListener("mousemove",ge),window.addEventListener("mouseup",Pe),ne.addEventListener("dblclick",et),()=>{ne.removeEventListener("mousedown",te),window.removeEventListener("mousemove",ge),window.removeEventListener("mouseup",Pe),ne.removeEventListener("dblclick",et)}},[Z,P]);let Se=Pr(()=>{ho(`${t}/thread/${e}`).then(ne=>ne.json()).then(ne=>{D(ne.messages??[]),ee(!1)}).catch(()=>ee(!1))},[t,e]);uo(()=>{ee(!0),Se()},[Se]),uo(()=>{de.current&&!o&&Se(),de.current=o},[o]);let Je=Lc(()=>s?hm(s):[],[s]),lt=Lc(()=>s?mm(s):null,[s]);uo(()=>{let ne=fe.current;if(!ne)return;let te=()=>{We(ne.scrollHeight-ne.scrollTop-ne.clientHeight<40);let Pe=ne.scrollTop+ne.clientHeight,et=ne.querySelectorAll("[data-msg]"),Re=0;for(let _t=0;_t<et.length;_t++){let Nt=et[_t];Nt.offsetTop+Nt.offsetHeight>Pe+20&&Re++}j(Re)};return ne.addEventListener("scroll",te,{passive:!0}),()=>ne.removeEventListener("scroll",te)},[]),uo(()=>{ce&&fe.current&&(fe.current.scrollTop=fe.current.scrollHeight)},[M,Je.length,o,ce]),uo(()=>{let ne=te=>{te.key==="Escape"&&(te.stopPropagation(),a())};return document.addEventListener("keydown",ne),()=>document.removeEventListener("keydown",ne)},[a]);let ke=Pr(()=>{if(!C.trim()||!l)return;let ne=C.trim(),te=A.length>0?A:void 0,ge=te?te.map(Pe=>URL.createObjectURL(Pe)):void 0;D(Pe=>[...Pe,{role:"human",timestamp:Date.now(),jobId:"pending",replyToQuestion:ne,...ge?{replyImageUrls:ge}:{}}]),l(e,ne,te),S(""),y([])},[C,A,e,l]),nt=Pr(ne=>{let te=ne.clipboardData.items,ge=[];for(let Pe=0;Pe<te.length;Pe++){let et=te[Pe];if(et.type.startsWith("image/")){let Re=et.getAsFile();Re&&ge.push(Re)}}ge.length>0&&(ne.preventDefault(),y(Pe=>[...Pe,...ge]))},[]),ot=Pr(ne=>{ne.key==="Enter"&&(ne.metaKey||ne.ctrlKey)&&(ne.preventDefault(),ke())},[ke]),rt=Ee.current.top+Ge.current.y,Lt=Ee.current.left+Ge.current.x,yt=Ac(rt,Lt,d?.current);return Ue(Bo,{children:[F&&q("div",{"data-devtools":"thread-panel-backdrop",onMouseDown:ne=>{ne.target===ne.currentTarget&&a()},style:{position:"fixed",inset:0,zIndex:9999}}),Ue("div",{ref:De,style:{...Ug,height:yt,position:"fixed",top:rt,left:Lt,zIndex:1e4},"data-devtools":"thread-panel",onMouseEnter:u,children:[(()=>{let te=`<svg xmlns='http://www.w3.org/2000/svg' width='5' height='5'><path d='M-1,1 l2,-2 M0,5 l5,-5 M4,6 l2,-2' stroke='${o?n:"rgb(0,0,0)"}' stroke-width='.75'/></svg>`,ge=`url("data:image/svg+xml,${encodeURIComponent(te)}")`;return Ue(Bo,{children:[q("style",{children:`@keyframes popmelt-border-march { to { background-position: 0 -5px; } }
77
- [data-popmelt-reply]::placeholder { opacity: 0.35; }`}),q("div",{style:{position:"absolute",inset:-3,padding:5,backgroundImage:ge,backgroundSize:"5px 5px",WebkitMask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",WebkitMaskComposite:"xor",mask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",maskComposite:"exclude",pointerEvents:"none",...o&&{animation:"popmelt-border-march 0.8s linear infinite"}}})]})})(),Ue("div",{style:{display:"flex",flexDirection:"column",overflow:"hidden",flex:1,minHeight:0},children:[Ue("div",{ref:ze,style:{...Kg,backgroundColor:n,color:"#ffffff",cursor:"grab",userSelect:"none",WebkitUserSelect:"none"},children:[Ue("span",{style:{display:"flex",alignItems:"center",gap:3,minWidth:0},children:[q("span",{style:{flexShrink:0},children:h?`${h}.`:"Conversation"}),I&&q("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:I})]}),q("button",{onClick:a,style:{background:"none",border:"none",cursor:"pointer",fontSize:16,color:"#ffffff",padding:"0 4px",lineHeight:1},children:"\xD7"})]}),q("style",{dangerouslySetInnerHTML:{__html:qg+`
72
+ `).trim()}function Pm(e){let t=e.match(/<novel>\s*([\s\S]*?)\s*<\/novel>/);if(!t?.[1])return[];try{let n=JSON.parse(t[1]);return Array.isArray(n)?n.filter(o=>{if(typeof o!="object"||o===null)return!1;let r=o;return typeof r.category=="string"&&typeof r.element=="string"&&typeof r.decision=="string"&&typeof r.reason=="string"}):[]}catch{return[]}}function Bm(e){let t=e.match(/<eval_run_result>\s*([\s\S]*?)\s*<\/eval_run_result>/);if(!t?.[1])return null;try{let n=JSON.parse(t[1]);if(!n||typeof n!="object")return null;let o=n,r=o.status,i=r==="pass"||r==="fail"||r==="needs_review"?r:"needs_review",a=(Array.isArray(o.assertionResults)?o.assertionResults:[]).flatMap(l=>{if(!l||typeof l!="object")return[];let d=l,c=typeof d.assertion=="string"?d.assertion.trim():"";if(!c)return[];let p=d.status;return[{assertion:c,status:p==="pass"||p==="fail"||p==="needs_review"?p:"needs_review",summary:typeof d.summary=="string"?d.summary.trim():""}]});return{title:typeof o.title=="string"?o.title.trim():void 0,status:i,summary:typeof o.summary=="string"?o.summary.trim():"",assertionResults:a}}catch{return null}}function Dm(e){return e?{title:e.title,status:e.status,summary:e.summary,assertionResults:e.assertionResults.map(t=>({assertion:t.assertion,status:t.status,summary:t.summary}))}:null}function Om({result:e}){let t=e.assertionResults;if(t.length===0)return null;let n=e.status==="pass"?"Pass":e.status==="fail"?"Fail":"Needs review",o=e.status==="pass"?"#047857":e.status==="fail"?"#b91c1c":"#6b7280";return Ke("div",{style:{padding:"8px 16px",backgroundColor:"rgba(0, 0, 0, 0.03)",fontSize:11,lineHeight:1.35,color:"#374151"},children:[Ke("div",{style:{display:"flex",alignItems:"baseline",gap:6,marginBottom:7},children:[ee("span",{style:{fontWeight:700,color:"#111827"},children:e.title??"Eval result"}),ee("span",{style:{color:o,fontWeight:700,marginLeft:"auto"},children:n})]}),e.summary&&ee("div",{style:{color:"#6b7280",marginBottom:8},children:e.summary}),ee("div",{style:{display:"flex",flexDirection:"column",gap:6},children:t.map((r,i)=>{let s=r.status==="pass"?"\u2611":r.status==="fail"?"\u2612":"\u25A1",a=r.status==="pass"?"Pass":r.status==="fail"?"Fail":"Needs review",l=r.status==="pass"?"#047857":r.status==="fail"?"#b91c1c":"#6b7280",d=r.status==="needs_review"?"inherit":l;return Ke("div",{style:{display:"grid",gridTemplateColumns:"18px minmax(0, 1fr)",columnGap:5,alignItems:"start"},children:[ee("span",{style:{color:l,fontSize:15,lineHeight:1},children:s}),Ke("div",{style:{minWidth:0},children:[ee("div",{style:{color:d},children:r.assertion}),r.status==="needs_review"?Ke("div",{style:{marginTop:1,color:"#6b7280"},children:[ee("span",{style:{color:l,fontWeight:700},children:a}),r.summary?Ke("span",{children:[": ",r.summary]}):null]}):r.summary?ee("div",{style:{marginTop:1,color:"#6b7280"},children:r.summary}):null]})]},`${r.assertion}-${i}`)})})]})}function ed(e){return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}var Ma=["reviewing","considering","thinking","zhuzhing","iterating","tweaking","reflecting","noodling","pondering","finessing","polishing","riffing"],_m=3e3,Hm=250;function Nm({color:e}){let[t,n]=Qn(0),[o,r]=Qn(()=>Math.floor(Math.random()*Ma.length));return So(()=>{let i=setInterval(()=>n(a=>(a+1)%2),Hm),s=setInterval(()=>r(a=>(a+1)%Ma.length),_m);return()=>{clearInterval(i),clearInterval(s)}},[]),Ke("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[ee("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:e,style:{verticalAlign:"middle",flexShrink:0},children:t===1?Ke(Vo,{children:[ee("circle",{cx:"7",cy:"7",r:"2"}),ee("circle",{cx:"17",cy:"7",r:"2"}),ee("circle",{cx:"7",cy:"17",r:"2"}),ee("circle",{cx:"17",cy:"17",r:"2"})]}):Ke(Vo,{children:[ee("circle",{cx:"12",cy:"6",r:"2"}),ee("circle",{cx:"6",cy:"12",r:"2"}),ee("circle",{cx:"18",cy:"12",r:"2"}),ee("circle",{cx:"12",cy:"18",r:"2"})]})}),ee("span",{style:{fontSize:11,color:"#9ca3af",fontStyle:"italic"},children:Ma[o]})]})}var ls=32,ss={width:ls,height:ls,objectFit:"cover",cursor:"pointer",border:"1px solid rgba(0,0,0,0.1)"};function Fm(e){let t=/^`(\/[^`]*)`$/gm,n=[...e.matchAll(t)];if(n.length===0)return null;let o=[];for(let r=0;r<n.length;r++){let i=n[r],s=i[1],a=i.index+i[0].length,l=r+1<n.length?n[r+1].index:e.length,d=e.slice(a,l).trim();o.push({route:s,text:d})}return o}function zm(e,t){let n=[];if(e.replyImageUrls)for(let o of e.replyImageUrls){let r=o.startsWith("blob:")||o.startsWith("http")?o:`${t}${o}`;n.push({url:r,label:"pasted image"})}return n}function $m(e,t){let n=[];if(e.imageUrls)for(let[,o]of Object.entries(e.imageUrls))for(let r of o)n.push({url:`${t}${r}`,label:"pasted image"});return n}function Wm({src:e,onClose:t}){return So(()=>{let n=o=>{o.key==="Escape"&&(o.stopPropagation(),t())};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[t]),ee("div",{onClick:t,style:{position:"fixed",inset:0,zIndex:1e5,backgroundColor:"rgba(0,0,0,0.8)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},children:ee("img",{src:e,onClick:n=>n.stopPropagation(),style:{maxWidth:"90vw",maxHeight:"90vh",objectFit:"contain",cursor:"default",boxShadow:"0 4px 24px rgba(0,0,0,0.4)"}})})}function jm(e){let t=String(e.data.tool||""),n=e.data.file?String(e.data.file):null,o=n?n.split("/").pop()??n:null,r=e.data.content?String(e.data.content):null;switch(t){case"Read":return o?`Reading ${o}`:"Reading file";case"Edit":return o?`Editing ${o}`:"Editing file";case"Write":return o?`Writing ${o}`:"Writing file";case"Bash":return r?Gm(r):"Running command";case"Glob":return"Searching files";case"Grep":return"Searching code";case"WebFetch":return"Fetching page";case"WebSearch":return"Searching web";default:return t?`Using ${t}`:null}}function Gm(e){let t=e.split(`
73
+ `)[0].trim();return t.length<=60?t:t.slice(0,57)+"\u2026"}var Jm=new Set(["Read","Glob","Grep","WebFetch","WebSearch"]),Ym=new Set(["Edit","Write","Bash"]);function Vm(e){let t=0,n=!1;for(let o of e){if(o.type!=="tool_use")continue;let r=String(o.data.tool||"");Ym.has(r)?n=!0:Jm.has(r)&&t++}return!n&&t>=3?"researching":n?"applying changes":null}function Um(e){let t=[];for(let n of e)if(n.type==="tool_use"){let o=jm(n),r=String(n.data.tool||""),i=n.data.file?String(n.data.file):null,s=n.data.content?String(n.data.content):null,a=i??s??void 0;if(o){let l=t[t.length-1];l&&l.kind==="tool_group"&&l.tool===r?l.items.push({label:o,detail:a}):t.push({kind:"tool_group",tool:r,items:[{label:o,detail:a}]})}if(s&&i){let l=i.includes(".")?`.${i.split(".").pop().toLowerCase()}`:"",d=i.includes(".claude/plans/");t.push({kind:"file_content",file:i,content:s,ext:l,isPlan:d})}}else if(n.type==="delta"){let o=String(n.data.text||"");if(!o)continue;let r=t[t.length-1];r&&r.kind==="text"?r.text+=o:t.push({kind:"text",text:o})}else if(n.type==="thinking"){let o=String(n.data.text||"");if(!o)continue;let r=t[t.length-1];r&&r.kind==="thinking"?r.text+=o:t.push({kind:"thinking",text:o})}return t}function Km({file:e,content:t,ext:n,isPlan:o,onAccept:r}){let[i,s]=Qn(o),a=e.split("/").pop()??e;return Ke("div",{style:{margin:"4px 0 4px 12px",border:"1px solid rgba(0,0,0,0.08)",backgroundColor:"rgba(255,255,255,0.6)",fontSize:11},children:[Ke("div",{onClick:()=>s(d=>!d),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 8px",cursor:"pointer",userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",color:"#374151"},children:[ee("span",{style:{fontSize:9,color:"#9ca3af"},children:i?"\u25BC":"\u25B6"}),ee("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a}),o&&ee("span",{style:{fontSize:9,color:"#6366f1",fontFamily:"inherit"},children:"plan"})]}),i&&Ke(Vo,{children:[ee("div",{style:{maxHeight:300,overflowY:"auto",padding:"6px 10px",borderTop:"1px solid rgba(0,0,0,0.06)",lineHeight:1.5,wordBreak:"break-word"},children:n===".md"?xo(t):ee("pre",{style:{margin:0,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:11,whiteSpace:"pre-wrap"},children:t})}),o&&r&&ee("div",{style:{padding:"4px 8px",borderTop:"1px solid rgba(0,0,0,0.06)",display:"flex",justifyContent:"flex-end"},children:ee("button",{onClick:d=>{d.stopPropagation(),r()},style:{background:"#111",color:"#fff",border:"none",padding:"4px 12px",fontSize:11,cursor:"pointer",fontFamily:"inherit"},children:"Accept"})})]})]})}function Xm(e){let t=[];for(let n of e){let o=t[t.length-1];o&&o.val===n?o.count++:t.push({val:n,count:1})}return t.map(n=>n.count>1?`${n.val} (x${n.count})`:n.val)}function qm(e,t){switch(e){case"Bash":{let n=t.map(o=>(o.label||"").split(/\s/)[0]).filter(Boolean);return`Used Bash: ${Xm(n).join(", ")}`}case"Read":return`Read: ${t.map(n=>n.label.replace(/^Reading /,"")).join(", ")}`;case"Edit":return`Edited: ${t.map(n=>n.label.replace(/^Editing /,"")).join(", ")}`;case"Write":return`Wrote: ${t.map(n=>n.label.replace(/^Writing /,"")).join(", ")}`;case"Grep":return t.length===1?"Searched code":`Searched code (${t.length})`;case"Glob":return t.length===1?"Searched files":`Searched files (${t.length})`;default:return`Used ${e}: ${t.map(n=>n.label).join(", ")}`}}var Zm={fontSize:11,color:"#9ca3af",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:1.6};function Qm({label:e}){let t=e.indexOf(" ");return t===-1?ee(Vo,{children:e}):Ke(Vo,{children:[ee("b",{children:e.slice(0,t)}),e.slice(t)]})}function rd({tool:e,items:t}){let[n,o]=Qn(!1),r=t.length>1;return Ke("div",{style:Zm,children:[Ke("div",{onClick:r?()=>o(i=>!i):void 0,style:{cursor:r?"pointer":"default",userSelect:"none",color:"#9ca3af"},children:[r&&ee("span",{style:{fontSize:13,marginRight:4},children:n?"\u25BE":"\u25B8"}),qm(e,t)]}),n&&ee("div",{style:{marginLeft:17},children:t.map((i,s)=>ee("div",{children:ee(Qm,{label:i.detail??i.label})},s))})]})}var eh=Sm(function({msg:t,index:n,bridgeUrl:o,accentColor:r,onLightbox:i}){let s=t.role==="human";if(t.cancelled||t.error)return Ke("div",{"data-msg":!0,style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:[Ke("div",{style:{display:"flex",alignItems:"center",gap:4},children:[ee("span",{style:{fontSize:11,color:t.error?"#dc2626":"#9ca3af",fontStyle:"italic"},children:t.error?"Error":"Cancelled"}),ee("span",{style:{fontSize:10,color:"#9ca3af",marginLeft:"auto"},children:ed(t.timestamp)})]}),t.error&&ee("div",{style:{fontSize:12,color:"#6b7280",lineHeight:1.4},children:t.error})]},`${t.jobId}-${n}`);let a=s?null:Dm(t.evalRun)??(t.responseText?Bm(t.responseText):null),l=s?t.replyToQuestion||t.feedbackSummary||"(annotation)":a?"":as(t.responseText||""),d=s?void 0:t.question,c=!s&&t.resolutions&&t.resolutions.length>0,p=!s&&t.segments&&t.segments.length>0,u=!s&&!p&&t.toolsUsed&&t.toolsUsed.length>0;return!l&&!d&&!c&&!p&&!a?null:Ke("div",{"data-msg":!0,style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:[Ke("div",{style:{display:"flex",alignItems:"center",gap:4},children:[!s&&ee(ci,{provider:t.provider,size:11,style:{color:"#6b7280"}}),ee("span",{style:{fontWeight:600,fontSize:11,color:s?r:"#6b7280"},children:s?"You":ba(t.model,t.provider)}),ee("span",{style:{fontSize:10,color:"#9ca3af",marginLeft:"auto"},children:ed(t.timestamp)})]}),s&&!t.replyToQuestion&&(()=>{let m=l?Fm(l):null;if(m&&t.screenshotUrls)return ee("div",{style:{display:"flex",flexDirection:"column",gap:4},children:m.map((b,I)=>{let P=t.screenshotUrls?.[b.route],N=P?`${o}${P}`:null;return Ke("div",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[N?ee("img",{src:N,title:b.route,style:{...ss,flexShrink:0,marginTop:1},onClick:()=>i(N)}):ee("div",{style:{width:ls,height:ls,flexShrink:0}}),Ke("div",{style:{lineHeight:1.5,wordBreak:"break-word",minWidth:0},children:[ee("code",{style:{fontSize:10,backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px"},children:b.route}),b.text&&ee("div",{style:{marginTop:2},children:xo(b.text)})]})]},I)})});let v=t.screenshotUrl?`${o}${t.screenshotUrl}`:null;return v&&l?Ke("div",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[ee("img",{src:v,title:"screenshot",style:{...ss,flexShrink:0,marginTop:1},onClick:()=>i(v)}),ee("div",{style:{lineHeight:1.5,wordBreak:"break-word",minWidth:0},children:l.includes(`
74
+ `)?xo(l):l})]}):l?ee("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:l.includes(`
75
+ `)?xo(l):l}):null})(),s&&t.replyToQuestion&&l&&ee("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:l.includes(`
76
+ `)?xo(l):l}),!s&&p&&t.segments.map((m,v)=>{if(m.kind==="tool_group")return ee(rd,{tool:m.tool,items:m.items},v);let b=a?Am(as(m.text)):as(m.text);return b?ee("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:xo(b)},v):null}),!s&&!p&&l&&ee("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:xo(l)}),!s&&a&&ee(Om,{result:a}),s&&t.replyToQuestion&&(()=>{let m=zm(t,o);return m.length===0?null:ee("div",{style:{display:"flex",gap:4,flexWrap:"wrap",marginTop:6},children:m.map((v,b)=>ee("img",{src:v.url,title:v.label,style:ss,onClick:()=>i(v.url)},b))})})(),s&&!t.replyToQuestion&&(()=>{let m=$m(t,o);return m.length===0?null:ee("div",{style:{display:"flex",gap:4,flexWrap:"wrap",marginTop:6},children:m.map((v,b)=>ee("img",{src:v.url,title:v.label,style:ss,onClick:()=>i(v.url)},b))})})(),d&&ee("div",{style:{lineHeight:1.5,wordBreak:"break-word"},children:xo(d)}),(u||c)&&Ke("div",{style:{padding:"8px 16px",backgroundColor:"rgba(0, 0, 0, 0.03)",fontSize:11,lineHeight:1.5,color:"#374151"},children:[u&&ee("div",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:10},children:t.toolsUsed.map((m,v)=>ee("div",{children:m},v))}),c&&t.resolutions.map((m,v)=>{let b=m.finalScope??m.inferredScope;return Ke("div",{style:{marginTop:u?4:0},children:[ee("span",{style:{color:m.status==="resolved"?"#10b981":"#f59e0b"},children:m.status==="resolved"?"Done":"Needs review"}),m.summary?` \u2014 ${m.summary}`:""]},v)})]}),!s&&t.responseText&&(()=>{let m=Pm(t.responseText);return m.length===0?null:ee("div",{style:{padding:"8px 16px",backgroundColor:"rgba(0, 0, 0, 0.03)",fontSize:11,lineHeight:1.5,color:"#374151",marginTop:2},children:m.map((v,b)=>Ke("div",{style:{marginTop:b>0?6:0},children:[ee("span",{style:{display:"inline-block",backgroundColor:"#8b5cf6",color:"#fff",fontSize:9,fontWeight:600,textTransform:"uppercase",padding:"1px 5px",borderRadius:3,marginRight:6,verticalAlign:"middle"},children:v.category}),ee("strong",{children:v.element})," \u2014 ",v.decision,ee("div",{style:{color:"#9ca3af",fontStyle:"italic",marginTop:1},children:v.reason})]},b))})})()]},`${t.jobId}-${n}`)});function id({threadId:e,bridgeUrl:t,accentColor:n,isStreaming:o,isQueued:r,queuePosition:i,streamingEvents:s,onClose:a,onReply:l,onCancel:d,lastError:c,onMouseEnter:p,toolbarRef:u,currentModel:m,currentProvider:v,annotationNumber:b,annotationText:I,onOpenEvals:P,preferredSide:N="right",modal:C=!0}){let[k,E]=Qn([]),[$,Q]=Qn(!0),[V,M]=Qn(""),[B,f]=Qn([]),g=Vn(!1),j=Vn(null),[fe,Re]=Qn(!0),[le,Ce]=Qn(0),[Ee,K]=Qn(null),O=Yr(W=>K(W),[]),Z=Vn(null),pe=Vn(null),Le=Vn(0),_e=Yr((W,ye)=>{let Se=W&&ye.trim();Z.current&&(Z.current.style.opacity=Se?"0.65":"1"),j.current&&(j.current.style.borderTop=`1px solid ${Se?n:"rgba(0,0,0,0.12)"}`)},[n]),ge=Vn(null),lt=Vn(null),Xe=Vn(o),ce=Vn(ka(N)),Ae=Vn({x:0,y:0}),ft=Vn(!1),G=Vn({x:0,y:0,offsetX:0,offsetY:0}),se=Vn(N==="right"),[,ie]=Qn(0),Ne=`${Em}:${N}`;So(()=>{try{let W=localStorage.getItem(Ne);if(W){let ye=JSON.parse(W);if(typeof ye.top=="number"&&typeof ye.left=="number"){let Se=window.innerWidth-Vr-Ln,He={top:Math.max(Ln,Math.min(ye.top,window.innerHeight-Ln-200)),left:Math.max(Ln,Math.min(ye.left,Se))};se.current=He.left>=Se-2,ce.current=He,ie($t=>$t+1)}}}catch{}},[Ne]),So(()=>{let W=()=>{if(se.current)ce.current=ka(N);else{let ye=ce.current,Se=window.innerWidth-Vr-Ln;ce.current={top:Math.max(Ln,Math.min(ye.top,window.innerHeight-Ln-200)),left:Math.max(Ln,Math.min(ye.left,Se))}}ie(ye=>ye+1)};return window.addEventListener("resize",W,{passive:!0}),()=>window.removeEventListener("resize",W)},[N]),So(()=>{let W=lt.current;if(!W)return;let ye=tt=>{tt.button!==0||tt.target.closest("button")||(tt.preventDefault(),tt.stopPropagation(),ft.current=!0,G.current={x:tt.clientX,y:tt.clientY,offsetX:Ae.current.x,offsetY:Ae.current.y})},Se=tt=>{if(!ft.current)return;let Gt=G.current,Jt=Gt.offsetX+(tt.clientX-Gt.x),Bt=Gt.offsetY+(tt.clientY-Gt.y),un=Math.max(Ln,Math.min(window.innerWidth-Vr-Ln,ce.current.left+Jt)),gt=Math.max(Ln,ce.current.top+Bt);Ae.current={x:un-ce.current.left,y:gt-ce.current.top};let Lt=ge.current;Lt&&(Lt.style.top=`${gt}px`,Lt.style.left=`${un}px`,Lt.style.height=`${Qc(gt,un,u?.current)}px`)},He=()=>{if(!ft.current)return;let tt=ce.current.top+Ae.current.y,Gt=ce.current.left+Ae.current.x;ce.current={top:tt,left:Gt},Ae.current={x:0,y:0};let Jt=window.innerWidth-Vr-Ln;se.current=Gt>=Jt-2;try{localStorage.setItem(Ne,JSON.stringify({top:tt,left:Gt}))}catch{}ft.current=!1},$t=()=>{ce.current=ka(N),Ae.current={x:0,y:0},se.current=N==="right";try{localStorage.removeItem(Ne)}catch{}ie(tt=>tt+1)};return W.addEventListener("mousedown",ye),window.addEventListener("mousemove",Se),window.addEventListener("mouseup",He),W.addEventListener("dblclick",$t),()=>{W.removeEventListener("mousedown",ye),window.removeEventListener("mousemove",Se),window.removeEventListener("mouseup",He),W.removeEventListener("dblclick",$t)}},[Ne,N]);let rt=Yr(async()=>{try{let W=await Ro(`${t}/thread/${e}`);if(!W.ok)throw new Error(`Thread fetch failed: ${W.status}`);let Se=(await W.json()).messages??[];return E(Se),Q(!1),Se.length}catch{return Q(!1),null}},[t,e]);So(()=>{let W=!1;Le.current=0,Q(!0),pe.current&&(clearTimeout(pe.current),pe.current=null);let ye=async()=>{let Se=await rt();W||Se!==0||Le.current>=5||(Le.current+=1,pe.current=setTimeout(ye,200*Le.current))};return ye(),()=>{W=!0,pe.current&&(clearTimeout(pe.current),pe.current=null)}},[rt]),So(()=>{Xe.current&&!o&&rt(),Xe.current=o},[o]);let Ie=Zc(()=>s?Um(s):[],[s]),et=Zc(()=>s?Vm(s):null,[s]);So(()=>{let W=Z.current;if(!W)return;let ye=()=>{Re(W.scrollHeight-W.scrollTop-W.clientHeight<40);let He=W.scrollTop+W.clientHeight,$t=W.querySelectorAll("[data-msg]"),tt=0;for(let Gt=0;Gt<$t.length;Gt++){let Jt=$t[Gt];Jt.offsetTop+Jt.offsetHeight>He+20&&tt++}Ce(tt)};return W.addEventListener("scroll",ye,{passive:!0}),()=>W.removeEventListener("scroll",ye)},[]),So(()=>{fe&&Z.current&&(Z.current.scrollTop=Z.current.scrollHeight)},[k,Ie.length,o,fe]),So(()=>{let W=ye=>{ye.key==="Escape"&&(ye.stopPropagation(),a())};return document.addEventListener("keydown",W),()=>document.removeEventListener("keydown",W)},[a]);let it=Yr(()=>{if(!V.trim()||!l)return;let W=V.trim(),ye=B.length>0?B:void 0,Se=ye?ye.map(He=>URL.createObjectURL(He)):void 0;E(He=>[...He,{role:"human",timestamp:Date.now(),jobId:"pending",replyToQuestion:W,...Se?{replyImageUrls:Se}:{}}]),l(e,W,ye),M(""),f([])},[V,B,e,l]),qe=Yr(W=>{let ye=W.clipboardData.items,Se=[];for(let He=0;He<ye.length;He++){let $t=ye[He];if($t.type.startsWith("image/")){let tt=$t.getAsFile();tt&&Se.push(tt)}}Se.length>0&&(W.preventDefault(),f(He=>[...He,...Se]))},[]),Rt=Yr(W=>{W.key==="Enter"&&(W.metaKey||W.ctrlKey)&&(W.preventDefault(),it())},[it]),Kt=ce.current.top+Ae.current.y,Dt=ce.current.left+Ae.current.x,Ge=Qc(Kt,Dt,u?.current);return Ke(Vo,{children:[C&&ee("div",{"data-devtools":"thread-panel-backdrop",onMouseDown:W=>{W.target===W.currentTarget&&a()},style:{position:"fixed",inset:0,zIndex:9999}}),Ke("div",{ref:ge,style:{...km,height:Ge,position:"fixed",top:Kt,left:Dt,zIndex:1e4},"data-devtools":"thread-panel",onMouseEnter:p,children:[(()=>{let ye=`<svg xmlns='http://www.w3.org/2000/svg' width='5' height='5'><path d='M-1,1 l2,-2 M0,5 l5,-5 M4,6 l2,-2' stroke='${o?n:"rgb(0,0,0)"}' stroke-width='.75'/></svg>`,Se=`url("data:image/svg+xml,${encodeURIComponent(ye)}")`;return Ke(Vo,{children:[ee("style",{children:`@keyframes popmelt-border-march { to { background-position: 0 -5px; } }
77
+ [data-popmelt-reply]::placeholder { opacity: 0.35; }`}),ee("div",{style:{position:"absolute",inset:-3,padding:5,backgroundImage:Se,backgroundSize:"5px 5px",WebkitMask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",WebkitMaskComposite:"xor",mask:"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) border-box",maskComposite:"exclude",pointerEvents:"none",...o&&{animation:"popmelt-border-march 0.8s linear infinite"}}})]})})(),Ke("div",{style:{display:"flex",flexDirection:"column",overflow:"hidden",flex:1,minHeight:0},children:[Ke("div",{ref:lt,style:{...Mm,backgroundColor:n,color:"#ffffff",cursor:"grab",userSelect:"none",WebkitUserSelect:"none"},children:[Ke("span",{style:{display:"flex",alignItems:"center",gap:3,minWidth:0},children:[ee("span",{style:{flexShrink:0},children:b?`${b}.`:"Conversation"}),I&&ee("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:I})]}),ee("button",{onClick:a,style:{background:"none",border:"none",cursor:"pointer",fontSize:16,color:"#ffffff",padding:"0 4px",lineHeight:1},children:"\xD7"})]}),ee("style",{dangerouslySetInnerHTML:{__html:Rm+`
78
78
  [data-devtools="thread-panel"] ::selection { background: color-mix(in srgb, ${n} 15%, transparent); }
79
- `}}),Ue("div",{ref:fe,style:{...Xg,transition:"opacity 150ms ease"},"data-devtools":"thread-panel-messages",children:[J&&q("div",{style:{padding:16,color:"#9ca3af",textAlign:"center"},children:"Loading..."}),!J&&M.length===0&&!o&&q("div",{style:{padding:16,color:"#9ca3af",textAlign:"center"},children:"No messages yet."}),M.map((ne,te)=>q(wm,{msg:ne,index:te,bridgeUrl:t,accentColor:n,onLightbox:he},`${ne.jobId}-${te}`)),!o&&O&&M.some(ne=>ne.role==="assistant"&&(ne.responseText?.includes("<eval_proposals>")||ne.responseText?.includes("<evals>")))&&q("div",{style:{padding:"0 16px 12px"},children:q("button",{type:"button",onClick:O,style:{width:"100%",border:"1px solid rgba(0,0,0,0.12)",background:"rgba(0,0,0,0.02)",color:"#6b7280",cursor:"pointer",fontFamily:Vt,fontSize:11,fontWeight:650,padding:"5px 8px"},children:"Review proposals"})}),o&&q("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:r?Ue("div",{style:{display:"flex",alignItems:"center",gap:6},children:[Ue("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:n,style:{verticalAlign:"middle",flexShrink:0,opacity:.5},children:[q("circle",{cx:"12",cy:"6",r:"2"}),q("circle",{cx:"6",cy:"12",r:"2"}),q("circle",{cx:"18",cy:"12",r:"2"}),q("circle",{cx:"12",cy:"18",r:"2"})]}),Ue("span",{style:{fontSize:11,color:"#9ca3af",fontStyle:"italic"},children:["queued",i?` ${i}`:""]})]}):Ue(Bo,{children:[Ue("div",{style:{display:"flex",alignItems:"center",gap:4},children:[q(Jr,{provider:x,size:11,style:{color:"#6b7280"}}),q("span",{style:{fontWeight:600,fontSize:11,color:"#6b7280"},children:Xs(g,x)})]}),Je.map((ne,te)=>{if(ne.kind==="tool_group")return q(Hc,{tool:ne.tool,items:ne.items},te);if(ne.kind==="file_content")return q(ym,{file:ne.file,content:ne.content,ext:ne.ext,isPlan:ne.isPlan,onAccept:ne.isPlan&&l?()=>l(e,"Looks good, please proceed with implementation."):void 0},te);if(ne.kind==="thinking")return q("div",{style:{paddingLeft:12,fontSize:11,color:"#9ca3af",fontStyle:"italic",lineHeight:1.4,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:80,overflowY:"auto"},children:ne.text},te);let ge=zi(ne.text);return ge?q("div",{style:{paddingLeft:12,lineHeight:1.5,wordBreak:"break-word"},children:co(ge)},te):null}),Ue("div",{style:{display:"flex",alignItems:"center",gap:6},children:[q(sm,{color:n}),p&&q("button",{onClick:p,style:{background:"none",border:"1px solid rgba(0,0,0,0.1)",color:"#6b7280",fontSize:10,padding:"2px 8px",cursor:"pointer",fontFamily:"inherit",marginLeft:"auto"},children:"Cancel"})]})]})}),!ce&&M.length>0&&q("div",{style:{position:"sticky",bottom:5,display:"flex",justifyContent:"flex-end",paddingRight:3,pointerEvents:"none"},children:q("button",{onClick:()=>{fe.current&&fe.current.scrollTo({top:fe.current.scrollHeight,behavior:"smooth"})},style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",padding:4,fontSize:10,fontFamily:Vt,color:"transparent",backgroundColor:"#eaeaea",backgroundImage:`url("data:image/svg+xml,${encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='5' height='5'><path d='M-1,1 l2,-2 M0,5 l5,-5 M4,6 l2,-2' stroke='rgb(0,0,0)' stroke-width='.75'/></svg>")}")`,backgroundSize:"5px 5px",border:"none",borderRadius:0,cursor:"pointer",pointerEvents:"auto",userSelect:"none"},children:Ue("span",{style:{position:"relative",backgroundColor:"#eaeaea",padding:"0 6px",color:"#374151",fontFamily:Vt,lineHeight:1.4},children:[be," message",be!==1?"s":""," \u2193"]})})})]}),!o&&c&&Ue("div",{style:{padding:"8px 16px",backgroundColor:"rgba(239, 68, 68, 0.06)",fontSize:11,color:"#dc2626",lineHeight:1.4},children:[q("span",{style:{fontWeight:600},children:"Error: "}),c]}),l&&Ue("div",{style:{flexShrink:0,position:"relative"},children:[A.length>0&&q("div",{style:{position:"absolute",bottom:"100%",display:"flex",gap:4,padding:"6px 5px 5px",flexWrap:"wrap"},children:A.map((ne,te)=>Ue("span",{onClick:()=>y(ge=>ge.filter((Pe,et)=>et!==te)),onMouseEnter:ge=>{let Pe=ge.currentTarget.querySelector("[data-chip-x]");Pe&&(Pe.style.color="#fff")},onMouseLeave:ge=>{let Pe=ge.currentTarget.querySelector("[data-chip-x]");Pe&&(Pe.style.color="rgba(255,255,255,0.4)")},style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:10,color:"#fff",backgroundColor:n,backdropFilter:"blur(4px)",padding:"2px 6px 2px 6px",cursor:"pointer"},children:["image ",te+1,q("span",{"data-chip-x":!0,style:{fontSize:12,lineHeight:1,color:"rgba(255,255,255,0.4)"},children:"\xD7"})]},te))}),Ue("div",{ref:L,style:{...Zg,borderTop:"1px solid rgba(0,0,0,0.12)"},children:[q("input",{"data-popmelt-reply":!0,autoFocus:!0,value:C,onChange:ne=>{S(ne.target.value),Ae(T.current,ne.target.value)},onFocus:()=>{T.current=!0,Ae(!0,C)},onBlur:()=>{T.current=!1,Ae(!1,C)},onKeyDown:ot,onPaste:nt,placeholder:"Reply here (cmd + enter to send)",style:{flex:1,minWidth:0,minHeight:44,padding:"0 4px",fontSize:12,fontFamily:Vt,backgroundColor:"transparent",color:"#1f2937",border:"none",outline:"none",lineHeight:"40px",boxSizing:"border-box"}}),q("button",{onClick:ke,disabled:!C.trim(),style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",cursor:C.trim()?"pointer":"default",color:C.trim()?n:"rgba(0,0,0,0.2)",flexShrink:0},children:Ue("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[q("path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z"}),q("path",{d:"M6 12h16"})]})})]})]})]})]}),se&&q(dm,{src:se,onClose:()=>_(null)})]})}import{jsx as Br,jsxs as Fc}from"react/jsx-runtime";var km=[],da=Cm(null),sa="devtools-provider",Wi="devtools-model",aa="devtools-open-thread-id",la="popmelt-synthesize-thread",ca="popmelt-eval-synthesize-thread",Or="#000000";async function Nc(e,t){t?await t(e):(window.history.pushState(window.history.state,"",e),window.dispatchEvent(new PopStateEvent("popstate",{state:window.history.state}))),await new Promise(n=>{requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(n,600)}))})}var Tm={0:0,1:1},Mm={0:0,1:1,2:1};function Im(e,t,n){if(t==="copilot")return 0;let o=t==="codex"?_i:Hi;return e==="copilot"?0:e==="claude"&&t==="codex"?Tm[n]??Math.min(n,o.length-1):e==="codex"&&t==="claude"?Mm[n]??Math.min(n,o.length-1):Math.min(n,o.length-1)}function Rm({children:e,enabled:t=process.env.NODE_ENV==="development",bridgeUrl:n=typeof window<"u"?window.__POPMELT_BRIDGE_URL__??"http://localhost:1111":"http://localhost:1111",navigate:o}){let r=typeof window<"u"?window.__POPMELT_PROJECT_ID__??null:null,[i,s]=ht(r),[a,l]=ht(!!r),p=i,[c,u]=Aa(),d=Ra(n,t&&!!p,p),g=qt(null),x=qt(null),h=Ma()??n,I=qt(new Map),O=qt(new Map),P=qt(!1),F=mr(),[M,D]=ht(()=>typeof window>"u"?"claude":localStorage.getItem(sa)||"claude"),[J,ee]=ht(()=>{if(typeof window>"u")return 0;let v=localStorage.getItem(Wi);return v&&parseInt(v,10)||0}),[C,S]=ht([]),[A,y]=ht({}),[T,L]=ht(0),[ce,We]=ht({}),[be,j]=ht(null),[se,_]=ht("idle"),[he,fe]=ht(null);Et(()=>{d.isConnected&&pa(h).then(v=>{if(!v)return;let N=Object.entries(v.providers).filter(([,Ie])=>Ie.available).map(([Ie])=>Ie);N.length>0&&S(N);let re={};for(let[Ie,_e]of Object.entries(v.providers))_e.models&&_e.models.length>0&&(re[Ie]=_e.models);y(re);let ie={};for(let[Ie,_e]of Object.entries(v.providers))_e.mcp&&(ie[Ie]=_e.mcp);We(ie)})},[d.isConnected,d.capabilitiesVersion,T,h]),Et(()=>{if(!d.isConnected){j(null);return}let v=!1;return yo(h).then(N=>{v||j(N?.version??null)}),()=>{v=!0}},[d.isConnected,d.capabilitiesVersion,T,h]),Et(()=>{if(se==="idle"||se==="restarting")return;let v=window.setTimeout(()=>{_("idle"),fe(null)},se==="ok"?4e3:8e3);return()=>window.clearTimeout(v)},[se]),Et(()=>{if(C.length>0&&!C.includes(M)){let v=C[0];D(v),localStorage.setItem(sa,v)}},[C,M]);let Ae=M==="codex"?[..._i]:M==="copilot"?[...Ks]:[...Hi],De=A[M]&&A[M].length>0?A[M]:Ae,ze=De[J]??De[0];Et(()=>{if(!t||p||a)return;let v=!1;return fetch("/popmelt/status").then(N=>N.ok?N.json():null).then(N=>{if(v)return;let re=N?.projectId??null;re&&typeof window<"u"&&(window.__POPMELT_PROJECT_ID__=re),s(re),l(!0)}).catch(()=>{v||l(!0)}),()=>{v=!0}},[t,p,a]),Et(()=>{J>=De.length&&(ee(0),localStorage.setItem(Wi,"0"))},[J,De.length]);let de=Ht(v=>{let N=M;D(v),localStorage.setItem(sa,v);let re=Im(N,v,J);ee(re),localStorage.setItem(Wi,String(re))},[M,J]),Ee=Ht(v=>{ee(v),localStorage.setItem(Wi,String(v))},[]),[Ge,Qe]=ht(new Set),[pt,je]=ht(null),[X,Z]=ht(null),[Se,Je]=ht(null),[lt,ke]=ht(null);Et(()=>{d.isConnected&&ur(h).then(v=>{v?.components&&Qe(new Set(Object.keys(v.components)))})},[d.isConnected,h]);let nt=Ht(async v=>{let N=[];for(let re of v)try{(await ma(re,h)).added&&N.push(re)}catch(ie){console.error("[Popmelt] Failed to add component to model:",re,ie)}N.length>0&&(Qe(re=>{let ie=new Set(re);for(let Ie of N)ie.add(Ie);return ie}),je(N[N.length-1]))},[h]),ot=Ht(v=>{je(v)},[]),rt=Ht(()=>{ur(h).then(v=>{v?.components&&Qe(new Set(Object.keys(v.components)))})},[h]),Lt=Ht(async v=>{try{(await ha(v,h)).removed&&Qe(re=>{let ie=new Set(re);return ie.delete(v),ie})}catch(N){console.error("[Popmelt] Failed to remove component from model:",N)}},[h]),yt=Ht((v,N)=>{u({type:"MODIFY_SPACING_TOKEN",payload:v}),u({type:"ADD_SPACING_TOKEN_CHANGE",payload:N})},[u]),ne=Ht((v,N)=>{u({type:"DELETE_SPACING_TOKEN",payload:{tokenPath:v,originalValue:N}})},[u]),[te,ge]=ht(null),[Pe,et]=ht(()=>typeof window>"u"?null:localStorage.getItem(la)||null),[Re,_t]=ht(null),[Nt,xn]=ht(()=>typeof window>"u"?null:localStorage.getItem(ca)||null),[Pn,At]=ht(0),[xt,Kt]=ht({}),[ft,Jt]=ht(new Set);Et(()=>{Pe?localStorage.setItem(la,Pe):localStorage.removeItem(la)},[Pe]),Et(()=>{Nt?localStorage.setItem(ca,Nt):localStorage.removeItem(ca)},[Nt]);let[tt,Gn]=ht(0),on=qt([]);Et(()=>{let v=on.current,N=c.spacingTokenMods;on.current=N;let re=new Map(v.map(_e=>[_e.tokenPath,_e])),ie=new Map(N.map(_e=>[_e.tokenPath,_e])),Ie=!1;for(let[_e,$e]of ie){let ve=re.get(_e);if(!(ve&&ve.currentValue===$e.currentValue)){Ie=!0,$e.currentValue==="__deleted__"?ya(_e,h).catch(f=>console.error("[Popmelt] Failed to sync token delete:",f)):Vi(_e,$e.currentValue,h).catch(f=>console.error("[Popmelt] Failed to sync token update:",f));for(let f of $e.targets){let b=document.querySelector(f.selector);if(b)if($e.currentValue==="__deleted__")b.style.removeProperty(f.property);else{let R=$e.currentPx;R>0&&b.style.setProperty(f.property,`${R}px`,"important")}}}}for(let[_e,$e]of re)if(!ie.has(_e)){Ie=!0,Vi(_e,$e.originalValue,h).catch(ve=>console.error("[Popmelt] Failed to restore token on undo:",ve));for(let ve of $e.targets){let f=document.querySelector(ve.selector);f&&f.style.removeProperty(ve.property)}}Ie&&Gn(_e=>_e+1)},[c.spacingTokenMods,h]);let[Mn,no]=ht(()=>Da()),oo=Ht(v=>{no(v),Oa(v)},[]),[qe,st]=ht(()=>typeof window>"u"?null:localStorage.getItem(aa)||null),fn=qt(null),[U,Me]=ht(new Set),[He,Pt]=ht(null);Et(()=>{qe?localStorage.setItem(aa,qe):localStorage.removeItem(aa)},[qe]);let Xe="popmelt-in-flight-jobs",[Oe,St]=ht(()=>{try{let v=localStorage.getItem(Xe);return v?JSON.parse(v):{}}catch{return{}}});Et(()=>{try{Object.keys(Oe).length>0?localStorage.setItem(Xe,JSON.stringify(Oe)):localStorage.removeItem(Xe)}catch{}},[Oe]),Et(()=>{let v=N=>{if(N.key===Xe)try{let re=N.newValue?JSON.parse(N.newValue):{};St(re)}catch{}};return window.addEventListener("storage",v),()=>window.removeEventListener("storage",v)},[]);let $t=qt(new Map),gn=qt(new Map);Et(()=>{for(let[v,N]of Object.entries(Oe))N.annotationIds.length>0&&$t.current.set(v,N.annotationIds),N.threadId&&gn.current.set(v,N.threadId)},[Oe]);let rn=qt("");Et(()=>{if(c.annotations.length===0)return;let v=Object.keys(Oe).sort().join(",");if(v===rn.current)return;rn.current=v;let N=new Set;for(let ie of Object.values(Oe))for(let Ie of ie.annotationIds)N.add(Ie);let re=c.annotations.filter(ie=>N.has(ie.id)?!1:!!(ie.status==="in_flight"||(ie.status==="pending"||!ie.status)&&(ie.captured||ie.threadId))).map(ie=>ie.id);re.length>0&&u({type:"SET_ANNOTATION_STATUS",payload:{ids:re,status:"dismissed"}})},[c.annotations,Oe,u]);let po=to(()=>{let v=new Set;for(let N of Object.values(Oe))for(let re of N.annotationIds)v.add(re);return v},[Oe]),Wt=to(()=>{let v=new Set(d.activeJobIds),N=new Set;for(let[re,ie]of Object.entries(Oe))if(v.has(re))for(let Ie of ie.annotationIds)N.add(Ie);return N},[Oe,d.activeJobIds]),ko=to(()=>{let v=new Set(d.activeJobIds),N=Object.entries(Oe).filter(([Ie])=>!v.has(Ie)),re=N.length,ie=new Map;return N.forEach(([,Ie],_e)=>{let $e=`(${_e+1}/${re})`;for(let ve of Ie.annotationIds)ie.set(ve,$e)}),ie},[Oe,d.activeJobIds]),fo=to(()=>{let v=new Set;for(let N of Object.values(Oe))for(let re of N.styleSelectors)v.add(re);return v},[Oe]),ir=to(()=>{let v=new Map;for(let N of Object.values(Oe)){for(let re of N.styleSelectors)v.set(re,N.color);for(let re of N.annotationIds){let ie=c.annotations.find(Ie=>Ie.id===re);if(ie&&(ie.linkedSelector&&v.set(ie.linkedSelector,N.color),ie.groupId))for(let Ie of c.annotations)Ie.groupId===ie.groupId&&Ie.linkedSelector&&v.set(Ie.linkedSelector,N.color)}}return v},[Oe,c.annotations]),Jn=qt(c.annotations);Jn.current=c.annotations;let Sn=qt(c.styleModifications);Sn.current=c.styleModifications;let ro=qt(Oe);ro.current=Oe,Et(()=>{let v=null,N=()=>{if(Object.keys(ro.current).length>0)return;let ie=Jn.current,Ie=Sn.current,_e=[],$e=[];for(let ve of ie){if(!ve.linkedSelector||!ve.linkedSelector.startsWith("[data-pm=")||ve.pathname||ve.captured||ve.status&&ve.status!=="pending")continue;let f=document.querySelector(ve.linkedSelector);!f&&ve.elements?.[0]?.selector&&(f=document.querySelector(ve.elements[0].selector)),f||_e.push(ve.linkedSelector)}for(let ve of Ie)document.querySelector(ve.selector)||$e.push(ve.selector);(_e.length>0||$e.length>0)&&u({type:"CLEANUP_ORPHANED",payload:{linkedSelectors:_e,styleSelectors:$e}})},re=new MutationObserver(ie=>{ie.some(Ie=>Ie.removedNodes.length>0)&&(v&&clearTimeout(v),v=setTimeout(N,3e3))});return re.observe(document.body,{childList:!0,subtree:!0}),()=>{re.disconnect(),v&&clearTimeout(v)}},[u]);let Yn=qt(typeof window<"u"?window.location.pathname:"/");Et(()=>{let v=ie=>{if(P.current)return;let Ie=window.location.pathname;if(ie===Ie)return;let _e=Jn.current.filter(ve=>ve.pathname===ie&&(ve.status??"pending")==="pending");if(console.log(`[Popmelt] Navigation from ${ie} \u2192 ${Ie}, ${_e.length} pending annotations on departing page`),_e.length===0)return;let $e=g.current;if(!$e){console.warn("[Popmelt] No canvas ref for capture-on-leave");return}if(hr(document.body,$e,_e,{dpr:1}).then(ve=>_r(ve)).then(ve=>{ve?(O.current.set(ie,ve),console.log(`[Popmelt] Cached screenshot for ${ie} (${(ve.size/1024).toFixed(0)}KB)`)):console.warn(`[Popmelt] Capture-on-leave produced no blob for ${ie}`)}).catch(ve=>{console.warn("[Popmelt] Capture-on-leave failed:",ve)}),O.current.size>20){let ve=[...O.current.entries()];O.current=new Map(ve.slice(-10))}},N=ie=>{let Ie=ie.detail?.prevPath;Ie&&(v(Ie),Yn.current=window.location.pathname)},re=()=>{let ie=Yn.current;v(ie),Yn.current=window.location.pathname};return window.addEventListener("popmelt:locationchange",N),window.addEventListener("popstate",re),()=>{window.removeEventListener("popmelt:locationchange",N),window.removeEventListener("popstate",re)}},[]),Et(()=>{if(d.lastCompletedJobId&&d.lastCompletedJobId in Oe&&St(v=>{let{[d.lastCompletedJobId]:N,...re}=v;return re}),d.lastCompletedJobId&&d.lastCompletedJobId===te&&(Gn(v=>v+1),ge(null)),d.lastCompletedJobId&&d.lastCompletedJobId===Re&&(At(v=>v+1),_t(null)),d.lastCompletedJobId){let v=Object.entries(xt).find(([,N])=>N===d.lastCompletedJobId)?.[0];v&&(Kt(N=>{let{[v]:re,...ie}=N;return ie}),At(N=>N+1))}},[d.lastCompletedJobId,te,Re,xt]);let Ft=qt(new Set),wt=qt(!1);Et(()=>{if(!d.isConnected){wt.current=!1;return}wt.current||(wt.current=!0,yo(h).then(async v=>{if(!v)return;let N=v.activeJobs??[],re=v.recentJobs??[],ie=new Set(N.map($e=>$e.id)),Ie=JSON.parse(localStorage.getItem(Xe)||"{}"),_e=new Set;for(let $e of Object.values(Ie))if($e.annotationIds)for(let ve of $e.annotationIds)_e.add(ve);St($e=>{let ve={...$e},f=Date.now();for(let R of Object.keys(ve)){if(R.startsWith("_pending_")){let m=parseInt(R.replace(/^_pending_(?:reply_)?/,""),10);!isNaN(m)&&f-m>3e4&&delete ve[R];continue}ie.has(R)||delete ve[R]}for(let R of N)if(!ve[R.id]&&(R.annotationIds?.length||R.threadId)){let m=R.kind;ve[R.id]={annotationIds:R.annotationIds??[],styleSelectors:[],color:m==="synthesize_evals"||m==="run_eval"?Or:R.color??"#888",threadId:R.threadId,kind:m}}let b=new Set;for(let R of re)if(R.annotationIds)for(let m of R.annotationIds)b.add(m);for(let R of Object.keys(ve)){if(!R.startsWith("_pending_"))continue;let m=ve[R];m&&m.annotationIds.some(k=>b.has(k))&&delete ve[R]}return ve});for(let $e of re)if($e.status==="done"&&$e.annotationIds?.length&&$e.annotationIds.some(ve=>_e.has(ve))&&!Ft.current.has($e.id))try{let ve=await Xr(h,$e.id);if(!ve)continue;let f=ve.events.find(b=>b.type==="done");f&&Array.isArray(f.resolutions)&&(Ft.current.add($e.id),u({type:"APPLY_RESOLUTIONS",payload:{resolutions:f.resolutions,threadId:f.threadId??void 0}}))}catch{}}))},[d.isConnected,h,u]),Et(()=>{let v=d.events.filter(N=>N.type==="done"&&N.data.resolutions);for(let N of v){let re=N.data.jobId;Ft.current.has(re)||(Ft.current.add(re),Array.isArray(N.data.resolutions)&&u({type:"APPLY_RESOLUTIONS",payload:{resolutions:N.data.resolutions,threadId:N.data.threadId}}))}},[d.events,u]);let jt=qt(new Set);Et(()=>{let v=d.events.filter(N=>N.type==="error"&&N.data.cancelled);for(let N of v){let re=N.data.jobId;if(!re||jt.current.has(re))continue;jt.current.add(re);let ie=Oe[re];ie&&ie.annotationIds.length>0&&u({type:"SET_ANNOTATION_STATUS",payload:{ids:ie.annotationIds,status:"dismissed"}})}},[d.events,Oe,u]);let Gt=qt(0);Et(()=>{let v=d.incrementalResolutions;if(v.length<=Gt.current)return;let N=v.slice(Gt.current);Gt.current=v.length,u({type:"APPLY_RESOLUTIONS",payload:{resolutions:N}})},[d.incrementalResolutions,u]),Et(()=>{d.incrementalResolutions.length===0&&(Gt.current=0)},[d.incrementalResolutions.length]);let wn=Ht(async()=>{let v=g.current;if(!v)return!1;let N=await hr(document.body,v,c.annotations);if(N.length===0)return!1;let re=await $a(N,c.annotations,c.styleModifications);return re&&u({type:"MARK_CAPTURED"}),re},[c.annotations,c.styleModifications,u]),io=Ht((v,N)=>{let re=I.current.get(v)||[];I.current.set(v,[...re,...N])},[]),In=Ht(async()=>{let v=g.current;if(!v)return!1;let N=c.annotations.filter(w=>(w.status??"pending")==="pending"),re=c.spacingTokenChanges.filter(w=>!w.captured);if(N.length===0&&c.styleModifications.filter(w=>!w.captured).length===0&&re.length===0)return!1;let ie=new Map;for(let w of N){let W=w.pathname||F;ie.has(W)||ie.set(W,[]),ie.get(W).push(w)}let Ie=new Map,_e=[...ie.keys()].filter(w=>w!==F);if(_e.length>0){let w=F,W={x:window.scrollX,y:window.scrollY};P.current=!0;for(let Y of _e)try{console.log(`[Popmelt] Navigating to ${Y} for screenshot capture`),await Nc(Y,o),window.location.pathname!==Y&&console.warn(`[Popmelt] Navigation to ${Y} did not take effect (at ${window.location.pathname})`);let V=ie.get(Y)||[],me=await hr(document.body,v,V,{dpr:1}),Ce=await _r(me);Ce&&(Ie.set(Y,Ce),console.log(`[Popmelt] Captured ${Y} (${(Ce.size/1024).toFixed(0)}KB)`))}catch(V){console.warn(`[Popmelt] Failed to capture ${Y}:`,V)}await Nc(w,o),window.scrollTo(W.x,W.y),P.current=!1}let $e=N.filter(w=>(w.pathname||F)===F),ve=await hr(document.body,v,$e.length>0?c.annotations:[],{dpr:1});if(ve.length>0){let w=await _r(ve);w&&Ie.set(F,w)}if(Ie.size===0)return!1;let f=es(N,c.styleModifications,void 0,re.length>0?re:void 0),b=JSON.stringify(f),R=new Map;for(let w of N){let W=I.current.get(w.id);if(W&&W.length>0&&R.set(w.id,W),w.groupId){for(let Y of N)if(Y.groupId===w.groupId&&Y.id!==w.id){let V=I.current.get(Y.id);V&&V.length>0&&R.set(Y.id,V)}}}let m=ie.size>1;console.log(`[Popmelt] Submit: ${ie.size} page(s), ${Ie.size} screenshot(s), pages: [${[...ie.keys()].join(", ")}], cached: [${[...O.current.keys()].join(", ")}]`);let k=m?Ie:Ie.get(F)??Ie,E=N.map(w=>w.id),$=c.styleModifications.filter(w=>!w.captured).map(w=>w.selector),B=Qi(c.activeColor),G=`_pending_${Date.now()}`,K={annotationIds:E,styleSelectors:$,color:c.activeColor,threadId:void 0};try{let w=JSON.parse(localStorage.getItem(Xe)||"{}");w[G]=K,localStorage.setItem(Xe,JSON.stringify(w))}catch{}St(w=>({...w,[G]:K}));try{let{jobId:w,threadId:W}=await ga(k,b,h,B,M,ze.id,R.size>0?R:void 0,oi());for(let Le of R.keys())I.current.delete(Le);for(let Le of ie.keys())O.current.delete(Le);let Y={...K,threadId:W};try{let Le=JSON.parse(localStorage.getItem(Xe)||"{}");delete Le[G],Le[w]=Y,localStorage.setItem(Xe,JSON.stringify(Le))}catch{}St(Le=>{let{[G]:gt,...mt}=Le;return{...mt,[w]:Y}}),u({type:"MARK_CAPTURED"}),W&&E.length>0&&u({type:"SET_ANNOTATION_THREAD",payload:{ids:E,threadId:W}});let V=c.activeColor.match(/oklch\([^)]*\s+([\d.]+)\s*\)/),Ce=((V?.[1]?parseFloat(V[1]):29)+60)%360;return u({type:"SET_COLOR",payload:`oklch(0.628 0.258 ${Ce})`}),!0}catch(w){try{let W=JSON.parse(localStorage.getItem(Xe)||"{}");delete W[G],localStorage.setItem(Xe,JSON.stringify(W))}catch{}return St(W=>{let{[G]:Y,...V}=W;return V}),console.error("[Pare] Failed to send to bridge:",w),!1}},[c.annotations,c.styleModifications,c.spacingTokenChanges,c.activeColor,u,h,M,ze.id,F,o]),To=Ht(async()=>{if(Pe){st(Pe);return}try{let{jobId:v,threadId:N}=await wa(h,M,ze.id);ge(v),et(N);let re={annotationIds:[],styleSelectors:[],color:"#6b7280",threadId:N,kind:"synthesize"};St(ie=>({...ie,[v]:re})),st(N)}catch(v){console.error("[Popmelt] Failed to start synthesize:",v)}},[h,M,ze.id,Pe]),Zt=Ht(async()=>{_t(null),xn(null),st(null);try{let{jobId:v,threadId:N}=await Ca(h,M,ze.id);_t(v),xn(N);let re={annotationIds:[],styleSelectors:[],color:Or,threadId:N,kind:"synthesize_evals"};St(ie=>({...ie,[v]:re})),st(N)}catch(v){console.error("[Popmelt] Failed to start eval synthesis:",v)}},[h,M,ze.id]),sr=Ht(async v=>{let N=g.current;if(N){Kt(re=>({...re,[v.id]:"_pending_"}));try{let ie=(await hr(document.body,N,[],{dpr:1}))[0];if(!ie){Kt($e=>{let{[v.id]:ve,...f}=$e;return f});return}let{jobId:Ie,threadId:_e}=await xa(v.id,ie,{url:window.location.href,viewport:{width:window.innerWidth,height:window.innerHeight},scrollX:window.scrollX,scrollY:window.scrollY},h,M,ze.id,oi());if(Kt($e=>({...$e,[v.id]:Ie})),_e){Jt(ve=>new Set(ve).add(_e));let $e={annotationIds:[],styleSelectors:[],color:Or,threadId:_e,kind:"run_eval"};St(ve=>({...ve,[Ie]:$e})),st(_e)}}catch(re){Kt(ie=>{let{[v.id]:Ie,..._e}=ie;return _e}),console.error("[Popmelt] Failed to run eval:",re)}}},[h,M,ze.id]),Vn=Ht(async(v,N,re)=>{let ie=Object.values(ro.current).find(f=>f.threadId===v)?.color??c.annotations.find(f=>f.threadId===v)?.color??c.activeColor,Ie=c.annotations.filter(f=>f.threadId===v&&(f.status==="waiting_input"||f.status==="resolved"||f.status==="needs_review")),_e=Ie.map(f=>f.id),$e=`_pending_reply_${Date.now()}`,ve={annotationIds:_e,styleSelectors:[],color:ie,threadId:v};try{let f=JSON.parse(localStorage.getItem(Xe)||"{}");f[$e]=ve,localStorage.setItem(Xe,JSON.stringify(f))}catch{}St(f=>({...f,[$e]:ve}));try{let f=Qi(c.activeColor),{jobId:b}=await Ea(v,N,h,f,M,ze.id,re,oi()),R={...ve};try{let m=JSON.parse(localStorage.getItem(Xe)||"{}");delete m[$e],m[b]=R,localStorage.setItem(Xe,JSON.stringify(m))}catch{}St(m=>{let{[$e]:k,...E}=m;return{...E,[b]:R}}),Ie.length>0&&u({type:"SET_ANNOTATION_STATUS",payload:{ids:_e,status:"in_flight"}}),d.dismissQuestion(v)}catch(f){try{let b=JSON.parse(localStorage.getItem(Xe)||"{}");delete b[$e],localStorage.setItem(Xe,JSON.stringify(b))}catch{}St(b=>{let{[$e]:R,...m}=b;return m}),console.error("[Pare] Failed to send reply:",f)}},[c.activeColor,c.annotations,h,d.dismissQuestion,u,M,ze.id]),Nn=qt(new Set);Et(()=>{for(let v of d.pendingQuestions){if(Nn.current.has(v.jobId))continue;Nn.current.add(v.jobId);let N=v.annotationIds&&v.annotationIds.length>0?v.annotationIds:void 0;!N&&v.threadId&&(N=c.annotations.filter(re=>re.threadId===v.threadId).map(re=>re.id)),N&&N.length>0&&u({type:"SET_ANNOTATION_QUESTION",payload:{ids:N,question:v.question,threadId:v.threadId}})}},[d.pendingQuestions,u,c.annotations]);let ar=to(()=>{if(d.activeJobId&&d.activeJobId in Oe)return Oe[d.activeJobId].color;let v=Object.values(Oe);return v.length>0?v[v.length-1].color:void 0},[d.activeJobId,Oe]),Mo=Ht(v=>{st(v)},[]),Ho=Ht(v=>{Jt(N=>new Set(N).add(v)),fn.current=Or,st(v)},[]),lr=Ht(v=>{let N=Oe[v],re=N?.threadId||gn.current.get(v);re&&(fn.current=N?.kind==="synthesize_evals"||N?.kind==="run_eval"?Or:N?.color??null,st(re))},[Oe]),cr=Ht(v=>{if(!v){Pt(null);return}let N=$t.current.get(v);N&&N.length>0?Pt(new Set(N)):Pt(null)},[]),H=Ht(async v=>{try{let N=v?`${h}/cancel?jobId=${v}`:`${h}/cancel`;await ho(N,{method:"POST"})}catch{}},[h]),z=Ht(async()=>{_("restarting"),fe("Restarting bridge");let v=await Ui(h,si,2e4);if(v.ok){j(v.status.version??si),_("ok"),fe(v.status.version?`Bridge restarted on ${v.status.version}`:"Bridge restarted"),L(N=>N+1);return}j(v.status?.version??be),_("error"),fe(v.error)},[be,h]),Q=to(()=>{if(!qe)return null;for(let v of Object.values(Oe))if(v.threadId===qe&&v.kind)return v.kind;return qe===Pe?"synthesize":qe===Nt?"synthesize_evals":ft.has(qe)?"run_eval":null},[qe,Oe,Pe,Nt,ft]),oe=Q==="synthesize_evals"||Q==="run_eval",ue=Q==="synthesize";Et(()=>{(c.activeTool==="model"&&qe&&!ue||c.activeTool==="eval"&&qe&&!oe)&&st(null)},[c.activeTool,qe,ue,oe]);let xe=Ht(()=>{u({type:"SET_TOOL",payload:"eval"}),At(v=>v+1),st(null)},[u]),we=qt(null);Et(()=>{c.isAnnotating?we.current&&(st(we.current),we.current=null):qe&&(we.current=qe,st(null))},[c.isAnnotating]);let ae=to(()=>{if(!qe)return null;for(let[v,N]of Object.entries(Oe))if(N.threadId===qe)return v;for(let[v,N]of Object.entries(d.activeJobThreads))if(N===qe)return v;return null},[qe,Oe,d.activeJobThreads]),at=qe?c.annotations.find(v=>v.threadId===qe):void 0,It=to(()=>ae?d.events.filter(v=>v.data.jobId===ae):km,[ae,d.events.length]),ln=to(()=>oe?Or:at?.color??fn.current??c.activeColor,[oe,at?.color,c.activeColor]),cn=at?c.annotations.indexOf(at)+1:void 0;Et(()=>{if(oe)return;let v=at?.color??fn.current;qe&&v&&u({type:"SET_COLOR",payload:v})},[qe,oe]);let[Ke,Dt]=ht(!1),[Rn,mn]=ht(0),Qt=qt(null),dr=Ht(v=>{v?(Qt.current&&(clearTimeout(Qt.current),Qt.current=null),Dt(!0)):Qt.current=setTimeout(()=>{Dt(!1),Qt.current=null},150)},[]),ji=Ht(()=>{mn(v=>v+1),d.clearEvents(),st(null),Me(new Set),H()},[d.clearEvents,H]);Et(()=>()=>{Qt.current&&clearTimeout(Qt.current)},[]);let[Gi,Ji]=ht(!1);Et(()=>{Ji(!0)},[]);let Kr=to(()=>({isEnabled:t}),[t]);return!t||!Gi?Br(da.Provider,{value:Kr,children:e}):Fc(da.Provider,{value:Kr,children:[e,Br(Jl,{state:c,dispatch:u,onScreenshot:wn,inFlightAnnotationIds:po,activeAnnotationIds:Wt,queuePositionMap:ko,inFlightStyleSelectors:fo,inFlightSelectorColors:ir,onAttachImages:io,onReply:d.isConnected?Vn:void 0,onViewThread:d.isConnected?Mo:void 0,onCloseThread:v=>{st(null),v&&Me(N=>new Set(N).add(v))},onModelComponentsAdd:d.isConnected?nt:void 0,onModelComponentFocus:d.isConnected?ot:void 0,onModelComponentHover:Z,modelComponentNames:Ge,modelPanelHoveredComponent:Se,modelSpacingTokenHover:lt,highlightedAnnotationIds:He,focusedThreadAnnotationId:at?.id,externalCanvasRef:g,toolbarRef:x}),Br(Rc,{children:Fc(Mc,{children:[Br(wc,{state:c,dispatch:u,onScreenshot:wn,onSendToClaude:d.isConnected?In:void 0,hasActiveJobs:Object.keys(Oe).length>0||d.activeJobIds.length>0,activeJobColor:ar,onCrosshairHover:dr,onClear:ji,provider:M,onProviderChange:d.isConnected&&C.length>1?de:void 0,availableProviders:C,modelIndex:J,modelCount:De.length,modelLabel:ze.label,onModelChange:d.isConnected?Ee:void 0,onViewThread:d.isConnected?Mo:void 0,isThreadPanelOpen:qe!==null&&!ue&&!oe,mcpStatus:ce,bridgeUrl:h,isBridgeConnected:d.isConnected,packageVersion:si,bridgeVersion:be,bridgeRestartState:se,bridgeRestartMessage:he,onBridgeRestart:z,modelSelectedComponent:pt,modelCanvasHoveredComponent:X,onModelComponentHover:Je,onSpacingTokenHover:ke,onModifySpacingToken:d.isConnected?yt:void 0,onDeleteSpacingToken:d.isConnected?ne:void 0,modelRefreshKey:tt,onModelComponentAdded:rt,onModelComponentRemoved:Lt,onSynthesizeRules:d.isConnected&&M!=="copilot"?To:void 0,isSynthesizing:te!==null,onSynthesizeEvals:d.isConnected&&M!=="copilot"?Zt:void 0,isSynthesizingEvals:Re!==null,onRunEval:d.isConnected&&M!=="copilot"?sr:void 0,onViewEvalRunThread:Ho,runningEvalIds:Object.keys(xt),evalRefreshKey:Pn,toolbarRef:x,snapPosition:Mn,onSnapPositionChange:oo}),qe&&Br(_c,{threadId:qe,bridgeUrl:h,accentColor:ln,isStreaming:ae!==null,isQueued:ae!==null&&!d.activeJobIds.includes(ae),queuePosition:ae&&!d.activeJobIds.includes(ae)?(()=>{let v=new Set(d.activeJobIds),N=Object.keys(Oe).filter(ie=>!v.has(ie)),re=N.indexOf(ae);return re>=0?`(${re+1}/${N.length})`:void 0})():void 0,streamingEvents:It,onClose:()=>st(null),onReply:Vn,onCancel:ae?()=>H(ae):void 0,lastError:d.lastErrorByJob?.[ae??""]??(d.lastCompletedJobId&&gn.current.get(d.lastCompletedJobId)===qe?d.lastErrorByJob?.[d.lastCompletedJobId]:void 0),toolbarRef:x,currentModel:ze.id,currentProvider:M,annotationNumber:cn,annotationText:at?.text,onOpenEvals:qe===Nt?xe:void 0,preferredSide:oe?"left":"right",modal:!oe},`${qe}:${oe?"eval":"default"}`),Br(Tc,{bridge:d,bridgeUrl:h,inFlightJobs:Oe,isVisible:Ke||d.lastResponseText!==null||d.activeJobIds.length>0,onHover:dr,clearSignal:Rn,onReply:Vn,onViewThread:Mo,onClickJob:lr,onCancel:H,onHoverJob:cr,isConnected:d.isConnected,dismissedThreadIds:U,snapPosition:Mn})]})})]})}function Lm(){let e=Em(da);if(!e)throw new Error("usePopmelt must be used within PopmeltProvider");return e}export{Rm as PopmeltProvider,Lm as usePopmelt};
79
+ `}}),Ke("div",{ref:Z,style:{...Im,transition:"opacity 150ms ease"},"data-devtools":"thread-panel-messages",children:[$&&ee("div",{style:{padding:16,color:"#9ca3af",textAlign:"center"},children:"Loading..."}),!$&&k.length===0&&!o&&ee("div",{style:{padding:16,color:"#9ca3af",textAlign:"center"},children:"No messages yet."}),k.map((W,ye)=>ee(eh,{msg:W,index:ye,bridgeUrl:t,accentColor:n,onLightbox:O},`${W.jobId}-${ye}`)),!o&&P&&k.some(W=>W.role==="assistant"&&(W.responseText?.includes("<eval_proposals>")||W.responseText?.includes("<evals>")))&&ee("div",{style:{padding:"0 16px 12px"},children:ee("button",{type:"button",onClick:P,style:{width:"100%",border:"1px solid rgba(0,0,0,0.12)",background:"rgba(0,0,0,0.02)",color:"#6b7280",cursor:"pointer",fontFamily:vn,fontSize:11,fontWeight:650,padding:"5px 8px"},children:"Review proposals"})}),o&&ee("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:r?Ke("div",{style:{display:"flex",alignItems:"center",gap:6},children:[Ke("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:n,style:{verticalAlign:"middle",flexShrink:0,opacity:.5},children:[ee("circle",{cx:"12",cy:"6",r:"2"}),ee("circle",{cx:"6",cy:"12",r:"2"}),ee("circle",{cx:"18",cy:"12",r:"2"}),ee("circle",{cx:"12",cy:"18",r:"2"})]}),Ke("span",{style:{fontSize:11,color:"#9ca3af",fontStyle:"italic"},children:["queued",i?` ${i}`:""]})]}):Ke(Vo,{children:[Ke("div",{style:{display:"flex",alignItems:"center",gap:4},children:[ee(ci,{provider:v,size:11,style:{color:"#6b7280"}}),ee("span",{style:{fontWeight:600,fontSize:11,color:"#6b7280"},children:ba(m,v)})]}),Ie.map((W,ye)=>{if(W.kind==="tool_group")return ee(rd,{tool:W.tool,items:W.items},ye);if(W.kind==="file_content")return ee(Km,{file:W.file,content:W.content,ext:W.ext,isPlan:W.isPlan,onAccept:W.isPlan&&l?()=>l(e,"Looks good, please proceed with implementation."):void 0},ye);if(W.kind==="thinking")return ee("div",{style:{paddingLeft:12,fontSize:11,color:"#9ca3af",fontStyle:"italic",lineHeight:1.4,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:80,overflowY:"auto"},children:W.text},ye);let Se=as(W.text);return Se?ee("div",{style:{paddingLeft:12,lineHeight:1.5,wordBreak:"break-word"},children:xo(Se)},ye):null}),Ke("div",{style:{display:"flex",alignItems:"center",gap:6},children:[ee(Nm,{color:n}),d&&ee("button",{onClick:d,style:{background:"none",border:"1px solid rgba(0,0,0,0.1)",color:"#6b7280",fontSize:10,padding:"2px 8px",cursor:"pointer",fontFamily:"inherit",marginLeft:"auto"},children:"Cancel"})]})]})}),!fe&&k.length>0&&ee("div",{style:{position:"sticky",bottom:5,display:"flex",justifyContent:"flex-end",paddingRight:3,pointerEvents:"none"},children:ee("button",{onClick:()=>{Z.current&&Z.current.scrollTo({top:Z.current.scrollHeight,behavior:"smooth"})},style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",padding:4,fontSize:10,fontFamily:vn,color:"transparent",backgroundColor:"#eaeaea",backgroundImage:`url("data:image/svg+xml,${encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='5' height='5'><path d='M-1,1 l2,-2 M0,5 l5,-5 M4,6 l2,-2' stroke='rgb(0,0,0)' stroke-width='.75'/></svg>")}")`,backgroundSize:"5px 5px",border:"none",borderRadius:0,cursor:"pointer",pointerEvents:"auto",userSelect:"none"},children:Ke("span",{style:{position:"relative",backgroundColor:"#eaeaea",padding:"0 6px",color:"#374151",fontFamily:vn,lineHeight:1.4},children:[le," message",le!==1?"s":""," \u2193"]})})})]}),!o&&c&&Ke("div",{style:{padding:"8px 16px",backgroundColor:"rgba(239, 68, 68, 0.06)",fontSize:11,color:"#dc2626",lineHeight:1.4},children:[ee("span",{style:{fontWeight:600},children:"Error: "}),c]}),l&&Ke("div",{style:{flexShrink:0,position:"relative"},children:[B.length>0&&ee("div",{style:{position:"absolute",bottom:"100%",display:"flex",gap:4,padding:"6px 5px 5px",flexWrap:"wrap"},children:B.map((W,ye)=>Ke("span",{onClick:()=>f(Se=>Se.filter((He,$t)=>$t!==ye)),onMouseEnter:Se=>{let He=Se.currentTarget.querySelector("[data-chip-x]");He&&(He.style.color="#fff")},onMouseLeave:Se=>{let He=Se.currentTarget.querySelector("[data-chip-x]");He&&(He.style.color="rgba(255,255,255,0.4)")},style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:10,color:"#fff",backgroundColor:n,backdropFilter:"blur(4px)",padding:"2px 6px 2px 6px",cursor:"pointer"},children:["image ",ye+1,ee("span",{"data-chip-x":!0,style:{fontSize:12,lineHeight:1,color:"rgba(255,255,255,0.4)"},children:"\xD7"})]},ye))}),Ke("div",{ref:j,style:{...Lm,borderTop:"1px solid rgba(0,0,0,0.12)"},children:[ee("input",{"data-popmelt-reply":!0,autoFocus:!0,value:V,onChange:W=>{M(W.target.value),_e(g.current,W.target.value)},onFocus:()=>{g.current=!0,_e(!0,V)},onBlur:()=>{g.current=!1,_e(!1,V)},onKeyDown:Rt,onPaste:qe,placeholder:"Reply here (cmd + enter to send)",style:{flex:1,minWidth:0,minHeight:44,padding:"0 4px",fontSize:12,fontFamily:vn,backgroundColor:"transparent",color:"#1f2937",border:"none",outline:"none",lineHeight:"40px",boxSizing:"border-box"}}),ee("button",{onClick:it,disabled:!V.trim(),style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",cursor:V.trim()?"pointer":"default",color:V.trim()?n:"rgba(0,0,0,0.2)",flexShrink:0},children:Ke("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[ee("path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z"}),ee("path",{d:"M6 12h16"})]})})]})]})]})]}),Ee&&ee(Wm,{src:Ee,onClose:()=>K(null)})]})}import{jsx as Kr,jsxs as ad}from"react/jsx-runtime";var oh=[],Pa=th(null),Ia="devtools-provider",cs="devtools-model",Ra="devtools-open-thread-id",La="popmelt-synthesize-thread",Aa="popmelt-eval-synthesize-thread",Ur="#000000";function rh(e){let t=e.getBoundingClientRect();return t.bottom<0||t.top>window.innerHeight||t.right<0||t.left>window.innerWidth}function ih(e){for(let t of e){let n=En(t);if(n){rh(n)&&n.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"});return}}}async function sd(e,t){t?await t(e):(window.history.pushState(window.history.state,"",e),window.dispatchEvent(new PopStateEvent("popstate",{state:window.history.state}))),await new Promise(n=>{requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(n,600)}))})}var sh={0:0,1:1},ah={0:0,1:1,2:1};function lh(e,t,n){if(t==="copilot")return 0;let o=t==="codex"?rs:os;return e==="copilot"?0:e==="claude"&&t==="codex"?sh[n]??Math.min(n,o.length-1):e==="codex"&&t==="claude"?ah[n]??Math.min(n,o.length-1):Math.min(n,o.length-1)}function ch({children:e,enabled:t=process.env.NODE_ENV==="development",bridgeUrl:n=typeof window<"u"?window.__POPMELT_BRIDGE_URL__??"http://localhost:1111":"http://localhost:1111",navigate:o}){let r=typeof window<"u"?window.__POPMELT_PROJECT_ID__??null:null,[i,s]=St(r),[a,l]=St(!!r),d=i,[c,p]=Qa(),u=qa(n,t&&!!d,d),m=nn(null),v=nn(null),b=Ka()??n,I=nn(new Map),P=nn(new Map),N=nn(!1),C=kr(),[k,E]=St(()=>typeof window>"u"?"claude":localStorage.getItem(Ia)||"claude"),[$,Q]=St(()=>{if(typeof window>"u")return 0;let S=localStorage.getItem(cs);return S&&parseInt(S,10)||0}),[V,M]=St([]),[B,f]=St({}),[g,j]=St(0),[fe,Re]=St({}),[le,Ce]=St(null),[Ee,K]=St("idle"),[O,Z]=St(null);It(()=>{u.isConnected&&Da(b).then(S=>{if(!S)return;let R=Object.entries(S.providers).filter(([,he])=>he.available).map(([he])=>he);R.length>0&&M(R);let te={};for(let[he,ke]of Object.entries(S.providers))ke.models&&ke.models.length>0&&(te[he]=ke.models);f(te);let ae={};for(let[he,ke]of Object.entries(S.providers))ke.mcp&&(ae[he]=ke.mcp);Re(ae)})},[u.isConnected,u.capabilitiesVersion,g,b]),It(()=>{if(!u.isConnected){Ce(null);return}let S=!1;return Lo(b).then(R=>{S||Ce(R?.version??null)}),()=>{S=!0}},[u.isConnected,u.capabilitiesVersion,g,b]),It(()=>{if(Ee==="idle"||Ee==="restarting")return;let S=window.setTimeout(()=>{K("idle"),Z(null)},Ee==="ok"?4e3:8e3);return()=>window.clearTimeout(S)},[Ee]),It(()=>{if(V.length>0&&!V.includes(k)){let S=V[0];E(S),localStorage.setItem(Ia,S)}},[V,k]);let pe=k==="codex"?[...rs]:k==="copilot"?[...ya]:[...os],Le=B[k]&&B[k].length>0?B[k]:pe,_e=Le[$]??Le[0];It(()=>{if(!t||d||a)return;let S=!1;return fetch("/popmelt/status").then(R=>R.ok?R.json():null).then(R=>{if(S)return;let te=R?.projectId??null;te&&typeof window<"u"&&(window.__POPMELT_PROJECT_ID__=te),s(te),l(!0)}).catch(()=>{S||l(!0)}),()=>{S=!0}},[t,d,a]),It(()=>{$>=Le.length&&(Q(0),localStorage.setItem(cs,"0"))},[$,Le.length]);let ge=zt(S=>{let R=k;E(S),localStorage.setItem(Ia,S);let te=lh(R,S,$);Q(te),localStorage.setItem(cs,String(te))},[k,$]),lt=zt(S=>{Q(S),localStorage.setItem(cs,String(S))},[]),[Xe,ce]=St(new Set),[Ae,ft]=St(null),[G,se]=St(null),[ie,Ne]=St(null),[rt,Ie]=St(null);It(()=>{u.isConnected&&Cr(b).then(S=>{S?.components&&ce(new Set(Object.keys(S.components)))})},[u.isConnected,b]);let et=zt(async S=>{let R=[];for(let te of S)try{(await Ha(te,b)).added&&R.push(te)}catch(ae){console.error("[Popmelt] Failed to add component to model:",te,ae)}R.length>0&&(ce(te=>{let ae=new Set(te);for(let he of R)ae.add(he);return ae}),ft(R[R.length-1]))},[b]),it=zt(S=>{ft(S)},[]),qe=zt(()=>{Cr(b).then(S=>{S?.components&&ce(new Set(Object.keys(S.components)))})},[b]),Rt=zt(async S=>{try{(await Na(S,b)).removed&&ce(te=>{let ae=new Set(te);return ae.delete(S),ae})}catch(R){console.error("[Popmelt] Failed to remove component from model:",R)}},[b]),Kt=zt((S,R)=>{p({type:"MODIFY_SPACING_TOKEN",payload:S}),p({type:"ADD_SPACING_TOKEN_CHANGE",payload:R})},[p]),Dt=zt((S,R)=>{p({type:"DELETE_SPACING_TOKEN",payload:{tokenPath:S,originalValue:R}})},[p]),[Ge,W]=St(null),[ye,Se]=St(()=>typeof window>"u"?null:localStorage.getItem(La)||null),[He,$t]=St(null),[tt,Gt]=St(()=>typeof window>"u"?null:localStorage.getItem(Aa)||null),[Jt,Bt]=St(0),[un,gt]=St({}),[Lt,st]=St(new Set);It(()=>{ye?localStorage.setItem(La,ye):localStorage.removeItem(La)},[ye]),It(()=>{tt?localStorage.setItem(Aa,tt):localStorage.removeItem(Aa)},[tt]);let[Yt,eo]=St(0),sn=nn([]);It(()=>{let S=sn.current,R=c.spacingTokenMods;sn.current=R;let te=new Map(S.map(ke=>[ke.tokenPath,ke])),ae=new Map(R.map(ke=>[ke.tokenPath,ke])),he=!1;for(let[ke,Oe]of ae){let me=te.get(ke);if(!(me&&me.currentValue===Oe.currentValue)){he=!0,Oe.currentValue==="__deleted__"?Fa(ke,b).catch(We=>console.error("[Popmelt] Failed to sync token delete:",We)):fs(ke,Oe.currentValue,b).catch(We=>console.error("[Popmelt] Failed to sync token update:",We));for(let We of Oe.targets){let ln=document.querySelector(We.selector);if(ln)if(Oe.currentValue==="__deleted__")ln.style.removeProperty(We.property);else{let yt=Oe.currentPx;yt>0&&ln.style.setProperty(We.property,`${yt}px`,"important")}}}}for(let[ke,Oe]of te)if(!ae.has(ke)){he=!0,fs(ke,Oe.originalValue,b).catch(me=>console.error("[Popmelt] Failed to restore token on undo:",me));for(let me of Oe.targets){let We=document.querySelector(me.selector);We&&We.style.removeProperty(me.property)}}he&&eo(ke=>ke+1)},[c.spacingTokenMods,b]);let[Un,fo]=St(()=>tl()),On=zt(S=>{fo(S),nl(S)},[]),[nt,at]=St(()=>typeof window>"u"?null:localStorage.getItem(Ra)||null),Xt=nn(null),[U,Te]=St(new Set),[Ue,ht]=St(null);It(()=>{nt?localStorage.setItem(Ra,nt):localStorage.removeItem(Ra)},[nt]);let mt="popmelt-in-flight-jobs",[Pe,ct]=St(()=>{try{let S=localStorage.getItem(mt);return S?JSON.parse(S):{}}catch{return{}}});It(()=>{try{Object.keys(Pe).length>0?localStorage.setItem(mt,JSON.stringify(Pe)):localStorage.removeItem(mt)}catch{}},[Pe]),It(()=>{let S=R=>{if(R.key===mt)try{let te=R.newValue?JSON.parse(R.newValue):{};ct(te)}catch{}};return window.addEventListener("storage",S),()=>window.removeEventListener("storage",S)},[]);let to=nn(new Map),qt=nn(new Map),_n=nn(new Map);It(()=>{for(let[S,R]of Object.entries(Pe)){R.annotationIds.length>0&&to.current.set(S,R.annotationIds);let te=new Set(R.styleSelectors);for(let ae of R.annotationIds){let he=c.annotations.find(ke=>ke.id===ae);if(he&&(he.linkedSelector&&te.add(he.linkedSelector),he.groupId))for(let ke of c.annotations)ke.groupId===he.groupId&&ke.linkedSelector&&te.add(ke.linkedSelector)}te.size>0&&qt.current.set(S,Array.from(te)),R.threadId&&_n.current.set(S,R.threadId)}},[Pe,c.annotations]);let Wt=nn("");It(()=>{if(c.annotations.length===0)return;let S=Object.keys(Pe).sort().join(",");if(S===Wt.current)return;Wt.current=S;let R=new Set;for(let ae of Object.values(Pe))for(let he of ae.annotationIds)R.add(he);let te=c.annotations.filter(ae=>R.has(ae.id)?!1:!!(ae.status==="in_flight"||(ae.status==="pending"||!ae.status)&&(ae.captured||ae.threadId))).map(ae=>ae.id);te.length>0&&p({type:"SET_ANNOTATION_STATUS",payload:{ids:te,status:"dismissed"}})},[c.annotations,Pe,p]);let Ho=po(()=>{let S=new Set;for(let R of Object.values(Pe))for(let te of R.annotationIds)S.add(te);return S},[Pe]),Uo=po(()=>{let S=new Set(u.activeJobIds),R=new Set;for(let[te,ae]of Object.entries(Pe))if(S.has(te))for(let he of ae.annotationIds)R.add(he);return R},[Pe,u.activeJobIds]),wo=po(()=>{let S=new Set(u.activeJobIds),R=Object.entries(Pe).filter(([he])=>!S.has(he)),te=R.length,ae=new Map;return R.forEach(([,he],ke)=>{let Oe=`(${ke+1}/${te})`;for(let me of he.annotationIds)ae.set(me,Oe)}),ae},[Pe,u.activeJobIds]),No=po(()=>{let S=new Set;for(let R of Object.values(Pe))if(!(!R.global&&R.routePathnames?.length&&!R.routePathnames.includes(C)))for(let te of R.styleSelectors)S.add(te);return S},[Pe,C]),Ko=po(()=>{let S=new Map;for(let R of Object.values(Pe))if(!(!R.global&&R.routePathnames?.length&&!R.routePathnames.includes(C))){for(let te of R.styleSelectors)S.set(te,R.color);for(let te of R.annotationIds){let ae=c.annotations.find(he=>he.id===te);if(ae&&(ae.linkedSelector&&S.set(ae.linkedSelector,R.color),ae.groupId))for(let he of c.annotations)he.groupId===ae.groupId&&he.linkedSelector&&S.set(he.linkedSelector,R.color)}}return S},[Pe,c.annotations,C]),an=nn(c.annotations);an.current=c.annotations;let Xo=nn(c.styleModifications);Xo.current=c.styleModifications;let Co=nn(Pe);Co.current=Pe,It(()=>{let S=null,R=()=>{if(Object.keys(Co.current).length>0)return;let ae=an.current,he=Xo.current,ke=[],Oe=[];for(let me of ae){if(!me.linkedSelector||!me.linkedSelector.startsWith("[data-pm=")||me.pathname||me.captured||me.status&&me.status!=="pending")continue;let We=document.querySelector(me.linkedSelector);!We&&me.elements?.[0]?.selector&&(We=document.querySelector(me.elements[0].selector)),We||ke.push(me.linkedSelector)}for(let me of he)me.pathname&&me.pathname!==window.location.pathname||document.querySelector(me.selector)||Oe.push(me.selector);(ke.length>0||Oe.length>0)&&p({type:"CLEANUP_ORPHANED",payload:{linkedSelectors:ke,styleSelectors:Oe}})},te=new MutationObserver(ae=>{ae.some(he=>he.removedNodes.length>0)&&(S&&clearTimeout(S),S=setTimeout(R,3e3))});return te.observe(document.body,{childList:!0,subtree:!0}),()=>{te.disconnect(),S&&clearTimeout(S)}},[p]);let Je=nn(typeof window<"u"?window.location.pathname:"/");It(()=>{let S=ae=>{if(N.current)return;let he=window.location.pathname;if(ae===he)return;let ke=an.current.filter(me=>me.pathname===ae&&(me.status??"pending")==="pending");if(console.log(`[Popmelt] Navigation from ${ae} \u2192 ${he}, ${ke.length} pending annotations on departing page`),ke.length===0)return;let Oe=m.current;if(!Oe){console.warn("[Popmelt] No canvas ref for capture-on-leave");return}if(Pr(document.body,Oe,ke,{dpr:1}).then(me=>ti(me)).then(me=>{me?(P.current.set(ae,me),console.log(`[Popmelt] Cached screenshot for ${ae} (${(me.size/1024).toFixed(0)}KB)`)):console.warn(`[Popmelt] Capture-on-leave produced no blob for ${ae}`)}).catch(me=>{console.warn("[Popmelt] Capture-on-leave failed:",me)}),P.current.size>20){let me=[...P.current.entries()];P.current=new Map(me.slice(-10))}},R=ae=>{let he=ae.detail?.prevPath;he&&(S(he),Je.current=window.location.pathname)},te=()=>{let ae=Je.current;S(ae),Je.current=window.location.pathname};return window.addEventListener("popmelt:locationchange",R),window.addEventListener("popstate",te),()=>{window.removeEventListener("popmelt:locationchange",R),window.removeEventListener("popstate",te)}},[]),It(()=>{if(u.lastCompletedJobId&&u.lastCompletedJobId in Pe&&ct(S=>{let{[u.lastCompletedJobId]:R,...te}=S;return te}),u.lastCompletedJobId&&u.lastCompletedJobId===Ge&&(eo(S=>S+1),W(null)),u.lastCompletedJobId&&u.lastCompletedJobId===He&&(Bt(S=>S+1),$t(null)),u.lastCompletedJobId){let S=Object.entries(un).find(([,R])=>R===u.lastCompletedJobId)?.[0];S&&(gt(R=>{let{[S]:te,...ae}=R;return ae}),Bt(R=>R+1))}},[u.lastCompletedJobId,Ge,He,un]);let no=nn(new Set),Ct=nn(!1);It(()=>{if(!u.isConnected){Ct.current=!1;return}Ct.current||(Ct.current=!0,Lo(b).then(async S=>{if(!S)return;let R=S.activeJobs??[],te=S.recentJobs??[],ae=new Set(R.map(Oe=>Oe.id)),he=JSON.parse(localStorage.getItem(mt)||"{}"),ke=new Set;for(let Oe of Object.values(he))if(Oe.annotationIds)for(let me of Oe.annotationIds)ke.add(me);ct(Oe=>{let me={...Oe},We=Date.now();for(let yt of Object.keys(me)){if(yt.startsWith("_pending_")){let kt=parseInt(yt.replace(/^_pending_(?:reply_)?/,""),10);!isNaN(kt)&&We-kt>3e4&&delete me[yt];continue}ae.has(yt)||delete me[yt]}for(let yt of R)if(!me[yt.id]&&(yt.annotationIds?.length||yt.threadId)){let kt=yt.kind,Wn=Array.from(new Set((yt.annotationIds??[]).map(er=>c.annotations.find(To=>To.id===er)?.pathname||C).filter(Boolean)));me[yt.id]={annotationIds:yt.annotationIds??[],styleSelectors:[],color:kt==="synthesize_evals"||kt==="run_eval"?Ur:yt.color??"#888",threadId:yt.threadId,kind:kt,routePathnames:Wn.length>0?Wn:void 0,global:kt==="synthesize"||kt==="synthesize_evals"||kt==="run_eval"}}let ln=new Set;for(let yt of te)if(yt.annotationIds)for(let kt of yt.annotationIds)ln.add(kt);for(let yt of Object.keys(me)){if(!yt.startsWith("_pending_"))continue;let kt=me[yt];kt&&kt.annotationIds.some(Wn=>ln.has(Wn))&&delete me[yt]}return me});for(let Oe of te)if(Oe.status==="done"&&Oe.annotationIds?.length&&Oe.annotationIds.some(me=>ke.has(me))&&!no.current.has(Oe.id))try{let me=await bi(b,Oe.id);if(!me)continue;let We=me.events.find(ln=>ln.type==="done");We&&Array.isArray(We.resolutions)&&(no.current.add(Oe.id),p({type:"APPLY_RESOLUTIONS",payload:{resolutions:We.resolutions,threadId:We.threadId??void 0}}))}catch{}}))},[u.isConnected,b,p,c.annotations,C]),It(()=>{let S=u.events.filter(R=>R.type==="done"&&R.data.resolutions);for(let R of S){let te=R.data.jobId;no.current.has(te)||(no.current.add(te),Array.isArray(R.data.resolutions)&&p({type:"APPLY_RESOLUTIONS",payload:{resolutions:R.data.resolutions,threadId:R.data.threadId}}))}},[u.events,p]);let kn=nn(new Set);It(()=>{let S=u.events.filter(R=>R.type==="error"&&R.data.cancelled);for(let R of S){let te=R.data.jobId;if(!te||kn.current.has(te))continue;kn.current.add(te);let ae=Pe[te];ae&&ae.annotationIds.length>0&&p({type:"SET_ANNOTATION_STATUS",payload:{ids:ae.annotationIds,status:"dismissed"}})}},[u.events,Pe,p]);let yn=nn(0);It(()=>{let S=u.incrementalResolutions;if(S.length<=yn.current)return;let R=S.slice(yn.current);yn.current=S.length,p({type:"APPLY_RESOLUTIONS",payload:{resolutions:R}})},[u.incrementalResolutions,p]),It(()=>{u.incrementalResolutions.length===0&&(yn.current=0)},[u.incrementalResolutions.length]);let An=zt(async()=>{let S=m.current;if(!S)return!1;let R=await Pr(document.body,S,c.annotations);if(R.length===0)return!1;let te=await El(R,c.annotations,c.styleModifications);return te&&p({type:"MARK_CAPTURED"}),te},[c.annotations,c.styleModifications,p]),qo=zt((S,R)=>{let te=I.current.get(S)||[];I.current.set(S,[...te,...R])},[]),oo=zt(async()=>{let S=m.current;if(!S)return!1;let R=c.annotations.filter(Ye=>(Ye.status??"pending")==="pending"),te=c.styleModifications.filter(Ye=>!Ye.captured&&(!Ye.pathname||Ye.pathname===C)),ae=c.spacingTokenChanges.filter(Ye=>!Ye.captured);if(R.length===0&&te.length===0&&ae.length===0)return!1;let he=new Map;for(let Ye of R){let Qt=Ye.pathname||C;he.has(Qt)||he.set(Qt,[]),he.get(Qt).push(Ye)}let ke=new Map,Oe=[...he.keys()].filter(Ye=>Ye!==C);if(Oe.length>0){let Ye=C,Qt={x:window.scrollX,y:window.scrollY};N.current=!0;for(let gn of Oe)try{console.log(`[Popmelt] Navigating to ${gn} for screenshot capture`),await sd(gn,o),window.location.pathname!==gn&&console.warn(`[Popmelt] Navigation to ${gn} did not take effect (at ${window.location.pathname})`);let Nn=he.get(gn)||[],yi=await Pr(document.body,S,Nn,{dpr:1}),h=await ti(yi);h&&(ke.set(gn,h),console.log(`[Popmelt] Captured ${gn} (${(h.size/1024).toFixed(0)}KB)`))}catch(Nn){console.warn(`[Popmelt] Failed to capture ${gn}:`,Nn)}await sd(Ye,o),window.scrollTo(Qt.x,Qt.y),N.current=!1}let me=R.filter(Ye=>(Ye.pathname||C)===C),We=await Pr(document.body,S,me.length>0?c.annotations:[],{dpr:1});if(We.length>0){let Ye=await ti(We);Ye&&ke.set(C,Ye)}if(ke.size===0)return!1;let ln=Is(R,te,void 0,ae.length>0?ae:void 0),yt=JSON.stringify(ln),kt=new Map;for(let Ye of R){let Qt=I.current.get(Ye.id);if(Qt&&Qt.length>0&&kt.set(Ye.id,Qt),Ye.groupId){for(let gn of R)if(gn.groupId===Ye.groupId&&gn.id!==Ye.id){let Nn=I.current.get(gn.id);Nn&&Nn.length>0&&kt.set(gn.id,Nn)}}}let Wn=he.size>1;console.log(`[Popmelt] Submit: ${he.size} page(s), ${ke.size} screenshot(s), pages: [${[...he.keys()].join(", ")}], cached: [${[...P.current.keys()].join(", ")}]`);let er=Wn?ke:ke.get(C)??ke,To=R.map(Ye=>Ye.id),ds=te.map(Ye=>Ye.selector),us=Array.from(new Set([...R.map(Ye=>Ye.pathname||C),...te.map(Ye=>Ye.pathname||C)])),hi=Ms(c.activeColor),ko=`_pending_${Date.now()}`,Xr={annotationIds:To,styleSelectors:ds,color:c.activeColor,threadId:void 0,routePathnames:us};try{let Ye=JSON.parse(localStorage.getItem(mt)||"{}");Ye[ko]=Xr,localStorage.setItem(mt,JSON.stringify(Ye))}catch{}ct(Ye=>({...Ye,[ko]:Xr}));try{let{jobId:Ye,threadId:Qt}=await _a(er,yt,b,hi,k,_e.id,kt.size>0?kt:void 0,Ti());for(let x of kt.keys())I.current.delete(x);for(let x of he.keys())P.current.delete(x);let gn={...Xr,threadId:Qt};try{let x=JSON.parse(localStorage.getItem(mt)||"{}");delete x[ko],x[Ye]=gn,localStorage.setItem(mt,JSON.stringify(x))}catch{}ct(x=>{let{[ko]:_,...y}=x;return{...y,[Ye]:gn}}),p({type:"MARK_CAPTURED"}),Qt&&To.length>0&&p({type:"SET_ANNOTATION_THREAD",payload:{ids:To,threadId:Qt}});let Nn=c.activeColor.match(/oklch\([^)]*\s+([\d.]+)\s*\)/),h=((Nn?.[1]?parseFloat(Nn[1]):29)+60)%360;return p({type:"SET_COLOR",payload:`oklch(0.628 0.258 ${h})`}),!0}catch(Ye){try{let Qt=JSON.parse(localStorage.getItem(mt)||"{}");delete Qt[ko],localStorage.setItem(mt,JSON.stringify(Qt))}catch{}return ct(Qt=>{let{[ko]:gn,...Nn}=Qt;return Nn}),console.error("[Pare] Failed to send to bridge:",Ye),!1}},[c.annotations,c.styleModifications,c.spacingTokenChanges,c.activeColor,p,b,k,_e.id,C,o]),ro=zt(async()=>{if(ye){at(ye);return}try{let{jobId:S,threadId:R}=await Ga(b,k,_e.id);W(S),Se(R);let te={annotationIds:[],styleSelectors:[],color:"#6b7280",threadId:R,kind:"synthesize",global:!0};ct(ae=>({...ae,[S]:te})),at(R)}catch(S){console.error("[Popmelt] Failed to start synthesize:",S)}},[b,k,_e.id,ye]),Kn=zt(async()=>{$t(null),Gt(null),at(null);try{let{jobId:S,threadId:R}=await Ja(b,k,_e.id);$t(S),Gt(R);let te={annotationIds:[],styleSelectors:[],color:Ur,threadId:R,kind:"synthesize_evals",global:!0};ct(ae=>({...ae,[S]:te})),at(R)}catch(S){console.error("[Popmelt] Failed to start eval synthesis:",S)}},[b,k,_e.id]),Zt=zt(async S=>{let R=m.current;if(R){gt(te=>({...te,[S.id]:"_pending_"}));try{let ae=(await Pr(document.body,R,[],{dpr:1}))[0];if(!ae){gt(Oe=>{let{[S.id]:me,...We}=Oe;return We});return}let{jobId:he,threadId:ke}=await Wa(S.id,ae,{url:window.location.href,viewport:{width:window.innerWidth,height:window.innerHeight},scrollX:window.scrollX,scrollY:window.scrollY},b,k,_e.id,Ti());if(gt(Oe=>({...Oe,[S.id]:he})),ke){st(me=>new Set(me).add(ke));let Oe={annotationIds:[],styleSelectors:[],color:Ur,threadId:ke,kind:"run_eval",global:!0};ct(me=>({...me,[he]:Oe})),at(ke)}}catch(te){gt(ae=>{let{[S.id]:he,...ke}=ae;return ke}),console.error("[Popmelt] Failed to run eval:",te)}}},[b,k,_e.id]),io=zt(async(S,R,te)=>{let ae=Object.values(Co.current).find(We=>We.threadId===S)?.color??c.annotations.find(We=>We.threadId===S)?.color??c.activeColor,he=c.annotations.filter(We=>We.threadId===S&&(We.status==="waiting_input"||We.status==="resolved"||We.status==="needs_review")),ke=he.map(We=>We.id),Oe=`_pending_reply_${Date.now()}`,me={annotationIds:ke,styleSelectors:[],color:ae,threadId:S};try{let We=JSON.parse(localStorage.getItem(mt)||"{}");We[Oe]=me,localStorage.setItem(mt,JSON.stringify(We))}catch{}ct(We=>({...We,[Oe]:me}));try{let We=Ms(c.activeColor),{jobId:ln}=await Ya(S,R,b,We,k,_e.id,te,Ti()),yt={...me};try{let kt=JSON.parse(localStorage.getItem(mt)||"{}");delete kt[Oe],kt[ln]=yt,localStorage.setItem(mt,JSON.stringify(kt))}catch{}ct(kt=>{let{[Oe]:Wn,...er}=kt;return{...er,[ln]:yt}}),he.length>0&&p({type:"SET_ANNOTATION_STATUS",payload:{ids:ke,status:"in_flight"}}),u.dismissQuestion(S)}catch(We){try{let ln=JSON.parse(localStorage.getItem(mt)||"{}");delete ln[Oe],localStorage.setItem(mt,JSON.stringify(ln))}catch{}ct(ln=>{let{[Oe]:yt,...kt}=ln;return kt}),console.error("[Pare] Failed to send reply:",We)}},[c.activeColor,c.annotations,b,u.dismissQuestion,p,k,_e.id]),Zo=nn(new Set);It(()=>{for(let S of u.pendingQuestions){if(Zo.current.has(S.jobId))continue;Zo.current.add(S.jobId);let R=S.annotationIds&&S.annotationIds.length>0?S.annotationIds:void 0;!R&&S.threadId&&(R=c.annotations.filter(te=>te.threadId===S.threadId).map(te=>te.id)),R&&R.length>0&&p({type:"SET_ANNOTATION_QUESTION",payload:{ids:R,question:S.question,threadId:S.threadId}})}},[u.pendingQuestions,p,c.annotations]);let Fo=po(()=>{if(u.activeJobId&&u.activeJobId in Pe)return Pe[u.activeJobId].color;let S=Object.values(Pe);return S.length>0?S[S.length-1].color:void 0},[u.activeJobId,Pe]),zo=zt(S=>{at(S)},[]),Qo=zt(S=>{st(R=>new Set(R).add(S)),Xt.current=Ur,at(S)},[]),$o=zt(S=>{let R=Pe[S],te=qt.current.get(S);if(R){let he=new Set(R.styleSelectors);for(let ke of R.annotationIds){let Oe=c.annotations.find(me=>me.id===ke);if(Oe&&(Oe.linkedSelector&&he.add(Oe.linkedSelector),Oe.groupId))for(let me of c.annotations)me.groupId===Oe.groupId&&me.linkedSelector&&he.add(me.linkedSelector)}he.size>0&&(te=Array.from(he))}te?.length&&ih(te);let ae=R?.threadId||_n.current.get(S);ae&&(Xt.current=R?.kind==="synthesize_evals"||R?.kind==="run_eval"?Ur:R?.color??null,at(ae))},[Pe,c.annotations]),A=zt(S=>{if(!S){ht(null);return}let R=to.current.get(S);R&&R.length>0?ht(new Set(R)):ht(null)},[]),F=zt(async S=>{try{let R=S?`${b}/cancel?jobId=${S}`:`${b}/cancel`;await Ro(R,{method:"POST"})}catch{}},[b]),oe=zt(async()=>{K("restarting"),Z("Restarting bridge");let S=await gs(b,Ni,2e4);if(S.ok){Ce(S.status.version??Ni),K("ok"),Z(S.status.version?`Bridge restarted on ${S.status.version}`:"Bridge restarted"),j(R=>R+1);return}Ce(S.status?.version??le),K("error"),Z(S.error)},[le,b]),re=po(()=>{if(!nt)return null;for(let S of Object.values(Pe))if(S.threadId===nt&&S.kind)return S.kind;return nt===ye?"synthesize":nt===tt?"synthesize_evals":Lt.has(nt)?"run_eval":null},[nt,Pe,ye,tt,Lt]),ne=re==="synthesize_evals"||re==="run_eval",we=re==="synthesize";It(()=>{(c.activeTool==="model"&&nt&&!we||c.activeTool==="eval"&&nt&&!ne)&&at(null)},[c.activeTool,nt,we,ne]);let Be=zt(()=>{p({type:"SET_TOOL",payload:"eval"}),Bt(S=>S+1),at(null)},[p]),ve=nn(null);It(()=>{c.isAnnotating?ve.current&&(at(ve.current),ve.current=null):nt&&(ve.current=nt,at(null))},[c.isAnnotating]);let ut=po(()=>{if(!nt)return null;for(let[S,R]of Object.entries(Pe))if(R.threadId===nt)return S;for(let[S,R]of Object.entries(u.activeJobThreads))if(R===nt)return S;return null},[nt,Pe,u.activeJobThreads]),Et=nt?c.annotations.find(S=>S.threadId===nt):void 0,Vt=po(()=>ut?u.events.filter(S=>S.data.jobId===ut):oh,[ut,u.events.length]),pn=po(()=>ne?Ur:Et?.color??Xt.current??c.activeColor,[ne,Et?.color,c.activeColor]),ot=Et?c.annotations.indexOf(Et)+1:void 0;It(()=>{if(ne)return;let S=Et?.color??Xt.current;nt&&S&&p({type:"SET_COLOR",payload:S})},[nt,ne]);let[wn,Cn]=St(!1),[fn,Mn]=St(0),Hn=nn(null),go=zt(S=>{S?(Hn.current&&(clearTimeout(Hn.current),Hn.current=null),Cn(!0)):Hn.current=setTimeout(()=>{Cn(!1),Hn.current=null},150)},[]),wr=zt(()=>{Mn(S=>S+1),u.clearEvents(),at(null),Te(new Set),F()},[u.clearEvents,F]);It(()=>()=>{Hn.current&&clearTimeout(Hn.current)},[]);let[gi,mi]=St(!1);It(()=>{mi(!0)},[]);let Eo=po(()=>({isEnabled:t}),[t]);return!t||!gi?Kr(Pa.Provider,{value:Eo,children:e}):ad(Pa.Provider,{value:Eo,children:[e,Kr(pc,{state:c,dispatch:p,onScreenshot:An,inFlightAnnotationIds:Ho,activeAnnotationIds:Uo,queuePositionMap:wo,inFlightStyleSelectors:No,inFlightSelectorColors:Ko,onAttachImages:qo,onReply:u.isConnected?io:void 0,onViewThread:u.isConnected?zo:void 0,onCloseThread:S=>{at(null),S&&Te(R=>new Set(R).add(S))},onModelComponentsAdd:u.isConnected?et:void 0,onModelComponentFocus:u.isConnected?it:void 0,onModelComponentHover:se,modelComponentNames:Xe,modelPanelHoveredComponent:ie,modelSpacingTokenHover:rt,highlightedAnnotationIds:Ue,focusedThreadAnnotationId:Et?.id,externalCanvasRef:m,toolbarRef:v}),Kr(qc,{children:ad(Kc,{children:[Kr(jc,{state:c,dispatch:p,onScreenshot:An,onSendToClaude:u.isConnected?oo:void 0,hasActiveJobs:Object.keys(Pe).length>0||u.activeJobIds.length>0,activeJobColor:Fo,onCrosshairHover:go,onClear:wr,provider:k,onProviderChange:u.isConnected&&V.length>1?ge:void 0,availableProviders:V,modelIndex:$,modelCount:Le.length,modelLabel:_e.label,onModelChange:u.isConnected?lt:void 0,onViewThread:u.isConnected?zo:void 0,isThreadPanelOpen:nt!==null&&!we&&!ne,mcpStatus:fe,bridgeUrl:b,isBridgeConnected:u.isConnected,packageVersion:Ni,bridgeVersion:le,bridgeRestartState:Ee,bridgeRestartMessage:O,onBridgeRestart:oe,modelSelectedComponent:Ae,modelCanvasHoveredComponent:G,onModelComponentHover:Ne,onSpacingTokenHover:Ie,onModifySpacingToken:u.isConnected?Kt:void 0,onDeleteSpacingToken:u.isConnected?Dt:void 0,modelRefreshKey:Yt,onModelComponentAdded:qe,onModelComponentRemoved:Rt,onSynthesizeRules:u.isConnected&&k!=="copilot"?ro:void 0,isSynthesizing:Ge!==null,onSynthesizeEvals:u.isConnected&&k!=="copilot"?Kn:void 0,isSynthesizingEvals:He!==null,onRunEval:u.isConnected&&k!=="copilot"?Zt:void 0,onViewEvalRunThread:Qo,runningEvalIds:Object.keys(un),evalRefreshKey:Jt,toolbarRef:v,snapPosition:Un,onSnapPositionChange:On}),nt&&Kr(id,{threadId:nt,bridgeUrl:b,accentColor:pn,isStreaming:ut!==null,isQueued:ut!==null&&!u.activeJobIds.includes(ut),queuePosition:ut&&!u.activeJobIds.includes(ut)?(()=>{let S=new Set(u.activeJobIds),R=Object.keys(Pe).filter(ae=>!S.has(ae)),te=R.indexOf(ut);return te>=0?`(${te+1}/${R.length})`:void 0})():void 0,streamingEvents:Vt,onClose:()=>at(null),onReply:io,onCancel:ut?()=>F(ut):void 0,lastError:u.lastErrorByJob?.[ut??""]??(u.lastCompletedJobId&&_n.current.get(u.lastCompletedJobId)===nt?u.lastErrorByJob?.[u.lastCompletedJobId]:void 0),toolbarRef:v,currentModel:_e.id,currentProvider:k,annotationNumber:ot,annotationText:Et?.text,onOpenEvals:nt===tt?Be:void 0,preferredSide:ne?"left":"right",modal:!ne},`${nt}:${ne?"eval":"default"}`),Kr(Uc,{bridge:u,bridgeUrl:b,inFlightJobs:Pe,isVisible:wn||u.lastResponseText!==null||u.activeJobIds.length>0,onHover:go,clearSignal:fn,onReply:io,onViewThread:zo,onClickJob:$o,onCancel:F,onHoverJob:A,isConnected:u.isConnected,dismissedThreadIds:U,snapPosition:Un,currentPathname:C})]})})]})}function dh(){let e=nh(Pa);if(!e)throw new Error("usePopmelt must be used within PopmeltProvider");return e}export{ch as PopmeltProvider,dh as usePopmelt};