@popmelt.com/core 0.7.5 → 0.7.6

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,10 +1,10 @@
1
1
  "use client";
2
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.5";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(`
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
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()},re=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(`
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
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=re.height+8,$e=re.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:re.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:re.isWrapped?"pre-wrap":"pre",wordBreak:re.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:`
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:`
8
8
  .popmelt-eval-assertion-input::placeholder {
9
9
  color: #aaa;
10
10
  opacity: 1;
@@ -76,4 +76,4 @@ Your AI gets the visual and technical context it needs to act.`,usage:[],keys:[{
76
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
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+`
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||a),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 ie={};for(let[Ie,_e]of Object.entries(v.providers))_e.models&&_e.models.length>0&&(ie[Ie]=_e.models);y(ie);let re={};for(let[Ie,_e]of Object.entries(v.providers))_e.mcp&&(re[Ie]=_e.mcp);We(re)})},[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=>{v||(s(N?.projectId??null),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 ie=Im(N,v,J);ee(ie),localStorage.setItem(Wi,String(ie))},[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 ie of v)try{(await ma(ie,h)).added&&N.push(ie)}catch(re){console.error("[Popmelt] Failed to add component to model:",ie,re)}N.length>0&&(Qe(ie=>{let re=new Set(ie);for(let Ie of N)re.add(Ie);return re}),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(ie=>{let re=new Set(ie);return re.delete(v),re})}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 ie=new Map(v.map(_e=>[_e.tokenPath,_e])),re=new Map(N.map(_e=>[_e.tokenPath,_e])),Ie=!1;for(let[_e,$e]of re){let ve=ie.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 ie)if(!re.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 ie=N.newValue?JSON.parse(N.newValue):{};St(ie)}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 re of Object.values(Oe))for(let Ie of re.annotationIds)N.add(Ie);let ie=c.annotations.filter(re=>N.has(re.id)?!1:!!(re.status==="in_flight"||(re.status==="pending"||!re.status)&&(re.captured||re.threadId))).map(re=>re.id);ie.length>0&&u({type:"SET_ANNOTATION_STATUS",payload:{ids:ie,status:"dismissed"}})},[c.annotations,Oe,u]);let po=to(()=>{let v=new Set;for(let N of Object.values(Oe))for(let ie of N.annotationIds)v.add(ie);return v},[Oe]),Wt=to(()=>{let v=new Set(d.activeJobIds),N=new Set;for(let[ie,re]of Object.entries(Oe))if(v.has(ie))for(let Ie of re.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)),ie=N.length,re=new Map;return N.forEach(([,Ie],_e)=>{let $e=`(${_e+1}/${ie})`;for(let ve of Ie.annotationIds)re.set(ve,$e)}),re},[Oe,d.activeJobIds]),fo=to(()=>{let v=new Set;for(let N of Object.values(Oe))for(let ie of N.styleSelectors)v.add(ie);return v},[Oe]),ir=to(()=>{let v=new Map;for(let N of Object.values(Oe)){for(let ie of N.styleSelectors)v.set(ie,N.color);for(let ie of N.annotationIds){let re=c.annotations.find(Ie=>Ie.id===ie);if(re&&(re.linkedSelector&&v.set(re.linkedSelector,N.color),re.groupId))for(let Ie of c.annotations)Ie.groupId===re.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 re=Jn.current,Ie=Sn.current,_e=[],$e=[];for(let ve of re){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}})},ie=new MutationObserver(re=>{re.some(Ie=>Ie.removedNodes.length>0)&&(v&&clearTimeout(v),v=setTimeout(N,3e3))});return ie.observe(document.body,{childList:!0,subtree:!0}),()=>{ie.disconnect(),v&&clearTimeout(v)}},[u]);let Yn=qt(typeof window<"u"?window.location.pathname:"/");Et(()=>{let v=re=>{if(P.current)return;let Ie=window.location.pathname;if(re===Ie)return;let _e=Jn.current.filter(ve=>ve.pathname===re&&(ve.status??"pending")==="pending");if(console.log(`[Popmelt] Navigation from ${re} \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(re,ve),console.log(`[Popmelt] Cached screenshot for ${re} (${(ve.size/1024).toFixed(0)}KB)`)):console.warn(`[Popmelt] Capture-on-leave produced no blob for ${re}`)}).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=re=>{let Ie=re.detail?.prevPath;Ie&&(v(Ie),Yn.current=window.location.pathname)},ie=()=>{let re=Yn.current;v(re),Yn.current=window.location.pathname};return window.addEventListener("popmelt:locationchange",N),window.addEventListener("popstate",ie),()=>{window.removeEventListener("popmelt:locationchange",N),window.removeEventListener("popstate",ie)}},[]),Et(()=>{if(d.lastCompletedJobId&&d.lastCompletedJobId in Oe&&St(v=>{let{[d.lastCompletedJobId]:N,...ie}=v;return ie}),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]:ie,...re}=N;return re}),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??[],ie=v.recentJobs??[],re=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}re.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 ie)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 ie)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 ie=N.data.jobId;Ft.current.has(ie)||(Ft.current.add(ie),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 ie=N.data.jobId;if(!ie||jt.current.has(ie))continue;jt.current.add(ie);let re=Oe[ie];re&&re.annotationIds.length>0&&u({type:"SET_ANNOTATION_STATUS",payload:{ids:re.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 ie=await $a(N,c.annotations,c.styleModifications);return ie&&u({type:"MARK_CAPTURED"}),ie},[c.annotations,c.styleModifications,u]),io=Ht((v,N)=>{let ie=I.current.get(v)||[];I.current.set(v,[...ie,...N])},[]),In=Ht(async()=>{let v=g.current;if(!v)return!1;let N=c.annotations.filter(w=>(w.status??"pending")==="pending"),ie=c.spacingTokenChanges.filter(w=>!w.captured);if(N.length===0&&c.styleModifications.filter(w=>!w.captured).length===0&&ie.length===0)return!1;let re=new Map;for(let w of N){let W=w.pathname||F;re.has(W)||re.set(W,[]),re.get(W).push(w)}let Ie=new Map,_e=[...re.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=re.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,ie.length>0?ie: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=re.size>1;console.log(`[Popmelt] Submit: ${re.size} page(s), ${Ie.size} screenshot(s), pages: [${[...re.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 re.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 ie={annotationIds:[],styleSelectors:[],color:"#6b7280",threadId:N,kind:"synthesize"};St(re=>({...re,[v]:ie})),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 ie={annotationIds:[],styleSelectors:[],color:Or,threadId:N,kind:"synthesize_evals"};St(re=>({...re,[v]:ie})),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(ie=>({...ie,[v.id]:"_pending_"}));try{let re=(await hr(document.body,N,[],{dpr:1}))[0];if(!re){Kt($e=>{let{[v.id]:ve,...f}=$e;return f});return}let{jobId:Ie,threadId:_e}=await xa(v.id,re,{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(ie){Kt(re=>{let{[v.id]:Ie,..._e}=re;return _e}),console.error("[Popmelt] Failed to run eval:",ie)}}},[h,M,ze.id]),Vn=Ht(async(v,N,ie)=>{let re=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:re,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,ie,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(ie=>ie.threadId===v.threadId).map(ie=>ie.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],ie=N?.threadId||gn.current.get(v);ie&&(fn.current=N?.kind==="synthesize_evals"||N?.kind==="run_eval"?Or:N?.color??null,st(ie))},[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(re=>!v.has(re)),ie=N.indexOf(ae);return ie>=0?`(${ie+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
+ `}}),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};