@qwanyx/stack 0.2.119 → 0.2.120

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.cjs.js CHANGED
@@ -180,9 +180,9 @@ React keys must be passed directly to JSX without using spread:
180
180
  from { transform: rotate(0deg); }
181
181
  to { transform: rotate(360deg); }
182
182
  }
183
- `})]})}const Rg={background:"#ffffff",text:"#111827",textSecondary:"#6b7280",border:"#e5e7eb",primary:"#3b82f6",chipBackground:"#f3f4f6",chipText:"#374151",hoverBackground:"#f9fafb"};function Fg({options:r,value:e,onChange:t,placeholder:n="Search or select...",allowCreate:s=!0,onCreate:i,allowDelete:o=!1,onDelete:a,label:l,disabled:u=!1,max:c=0,theme:d={},className:h=""}){const p={...Rg,...d},[g,m]=y.useState(!1),[x,_]=y.useState(""),b=y.useRef(null),S=y.useRef(null);y.useEffect(()=>{function N(R){b.current&&!b.current.contains(R.target)&&(m(!1),_(""))}return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);const C=r.filter(N=>{var R;return((R=N.label)==null?void 0:R.toLowerCase().includes(x.toLowerCase()))&&!e.includes(N.id)}),k=s&&x.trim()&&!r.some(N=>{var R;return((R=N.label)==null?void 0:R.toLowerCase())===x.toLowerCase()}),E=e.map(N=>r.find(R=>R.id===N)).filter(Boolean),v=y.useCallback(N=>{var R;c>0&&e.length>=c||(t([...e,N]),_(""),c===1?m(!1):(R=S.current)==null||R.focus())},[e,t,c]),T=y.useCallback(N=>{t(e.filter(R=>R!==N))},[e,t]),B=y.useCallback(async()=>{if(!k)return;const N=await(i==null?void 0:i(x.trim()));N&&v(N.id),_("")},[k,x,i,v]),j=y.useCallback(N=>{N.key==="Enter"?(N.preventDefault(),k?B():C.length>0&&v(C[0].id)):N.key==="Backspace"&&!x&&e.length>0?T(e[e.length-1]):N.key==="Escape"&&(m(!1),_(""))},[k,C,x,e,B,v,T]);return f.jsxs("div",{ref:b,className:h,style:{position:"relative"},children:[l&&f.jsx("label",{style:{display:"block",fontSize:"12px",textTransform:"uppercase",color:p.textSecondary,marginBottom:"4px"},children:l}),f.jsxs("div",{onClick:()=>!u&&m(!0),style:{display:"flex",flexWrap:"wrap",gap:"6px",padding:"8px 12px",border:`1px solid ${g?p.primary:p.border}`,borderRadius:"8px",background:u?p.hoverBackground:p.background,cursor:u?"not-allowed":"text",minHeight:"42px",alignItems:"center"},children:[E.map(N=>f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"4px",fontSize:"13px",background:N.color||p.chipBackground,color:N.color?"#fff":p.chipText},children:[N.label,!u&&f.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),T(N.id)},style:{border:"none",background:"transparent",cursor:"pointer",padding:"0 2px",fontSize:"14px",color:"inherit",opacity:.7},children:"×"})]},N.id)),f.jsx("input",{ref:S,type:"text",value:x,onChange:N=>{_(N.target.value),g||m(!0)},onFocus:()=>m(!0),onKeyDown:j,placeholder:E.length===0?n:"",disabled:u||c>0&&e.length>=c,style:{flex:1,minWidth:"60px",border:"none",outline:"none",fontSize:"14px",background:"transparent",color:p.text}})]}),g&&!u&&f.jsx("div",{style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:p.background,border:`1px solid ${p.border}`,borderRadius:"8px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",maxHeight:"200px",overflowY:"auto",zIndex:50},children:C.length===0&&!k?f.jsx("div",{style:{padding:"12px",fontSize:"14px",color:p.textSecondary,textAlign:"center"},children:x?"No matches":"No options available"}):f.jsxs(f.Fragment,{children:[C.map(N=>f.jsxs("div",{onClick:()=>v(N.id),style:{padding:"10px 12px",fontSize:"14px",cursor:"pointer",color:p.text,display:"flex",alignItems:"center",justifyContent:"space-between"},onMouseEnter:R=>{R.currentTarget.style.background=p.hoverBackground||""},onMouseLeave:R=>{R.currentTarget.style.background=""},children:[N.label,o&&a&&f.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),a(N.id)},style:{border:"none",background:"transparent",cursor:"pointer",padding:"2px",fontSize:"14px",color:p.textSecondary,opacity:.5},onMouseEnter:R=>{R.currentTarget.style.opacity="1",R.currentTarget.style.color="#ef4444"},onMouseLeave:R=>{R.currentTarget.style.opacity="0.5",R.currentTarget.style.color=p.textSecondary||""},children:"×"})]},N.id)),k&&f.jsxs("div",{onClick:B,style:{padding:"10px 12px",fontSize:"14px",cursor:"pointer",color:p.primary,borderTop:C.length>0?`1px solid ${p.border}`:"none"},onMouseEnter:N=>{N.currentTarget.style.background=p.hoverBackground||""},onMouseLeave:N=>{N.currentTarget.style.background=""},children:['+ Create "',x.trim(),'"']})]})})]})}const Lg={background:"#f9fafb",cardBackground:"#ffffff",cardHover:"#f3f4f6",text:"#111827",textSecondary:"#6b7280",border:"#e5e7eb",primary:"#374151"},Kc=y.forwardRef(({filteredOptions:r,search:e,theme:t,maxHeight:n,onCardClick:s},i)=>{const o=y.useRef(null),[a,l]=y.useState(typeof n=="number"?`${n}px`:n);return y.useEffect(()=>{const u=o.current;if(!u)return;const c=u.getBoundingClientRect(),d=window.innerHeight-c.top-16;l(`${Math.max(120,Math.min(d,typeof n=="number"?n:9999))}px`)},[n,r.length]),y.useEffect(()=>{typeof i=="function"?i(o.current):i&&(i.current=o.current)}),f.jsx("div",{ref:o,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",maxHeight:a,overflowY:"auto",border:`1px solid ${t.border}`,borderRadius:"8px",background:t.background,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",zIndex:50},children:r.length===0?f.jsx("div",{style:{padding:"16px",textAlign:"center",color:t.textSecondary,fontSize:"14px"},children:e?`No results for "${e}"`:"No items"}):r.map((u,c)=>f.jsxs("div",{onClick:()=>s(u),style:{padding:"10px 14px",cursor:"pointer",borderBottom:c<r.length-1?`1px solid ${t.border}`:"none",background:t.cardBackground,transition:"background 0.15s",display:"flex",alignItems:"center",gap:"10px"},onMouseEnter:d=>{d.currentTarget.style.background=t.cardHover||"#f3f4f6"},onMouseLeave:d=>{d.currentTarget.style.background=t.cardBackground||"#f9fafb"},children:[u.icon&&f.jsx("span",{className:"material-icons",style:{fontSize:"18px",color:u.color||t.textSecondary,flexShrink:0},children:u.icon}),f.jsxs("div",{style:{flex:1,minWidth:0},children:[f.jsx("div",{style:{fontSize:"14px",fontWeight:500,color:u.color||t.text,marginBottom:u.notes?"2px":0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.label}),u.notes&&f.jsx("div",{style:{fontSize:"12px",color:t.textSecondary,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.notes})]})]},u.id))})});Kc.displayName="DropdownList";function Pg({options:r,value:e,type:t,placeholder:n="Search...",onItemClick:s,onClear:i,onCreate:o,maxHeight:a=300,className:l="",theme:u={}}){const c={...Lg,...u},[d,h]=y.useState(""),[p,g]=y.useState(!1),m=y.useRef(null),x=y.useRef(null),_=y.useRef(null),b=y.useMemo(()=>e&&r.find(B=>B.id===e)||null,[e,r]),S=y.useMemo(()=>{if(!d.trim())return r;const B=d.toLowerCase();return r.filter(j=>{var N,R;return((N=j.label)==null?void 0:N.toLowerCase().includes(B))||((R=j.notes)==null?void 0:R.toLowerCase().includes(B))})},[r,d]);y.useEffect(()=>{const B=j=>{m.current&&!m.current.contains(j.target)&&g(!1)};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[]);const C=B=>{s&&s(B),g(!1),h("")},k=()=>{o&&o(d.trim()||void 0),g(!1),h("")},E=()=>{g(!0)},v=B=>{h(B.target.value),p||g(!0)},T=B=>{B.key==="Enter"?(B.preventDefault(),S.length>0&&s?(s(S[0]),g(!1),h("")):o&&d.trim()&&(o(d.trim()),g(!1),h(""))):B.key==="Escape"&&(g(!1),h(""))};return f.jsxs("div",{ref:m,className:`combostack ${l}`,style:{position:"relative",width:"100%",height:"32px"},children:[f.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center",height:"100%"},children:[f.jsx("div",{style:{flex:1,position:"relative"},children:b&&!p?f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 10px",fontSize:"13px",border:`1px solid ${c.border}`,borderRadius:"8px",background:c.background,color:c.text,cursor:"pointer",height:"32px",boxSizing:"border-box"},onClick:()=>g(!0),children:[f.jsxs("div",{style:{overflow:"hidden"},children:[f.jsx("div",{style:{fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:b.label}),b.notes&&f.jsx("div",{style:{fontSize:"11px",color:c.textSecondary,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:b.notes})]}),i&&f.jsx("button",{onClick:B=>{B.stopPropagation(),i()},style:{marginLeft:"8px",padding:"2px",background:"none",border:"none",cursor:"pointer",color:c.textSecondary,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",flexShrink:0},title:"Clear selection",children:f.jsx("span",{className:"material-icons",style:{fontSize:"16px"},children:"close"})})]}):f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"material-icons",style:{position:"absolute",left:"10px",top:"50%",transform:"translateY(-50%)",color:c.textSecondary,fontSize:"16px",pointerEvents:"none"},children:"search"}),f.jsx("input",{ref:x,type:"text",value:d,onChange:v,onFocus:E,onKeyDown:T,placeholder:n,style:{width:"100%",height:"32px",padding:"0 12px 0 36px",fontSize:"13px",border:`1px solid ${p?c.primary:c.border}`,borderRadius:"8px",background:c.background,color:c.text,outline:"none",boxSizing:"border-box",transition:"border-color 0.15s"}})]})}),o&&f.jsx("button",{onClick:k,style:{display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",color:c.text,cursor:"pointer",padding:"4px",borderRadius:"4px",transition:"opacity 0.15s",flexShrink:0,opacity:.7},onMouseEnter:B=>{B.currentTarget.style.opacity="1"},onMouseLeave:B=>{B.currentTarget.style.opacity="0.7"},title:`Create ${t||"item"}`,children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px"},children:"add"})})]}),p&&f.jsx(Kc,{ref:_,filteredOptions:S,search:d,theme:c,maxHeight:a,onCardClick:C})]})}function Ig({items:r,columns:e,getItemId:t,getItemColumn:n,getItemOrder:s,renderItem:i,onItemMove:o,onItemReorder:a,onItemClick:l,renderColumnHeader:u,renderColumnFooter:c,className:d="",columnClassName:h="",columnStyle:p,itemClassName:g=""}){const[m,x]=y.useState(null),[_,b]=y.useState(null),[S,C]=y.useState(null),k=y.useRef(null),E=e.reduce((M,w)=>{let D=r.filter(F=>n(F)===w.id);return s&&(D=D.sort((F,I)=>s(F)-s(I))),M[w.id]=D,M},{}),v=y.useCallback((M,w)=>{const D=t(w),F=n(w);x(D),k.current=F,M.dataTransfer.effectAllowed="move",M.dataTransfer.setData("text/plain",D),requestAnimationFrame(()=>{const I=M.target;I.style.opacity="0.5"})},[t,n]),T=y.useCallback(M=>{const w=M.target;w.style.opacity="1",x(null),b(null),C(null),k.current=null},[]),B=y.useCallback((M,w,D)=>{M.preventDefault(),M.dataTransfer.dropEffect="move",b(w),C(D)},[]),j=y.useCallback(M=>{const w=M.relatedTarget;w!=null&&w.closest("[data-kanban-column]")||(b(null),C(null))},[]),N=y.useCallback((M,w,D)=>{if(M.preventDefault(),!m)return;const F=k.current;F===w?a==null||a(m,w,D):F&&o(m,F,w,D),x(null),b(null),C(null),k.current=null},[m,o,a]),R=(M,w)=>f.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[f.jsxs("div",{className:"flex items-center gap-2",children:[M.color&&f.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:M.color}}),f.jsx("span",{className:"font-medium text-sm text-neutral-700",children:M.label})]}),f.jsx("span",{className:"text-xs text-neutral-400 bg-neutral-100 px-2 py-0.5 rounded-full",children:w})]});return f.jsx("div",{className:`flex gap-4 overflow-x-auto pb-4 h-full ${d}`,style:{alignItems:"flex-start"},children:e.map(M=>{const w=E[M.id]||[],D=_===M.id,F=w.length>0||D;return f.jsxs("div",{"data-kanban-column":M.id,className:`flex-1 min-w-[180px] rounded-xl flex flex-col ${h||"bg-neutral-50"}`,style:{...p,maxHeight:"100%",...F?{}:{}},onDragOver:I=>{I.preventDefault(),m&&!D&&b(M.id)},onDragLeave:j,onDrop:I=>N(I,M.id,S??w.length),children:[f.jsx("div",{className:"flex-shrink-0 border-b border-neutral-200",children:u?u(M,w.length):R(M,w.length)}),f.jsxs("div",{className:`overflow-y-auto p-2 space-y-2 transition-colors ${D?"bg-blue-50":""}`,style:{minHeight:F?100:40},children:[w.map((I,q)=>{const Z=t(I),te=m===Z,W=D&&S===q&&!te;return f.jsxs("div",{children:[W&&f.jsx("div",{className:"h-1 bg-blue-500 rounded-full mb-2 mx-1"}),f.jsx("div",{draggable:!0,onDragStart:Q=>v(Q,I),onDragEnd:T,onDragOver:Q=>B(Q,M.id,q),onClick:()=>l==null?void 0:l(I),className:`cursor-grab active:cursor-grabbing transition-all ${te?"opacity-50 scale-95":""} ${g}`,children:i(I,te)})]},Z)}),f.jsx("div",{className:"min-h-[40px]",onDragOver:I=>{I.preventDefault(),B(I,M.id,w.length)},children:D&&S===w.length&&f.jsx("div",{className:"h-1 bg-blue-500 rounded-full mx-1 mt-1"})}),w.length===0&&D&&f.jsx("div",{className:"h-20 border-2 border-dashed border-blue-300 rounded-lg bg-blue-50/50 flex items-center justify-center",children:f.jsx("span",{className:"text-sm text-blue-400",children:"Drop here"})})]}),c&&f.jsx("div",{className:"flex-shrink-0 border-t border-neutral-200 p-2",children:c(M)})]},M.id)})})}function Yc(r){const e=r.data||{};return e.image||e.poster||e.thumbnail||e.cover||e.photo}function zg(r){const e=r.data||{};return e.subtitle||e.director||e.author||e.creator}function Og(r){const e=r.data||{};return e.description||r.description||e.synopsis||e.summary}function $g(r){const e=r.data||{},t=[];return e.year&&t.push(String(e.year)),e.duration&&t.push(`${e.duration} min`),e.country&&t.push(e.country),e.category&&t.push(e.category),t.join(" • ")}const qg={"1:1":1,"2:3":1.5,"16:9":.5625};function Qc({node:r,aspectRatio:e,onClick:t}){const[n,s]=y.useState(!1),i=Yc(r),o=qg[e],a=e==="2:3"?160:e==="16:9"?280:180,l=e==="2:3"||e==="16:9"?a*o:a;return f.jsxs("div",{onClick:t,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{position:"relative",width:a,height:l,flexShrink:0,borderRadius:6,overflow:"hidden",cursor:"pointer",transform:n?"scale(1.08)":"scale(1)",transition:"transform 0.2s ease-out",zIndex:n?10:1,boxShadow:n?"0 8px 24px rgba(0,0,0,0.5)":"0 2px 8px rgba(0,0,0,0.3)"},children:[i?f.jsx("img",{src:i,alt:r.title||"Item",style:{width:"100%",height:"100%",objectFit:"cover"}}):f.jsx("div",{style:{width:"100%",height:"100%",background:"linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:f.jsx("span",{style:{fontSize:32,opacity:.3},children:"📄"})}),f.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,padding:"24px 8px 8px",background:"linear-gradient(to top, rgba(0,0,0,0.9) 0%, transparent 100%)",opacity:n?1:.8,transition:"opacity 0.2s ease"},children:f.jsx("p",{style:{margin:0,fontSize:13,fontWeight:600,color:"white",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.title||"Untitled"})})]})}function Jc({title:r,nodes:e,cardAspectRatio:t,onNodeClick:n}){const s=y.useRef(null),[i,o]=y.useState(!1),[a,l]=y.useState(!1),[u,c]=y.useState(!1),d=()=>{const p=s.current;p&&(l(p.scrollLeft>0),c(p.scrollLeft<p.scrollWidth-p.clientWidth-10))};y.useEffect(()=>{d();const p=s.current;if(p)return p.addEventListener("scroll",d),()=>p.removeEventListener("scroll",d)},[e]);const h=p=>{const g=s.current;if(!g)return;const m=g.clientWidth*.8;g.scrollBy({left:p==="left"?-m:m,behavior:"smooth"})};return e.length===0?null:f.jsxs("div",{style:{marginBottom:32},onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[f.jsx("h3",{style:{margin:"0 0 12px 48px",fontSize:20,fontWeight:700,color:"white"},children:r}),f.jsxs("div",{style:{position:"relative"},children:[a&&f.jsx("button",{onClick:()=>h("left"),style:{position:"absolute",left:0,top:0,bottom:0,width:48,border:"none",background:"linear-gradient(to right, rgba(20,20,20,0.95) 0%, transparent 100%)",color:"white",cursor:"pointer",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",opacity:i?1:0,transition:"opacity 0.2s ease"},children:f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})})}),u&&f.jsx("button",{onClick:()=>h("right"),style:{position:"absolute",right:0,top:0,bottom:0,width:48,border:"none",background:"linear-gradient(to left, rgba(20,20,20,0.95) 0%, transparent 100%)",color:"white",cursor:"pointer",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",opacity:i?1:0,transition:"opacity 0.2s ease"},children:f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M8.59 16.59L10 18l6-6-6-6-1.41 1.41L13.17 12z"})})}),f.jsx("div",{ref:s,style:{display:"flex",gap:8,overflowX:"auto",overflowY:"hidden",padding:"8px 48px",scrollbarWidth:"none",msOverflowStyle:"none"},children:e.map(p=>f.jsx(Qc,{node:p,aspectRatio:t,onClick:()=>n(p)},p._id))})]})]})}function Xc({node:r,onClose:e}){const t=Yc(r),n=zg(r),s=Og(r),i=$g(r);return y.useEffect(()=>{const o=a=>{a.key==="Escape"&&e()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e]),y.useEffect(()=>(document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}),[]),f.jsx("div",{onClick:e,style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0, 0, 0, 0.85)",display:"flex",alignItems:"center",justifyContent:"center",padding:24},children:f.jsxs("div",{onClick:o=>o.stopPropagation(),style:{position:"relative",width:"100%",maxWidth:850,maxHeight:"90vh",background:"#181818",borderRadius:8,overflow:"hidden",boxShadow:"0 16px 64px rgba(0,0,0,0.6)"},children:[f.jsx("button",{onClick:e,style:{position:"absolute",top:12,right:12,width:36,height:36,borderRadius:"50%",border:"none",background:"#181818",color:"white",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10,fontSize:20},children:"✕"}),f.jsxs("div",{style:{overflowY:"auto",maxHeight:"90vh"},children:[f.jsxs("div",{style:{position:"relative",width:"100%",aspectRatio:"16/9",background:"#0a0a0a"},children:[t?f.jsx("img",{src:t,alt:r.title||"Item",style:{width:"100%",height:"100%",objectFit:"cover"}}):f.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:f.jsx("span",{style:{fontSize:64,opacity:.2},children:"📄"})}),f.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:"50%",background:"linear-gradient(to top, #181818 0%, transparent 100%)"}}),f.jsx("div",{style:{position:"absolute",bottom:24,left:32,right:32},children:f.jsx("h1",{style:{margin:0,fontSize:32,fontWeight:700,color:"white",textShadow:"0 2px 8px rgba(0,0,0,0.5)"},children:r.title||"Untitled"})})]}),f.jsxs("div",{style:{padding:"0 32px 32px"},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:16},children:[n&&f.jsx("span",{style:{color:"#a3a3a3",fontSize:15},children:n}),i&&f.jsx("span",{style:{color:"#737373",fontSize:14},children:i})]}),s&&f.jsx("p",{style:{margin:0,fontSize:15,lineHeight:1.6,color:"#d4d4d4"},children:s}),r.data&&Object.keys(r.data).length>0&&f.jsxs("div",{style:{marginTop:24},children:[f.jsx("h4",{style:{margin:"0 0 12px",fontSize:14,fontWeight:600,color:"#737373",textTransform:"uppercase",letterSpacing:1},children:"Details"}),f.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:12},children:Object.entries(r.data).filter(([o])=>!["image","poster","thumbnail","cover","photo","description","subtitle","synopsis","summary"].includes(o)).slice(0,8).map(([o,a])=>f.jsxs("div",{children:[f.jsx("span",{style:{color:"#737373",fontSize:12,textTransform:"capitalize"},children:o.replace(/_/g," ")}),f.jsx("p",{style:{margin:"4px 0 0",color:"#d4d4d4",fontSize:14},children:String(a)})]},o))})]})]})]})]})})}function Ug({nodes:r,lanes:e,cardAspectRatio:t="2:3",onNodeClick:n}){const[s,i]=y.useState(null),o=y.useMemo(()=>e.map(u=>({...u,nodes:r.filter(u.filter)})),[r,e]),a=u=>{n?n(u):i(u)},l=()=>{i(null)};return f.jsxs("div",{style:{minHeight:"100vh",background:"#141414",paddingTop:24,paddingBottom:48},children:[o.map(u=>f.jsx(Jc,{title:u.title,nodes:u.nodes,cardAspectRatio:t,onNodeClick:a},u.id)),o.every(u=>u.nodes.length===0)&&f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,color:"#737373"},children:[f.jsx("span",{style:{fontSize:48,marginBottom:16},children:"📭"}),f.jsx("p",{style:{margin:0,fontSize:18},children:"No items to display"})]}),s&&f.jsx(Xc,{node:s,onClose:l})]})}const Wg={background:"#ffffff",hourLineColor:"#e5e7eb",halfHourLineColor:"#f3f4f6",hourTextColor:"#9ca3af",currentTimeColor:"#ef4444",allDayBackground:"#f9fafb",allDayBorder:"#e5e7eb"};function Hg(r){const e=r.match(/^(\d{1,2}):(\d{2})$/);return e?{hours:parseInt(e[1],10),minutes:parseInt(e[2],10)}:null}function Vg(r){const e=r%12||12,t=r<12?"AM":"PM";return`${e} ${t}`}function Gg(r){const e=new Date;return r.getDate()===e.getDate()&&r.getMonth()===e.getMonth()&&r.getFullYear()===e.getFullYear()}function Kg({items:r,date:e,startHour:t=7,endHour:n=22,hourHeight:s=60,getItemTime:i,getItemDuration:o,getItemIsAllDay:a,getItemId:l,renderItem:u,onItemClick:c,onTimeSlotClick:d,showCurrentTime:h=!0,className:p="",theme:g={}}){const m={...Wg,...g},{allDayItems:x,timedItems:_}=y.useMemo(()=>{const v=[],T=[];for(const B of r)a(B)?v.push(B):T.push(B);return{allDayItems:v,timedItems:T}},[r,a]),b=y.useMemo(()=>{const v=[];for(let T=t;T<=n;T++)v.push(T);return v},[t,n]),S=(n-t+1)*s,C=y.useCallback(v=>{const T=i(v);if(!T)return null;const B=Hg(T);if(!B)return null;const{hours:j,minutes:N}=B,R=Math.max(t,Math.min(n,j)),M=j<t?0:N,w=(R-t)*s+M/60*s,D=o(v),F=Math.max(20,D/60*s);return{top:w,height:F}},[i,o,t,n,s]),k=y.useMemo(()=>{if(!h||!Gg(e))return null;const v=new Date,T=v.getHours(),B=v.getMinutes();return T<t||T>n?null:(T-t)*s+B/60*s},[e,h,t,n,s]),E=y.useCallback(v=>{if(!d)return;const T=v.currentTarget.getBoundingClientRect(),j=(v.clientY-T.top)/s*60,N=Math.floor(j/60)+t,R=Math.round(j%60/15)*15,M=Math.min(n,Math.max(t,N)),w=R>=60?0:R,D=`${M.toString().padStart(2,"0")}:${w.toString().padStart(2,"0")}`;d(D)},[d,s,t,n]);return f.jsxs("div",{className:p,style:{background:m.background},children:[x.length>0&&f.jsxs("div",{style:{padding:"8px 0 8px 60px",borderBottom:`1px solid ${m.allDayBorder}`,background:m.allDayBackground},children:[f.jsx("div",{style:{fontSize:"11px",color:m.hourTextColor,marginBottom:"4px",textTransform:"uppercase",letterSpacing:"0.05em"},children:"All Day"}),f.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:x.map(v=>f.jsx("div",{onClick:()=>c==null?void 0:c(v),style:{cursor:c?"pointer":"default"},children:u(v)},l(v)))})]}),f.jsxs("div",{style:{position:"relative",height:S},children:[b.map((v,T)=>f.jsxs("div",{style:{position:"absolute",top:T*s,left:0,right:0},children:[f.jsx("div",{style:{position:"absolute",left:0,top:-8,width:"50px",textAlign:"right",paddingRight:"10px",fontSize:"11px",color:m.hourTextColor},children:Vg(v)}),f.jsx("div",{style:{position:"absolute",left:"60px",right:0,top:0,height:"1px",background:m.hourLineColor}}),T<b.length-1&&f.jsx("div",{style:{position:"absolute",left:"60px",right:0,top:s/2,height:"1px",background:m.halfHourLineColor}})]},v)),f.jsx("div",{style:{position:"absolute",left:"60px",right:0,top:0,bottom:0,cursor:d?"pointer":"default"},onClick:E}),k!==null&&f.jsxs("div",{style:{position:"absolute",left:"55px",right:0,top:k,zIndex:20,pointerEvents:"none"},children:[f.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",background:m.currentTimeColor,marginLeft:"-5px",marginTop:"-5px",position:"absolute"}}),f.jsx("div",{style:{marginLeft:"5px",height:"2px",background:m.currentTimeColor}})]}),_.map(v=>{const T=C(v);return T?f.jsx("div",{style:{position:"absolute",left:"64px",right:"8px",top:T.top,height:T.height,zIndex:10,cursor:c?"pointer":"default"},onClick:B=>{B.stopPropagation(),c==null||c(v)},children:u(v)},l(v)):null})]})]})}function Zc({onComplete:r,onCancel:e,onTranscribe:t,onTranscriptionComplete:n,variant:s="widget",hideSaveButton:i=!1,maxDuration:o=180,extraControls:a}){const l=s==="widget",[u,c]=y.useState("idle"),[d,h]=y.useState(0),[p,g]=y.useState(0),[m,x]=y.useState(!1),[_,b]=y.useState(0),[S,C]=y.useState(null),[k,E]=y.useState(!1),[v,T]=y.useState(null),[B,j]=y.useState(!0),[N,R]=y.useState([]),[M,w]=y.useState({completed:0,total:0}),D=y.useRef(!1),F=y.useRef(!0);y.useEffect(()=>{F.current=B},[B]);const I=y.useRef(null),q=y.useRef(null),Z=y.useRef(null),te=y.useRef(null),W=y.useRef(null),Q=y.useRef([]),H=y.useRef(null),ie=y.useRef(null),ue=y.useRef(null),de=y.useRef(null),we=y.useRef(!1),fe=y.useRef([]),Ce=y.useRef(null),O=y.useRef(null),je=y.useRef([]),re=y.useRef([]),Le=y.useRef("insert"),Me=y.useRef(!1),xe=y.useRef(0),Se=y.useRef(0),Re=y.useRef(0),se=J=>{const P=Math.floor(J/60),he=Math.floor(J%60);return`${P.toString().padStart(2,"0")}:${he.toString().padStart(2,"0")}`},ce=async J=>{const P=await J.arrayBuffer(),he=new AudioContext,ge=await he.decodeAudioData(P);return await he.close(),ge},$=J=>{const P=J.numberOfChannels,he=J.sampleRate,ge=1,Y=16,Ae=Y/8,Ee=P*Ae,Te=he*Ee,Pe=J.length*Ee,We=new ArrayBuffer(44+Pe),ke=new DataView(We),L=(ve,Ne)=>{for(let st=0;st<Ne.length;st++)ke.setUint8(ve+st,Ne.charCodeAt(st))};L(0,"RIFF"),ke.setUint32(4,36+Pe,!0),L(8,"WAVE"),L(12,"fmt "),ke.setUint32(16,16,!0),ke.setUint16(20,ge,!0),ke.setUint16(22,P,!0),ke.setUint32(24,he,!0),ke.setUint32(28,Te,!0),ke.setUint16(32,Ee,!0),ke.setUint16(34,Y,!0),L(36,"data"),ke.setUint32(40,Pe,!0);const be=[];for(let ve=0;ve<P;ve++)be.push(J.getChannelData(ve));let _e=44;for(let ve=0;ve<J.length;ve++)for(let Ne=0;Ne<P;Ne++){const st=Math.max(-1,Math.min(1,be[Ne][ve])),ct=st<0?st*32768:st*32767;ke.setInt16(_e,ct,!0),_e+=2}return new Blob([We],{type:"audio/wav"})},Ge=async(J,P,he,ge)=>{const Y=new AudioContext,Ae=J.sampleRate,Ee=Math.max(J.numberOfChannels,P.numberOfChannels),Te=Math.min(he,J.length),Pe=Math.max(0,J.length-he),We=ge==="insert"?Te+P.length+Pe:Te+P.length,ke=Y.createBuffer(Ee,We,Ae);for(let L=0;L<Ee;L++){const be=ke.getChannelData(L),_e=L<J.numberOfChannels?J.getChannelData(L):J.getChannelData(0);for(let Ne=0;Ne<Te;Ne++)be[Ne]=_e[Ne];const ve=L<P.numberOfChannels?P.getChannelData(L):P.getChannelData(0);for(let Ne=0;Ne<P.length;Ne++)be[Te+Ne]=ve[Ne];if(ge==="insert")for(let Ne=0;Ne<Pe;Ne++)be[Te+P.length+Ne]=_e[he+Ne]}return await Y.close(),ke},Ke=y.useCallback(()=>{const J=I.current;if(!J)return;const P=J.getContext("2d");if(!P)return;const he=J.getBoundingClientRect(),ge=he.width,Y=he.height,Ae=fe.current,Ee=p||d||1,Te=u==="recording"?d:_;P.fillStyle="#2d3b35",P.fillRect(0,0,ge,Y);const Pe=8,We="rgba(0, 0, 0, 0.4)",ke=P.createLinearGradient(0,0,0,Pe);ke.addColorStop(0,We),ke.addColorStop(1,"transparent"),P.fillStyle=ke,P.fillRect(0,0,ge,Pe);const L=P.createLinearGradient(0,Y-Pe,0,Y);L.addColorStop(0,"transparent"),L.addColorStop(1,We),P.fillStyle=L,P.fillRect(0,Y-Pe,ge,Pe);const be=P.createLinearGradient(0,0,Pe,0);be.addColorStop(0,We),be.addColorStop(1,"transparent"),P.fillStyle=be,P.fillRect(0,0,Pe,Y);const _e=P.createLinearGradient(ge-Pe,0,ge,0);_e.addColorStop(0,"transparent"),_e.addColorStop(1,We),P.fillStyle=_e,P.fillRect(ge-Pe,0,Pe,Y),P.strokeStyle="#5a6b62",P.lineWidth=1,P.beginPath(),P.moveTo(0,Y/2),P.lineTo(ge,Y/2),P.stroke();const ve=ge/2;if(Ae.length>0)if(u==="recording")for(let ct=0;ct<Ae.length;ct++){const bt=Ae.length-1-ct,Xt=ve-bt*4;if(Xt<-3||Xt>ge)continue;const A=Ae[ct]*(Y/2-12),U=Y/2-A;P.fillStyle="#10b981",P.fillRect(Xt,U,3,A*2)}else{const ct=Ee>0?Te/Ee*Ae.length:0;for(let bt=0;bt<Ae.length;bt++){const Xt=ct-bt,A=ve-Xt*4;if(A<-3||A>ge)continue;const U=Ae[bt]*(Y/2-12),ne=Y/2-U;P.fillStyle=bt<=ct?"#10b981":"#4b5563",P.fillRect(A,ne,3,U*2)}}P.strokeStyle="#ef4444",P.lineWidth=1,P.beginPath(),P.moveTo(ve,0),P.lineTo(ve,Y),P.stroke(),P.fillStyle="#fff",P.font="bold 18px monospace",P.textAlign="center",P.fillText(se(Te),ve,Y-6),u==="recording"&&(P.fillStyle="#ef4444",P.beginPath(),P.arc(20,20,8,0,Math.PI*2),P.fill(),P.fillStyle="#fff",P.font="10px sans-serif",P.textAlign="left",P.fillText("REC",34,24)),P.textAlign="left"},[u,_,d,p]),X=()=>{const J=W.current;if(!J||!we.current)return;const P=J.frequencyBinCount,he=new Uint8Array(P);J.getByteTimeDomainData(he);let ge=0;for(let Ee=0;Ee<P;Ee++){const Te=(he[Ee]-128)/128;ge+=Te*Te}const Y=Math.sqrt(ge/P),Ae=Math.min(1,Y*3);fe.current.push(Ae),Ke(),we.current&&(ie.current=requestAnimationFrame(X))},K=async()=>{try{C(null),E(!1),Ce.current===null&&(fe.current=[]);const J=await navigator.mediaDevices.getUserMedia({audio:!0});Z.current=J;const P=new AudioContext;te.current=P;const he=P.createAnalyser();he.fftSize=2048,W.current=he,P.createMediaStreamSource(J).connect(he);const Y=new MediaRecorder(J);q.current=Y,Q.current=[],Y.ondataavailable=Ae=>{Ae.data.size>0&&Q.current.push(Ae.data)},Y.onstop=async()=>{try{if(we.current=!1,Q.current.length===0){C("No audio was recorded. Please try again."),c("idle"),J.getTracks().forEach(ke=>ke.stop());return}const Ae=new Blob(Q.current,{type:"audio/webm"});let Ee,Te;if(Ce.current!==null&&O.current)try{const ke=await ce(Ae),L=O.current.sampleRate,be=Math.floor(Ce.current*L),_e=await Ge(O.current,ke,be,Le.current);Ee=$(_e),Te=_e.length/_e.sampleRate,Le.current==="insert"&&(fe.current=[...fe.current,...re.current]),Ce.current=null,O.current=null,je.current=[],re.current=[]}catch{Ee=Ae,Te=xe.current>0?xe.current:1}else Ee=Ae,Te=xe.current>0?xe.current:1;if(de.current=Ee,J.getTracks().forEach(ke=>ke.stop()),F.current&&t){R(ke=>[...ke,Ee]),w(ke=>({...ke,total:ke.total+1})),de.current=null,fe.current=[],b(0),g(0),h(0),c("idle");return}const Pe=URL.createObjectURL(Ee),We=new Audio(Pe);We.ontimeupdate=()=>{b(We.currentTime)},We.onended=()=>{x(!1)},ue.current=We,g(Te),b(Te),c("editing")}catch{C("Failed to process recording"),c("idle")}},Y.start(100),we.current=!0,c("recording"),h(0),xe.current=0,H.current=setInterval(()=>{xe.current+=1,h(xe.current),xe.current>=o&&(q.current&&q.current.state!=="inactive"&&q.current.stop(),we.current=!1,T(null),H.current&&(clearInterval(H.current),H.current=null),ie.current&&(cancelAnimationFrame(ie.current),ie.current=null),setTimeout(()=>{alert(`Maximum recording time of ${Math.floor(o/60)} minutes reached.`)},100))},1e3)}catch{C("Could not access microphone. Please allow microphone access.")}},pe=()=>{we.current=!1,E(!1),T(null),ie.current&&(cancelAnimationFrame(ie.current),ie.current=null),H.current&&(clearInterval(H.current),H.current=null),q.current&&q.current.state!=="inactive"&&q.current.stop()},De=J=>{const P=I.current;if(!P)return;const he=p||d;if(he<=0)return;const ge=fe.current;if(ge.length===0)return;const Y=P.getBoundingClientRect(),Ae=J-Se.current,Ee=4,Te=Y.width/P.width,Pe=ge.length/he*Ee,We=-Ae/(Pe*Te),ke=Re.current+We,L=Math.max(0,Math.min(ke,he));ue.current&&(ue.current.currentTime=L),b(L)},Be=()=>{ue.current&&(ue.current.currentTime=0),b(0)},Qe=()=>{const J=p||d;ue.current&&(ue.current.currentTime=J),b(J)},Et=()=>{const J=ue.current;J&&(m?(J.pause(),b(J.currentTime),x(!1)):(J.currentTime=_,J.play().catch(()=>{}),x(!0)))},ae=async J=>{if(!de.current){K();return}try{ue.current&&(ue.current.pause(),x(!1)),Le.current=J,O.current=await ce(de.current);const P=p||d;Ce.current=_;const he=P>0?_/P:0,ge=Math.floor(he*fe.current.length);je.current=fe.current.slice(0,ge),re.current=fe.current.slice(ge),fe.current=[...je.current],K()}catch{C("Failed to prepare recording. Please try again.")}},me=()=>{ue.current&&(ue.current.pause(),ue.current=null),de.current=null,O.current=null,Ce.current=null,je.current=[],x(!1),b(0),g(0),h(0),K()},Ye=()=>{de.current?r(de.current,p||d):alert("No audio recorded yet!")};y.useEffect(()=>{u==="recording"&&I.current&&W.current&&we.current&&(ie.current=requestAnimationFrame(X))},[u]),y.useEffect(()=>{const J=I.current;if(!J)return;const P=()=>{const he=window.devicePixelRatio||1,ge=J.getBoundingClientRect();J.width=ge.width*he,J.height=ge.height*he;const Y=J.getContext("2d");Y&&Y.scale(he,he)};return P(),window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[]),y.useEffect(()=>{if(u==="idle"){const J=I.current;if(!J)return;const P=J.getContext("2d");if(!P)return;const he=J.getBoundingClientRect(),ge=he.width,Y=he.height;P.fillStyle="#2d3b35",P.fillRect(0,0,ge,Y);const Ae=8,Ee="rgba(0, 0, 0, 0.4)",Te=P.createLinearGradient(0,0,0,Ae);Te.addColorStop(0,Ee),Te.addColorStop(1,"transparent"),P.fillStyle=Te,P.fillRect(0,0,ge,Ae);const Pe=P.createLinearGradient(0,Y-Ae,0,Y);Pe.addColorStop(0,"transparent"),Pe.addColorStop(1,Ee),P.fillStyle=Pe,P.fillRect(0,Y-Ae,ge,Ae);const We=P.createLinearGradient(0,0,Ae,0);We.addColorStop(0,Ee),We.addColorStop(1,"transparent"),P.fillStyle=We,P.fillRect(0,0,Ae,Y);const ke=P.createLinearGradient(ge-Ae,0,ge,0);ke.addColorStop(0,"transparent"),ke.addColorStop(1,Ee),P.fillStyle=ke,P.fillRect(ge-Ae,0,Ae,Y),P.strokeStyle="#5a6b62",P.lineWidth=1,P.beginPath(),P.moveTo(0,Y/2),P.lineTo(ge,Y/2),P.stroke();const L=ge/2;P.strokeStyle="#ef4444",P.lineWidth=1,P.beginPath(),P.moveTo(L,0),P.lineTo(L,Y),P.stroke(),P.fillStyle="#fff",P.font="bold 18px monospace",P.textAlign="center",P.fillText("00:00",L,Y-6)}},[u]);const at=y.useCallback(J=>{R(P=>[...P,J]),w(P=>({...P,total:P.total+1}))},[]);if(y.useEffect(()=>{(async()=>{if(D.current||N.length===0||!t)return;D.current=!0;const P=N[0];try{const he=await t(P);he&&n&&n(he)}catch(he){console.error("Transcription failed:",he)}finally{R(he=>he.slice(1)),w(he=>({...he,completed:he.completed+1})),D.current=!1}})()},[N,t,n]),y.useEffect(()=>()=>{we.current=!1,H.current&&clearInterval(H.current),ie.current&&cancelAnimationFrame(ie.current),Z.current&&Z.current.getTracks().forEach(J=>J.stop()),te.current&&te.current.state!=="closed"&&te.current.close()},[]),y.useEffect(()=>{if(u==="editing"&&m){let J;const P=()=>{const he=ue.current;if(he&&m){const ge=I.current;if(ge){const Y=ge.getContext("2d");if(Y){const Ae=ge.getBoundingClientRect(),Ee=Ae.width,Te=Ae.height,Pe=fe.current,We=p||d||1,ke=he.currentTime;Y.fillStyle="#2d3b35",Y.fillRect(0,0,Ee,Te);const L=8,be="rgba(0, 0, 0, 0.4)",_e=Y.createLinearGradient(0,0,0,L);_e.addColorStop(0,be),_e.addColorStop(1,"transparent"),Y.fillStyle=_e,Y.fillRect(0,0,Ee,L);const ve=Y.createLinearGradient(0,Te-L,0,Te);ve.addColorStop(0,"transparent"),ve.addColorStop(1,be),Y.fillStyle=ve,Y.fillRect(0,Te-L,Ee,L);const Ne=Y.createLinearGradient(0,0,L,0);Ne.addColorStop(0,be),Ne.addColorStop(1,"transparent"),Y.fillStyle=Ne,Y.fillRect(0,0,L,Te);const st=Y.createLinearGradient(Ee-L,0,Ee,0);st.addColorStop(0,"transparent"),st.addColorStop(1,be),Y.fillStyle=st,Y.fillRect(Ee-L,0,L,Te),Y.strokeStyle="#5a6b62",Y.lineWidth=1,Y.beginPath(),Y.moveTo(0,Te/2),Y.lineTo(Ee,Te/2),Y.stroke();const ct=Ee/2,bt=3,Xt=4,A=We>0?ke/We*Pe.length:0;for(let ye=0;ye<Pe.length;ye++){const $e=A-ye,qe=ct-$e*Xt;if(qe<-bt||qe>Ee)continue;const Ie=Pe[ye]*(Te/2-12),Fe=Te/2-Ie;Y.fillStyle=ye<=A?"#10b981":"#4b5563",Y.fillRect(qe,Fe,bt,Ie*2)}Y.strokeStyle="#ef4444",Y.lineWidth=1,Y.beginPath(),Y.moveTo(ct,0),Y.lineTo(ct,Te),Y.stroke(),Y.fillStyle="#fff",Y.font="bold 18px monospace",Y.textAlign="center";const U=Math.floor(ke/60),ne=Math.floor(ke%60);Y.fillText(`${U.toString().padStart(2,"0")}:${ne.toString().padStart(2,"0")}`,ct,Te-6),Y.textAlign="left"}}J=requestAnimationFrame(P)}};return J=requestAnimationFrame(P),()=>cancelAnimationFrame(J)}},[u,m,p,d]),y.useEffect(()=>{u==="editing"&&!m&&Ke()},[u,_,m,Ke]),S)return f.jsxs("div",{style:{border:"1px solid #fecaca",borderRadius:"12px",padding:"16px",background:"#fef2f2"},children:[f.jsx("p",{style:{fontSize:"14px",color:"#dc2626",marginBottom:"12px"},children:S}),f.jsx("button",{onClick:()=>{C(null),K()},style:{padding:"8px 16px",fontSize:"14px",background:"#171717",color:"white",borderRadius:"8px",border:"none",cursor:"pointer"},children:"Try Again"})]});const He={padding:"8px",borderRadius:"8px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 0.15s"},Xe={...He,opacity:.3,cursor:"not-allowed"},br=l?{border:"1px solid #e5e5e5",borderRadius:"12px",overflow:"hidden",background:"white"}:{overflow:"hidden",background:"white",flexShrink:0};return f.jsxs("div",{style:br,children:[f.jsx("canvas",{ref:I,style:{width:"100%",height:"32px",cursor:"pointer",flexShrink:0},onMouseDown:J=>{if(u==="editing"){Me.current=!0,Se.current=J.clientX,Re.current=_;const P=ge=>{Me.current&&De(ge.clientX)},he=()=>{Me.current=!1,window.removeEventListener("mousemove",P),window.removeEventListener("mouseup",he)};window.addEventListener("mousemove",P),window.addEventListener("mouseup",he)}}}),f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:l?"6px 8px":"4px",borderTop:"1px solid #d4d4d4",background:"linear-gradient(to bottom, #e0e0e0 0%, #c8c8c8 100%)",boxShadow:"inset 0 1px 0 rgba(255,255,255,0.6), inset 0 -1px 0 rgba(0,0,0,0.1)",flexShrink:0},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[f.jsx("button",{onClick:Be,disabled:u==="idle"||u==="recording",style:u==="idle"||u==="recording"?Xe:He,title:"Go to start",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:"#171717"},children:"first_page"})}),f.jsx("button",{onClick:()=>{if(u==="recording"){const J=q.current;J&&(J.state==="recording"?(J.pause(),E(!0)):J.state==="paused"&&(J.resume(),E(!1)))}else Et()},disabled:u==="idle",style:u==="idle"?Xe:He,title:m||u==="recording"&&!k?"Pause":"Play",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:"#171717"},children:m||u==="recording"&&!k?"pause":"play_arrow"})}),f.jsx("button",{onClick:Qe,disabled:u==="idle"||u==="recording",style:u==="idle"||u==="recording"?Xe:He,title:"Go to end",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:"#171717"},children:"last_page"})}),f.jsx("div",{style:{width:"1px",height:"24px",margin:"0 4px",background:"linear-gradient(to bottom, rgba(255,255,255,0.5), rgba(0,0,0,0.15))"}}),f.jsx("button",{onClick:()=>{v==="insert"?pe():u==="idle"?(T("insert"),K()):u==="editing"&&(T("insert"),ae("insert"))},disabled:u==="recording"&&v!=="insert"||m,style:u==="recording"&&v!=="insert"||m?Xe:He,title:v==="insert"?"Stop recording":"Insert recording",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:v==="insert"?"#ef4444":"#171717"},children:"add"})}),f.jsx("button",{onClick:()=>{F.current||(v==="mic"?pe():u==="idle"?(T("mic"),K()):u==="editing"&&(T("mic"),ae("replace")))},onMouseDown:()=>{F.current&&u==="idle"&&!m&&(T("mic"),K())},onMouseUp:()=>{F.current&&u==="recording"&&v==="mic"&&pe()},onMouseLeave:()=>{F.current&&u==="recording"&&v==="mic"&&pe()},onTouchStart:J=>{J.preventDefault(),F.current&&u==="idle"&&!m&&(T("mic"),K())},onTouchEnd:J=>{J.preventDefault(),F.current&&u==="recording"&&v==="mic"&&pe()},disabled:u==="recording"&&v!=="mic"||m,style:u==="recording"&&v!=="mic"||m?Xe:He,title:B?"Hold to record (walkie-talkie)":v==="mic"?"Stop recording":"Record",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:v==="mic"?"#ef4444":"#171717"},children:"mic"})}),f.jsx("button",{onClick:()=>{u==="idle"&&!m?(T("round"),K()):u==="recording"&&v==="round"&&pe()},disabled:u==="editing"||u==="recording"&&v!=="round"||m,style:u==="editing"||u==="recording"&&v!=="round"||m?Xe:{...He,width:"28px",height:"28px",borderRadius:"50%",padding:0},title:"Click to record / click to stop",children:f.jsx("span",{style:{display:"block",width:"14px",height:"14px",borderRadius:"50%",background:u==="recording"&&v==="round"?"#171717":"#ef4444",transition:"background 0.15s"}})}),f.jsx("button",{onClick:()=>{v==="startover"?pe():u==="editing"&&(T("startover"),me())},disabled:u==="idle"||u==="recording"&&v!=="startover"||m,style:u==="idle"||u==="recording"&&v!=="startover"||m?Xe:He,title:v==="startover"?"Stop recording":"Start over",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:v==="startover"?"#ef4444":"#171717"},children:"refresh"})})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[a,M.total>0&&M.completed<M.total&&f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",background:"rgba(16, 185, 129, 0.1)",borderRadius:"4px",fontSize:"11px",color:"#10b981"},children:[f.jsx("span",{className:"material-icons",style:{fontSize:"14px",animation:"spin 1s linear infinite"},children:"sync"}),M.completed,"/",M.total]}),t&&f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginRight:"4px"},children:[f.jsx("button",{onClick:()=>j(!B),style:{width:"28px",height:"16px",borderRadius:"8px",border:"none",background:B?"#10b981":"#9ca3af",cursor:"pointer",position:"relative",transition:"background 0.2s",padding:0},title:B?"Auto-transcribe ON":"Auto-transcribe OFF",children:f.jsx("div",{style:{width:"12px",height:"12px",borderRadius:"50%",background:"white",position:"absolute",top:"2px",left:B?"14px":"2px",transition:"left 0.2s",boxShadow:"0 1px 2px rgba(0,0,0,0.2)"}})}),f.jsx("span",{style:{fontSize:"10px",color:"#666"},children:"auto"})]}),f.jsx("button",{onClick:()=>{u==="editing"&&de.current&&at(de.current)},disabled:u!=="editing",style:u!=="editing"?Xe:He,title:"Transcribe audio",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:B?"#10b981":"#171717"},children:"subtitles"})})]}),!i&&f.jsx("button",{onClick:Ye,disabled:u!=="editing",style:u!=="editing"?Xe:He,title:"Save recording",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:"#171717"},children:"save"})})]})]}),M.total>0&&M.completed<M.total&&f.jsx("div",{style:{height:"3px",background:"#e5e5e5",overflow:"hidden"},children:f.jsx("div",{style:{height:"100%",background:"#10b981",width:`${M.completed/M.total*100}%`,transition:"width 0.3s ease"}})})]})}function Yg({label:r,value:e,onChange:t,onTranscribe:n,onAIAction:s,onAIPrompt:i,onAudioSave:o,placeholder:a="Type or record...",className:l="",rows:u,llmClient:c,graphClient:d,nodeId:h,audioFilename:p,existingAudio:g,existingVoice:m,onAudioGenerated:x,onGenerateTTS:_,audioUrl:b,voice:S="coral",onVoiceChange:C,generateButton:k,generatePrompt:E,generateSourceText:v,generateSourceError:T}){const[B,j]=y.useState(!1),[N,R]=y.useState(!1),[M,w]=y.useState(""),[D,F]=y.useState(!1),[I,q]=y.useState(!1),[Z,te]=y.useState(null),[W,Q]=y.useState(m||S),[H,ie]=y.useState(g),[ue,de]=y.useState(Date.now()),we=y.useRef(null),fe=y.useRef(null),Ce=!!(c&&d&&h&&p);y.useEffect(()=>{g!==void 0&&ie(g)},[g]),y.useEffect(()=>{m!==void 0&&Q(m)},[m]);const O=Ce&&H&&d&&h?`${d.getFileUrl(h,H)}?v=${ue}`:b,je=se=>{t(e?`${e}
183
+ `})]})}const Rg={background:"#ffffff",text:"#111827",textSecondary:"#6b7280",border:"#e5e7eb",primary:"#3b82f6",chipBackground:"#f3f4f6",chipText:"#374151",hoverBackground:"#f9fafb"};function Fg({options:r,value:e,onChange:t,placeholder:n="Search or select...",allowCreate:s=!0,onCreate:i,allowDelete:o=!1,onDelete:a,label:l,disabled:u=!1,max:c=0,theme:d={},className:h=""}){const p={...Rg,...d},[g,m]=y.useState(!1),[x,_]=y.useState(""),b=y.useRef(null),S=y.useRef(null);y.useEffect(()=>{function N(R){b.current&&!b.current.contains(R.target)&&(m(!1),_(""))}return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);const C=r.filter(N=>{var R;return((R=N.label)==null?void 0:R.toLowerCase().includes(x.toLowerCase()))&&!e.includes(N.id)}),k=s&&x.trim()&&!r.some(N=>{var R;return((R=N.label)==null?void 0:R.toLowerCase())===x.toLowerCase()}),E=e.map(N=>r.find(R=>R.id===N)).filter(Boolean),v=y.useCallback(N=>{var R;c>0&&e.length>=c||(t([...e,N]),_(""),c===1?m(!1):(R=S.current)==null||R.focus())},[e,t,c]),T=y.useCallback(N=>{t(e.filter(R=>R!==N))},[e,t]),B=y.useCallback(async()=>{if(!k)return;const N=await(i==null?void 0:i(x.trim()));N&&v(N.id),_("")},[k,x,i,v]),j=y.useCallback(N=>{N.key==="Enter"?(N.preventDefault(),k?B():C.length>0&&v(C[0].id)):N.key==="Backspace"&&!x&&e.length>0?T(e[e.length-1]):N.key==="Escape"&&(m(!1),_(""))},[k,C,x,e,B,v,T]);return f.jsxs("div",{ref:b,className:h,style:{position:"relative"},children:[l&&f.jsx("label",{style:{display:"block",fontSize:"12px",textTransform:"uppercase",color:p.textSecondary,marginBottom:"4px"},children:l}),f.jsxs("div",{onClick:()=>!u&&m(!0),style:{display:"flex",flexWrap:"wrap",gap:"6px",padding:"8px 12px",border:`1px solid ${g?p.primary:p.border}`,borderRadius:"8px",background:u?p.hoverBackground:p.background,cursor:u?"not-allowed":"text",minHeight:"42px",alignItems:"center"},children:[E.map(N=>f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"4px",fontSize:"13px",background:N.color||p.chipBackground,color:N.color?"#fff":p.chipText},children:[N.label,!u&&f.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),T(N.id)},style:{border:"none",background:"transparent",cursor:"pointer",padding:"0 2px",fontSize:"14px",color:"inherit",opacity:.7},children:"×"})]},N.id)),f.jsx("input",{ref:S,type:"text",value:x,onChange:N=>{_(N.target.value),g||m(!0)},onFocus:()=>m(!0),onKeyDown:j,placeholder:E.length===0?n:"",disabled:u||c>0&&e.length>=c,style:{flex:1,minWidth:"60px",border:"none",outline:"none",fontSize:"14px",background:"transparent",color:p.text}})]}),g&&!u&&f.jsx("div",{style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:p.background,border:`1px solid ${p.border}`,borderRadius:"8px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",maxHeight:"200px",overflowY:"auto",zIndex:50},children:C.length===0&&!k?f.jsx("div",{style:{padding:"12px",fontSize:"14px",color:p.textSecondary,textAlign:"center"},children:x?"No matches":"No options available"}):f.jsxs(f.Fragment,{children:[C.map(N=>f.jsxs("div",{onClick:()=>v(N.id),style:{padding:"10px 12px",fontSize:"14px",cursor:"pointer",color:p.text,display:"flex",alignItems:"center",justifyContent:"space-between"},onMouseEnter:R=>{R.currentTarget.style.background=p.hoverBackground||""},onMouseLeave:R=>{R.currentTarget.style.background=""},children:[N.label,o&&a&&f.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),a(N.id)},style:{border:"none",background:"transparent",cursor:"pointer",padding:"2px",fontSize:"14px",color:p.textSecondary,opacity:.5},onMouseEnter:R=>{R.currentTarget.style.opacity="1",R.currentTarget.style.color="#ef4444"},onMouseLeave:R=>{R.currentTarget.style.opacity="0.5",R.currentTarget.style.color=p.textSecondary||""},children:"×"})]},N.id)),k&&f.jsxs("div",{onClick:B,style:{padding:"10px 12px",fontSize:"14px",cursor:"pointer",color:p.primary,borderTop:C.length>0?`1px solid ${p.border}`:"none"},onMouseEnter:N=>{N.currentTarget.style.background=p.hoverBackground||""},onMouseLeave:N=>{N.currentTarget.style.background=""},children:['+ Create "',x.trim(),'"']})]})})]})}const Lg={background:"#f9fafb",cardBackground:"#ffffff",cardHover:"#f3f4f6",text:"#111827",textSecondary:"#6b7280",border:"#e5e7eb",primary:"#374151"},Kc=y.forwardRef(({filteredOptions:r,search:e,theme:t,maxHeight:n,onCardClick:s},i)=>{const o=y.useRef(null),[a,l]=y.useState(typeof n=="number"?`${n}px`:n);return y.useEffect(()=>{const u=o.current;if(!u)return;const c=u.getBoundingClientRect(),d=window.innerHeight-c.top-16;l(`${Math.max(120,Math.min(d,typeof n=="number"?n:9999))}px`)},[n,r.length]),y.useEffect(()=>{typeof i=="function"?i(o.current):i&&(i.current=o.current)}),f.jsx("div",{ref:o,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",maxHeight:a,overflowY:"auto",border:`1px solid ${t.border}`,borderRadius:"8px",background:t.background,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",zIndex:50},children:r.length===0?f.jsx("div",{style:{padding:"16px",textAlign:"center",color:t.textSecondary,fontSize:"14px"},children:e?`No results for "${e}"`:"No items"}):r.map((u,c)=>f.jsxs("div",{onClick:()=>s(u),style:{padding:"10px 14px",cursor:"pointer",borderBottom:c<r.length-1?`1px solid ${t.border}`:"none",background:t.cardBackground,transition:"background 0.15s",display:"flex",alignItems:"center",gap:"10px"},onMouseEnter:d=>{d.currentTarget.style.background=t.cardHover||"#f3f4f6"},onMouseLeave:d=>{d.currentTarget.style.background=t.cardBackground||"#f9fafb"},children:[u.icon&&f.jsx("span",{className:"material-icons",style:{fontSize:"18px",color:u.color||t.textSecondary,flexShrink:0},children:u.icon}),f.jsxs("div",{style:{flex:1,minWidth:0},children:[f.jsx("div",{style:{fontSize:"14px",fontWeight:500,color:u.color||t.text,marginBottom:u.notes?"2px":0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.label}),u.notes&&f.jsx("div",{style:{fontSize:"12px",color:t.textSecondary,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.notes})]})]},u.id))})});Kc.displayName="DropdownList";function Pg({options:r,value:e,type:t,placeholder:n="Search...",onItemClick:s,onClear:i,onCreate:o,maxHeight:a=300,className:l="",theme:u={}}){const c={...Lg,...u},[d,h]=y.useState(""),[p,g]=y.useState(!1),m=y.useRef(null),x=y.useRef(null),_=y.useRef(null),b=y.useMemo(()=>e&&r.find(B=>B.id===e)||null,[e,r]),S=y.useMemo(()=>{if(!d.trim())return r;const B=d.toLowerCase();return r.filter(j=>{var N,R;return((N=j.label)==null?void 0:N.toLowerCase().includes(B))||((R=j.notes)==null?void 0:R.toLowerCase().includes(B))})},[r,d]);y.useEffect(()=>{const B=j=>{m.current&&!m.current.contains(j.target)&&g(!1)};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[]);const C=B=>{s&&s(B),g(!1),h("")},k=()=>{o&&o(d.trim()||void 0),g(!1),h("")},E=()=>{g(!0)},v=B=>{h(B.target.value),p||g(!0)},T=B=>{B.key==="Enter"?(B.preventDefault(),S.length>0&&s?(s(S[0]),g(!1),h("")):o&&d.trim()&&(o(d.trim()),g(!1),h(""))):B.key==="Escape"&&(g(!1),h(""))};return f.jsxs("div",{ref:m,className:`combostack ${l}`,style:{position:"relative",width:"100%",height:"32px"},children:[f.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center",height:"100%"},children:[f.jsx("div",{style:{flex:1,position:"relative"},children:b&&!p?f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 10px",fontSize:"13px",border:`1px solid ${c.border}`,borderRadius:"8px",background:c.background,color:c.text,cursor:"pointer",height:"32px",boxSizing:"border-box"},onClick:()=>g(!0),children:[f.jsxs("div",{style:{overflow:"hidden"},children:[f.jsx("div",{style:{fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:b.label}),b.notes&&f.jsx("div",{style:{fontSize:"11px",color:c.textSecondary,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:b.notes})]}),i&&f.jsx("button",{onClick:B=>{B.stopPropagation(),i()},style:{marginLeft:"8px",padding:"2px",background:"none",border:"none",cursor:"pointer",color:c.textSecondary,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",flexShrink:0},title:"Clear selection",children:f.jsx("span",{className:"material-icons",style:{fontSize:"16px"},children:"close"})})]}):f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"material-icons",style:{position:"absolute",left:"10px",top:"50%",transform:"translateY(-50%)",color:c.textSecondary,fontSize:"16px",pointerEvents:"none"},children:"search"}),f.jsx("input",{ref:x,type:"text",value:d,onChange:v,onFocus:E,onKeyDown:T,placeholder:n,style:{width:"100%",height:"32px",padding:"0 12px 0 36px",fontSize:"13px",border:`1px solid ${p?c.primary:c.border}`,borderRadius:"8px",background:c.background,color:c.text,outline:"none",boxSizing:"border-box",transition:"border-color 0.15s"}})]})}),o&&f.jsx("button",{onClick:k,style:{display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",color:c.text,cursor:"pointer",padding:"4px",borderRadius:"4px",transition:"opacity 0.15s",flexShrink:0,opacity:.7},onMouseEnter:B=>{B.currentTarget.style.opacity="1"},onMouseLeave:B=>{B.currentTarget.style.opacity="0.7"},title:`Create ${t||"item"}`,children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px"},children:"add"})})]}),p&&f.jsx(Kc,{ref:_,filteredOptions:S,search:d,theme:c,maxHeight:a,onCardClick:C})]})}function Ig({items:r,columns:e,getItemId:t,getItemColumn:n,getItemOrder:s,renderItem:i,onItemMove:o,onItemReorder:a,onItemClick:l,renderColumnHeader:u,renderColumnFooter:c,className:d="",columnClassName:h="",columnStyle:p,itemClassName:g=""}){const[m,x]=y.useState(null),[_,b]=y.useState(null),[S,C]=y.useState(null),k=y.useRef(null),E=e.reduce((M,w)=>{let D=r.filter(F=>n(F)===w.id);return s&&(D=D.sort((F,I)=>s(F)-s(I))),M[w.id]=D,M},{}),v=y.useCallback((M,w)=>{const D=t(w),F=n(w);x(D),k.current=F,M.dataTransfer.effectAllowed="move",M.dataTransfer.setData("text/plain",D),requestAnimationFrame(()=>{const I=M.target;I.style.opacity="0.5"})},[t,n]),T=y.useCallback(M=>{const w=M.target;w.style.opacity="1",x(null),b(null),C(null),k.current=null},[]),B=y.useCallback((M,w,D)=>{M.preventDefault(),M.dataTransfer.dropEffect="move",b(w),C(D)},[]),j=y.useCallback(M=>{const w=M.relatedTarget;w!=null&&w.closest("[data-kanban-column]")||(b(null),C(null))},[]),N=y.useCallback((M,w,D)=>{if(M.preventDefault(),!m)return;const F=k.current;F===w?a==null||a(m,w,D):F&&o(m,F,w,D),x(null),b(null),C(null),k.current=null},[m,o,a]),R=(M,w)=>f.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[f.jsxs("div",{className:"flex items-center gap-2",children:[M.color&&f.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:M.color}}),f.jsx("span",{className:"font-medium text-sm text-neutral-700",children:M.label})]}),f.jsx("span",{className:"text-xs text-neutral-400 bg-neutral-100 px-2 py-0.5 rounded-full",children:w})]});return f.jsx("div",{className:`flex gap-4 overflow-x-auto pb-4 h-full ${d}`,style:{alignItems:"flex-start"},children:e.map(M=>{const w=E[M.id]||[],D=_===M.id,F=w.length>0||D;return f.jsxs("div",{"data-kanban-column":M.id,className:`flex-1 min-w-[180px] rounded-xl flex flex-col ${h||"bg-neutral-50"}`,style:{...p,maxHeight:"100%",...F?{}:{}},onDragOver:I=>{I.preventDefault(),m&&!D&&b(M.id)},onDragLeave:j,onDrop:I=>N(I,M.id,S??w.length),children:[f.jsx("div",{className:"flex-shrink-0 border-b border-neutral-200",children:u?u(M,w.length):R(M,w.length)}),f.jsxs("div",{className:`overflow-y-auto p-2 space-y-2 transition-colors ${D?"bg-blue-50":""}`,style:{minHeight:F?100:40},children:[w.map((I,q)=>{const Z=t(I),te=m===Z,W=D&&S===q&&!te;return f.jsxs("div",{children:[W&&f.jsx("div",{className:"h-1 bg-blue-500 rounded-full mb-2 mx-1"}),f.jsx("div",{draggable:!0,onDragStart:Q=>v(Q,I),onDragEnd:T,onDragOver:Q=>B(Q,M.id,q),onClick:()=>l==null?void 0:l(I),className:`cursor-grab active:cursor-grabbing transition-all ${te?"opacity-50 scale-95":""} ${g}`,children:i(I,te)})]},Z)}),f.jsx("div",{className:"min-h-[40px]",onDragOver:I=>{I.preventDefault(),B(I,M.id,w.length)},children:D&&S===w.length&&f.jsx("div",{className:"h-1 bg-blue-500 rounded-full mx-1 mt-1"})}),w.length===0&&D&&f.jsx("div",{className:"h-20 border-2 border-dashed border-blue-300 rounded-lg bg-blue-50/50 flex items-center justify-center",children:f.jsx("span",{className:"text-sm text-blue-400",children:"Drop here"})})]}),c&&f.jsx("div",{className:"flex-shrink-0 border-t border-neutral-200 p-2",children:c(M)})]},M.id)})})}function Yc(r){const e=r.data||{};return e.image||e.poster||e.thumbnail||e.cover||e.photo}function zg(r){const e=r.data||{};return e.subtitle||e.director||e.author||e.creator}function Og(r){const e=r.data||{};return e.description||r.description||e.synopsis||e.summary}function $g(r){const e=r.data||{},t=[];return e.year&&t.push(String(e.year)),e.duration&&t.push(`${e.duration} min`),e.country&&t.push(e.country),e.category&&t.push(e.category),t.join(" • ")}const qg={"1:1":1,"2:3":1.5,"16:9":.5625};function Qc({node:r,aspectRatio:e,onClick:t}){const[n,s]=y.useState(!1),i=Yc(r),o=qg[e],a=e==="2:3"?160:e==="16:9"?280:180,l=e==="2:3"||e==="16:9"?a*o:a;return f.jsxs("div",{onClick:t,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{position:"relative",width:a,height:l,flexShrink:0,borderRadius:6,overflow:"hidden",cursor:"pointer",transform:n?"scale(1.08)":"scale(1)",transition:"transform 0.2s ease-out",zIndex:n?10:1,boxShadow:n?"0 8px 24px rgba(0,0,0,0.5)":"0 2px 8px rgba(0,0,0,0.3)"},children:[i?f.jsx("img",{src:i,alt:r.title||"Item",style:{width:"100%",height:"100%",objectFit:"cover"}}):f.jsx("div",{style:{width:"100%",height:"100%",background:"linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:f.jsx("span",{style:{fontSize:32,opacity:.3},children:"📄"})}),f.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,padding:"24px 8px 8px",background:"linear-gradient(to top, rgba(0,0,0,0.9) 0%, transparent 100%)",opacity:n?1:.8,transition:"opacity 0.2s ease"},children:f.jsx("p",{style:{margin:0,fontSize:13,fontWeight:600,color:"white",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.title||"Untitled"})})]})}function Jc({title:r,nodes:e,cardAspectRatio:t,onNodeClick:n}){const s=y.useRef(null),[i,o]=y.useState(!1),[a,l]=y.useState(!1),[u,c]=y.useState(!1),d=()=>{const p=s.current;p&&(l(p.scrollLeft>0),c(p.scrollLeft<p.scrollWidth-p.clientWidth-10))};y.useEffect(()=>{d();const p=s.current;if(p)return p.addEventListener("scroll",d),()=>p.removeEventListener("scroll",d)},[e]);const h=p=>{const g=s.current;if(!g)return;const m=g.clientWidth*.8;g.scrollBy({left:p==="left"?-m:m,behavior:"smooth"})};return e.length===0?null:f.jsxs("div",{style:{marginBottom:32},onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[f.jsx("h3",{style:{margin:"0 0 12px 48px",fontSize:20,fontWeight:700,color:"white"},children:r}),f.jsxs("div",{style:{position:"relative"},children:[a&&f.jsx("button",{onClick:()=>h("left"),style:{position:"absolute",left:0,top:0,bottom:0,width:48,border:"none",background:"linear-gradient(to right, rgba(20,20,20,0.95) 0%, transparent 100%)",color:"white",cursor:"pointer",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",opacity:i?1:0,transition:"opacity 0.2s ease"},children:f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})})}),u&&f.jsx("button",{onClick:()=>h("right"),style:{position:"absolute",right:0,top:0,bottom:0,width:48,border:"none",background:"linear-gradient(to left, rgba(20,20,20,0.95) 0%, transparent 100%)",color:"white",cursor:"pointer",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",opacity:i?1:0,transition:"opacity 0.2s ease"},children:f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M8.59 16.59L10 18l6-6-6-6-1.41 1.41L13.17 12z"})})}),f.jsx("div",{ref:s,style:{display:"flex",gap:8,overflowX:"auto",overflowY:"hidden",padding:"8px 48px",scrollbarWidth:"none",msOverflowStyle:"none"},children:e.map(p=>f.jsx(Qc,{node:p,aspectRatio:t,onClick:()=>n(p)},p._id))})]})]})}function Xc({node:r,onClose:e}){const t=Yc(r),n=zg(r),s=Og(r),i=$g(r);return y.useEffect(()=>{const o=a=>{a.key==="Escape"&&e()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e]),y.useEffect(()=>(document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}),[]),f.jsx("div",{onClick:e,style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0, 0, 0, 0.85)",display:"flex",alignItems:"center",justifyContent:"center",padding:24},children:f.jsxs("div",{onClick:o=>o.stopPropagation(),style:{position:"relative",width:"100%",maxWidth:850,maxHeight:"90vh",background:"#181818",borderRadius:8,overflow:"hidden",boxShadow:"0 16px 64px rgba(0,0,0,0.6)"},children:[f.jsx("button",{onClick:e,style:{position:"absolute",top:12,right:12,width:36,height:36,borderRadius:"50%",border:"none",background:"#181818",color:"white",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10,fontSize:20},children:"✕"}),f.jsxs("div",{style:{overflowY:"auto",maxHeight:"90vh"},children:[f.jsxs("div",{style:{position:"relative",width:"100%",aspectRatio:"16/9",background:"#0a0a0a"},children:[t?f.jsx("img",{src:t,alt:r.title||"Item",style:{width:"100%",height:"100%",objectFit:"cover"}}):f.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:f.jsx("span",{style:{fontSize:64,opacity:.2},children:"📄"})}),f.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:"50%",background:"linear-gradient(to top, #181818 0%, transparent 100%)"}}),f.jsx("div",{style:{position:"absolute",bottom:24,left:32,right:32},children:f.jsx("h1",{style:{margin:0,fontSize:32,fontWeight:700,color:"white",textShadow:"0 2px 8px rgba(0,0,0,0.5)"},children:r.title||"Untitled"})})]}),f.jsxs("div",{style:{padding:"0 32px 32px"},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:16},children:[n&&f.jsx("span",{style:{color:"#a3a3a3",fontSize:15},children:n}),i&&f.jsx("span",{style:{color:"#737373",fontSize:14},children:i})]}),s&&f.jsx("p",{style:{margin:0,fontSize:15,lineHeight:1.6,color:"#d4d4d4"},children:s}),r.data&&Object.keys(r.data).length>0&&f.jsxs("div",{style:{marginTop:24},children:[f.jsx("h4",{style:{margin:"0 0 12px",fontSize:14,fontWeight:600,color:"#737373",textTransform:"uppercase",letterSpacing:1},children:"Details"}),f.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:12},children:Object.entries(r.data).filter(([o])=>!["image","poster","thumbnail","cover","photo","description","subtitle","synopsis","summary"].includes(o)).slice(0,8).map(([o,a])=>f.jsxs("div",{children:[f.jsx("span",{style:{color:"#737373",fontSize:12,textTransform:"capitalize"},children:o.replace(/_/g," ")}),f.jsx("p",{style:{margin:"4px 0 0",color:"#d4d4d4",fontSize:14},children:String(a)})]},o))})]})]})]})]})})}function Ug({nodes:r,lanes:e,cardAspectRatio:t="2:3",onNodeClick:n}){const[s,i]=y.useState(null),o=y.useMemo(()=>e.map(u=>({...u,nodes:r.filter(u.filter)})),[r,e]),a=u=>{n?n(u):i(u)},l=()=>{i(null)};return f.jsxs("div",{style:{minHeight:"100vh",background:"#141414",paddingTop:24,paddingBottom:48},children:[o.map(u=>f.jsx(Jc,{title:u.title,nodes:u.nodes,cardAspectRatio:t,onNodeClick:a},u.id)),o.every(u=>u.nodes.length===0)&&f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,color:"#737373"},children:[f.jsx("span",{style:{fontSize:48,marginBottom:16},children:"📭"}),f.jsx("p",{style:{margin:0,fontSize:18},children:"No items to display"})]}),s&&f.jsx(Xc,{node:s,onClose:l})]})}const Wg={background:"#ffffff",hourLineColor:"#e5e7eb",halfHourLineColor:"#f3f4f6",hourTextColor:"#9ca3af",currentTimeColor:"#ef4444",allDayBackground:"#f9fafb",allDayBorder:"#e5e7eb"};function Hg(r){const e=r.match(/^(\d{1,2}):(\d{2})$/);return e?{hours:parseInt(e[1],10),minutes:parseInt(e[2],10)}:null}function Vg(r){const e=r%12||12,t=r<12?"AM":"PM";return`${e} ${t}`}function Gg(r){const e=new Date;return r.getDate()===e.getDate()&&r.getMonth()===e.getMonth()&&r.getFullYear()===e.getFullYear()}function Kg({items:r,date:e,startHour:t=7,endHour:n=22,hourHeight:s=60,getItemTime:i,getItemDuration:o,getItemIsAllDay:a,getItemId:l,renderItem:u,onItemClick:c,onTimeSlotClick:d,showCurrentTime:h=!0,className:p="",theme:g={}}){const m={...Wg,...g},{allDayItems:x,timedItems:_}=y.useMemo(()=>{const v=[],T=[];for(const B of r)a(B)?v.push(B):T.push(B);return{allDayItems:v,timedItems:T}},[r,a]),b=y.useMemo(()=>{const v=[];for(let T=t;T<=n;T++)v.push(T);return v},[t,n]),S=(n-t+1)*s,C=y.useCallback(v=>{const T=i(v);if(!T)return null;const B=Hg(T);if(!B)return null;const{hours:j,minutes:N}=B,R=Math.max(t,Math.min(n,j)),M=j<t?0:N,w=(R-t)*s+M/60*s,D=o(v),F=Math.max(20,D/60*s);return{top:w,height:F}},[i,o,t,n,s]),k=y.useMemo(()=>{if(!h||!Gg(e))return null;const v=new Date,T=v.getHours(),B=v.getMinutes();return T<t||T>n?null:(T-t)*s+B/60*s},[e,h,t,n,s]),E=y.useCallback(v=>{if(!d)return;const T=v.currentTarget.getBoundingClientRect(),j=(v.clientY-T.top)/s*60,N=Math.floor(j/60)+t,R=Math.round(j%60/15)*15,M=Math.min(n,Math.max(t,N)),w=R>=60?0:R,D=`${M.toString().padStart(2,"0")}:${w.toString().padStart(2,"0")}`;d(D)},[d,s,t,n]);return f.jsxs("div",{className:p,style:{background:m.background},children:[x.length>0&&f.jsxs("div",{style:{padding:"8px 0 8px 60px",borderBottom:`1px solid ${m.allDayBorder}`,background:m.allDayBackground},children:[f.jsx("div",{style:{fontSize:"11px",color:m.hourTextColor,marginBottom:"4px",textTransform:"uppercase",letterSpacing:"0.05em"},children:"All Day"}),f.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:x.map(v=>f.jsx("div",{onClick:()=>c==null?void 0:c(v),style:{cursor:c?"pointer":"default"},children:u(v)},l(v)))})]}),f.jsxs("div",{style:{position:"relative",height:S},children:[b.map((v,T)=>f.jsxs("div",{style:{position:"absolute",top:T*s,left:0,right:0},children:[f.jsx("div",{style:{position:"absolute",left:0,top:-8,width:"50px",textAlign:"right",paddingRight:"10px",fontSize:"11px",color:m.hourTextColor},children:Vg(v)}),f.jsx("div",{style:{position:"absolute",left:"60px",right:0,top:0,height:"1px",background:m.hourLineColor}}),T<b.length-1&&f.jsx("div",{style:{position:"absolute",left:"60px",right:0,top:s/2,height:"1px",background:m.halfHourLineColor}})]},v)),f.jsx("div",{style:{position:"absolute",left:"60px",right:0,top:0,bottom:0,cursor:d?"pointer":"default"},onClick:E}),k!==null&&f.jsxs("div",{style:{position:"absolute",left:"55px",right:0,top:k,zIndex:20,pointerEvents:"none"},children:[f.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",background:m.currentTimeColor,marginLeft:"-5px",marginTop:"-5px",position:"absolute"}}),f.jsx("div",{style:{marginLeft:"5px",height:"2px",background:m.currentTimeColor}})]}),_.map(v=>{const T=C(v);return T?f.jsx("div",{style:{position:"absolute",left:"64px",right:"8px",top:T.top,height:T.height,zIndex:10,cursor:c?"pointer":"default"},onClick:B=>{B.stopPropagation(),c==null||c(v)},children:u(v)},l(v)):null})]})]})}function Zc({onComplete:r,onCancel:e,onTranscribe:t,onTranscriptionComplete:n,variant:s="widget",hideSaveButton:i=!1,maxDuration:o=180,extraControls:a}){const l=s==="widget",[u,c]=y.useState("idle"),[d,h]=y.useState(0),[p,g]=y.useState(0),[m,x]=y.useState(!1),[_,b]=y.useState(0),[S,C]=y.useState(null),[k,E]=y.useState(!1),[v,T]=y.useState(null),[B,j]=y.useState(!0),[N,R]=y.useState([]),[M,w]=y.useState({completed:0,total:0}),D=y.useRef(!1),F=y.useRef(!0);y.useEffect(()=>{F.current=B},[B]);const I=y.useRef(null),q=y.useRef(null),Z=y.useRef(null),te=y.useRef(null),W=y.useRef(null),Q=y.useRef([]),H=y.useRef(null),ie=y.useRef(null),ue=y.useRef(null),de=y.useRef(null),we=y.useRef(!1),fe=y.useRef([]),Ce=y.useRef(null),O=y.useRef(null),je=y.useRef([]),re=y.useRef([]),Le=y.useRef("insert"),Me=y.useRef(!1),xe=y.useRef(0),Se=y.useRef(0),Re=y.useRef(0),se=J=>{const P=Math.floor(J/60),he=Math.floor(J%60);return`${P.toString().padStart(2,"0")}:${he.toString().padStart(2,"0")}`},ce=async J=>{const P=await J.arrayBuffer(),he=new AudioContext,ge=await he.decodeAudioData(P);return await he.close(),ge},$=J=>{const P=J.numberOfChannels,he=J.sampleRate,ge=1,Y=16,Ae=Y/8,Ee=P*Ae,Te=he*Ee,Pe=J.length*Ee,We=new ArrayBuffer(44+Pe),ke=new DataView(We),L=(ve,Ne)=>{for(let st=0;st<Ne.length;st++)ke.setUint8(ve+st,Ne.charCodeAt(st))};L(0,"RIFF"),ke.setUint32(4,36+Pe,!0),L(8,"WAVE"),L(12,"fmt "),ke.setUint32(16,16,!0),ke.setUint16(20,ge,!0),ke.setUint16(22,P,!0),ke.setUint32(24,he,!0),ke.setUint32(28,Te,!0),ke.setUint16(32,Ee,!0),ke.setUint16(34,Y,!0),L(36,"data"),ke.setUint32(40,Pe,!0);const be=[];for(let ve=0;ve<P;ve++)be.push(J.getChannelData(ve));let _e=44;for(let ve=0;ve<J.length;ve++)for(let Ne=0;Ne<P;Ne++){const st=Math.max(-1,Math.min(1,be[Ne][ve])),ct=st<0?st*32768:st*32767;ke.setInt16(_e,ct,!0),_e+=2}return new Blob([We],{type:"audio/wav"})},Ge=async(J,P,he,ge)=>{const Y=new AudioContext,Ae=J.sampleRate,Ee=Math.max(J.numberOfChannels,P.numberOfChannels),Te=Math.min(he,J.length),Pe=Math.max(0,J.length-he),We=ge==="insert"?Te+P.length+Pe:Te+P.length,ke=Y.createBuffer(Ee,We,Ae);for(let L=0;L<Ee;L++){const be=ke.getChannelData(L),_e=L<J.numberOfChannels?J.getChannelData(L):J.getChannelData(0);for(let Ne=0;Ne<Te;Ne++)be[Ne]=_e[Ne];const ve=L<P.numberOfChannels?P.getChannelData(L):P.getChannelData(0);for(let Ne=0;Ne<P.length;Ne++)be[Te+Ne]=ve[Ne];if(ge==="insert")for(let Ne=0;Ne<Pe;Ne++)be[Te+P.length+Ne]=_e[he+Ne]}return await Y.close(),ke},Ke=y.useCallback(()=>{const J=I.current;if(!J)return;const P=J.getContext("2d");if(!P)return;const he=J.getBoundingClientRect(),ge=he.width,Y=he.height,Ae=fe.current,Ee=p||d||1,Te=u==="recording"?d:_;P.fillStyle="#2d3b35",P.fillRect(0,0,ge,Y);const Pe=8,We="rgba(0, 0, 0, 0.4)",ke=P.createLinearGradient(0,0,0,Pe);ke.addColorStop(0,We),ke.addColorStop(1,"transparent"),P.fillStyle=ke,P.fillRect(0,0,ge,Pe);const L=P.createLinearGradient(0,Y-Pe,0,Y);L.addColorStop(0,"transparent"),L.addColorStop(1,We),P.fillStyle=L,P.fillRect(0,Y-Pe,ge,Pe);const be=P.createLinearGradient(0,0,Pe,0);be.addColorStop(0,We),be.addColorStop(1,"transparent"),P.fillStyle=be,P.fillRect(0,0,Pe,Y);const _e=P.createLinearGradient(ge-Pe,0,ge,0);_e.addColorStop(0,"transparent"),_e.addColorStop(1,We),P.fillStyle=_e,P.fillRect(ge-Pe,0,Pe,Y),P.strokeStyle="#5a6b62",P.lineWidth=1,P.beginPath(),P.moveTo(0,Y/2),P.lineTo(ge,Y/2),P.stroke();const ve=ge/2;if(Ae.length>0)if(u==="recording")for(let ct=0;ct<Ae.length;ct++){const bt=Ae.length-1-ct,Xt=ve-bt*4;if(Xt<-3||Xt>ge)continue;const A=Ae[ct]*(Y/2-12),U=Y/2-A;P.fillStyle="#10b981",P.fillRect(Xt,U,3,A*2)}else{const ct=Ee>0?Te/Ee*Ae.length:0;for(let bt=0;bt<Ae.length;bt++){const Xt=ct-bt,A=ve-Xt*4;if(A<-3||A>ge)continue;const U=Ae[bt]*(Y/2-12),ne=Y/2-U;P.fillStyle=bt<=ct?"#10b981":"#4b5563",P.fillRect(A,ne,3,U*2)}}P.strokeStyle="#ef4444",P.lineWidth=1,P.beginPath(),P.moveTo(ve,0),P.lineTo(ve,Y),P.stroke(),P.fillStyle="#fff",P.font="bold 18px monospace",P.textAlign="center",P.fillText(se(Te),ve,Y-6),u==="recording"&&(P.fillStyle="#ef4444",P.beginPath(),P.arc(20,20,8,0,Math.PI*2),P.fill(),P.fillStyle="#fff",P.font="10px sans-serif",P.textAlign="left",P.fillText("REC",34,24)),P.textAlign="left"},[u,_,d,p]),X=()=>{const J=W.current;if(!J||!we.current)return;const P=J.frequencyBinCount,he=new Uint8Array(P);J.getByteTimeDomainData(he);let ge=0;for(let Ee=0;Ee<P;Ee++){const Te=(he[Ee]-128)/128;ge+=Te*Te}const Y=Math.sqrt(ge/P),Ae=Math.min(1,Y*3);fe.current.push(Ae),Ke(),we.current&&(ie.current=requestAnimationFrame(X))},K=async()=>{try{C(null),E(!1),Ce.current===null&&(fe.current=[]);const J=await navigator.mediaDevices.getUserMedia({audio:!0});Z.current=J;const P=new AudioContext;te.current=P;const he=P.createAnalyser();he.fftSize=2048,W.current=he,P.createMediaStreamSource(J).connect(he);const Y=new MediaRecorder(J);q.current=Y,Q.current=[],Y.ondataavailable=Ae=>{Ae.data.size>0&&Q.current.push(Ae.data)},Y.onstop=async()=>{try{if(we.current=!1,Q.current.length===0){C("No audio was recorded. Please try again."),c("idle"),J.getTracks().forEach(ke=>ke.stop());return}const Ae=new Blob(Q.current,{type:"audio/webm"});let Ee,Te;if(Ce.current!==null&&O.current)try{const ke=await ce(Ae),L=O.current.sampleRate,be=Math.floor(Ce.current*L),_e=await Ge(O.current,ke,be,Le.current);Ee=$(_e),Te=_e.length/_e.sampleRate,Le.current==="insert"&&(fe.current=[...fe.current,...re.current]),Ce.current=null,O.current=null,je.current=[],re.current=[]}catch{Ee=Ae,Te=xe.current>0?xe.current:1}else Ee=Ae,Te=xe.current>0?xe.current:1;if(de.current=Ee,J.getTracks().forEach(ke=>ke.stop()),F.current&&t){R(ke=>[...ke,Ee]),w(ke=>({...ke,total:ke.total+1})),de.current=null,fe.current=[],b(0),g(0),h(0),c("idle");return}const Pe=URL.createObjectURL(Ee),We=new Audio(Pe);We.ontimeupdate=()=>{b(We.currentTime)},We.onended=()=>{x(!1)},ue.current=We,g(Te),b(Te),c("editing")}catch{C("Failed to process recording"),c("idle")}},Y.start(100),we.current=!0,c("recording"),h(0),xe.current=0,H.current=setInterval(()=>{xe.current+=1,h(xe.current),xe.current>=o&&(q.current&&q.current.state!=="inactive"&&q.current.stop(),we.current=!1,T(null),H.current&&(clearInterval(H.current),H.current=null),ie.current&&(cancelAnimationFrame(ie.current),ie.current=null),setTimeout(()=>{alert(`Maximum recording time of ${Math.floor(o/60)} minutes reached.`)},100))},1e3)}catch{C("Could not access microphone. Please allow microphone access.")}},pe=()=>{we.current=!1,E(!1),T(null),ie.current&&(cancelAnimationFrame(ie.current),ie.current=null),H.current&&(clearInterval(H.current),H.current=null),q.current&&q.current.state!=="inactive"&&q.current.stop()},De=J=>{const P=I.current;if(!P)return;const he=p||d;if(he<=0)return;const ge=fe.current;if(ge.length===0)return;const Y=P.getBoundingClientRect(),Ae=J-Se.current,Ee=4,Te=Y.width/P.width,Pe=ge.length/he*Ee,We=-Ae/(Pe*Te),ke=Re.current+We,L=Math.max(0,Math.min(ke,he));ue.current&&(ue.current.currentTime=L),b(L)},Be=()=>{ue.current&&(ue.current.currentTime=0),b(0)},Qe=()=>{const J=p||d;ue.current&&(ue.current.currentTime=J),b(J)},Et=()=>{const J=ue.current;J&&(m?(J.pause(),b(J.currentTime),x(!1)):(J.currentTime=_,J.play().catch(()=>{}),x(!0)))},ae=async J=>{if(!de.current){K();return}try{ue.current&&(ue.current.pause(),x(!1)),Le.current=J,O.current=await ce(de.current);const P=p||d;Ce.current=_;const he=P>0?_/P:0,ge=Math.floor(he*fe.current.length);je.current=fe.current.slice(0,ge),re.current=fe.current.slice(ge),fe.current=[...je.current],K()}catch{C("Failed to prepare recording. Please try again.")}},me=()=>{ue.current&&(ue.current.pause(),ue.current=null),de.current=null,O.current=null,Ce.current=null,je.current=[],x(!1),b(0),g(0),h(0),K()},Ye=()=>{de.current?r(de.current,p||d):alert("No audio recorded yet!")};y.useEffect(()=>{u==="recording"&&I.current&&W.current&&we.current&&(ie.current=requestAnimationFrame(X))},[u]),y.useEffect(()=>{const J=I.current;if(!J)return;const P=()=>{const he=window.devicePixelRatio||1,ge=J.getBoundingClientRect();J.width=ge.width*he,J.height=ge.height*he;const Y=J.getContext("2d");Y&&Y.scale(he,he)};return P(),window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[]),y.useEffect(()=>{if(u==="idle"){const J=I.current;if(!J)return;const P=J.getContext("2d");if(!P)return;const he=J.getBoundingClientRect(),ge=he.width,Y=he.height;P.fillStyle="#2d3b35",P.fillRect(0,0,ge,Y);const Ae=8,Ee="rgba(0, 0, 0, 0.4)",Te=P.createLinearGradient(0,0,0,Ae);Te.addColorStop(0,Ee),Te.addColorStop(1,"transparent"),P.fillStyle=Te,P.fillRect(0,0,ge,Ae);const Pe=P.createLinearGradient(0,Y-Ae,0,Y);Pe.addColorStop(0,"transparent"),Pe.addColorStop(1,Ee),P.fillStyle=Pe,P.fillRect(0,Y-Ae,ge,Ae);const We=P.createLinearGradient(0,0,Ae,0);We.addColorStop(0,Ee),We.addColorStop(1,"transparent"),P.fillStyle=We,P.fillRect(0,0,Ae,Y);const ke=P.createLinearGradient(ge-Ae,0,ge,0);ke.addColorStop(0,"transparent"),ke.addColorStop(1,Ee),P.fillStyle=ke,P.fillRect(ge-Ae,0,Ae,Y),P.strokeStyle="#5a6b62",P.lineWidth=1,P.beginPath(),P.moveTo(0,Y/2),P.lineTo(ge,Y/2),P.stroke();const L=ge/2;P.strokeStyle="#ef4444",P.lineWidth=1,P.beginPath(),P.moveTo(L,0),P.lineTo(L,Y),P.stroke(),P.fillStyle="#fff",P.font="bold 18px monospace",P.textAlign="center",P.fillText("00:00",L,Y-6)}},[u]);const at=y.useCallback(J=>{R(P=>[...P,J]),w(P=>({...P,total:P.total+1}))},[]);if(y.useEffect(()=>{(async()=>{if(D.current||N.length===0||!t)return;D.current=!0;const P=N[0];try{const he=await t(P);he&&n&&n(he)}catch(he){console.error("Transcription failed:",he)}finally{R(he=>he.slice(1)),w(he=>({...he,completed:he.completed+1})),D.current=!1}})()},[N,t,n]),y.useEffect(()=>()=>{we.current=!1,H.current&&clearInterval(H.current),ie.current&&cancelAnimationFrame(ie.current),Z.current&&Z.current.getTracks().forEach(J=>J.stop()),te.current&&te.current.state!=="closed"&&te.current.close()},[]),y.useEffect(()=>{if(u==="editing"&&m){let J;const P=()=>{const he=ue.current;if(he&&m){const ge=I.current;if(ge){const Y=ge.getContext("2d");if(Y){const Ae=ge.getBoundingClientRect(),Ee=Ae.width,Te=Ae.height,Pe=fe.current,We=p||d||1,ke=he.currentTime;Y.fillStyle="#2d3b35",Y.fillRect(0,0,Ee,Te);const L=8,be="rgba(0, 0, 0, 0.4)",_e=Y.createLinearGradient(0,0,0,L);_e.addColorStop(0,be),_e.addColorStop(1,"transparent"),Y.fillStyle=_e,Y.fillRect(0,0,Ee,L);const ve=Y.createLinearGradient(0,Te-L,0,Te);ve.addColorStop(0,"transparent"),ve.addColorStop(1,be),Y.fillStyle=ve,Y.fillRect(0,Te-L,Ee,L);const Ne=Y.createLinearGradient(0,0,L,0);Ne.addColorStop(0,be),Ne.addColorStop(1,"transparent"),Y.fillStyle=Ne,Y.fillRect(0,0,L,Te);const st=Y.createLinearGradient(Ee-L,0,Ee,0);st.addColorStop(0,"transparent"),st.addColorStop(1,be),Y.fillStyle=st,Y.fillRect(Ee-L,0,L,Te),Y.strokeStyle="#5a6b62",Y.lineWidth=1,Y.beginPath(),Y.moveTo(0,Te/2),Y.lineTo(Ee,Te/2),Y.stroke();const ct=Ee/2,bt=3,Xt=4,A=We>0?ke/We*Pe.length:0;for(let ye=0;ye<Pe.length;ye++){const $e=A-ye,qe=ct-$e*Xt;if(qe<-bt||qe>Ee)continue;const Ie=Pe[ye]*(Te/2-12),Fe=Te/2-Ie;Y.fillStyle=ye<=A?"#10b981":"#4b5563",Y.fillRect(qe,Fe,bt,Ie*2)}Y.strokeStyle="#ef4444",Y.lineWidth=1,Y.beginPath(),Y.moveTo(ct,0),Y.lineTo(ct,Te),Y.stroke(),Y.fillStyle="#fff",Y.font="bold 18px monospace",Y.textAlign="center";const U=Math.floor(ke/60),ne=Math.floor(ke%60);Y.fillText(`${U.toString().padStart(2,"0")}:${ne.toString().padStart(2,"0")}`,ct,Te-6),Y.textAlign="left"}}J=requestAnimationFrame(P)}};return J=requestAnimationFrame(P),()=>cancelAnimationFrame(J)}},[u,m,p,d]),y.useEffect(()=>{u==="editing"&&!m&&Ke()},[u,_,m,Ke]),S)return f.jsxs("div",{style:{border:"1px solid #fecaca",borderRadius:"12px",padding:"16px",background:"#fef2f2"},children:[f.jsx("p",{style:{fontSize:"14px",color:"#dc2626",marginBottom:"12px"},children:S}),f.jsx("button",{onClick:()=>{C(null),K()},style:{padding:"8px 16px",fontSize:"14px",background:"#171717",color:"white",borderRadius:"8px",border:"none",cursor:"pointer"},children:"Try Again"})]});const He={padding:"8px",borderRadius:"8px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 0.15s"},Xe={...He,opacity:.3,cursor:"not-allowed"},br=l?{border:"1px solid #e5e5e5",borderRadius:"12px",overflow:"hidden",background:"white"}:{background:"white",flexShrink:0};return f.jsxs("div",{style:br,children:[f.jsx("canvas",{ref:I,style:{width:"100%",height:"32px",cursor:"pointer",flexShrink:0},onMouseDown:J=>{if(u==="editing"){Me.current=!0,Se.current=J.clientX,Re.current=_;const P=ge=>{Me.current&&De(ge.clientX)},he=()=>{Me.current=!1,window.removeEventListener("mousemove",P),window.removeEventListener("mouseup",he)};window.addEventListener("mousemove",P),window.addEventListener("mouseup",he)}}}),f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:l?"6px 8px":"4px",borderTop:"1px solid #d4d4d4",background:"linear-gradient(to bottom, #e0e0e0 0%, #c8c8c8 100%)",boxShadow:"inset 0 1px 0 rgba(255,255,255,0.6), inset 0 -1px 0 rgba(0,0,0,0.1)",flexShrink:0},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[f.jsx("button",{onClick:Be,disabled:u==="idle"||u==="recording",style:u==="idle"||u==="recording"?Xe:He,title:"Go to start",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:"#171717"},children:"first_page"})}),f.jsx("button",{onClick:()=>{if(u==="recording"){const J=q.current;J&&(J.state==="recording"?(J.pause(),E(!0)):J.state==="paused"&&(J.resume(),E(!1)))}else Et()},disabled:u==="idle",style:u==="idle"?Xe:He,title:m||u==="recording"&&!k?"Pause":"Play",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:"#171717"},children:m||u==="recording"&&!k?"pause":"play_arrow"})}),f.jsx("button",{onClick:Qe,disabled:u==="idle"||u==="recording",style:u==="idle"||u==="recording"?Xe:He,title:"Go to end",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:"#171717"},children:"last_page"})}),f.jsx("div",{style:{width:"1px",height:"24px",margin:"0 4px",background:"linear-gradient(to bottom, rgba(255,255,255,0.5), rgba(0,0,0,0.15))"}}),f.jsx("button",{onClick:()=>{v==="insert"?pe():u==="idle"?(T("insert"),K()):u==="editing"&&(T("insert"),ae("insert"))},disabled:u==="recording"&&v!=="insert"||m,style:u==="recording"&&v!=="insert"||m?Xe:He,title:v==="insert"?"Stop recording":"Insert recording",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:v==="insert"?"#ef4444":"#171717"},children:"add"})}),f.jsx("button",{onClick:()=>{F.current||(v==="mic"?pe():u==="idle"?(T("mic"),K()):u==="editing"&&(T("mic"),ae("replace")))},onMouseDown:()=>{F.current&&u==="idle"&&!m&&(T("mic"),K())},onMouseUp:()=>{F.current&&u==="recording"&&v==="mic"&&pe()},onMouseLeave:()=>{F.current&&u==="recording"&&v==="mic"&&pe()},onTouchStart:J=>{J.preventDefault(),F.current&&u==="idle"&&!m&&(T("mic"),K())},onTouchEnd:J=>{J.preventDefault(),F.current&&u==="recording"&&v==="mic"&&pe()},disabled:u==="recording"&&v!=="mic"||m,style:u==="recording"&&v!=="mic"||m?Xe:He,title:B?"Hold to record (walkie-talkie)":v==="mic"?"Stop recording":"Record",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:v==="mic"?"#ef4444":"#171717"},children:"mic"})}),f.jsx("button",{onClick:()=>{u==="idle"&&!m?(T("round"),K()):u==="recording"&&v==="round"&&pe()},disabled:u==="editing"||u==="recording"&&v!=="round"||m,style:u==="editing"||u==="recording"&&v!=="round"||m?Xe:{...He,width:"28px",height:"28px",borderRadius:"50%",padding:0},title:"Click to record / click to stop",children:f.jsx("span",{style:{display:"block",width:"14px",height:"14px",borderRadius:"50%",background:u==="recording"&&v==="round"?"#171717":"#ef4444",transition:"background 0.15s"}})}),f.jsx("button",{onClick:()=>{v==="startover"?pe():u==="editing"&&(T("startover"),me())},disabled:u==="idle"||u==="recording"&&v!=="startover"||m,style:u==="idle"||u==="recording"&&v!=="startover"||m?Xe:He,title:v==="startover"?"Stop recording":"Start over",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:v==="startover"?"#ef4444":"#171717"},children:"refresh"})})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[a,M.total>0&&M.completed<M.total&&f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",background:"rgba(16, 185, 129, 0.1)",borderRadius:"4px",fontSize:"11px",color:"#10b981"},children:[f.jsx("span",{className:"material-icons",style:{fontSize:"14px",animation:"spin 1s linear infinite"},children:"sync"}),M.completed,"/",M.total]}),t&&f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginRight:"4px"},children:[f.jsx("button",{onClick:()=>j(!B),style:{width:"28px",height:"16px",borderRadius:"8px",border:"none",background:B?"#10b981":"#9ca3af",cursor:"pointer",position:"relative",transition:"background 0.2s",padding:0},title:B?"Auto-transcribe ON":"Auto-transcribe OFF",children:f.jsx("div",{style:{width:"12px",height:"12px",borderRadius:"50%",background:"white",position:"absolute",top:"2px",left:B?"14px":"2px",transition:"left 0.2s",boxShadow:"0 1px 2px rgba(0,0,0,0.2)"}})}),f.jsx("span",{style:{fontSize:"10px",color:"#666"},children:"auto"})]}),f.jsx("button",{onClick:()=>{u==="editing"&&de.current&&at(de.current)},disabled:u!=="editing",style:u!=="editing"?Xe:He,title:"Transcribe audio",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:B?"#10b981":"#171717"},children:"subtitles"})})]}),!i&&f.jsx("button",{onClick:Ye,disabled:u!=="editing",style:u!=="editing"?Xe:He,title:"Save recording",children:f.jsx("span",{className:"material-icons",style:{fontSize:"20px",color:"#171717"},children:"save"})})]})]}),M.total>0&&M.completed<M.total&&f.jsx("div",{style:{height:"3px",background:"#e5e5e5",overflow:"hidden"},children:f.jsx("div",{style:{height:"100%",background:"#10b981",width:`${M.completed/M.total*100}%`,transition:"width 0.3s ease"}})})]})}function Yg({label:r,value:e,onChange:t,onTranscribe:n,onAIAction:s,onAIPrompt:i,onAudioSave:o,placeholder:a="Type or record...",className:l="",rows:u,llmClient:c,graphClient:d,nodeId:h,audioFilename:p,existingAudio:g,existingVoice:m,onAudioGenerated:x,onGenerateTTS:_,audioUrl:b,voice:S="coral",onVoiceChange:C,generateButton:k,generatePrompt:E,generateSourceText:v,generateSourceError:T}){const[B,j]=y.useState(!1),[N,R]=y.useState(!1),[M,w]=y.useState(""),[D,F]=y.useState(!1),[I,q]=y.useState(!1),[Z,te]=y.useState(null),[W,Q]=y.useState(m||S),[H,ie]=y.useState(g),[ue,de]=y.useState(Date.now()),we=y.useRef(null),fe=y.useRef(null),Ce=!!(c&&d&&h&&p);y.useEffect(()=>{g!==void 0&&ie(g)},[g]),y.useEffect(()=>{m!==void 0&&Q(m)},[m]);const O=Ce&&H&&d&&h?`${d.getFileUrl(h,H)}?v=${ue}`:b,je=se=>{t(e?`${e}
184
184
 
185
- ${se}`:se)},re=async se=>{if(!(!(typeof e=="string"?e:"").trim()||B||!s)){j(!0),R(!1);try{const ce=await s(se,e);t(ce)}catch(ce){console.error(`${se} failed:`,ce)}finally{j(!1)}}},Le=()=>{setTimeout(()=>{var se;(se=we.current)!=null&&se.contains(document.activeElement)||R(!1)},150)},Me=async()=>{if(!(!M.trim()||B||!i)){j(!0);try{const se=await i(M,e);t(se),w("")}catch(se){console.error("AI prompt failed:",se)}finally{j(!1)}}},xe=async()=>{if(!(typeof e=="string"?e:"").trim()||D)return;if(!(Ce||_)){console.warn("TTS: No generation mode available",{integratedTTS:Ce,hasCallback:!!_,llmClient:!!c,graphClient:!!d,nodeId:h,audioFilename:p}),alert("TTS non disponible. Sauvegardez d'abord le cours.");return}fe.current&&(fe.current.pause(),fe.current.currentTime=0),F(!0);try{if(Ce&&c&&d&&h&&p){console.log("TTS: Generating audio...",{voice:W,textLength:e.length});const ce=await c.tts(e,{voice:W});console.log("TTS: Audio generated, uploading...",{audioLength:ce==null?void 0:ce.length});const $=atob(ce),Ge=new Uint8Array($.length);for(let K=0;K<$.length;K++)Ge[K]=$.charCodeAt(K);const Ke=new Blob([Ge],{type:"audio/mpeg"}),X=new File([Ke],p,{type:"audio/mpeg"});await d.uploadFile(h,p,X),console.log("TTS: Upload complete",{nodeId:h,audioFilename:p}),de(Date.now()),ie(p),x==null||x(p,W)}else _&&(await _(e,W),de(Date.now()))}catch(ce){console.error("TTS generation failed:",ce),alert("Erreur TTS: "+(ce instanceof Error?ce.message:"Erreur inconnue"))}finally{F(!1)}},Se=async()=>{if(!(!c||!E||I)){if(!(v!=null&&v.trim())){te(T||"Le texte source est requis pour la génération.");return}q(!0),te(null);try{const se=await c.chat([{role:"system",content:E},{role:"user",content:v}]);t(se)}catch(se){te(se instanceof Error?se.message:"Erreur de génération")}finally{q(!1)}}},Re=se=>{Q(se),C==null||C(se)};return f.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${l}`,children:[f.jsx(Zc,{onComplete:o||(()=>{}),onTranscribe:n,onTranscriptionComplete:je,hideSaveButton:!o,variant:"div",extraControls:f.jsxs(f.Fragment,{children:[i&&f.jsx("button",{type:"button",onClick:Me,disabled:B||!M.trim(),style:{padding:"4px",borderRadius:"4px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:B||!M.trim()?.3:1},title:"Envoyer le prompt AI",children:f.jsx("span",{className:"material-icons",style:{fontSize:"18px",color:B?"#9333ea":"#171717"},children:B?"hourglass_empty":"smart_toy"})}),s&&f.jsxs("div",{className:"relative",ref:we,style:{display:"inline-flex"},children:[f.jsx("button",{type:"button",onClick:()=>R(!N),disabled:B||!(typeof e=="string"?e:"").trim(),style:{padding:"4px 8px",marginRight:"6px",borderRadius:"4px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:B||!(typeof e=="string"?e:"").trim()?.4:1},children:f.jsx("span",{className:"material-icons",style:{fontSize:"18px",color:"#171717",transform:N?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:"chevron_right"})}),N&&!B&&f.jsxs("div",{className:"absolute right-0 top-full mt-1 bg-white border border-neutral-200 rounded-lg shadow-lg z-50 min-w-[180px] py-1",onBlur:Le,children:[f.jsxs("button",{type:"button",onClick:()=>re("restructure"),className:"w-full px-3 py-2 text-left text-sm hover:bg-neutral-50 flex items-center gap-2",children:[f.jsx("span",{className:"material-icons text-base text-blue-500",children:"format_list_bulleted"}),f.jsxs("div",{children:[f.jsx("div",{className:"font-medium",children:"Restructure"}),f.jsx("div",{className:"text-xs text-neutral-500",children:"Organize & clarify"})]})]}),f.jsxs("button",{type:"button",onClick:()=>re("proofread"),className:"w-full px-3 py-2 text-left text-sm hover:bg-neutral-50 flex items-center gap-2",children:[f.jsx("span",{className:"material-icons text-base text-green-500",children:"spellcheck"}),f.jsxs("div",{children:[f.jsx("div",{className:"font-medium",children:"Proofread"}),f.jsx("div",{className:"text-xs text-neutral-500",children:"Fix grammar & spelling"})]})]}),f.jsxs("button",{type:"button",onClick:()=>re("rewrite"),className:"w-full px-3 py-2 text-left text-sm hover:bg-neutral-50 flex items-center gap-2",children:[f.jsx("span",{className:"material-icons text-base text-purple-500",children:"brush"}),f.jsxs("div",{children:[f.jsx("div",{className:"font-medium",children:"Rewrite"}),f.jsx("div",{className:"text-xs text-neutral-500",children:"Your voice & style"})]})]})]})]})]})}),i&&f.jsx("div",{className:"bg-neutral-50 border-b border-neutral-200",children:f.jsx("textarea",{value:M,onChange:se=>w(se.target.value),onKeyDown:se=>{se.stopPropagation(),se.key==="Enter"&&se.ctrlKey&&(se.preventDefault(),Me())},placeholder:"Instructions AI... (Ctrl+Enter)",disabled:B,rows:3,className:"w-full px-3 py-2 text-sm border-0 resize-y min-h-[60px] focus:ring-0 focus:outline-none bg-transparent disabled:opacity-50"})}),(r||(typeof e=="string"?e:"").trim()||Ce||_||k)&&f.jsxs("div",{className:"flex items-center justify-between px-2 py-1",children:[f.jsxs("div",{className:"flex items-center gap-2",children:[r&&f.jsx("label",{className:"text-sm font-medium text-neutral-700",children:r}),k&&c&&E&&f.jsxs("button",{type:"button",onClick:Se,disabled:I,className:"flex items-center gap-1 px-2 py-1 text-xs bg-purple-100 text-purple-700 hover:bg-purple-200 rounded transition-colors disabled:opacity-50",title:k.label,children:[f.jsx("span",{className:"material-icons",style:{fontSize:"14px"},children:I?"hourglass_empty":k.icon||"auto_awesome"}),k.label]})]}),f.jsxs("div",{className:"flex items-center gap-1",children:[(typeof e=="string"?e:"").trim()&&f.jsx("button",{type:"button",onClick:()=>navigator.clipboard.writeText(e),className:"p-1 rounded hover:bg-neutral-100 transition-colors",title:"Copy to clipboard",children:f.jsx("span",{className:"material-icons text-neutral-500",style:{fontSize:"16px"},children:"content_copy"})}),(Ce||_)&&f.jsxs("div",{className:"flex items-center gap-1",children:[f.jsx("select",{value:W,onChange:se=>Re(se.target.value),disabled:D,className:"px-1.5 py-0.5 text-xs border border-neutral-200 rounded bg-white focus:outline-none focus:ring-1 focus:ring-blue-500 disabled:opacity-50",title:"Choisir la voix",children:ou.map(se=>f.jsxs("option",{value:se.id,children:[se.name," - ",se.description]},se.id))}),f.jsx("button",{type:"button",onClick:xe,disabled:D||!(typeof e=="string"?e:"").trim(),className:"p-1 rounded hover:bg-blue-50 transition-colors disabled:opacity-40",title:D?"Génération en cours...":"Générer audio TTS",children:f.jsx("span",{className:`material-icons ${D?"animate-pulse text-blue-600":O?"text-green-600":"text-neutral-400"}`,style:{fontSize:"16px"},children:D?"hourglass_empty":"record_voice_over"})}),O&&f.jsxs(f.Fragment,{children:[f.jsx("audio",{ref:fe,src:O,controls:!0,className:"h-6 w-32"},ue),f.jsx("button",{type:"button",onClick:()=>{fe.current&&fe.current.pause(),ie(void 0),x==null||x("",W)},className:"p-1 rounded hover:bg-red-50 transition-colors",title:"Supprimer l'audio",children:f.jsx("span",{className:"material-icons text-red-400 hover:text-red-600",style:{fontSize:"14px"},children:"delete"})})]})]})]})]}),f.jsx("textarea",{value:e,onChange:se=>t(se.target.value),onKeyDown:se=>se.stopPropagation(),placeholder:a,rows:u,disabled:B||I,className:"flex-1 w-full px-3 py-2 border-0 focus:ring-0 focus:outline-none text-sm disabled:opacity-50 disabled:bg-neutral-50 resize-none"}),Z&&f.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:f.jsxs("div",{className:"bg-white rounded-lg shadow-xl p-6 max-w-md mx-4",children:[f.jsxs("div",{className:"flex items-start gap-3",children:[f.jsx("span",{className:"material-icons text-amber-500",style:{fontSize:"24px"},children:"warning"}),f.jsxs("div",{className:"flex-1",children:[f.jsx("h3",{className:"font-medium text-neutral-900 mb-2",children:"Génération impossible"}),f.jsx("p",{className:"text-sm text-neutral-600",children:Z})]})]}),f.jsx("div",{className:"mt-4 flex justify-end",children:f.jsx("button",{type:"button",onClick:()=>te(null),className:"px-4 py-2 bg-neutral-100 hover:bg-neutral-200 text-neutral-700 rounded transition-colors text-sm",children:"Compris"})})]})})]})}const gs={"4/3":4/3,"16/9":16/9,"1/1":1,"3/4":3/4,"9/16":9/16,free:null};function Qg({src:r,onSave:e,onCancel:t,aspectRatio:n="4/3",outputFormat:s="image/jpeg",outputQuality:i=.9,theme:o="dark"}){const a=y.useRef(null),l=y.useRef(null),u=y.useRef(null),[c,d]=y.useState(!0),[h,p]=y.useState(null),[g,m]=y.useState(n),[x,_]=y.useState(0),[b,S]=y.useState({x:0,y:0,width:100,height:100}),[C,k]=y.useState(!1),[E,v]=y.useState(null),[T,B]=y.useState({x:0,y:0}),[j,N]=y.useState({x:0,y:0,width:100,height:100}),R=o==="dark",M=y.useCallback(()=>{const O=u.current;return O?x===90||x===270?{width:O.height,height:O.width}:{width:O.width,height:O.height}:{width:100,height:100}},[x]),w=y.useCallback((O,je)=>{const re=O/je,Le=.05;for(const[Me,xe]of Object.entries(gs))if(xe!==null&&Math.abs(re-xe)/xe<Le)return Me;return"free"},[]);y.useEffect(()=>{const O=new Image;O.crossOrigin="anonymous",O.onload=()=>{u.current=O;const je=w(O.width,O.height);m(je),d(!1)},O.onerror=()=>{p("Failed to load image"),d(!1)},O.src=r},[r,w]);const D=y.useCallback(()=>{const{width:O,height:je}=M(),re=gs[g];if(re===null){S({x:0,y:0,width:100,height:100});return}const Le=O/je;let Me,xe;Le>re?(xe=100,Me=re/Le*100):(Me=100,xe=Le/re*100);const Se=(100-Me)/2,Re=(100-xe)/2;S({x:Se,y:Re,width:Me,height:xe})},[g,M]);y.useEffect(()=>{u.current&&D()},[g,x,D]),y.useEffect(()=>{const O=l.current,je=u.current;if(!O||!je||c)return;const re=O.getContext("2d");if(!re)return;const Le=a.current;if(!Le)return;const Me=Le.clientWidth,xe=Le.clientHeight-140,{width:Se,height:Re}=M(),se=Se/Re;let ce,$;Me/xe>se?($=Math.min(xe,Re),ce=$*se):(ce=Math.min(Me,Se),$=ce/se),ce>Me&&(ce=Me,$=ce/se),$>xe&&($=xe,ce=$*se),O.width=ce,O.height=$,re.clearRect(0,0,ce,$),re.save(),re.translate(ce/2,$/2),re.rotate(x*Math.PI/180);let Ge,Ke;x===90||x===270?(Ge=$,Ke=ce):(Ge=ce,Ke=$),re.drawImage(je,-Ge/2,-Ke/2,Ge,Ke),re.restore(),re.fillStyle="rgba(0, 0, 0, 0.6)";const X=b.x/100*ce,K=b.y/100*$,pe=b.width/100*ce,De=b.height/100*$;re.fillRect(0,0,ce,K),re.fillRect(0,K+De,ce,$-K-De),re.fillRect(0,K,X,De),re.fillRect(X+pe,K,ce-X-pe,De),re.strokeStyle="#fff",re.lineWidth=2,re.strokeRect(X,K,pe,De),re.strokeStyle="rgba(255, 255, 255, 0.3)",re.lineWidth=1,re.beginPath(),re.moveTo(X+pe/3,K),re.lineTo(X+pe/3,K+De),re.moveTo(X+pe*2/3,K),re.lineTo(X+pe*2/3,K+De),re.moveTo(X,K+De/3),re.lineTo(X+pe,K+De/3),re.moveTo(X,K+De*2/3),re.lineTo(X+pe,K+De*2/3),re.stroke();const Be=14;re.fillStyle="#fff",re.strokeStyle="#333",re.lineWidth=1,[{x:X,y:K},{x:X+pe,y:K},{x:X,y:K+De},{x:X+pe,y:K+De}].forEach(Et=>{re.fillRect(Et.x-Be/2,Et.y-Be/2,Be,Be),re.strokeRect(Et.x-Be/2,Et.y-Be/2,Be,Be)})},[b,x,c,M]);const F=O=>{const je=l.current;if(!je)return;const re=je.getBoundingClientRect(),Le=(O.clientX-re.left)/re.width*100,Me=(O.clientY-re.top)/re.height*100,xe=4,Se=[{name:"nw",x:b.x,y:b.y},{name:"ne",x:b.x+b.width,y:b.y},{name:"sw",x:b.x,y:b.y+b.height},{name:"se",x:b.x+b.width,y:b.y+b.height}];for(const Re of Se)if(Math.abs(Le-Re.x)<xe&&Math.abs(Me-Re.y)<xe){v(Re.name),B({x:Le,y:Me}),N({...b});return}Le>=b.x&&Le<=b.x+b.width&&Me>=b.y&&Me<=b.y+b.height&&(k(!0),B({x:Le,y:Me}),N({...b}))},I=O=>{const je=l.current;if(!je)return;const re=je.getBoundingClientRect(),Le=(O.clientX-re.left)/re.width*100,Me=(O.clientY-re.top)/re.height*100;if(C){const xe=Le-T.x,Se=Me-T.y;let Re=j.x+xe,se=j.y+Se;Re=Math.max(0,Math.min(Re,100-j.width)),se=Math.max(0,Math.min(se,100-j.height)),S({...j,x:Re,y:se})}else if(E){const xe=gs[g],{width:Se,height:Re}=M(),se=Se/Re,ce=xe?xe/se:null;let $={...j};const Ge=Le-T.x,Ke=Me-T.y;if(E==="se")$.width=Math.max(10,Math.min(100-$.x,j.width+Ge)),ce?($.height=$.width/ce,$.y+$.height>100&&($.height=100-$.y,$.width=$.height*ce)):$.height=Math.max(10,Math.min(100-$.y,j.height+Ke));else if(E==="sw"){const X=-Ge,K=Math.max(10,j.width+X),pe=j.x+j.width-K;pe>=0&&($.width=K,$.x=pe,ce?($.height=$.width/ce,$.y+$.height>100&&($.height=100-$.y,$.width=$.height*ce,$.x=j.x+j.width-$.width)):$.height=Math.max(10,Math.min(100-$.y,j.height+Ke)))}else if(E==="ne")if($.width=Math.max(10,Math.min(100-$.x,j.width+Ge)),ce){const X=$.width/ce,K=j.y+j.height-X;K>=0?($.height=X,$.y=K):($.y=0,$.height=j.y+j.height,$.width=$.height*ce)}else{const X=-Ke,K=Math.max(10,j.height+X),pe=j.y+j.height-K;pe>=0&&($.height=K,$.y=pe)}else if(E==="nw"){const X=-Ge,K=Math.max(10,j.width+X),pe=j.x+j.width-K;if(pe>=0)if($.width=K,$.x=pe,ce){const De=$.width/ce,Be=j.y+j.height-De;Be>=0?($.height=De,$.y=Be):($.y=0,$.height=j.y+j.height,$.width=$.height*ce,$.x=j.x+j.width-$.width)}else{const De=-Ke,Be=Math.max(10,j.height+De),Qe=j.y+j.height-Be;Qe>=0&&($.height=Be,$.y=Qe)}}$.x=Math.max(0,$.x),$.y=Math.max(0,$.y),$.width=Math.min($.width,100-$.x),$.height=Math.min($.height,100-$.y),S($)}},q=()=>{k(!1),v(null)},Z=O=>{_(je=>O==="right"?(je+90)%360:(je-90+360)%360)},te=()=>{const O=u.current;if(!O)return;const{width:je,height:re}=M(),Le=b.x/100*je,Me=b.y/100*re,xe=b.width/100*je,Se=b.height/100*re,Re=document.createElement("canvas"),se=Re.getContext("2d");if(!se)return;Re.width=xe,Re.height=Se;const ce=document.createElement("canvas"),$=ce.getContext("2d");$&&(ce.width=je,ce.height=re,$.save(),$.translate(je/2,re/2),$.rotate(x*Math.PI/180),$.drawImage(O,-O.width/2,-O.height/2,O.width,O.height),$.restore(),se.drawImage(ce,Le,Me,xe,Se,0,0,xe,Se),Re.toBlob(Ge=>{Ge&&e(Ge)},s,i))},W={display:"flex",flexDirection:"column",width:"100%",height:"100%",background:R?"#1a1a1a":"#f5f5f5",overflow:"hidden"},Q={flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:"16px",minHeight:0,overflow:"hidden"},H={display:"flex",flexDirection:"column",gap:"12px",padding:"16px",borderTop:`1px solid ${R?"#333":"#ddd"}`,background:R?"#242424":"#fff",flexShrink:0},ie={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px"},ue={padding:"10px 20px",borderRadius:"8px",border:"none",cursor:"pointer",fontSize:"14px",fontWeight:500,transition:"background 0.15s, opacity 0.15s"},de={...ue,background:"#E67E22",color:"#fff"},we={...ue,background:R?"#333":"#e5e5e5",color:R?"#fff":"#333"},fe={padding:"10px",borderRadius:"8px",border:"none",background:R?"#333":"#e5e5e5",color:R?"#fff":"#333",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},Ce=O=>({padding:"8px 14px",borderRadius:"6px",border:O?"2px solid #E67E22":"2px solid transparent",background:O?"#E67E22":R?"#333":"#e5e5e5",color:O?"#fff":R?"#ccc":"#666",cursor:"pointer",fontSize:"13px",fontWeight:600,transition:"all 0.15s"});return c?f.jsx("div",{style:{...W,alignItems:"center",justifyContent:"center"},children:f.jsx("div",{style:{color:R?"#aaa":"#666"},children:"Loading image..."})}):h?f.jsxs("div",{style:{...W,alignItems:"center",justifyContent:"center"},children:[f.jsx("div",{style:{color:"#ef4444"},children:h}),t&&f.jsx("button",{onClick:t,style:{...we,marginTop:"16px"},children:"Close"})]}):f.jsxs("div",{ref:a,style:W,children:[f.jsx("div",{style:Q,children:f.jsx("canvas",{ref:l,style:{cursor:C?"grabbing":E?"nwse-resize":"grab",maxWidth:"100%",maxHeight:"100%"},onMouseDown:F,onMouseMove:I,onMouseUp:q,onMouseLeave:q})}),f.jsxs("div",{style:H,children:[f.jsx("div",{style:{display:"flex",gap:"8px",flexWrap:"wrap",justifyContent:"center"},children:Object.keys(gs).map(O=>f.jsx("button",{onClick:()=>m(O),style:Ce(g===O),children:O==="free"?"Libre":O},O))}),f.jsxs("div",{style:ie,children:[f.jsxs("div",{style:{display:"flex",gap:"8px"},children:[f.jsx("button",{onClick:()=>Z("left"),style:fe,title:"Rotate left",children:f.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:f.jsx("path",{d:"M2.5 2v6h6M2.66 15.57a10 10 0 1 0 .57-8.38"})})}),f.jsx("button",{onClick:()=>Z("right"),style:fe,title:"Rotate right",children:f.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:f.jsx("path",{d:"M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38"})})})]}),f.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t&&f.jsx("button",{onClick:t,style:we,children:"Annuler"}),f.jsx("button",{onClick:te,style:de,children:"Enregistrer"})]})]})]})]})}var Jg={value:()=>{}};function la(){for(var r=0,e=arguments.length,t={},n;r<e;++r){if(!(n=arguments[r]+"")||n in t||/[\s.]/.test(n))throw new Error("illegal type: "+n);t[n]=[]}return new Cs(t)}function Cs(r){this._=r}function Xg(r,e){return r.trim().split(/^|\s+/).map(function(t){var n="",s=t.indexOf(".");if(s>=0&&(n=t.slice(s+1),t=t.slice(0,s)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}})}Cs.prototype=la.prototype={constructor:Cs,on:function(r,e){var t=this._,n=Xg(r+"",t),s,i=-1,o=n.length;if(arguments.length<2){for(;++i<o;)if((s=(r=n[i]).type)&&(s=Zg(t[s],r.name)))return s;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++i<o;)if(s=(r=n[i]).type)t[s]=zl(t[s],r.name,e);else if(e==null)for(s in t)t[s]=zl(t[s],r.name,null);return this},copy:function(){var r={},e=this._;for(var t in e)r[t]=e[t].slice();return new Cs(r)},call:function(r,e){if((s=arguments.length-2)>0)for(var t=new Array(s),n=0,s,i;n<s;++n)t[n]=arguments[n+2];if(!this._.hasOwnProperty(r))throw new Error("unknown type: "+r);for(i=this._[r],n=0,s=i.length;n<s;++n)i[n].value.apply(e,t)},apply:function(r,e,t){if(!this._.hasOwnProperty(r))throw new Error("unknown type: "+r);for(var n=this._[r],s=0,i=n.length;s<i;++s)n[s].value.apply(e,t)}};function Zg(r,e){for(var t=0,n=r.length,s;t<n;++t)if((s=r[t]).name===e)return s.value}function zl(r,e,t){for(var n=0,s=r.length;n<s;++n)if(r[n].name===e){r[n]=Jg,r=r.slice(0,n).concat(r.slice(n+1));break}return t!=null&&r.push({name:e,value:t}),r}var bo="http://www.w3.org/1999/xhtml";const Ol={svg:"http://www.w3.org/2000/svg",xhtml:bo,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function _i(r){var e=r+="",t=e.indexOf(":");return t>=0&&(e=r.slice(0,t))!=="xmlns"&&(r=r.slice(t+1)),Ol.hasOwnProperty(e)?{space:Ol[e],local:r}:r}function e0(r){return function(){var e=this.ownerDocument,t=this.namespaceURI;return t===bo&&e.documentElement.namespaceURI===bo?e.createElement(r):e.createElementNS(t,r)}}function t0(r){return function(){return this.ownerDocument.createElementNS(r.space,r.local)}}function ed(r){var e=_i(r);return(e.local?t0:e0)(e)}function r0(){}function ua(r){return r==null?r0:function(){return this.querySelector(r)}}function n0(r){typeof r!="function"&&(r=ua(r));for(var e=this._groups,t=e.length,n=new Array(t),s=0;s<t;++s)for(var i=e[s],o=i.length,a=n[s]=new Array(o),l,u,c=0;c<o;++c)(l=i[c])&&(u=r.call(l,l.__data__,c,i))&&("__data__"in l&&(u.__data__=l.__data__),a[c]=u);return new Tt(n,this._parents)}function s0(r){return r==null?[]:Array.isArray(r)?r:Array.from(r)}function i0(){return[]}function td(r){return r==null?i0:function(){return this.querySelectorAll(r)}}function o0(r){return function(){return s0(r.apply(this,arguments))}}function a0(r){typeof r=="function"?r=o0(r):r=td(r);for(var e=this._groups,t=e.length,n=[],s=[],i=0;i<t;++i)for(var o=e[i],a=o.length,l,u=0;u<a;++u)(l=o[u])&&(n.push(r.call(l,l.__data__,u,o)),s.push(l));return new Tt(n,s)}function rd(r){return function(){return this.matches(r)}}function nd(r){return function(e){return e.matches(r)}}var l0=Array.prototype.find;function u0(r){return function(){return l0.call(this.children,r)}}function c0(){return this.firstElementChild}function d0(r){return this.select(r==null?c0:u0(typeof r=="function"?r:nd(r)))}var f0=Array.prototype.filter;function h0(){return Array.from(this.children)}function p0(r){return function(){return f0.call(this.children,r)}}function g0(r){return this.selectAll(r==null?h0:p0(typeof r=="function"?r:nd(r)))}function m0(r){typeof r!="function"&&(r=rd(r));for(var e=this._groups,t=e.length,n=new Array(t),s=0;s<t;++s)for(var i=e[s],o=i.length,a=n[s]=[],l,u=0;u<o;++u)(l=i[u])&&r.call(l,l.__data__,u,i)&&a.push(l);return new Tt(n,this._parents)}function sd(r){return new Array(r.length)}function y0(){return new Tt(this._enter||this._groups.map(sd),this._parents)}function Qs(r,e){this.ownerDocument=r.ownerDocument,this.namespaceURI=r.namespaceURI,this._next=null,this._parent=r,this.__data__=e}Qs.prototype={constructor:Qs,appendChild:function(r){return this._parent.insertBefore(r,this._next)},insertBefore:function(r,e){return this._parent.insertBefore(r,e)},querySelector:function(r){return this._parent.querySelector(r)},querySelectorAll:function(r){return this._parent.querySelectorAll(r)}};function x0(r){return function(){return r}}function b0(r,e,t,n,s,i){for(var o=0,a,l=e.length,u=i.length;o<u;++o)(a=e[o])?(a.__data__=i[o],n[o]=a):t[o]=new Qs(r,i[o]);for(;o<l;++o)(a=e[o])&&(s[o]=a)}function v0(r,e,t,n,s,i,o){var a,l,u=new Map,c=e.length,d=i.length,h=new Array(c),p;for(a=0;a<c;++a)(l=e[a])&&(h[a]=p=o.call(l,l.__data__,a,e)+"",u.has(p)?s[a]=l:u.set(p,l));for(a=0;a<d;++a)p=o.call(r,i[a],a,i)+"",(l=u.get(p))?(n[a]=l,l.__data__=i[a],u.delete(p)):t[a]=new Qs(r,i[a]);for(a=0;a<c;++a)(l=e[a])&&u.get(h[a])===l&&(s[a]=l)}function _0(r){return r.__data__}function w0(r,e){if(!arguments.length)return Array.from(this,_0);var t=e?v0:b0,n=this._parents,s=this._groups;typeof r!="function"&&(r=x0(r));for(var i=s.length,o=new Array(i),a=new Array(i),l=new Array(i),u=0;u<i;++u){var c=n[u],d=s[u],h=d.length,p=C0(r.call(c,c&&c.__data__,u,n)),g=p.length,m=a[u]=new Array(g),x=o[u]=new Array(g),_=l[u]=new Array(h);t(c,d,m,x,_,p,e);for(var b=0,S=0,C,k;b<g;++b)if(C=m[b]){for(b>=S&&(S=b+1);!(k=x[S])&&++S<g;);C._next=k||null}}return o=new Tt(o,n),o._enter=a,o._exit=l,o}function C0(r){return typeof r=="object"&&"length"in r?r:Array.from(r)}function S0(){return new Tt(this._exit||this._groups.map(sd),this._parents)}function k0(r,e,t){var n=this.enter(),s=this,i=this.exit();return typeof r=="function"?(n=r(n),n&&(n=n.selection())):n=n.append(r+""),e!=null&&(s=e(s),s&&(s=s.selection())),t==null?i.remove():t(i),n&&s?n.merge(s).order():s}function E0(r){for(var e=r.selection?r.selection():r,t=this._groups,n=e._groups,s=t.length,i=n.length,o=Math.min(s,i),a=new Array(s),l=0;l<o;++l)for(var u=t[l],c=n[l],d=u.length,h=a[l]=new Array(d),p,g=0;g<d;++g)(p=u[g]||c[g])&&(h[g]=p);for(;l<s;++l)a[l]=t[l];return new Tt(a,this._parents)}function D0(){for(var r=this._groups,e=-1,t=r.length;++e<t;)for(var n=r[e],s=n.length-1,i=n[s],o;--s>=0;)(o=n[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function A0(r){r||(r=T0);function e(d,h){return d&&h?r(d.__data__,h.__data__):!d-!h}for(var t=this._groups,n=t.length,s=new Array(n),i=0;i<n;++i){for(var o=t[i],a=o.length,l=s[i]=new Array(a),u,c=0;c<a;++c)(u=o[c])&&(l[c]=u);l.sort(e)}return new Tt(s,this._parents).order()}function T0(r,e){return r<e?-1:r>e?1:r>=e?0:NaN}function N0(){var r=arguments[0];return arguments[0]=this,r.apply(null,arguments),this}function B0(){return Array.from(this)}function j0(){for(var r=this._groups,e=0,t=r.length;e<t;++e)for(var n=r[e],s=0,i=n.length;s<i;++s){var o=n[s];if(o)return o}return null}function M0(){let r=0;for(const e of this)++r;return r}function R0(){return!this.node()}function F0(r){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var s=e[t],i=0,o=s.length,a;i<o;++i)(a=s[i])&&r.call(a,a.__data__,i,s);return this}function L0(r){return function(){this.removeAttribute(r)}}function P0(r){return function(){this.removeAttributeNS(r.space,r.local)}}function I0(r,e){return function(){this.setAttribute(r,e)}}function z0(r,e){return function(){this.setAttributeNS(r.space,r.local,e)}}function O0(r,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttribute(r):this.setAttribute(r,t)}}function $0(r,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttributeNS(r.space,r.local):this.setAttributeNS(r.space,r.local,t)}}function q0(r,e){var t=_i(r);if(arguments.length<2){var n=this.node();return t.local?n.getAttributeNS(t.space,t.local):n.getAttribute(t)}return this.each((e==null?t.local?P0:L0:typeof e=="function"?t.local?$0:O0:t.local?z0:I0)(t,e))}function id(r){return r.ownerDocument&&r.ownerDocument.defaultView||r.document&&r||r.defaultView}function U0(r){return function(){this.style.removeProperty(r)}}function W0(r,e,t){return function(){this.style.setProperty(r,e,t)}}function H0(r,e,t){return function(){var n=e.apply(this,arguments);n==null?this.style.removeProperty(r):this.style.setProperty(r,n,t)}}function V0(r,e,t){return arguments.length>1?this.each((e==null?U0:typeof e=="function"?H0:W0)(r,e,t??"")):rn(this.node(),r)}function rn(r,e){return r.style.getPropertyValue(e)||id(r).getComputedStyle(r,null).getPropertyValue(e)}function G0(r){return function(){delete this[r]}}function K0(r,e){return function(){this[r]=e}}function Y0(r,e){return function(){var t=e.apply(this,arguments);t==null?delete this[r]:this[r]=t}}function Q0(r,e){return arguments.length>1?this.each((e==null?G0:typeof e=="function"?Y0:K0)(r,e)):this.node()[r]}function od(r){return r.trim().split(/^|\s+/)}function ca(r){return r.classList||new ad(r)}function ad(r){this._node=r,this._names=od(r.getAttribute("class")||"")}ad.prototype={add:function(r){var e=this._names.indexOf(r);e<0&&(this._names.push(r),this._node.setAttribute("class",this._names.join(" ")))},remove:function(r){var e=this._names.indexOf(r);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(r){return this._names.indexOf(r)>=0}};function ld(r,e){for(var t=ca(r),n=-1,s=e.length;++n<s;)t.add(e[n])}function ud(r,e){for(var t=ca(r),n=-1,s=e.length;++n<s;)t.remove(e[n])}function J0(r){return function(){ld(this,r)}}function X0(r){return function(){ud(this,r)}}function Z0(r,e){return function(){(e.apply(this,arguments)?ld:ud)(this,r)}}function em(r,e){var t=od(r+"");if(arguments.length<2){for(var n=ca(this.node()),s=-1,i=t.length;++s<i;)if(!n.contains(t[s]))return!1;return!0}return this.each((typeof e=="function"?Z0:e?J0:X0)(t,e))}function tm(){this.textContent=""}function rm(r){return function(){this.textContent=r}}function nm(r){return function(){var e=r.apply(this,arguments);this.textContent=e??""}}function sm(r){return arguments.length?this.each(r==null?tm:(typeof r=="function"?nm:rm)(r)):this.node().textContent}function im(){this.innerHTML=""}function om(r){return function(){this.innerHTML=r}}function am(r){return function(){var e=r.apply(this,arguments);this.innerHTML=e??""}}function lm(r){return arguments.length?this.each(r==null?im:(typeof r=="function"?am:om)(r)):this.node().innerHTML}function um(){this.nextSibling&&this.parentNode.appendChild(this)}function cm(){return this.each(um)}function dm(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function fm(){return this.each(dm)}function hm(r){var e=typeof r=="function"?r:ed(r);return this.select(function(){return this.appendChild(e.apply(this,arguments))})}function pm(){return null}function gm(r,e){var t=typeof r=="function"?r:ed(r),n=e==null?pm:typeof e=="function"?e:ua(e);return this.select(function(){return this.insertBefore(t.apply(this,arguments),n.apply(this,arguments)||null)})}function mm(){var r=this.parentNode;r&&r.removeChild(this)}function ym(){return this.each(mm)}function xm(){var r=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(r,this.nextSibling):r}function bm(){var r=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(r,this.nextSibling):r}function vm(r){return this.select(r?bm:xm)}function _m(r){return arguments.length?this.property("__data__",r):this.node().__data__}function wm(r){return function(e){r.call(this,e,this.__data__)}}function Cm(r){return r.trim().split(/^|\s+/).map(function(e){var t="",n=e.indexOf(".");return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function Sm(r){return function(){var e=this.__on;if(e){for(var t=0,n=-1,s=e.length,i;t<s;++t)i=e[t],(!r.type||i.type===r.type)&&i.name===r.name?this.removeEventListener(i.type,i.listener,i.options):e[++n]=i;++n?e.length=n:delete this.__on}}}function km(r,e,t){return function(){var n=this.__on,s,i=wm(e);if(n){for(var o=0,a=n.length;o<a;++o)if((s=n[o]).type===r.type&&s.name===r.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=i,s.options=t),s.value=e;return}}this.addEventListener(r.type,i,t),s={type:r.type,name:r.name,value:e,listener:i,options:t},n?n.push(s):this.__on=[s]}}function Em(r,e,t){var n=Cm(r+""),s,i=n.length,o;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,u=a.length,c;l<u;++l)for(s=0,c=a[l];s<i;++s)if((o=n[s]).type===c.type&&o.name===c.name)return c.value}return}for(a=e?km:Sm,s=0;s<i;++s)this.each(a(n[s],e,t));return this}function cd(r,e,t){var n=id(r),s=n.CustomEvent;typeof s=="function"?s=new s(e,t):(s=n.document.createEvent("Event"),t?(s.initEvent(e,t.bubbles,t.cancelable),s.detail=t.detail):s.initEvent(e,!1,!1)),r.dispatchEvent(s)}function Dm(r,e){return function(){return cd(this,r,e)}}function Am(r,e){return function(){return cd(this,r,e.apply(this,arguments))}}function Tm(r,e){return this.each((typeof e=="function"?Am:Dm)(r,e))}function*Nm(){for(var r=this._groups,e=0,t=r.length;e<t;++e)for(var n=r[e],s=0,i=n.length,o;s<i;++s)(o=n[s])&&(yield o)}var dd=[null];function Tt(r,e){this._groups=r,this._parents=e}function ss(){return new Tt([[document.documentElement]],dd)}function Bm(){return this}Tt.prototype=ss.prototype={constructor:Tt,select:n0,selectAll:a0,selectChild:d0,selectChildren:g0,filter:m0,data:w0,enter:y0,exit:S0,join:k0,merge:E0,selection:Bm,order:D0,sort:A0,call:N0,nodes:B0,node:j0,size:M0,empty:R0,each:F0,attr:q0,style:V0,property:Q0,classed:em,text:sm,html:lm,raise:cm,lower:fm,append:hm,insert:gm,remove:ym,clone:vm,datum:_m,on:Em,dispatch:Tm,[Symbol.iterator]:Nm};function Ft(r){return typeof r=="string"?new Tt([[document.querySelector(r)]],[document.documentElement]):new Tt([[r]],dd)}function jm(r){let e;for(;e=r.sourceEvent;)r=e;return r}function wr(r,e){if(r=jm(r),e===void 0&&(e=r.currentTarget),e){var t=e.ownerSVGElement||e;if(t.createSVGPoint){var n=t.createSVGPoint();return n.x=r.clientX,n.y=r.clientY,n=n.matrixTransform(e.getScreenCTM().inverse()),[n.x,n.y]}if(e.getBoundingClientRect){var s=e.getBoundingClientRect();return[r.clientX-s.left-e.clientLeft,r.clientY-s.top-e.clientTop]}}return[r.pageX,r.pageY]}const vo={capture:!0,passive:!1};function _o(r){r.preventDefault(),r.stopImmediatePropagation()}function Mm(r){var e=r.document.documentElement,t=Ft(r).on("dragstart.drag",_o,vo);"onselectstart"in e?t.on("selectstart.drag",_o,vo):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Rm(r,e){var t=r.document.documentElement,n=Ft(r).on("dragstart.drag",null);e&&(n.on("click.drag",_o,vo),setTimeout(function(){n.on("click.drag",null)},0)),"onselectstart"in t?n.on("selectstart.drag",null):(t.style.MozUserSelect=t.__noselect,delete t.__noselect)}function da(r,e,t){r.prototype=e.prototype=t,t.constructor=r}function fd(r,e){var t=Object.create(r.prototype);for(var n in e)t[n]=e[n];return t}function is(){}var $n=.7,Js=1/$n,Jr="\\s*([+-]?\\d+)\\s*",qn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Vt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Fm=/^#([0-9a-f]{3,8})$/,Lm=new RegExp(`^rgb\\(${Jr},${Jr},${Jr}\\)$`),Pm=new RegExp(`^rgb\\(${Vt},${Vt},${Vt}\\)$`),Im=new RegExp(`^rgba\\(${Jr},${Jr},${Jr},${qn}\\)$`),zm=new RegExp(`^rgba\\(${Vt},${Vt},${Vt},${qn}\\)$`),Om=new RegExp(`^hsl\\(${qn},${Vt},${Vt}\\)$`),$m=new RegExp(`^hsla\\(${qn},${Vt},${Vt},${qn}\\)$`),$l={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};da(is,Un,{copy(r){return Object.assign(new this.constructor,this,r)},displayable(){return this.rgb().displayable()},hex:ql,formatHex:ql,formatHex8:qm,formatHsl:Um,formatRgb:Ul,toString:Ul});function ql(){return this.rgb().formatHex()}function qm(){return this.rgb().formatHex8()}function Um(){return hd(this).formatHsl()}function Ul(){return this.rgb().formatRgb()}function Un(r){var e,t;return r=(r+"").trim().toLowerCase(),(e=Fm.exec(r))?(t=e[1].length,e=parseInt(e[1],16),t===6?Wl(e):t===3?new Ct(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?ms(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?ms(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=Lm.exec(r))?new Ct(e[1],e[2],e[3],1):(e=Pm.exec(r))?new Ct(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=Im.exec(r))?ms(e[1],e[2],e[3],e[4]):(e=zm.exec(r))?ms(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=Om.exec(r))?Gl(e[1],e[2]/100,e[3]/100,1):(e=$m.exec(r))?Gl(e[1],e[2]/100,e[3]/100,e[4]):$l.hasOwnProperty(r)?Wl($l[r]):r==="transparent"?new Ct(NaN,NaN,NaN,0):null}function Wl(r){return new Ct(r>>16&255,r>>8&255,r&255,1)}function ms(r,e,t,n){return n<=0&&(r=e=t=NaN),new Ct(r,e,t,n)}function Wm(r){return r instanceof is||(r=Un(r)),r?(r=r.rgb(),new Ct(r.r,r.g,r.b,r.opacity)):new Ct}function wo(r,e,t,n){return arguments.length===1?Wm(r):new Ct(r,e,t,n??1)}function Ct(r,e,t,n){this.r=+r,this.g=+e,this.b=+t,this.opacity=+n}da(Ct,wo,fd(is,{brighter(r){return r=r==null?Js:Math.pow(Js,r),new Ct(this.r*r,this.g*r,this.b*r,this.opacity)},darker(r){return r=r==null?$n:Math.pow($n,r),new Ct(this.r*r,this.g*r,this.b*r,this.opacity)},rgb(){return this},clamp(){return new Ct(Tr(this.r),Tr(this.g),Tr(this.b),Xs(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Hl,formatHex:Hl,formatHex8:Hm,formatRgb:Vl,toString:Vl}));function Hl(){return`#${Sr(this.r)}${Sr(this.g)}${Sr(this.b)}`}function Hm(){return`#${Sr(this.r)}${Sr(this.g)}${Sr(this.b)}${Sr((isNaN(this.opacity)?1:this.opacity)*255)}`}function Vl(){const r=Xs(this.opacity);return`${r===1?"rgb(":"rgba("}${Tr(this.r)}, ${Tr(this.g)}, ${Tr(this.b)}${r===1?")":`, ${r})`}`}function Xs(r){return isNaN(r)?1:Math.max(0,Math.min(1,r))}function Tr(r){return Math.max(0,Math.min(255,Math.round(r)||0))}function Sr(r){return r=Tr(r),(r<16?"0":"")+r.toString(16)}function Gl(r,e,t,n){return n<=0?r=e=t=NaN:t<=0||t>=1?r=e=NaN:e<=0&&(r=NaN),new Lt(r,e,t,n)}function hd(r){if(r instanceof Lt)return new Lt(r.h,r.s,r.l,r.opacity);if(r instanceof is||(r=Un(r)),!r)return new Lt;if(r instanceof Lt)return r;r=r.rgb();var e=r.r/255,t=r.g/255,n=r.b/255,s=Math.min(e,t,n),i=Math.max(e,t,n),o=NaN,a=i-s,l=(i+s)/2;return a?(e===i?o=(t-n)/a+(t<n)*6:t===i?o=(n-e)/a+2:o=(e-t)/a+4,a/=l<.5?i+s:2-i-s,o*=60):a=l>0&&l<1?0:o,new Lt(o,a,l,r.opacity)}function Vm(r,e,t,n){return arguments.length===1?hd(r):new Lt(r,e,t,n??1)}function Lt(r,e,t,n){this.h=+r,this.s=+e,this.l=+t,this.opacity=+n}da(Lt,Vm,fd(is,{brighter(r){return r=r==null?Js:Math.pow(Js,r),new Lt(this.h,this.s,this.l*r,this.opacity)},darker(r){return r=r==null?$n:Math.pow($n,r),new Lt(this.h,this.s,this.l*r,this.opacity)},rgb(){var r=this.h%360+(this.h<0)*360,e=isNaN(r)||isNaN(this.s)?0:this.s,t=this.l,n=t+(t<.5?t:1-t)*e,s=2*t-n;return new Ct(qi(r>=240?r-240:r+120,s,n),qi(r,s,n),qi(r<120?r+240:r-120,s,n),this.opacity)},clamp(){return new Lt(Kl(this.h),ys(this.s),ys(this.l),Xs(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const r=Xs(this.opacity);return`${r===1?"hsl(":"hsla("}${Kl(this.h)}, ${ys(this.s)*100}%, ${ys(this.l)*100}%${r===1?")":`, ${r})`}`}}));function Kl(r){return r=(r||0)%360,r<0?r+360:r}function ys(r){return Math.max(0,Math.min(1,r||0))}function qi(r,e,t){return(r<60?e+(t-e)*r/60:r<180?t:r<240?e+(t-e)*(240-r)/60:e)*255}const pd=r=>()=>r;function Gm(r,e){return function(t){return r+t*e}}function Km(r,e,t){return r=Math.pow(r,t),e=Math.pow(e,t)-r,t=1/t,function(n){return Math.pow(r+n*e,t)}}function Ym(r){return(r=+r)==1?gd:function(e,t){return t-e?Km(e,t,r):pd(isNaN(e)?t:e)}}function gd(r,e){var t=e-r;return t?Gm(r,t):pd(isNaN(r)?e:r)}const Yl=function r(e){var t=Ym(e);function n(s,i){var o=t((s=wo(s)).r,(i=wo(i)).r),a=t(s.g,i.g),l=t(s.b,i.b),u=gd(s.opacity,i.opacity);return function(c){return s.r=o(c),s.g=a(c),s.b=l(c),s.opacity=u(c),s+""}}return n.gamma=r,n}(1);function dr(r,e){return r=+r,e=+e,function(t){return r*(1-t)+e*t}}var Co=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Ui=new RegExp(Co.source,"g");function Qm(r){return function(){return r}}function Jm(r){return function(e){return r(e)+""}}function Xm(r,e){var t=Co.lastIndex=Ui.lastIndex=0,n,s,i,o=-1,a=[],l=[];for(r=r+"",e=e+"";(n=Co.exec(r))&&(s=Ui.exec(e));)(i=s.index)>t&&(i=e.slice(t,i),a[o]?a[o]+=i:a[++o]=i),(n=n[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,l.push({i:o,x:dr(n,s)})),t=Ui.lastIndex;return t<e.length&&(i=e.slice(t),a[o]?a[o]+=i:a[++o]=i),a.length<2?l[0]?Jm(l[0].x):Qm(e):(e=l.length,function(u){for(var c=0,d;c<e;++c)a[(d=l[c]).i]=d.x(u);return a.join("")})}var Ql=180/Math.PI,So={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function md(r,e,t,n,s,i){var o,a,l;return(o=Math.sqrt(r*r+e*e))&&(r/=o,e/=o),(l=r*t+e*n)&&(t-=r*l,n-=e*l),(a=Math.sqrt(t*t+n*n))&&(t/=a,n/=a,l/=a),r*n<e*t&&(r=-r,e=-e,l=-l,o=-o),{translateX:s,translateY:i,rotate:Math.atan2(e,r)*Ql,skewX:Math.atan(l)*Ql,scaleX:o,scaleY:a}}var xs;function Zm(r){const e=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(r+"");return e.isIdentity?So:md(e.a,e.b,e.c,e.d,e.e,e.f)}function ey(r){return r==null||(xs||(xs=document.createElementNS("http://www.w3.org/2000/svg","g")),xs.setAttribute("transform",r),!(r=xs.transform.baseVal.consolidate()))?So:(r=r.matrix,md(r.a,r.b,r.c,r.d,r.e,r.f))}function yd(r,e,t,n){function s(u){return u.length?u.pop()+" ":""}function i(u,c,d,h,p,g){if(u!==d||c!==h){var m=p.push("translate(",null,e,null,t);g.push({i:m-4,x:dr(u,d)},{i:m-2,x:dr(c,h)})}else(d||h)&&p.push("translate("+d+e+h+t)}function o(u,c,d,h){u!==c?(u-c>180?c+=360:c-u>180&&(u+=360),h.push({i:d.push(s(d)+"rotate(",null,n)-2,x:dr(u,c)})):c&&d.push(s(d)+"rotate("+c+n)}function a(u,c,d,h){u!==c?h.push({i:d.push(s(d)+"skewX(",null,n)-2,x:dr(u,c)}):c&&d.push(s(d)+"skewX("+c+n)}function l(u,c,d,h,p,g){if(u!==d||c!==h){var m=p.push(s(p)+"scale(",null,",",null,")");g.push({i:m-4,x:dr(u,d)},{i:m-2,x:dr(c,h)})}else(d!==1||h!==1)&&p.push(s(p)+"scale("+d+","+h+")")}return function(u,c){var d=[],h=[];return u=r(u),c=r(c),i(u.translateX,u.translateY,c.translateX,c.translateY,d,h),o(u.rotate,c.rotate,d,h),a(u.skewX,c.skewX,d,h),l(u.scaleX,u.scaleY,c.scaleX,c.scaleY,d,h),u=c=null,function(p){for(var g=-1,m=h.length,x;++g<m;)d[(x=h[g]).i]=x.x(p);return d.join("")}}}var ty=yd(Zm,"px, ","px)","deg)"),ry=yd(ey,", ",")",")"),ny=1e-12;function Jl(r){return((r=Math.exp(r))+1/r)/2}function sy(r){return((r=Math.exp(r))-1/r)/2}function iy(r){return((r=Math.exp(2*r))-1)/(r+1)}const oy=function r(e,t,n){function s(i,o){var a=i[0],l=i[1],u=i[2],c=o[0],d=o[1],h=o[2],p=c-a,g=d-l,m=p*p+g*g,x,_;if(m<ny)_=Math.log(h/u)/e,x=function(v){return[a+v*p,l+v*g,u*Math.exp(e*v*_)]};else{var b=Math.sqrt(m),S=(h*h-u*u+n*m)/(2*u*t*b),C=(h*h-u*u-n*m)/(2*h*t*b),k=Math.log(Math.sqrt(S*S+1)-S),E=Math.log(Math.sqrt(C*C+1)-C);_=(E-k)/e,x=function(v){var T=v*_,B=Jl(k),j=u/(t*b)*(B*iy(e*T+k)-sy(k));return[a+j*p,l+j*g,u*B/Jl(e*T+k)]}}return x.duration=_*1e3*e/Math.SQRT2,x}return s.rho=function(i){var o=Math.max(.001,+i),a=o*o,l=a*a;return r(o,a,l)},s}(Math.SQRT2,2,4);var nn=0,Cn=0,yn=0,xd=1e3,Zs,Sn,ei=0,Lr=0,wi=0,Wn=typeof performance=="object"&&performance.now?performance:Date,bd=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(r){setTimeout(r,17)};function fa(){return Lr||(bd(ay),Lr=Wn.now()+wi)}function ay(){Lr=0}function ti(){this._call=this._time=this._next=null}ti.prototype=vd.prototype={constructor:ti,restart:function(r,e,t){if(typeof r!="function")throw new TypeError("callback is not a function");t=(t==null?fa():+t)+(e==null?0:+e),!this._next&&Sn!==this&&(Sn?Sn._next=this:Zs=this,Sn=this),this._call=r,this._time=t,ko()},stop:function(){this._call&&(this._call=null,this._time=1/0,ko())}};function vd(r,e,t){var n=new ti;return n.restart(r,e,t),n}function ly(){fa(),++nn;for(var r=Zs,e;r;)(e=Lr-r._time)>=0&&r._call.call(void 0,e),r=r._next;--nn}function Xl(){Lr=(ei=Wn.now())+wi,nn=Cn=0;try{ly()}finally{nn=0,cy(),Lr=0}}function uy(){var r=Wn.now(),e=r-ei;e>xd&&(wi-=e,ei=r)}function cy(){for(var r,e=Zs,t,n=1/0;e;)e._call?(n>e._time&&(n=e._time),r=e,e=e._next):(t=e._next,e._next=null,e=r?r._next=t:Zs=t);Sn=r,ko(n)}function ko(r){if(!nn){Cn&&(Cn=clearTimeout(Cn));var e=r-Lr;e>24?(r<1/0&&(Cn=setTimeout(Xl,r-Wn.now()-wi)),yn&&(yn=clearInterval(yn))):(yn||(ei=Wn.now(),yn=setInterval(uy,xd)),nn=1,bd(Xl))}}function Zl(r,e,t){var n=new ti;return e=e==null?0:+e,n.restart(s=>{n.stop(),r(s+e)},e,t),n}var dy=la("start","end","cancel","interrupt"),fy=[],_d=0,eu=1,Eo=2,Ss=3,tu=4,Do=5,ks=6;function Ci(r,e,t,n,s,i){var o=r.__transition;if(!o)r.__transition={};else if(t in o)return;hy(r,t,{name:e,index:n,group:s,on:dy,tween:fy,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:_d})}function ha(r,e){var t=$t(r,e);if(t.state>_d)throw new Error("too late; already scheduled");return t}function Jt(r,e){var t=$t(r,e);if(t.state>Ss)throw new Error("too late; already running");return t}function $t(r,e){var t=r.__transition;if(!t||!(t=t[e]))throw new Error("transition not found");return t}function hy(r,e,t){var n=r.__transition,s;n[e]=t,t.timer=vd(i,0,t.time);function i(u){t.state=eu,t.timer.restart(o,t.delay,t.time),t.delay<=u&&o(u-t.delay)}function o(u){var c,d,h,p;if(t.state!==eu)return l();for(c in n)if(p=n[c],p.name===t.name){if(p.state===Ss)return Zl(o);p.state===tu?(p.state=ks,p.timer.stop(),p.on.call("interrupt",r,r.__data__,p.index,p.group),delete n[c]):+c<e&&(p.state=ks,p.timer.stop(),p.on.call("cancel",r,r.__data__,p.index,p.group),delete n[c])}if(Zl(function(){t.state===Ss&&(t.state=tu,t.timer.restart(a,t.delay,t.time),a(u))}),t.state=Eo,t.on.call("start",r,r.__data__,t.index,t.group),t.state===Eo){for(t.state=Ss,s=new Array(h=t.tween.length),c=0,d=-1;c<h;++c)(p=t.tween[c].value.call(r,r.__data__,t.index,t.group))&&(s[++d]=p);s.length=d+1}}function a(u){for(var c=u<t.duration?t.ease.call(null,u/t.duration):(t.timer.restart(l),t.state=Do,1),d=-1,h=s.length;++d<h;)s[d].call(r,c);t.state===Do&&(t.on.call("end",r,r.__data__,t.index,t.group),l())}function l(){t.state=ks,t.timer.stop(),delete n[e];for(var u in n)return;delete r.__transition}}function Es(r,e){var t=r.__transition,n,s,i=!0,o;if(t){e=e==null?null:e+"";for(o in t){if((n=t[o]).name!==e){i=!1;continue}s=n.state>Eo&&n.state<Do,n.state=ks,n.timer.stop(),n.on.call(s?"interrupt":"cancel",r,r.__data__,n.index,n.group),delete t[o]}i&&delete r.__transition}}function py(r){return this.each(function(){Es(this,r)})}function gy(r,e){var t,n;return function(){var s=Jt(this,r),i=s.tween;if(i!==t){n=t=i;for(var o=0,a=n.length;o<a;++o)if(n[o].name===e){n=n.slice(),n.splice(o,1);break}}s.tween=n}}function my(r,e,t){var n,s;if(typeof t!="function")throw new Error;return function(){var i=Jt(this,r),o=i.tween;if(o!==n){s=(n=o).slice();for(var a={name:e,value:t},l=0,u=s.length;l<u;++l)if(s[l].name===e){s[l]=a;break}l===u&&s.push(a)}i.tween=s}}function yy(r,e){var t=this._id;if(r+="",arguments.length<2){for(var n=$t(this.node(),t).tween,s=0,i=n.length,o;s<i;++s)if((o=n[s]).name===r)return o.value;return null}return this.each((e==null?gy:my)(t,r,e))}function pa(r,e,t){var n=r._id;return r.each(function(){var s=Jt(this,n);(s.value||(s.value={}))[e]=t.apply(this,arguments)}),function(s){return $t(s,n).value[e]}}function wd(r,e){var t;return(typeof e=="number"?dr:e instanceof Un?Yl:(t=Un(e))?(e=t,Yl):Xm)(r,e)}function xy(r){return function(){this.removeAttribute(r)}}function by(r){return function(){this.removeAttributeNS(r.space,r.local)}}function vy(r,e,t){var n,s=t+"",i;return function(){var o=this.getAttribute(r);return o===s?null:o===n?i:i=e(n=o,t)}}function _y(r,e,t){var n,s=t+"",i;return function(){var o=this.getAttributeNS(r.space,r.local);return o===s?null:o===n?i:i=e(n=o,t)}}function wy(r,e,t){var n,s,i;return function(){var o,a=t(this),l;return a==null?void this.removeAttribute(r):(o=this.getAttribute(r),l=a+"",o===l?null:o===n&&l===s?i:(s=l,i=e(n=o,a)))}}function Cy(r,e,t){var n,s,i;return function(){var o,a=t(this),l;return a==null?void this.removeAttributeNS(r.space,r.local):(o=this.getAttributeNS(r.space,r.local),l=a+"",o===l?null:o===n&&l===s?i:(s=l,i=e(n=o,a)))}}function Sy(r,e){var t=_i(r),n=t==="transform"?ry:wd;return this.attrTween(r,typeof e=="function"?(t.local?Cy:wy)(t,n,pa(this,"attr."+r,e)):e==null?(t.local?by:xy)(t):(t.local?_y:vy)(t,n,e))}function ky(r,e){return function(t){this.setAttribute(r,e.call(this,t))}}function Ey(r,e){return function(t){this.setAttributeNS(r.space,r.local,e.call(this,t))}}function Dy(r,e){var t,n;function s(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&Ey(r,i)),t}return s._value=e,s}function Ay(r,e){var t,n;function s(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&ky(r,i)),t}return s._value=e,s}function Ty(r,e){var t="attr."+r;if(arguments.length<2)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;var n=_i(r);return this.tween(t,(n.local?Dy:Ay)(n,e))}function Ny(r,e){return function(){ha(this,r).delay=+e.apply(this,arguments)}}function By(r,e){return e=+e,function(){ha(this,r).delay=e}}function jy(r){var e=this._id;return arguments.length?this.each((typeof r=="function"?Ny:By)(e,r)):$t(this.node(),e).delay}function My(r,e){return function(){Jt(this,r).duration=+e.apply(this,arguments)}}function Ry(r,e){return e=+e,function(){Jt(this,r).duration=e}}function Fy(r){var e=this._id;return arguments.length?this.each((typeof r=="function"?My:Ry)(e,r)):$t(this.node(),e).duration}function Ly(r,e){if(typeof e!="function")throw new Error;return function(){Jt(this,r).ease=e}}function Py(r){var e=this._id;return arguments.length?this.each(Ly(e,r)):$t(this.node(),e).ease}function Iy(r,e){return function(){var t=e.apply(this,arguments);if(typeof t!="function")throw new Error;Jt(this,r).ease=t}}function zy(r){if(typeof r!="function")throw new Error;return this.each(Iy(this._id,r))}function Oy(r){typeof r!="function"&&(r=rd(r));for(var e=this._groups,t=e.length,n=new Array(t),s=0;s<t;++s)for(var i=e[s],o=i.length,a=n[s]=[],l,u=0;u<o;++u)(l=i[u])&&r.call(l,l.__data__,u,i)&&a.push(l);return new sr(n,this._parents,this._name,this._id)}function $y(r){if(r._id!==this._id)throw new Error;for(var e=this._groups,t=r._groups,n=e.length,s=t.length,i=Math.min(n,s),o=new Array(n),a=0;a<i;++a)for(var l=e[a],u=t[a],c=l.length,d=o[a]=new Array(c),h,p=0;p<c;++p)(h=l[p]||u[p])&&(d[p]=h);for(;a<n;++a)o[a]=e[a];return new sr(o,this._parents,this._name,this._id)}function qy(r){return(r+"").trim().split(/^|\s+/).every(function(e){var t=e.indexOf(".");return t>=0&&(e=e.slice(0,t)),!e||e==="start"})}function Uy(r,e,t){var n,s,i=qy(e)?ha:Jt;return function(){var o=i(this,r),a=o.on;a!==n&&(s=(n=a).copy()).on(e,t),o.on=s}}function Wy(r,e){var t=this._id;return arguments.length<2?$t(this.node(),t).on.on(r):this.each(Uy(t,r,e))}function Hy(r){return function(){var e=this.parentNode;for(var t in this.__transition)if(+t!==r)return;e&&e.removeChild(this)}}function Vy(){return this.on("end.remove",Hy(this._id))}function Gy(r){var e=this._name,t=this._id;typeof r!="function"&&(r=ua(r));for(var n=this._groups,s=n.length,i=new Array(s),o=0;o<s;++o)for(var a=n[o],l=a.length,u=i[o]=new Array(l),c,d,h=0;h<l;++h)(c=a[h])&&(d=r.call(c,c.__data__,h,a))&&("__data__"in c&&(d.__data__=c.__data__),u[h]=d,Ci(u[h],e,t,h,u,$t(c,t)));return new sr(i,this._parents,e,t)}function Ky(r){var e=this._name,t=this._id;typeof r!="function"&&(r=td(r));for(var n=this._groups,s=n.length,i=[],o=[],a=0;a<s;++a)for(var l=n[a],u=l.length,c,d=0;d<u;++d)if(c=l[d]){for(var h=r.call(c,c.__data__,d,l),p,g=$t(c,t),m=0,x=h.length;m<x;++m)(p=h[m])&&Ci(p,e,t,m,h,g);i.push(h),o.push(c)}return new sr(i,o,e,t)}var Yy=ss.prototype.constructor;function Qy(){return new Yy(this._groups,this._parents)}function Jy(r,e){var t,n,s;return function(){var i=rn(this,r),o=(this.style.removeProperty(r),rn(this,r));return i===o?null:i===t&&o===n?s:s=e(t=i,n=o)}}function Cd(r){return function(){this.style.removeProperty(r)}}function Xy(r,e,t){var n,s=t+"",i;return function(){var o=rn(this,r);return o===s?null:o===n?i:i=e(n=o,t)}}function Zy(r,e,t){var n,s,i;return function(){var o=rn(this,r),a=t(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(r),rn(this,r))),o===l?null:o===n&&l===s?i:(s=l,i=e(n=o,a))}}function e2(r,e){var t,n,s,i="style."+e,o="end."+i,a;return function(){var l=Jt(this,r),u=l.on,c=l.value[i]==null?a||(a=Cd(e)):void 0;(u!==t||s!==c)&&(n=(t=u).copy()).on(o,s=c),l.on=n}}function t2(r,e,t){var n=(r+="")=="transform"?ty:wd;return e==null?this.styleTween(r,Jy(r,n)).on("end.style."+r,Cd(r)):typeof e=="function"?this.styleTween(r,Zy(r,n,pa(this,"style."+r,e))).each(e2(this._id,r)):this.styleTween(r,Xy(r,n,e),t).on("end.style."+r,null)}function r2(r,e,t){return function(n){this.style.setProperty(r,e.call(this,n),t)}}function n2(r,e,t){var n,s;function i(){var o=e.apply(this,arguments);return o!==s&&(n=(s=o)&&r2(r,o,t)),n}return i._value=e,i}function s2(r,e,t){var n="style."+(r+="");if(arguments.length<2)return(n=this.tween(n))&&n._value;if(e==null)return this.tween(n,null);if(typeof e!="function")throw new Error;return this.tween(n,n2(r,e,t??""))}function i2(r){return function(){this.textContent=r}}function o2(r){return function(){var e=r(this);this.textContent=e??""}}function a2(r){return this.tween("text",typeof r=="function"?o2(pa(this,"text",r)):i2(r==null?"":r+""))}function l2(r){return function(e){this.textContent=r.call(this,e)}}function u2(r){var e,t;function n(){var s=r.apply(this,arguments);return s!==t&&(e=(t=s)&&l2(s)),e}return n._value=r,n}function c2(r){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(r==null)return this.tween(e,null);if(typeof r!="function")throw new Error;return this.tween(e,u2(r))}function d2(){for(var r=this._name,e=this._id,t=Sd(),n=this._groups,s=n.length,i=0;i<s;++i)for(var o=n[i],a=o.length,l,u=0;u<a;++u)if(l=o[u]){var c=$t(l,e);Ci(l,r,t,u,o,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new sr(n,this._parents,r,t)}function f2(){var r,e,t=this,n=t._id,s=t.size();return new Promise(function(i,o){var a={value:o},l={value:function(){--s===0&&i()}};t.each(function(){var u=Jt(this,n),c=u.on;c!==r&&(e=(r=c).copy(),e._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),u.on=e}),s===0&&i()})}var h2=0;function sr(r,e,t,n){this._groups=r,this._parents=e,this._name=t,this._id=n}function Sd(){return++h2}var er=ss.prototype;sr.prototype={constructor:sr,select:Gy,selectAll:Ky,selectChild:er.selectChild,selectChildren:er.selectChildren,filter:Oy,merge:$y,selection:Qy,transition:d2,call:er.call,nodes:er.nodes,node:er.node,size:er.size,empty:er.empty,each:er.each,on:Wy,attr:Sy,attrTween:Ty,style:t2,styleTween:s2,text:a2,textTween:c2,remove:Vy,tween:yy,delay:jy,duration:Fy,ease:Py,easeVarying:zy,end:f2,[Symbol.iterator]:er[Symbol.iterator]};function p2(r){return((r*=2)<=1?r*r*r:(r-=2)*r*r+2)/2}var g2={time:null,delay:0,duration:250,ease:p2};function m2(r,e){for(var t;!(t=r.__transition)||!(t=t[e]);)if(!(r=r.parentNode))throw new Error(`transition ${e} not found`);return t}function y2(r){var e,t;r instanceof sr?(e=r._id,r=r._name):(e=Sd(),(t=g2).time=fa(),r=r==null?null:r+"");for(var n=this._groups,s=n.length,i=0;i<s;++i)for(var o=n[i],a=o.length,l,u=0;u<a;++u)(l=o[u])&&Ci(l,r,e,u,o,t||m2(l,e));return new sr(n,this._parents,r,e)}ss.prototype.interrupt=py;ss.prototype.transition=y2;const bs=r=>()=>r;function x2(r,{sourceEvent:e,target:t,transform:n,dispatch:s}){Object.defineProperties(this,{type:{value:r,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:t,enumerable:!0,configurable:!0},transform:{value:n,enumerable:!0,configurable:!0},_:{value:s}})}function rr(r,e,t){this.k=r,this.x=e,this.y=t}rr.prototype={constructor:rr,scale:function(r){return r===1?this:new rr(this.k*r,this.x,this.y)},translate:function(r,e){return r===0&e===0?this:new rr(this.k,this.x+this.k*r,this.y+this.k*e)},apply:function(r){return[r[0]*this.k+this.x,r[1]*this.k+this.y]},applyX:function(r){return r*this.k+this.x},applyY:function(r){return r*this.k+this.y},invert:function(r){return[(r[0]-this.x)/this.k,(r[1]-this.y)/this.k]},invertX:function(r){return(r-this.x)/this.k},invertY:function(r){return(r-this.y)/this.k},rescaleX:function(r){return r.copy().domain(r.range().map(this.invertX,this).map(r.invert,r))},rescaleY:function(r){return r.copy().domain(r.range().map(this.invertY,this).map(r.invert,r))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ri=new rr(1,0,0);rr.prototype;function Wi(r){r.stopImmediatePropagation()}function xn(r){r.preventDefault(),r.stopImmediatePropagation()}function b2(r){return(!r.ctrlKey||r.type==="wheel")&&!r.button}function v2(){var r=this;return r instanceof SVGElement?(r=r.ownerSVGElement||r,r.hasAttribute("viewBox")?(r=r.viewBox.baseVal,[[r.x,r.y],[r.x+r.width,r.y+r.height]]):[[0,0],[r.width.baseVal.value,r.height.baseVal.value]]):[[0,0],[r.clientWidth,r.clientHeight]]}function ru(){return this.__zoom||ri}function _2(r){return-r.deltaY*(r.deltaMode===1?.05:r.deltaMode?1:.002)*(r.ctrlKey?10:1)}function w2(){return navigator.maxTouchPoints||"ontouchstart"in this}function C2(r,e,t){var n=r.invertX(e[0][0])-t[0][0],s=r.invertX(e[1][0])-t[1][0],i=r.invertY(e[0][1])-t[0][1],o=r.invertY(e[1][1])-t[1][1];return r.translate(s>n?(n+s)/2:Math.min(0,n)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function S2(){var r=b2,e=v2,t=C2,n=_2,s=w2,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,l=oy,u=la("start","zoom","end"),c,d,h,p=500,g=150,m=0,x=10;function _(w){w.property("__zoom",ru).on("wheel.zoom",T,{passive:!1}).on("mousedown.zoom",B).on("dblclick.zoom",j).filter(s).on("touchstart.zoom",N).on("touchmove.zoom",R).on("touchend.zoom touchcancel.zoom",M).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}_.transform=function(w,D,F,I){var q=w.selection?w.selection():w;q.property("__zoom",ru),w!==q?k(w,D,F,I):q.interrupt().each(function(){E(this,arguments).event(I).start().zoom(null,typeof D=="function"?D.apply(this,arguments):D).end()})},_.scaleBy=function(w,D,F,I){_.scaleTo(w,function(){var q=this.__zoom.k,Z=typeof D=="function"?D.apply(this,arguments):D;return q*Z},F,I)},_.scaleTo=function(w,D,F,I){_.transform(w,function(){var q=e.apply(this,arguments),Z=this.__zoom,te=F==null?C(q):typeof F=="function"?F.apply(this,arguments):F,W=Z.invert(te),Q=typeof D=="function"?D.apply(this,arguments):D;return t(S(b(Z,Q),te,W),q,o)},F,I)},_.translateBy=function(w,D,F,I){_.transform(w,function(){return t(this.__zoom.translate(typeof D=="function"?D.apply(this,arguments):D,typeof F=="function"?F.apply(this,arguments):F),e.apply(this,arguments),o)},null,I)},_.translateTo=function(w,D,F,I,q){_.transform(w,function(){var Z=e.apply(this,arguments),te=this.__zoom,W=I==null?C(Z):typeof I=="function"?I.apply(this,arguments):I;return t(ri.translate(W[0],W[1]).scale(te.k).translate(typeof D=="function"?-D.apply(this,arguments):-D,typeof F=="function"?-F.apply(this,arguments):-F),Z,o)},I,q)};function b(w,D){return D=Math.max(i[0],Math.min(i[1],D)),D===w.k?w:new rr(D,w.x,w.y)}function S(w,D,F){var I=D[0]-F[0]*w.k,q=D[1]-F[1]*w.k;return I===w.x&&q===w.y?w:new rr(w.k,I,q)}function C(w){return[(+w[0][0]+ +w[1][0])/2,(+w[0][1]+ +w[1][1])/2]}function k(w,D,F,I){w.on("start.zoom",function(){E(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){E(this,arguments).event(I).end()}).tween("zoom",function(){var q=this,Z=arguments,te=E(q,Z).event(I),W=e.apply(q,Z),Q=F==null?C(W):typeof F=="function"?F.apply(q,Z):F,H=Math.max(W[1][0]-W[0][0],W[1][1]-W[0][1]),ie=q.__zoom,ue=typeof D=="function"?D.apply(q,Z):D,de=l(ie.invert(Q).concat(H/ie.k),ue.invert(Q).concat(H/ue.k));return function(we){if(we===1)we=ue;else{var fe=de(we),Ce=H/fe[2];we=new rr(Ce,Q[0]-fe[0]*Ce,Q[1]-fe[1]*Ce)}te.zoom(null,we)}})}function E(w,D,F){return!F&&w.__zooming||new v(w,D)}function v(w,D){this.that=w,this.args=D,this.active=0,this.sourceEvent=null,this.extent=e.apply(w,D),this.taps=0}v.prototype={event:function(w){return w&&(this.sourceEvent=w),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(w,D){return this.mouse&&w!=="mouse"&&(this.mouse[1]=D.invert(this.mouse[0])),this.touch0&&w!=="touch"&&(this.touch0[1]=D.invert(this.touch0[0])),this.touch1&&w!=="touch"&&(this.touch1[1]=D.invert(this.touch1[0])),this.that.__zoom=D,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(w){var D=Ft(this.that).datum();u.call(w,this.that,new x2(w,{sourceEvent:this.sourceEvent,target:_,transform:this.that.__zoom,dispatch:u}),D)}};function T(w,...D){if(!r.apply(this,arguments))return;var F=E(this,D).event(w),I=this.__zoom,q=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,n.apply(this,arguments)))),Z=wr(w);if(F.wheel)(F.mouse[0][0]!==Z[0]||F.mouse[0][1]!==Z[1])&&(F.mouse[1]=I.invert(F.mouse[0]=Z)),clearTimeout(F.wheel);else{if(I.k===q)return;F.mouse=[Z,I.invert(Z)],Es(this),F.start()}xn(w),F.wheel=setTimeout(te,g),F.zoom("mouse",t(S(b(I,q),F.mouse[0],F.mouse[1]),F.extent,o));function te(){F.wheel=null,F.end()}}function B(w,...D){if(h||!r.apply(this,arguments))return;var F=w.currentTarget,I=E(this,D,!0).event(w),q=Ft(w.view).on("mousemove.zoom",Q,!0).on("mouseup.zoom",H,!0),Z=wr(w,F),te=w.clientX,W=w.clientY;Mm(w.view),Wi(w),I.mouse=[Z,this.__zoom.invert(Z)],Es(this),I.start();function Q(ie){if(xn(ie),!I.moved){var ue=ie.clientX-te,de=ie.clientY-W;I.moved=ue*ue+de*de>m}I.event(ie).zoom("mouse",t(S(I.that.__zoom,I.mouse[0]=wr(ie,F),I.mouse[1]),I.extent,o))}function H(ie){q.on("mousemove.zoom mouseup.zoom",null),Rm(ie.view,I.moved),xn(ie),I.event(ie).end()}}function j(w,...D){if(r.apply(this,arguments)){var F=this.__zoom,I=wr(w.changedTouches?w.changedTouches[0]:w,this),q=F.invert(I),Z=F.k*(w.shiftKey?.5:2),te=t(S(b(F,Z),I,q),e.apply(this,D),o);xn(w),a>0?Ft(this).transition().duration(a).call(k,te,I,w):Ft(this).call(_.transform,te,I,w)}}function N(w,...D){if(r.apply(this,arguments)){var F=w.touches,I=F.length,q=E(this,D,w.changedTouches.length===I).event(w),Z,te,W,Q;for(Wi(w),te=0;te<I;++te)W=F[te],Q=wr(W,this),Q=[Q,this.__zoom.invert(Q),W.identifier],q.touch0?!q.touch1&&q.touch0[2]!==Q[2]&&(q.touch1=Q,q.taps=0):(q.touch0=Q,Z=!0,q.taps=1+!!c);c&&(c=clearTimeout(c)),Z&&(q.taps<2&&(d=Q[0],c=setTimeout(function(){c=null},p)),Es(this),q.start())}}function R(w,...D){if(this.__zooming){var F=E(this,D).event(w),I=w.changedTouches,q=I.length,Z,te,W,Q;for(xn(w),Z=0;Z<q;++Z)te=I[Z],W=wr(te,this),F.touch0&&F.touch0[2]===te.identifier?F.touch0[0]=W:F.touch1&&F.touch1[2]===te.identifier&&(F.touch1[0]=W);if(te=F.that.__zoom,F.touch1){var H=F.touch0[0],ie=F.touch0[1],ue=F.touch1[0],de=F.touch1[1],we=(we=ue[0]-H[0])*we+(we=ue[1]-H[1])*we,fe=(fe=de[0]-ie[0])*fe+(fe=de[1]-ie[1])*fe;te=b(te,Math.sqrt(we/fe)),W=[(H[0]+ue[0])/2,(H[1]+ue[1])/2],Q=[(ie[0]+de[0])/2,(ie[1]+de[1])/2]}else if(F.touch0)W=F.touch0[0],Q=F.touch0[1];else return;F.zoom("touch",t(S(te,W,Q),F.extent,o))}}function M(w,...D){if(this.__zooming){var F=E(this,D).event(w),I=w.changedTouches,q=I.length,Z,te;for(Wi(w),h&&clearTimeout(h),h=setTimeout(function(){h=null},p),Z=0;Z<q;++Z)te=I[Z],F.touch0&&F.touch0[2]===te.identifier?delete F.touch0:F.touch1&&F.touch1[2]===te.identifier&&delete F.touch1;if(F.touch1&&!F.touch0&&(F.touch0=F.touch1,delete F.touch1),F.touch0)F.touch0[1]=this.__zoom.invert(F.touch0[0]);else if(F.end(),F.taps===2&&(te=wr(te,this),Math.hypot(d[0]-te[0],d[1]-te[1])<x)){var W=Ft(this).on("dblclick.zoom");W&&W.apply(this,arguments)}}}return _.wheelDelta=function(w){return arguments.length?(n=typeof w=="function"?w:bs(+w),_):n},_.filter=function(w){return arguments.length?(r=typeof w=="function"?w:bs(!!w),_):r},_.touchable=function(w){return arguments.length?(s=typeof w=="function"?w:bs(!!w),_):s},_.extent=function(w){return arguments.length?(e=typeof w=="function"?w:bs([[+w[0][0],+w[0][1]],[+w[1][0],+w[1][1]]]),_):e},_.scaleExtent=function(w){return arguments.length?(i[0]=+w[0],i[1]=+w[1],_):[i[0],i[1]]},_.translateExtent=function(w){return arguments.length?(o[0][0]=+w[0][0],o[1][0]=+w[1][0],o[0][1]=+w[0][1],o[1][1]=+w[1][1],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(w){return arguments.length?(t=w,_):t},_.duration=function(w){return arguments.length?(a=+w,_):a},_.interpolate=function(w){return arguments.length?(l=w,_):l},_.on=function(){var w=u.on.apply(u,arguments);return w===u?_:w},_.clickDistance=function(w){return arguments.length?(m=(w=+w)*w,_):Math.sqrt(m)},_.tapDistance=function(w){return arguments.length?(x=+w,_):x},_}function kd(r={}){const{minZoom:e=.1,maxZoom:t=4,initialTransform:n,zoomable:s=!0,pannable:i=!0,onTransformChange:o}=r,a=y.useRef(null),l=y.useRef(),[u,c]=y.useState(n||{x:0,y:0,k:1});y.useEffect(()=>{if(!a.current)return;const x=S2().scaleExtent([e,t]).filter(b=>!s&&b.type==="wheel"||!i&&(b.type==="mousedown"||b.type==="touchstart")?!1:b.type==="wheel"?s:b.type==="mousedown"||b.type==="touchstart"?b.target.closest("[data-qmap-node]")?!1:i:!0).on("zoom",b=>{const S={x:b.transform.x,y:b.transform.y,k:b.transform.k};c(S),o==null||o(S)});l.current=x;const _=Ft(a.current);return _.call(x),_.on("dblclick.zoom",null),n&&_.call(x.transform,ri.translate(n.x,n.y).scale(n.k)),()=>{_.on(".zoom",null)}},[e,t,s,i]),y.useEffect(()=>{l.current&&l.current.on("zoom",x=>{const _={x:x.transform.x,y:x.transform.y,k:x.transform.k};c(_),o==null||o(_)})},[o]);const d=y.useCallback((x,_,b,S=!0)=>{if(!a.current||!l.current)return;const C=Ft(a.current),k=ri.translate(x,_).scale(b);C.call(l.current.transform,k)},[]),h=y.useCallback(()=>{!a.current||!l.current||Ft(a.current).call(l.current.scaleBy,1.3)},[]),p=y.useCallback(()=>{!a.current||!l.current||Ft(a.current).call(l.current.scaleBy,.7)},[]),g=y.useCallback(()=>{d(0,0,1,!0)},[d]),m=y.useCallback((x,_=50)=>{if(!a.current||!l.current||x.length===0)return;const b=a.current,S=b.clientWidth,C=b.clientHeight;let k=1/0,E=1/0,v=-1/0,T=-1/0;for(const q of x){const Z=q.width||200,te=q.height||100;k=Math.min(k,q.x),E=Math.min(E,q.y),v=Math.max(v,q.x+Z),T=Math.max(T,q.y+te)}const B=v-k,j=T-E,N=(S-_*2)/B,R=(C-_*2)/j,M=Math.min(N,R,t),w=(k+v)/2,D=(E+T)/2,F=S/2-w*M,I=C/2-D*M;d(F,I,M,!0)},[t,d]);return{transform:u,containerRef:a,zoomTo:d,zoomIn:h,zoomOut:p,resetZoom:g,fitToContent:m}}function Ed(r){const{transform:e,onDragStart:t,onDragMove:n,onDragEnd:s,disabled:i=!1}=r,[o,a]=y.useState(null),[l,u]=y.useState(!1),[c,d]=y.useState({x:0,y:0}),h=y.useRef(null),p=y.useRef({x:0,y:0}),g=y.useRef(e);y.useEffect(()=>{g.current=e},[e]);const m=y.useCallback((S,C)=>{const k=g.current;return{x:(S-k.x)/k.k,y:(C-k.y)/k.k}},[]),x=y.useCallback((S,C)=>{if(i)return;C.preventDefault(),C.stopPropagation();const k=C.currentTarget,E=parseFloat(k.dataset.x||"0"),v=parseFloat(k.dataset.y||"0");h.current={x:C.clientX,y:C.clientY,nodeX:E,nodeY:v},p.current={x:E,y:v},a(S),u(!0),d({x:0,y:0}),t==null||t(S)},[i,m,t]),_=y.useCallback(S=>{if(!l||!o||!h.current)return;const C=g.current,k=h.current,E=S.clientX-k.x,v=S.clientY-k.y,T=E/C.k,B=v/C.k,j=k.nodeX+T,N=k.nodeY+B;p.current={x:j,y:N},d({x:T,y:B}),n==null||n(o,j,N,T,B)},[l,o,n]),b=y.useCallback(()=>{if(!l||!o)return;const S=p.current;s==null||s(o,S.x,S.y),a(null),u(!1),d({x:0,y:0}),h.current=null},[l,o,s]);return y.useEffect(()=>{if(!l)return;const S=k=>{_(k)},C=()=>{b()};return window.addEventListener("mousemove",S),window.addEventListener("mouseup",C),()=>{window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",C)}},[l,_,b]),{draggedNodeId:o,isDragging:l,dragOffset:c,startDrag:x,updateDrag:_,endDrag:b}}function Dd(r){const{transform:e,nodePositions:t,disabled:n=!1,controlledSelectedIds:s,onSelectionChange:i}=r,[o,a]=y.useState(new Set),l=s!==void 0,u=l?new Set(s):o,c=l?j=>{const N=typeof j=="function"?j(u):j;i==null||i(Array.from(N))}:a,[d,h]=y.useState(null),[p,g]=y.useState(!1),m=y.useRef(null),x=y.useRef(e),_=y.useRef(t);y.useEffect(()=>{x.current=e},[e]),y.useEffect(()=>{_.current=t},[t]);const b=y.useCallback((j,N)=>{const R=x.current;return{x:(j-R.x)/R.k,y:(N-R.y)/R.k}},[]),S=y.useCallback((j,N)=>{const R=_.current.get(j);if(!R)return!1;const M=R.width||200,w=R.height||100;return R.x<N.x+N.width&&R.x+M>N.x&&R.y<N.y+N.height&&R.y+w>N.y},[]),C=y.useCallback(j=>{if(n||j.target.closest("[data-qmap-node]"))return;j.preventDefault();const R=b(j.clientX,j.clientY);m.current=R,h({x:R.x,y:R.y,width:0,height:0}),g(!0),j.shiftKey||c(new Set)},[n,b]),k=y.useCallback(j=>{if(!p||!m.current)return;const N=m.current,R=b(j.clientX,j.clientY),M={x:Math.min(N.x,R.x),y:Math.min(N.y,R.y),width:Math.abs(R.x-N.x),height:Math.abs(R.y-N.y)};h(M);const w=new Set;for(const[D]of _.current)S(D,M)&&w.add(D);c(w)},[p,b,S]),E=y.useCallback(()=>{p&&(i==null||i(Array.from(u)),g(!1),h(null),m.current=null)},[p,u,i]);y.useEffect(()=>{if(!p)return;const j=R=>{k(R)},N=()=>{E()};return window.addEventListener("mousemove",j),window.addEventListener("mouseup",N),()=>{window.removeEventListener("mousemove",j),window.removeEventListener("mouseup",N)}},[p,k,E]);const v=y.useCallback((j,N=!1)=>{c(R=>{const M=new Set(N?R:[]);return R.has(j)&&N?M.delete(j):M.add(j),i==null||i(Array.from(M)),M})},[i]),T=y.useCallback(()=>{const j=new Set(_.current.keys());c(j),i==null||i(Array.from(j))},[i]),B=y.useCallback(()=>{c(new Set),i==null||i([])},[i]);return{selectedIds:u,setSelectedIds:c,selectionBox:d,isSelecting:p,startSelection:C,updateSelection:k,endSelection:E,toggleSelect:v,selectAll:T,clearSelection:B}}const Ad=y.memo(function({nodeId:e,position:t,isSelected:n,isDragging:s,draggable:i,onDragStart:o,onClick:a,onDoubleClick:l,onContextMenu:u,nodeRef:c,children:d}){const h=y.useCallback(_=>{i&&_.button===0&&o(e,_)},[e,i,o]),p=y.useCallback(_=>{s||a==null||a(_)},[s,a]),g=y.useCallback(_=>{_.stopPropagation(),l==null||l(_)},[l]),m=y.useCallback(_=>{_.preventDefault(),_.stopPropagation(),u==null||u(_)},[u]),x=t.rotation||0;return f.jsx("div",{ref:c,"data-qmap-node":e,"data-x":t.x,"data-y":t.y,style:{position:"absolute",left:t.x,top:t.y,transform:x!==0?`rotate(${x}deg)`:void 0,transformOrigin:"center center",cursor:i?s?"grabbing":"grab":"pointer",userSelect:"none",opacity:s?.8:1,zIndex:s?1e3:n?100:1,WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},onMouseDown:h,onClick:p,onDoubleClick:g,onContextMenu:m,children:d})},(r,e)=>r.nodeId===e.nodeId&&r.position.x===e.position.x&&r.position.y===e.position.y&&r.position.rotation===e.position.rotation&&r.isSelected===e.isSelected&&r.isDragging===e.isDragging&&r.draggable===e.draggable&&r.children===e.children);function Td(r,e,t="bezier"){const n={x:r.x+(r.width||200)/2,y:r.y+(r.height||100)/2},s={x:e.x+(e.width||200)/2,y:e.y+(e.height||100)/2};switch(t){case"straight":return`M ${n.x} ${n.y} L ${s.x} ${s.y}`;case"orthogonal":return E2(n,s);case"bezier":default:return k2(n,s)}}function k2(r,e){const t=e.x-r.x,n=e.y-r.y,s=Math.sqrt(t*t+n*n),i=Math.min(s*.4,150),o=Math.abs(t)>Math.abs(n);let a,l,u,c;return o?(a=r.x+i*Math.sign(t),l=r.y,u=e.x-i*Math.sign(t),c=e.y):(a=r.x,l=r.y+i*Math.sign(n),u=e.x,c=e.y-i*Math.sign(n)),`M ${r.x} ${r.y} C ${a} ${l}, ${u} ${c}, ${e.x} ${e.y}`}function E2(r,e){const t=e.x-r.x,n=e.y-r.y;if(Math.abs(t)>Math.abs(n)){const i=r.x+t/2;return`M ${r.x} ${r.y} H ${i} V ${e.y} H ${e.x}`}else{const i=r.y+n/2;return`M ${r.x} ${r.y} V ${i} H ${e.x} V ${e.y}`}}function ga(r){const e=r.width||200,t=r.height||100;return{x:r.x+e/2,y:r.y+t/2}}function D2(r,e){const t=r.width||200,n=r.height||100,s=ga(r),i=e.x-s.x,o=e.y-s.y;if(i===0&&o===0)return s;const a=t/2,l=n/2,u=Math.abs(o/(i||.001)),c=l/a;let d,h;return u<c?(d=s.x+(i>0?a:-a),h=s.y+o*a/Math.abs(i)):(h=s.y+(o>0?l:-l),d=s.x+i*l/Math.abs(o)),{x:d,y:h}}function A2(r,e){const t=r.width||200,n=r.height||100;switch(e){case"left":return{x:r.x,y:r.y+n/2};case"right":return{x:r.x+t,y:r.y+n/2};case"top":return{x:r.x+t/2,y:r.y};case"bottom":return{x:r.x+t/2,y:r.y+n};case"center":default:return ga(r)}}function T2(r,e){return r.x>=e.x&&r.x<=e.x+e.width&&r.y>=e.y&&r.y<=e.y+e.height}function N2(r,e){return r.x<e.x+e.width&&r.x+r.width>e.x&&r.y<e.y+e.height&&r.y+r.height>e.y}function B2(r){if(r.length===0)return null;let e=1/0,t=1/0,n=-1/0,s=-1/0;for(const i of r){const o=i.width||200,a=i.height||100;e=Math.min(e,i.x),t=Math.min(t,i.y),n=Math.max(n,i.x+o),s=Math.max(s,i.y+a)}return{x:e,y:t,width:n-e,height:s-t}}function j2(r,e){const t=e.x-r.x,n=e.y-r.y;return Math.sqrt(t*t+n*n)}function M2(r,e){const t=e.x-r.x,n=e.y-r.y;return t*t+n*n}const Nd=y.memo(function({edge:e,sourcePosition:t,targetPosition:n,style:s,color:i,width:o,onClick:a}){const[l,u]=y.useState(!1),c=y.useMemo(()=>Td(t,n,s),[t,n,s]),d=y.useCallback(x=>{x.stopPropagation(),a==null||a(e,x)},[e,a]),h=y.useCallback(()=>{u(!0)},[]),p=y.useCallback(()=>{u(!1)},[]),g=e.color||i,m=e.width||o;return f.jsxs("g",{children:[f.jsx("path",{d:c,fill:"none",stroke:"transparent",strokeWidth:Math.max(m*3,10),style:{cursor:a?"pointer":"default",pointerEvents:"stroke"},onClick:d,onMouseEnter:h,onMouseLeave:p}),f.jsx("path",{d:c,fill:"none",stroke:g,strokeWidth:l?m*1.5:m,strokeLinecap:"round",strokeLinejoin:"round",style:{pointerEvents:"none",transition:"stroke-width 0.15s ease"}}),e.label&&f.jsx(R2,{pathD:c,label:e.label,color:g})]})},(r,e)=>r.edge.id===e.edge.id&&r.sourcePosition.x===e.sourcePosition.x&&r.sourcePosition.y===e.sourcePosition.y&&r.sourcePosition.width===e.sourcePosition.width&&r.sourcePosition.height===e.sourcePosition.height&&r.targetPosition.x===e.targetPosition.x&&r.targetPosition.y===e.targetPosition.y&&r.targetPosition.width===e.targetPosition.width&&r.targetPosition.height===e.targetPosition.height&&r.style===e.style&&r.color===e.color&&r.width===e.width&&r.edge.label===e.edge.label&&r.edge.color===e.edge.color&&r.edge.width===e.edge.width);function R2({pathD:r,label:e,color:t}){const n=y.useMemo(()=>`edge-label-${Math.random().toString(36).substr(2,9)}`,[]);return f.jsxs(f.Fragment,{children:[f.jsx("defs",{children:f.jsx("path",{id:n,d:r})}),f.jsx("text",{fill:t,fontSize:"12",fontFamily:"system-ui, sans-serif",style:{pointerEvents:"none"},children:f.jsx("textPath",{href:`#${n}`,startOffset:"50%",textAnchor:"middle",children:e})})]})}const Bd=y.memo(function({edges:e,nodePositions:t,defaultStyle:n,defaultColor:s,defaultWidth:i,onEdgeClick:o}){const a=y.useMemo(()=>e.filter(l=>t.has(l.source)&&t.has(l.target)),[e,t]);return f.jsx("svg",{style:{position:"absolute",top:0,left:0,width:1,height:1,overflow:"visible",pointerEvents:"none"},children:f.jsx("g",{style:{pointerEvents:"auto"},children:a.map(l=>{const u=t.get(l.source),c=t.get(l.target);return f.jsx(Nd,{edge:l,sourcePosition:u,targetPosition:c,style:l.style||n,color:l.color||s,width:l.width||i,onClick:o},l.id)})})})},(r,e)=>!(r.edges!==e.edges||r.nodePositions!==e.nodePositions||r.defaultStyle!==e.defaultStyle||r.defaultColor!==e.defaultColor||r.defaultWidth!==e.defaultWidth)),jd=y.memo(function({box:e,transform:t}){const n=y.useMemo(()=>({x:e.x*t.k+t.x,y:e.y*t.k+t.y,width:e.width*t.k,height:e.height*t.k}),[e,t]);return f.jsx("div",{style:{position:"absolute",left:n.x,top:n.y,width:n.width,height:n.height,backgroundColor:"rgba(59, 130, 246, 0.1)",border:"1px solid rgba(59, 130, 246, 0.5)",borderRadius:2,pointerEvents:"none",zIndex:9999}})}),F2=200,L2=100,P2="bezier",I2="#94a3b8",z2=2,O2=.1,$2=4;function q2({viewNode:r,nodes:e,edges:t,renderNode:n,defaultNodeWidth:s=F2,defaultNodeHeight:i=L2,onNodeMove:o,onNodeDrag:a,onNodeClick:l,onNodeDoubleClick:u,onNodeContextMenu:c,selectedIds:d,onSelectionChange:h,onEdgeClick:p,onViewChange:g,onTransformChange:m,minZoom:x=O2,maxZoom:_=$2,initialTransform:b,defaultEdgeStyle:S=P2,defaultEdgeColor:C=I2,defaultEdgeWidth:k=z2,draggable:E=!0,selectable:v=!0,zoomable:T=!0,pannable:B=!0,className:j="",style:N,background:R="#f8fafc",showGrid:M=!1,gridSize:w=20}){const D=r.data||{positions:{}},F=D.positions||{},I=y.useMemo(()=>{const X=new Map;for(const K of e){const pe=F[K._id]||{x:0,y:0};X.set(K._id,{x:pe.x,y:pe.y,width:pe.width||s,height:pe.height||i,rotation:pe.rotation||0})}return X},[e,F,s,i]),{transform:q,containerRef:Z,zoomIn:te,zoomOut:W,resetZoom:Q,fitToContent:H}=kd({minZoom:x,maxZoom:_,initialTransform:b||D.transform,zoomable:T,pannable:B,onTransformChange:X=>{m==null||m(X);const K={...D,transform:X};g==null||g(K)}}),[ie,ue]=y.useState(new Map),[de,we]=y.useState(new Map),fe=y.useRef(new Map);y.useEffect(()=>{const X=q.k||1,K=new Map;fe.current.forEach((De,Be)=>{if(De){const Qe=De.getBoundingClientRect();K.set(Be,{width:Math.round(Qe.width/X),height:Math.round(Qe.height/X)})}}),e.some(De=>{const Be=K.get(De._id),Qe=de.get(De._id);return Be?Qe?Be.width!==Qe.width||Be.height!==Qe.height:!0:!1})&&we(K)},[e,de,q.k]);const{draggedNodeId:Ce,startDrag:O}=Ed({transform:q,disabled:!E,onDragStart:X=>{const K=I.get(X);K&&ue(new Map([[X,{x:K.x,y:K.y}]]))},onDragMove:(X,K,pe)=>{ue(new Map([[X,{x:K,y:pe}]])),a==null||a(X,K,pe)},onDragEnd:(X,K,pe)=>{ue(new Map),o==null||o(X,K,pe)}}),{selectedIds:je,selectionBox:re,isSelecting:Le,startSelection:Me,toggleSelect:xe,clearSelection:Se}=Dd({transform:q,nodePositions:I,disabled:!v,controlledSelectedIds:d,onSelectionChange:h}),Re=y.useCallback(X=>{const K=I.get(X)||{x:0,y:0,width:s,height:i},pe=ie.get(X),De=de.get(X),Be=(De==null?void 0:De.width)||K.width||s,Qe=(De==null?void 0:De.height)||K.height||i;return pe?{...K,x:pe.x,y:pe.y,width:Be,height:Qe}:{...K,width:Be,height:Qe}},[I,ie,de,s,i]),se=y.useMemo(()=>{const X=new Map;for(const K of I.keys())X.set(K,Re(K));return X},[I,Re]),ce=y.useCallback((X,K)=>{xe(X._id,K.shiftKey),l==null||l(X,K)},[xe,l]),$=y.useCallback(X=>{X.target.closest("[data-qmap-node]")||Se()},[Se]),Ge=y.useCallback(X=>{X.button===0&&(X.target.closest("[data-qmap-node]")||Me(X))},[Me]),Ke=M?`
185
+ ${se}`:se)},re=async se=>{if(!(!(typeof e=="string"?e:"").trim()||B||!s)){j(!0),R(!1);try{const ce=await s(se,e);t(ce)}catch(ce){console.error(`${se} failed:`,ce)}finally{j(!1)}}},Le=()=>{setTimeout(()=>{var se;(se=we.current)!=null&&se.contains(document.activeElement)||R(!1)},150)},Me=async()=>{if(!(!M.trim()||B||!i)){j(!0);try{const se=await i(M,e);t(se),w("")}catch(se){console.error("AI prompt failed:",se)}finally{j(!1)}}},xe=async()=>{if(!(typeof e=="string"?e:"").trim()||D)return;if(!(Ce||_)){console.warn("TTS: No generation mode available",{integratedTTS:Ce,hasCallback:!!_,llmClient:!!c,graphClient:!!d,nodeId:h,audioFilename:p}),alert("TTS non disponible. Sauvegardez d'abord le cours.");return}fe.current&&(fe.current.pause(),fe.current.currentTime=0),F(!0);try{if(Ce&&c&&d&&h&&p){console.log("TTS: Generating audio...",{voice:W,textLength:e.length});const ce=await c.tts(e,{voice:W});console.log("TTS: Audio generated, uploading...",{audioLength:ce==null?void 0:ce.length});const $=atob(ce),Ge=new Uint8Array($.length);for(let K=0;K<$.length;K++)Ge[K]=$.charCodeAt(K);const Ke=new Blob([Ge],{type:"audio/mpeg"}),X=new File([Ke],p,{type:"audio/mpeg"});await d.uploadFile(h,p,X),console.log("TTS: Upload complete",{nodeId:h,audioFilename:p}),de(Date.now()),ie(p),x==null||x(p,W)}else _&&(await _(e,W),de(Date.now()))}catch(ce){console.error("TTS generation failed:",ce),alert("Erreur TTS: "+(ce instanceof Error?ce.message:"Erreur inconnue"))}finally{F(!1)}},Se=async()=>{if(!(!c||!E||I)){if(!(v!=null&&v.trim())){te(T||"Le texte source est requis pour la génération.");return}q(!0),te(null);try{const se=await c.chat([{role:"system",content:E},{role:"user",content:v}]);t(se)}catch(se){te(se instanceof Error?se.message:"Erreur de génération")}finally{q(!1)}}},Re=se=>{Q(se),C==null||C(se)};return f.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${l}`,children:[f.jsx(Zc,{onComplete:o||(()=>{}),onTranscribe:n,onTranscriptionComplete:je,hideSaveButton:!o,variant:"div",extraControls:f.jsxs(f.Fragment,{children:[i&&f.jsx("button",{type:"button",onClick:Me,disabled:B||!M.trim(),style:{padding:"4px",borderRadius:"4px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:B||!M.trim()?.3:1},title:"Envoyer le prompt AI",children:f.jsx("span",{className:"material-icons",style:{fontSize:"18px",color:B?"#9333ea":"#171717"},children:B?"hourglass_empty":"smart_toy"})}),s&&f.jsxs("div",{className:"relative",ref:we,style:{display:"inline-flex"},children:[f.jsx("button",{type:"button",onClick:()=>R(!N),disabled:B||!(typeof e=="string"?e:"").trim(),style:{padding:"4px 8px",marginRight:"6px",borderRadius:"4px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:B||!(typeof e=="string"?e:"").trim()?.4:1},children:f.jsx("span",{className:"material-icons",style:{fontSize:"18px",color:"#171717",transform:N?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:"chevron_right"})}),N&&!B&&f.jsxs("div",{className:"absolute right-0 top-full mt-1 bg-white border border-neutral-200 rounded-lg shadow-lg z-50 min-w-[180px] py-1",onBlur:Le,children:[f.jsxs("button",{type:"button",onClick:()=>re("restructure"),className:"w-full px-3 py-2 text-left text-sm hover:bg-neutral-50 flex items-center gap-2",children:[f.jsx("span",{className:"material-icons text-base text-blue-500",children:"format_list_bulleted"}),f.jsxs("div",{children:[f.jsx("div",{className:"font-medium",children:"Restructure"}),f.jsx("div",{className:"text-xs text-neutral-500",children:"Organize & clarify"})]})]}),f.jsxs("button",{type:"button",onClick:()=>re("proofread"),className:"w-full px-3 py-2 text-left text-sm hover:bg-neutral-50 flex items-center gap-2",children:[f.jsx("span",{className:"material-icons text-base text-green-500",children:"spellcheck"}),f.jsxs("div",{children:[f.jsx("div",{className:"font-medium",children:"Proofread"}),f.jsx("div",{className:"text-xs text-neutral-500",children:"Fix grammar & spelling"})]})]}),f.jsxs("button",{type:"button",onClick:()=>re("rewrite"),className:"w-full px-3 py-2 text-left text-sm hover:bg-neutral-50 flex items-center gap-2",children:[f.jsx("span",{className:"material-icons text-base text-purple-500",children:"brush"}),f.jsxs("div",{children:[f.jsx("div",{className:"font-medium",children:"Rewrite"}),f.jsx("div",{className:"text-xs text-neutral-500",children:"Your voice & style"})]})]})]})]})]})}),i&&f.jsx("div",{className:"bg-neutral-50 border-b border-neutral-200",children:f.jsx("textarea",{value:M,onChange:se=>w(se.target.value),onKeyDown:se=>{se.stopPropagation(),se.key==="Enter"&&se.ctrlKey&&(se.preventDefault(),Me())},placeholder:"Instructions AI... (Ctrl+Enter)",disabled:B,rows:3,className:"w-full px-3 py-2 text-sm border-0 resize-y min-h-[60px] focus:ring-0 focus:outline-none bg-transparent disabled:opacity-50"})}),(r||Ce||_||k)&&f.jsxs("div",{className:"flex items-center justify-between px-2 py-1",children:[f.jsxs("div",{className:"flex items-center gap-2",children:[r&&f.jsx("label",{className:"text-sm font-medium text-neutral-700",children:r}),k&&c&&E&&f.jsxs("button",{type:"button",onClick:Se,disabled:I,className:"flex items-center gap-1 px-2 py-1 text-xs bg-purple-100 text-purple-700 hover:bg-purple-200 rounded transition-colors disabled:opacity-50",title:k.label,children:[f.jsx("span",{className:"material-icons",style:{fontSize:"14px"},children:I?"hourglass_empty":k.icon||"auto_awesome"}),k.label]})]}),f.jsxs("div",{className:"flex items-center gap-1",children:[(typeof e=="string"?e:"").trim()&&f.jsx("button",{type:"button",onClick:()=>navigator.clipboard.writeText(e),className:"p-1 rounded hover:bg-neutral-100 transition-colors",title:"Copy to clipboard",children:f.jsx("span",{className:"material-icons text-neutral-500",style:{fontSize:"16px"},children:"content_copy"})}),(Ce||_)&&f.jsxs("div",{className:"flex items-center gap-1",children:[f.jsx("select",{value:W,onChange:se=>Re(se.target.value),disabled:D,className:"px-1.5 py-0.5 text-xs border border-neutral-200 rounded bg-white focus:outline-none focus:ring-1 focus:ring-blue-500 disabled:opacity-50",title:"Choisir la voix",children:ou.map(se=>f.jsxs("option",{value:se.id,children:[se.name," - ",se.description]},se.id))}),f.jsx("button",{type:"button",onClick:xe,disabled:D||!(typeof e=="string"?e:"").trim(),className:"p-1 rounded hover:bg-blue-50 transition-colors disabled:opacity-40",title:D?"Génération en cours...":"Générer audio TTS",children:f.jsx("span",{className:`material-icons ${D?"animate-pulse text-blue-600":O?"text-green-600":"text-neutral-400"}`,style:{fontSize:"16px"},children:D?"hourglass_empty":"record_voice_over"})}),O&&f.jsxs(f.Fragment,{children:[f.jsx("audio",{ref:fe,src:O,controls:!0,className:"h-6 w-32"},ue),f.jsx("button",{type:"button",onClick:()=>{fe.current&&fe.current.pause(),ie(void 0),x==null||x("",W)},className:"p-1 rounded hover:bg-red-50 transition-colors",title:"Supprimer l'audio",children:f.jsx("span",{className:"material-icons text-red-400 hover:text-red-600",style:{fontSize:"14px"},children:"delete"})})]})]})]})]}),f.jsx("textarea",{value:e,onChange:se=>t(se.target.value),onKeyDown:se=>se.stopPropagation(),placeholder:a,rows:u,disabled:B||I,className:"flex-1 w-full px-3 py-2 border-0 focus:ring-0 focus:outline-none text-sm disabled:opacity-50 disabled:bg-neutral-50 resize-none"}),Z&&f.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:f.jsxs("div",{className:"bg-white rounded-lg shadow-xl p-6 max-w-md mx-4",children:[f.jsxs("div",{className:"flex items-start gap-3",children:[f.jsx("span",{className:"material-icons text-amber-500",style:{fontSize:"24px"},children:"warning"}),f.jsxs("div",{className:"flex-1",children:[f.jsx("h3",{className:"font-medium text-neutral-900 mb-2",children:"Génération impossible"}),f.jsx("p",{className:"text-sm text-neutral-600",children:Z})]})]}),f.jsx("div",{className:"mt-4 flex justify-end",children:f.jsx("button",{type:"button",onClick:()=>te(null),className:"px-4 py-2 bg-neutral-100 hover:bg-neutral-200 text-neutral-700 rounded transition-colors text-sm",children:"Compris"})})]})})]})}const gs={"4/3":4/3,"16/9":16/9,"1/1":1,"3/4":3/4,"9/16":9/16,free:null};function Qg({src:r,onSave:e,onCancel:t,aspectRatio:n="4/3",outputFormat:s="image/jpeg",outputQuality:i=.9,theme:o="dark"}){const a=y.useRef(null),l=y.useRef(null),u=y.useRef(null),[c,d]=y.useState(!0),[h,p]=y.useState(null),[g,m]=y.useState(n),[x,_]=y.useState(0),[b,S]=y.useState({x:0,y:0,width:100,height:100}),[C,k]=y.useState(!1),[E,v]=y.useState(null),[T,B]=y.useState({x:0,y:0}),[j,N]=y.useState({x:0,y:0,width:100,height:100}),R=o==="dark",M=y.useCallback(()=>{const O=u.current;return O?x===90||x===270?{width:O.height,height:O.width}:{width:O.width,height:O.height}:{width:100,height:100}},[x]),w=y.useCallback((O,je)=>{const re=O/je,Le=.05;for(const[Me,xe]of Object.entries(gs))if(xe!==null&&Math.abs(re-xe)/xe<Le)return Me;return"free"},[]);y.useEffect(()=>{const O=new Image;O.crossOrigin="anonymous",O.onload=()=>{u.current=O;const je=w(O.width,O.height);m(je),d(!1)},O.onerror=()=>{p("Failed to load image"),d(!1)},O.src=r},[r,w]);const D=y.useCallback(()=>{const{width:O,height:je}=M(),re=gs[g];if(re===null){S({x:0,y:0,width:100,height:100});return}const Le=O/je;let Me,xe;Le>re?(xe=100,Me=re/Le*100):(Me=100,xe=Le/re*100);const Se=(100-Me)/2,Re=(100-xe)/2;S({x:Se,y:Re,width:Me,height:xe})},[g,M]);y.useEffect(()=>{u.current&&D()},[g,x,D]),y.useEffect(()=>{const O=l.current,je=u.current;if(!O||!je||c)return;const re=O.getContext("2d");if(!re)return;const Le=a.current;if(!Le)return;const Me=Le.clientWidth,xe=Le.clientHeight-140,{width:Se,height:Re}=M(),se=Se/Re;let ce,$;Me/xe>se?($=Math.min(xe,Re),ce=$*se):(ce=Math.min(Me,Se),$=ce/se),ce>Me&&(ce=Me,$=ce/se),$>xe&&($=xe,ce=$*se),O.width=ce,O.height=$,re.clearRect(0,0,ce,$),re.save(),re.translate(ce/2,$/2),re.rotate(x*Math.PI/180);let Ge,Ke;x===90||x===270?(Ge=$,Ke=ce):(Ge=ce,Ke=$),re.drawImage(je,-Ge/2,-Ke/2,Ge,Ke),re.restore(),re.fillStyle="rgba(0, 0, 0, 0.6)";const X=b.x/100*ce,K=b.y/100*$,pe=b.width/100*ce,De=b.height/100*$;re.fillRect(0,0,ce,K),re.fillRect(0,K+De,ce,$-K-De),re.fillRect(0,K,X,De),re.fillRect(X+pe,K,ce-X-pe,De),re.strokeStyle="#fff",re.lineWidth=2,re.strokeRect(X,K,pe,De),re.strokeStyle="rgba(255, 255, 255, 0.3)",re.lineWidth=1,re.beginPath(),re.moveTo(X+pe/3,K),re.lineTo(X+pe/3,K+De),re.moveTo(X+pe*2/3,K),re.lineTo(X+pe*2/3,K+De),re.moveTo(X,K+De/3),re.lineTo(X+pe,K+De/3),re.moveTo(X,K+De*2/3),re.lineTo(X+pe,K+De*2/3),re.stroke();const Be=14;re.fillStyle="#fff",re.strokeStyle="#333",re.lineWidth=1,[{x:X,y:K},{x:X+pe,y:K},{x:X,y:K+De},{x:X+pe,y:K+De}].forEach(Et=>{re.fillRect(Et.x-Be/2,Et.y-Be/2,Be,Be),re.strokeRect(Et.x-Be/2,Et.y-Be/2,Be,Be)})},[b,x,c,M]);const F=O=>{const je=l.current;if(!je)return;const re=je.getBoundingClientRect(),Le=(O.clientX-re.left)/re.width*100,Me=(O.clientY-re.top)/re.height*100,xe=4,Se=[{name:"nw",x:b.x,y:b.y},{name:"ne",x:b.x+b.width,y:b.y},{name:"sw",x:b.x,y:b.y+b.height},{name:"se",x:b.x+b.width,y:b.y+b.height}];for(const Re of Se)if(Math.abs(Le-Re.x)<xe&&Math.abs(Me-Re.y)<xe){v(Re.name),B({x:Le,y:Me}),N({...b});return}Le>=b.x&&Le<=b.x+b.width&&Me>=b.y&&Me<=b.y+b.height&&(k(!0),B({x:Le,y:Me}),N({...b}))},I=O=>{const je=l.current;if(!je)return;const re=je.getBoundingClientRect(),Le=(O.clientX-re.left)/re.width*100,Me=(O.clientY-re.top)/re.height*100;if(C){const xe=Le-T.x,Se=Me-T.y;let Re=j.x+xe,se=j.y+Se;Re=Math.max(0,Math.min(Re,100-j.width)),se=Math.max(0,Math.min(se,100-j.height)),S({...j,x:Re,y:se})}else if(E){const xe=gs[g],{width:Se,height:Re}=M(),se=Se/Re,ce=xe?xe/se:null;let $={...j};const Ge=Le-T.x,Ke=Me-T.y;if(E==="se")$.width=Math.max(10,Math.min(100-$.x,j.width+Ge)),ce?($.height=$.width/ce,$.y+$.height>100&&($.height=100-$.y,$.width=$.height*ce)):$.height=Math.max(10,Math.min(100-$.y,j.height+Ke));else if(E==="sw"){const X=-Ge,K=Math.max(10,j.width+X),pe=j.x+j.width-K;pe>=0&&($.width=K,$.x=pe,ce?($.height=$.width/ce,$.y+$.height>100&&($.height=100-$.y,$.width=$.height*ce,$.x=j.x+j.width-$.width)):$.height=Math.max(10,Math.min(100-$.y,j.height+Ke)))}else if(E==="ne")if($.width=Math.max(10,Math.min(100-$.x,j.width+Ge)),ce){const X=$.width/ce,K=j.y+j.height-X;K>=0?($.height=X,$.y=K):($.y=0,$.height=j.y+j.height,$.width=$.height*ce)}else{const X=-Ke,K=Math.max(10,j.height+X),pe=j.y+j.height-K;pe>=0&&($.height=K,$.y=pe)}else if(E==="nw"){const X=-Ge,K=Math.max(10,j.width+X),pe=j.x+j.width-K;if(pe>=0)if($.width=K,$.x=pe,ce){const De=$.width/ce,Be=j.y+j.height-De;Be>=0?($.height=De,$.y=Be):($.y=0,$.height=j.y+j.height,$.width=$.height*ce,$.x=j.x+j.width-$.width)}else{const De=-Ke,Be=Math.max(10,j.height+De),Qe=j.y+j.height-Be;Qe>=0&&($.height=Be,$.y=Qe)}}$.x=Math.max(0,$.x),$.y=Math.max(0,$.y),$.width=Math.min($.width,100-$.x),$.height=Math.min($.height,100-$.y),S($)}},q=()=>{k(!1),v(null)},Z=O=>{_(je=>O==="right"?(je+90)%360:(je-90+360)%360)},te=()=>{const O=u.current;if(!O)return;const{width:je,height:re}=M(),Le=b.x/100*je,Me=b.y/100*re,xe=b.width/100*je,Se=b.height/100*re,Re=document.createElement("canvas"),se=Re.getContext("2d");if(!se)return;Re.width=xe,Re.height=Se;const ce=document.createElement("canvas"),$=ce.getContext("2d");$&&(ce.width=je,ce.height=re,$.save(),$.translate(je/2,re/2),$.rotate(x*Math.PI/180),$.drawImage(O,-O.width/2,-O.height/2,O.width,O.height),$.restore(),se.drawImage(ce,Le,Me,xe,Se,0,0,xe,Se),Re.toBlob(Ge=>{Ge&&e(Ge)},s,i))},W={display:"flex",flexDirection:"column",width:"100%",height:"100%",background:R?"#1a1a1a":"#f5f5f5",overflow:"hidden"},Q={flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:"16px",minHeight:0,overflow:"hidden"},H={display:"flex",flexDirection:"column",gap:"12px",padding:"16px",borderTop:`1px solid ${R?"#333":"#ddd"}`,background:R?"#242424":"#fff",flexShrink:0},ie={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px"},ue={padding:"10px 20px",borderRadius:"8px",border:"none",cursor:"pointer",fontSize:"14px",fontWeight:500,transition:"background 0.15s, opacity 0.15s"},de={...ue,background:"#E67E22",color:"#fff"},we={...ue,background:R?"#333":"#e5e5e5",color:R?"#fff":"#333"},fe={padding:"10px",borderRadius:"8px",border:"none",background:R?"#333":"#e5e5e5",color:R?"#fff":"#333",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},Ce=O=>({padding:"8px 14px",borderRadius:"6px",border:O?"2px solid #E67E22":"2px solid transparent",background:O?"#E67E22":R?"#333":"#e5e5e5",color:O?"#fff":R?"#ccc":"#666",cursor:"pointer",fontSize:"13px",fontWeight:600,transition:"all 0.15s"});return c?f.jsx("div",{style:{...W,alignItems:"center",justifyContent:"center"},children:f.jsx("div",{style:{color:R?"#aaa":"#666"},children:"Loading image..."})}):h?f.jsxs("div",{style:{...W,alignItems:"center",justifyContent:"center"},children:[f.jsx("div",{style:{color:"#ef4444"},children:h}),t&&f.jsx("button",{onClick:t,style:{...we,marginTop:"16px"},children:"Close"})]}):f.jsxs("div",{ref:a,style:W,children:[f.jsx("div",{style:Q,children:f.jsx("canvas",{ref:l,style:{cursor:C?"grabbing":E?"nwse-resize":"grab",maxWidth:"100%",maxHeight:"100%"},onMouseDown:F,onMouseMove:I,onMouseUp:q,onMouseLeave:q})}),f.jsxs("div",{style:H,children:[f.jsx("div",{style:{display:"flex",gap:"8px",flexWrap:"wrap",justifyContent:"center"},children:Object.keys(gs).map(O=>f.jsx("button",{onClick:()=>m(O),style:Ce(g===O),children:O==="free"?"Libre":O},O))}),f.jsxs("div",{style:ie,children:[f.jsxs("div",{style:{display:"flex",gap:"8px"},children:[f.jsx("button",{onClick:()=>Z("left"),style:fe,title:"Rotate left",children:f.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:f.jsx("path",{d:"M2.5 2v6h6M2.66 15.57a10 10 0 1 0 .57-8.38"})})}),f.jsx("button",{onClick:()=>Z("right"),style:fe,title:"Rotate right",children:f.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:f.jsx("path",{d:"M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38"})})})]}),f.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t&&f.jsx("button",{onClick:t,style:we,children:"Annuler"}),f.jsx("button",{onClick:te,style:de,children:"Enregistrer"})]})]})]})]})}var Jg={value:()=>{}};function la(){for(var r=0,e=arguments.length,t={},n;r<e;++r){if(!(n=arguments[r]+"")||n in t||/[\s.]/.test(n))throw new Error("illegal type: "+n);t[n]=[]}return new Cs(t)}function Cs(r){this._=r}function Xg(r,e){return r.trim().split(/^|\s+/).map(function(t){var n="",s=t.indexOf(".");if(s>=0&&(n=t.slice(s+1),t=t.slice(0,s)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}})}Cs.prototype=la.prototype={constructor:Cs,on:function(r,e){var t=this._,n=Xg(r+"",t),s,i=-1,o=n.length;if(arguments.length<2){for(;++i<o;)if((s=(r=n[i]).type)&&(s=Zg(t[s],r.name)))return s;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++i<o;)if(s=(r=n[i]).type)t[s]=zl(t[s],r.name,e);else if(e==null)for(s in t)t[s]=zl(t[s],r.name,null);return this},copy:function(){var r={},e=this._;for(var t in e)r[t]=e[t].slice();return new Cs(r)},call:function(r,e){if((s=arguments.length-2)>0)for(var t=new Array(s),n=0,s,i;n<s;++n)t[n]=arguments[n+2];if(!this._.hasOwnProperty(r))throw new Error("unknown type: "+r);for(i=this._[r],n=0,s=i.length;n<s;++n)i[n].value.apply(e,t)},apply:function(r,e,t){if(!this._.hasOwnProperty(r))throw new Error("unknown type: "+r);for(var n=this._[r],s=0,i=n.length;s<i;++s)n[s].value.apply(e,t)}};function Zg(r,e){for(var t=0,n=r.length,s;t<n;++t)if((s=r[t]).name===e)return s.value}function zl(r,e,t){for(var n=0,s=r.length;n<s;++n)if(r[n].name===e){r[n]=Jg,r=r.slice(0,n).concat(r.slice(n+1));break}return t!=null&&r.push({name:e,value:t}),r}var bo="http://www.w3.org/1999/xhtml";const Ol={svg:"http://www.w3.org/2000/svg",xhtml:bo,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function _i(r){var e=r+="",t=e.indexOf(":");return t>=0&&(e=r.slice(0,t))!=="xmlns"&&(r=r.slice(t+1)),Ol.hasOwnProperty(e)?{space:Ol[e],local:r}:r}function e0(r){return function(){var e=this.ownerDocument,t=this.namespaceURI;return t===bo&&e.documentElement.namespaceURI===bo?e.createElement(r):e.createElementNS(t,r)}}function t0(r){return function(){return this.ownerDocument.createElementNS(r.space,r.local)}}function ed(r){var e=_i(r);return(e.local?t0:e0)(e)}function r0(){}function ua(r){return r==null?r0:function(){return this.querySelector(r)}}function n0(r){typeof r!="function"&&(r=ua(r));for(var e=this._groups,t=e.length,n=new Array(t),s=0;s<t;++s)for(var i=e[s],o=i.length,a=n[s]=new Array(o),l,u,c=0;c<o;++c)(l=i[c])&&(u=r.call(l,l.__data__,c,i))&&("__data__"in l&&(u.__data__=l.__data__),a[c]=u);return new Tt(n,this._parents)}function s0(r){return r==null?[]:Array.isArray(r)?r:Array.from(r)}function i0(){return[]}function td(r){return r==null?i0:function(){return this.querySelectorAll(r)}}function o0(r){return function(){return s0(r.apply(this,arguments))}}function a0(r){typeof r=="function"?r=o0(r):r=td(r);for(var e=this._groups,t=e.length,n=[],s=[],i=0;i<t;++i)for(var o=e[i],a=o.length,l,u=0;u<a;++u)(l=o[u])&&(n.push(r.call(l,l.__data__,u,o)),s.push(l));return new Tt(n,s)}function rd(r){return function(){return this.matches(r)}}function nd(r){return function(e){return e.matches(r)}}var l0=Array.prototype.find;function u0(r){return function(){return l0.call(this.children,r)}}function c0(){return this.firstElementChild}function d0(r){return this.select(r==null?c0:u0(typeof r=="function"?r:nd(r)))}var f0=Array.prototype.filter;function h0(){return Array.from(this.children)}function p0(r){return function(){return f0.call(this.children,r)}}function g0(r){return this.selectAll(r==null?h0:p0(typeof r=="function"?r:nd(r)))}function m0(r){typeof r!="function"&&(r=rd(r));for(var e=this._groups,t=e.length,n=new Array(t),s=0;s<t;++s)for(var i=e[s],o=i.length,a=n[s]=[],l,u=0;u<o;++u)(l=i[u])&&r.call(l,l.__data__,u,i)&&a.push(l);return new Tt(n,this._parents)}function sd(r){return new Array(r.length)}function y0(){return new Tt(this._enter||this._groups.map(sd),this._parents)}function Qs(r,e){this.ownerDocument=r.ownerDocument,this.namespaceURI=r.namespaceURI,this._next=null,this._parent=r,this.__data__=e}Qs.prototype={constructor:Qs,appendChild:function(r){return this._parent.insertBefore(r,this._next)},insertBefore:function(r,e){return this._parent.insertBefore(r,e)},querySelector:function(r){return this._parent.querySelector(r)},querySelectorAll:function(r){return this._parent.querySelectorAll(r)}};function x0(r){return function(){return r}}function b0(r,e,t,n,s,i){for(var o=0,a,l=e.length,u=i.length;o<u;++o)(a=e[o])?(a.__data__=i[o],n[o]=a):t[o]=new Qs(r,i[o]);for(;o<l;++o)(a=e[o])&&(s[o]=a)}function v0(r,e,t,n,s,i,o){var a,l,u=new Map,c=e.length,d=i.length,h=new Array(c),p;for(a=0;a<c;++a)(l=e[a])&&(h[a]=p=o.call(l,l.__data__,a,e)+"",u.has(p)?s[a]=l:u.set(p,l));for(a=0;a<d;++a)p=o.call(r,i[a],a,i)+"",(l=u.get(p))?(n[a]=l,l.__data__=i[a],u.delete(p)):t[a]=new Qs(r,i[a]);for(a=0;a<c;++a)(l=e[a])&&u.get(h[a])===l&&(s[a]=l)}function _0(r){return r.__data__}function w0(r,e){if(!arguments.length)return Array.from(this,_0);var t=e?v0:b0,n=this._parents,s=this._groups;typeof r!="function"&&(r=x0(r));for(var i=s.length,o=new Array(i),a=new Array(i),l=new Array(i),u=0;u<i;++u){var c=n[u],d=s[u],h=d.length,p=C0(r.call(c,c&&c.__data__,u,n)),g=p.length,m=a[u]=new Array(g),x=o[u]=new Array(g),_=l[u]=new Array(h);t(c,d,m,x,_,p,e);for(var b=0,S=0,C,k;b<g;++b)if(C=m[b]){for(b>=S&&(S=b+1);!(k=x[S])&&++S<g;);C._next=k||null}}return o=new Tt(o,n),o._enter=a,o._exit=l,o}function C0(r){return typeof r=="object"&&"length"in r?r:Array.from(r)}function S0(){return new Tt(this._exit||this._groups.map(sd),this._parents)}function k0(r,e,t){var n=this.enter(),s=this,i=this.exit();return typeof r=="function"?(n=r(n),n&&(n=n.selection())):n=n.append(r+""),e!=null&&(s=e(s),s&&(s=s.selection())),t==null?i.remove():t(i),n&&s?n.merge(s).order():s}function E0(r){for(var e=r.selection?r.selection():r,t=this._groups,n=e._groups,s=t.length,i=n.length,o=Math.min(s,i),a=new Array(s),l=0;l<o;++l)for(var u=t[l],c=n[l],d=u.length,h=a[l]=new Array(d),p,g=0;g<d;++g)(p=u[g]||c[g])&&(h[g]=p);for(;l<s;++l)a[l]=t[l];return new Tt(a,this._parents)}function D0(){for(var r=this._groups,e=-1,t=r.length;++e<t;)for(var n=r[e],s=n.length-1,i=n[s],o;--s>=0;)(o=n[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function A0(r){r||(r=T0);function e(d,h){return d&&h?r(d.__data__,h.__data__):!d-!h}for(var t=this._groups,n=t.length,s=new Array(n),i=0;i<n;++i){for(var o=t[i],a=o.length,l=s[i]=new Array(a),u,c=0;c<a;++c)(u=o[c])&&(l[c]=u);l.sort(e)}return new Tt(s,this._parents).order()}function T0(r,e){return r<e?-1:r>e?1:r>=e?0:NaN}function N0(){var r=arguments[0];return arguments[0]=this,r.apply(null,arguments),this}function B0(){return Array.from(this)}function j0(){for(var r=this._groups,e=0,t=r.length;e<t;++e)for(var n=r[e],s=0,i=n.length;s<i;++s){var o=n[s];if(o)return o}return null}function M0(){let r=0;for(const e of this)++r;return r}function R0(){return!this.node()}function F0(r){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var s=e[t],i=0,o=s.length,a;i<o;++i)(a=s[i])&&r.call(a,a.__data__,i,s);return this}function L0(r){return function(){this.removeAttribute(r)}}function P0(r){return function(){this.removeAttributeNS(r.space,r.local)}}function I0(r,e){return function(){this.setAttribute(r,e)}}function z0(r,e){return function(){this.setAttributeNS(r.space,r.local,e)}}function O0(r,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttribute(r):this.setAttribute(r,t)}}function $0(r,e){return function(){var t=e.apply(this,arguments);t==null?this.removeAttributeNS(r.space,r.local):this.setAttributeNS(r.space,r.local,t)}}function q0(r,e){var t=_i(r);if(arguments.length<2){var n=this.node();return t.local?n.getAttributeNS(t.space,t.local):n.getAttribute(t)}return this.each((e==null?t.local?P0:L0:typeof e=="function"?t.local?$0:O0:t.local?z0:I0)(t,e))}function id(r){return r.ownerDocument&&r.ownerDocument.defaultView||r.document&&r||r.defaultView}function U0(r){return function(){this.style.removeProperty(r)}}function W0(r,e,t){return function(){this.style.setProperty(r,e,t)}}function H0(r,e,t){return function(){var n=e.apply(this,arguments);n==null?this.style.removeProperty(r):this.style.setProperty(r,n,t)}}function V0(r,e,t){return arguments.length>1?this.each((e==null?U0:typeof e=="function"?H0:W0)(r,e,t??"")):rn(this.node(),r)}function rn(r,e){return r.style.getPropertyValue(e)||id(r).getComputedStyle(r,null).getPropertyValue(e)}function G0(r){return function(){delete this[r]}}function K0(r,e){return function(){this[r]=e}}function Y0(r,e){return function(){var t=e.apply(this,arguments);t==null?delete this[r]:this[r]=t}}function Q0(r,e){return arguments.length>1?this.each((e==null?G0:typeof e=="function"?Y0:K0)(r,e)):this.node()[r]}function od(r){return r.trim().split(/^|\s+/)}function ca(r){return r.classList||new ad(r)}function ad(r){this._node=r,this._names=od(r.getAttribute("class")||"")}ad.prototype={add:function(r){var e=this._names.indexOf(r);e<0&&(this._names.push(r),this._node.setAttribute("class",this._names.join(" ")))},remove:function(r){var e=this._names.indexOf(r);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(r){return this._names.indexOf(r)>=0}};function ld(r,e){for(var t=ca(r),n=-1,s=e.length;++n<s;)t.add(e[n])}function ud(r,e){for(var t=ca(r),n=-1,s=e.length;++n<s;)t.remove(e[n])}function J0(r){return function(){ld(this,r)}}function X0(r){return function(){ud(this,r)}}function Z0(r,e){return function(){(e.apply(this,arguments)?ld:ud)(this,r)}}function em(r,e){var t=od(r+"");if(arguments.length<2){for(var n=ca(this.node()),s=-1,i=t.length;++s<i;)if(!n.contains(t[s]))return!1;return!0}return this.each((typeof e=="function"?Z0:e?J0:X0)(t,e))}function tm(){this.textContent=""}function rm(r){return function(){this.textContent=r}}function nm(r){return function(){var e=r.apply(this,arguments);this.textContent=e??""}}function sm(r){return arguments.length?this.each(r==null?tm:(typeof r=="function"?nm:rm)(r)):this.node().textContent}function im(){this.innerHTML=""}function om(r){return function(){this.innerHTML=r}}function am(r){return function(){var e=r.apply(this,arguments);this.innerHTML=e??""}}function lm(r){return arguments.length?this.each(r==null?im:(typeof r=="function"?am:om)(r)):this.node().innerHTML}function um(){this.nextSibling&&this.parentNode.appendChild(this)}function cm(){return this.each(um)}function dm(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function fm(){return this.each(dm)}function hm(r){var e=typeof r=="function"?r:ed(r);return this.select(function(){return this.appendChild(e.apply(this,arguments))})}function pm(){return null}function gm(r,e){var t=typeof r=="function"?r:ed(r),n=e==null?pm:typeof e=="function"?e:ua(e);return this.select(function(){return this.insertBefore(t.apply(this,arguments),n.apply(this,arguments)||null)})}function mm(){var r=this.parentNode;r&&r.removeChild(this)}function ym(){return this.each(mm)}function xm(){var r=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(r,this.nextSibling):r}function bm(){var r=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(r,this.nextSibling):r}function vm(r){return this.select(r?bm:xm)}function _m(r){return arguments.length?this.property("__data__",r):this.node().__data__}function wm(r){return function(e){r.call(this,e,this.__data__)}}function Cm(r){return r.trim().split(/^|\s+/).map(function(e){var t="",n=e.indexOf(".");return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function Sm(r){return function(){var e=this.__on;if(e){for(var t=0,n=-1,s=e.length,i;t<s;++t)i=e[t],(!r.type||i.type===r.type)&&i.name===r.name?this.removeEventListener(i.type,i.listener,i.options):e[++n]=i;++n?e.length=n:delete this.__on}}}function km(r,e,t){return function(){var n=this.__on,s,i=wm(e);if(n){for(var o=0,a=n.length;o<a;++o)if((s=n[o]).type===r.type&&s.name===r.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=i,s.options=t),s.value=e;return}}this.addEventListener(r.type,i,t),s={type:r.type,name:r.name,value:e,listener:i,options:t},n?n.push(s):this.__on=[s]}}function Em(r,e,t){var n=Cm(r+""),s,i=n.length,o;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,u=a.length,c;l<u;++l)for(s=0,c=a[l];s<i;++s)if((o=n[s]).type===c.type&&o.name===c.name)return c.value}return}for(a=e?km:Sm,s=0;s<i;++s)this.each(a(n[s],e,t));return this}function cd(r,e,t){var n=id(r),s=n.CustomEvent;typeof s=="function"?s=new s(e,t):(s=n.document.createEvent("Event"),t?(s.initEvent(e,t.bubbles,t.cancelable),s.detail=t.detail):s.initEvent(e,!1,!1)),r.dispatchEvent(s)}function Dm(r,e){return function(){return cd(this,r,e)}}function Am(r,e){return function(){return cd(this,r,e.apply(this,arguments))}}function Tm(r,e){return this.each((typeof e=="function"?Am:Dm)(r,e))}function*Nm(){for(var r=this._groups,e=0,t=r.length;e<t;++e)for(var n=r[e],s=0,i=n.length,o;s<i;++s)(o=n[s])&&(yield o)}var dd=[null];function Tt(r,e){this._groups=r,this._parents=e}function ss(){return new Tt([[document.documentElement]],dd)}function Bm(){return this}Tt.prototype=ss.prototype={constructor:Tt,select:n0,selectAll:a0,selectChild:d0,selectChildren:g0,filter:m0,data:w0,enter:y0,exit:S0,join:k0,merge:E0,selection:Bm,order:D0,sort:A0,call:N0,nodes:B0,node:j0,size:M0,empty:R0,each:F0,attr:q0,style:V0,property:Q0,classed:em,text:sm,html:lm,raise:cm,lower:fm,append:hm,insert:gm,remove:ym,clone:vm,datum:_m,on:Em,dispatch:Tm,[Symbol.iterator]:Nm};function Ft(r){return typeof r=="string"?new Tt([[document.querySelector(r)]],[document.documentElement]):new Tt([[r]],dd)}function jm(r){let e;for(;e=r.sourceEvent;)r=e;return r}function wr(r,e){if(r=jm(r),e===void 0&&(e=r.currentTarget),e){var t=e.ownerSVGElement||e;if(t.createSVGPoint){var n=t.createSVGPoint();return n.x=r.clientX,n.y=r.clientY,n=n.matrixTransform(e.getScreenCTM().inverse()),[n.x,n.y]}if(e.getBoundingClientRect){var s=e.getBoundingClientRect();return[r.clientX-s.left-e.clientLeft,r.clientY-s.top-e.clientTop]}}return[r.pageX,r.pageY]}const vo={capture:!0,passive:!1};function _o(r){r.preventDefault(),r.stopImmediatePropagation()}function Mm(r){var e=r.document.documentElement,t=Ft(r).on("dragstart.drag",_o,vo);"onselectstart"in e?t.on("selectstart.drag",_o,vo):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Rm(r,e){var t=r.document.documentElement,n=Ft(r).on("dragstart.drag",null);e&&(n.on("click.drag",_o,vo),setTimeout(function(){n.on("click.drag",null)},0)),"onselectstart"in t?n.on("selectstart.drag",null):(t.style.MozUserSelect=t.__noselect,delete t.__noselect)}function da(r,e,t){r.prototype=e.prototype=t,t.constructor=r}function fd(r,e){var t=Object.create(r.prototype);for(var n in e)t[n]=e[n];return t}function is(){}var $n=.7,Js=1/$n,Jr="\\s*([+-]?\\d+)\\s*",qn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Vt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Fm=/^#([0-9a-f]{3,8})$/,Lm=new RegExp(`^rgb\\(${Jr},${Jr},${Jr}\\)$`),Pm=new RegExp(`^rgb\\(${Vt},${Vt},${Vt}\\)$`),Im=new RegExp(`^rgba\\(${Jr},${Jr},${Jr},${qn}\\)$`),zm=new RegExp(`^rgba\\(${Vt},${Vt},${Vt},${qn}\\)$`),Om=new RegExp(`^hsl\\(${qn},${Vt},${Vt}\\)$`),$m=new RegExp(`^hsla\\(${qn},${Vt},${Vt},${qn}\\)$`),$l={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};da(is,Un,{copy(r){return Object.assign(new this.constructor,this,r)},displayable(){return this.rgb().displayable()},hex:ql,formatHex:ql,formatHex8:qm,formatHsl:Um,formatRgb:Ul,toString:Ul});function ql(){return this.rgb().formatHex()}function qm(){return this.rgb().formatHex8()}function Um(){return hd(this).formatHsl()}function Ul(){return this.rgb().formatRgb()}function Un(r){var e,t;return r=(r+"").trim().toLowerCase(),(e=Fm.exec(r))?(t=e[1].length,e=parseInt(e[1],16),t===6?Wl(e):t===3?new Ct(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?ms(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?ms(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=Lm.exec(r))?new Ct(e[1],e[2],e[3],1):(e=Pm.exec(r))?new Ct(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=Im.exec(r))?ms(e[1],e[2],e[3],e[4]):(e=zm.exec(r))?ms(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=Om.exec(r))?Gl(e[1],e[2]/100,e[3]/100,1):(e=$m.exec(r))?Gl(e[1],e[2]/100,e[3]/100,e[4]):$l.hasOwnProperty(r)?Wl($l[r]):r==="transparent"?new Ct(NaN,NaN,NaN,0):null}function Wl(r){return new Ct(r>>16&255,r>>8&255,r&255,1)}function ms(r,e,t,n){return n<=0&&(r=e=t=NaN),new Ct(r,e,t,n)}function Wm(r){return r instanceof is||(r=Un(r)),r?(r=r.rgb(),new Ct(r.r,r.g,r.b,r.opacity)):new Ct}function wo(r,e,t,n){return arguments.length===1?Wm(r):new Ct(r,e,t,n??1)}function Ct(r,e,t,n){this.r=+r,this.g=+e,this.b=+t,this.opacity=+n}da(Ct,wo,fd(is,{brighter(r){return r=r==null?Js:Math.pow(Js,r),new Ct(this.r*r,this.g*r,this.b*r,this.opacity)},darker(r){return r=r==null?$n:Math.pow($n,r),new Ct(this.r*r,this.g*r,this.b*r,this.opacity)},rgb(){return this},clamp(){return new Ct(Tr(this.r),Tr(this.g),Tr(this.b),Xs(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Hl,formatHex:Hl,formatHex8:Hm,formatRgb:Vl,toString:Vl}));function Hl(){return`#${Sr(this.r)}${Sr(this.g)}${Sr(this.b)}`}function Hm(){return`#${Sr(this.r)}${Sr(this.g)}${Sr(this.b)}${Sr((isNaN(this.opacity)?1:this.opacity)*255)}`}function Vl(){const r=Xs(this.opacity);return`${r===1?"rgb(":"rgba("}${Tr(this.r)}, ${Tr(this.g)}, ${Tr(this.b)}${r===1?")":`, ${r})`}`}function Xs(r){return isNaN(r)?1:Math.max(0,Math.min(1,r))}function Tr(r){return Math.max(0,Math.min(255,Math.round(r)||0))}function Sr(r){return r=Tr(r),(r<16?"0":"")+r.toString(16)}function Gl(r,e,t,n){return n<=0?r=e=t=NaN:t<=0||t>=1?r=e=NaN:e<=0&&(r=NaN),new Lt(r,e,t,n)}function hd(r){if(r instanceof Lt)return new Lt(r.h,r.s,r.l,r.opacity);if(r instanceof is||(r=Un(r)),!r)return new Lt;if(r instanceof Lt)return r;r=r.rgb();var e=r.r/255,t=r.g/255,n=r.b/255,s=Math.min(e,t,n),i=Math.max(e,t,n),o=NaN,a=i-s,l=(i+s)/2;return a?(e===i?o=(t-n)/a+(t<n)*6:t===i?o=(n-e)/a+2:o=(e-t)/a+4,a/=l<.5?i+s:2-i-s,o*=60):a=l>0&&l<1?0:o,new Lt(o,a,l,r.opacity)}function Vm(r,e,t,n){return arguments.length===1?hd(r):new Lt(r,e,t,n??1)}function Lt(r,e,t,n){this.h=+r,this.s=+e,this.l=+t,this.opacity=+n}da(Lt,Vm,fd(is,{brighter(r){return r=r==null?Js:Math.pow(Js,r),new Lt(this.h,this.s,this.l*r,this.opacity)},darker(r){return r=r==null?$n:Math.pow($n,r),new Lt(this.h,this.s,this.l*r,this.opacity)},rgb(){var r=this.h%360+(this.h<0)*360,e=isNaN(r)||isNaN(this.s)?0:this.s,t=this.l,n=t+(t<.5?t:1-t)*e,s=2*t-n;return new Ct(qi(r>=240?r-240:r+120,s,n),qi(r,s,n),qi(r<120?r+240:r-120,s,n),this.opacity)},clamp(){return new Lt(Kl(this.h),ys(this.s),ys(this.l),Xs(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const r=Xs(this.opacity);return`${r===1?"hsl(":"hsla("}${Kl(this.h)}, ${ys(this.s)*100}%, ${ys(this.l)*100}%${r===1?")":`, ${r})`}`}}));function Kl(r){return r=(r||0)%360,r<0?r+360:r}function ys(r){return Math.max(0,Math.min(1,r||0))}function qi(r,e,t){return(r<60?e+(t-e)*r/60:r<180?t:r<240?e+(t-e)*(240-r)/60:e)*255}const pd=r=>()=>r;function Gm(r,e){return function(t){return r+t*e}}function Km(r,e,t){return r=Math.pow(r,t),e=Math.pow(e,t)-r,t=1/t,function(n){return Math.pow(r+n*e,t)}}function Ym(r){return(r=+r)==1?gd:function(e,t){return t-e?Km(e,t,r):pd(isNaN(e)?t:e)}}function gd(r,e){var t=e-r;return t?Gm(r,t):pd(isNaN(r)?e:r)}const Yl=function r(e){var t=Ym(e);function n(s,i){var o=t((s=wo(s)).r,(i=wo(i)).r),a=t(s.g,i.g),l=t(s.b,i.b),u=gd(s.opacity,i.opacity);return function(c){return s.r=o(c),s.g=a(c),s.b=l(c),s.opacity=u(c),s+""}}return n.gamma=r,n}(1);function dr(r,e){return r=+r,e=+e,function(t){return r*(1-t)+e*t}}var Co=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Ui=new RegExp(Co.source,"g");function Qm(r){return function(){return r}}function Jm(r){return function(e){return r(e)+""}}function Xm(r,e){var t=Co.lastIndex=Ui.lastIndex=0,n,s,i,o=-1,a=[],l=[];for(r=r+"",e=e+"";(n=Co.exec(r))&&(s=Ui.exec(e));)(i=s.index)>t&&(i=e.slice(t,i),a[o]?a[o]+=i:a[++o]=i),(n=n[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,l.push({i:o,x:dr(n,s)})),t=Ui.lastIndex;return t<e.length&&(i=e.slice(t),a[o]?a[o]+=i:a[++o]=i),a.length<2?l[0]?Jm(l[0].x):Qm(e):(e=l.length,function(u){for(var c=0,d;c<e;++c)a[(d=l[c]).i]=d.x(u);return a.join("")})}var Ql=180/Math.PI,So={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function md(r,e,t,n,s,i){var o,a,l;return(o=Math.sqrt(r*r+e*e))&&(r/=o,e/=o),(l=r*t+e*n)&&(t-=r*l,n-=e*l),(a=Math.sqrt(t*t+n*n))&&(t/=a,n/=a,l/=a),r*n<e*t&&(r=-r,e=-e,l=-l,o=-o),{translateX:s,translateY:i,rotate:Math.atan2(e,r)*Ql,skewX:Math.atan(l)*Ql,scaleX:o,scaleY:a}}var xs;function Zm(r){const e=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(r+"");return e.isIdentity?So:md(e.a,e.b,e.c,e.d,e.e,e.f)}function ey(r){return r==null||(xs||(xs=document.createElementNS("http://www.w3.org/2000/svg","g")),xs.setAttribute("transform",r),!(r=xs.transform.baseVal.consolidate()))?So:(r=r.matrix,md(r.a,r.b,r.c,r.d,r.e,r.f))}function yd(r,e,t,n){function s(u){return u.length?u.pop()+" ":""}function i(u,c,d,h,p,g){if(u!==d||c!==h){var m=p.push("translate(",null,e,null,t);g.push({i:m-4,x:dr(u,d)},{i:m-2,x:dr(c,h)})}else(d||h)&&p.push("translate("+d+e+h+t)}function o(u,c,d,h){u!==c?(u-c>180?c+=360:c-u>180&&(u+=360),h.push({i:d.push(s(d)+"rotate(",null,n)-2,x:dr(u,c)})):c&&d.push(s(d)+"rotate("+c+n)}function a(u,c,d,h){u!==c?h.push({i:d.push(s(d)+"skewX(",null,n)-2,x:dr(u,c)}):c&&d.push(s(d)+"skewX("+c+n)}function l(u,c,d,h,p,g){if(u!==d||c!==h){var m=p.push(s(p)+"scale(",null,",",null,")");g.push({i:m-4,x:dr(u,d)},{i:m-2,x:dr(c,h)})}else(d!==1||h!==1)&&p.push(s(p)+"scale("+d+","+h+")")}return function(u,c){var d=[],h=[];return u=r(u),c=r(c),i(u.translateX,u.translateY,c.translateX,c.translateY,d,h),o(u.rotate,c.rotate,d,h),a(u.skewX,c.skewX,d,h),l(u.scaleX,u.scaleY,c.scaleX,c.scaleY,d,h),u=c=null,function(p){for(var g=-1,m=h.length,x;++g<m;)d[(x=h[g]).i]=x.x(p);return d.join("")}}}var ty=yd(Zm,"px, ","px)","deg)"),ry=yd(ey,", ",")",")"),ny=1e-12;function Jl(r){return((r=Math.exp(r))+1/r)/2}function sy(r){return((r=Math.exp(r))-1/r)/2}function iy(r){return((r=Math.exp(2*r))-1)/(r+1)}const oy=function r(e,t,n){function s(i,o){var a=i[0],l=i[1],u=i[2],c=o[0],d=o[1],h=o[2],p=c-a,g=d-l,m=p*p+g*g,x,_;if(m<ny)_=Math.log(h/u)/e,x=function(v){return[a+v*p,l+v*g,u*Math.exp(e*v*_)]};else{var b=Math.sqrt(m),S=(h*h-u*u+n*m)/(2*u*t*b),C=(h*h-u*u-n*m)/(2*h*t*b),k=Math.log(Math.sqrt(S*S+1)-S),E=Math.log(Math.sqrt(C*C+1)-C);_=(E-k)/e,x=function(v){var T=v*_,B=Jl(k),j=u/(t*b)*(B*iy(e*T+k)-sy(k));return[a+j*p,l+j*g,u*B/Jl(e*T+k)]}}return x.duration=_*1e3*e/Math.SQRT2,x}return s.rho=function(i){var o=Math.max(.001,+i),a=o*o,l=a*a;return r(o,a,l)},s}(Math.SQRT2,2,4);var nn=0,Cn=0,yn=0,xd=1e3,Zs,Sn,ei=0,Lr=0,wi=0,Wn=typeof performance=="object"&&performance.now?performance:Date,bd=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(r){setTimeout(r,17)};function fa(){return Lr||(bd(ay),Lr=Wn.now()+wi)}function ay(){Lr=0}function ti(){this._call=this._time=this._next=null}ti.prototype=vd.prototype={constructor:ti,restart:function(r,e,t){if(typeof r!="function")throw new TypeError("callback is not a function");t=(t==null?fa():+t)+(e==null?0:+e),!this._next&&Sn!==this&&(Sn?Sn._next=this:Zs=this,Sn=this),this._call=r,this._time=t,ko()},stop:function(){this._call&&(this._call=null,this._time=1/0,ko())}};function vd(r,e,t){var n=new ti;return n.restart(r,e,t),n}function ly(){fa(),++nn;for(var r=Zs,e;r;)(e=Lr-r._time)>=0&&r._call.call(void 0,e),r=r._next;--nn}function Xl(){Lr=(ei=Wn.now())+wi,nn=Cn=0;try{ly()}finally{nn=0,cy(),Lr=0}}function uy(){var r=Wn.now(),e=r-ei;e>xd&&(wi-=e,ei=r)}function cy(){for(var r,e=Zs,t,n=1/0;e;)e._call?(n>e._time&&(n=e._time),r=e,e=e._next):(t=e._next,e._next=null,e=r?r._next=t:Zs=t);Sn=r,ko(n)}function ko(r){if(!nn){Cn&&(Cn=clearTimeout(Cn));var e=r-Lr;e>24?(r<1/0&&(Cn=setTimeout(Xl,r-Wn.now()-wi)),yn&&(yn=clearInterval(yn))):(yn||(ei=Wn.now(),yn=setInterval(uy,xd)),nn=1,bd(Xl))}}function Zl(r,e,t){var n=new ti;return e=e==null?0:+e,n.restart(s=>{n.stop(),r(s+e)},e,t),n}var dy=la("start","end","cancel","interrupt"),fy=[],_d=0,eu=1,Eo=2,Ss=3,tu=4,Do=5,ks=6;function Ci(r,e,t,n,s,i){var o=r.__transition;if(!o)r.__transition={};else if(t in o)return;hy(r,t,{name:e,index:n,group:s,on:dy,tween:fy,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:_d})}function ha(r,e){var t=$t(r,e);if(t.state>_d)throw new Error("too late; already scheduled");return t}function Jt(r,e){var t=$t(r,e);if(t.state>Ss)throw new Error("too late; already running");return t}function $t(r,e){var t=r.__transition;if(!t||!(t=t[e]))throw new Error("transition not found");return t}function hy(r,e,t){var n=r.__transition,s;n[e]=t,t.timer=vd(i,0,t.time);function i(u){t.state=eu,t.timer.restart(o,t.delay,t.time),t.delay<=u&&o(u-t.delay)}function o(u){var c,d,h,p;if(t.state!==eu)return l();for(c in n)if(p=n[c],p.name===t.name){if(p.state===Ss)return Zl(o);p.state===tu?(p.state=ks,p.timer.stop(),p.on.call("interrupt",r,r.__data__,p.index,p.group),delete n[c]):+c<e&&(p.state=ks,p.timer.stop(),p.on.call("cancel",r,r.__data__,p.index,p.group),delete n[c])}if(Zl(function(){t.state===Ss&&(t.state=tu,t.timer.restart(a,t.delay,t.time),a(u))}),t.state=Eo,t.on.call("start",r,r.__data__,t.index,t.group),t.state===Eo){for(t.state=Ss,s=new Array(h=t.tween.length),c=0,d=-1;c<h;++c)(p=t.tween[c].value.call(r,r.__data__,t.index,t.group))&&(s[++d]=p);s.length=d+1}}function a(u){for(var c=u<t.duration?t.ease.call(null,u/t.duration):(t.timer.restart(l),t.state=Do,1),d=-1,h=s.length;++d<h;)s[d].call(r,c);t.state===Do&&(t.on.call("end",r,r.__data__,t.index,t.group),l())}function l(){t.state=ks,t.timer.stop(),delete n[e];for(var u in n)return;delete r.__transition}}function Es(r,e){var t=r.__transition,n,s,i=!0,o;if(t){e=e==null?null:e+"";for(o in t){if((n=t[o]).name!==e){i=!1;continue}s=n.state>Eo&&n.state<Do,n.state=ks,n.timer.stop(),n.on.call(s?"interrupt":"cancel",r,r.__data__,n.index,n.group),delete t[o]}i&&delete r.__transition}}function py(r){return this.each(function(){Es(this,r)})}function gy(r,e){var t,n;return function(){var s=Jt(this,r),i=s.tween;if(i!==t){n=t=i;for(var o=0,a=n.length;o<a;++o)if(n[o].name===e){n=n.slice(),n.splice(o,1);break}}s.tween=n}}function my(r,e,t){var n,s;if(typeof t!="function")throw new Error;return function(){var i=Jt(this,r),o=i.tween;if(o!==n){s=(n=o).slice();for(var a={name:e,value:t},l=0,u=s.length;l<u;++l)if(s[l].name===e){s[l]=a;break}l===u&&s.push(a)}i.tween=s}}function yy(r,e){var t=this._id;if(r+="",arguments.length<2){for(var n=$t(this.node(),t).tween,s=0,i=n.length,o;s<i;++s)if((o=n[s]).name===r)return o.value;return null}return this.each((e==null?gy:my)(t,r,e))}function pa(r,e,t){var n=r._id;return r.each(function(){var s=Jt(this,n);(s.value||(s.value={}))[e]=t.apply(this,arguments)}),function(s){return $t(s,n).value[e]}}function wd(r,e){var t;return(typeof e=="number"?dr:e instanceof Un?Yl:(t=Un(e))?(e=t,Yl):Xm)(r,e)}function xy(r){return function(){this.removeAttribute(r)}}function by(r){return function(){this.removeAttributeNS(r.space,r.local)}}function vy(r,e,t){var n,s=t+"",i;return function(){var o=this.getAttribute(r);return o===s?null:o===n?i:i=e(n=o,t)}}function _y(r,e,t){var n,s=t+"",i;return function(){var o=this.getAttributeNS(r.space,r.local);return o===s?null:o===n?i:i=e(n=o,t)}}function wy(r,e,t){var n,s,i;return function(){var o,a=t(this),l;return a==null?void this.removeAttribute(r):(o=this.getAttribute(r),l=a+"",o===l?null:o===n&&l===s?i:(s=l,i=e(n=o,a)))}}function Cy(r,e,t){var n,s,i;return function(){var o,a=t(this),l;return a==null?void this.removeAttributeNS(r.space,r.local):(o=this.getAttributeNS(r.space,r.local),l=a+"",o===l?null:o===n&&l===s?i:(s=l,i=e(n=o,a)))}}function Sy(r,e){var t=_i(r),n=t==="transform"?ry:wd;return this.attrTween(r,typeof e=="function"?(t.local?Cy:wy)(t,n,pa(this,"attr."+r,e)):e==null?(t.local?by:xy)(t):(t.local?_y:vy)(t,n,e))}function ky(r,e){return function(t){this.setAttribute(r,e.call(this,t))}}function Ey(r,e){return function(t){this.setAttributeNS(r.space,r.local,e.call(this,t))}}function Dy(r,e){var t,n;function s(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&Ey(r,i)),t}return s._value=e,s}function Ay(r,e){var t,n;function s(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&ky(r,i)),t}return s._value=e,s}function Ty(r,e){var t="attr."+r;if(arguments.length<2)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;var n=_i(r);return this.tween(t,(n.local?Dy:Ay)(n,e))}function Ny(r,e){return function(){ha(this,r).delay=+e.apply(this,arguments)}}function By(r,e){return e=+e,function(){ha(this,r).delay=e}}function jy(r){var e=this._id;return arguments.length?this.each((typeof r=="function"?Ny:By)(e,r)):$t(this.node(),e).delay}function My(r,e){return function(){Jt(this,r).duration=+e.apply(this,arguments)}}function Ry(r,e){return e=+e,function(){Jt(this,r).duration=e}}function Fy(r){var e=this._id;return arguments.length?this.each((typeof r=="function"?My:Ry)(e,r)):$t(this.node(),e).duration}function Ly(r,e){if(typeof e!="function")throw new Error;return function(){Jt(this,r).ease=e}}function Py(r){var e=this._id;return arguments.length?this.each(Ly(e,r)):$t(this.node(),e).ease}function Iy(r,e){return function(){var t=e.apply(this,arguments);if(typeof t!="function")throw new Error;Jt(this,r).ease=t}}function zy(r){if(typeof r!="function")throw new Error;return this.each(Iy(this._id,r))}function Oy(r){typeof r!="function"&&(r=rd(r));for(var e=this._groups,t=e.length,n=new Array(t),s=0;s<t;++s)for(var i=e[s],o=i.length,a=n[s]=[],l,u=0;u<o;++u)(l=i[u])&&r.call(l,l.__data__,u,i)&&a.push(l);return new sr(n,this._parents,this._name,this._id)}function $y(r){if(r._id!==this._id)throw new Error;for(var e=this._groups,t=r._groups,n=e.length,s=t.length,i=Math.min(n,s),o=new Array(n),a=0;a<i;++a)for(var l=e[a],u=t[a],c=l.length,d=o[a]=new Array(c),h,p=0;p<c;++p)(h=l[p]||u[p])&&(d[p]=h);for(;a<n;++a)o[a]=e[a];return new sr(o,this._parents,this._name,this._id)}function qy(r){return(r+"").trim().split(/^|\s+/).every(function(e){var t=e.indexOf(".");return t>=0&&(e=e.slice(0,t)),!e||e==="start"})}function Uy(r,e,t){var n,s,i=qy(e)?ha:Jt;return function(){var o=i(this,r),a=o.on;a!==n&&(s=(n=a).copy()).on(e,t),o.on=s}}function Wy(r,e){var t=this._id;return arguments.length<2?$t(this.node(),t).on.on(r):this.each(Uy(t,r,e))}function Hy(r){return function(){var e=this.parentNode;for(var t in this.__transition)if(+t!==r)return;e&&e.removeChild(this)}}function Vy(){return this.on("end.remove",Hy(this._id))}function Gy(r){var e=this._name,t=this._id;typeof r!="function"&&(r=ua(r));for(var n=this._groups,s=n.length,i=new Array(s),o=0;o<s;++o)for(var a=n[o],l=a.length,u=i[o]=new Array(l),c,d,h=0;h<l;++h)(c=a[h])&&(d=r.call(c,c.__data__,h,a))&&("__data__"in c&&(d.__data__=c.__data__),u[h]=d,Ci(u[h],e,t,h,u,$t(c,t)));return new sr(i,this._parents,e,t)}function Ky(r){var e=this._name,t=this._id;typeof r!="function"&&(r=td(r));for(var n=this._groups,s=n.length,i=[],o=[],a=0;a<s;++a)for(var l=n[a],u=l.length,c,d=0;d<u;++d)if(c=l[d]){for(var h=r.call(c,c.__data__,d,l),p,g=$t(c,t),m=0,x=h.length;m<x;++m)(p=h[m])&&Ci(p,e,t,m,h,g);i.push(h),o.push(c)}return new sr(i,o,e,t)}var Yy=ss.prototype.constructor;function Qy(){return new Yy(this._groups,this._parents)}function Jy(r,e){var t,n,s;return function(){var i=rn(this,r),o=(this.style.removeProperty(r),rn(this,r));return i===o?null:i===t&&o===n?s:s=e(t=i,n=o)}}function Cd(r){return function(){this.style.removeProperty(r)}}function Xy(r,e,t){var n,s=t+"",i;return function(){var o=rn(this,r);return o===s?null:o===n?i:i=e(n=o,t)}}function Zy(r,e,t){var n,s,i;return function(){var o=rn(this,r),a=t(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(r),rn(this,r))),o===l?null:o===n&&l===s?i:(s=l,i=e(n=o,a))}}function e2(r,e){var t,n,s,i="style."+e,o="end."+i,a;return function(){var l=Jt(this,r),u=l.on,c=l.value[i]==null?a||(a=Cd(e)):void 0;(u!==t||s!==c)&&(n=(t=u).copy()).on(o,s=c),l.on=n}}function t2(r,e,t){var n=(r+="")=="transform"?ty:wd;return e==null?this.styleTween(r,Jy(r,n)).on("end.style."+r,Cd(r)):typeof e=="function"?this.styleTween(r,Zy(r,n,pa(this,"style."+r,e))).each(e2(this._id,r)):this.styleTween(r,Xy(r,n,e),t).on("end.style."+r,null)}function r2(r,e,t){return function(n){this.style.setProperty(r,e.call(this,n),t)}}function n2(r,e,t){var n,s;function i(){var o=e.apply(this,arguments);return o!==s&&(n=(s=o)&&r2(r,o,t)),n}return i._value=e,i}function s2(r,e,t){var n="style."+(r+="");if(arguments.length<2)return(n=this.tween(n))&&n._value;if(e==null)return this.tween(n,null);if(typeof e!="function")throw new Error;return this.tween(n,n2(r,e,t??""))}function i2(r){return function(){this.textContent=r}}function o2(r){return function(){var e=r(this);this.textContent=e??""}}function a2(r){return this.tween("text",typeof r=="function"?o2(pa(this,"text",r)):i2(r==null?"":r+""))}function l2(r){return function(e){this.textContent=r.call(this,e)}}function u2(r){var e,t;function n(){var s=r.apply(this,arguments);return s!==t&&(e=(t=s)&&l2(s)),e}return n._value=r,n}function c2(r){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(r==null)return this.tween(e,null);if(typeof r!="function")throw new Error;return this.tween(e,u2(r))}function d2(){for(var r=this._name,e=this._id,t=Sd(),n=this._groups,s=n.length,i=0;i<s;++i)for(var o=n[i],a=o.length,l,u=0;u<a;++u)if(l=o[u]){var c=$t(l,e);Ci(l,r,t,u,o,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new sr(n,this._parents,r,t)}function f2(){var r,e,t=this,n=t._id,s=t.size();return new Promise(function(i,o){var a={value:o},l={value:function(){--s===0&&i()}};t.each(function(){var u=Jt(this,n),c=u.on;c!==r&&(e=(r=c).copy(),e._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),u.on=e}),s===0&&i()})}var h2=0;function sr(r,e,t,n){this._groups=r,this._parents=e,this._name=t,this._id=n}function Sd(){return++h2}var er=ss.prototype;sr.prototype={constructor:sr,select:Gy,selectAll:Ky,selectChild:er.selectChild,selectChildren:er.selectChildren,filter:Oy,merge:$y,selection:Qy,transition:d2,call:er.call,nodes:er.nodes,node:er.node,size:er.size,empty:er.empty,each:er.each,on:Wy,attr:Sy,attrTween:Ty,style:t2,styleTween:s2,text:a2,textTween:c2,remove:Vy,tween:yy,delay:jy,duration:Fy,ease:Py,easeVarying:zy,end:f2,[Symbol.iterator]:er[Symbol.iterator]};function p2(r){return((r*=2)<=1?r*r*r:(r-=2)*r*r+2)/2}var g2={time:null,delay:0,duration:250,ease:p2};function m2(r,e){for(var t;!(t=r.__transition)||!(t=t[e]);)if(!(r=r.parentNode))throw new Error(`transition ${e} not found`);return t}function y2(r){var e,t;r instanceof sr?(e=r._id,r=r._name):(e=Sd(),(t=g2).time=fa(),r=r==null?null:r+"");for(var n=this._groups,s=n.length,i=0;i<s;++i)for(var o=n[i],a=o.length,l,u=0;u<a;++u)(l=o[u])&&Ci(l,r,e,u,o,t||m2(l,e));return new sr(n,this._parents,r,e)}ss.prototype.interrupt=py;ss.prototype.transition=y2;const bs=r=>()=>r;function x2(r,{sourceEvent:e,target:t,transform:n,dispatch:s}){Object.defineProperties(this,{type:{value:r,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:t,enumerable:!0,configurable:!0},transform:{value:n,enumerable:!0,configurable:!0},_:{value:s}})}function rr(r,e,t){this.k=r,this.x=e,this.y=t}rr.prototype={constructor:rr,scale:function(r){return r===1?this:new rr(this.k*r,this.x,this.y)},translate:function(r,e){return r===0&e===0?this:new rr(this.k,this.x+this.k*r,this.y+this.k*e)},apply:function(r){return[r[0]*this.k+this.x,r[1]*this.k+this.y]},applyX:function(r){return r*this.k+this.x},applyY:function(r){return r*this.k+this.y},invert:function(r){return[(r[0]-this.x)/this.k,(r[1]-this.y)/this.k]},invertX:function(r){return(r-this.x)/this.k},invertY:function(r){return(r-this.y)/this.k},rescaleX:function(r){return r.copy().domain(r.range().map(this.invertX,this).map(r.invert,r))},rescaleY:function(r){return r.copy().domain(r.range().map(this.invertY,this).map(r.invert,r))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ri=new rr(1,0,0);rr.prototype;function Wi(r){r.stopImmediatePropagation()}function xn(r){r.preventDefault(),r.stopImmediatePropagation()}function b2(r){return(!r.ctrlKey||r.type==="wheel")&&!r.button}function v2(){var r=this;return r instanceof SVGElement?(r=r.ownerSVGElement||r,r.hasAttribute("viewBox")?(r=r.viewBox.baseVal,[[r.x,r.y],[r.x+r.width,r.y+r.height]]):[[0,0],[r.width.baseVal.value,r.height.baseVal.value]]):[[0,0],[r.clientWidth,r.clientHeight]]}function ru(){return this.__zoom||ri}function _2(r){return-r.deltaY*(r.deltaMode===1?.05:r.deltaMode?1:.002)*(r.ctrlKey?10:1)}function w2(){return navigator.maxTouchPoints||"ontouchstart"in this}function C2(r,e,t){var n=r.invertX(e[0][0])-t[0][0],s=r.invertX(e[1][0])-t[1][0],i=r.invertY(e[0][1])-t[0][1],o=r.invertY(e[1][1])-t[1][1];return r.translate(s>n?(n+s)/2:Math.min(0,n)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function S2(){var r=b2,e=v2,t=C2,n=_2,s=w2,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,l=oy,u=la("start","zoom","end"),c,d,h,p=500,g=150,m=0,x=10;function _(w){w.property("__zoom",ru).on("wheel.zoom",T,{passive:!1}).on("mousedown.zoom",B).on("dblclick.zoom",j).filter(s).on("touchstart.zoom",N).on("touchmove.zoom",R).on("touchend.zoom touchcancel.zoom",M).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}_.transform=function(w,D,F,I){var q=w.selection?w.selection():w;q.property("__zoom",ru),w!==q?k(w,D,F,I):q.interrupt().each(function(){E(this,arguments).event(I).start().zoom(null,typeof D=="function"?D.apply(this,arguments):D).end()})},_.scaleBy=function(w,D,F,I){_.scaleTo(w,function(){var q=this.__zoom.k,Z=typeof D=="function"?D.apply(this,arguments):D;return q*Z},F,I)},_.scaleTo=function(w,D,F,I){_.transform(w,function(){var q=e.apply(this,arguments),Z=this.__zoom,te=F==null?C(q):typeof F=="function"?F.apply(this,arguments):F,W=Z.invert(te),Q=typeof D=="function"?D.apply(this,arguments):D;return t(S(b(Z,Q),te,W),q,o)},F,I)},_.translateBy=function(w,D,F,I){_.transform(w,function(){return t(this.__zoom.translate(typeof D=="function"?D.apply(this,arguments):D,typeof F=="function"?F.apply(this,arguments):F),e.apply(this,arguments),o)},null,I)},_.translateTo=function(w,D,F,I,q){_.transform(w,function(){var Z=e.apply(this,arguments),te=this.__zoom,W=I==null?C(Z):typeof I=="function"?I.apply(this,arguments):I;return t(ri.translate(W[0],W[1]).scale(te.k).translate(typeof D=="function"?-D.apply(this,arguments):-D,typeof F=="function"?-F.apply(this,arguments):-F),Z,o)},I,q)};function b(w,D){return D=Math.max(i[0],Math.min(i[1],D)),D===w.k?w:new rr(D,w.x,w.y)}function S(w,D,F){var I=D[0]-F[0]*w.k,q=D[1]-F[1]*w.k;return I===w.x&&q===w.y?w:new rr(w.k,I,q)}function C(w){return[(+w[0][0]+ +w[1][0])/2,(+w[0][1]+ +w[1][1])/2]}function k(w,D,F,I){w.on("start.zoom",function(){E(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){E(this,arguments).event(I).end()}).tween("zoom",function(){var q=this,Z=arguments,te=E(q,Z).event(I),W=e.apply(q,Z),Q=F==null?C(W):typeof F=="function"?F.apply(q,Z):F,H=Math.max(W[1][0]-W[0][0],W[1][1]-W[0][1]),ie=q.__zoom,ue=typeof D=="function"?D.apply(q,Z):D,de=l(ie.invert(Q).concat(H/ie.k),ue.invert(Q).concat(H/ue.k));return function(we){if(we===1)we=ue;else{var fe=de(we),Ce=H/fe[2];we=new rr(Ce,Q[0]-fe[0]*Ce,Q[1]-fe[1]*Ce)}te.zoom(null,we)}})}function E(w,D,F){return!F&&w.__zooming||new v(w,D)}function v(w,D){this.that=w,this.args=D,this.active=0,this.sourceEvent=null,this.extent=e.apply(w,D),this.taps=0}v.prototype={event:function(w){return w&&(this.sourceEvent=w),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(w,D){return this.mouse&&w!=="mouse"&&(this.mouse[1]=D.invert(this.mouse[0])),this.touch0&&w!=="touch"&&(this.touch0[1]=D.invert(this.touch0[0])),this.touch1&&w!=="touch"&&(this.touch1[1]=D.invert(this.touch1[0])),this.that.__zoom=D,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(w){var D=Ft(this.that).datum();u.call(w,this.that,new x2(w,{sourceEvent:this.sourceEvent,target:_,transform:this.that.__zoom,dispatch:u}),D)}};function T(w,...D){if(!r.apply(this,arguments))return;var F=E(this,D).event(w),I=this.__zoom,q=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,n.apply(this,arguments)))),Z=wr(w);if(F.wheel)(F.mouse[0][0]!==Z[0]||F.mouse[0][1]!==Z[1])&&(F.mouse[1]=I.invert(F.mouse[0]=Z)),clearTimeout(F.wheel);else{if(I.k===q)return;F.mouse=[Z,I.invert(Z)],Es(this),F.start()}xn(w),F.wheel=setTimeout(te,g),F.zoom("mouse",t(S(b(I,q),F.mouse[0],F.mouse[1]),F.extent,o));function te(){F.wheel=null,F.end()}}function B(w,...D){if(h||!r.apply(this,arguments))return;var F=w.currentTarget,I=E(this,D,!0).event(w),q=Ft(w.view).on("mousemove.zoom",Q,!0).on("mouseup.zoom",H,!0),Z=wr(w,F),te=w.clientX,W=w.clientY;Mm(w.view),Wi(w),I.mouse=[Z,this.__zoom.invert(Z)],Es(this),I.start();function Q(ie){if(xn(ie),!I.moved){var ue=ie.clientX-te,de=ie.clientY-W;I.moved=ue*ue+de*de>m}I.event(ie).zoom("mouse",t(S(I.that.__zoom,I.mouse[0]=wr(ie,F),I.mouse[1]),I.extent,o))}function H(ie){q.on("mousemove.zoom mouseup.zoom",null),Rm(ie.view,I.moved),xn(ie),I.event(ie).end()}}function j(w,...D){if(r.apply(this,arguments)){var F=this.__zoom,I=wr(w.changedTouches?w.changedTouches[0]:w,this),q=F.invert(I),Z=F.k*(w.shiftKey?.5:2),te=t(S(b(F,Z),I,q),e.apply(this,D),o);xn(w),a>0?Ft(this).transition().duration(a).call(k,te,I,w):Ft(this).call(_.transform,te,I,w)}}function N(w,...D){if(r.apply(this,arguments)){var F=w.touches,I=F.length,q=E(this,D,w.changedTouches.length===I).event(w),Z,te,W,Q;for(Wi(w),te=0;te<I;++te)W=F[te],Q=wr(W,this),Q=[Q,this.__zoom.invert(Q),W.identifier],q.touch0?!q.touch1&&q.touch0[2]!==Q[2]&&(q.touch1=Q,q.taps=0):(q.touch0=Q,Z=!0,q.taps=1+!!c);c&&(c=clearTimeout(c)),Z&&(q.taps<2&&(d=Q[0],c=setTimeout(function(){c=null},p)),Es(this),q.start())}}function R(w,...D){if(this.__zooming){var F=E(this,D).event(w),I=w.changedTouches,q=I.length,Z,te,W,Q;for(xn(w),Z=0;Z<q;++Z)te=I[Z],W=wr(te,this),F.touch0&&F.touch0[2]===te.identifier?F.touch0[0]=W:F.touch1&&F.touch1[2]===te.identifier&&(F.touch1[0]=W);if(te=F.that.__zoom,F.touch1){var H=F.touch0[0],ie=F.touch0[1],ue=F.touch1[0],de=F.touch1[1],we=(we=ue[0]-H[0])*we+(we=ue[1]-H[1])*we,fe=(fe=de[0]-ie[0])*fe+(fe=de[1]-ie[1])*fe;te=b(te,Math.sqrt(we/fe)),W=[(H[0]+ue[0])/2,(H[1]+ue[1])/2],Q=[(ie[0]+de[0])/2,(ie[1]+de[1])/2]}else if(F.touch0)W=F.touch0[0],Q=F.touch0[1];else return;F.zoom("touch",t(S(te,W,Q),F.extent,o))}}function M(w,...D){if(this.__zooming){var F=E(this,D).event(w),I=w.changedTouches,q=I.length,Z,te;for(Wi(w),h&&clearTimeout(h),h=setTimeout(function(){h=null},p),Z=0;Z<q;++Z)te=I[Z],F.touch0&&F.touch0[2]===te.identifier?delete F.touch0:F.touch1&&F.touch1[2]===te.identifier&&delete F.touch1;if(F.touch1&&!F.touch0&&(F.touch0=F.touch1,delete F.touch1),F.touch0)F.touch0[1]=this.__zoom.invert(F.touch0[0]);else if(F.end(),F.taps===2&&(te=wr(te,this),Math.hypot(d[0]-te[0],d[1]-te[1])<x)){var W=Ft(this).on("dblclick.zoom");W&&W.apply(this,arguments)}}}return _.wheelDelta=function(w){return arguments.length?(n=typeof w=="function"?w:bs(+w),_):n},_.filter=function(w){return arguments.length?(r=typeof w=="function"?w:bs(!!w),_):r},_.touchable=function(w){return arguments.length?(s=typeof w=="function"?w:bs(!!w),_):s},_.extent=function(w){return arguments.length?(e=typeof w=="function"?w:bs([[+w[0][0],+w[0][1]],[+w[1][0],+w[1][1]]]),_):e},_.scaleExtent=function(w){return arguments.length?(i[0]=+w[0],i[1]=+w[1],_):[i[0],i[1]]},_.translateExtent=function(w){return arguments.length?(o[0][0]=+w[0][0],o[1][0]=+w[1][0],o[0][1]=+w[0][1],o[1][1]=+w[1][1],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(w){return arguments.length?(t=w,_):t},_.duration=function(w){return arguments.length?(a=+w,_):a},_.interpolate=function(w){return arguments.length?(l=w,_):l},_.on=function(){var w=u.on.apply(u,arguments);return w===u?_:w},_.clickDistance=function(w){return arguments.length?(m=(w=+w)*w,_):Math.sqrt(m)},_.tapDistance=function(w){return arguments.length?(x=+w,_):x},_}function kd(r={}){const{minZoom:e=.1,maxZoom:t=4,initialTransform:n,zoomable:s=!0,pannable:i=!0,onTransformChange:o}=r,a=y.useRef(null),l=y.useRef(),[u,c]=y.useState(n||{x:0,y:0,k:1});y.useEffect(()=>{if(!a.current)return;const x=S2().scaleExtent([e,t]).filter(b=>!s&&b.type==="wheel"||!i&&(b.type==="mousedown"||b.type==="touchstart")?!1:b.type==="wheel"?s:b.type==="mousedown"||b.type==="touchstart"?b.target.closest("[data-qmap-node]")?!1:i:!0).on("zoom",b=>{const S={x:b.transform.x,y:b.transform.y,k:b.transform.k};c(S),o==null||o(S)});l.current=x;const _=Ft(a.current);return _.call(x),_.on("dblclick.zoom",null),n&&_.call(x.transform,ri.translate(n.x,n.y).scale(n.k)),()=>{_.on(".zoom",null)}},[e,t,s,i]),y.useEffect(()=>{l.current&&l.current.on("zoom",x=>{const _={x:x.transform.x,y:x.transform.y,k:x.transform.k};c(_),o==null||o(_)})},[o]);const d=y.useCallback((x,_,b,S=!0)=>{if(!a.current||!l.current)return;const C=Ft(a.current),k=ri.translate(x,_).scale(b);C.call(l.current.transform,k)},[]),h=y.useCallback(()=>{!a.current||!l.current||Ft(a.current).call(l.current.scaleBy,1.3)},[]),p=y.useCallback(()=>{!a.current||!l.current||Ft(a.current).call(l.current.scaleBy,.7)},[]),g=y.useCallback(()=>{d(0,0,1,!0)},[d]),m=y.useCallback((x,_=50)=>{if(!a.current||!l.current||x.length===0)return;const b=a.current,S=b.clientWidth,C=b.clientHeight;let k=1/0,E=1/0,v=-1/0,T=-1/0;for(const q of x){const Z=q.width||200,te=q.height||100;k=Math.min(k,q.x),E=Math.min(E,q.y),v=Math.max(v,q.x+Z),T=Math.max(T,q.y+te)}const B=v-k,j=T-E,N=(S-_*2)/B,R=(C-_*2)/j,M=Math.min(N,R,t),w=(k+v)/2,D=(E+T)/2,F=S/2-w*M,I=C/2-D*M;d(F,I,M,!0)},[t,d]);return{transform:u,containerRef:a,zoomTo:d,zoomIn:h,zoomOut:p,resetZoom:g,fitToContent:m}}function Ed(r){const{transform:e,onDragStart:t,onDragMove:n,onDragEnd:s,disabled:i=!1}=r,[o,a]=y.useState(null),[l,u]=y.useState(!1),[c,d]=y.useState({x:0,y:0}),h=y.useRef(null),p=y.useRef({x:0,y:0}),g=y.useRef(e);y.useEffect(()=>{g.current=e},[e]);const m=y.useCallback((S,C)=>{const k=g.current;return{x:(S-k.x)/k.k,y:(C-k.y)/k.k}},[]),x=y.useCallback((S,C)=>{if(i)return;C.preventDefault(),C.stopPropagation();const k=C.currentTarget,E=parseFloat(k.dataset.x||"0"),v=parseFloat(k.dataset.y||"0");h.current={x:C.clientX,y:C.clientY,nodeX:E,nodeY:v},p.current={x:E,y:v},a(S),u(!0),d({x:0,y:0}),t==null||t(S)},[i,m,t]),_=y.useCallback(S=>{if(!l||!o||!h.current)return;const C=g.current,k=h.current,E=S.clientX-k.x,v=S.clientY-k.y,T=E/C.k,B=v/C.k,j=k.nodeX+T,N=k.nodeY+B;p.current={x:j,y:N},d({x:T,y:B}),n==null||n(o,j,N,T,B)},[l,o,n]),b=y.useCallback(()=>{if(!l||!o)return;const S=p.current;s==null||s(o,S.x,S.y),a(null),u(!1),d({x:0,y:0}),h.current=null},[l,o,s]);return y.useEffect(()=>{if(!l)return;const S=k=>{_(k)},C=()=>{b()};return window.addEventListener("mousemove",S),window.addEventListener("mouseup",C),()=>{window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",C)}},[l,_,b]),{draggedNodeId:o,isDragging:l,dragOffset:c,startDrag:x,updateDrag:_,endDrag:b}}function Dd(r){const{transform:e,nodePositions:t,disabled:n=!1,controlledSelectedIds:s,onSelectionChange:i}=r,[o,a]=y.useState(new Set),l=s!==void 0,u=l?new Set(s):o,c=l?j=>{const N=typeof j=="function"?j(u):j;i==null||i(Array.from(N))}:a,[d,h]=y.useState(null),[p,g]=y.useState(!1),m=y.useRef(null),x=y.useRef(e),_=y.useRef(t);y.useEffect(()=>{x.current=e},[e]),y.useEffect(()=>{_.current=t},[t]);const b=y.useCallback((j,N)=>{const R=x.current;return{x:(j-R.x)/R.k,y:(N-R.y)/R.k}},[]),S=y.useCallback((j,N)=>{const R=_.current.get(j);if(!R)return!1;const M=R.width||200,w=R.height||100;return R.x<N.x+N.width&&R.x+M>N.x&&R.y<N.y+N.height&&R.y+w>N.y},[]),C=y.useCallback(j=>{if(n||j.target.closest("[data-qmap-node]"))return;j.preventDefault();const R=b(j.clientX,j.clientY);m.current=R,h({x:R.x,y:R.y,width:0,height:0}),g(!0),j.shiftKey||c(new Set)},[n,b]),k=y.useCallback(j=>{if(!p||!m.current)return;const N=m.current,R=b(j.clientX,j.clientY),M={x:Math.min(N.x,R.x),y:Math.min(N.y,R.y),width:Math.abs(R.x-N.x),height:Math.abs(R.y-N.y)};h(M);const w=new Set;for(const[D]of _.current)S(D,M)&&w.add(D);c(w)},[p,b,S]),E=y.useCallback(()=>{p&&(i==null||i(Array.from(u)),g(!1),h(null),m.current=null)},[p,u,i]);y.useEffect(()=>{if(!p)return;const j=R=>{k(R)},N=()=>{E()};return window.addEventListener("mousemove",j),window.addEventListener("mouseup",N),()=>{window.removeEventListener("mousemove",j),window.removeEventListener("mouseup",N)}},[p,k,E]);const v=y.useCallback((j,N=!1)=>{c(R=>{const M=new Set(N?R:[]);return R.has(j)&&N?M.delete(j):M.add(j),i==null||i(Array.from(M)),M})},[i]),T=y.useCallback(()=>{const j=new Set(_.current.keys());c(j),i==null||i(Array.from(j))},[i]),B=y.useCallback(()=>{c(new Set),i==null||i([])},[i]);return{selectedIds:u,setSelectedIds:c,selectionBox:d,isSelecting:p,startSelection:C,updateSelection:k,endSelection:E,toggleSelect:v,selectAll:T,clearSelection:B}}const Ad=y.memo(function({nodeId:e,position:t,isSelected:n,isDragging:s,draggable:i,onDragStart:o,onClick:a,onDoubleClick:l,onContextMenu:u,nodeRef:c,children:d}){const h=y.useCallback(_=>{i&&_.button===0&&o(e,_)},[e,i,o]),p=y.useCallback(_=>{s||a==null||a(_)},[s,a]),g=y.useCallback(_=>{_.stopPropagation(),l==null||l(_)},[l]),m=y.useCallback(_=>{_.preventDefault(),_.stopPropagation(),u==null||u(_)},[u]),x=t.rotation||0;return f.jsx("div",{ref:c,"data-qmap-node":e,"data-x":t.x,"data-y":t.y,style:{position:"absolute",left:t.x,top:t.y,transform:x!==0?`rotate(${x}deg)`:void 0,transformOrigin:"center center",cursor:i?s?"grabbing":"grab":"pointer",userSelect:"none",opacity:s?.8:1,zIndex:s?1e3:n?100:1,WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},onMouseDown:h,onClick:p,onDoubleClick:g,onContextMenu:m,children:d})},(r,e)=>r.nodeId===e.nodeId&&r.position.x===e.position.x&&r.position.y===e.position.y&&r.position.rotation===e.position.rotation&&r.isSelected===e.isSelected&&r.isDragging===e.isDragging&&r.draggable===e.draggable&&r.children===e.children);function Td(r,e,t="bezier"){const n={x:r.x+(r.width||200)/2,y:r.y+(r.height||100)/2},s={x:e.x+(e.width||200)/2,y:e.y+(e.height||100)/2};switch(t){case"straight":return`M ${n.x} ${n.y} L ${s.x} ${s.y}`;case"orthogonal":return E2(n,s);case"bezier":default:return k2(n,s)}}function k2(r,e){const t=e.x-r.x,n=e.y-r.y,s=Math.sqrt(t*t+n*n),i=Math.min(s*.4,150),o=Math.abs(t)>Math.abs(n);let a,l,u,c;return o?(a=r.x+i*Math.sign(t),l=r.y,u=e.x-i*Math.sign(t),c=e.y):(a=r.x,l=r.y+i*Math.sign(n),u=e.x,c=e.y-i*Math.sign(n)),`M ${r.x} ${r.y} C ${a} ${l}, ${u} ${c}, ${e.x} ${e.y}`}function E2(r,e){const t=e.x-r.x,n=e.y-r.y;if(Math.abs(t)>Math.abs(n)){const i=r.x+t/2;return`M ${r.x} ${r.y} H ${i} V ${e.y} H ${e.x}`}else{const i=r.y+n/2;return`M ${r.x} ${r.y} V ${i} H ${e.x} V ${e.y}`}}function ga(r){const e=r.width||200,t=r.height||100;return{x:r.x+e/2,y:r.y+t/2}}function D2(r,e){const t=r.width||200,n=r.height||100,s=ga(r),i=e.x-s.x,o=e.y-s.y;if(i===0&&o===0)return s;const a=t/2,l=n/2,u=Math.abs(o/(i||.001)),c=l/a;let d,h;return u<c?(d=s.x+(i>0?a:-a),h=s.y+o*a/Math.abs(i)):(h=s.y+(o>0?l:-l),d=s.x+i*l/Math.abs(o)),{x:d,y:h}}function A2(r,e){const t=r.width||200,n=r.height||100;switch(e){case"left":return{x:r.x,y:r.y+n/2};case"right":return{x:r.x+t,y:r.y+n/2};case"top":return{x:r.x+t/2,y:r.y};case"bottom":return{x:r.x+t/2,y:r.y+n};case"center":default:return ga(r)}}function T2(r,e){return r.x>=e.x&&r.x<=e.x+e.width&&r.y>=e.y&&r.y<=e.y+e.height}function N2(r,e){return r.x<e.x+e.width&&r.x+r.width>e.x&&r.y<e.y+e.height&&r.y+r.height>e.y}function B2(r){if(r.length===0)return null;let e=1/0,t=1/0,n=-1/0,s=-1/0;for(const i of r){const o=i.width||200,a=i.height||100;e=Math.min(e,i.x),t=Math.min(t,i.y),n=Math.max(n,i.x+o),s=Math.max(s,i.y+a)}return{x:e,y:t,width:n-e,height:s-t}}function j2(r,e){const t=e.x-r.x,n=e.y-r.y;return Math.sqrt(t*t+n*n)}function M2(r,e){const t=e.x-r.x,n=e.y-r.y;return t*t+n*n}const Nd=y.memo(function({edge:e,sourcePosition:t,targetPosition:n,style:s,color:i,width:o,onClick:a}){const[l,u]=y.useState(!1),c=y.useMemo(()=>Td(t,n,s),[t,n,s]),d=y.useCallback(x=>{x.stopPropagation(),a==null||a(e,x)},[e,a]),h=y.useCallback(()=>{u(!0)},[]),p=y.useCallback(()=>{u(!1)},[]),g=e.color||i,m=e.width||o;return f.jsxs("g",{children:[f.jsx("path",{d:c,fill:"none",stroke:"transparent",strokeWidth:Math.max(m*3,10),style:{cursor:a?"pointer":"default",pointerEvents:"stroke"},onClick:d,onMouseEnter:h,onMouseLeave:p}),f.jsx("path",{d:c,fill:"none",stroke:g,strokeWidth:l?m*1.5:m,strokeLinecap:"round",strokeLinejoin:"round",style:{pointerEvents:"none",transition:"stroke-width 0.15s ease"}}),e.label&&f.jsx(R2,{pathD:c,label:e.label,color:g})]})},(r,e)=>r.edge.id===e.edge.id&&r.sourcePosition.x===e.sourcePosition.x&&r.sourcePosition.y===e.sourcePosition.y&&r.sourcePosition.width===e.sourcePosition.width&&r.sourcePosition.height===e.sourcePosition.height&&r.targetPosition.x===e.targetPosition.x&&r.targetPosition.y===e.targetPosition.y&&r.targetPosition.width===e.targetPosition.width&&r.targetPosition.height===e.targetPosition.height&&r.style===e.style&&r.color===e.color&&r.width===e.width&&r.edge.label===e.edge.label&&r.edge.color===e.edge.color&&r.edge.width===e.edge.width);function R2({pathD:r,label:e,color:t}){const n=y.useMemo(()=>`edge-label-${Math.random().toString(36).substr(2,9)}`,[]);return f.jsxs(f.Fragment,{children:[f.jsx("defs",{children:f.jsx("path",{id:n,d:r})}),f.jsx("text",{fill:t,fontSize:"12",fontFamily:"system-ui, sans-serif",style:{pointerEvents:"none"},children:f.jsx("textPath",{href:`#${n}`,startOffset:"50%",textAnchor:"middle",children:e})})]})}const Bd=y.memo(function({edges:e,nodePositions:t,defaultStyle:n,defaultColor:s,defaultWidth:i,onEdgeClick:o}){const a=y.useMemo(()=>e.filter(l=>t.has(l.source)&&t.has(l.target)),[e,t]);return f.jsx("svg",{style:{position:"absolute",top:0,left:0,width:1,height:1,overflow:"visible",pointerEvents:"none"},children:f.jsx("g",{style:{pointerEvents:"auto"},children:a.map(l=>{const u=t.get(l.source),c=t.get(l.target);return f.jsx(Nd,{edge:l,sourcePosition:u,targetPosition:c,style:l.style||n,color:l.color||s,width:l.width||i,onClick:o},l.id)})})})},(r,e)=>!(r.edges!==e.edges||r.nodePositions!==e.nodePositions||r.defaultStyle!==e.defaultStyle||r.defaultColor!==e.defaultColor||r.defaultWidth!==e.defaultWidth)),jd=y.memo(function({box:e,transform:t}){const n=y.useMemo(()=>({x:e.x*t.k+t.x,y:e.y*t.k+t.y,width:e.width*t.k,height:e.height*t.k}),[e,t]);return f.jsx("div",{style:{position:"absolute",left:n.x,top:n.y,width:n.width,height:n.height,backgroundColor:"rgba(59, 130, 246, 0.1)",border:"1px solid rgba(59, 130, 246, 0.5)",borderRadius:2,pointerEvents:"none",zIndex:9999}})}),F2=200,L2=100,P2="bezier",I2="#94a3b8",z2=2,O2=.1,$2=4;function q2({viewNode:r,nodes:e,edges:t,renderNode:n,defaultNodeWidth:s=F2,defaultNodeHeight:i=L2,onNodeMove:o,onNodeDrag:a,onNodeClick:l,onNodeDoubleClick:u,onNodeContextMenu:c,selectedIds:d,onSelectionChange:h,onEdgeClick:p,onViewChange:g,onTransformChange:m,minZoom:x=O2,maxZoom:_=$2,initialTransform:b,defaultEdgeStyle:S=P2,defaultEdgeColor:C=I2,defaultEdgeWidth:k=z2,draggable:E=!0,selectable:v=!0,zoomable:T=!0,pannable:B=!0,className:j="",style:N,background:R="#f8fafc",showGrid:M=!1,gridSize:w=20}){const D=r.data||{positions:{}},F=D.positions||{},I=y.useMemo(()=>{const X=new Map;for(const K of e){const pe=F[K._id]||{x:0,y:0};X.set(K._id,{x:pe.x,y:pe.y,width:pe.width||s,height:pe.height||i,rotation:pe.rotation||0})}return X},[e,F,s,i]),{transform:q,containerRef:Z,zoomIn:te,zoomOut:W,resetZoom:Q,fitToContent:H}=kd({minZoom:x,maxZoom:_,initialTransform:b||D.transform,zoomable:T,pannable:B,onTransformChange:X=>{m==null||m(X);const K={...D,transform:X};g==null||g(K)}}),[ie,ue]=y.useState(new Map),[de,we]=y.useState(new Map),fe=y.useRef(new Map);y.useEffect(()=>{const X=q.k||1,K=new Map;fe.current.forEach((De,Be)=>{if(De){const Qe=De.getBoundingClientRect();K.set(Be,{width:Math.round(Qe.width/X),height:Math.round(Qe.height/X)})}}),e.some(De=>{const Be=K.get(De._id),Qe=de.get(De._id);return Be?Qe?Be.width!==Qe.width||Be.height!==Qe.height:!0:!1})&&we(K)},[e,de,q.k]);const{draggedNodeId:Ce,startDrag:O}=Ed({transform:q,disabled:!E,onDragStart:X=>{const K=I.get(X);K&&ue(new Map([[X,{x:K.x,y:K.y}]]))},onDragMove:(X,K,pe)=>{ue(new Map([[X,{x:K,y:pe}]])),a==null||a(X,K,pe)},onDragEnd:(X,K,pe)=>{ue(new Map),o==null||o(X,K,pe)}}),{selectedIds:je,selectionBox:re,isSelecting:Le,startSelection:Me,toggleSelect:xe,clearSelection:Se}=Dd({transform:q,nodePositions:I,disabled:!v,controlledSelectedIds:d,onSelectionChange:h}),Re=y.useCallback(X=>{const K=I.get(X)||{x:0,y:0,width:s,height:i},pe=ie.get(X),De=de.get(X),Be=(De==null?void 0:De.width)||K.width||s,Qe=(De==null?void 0:De.height)||K.height||i;return pe?{...K,x:pe.x,y:pe.y,width:Be,height:Qe}:{...K,width:Be,height:Qe}},[I,ie,de,s,i]),se=y.useMemo(()=>{const X=new Map;for(const K of I.keys())X.set(K,Re(K));return X},[I,Re]),ce=y.useCallback((X,K)=>{xe(X._id,K.shiftKey),l==null||l(X,K)},[xe,l]),$=y.useCallback(X=>{X.target.closest("[data-qmap-node]")||Se()},[Se]),Ge=y.useCallback(X=>{X.button===0&&(X.target.closest("[data-qmap-node]")||Me(X))},[Me]),Ke=M?`
186
186
  linear-gradient(to right, rgba(0,0,0,0.05) 1px, transparent 1px),
187
187
  linear-gradient(to bottom, rgba(0,0,0,0.05) 1px, transparent 1px)
188
188
  `:void 0;return f.jsxs("div",{ref:Z,className:`qmap-container ${j}`,style:{position:"relative",width:"100%",height:"100%",overflow:"hidden",background:R,backgroundImage:Ke,backgroundSize:M?`${w}px ${w}px`:void 0,cursor:Le?"crosshair":B?"grab":"default",...N},onMouseDown:Ge,onClick:$,children:[f.jsxs("div",{className:"qmap-canvas",style:{position:"absolute",transformOrigin:"0 0",transform:`translate(${q.x}px, ${q.y}px) scale(${q.k})`,willChange:"transform"},children:[f.jsx(Bd,{edges:t,nodePositions:se,defaultStyle:S,defaultColor:C,defaultWidth:k,onEdgeClick:p}),e.map(X=>{const K=Re(X._id),pe=je.has(X._id),De=Ce===X._id;return f.jsx(Ad,{nodeId:X._id,position:K,isSelected:pe,isDragging:De,draggable:E,onDragStart:O,onClick:Be=>ce(X,Be),onDoubleClick:Be=>u==null?void 0:u(X,Be),onContextMenu:Be=>c==null?void 0:c(X,Be),nodeRef:Be=>{Be?fe.current.set(X._id,Be):fe.current.delete(X._id)},children:n(X,pe,K)},X._id)})]}),re&&f.jsx(jd,{box:re,transform:q}),f.jsxs("div",{className:"qmap-controls",style:{position:"absolute",bottom:16,right:16,display:"flex",flexDirection:"column",gap:4,zIndex:100},children:[f.jsx("button",{onClick:te,style:{width:32,height:32,border:"1px solid #e2e8f0",borderRadius:4,background:"white",cursor:"pointer",fontSize:18,display:"flex",alignItems:"center",justifyContent:"center"},title:"Zoom in",children:"+"}),f.jsx("button",{onClick:W,style:{width:32,height:32,border:"1px solid #e2e8f0",borderRadius:4,background:"white",cursor:"pointer",fontSize:18,display:"flex",alignItems:"center",justifyContent:"center"},title:"Zoom out",children:"−"}),f.jsx("button",{onClick:Q,style:{width:32,height:32,border:"1px solid #e2e8f0",borderRadius:4,background:"white",cursor:"pointer",fontSize:12,display:"flex",alignItems:"center",justifyContent:"center"},title:"Reset zoom",children:"1:1"}),f.jsx("button",{onClick:()=>H(Array.from(se.values())),style:{width:32,height:32,border:"1px solid #e2e8f0",borderRadius:4,background:"white",cursor:"pointer",fontSize:12,display:"flex",alignItems:"center",justifyContent:"center"},title:"Fit to content",children:"⊡"})]})]})}exports.$createQRCodeNode=aa;exports.$isQRCodeNode=kg;exports.AnimatedCardFlip=kf;exports.ApiClient=au;exports.AudioEditor=Zc;exports.AuthFlow=fu;exports.AuthFlowModal=bf;exports.AuthManager=Je;exports.AuthProvider=df;exports.AuthService=Ao;exports.Card=wf;exports.ComboBox=Fg;exports.ComboStack=Pg;exports.DataOperations=vs;exports.Detail=Cf;exports.ForgotPasswordForm=cu;exports.GraphClient=Id;exports.ImageEditor=Qg;exports.KanbanBoard=Ig;exports.LLMClient=sf;exports.LoginForm=No;exports.LoginModal=pf;exports.Mail=Df;exports.MailClient=iu;exports.MailComposer=Mg;exports.MailEditor=Gc;exports.NetflixCard=Qc;exports.NetflixDetail=Xc;exports.NetflixLane=Jc;exports.NetflixStack=Ug;exports.QMap=q2;exports.QMapEdgeComponent=Nd;exports.QMapEdgeLayer=Bd;exports.QMapNode=Ad;exports.QMapSelectionBox=jd;exports.QRCodeNode=un;exports.RegisterForm=uu;exports.ResetPasswordForm=du;exports.SelectableList=Af;exports.Stack=_f;exports.TTS_VOICES=ou;exports.Timeline=Kg;exports.VerifyCodeForm=Gi;exports.VoiceTextEditor=Yg;exports.calculateBoundingBox=B2;exports.calculateEdgePath=Td;exports.distance=j2;exports.distanceSquared=M2;exports.getApiClient=To;exports.getAuthService=af;exports.getConnectionPoint=D2;exports.getNodeCenter=ga;exports.getNodeSidePoint=A2;exports.initializeApiClient=lf;exports.initializeAuthService=of;exports.pointInRect=T2;exports.rectsIntersect=N2;exports.useAuth=ff;exports.useMutation=vf;exports.useNodeDrag=Ed;exports.useQuery=hu;exports.useSelection=Dd;exports.useZoomPan=kd;
package/dist/index.esm.js CHANGED
@@ -17751,7 +17751,7 @@ function Ag({ onComplete: r, onCancel: e, onTranscribe: t, onTranscriptionComple
17751
17751
  ...Ye,
17752
17752
  opacity: 0.3,
17753
17753
  cursor: "not-allowed"
17754
- }, Sr = l ? { border: "1px solid #e5e5e5", borderRadius: "12px", overflow: "hidden", background: "white" } : { overflow: "hidden", background: "white", flexShrink: 0 };
17754
+ }, Sr = l ? { border: "1px solid #e5e5e5", borderRadius: "12px", overflow: "hidden", background: "white" } : { background: "white", flexShrink: 0 };
17755
17755
  return /* @__PURE__ */ f.jsxs("div", { style: Sr, children: [
17756
17756
  /* @__PURE__ */ f.jsx(
17757
17757
  "canvas",
@@ -18191,7 +18191,7 @@ ${ie}` : ie);
18191
18191
  className: "w-full px-3 py-2 text-sm border-0 resize-y min-h-[60px] focus:ring-0 focus:outline-none bg-transparent disabled:opacity-50"
18192
18192
  }
18193
18193
  ) }),
18194
- (r || (typeof e == "string" ? e : "").trim() || Ee || v || S) && /* @__PURE__ */ f.jsxs("div", { className: "flex items-center justify-between px-2 py-1", children: [
18194
+ (r || Ee || v || S) && /* @__PURE__ */ f.jsxs("div", { className: "flex items-center justify-between px-2 py-1", children: [
18195
18195
  /* @__PURE__ */ f.jsxs("div", { className: "flex items-center gap-2", children: [
18196
18196
  r && /* @__PURE__ */ f.jsx("label", { className: "text-sm font-medium text-neutral-700", children: r }),
18197
18197
  S && c && k && /* @__PURE__ */ f.jsxs(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qwanyx/stack",
3
- "version": "0.2.119",
3
+ "version": "0.2.120",
4
4
  "description": "Modern HyperCard for React - All-in-one data management (REST + Graph API + Auth + Hooks + UI)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",