@mean-weasel/lineage 0.1.18 → 0.1.20

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.
@@ -0,0 +1,16 @@
1
+ import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"./jsx-runtime-DAFSxiwi.js";var p=c(n(),1),m=a(),h=class extends Error{status;payload;constructor(e,t,n){super(e),this.status=t,this.payload=n,this.name=`ApiError`}};async function g(e,t){let n=await fetch(e,t),r=await n.json().catch(()=>({}));if(!n.ok)throw new h(r.message||r.error||`Request failed: ${n.status}`,n.status,r);return r}function _(e,t,n){return g(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:t,...n})})}function v(e){return{...e,scheduledAt:e.scheduledAt?new Date(e.scheduledAt).toISOString():void 0,postedAt:e.postedAt?new Date(e.postedAt).toISOString():void 0}}var y=t(`Archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),b=t(`Bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),x=t(`CalendarClock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),S=t(`ChevronDown`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),C=t(`CircleAlert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),w=t(`CircleCheck`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),T=t(`Clipboard`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}]]),E=t(`CloudUpload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]),D=t(`Cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),O=t(`Crosshair`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`22`,x2:`18`,y1:`12`,y2:`12`,key:`l9bcsi`}],[`line`,{x1:`6`,x2:`2`,y1:`12`,y2:`12`,key:`13hhkx`}],[`line`,{x1:`12`,x2:`12`,y1:`6`,y2:`2`,key:`10w3f3`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`18`,key:`15g9kq`}]]),k=t(`Database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),A=t(`Download`,[[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`polyline`,{points:`7 10 12 15 17 10`,key:`2ggqvy`}],[`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`,key:`1vk2je`}]]),j=t(`Ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),M=t(`ExternalLink`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),N=t(`Eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),P=t(`FileArchive`,[[`path`,{d:`M10 12v-1`,key:`v7bkov`}],[`path`,{d:`M10 18v-2`,key:`1cjy8d`}],[`path`,{d:`M10 7V6`,key:`dljcrl`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M15.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v16a2 2 0 0 0 .274 1.01`,key:`gkbcor`}],[`circle`,{cx:`10`,cy:`20`,r:`2`,key:`1xzdoj`}]]),F=t(`FileDown`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]),I=t(`FileSearch`,[[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M4.268 21a2 2 0 0 0 1.727 1H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3`,key:`ms7g94`}],[`path`,{d:`m9 18-1.5-1.5`,key:`1j6qii`}],[`circle`,{cx:`5`,cy:`14`,r:`3`,key:`ufru5t`}]]),L=t(`FileText`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),R=t(`Filter`,[[`polygon`,{points:`22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3`,key:`1yg77f`}]]),z=t(`Flag`,[[`path`,{d:`M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z`,key:`i9b6wo`}],[`line`,{x1:`4`,x2:`4`,y1:`22`,y2:`15`,key:`1cm3nv`}]]),B=t(`HardDrive`,[[`line`,{x1:`22`,x2:`2`,y1:`12`,y2:`12`,key:`1y58io`}],[`path`,{d:`M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`oot6mr`}],[`line`,{x1:`6`,x2:`6.01`,y1:`16`,y2:`16`,key:`sgf278`}],[`line`,{x1:`10`,x2:`10.01`,y1:`16`,y2:`16`,key:`1l4acy`}]]),V=t(`ImagePlus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),H=t(`Image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),U=t(`Link2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),W=t(`ListChecks`,[[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}],[`path`,{d:`M13 6h8`,key:`15sg57`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 18h8`,key:`oe0vm4`}]]),ee=t(`LoaderCircle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),te=t(`Maximize2`,[[`polyline`,{points:`15 3 21 3 21 9`,key:`mznyad`}],[`polyline`,{points:`9 21 3 21 3 15`,key:`1avn1i`}],[`line`,{x1:`21`,x2:`14`,y1:`3`,y2:`10`,key:`ota7mn`}],[`line`,{x1:`3`,x2:`10`,y1:`21`,y2:`14`,key:`1atl0r`}]]),ne=t(`PanelLeftClose`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),re=t(`PanelLeftOpen`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),ie=t(`Plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),ae=t(`Search`,[[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]),oe=t(`Send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),se=t(`ShieldCheck`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),G=t(`SlidersHorizontal`,[[`line`,{x1:`21`,x2:`14`,y1:`4`,y2:`4`,key:`obuewd`}],[`line`,{x1:`10`,x2:`3`,y1:`4`,y2:`4`,key:`1q6298`}],[`line`,{x1:`21`,x2:`12`,y1:`12`,y2:`12`,key:`1iu8h1`}],[`line`,{x1:`8`,x2:`3`,y1:`12`,y2:`12`,key:`ntss68`}],[`line`,{x1:`21`,x2:`16`,y1:`20`,y2:`20`,key:`14d8ph`}],[`line`,{x1:`12`,x2:`3`,y1:`20`,y2:`20`,key:`m0wm8r`}],[`line`,{x1:`14`,x2:`14`,y1:`2`,y2:`6`,key:`14e1ph`}],[`line`,{x1:`8`,x2:`8`,y1:`10`,y2:`14`,key:`1i6ji0`}],[`line`,{x1:`16`,x2:`16`,y1:`18`,y2:`22`,key:`1lctlv`}]]),ce=t(`SquareCheckBig`,[[`path`,{d:`M21 10.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.5`,key:`1uzm8b`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]),le=t(`Square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),K=t(`Trash2`,[[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6`,key:`4alrt4`}],[`path`,{d:`M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2`,key:`v07s0e`}],[`line`,{x1:`10`,x2:`10`,y1:`11`,y2:`17`,key:`1uufr5`}],[`line`,{x1:`14`,x2:`14`,y1:`11`,y2:`17`,key:`xtxkd`}]]),ue=t(`Upload`,[[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`polyline`,{points:`17 8 12 3 7 8`,key:`t8dd8p`}],[`line`,{x1:`12`,x2:`12`,y1:`3`,y2:`15`,key:`widbto`}]]),de=t(`X`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]);function q(e){if(!e||e<=0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`],n=Math.min(Math.floor(Math.log(e)/Math.log(1024)),t.length-1),r=e/1024**n;return`${r>=10||n===0?r.toFixed(0):r.toFixed(1)} ${t[n]}`}function fe(e){if(!e)return`Not synced`;let t=new Date(e);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat(`en`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}).format(t)}function pe(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}var me=`demo-project`,J=[`all`,`working`,`approved`,`published`,`archived`,`planned`],he=[`all`,`planned`,`scheduled`,`posted`,`skipped`,`not-posted`],Y=[`local`,`catalog`,`all`],ge=[`image`,`video`,`gif`,`audio`,`doc`,`other`],_e=new Set([`image`,`video`,`gif`]);function ve(e){let t=e.hasLocal&&e.hasS3?`local-s3`:e.hasLocal?`local-only`:e.hasS3?`s3-backed`:`catalog-record`,n={"catalog-record":[`catalog only`,`Catalog metadata exists, but no S3 object is recorded yet.`],"local-only":[`local only`,`Only in local review. Back up when this is a keeper.`],"local-s3":[`local + S3`,`Local file and S3 object are both known.`],"s3-backed":[`S3 backed`,`Cataloged with an S3 object.`]};return{description:n[t][1],kind:t,label:n[t][0]}}function ye(e){return ve({hasLocal:!!e.local?.relative_path,hasS3:!!e.s3?.key})}function be(e){return e===`image`||e===`gif`?H:e===`video`?l:e===`doc`?L:P}function xe(e,t){return e.find(e=>e.asset_id===t)||e[0]}function Se(e){return!!((e?.s3?.key||e?.local?.relative_path)&&_e.has(e.content_type))}function Ce(e){return e.s3?.size_bytes||e.local?.size_bytes}function we(e){return e.s3?.updated_at||e.local?.updated_at}function Te(e){let t=e.placements?.at(-1);return t?`${t.channel}: ${t.status}`:`not posted`}var X=d();function Ee({asset:e,previewUrl:t,previewError:n,onPresign:r,onPromote:a,onArchive:o,onCopy:s,onCopyPreview:c,onDelete:l,onPlacement:u,onPull:d,onToggleBackup:f,selectedForBackup:p}){if(!e)return(0,X.jsx)(`aside`,{className:`inspector empty`,children:`No asset selected`});let m=be(e.content_type),h=t&&Se(e),g=e.source===`local`,_=ye(e);return(0,X.jsxs)(`aside`,{className:`inspector`,children:[(0,X.jsx)(`div`,{className:`preview-pane`,children:h&&e.content_type===`video`?(0,X.jsx)(`video`,{src:t,controls:!0}):h?(0,X.jsx)(`img`,{src:t,alt:e.title}):(0,X.jsxs)(`div`,{className:`preview-placeholder`,children:[(0,X.jsx)(m,{size:36}),(0,X.jsx)(`span`,{children:e.content_type}),(0,X.jsx)(`small`,{children:n?`Preview unavailable`:_.description}),n&&(0,X.jsxs)(`details`,{className:`preview-error`,children:[(0,X.jsx)(`summary`,{children:`Details`}),(0,X.jsx)(`code`,{children:n})]})]})}),(0,X.jsxs)(`div`,{className:`inspector-title`,children:[(0,X.jsx)(`span`,{className:`status-chip ${e.status}`,children:e.status}),(0,X.jsx)(`span`,{className:`storage-chip ${_.kind}`,title:_.description,children:_.label}),(0,X.jsx)(`h2`,{children:e.title}),(0,X.jsx)(`p`,{children:e.hook})]}),(0,X.jsxs)(`div`,{className:`action-grid`,children:[(0,X.jsxs)(`button`,{onClick:()=>r(e),children:[(0,X.jsx)(M,{size:16}),`Preview`]}),(0,X.jsxs)(`button`,{onClick:()=>c(e),disabled:!Se(e),children:[(0,X.jsx)(i,{size:16}),`Copy link`]}),(0,X.jsxs)(`button`,{onClick:()=>d(e),disabled:!e.s3?.key,children:[(0,X.jsx)(A,{size:16}),`Pull`]}),(0,X.jsxs)(`button`,{onClick:()=>a(e),disabled:g||e.status===`published`,children:[(0,X.jsx)(w,{size:16}),`Promote`]}),(0,X.jsxs)(`button`,{onClick:()=>o(e),disabled:g||e.status===`archived`,children:[(0,X.jsx)(y,{size:16}),`Archive`]}),(0,X.jsx)(`button`,{onClick:()=>f(e),disabled:!g,children:p?`Selected`:`Select backup`}),(0,X.jsxs)(`button`,{onClick:()=>s(e.asset_id,`asset ID`),children:[(0,X.jsx)(i,{size:16}),`Copy ID`]}),(0,X.jsxs)(`button`,{onClick:()=>s(e.s3?.key||``,`S3 key`),disabled:!e.s3?.key,children:[(0,X.jsx)(i,{size:16}),`Copy key`]})]}),(0,X.jsx)(ke,{asset:e}),!g&&(0,X.jsx)(Oe,{asset:e,onPlacement:u}),!g&&(0,X.jsx)(De,{asset:e,onDelete:l},e.asset_id)]})}function De({asset:e,onDelete:t}){let[n,r]=(0,p.useState)(``),i=`delete ${e.asset_id}`;return(0,X.jsxs)(`section`,{className:`danger-section`,children:[(0,X.jsxs)(`label`,{children:[`Delete confirmation`,(0,X.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:i})]}),(0,X.jsxs)(`button`,{disabled:n!==i,onClick:()=>t(e,n),children:[(0,X.jsx)(K,{size:16}),`Delete object`]})]})}function Oe({asset:e,onPlacement:t}){let[n,r]=(0,p.useState)(``),[i,a]=(0,p.useState)(``),[o,s]=(0,p.useState)(``);return(0,X.jsxs)(`section`,{className:`detail-section placement-section`,children:[(0,X.jsx)(`h3`,{children:`Placement`}),e.placements?.length?(0,X.jsx)(`div`,{className:`placement-list`,children:e.placements.map(e=>(0,X.jsxs)(`div`,{className:`placement-item`,children:[(0,X.jsxs)(`span`,{className:`placement-chip ${e.status}`,children:[e.channel,`: `,e.status]}),(0,X.jsx)(`small`,{children:e.posted_at||e.scheduled_at||e.updated_at}),e.url&&(0,X.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:`Open`})]},`${e.channel}-${e.updated_at}`))}):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No placements yet`}),(0,X.jsxs)(`label`,{children:[`Scheduled at`,(0,X.jsx)(`input`,{type:`datetime-local`,value:n,onChange:e=>r(e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Posted at`,(0,X.jsx)(`input`,{type:`datetime-local`,value:i,onChange:e=>a(e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Posted URL`,(0,X.jsx)(`input`,{placeholder:`https://...`,value:o,onChange:e=>s(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`action-grid`,children:[(0,X.jsxs)(`button`,{onClick:()=>t(e,`scheduled`,{scheduledAt:n}),children:[(0,X.jsx)(x,{size:16}),`Scheduled`]}),(0,X.jsxs)(`button`,{onClick:()=>t(e,`posted`,{postedAt:i||new Date().toISOString(),url:o}),children:[(0,X.jsx)(oe,{size:16}),`Posted`]})]})]})}function ke({asset:e}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`section`,{className:`detail-section`,children:[(0,X.jsx)(`h3`,{children:`Metadata`}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Asset ID`}),(0,X.jsx)(`dd`,{children:e.asset_id})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Campaign`}),(0,X.jsx)(`dd`,{children:e.campaign})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Channel`}),(0,X.jsx)(`dd`,{children:e.channel})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Audience`}),(0,X.jsx)(`dd`,{children:e.audience})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`CTA`}),(0,X.jsx)(`dd`,{children:e.cta})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`UTM`}),(0,X.jsx)(`dd`,{children:e.utm_content})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Storage`}),(0,X.jsx)(`dd`,{children:ye(e).label})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Source`}),(0,X.jsx)(`dd`,{children:e.source||`catalog`})]})]})]}),e.local&&(0,X.jsxs)(`section`,{className:`detail-section`,children:[(0,X.jsx)(`h3`,{children:`Local`}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Size`}),(0,X.jsx)(`dd`,{children:q(Ce(e))})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Updated`}),(0,X.jsx)(`dd`,{children:fe(we(e))})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Checksum`}),(0,X.jsx)(`dd`,{children:e.local.checksum_sha256.slice(0,12)})]})]}),(0,X.jsx)(`code`,{className:`object-key`,children:e.local.relative_path})]}),(0,X.jsxs)(`section`,{className:`detail-section`,children:[(0,X.jsx)(`h3`,{children:`S3`}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Bucket`}),(0,X.jsx)(`dd`,{children:e.s3?.bucket||`not uploaded`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Size`}),(0,X.jsx)(`dd`,{children:q(e.s3?.size_bytes)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Updated`}),(0,X.jsx)(`dd`,{children:fe(e.s3?.updated_at)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`ETag`}),(0,X.jsx)(`dd`,{children:e.s3?.etag||`none`})]})]}),(0,X.jsx)(`code`,{className:`object-key`,children:e.s3?.key||`No object key yet`})]})]})}function Ae({asset:e,onArchive:t,onClose:n,onCopy:r,onCopyPreview:i,onDelete:a,onPlacement:o,onPresign:s,onPromote:c,onPull:l,onToggleBackup:u,previewError:d,previewUrl:f,selectedForBackup:p}){return(0,X.jsx)(`div`,{className:`drawer-backdrop asset-detail-backdrop`,onClick:n,children:(0,X.jsxs)(`section`,{"aria-label":`Asset details`,className:`asset-detail-drawer`,onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Asset details`}),(0,X.jsx)(`p`,{children:e?.title||`No asset selected`})]}),(0,X.jsx)(`button`,{"aria-label":`Close asset details`,className:`icon-button`,onClick:n,type:`button`,children:(0,X.jsx)(de,{size:18})})]}),(0,X.jsx)(Ee,{asset:e,onArchive:t,onCopy:r,onCopyPreview:i,onDelete:a,onPlacement:o,onPresign:s,onPromote:c,onPull:l,onToggleBackup:u,previewError:d,previewUrl:f,selectedForBackup:p})]})})}var je=(0,p.createContext)(null);function Me({children:e,runtime:t}){return(0,X.jsx)(je.Provider,{value:t?.cli||null,children:e})}function Ne(){return(0,p.useContext)(je)}function Z(e,t){if(!e)return`Lineage runtime identity unavailable; refresh before copying this command.`;let n=t.trim().replace(/\s+--json$/,``);return`${e.launcher} ${n} ${e.runtime_selector} --json`}function Pe({asset:e,ledgerSelected:t,previewUrl:n,selected:r,onSelect:i,onToggleLedgerSelected:a,selectionPending:o}){let s=be(e.content_type),c=ye(e),l=t?ce:le;return(0,X.jsxs)(`div`,{className:`asset-row ${r?`selected`:``} ${t?`ledger-selected`:``}`,"data-asset-id":e.asset_id,onClick:i,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&i()},role:`button`,tabIndex:0,children:[(0,X.jsx)(`button`,{"aria-label":`${t?`Remove from`:`Add to`} current selections`,className:`ledger-select-button ${t?`selected`:``}`,"data-testid":`ledger-select-${e.asset_id}`,disabled:o,onClick:e=>{e.stopPropagation(),a()},type:`button`,children:(0,X.jsx)(l,{size:17})}),(0,X.jsx)(`div`,{className:`thumb`,children:n&&(e.content_type===`image`||e.content_type===`gif`)?(0,X.jsx)(`img`,{src:n,alt:``,loading:`lazy`}):n&&e.content_type===`video`?(0,X.jsx)(`video`,{src:n,muted:!0,preload:`metadata`}):(0,X.jsx)(s,{size:20})}),(0,X.jsxs)(`div`,{className:`asset-main`,children:[(0,X.jsxs)(`div`,{className:`asset-title-line`,children:[(0,X.jsx)(`strong`,{className:`asset-title-text`,title:e.title,children:e.title}),(0,X.jsx)(`span`,{className:`status-chip ${e.status}`,children:e.status}),(0,X.jsx)(`span`,{className:`storage-chip ${c.kind}`,title:c.description,children:c.label})]}),(0,X.jsx)(`span`,{className:`asset-id`,children:e.asset_id})]}),(0,X.jsxs)(`div`,{className:`asset-meta`,children:[(0,X.jsx)(`span`,{children:e.channel}),(0,X.jsx)(`span`,{children:e.audience}),(0,X.jsx)(`span`,{className:`placement-chip`,children:Te(e)})]}),(0,X.jsxs)(`div`,{className:`asset-meta narrow`,children:[(0,X.jsx)(`span`,{children:e.content_type}),(0,X.jsx)(`span`,{children:q(Ce(e))})]}),(0,X.jsxs)(`div`,{className:`asset-version`,children:[(0,X.jsx)(`span`,{children:fe(we(e))}),(0,X.jsx)(`code`,{children:e.s3?.version_id?e.s3.version_id.slice(0,10):`needs backup`})]})]})}function Fe({assets:e,candidateAssets:t=[],cli:n=null,inspectedReviewSetId:r,error:i,loading:a,onActivateReviewSet:s,onArchiveReviewSet:c,onClear:l,onChooseReviewLabels:u,onContinueFromNextContext:d,onInspectReviewSet:f,onRefresh:p,onToggleReviewLabel:m,pending:h,project:g,reviewDraftLabels:_,reviewActionPending:v,reviewPending:y,selection:b}){let x=b?.current.items.filter(e=>e.selected_at&&!e.deselected_at)||[],S=b?.active_review_set||null,C=b?.review_sets||[],w=new Map([...t,...e].map(e=>[e.asset_id,e])),T=_||[],E=C.find(e=>e.id===r)||S||C[0]||null,D=S?.items.filter(Ie).length||0;function O(){!u||T.length===0||u(T)}return(0,X.jsxs)(`section`,{className:`selection-ledger-panel`,"aria-label":`Current asset selections`,children:[(0,X.jsxs)(`div`,{className:`selection-ledger-title`,children:[(0,X.jsx)(ce,{size:16}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{children:`Current asset selections`}),(0,X.jsxs)(`p`,{children:[g,` · SQLite selection set`]})]})]}),(0,X.jsxs)(`div`,{className:`selection-ledger-actions`,children:[(0,X.jsxs)(`span`,{children:[x.length,` selected`]}),(0,X.jsxs)(`button`,{disabled:a,onClick:p,type:`button`,children:[(0,X.jsx)(o,{className:a?`spin`:``,size:14}),`Refresh`]}),(0,X.jsxs)(`button`,{disabled:h||x.length===0,onClick:l,type:`button`,children:[(0,X.jsx)(K,{size:14}),`Clear`]})]}),i&&(0,X.jsx)(`p`,{className:`selection-ledger-error`,children:i}),x.length>0&&(0,X.jsx)(`div`,{className:`selection-ledger-items`,children:x.map(e=>(0,X.jsxs)(`span`,{title:e.asset_id,children:[e.variation_label?`${e.variation_label}: `:``,w.get(e.asset_id)?.title||e.asset_id]},e.id))}),!S&&C.length>0&&(0,X.jsx)(`p`,{className:`review-set-empty`,children:`No active review set. Activate a recent set to choose labels from it.`}),S&&(0,X.jsxs)(`details`,{className:`review-set-panel`,"aria-label":`Active review set`,children:[(0,X.jsxs)(`summary`,{className:`review-set-header`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{children:`Active review set`}),(0,X.jsxs)(`p`,{children:[S.label,` · `,S.key]})]}),(0,X.jsxs)(`div`,{className:`review-set-header-badges`,children:[(0,X.jsx)(`span`,{className:`review-set-next-context`,children:`next work context`}),(0,X.jsxs)(`span`,{children:[S.items.length,` candidates`]})]})]}),(0,X.jsx)(`div`,{className:`review-set-candidates`,children:S.items.map(e=>{let t=e.variation_label||String(e.position+1),n=w.get(e.asset_id),r=n?ye(n):null,i=Ie(e),a=T.includes(t);return(0,X.jsxs)(`button`,{"aria-pressed":a,className:`review-set-candidate${i?` selected`:``}${a?` drafted`:``}`,disabled:y||!m,onClick:()=>m?.(t),title:e.asset_id,type:`button`,children:[(0,X.jsx)(`span`,{className:`review-set-label`,children:t}),(0,X.jsxs)(`span`,{className:`review-set-copy`,children:[(0,X.jsx)(`strong`,{children:n?.title||e.asset_id}),(0,X.jsxs)(`small`,{children:[n?n.asset_id:`not on this page`,` · `,r?.label||`storage unknown`]})]}),i&&(0,X.jsx)(`span`,{className:`review-set-selected`,children:`selected`})]},e.id)})}),(0,X.jsxs)(`div`,{className:`review-set-actions`,children:[(0,X.jsxs)(`span`,{children:[T.length,` label`,T.length===1?``:`s`,` chosen`]}),(0,X.jsxs)(`button`,{disabled:!u||y||T.length===0,onClick:O,type:`button`,children:[(0,X.jsx)(ce,{size:14}),`Select labels`]})]}),(0,X.jsxs)(`details`,{className:`review-set-work-packet`,"aria-label":`Agent work packet`,children:[(0,X.jsxs)(`summary`,{className:`review-set-work-packet-title`,children:[(0,X.jsx)(`h4`,{children:`Agent work packet`}),(0,X.jsxs)(`span`,{children:[S.items.length,` candidates · `,D,` selected · SQLite-backed`]})]}),(0,X.jsxs)(`div`,{className:`review-set-work-packet-body`,children:[(0,X.jsx)(`code`,{children:Z(n,`selections review-set packet --project '${g}'`)}),(0,X.jsx)(`code`,{children:Z(n,`agent "keep working on my selections" --project '${g}'`)}),(0,X.jsx)(`button`,{disabled:S.items.length===0||!d,onClick:d,type:`button`,children:`Continue from next context`})]})]})]}),C.length>0&&(0,X.jsxs)(`details`,{className:`review-set-history`,"aria-label":`Recent review sets`,children:[(0,X.jsxs)(`summary`,{className:`review-set-history-title`,children:[(0,X.jsx)(`h4`,{children:`Recent review sets`}),(0,X.jsxs)(`span`,{children:[C.length,` total`]})]}),C.slice(0,5).map(e=>{let t=e.items.filter(Ie).map(e=>e.variation_label).filter(Boolean).join(`, `),n=v?.endsWith(`:${e.id}`);return(0,X.jsxs)(`div`,{className:`review-set-history-row ${e.status}`,children:[(0,X.jsx)(`span`,{className:`review-set-status ${e.status}`,children:e.status}),(0,X.jsx)(`strong`,{children:e.label}),(0,X.jsxs)(`small`,{children:[e.key,` · `,fe(e.updated_at),` · `,e.items.length,` candidates`,t?` · selected ${t}`:``]}),(0,X.jsxs)(`div`,{className:`review-set-history-actions`,children:[(0,X.jsx)(`button`,{"aria-pressed":E?.id===e.id,onClick:()=>{f?.(e.id)},type:`button`,children:`Inspect`}),(0,X.jsx)(`button`,{disabled:e.status===`active`||n||!s,onClick:()=>{s?.(e.id)},type:`button`,children:`Set next`}),(0,X.jsx)(`button`,{disabled:e.status===`archived`||n||!c,onClick:()=>{c?.(e.id)},type:`button`,children:`Archive`})]})]},e.id)})]}),E&&(0,X.jsxs)(`details`,{className:`review-set-detail`,"aria-label":`Review set detail`,children:[(0,X.jsxs)(`summary`,{children:[(0,X.jsx)(`h4`,{children:`Review set handoff`}),(0,X.jsxs)(`p`,{children:[E.label,` · `,E.status===`active`?`next work context`:E.status,` · `,E.items.filter(Ie).length,` selected`]})]}),(0,X.jsx)(`div`,{className:`review-set-detail-assets`,children:E.items.map(e=>{let t=e.variation_label||String(e.position+1),n=w.get(e.asset_id);return(0,X.jsxs)(`span`,{className:Ie(e)?`selected`:``,children:[t,`: `,n?.title||e.asset_id]},e.id)})}),(0,X.jsx)(`code`,{children:Z(n,`selections review-set inspect --project '${g}' --set-id '${E.id}'`)}),(0,X.jsx)(`code`,{children:Z(n,`selections review-set set-next --project '${g}' --set-id '${E.id}'`)}),(0,X.jsxs)(`code`,{children:[`After choosing labels: `,Z(n,`agent "keep working on my selections" --project '${g}'`)]})]})]})}function Ie(e){return!!(e.selected_at&&!e.deselected_at)}function Le(e,t,n){let r=e?.pagination.total??0,i=t===`all`?`all sources`:t,a=`${e?.catalog.default_bucket||`Loading bucket`} · ${e?.catalog.default_region||`us-east-1`}`,o=t===`all`?`${r} matching assets`:`${r} matching ${i} assets`,s=n?.items.length||0;return{note:r===0&&s>0?`Active review set still has ${s} candidate${s===1?``:`s`} outside this asset filter.`:void 0,subtitle:`${a} · filter: ${i}`,title:o}}function Re(e){let t=Ne(),{snapshot:n}=e,[r,i]=(0,p.useState)(null),[a,o]=(0,p.useState)(null),[s,c]=(0,p.useState)(!1),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)([]),[m,h]=(0,p.useState)([]),[_,v]=(0,p.useState)(null),y=new Set(r?.current.items.filter(e=>e.selected_at&&!e.deselected_at).map(e=>e.asset_id)||[]),b=r?.active_review_set||null,x=[...new Set((r?.review_sets||[]).slice(0,6).flatMap(e=>e.items.map(e=>e.asset_id)))],S=x.join(`|`),C=b?.items.filter(e=>e.selected_at&&!e.deselected_at).map(e=>e.variation_label).filter(e=>!!e)||[],w=C.join(`|`),T=Le(n,e.source,b);async function E(){c(!0);try{let t=new URLSearchParams({project:e.project});i(await g(`/api/selections?${t}`)),o(null)}catch(e){o(e instanceof Error?e.message:String(e))}finally{c(!1)}}async function D(t,n){u(n);try{let n=await g(`/api/selections/current`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:e.project,assetIds:t,confirmWrite:!0})});i(e=>e&&{...e,current:n.selection||n.current||e.current}),o(null),e.onSelectionChanged?.(),window.dispatchEvent(new CustomEvent(`asset-selection-updated`))}catch(e){o(e instanceof Error?e.message:String(e))}finally{u(null)}}async function O(){u(`clear`);try{await g(`/api/selections/current/clear`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:e.project,confirmWrite:!0})}),await E(),e.onSelectionChanged?.(),window.dispatchEvent(new CustomEvent(`asset-selection-updated`))}catch(e){o(e instanceof Error?e.message:String(e))}finally{u(null)}}async function k(t){let n=r?.active_review_set?.id;if(n){u(`review:${t.join(`,`)}`);try{await g(`/api/selections/review-sets/choose`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:e.project,labels:t,setId:n,selectedBy:`human`,confirmWrite:!0})}),await E(),e.onSelectionChanged?.(),window.dispatchEvent(new CustomEvent(`asset-selection-updated`))}catch(e){o(e instanceof Error?e.message:String(e))}finally{u(null)}}}async function A(t,n){u(`review-set:${n}:${t}`);try{await g(`/api/selections/review-sets/${n}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:e.project,setId:t,confirmWrite:!0})}),await E(),e.onSelectionChanged?.(),window.dispatchEvent(new CustomEvent(`asset-selection-updated`))}catch(e){o(e instanceof Error?e.message:String(e))}finally{u(null)}}function j(e){f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e].sort())}function M(e){let t=r?.current.items.filter(e=>e.selected_at&&!e.deselected_at).map(e=>e.asset_id)||[];D(y.has(e.asset_id)?t.filter(t=>t!==e.asset_id):[...t,e.asset_id],e.asset_id)}function N(){e.onCopy?.(Z(t,`agent "keep working on my selections" --project '${e.project}'`),`next context command`)}return(0,p.useEffect)(()=>{E()},[e.project]),(0,p.useEffect)(()=>{f(C)},[b?.id,w]),(0,p.useEffect)(()=>{if(x.length===0){h([]);return}g(`/api/assets/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:e.project,assetIds:x})}).then(e=>{h(e.assets),o(null)}).catch(e=>{o(e instanceof Error?e.message:String(e))})},[e.project,S]),(0,X.jsxs)(`section`,{className:`asset-board`,children:[(0,X.jsxs)(`div`,{className:`board-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:T.title}),(0,X.jsx)(`p`,{children:T.subtitle}),T.note&&(0,X.jsx)(`p`,{className:`board-context-note`,children:T.note})]}),(0,X.jsxs)(`div`,{className:`mini-stats`,children:[(0,X.jsxs)(`button`,{"aria-checked":e.liveSync,"aria-label":`Live cloud inventory`,className:`asset-live-inventory ${e.liveSync?`on`:``}`,onClick:()=>e.setLiveSync(e=>!e),role:`switch`,type:`button`,children:[(0,X.jsx)(`span`,{children:`Live cloud inventory`}),(0,X.jsx)(`small`,{children:`Includes a live read from the configured cloud bucket for this project.`})]}),(0,X.jsx)(`span`,{children:e.liveSync?`${e.totals.orphan} uncataloged cloud objects`:`Live cloud inventory off`}),(0,X.jsxs)(`span`,{children:[`Page `,n?.pagination.page||e.page,`/`,n?.pagination.totalPages||1]}),(0,X.jsx)(`span`,{children:fe(n?.fetchedAt)})]})]}),(0,X.jsx)(Fe,{assets:e.assets,candidateAssets:m,cli:t,inspectedReviewSetId:_,error:a,loading:s,onActivateReviewSet:e=>A(e,`activate`),onArchiveReviewSet:e=>A(e,`archive`),onClear:()=>void O(),onChooseReviewLabels:e=>k(e),onContinueFromNextContext:e.onCopy?N:void 0,onInspectReviewSet:v,onRefresh:()=>void E(),onToggleReviewLabel:j,pending:l===`clear`,project:e.project,reviewDraftLabels:d,reviewActionPending:l,reviewPending:!!l?.startsWith(`review:`),selection:r}),(0,X.jsx)(`div`,{className:`asset-list`,children:e.assets.map(t=>(0,X.jsx)(Pe,{asset:t,ledgerSelected:y.has(t.asset_id),onSelect:()=>e.setSelectedId(t.asset_id),onToggleLedgerSelected:()=>M(t),previewUrl:e.previewUrls[t.asset_id]||null,selected:t.asset_id===e.selected?.asset_id,selectionPending:l===t.asset_id},t.asset_id))}),(0,X.jsxs)(`footer`,{className:`pagination-bar`,children:[(0,X.jsx)(`button`,{disabled:!n||n.pagination.page<=1,onClick:()=>e.setPage(e=>Math.max(e-1,1)),children:`Previous`}),(0,X.jsxs)(`span`,{children:[n?.pagination.page||1,` of `,n?.pagination.totalPages||1]}),(0,X.jsx)(`button`,{disabled:!n||n.pagination.page>=n.pagination.totalPages,onClick:()=>e.setPage(e=>e+1),children:`Next`}),(0,X.jsxs)(`label`,{children:[`Per page`,(0,X.jsx)(`select`,{onChange:t=>e.setPageSize(Number(t.target.value)),value:e.pageSize,children:[10,25,50,100].map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]})]})]})}function ze({onCopy:e,onOpenWork:t,project:n}){let r=Ne(),[i,a]=(0,p.useState)([]),[s,c]=(0,p.useState)(!1),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)(``),[m,h]=(0,p.useState)(`all`),[_,v]=(0,p.useState)(`open`);async function y(){c(!0);try{let e=await g(`/api/agent-claims?${new URLSearchParams({project:n})}`);a(e.claims),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}}(0,p.useEffect)(()=>{y()},[n]);let b=(0,p.useMemo)(()=>i.filter(e=>Ge(e,d,m,_)),[i,d,m,_]),x=(0,p.useMemo)(()=>[...new Set(i.map(e=>e.scope_type))].sort(),[i]);return(0,X.jsxs)(`section`,{className:`agents-view`,"aria-label":`Agents`,children:[(0,X.jsxs)(`header`,{className:`agents-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Agents`}),(0,X.jsxs)(`p`,{children:[n,` active work claims`]})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,disabled:s,onClick:()=>void y(),type:`button`,children:[(0,X.jsx)(o,{className:s?`spin`:``,size:17}),`Refresh`]})]}),l&&(0,X.jsx)(`p`,{className:`agents-error`,children:l}),(0,X.jsx)(`div`,{className:`agents-workspace`,children:(0,X.jsxs)(`section`,{className:`agents-browser`,"aria-label":`Agent claim browser`,children:[(0,X.jsxs)(`div`,{className:`agents-filters`,children:[(0,X.jsxs)(`label`,{children:[(0,X.jsx)(ae,{size:15}),(0,X.jsx)(`input`,{"aria-label":`Search claims`,onChange:e=>f(e.target.value),placeholder:`Agent, target, channel...`,value:d})]}),(0,X.jsxs)(`label`,{children:[(0,X.jsx)(R,{size:15}),(0,X.jsxs)(`select`,{"aria-label":`Filter status`,onChange:e=>v(e.target.value),value:_,children:[(0,X.jsx)(`option`,{value:`open`,children:`Open`}),(0,X.jsx)(`option`,{value:`attention`,children:`Attention`}),(0,X.jsx)(`option`,{value:`closed`,children:`Closed`}),(0,X.jsx)(`option`,{value:`all`,children:`All`})]})]}),(0,X.jsxs)(`select`,{"aria-label":`Filter scope`,onChange:e=>h(e.target.value),value:m,children:[(0,X.jsx)(`option`,{value:`all`,children:`All scopes`}),x.map(e=>(0,X.jsx)(`option`,{value:e,children:Ke(e)},e))]})]}),(0,X.jsx)(Be,{cli:r,claims:b,empty:`No claims match these filters.`,onCopy:e,onOpenWork:t,title:`Claims`})]})})]})}function Be({cli:e,claims:t,empty:n,onCopy:r,onOpenWork:i,title:a}){return(0,X.jsxs)(`section`,{className:`agents-group`,children:[(0,X.jsx)(`h3`,{children:a}),t.length===0?(0,X.jsx)(`p`,{className:`agents-empty`,children:n}):(0,X.jsx)(`div`,{className:`agents-list`,children:t.map(t=>(0,X.jsx)(Ve,{cli:e,claim:t,onCopy:r,onOpenWork:i},t.id))})]})}function Ve({cli:e,claim:t,onCopy:n,onOpenWork:r}){let i=()=>r(He(t));return(0,X.jsxs)(`article`,{className:`agent-claim-row ${t.derived_state}`,onDoubleClick:i,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())},tabIndex:0,title:`Double-click to open the corresponding graph`,children:[(0,X.jsxs)(`div`,{className:`agent-claim-main`,children:[(0,X.jsx)(se,{size:16}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:t.agent_name}),(0,X.jsxs)(`span`,{children:[Ke(t.scope_type),` · `,t.derived_state]})]})]}),(0,X.jsxs)(`div`,{className:`agent-claim-target`,children:[(0,X.jsx)(`strong`,{children:t.target_title||t.target_id}),(0,X.jsx)(`code`,{children:t.target_id})]}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Project`}),(0,X.jsx)(`dd`,{children:t.project})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Channel`}),(0,X.jsx)(`dd`,{children:t.channel||`all`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Last seen`}),(0,X.jsx)(`dd`,{children:qe(t.heartbeat_age_seconds)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Expires`}),(0,X.jsx)(`dd`,{children:Je(t.expires_at)})]})]}),(0,X.jsxs)(`div`,{className:`agent-row-actions`,children:[(0,X.jsxs)(`button`,{"aria-label":`Open graph for ${t.agent_name}`,className:`secondary-button agent-row-open-graph`,onClick:e=>{e.stopPropagation(),i()},type:`button`,children:[(0,X.jsx)(u,{size:14}),`Open graph`]}),(0,X.jsxs)(`button`,{"aria-label":`Copy briefing for ${t.agent_name}`,className:`secondary-button agent-row-copy-briefing`,onClick:r=>{r.stopPropagation(),n(We(t,e),`agent briefing`)},type:`button`,children:[(0,X.jsx)(T,{size:14}),`Copy briefing`]})]})]})}function He(e){let t=Ue(e.target_id);return{assetId:t,claim:e,view:`lineage`,workspaceId:t?e.target_id:void 0}}function Ue(e){let t=e.indexOf(`:lineage-workspace:`);return t>=0?e.slice(t+19):void 0}function We(e,t){let n=Ue(e.target_id);return[`Agent briefing: ${e.agent_name}`,`Project: ${e.project}`,`Target: ${e.target_title||e.target_id}`,`Claim: ${e.id}`,`Scope: ${Ke(e.scope_type)}`,`Channel: ${e.channel||`all`}`,`Status: ${e.status} / ${e.derived_state}`,n?`Lineage root: ${n}`:void 0,n?`Inspect graph: ${Z(t,`next --project '${e.project}' --root '${n}'`)}`:void 0,n?`Brief graph: ${Z(t,`brief --project '${e.project}' --root '${n}'`)}`:void 0].filter(e=>!!e).join(`
2
+ `)}function Ge(e,t,n,r){if(n!==`all`&&e.scope_type!==n||r===`open`&&e.status!==`active`||r===`attention`&&!(e.status===`active`&&(e.derived_state===`stale`||e.derived_state===`expired`))||r===`closed`&&e.status===`active`)return!1;let i=t.trim().toLowerCase();return i?[e.agent_name,e.agent_id,e.channel,e.project,e.scope_type,e.status,e.target_id,e.target_title].some(e=>e?.toLowerCase().includes(i)):!0}function Ke(e){return e.replace(/_/g,` `)}function qe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return t<60?`${t}m`:`${Math.floor(t/60)}h ${t%60}m`}function Je(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Ye(e){return e?e.local&&e.s3?`local + S3`:e.s3?`S3`:e.local?`local only`:e.source||`catalog`:`unresolved`}function Xe({loading:t,onAttach:n,onOpenAsset:r,onPage:i,page:a,post:o,snapshot:c}){let l=new Set(o.assets.map(e=>e.asset_id)),u=c?.assets||[],d=c?.pagination;return(0,X.jsxs)(`aside`,{className:`asset-candidates`,"aria-label":`Candidate assets`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:`Candidate assets`}),(0,X.jsxs)(`p`,{children:[o.channel,` · not posted · page `,d?.page||a,` of `,d?.totalPages||1]})]}),t&&(0,X.jsx)(`span`,{children:`Loading`})]}),(0,X.jsxs)(`div`,{className:`candidate-list`,children:[u.map(e=>(0,X.jsxs)(`article`,{children:[(0,X.jsxs)(`button`,{className:`candidate-title`,onClick:()=>r(e.asset_id),type:`button`,children:[(0,X.jsx)(`strong`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id})]}),(0,X.jsxs)(`span`,{children:[e.content_type,` · `,Ye(e)]}),(0,X.jsxs)(`button`,{disabled:l.has(e.asset_id),onClick:()=>void n(e.asset_id),type:`button`,children:[(0,X.jsx)(U,{size:15}),l.has(e.asset_id)?`Attached`:`Attach`]})]},e.asset_id)),!t&&u.length===0&&(0,X.jsx)(`p`,{children:`No candidate assets for this channel yet.`})]}),(0,X.jsxs)(`div`,{className:`candidate-pager`,children:[(0,X.jsxs)(`button`,{disabled:!d||d.page<=1,onClick:()=>i(a-1),type:`button`,children:[(0,X.jsx)(s,{size:15}),`Prev`]}),(0,X.jsxs)(`button`,{disabled:!d||d.page>=d.totalPages,onClick:()=>i(a+1),type:`button`,children:[`Next`,(0,X.jsx)(e,{size:15})]})]})]})}function Ze(e){let t=Z(e.cli||null,`content post phase --project '${e.post.project}' --post-id '${e.post.id}' --phase scheduled --scheduled-at <iso> --confirm-write`),n=Qe(e.post)||t,r=e.post.assets.length>0;return(0,X.jsxs)(`article`,{className:`post-card phase-${e.post.phase} ${e.isTarget?`is-target`:``}`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`label`,{className:`post-select`,children:[(0,X.jsx)(`input`,{"aria-label":`Select ${e.post.title}`,checked:e.checked,onChange:t=>e.onToggleSelected(t.target.checked),type:`checkbox`}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e.post.title}),(0,X.jsx)(`code`,{children:e.post.id})]})]}),(0,X.jsxs)(`div`,{className:`post-status`,children:[e.isTarget&&(0,X.jsx)(`b`,{className:`target-state`,children:`next target`}),(0,X.jsxs)(`span`,{children:[e.post.channel,`: `,e.post.phase]}),e.post.readiness&&(0,X.jsx)(`b`,{className:`readiness-state`,children:$e(e.post.readiness)}),(0,X.jsx)(`b`,{className:r?`asset-state has-asset`:`asset-state needs-asset`,children:r?`${e.post.assets.length} asset${e.post.assets.length===1?``:`s`}`:`needs asset`})]})]}),(0,X.jsxs)(`div`,{className:`post-assets`,children:[e.post.assets.map(t=>(0,X.jsxs)(`button`,{className:`asset-chip`,onClick:()=>e.onOpenAsset(t.asset_id),type:`button`,children:[t.role,`: `,t.asset_id,` · `,Ye(e.assetLookup[t.asset_id])]},`${t.asset_id}-${t.role}`)),!r&&(0,X.jsx)(`span`,{className:`muted-pill`,children:`no attached assets`})]}),(0,X.jsxs)(`div`,{className:`phase-controls`,children:[(0,X.jsx)(`input`,{"aria-label":`Scheduled at for ${e.post.id}`,onChange:t=>e.setPhaseInputs({...e.phaseInputs,scheduledAt:t.target.value}),type:`datetime-local`,value:e.phaseInputs.scheduledAt}),(0,X.jsx)(`input`,{"aria-label":`Posted URL for ${e.post.id}`,onChange:t=>e.setPhaseInputs({...e.phaseInputs,url:t.target.value}),placeholder:`Posted URL`,value:e.phaseInputs.url}),(0,X.jsxs)(`button`,{onClick:()=>void e.setPhase(e.post,`review`),type:`button`,children:[(0,X.jsx)(T,{size:15}),`Review`]}),(0,X.jsxs)(`button`,{onClick:()=>void e.setPhase(e.post,`scheduled`),type:`button`,children:[(0,X.jsx)(x,{size:15}),`Schedule`]}),(0,X.jsxs)(`button`,{onClick:()=>void e.setPhase(e.post,`posted`),type:`button`,children:[(0,X.jsx)(oe,{size:15}),`Posted`]})]}),(0,X.jsxs)(`div`,{className:`attach-row`,children:[(0,X.jsx)(`input`,{"aria-label":`Asset id for ${e.post.id}`,onChange:t=>e.setAttachForm({...e.attachForm,assetId:t.target.value,postId:e.post.id}),placeholder:e.selectedAsset?.asset_id||`asset-id`,value:e.attachForm.postId===e.post.id?e.attachForm.assetId:``}),(0,X.jsxs)(`button`,{onClick:()=>void e.attachAsset(),type:`button`,children:[(0,X.jsx)(U,{size:15}),`Attach `,e.selectedAsset?`selected`:`asset`]}),(0,X.jsxs)(`button`,{className:e.isTarget?`target-button active`:`target-button`,onClick:()=>void e.onSetTarget(),type:`button`,children:[(0,X.jsx)(z,{size:15}),e.isTarget?`Selected`:`Set next`]}),(0,X.jsxs)(`button`,{className:`text-button`,onClick:e.onPreview,type:`button`,children:[(0,X.jsx)(N,{size:15}),`Preview`]}),(0,X.jsx)(`button`,{className:`text-button`,onClick:()=>void e.onCopy(n,`content post handoff`),type:`button`,children:`Copy handoff`})]})]})}function Qe(e){return e.handoff?[`Content post: ${e.title}`,`Project: ${e.project}`,`Batch: ${e.batch_id}`,`Channel: ${e.channel}`,`Post: ${e.id}`,`Readiness: ${e.readiness||`unknown`}`,``,e.handoff.agentPrompt,e.handoff.inspectBatchCommand,e.handoff.setTargetTemplate,e.handoff.attachAssetTemplate,e.handoff.moveToReviewCommand,e.handoff.scheduleTemplate,e.handoff.markPostedTemplate].filter(Boolean).join(`
3
+ `):``}function $e(e){return e.replace(/_/g,` `)}var et=[`draft`,`review`,`scheduled`,`posted`,`skipped`,`archived`];function tt({channels:e,filters:t,filteredCount:n,needsAssetCount:r,selectedCount:i,setFilters:a,setPhase:o,totalCount:s}){return(0,X.jsxs)(`div`,{className:`content-tools`,children:[(0,X.jsxs)(`div`,{className:`filter-row`,children:[(0,X.jsxs)(`select`,{"aria-label":`Filter content phase`,onChange:e=>a({...t,phase:e.target.value}),value:t.phase,children:[(0,X.jsx)(`option`,{value:`all`,children:`all phases`}),et.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))]}),(0,X.jsxs)(`select`,{"aria-label":`Filter content channel`,onChange:e=>a({...t,channel:e.target.value}),value:t.channel,children:[(0,X.jsx)(`option`,{value:`all`,children:`all channels`}),e.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))]}),(0,X.jsxs)(`select`,{"aria-label":`Filter content asset state`,onChange:e=>a({...t,asset:e.target.value}),value:t.asset,children:[(0,X.jsx)(`option`,{value:`all`,children:`all asset states`}),(0,X.jsx)(`option`,{value:`needs-assets`,children:`needs asset`}),(0,X.jsx)(`option`,{value:`has-assets`,children:`has asset`})]}),(0,X.jsxs)(`span`,{children:[n,`/`,s,` posts · `,r,` need assets`]})]}),(0,X.jsxs)(`div`,{className:`bulk-row`,children:[(0,X.jsxs)(`span`,{children:[i,` selected`]}),[`review`,`scheduled`,`posted`].map(e=>(0,X.jsx)(`button`,{disabled:i===0,onClick:()=>void o(e),type:`button`,children:e===`review`?`Move to review`:`Mark ${e}`},e))]})]})}function nt({onCopy:e,post:t}){return(0,X.jsxs)(`aside`,{className:`post-preview`,"aria-label":`Post markdown preview`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:t.title}),(0,X.jsxs)(`p`,{children:[t.channel,` · `,t.phase,` · `,t.source_path||`manual post`]})]}),(0,X.jsx)(`button`,{className:`text-button`,onClick:()=>void e(t.body||``,`post markdown`),type:`button`,children:`Copy markdown`}),(0,X.jsx)(`pre`,{children:t.body||`No markdown body saved for this post yet.`})]})}function rt(e,t){return Z(e,`agent next --project '${t}'`)}function it({cli:e=null,onCopy:t,onFocusPost:n,queue:r}){if(!r)return null;let i=rt(e,r.project);return(0,X.jsxs)(`section`,{className:`content-queue`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h3`,{children:[(0,X.jsx)(O,{size:16}),`Content ops queue`]}),(0,X.jsxs)(`p`,{children:[r.totals.posts,` posts · `,r.totals.lanes.needs_asset,` need assets · `,r.totals.lanes.in_review,` in review`]})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,onClick:()=>void t(r.handoff.inspectQueueCommand,`content queue inspect command`),type:`button`,children:[(0,X.jsx)(T,{size:15}),`Copy queue`]}),(0,X.jsxs)(`button`,{className:`secondary-button`,onClick:()=>void t(i,`agent next command`),type:`button`,children:[(0,X.jsx)(T,{size:15}),`Copy agent next`]})]}),(0,X.jsxs)(`div`,{className:`queue-storage`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(B,{size:14}),r.totals.storage.local,` local`]}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(k,{size:14}),r.totals.storage.s3,` S3`]}),(0,X.jsxs)(`span`,{children:[r.totals.storage.unresolved,` unresolved`]}),(0,X.jsx)(`code`,{children:i})]}),r.next_action&&(0,X.jsxs)(`div`,{className:`queue-next-action`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{children:`Next action`}),(0,X.jsx)(`strong`,{children:r.next_action.post.title}),(0,X.jsxs)(`code`,{children:[r.next_action.post.channel,` · `,r.next_action.readiness]})]}),(0,X.jsxs)(`div`,{className:`queue-item-actions`,children:[(0,X.jsxs)(`button`,{"aria-label":`Focus next action ${r.next_action.post.id}`,onClick:()=>void n(r.next_action.post),type:`button`,children:[(0,X.jsx)(ae,{size:14}),`Focus`]}),(0,X.jsxs)(`button`,{"aria-label":`Copy next action ${r.next_action.post.id} handoff`,onClick:()=>void t(st(r.next_action,e),`content queue next action handoff`),type:`button`,children:[(0,X.jsx)(T,{size:14}),`Copy`]})]})]}),(0,X.jsx)(`div`,{className:`queue-lanes`,children:r.lanes.map(i=>(0,X.jsxs)(`article`,{className:`queue-lane`,"data-lane-id":i.id,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{className:`queue-lane-title`,children:[(0,X.jsx)(`strong`,{children:i.label}),(0,X.jsx)(`span`,{children:i.total})]}),i.items.length>0&&(0,X.jsxs)(`div`,{className:`queue-lane-actions`,children:[(0,X.jsxs)(`button`,{"aria-label":`Focus ${i.label} lane`,onClick:()=>void n(i.items[0].post),type:`button`,children:[(0,X.jsx)(ae,{size:13}),`Focus first`]}),(0,X.jsxs)(`button`,{"aria-label":`Copy ${i.label} lane handoff`,onClick:()=>void t(ct(i,r.handoff.inspectQueueCommand,e),`content queue lane handoff`),type:`button`,children:[(0,X.jsx)(T,{size:13}),`Copy lane`]})]})]}),(0,X.jsxs)(`div`,{className:`queue-items`,children:[i.items.map(r=>(0,X.jsx)(at,{cli:e,item:r,onCopy:t,onFocusPost:n},`${i.id}-${r.post.id}`)),i.items.length===0&&(0,X.jsx)(`p`,{className:`queue-empty`,children:`Empty`})]})]},i.id))})]})}function at({cli:e,item:t,onCopy:n,onFocusPost:r}){let i=st(t,e);return(0,X.jsxs)(`div`,{className:t.is_target?`queue-item is-target`:`queue-item`,"data-post-id":t.post.id,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:t.post.title}),(0,X.jsxs)(`code`,{children:[t.post.channel,` · `,t.readiness]})]}),(0,X.jsxs)(`div`,{className:`queue-item-meta`,children:[(0,X.jsxs)(`span`,{children:[t.attached_asset_count,` asset`,t.attached_asset_count===1?``:`s`]}),(0,X.jsx)(`span`,{children:ot(t)}),t.backup_cue&&(0,X.jsx)(`span`,{className:t.backup_cue.local_only>0?`queue-backup-cue local-only`:`queue-backup-cue`,children:t.backup_cue.label})]}),(0,X.jsxs)(`div`,{className:`queue-item-actions`,children:[(0,X.jsxs)(`button`,{"aria-label":`Focus ${t.post.id}`,onClick:()=>void r(t.post),type:`button`,children:[(0,X.jsx)(ae,{size:14}),`Focus`]}),i&&(0,X.jsxs)(`button`,{"aria-label":`Copy ${t.post.id} handoff`,onClick:()=>void n(i,`content queue item handoff`),type:`button`,children:[(0,X.jsx)(T,{size:14}),`Copy`]})]})]})}function ot(e){let t=e.asset_storage;return t.total===0?`no storage`:[t.local>0?`${t.local} local`:``,t.s3>0?`${t.s3} S3`:``,t.unresolved>0?`${t.unresolved} unresolved`:``].filter(Boolean).join(` · `)}function st(e,t){return e.handoff?[`Content queue item: ${e.post.title}`,`Post: ${e.post.id}`,`Readiness: ${e.readiness}`,`Storage: ${ot(e)}`,e.backup_cue?`Backup cue: ${e.backup_cue.label}`:``,``,e.handoff.agentPrompt,rt(t,e.post.project),e.handoff.inspectBatchCommand,e.backup_cue?.local_queue_command,e.backup_cue?.local_review_command,e.backup_cue?.local_backup_command,e.handoff.setTargetTemplate,e.handoff.attachAssetTemplate,e.handoff.moveToReviewCommand,e.handoff.scheduleTemplate,e.handoff.markPostedTemplate].filter(Boolean).join(`
4
+ `):``}function ct(e,t,n){let r=e.items[0];return[`Content queue lane: ${e.label}`,`Readiness: ${e.id}`,`Items: ${e.total}`,``,...e.items.slice(0,6).map(e=>`- ${e.post.id}: ${e.post.title} (${e.post.channel} · ${e.post.phase} · ${ot(e)})`),e.total>6?`- ${e.total-6} more item${e.total-6==1?``:`s`}`:``,``,r?.handoff?.agentPrompt,r?rt(n,r.post.project):``,t,r?.handoff?.inspectBatchCommand,r?.backup_cue?.local_queue_command,r?.backup_cue?.local_review_command,r?.backup_cue?.local_backup_command,r?.handoff?.setTargetTemplate,r?.handoff?.attachAssetTemplate,r?.handoff?.moveToReviewCommand].filter(Boolean).join(`
5
+ `)}function lt(e,t){return Z(e,`agent selected --project '${t}'`)}function ut(e,t){return Z(e,`agent "work on the selected target for ${t}" --project '${t}'`)}function dt({agentClaims:e=[],cli:t=null,onClear:n,onCopy:r,pending:i,target:a}){let o=a?.target,s=o?.handoff||a?.handoff,c=a?.project||o?.post.project||``,l=c?lt(t,c):``,u=c?ut(t,c):``,d=o?ft(e,o.post.project,o.post.id,o.post.channel):[];return(0,X.jsxs)(`section`,{className:`target-panel ${o?`has-target`:`empty-target`}`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h3`,{children:[(0,X.jsx)(z,{size:16}),`Next content target`]}),(0,X.jsx)(`p`,{children:o?`${o.post.channel} · ${o.readiness}`:`No selected target yet`})]}),(0,X.jsxs)(`div`,{className:`target-actions`,children:[s&&(0,X.jsxs)(`button`,{className:`secondary-button`,onClick:()=>void r(s.inspectTargetCommand,`content target inspect command`),type:`button`,children:[(0,X.jsx)(T,{size:15}),`Copy inspect`]}),l&&(0,X.jsxs)(`button`,{className:`secondary-button`,onClick:()=>void r(l,`agent selected command`),type:`button`,children:[(0,X.jsx)(T,{size:15}),`Copy agent`]}),o&&(0,X.jsxs)(`button`,{className:`secondary-button danger`,disabled:i,onClick:()=>void n(),type:`button`,children:[(0,X.jsx)(de,{size:15}),`Clear`]})]})]}),o?(0,X.jsxs)(`div`,{className:`target-body`,children:[(0,X.jsx)(`strong`,{children:o.post.title}),(0,X.jsx)(`code`,{children:o.post.id}),(0,X.jsxs)(`div`,{className:`target-meta`,children:[(0,X.jsx)(`span`,{children:o.batch.id}),(0,X.jsxs)(`span`,{children:[o.post.assets.length,` asset`,o.post.assets.length===1?``:`s`]}),(0,X.jsx)(`span`,{children:`SQLite target`}),o.notes&&(0,X.jsx)(`span`,{children:o.notes})]}),pt(d),(0,X.jsx)(`p`,{children:o.handoff.agentPrompt}),(0,X.jsx)(`code`,{className:`agent-command`,children:l}),(0,X.jsxs)(`div`,{className:`target-actions wrap`,children:[(0,X.jsx)(`button`,{onClick:()=>void r(l,`agent selected command`),type:`button`,children:`Copy selected`}),(0,X.jsx)(`button`,{onClick:()=>void r(u,`agent selected prompt`),type:`button`,children:`Copy prompt`}),(0,X.jsx)(`button`,{onClick:()=>void r(o.handoff.attachAssetTemplate,`content target attach command`),type:`button`,children:`Copy attach`}),(0,X.jsx)(`button`,{onClick:()=>void r(o.handoff.moveToReviewCommand,`content target review command`),type:`button`,children:`Copy review`}),(0,X.jsx)(`button`,{onClick:()=>void r(o.handoff.scheduleTemplate,`content target schedule command`),type:`button`,children:`Copy schedule`})]})]}):(0,X.jsxs)(`div`,{className:`target-empty`,children:[(0,X.jsx)(`p`,{children:`Choose Set next on a post so agents can inspect the same SQLite target from the CLI.`}),c&&(0,X.jsx)(`code`,{className:`agent-command`,children:lt(t,c)})]})]})}function ft(e,t,n,r){return e.filter(e=>e.project!==t||e.status!==`active`||e.derived_state===`expired`?!1:e.scope_type===`content_post`&&e.target_id===n?!0:e.scope_type===`project_channel`&&(!e.channel||!r||e.channel===r))}function pt(e){if(e.length===0)return null;let t=e.some(e=>e.derived_state===`stale`)?`stale`:e.some(e=>e.derived_state===`idle`)?`idle`:`active`,n=e.length===1?`${t===`active`?`Claimed`:t===`idle`?`Idle claim`:`Stale claim`} by ${e[0].agent_name}`:`${e.length} active claims`;return(0,X.jsxs)(`p`,{className:`target-claim-occupancy ${t}`,children:[(0,X.jsx)(se,{size:14}),(0,X.jsx)(`span`,{children:n}),e.length===1&&(0,X.jsxs)(`span`,{className:`target-claim-actions`,children:[e[0].derived_state===`stale`&&(0,X.jsx)(`button`,{onClick:()=>{mt(`release-stale`,e[0])},type:`button`,children:`Release stale`}),(0,X.jsx)(`button`,{onClick:()=>{mt(`transfer`,e[0])},type:`button`,children:`Transfer`}),(0,X.jsx)(`button`,{onClick:()=>{mt(`revoke`,e[0])},type:`button`,children:`Revoke`})]})]})}async function mt(e,t){let n=ht(e,t);n&&await g(`/api/agent-claims/${t.id}/${e}`,{body:JSON.stringify({project:t.project,...n}),headers:{"Content-Type":`application/json`},method:`POST`})}function ht(e,t){if(e===`release-stale`)return window.confirm(`Release stale claim held by ${t.agent_name}?`)?{confirmWrite:!0,reason:`Released stale ${t.scope_type} claim ${t.id} from the content target panel.`}:null;if(e===`revoke`){let e=window.prompt(`Reason for revoking ${t.agent_name}'s claim?`);return!e?.trim()||!window.confirm(`Revoke claim ${t.id} from ${t.agent_name}?`)?null:{confirmWrite:!0,reason:e.trim()}}let n=window.prompt(`Transfer claim ${t.id} to which agent?`);return!n?.trim()||!window.confirm(`Transfer claim ${t.id} from ${t.agent_name} to ${n.trim()}?`)?null:{confirmWrite:!0,reason:`Transferred from content target panel.`,toAgentName:n.trim()}}var gt=[`draft`,`review`,`scheduled`,`posted`,`skipped`,`archived`];function _t({onCopy:e,onOpenAsset:t,onToast:n,onWorkTargetsChanged:r,project:i,selectedAsset:a}){let s=Ne(),[c,l]=(0,p.useState)(null),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(``),[h,_]=(0,p.useState)(!1),[v,y]=(0,p.useState)(``),[b,x]=(0,p.useState)(null),[S,C]=(0,p.useState)({batchId:``,campaign:`2026-06-organic-traffic-test`,channel:``,title:``}),[w,T]=(0,p.useState)({channel:`tiktok`,phase:`draft`,postId:``,title:``}),[E,D]=(0,p.useState)({batchId:`demo-2026-06-priority`,kind:`drafts`,title:`Demo imported drafts`}),[O,k]=(0,p.useState)({asset:`all`,channel:`all`,phase:`all`}),[A,j]=(0,p.useState)({assetId:``,postId:``,role:`primary`}),[M,N]=(0,p.useState)({}),[P,F]=(0,p.useState)([]),[I,L]=(0,p.useState)(``),[R,z]=(0,p.useState)(null),[B,V]=(0,p.useState)(1),[H,U]=(0,p.useState)(!1),[W,ee]=(0,p.useState)(null),[te,ne]=(0,p.useState)(null),[re,ie]=(0,p.useState)([]),ae=c?.batches||[],oe=(0,p.useMemo)(()=>ae.find(e=>e.id===f)||ae[0],[ae,f]),se=(0,p.useMemo)(()=>[...new Set((u?.posts||[]).map(e=>e.channel))].sort(),[u]),G=(0,p.useMemo)(()=>(u?.posts||[]).filter(e=>{let t=O.phase===`all`||e.phase===O.phase,n=O.channel===`all`||e.channel===O.channel,r=O.asset===`all`||O.asset===`has-assets`&&e.assets.length>0||O.asset===`needs-assets`&&e.assets.length===0;return t&&n&&r}),[u,O]),ce=(0,p.useMemo)(()=>(u?.posts||[]).filter(e=>e.assets.length===0).length,[u]),le=(0,p.useMemo)(()=>(u?.posts||[]).find(e=>e.id===I)||G[0],[u,G,I]),K=R?.assets||[],ue=(0,p.useMemo)(()=>Object.fromEntries(K.map(e=>[e.asset_id,e])),[K]);async function de(e=oe?.id||f){_(!0),x(null);try{let t=new URLSearchParams({project:i}),[n,r,a,o]=await Promise.all([g(`/api/content/batches?${t}`),g(`/api/content/target?${t}`),g(`/api/content/queue?${t}`),g(`/api/agent-claims?${t}`)]);l(n),ee(r),ne(a),ie(o.claims);let s=e||n.batches[0]?.id||``;m(s),d(s?await g(`/api/content/batches/${s}?${new URLSearchParams({project:i})}`):null)}catch(e){x(e instanceof Error?e.message:String(e))}finally{_(!1)}}(0,p.useEffect)(()=>{de(``)},[i]),(0,p.useEffect)(()=>{F([]),L(``),V(1)},[u?.batch.id]),(0,p.useEffect)(()=>{V(1)},[le?.id]),(0,p.useEffect)(()=>{if(!le){z(null);return}let e=new URLSearchParams({channel:le.channel,page:String(B),pageSize:`6`,placementStatus:`not-posted`,project:i,source:`all`});U(!0),g(`/api/assets?${e}`).then(z).catch(e=>n(`error`,e instanceof Error?e.message:String(e))).finally(()=>U(!1))},[B,n,le,i]);async function q(e,t,i=oe?.id||``){y(e);try{await t(),n(`ok`,e),await de(i),r?.()}catch(e){n(`error`,e instanceof Error?e.message:String(e))}finally{y(``)}}async function fe(){await q(`Saved content batch`,()=>g(`/api/content/batches`,{body:JSON.stringify({...S,confirmWrite:!0,project:i}),headers:{"Content-Type":`application/json`},method:`POST`}),S.batchId),C(e=>({...e,batchId:``,title:``}))}async function pe(){oe&&(await q(`Saved content post`,()=>g(`/api/content/posts`,{body:JSON.stringify({...w,batchId:oe.id,confirmWrite:!0,project:i}),headers:{"Content-Type":`application/json`},method:`POST`})),T(e=>({...e,postId:``,title:``})))}async function me(){await q(`Imported demo content batch`,()=>g(`/api/content/import/demo`,{body:JSON.stringify({...E,confirmWrite:!0,project:i}),headers:{"Content-Type":`application/json`},method:`POST`}),E.batchId)}function J(e,t){F(n=>t?[...new Set([...n,e])]:n.filter(t=>t!==e))}async function he(e){let t=(u?.posts||[]).filter(e=>P.includes(e.id));if(t.length===0)return;let n=e===`posted`?new Date().toISOString():void 0;await q(`Marked ${t.length} posts ${e}`,()=>Promise.all(t.map(t=>g(`/api/content/posts/${t.id}`,{body:JSON.stringify({confirmWrite:!0,phase:e,postedAt:n,project:i}),headers:{"Content-Type":`application/json`},method:`POST`})))),F([])}async function Y(e){let t=A.assetId||a?.asset_id||``;await q(`Attached asset to post`,()=>g(`/api/content/posts/${e}/assets`,{body:JSON.stringify({assetId:t,confirmWrite:!0,project:i,role:A.role}),headers:{"Content-Type":`application/json`},method:`POST`})),j(e=>({...e,assetId:``,postId:``}))}async function ge(e,t){await q(`Attached candidate asset to post`,()=>g(`/api/content/posts/${e}/assets`,{body:JSON.stringify({assetId:t,confirmWrite:!0,project:i,role:`primary`}),headers:{"Content-Type":`application/json`},method:`POST`}))}async function _e(e){await q(`Selected next content target`,()=>g(`/api/content/target`,{body:JSON.stringify({confirmWrite:!0,notes:`Selected from ${e.batch_id}`,postId:e.id,project:i}),headers:{"Content-Type":`application/json`},method:`POST`}))}async function ve(){await q(`Cleared next content target`,()=>g(`/api/content/target/clear`,{body:JSON.stringify({confirmWrite:!0,project:i}),headers:{"Content-Type":`application/json`},method:`POST`}))}async function ye(e){k({asset:`all`,channel:e.channel,phase:e.phase}),await de(e.batch_id),L(e.id)}async function be(e,t){let n=M[e.id]||{phase:t,postedAt:``,scheduledAt:``,url:``},r=n.scheduledAt?new Date(n.scheduledAt).toISOString():void 0,a=t===`posted`?n.postedAt||new Date().toISOString():n.postedAt||void 0;await q(`Marked ${e.id} ${t}`,()=>g(`/api/content/posts/${e.id}`,{body:JSON.stringify({confirmWrite:!0,phase:t,postedAt:a,project:i,scheduledAt:r,url:n.url||void 0}),headers:{"Content-Type":`application/json`},method:`POST`}))}return(0,X.jsxs)(`section`,{className:`content-view`,children:[(0,X.jsxs)(`header`,{className:`content-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Content batches`}),(0,X.jsxs)(`p`,{children:[i,` post drafts, attached assets, and phase state in SQLite.`]})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,disabled:h,onClick:()=>void de(),children:[(0,X.jsx)(o,{className:h?`spin`:``,size:17}),` Refresh`]})]}),b&&(0,X.jsx)(`div`,{className:`content-error`,children:b}),(0,X.jsxs)(`div`,{className:`content-grid`,children:[(0,X.jsxs)(`aside`,{className:`content-panel content-sidebar`,children:[(0,X.jsx)(vt,{form:S,pending:!!v,setForm:C,submit:fe}),(0,X.jsx)(yt,{form:E,pending:!!v,setForm:D,submit:me}),(0,X.jsxs)(`div`,{className:`batch-list`,children:[ae.map(e=>(0,X.jsxs)(`button`,{"aria-pressed":oe?.id===e.id,onClick:()=>void de(e.id),type:`button`,children:[(0,X.jsx)(`strong`,{children:e.title}),(0,X.jsx)(`code`,{children:e.id}),(0,X.jsxs)(`span`,{children:[e.post_count,` posts · `,St(e.phase_counts)]})]},e.id)),ae.length===0&&(0,X.jsx)(`p`,{className:`content-empty`,children:`No content batches yet.`})]})]}),(0,X.jsx)(`div`,{className:`content-panel batch-detail`,children:u?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(xt,{detail:u,onCopy:e}),(0,X.jsx)(dt,{agentClaims:re,cli:s,onClear:ve,onCopy:e,pending:!!v,target:W}),(0,X.jsx)(it,{cli:s,onCopy:e,onFocusPost:ye,queue:te}),(0,X.jsx)(bt,{form:w,pending:!!v,setForm:T,submit:pe}),(0,X.jsx)(tt,{channels:se,filters:O,filteredCount:G.length,needsAssetCount:ce,selectedCount:P.length,setFilters:k,setPhase:he,totalCount:u.posts.length}),le&&(0,X.jsxs)(`div`,{className:`post-workbench`,children:[(0,X.jsx)(nt,{post:le,onCopy:e}),(0,X.jsx)(Xe,{loading:H,onAttach:e=>ge(le.id,e),onOpenAsset:t,onPage:V,page:B,post:le,snapshot:R})]}),(0,X.jsxs)(`div`,{className:`post-list`,children:[G.map(n=>(0,X.jsx)(Ze,{attachAsset:()=>Y(n.id),attachForm:A,assetLookup:ue,checked:P.includes(n.id),cli:s,isTarget:W?.target?.post.id===n.id,onCopy:e,onOpenAsset:t,onPreview:()=>L(n.id),onSetTarget:()=>_e(n),onToggleSelected:e=>J(n.id,e),phaseInputs:M[n.id]||{phase:n.phase,postedAt:``,scheduledAt:``,url:``},post:n,selectedAsset:a,setAttachForm:j,setPhase:be,setPhaseInputs:e=>N(t=>({...t,[n.id]:e}))},n.id)),u.posts.length===0&&(0,X.jsx)(`p`,{className:`content-empty`,children:`No posts in this batch yet.`}),u.posts.length>0&&G.length===0&&(0,X.jsx)(`p`,{className:`content-empty`,children:`No posts match these filters.`})]})]}):(0,X.jsxs)(`div`,{className:`content-empty-state`,children:[(0,X.jsx)(`h3`,{children:`No batch selected`}),(0,X.jsx)(`p`,{children:`Create a batch or seed one with the CLI, then it will appear here.`}),(0,X.jsx)(`code`,{children:Z(s,`content batch create --project '${i}' --batch-id <id> --title <title> --confirm-write`)})]})})]})]})}function vt({form:e,pending:t,setForm:n,submit:r}){return(0,X.jsxs)(`form`,{className:`content-form`,onSubmit:e=>{e.preventDefault(),r()},children:[(0,X.jsx)(`h3`,{children:`New batch`}),(0,X.jsx)(`input`,{"aria-label":`Batch id`,onChange:t=>n({...e,batchId:t.target.value}),placeholder:`batch-id`,required:!0,value:e.batchId}),(0,X.jsx)(`input`,{"aria-label":`Batch title`,onChange:t=>n({...e,title:t.target.value}),placeholder:`Title`,required:!0,value:e.title}),(0,X.jsx)(`input`,{"aria-label":`Batch campaign`,onChange:t=>n({...e,campaign:t.target.value}),placeholder:`Campaign`,value:e.campaign}),(0,X.jsx)(`input`,{"aria-label":`Batch channel`,onChange:t=>n({...e,channel:t.target.value}),placeholder:`Optional channel`,value:e.channel}),(0,X.jsxs)(`button`,{className:`primary-button`,disabled:t,type:`submit`,children:[(0,X.jsx)(ie,{size:16}),`Create`]})]})}function yt({form:e,pending:t,setForm:n,submit:r}){return(0,X.jsxs)(`form`,{className:`content-form compact`,onSubmit:e=>{e.preventDefault(),r()},children:[(0,X.jsx)(`h3`,{children:`Import markdown`}),(0,X.jsx)(`input`,{"aria-label":`Import batch id`,onChange:t=>n({...e,batchId:t.target.value}),placeholder:`batch-id`,required:!0,value:e.batchId}),(0,X.jsx)(`input`,{"aria-label":`Import batch title`,onChange:t=>n({...e,title:t.target.value}),placeholder:`Title`,value:e.title}),(0,X.jsxs)(`select`,{"aria-label":`Import kind`,onChange:t=>n({...e,kind:t.target.value}),value:e.kind,children:[(0,X.jsx)(`option`,{value:`drafts`,children:`drafts`}),(0,X.jsx)(`option`,{value:`concepts`,children:`concepts`}),(0,X.jsx)(`option`,{value:`all`,children:`all`})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,disabled:t,type:`submit`,children:[(0,X.jsx)(F,{size:16}),`Import demo`]})]})}function bt({form:e,pending:t,setForm:n,submit:r}){return(0,X.jsxs)(`form`,{className:`content-form inline`,onSubmit:e=>{e.preventDefault(),r()},children:[(0,X.jsx)(`h3`,{children:`New post`}),(0,X.jsx)(`input`,{"aria-label":`Post id`,onChange:t=>n({...e,postId:t.target.value}),placeholder:`post-id`,required:!0,value:e.postId}),(0,X.jsx)(`input`,{"aria-label":`Post title`,onChange:t=>n({...e,title:t.target.value}),placeholder:`Title`,required:!0,value:e.title}),(0,X.jsx)(`input`,{"aria-label":`Post channel`,onChange:t=>n({...e,channel:t.target.value}),placeholder:`Channel`,required:!0,value:e.channel}),(0,X.jsx)(`select`,{"aria-label":`Post phase`,onChange:t=>n({...e,phase:t.target.value}),value:e.phase,children:gt.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsxs)(`button`,{className:`primary-button`,disabled:t,type:`submit`,children:[(0,X.jsx)(ie,{size:16}),`Add post`]})]})}function xt({detail:e,onCopy:t}){return(0,X.jsxs)(`div`,{className:`batch-header`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{children:e.batch.title}),(0,X.jsxs)(`p`,{children:[e.batch.id,` · `,e.batch.campaign||`no campaign`,` · updated `,fe(e.batch.updated_at)]})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,onClick:()=>void t(e.handoff.inspectCommand,`content batch inspect command`),children:[(0,X.jsx)(T,{size:16}),`Copy handoff`]})]})}function St(e){return gt.filter(t=>e[t]>0).map(t=>`${e[t]} ${t}`).join(`, `)||`empty`}function Ct({copiedText:e,onDismiss:t}){return(0,X.jsxs)(`aside`,{className:`copy-fallback`,"aria-label":`Copied ${e.label}`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`strong`,{children:[`Copied `,e.label]}),(0,X.jsx)(`p`,{children:`Visible here too, so an agent handoff still works if browser clipboard access is blocked.`})]}),(0,X.jsx)(`code`,{children:e.text}),(0,X.jsx)(`button`,{onClick:t,type:`button`,children:`Dismiss`})]})}function wt(e,t){return Z(e,`agent selected --project '${t}'`)}function Tt(e,t){return Z(e,`agent "work on the selected target for ${t}" --project '${t}'`)}function Et(e,t){return Z(e,`agent next --project '${t}'`)}function Dt(e,t){return Z(e,`agent selections --project '${t}'`)}function Ot({onCopy:e,project:t,refreshKey:n,selectedAsset:r,view:i}){let a=Ne(),[o,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(null),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(null),[h,_]=(0,p.useState)(null),[v,y]=(0,p.useState)([]),[b,x]=(0,p.useState)(!1);async function S(){s(!0);try{let e=new URLSearchParams({project:t}),[n,r,i,a]=await Promise.all([g(`/api/content/target?${e}`),g(`/api/content/queue?${e}`),g(`/api/selections?${e}`),g(`/api/agent-claims?${e}`)]);m(n),_(r),d(i),y(a.claims),l(null)}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}}(0,p.useEffect)(()=>{S()},[t,n]),(0,p.useEffect)(()=>{let e=()=>{S()};return window.addEventListener(`asset-selection-updated`,e),()=>window.removeEventListener(`asset-selection-updated`,e)},[t]);async function C(e,n){let r=jt(e,n);r&&(await g(`/api/agent-claims/${n.id}/${e}`,{body:JSON.stringify({project:t,...r}),headers:{"Content-Type":`application/json`},method:`POST`}),await S())}return(0,X.jsx)(kt,{claims:v,cli:a,drawerOpen:b,error:c,loading:o,onClaimControl:(e,t)=>{C(e,t)},onCopy:e,onRefresh:()=>void S(),onToggleDrawer:()=>x(e=>!e),project:t,queue:h,selectedAsset:r,selection:u,target:f,view:i})}function kt({drawerOpen:e=!1,claims:t=[],cli:n=null,error:r,loading:i,onClaimControl:a,onCopy:s,onRefresh:c,onToggleDrawer:l,project:u,queue:d,selectedAsset:f,selection:p,target:m,view:h}){let g=h===`lineage`,_=m?.target,v=d?.next_action,y=p?.current.items.filter(e=>e.selected_at&&!e.deselected_at)||[],x=_?At(t,u,`content_post`,_.post.id,_.post.channel):[],C=v?At(t,u,`content_queue_lane`,d?.next_action_lane?.id||v.readiness,v.post.channel):[],w=p?.current?At(t,u,`selection_set`,p.current.id):[],E=new Set([...x,...C,...w].map(e=>e.id)).size,D=y.length>0?`${y.length} selected asset${y.length===1?``:`s`}`:_?`Selected content target`:v?`Next content item ready`:`Natural language handoff ready`,k=E>0?`${D} · ${E} claim${E===1?``:`s`}`:D;return(0,X.jsxs)(`section`,{className:`current-work-panel ${g?`lineage-context`:``} ${e?`open`:`collapsed`}`,"aria-label":`Agent context drawer`,"data-testid":`agent-context-drawer`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`button`,{"aria-controls":`agent-context-drawer-body`,"aria-expanded":e,className:`work-target-toggle`,"data-testid":`agent-context-toggle`,onClick:l,type:`button`,children:[(0,X.jsx)(`span`,{className:`work-target-toggle-icon`,children:(0,X.jsx)(b,{size:16})}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:`Agent context`}),(0,X.jsx)(`small`,{children:k})]}),(0,X.jsx)(S,{className:`work-target-chevron`,size:17})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,disabled:i,onClick:c,type:`button`,children:[(0,X.jsx)(o,{className:i?`spin`:``,size:15}),`Refresh`]})]}),(0,X.jsx)(`div`,{className:`work-target-drawer-body ${e?`open`:`collapsed`}`,"data-testid":`agent-context-drawer-body`,id:`agent-context-drawer-body`,style:{height:e?360:0,opacity:+!!e,transform:e?`translateY(0)`:`translateY(10px)`},children:(0,X.jsxs)(`div`,{className:`work-target-drawer-content`,children:[(0,X.jsx)(`p`,{className:`work-target-intro`,children:`Use plain English in the agent session, or keep the exact CLI commands here when precision helps.`}),r&&(0,X.jsx)(`p`,{className:`work-target-error`,children:r}),(0,X.jsxs)(`div`,{className:`work-target-grid`,children:[(0,X.jsxs)(`article`,{className:_?`work-target-card primary`:`work-target-card`,children:[(0,X.jsxs)(`div`,{className:`work-target-title`,children:[(0,X.jsx)(z,{size:16}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{children:`Content selected target`}),(0,X.jsx)(`small`,{children:`SQLite content target`})]})]}),_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:_.post.title}),(0,X.jsx)(`code`,{children:_.post.id}),(0,X.jsxs)(`p`,{children:[_.post.channel,` · `,_.readiness,` · `,_.post.assets.length,` asset`,_.post.assets.length===1?``:`s`]}),Mt(x,a),(0,X.jsx)(`code`,{className:`command-line`,children:wt(n,u)}),(0,X.jsxs)(`div`,{className:`work-target-actions`,children:[(0,X.jsxs)(`button`,{onClick:()=>void s(wt(n,u),`agent selected command`),type:`button`,children:[(0,X.jsx)(T,{size:14}),`Copy selected`]}),(0,X.jsxs)(`button`,{onClick:()=>void s(Tt(n,u),`agent selected prompt`),type:`button`,children:[(0,X.jsx)(T,{size:14}),`Copy prompt`]})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:`No selected content target`}),(0,X.jsx)(`p`,{children:`Say: work on the selected target for Demo.`}),(0,X.jsx)(`code`,{className:`command-line`,children:wt(n,u)})]})]}),(0,X.jsxs)(`article`,{className:`work-target-card`,children:[(0,X.jsxs)(`div`,{className:`work-target-title`,children:[(0,X.jsx)(O,{size:16}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{children:`Content queue next`}),(0,X.jsx)(`small`,{children:`Computed next action`})]})]}),v?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:v.post.title}),(0,X.jsx)(`code`,{children:v.post.id}),(0,X.jsxs)(`p`,{children:[v.post.channel,` · `,v.readiness,` · `,Nt(v.asset_storage)]}),Mt(C,a),(0,X.jsx)(`code`,{className:`command-line`,children:Et(n,u)}),(0,X.jsx)(`div`,{className:`work-target-actions`,children:(0,X.jsxs)(`button`,{onClick:()=>void s(Et(n,u),`agent next command`),type:`button`,children:[(0,X.jsx)(T,{size:14}),`Copy next`]})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:`No actionable queue item`}),(0,X.jsx)(`p`,{children:d?.warning||`Say: what should I work on next for Demo.`}),(0,X.jsx)(`code`,{className:`command-line`,children:Et(n,u)})]})]}),(0,X.jsxs)(`article`,{className:`work-target-card context`,children:[(0,X.jsxs)(`div`,{className:`work-target-title`,children:[(0,X.jsx)(I,{size:16}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{children:`Selected asset`}),(0,X.jsx)(`small`,{children:`UI context, not an agent target`})]})]}),f?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:f.title}),(0,X.jsx)(`code`,{children:f.asset_id}),(0,X.jsxs)(`p`,{children:[f.channel||`no channel`,` · `,f.status,` · `,ye(f).label]}),(0,X.jsx)(`div`,{className:`work-target-actions`,children:(0,X.jsxs)(`button`,{onClick:()=>void s(f.asset_id,`selected asset ID`),type:`button`,children:[(0,X.jsx)(T,{size:14}),`Copy asset ID`]})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:`No asset selected`}),(0,X.jsx)(`p`,{children:`Select an asset to use as context for content attachment, backup, or lineage work.`})]})]}),(0,X.jsxs)(`article`,{className:y.length>0?`work-target-card asset-selection`:`work-target-card`,"data-testid":`agent-context-asset-selections`,children:[(0,X.jsxs)(`div`,{className:`work-target-title`,children:[(0,X.jsx)(W,{size:16}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{children:`Asset selections`}),(0,X.jsx)(`small`,{children:`SQLite current set`})]})]}),y.length>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`strong`,{children:[y.length,` selected asset`,y.length===1?``:`s`]}),(0,X.jsx)(`code`,{children:y.map(e=>e.variation_label?`${e.variation_label}:${e.asset_id}`:e.asset_id).join(`, `)}),Mt(w,a),(0,X.jsx)(`code`,{className:`command-line`,children:Dt(n,u)}),(0,X.jsx)(`div`,{className:`work-target-actions`,children:(0,X.jsxs)(`button`,{onClick:()=>void s(Dt(n,u),`agent selections command`),type:`button`,children:[(0,X.jsx)(T,{size:14}),`Copy selections`]})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:`No selected assets`}),(0,X.jsx)(`p`,{children:`Say: keep working on my selections.`}),(0,X.jsx)(`code`,{className:`command-line`,children:Dt(n,u)})]})]})]})]})})]})}function At(e,t,n,r,i){return e.filter(e=>e.project!==t||e.status!==`active`||e.derived_state===`expired`?!1:e.scope_type===n&&e.target_id===r?!0:e.scope_type===`project_channel`&&(!e.channel||!i||e.channel===i))}function jt(e,t){if(e===`release-stale`)return window.confirm(`Release stale claim held by ${t.agent_name}?`)?{confirmWrite:!0,reason:`Released stale ${t.scope_type} claim ${t.id} from the Agent context drawer.`}:null;if(e===`revoke`){let e=window.prompt(`Reason for revoking ${t.agent_name}'s claim?`);return!e?.trim()||!window.confirm(`Revoke claim ${t.id} from ${t.agent_name}?`)?null:{confirmWrite:!0,reason:e.trim()}}let n=window.prompt(`Transfer claim ${t.id} to which agent?`);return!n?.trim()||!window.confirm(`Transfer claim ${t.id} from ${t.agent_name} to ${n.trim()}?`)?null:{confirmWrite:!0,reason:`Transferred from Agent context drawer.`,toAgentName:n.trim()}}function Mt(e,t){if(e.length===0)return null;let n=e.filter(e=>e.derived_state===`stale`).length>0?`stale`:e.some(e=>e.derived_state===`idle`)?`idle`:`active`,r=e.length===1?`${n===`active`?`Claimed`:n===`idle`?`Idle claim`:`Stale claim`} by ${e[0].agent_name}`:`${e.length} active claims`;return(0,X.jsxs)(`div`,{className:`claim-occupancy ${n}`,children:[(0,X.jsxs)(`p`,{children:[(0,X.jsx)(se,{size:14}),(0,X.jsx)(`span`,{children:r})]}),t&&e.length===1&&(0,X.jsxs)(`span`,{className:`claim-occupancy-actions`,children:[e[0].derived_state===`stale`&&(0,X.jsx)(`button`,{onClick:()=>t(`release-stale`,e[0]),type:`button`,children:`Release stale`}),(0,X.jsx)(`button`,{onClick:()=>t(`transfer`,e[0]),type:`button`,children:`Transfer`}),(0,X.jsx)(`button`,{onClick:()=>t(`revoke`,e[0]),type:`button`,children:`Revoke`})]})]})}function Nt(e){return e.total===0?`no assets`:[e.local?`${e.local} local`:``,e.s3?`${e.s3} S3`:``,e.unresolved?`${e.unresolved} unresolved`:``].filter(Boolean).join(` · `)}var Pt=[[`all`,`All storage`],[`local-only`,`Local only`],[`s3-backed`,`S3 backed`],[`local-and-s3`,`Local + S3`]],Ft=[[`all`,`All review`],[`unreviewed`,`Needs review`],[`approved`,`Approved`],[`needs_revision`,`Needs revision`]],It=[[`all`,`All placement`],[`scheduled`,`Scheduled`],[`posted`,`Posted`],[`not-posted`,`Not posted`],[`not-scheduled`,`No schedule`]],Lt=[[`all`,`All lineage`],[`selected`,`Next variation`],[`not-selected`,`Not selected`]];function Rt(e){let t=new Set(e.sources.map(e=>e.source_type));return t.has(`local`)&&t.has(`s3`)?`local + S3`:t.has(`local`)?`local only`:t.has(`s3`)?`S3 backed`:`catalog only`}function zt(e){let t=e.workflow.placements.at(-1);return t?`${t.channel}: ${t.status}`:`not scheduled`}function Bt(e){return e.workflow.selection?`selected`:e.workflow.placements.some(e=>e.status===`posted`)?`posted`:e.workflow.placements.some(e=>e.status===`scheduled`)?`scheduled`:e.workflow.review?.review_state===`approved`?`approved`:`working`}function Vt({project:e,query:t,onOpenAsset:n}){let[r,i]=(0,p.useState)(null),[a,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(!1),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(null),[h,_]=(0,p.useState)(1),[v,y]=(0,p.useState)(25),[b,x]=(0,p.useState)(`all`),[S,C]=(0,p.useState)(`all`),[w,T]=(0,p.useState)(`all`),[E,D]=(0,p.useState)(`all`),O=(0,p.useMemo)(()=>{let n=new URLSearchParams({project:e,page:String(h),pageSize:String(v)});return t.trim()&&n.set(`q`,t.trim()),b!==`all`&&n.set(`placement`,b),S!==`all`&&n.set(`review`,S),w!==`all`&&n.set(`selection`,w),E!==`all`&&n.set(`storage`,E),n},[h,v,b,e,t,S,w,E]);async function A(e=!1){d(null),s(!0),l(e);try{let t=new URLSearchParams(O);e&&t.set(`refresh`,`true`),i(await g(`/api/ledger?${t.toString()}`))}catch(e){d(e instanceof Error?e.message:String(e))}finally{s(!1),l(!1)}}(0,p.useEffect)(()=>{_(1)},[e,t,v,b,S,w,E]),(0,p.useEffect)(()=>{A(!1)},[O]),(0,p.useEffect)(()=>{!r||!f||r.records.some(e=>e.id===f)||m(null)},[f,r]);let j=r?.records||[];return(0,X.jsxs)(`section`,{className:`ledger-view`,children:[(0,X.jsxs)(`header`,{className:`ledger-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Ledger`}),(0,X.jsx)(`p`,{children:`SQLite truth table for local files, S3 objects, review state, posting state, and lineage selection.`})]}),(0,X.jsxs)(`div`,{className:`ledger-head-actions`,children:[(0,X.jsx)(`span`,{children:r?.last_index_run?.completed_at?`Indexed ${fe(r.last_index_run.completed_at)}`:`Not indexed yet`}),(0,X.jsxs)(`button`,{className:`secondary-button`,disabled:a,onClick:()=>void A(!0),children:[c?(0,X.jsx)(o,{className:`spin`,size:17}):(0,X.jsx)(k,{size:17}),`Refresh index`]})]})]}),u&&(0,X.jsx)(`div`,{className:`ledger-error`,children:u}),(0,X.jsxs)(`div`,{className:`ledger-summary`,"aria-label":`Ledger summary`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:r?.totals.records??0}),` records`]}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:r?.totals.local??0}),` local sources`]}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:r?.totals.s3??0}),` S3 sources`]}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:r?.totals.catalog??0}),` catalog entries`]})]}),(0,X.jsxs)(`div`,{className:`ledger-filters`,"aria-label":`Ledger quick filters`,children:[(0,X.jsx)(Wt,{current:E,label:`Storage`,options:Pt,setValue:D}),(0,X.jsx)(Wt,{current:S,label:`Review`,options:Ft,setValue:C}),(0,X.jsx)(Wt,{current:b,label:`Placement`,options:It,setValue:x}),(0,X.jsx)(Wt,{current:w,label:`Lineage`,options:Lt,setValue:T})]}),(0,X.jsx)(`div`,{className:`ledger-list`,"aria-label":`Asset ledger records`,children:j.map(e=>(0,X.jsx)(Ht,{expanded:f===e.id,onOpenAsset:n,onToggle:()=>m(t=>t===e.id?null:e.id),record:e},e.id))}),j.length===0&&(0,X.jsx)(`div`,{className:`ledger-empty`,children:`No ledger records match these filters. Refresh the index or loosen the filters.`}),(0,X.jsxs)(`footer`,{className:`pagination-bar`,children:[(0,X.jsx)(`button`,{disabled:!r||r.pagination.page<=1,onClick:()=>_(e=>Math.max(e-1,1)),children:`Previous`}),(0,X.jsxs)(`span`,{children:[r?.pagination.page||1,` of `,r?.pagination.totalPages||1]}),(0,X.jsx)(`button`,{disabled:!r||r.pagination.page>=r.pagination.totalPages,onClick:()=>_(e=>e+1),children:`Next`}),(0,X.jsxs)(`label`,{children:[`Per page`,(0,X.jsx)(`select`,{onChange:e=>y(Number(e.target.value)),value:v,children:[10,25,50,100].map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]})]})]})}function Ht({expanded:e,onOpenAsset:t,onToggle:n,record:r}){return(0,X.jsxs)(`article`,{className:`ledger-record ${Bt(r)} ${e?`expanded`:``}`,children:[(0,X.jsxs)(`button`,{"aria-expanded":e,className:`ledger-record-main`,onClick:n,type:`button`,children:[(0,X.jsxs)(`div`,{className:`ledger-record-title`,children:[(0,X.jsx)(`strong`,{children:r.title}),(0,X.jsx)(`code`,{children:r.canonical_asset_id})]}),(0,X.jsxs)(`div`,{className:`ledger-record-meta`,children:[(0,X.jsx)(`span`,{children:r.media_type}),r.channel?(0,X.jsx)(`span`,{children:r.channel}):null,r.campaign?(0,X.jsx)(`span`,{children:r.campaign}):null]}),(0,X.jsxs)(`div`,{className:`ledger-record-states`,children:[(0,X.jsx)(Ut,{label:Rt(r)}),(0,X.jsx)(Ut,{label:r.workflow.review?.review_state||`unreviewed`}),(0,X.jsx)(Ut,{label:zt(r)}),(0,X.jsx)(Ut,{label:r.workflow.selection?`next variation`:`not selected`})]})]}),e?(0,X.jsxs)(`div`,{className:`ledger-record-detail`,children:[(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{children:`Sources`}),(0,X.jsx)(`ul`,{children:r.sources.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`strong`,{children:e.source_type}),(0,X.jsx)(`span`,{children:e.local_path||e.s3_key||e.asset_id||`source recorded`})]},e.id))})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h3`,{children:`Workflow`}),(0,X.jsxs)(`p`,{children:[`Review: `,r.workflow.review?.review_state||`unreviewed`]}),(0,X.jsxs)(`p`,{children:[`Placement: `,zt(r)]}),(0,X.jsxs)(`p`,{children:[`Lineage: `,r.workflow.selection?`using ${r.workflow.selection.asset_id}`:`not selected for next variation`]})]}),(0,X.jsx)(`button`,{className:`secondary-button`,onClick:()=>t(r.canonical_asset_id),type:`button`,children:`View in Assets`})]}):null]})}function Ut({label:e}){return(0,X.jsx)(`span`,{className:`ledger-pill`,children:e})}function Wt({current:e,label:t,options:n,setValue:r}){return(0,X.jsxs)(`label`,{className:`ledger-filter-group`,children:[(0,X.jsx)(`span`,{children:t}),(0,X.jsx)(`select`,{"aria-label":t,onChange:e=>r(e.target.value),value:e,children:n.map(([e,t])=>(0,X.jsx)(`option`,{value:e,children:t},e))})]})}function Gt(e){if(typeof e==`string`||typeof e==`number`)return``+e;let t=``;if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Gt(e[n]))!==``&&(t+=(t&&` `)+r);else for(let n in e)e[n]&&(t+=(t&&` `)+n);return t}var Kt={value:()=>{}};function qt(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new Jt(n)}function Jt(e){this._=e}function Yt(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}Jt.prototype=qt.prototype={constructor:Jt,on:function(e,t){var n=this._,r=Yt(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=Xt(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=Zt(n[i],e.name,t);else if(t==null)for(i in n)n[i]=Zt(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Jt(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function Xt(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function Zt(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=Kt,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var Qt={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function $t(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),Qt.hasOwnProperty(t)?{space:Qt[t],local:e}:e}function en(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function tn(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function nn(e){var t=$t(e);return(t.local?tn:en)(t)}function rn(){}function an(e){return e==null?rn:function(){return this.querySelector(e)}}function on(e){typeof e!=`function`&&(e=an(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new Jr(r,this._parents)}function sn(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function cn(){return[]}function ln(e){return e==null?cn:function(){return this.querySelectorAll(e)}}function un(e){return function(){return sn(e.apply(this,arguments))}}function dn(e){e=typeof e==`function`?un(e):ln(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new Jr(r,i)}function fn(e){return function(){return this.matches(e)}}function pn(e){return function(t){return t.matches(e)}}var mn=Array.prototype.find;function hn(e){return function(){return mn.call(this.children,e)}}function gn(){return this.firstElementChild}function _n(e){return this.select(e==null?gn:hn(typeof e==`function`?e:pn(e)))}var vn=Array.prototype.filter;function yn(){return Array.from(this.children)}function bn(e){return function(){return vn.call(this.children,e)}}function xn(e){return this.selectAll(e==null?yn:bn(typeof e==`function`?e:pn(e)))}function Sn(e){typeof e!=`function`&&(e=fn(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new Jr(r,this._parents)}function Cn(e){return Array(e.length)}function wn(){return new Jr(this._enter||this._groups.map(Cn),this._parents)}function Tn(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Tn.prototype={constructor:Tn,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function En(e){return function(){return e}}function Dn(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new Tn(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function On(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new Tn(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function kn(e){return e.__data__}function An(e,t){if(!arguments.length)return Array.from(this,kn);var n=t?On:Dn,r=this._parents,i=this._groups;typeof e!=`function`&&(e=En(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=jn(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new Jr(o,r),o._enter=s,o._exit=c,o}function jn(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function Mn(){return new Jr(this._exit||this._groups.map(Cn),this._parents)}function Nn(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function Pn(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new Jr(s,this._parents)}function Fn(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function In(e){e||=Ln;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new Jr(i,this._parents).order()}function Ln(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Rn(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function zn(){return Array.from(this)}function Bn(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function Vn(){let e=0;for(let t of this)++e;return e}function Hn(){return!this.node()}function Un(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function Wn(e){return function(){this.removeAttribute(e)}}function Gn(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Kn(e,t){return function(){this.setAttribute(e,t)}}function qn(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Jn(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Yn(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Xn(e,t){var n=$t(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Gn:Wn:typeof t==`function`?n.local?Yn:Jn:n.local?qn:Kn)(n,t))}function Zn(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Qn(e){return function(){this.style.removeProperty(e)}}function $n(e,t,n){return function(){this.style.setProperty(e,t,n)}}function er(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function tr(e,t,n){return arguments.length>1?this.each((t==null?Qn:typeof t==`function`?er:$n)(e,t,n??``)):nr(this.node(),e)}function nr(e,t){return e.style.getPropertyValue(t)||Zn(e).getComputedStyle(e,null).getPropertyValue(t)}function rr(e){return function(){delete this[e]}}function ir(e,t){return function(){this[e]=t}}function ar(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function or(e,t){return arguments.length>1?this.each((t==null?rr:typeof t==`function`?ar:ir)(e,t)):this.node()[e]}function sr(e){return e.trim().split(/^|\s+/)}function cr(e){return e.classList||new lr(e)}function lr(e){this._node=e,this._names=sr(e.getAttribute(`class`)||``)}lr.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function ur(e,t){for(var n=cr(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function dr(e,t){for(var n=cr(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function fr(e){return function(){ur(this,e)}}function pr(e){return function(){dr(this,e)}}function mr(e,t){return function(){(t.apply(this,arguments)?ur:dr)(this,e)}}function hr(e,t){var n=sr(e+``);if(arguments.length<2){for(var r=cr(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?mr:t?fr:pr)(n,t))}function gr(){this.textContent=``}function _r(e){return function(){this.textContent=e}}function vr(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function yr(e){return arguments.length?this.each(e==null?gr:(typeof e==`function`?vr:_r)(e)):this.node().textContent}function br(){this.innerHTML=``}function xr(e){return function(){this.innerHTML=e}}function Sr(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function Cr(e){return arguments.length?this.each(e==null?br:(typeof e==`function`?Sr:xr)(e)):this.node().innerHTML}function wr(){this.nextSibling&&this.parentNode.appendChild(this)}function Tr(){return this.each(wr)}function Er(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Dr(){return this.each(Er)}function Or(e){var t=typeof e==`function`?e:nn(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function kr(){return null}function Ar(e,t){var n=typeof e==`function`?e:nn(e),r=t==null?kr:typeof t==`function`?t:an(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function jr(){var e=this.parentNode;e&&e.removeChild(this)}function Mr(){return this.each(jr)}function Nr(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Pr(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Fr(e){return this.select(e?Pr:Nr)}function Ir(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function Lr(e){return function(t){e.call(this,t,this.__data__)}}function Rr(e){return e.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 zr(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function Br(e,t,n){return function(){var r=this.__on,i,a=Lr(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function Vr(e,t,n){var r=Rr(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?Br:zr,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function Hr(e,t,n){var r=Zn(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function Ur(e,t){return function(){return Hr(this,e,t)}}function Wr(e,t){return function(){return Hr(this,e,t.apply(this,arguments))}}function Gr(e,t){return this.each((typeof t==`function`?Wr:Ur)(e,t))}function*Kr(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var qr=[null];function Jr(e,t){this._groups=e,this._parents=t}function Yr(){return new Jr([[document.documentElement]],qr)}function Xr(){return this}Jr.prototype=Yr.prototype={constructor:Jr,select:on,selectAll:dn,selectChild:_n,selectChildren:xn,filter:Sn,data:An,enter:wn,exit:Mn,join:Nn,merge:Pn,selection:Xr,order:Fn,sort:In,call:Rn,nodes:zn,node:Bn,size:Vn,empty:Hn,each:Un,attr:Xn,style:tr,property:or,classed:hr,text:yr,html:Cr,raise:Tr,lower:Dr,append:Or,insert:Ar,remove:Mr,clone:Fr,datum:Ir,on:Vr,dispatch:Gr,[Symbol.iterator]:Kr};function Zr(e){return typeof e==`string`?new Jr([[document.querySelector(e)]],[document.documentElement]):new Jr([[e]],qr)}function Qr(e){let t;for(;t=e.sourceEvent;)e=t;return e}function $r(e,t){if(e=Qr(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}var ei={passive:!1},ti={capture:!0,passive:!1};function ni(e){e.stopImmediatePropagation()}function ri(e){e.preventDefault(),e.stopImmediatePropagation()}function ii(e){var t=e.document.documentElement,n=Zr(e).on(`dragstart.drag`,ri,ti);`onselectstart`in t?n.on(`selectstart.drag`,ri,ti):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect=`none`)}function ai(e,t){var n=e.document.documentElement,r=Zr(e).on(`dragstart.drag`,null);t&&(r.on(`click.drag`,ri,ti),setTimeout(function(){r.on(`click.drag`,null)},0)),`onselectstart`in n?r.on(`selectstart.drag`,null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var oi=e=>()=>e;function si(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:a,x:o,y:s,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}si.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function ci(e){return!e.ctrlKey&&!e.button}function li(){return this.parentNode}function ui(e,t){return t??{x:e.x,y:e.y}}function di(){return navigator.maxTouchPoints||`ontouchstart`in this}function fi(){var e=ci,t=li,n=ui,r=di,i={},a=qt(`start`,`drag`,`end`),o=0,s,c,l,u,d=0;function f(e){e.on(`mousedown.drag`,p).filter(r).on(`touchstart.drag`,g).on(`touchmove.drag`,_,ei).on(`touchend.drag touchcancel.drag`,v).style(`touch-action`,`none`).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}function p(n,r){if(!(u||!e.call(this,n,r))){var i=y(this,t.call(this,n,r),n,r,`mouse`);i&&(Zr(n.view).on(`mousemove.drag`,m,ti).on(`mouseup.drag`,h,ti),ii(n.view),ni(n),l=!1,s=n.clientX,c=n.clientY,i(`start`,n))}}function m(e){if(ri(e),!l){var t=e.clientX-s,n=e.clientY-c;l=t*t+n*n>d}i.mouse(`drag`,e)}function h(e){Zr(e.view).on(`mousemove.drag mouseup.drag`,null),ai(e.view,l),ri(e),i.mouse(`end`,e)}function g(n,r){if(e.call(this,n,r)){var i=n.changedTouches,a=t.call(this,n,r),o=i.length,s,c;for(s=0;s<o;++s)(c=y(this,a,n,r,i[s].identifier,i[s]))&&(ni(n),c(`start`,n,i[s]))}}function _(e){var t=e.changedTouches,n=t.length,r,a;for(r=0;r<n;++r)(a=i[t[r].identifier])&&(ri(e),a(`drag`,e,t[r]))}function v(e){var t=e.changedTouches,n=t.length,r,a;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),r=0;r<n;++r)(a=i[t[r].identifier])&&(ni(e),a(`end`,e,t[r]))}function y(e,t,r,s,c,l){var u=a.copy(),d=$r(l||r,t),p,m,h;if((h=n.call(e,new si(`beforestart`,{sourceEvent:r,target:f,identifier:c,active:o,x:d[0],y:d[1],dx:0,dy:0,dispatch:u}),s))!=null)return p=h.x-d[0]||0,m=h.y-d[1]||0,function n(r,a,l){var g=d,_;switch(r){case`start`:i[c]=n,_=o++;break;case`end`:delete i[c],--o;case`drag`:d=$r(l||a,t),_=o;break}u.call(r,e,new si(r,{sourceEvent:a,subject:h,target:f,identifier:c,active:_,x:d[0]+p,y:d[1]+m,dx:d[0]-g[0],dy:d[1]-g[1],dispatch:u}),s)}}return f.filter=function(t){return arguments.length?(e=typeof t==`function`?t:oi(!!t),f):e},f.container=function(e){return arguments.length?(t=typeof e==`function`?e:oi(e),f):t},f.subject=function(e){return arguments.length?(n=typeof e==`function`?e:oi(e),f):n},f.touchable=function(e){return arguments.length?(r=typeof e==`function`?e:oi(!!e),f):r},f.on=function(){var e=a.on.apply(a,arguments);return e===a?f:e},f.clickDistance=function(e){return arguments.length?(d=(e=+e)*e,f):Math.sqrt(d)},f}function pi(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function mi(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function hi(){}var gi=.7,_i=1/gi,vi=`\\s*([+-]?\\d+)\\s*`,yi=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,bi=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,xi=/^#([0-9a-f]{3,8})$/,Si=RegExp(`^rgb\\(${vi},${vi},${vi}\\)$`),Ci=RegExp(`^rgb\\(${bi},${bi},${bi}\\)$`),wi=RegExp(`^rgba\\(${vi},${vi},${vi},${yi}\\)$`),Ti=RegExp(`^rgba\\(${bi},${bi},${bi},${yi}\\)$`),Ei=RegExp(`^hsl\\(${yi},${bi},${bi}\\)$`),Di=RegExp(`^hsla\\(${yi},${bi},${bi},${yi}\\)$`),Oi={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};pi(hi,Ni,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:ki,formatHex:ki,formatHex8:Ai,formatHsl:ji,formatRgb:Mi,toString:Mi});function ki(){return this.rgb().formatHex()}function Ai(){return this.rgb().formatHex8()}function ji(){return Ki(this).formatHsl()}function Mi(){return this.rgb().formatRgb()}function Ni(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=xi.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Pi(t):n===3?new Ri(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Fi(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Fi(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Si.exec(e))?new Ri(t[1],t[2],t[3],1):(t=Ci.exec(e))?new Ri(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=wi.exec(e))?Fi(t[1],t[2],t[3],t[4]):(t=Ti.exec(e))?Fi(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Ei.exec(e))?Gi(t[1],t[2]/100,t[3]/100,1):(t=Di.exec(e))?Gi(t[1],t[2]/100,t[3]/100,t[4]):Oi.hasOwnProperty(e)?Pi(Oi[e]):e===`transparent`?new Ri(NaN,NaN,NaN,0):null}function Pi(e){return new Ri(e>>16&255,e>>8&255,e&255,1)}function Fi(e,t,n,r){return r<=0&&(e=t=n=NaN),new Ri(e,t,n,r)}function Ii(e){return e instanceof hi||(e=Ni(e)),e?(e=e.rgb(),new Ri(e.r,e.g,e.b,e.opacity)):new Ri}function Li(e,t,n,r){return arguments.length===1?Ii(e):new Ri(e,t,n,r??1)}function Ri(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}pi(Ri,Li,mi(hi,{brighter(e){return e=e==null?_i:_i**+e,new Ri(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?gi:gi**+e,new Ri(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ri(Ui(this.r),Ui(this.g),Ui(this.b),Hi(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:zi,formatHex:zi,formatHex8:Bi,formatRgb:Vi,toString:Vi}));function zi(){return`#${Wi(this.r)}${Wi(this.g)}${Wi(this.b)}`}function Bi(){return`#${Wi(this.r)}${Wi(this.g)}${Wi(this.b)}${Wi((isNaN(this.opacity)?1:this.opacity)*255)}`}function Vi(){let e=Hi(this.opacity);return`${e===1?`rgb(`:`rgba(`}${Ui(this.r)}, ${Ui(this.g)}, ${Ui(this.b)}${e===1?`)`:`, ${e})`}`}function Hi(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Ui(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Wi(e){return e=Ui(e),(e<16?`0`:``)+e.toString(16)}function Gi(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ji(e,t,n,r)}function Ki(e){if(e instanceof Ji)return new Ji(e.h,e.s,e.l,e.opacity);if(e instanceof hi||(e=Ni(e)),!e)return new Ji;if(e instanceof Ji)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new Ji(o,s,c,e.opacity)}function qi(e,t,n,r){return arguments.length===1?Ki(e):new Ji(e,t,n,r??1)}function Ji(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}pi(Ji,qi,mi(hi,{brighter(e){return e=e==null?_i:_i**+e,new Ji(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?gi:gi**+e,new Ji(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new Ri(Zi(e>=240?e-240:e+120,i,r),Zi(e,i,r),Zi(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new Ji(Yi(this.h),Xi(this.s),Xi(this.l),Hi(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(){let e=Hi(this.opacity);return`${e===1?`hsl(`:`hsla(`}${Yi(this.h)}, ${Xi(this.s)*100}%, ${Xi(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function Yi(e){return e=(e||0)%360,e<0?e+360:e}function Xi(e){return Math.max(0,Math.min(1,e||0))}function Zi(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var Qi=e=>()=>e;function $i(e,t){return function(n){return e+n*t}}function ea(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function ta(e){return(e=+e)==1?na:function(t,n){return n-t?ea(t,n,e):Qi(isNaN(t)?n:t)}}function na(e,t){var n=t-e;return n?$i(e,n):Qi(isNaN(e)?t:e)}var ra=(function e(t){var n=ta(t);function r(e,t){var r=n((e=Li(e)).r,(t=Li(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=na(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function ia(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function aa(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function oa(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o;for(o=0;o<r;++o)i[o]=ha(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function sa(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function ca(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function la(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=ha(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var ua=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,da=new RegExp(ua.source,`g`);function fa(e){return function(){return e}}function pa(e){return function(t){return e(t)+``}}function ma(e,t){var n=ua.lastIndex=da.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=ua.exec(e))&&(i=da.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:ca(r,i)})),n=da.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?pa(c[0].x):fa(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function ha(e,t){var n=typeof t,r;return t==null||n===`boolean`?Qi(t):(n===`number`?ca:n===`string`?(r=Ni(t))?(t=r,ra):ma:t instanceof Ni?ra:t instanceof Date?sa:aa(t)?ia:Array.isArray(t)?oa:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?la:ca)(e,t)}var ga=180/Math.PI,_a={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function va(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*ga,skewX:Math.atan(c)*ga,scaleX:o,scaleY:s}}var ya;function ba(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?_a:va(t.a,t.b,t.c,t.d,t.e,t.f)}function xa(e){return e==null||(ya||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),ya.setAttribute(`transform`,e),!(e=ya.transform.baseVal.consolidate()))?_a:(e=e.matrix,va(e.a,e.b,e.c,e.d,e.e,e.f))}function Sa(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:ca(e,i)},{i:c-2,x:ca(r,a)})}else(i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:ca(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:ca(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:ca(e,n)},{i:s-2,x:ca(t,r)})}else(n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var Ca=Sa(ba,`px, `,`px)`,`deg)`),wa=Sa(xa,`, `,`)`,`)`),Ta=1e-12;function Ea(e){return((e=Math.exp(e))+1/e)/2}function Da(e){return((e=Math.exp(e))-1/e)/2}function Oa(e){return((e=Math.exp(2*e))-1)/(e+1)}var ka=(function e(t,n,r){function i(e,i){var a=e[0],o=e[1],s=e[2],c=i[0],l=i[1],u=i[2],d=c-a,f=l-o,p=d*d+f*f,m,h;if(p<Ta)h=Math.log(u/s)/t,m=function(e){return[a+e*d,o+e*f,s*Math.exp(t*e*h)]};else{var g=Math.sqrt(p),_=(u*u-s*s+r*p)/(2*s*n*g),v=(u*u-s*s-r*p)/(2*u*n*g),y=Math.log(Math.sqrt(_*_+1)-_);h=(Math.log(Math.sqrt(v*v+1)-v)-y)/t,m=function(e){var r=e*h,i=Ea(y),c=s/(n*g)*(i*Oa(t*r+y)-Da(y));return[a+c*d,o+c*f,s*i/Ea(t*r+y)]}}return m.duration=h*1e3*t/Math.SQRT2,m}return i.rho=function(t){var n=Math.max(.001,+t),r=n*n;return e(n,r,r*r)},i})(Math.SQRT2,2,4),Aa=0,ja=0,Ma=0,Na=1e3,Pa,Fa,Ia=0,La=0,Ra=0,za=typeof performance==`object`&&performance.now?performance:Date,Ba=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Va(){return La||=(Ba(Ha),za.now()+Ra)}function Ha(){La=0}function Ua(){this._call=this._time=this._next=null}Ua.prototype=Wa.prototype={constructor:Ua,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?Va():+n)+(t==null?0:+t),!this._next&&Fa!==this&&(Fa?Fa._next=this:Pa=this,Fa=this),this._call=e,this._time=n,Ya()},stop:function(){this._call&&(this._call=null,this._time=1/0,Ya())}};function Wa(e,t,n){var r=new Ua;return r.restart(e,t,n),r}function Ga(){Va(),++Aa;for(var e=Pa,t;e;)(t=La-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Aa}function Ka(){La=(Ia=za.now())+Ra,Aa=ja=0;try{Ga()}finally{Aa=0,Ja(),La=0}}function qa(){var e=za.now(),t=e-Ia;t>Na&&(Ra-=t,Ia=e)}function Ja(){for(var e,t=Pa,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Pa=n);Fa=e,Ya(r)}function Ya(e){Aa||(ja&&=clearTimeout(ja),e-La>24?(e<1/0&&(ja=setTimeout(Ka,e-za.now()-Ra)),Ma&&=clearInterval(Ma)):(Ma||=(Ia=za.now(),setInterval(qa,Na)),Aa=1,Ba(Ka)))}function Xa(e,t,n){var r=new Ua;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var Za=qt(`start`,`end`,`cancel`,`interrupt`),Qa=[];function $a(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;ro(e,n,{name:t,index:r,group:i,on:Za,tween:Qa,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function eo(e,t){var n=no(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function to(e,t){var n=no(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function no(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function ro(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Wa(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return Xa(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(Xa(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function io(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function ao(e){return this.each(function(){io(this,e)})}function oo(e,t){var n,r;return function(){var i=to(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function so(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=to(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function co(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=no(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?oo:so)(n,e,t))}function lo(e,t,n){var r=e._id;return e.each(function(){var e=to(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return no(e,r).value[t]}}function uo(e,t){var n;return(typeof t==`number`?ca:t instanceof Ni?ra:(n=Ni(t))?(t=n,ra):ma)(e,t)}function fo(e){return function(){this.removeAttribute(e)}}function po(e){return function(){this.removeAttributeNS(e.space,e.local)}}function mo(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function ho(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function go(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function _o(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function vo(e,t){var n=$t(e),r=n===`transform`?wa:uo;return this.attrTween(e,typeof t==`function`?(n.local?_o:go)(n,r,lo(this,`attr.`+e,t)):t==null?(n.local?po:fo)(n):(n.local?ho:mo)(n,r,t))}function yo(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function bo(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function xo(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&bo(e,i)),n}return i._value=t,i}function So(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&yo(e,i)),n}return i._value=t,i}function Co(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=$t(e);return this.tween(n,(r.local?xo:So)(r,t))}function wo(e,t){return function(){eo(this,e).delay=+t.apply(this,arguments)}}function To(e,t){return t=+t,function(){eo(this,e).delay=t}}function Eo(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?wo:To)(t,e)):no(this.node(),t).delay}function Do(e,t){return function(){to(this,e).duration=+t.apply(this,arguments)}}function Oo(e,t){return t=+t,function(){to(this,e).duration=t}}function ko(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?Do:Oo)(t,e)):no(this.node(),t).duration}function Ao(e,t){if(typeof t!=`function`)throw Error();return function(){to(this,e).ease=t}}function jo(e){var t=this._id;return arguments.length?this.each(Ao(t,e)):no(this.node(),t).ease}function Mo(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();to(this,e).ease=n}}function No(e){if(typeof e!=`function`)throw Error();return this.each(Mo(this._id,e))}function Po(e){typeof e!=`function`&&(e=fn(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new ls(r,this._parents,this._name,this._id)}function Fo(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new ls(o,this._parents,this._name,this._id)}function Io(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function Lo(e,t,n){var r,i,a=Io(t)?eo:to;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function Ro(e,t){var n=this._id;return arguments.length<2?no(this.node(),n).on.on(e):this.each(Lo(n,e,t))}function zo(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Bo(){return this.on(`end.remove`,zo(this._id))}function Vo(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=an(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,$a(l[f],t,n,f,l,no(u,n)));return new ls(a,this._parents,t,n)}function Ho(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=ln(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=no(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&$a(p,t,n,h,f,m);a.push(f),o.push(u)}return new ls(a,o,t,n)}var Uo=Yr.prototype.constructor;function Wo(){return new Uo(this._groups,this._parents)}function Go(e,t){var n,r,i;return function(){var a=nr(this,e),o=(this.style.removeProperty(e),nr(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function Ko(e){return function(){this.style.removeProperty(e)}}function qo(e,t,n){var r,i=n+``,a;return function(){var o=nr(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function Jo(e,t,n){var r,i,a;return function(){var o=nr(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),nr(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function Yo(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=to(this,e),l=c.on,u=c.value[a]==null?s||=Ko(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function Xo(e,t,n){var r=(e+=``)==`transform`?Ca:uo;return t==null?this.styleTween(e,Go(e,r)).on(`end.style.`+e,Ko(e)):typeof t==`function`?this.styleTween(e,Jo(e,r,lo(this,`style.`+e,t))).each(Yo(this._id,e)):this.styleTween(e,qo(e,r,t),n).on(`end.style.`+e,null)}function Zo(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Qo(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&Zo(e,a,n)),r}return a._value=t,a}function $o(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,Qo(e,t,n??``))}function es(e){return function(){this.textContent=e}}function ts(e){return function(){var t=e(this);this.textContent=t??``}}function ns(e){return this.tween(`text`,typeof e==`function`?ts(lo(this,`text`,e)):es(e==null?``:e+``))}function rs(e){return function(t){this.textContent=e.call(this,t)}}function is(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&rs(r)),t}return r._value=e,r}function as(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,is(e))}function os(){for(var e=this._name,t=this._id,n=ds(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=no(c,t);$a(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new ls(r,this._parents,e,n)}function ss(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=to(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var cs=0;function ls(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function us(e){return Yr().transition(e)}function ds(){return++cs}var fs=Yr.prototype;ls.prototype=us.prototype={constructor:ls,select:Vo,selectAll:Ho,selectChild:fs.selectChild,selectChildren:fs.selectChildren,filter:Po,merge:Fo,selection:Wo,transition:os,call:fs.call,nodes:fs.nodes,node:fs.node,size:fs.size,empty:fs.empty,each:fs.each,on:Ro,attr:vo,attrTween:Co,style:Xo,styleTween:$o,text:ns,textTween:as,remove:Bo,tween:co,delay:Eo,duration:ko,ease:jo,easeVarying:No,end:ss,[Symbol.iterator]:fs[Symbol.iterator]};function ps(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var ms={time:null,delay:0,duration:250,ease:ps};function hs(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function gs(e){var t,n;e instanceof ls?(t=e._id,e=e._name):(t=ds(),(n=ms).time=Va(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&$a(c,e,t,l,o,n||hs(c,t));return new ls(r,this._parents,e,t)}Yr.prototype.interrupt=ao,Yr.prototype.transition=gs;var _s=e=>()=>e;function vs(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function ys(e,t,n){this.k=e,this.x=t,this.y=n}ys.prototype={constructor:ys,scale:function(e){return e===1?this:new ys(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new ys(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var bs=new ys(1,0,0);xs.prototype=ys.prototype;function xs(e){for(;!e.__zoom;)if(!(e=e.parentNode))return bs;return e.__zoom}function Ss(e){e.stopImmediatePropagation()}function Cs(e){e.preventDefault(),e.stopImmediatePropagation()}function ws(e){return(!e.ctrlKey||e.type===`wheel`)&&!e.button}function Ts(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute(`viewBox`)?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Es(){return this.__zoom||bs}function Ds(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Os(){return navigator.maxTouchPoints||`ontouchstart`in this}function ks(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function As(){var e=ws,t=Ts,n=ks,r=Ds,i=Os,a=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],s=250,c=ka,l=qt(`start`,`zoom`,`end`),u,d,f,p=500,m=150,h=0,g=10;function _(e){e.property(`__zoom`,Es).on(`wheel.zoom`,w,{passive:!1}).on(`mousedown.zoom`,T).on(`dblclick.zoom`,E).filter(i).on(`touchstart.zoom`,D).on(`touchmove.zoom`,O).on(`touchend.zoom touchcancel.zoom`,k).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}_.transform=function(e,t,n,r){var i=e.selection?e.selection():e;i.property(`__zoom`,Es),e===i?i.interrupt().each(function(){S(this,arguments).event(r).start().zoom(null,typeof t==`function`?t.apply(this,arguments):t).end()}):x(e,t,n,r)},_.scaleBy=function(e,t,n,r){_.scaleTo(e,function(){return this.__zoom.k*(typeof t==`function`?t.apply(this,arguments):t)},n,r)},_.scaleTo=function(e,r,i,a){_.transform(e,function(){var e=t.apply(this,arguments),a=this.__zoom,s=i==null?b(e):typeof i==`function`?i.apply(this,arguments):i,c=a.invert(s),l=typeof r==`function`?r.apply(this,arguments):r;return n(y(v(a,l),s,c),e,o)},i,a)},_.translateBy=function(e,r,i,a){_.transform(e,function(){return n(this.__zoom.translate(typeof r==`function`?r.apply(this,arguments):r,typeof i==`function`?i.apply(this,arguments):i),t.apply(this,arguments),o)},null,a)},_.translateTo=function(e,r,i,a,s){_.transform(e,function(){var e=t.apply(this,arguments),s=this.__zoom,c=a==null?b(e):typeof a==`function`?a.apply(this,arguments):a;return n(bs.translate(c[0],c[1]).scale(s.k).translate(typeof r==`function`?-r.apply(this,arguments):-r,typeof i==`function`?-i.apply(this,arguments):-i),e,o)},a,s)};function v(e,t){return t=Math.max(a[0],Math.min(a[1],t)),t===e.k?e:new ys(t,e.x,e.y)}function y(e,t,n){var r=t[0]-n[0]*e.k,i=t[1]-n[1]*e.k;return r===e.x&&i===e.y?e:new ys(e.k,r,i)}function b(e){return[(+e[0][0]+ +e[1][0])/2,(+e[0][1]+ +e[1][1])/2]}function x(e,n,r,i){e.on(`start.zoom`,function(){S(this,arguments).event(i).start()}).on(`interrupt.zoom end.zoom`,function(){S(this,arguments).event(i).end()}).tween(`zoom`,function(){var e=this,a=arguments,o=S(e,a).event(i),s=t.apply(e,a),l=r==null?b(s):typeof r==`function`?r.apply(e,a):r,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),d=e.__zoom,f=typeof n==`function`?n.apply(e,a):n,p=c(d.invert(l).concat(u/d.k),f.invert(l).concat(u/f.k));return function(e){if(e===1)e=f;else{var t=p(e),n=u/t[2];e=new ys(n,l[0]-t[0]*n,l[1]-t[1]*n)}o.zoom(null,e)}})}function S(e,t,n){return!n&&e.__zooming||new C(e,t)}function C(e,n){this.that=e,this.args=n,this.active=0,this.sourceEvent=null,this.extent=t.apply(e,n),this.taps=0}C.prototype={event:function(e){return e&&(this.sourceEvent=e),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit(`start`)),this},zoom:function(e,t){return this.mouse&&e!==`mouse`&&(this.mouse[1]=t.invert(this.mouse[0])),this.touch0&&e!==`touch`&&(this.touch0[1]=t.invert(this.touch0[0])),this.touch1&&e!==`touch`&&(this.touch1[1]=t.invert(this.touch1[0])),this.that.__zoom=t,this.emit(`zoom`),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit(`end`)),this},emit:function(e){var t=Zr(this.that).datum();l.call(e,this.that,new vs(e,{sourceEvent:this.sourceEvent,target:_,type:e,transform:this.that.__zoom,dispatch:l}),t)}};function w(t,...i){if(!e.apply(this,arguments))return;var s=S(this,i).event(t),c=this.__zoom,l=Math.max(a[0],Math.min(a[1],c.k*2**r.apply(this,arguments))),u=$r(t);if(s.wheel)(s.mouse[0][0]!==u[0]||s.mouse[0][1]!==u[1])&&(s.mouse[1]=c.invert(s.mouse[0]=u)),clearTimeout(s.wheel);else if(c.k===l)return;else s.mouse=[u,c.invert(u)],io(this),s.start();Cs(t),s.wheel=setTimeout(d,m),s.zoom(`mouse`,n(y(v(c,l),s.mouse[0],s.mouse[1]),s.extent,o));function d(){s.wheel=null,s.end()}}function T(t,...r){if(f||!e.apply(this,arguments))return;var i=t.currentTarget,a=S(this,r,!0).event(t),s=Zr(t.view).on(`mousemove.zoom`,d,!0).on(`mouseup.zoom`,p,!0),c=$r(t,i),l=t.clientX,u=t.clientY;ii(t.view),Ss(t),a.mouse=[c,this.__zoom.invert(c)],io(this),a.start();function d(e){if(Cs(e),!a.moved){var t=e.clientX-l,r=e.clientY-u;a.moved=t*t+r*r>h}a.event(e).zoom(`mouse`,n(y(a.that.__zoom,a.mouse[0]=$r(e,i),a.mouse[1]),a.extent,o))}function p(e){s.on(`mousemove.zoom mouseup.zoom`,null),ai(e.view,a.moved),Cs(e),a.event(e).end()}}function E(r,...i){if(e.apply(this,arguments)){var a=this.__zoom,c=$r(r.changedTouches?r.changedTouches[0]:r,this),l=a.invert(c),u=a.k*(r.shiftKey?.5:2),d=n(y(v(a,u),c,l),t.apply(this,i),o);Cs(r),s>0?Zr(this).transition().duration(s).call(x,d,c,r):Zr(this).call(_.transform,d,c,r)}}function D(t,...n){if(e.apply(this,arguments)){var r=t.touches,i=r.length,a=S(this,n,t.changedTouches.length===i).event(t),o,s,c,l;for(Ss(t),s=0;s<i;++s)c=r[s],l=$r(c,this),l=[l,this.__zoom.invert(l),c.identifier],a.touch0?!a.touch1&&a.touch0[2]!==l[2]&&(a.touch1=l,a.taps=0):(a.touch0=l,o=!0,a.taps=1+!!u);u&&=clearTimeout(u),o&&(a.taps<2&&(d=l[0],u=setTimeout(function(){u=null},p)),io(this),a.start())}}function O(e,...t){if(this.__zooming){var r=S(this,t).event(e),i=e.changedTouches,a=i.length,s,c,l,u;for(Cs(e),s=0;s<a;++s)c=i[s],l=$r(c,this),r.touch0&&r.touch0[2]===c.identifier?r.touch0[0]=l:r.touch1&&r.touch1[2]===c.identifier&&(r.touch1[0]=l);if(c=r.that.__zoom,r.touch1){var d=r.touch0[0],f=r.touch0[1],p=r.touch1[0],m=r.touch1[1],h=(h=p[0]-d[0])*h+(h=p[1]-d[1])*h,g=(g=m[0]-f[0])*g+(g=m[1]-f[1])*g;c=v(c,Math.sqrt(h/g)),l=[(d[0]+p[0])/2,(d[1]+p[1])/2],u=[(f[0]+m[0])/2,(f[1]+m[1])/2]}else if(r.touch0)l=r.touch0[0],u=r.touch0[1];else return;r.zoom(`touch`,n(y(c,l,u),r.extent,o))}}function k(e,...t){if(this.__zooming){var n=S(this,t).event(e),r=e.changedTouches,i=r.length,a,o;for(Ss(e),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),a=0;a<i;++a)o=r[a],n.touch0&&n.touch0[2]===o.identifier?delete n.touch0:n.touch1&&n.touch1[2]===o.identifier&&delete n.touch1;if(n.touch1&&!n.touch0&&(n.touch0=n.touch1,delete n.touch1),n.touch0)n.touch0[1]=this.__zoom.invert(n.touch0[0]);else if(n.end(),n.taps===2&&(o=$r(o,this),Math.hypot(d[0]-o[0],d[1]-o[1])<g)){var s=Zr(this).on(`dblclick.zoom`);s&&s.apply(this,arguments)}}}return _.wheelDelta=function(e){return arguments.length?(r=typeof e==`function`?e:_s(+e),_):r},_.filter=function(t){return arguments.length?(e=typeof t==`function`?t:_s(!!t),_):e},_.touchable=function(e){return arguments.length?(i=typeof e==`function`?e:_s(!!e),_):i},_.extent=function(e){return arguments.length?(t=typeof e==`function`?e:_s([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),_):t},_.scaleExtent=function(e){return arguments.length?(a[0]=+e[0],a[1]=+e[1],_):[a[0],a[1]]},_.translateExtent=function(e){return arguments.length?(o[0][0]=+e[0][0],o[1][0]=+e[1][0],o[0][1]=+e[0][1],o[1][1]=+e[1][1],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(e){return arguments.length?(n=e,_):n},_.duration=function(e){return arguments.length?(s=+e,_):s},_.interpolate=function(e){return arguments.length?(c=e,_):c},_.on=function(){var e=l.on.apply(l,arguments);return e===l?_:e},_.clickDistance=function(e){return arguments.length?(h=(e=+e)*e,_):Math.sqrt(h)},_.tapDistance=function(e){return arguments.length?(g=+e,_):g},_}var js={error001:(e=`react`)=>`Seems like you have not used ${e===`svelte`?`SvelteFlowProvider`:`ReactFlowProvider`} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>`It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.`,error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>`The parent container needs a width and a height to render the graph.`,error005:()=>`Only child nodes can use a parent extent.`,error006:()=>`Can't create edge. An edge needs a source and a target.`,error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e===`source`?n:r}", edge id: ${t}.`,error010:()=>`Handle: No node id found. Make sure to only use a Handle inside a custom Node.`,error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e=`react`)=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>`useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.`,error015:()=>`It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.`,error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},Ms=[[-1/0,-1/0],[1/0,1/0]],Ns=[`Enter`,` `,`Escape`],Ps={"node.a11yDescription.default":`Press enter or space to select a node. Press delete to remove it and escape to cancel.`,"node.a11yDescription.keyboardDisabled":`Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.`,"node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":`Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.`,"controls.ariaLabel":`Control Panel`,"controls.zoomIn.ariaLabel":`Zoom In`,"controls.zoomOut.ariaLabel":`Zoom Out`,"controls.fitView.ariaLabel":`Fit View`,"controls.interactive.ariaLabel":`Toggle Interactivity`,"minimap.ariaLabel":`Mini Map`,"handle.ariaLabel":`Handle`},Fs;(function(e){e.Strict=`strict`,e.Loose=`loose`})(Fs||={});var Is;(function(e){e.Free=`free`,e.Vertical=`vertical`,e.Horizontal=`horizontal`})(Is||={});var Ls;(function(e){e.Partial=`partial`,e.Full=`full`})(Ls||={});var Rs={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null},zs;(function(e){e.Bezier=`default`,e.Straight=`straight`,e.Step=`step`,e.SmoothStep=`smoothstep`,e.SimpleBezier=`simplebezier`})(zs||={});var Bs;(function(e){e.Arrow=`arrow`,e.ArrowClosed=`arrowclosed`})(Bs||={});var Q;(function(e){e.Left=`left`,e.Top=`top`,e.Right=`right`,e.Bottom=`bottom`})(Q||={});var Vs={[Q.Left]:Q.Right,[Q.Right]:Q.Left,[Q.Top]:Q.Bottom,[Q.Bottom]:Q.Top};function Hs(e){return e===null?null:e?`valid`:`invalid`}var Us=e=>`id`in e&&`source`in e&&`target`in e,Ws=e=>`id`in e&&`position`in e&&!(`source`in e)&&!(`target`in e),Gs=e=>`id`in e&&`internals`in e&&!(`source`in e)&&!(`target`in e),Ks=(e,t=[0,0])=>{let{width:n,height:r}=Ec(e),i=e.origin??t,a=n*i[0],o=r*i[1];return{x:e.position.x-a,y:e.position.y-o}},qs=(e,t={nodeOrigin:[0,0]})=>e.length===0?{x:0,y:0,width:0,height:0}:cc(e.reduce((e,n)=>{let r=typeof n==`string`,i=!t.nodeLookup&&!r?n:void 0;return t.nodeLookup&&(i=r?t.nodeLookup.get(n):Gs(n)?n:t.nodeLookup.get(n.id)),oc(e,i?uc(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0})},{x:1/0,y:1/0,x2:-1/0,y2:-1/0})),Js=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(e=>{(t.filter===void 0||t.filter(e))&&(n=oc(n,uc(e)),r=!0)}),r?cc(n):{x:0,y:0,width:0,height:0}},Ys=(e,t,[n,r,i]=[0,0,1],a=!1,o=!1)=>{let s=(t.x-n)/i,c=(t.y-r)/i,l=t.width/i,u=t.height/i,d=[];for(let t of e.values()){let{measured:e,selectable:n=!0,hidden:r=!1}=t;if(o&&!n||r)continue;let i=e.width??t.width??t.initialWidth??0,f=e.height??t.height??t.initialHeight??0,{x:p,y:m}=t.internals.positionAbsolute,h=fc(s,c,l,u,p,m,i,f),g=i*f,_=a&&h>0;(!t.internals.handleBounds||_||h>=g||t.dragging)&&d.push(t)}return d},Xs=(e,t)=>{let n=new Set;return e.forEach(e=>{n.add(e.id)}),t.filter(e=>n.has(e.source)||n.has(e.target))};function Zs(e,t){let n=new Map,r=t?.nodes?new Set(t.nodes.map(e=>e.id)):null;return e.forEach(e=>{e.measured.width&&e.measured.height&&(t?.includeHiddenNodes||!e.hidden)&&(!r||r.has(e.id))&&n.set(e.id,e)}),n}async function Qs({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:a},o){if(e.size===0)return!0;let s=Cc(Js(Zs(e,o)),t,n,o?.minZoom??i,o?.maxZoom??a,o?.padding??.1);return await r.setViewport(s,{duration:o?.duration,ease:o?.ease,interpolate:o?.interpolate}),!0}function $s({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:a}){let o=n.get(e),s=o.parentId?n.get(o.parentId):void 0,{x:c,y:l}=s?s.internals.positionAbsolute:{x:0,y:0},u=o.origin??r,d=o.extent||i;if(o.extent===`parent`&&!o.expandParent)if(!s)a?.(`005`,js.error005());else{let e=s.measured.width,t=s.measured.height;e&&t&&(d=[[c,l],[c+e,l+t]])}else s&&Tc(o.extent)&&(d=[[o.extent[0][0]+c,o.extent[0][1]+l],[o.extent[1][0]+c,o.extent[1][1]+l]]);let f=Tc(d)?nc(t,d,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&a?.(`015`,js.error015()),{position:{x:f.x-c+(o.measured.width??0)*u[0],y:f.y-l+(o.measured.height??0)*u[1]},positionAbsolute:f}}async function ec({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){let a=new Set(e.map(e=>e.id)),o=[];for(let e of n){if(e.deletable===!1)continue;let t=a.has(e.id),n=!t&&e.parentId&&o.find(t=>t.id===e.parentId);(t||n)&&o.push(e)}let s=new Set(t.map(e=>e.id)),c=r.filter(e=>e.deletable!==!1),l=Xs(o,c);for(let e of c)s.has(e.id)&&!l.find(t=>t.id===e.id)&&l.push(e);if(!i)return{edges:l,nodes:o};let u=await i({nodes:o,edges:l});return typeof u==`boolean`?u?{edges:l,nodes:o}:{edges:[],nodes:[]}:u}var tc=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),nc=(e={x:0,y:0},t,n)=>({x:tc(e.x,t[0][0],t[1][0]-(n?.width??0)),y:tc(e.y,t[0][1],t[1][1]-(n?.height??0))});function rc(e,t,n){let{width:r,height:i}=Ec(n),{x:a,y:o}=n.internals.positionAbsolute;return nc(e,[[a,o],[a+r,o+i]],t)}var ic=(e,t,n)=>e<t?tc(Math.abs(e-t),1,t)/t:e>n?-tc(Math.abs(e-n),1,t)/t:0,ac=(e,t,n=15,r=40)=>[ic(e.x,r,t.width-r)*n,ic(e.y,r,t.height-r)*n],oc=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),sc=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),cc=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),lc=(e,t=[0,0])=>{let{x:n,y:r}=Gs(e)?e.internals.positionAbsolute:Ks(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},uc=(e,t=[0,0])=>{let{x:n,y:r}=Gs(e)?e.internals.positionAbsolute:Ks(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},dc=(e,t)=>cc(oc(sc(e),sc(t))),fc=(e,t,n,r,i,a,o,s)=>{let c=Math.max(0,Math.min(e+n,i+o)-Math.max(e,i)),l=Math.max(0,Math.min(t+r,a+s)-Math.max(t,a));return Math.ceil(c*l)},pc=(e,t)=>fc(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),mc=e=>hc(e.width)&&hc(e.height)&&hc(e.x)&&hc(e.y),hc=e=>!isNaN(e)&&isFinite(e),gc=(e,t)=>(e,t)=>{},_c=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),vc=({x:e,y:t},[n,r,i],a=!1,o=[1,1])=>{let s={x:(e-n)/i,y:(t-r)/i};return a?_c(s,o):s},yc=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function bc(e,t){if(typeof e==`number`)return Math.floor((t-t/(1+e))*.5);if(typeof e==`string`&&e.endsWith(`px`)){let t=parseFloat(e);if(!Number.isNaN(t))return Math.floor(t)}if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function xc(e,t,n){if(typeof e==`string`||typeof e==`number`){let r=bc(e,n),i=bc(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e==`object`){let r=bc(e.top??e.y??0,n),i=bc(e.bottom??e.y??0,n),a=bc(e.left??e.x??0,t),o=bc(e.right??e.x??0,t);return{top:r,right:o,bottom:i,left:a,x:a+o,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function Sc(e,t,n,r,i,a){let{x:o,y:s}=yc(e,[t,n,r]),{x:c,y:l}=yc({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-c,d=a-l;return{left:Math.floor(o),top:Math.floor(s),right:Math.floor(u),bottom:Math.floor(d)}}var Cc=(e,t,n,r,i,a)=>{let o=xc(a,t,n),s=(t-o.x)/e.width,c=(n-o.y)/e.height,l=tc(Math.min(s,c),r,i),u=e.x+e.width/2,d=e.y+e.height/2,f=t/2-u*l,p=n/2-d*l,m=Sc(e,f,p,l,t,n),h={left:Math.min(m.left-o.left,0),top:Math.min(m.top-o.top,0),right:Math.min(m.right-o.right,0),bottom:Math.min(m.bottom-o.bottom,0)};return{x:f-h.left+h.right,y:p-h.top+h.bottom,zoom:l}},wc=()=>typeof navigator<`u`&&navigator?.userAgent?.indexOf(`Mac`)>=0;function Tc(e){return e!=null&&e!==`parent`}function Ec(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function Dc(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Oc(e,t={width:0,height:0},n,r,i){let a={...e},o=r.get(n);if(o){let e=o.origin||i;a.x+=o.internals.positionAbsolute.x-(t.width??0)*e[0],a.y+=o.internals.positionAbsolute.y-(t.height??0)*e[1]}return a}function kc(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Ac(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function jc(e){return{...Ps,...e||{}}}function Mc(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){let{x:a,y:o}=Rc(e),s=vc({x:a-(i?.left??0),y:o-(i?.top??0)},r),{x:c,y:l}=n?_c(s,t):s;return{xSnapped:c,ySnapped:l,...s}}var Nc=e=>({width:e.offsetWidth,height:e.offsetHeight}),Pc=e=>e?.getRootNode?.()||window?.document,Fc=[`INPUT`,`SELECT`,`TEXTAREA`];function Ic(e){let t=e.composedPath?.()?.[0]||e.target;return t?.nodeType===1?Fc.includes(t.nodeName)||t.hasAttribute(`contenteditable`)||!!t.closest(`.nokey`):!1}var Lc=e=>`clientX`in e,Rc=(e,t)=>{let n=Lc(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},zc=(e,t,n,r,i)=>{let a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...Nc(t)}})};function Bc({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:a,targetControlX:o,targetControlY:s}){let c=e*.125+i*.375+o*.375+n*.125,l=t*.125+a*.375+s*.375+r*.125;return[c,l,Math.abs(c-e),Math.abs(l-t)]}function Vc(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Hc({pos:e,x1:t,y1:n,x2:r,y2:i,c:a}){switch(e){case Q.Left:return[t-Vc(t-r,a),n];case Q.Right:return[t+Vc(r-t,a),n];case Q.Top:return[t,n-Vc(n-i,a)];case Q.Bottom:return[t,n+Vc(i-n,a)]}}function Uc({sourceX:e,sourceY:t,sourcePosition:n=Q.Bottom,targetX:r,targetY:i,targetPosition:a=Q.Top,curvature:o=.25}){let[s,c]=Hc({pos:n,x1:e,y1:t,x2:r,y2:i,c:o}),[l,u]=Hc({pos:a,x1:r,y1:i,x2:e,y2:t,c:o}),[d,f,p,m]=Bc({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:s,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${s},${c} ${l},${u} ${r},${i}`,d,f,p,m]}function Wc({sourceX:e,sourceY:t,targetX:n,targetY:r}){let i=Math.abs(n-e)/2,a=n<e?n+i:n-i,o=Math.abs(r-t)/2;return[a,r<t?r+o:r-o,i,o]}function Gc({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:a=`basic`}){return a===`manual`?r:(i&&n?r+1e3:r)+Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0)}function Kc({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){let a=oc(uc(e),uc(t));return a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1),pc({x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]},cc(a))>0}var qc=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||``}-${n}${r||``}`,Jc=(e,t)=>t.some(t=>t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle)),Yc=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.(`006`,js.error006()),t;let r=n.getEdgeId||qc,i;return i=Us(e)?{...e}:{...e,id:r(e)},Jc(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function Xc({sourceX:e,sourceY:t,targetX:n,targetY:r}){let[i,a,o,s]=Wc({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,a,o,s]}var Zc={[Q.Left]:{x:-1,y:0},[Q.Right]:{x:1,y:0},[Q.Top]:{x:0,y:-1},[Q.Bottom]:{x:0,y:1}},Qc=({source:e,sourcePosition:t=Q.Bottom,target:n})=>t===Q.Left||t===Q.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},$c=(e,t)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2);function el({source:e,sourcePosition:t=Q.Bottom,target:n,targetPosition:r=Q.Top,center:i,offset:a,stepPosition:o}){let s=Zc[t],c=Zc[r],l={x:e.x+s.x*a,y:e.y+s.y*a},u={x:n.x+c.x*a,y:n.y+c.y*a},d=Qc({source:l,sourcePosition:t,target:u}),f=d.x===0?`y`:`x`,p=d[f],m=[],h,g,_={x:0,y:0},v={x:0,y:0},[,,y,b]=Wc({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(s[f]*c[f]===-1){f===`x`?(h=i.x??l.x+(u.x-l.x)*o,g=i.y??(l.y+u.y)/2):(h=i.x??(l.x+u.x)/2,g=i.y??l.y+(u.y-l.y)*o);let e=[{x:h,y:l.y},{x:h,y:u.y}],t=[{x:l.x,y:g},{x:u.x,y:g}];m=s[f]===p?f===`x`?e:t:f===`x`?t:e}else{let i=[{x:l.x,y:u.y}],o=[{x:u.x,y:l.y}];if(m=f===`x`?s.x===p?o:i:s.y===p?i:o,t===r){let t=Math.abs(e[f]-n[f]);if(t<=a){let r=Math.min(a-1,a-t);s[f]===p?_[f]=(l[f]>e[f]?-1:1)*r:v[f]=(u[f]>n[f]?-1:1)*r}}if(t!==r){let e=f===`x`?`y`:`x`,t=s[f]===c[e],n=l[e]>u[e],r=l[e]<u[e];(s[f]===1&&(!t&&n||t&&r)||s[f]!==1&&(!t&&r||t&&n))&&(m=f===`x`?i:o)}let d={x:l.x+_.x,y:l.y+_.y},y={x:u.x+v.x,y:u.y+v.y};Math.max(Math.abs(d.x-m[0].x),Math.abs(y.x-m[0].x))>=Math.max(Math.abs(d.y-m[0].y),Math.abs(y.y-m[0].y))?(h=(d.x+y.x)/2,g=m[0].y):(h=m[0].x,g=(d.y+y.y)/2)}let x={x:l.x+_.x,y:l.y+_.y},S={x:u.x+v.x,y:u.y+v.y};return[[e,...x.x!==m[0].x||x.y!==m[0].y?[x]:[],...m,...S.x!==m[m.length-1].x||S.y!==m[m.length-1].y?[S]:[],n],h,g,y,b]}function tl(e,t,n,r){let i=Math.min($c(e,t)/2,$c(t,n)/2,r),{x:a,y:o}=t;if(e.x===a&&a===n.x||e.y===o&&o===n.y)return`L${a} ${o}`;if(e.y===o){let t=e.x<n.x?-1:1,r=e.y<n.y?1:-1;return`L ${a+i*t},${o}Q ${a},${o} ${a},${o+i*r}`}let s=e.x<n.x?1:-1;return`L ${a},${o+i*(e.y<n.y?-1:1)}Q ${a},${o} ${a+i*s},${o}`}function nl({sourceX:e,sourceY:t,sourcePosition:n=Q.Bottom,targetX:r,targetY:i,targetPosition:a=Q.Top,borderRadius:o=5,centerX:s,centerY:c,offset:l=20,stepPosition:u=.5}){let[d,f,p,m,h]=el({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:a,center:{x:s,y:c},offset:l,stepPosition:u}),g=`M${d[0].x} ${d[0].y}`;for(let e=1;e<d.length-1;e++)g+=tl(d[e-1],d[e],d[e+1],o);return g+=`L${d[d.length-1].x} ${d[d.length-1].y}`,[g,f,p,m,h]}function rl(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function il(e){let{sourceNode:t,targetNode:n}=e;if(!rl(t)||!rl(n))return null;let r=t.internals.handleBounds||al(t.handles),i=n.internals.handleBounds||al(n.handles),a=sl(r?.source??[],e.sourceHandle),o=sl(e.connectionMode===Fs.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!a||!o)return e.onError?.(`008`,js.error008(a?`target`:`source`,{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;let s=a?.position||Q.Bottom,c=o?.position||Q.Top,l=ol(t,a,s),u=ol(n,o,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:s,targetPosition:c}}function al(e){if(!e)return null;let t=[],n=[];for(let r of e)r.width=r.width??1,r.height=r.height??1,r.type===`source`?t.push(r):r.type===`target`&&n.push(r);return{source:t,target:n}}function ol(e,t,n=Q.Left,r=!1){let i=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:o,height:s}=t??Ec(e);if(r)return{x:i+o/2,y:a+s/2};switch(t?.position??n){case Q.Top:return{x:i+o/2,y:a};case Q.Right:return{x:i+o,y:a+s/2};case Q.Bottom:return{x:i+o/2,y:a+s};case Q.Left:return{x:i,y:a+s/2}}}function sl(e,t){return e&&(t?e.find(e=>e.id===t):e[0])||null}function cl(e,t){return e?typeof e==`string`?e:`${t?`${t}__`:``}${Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`&`)}`:``}function ll(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){let a=new Set;return e.reduce((e,o)=>([o.markerStart||r,o.markerEnd||i].forEach(r=>{if(r&&typeof r==`object`){let i=cl(r,t);a.has(i)||(e.push({id:i,color:r.color||n,...r}),a.add(i))}}),e),[]).sort((e,t)=>e.id.localeCompare(t.id))}var ul=1e3,dl=10,fl={nodeOrigin:[0,0],nodeExtent:Ms,elevateNodesOnSelect:!0,zIndexMode:`basic`,defaults:{}},pl={...fl,checkEquality:!0};function ml(e,t){let n={...e};for(let e in t)t[e]!==void 0&&(n[e]=t[e]);return n}function hl(e,t,n){let r=ml(fl,n);for(let n of e.values())if(n.parentId)bl(n,e,t,r);else{let e=nc(Ks(n,r.nodeOrigin),Tc(n.extent)?n.extent:r.nodeExtent,Ec(n));n.internals.positionAbsolute=e}}function gl(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;let n=[],r=[];for(let t of e.handles){let i={id:t.id,width:t.width??1,height:t.height??1,nodeId:e.id,x:t.x,y:t.y,position:t.position,type:t.type};t.type===`source`?n.push(i):t.type===`target`&&r.push(i)}return{source:n,target:r}}function _l(e){return e===`manual`}function vl(e,t,n,r={}){let i=ml(pl,r),a={i:0},o=new Map(t),s=i?.elevateNodesOnSelect&&!_l(i.zIndexMode)?ul:0,c=e.length>0,l=!1;t.clear(),n.clear();for(let u of e){let e=o.get(u.id);if(i.checkEquality&&u===e?.internals.userNode)t.set(u.id,e);else{let n=nc(Ks(u,i.nodeOrigin),Tc(u.extent)?u.extent:i.nodeExtent,Ec(u));e={...i.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:n,handleBounds:gl(u,e),z:xl(u,s,i.zIndexMode),userNode:u}},t.set(u.id,e)}(e.measured===void 0||e.measured.width===void 0||e.measured.height===void 0)&&!e.hidden&&(c=!1),u.parentId&&bl(e,t,n,r,a),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function yl(e,t){if(!e.parentId)return;let n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function bl(e,t,n,r,i){let{elevateNodesOnSelect:a,nodeOrigin:o,nodeExtent:s,zIndexMode:c}=ml(fl,r),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}yl(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&c===`auto`&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*dl),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);let{x:d,y:f,z:p}=Sl(e,u,o,s,a&&!_l(c)?ul:0,c),{positionAbsolute:m}=e.internals,h=d!==m.x||f!==m.y;(h||p!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:h?{x:d,y:f}:m,z:p}})}function xl(e,t,n){let r=hc(e.zIndex)?e.zIndex:0;return _l(n)?r:r+(e.selected?t:0)}function Sl(e,t,n,r,i,a){let{x:o,y:s}=t.internals.positionAbsolute,c=Ec(e),l=Ks(e,n),u=Tc(e.extent)?nc(l,e.extent,c):l,d=nc({x:o+u.x,y:s+u.y},r,c);e.extent===`parent`&&(d=rc(d,c,t));let f=xl(e,i,a),p=t.internals.z??0;return{x:d.x,y:d.y,z:p>=f?p+1:f}}function Cl(e,t,n,r=[0,0]){let i=[],a=new Map;for(let n of e){let e=t.get(n.parentId);if(!e)continue;let r=dc(a.get(n.parentId)?.expandedRect??lc(e),n.rect);a.set(n.parentId,{expandedRect:r,parent:e})}return a.size>0&&a.forEach(({expandedRect:t,parent:a},o)=>{let s=a.internals.positionAbsolute,c=Ec(a),l=a.origin??r,u=t.x<s.x?Math.round(Math.abs(s.x-t.x)):0,d=t.y<s.y?Math.round(Math.abs(s.y-t.y)):0,f=Math.max(c.width,Math.round(t.width)),p=Math.max(c.height,Math.round(t.height)),m=(f-c.width)*l[0],h=(p-c.height)*l[1];(u>0||d>0||m||h)&&(i.push({id:o,type:`position`,position:{x:a.position.x-u+m,y:a.position.y-d+h}}),n.get(o)?.forEach(t=>{e.some(e=>e.id===t.id)||i.push({id:t.id,type:`position`,position:{x:t.position.x+u,y:t.position.y+d}})})),(c.width<t.width||c.height<t.height||u||d)&&i.push({id:o,type:`dimensions`,setAttributes:!0,dimensions:{width:f+(u?l[0]*u-m:0),height:p+(d?l[1]*d-h:0)}})}),i}function wl(e,t,n,r,i,a,o){let s=r?.querySelector(`.xyflow__viewport`),c=!1;if(!s)return{changes:[],updatedInternals:c};let l=[],u=window.getComputedStyle(s),{m22:d}=new window.DOMMatrixReadOnly(u.transform),f=[];for(let r of e.values()){let e=t.get(r.id);if(!e)continue;if(e.hidden){t.set(e.id,{...e,internals:{...e.internals,handleBounds:void 0}}),c=!0;continue}let s=Nc(r.nodeElement),u=e.measured.width!==s.width||e.measured.height!==s.height;if(s.width&&s.height&&(u||!e.internals.handleBounds||r.force)){let p=r.nodeElement.getBoundingClientRect(),m=Tc(e.extent)?e.extent:a,{positionAbsolute:h}=e.internals;e.parentId&&e.extent===`parent`?h=rc(h,s,t.get(e.parentId)):m&&(h=nc(h,m,s));let g={...e,measured:s,internals:{...e.internals,positionAbsolute:h,handleBounds:{source:zc(`source`,r.nodeElement,p,d,e.id),target:zc(`target`,r.nodeElement,p,d,e.id)}}};t.set(e.id,g),e.parentId&&bl(g,t,n,{nodeOrigin:i,zIndexMode:o}),c=!0,u&&(l.push({id:e.id,type:`dimensions`,dimensions:s}),e.expandParent&&e.parentId&&f.push({id:e.id,parentId:e.parentId,rect:lc(g,i)}))}}if(f.length>0){let e=Cl(f,t,n,i);l.push(...e)}return{changes:l,updatedInternals:c}}async function Tl({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:a}){if(!t||!e.x&&!e.y)return!1;let o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,a]],r);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function El(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function Dl(e,t,n){e.clear(),t.clear();for(let r of n){let{source:n,target:i,sourceHandle:a=null,targetHandle:o=null}=r,s={edgeId:r.id,source:n,target:i,sourceHandle:a,targetHandle:o},c=`${n}-${a}--${i}-${o}`;El(`source`,s,`${i}-${o}--${n}-${a}`,e,n,a),El(`target`,s,c,e,i,o),t.set(r.id,r)}}function Ol(e,t){if(!e.parentId)return!1;let n=t.get(e.parentId);return n?n.selected?!0:Ol(n,t):!1}function kl(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function Al(e,t,n,r){let i=new Map;for(let[a,o]of e)if((o.selected||o.id===r)&&(!o.parentId||!Ol(o,e))&&(o.draggable||t&&o.draggable===void 0)){let t=e.get(a);t&&i.set(a,{id:a,position:t.position||{x:0,y:0},distance:{x:n.x-t.internals.positionAbsolute.x,y:n.y-t.internals.positionAbsolute.y},extent:t.extent,parentId:t.parentId,origin:t.origin,expandParent:t.expandParent,internals:{positionAbsolute:t.internals.positionAbsolute||{x:0,y:0}},measured:{width:t.measured.width??0,height:t.measured.height??0}})}return i}function jl({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){let i=[];for(let[e,a]of t){let t=n.get(e)?.internals.userNode;t&&i.push({...t,position:a.position,dragging:r})}if(!e)return[i[0],i];let a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:i[0],i]}function Ml({dragItems:e,snapGrid:t,x:n,y:r}){let i=e.values().next().value;if(!i)return null;let a={x:n-i.distance.x,y:r-i.distance.y},o=_c(a,t);return{x:o.x-a.x,y:o.y-a.y}}function Nl({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let a={x:null,y:null},o=0,s=new Map,c=!1,l={x:0,y:0},u=null,d=!1,f=null,p=!1,m=!1,h=null;function g({noDragClassName:g,handleSelector:_,domNode:v,isSelectable:y,nodeId:b,nodeClickDistance:x=0}){f=Zr(v);function S({x:e,y:n}){let{nodeLookup:i,nodeExtent:o,snapGrid:c,snapToGrid:l,nodeOrigin:u,onNodeDrag:d,onSelectionDrag:f,onError:p,updateNodePositions:g}=t();a={x:e,y:n};let _=!1,v=s.size>1,y=v&&o?sc(Js(s)):null,x=v&&l?Ml({dragItems:s,snapGrid:c,x:e,y:n}):null;for(let[t,r]of s){if(!i.has(t))continue;let a={x:e-r.distance.x,y:n-r.distance.y};l&&(a=x?{x:Math.round(a.x+x.x),y:Math.round(a.y+x.y)}:_c(a,c));let s=null;if(v&&o&&!r.extent&&y){let{positionAbsolute:e}=r.internals,t=e.x-y.x+o[0][0],n=e.x+r.measured.width-y.x2+o[1][0],i=e.y-y.y+o[0][1],a=e.y+r.measured.height-y.y2+o[1][1];s=[[t,i],[n,a]]}let{position:d,positionAbsolute:f}=$s({nodeId:t,nextPosition:a,nodeLookup:i,nodeExtent:s||o,nodeOrigin:u,onError:p});_=_||r.position.x!==d.x||r.position.y!==d.y,r.position=d,r.internals.positionAbsolute=f}if(m||=_,_&&(g(s,!0),h&&(r||d||!b&&f))){let[e,t]=jl({nodeId:b,dragItems:s,nodeLookup:i});r?.(h,s,e,t),d?.(h,e,t),b||f?.(h,t)}}async function C(){if(!u)return;let{transform:e,panBy:n,autoPanSpeed:r,autoPanOnNodeDrag:i}=t();if(!i){c=!1,cancelAnimationFrame(o);return}let[s,d]=ac(l,u,r);(s!==0||d!==0)&&(a.x=(a.x??0)-s/e[2],a.y=(a.y??0)-d/e[2],await n({x:s,y:d})&&S(a)),o=requestAnimationFrame(C)}function w(r){let{nodeLookup:i,multiSelectionActive:o,nodesDraggable:c,transform:l,snapGrid:f,snapToGrid:p,selectNodesOnDrag:m,onNodeDragStart:h,onSelectionDragStart:g,unselectNodesAndEdges:_}=t();d=!0,(!m||!y)&&!o&&b&&(i.get(b)?.selected||_()),y&&m&&b&&e?.(b);let v=Mc(r.sourceEvent,{transform:l,snapGrid:f,snapToGrid:p,containerBounds:u});if(a=v,s=Al(i,c,v,b),s.size>0&&(n||h||!b&&g)){let[e,t]=jl({nodeId:b,dragItems:s,nodeLookup:i});n?.(r.sourceEvent,s,e,t),h?.(r.sourceEvent,e,t),b||g?.(r.sourceEvent,t)}}let T=fi().clickDistance(x).on(`start`,e=>{let{domNode:n,nodeDragThreshold:r,transform:i,snapGrid:o,snapToGrid:s}=t();u=n?.getBoundingClientRect()||null,p=!1,m=!1,h=e.sourceEvent,r===0&&w(e),a=Mc(e.sourceEvent,{transform:i,snapGrid:o,snapToGrid:s,containerBounds:u}),l=Rc(e.sourceEvent,u)}).on(`drag`,e=>{let{autoPanOnNodeDrag:n,transform:r,snapGrid:i,snapToGrid:o,nodeDragThreshold:f,nodeLookup:m}=t(),g=Mc(e.sourceEvent,{transform:r,snapGrid:i,snapToGrid:o,containerBounds:u});if(h=e.sourceEvent,(e.sourceEvent.type===`touchmove`&&e.sourceEvent.touches.length>1||b&&!m.has(b))&&(p=!0),!p){if(!c&&n&&d&&(c=!0,C()),!d){let t=Rc(e.sourceEvent,u),n=t.x-l.x,r=t.y-l.y;Math.sqrt(n*n+r*r)>f&&w(e)}(a.x!==g.xSnapped||a.y!==g.ySnapped)&&s&&d&&(l=Rc(e.sourceEvent,u),S(g))}}).on(`end`,e=>{if(!d||p){p&&s.size>0&&t().updateNodePositions(s,!1);return}if(c=!1,d=!1,cancelAnimationFrame(o),s.size>0){let{nodeLookup:n,updateNodePositions:r,onNodeDragStop:a,onSelectionDragStop:o}=t();if(m&&=(r(s,!1),!1),i||a||!b&&o){let[t,r]=jl({nodeId:b,dragItems:s,nodeLookup:n,dragging:!1});i?.(e.sourceEvent,s,t,r),a?.(e.sourceEvent,t,r),b||o?.(e.sourceEvent,r)}}}).filter(e=>{let t=e.target;return!e.button&&(!g||!kl(t,`.${g}`,v))&&(!_||kl(t,_,v))});f.call(T)}function _(){f?.on(`.drag`,null)}return{update:g,destroy:_}}function Pl(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())pc(i,lc(e))>0&&r.push(e);return r}var Fl=250;function Il(e,t,n,r){let i=[],a=1/0,o=Pl(e,n,t+Fl);for(let n of o){let o=[...n.internals.handleBounds?.source??[],...n.internals.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=ol(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function Ll(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===`strict`?o.internals.handleBounds?.[t]:[...o.internals.handleBounds?.source??[],...o.internals.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...ol(o,c,c.position,!0)}:c}function Rl(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function zl(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}var Bl=()=>!0;function Vl(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:a,isTarget:o,domNode:s,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:d,panBy:f,cancelConnection:p,onConnectStart:m,onConnect:h,onConnectEnd:g,isValidConnection:_=Bl,onReconnectEnd:v,updateConnection:y,getTransform:b,getFromHandle:x,autoPanSpeed:S,dragThreshold:C=1,handleDomNode:w}){let T=Pc(e.target),E=0,D,{x:O,y:k}=Rc(e),A=Rl(a,w),j=s?.getBoundingClientRect(),M=!1;if(!j||!A)return;let N=Ll(i,A,r,c,t);if(!N)return;let P=Rc(e,j),F=!1,I=null,L=!1,R=null;function z(){if(!u||!j)return;let[e,t]=ac(P,j,S);f({x:e,y:t}),E=requestAnimationFrame(z)}let B={...N,nodeId:i,type:A,position:N.position},V=c.get(i),H={inProgress:!0,isValid:null,from:ol(V,B,Q.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:V,to:P,toHandle:null,toPosition:Vs[B.position],toNode:null,pointer:P};function U(){M=!0,y(H),m?.(e,{nodeId:i,handleId:r,handleType:A})}C===0&&U();function W(e){if(!M){let{x:t,y:n}=Rc(e),r=t-O,i=n-k;if(!(r*r+i*i>C*C))return;U()}if(!x()||!B){ee(e);return}let a=b();P=Rc(e,j),D=Il(vc(P,a,!1,[1,1]),n,c,B),F||=(z(),!0);let s=Hl(e,{handle:D,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:o?`target`:`source`,isValidConnection:_,doc:T,lib:l,flowId:d,nodeLookup:c});R=s.handleDomNode,I=s.connection,L=zl(!!D,s.isValid);let u=c.get(i),f=u?ol(u,B,Q.Left,!0):H.from,p={...H,from:f,isValid:L,to:s.toHandle&&L?yc({x:s.toHandle.x,y:s.toHandle.y},a):P,toHandle:s.toHandle,toPosition:L&&s.toHandle?s.toHandle.position:Vs[B.position],toNode:s.toHandle?c.get(s.toHandle.nodeId):null,pointer:P};y(p),H=p}function ee(e){if(!(`touches`in e&&e.touches.length>0)){if(M){(D||R)&&I&&L&&h?.(I);let{inProgress:t,...n}=H,r={...n,toPosition:H.toHandle?H.toPosition:null};g?.(e,r),a&&v?.(e,r)}p(),cancelAnimationFrame(E),F=!1,L=!1,I=null,R=null,T.removeEventListener(`mousemove`,W),T.removeEventListener(`mouseup`,ee),T.removeEventListener(`touchmove`,W),T.removeEventListener(`touchend`,ee)}}T.addEventListener(`mousemove`,W),T.addEventListener(`mouseup`,ee),T.addEventListener(`touchmove`,W),T.addEventListener(`touchend`,ee)}function Hl(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=Bl,nodeLookup:u}){let d=a===`target`,f=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:m}=Rc(e),h=o.elementFromPoint(p,m),g=h?.classList.contains(`${s}-flow__handle`)?h:f,_={handleDomNode:g,isValid:!1,connection:null,toHandle:null};if(g){let e=Rl(void 0,g),t=g.getAttribute(`data-nodeid`),a=g.getAttribute(`data-handleid`),o=g.classList.contains(`connectable`),s=g.classList.contains(`connectableend`);if(!t||!e)return _;let c={source:d?t:r,sourceHandle:d?a:i,target:d?r:t,targetHandle:d?i:a};_.connection=c,_.isValid=o&&s&&(n===Fs.Strict?d&&e===`source`||!d&&e===`target`:t!==r||a!==i)&&l(c),_.toHandle=Ll(t,e,a,u,n,!0)}return _}var Ul={onPointerDown:Vl,isValid:Hl};function Wl({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){let i=Zr(e);function a({translateExtent:e,width:a,height:o,zoomStep:s=1,pannable:c=!0,zoomable:l=!0,inversePan:u=!1}){let d=e=>{if(e.sourceEvent.type!==`wheel`||!t)return;let r=n(),i=e.sourceEvent.ctrlKey&&wc()?10:1,a=-e.sourceEvent.deltaY*(e.sourceEvent.deltaMode===1?.05:e.sourceEvent.deltaMode?1:.002)*s,o=r[2]*2**(a*i);t.scaleTo(o)},f=[0,0],p=As().on(`start`,e=>{(e.sourceEvent.type===`mousedown`||e.sourceEvent.type===`touchstart`)&&(f=[e.sourceEvent.clientX??e.sourceEvent.touches[0].clientX,e.sourceEvent.clientY??e.sourceEvent.touches[0].clientY])}).on(`zoom`,c?i=>{let s=n();if(i.sourceEvent.type!==`mousemove`&&i.sourceEvent.type!==`touchmove`||!t)return;let c=[i.sourceEvent.clientX??i.sourceEvent.touches[0].clientX,i.sourceEvent.clientY??i.sourceEvent.touches[0].clientY],l=[c[0]-f[0],c[1]-f[1]];f=c;let d=r()*Math.max(s[2],Math.log(s[2]))*(u?-1:1),p={x:s[0]-l[0]*d,y:s[1]-l[1]*d},m=[[0,0],[a,o]];t.setViewportConstrained({x:p.x,y:p.y,zoom:s[2]},m,e)}:null).on(`zoom.wheel`,l?d:null);i.call(p,{})}function o(){i.on(`zoom`,null)}return{update:a,destroy:o,pointer:$r}}var Gl=e=>({x:e.x,y:e.y,zoom:e.k}),Kl=({x:e,y:t,zoom:n})=>bs.translate(e,t).scale(n),ql=(e,t)=>e.target.closest(`.${t}`),Jl=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Yl=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Xl=(e,t=0,n=Yl,r=()=>{})=>{let i=typeof t==`number`&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on(`end`,r):e},Zl=e=>{let t=e.ctrlKey&&wc()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Ql({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:a,zoomOnPinch:o,onPanZoomStart:s,onPanZoom:c,onPanZoomEnd:l}){return u=>{if(ql(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();let d=n.property(`__zoom`).k||1;if(u.ctrlKey&&o){let e=$r(u),t=d*2**Zl(u);r.scaleTo(n,t,e,u);return}let f=u.deltaMode===1?20:1,p=i===Is.Vertical?0:u.deltaX*f,m=i===Is.Horizontal?0:u.deltaY*f;!wc()&&u.shiftKey&&i!==Is.Vertical&&(p=u.deltaY*f,m=0),r.translateBy(n,-(p/d)*a,-(m/d)*a,{internal:!0});let h=Gl(n.property(`__zoom`));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(u,h),e.panScrollTimeout=setTimeout(()=>{l?.(u,h),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,s?.(u,h))}}function $l({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){let a=r.type===`wheel`,o=!t&&a&&!r.ctrlKey,s=ql(r,e);if(r.ctrlKey&&a&&s&&r.preventDefault(),o||s)return null;r.preventDefault(),n.call(this,r,i)}}function eu({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;let i=Gl(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type===`mousedown`&&t(!0),n&&n?.(r.sourceEvent,i)}}function tu({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return a=>{e.usedRightMouseButton=!!(n&&Jl(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),i&&!a.sourceEvent?.internal&&i?.(a.sourceEvent,Gl(a.transform))}}function nu({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:a}){return o=>{if(!o.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&Jl(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&a(o.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){let t=Gl(o.transform);e.prevViewport=t,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(o.sourceEvent,t)},n?150:0)}}}function ru({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:a,userSelectionActive:o,noWheelClassName:s,noPanClassName:c,lib:l,connectionInProgress:u}){return d=>{let f=e||t,p=n&&d.ctrlKey,m=d.type===`wheel`;if(d.button===1&&d.type===`mousedown`&&(ql(d,`${l}-flow__node`)||ql(d,`${l}-flow__edge`)))return!0;if(!r&&!f&&!i&&!a&&!n||o||u&&!m||ql(d,s)&&m||ql(d,c)&&(!m||i&&m&&!e)||!n&&d.ctrlKey&&m)return!1;if(!n&&d.type===`touchstart`&&d.touches?.length>1)return d.preventDefault(),!1;if(!f&&!i&&!p&&m||!r&&(d.type===`mousedown`||d.type===`touchstart`)||Array.isArray(r)&&!r.includes(d.button)&&d.type===`mousedown`)return!1;let h=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||m)&&h}}function iu({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:a,onPanZoomStart:o,onPanZoomEnd:s,onDraggingChange:c}){let l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=As().scaleExtent([t,n]).translateExtent(r),f=Zr(e).call(d);v({x:i.x,y:i.y,zoom:tc(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);let p=f.on(`wheel.zoom`),m=f.on(`dblclick.zoom`);d.wheelDelta(Zl);async function h(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?ha:ka).transform(Xl(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function g({noWheelClassName:e,noPanClassName:t,onPaneContextMenu:n,userSelectionActive:r,panOnScroll:i,panOnDrag:u,panOnScrollMode:h,panOnScrollSpeed:g,preventScrolling:v,zoomOnPinch:y,zoomOnScroll:b,zoomOnDoubleClick:x,zoomActivationKeyPressed:S,lib:C,onTransformChange:w,connectionInProgress:T,paneClickDistance:E,selectionOnDrag:D}){r&&!l.isZoomingOrPanning&&_();let O=i&&!S&&!r;d.clickDistance(D?1/0:!hc(E)||E<0?0:E);let k=O?Ql({zoomPanValues:l,noWheelClassName:e,d3Selection:f,d3Zoom:d,panOnScrollMode:h,panOnScrollSpeed:g,zoomOnPinch:y,onPanZoomStart:o,onPanZoom:a,onPanZoomEnd:s}):$l({noWheelClassName:e,preventScrolling:v,d3ZoomHandler:p});f.on(`wheel.zoom`,k,{passive:!1});let A=eu({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:o});d.on(`start`,A);let j=tu({zoomPanValues:l,panOnDrag:u,onPaneContextMenu:!!n,onPanZoom:a,onTransformChange:w});d.on(`zoom`,j);let M=nu({zoomPanValues:l,panOnDrag:u,panOnScroll:i,onPaneContextMenu:n,onPanZoomEnd:s,onDraggingChange:c});d.on(`end`,M);let N=ru({zoomActivationKeyPressed:S,panOnDrag:u,zoomOnScroll:b,panOnScroll:i,zoomOnDoubleClick:x,zoomOnPinch:y,userSelectionActive:r,noPanClassName:t,noWheelClassName:e,lib:C,connectionInProgress:T});d.filter(N),x?f.on(`dblclick.zoom`,m):f.on(`dblclick.zoom`,null)}function _(){d.on(`zoom`,null)}async function v(e,t,n){let r=Kl(e),i=d?.constrain()(r,t,n);return i&&await h(i),i}async function y(e,t){let n=Kl(e);return await h(n,t),n}function b(e){if(f){let t=Kl(e),n=f.property(`__zoom`);(n.k!==e.zoom||n.x!==e.x||n.y!==e.y)&&d?.transform(f,t,null,{sync:!0})}}function x(){let e=f?xs(f.node()):{x:0,y:0,k:1};return{x:e.x,y:e.y,zoom:e.k}}async function S(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?ha:ka).scaleTo(Xl(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}async function C(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?ha:ka).scaleBy(Xl(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function w(e){d?.scaleExtent(e)}function T(e){d?.translateExtent(e)}function E(e){let t=!hc(e)||e<0?0:e;d?.clickDistance(t)}return{update:g,destroy:_,setViewport:y,setViewportConstrained:v,getViewport:x,scaleTo:S,scaleBy:C,setScaleExtent:w,setTranslateExtent:T,syncViewport:b,setClickDistance:E}}var au;(function(e){e.Line=`line`,e.Handle=`handle`})(au||={});function ou({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:a}){let o=e-t,s=n-r,c=[o>0?1:o<0?-1:0,s>0?1:s<0?-1:0];return o&&i&&(c[0]*=-1),s&&a&&(c[1]*=-1),c}function su(e){return{isHorizontal:e.includes(`right`)||e.includes(`left`),isVertical:e.includes(`bottom`)||e.includes(`top`),affectsX:e.includes(`left`),affectsY:e.includes(`top`)}}function cu(e,t){return Math.max(0,t-e)}function lu(e,t){return Math.max(0,e-t)}function uu(e,t,n){return Math.max(0,t-e,e-n)}function du(e,t){return e?!t:t}function fu(e,t,n,r,i,a,o,s){let{affectsX:c,affectsY:l}=t,{isHorizontal:u,isVertical:d}=t,f=u&&d,{xSnapped:p,ySnapped:m}=n,{minWidth:h,maxWidth:g,minHeight:_,maxHeight:v}=r,{x:y,y:b,width:x,height:S,aspectRatio:C}=e,w=Math.floor(u?p-e.pointerX:0),T=Math.floor(d?m-e.pointerY:0),E=x+(c?-w:w),D=S+(l?-T:T),O=-a[0]*x,k=-a[1]*S,A=uu(E,h,g),j=uu(D,_,v);if(o){let e=0,t=0;c&&w<0?e=cu(y+w+O,o[0][0]):!c&&w>0&&(e=lu(y+E+O,o[1][0])),l&&T<0?t=cu(b+T+k,o[0][1]):!l&&T>0&&(t=lu(b+D+k,o[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(s){let e=0,t=0;c&&w>0?e=lu(y+w,s[0][0]):!c&&w<0&&(e=cu(y+E,s[1][0])),l&&T>0?t=lu(b+T,s[0][1]):!l&&T<0&&(t=cu(b+D,s[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(i){if(u){let e=uu(E/C,_,v)*C;if(A=Math.max(A,e),o){let e=0;e=!c&&!l||c&&!l&&f?lu(b+k+E/C,o[1][1])*C:cu(b+k+(c?w:-w)/C,o[0][1])*C,A=Math.max(A,e)}if(s){let e=0;e=!c&&!l||c&&!l&&f?cu(b+E/C,s[1][1])*C:lu(b+(c?w:-w)/C,s[0][1])*C,A=Math.max(A,e)}}if(d){let e=uu(D*C,h,g)/C;if(j=Math.max(j,e),o){let e=0;e=!c&&!l||l&&!c&&f?lu(y+D*C+O,o[1][0])/C:cu(y+(l?T:-T)*C+O,o[0][0])/C,j=Math.max(j,e)}if(s){let e=0;e=!c&&!l||l&&!c&&f?cu(y+D*C,s[1][0])/C:lu(y+(l?T:-T)*C,s[0][0])/C,j=Math.max(j,e)}}}T+=T<0?j:-j,w+=w<0?A:-A,i&&(f?E>D*C?T=(du(c,l)?-w:w)/C:w=(du(c,l)?-T:T)*C:u?(T=w/C,l=c):(w=T*C,c=l));let M=c?y+w:y,N=l?b+T:b;return{width:x+(c?-w:w),height:S+(l?-T:T),x:a[0]*w*(c?-1:1)+M,y:a[1]*T*(l?-1:1)+N}}var pu={width:0,height:0,x:0,y:0},mu={...pu,pointerX:0,pointerY:0,aspectRatio:1};function hu(e,t,n){let r=t.position.x+e.position.x,i=t.position.y+e.position.y,a=e.measured.width??0,o=e.measured.height??0,s=n[0]*a,c=n[1]*o;return[[r-s,i-c],[r+a-s,i+o-c]]}function gu({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){let a=Zr(e),o={controlDirection:su(`bottom-right`),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function s({controlPosition:e,boundaries:s,keepAspectRatio:c,resizeDirection:l,onResizeStart:u,onResize:d,onResizeEnd:f,shouldResize:p}){let m={...pu},h={...mu};o={boundaries:s,resizeDirection:l,keepAspectRatio:c,controlDirection:su(e)};let g,_=null,v=[],y,b,x,S=!1,C=fi().on(`start`,e=>{let{nodeLookup:r,transform:i,snapGrid:a,snapToGrid:o,nodeOrigin:s,paneDomNode:c}=n();if(g=r.get(t),!g)return;_=c?.getBoundingClientRect()??null;let{xSnapped:l,ySnapped:d}=Mc(e.sourceEvent,{transform:i,snapGrid:a,snapToGrid:o,containerBounds:_});m={width:g.measured.width??0,height:g.measured.height??0,x:g.position.x??0,y:g.position.y??0},h={...m,pointerX:l,pointerY:d,aspectRatio:m.width/m.height},y=void 0,b=Tc(g.extent)?g.extent:void 0,g.parentId&&(g.extent===`parent`||g.expandParent)&&(y=r.get(g.parentId)),y&&g.extent===`parent`&&(b=[[0,0],[y.measured.width,y.measured.height]]),v=[],x=void 0;for(let[e,n]of r)if(n.parentId===t&&(v.push({id:e,position:{...n.position},extent:n.extent}),n.extent===`parent`||n.expandParent)){let e=hu(n,g,n.origin??s);x=x?[[Math.min(e[0][0],x[0][0]),Math.min(e[0][1],x[0][1])],[Math.max(e[1][0],x[1][0]),Math.max(e[1][1],x[1][1])]]:e}u?.(e,{...m})}).on(`drag`,e=>{let{transform:t,snapGrid:i,snapToGrid:a,nodeOrigin:s}=n(),c=Mc(e.sourceEvent,{transform:t,snapGrid:i,snapToGrid:a,containerBounds:_}),l=[];if(!g)return;let{x:u,y:f,width:C,height:w}=m,T={},E=g.origin??s,{width:D,height:O,x:k,y:A}=fu(h,o.controlDirection,c,o.boundaries,o.keepAspectRatio,E,b,x),j=D!==C,M=O!==w,N=k!==u&&j,P=A!==f&&M;if(!N&&!P&&!j&&!M)return;if((N||P||E[0]===1||E[1]===1)&&(T.x=N?k:m.x,T.y=P?A:m.y,m.x=T.x,m.y=T.y,v.length>0)){let e=k-u,t=A-f;for(let n of v)n.position={x:n.position.x-e+E[0]*(D-C),y:n.position.y-t+E[1]*(O-w)},l.push(n)}if((j||M)&&(T.width=j&&(!o.resizeDirection||o.resizeDirection===`horizontal`)?D:m.width,T.height=M&&(!o.resizeDirection||o.resizeDirection===`vertical`)?O:m.height,m.width=T.width,m.height=T.height),y&&g.expandParent){let e=E[0]*(T.width??0);T.x&&T.x<e&&(m.x=e,h.x-=T.x-e);let t=E[1]*(T.height??0);T.y&&T.y<t&&(m.y=t,h.y-=T.y-t)}let F=ou({width:m.width,prevWidth:C,height:m.height,prevHeight:w,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),I={...m,direction:F};p?.(e,I)!==!1&&(S=!0,d?.(e,I),r(T,l))}).on(`end`,e=>{S&&=(f?.(e,{...m}),i?.({...m}),!1)});a.call(C)}function c(){a.on(`.drag`,null)}return{update:s,destroy:c}}var _u=r((e=>{var t=n();function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:r,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),vu=r(((e,t)=>{t.exports=_u()})),yu=r((e=>{var t=n(),r=vu();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=r.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),bu=c(r(((e,t)=>{t.exports=yu()}))(),1),xu=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e)),destroy:()=>{n.clear()}},o=t=e(r,i,a);return a},Su=e=>e?xu(e):xu,{useDebugValue:Cu}=p.default,{useSyncExternalStoreWithSelector:wu}=bu.default,Tu=e=>e;function Eu(e,t=Tu,n){let r=wu(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Cu(r),r}var Du=(e,t)=>{let n=Su(e),r=(e,r=t)=>Eu(n,e,r);return Object.assign(r,n),r},Ou=(e,t)=>e?Du(e,t):Du;function ku(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Au=f(),ju=(0,p.createContext)(null),Mu=ju.Provider,Nu=js.error001(`react`);function $(e,t){let n=(0,p.useContext)(ju);if(n===null)throw Error(Nu);return Eu(n,e,t)}function Pu(){let e=(0,p.useContext)(ju);if(e===null)throw Error(Nu);return(0,p.useMemo)(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}var Fu={display:`none`},Iu={position:`absolute`,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0px, 0px, 0px, 0px)`,clipPath:`inset(100%)`},Lu=`react-flow__node-desc`,Ru=`react-flow__edge-desc`,zu=`react-flow__aria-live`,Bu=e=>e.ariaLiveMessage,Vu=e=>e.ariaLabelConfig;function Hu({rfId:e}){let t=$(Bu);return(0,X.jsx)(`div`,{id:`${zu}-${e}`,"aria-live":`assertive`,"aria-atomic":`true`,style:Iu,children:t})}function Uu({rfId:e,disableKeyboardA11y:t}){let n=$(Vu);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{id:`${Lu}-${e}`,style:Fu,children:t?n[`node.a11yDescription.default`]:n[`node.a11yDescription.keyboardDisabled`]}),(0,X.jsx)(`div`,{id:`${Ru}-${e}`,style:Fu,children:n[`edge.a11yDescription.default`]}),!t&&(0,X.jsx)(Hu,{rfId:e})]})}var Wu=(0,p.forwardRef)(({position:e=`top-left`,children:t,className:n,style:r,...i},a)=>(0,X.jsx)(`div`,{className:Gt([`react-flow__panel`,n,...`${e}`.split(`-`)]),style:r,ref:a,...i,children:t}));Wu.displayName=`Panel`;var Gu=`https://reactflow.dev?utm_source=attribution`;function Ku({proOptions:e,position:t=`bottom-right`}){return e?.hideAttribution?null:(0,X.jsx)(Wu,{position:t,className:`react-flow__attribution`,"data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: ${Gu}`,children:(0,X.jsx)(`a`,{href:Gu,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`React Flow attribution`,children:`React Flow`})})}var qu=e=>{let t=[],n=[];for(let[,n]of e.nodeLookup)n.selected&&t.push(n.internals.userNode);for(let[,t]of e.edgeLookup)t.selected&&n.push(t);return{selectedNodes:t,selectedEdges:n}},Ju=e=>e.id;function Yu(e,t){return ku(e.selectedNodes.map(Ju),t.selectedNodes.map(Ju))&&ku(e.selectedEdges.map(Ju),t.selectedEdges.map(Ju))}function Xu({onSelectionChange:e}){let t=Pu(),{selectedNodes:n,selectedEdges:r}=$(qu,Yu);return(0,p.useEffect)(()=>{let i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(e=>e(i))},[n,r,e]),null}var Zu=e=>!!e.onSelectionChangeHandlers;function Qu({onSelectionChange:e}){let t=$(Zu);return e||t?(0,X.jsx)(Xu,{onSelectionChange:e}):null}var $u=[0,0],ed={x:0,y:0,zoom:1},td=[...`nodes.edges.defaultNodes.defaultEdges.onConnect.onConnectStart.onConnectEnd.onClickConnectStart.onClickConnectEnd.nodesDraggable.autoPanOnNodeFocus.nodesConnectable.nodesFocusable.edgesFocusable.edgesReconnectable.elevateNodesOnSelect.elevateEdgesOnSelect.minZoom.maxZoom.nodeExtent.onNodesChange.onEdgesChange.elementsSelectable.connectionMode.snapGrid.snapToGrid.translateExtent.connectOnClick.defaultEdgeOptions.fitView.fitViewOptions.onNodesDelete.onEdgesDelete.onDelete.onNodeDrag.onNodeDragStart.onNodeDragStop.onSelectionDrag.onSelectionDragStart.onSelectionDragStop.onMoveStart.onMove.onMoveEnd.noPanClassName.nodeOrigin.autoPanOnConnect.autoPanOnNodeDrag.onError.connectionRadius.isValidConnection.selectNodesOnDrag.nodeDragThreshold.connectionDragThreshold.onBeforeDelete.debug.autoPanSpeed.ariaLabelConfig.zIndexMode`.split(`.`),`rfId`],nd=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),rd={translateExtent:Ms,nodeOrigin:$u,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:`nopan`,rfId:`1`};function id(e){let{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:a,setNodeExtent:o,reset:s,setDefaultNodesAndEdges:c}=$(nd,ku),l=Pu();(0,p.useEffect)(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=rd,s()}),[]);let u=(0,p.useRef)(rd);return(0,p.useEffect)(()=>{for(let s of td){let c=e[s];c!==u.current[s]&&e[s]!==void 0&&(s===`nodes`?t(c):s===`edges`?n(c):s===`minZoom`?r(c):s===`maxZoom`?i(c):s===`translateExtent`?a(c):s===`nodeExtent`?o(c):s===`ariaLabelConfig`?l.setState({ariaLabelConfig:jc(c)}):s===`fitView`?l.setState({fitViewQueued:c}):s===`fitViewOptions`?l.setState({fitViewOptions:c}):l.setState({[s]:c}))}u.current=e},td.map(t=>e[t])),null}function ad(){return typeof window>`u`||!window.matchMedia?null:window.matchMedia(`(prefers-color-scheme: dark)`)}function od(e){let[t,n]=(0,p.useState)(e===`system`?null:e);return(0,p.useEffect)(()=>{if(e!==`system`){n(e);return}let t=ad(),r=()=>n(t?.matches?`dark`:`light`);return r(),t?.addEventListener(`change`,r),()=>{t?.removeEventListener(`change`,r)}},[e]),t===null?ad()?.matches?`dark`:`light`:t}var sd=typeof document<`u`?document:null;function cd(e=null,t={target:sd,actInsideInputWithModifier:!0}){let[n,r]=(0,p.useState)(!1),i=(0,p.useRef)(!1),a=(0,p.useRef)(new Set([])),[o,s]=(0,p.useMemo)(()=>{if(e!==null){let t=(Array.isArray(e)?e:[e]).filter(e=>typeof e==`string`).map(e=>e.replace(`+`,`
6
+ `).replace(`
7
+
8
+ `,`
9
+ +`).split(`
10
+ `));return[t,t.reduce((e,t)=>e.concat(...t),[])]}return[[],[]]},[e]);return(0,p.useEffect)(()=>{let n=t?.target??sd,c=t?.actInsideInputWithModifier??!0;if(e!==null){let e=e=>{if(i.current=e.ctrlKey||e.metaKey||e.shiftKey||e.altKey,(!i.current||i.current&&!c)&&Ic(e))return!1;let n=ud(e.code,s);if(a.current.add(e[n]),ld(o,a.current,!1)){let n=e.composedPath?.()?.[0]||e.target,a=n?.nodeName===`BUTTON`||n?.nodeName===`A`;t.preventDefault!==!1&&(i.current||!a)&&e.preventDefault(),r(!0)}},l=e=>{let t=ud(e.code,s);ld(o,a.current,!0)?(r(!1),a.current.clear()):a.current.delete(e[t]),e.key===`Meta`&&a.current.clear(),i.current=!1},u=()=>{a.current.clear(),r(!1)};return n?.addEventListener(`keydown`,e),n?.addEventListener(`keyup`,l),window.addEventListener(`blur`,u),window.addEventListener(`contextmenu`,u),()=>{n?.removeEventListener(`keydown`,e),n?.removeEventListener(`keyup`,l),window.removeEventListener(`blur`,u),window.removeEventListener(`contextmenu`,u)}}},[e,r]),n}function ld(e,t,n){return e.filter(e=>n||e.length===t.size).some(e=>e.every(e=>t.has(e)))}function ud(e,t){return t.includes(e)?`code`:`key`}var dd=()=>{let e=Pu();return(0,p.useMemo)(()=>({zoomIn:async t=>{let{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):!1},zoomOut:async t=>{let{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):!1},zoomTo:async(t,n)=>{let{panZoom:r}=e.getState();return r?r.scaleTo(t,n):!1},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{let{transform:[r,i,a],panZoom:o}=e.getState();return o?(await o.setViewport({x:t.x??r,y:t.y??i,zoom:t.zoom??a},n),!0):!1},getViewport:()=>{let[t,n,r]=e.getState().transform;return{x:t,y:n,zoom:r}},setCenter:async(t,n,r)=>e.getState().setCenter(t,n,r),fitBounds:async(t,n)=>{let{width:r,height:i,minZoom:a,maxZoom:o,panZoom:s}=e.getState(),c=Cc(t,r,i,a,o,n?.padding??.1);return s?(await s.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0):!1},screenToFlowPosition:(t,n={})=>{let{transform:r,snapGrid:i,snapToGrid:a,domNode:o}=e.getState();if(!o)return t;let{x:s,y:c}=o.getBoundingClientRect(),l={x:t.x-s,y:t.y-c},u=n.snapGrid??i;return vc(l,r,n.snapToGrid??a,u)},flowToScreenPosition:t=>{let{transform:n,domNode:r}=e.getState();if(!r)return t;let{x:i,y:a}=r.getBoundingClientRect(),o=yc(t,n);return{x:o.x+i,y:o.y+a}}}),[])};function fd(e,t){let n=[],r=new Map,i=[];for(let t of e)if(t.type===`add`){i.push(t);continue}else if(t.type===`remove`||t.type===`replace`)r.set(t.id,[t]);else{let e=r.get(t.id);e?e.push(t):r.set(t.id,[t])}for(let e of t){let t=r.get(e.id);if(!t){n.push(e);continue}if(t[0].type===`remove`)continue;if(t[0].type===`replace`){n.push({...t[0].item});continue}let i={...e};for(let e of t)pd(e,i);n.push(i)}return i.length&&i.forEach(e=>{e.index===void 0?n.push({...e.item}):n.splice(e.index,0,{...e.item})}),n}function pd(e,t){switch(e.type){case`select`:t.selected=e.selected;break;case`position`:e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case`dimensions`:e.dimensions!==void 0&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes===`width`)&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes===`height`)&&(t.height=e.dimensions.height))),typeof e.resizing==`boolean`&&(t.resizing=e.resizing);break}}function md(e,t){return fd(e,t)}function hd(e,t){return fd(e,t)}function gd(e,t){return{id:e,type:`select`,selected:t}}function _d(e,t=new Set,n=!1){let r=[];for(let[i,a]of e){let e=t.has(i);!(a.selected===void 0&&!e)&&a.selected!==e&&(n&&(a.selected=e),r.push(gd(a.id,e)))}return r}function vd({items:e=[],lookup:t}){let n=[],r=new Map(e.map(e=>[e.id,e]));for(let[r,i]of e.entries()){let e=t.get(i.id),a=e?.internals?.userNode??e;a!==void 0&&a!==i&&n.push({id:i.id,item:i,type:`replace`}),a===void 0&&n.push({item:i,type:`add`,index:r})}for(let[e]of t)r.get(e)===void 0&&n.push({id:e,type:`remove`});return n}function yd(e){return{id:e.id,type:`remove`}}var bd=gc(`React Flow`,`https://reactflow.dev/`);function xd(e,t,n={}){return Yc(e,t,{...n,onError:n.onError??bd})}var Sd=e=>Ws(e),Cd=e=>Us(e);function wd(e){return(0,p.forwardRef)(e)}var Td=typeof window<`u`?p.useLayoutEffect:p.useEffect;function Ed(e){let[t,n]=(0,p.useState)(BigInt(0)),[r]=(0,p.useState)(()=>Dd(()=>n(e=>e+BigInt(1))));return Td(()=>{let t=r.get();t.length&&(e(t),r.reset())},[t]),r}function Dd(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}var Od=(0,p.createContext)(null);function kd({children:e}){let t=Pu(),n=Ed((0,p.useCallback)(e=>{let{nodes:n=[],setNodes:r,hasDefaultNodes:i,onNodesChange:a,nodeLookup:o,fitViewQueued:s,onNodesChangeMiddlewareMap:c}=t.getState(),l=n;for(let t of e)l=typeof t==`function`?t(l):t;let u=vd({items:l,lookup:o});for(let e of c.values())u=e(u);i&&r(l),u.length>0?a?.(u):s&&window.requestAnimationFrame(()=>{let{fitViewQueued:e,nodes:n,setNodes:r}=t.getState();e&&r(n)})},[])),r=Ed((0,p.useCallback)(e=>{let{edges:n=[],setEdges:r,hasDefaultEdges:i,onEdgesChange:a,edgeLookup:o}=t.getState(),s=n;for(let t of e)s=typeof t==`function`?t(s):t;i?r(s):a&&a(vd({items:s,lookup:o}))},[])),i=(0,p.useMemo)(()=>({nodeQueue:n,edgeQueue:r}),[]);return(0,X.jsx)(Od.Provider,{value:i,children:e})}function Ad(){let e=(0,p.useContext)(Od);if(!e)throw Error(`useBatchContext must be used within a BatchProvider`);return e}var jd=e=>!!e.panZoom;function Md(){let e=dd(),t=Pu(),n=Ad(),r=$(jd),i=(0,p.useMemo)(()=>{let e=e=>t.getState().nodeLookup.get(e),r=e=>{n.nodeQueue.push(e)},i=e=>{n.edgeQueue.push(e)},a=e=>{let{nodeLookup:n,nodeOrigin:r}=t.getState(),i=Sd(e)?e:n.get(e.id),a=i.parentId?Oc(i.position,i.measured,i.parentId,n,r):i.position;return lc({...i,position:a,width:i.measured?.width??i.width,height:i.measured?.height??i.height})},o=(e,t,n={replace:!1})=>{r(r=>r.map(r=>{if(r.id===e){let e=typeof t==`function`?t(r):t;return n.replace&&Sd(e)?e:{...r,...e}}return r}))},s=(e,t,n={replace:!1})=>{i(r=>r.map(r=>{if(r.id===e){let e=typeof t==`function`?t(r):t;return n.replace&&Cd(e)?e:{...r,...e}}return r}))};return{getNodes:()=>t.getState().nodes.map(e=>({...e})),getNode:t=>e(t)?.internals.userNode,getInternalNode:e,getEdges:()=>{let{edges:e=[]}=t.getState();return e.map(e=>({...e}))},getEdge:e=>t.getState().edgeLookup.get(e),setNodes:r,setEdges:i,addNodes:e=>{let t=Array.isArray(e)?e:[e];n.nodeQueue.push(e=>[...e,...t])},addEdges:e=>{let t=Array.isArray(e)?e:[e];n.edgeQueue.push(e=>[...e,...t])},toObject:()=>{let{nodes:e=[],edges:n=[],transform:r}=t.getState(),[i,a,o]=r;return{nodes:e.map(e=>({...e})),edges:n.map(e=>({...e})),viewport:{x:i,y:a,zoom:o}}},deleteElements:async({nodes:e=[],edges:n=[]})=>{let{nodes:r,edges:i,onNodesDelete:a,onEdgesDelete:o,triggerNodeChanges:s,triggerEdgeChanges:c,onDelete:l,onBeforeDelete:u}=t.getState(),{nodes:d,edges:f}=await ec({nodesToRemove:e,edgesToRemove:n,nodes:r,edges:i,onBeforeDelete:u}),p=f.length>0,m=d.length>0;if(p){let e=f.map(yd);o?.(f),c(e)}if(m){let e=d.map(yd);a?.(d),s(e)}return(m||p)&&l?.({nodes:d,edges:f}),{deletedNodes:d,deletedEdges:f}},getIntersectingNodes:(e,n=!0,r)=>{let i=mc(e),o=i?e:a(e),s=r!==void 0;return o?(r||t.getState().nodes).filter(r=>{let a=t.getState().nodeLookup.get(r.id);if(a&&!i&&(r.id===e.id||!a.internals.positionAbsolute))return!1;let c=lc(s?r:a),l=pc(c,o);return n&&l>0||l>=c.width*c.height||l>=o.width*o.height}):[]},isNodeIntersecting:(e,t,n=!0)=>{let r=mc(e)?e:a(e);if(!r)return!1;let i=pc(r,t);return n&&i>0||i>=t.width*t.height||i>=r.width*r.height},updateNode:o,updateNodeData:(e,t,n={replace:!1})=>{o(e,e=>{let r=typeof t==`function`?t(e):t;return n.replace?{...e,data:r}:{...e,data:{...e.data,...r}}},n)},updateEdge:s,updateEdgeData:(e,t,n={replace:!1})=>{s(e,e=>{let r=typeof t==`function`?t(e):t;return n.replace?{...e,data:r}:{...e,data:{...e.data,...r}}},n)},getNodesBounds:e=>{let{nodeLookup:n,nodeOrigin:r}=t.getState();return qs(e,{nodeLookup:n,nodeOrigin:r})},getHandleConnections:({type:e,id:n,nodeId:r})=>Array.from(t.getState().connectionLookup.get(`${r}-${e}${n?`-${n}`:``}`)?.values()??[]),getNodeConnections:({type:e,handleId:n,nodeId:r})=>Array.from(t.getState().connectionLookup.get(`${r}${e?n?`-${e}-${n}`:`-${e}`:``}`)?.values()??[]),fitView:async e=>{let r=t.getState().fitViewResolver??Ac();return t.setState({fitViewQueued:!0,fitViewOptions:e,fitViewResolver:r}),n.nodeQueue.push(e=>[...e]),r.promise}}},[]);return(0,p.useMemo)(()=>({...i,...e,viewportInitialized:r}),[r])}var Nd=e=>e.selected,Pd=typeof window<`u`?window:void 0;function Fd({deleteKeyCode:e,multiSelectionKeyCode:t}){let n=Pu(),{deleteElements:r}=Md(),i=cd(e,{actInsideInputWithModifier:!1}),a=cd(t,{target:Pd});(0,p.useEffect)(()=>{if(i){let{edges:e,nodes:t}=n.getState();r({nodes:t.filter(Nd),edges:e.filter(Nd)}),n.setState({nodesSelectionActive:!1})}},[i]),(0,p.useEffect)(()=>{n.setState({multiSelectionActive:a})},[a])}function Id(e){let t=Pu();(0,p.useEffect)(()=>{let n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;let n=Nc(e.current);(n.height===0||n.width===0)&&t.getState().onError?.(`004`,js.error004()),t.setState({width:n.width||500,height:n.height||500})};if(e.current){n(),window.addEventListener(`resize`,n);let t=new ResizeObserver(()=>n());return t.observe(e.current),()=>{window.removeEventListener(`resize`,n),t&&e.current&&t.unobserve(e.current)}}},[])}var Ld={position:`absolute`,width:`100%`,height:`100%`,top:0,left:0},Rd=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function zd({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:a=Is.Free,zoomOnDoubleClick:o=!0,panOnDrag:s=!0,defaultViewport:c,translateExtent:l,minZoom:u,maxZoom:d,zoomActivationKeyCode:f,preventScrolling:m=!0,children:h,noWheelClassName:g,noPanClassName:_,onViewportChange:v,isControlledViewport:y,paneClickDistance:b,selectionOnDrag:x}){let S=Pu(),C=(0,p.useRef)(null),{userSelectionActive:w,lib:T,connectionInProgress:E}=$(Rd,ku),D=cd(f),O=(0,p.useRef)();Id(C);let k=(0,p.useCallback)(e=>{v?.({x:e[0],y:e[1],zoom:e[2]}),y||S.setState({transform:e})},[v,y]);return(0,p.useEffect)(()=>{if(C.current){O.current=iu({domNode:C.current,minZoom:u,maxZoom:d,translateExtent:l,viewport:c,onDraggingChange:e=>S.setState(t=>t.paneDragging===e?t:{paneDragging:e}),onPanZoomStart:(e,t)=>{let{onViewportChangeStart:n,onMoveStart:r}=S.getState();r?.(e,t),n?.(t)},onPanZoom:(e,t)=>{let{onViewportChange:n,onMove:r}=S.getState();r?.(e,t),n?.(t)},onPanZoomEnd:(e,t)=>{let{onViewportChangeEnd:n,onMoveEnd:r}=S.getState();r?.(e,t),n?.(t)}});let{x:e,y:t,zoom:n}=O.current.getViewport();return S.setState({panZoom:O.current,transform:[e,t,n],domNode:C.current.closest(`.react-flow`)}),()=>{O.current?.destroy()}}},[]),(0,p.useEffect)(()=>{O.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:a,zoomOnDoubleClick:o,panOnDrag:s,zoomActivationKeyPressed:D,preventScrolling:m,noPanClassName:_,userSelectionActive:w,noWheelClassName:g,lib:T,onTransformChange:k,connectionInProgress:E,selectionOnDrag:x,paneClickDistance:b})},[e,t,n,r,i,a,o,s,D,m,_,w,g,T,k,E,x,b]),(0,X.jsx)(`div`,{className:`react-flow__renderer`,ref:C,style:Ld,children:h})}var Bd=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function Vd(){let{userSelectionActive:e,userSelectionRect:t}=$(Bd,ku);return e&&t?(0,X.jsx)(`div`,{className:`react-flow__selection react-flow__container`,style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}var Hd=(e,t)=>n=>{n.target===t.current&&e?.(n)},Ud=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function Wd({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Ls.Full,panOnDrag:r,autoPanOnSelection:i,paneClickDistance:a,selectionOnDrag:o,onSelectionStart:s,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:u,onPaneScroll:d,onPaneMouseEnter:f,onPaneMouseMove:m,onPaneMouseLeave:h,children:g}){let _=(0,p.useRef)(0),v=Pu(),{userSelectionActive:y,elementsSelectable:b,dragging:x,panBy:S,autoPanSpeed:C}=$(Ud,ku),w=b&&(e||y),T=(0,p.useRef)(null),E=(0,p.useRef)(),D=(0,p.useRef)(new Set),O=(0,p.useRef)(new Set),k=(0,p.useRef)(!1),A=(0,p.useRef)(!1),j=(0,p.useRef)({x:0,y:0}),M=(0,p.useRef)(!1),N=e=>{if(A.current||k.current||v.getState().connection.inProgress){A.current=!1,k.current=!1;return}l?.(e),v.getState().resetSelectedElements(),v.setState({nodesSelectionActive:!1})},P=e=>{if(Array.isArray(r)&&r?.includes(2)){e.preventDefault();return}u?.(e)},F=d?e=>d(e):void 0,I=e=>{A.current&&=(e.stopPropagation(),!1)},L=n=>{let{domNode:r,transform:i}=v.getState();if(E.current=r?.getBoundingClientRect(),!E.current)return;let a=n.target===T.current;if(!a&&n.target.closest(`.nokey`)||!e||!(o&&a||t)||n.button!==0||!n.isPrimary)return;n.target?.setPointerCapture?.(n.pointerId),A.current=!1;let{x:s,y:c}=Rc(n.nativeEvent,E.current),l=vc({x:s,y:c},i);v.setState({userSelectionRect:{width:0,height:0,startX:l.x,startY:l.y,x:s,y:c}}),a||(n.stopPropagation(),n.preventDefault())};function R(e,t){let{userSelectionRect:r}=v.getState();if(!r)return;let{transform:i,nodeLookup:a,edgeLookup:o,connectionLookup:s,triggerNodeChanges:c,triggerEdgeChanges:l,defaultEdgeOptions:u}=v.getState(),d={x:r.startX,y:r.startY},{x:f,y:p}=yc(d,i),m={startX:d.x,startY:d.y,x:e<f?e:f,y:t<p?t:p,width:Math.abs(e-f),height:Math.abs(t-p)},h=D.current,g=O.current;D.current=new Set(Ys(a,m,i,n===Ls.Partial,!0).map(e=>e.id)),O.current=new Set;let _=u?.selectable??!0;for(let e of D.current){let t=s.get(e);if(t)for(let{edgeId:e}of t.values()){let t=o.get(e);t&&(t.selectable??_)&&O.current.add(e)}}kc(h,D.current)||c(_d(a,D.current,!0)),kc(g,O.current)||l(_d(o,O.current)),v.setState({userSelectionRect:m,userSelectionActive:!0,nodesSelectionActive:!1})}function z(){if(!i||!E.current)return;let[e,t]=ac(j.current,E.current,C);S({x:e,y:t}).then(e=>{if(!A.current||!e){_.current=requestAnimationFrame(z);return}let{x:t,y:n}=j.current;R(t,n),_.current=requestAnimationFrame(z)})}let B=()=>{cancelAnimationFrame(_.current),_.current=0,M.current=!1};return(0,p.useEffect)(()=>()=>B(),[]),(0,X.jsxs)(`div`,{className:Gt([`react-flow__pane`,{draggable:r===!0||Array.isArray(r)&&r.includes(0),dragging:x,selection:e}]),onClick:w?void 0:Hd(N,T),onContextMenu:Hd(P,T),onWheel:Hd(F,T),onPointerEnter:w?void 0:f,onPointerMove:w?e=>{let{userSelectionRect:n,transform:r,resetSelectedElements:i}=v.getState();if(!E.current||!n)return;let{x:o,y:c}=Rc(e.nativeEvent,E.current);j.current={x:o,y:c};let l=yc({x:n.startX,y:n.startY},r);if(!A.current){let n=t?0:a;if(Math.hypot(o-l.x,c-l.y)<=n)return;i(),s?.(e)}A.current=!0,M.current||=(z(),!0),R(o,c)}:m,onPointerUp:e=>{if(!w){e.target===T.current&&v.getState().connection.inProgress&&(k.current=!0);return}e.button===0&&(e.target?.releasePointerCapture?.(e.pointerId),!y&&e.target===T.current&&v.getState().userSelectionRect&&N?.(e),v.setState({userSelectionActive:!1,userSelectionRect:null}),A.current&&(c?.(e),v.setState({nodesSelectionActive:D.current.size>0})),B())},onPointerCancel:w?e=>{e.target?.releasePointerCapture?.(e.pointerId),B()}:void 0,onPointerDownCapture:w?L:void 0,onClickCapture:w?I:void 0,onPointerLeave:h,ref:T,style:Ld,children:[g,(0,X.jsx)(Vd,{})]})}function Gd({id:e,store:t,unselect:n=!1,nodeRef:r}){let{addSelectedNodes:i,unselectNodesAndEdges:a,multiSelectionActive:o,nodeLookup:s,onError:c}=t.getState(),l=s.get(e);if(!l){c?.(`012`,js.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(a({nodes:[l],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function Kd({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:i,isSelectable:a,nodeClickDistance:o}){let s=Pu(),[c,l]=(0,p.useState)(!1),u=(0,p.useRef)();return(0,p.useEffect)(()=>{u.current=Nl({getStoreItems:()=>s.getState(),onNodeMouseDown:t=>{Gd({id:t,store:s,nodeRef:e})},onDragStart:()=>{l(!0)},onDragStop:()=>{l(!1)}})},[]),(0,p.useEffect)(()=>{if(!(t||!e.current||!u.current))return u.current.update({noDragClassName:n,handleSelector:r,domNode:e.current,isSelectable:a,nodeId:i,nodeClickDistance:o}),()=>{u.current?.destroy()}},[n,r,t,a,e,i,o]),c}var qd=e=>t=>t.selected&&(t.draggable||e&&t.draggable===void 0);function Jd(){let e=Pu();return(0,p.useCallback)(t=>{let{nodeExtent:n,snapToGrid:r,snapGrid:i,nodesDraggable:a,onError:o,updateNodePositions:s,nodeLookup:c,nodeOrigin:l}=e.getState(),u=new Map,d=qd(a),f=r?i[0]:5,p=r?i[1]:5,m=t.direction.x*f*t.factor,h=t.direction.y*p*t.factor;for(let[,e]of c){if(!d(e))continue;let t={x:e.internals.positionAbsolute.x+m,y:e.internals.positionAbsolute.y+h};r&&(t=_c(t,i));let{position:a,positionAbsolute:s}=$s({nodeId:e.id,nextPosition:t,nodeLookup:c,nodeExtent:n,nodeOrigin:l,onError:o});e.position=a,e.internals.positionAbsolute=s,u.set(e.id,e)}s(u)},[])}var Yd=(0,p.createContext)(null),Xd=Yd.Provider;Yd.Consumer;var Zd=()=>(0,p.useContext)(Yd),Qd=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),$d=(0,p.createContext)(null);function ef({children:e}){let t=$(Qd,ku);return(0,X.jsx)($d.Provider,{value:t,children:e})}function tf(){let e=(0,p.useContext)($d);if(!e)throw Error(`useHandleConfig must be used within a HandleConfigProvider`);return e}var nf={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},rf=(e,t,n)=>r=>{let{connectionClickStartHandle:i,connectionMode:a,connection:o}=r,{fromHandle:s,toHandle:c,isValid:l}=o;if(!s&&!i)return nf;let u=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:s?.nodeId===e&&s?.id===t&&s?.type===n,connectingTo:u,clickConnecting:i?.nodeId===e&&i?.id===t&&i?.type===n,isPossibleEndHandle:a===Fs.Strict?s?.type!==n:e!==s?.nodeId||t!==s?.id,connectionInProcess:!!s,clickConnectionInProcess:!!i,valid:u&&l}};function af({type:e=`source`,position:t=Q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:a=!0,id:o,onConnect:s,children:c,className:l,onMouseDown:u,onTouchStart:d,...f},p){let m=o||null,h=e===`target`,g=Pu(),_=Zd(),{connectOnClick:v,noPanClassName:y,rfId:b}=tf(),{connectingFrom:x,connectingTo:S,clickConnecting:C,isPossibleEndHandle:w,connectionInProcess:T,clickConnectionInProcess:E,valid:D}=$(rf(_,m,e),ku);_||g.getState().onError?.(`010`,js.error010());let O=e=>{let{defaultEdgeOptions:t,onConnect:n,hasDefaultEdges:r}=g.getState(),i={...t,...e};if(r){let{edges:e,setEdges:t,onError:n}=g.getState();t(xd(i,e,{onError:n}))}n?.(i),s?.(i)},k=e=>{if(!_)return;let t=Lc(e.nativeEvent);if(i&&(t&&e.button===0||!t)){let t=g.getState();Ul.onPointerDown(e.nativeEvent,{handleDomNode:e.currentTarget,autoPanOnConnect:t.autoPanOnConnect,connectionMode:t.connectionMode,connectionRadius:t.connectionRadius,domNode:t.domNode,nodeLookup:t.nodeLookup,lib:t.lib,isTarget:h,handleId:m,nodeId:_,flowId:t.rfId,panBy:t.panBy,cancelConnection:t.cancelConnection,onConnectStart:t.onConnectStart,onConnectEnd:(...e)=>g.getState().onConnectEnd?.(...e),updateConnection:t.updateConnection,onConnect:O,isValidConnection:n||((...e)=>g.getState().isValidConnection?.(...e)??!0),getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,autoPanSpeed:t.autoPanSpeed,dragThreshold:t.connectionDragThreshold})}t?u?.(e):d?.(e)};return(0,X.jsx)(`div`,{"data-handleid":m,"data-nodeid":_,"data-handlepos":t,"data-id":`${b}-${_}-${m}-${e}`,className:Gt([`react-flow__handle`,`react-flow__handle-${t}`,`nodrag`,y,l,{source:!h,target:h,connectable:r,connectablestart:i,connectableend:a,clickconnecting:C,connectingfrom:x,connectingto:S,valid:D,connectionindicator:r&&(!T||w)&&(T||E?a:i)}]),onMouseDown:k,onTouchStart:k,onClick:v?t=>{let{onClickConnectStart:r,onClickConnectEnd:a,connectionClickStartHandle:o,connectionMode:s,isValidConnection:c,lib:l,rfId:u,nodeLookup:d,connection:f}=g.getState();if(!_||!o&&!i)return;if(!o){r?.(t.nativeEvent,{nodeId:_,handleId:m,handleType:e}),g.setState({connectionClickStartHandle:{nodeId:_,type:e,id:m}});return}let p=Pc(t.target),h=n||c,{connection:v,isValid:y}=Ul.isValid(t.nativeEvent,{handle:{nodeId:_,id:m,type:e},connectionMode:s,fromNodeId:o.nodeId,fromHandleId:o.id||null,fromType:o.type,isValidConnection:h,flowId:u,doc:p,lib:l,nodeLookup:d});y&&v&&O(v);let b=structuredClone(f);delete b.inProgress,b.toPosition=b.toHandle?b.toHandle.position:null,a?.(t,b),g.setState({connectionClickStartHandle:null})}:void 0,ref:p,...f,children:c})}var of=(0,p.memo)(wd(af));function sf({data:e,isConnectable:t,sourcePosition:n=Q.Bottom}){return(0,X.jsxs)(X.Fragment,{children:[e?.label,(0,X.jsx)(of,{type:`source`,position:n,isConnectable:t})]})}function cf({data:e,isConnectable:t,targetPosition:n=Q.Top,sourcePosition:r=Q.Bottom}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(of,{type:`target`,position:n,isConnectable:t}),e?.label,(0,X.jsx)(of,{type:`source`,position:r,isConnectable:t})]})}function lf(){return null}function uf({data:e,isConnectable:t,targetPosition:n=Q.Top}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(of,{type:`target`,position:n,isConnectable:t}),e?.label]})}var df={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},ff={input:sf,default:cf,output:uf,group:lf};function pf(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}var mf=e=>{let{width:t,height:n,x:r,y:i}=Js(e.nodeLookup,{filter:e=>!!e.selected});return{width:hc(t)?t:null,height:hc(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${i}px)`}};function hf({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){let r=Pu(),{width:i,height:a,transformString:o,userSelectionActive:s}=$(mf,ku),c=Jd(),l=(0,p.useRef)(null);(0,p.useEffect)(()=>{n||l.current?.focus({preventScroll:!0})},[n]);let u=!s&&i!==null&&a!==null;if(Kd({nodeRef:l,disabled:!u}),!u)return null;let d=e?t=>{e(t,r.getState().nodes.filter(e=>e.selected))}:void 0;return(0,X.jsx)(`div`,{className:Gt([`react-flow__nodesselection`,`react-flow__container`,t]),style:{transform:o},children:(0,X.jsx)(`div`,{ref:l,className:`react-flow__nodesselection-rect`,onContextMenu:d,tabIndex:n?void 0:-1,onKeyDown:n?void 0:e=>{Object.prototype.hasOwnProperty.call(df,e.key)&&(e.preventDefault(),c({direction:df[e.key],factor:e.shiftKey?4:1}))},style:{width:i,height:a}})})}var gf=typeof window<`u`?window:void 0,_f=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function vf({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:a,onPaneScroll:o,paneClickDistance:s,deleteKeyCode:c,selectionKeyCode:l,selectionOnDrag:u,selectionMode:d,onSelectionStart:f,onSelectionEnd:p,multiSelectionKeyCode:m,panActivationKeyCode:h,zoomActivationKeyCode:g,elementsSelectable:_,zoomOnScroll:v,zoomOnPinch:y,panOnScroll:b,panOnScrollSpeed:x,panOnScrollMode:S,zoomOnDoubleClick:C,panOnDrag:w,autoPanOnSelection:T,defaultViewport:E,translateExtent:D,minZoom:O,maxZoom:k,preventScrolling:A,onSelectionContextMenu:j,noWheelClassName:M,noPanClassName:N,disableKeyboardA11y:P,onViewportChange:F,isControlledViewport:I}){let{nodesSelectionActive:L,userSelectionActive:R}=$(_f,ku),z=cd(l,{target:gf}),B=cd(h,{target:gf}),V=B||w,H=B||b,U=u&&V!==!0,W=z||R||U;return Fd({deleteKeyCode:c,multiSelectionKeyCode:m}),(0,X.jsx)(zd,{onPaneContextMenu:a,elementsSelectable:_,zoomOnScroll:v,zoomOnPinch:y,panOnScroll:H,panOnScrollSpeed:x,panOnScrollMode:S,zoomOnDoubleClick:C,panOnDrag:!z&&V,defaultViewport:E,translateExtent:D,minZoom:O,maxZoom:k,zoomActivationKeyCode:g,preventScrolling:A,noWheelClassName:M,noPanClassName:N,onViewportChange:F,isControlledViewport:I,paneClickDistance:s,selectionOnDrag:U,children:(0,X.jsxs)(Wd,{onSelectionStart:f,onSelectionEnd:p,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:a,onPaneScroll:o,panOnDrag:V,autoPanOnSelection:T,isSelecting:!!W,selectionMode:d,selectionKeyPressed:z,paneClickDistance:s,selectionOnDrag:U,children:[e,L&&(0,X.jsx)(hf,{onSelectionContextMenu:j,noPanClassName:N,disableKeyboardA11y:P})]})})}vf.displayName=`FlowRenderer`;var yf=(0,p.memo)(vf),bf=e=>t=>e?Ys(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(e=>e.id):Array.from(t.nodeLookup.keys());function xf(e){return $((0,p.useCallback)(bf(e),[e]),ku)}var Sf=e=>e.updateNodeInternals;function Cf(){let e=$(Sf),[t]=(0,p.useState)(()=>typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{let n=new Map;t.forEach(e=>{let t=e.target.getAttribute(`data-id`);n.set(t,{id:t,nodeElement:e.target,force:!0})}),e(n)}));return(0,p.useEffect)(()=>()=>{t?.disconnect()},[t]),t}function wf({node:e,nodeType:t,hasDimensions:n,resizeObserver:r}){let i=Pu(),a=(0,p.useRef)(null),o=(0,p.useRef)(null),s=(0,p.useRef)(e.sourcePosition),c=(0,p.useRef)(e.targetPosition),l=(0,p.useRef)(t),u=n&&!!e.internals.handleBounds;return(0,p.useEffect)(()=>{a.current&&!e.hidden&&(!u||o.current!==a.current)&&(o.current&&r?.unobserve(o.current),r?.observe(a.current),o.current=a.current)},[u,e.hidden]),(0,p.useEffect)(()=>()=>{o.current&&=(r?.unobserve(o.current),null)},[]),(0,p.useEffect)(()=>{if(a.current){let n=l.current!==t,r=s.current!==e.sourcePosition,o=c.current!==e.targetPosition;(n||r||o)&&(l.current=t,s.current=e.sourcePosition,c.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:a.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),a}function Tf({id:e,onClick:t,onMouseEnter:n,onMouseMove:r,onMouseLeave:i,onContextMenu:a,onDoubleClick:o,nodesDraggable:s,elementsSelectable:c,nodesConnectable:l,nodesFocusable:u,resizeObserver:d,noDragClassName:f,noPanClassName:p,disableKeyboardA11y:m,rfId:h,nodeTypes:g,nodeClickDistance:_,onError:v}){let{node:y,internals:b,isParent:x}=$(t=>{let n=t.nodeLookup.get(e),r=t.parentLookup.has(e);return{node:n,internals:n.internals,isParent:r}},ku),S=y.type||`default`,C=g?.[S]||ff[S];C===void 0&&(v?.(`003`,js.error003(S)),S=`default`,C=g?.default||ff.default);let w=!!(y.draggable||s&&y.draggable===void 0),T=!!(y.selectable||c&&y.selectable===void 0),E=!!(y.connectable||l&&y.connectable===void 0),D=!!(y.focusable||u&&y.focusable===void 0),O=Pu(),k=Dc(y),A=wf({node:y,nodeType:S,hasDimensions:k,resizeObserver:d}),j=Kd({nodeRef:A,disabled:y.hidden||!w,noDragClassName:f,handleSelector:y.dragHandle,nodeId:e,isSelectable:T,nodeClickDistance:_}),M=Jd();if(y.hidden)return null;let N=Ec(y),P=pf(y),F=T||w||t||n||r||i,I=n?e=>n(e,{...b.userNode}):void 0,L=r?e=>r(e,{...b.userNode}):void 0,R=i?e=>i(e,{...b.userNode}):void 0,z=a?e=>a(e,{...b.userNode}):void 0,B=o?e=>o(e,{...b.userNode}):void 0,V=n=>{let{selectNodesOnDrag:r,nodeDragThreshold:i}=O.getState();T&&(!r||!w||i>0)&&Gd({id:e,store:O,nodeRef:A}),t&&t(n,{...b.userNode})},H=t=>{if(!(Ic(t.nativeEvent)||m)){if(Ns.includes(t.key)&&T){let n=t.key===`Escape`;Gd({id:e,store:O,unselect:n,nodeRef:A})}else if(w&&y.selected&&Object.prototype.hasOwnProperty.call(df,t.key)){t.preventDefault();let{ariaLabelConfig:e}=O.getState();O.setState({ariaLiveMessage:e[`node.a11yDescription.ariaLiveMessage`]({direction:t.key.replace(`Arrow`,``).toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),M({direction:df[t.key],factor:t.shiftKey?4:1})}}},U=()=>{if(m||!A.current?.matches(`:focus-visible`))return;let{transform:t,width:n,height:r,autoPanOnNodeFocus:i,setCenter:a}=O.getState();i&&(Ys(new Map([[e,y]]),{x:0,y:0,width:n,height:r},t,!0).length>0||a(y.position.x+N.width/2,y.position.y+N.height/2,{zoom:t[2]}))};return(0,X.jsx)(`div`,{className:Gt([`react-flow__node`,`react-flow__node-${S}`,{[p]:w},y.className,{selected:y.selected,selectable:T,parent:x,draggable:w,dragging:j}]),ref:A,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:F?`all`:`none`,visibility:k?`visible`:`hidden`,...y.style,...P},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:I,onMouseMove:L,onMouseLeave:R,onContextMenu:z,onClick:V,onDoubleClick:B,onKeyDown:D?H:void 0,tabIndex:D?0:void 0,onFocus:D?U:void 0,role:y.ariaRole??(D?`group`:void 0),"aria-roledescription":`node`,"aria-describedby":m?void 0:`${Lu}-${h}`,"aria-label":y.ariaLabel,...y.domAttributes,children:(0,X.jsx)(Xd,{value:e,children:(0,X.jsx)(C,{id:e,data:y.data,type:S,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:y.selected??!1,selectable:T,draggable:w,deletable:y.deletable??!0,isConnectable:E,sourcePosition:y.sourcePosition,targetPosition:y.targetPosition,dragging:j,dragHandle:y.dragHandle,zIndex:b.z,parentId:y.parentId,...N})})})}var Ef=(0,p.memo)(Tf),Df=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Of(e){let{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:i,onError:a}=$(Df,ku),o=xf(e.onlyRenderVisibleElements),s=Cf();return(0,X.jsx)(`div`,{className:`react-flow__nodes`,style:Ld,children:o.map(o=>(0,X.jsx)(Ef,{id:o,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:s,nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:a},o))})}Of.displayName=`NodeRenderer`;var kf=(0,p.memo)(Of);function Af(e){return $((0,p.useCallback)(t=>{if(!e)return t.edges.map(e=>e.id);let n=[];if(t.width&&t.height)for(let e of t.edges){let r=t.nodeLookup.get(e.source),i=t.nodeLookup.get(e.target);r&&i&&Kc({sourceNode:r,targetNode:i,width:t.width,height:t.height,transform:t.transform})&&n.push(e.id)}return n},[e]),ku)}var jf=({color:e=`none`,strokeWidth:t=1})=>(0,X.jsx)(`polyline`,{className:`arrow`,style:{strokeWidth:t,...e&&{stroke:e}},strokeLinecap:`round`,fill:`none`,strokeLinejoin:`round`,points:`-5,-4 0,0 -5,4`}),Mf=({color:e=`none`,strokeWidth:t=1})=>(0,X.jsx)(`polyline`,{className:`arrowclosed`,style:{strokeWidth:t,...e&&{stroke:e,fill:e}},strokeLinecap:`round`,strokeLinejoin:`round`,points:`-5,-4 0,0 -5,4 -5,-4`}),Nf={[Bs.Arrow]:jf,[Bs.ArrowClosed]:Mf};function Pf(e){let t=Pu();return(0,p.useMemo)(()=>Object.prototype.hasOwnProperty.call(Nf,e)?Nf[e]:(t.getState().onError?.(`009`,js.error009(e)),null),[e])}var Ff=({id:e,type:t,color:n,width:r=12.5,height:i=12.5,markerUnits:a=`strokeWidth`,strokeWidth:o,orient:s=`auto-start-reverse`})=>{let c=Pf(t);return c?(0,X.jsx)(`marker`,{className:`react-flow__arrowhead`,id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:`-10 -10 20 20`,markerUnits:a,orient:s,refX:`0`,refY:`0`,children:(0,X.jsx)(c,{color:n,strokeWidth:o})}):null},If=({defaultColor:e,rfId:t})=>{let n=$(e=>e.edges),r=$(e=>e.defaultEdgeOptions),i=(0,p.useMemo)(()=>ll(n,{id:t,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[n,r,t,e]);return i.length?(0,X.jsx)(`svg`,{className:`react-flow__marker`,"aria-hidden":`true`,children:(0,X.jsx)(`defs`,{children:i.map(e=>(0,X.jsx)(Ff,{id:e.id,type:e.type,color:e.color,width:e.width,height:e.height,markerUnits:e.markerUnits,strokeWidth:e.strokeWidth,orient:e.orient},e.id))})}):null};If.displayName=`MarkerDefinitions`;var Lf=(0,p.memo)(If);function Rf({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:a,labelBgPadding:o=[2,4],labelBgBorderRadius:s=2,children:c,className:l,...u}){let[d,f]=(0,p.useState)({x:1,y:0,width:0,height:0}),m=Gt([`react-flow__edge-textwrapper`,l]),h=(0,p.useRef)(null);return(0,p.useEffect)(()=>{if(h.current){let e=h.current.getBBox();f({x:e.x,y:e.y,width:e.width,height:e.height})}},[n]),n?(0,X.jsxs)(`g`,{transform:`translate(${e-d.width/2} ${t-d.height/2})`,className:m,visibility:d.width?`visible`:`hidden`,...u,children:[i&&(0,X.jsx)(`rect`,{width:d.width+2*o[0],x:-o[0],y:-o[1],height:d.height+2*o[1],className:`react-flow__edge-textbg`,style:a,rx:s,ry:s}),(0,X.jsx)(`text`,{className:`react-flow__edge-text`,y:d.height/2,dy:`0.3em`,ref:h,style:r,children:n}),c]}):null}Rf.displayName=`EdgeText`;var zf=(0,p.memo)(Rf);function Bf({path:e,labelX:t,labelY:n,label:r,labelStyle:i,labelShowBg:a,labelBgStyle:o,labelBgPadding:s,labelBgBorderRadius:c,interactionWidth:l=20,...u}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`path`,{...u,d:e,fill:`none`,className:Gt([`react-flow__edge-path`,u.className])}),l?(0,X.jsx)(`path`,{d:e,fill:`none`,strokeOpacity:0,strokeWidth:l,className:`react-flow__edge-interaction`}):null,r&&hc(t)&&hc(n)?(0,X.jsx)(zf,{x:t,y:n,label:r,labelStyle:i,labelShowBg:a,labelBgStyle:o,labelBgPadding:s,labelBgBorderRadius:c}):null]})}function Vf({pos:e,x1:t,y1:n,x2:r,y2:i}){return e===Q.Left||e===Q.Right?[.5*(t+r),n]:[t,.5*(n+i)]}function Hf({sourceX:e,sourceY:t,sourcePosition:n=Q.Bottom,targetX:r,targetY:i,targetPosition:a=Q.Top}){let[o,s]=Vf({pos:n,x1:e,y1:t,x2:r,y2:i}),[c,l]=Vf({pos:a,x1:r,y1:i,x2:e,y2:t}),[u,d,f,p]=Bc({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:o,sourceControlY:s,targetControlX:c,targetControlY:l});return[`M${e},${t} C${o},${s} ${c},${l} ${r},${i}`,u,d,f,p]}function Uf(e){return(0,p.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o,targetPosition:s,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:_})=>{let[v,y,b]=Hf({sourceX:n,sourceY:r,sourcePosition:o,targetX:i,targetY:a,targetPosition:s});return(0,X.jsx)(Bf,{id:e.isInternal?void 0:t,path:v,labelX:y,labelY:b,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:_})})}var Wf=Uf({isInternal:!1}),Gf=Uf({isInternal:!0});Wf.displayName=`SimpleBezierEdge`,Gf.displayName=`SimpleBezierEdgeInternal`;function Kf(e){return(0,p.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,sourcePosition:p=Q.Bottom,targetPosition:m=Q.Top,markerEnd:h,markerStart:g,pathOptions:_,interactionWidth:v})=>{let[y,b,x]=nl({sourceX:n,sourceY:r,sourcePosition:p,targetX:i,targetY:a,targetPosition:m,borderRadius:_?.borderRadius,offset:_?.offset,stepPosition:_?.stepPosition});return(0,X.jsx)(Bf,{id:e.isInternal?void 0:t,path:y,labelX:b,labelY:x,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:h,markerStart:g,interactionWidth:v})})}var qf=Kf({isInternal:!1}),Jf=Kf({isInternal:!0});qf.displayName=`SmoothStepEdge`,Jf.displayName=`SmoothStepEdgeInternal`;function Yf(e){return(0,p.memo)(({id:t,...n})=>{let r=e.isInternal?void 0:t;return(0,X.jsx)(qf,{...n,id:r,pathOptions:(0,p.useMemo)(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}var Xf=Yf({isInternal:!1}),Zf=Yf({isInternal:!0});Xf.displayName=`StepEdge`,Zf.displayName=`StepEdgeInternal`;function Qf(e){return(0,p.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:p,markerStart:m,interactionWidth:h})=>{let[g,_,v]=Xc({sourceX:n,sourceY:r,targetX:i,targetY:a});return(0,X.jsx)(Bf,{id:e.isInternal?void 0:t,path:g,labelX:_,labelY:v,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:p,markerStart:m,interactionWidth:h})})}var $f=Qf({isInternal:!1}),ep=Qf({isInternal:!0});$f.displayName=`StraightEdge`,ep.displayName=`StraightEdgeInternal`;function tp(e){return(0,p.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o=Q.Bottom,targetPosition:s=Q.Top,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,pathOptions:_,interactionWidth:v})=>{let[y,b,x]=Uc({sourceX:n,sourceY:r,sourcePosition:o,targetX:i,targetY:a,targetPosition:s,curvature:_?.curvature});return(0,X.jsx)(Bf,{id:e.isInternal?void 0:t,path:y,labelX:b,labelY:x,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:v})})}var np=tp({isInternal:!1}),rp=tp({isInternal:!0});np.displayName=`BezierEdge`,rp.displayName=`BezierEdgeInternal`;var ip={default:rp,straight:ep,step:Zf,smoothstep:Jf,simplebezier:Gf},ap={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},op=(e,t,n)=>n===Q.Left?e-t:n===Q.Right?e+t:e,sp=(e,t,n)=>n===Q.Top?e-t:n===Q.Bottom?e+t:e,cp=`react-flow__edgeupdater`;function lp({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:i,onMouseEnter:a,onMouseOut:o,type:s}){return(0,X.jsx)(`circle`,{onMouseDown:i,onMouseEnter:a,onMouseOut:o,className:Gt([cp,`${cp}-${s}`]),cx:op(t,r,e),cy:sp(n,r,e),r,stroke:`transparent`,fill:`transparent`})}function up({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:r,sourceY:i,targetX:a,targetY:o,sourcePosition:s,targetPosition:c,onReconnect:l,onReconnectStart:u,onReconnectEnd:d,setReconnecting:f,setUpdateHover:p}){let m=Pu(),h=(e,t)=>{if(e.button!==0)return;let{autoPanOnConnect:r,domNode:i,connectionMode:a,connectionRadius:o,lib:s,onConnectStart:c,cancelConnection:p,nodeLookup:h,rfId:g,panBy:_,updateConnection:v}=m.getState(),y=t.type===`target`;Ul.onPointerDown(e.nativeEvent,{autoPanOnConnect:r,connectionMode:a,connectionRadius:o,domNode:i,handleId:t.id,nodeId:t.nodeId,nodeLookup:h,isTarget:y,edgeUpdaterType:t.type,lib:s,flowId:g,cancelConnection:p,panBy:_,isValidConnection:(...e)=>m.getState().isValidConnection?.(...e)??!0,onConnect:e=>l?.(n,e),onConnectStart:(r,i)=>{f(!0),u?.(e,n,t.type),c?.(r,i)},onConnectEnd:(...e)=>m.getState().onConnectEnd?.(...e),onReconnectEnd:(e,r)=>{f(!1),d?.(e,n,t.type,r)},updateConnection:v,getTransform:()=>m.getState().transform,getFromHandle:()=>m.getState().connection.fromHandle,dragThreshold:m.getState().connectionDragThreshold,handleDomNode:e.currentTarget})},g=e=>h(e,{nodeId:n.target,id:n.targetHandle??null,type:`target`}),_=e=>h(e,{nodeId:n.source,id:n.sourceHandle??null,type:`source`}),v=()=>p(!0),y=()=>p(!1);return(0,X.jsxs)(X.Fragment,{children:[(e===!0||e===`source`)&&(0,X.jsx)(lp,{position:s,centerX:r,centerY:i,radius:t,onMouseDown:g,onMouseEnter:v,onMouseOut:y,type:`source`}),(e===!0||e===`target`)&&(0,X.jsx)(lp,{position:c,centerX:a,centerY:o,radius:t,onMouseDown:_,onMouseEnter:v,onMouseOut:y,type:`target`})]})}function dp({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:r,onClick:i,onDoubleClick:a,onContextMenu:o,onMouseEnter:s,onMouseMove:c,onMouseLeave:l,reconnectRadius:u,onReconnect:d,onReconnectStart:f,onReconnectEnd:m,rfId:h,edgeTypes:g,noPanClassName:_,onError:v,disableKeyboardA11y:y}){let b=$(t=>t.edgeLookup.get(e)),x=$(e=>e.defaultEdgeOptions);b=x?{...x,...b}:b;let S=b.type||`default`,C=g?.[S]||ip[S];C===void 0&&(v?.(`011`,js.error011(S)),S=`default`,C=g?.default||ip.default);let w=!!(b.focusable||t&&b.focusable===void 0),T=d!==void 0&&(b.reconnectable||n&&b.reconnectable===void 0),E=!!(b.selectable||r&&b.selectable===void 0),D=(0,p.useRef)(null),[O,k]=(0,p.useState)(!1),[A,j]=(0,p.useState)(!1),M=Pu(),{zIndex:N=b.zIndex,sourceX:P,sourceY:F,targetX:I,targetY:L,sourcePosition:R,targetPosition:z}=$((0,p.useCallback)(t=>{let n=t.nodeLookup.get(b.source),r=t.nodeLookup.get(b.target);if(!n||!r)return ap;let i=il({id:e,sourceNode:n,targetNode:r,sourceHandle:b.sourceHandle||null,targetHandle:b.targetHandle||null,connectionMode:t.connectionMode,onError:v}),a=Gc({selected:b.selected,zIndex:b.zIndex,sourceNode:n,targetNode:r,elevateOnSelect:t.elevateEdgesOnSelect,zIndexMode:t.zIndexMode});return{...i||ap,zIndex:a}},[b.source,b.target,b.sourceHandle,b.targetHandle,b.selected,b.zIndex]),ku),B=(0,p.useMemo)(()=>b.markerStart?`url('#${cl(b.markerStart,h)}')`:void 0,[b.markerStart,h]),V=(0,p.useMemo)(()=>b.markerEnd?`url('#${cl(b.markerEnd,h)}')`:void 0,[b.markerEnd,h]);if(b.hidden||P===null||F===null||I===null||L===null)return null;let H=t=>{let{addSelectedEdges:n,unselectNodesAndEdges:r,multiSelectionActive:a}=M.getState();E&&(M.setState({nodesSelectionActive:!1}),b.selected&&a?(r({nodes:[],edges:[b]}),D.current?.blur()):n([e])),i&&i(t,b)},U=a?e=>{a(e,{...b})}:void 0,W=o?e=>{o(e,{...b})}:void 0,ee=s?e=>{s(e,{...b})}:void 0,te=c?e=>{c(e,{...b})}:void 0,ne=l?e=>{l(e,{...b})}:void 0;return(0,X.jsx)(`svg`,{style:{zIndex:N},children:(0,X.jsxs)(`g`,{className:Gt([`react-flow__edge`,`react-flow__edge-${S}`,b.className,_,{selected:b.selected,animated:b.animated,inactive:!E&&!i,updating:O,selectable:E}]),onClick:H,onDoubleClick:U,onContextMenu:W,onMouseEnter:ee,onMouseMove:te,onMouseLeave:ne,onKeyDown:w?t=>{if(!y&&Ns.includes(t.key)&&E){let{unselectNodesAndEdges:n,addSelectedEdges:r}=M.getState();t.key===`Escape`?(D.current?.blur(),n({edges:[b]})):r([e])}}:void 0,tabIndex:w?0:void 0,role:b.ariaRole??(w?`group`:`img`),"aria-roledescription":`edge`,"data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":b.ariaLabel===null?void 0:b.ariaLabel||`Edge from ${b.source} to ${b.target}`,"aria-describedby":w?`${Ru}-${h}`:void 0,ref:D,...b.domAttributes,children:[!A&&(0,X.jsx)(C,{id:e,source:b.source,target:b.target,type:b.type,selected:b.selected,animated:b.animated,selectable:E,deletable:b.deletable??!0,label:b.label,labelStyle:b.labelStyle,labelShowBg:b.labelShowBg,labelBgStyle:b.labelBgStyle,labelBgPadding:b.labelBgPadding,labelBgBorderRadius:b.labelBgBorderRadius,sourceX:P,sourceY:F,targetX:I,targetY:L,sourcePosition:R,targetPosition:z,data:b.data,style:b.style,sourceHandleId:b.sourceHandle,targetHandleId:b.targetHandle,markerStart:B,markerEnd:V,pathOptions:`pathOptions`in b?b.pathOptions:void 0,interactionWidth:b.interactionWidth}),T&&(0,X.jsx)(up,{edge:b,isReconnectable:T,reconnectRadius:u,onReconnect:d,onReconnectStart:f,onReconnectEnd:m,sourceX:P,sourceY:F,targetX:I,targetY:L,sourcePosition:R,targetPosition:z,setUpdateHover:k,setReconnecting:j})]})})}var fp=(0,p.memo)(dp),pp=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function mp({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:r,noPanClassName:i,onReconnect:a,onEdgeContextMenu:o,onEdgeMouseEnter:s,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,reconnectRadius:d,onEdgeDoubleClick:f,onReconnectStart:p,onReconnectEnd:m,disableKeyboardA11y:h}){let{edgesFocusable:g,edgesReconnectable:_,elementsSelectable:v,onError:y}=$(pp,ku),b=Af(t);return(0,X.jsxs)(`div`,{className:`react-flow__edges`,children:[(0,X.jsx)(Lf,{defaultColor:e,rfId:n}),b.map(e=>(0,X.jsx)(fp,{id:e,edgesFocusable:g,edgesReconnectable:_,elementsSelectable:v,noPanClassName:i,onReconnect:a,onContextMenu:o,onMouseEnter:s,onMouseMove:c,onMouseLeave:l,onClick:u,reconnectRadius:d,onDoubleClick:f,onReconnectStart:p,onReconnectEnd:m,rfId:n,onError:y,edgeTypes:r,disableKeyboardA11y:h},e))]})}mp.displayName=`EdgeRenderer`;var hp=(0,p.memo)(mp),gp=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function _p({children:e}){return(0,X.jsx)(`div`,{className:`react-flow__viewport xyflow__viewport react-flow__container`,style:{transform:$(gp)},children:e})}function vp(e){let t=Md(),n=(0,p.useRef)(!1);(0,p.useEffect)(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}var yp=e=>e.panZoom?.syncViewport;function bp(e){let t=$(yp),n=Pu();return(0,p.useEffect)(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function xp(e){return e.connection.inProgress?{...e.connection,to:vc(e.connection.to,e.transform)}:{...e.connection}}function Sp(e){return e?t=>e(xp(t)):xp}function Cp(e){return $(Sp(e),ku)}var wp=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function Tp({containerStyle:e,style:t,type:n,component:r}){let{nodesConnectable:i,width:a,height:o,isValid:s,inProgress:c}=$(wp,ku);return a&&i&&c?(0,X.jsx)(`svg`,{style:e,width:a,height:o,className:`react-flow__connectionline react-flow__container`,children:(0,X.jsx)(`g`,{className:Gt([`react-flow__connection`,Hs(s)]),children:(0,X.jsx)(Ep,{style:t,type:n,CustomComponent:r,isValid:s})})}):null}var Ep=({style:e,type:t=zs.Bezier,CustomComponent:n,isValid:r})=>{let{inProgress:i,from:a,fromNode:o,fromHandle:s,fromPosition:c,to:l,toNode:u,toHandle:d,toPosition:f,pointer:p}=Cp();if(!i)return;if(n)return(0,X.jsx)(n,{connectionLineType:t,connectionLineStyle:e,fromNode:o,fromHandle:s,fromX:a.x,fromY:a.y,toX:l.x,toY:l.y,fromPosition:c,toPosition:f,connectionStatus:Hs(r),toNode:u,toHandle:d,pointer:p});let m=``,h={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:l.x,targetY:l.y,targetPosition:f};switch(t){case zs.Bezier:[m]=Uc(h);break;case zs.SimpleBezier:[m]=Hf(h);break;case zs.Step:[m]=nl({...h,borderRadius:0});break;case zs.SmoothStep:[m]=nl(h);break;default:[m]=Xc(h)}return(0,X.jsx)(`path`,{d:m,fill:`none`,className:`react-flow__connection-path`,style:e})};Ep.displayName=`ConnectionLine`;var Dp={};function Op(e=Dp){(0,p.useRef)(e),Pu(),(0,p.useEffect)(()=>{},[e])}function kp(){Pu(),(0,p.useRef)(!1),(0,p.useEffect)(()=>{},[])}function Ap({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:a,onEdgeDoubleClick:o,onNodeMouseEnter:s,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,onSelectionContextMenu:d,onSelectionStart:f,onSelectionEnd:p,connectionLineType:m,connectionLineStyle:h,connectionLineComponent:g,connectionLineContainerStyle:_,selectionKeyCode:v,selectionOnDrag:y,selectionMode:b,multiSelectionKeyCode:x,panActivationKeyCode:S,zoomActivationKeyCode:C,deleteKeyCode:w,onlyRenderVisibleElements:T,elementsSelectable:E,defaultViewport:D,translateExtent:O,minZoom:k,maxZoom:A,preventScrolling:j,defaultMarkerColor:M,zoomOnScroll:N,zoomOnPinch:P,panOnScroll:F,panOnScrollSpeed:I,panOnScrollMode:L,zoomOnDoubleClick:R,panOnDrag:z,autoPanOnSelection:B,onPaneClick:V,onPaneMouseEnter:H,onPaneMouseMove:U,onPaneMouseLeave:W,onPaneScroll:ee,onPaneContextMenu:te,paneClickDistance:ne,nodeClickDistance:re,onEdgeContextMenu:ie,onEdgeMouseEnter:ae,onEdgeMouseMove:oe,onEdgeMouseLeave:se,reconnectRadius:G,onReconnect:ce,onReconnectStart:le,onReconnectEnd:K,noDragClassName:ue,noWheelClassName:de,noPanClassName:q,disableKeyboardA11y:fe,nodeExtent:pe,rfId:me,viewport:J,onViewportChange:he}){return Op(e),Op(t),kp(),vp(n),bp(J),(0,X.jsx)(yf,{onPaneClick:V,onPaneMouseEnter:H,onPaneMouseMove:U,onPaneMouseLeave:W,onPaneContextMenu:te,onPaneScroll:ee,paneClickDistance:ne,deleteKeyCode:w,selectionKeyCode:v,selectionOnDrag:y,selectionMode:b,onSelectionStart:f,onSelectionEnd:p,multiSelectionKeyCode:x,panActivationKeyCode:S,zoomActivationKeyCode:C,elementsSelectable:E,zoomOnScroll:N,zoomOnPinch:P,zoomOnDoubleClick:R,panOnScroll:F,panOnScrollSpeed:I,panOnScrollMode:L,panOnDrag:z,autoPanOnSelection:B,defaultViewport:D,translateExtent:O,minZoom:k,maxZoom:A,onSelectionContextMenu:d,preventScrolling:j,noDragClassName:ue,noWheelClassName:de,noPanClassName:q,disableKeyboardA11y:fe,onViewportChange:he,isControlledViewport:!!J,children:(0,X.jsxs)(_p,{children:[(0,X.jsx)(hp,{edgeTypes:t,onEdgeClick:i,onEdgeDoubleClick:o,onReconnect:ce,onReconnectStart:le,onReconnectEnd:K,onlyRenderVisibleElements:T,onEdgeContextMenu:ie,onEdgeMouseEnter:ae,onEdgeMouseMove:oe,onEdgeMouseLeave:se,reconnectRadius:G,defaultMarkerColor:M,noPanClassName:q,disableKeyboardA11y:fe,rfId:me}),(0,X.jsx)(Tp,{style:h,type:m,component:g,containerStyle:_}),(0,X.jsx)(`div`,{className:`react-flow__edgelabel-renderer`}),(0,X.jsx)(kf,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:a,onNodeMouseEnter:s,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,nodeClickDistance:re,onlyRenderVisibleElements:T,noPanClassName:q,noDragClassName:ue,disableKeyboardA11y:fe,nodeExtent:pe,rfId:me}),(0,X.jsx)(`div`,{className:`react-flow__viewport-portal`})]})})}Ap.displayName=`GraphView`;var jp=(0,p.memo)(Ap),Mp=gc(`React Flow`,`https://reactflow.dev/`),Np=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c=.5,maxZoom:l=2,nodeOrigin:u,nodeExtent:d,zIndexMode:f=`basic`}={})=>{let p=new Map,m=new Map,h=new Map,g=new Map,_=r??t??[],v=n??e??[],y=u??[0,0],b=d??Ms;Dl(h,g,_);let{nodesInitialized:x}=vl(v,p,m,{nodeOrigin:y,nodeExtent:b,zIndexMode:f}),S=[0,0,1];if(o&&i&&a){let{x:e,y:t,zoom:n}=Cc(Js(p,{filter:e=>!!((e.width||e.initialWidth)&&(e.height||e.initialHeight))}),i,a,c,l,s?.padding??.1);S=[e,t,n]}return{rfId:`1`,width:i??0,height:a??0,transform:S,nodes:v,nodesInitialized:x,nodeLookup:p,parentLookup:m,edges:_,edgeLookup:g,connectionLookup:h,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:l,translateExtent:Ms,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Fs.Strict,domNode:null,paneDragging:!1,noPanClassName:`nopan`,nodeOrigin:y,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:o??!1,fitViewOptions:s,fitViewResolver:null,connection:{...Rs},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:``,autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Mp,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:`react`,debug:!1,ariaLabelConfig:Ps,zIndexMode:f,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},Pp=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:d,zIndexMode:f})=>Ou((p,m)=>{async function h(){let{nodeLookup:e,panZoom:t,fitViewOptions:n,fitViewResolver:r,width:i,height:a,minZoom:o,maxZoom:s}=m();t&&(await Qs({nodes:e,width:i,height:a,panZoom:t,minZoom:o,maxZoom:s},n),r?.resolve(!0),p({fitViewResolver:null}))}return{...Np({nodes:e,edges:t,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:d,defaultNodes:n,defaultEdges:r,zIndexMode:f}),setNodes:e=>{let{nodeLookup:t,parentLookup:n,nodeOrigin:r,elevateNodesOnSelect:i,fitViewQueued:a,zIndexMode:o,nodesSelectionActive:s}=m(),{nodesInitialized:c,hasSelectedNodes:l}=vl(e,t,n,{nodeOrigin:r,nodeExtent:d,elevateNodesOnSelect:i,checkEquality:!0,zIndexMode:o}),u=s&&l;a&&c?(h(),p({nodes:e,nodesInitialized:c,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:u})):p({nodes:e,nodesInitialized:c,nodesSelectionActive:u})},setEdges:e=>{let{connectionLookup:t,edgeLookup:n}=m();Dl(t,n,e),p({edges:e})},setDefaultNodesAndEdges:(e,t)=>{if(e){let{setNodes:t}=m();t(e),p({hasDefaultNodes:!0})}if(t){let{setEdges:e}=m();e(t),p({hasDefaultEdges:!0})}},updateNodeInternals:e=>{let{triggerNodeChanges:t,nodeLookup:n,parentLookup:r,domNode:i,nodeOrigin:a,nodeExtent:o,debug:s,fitViewQueued:c,zIndexMode:l}=m(),{changes:u,updatedInternals:d}=wl(e,n,r,i,a,o,l);d&&(hl(n,r,{nodeOrigin:a,nodeExtent:o,zIndexMode:l}),c?(h(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),u?.length>0&&(s&&console.log(`React Flow: trigger node changes`,u),t?.(u)))},updateNodePositions:(e,t=!1)=>{let n=[],r=[],{nodeLookup:i,triggerNodeChanges:a,connection:o,updateConnection:s,onNodesChangeMiddlewareMap:c}=m();for(let[a,c]of e){let e=i.get(a),l=!!(e?.expandParent&&e?.parentId&&c?.position),u={id:a,type:`position`,position:l?{x:Math.max(0,c.position.x),y:Math.max(0,c.position.y)}:c.position,dragging:t};if(e&&o.inProgress&&o.fromNode.id===e.id){let t=ol(e,o.fromHandle,Q.Left,!0);s({...o,from:t})}l&&e.parentId&&n.push({id:a,parentId:e.parentId,rect:{...c.internals.positionAbsolute,width:c.measured.width??0,height:c.measured.height??0}}),r.push(u)}if(n.length>0){let{parentLookup:e,nodeOrigin:t}=m(),a=Cl(n,i,e,t);r.push(...a)}for(let e of c.values())r=e(r);a(r)},triggerNodeChanges:e=>{let{onNodesChange:t,setNodes:n,nodes:r,hasDefaultNodes:i,debug:a}=m();e?.length&&(i&&n(md(e,r)),a&&console.log(`React Flow: trigger node changes`,e),t?.(e))},triggerEdgeChanges:e=>{let{onEdgesChange:t,setEdges:n,edges:r,hasDefaultEdges:i,debug:a}=m();e?.length&&(i&&n(hd(e,r)),a&&console.log(`React Flow: trigger edge changes`,e),t?.(e))},addSelectedNodes:e=>{let{multiSelectionActive:t,edgeLookup:n,nodeLookup:r,triggerNodeChanges:i,triggerEdgeChanges:a}=m();if(t){i(e.map(e=>gd(e,!0)));return}i(_d(r,new Set([...e]),!0)),a(_d(n))},addSelectedEdges:e=>{let{multiSelectionActive:t,edgeLookup:n,nodeLookup:r,triggerNodeChanges:i,triggerEdgeChanges:a}=m();if(t){a(e.map(e=>gd(e,!0)));return}a(_d(n,new Set([...e]))),i(_d(r,new Set,!0))},unselectNodesAndEdges:({nodes:e,edges:t}={})=>{let{edges:n,nodes:r,nodeLookup:i,triggerNodeChanges:a,triggerEdgeChanges:o}=m(),s=e||r,c=t||n,l=[];for(let e of s){if(!e.selected)continue;let t=i.get(e.id);t&&(t.selected=!1),l.push(gd(e.id,!1))}let u=[];for(let e of c)e.selected&&u.push(gd(e.id,!1));a(l),o(u)},setMinZoom:e=>{let{panZoom:t,maxZoom:n}=m();t?.setScaleExtent([e,n]),p({minZoom:e})},setMaxZoom:e=>{let{panZoom:t,minZoom:n}=m();t?.setScaleExtent([n,e]),p({maxZoom:e})},setTranslateExtent:e=>{m().panZoom?.setTranslateExtent(e),p({translateExtent:e})},resetSelectedElements:()=>{let{edges:e,nodes:t,triggerNodeChanges:n,triggerEdgeChanges:r,elementsSelectable:i}=m();if(!i)return;let a=t.reduce((e,t)=>t.selected?[...e,gd(t.id,!1)]:e,[]),o=e.reduce((e,t)=>t.selected?[...e,gd(t.id,!1)]:e,[]);n(a),r(o)},setNodeExtent:e=>{let{nodes:t,nodeLookup:n,parentLookup:r,nodeOrigin:i,elevateNodesOnSelect:a,nodeExtent:o,zIndexMode:s}=m();e[0][0]===o[0][0]&&e[0][1]===o[0][1]&&e[1][0]===o[1][0]&&e[1][1]===o[1][1]||(vl(t,n,r,{nodeOrigin:i,nodeExtent:e,elevateNodesOnSelect:a,checkEquality:!1,zIndexMode:s}),p({nodeExtent:e}))},panBy:e=>{let{transform:t,width:n,height:r,panZoom:i,translateExtent:a}=m();return Tl({delta:e,panZoom:i,transform:t,translateExtent:a,width:n,height:r})},setCenter:async(e,t,n)=>{let{width:r,height:i,maxZoom:a,panZoom:o}=m();if(!o)return!1;let s=n?.zoom===void 0?a:n.zoom;return await o.setViewport({x:r/2-e*s,y:i/2-t*s,zoom:s},{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0},cancelConnection:()=>{p({connection:{...Rs}})},updateConnection:e=>{p({connection:e})},reset:()=>p({...Np()})}},Object.is);function Fp({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:r,initialWidth:i,initialHeight:a,initialMinZoom:o,initialMaxZoom:s,initialFitViewOptions:c,fitView:l,nodeOrigin:u,nodeExtent:d,zIndexMode:f,children:m}){let[h]=(0,p.useState)(()=>Pp({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:l,minZoom:o,maxZoom:s,fitViewOptions:c,nodeOrigin:u,nodeExtent:d,zIndexMode:f}));return(0,X.jsx)(Mu,{value:h,children:(0,X.jsx)(kd,{children:(0,X.jsx)(ef,{children:m})})})}function Ip({children:e,nodes:t,edges:n,defaultNodes:r,defaultEdges:i,width:a,height:o,fitView:s,fitViewOptions:c,minZoom:l,maxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:m}){return(0,p.useContext)(ju)?(0,X.jsx)(X.Fragment,{children:e}):(0,X.jsx)(Fp,{initialNodes:t,initialEdges:n,defaultNodes:r,defaultEdges:i,initialWidth:a,initialHeight:o,fitView:s,initialFitViewOptions:c,initialMinZoom:l,initialMaxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:m,children:e})}var Lp={width:`100%`,height:`100%`,overflow:`hidden`,position:`relative`,zIndex:0};function Rp({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:i,nodeTypes:a,edgeTypes:o,onNodeClick:s,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:f,onConnect:m,onConnectStart:h,onConnectEnd:g,onClickConnectStart:_,onClickConnectEnd:v,onNodeMouseEnter:y,onNodeMouseMove:b,onNodeMouseLeave:x,onNodeContextMenu:S,onNodeDoubleClick:C,onNodeDragStart:w,onNodeDrag:T,onNodeDragStop:E,onNodesDelete:D,onEdgesDelete:O,onDelete:k,onSelectionChange:A,onSelectionDragStart:j,onSelectionDrag:M,onSelectionDragStop:N,onSelectionContextMenu:P,onSelectionStart:F,onSelectionEnd:I,onBeforeDelete:L,connectionMode:R,connectionLineType:z=zs.Bezier,connectionLineStyle:B,connectionLineComponent:V,connectionLineContainerStyle:H,deleteKeyCode:U=`Backspace`,selectionKeyCode:W=`Shift`,selectionOnDrag:ee=!1,selectionMode:te=Ls.Full,panActivationKeyCode:ne=`Space`,multiSelectionKeyCode:re=wc()?`Meta`:`Control`,zoomActivationKeyCode:ie=wc()?`Meta`:`Control`,snapToGrid:ae,snapGrid:oe,onlyRenderVisibleElements:se=!1,selectNodesOnDrag:G,nodesDraggable:ce,autoPanOnNodeFocus:le,nodesConnectable:K,nodesFocusable:ue,nodeOrigin:de=$u,edgesFocusable:q,edgesReconnectable:fe,elementsSelectable:pe=!0,defaultViewport:me=ed,minZoom:J=.5,maxZoom:he=2,translateExtent:Y=Ms,preventScrolling:ge=!0,nodeExtent:_e,defaultMarkerColor:ve=`#b1b1b7`,zoomOnScroll:ye=!0,zoomOnPinch:be=!0,panOnScroll:xe=!1,panOnScrollSpeed:Se=.5,panOnScrollMode:Ce=Is.Free,zoomOnDoubleClick:we=!0,panOnDrag:Te=!0,onPaneClick:Ee,onPaneMouseEnter:De,onPaneMouseMove:Oe,onPaneMouseLeave:ke,onPaneScroll:Ae,onPaneContextMenu:je,paneClickDistance:Me=1,nodeClickDistance:Ne=0,children:Z,onReconnect:Pe,onReconnectStart:Fe,onReconnectEnd:Ie,onEdgeContextMenu:Le,onEdgeDoubleClick:Re,onEdgeMouseEnter:ze,onEdgeMouseMove:Be,onEdgeMouseLeave:Ve,reconnectRadius:He=10,onNodesChange:Ue,onEdgesChange:We,noDragClassName:Ge=`nodrag`,noWheelClassName:Ke=`nowheel`,noPanClassName:qe=`nopan`,fitView:Je,fitViewOptions:Ye,connectOnClick:Xe,attributionPosition:Ze,proOptions:Qe,defaultEdgeOptions:$e,elevateNodesOnSelect:et=!0,elevateEdgesOnSelect:tt=!1,disableKeyboardA11y:nt=!1,autoPanOnConnect:rt,autoPanOnNodeDrag:it,autoPanOnSelection:at=!0,autoPanSpeed:ot,connectionRadius:st,isValidConnection:ct,onError:lt,style:ut,id:dt,nodeDragThreshold:ft,connectionDragThreshold:pt,viewport:mt,onViewportChange:ht,width:gt,height:_t,colorMode:vt=`light`,debug:yt,onScroll:bt,ariaLabelConfig:xt,zIndexMode:St=`basic`,...Ct},wt){let Tt=dt||`1`,Et=od(vt),Dt=(0,p.useCallback)(e=>{e.currentTarget.scrollTo({top:0,left:0,behavior:`instant`}),bt?.(e)},[bt]);return(0,X.jsx)(`div`,{"data-testid":`rf__wrapper`,...Ct,onScroll:Dt,style:{...ut,...Lp},ref:wt,className:Gt([`react-flow`,i,Et]),id:dt,role:`application`,children:(0,X.jsxs)(Ip,{nodes:e,edges:t,width:gt,height:_t,fitView:Je,fitViewOptions:Ye,minZoom:J,maxZoom:he,nodeOrigin:de,nodeExtent:_e,zIndexMode:St,children:[(0,X.jsx)(id,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:m,onConnectStart:h,onConnectEnd:g,onClickConnectStart:_,onClickConnectEnd:v,nodesDraggable:ce,autoPanOnNodeFocus:le,nodesConnectable:K,nodesFocusable:ue,edgesFocusable:q,edgesReconnectable:fe,elementsSelectable:pe,elevateNodesOnSelect:et,elevateEdgesOnSelect:tt,minZoom:J,maxZoom:he,nodeExtent:_e,onNodesChange:Ue,onEdgesChange:We,snapToGrid:ae,snapGrid:oe,connectionMode:R,translateExtent:Y,connectOnClick:Xe,defaultEdgeOptions:$e,fitView:Je,fitViewOptions:Ye,onNodesDelete:D,onEdgesDelete:O,onDelete:k,onNodeDragStart:w,onNodeDrag:T,onNodeDragStop:E,onSelectionDrag:M,onSelectionDragStart:j,onSelectionDragStop:N,onMove:u,onMoveStart:d,onMoveEnd:f,noPanClassName:qe,nodeOrigin:de,rfId:Tt,autoPanOnConnect:rt,autoPanOnNodeDrag:it,autoPanSpeed:ot,onError:lt,connectionRadius:st,isValidConnection:ct,selectNodesOnDrag:G,nodeDragThreshold:ft,connectionDragThreshold:pt,onBeforeDelete:L,debug:yt,ariaLabelConfig:xt,zIndexMode:St}),(0,X.jsx)(jp,{onInit:l,onNodeClick:s,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:b,onNodeMouseLeave:x,onNodeContextMenu:S,onNodeDoubleClick:C,nodeTypes:a,edgeTypes:o,connectionLineType:z,connectionLineStyle:B,connectionLineComponent:V,connectionLineContainerStyle:H,selectionKeyCode:W,selectionOnDrag:ee,selectionMode:te,deleteKeyCode:U,multiSelectionKeyCode:re,panActivationKeyCode:ne,zoomActivationKeyCode:ie,onlyRenderVisibleElements:se,defaultViewport:me,translateExtent:Y,minZoom:J,maxZoom:he,preventScrolling:ge,zoomOnScroll:ye,zoomOnPinch:be,zoomOnDoubleClick:we,panOnScroll:xe,panOnScrollSpeed:Se,panOnScrollMode:Ce,panOnDrag:Te,autoPanOnSelection:at,onPaneClick:Ee,onPaneMouseEnter:De,onPaneMouseMove:Oe,onPaneMouseLeave:ke,onPaneScroll:Ae,onPaneContextMenu:je,paneClickDistance:Me,nodeClickDistance:Ne,onSelectionContextMenu:P,onSelectionStart:F,onSelectionEnd:I,onReconnect:Pe,onReconnectStart:Fe,onReconnectEnd:Ie,onEdgeContextMenu:Le,onEdgeDoubleClick:Re,onEdgeMouseEnter:ze,onEdgeMouseMove:Be,onEdgeMouseLeave:Ve,reconnectRadius:He,defaultMarkerColor:ve,noDragClassName:Ge,noWheelClassName:Ke,noPanClassName:qe,rfId:Tt,disableKeyboardA11y:nt,nodeExtent:_e,viewport:mt,onViewportChange:ht}),(0,X.jsx)(Qu,{onSelectionChange:A}),Z,(0,X.jsx)(Ku,{proOptions:Qe,position:Ze}),(0,X.jsx)(Uu,{rfId:Tt,disableKeyboardA11y:nt})]})})}var zp=wd(Rp);function Bp(e){let[t,n]=(0,p.useState)(e);return[t,n,(0,p.useCallback)(e=>n(t=>md(e,t)),[])]}function Vp(e){let[t,n]=(0,p.useState)(e);return[t,n,(0,p.useCallback)(e=>n(t=>hd(e,t)),[])]}js.error014();function Hp({dimensions:e,lineWidth:t,variant:n,className:r}){return(0,X.jsx)(`path`,{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Gt([`react-flow__background-pattern`,n,r])})}function Up({radius:e,className:t}){return(0,X.jsx)(`circle`,{cx:e,cy:e,r:e,className:Gt([`react-flow__background-pattern`,`dots`,t])})}var Wp;(function(e){e.Lines=`lines`,e.Dots=`dots`,e.Cross=`cross`})(Wp||={});var Gp={[Wp.Dots]:1,[Wp.Lines]:1,[Wp.Cross]:6},Kp=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qp({id:e,variant:t=Wp.Dots,gap:n=20,size:r,lineWidth:i=1,offset:a=0,color:o,bgColor:s,style:c,className:l,patternClassName:u}){let d=(0,p.useRef)(null),{transform:f,patternId:m}=$(Kp,ku),h=r||Gp[t],g=t===Wp.Dots,_=t===Wp.Cross,v=Array.isArray(n)?n:[n,n],y=[v[0]*f[2]||1,v[1]*f[2]||1],b=h*f[2],x=Array.isArray(a)?a:[a,a],S=_?[b,b]:y,C=[x[0]*f[2]||1+S[0]/2,x[1]*f[2]||1+S[1]/2],w=`${m}${e||``}`;return(0,X.jsxs)(`svg`,{className:Gt([`react-flow__background`,l]),style:{...c,...Ld,"--xy-background-color-props":s,"--xy-background-pattern-color-props":o},ref:d,"data-testid":`rf__background`,children:[(0,X.jsx)(`pattern`,{id:w,x:f[0]%y[0],y:f[1]%y[1],width:y[0],height:y[1],patternUnits:`userSpaceOnUse`,patternTransform:`translate(-${C[0]},-${C[1]})`,children:g?(0,X.jsx)(Up,{radius:b/2,className:u}):(0,X.jsx)(Hp,{dimensions:S,lineWidth:i,variant:t,className:u})}),(0,X.jsx)(`rect`,{x:`0`,y:`0`,width:`100%`,height:`100%`,fill:`url(#${w})`})]})}qp.displayName=`Background`;var Jp=(0,p.memo)(qp);function Yp(){return(0,X.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 32`,children:(0,X.jsx)(`path`,{d:`M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z`})})}function Xp(){return(0,X.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 5`,children:(0,X.jsx)(`path`,{d:`M0 0h32v4.2H0z`})})}function Zp(){return(0,X.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 30`,children:(0,X.jsx)(`path`,{d:`M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z`})})}function Qp(){return(0,X.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 25 32`,children:(0,X.jsx)(`path`,{d:`M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z`})})}function $p(){return(0,X.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 25 32`,children:(0,X.jsx)(`path`,{d:`M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z`})})}function em({children:e,className:t,...n}){return(0,X.jsx)(`button`,{type:`button`,className:Gt([`react-flow__controls-button`,t]),...n,children:e})}var tm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function nm({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:a,onZoomOut:o,onFitView:s,onInteractiveChange:c,className:l,children:u,position:d=`bottom-left`,orientation:f=`vertical`,"aria-label":p}){let m=Pu(),{isInteractive:h,minZoomReached:g,maxZoomReached:_,ariaLabelConfig:v}=$(tm,ku),{zoomIn:y,zoomOut:b,fitView:x}=Md();return(0,X.jsxs)(Wu,{className:Gt([`react-flow__controls`,f===`horizontal`?`horizontal`:`vertical`,l]),position:d,style:e,"data-testid":`rf__controls`,"aria-label":p??v[`controls.ariaLabel`],children:[t&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(em,{onClick:()=>{y(),a?.()},className:`react-flow__controls-zoomin`,title:v[`controls.zoomIn.ariaLabel`],"aria-label":v[`controls.zoomIn.ariaLabel`],disabled:_,children:(0,X.jsx)(Yp,{})}),(0,X.jsx)(em,{onClick:()=>{b(),o?.()},className:`react-flow__controls-zoomout`,title:v[`controls.zoomOut.ariaLabel`],"aria-label":v[`controls.zoomOut.ariaLabel`],disabled:g,children:(0,X.jsx)(Xp,{})})]}),n&&(0,X.jsx)(em,{className:`react-flow__controls-fitview`,onClick:()=>{x(i),s?.()},title:v[`controls.fitView.ariaLabel`],"aria-label":v[`controls.fitView.ariaLabel`],children:(0,X.jsx)(Zp,{})}),r&&(0,X.jsx)(em,{className:`react-flow__controls-interactive`,onClick:()=>{m.setState({nodesDraggable:!h,nodesConnectable:!h,elementsSelectable:!h}),c?.(!h)},title:v[`controls.interactive.ariaLabel`],"aria-label":v[`controls.interactive.ariaLabel`],children:h?(0,X.jsx)($p,{}):(0,X.jsx)(Qp,{})}),u]})}nm.displayName=`Controls`;var rm=(0,p.memo)(nm);function im({id:e,x:t,y:n,width:r,height:i,style:a,color:o,strokeColor:s,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,selected:f,onClick:p}){let{background:m,backgroundColor:h}=a||{},g=o||m||h;return(0,X.jsx)(`rect`,{className:Gt([`react-flow__minimap-node`,{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:i,style:{fill:g,stroke:s,strokeWidth:c},shapeRendering:d,onClick:p?t=>p(t,e):void 0})}var am=(0,p.memo)(im),om=e=>e.nodes.map(e=>e.id),sm=e=>e instanceof Function?e:()=>e;function cm({nodeStrokeColor:e,nodeColor:t,nodeClassName:n=``,nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:a=am,onClick:o}){let s=$(om,ku),c=sm(t),l=sm(e),u=sm(n),d=typeof window>`u`||window.chrome?`crispEdges`:`geometricPrecision`;return(0,X.jsx)(X.Fragment,{children:s.map(e=>(0,X.jsx)(um,{id:e,nodeColorFunc:c,nodeStrokeColorFunc:l,nodeClassNameFunc:u,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:a,onClick:o,shapeRendering:d},e))})}function lm({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:a,shapeRendering:o,NodeComponent:s,onClick:c}){let{node:l,x:u,y:d,width:f,height:p}=$(t=>{let n=t.nodeLookup.get(e);if(!n)return{node:void 0,x:0,y:0,width:0,height:0};let r=n.internals.userNode,{x:i,y:a}=n.internals.positionAbsolute,{width:o,height:s}=Ec(r);return{node:r,x:i,y:a,width:o,height:s}},ku);return!l||l.hidden||!Dc(l)?null:(0,X.jsx)(s,{x:u,y:d,width:f,height:p,style:l.style,selected:!!l.selected,className:r(l),color:t(l),borderRadius:i,strokeColor:n(l),strokeWidth:a,shapeRendering:o,onClick:c,id:l.id})}var um=(0,p.memo)(lm),dm=(0,p.memo)(cm),fm=200,pm=150,mm=e=>!e.hidden,hm=e=>{let t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?dc(Js(e.nodeLookup,{filter:mm}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},gm=`react-flow__minimap-desc`;function _m({style:e,className:t,nodeStrokeColor:n,nodeColor:r,nodeClassName:i=``,nodeBorderRadius:a=5,nodeStrokeWidth:o,nodeComponent:s,bgColor:c,maskColor:l,maskStrokeColor:u,maskStrokeWidth:d,position:f=`bottom-right`,onClick:m,onNodeClick:h,pannable:g=!1,zoomable:_=!1,ariaLabel:v,inversePan:y,zoomStep:b=1,offsetScale:x=5}){let S=Pu(),C=(0,p.useRef)(null),{boundingRect:w,viewBB:T,rfId:E,panZoom:D,translateExtent:O,flowWidth:k,flowHeight:A,ariaLabelConfig:j}=$(hm,ku),M=e?.width??fm,N=e?.height??pm,P=w.width/M,F=w.height/N,I=Math.max(P,F),L=I*M,R=I*N,z=x*I,B=w.x-(L-w.width)/2-z,V=w.y-(R-w.height)/2-z,H=L+z*2,U=R+z*2,W=`${gm}-${E}`,ee=(0,p.useRef)(0),te=(0,p.useRef)();ee.current=I,(0,p.useEffect)(()=>{if(C.current&&D)return te.current=Wl({domNode:C.current,panZoom:D,getTransform:()=>S.getState().transform,getViewScale:()=>ee.current}),()=>{te.current?.destroy()}},[D]),(0,p.useEffect)(()=>{te.current?.update({translateExtent:O,width:k,height:A,inversePan:y,pannable:g,zoomStep:b,zoomable:_})},[g,_,y,b,O,k,A]);let ne=m?e=>{let[t,n]=te.current?.pointer(e)||[0,0];m(e,{x:t,y:n})}:void 0,re=h?(0,p.useCallback)((e,t)=>{let n=S.getState().nodeLookup.get(t).internals.userNode;h(e,n)},[]):void 0,ie=v??j[`minimap.ariaLabel`];return(0,X.jsx)(Wu,{position:f,style:{...e,"--xy-minimap-background-color-props":typeof c==`string`?c:void 0,"--xy-minimap-mask-background-color-props":typeof l==`string`?l:void 0,"--xy-minimap-mask-stroke-color-props":typeof u==`string`?u:void 0,"--xy-minimap-mask-stroke-width-props":typeof d==`number`?d*I:void 0,"--xy-minimap-node-background-color-props":typeof r==`string`?r:void 0,"--xy-minimap-node-stroke-color-props":typeof n==`string`?n:void 0,"--xy-minimap-node-stroke-width-props":typeof o==`number`?o:void 0},className:Gt([`react-flow__minimap`,t]),"data-testid":`rf__minimap`,children:(0,X.jsxs)(`svg`,{width:M,height:N,viewBox:`${B} ${V} ${H} ${U}`,className:`react-flow__minimap-svg`,role:`img`,"aria-labelledby":W,ref:C,onClick:ne,children:[ie&&(0,X.jsx)(`title`,{id:W,children:ie}),(0,X.jsx)(dm,{onClick:re,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:i,nodeStrokeWidth:o,nodeComponent:s}),(0,X.jsx)(`path`,{className:`react-flow__minimap-mask`,d:`M${B-z},${V-z}h${H+z*2}v${U+z*2}h${-H-z*2}z
11
+ M${T.x},${T.y}h${T.width}v${T.height}h${-T.width}z`,fillRule:`evenodd`,pointerEvents:`none`})]})})}_m.displayName=`MiniMap`;var vm=(0,p.memo)(_m),ym=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,bm={[au.Line]:`right`,[au.Handle]:`bottom-right`};function xm({nodeId:e,position:t,variant:n=au.Handle,className:r,style:i=void 0,children:a,color:o,minWidth:s=10,minHeight:c=10,maxWidth:l=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:d=!1,resizeDirection:f,autoScale:m=!0,shouldResize:h,onResizeStart:g,onResize:_,onResizeEnd:v}){let y=Zd(),b=typeof e==`string`?e:y,x=Pu(),S=(0,p.useRef)(null),C=n===au.Handle,w=$((0,p.useCallback)(ym(C&&m),[C,m]),ku),T=(0,p.useRef)(null),E=t??bm[n];return(0,p.useEffect)(()=>{if(!(!S.current||!b))return T.current||=gu({domNode:S.current,nodeId:b,getStoreItems:()=>{let{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,domNode:a}=x.getState();return{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,paneDomNode:a}},onChange:(e,t)=>{let{triggerNodeChanges:n,nodeLookup:r,parentLookup:i,nodeOrigin:a}=x.getState(),o=[],s={x:e.x,y:e.y},c=r.get(b);if(c&&c.expandParent&&c.parentId){let t=c.origin??a,n=e.width??c.measured.width??0,l=e.height??c.measured.height??0,u=Cl([{id:c.id,parentId:c.parentId,rect:{width:n,height:l,...Oc({x:e.x??c.position.x,y:e.y??c.position.y},{width:n,height:l},c.parentId,r,t)}}],r,i,a);o.push(...u),s.x=e.x?Math.max(t[0]*n,e.x):void 0,s.y=e.y?Math.max(t[1]*l,e.y):void 0}if(s.x!==void 0&&s.y!==void 0){let e={id:b,type:`position`,position:{...s}};o.push(e)}if(e.width!==void 0&&e.height!==void 0){let t={id:b,type:`dimensions`,resizing:!0,setAttributes:f?f===`horizontal`?`width`:`height`:!0,dimensions:{width:e.width,height:e.height}};o.push(t)}for(let e of t){let t={...e,type:`position`};o.push(t)}n(o)},onEnd:({width:e,height:t})=>{let n={id:b,type:`dimensions`,resizing:!1,dimensions:{width:e,height:t}};x.getState().triggerNodeChanges([n])}}),T.current.update({controlPosition:E,boundaries:{minWidth:s,minHeight:c,maxWidth:l,maxHeight:u},keepAspectRatio:d,resizeDirection:f,onResizeStart:g,onResize:_,onResizeEnd:v,shouldResize:h}),()=>{T.current?.destroy()}},[E,s,c,l,u,d,g,_,v,h]),(0,X.jsx)(`div`,{className:Gt([`react-flow__resize-control`,`nodrag`,...E.split(`-`),n,r]),ref:S,style:{...i,scale:w,...o&&{[C?`backgroundColor`:`borderColor`]:o}},children:a})}(0,p.memo)(xm);var Sm=`lineage.preferences.hover-previews`;function Cm(e){try{return(e||window.localStorage).getItem(Sm)!==`false`}catch{return!0}}function wm(e,t){try{return(t||window.localStorage).setItem(Sm,String(e)),!0}catch{return!1}}function Tm(e,t,n){let r=Math.min(420,Math.max(240,t-32)),i=Math.min(440,Math.max(220,n-32)),a=e.right+16+r<=t-16?e.right+16:Math.max(16,e.left-16-r),o=(e.top+e.bottom)/2-i/2,s=Math.min(Math.max(16,o),Math.max(16,n-i-16));return{left:Math.round(a),top:Math.round(s)}}function Em({data:e}){let t=ve({hasLocal:!!e.local_path,hasS3:!!e.s3_key}),n=Dm(e.lineage_tasks),r=e.replayState,i=e.replayInteractive!==!1,a=()=>{e.onPreviewDismiss?.(),(e.attempt_count||1)>1?e.onOpenHistory?.(e.asset_id):e.onOpenDetail?.(e.asset_id)},o=(t,n)=>{e.onPreviewChange?.(t,e.asset_id,Tm(n.getBoundingClientRect(),window.innerWidth,window.innerHeight))};return(0,X.jsxs)(`div`,{"aria-label":`${e.title} ${(e.attempt_count||1)>1?`attempt history`:`details`}`,"aria-hidden":r===`future`?!0:void 0,className:`lineage-node ${e.root?`root-node`:``} ${e.active?`active`:``} ${e.user_selected?`selected`:``} ${e.is_latest?`latest`:``} focus-${e.focusRole} ${r?`lineage-node-replay-${r}`:``}`,"data-focus-role":e.focusRole,"data-lineage-root":e.root?`true`:void 0,onBlur:e.hoverPreviewsEnabled?()=>e.onPreviewChange?.(`focus`,e.asset_id,null):void 0,onDoubleClick:e=>{e.stopPropagation(),a()},onFocus:e.hoverPreviewsEnabled?e=>o(`focus`,e.currentTarget):void 0,onKeyDown:t=>{let n=t.key.toLowerCase();if(!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey&&n===`b`){t.preventDefault(),t.stopPropagation(),e.onToggleBranch?.(e);return}if(!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey&&n===`r`){t.preventDefault(),t.stopPropagation(),e.onToggleReroll?.(e);return}if(!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey&&n===`d`){t.preventDefault(),t.stopPropagation(),e.onPreviewDismiss?.(),e.onOpenDetail?.(e.asset_id);return}t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),t.stopPropagation(),a())},onMouseEnter:e.hoverPreviewsEnabled?e=>o(`hover`,e.currentTarget):void 0,onMouseLeave:e.hoverPreviewsEnabled?()=>e.onPreviewChange?.(`hover`,e.asset_id,null):void 0,role:`button`,tabIndex:i?0:-1,title:e.hoverPreviewsEnabled?(e.attempt_count||1)>1?`Hover to preview; double-click to open attempt history; drag to reposition`:`Hover to preview; double-click to open detail; drag to reposition`:(e.attempt_count||1)>1?`Double-click to open attempt history; drag to reposition`:`Double-click to open detail; drag to reposition`,children:[(0,X.jsx)(of,{className:`lineage-handle`,isConnectable:!1,position:e.targetPosition,type:`target`}),(0,X.jsx)(of,{className:`lineage-handle`,isConnectable:!1,position:e.sourcePosition,type:`source`}),(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`lineage-node-action`,children:`Details`}),(0,X.jsx)(`div`,{className:`lineage-thumb`,children:e.preview_url&&(e.media_type===`image`||e.media_type===`gif`)?(0,X.jsx)(`img`,{src:e.preview_url,alt:``,loading:`lazy`}):e.preview_url&&e.media_type===`video`?(0,X.jsx)(`video`,{src:e.preview_url,muted:!0,preload:`metadata`}):(0,X.jsx)(`span`,{children:e.media_type})}),(0,X.jsx)(`strong`,{children:e.title}),(0,X.jsx)(`small`,{children:e.asset_id}),(0,X.jsxs)(`div`,{className:`lineage-badges`,children:[(0,X.jsx)(`span`,{className:t.kind,children:t.label}),(0,X.jsx)(`span`,{children:e.review_state}),e.root&&(0,X.jsx)(`span`,{className:`root`,children:`root`}),e.is_latest&&(0,X.jsx)(`span`,{className:`latest`,children:`latest`}),e.user_selected&&(0,X.jsx)(`span`,{className:`selected`,children:`next variation`}),(e.attempt_count||1)>1&&(0,X.jsxs)(`span`,{className:`attempt-stack`,children:[`v`,e.attempt_count]}),n.map(e=>(0,X.jsxs)(`span`,{className:`lineage-task-badge ${e.task_type} ${e.status===`pending`?`pending`:`locked`}`,children:[e.task_type,` `,e.status===`pending`?`pending`:`locked`]},e.id)),e.reroll_request?.status===`pending`&&!e.lineage_tasks?.reroll&&(0,X.jsx)(`span`,{className:`reroll`,children:`re-roll`})]}),(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`lineage-node-hint`,children:e.hoverPreviewsEnabled?`Hover to preview`:`Double-click for details`})]})}function Dm(e){return[`iterate`,`reroll`].map(t=>e?.[t]).filter(e=>!!(e&&[`pending`,`claimed`,`in_progress`].includes(e.status)))}function Om(e,t){let n=km(e.lineage_tasks?.iterate),r=km(e.lineage_tasks?.reroll),i=e.reroll_request?.status===`pending`;return{branchDisabled:n||!e.user_selected&&t,branchLocked:n,branchTitle:n?`An agent is working on this branch task. Manage it in the task queue.`:!e.user_selected&&t?`The branch selection is full.`:e.user_selected?`Remove from the next branch (B)`:`Use as a base for the next branch (B)`,rerollDisabled:r,rerollLocked:r,rerollSelected:i,rerollTitle:r?`An agent is working on this re-roll. Manage it in the task queue.`:i?`Remove from the re-roll queue (R)`:`Add to the re-roll queue (R)`}}function km(e){return e?.status===`claimed`||e?.status===`in_progress`}var Am={assetNode:Em},jm={activeSource:null,focus:null,hover:null};function Mm(e,t){return t===`downloading`?{action:`none`,description:`Fetching and verifying the 14 rich demo images.`,title:`Downloading rich demo media`}:t===`seeding`?{action:`none`,description:`Creating the rich demo workspace without starting a second index.`,title:`Creating rich demo workspace`}:t===`indexing`?{action:`none`,description:`Loading the automatic 14-node index. No manual action is needed.`,title:`Indexing rich demo images`}:t===`error`?{action:e?`retry-index`:`seed`,description:`The automatic setup stopped. Review the error message, then retry.`,title:`Rich demo setup failed`}:e?{action:`index`,description:`Index local/catalog assets to inspect this tree.`,title:`No lineage index yet`}:{action:`new`,description:`Search local and catalog assets, choose a root, and name the iteration tree.`,title:`Start a lineage`}}function Nm({flowEdges:e,flowNodes:t,graphKey:n,hoverPreviewsEnabled:r,loading:i,onSeedDemo:a,onEdgesChange:o,onEdgeEdit:s,onIndexNow:c,onNewLineage:l,onClearFocus:u,onNodeActionMenu:d,onNodeInspect:f,onNodeOpenDetail:m,onNodeOpenHistory:h,onNodePosition:g,onNodesChange:_,onReady:v,onSelectedAsset:y,onToggleBranch:b,onToggleReroll:x,onViewportInteraction:S,replayInteractive:C,selectionFull:w,workspaceProgress:T,workspaceRootAssetId:E}){let[D,O]=(0,p.useState)(jm),[k,A]=(0,p.useState)(null),j=(0,p.useRef)(!1),M=(0,p.useRef)(null),N=(0,p.useCallback)(()=>{M.current!==null&&(window.clearTimeout(M.current),M.current=null)},[]),P=(0,p.useCallback)(()=>{N(),O(jm)},[N]),F=(0,p.useCallback)(e=>{N(),M.current=window.setTimeout(()=>{M.current=null,e()},180)},[N]),I=(0,p.useCallback)((e,t,n)=>{let r=()=>O(r=>{if(n)return{...r,activeSource:e,[e]:{assetId:t,position:n}};if(r[e]?.assetId!==t)return r;let i={...r,[e]:null},a=e===`hover`?`focus`:`hover`;return{...i,activeSource:r.activeSource===e?i[a]?a:null:r.activeSource}});if(n){N(),r();return}F(r)},[N,F]);(0,p.useEffect)(()=>P(),[P,n]),(0,p.useEffect)(()=>{r||P()},[P,r]),(0,p.useEffect)(()=>()=>N(),[N]);let L=(0,p.useCallback)(e=>{P(),m(e)},[P,m]),R=(0,p.useCallback)(e=>{P(),h(e)},[P,h]),z=(0,p.useCallback)((e,t,n)=>{P(),d(e,t,n)},[P,d]),B=(0,p.useCallback)(async(e,t)=>{let n=`${e}:${t.asset_id}`;if(!j.current){j.current=!0,A(n);try{e===`branch`?await b(t):await x(t)}finally{j.current=!1,A(null)}}},[b,x]),V=(0,p.useMemo)(()=>t.map(e=>({...e,data:{...e.data,hoverPreviewsEnabled:r,onOpenDetail:L,onOpenHistory:R,onPreviewChange:r?I:void 0,onPreviewDismiss:P,onToggleBranch:e=>{Om(e,w).branchDisabled||B(`branch`,e)},onToggleReroll:e=>{Om(e,w).rerollDisabled||B(`reroll`,e)}}})),[I,P,t,r,L,R,B,w]);if(!t.length){let e=Mm(E,T);return(0,X.jsxs)(`div`,{className:`lineage-empty-state`,"data-lineage-state":T||(E?`empty`:`new`),children:[(0,X.jsx)(`strong`,{children:e.title}),(0,X.jsx)(`p`,{children:e.description}),(e.action===`index`||e.action===`retry-index`)&&(0,X.jsx)(`button`,{className:`primary-button`,disabled:i,onClick:c,children:e.action===`retry-index`?`Retry index`:`Index now`}),e.action===`new`&&(0,X.jsxs)(`div`,{className:`lineage-empty-actions`,children:[(0,X.jsx)(`button`,{className:`primary-button`,onClick:l,children:`New lineage`}),(0,X.jsx)(`button`,{className:`secondary-button`,disabled:i,onClick:a,children:`Load demo lineage`})]}),e.action===`seed`&&(0,X.jsx)(`button`,{className:`primary-button`,disabled:i,onClick:a,children:`Load demo lineage`})]})}let H=r&&D.activeSource?D[D.activeSource]:null,U=H?t.find(e=>e.id===H.assetId)?.data:void 0,W=U?Om(U,w):null;return(0,X.jsxs)(X.Fragment,{children:[H&&U&&W&&(0,Au.createPortal)((0,X.jsxs)(`section`,{"aria-label":`Quick actions for ${U.title}`,className:`lineage-hover-preview`,"data-testid":`lineage-hover-preview`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||F(P)},onKeyDown:e=>{let t=e.key.toLowerCase();e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||(t===`b`&&!W.branchDisabled&&(e.preventDefault(),B(`branch`,U)),t===`r`&&!W.rerollDisabled&&(e.preventDefault(),B(`reroll`,U)),t===`d`&&(e.preventDefault(),L(U.asset_id)))},onMouseEnter:N,onMouseLeave:e=>{D.activeSource===`hover`&&!e.currentTarget.contains(document.activeElement)&&I(`hover`,U.asset_id,null)},style:{left:H.position.left,top:H.position.top},children:[(0,X.jsx)(`div`,{className:`lineage-hover-preview-media`,children:U.preview_url&&(U.media_type===`image`||U.media_type===`gif`)?(0,X.jsx)(`img`,{alt:``,src:U.preview_url}):U.preview_url&&U.media_type===`video`?(0,X.jsx)(`video`,{autoPlay:!0,loop:!0,muted:!0,playsInline:!0,preload:`metadata`,src:U.preview_url}):(0,X.jsxs)(`span`,{children:[U.media_type,` preview unavailable`]})}),(0,X.jsxs)(`div`,{className:`lineage-hover-preview-copy`,children:[(0,X.jsx)(`strong`,{children:U.title}),(0,X.jsx)(`code`,{children:U.asset_id})]}),(0,X.jsxs)(`div`,{className:`lineage-hover-preview-actions`,children:[(0,X.jsxs)(`button`,{"aria-keyshortcuts":`B`,"aria-pressed":U.user_selected,className:U.user_selected?`selected`:``,disabled:W.branchDisabled||!!k,onClick:()=>void B(`branch`,U),title:W.branchTitle,type:`button`,children:[(0,X.jsx)(`kbd`,{children:`B`}),(0,X.jsx)(`span`,{children:U.user_selected?`Branch queued`:`Branch`})]}),(0,X.jsxs)(`button`,{"aria-keyshortcuts":`R`,"aria-pressed":W.rerollSelected,className:`reroll ${W.rerollSelected?`selected`:``}`,disabled:W.rerollDisabled||!!k,onClick:()=>void B(`reroll`,U),title:W.rerollTitle,type:`button`,children:[(0,X.jsx)(`kbd`,{children:`R`}),(0,X.jsx)(`span`,{children:W.rerollSelected?`Re-roll queued`:`Re-roll`})]}),(0,X.jsxs)(`button`,{"aria-keyshortcuts":`D`,onClick:()=>L(U.asset_id),type:`button`,children:[(0,X.jsx)(`kbd`,{children:`D`}),(0,X.jsx)(`span`,{children:`Details`})]})]}),(W.branchLocked||W.rerollLocked)&&(0,X.jsx)(`p`,{className:`lineage-hover-preview-lock`,children:`Active work is managed in the task queue.`})]}),document.body),(0,X.jsxs)(zp,{defaultViewport:{x:80,y:120,zoom:.82},edges:e,nodes:V,nodeTypes:Am,deleteKeyCode:null,edgesFocusable:C,elementsSelectable:C,minZoom:.3,nodesDraggable:C,nodesFocusable:!1,onEdgeDoubleClick:(e,t)=>{e.preventDefault(),C&&(P(),s(t.id,e.currentTarget))},onEdgesChange:o,onKeyDownCapture:t=>{if(!C||t.key!==`Enter`&&t.key!==` `)return;let n=t.target instanceof Element?t.target.closest(`.react-flow__edge`):null,r=n?.dataset.id;!r||!e.some(e=>e.id===r)||(t.preventDefault(),t.stopPropagation(),P(),s(r,n))},onNodeClick:(e,t)=>{d(``,0,0),f(t.id),y(t.id)},onNodeContextMenu:(e,t)=>{e.preventDefault(),f(t.id),z(t.id,e.clientX,e.clientY),y(t.id)},onNodeDoubleClick:(e,t)=>{P(),f(t.id),(t.data.attempt_count||1)>1?h(t.id):m(t.id),y(t.id)},onNodeDragStart:P,onNodeDragStop:(e,t)=>g(t),onNodesChange:_,onInit:v,onMoveStart:()=>{P(),S()},onPaneClick:u,children:[(0,X.jsx)(Jp,{}),(0,X.jsx)(rm,{}),(0,X.jsx)(vm,{pannable:!0,zoomable:!0})]},n)]})}function Pm({node:e,claims:t=[],onClearAllNext:n,onClearReroll:r,onClaimControl:i,canRemoveFromLineage:a,onClearNext:o,onClose:s,onOpenDetail:c,onRemoveFromLineage:l,onReplaceNext:u,onReview:d,onSelectNext:f,onMarkReroll:p,position:m,selectedCount:h,selectionFull:g}){function _(e){e(),s()}return(0,X.jsxs)(`div`,{className:`lineage-context-menu`,role:`menu`,style:{left:m.x,top:m.y},children:[(0,X.jsx)(`strong`,{children:e.title}),(0,X.jsx)(`button`,{disabled:!e.user_selected&&g,onClick:()=>_(e.user_selected?o:f),role:`menuitem`,children:e.user_selected?`Remove from next variation`:g?`Selection full`:`Use for next variation`}),!e.user_selected&&h>0&&(0,X.jsx)(`button`,{className:`selection-replace`,onClick:()=>_(u),role:`menuitem`,children:`Replace selection`}),e.user_selected&&h>1&&(0,X.jsx)(`button`,{className:`selection-replace`,onClick:()=>_(u),role:`menuitem`,children:`Use only this for next variation`}),h>0&&(0,X.jsx)(`button`,{onClick:()=>_(n),role:`menuitem`,children:`Clear all next variation`}),e.user_selected&&!e.is_latest&&(0,X.jsx)(`p`,{role:`status`,children:`Selected but not latest. Good for branching from an earlier idea.`}),e.reroll_request?.status===`pending`?(0,X.jsx)(`button`,{className:`reroll-action`,onClick:()=>_(r),role:`menuitem`,children:`Clear re-roll request`}):(0,X.jsx)(`button`,{className:`reroll-action`,onClick:()=>_(p),role:`menuitem`,children:`Mark for re-roll`}),t.length>0&&(0,X.jsxs)(`div`,{className:`lineage-context-claims`,role:`group`,"aria-label":`Agent claim controls`,children:[(0,X.jsx)(`span`,{children:Fm(t)}),t.length===1&&i&&(0,X.jsxs)(`div`,{children:[t[0].derived_state===`stale`&&(0,X.jsx)(`button`,{onClick:()=>Im(`release-stale`,t[0],i),role:`menuitem`,children:`Release stale claim`}),(0,X.jsx)(`button`,{onClick:()=>Im(`transfer`,t[0],i),role:`menuitem`,children:`Transfer claim`}),(0,X.jsx)(`button`,{onClick:()=>Im(`revoke`,t[0],i),role:`menuitem`,children:`Revoke claim`})]})]}),(0,X.jsx)(`button`,{onClick:()=>_(c),role:`menuitem`,children:`Open detail`}),(0,X.jsx)(`button`,{className:`danger`,disabled:!a,onClick:()=>_(l),role:`menuitem`,children:a?`Remove from lineage`:`Root cannot be removed`}),(0,X.jsx)(`button`,{onClick:()=>_(()=>d(`approved`)),role:`menuitem`,children:`Approve`}),(0,X.jsx)(`button`,{onClick:()=>_(()=>d(`needs_revision`)),role:`menuitem`,children:`Needs revision`}),(0,X.jsx)(`button`,{onClick:()=>_(()=>d(`rejected`)),role:`menuitem`,children:`Reject`}),(0,X.jsx)(`button`,{onClick:()=>_(()=>d(`ignored`)),role:`menuitem`,children:`Ignore`})]})}function Fm(e){if(e.length!==1)return`${e.length} active claims on this lineage`;let t=e[0];return`${t.derived_state===`stale`?`Stale claim`:t.derived_state===`idle`?`Idle claim`:`Claimed`} by ${t.agent_name}`}function Im(e,t,n){let r=Lm(e,t);r&&n(e,t,r)}function Lm(e,t){if(e===`release-stale`)return window.confirm(`Release stale claim held by ${t.agent_name}?`)?{confirmWrite:!0,reason:`Released stale ${t.scope_type} claim ${t.id} from the lineage context menu.`}:null;if(e===`revoke`){let e=window.prompt(`Reason for revoking ${t.agent_name}'s claim?`);return!e?.trim()||!window.confirm(`Revoke claim ${t.id} from ${t.agent_name}?`)?null:{confirmWrite:!0,reason:e.trim()}}let n=window.prompt(`Transfer claim ${t.id} to which agent?`);return!n?.trim()||!window.confirm(`Transfer claim ${t.id} from ${t.agent_name} to ${n.trim()}?`)?null:{confirmWrite:!0,reason:`Transferred from lineage context menu.`,toAgentName:n.trim()}}function Rm(e,t,n,r){return e&&t.some(t=>t.asset_id===e)?e:r?null:n}var zm=800;async function Bm(e,t=zm){let n=globalThis.navigator?.clipboard?.writeText;if(typeof n==`function`)try{return await Vm(n.call(globalThis.navigator.clipboard,e),t),{method:`clipboard`,ok:!0}}catch{if(Hm(e))return{method:`fallback`,ok:!0};throw Error(`Clipboard copy failed. Select the text and copy manually.`)}if(Hm(e))return{method:`fallback`,ok:!0};throw Error(`Clipboard unavailable. Select the text and copy manually.`)}async function Vm(e,t){let n;try{await Promise.race([e,new Promise((e,r)=>{n=setTimeout(()=>r(Error(`Clipboard write timed out.`)),t)})])}finally{n&&clearTimeout(n)}}function Hm(e){let t=globalThis.document;if(!t?.body||typeof t.createElement!=`function`||typeof t.execCommand!=`function`)return!1;let n=t.createElement(`textarea`),r=typeof HTMLElement==`function`&&t.activeElement instanceof HTMLElement?t.activeElement:null;n.value=e,n.setAttribute(`readonly`,``),n.style.position=`fixed`,n.style.left=`-9999px`,n.style.top=`0`,t.body.appendChild(n),n.focus(),n.select();try{return t.execCommand(`copy`)}finally{t.body.removeChild(n),r?.focus()}}function Um({canRemoveFromLineage:e,node:t,onClearAllNext:n,onClearNext:r,onOpenNode:i,onRemoveFromLineage:a,onReplaceNext:o,onReview:s,onSelectNext:c,onToast:l,selectedCount:u,selectionFull:d,snapshot:f}){let p=f.nodes.filter(e=>f.latest.includes(e.asset_id)),m=p.findIndex(e=>e.asset_id===t.asset_id),h=m>0?p[m-1]:null,g=m>=0&&m<p.length-1?p[m+1]:null,_=t.user_selected?`Remove from next variation`:d?`Selection full`:`Use for next variation`;async function v(){let e=t.local_path||t.s3_key;if(!e)return;let n=t.local_path?`local path`:`S3 key`;try{await Bm(e),l(`ok`,`Copied ${n}`)}catch(e){l(`error`,e instanceof Error?e.message:String(e))}}return(0,X.jsxs)(`footer`,{className:`lineage-node-actions`,children:[(0,X.jsxs)(`div`,{className:`lineage-node-actions-primary`,children:[(0,X.jsx)(`button`,{"aria-label":t.user_selected?`Remove ${t.title} from next variation`:`Use ${t.title} for next variation`,className:`primary-lite`,disabled:!t.user_selected&&d,onClick:()=>t.user_selected?r():c(t),type:`button`,children:_}),t.user_selected&&u>1&&(0,X.jsx)(`button`,{className:`selection-lite`,onClick:()=>o(t),type:`button`,children:`Use only this for next variation`}),!t.user_selected&&u>0&&(0,X.jsx)(`button`,{className:`selection-lite`,onClick:()=>o(t),type:`button`,children:`Replace selection`}),(0,X.jsxs)(`div`,{className:`lineage-node-review-actions`,"aria-label":`Review actions`,children:[(0,X.jsx)(`button`,{"aria-label":`Approve ${t.title}`,onClick:()=>s(`approved`,t.asset_id),type:`button`,children:`Approve`}),(0,X.jsx)(`button`,{"aria-label":`Reject ${t.title}`,onClick:()=>s(`rejected`,t.asset_id),type:`button`,children:`Reject`}),(0,X.jsx)(`button`,{"aria-label":`Ignore ${t.title}`,onClick:()=>s(`ignored`,t.asset_id),type:`button`,children:`Ignore`})]})]}),(0,X.jsxs)(`details`,{className:`lineage-node-actions-menu`,children:[(0,X.jsx)(`summary`,{children:`More actions`}),(0,X.jsxs)(`div`,{children:[u>0&&(0,X.jsx)(`button`,{onClick:n,type:`button`,children:`Clear all next variation`}),h&&(0,X.jsx)(`button`,{onClick:()=>i(h.asset_id),type:`button`,children:`Previous latest`}),g&&(0,X.jsx)(`button`,{onClick:()=>i(g.asset_id),type:`button`,children:`Next latest`}),t.preview_url&&(0,X.jsx)(`a`,{href:t.preview_url,rel:`noreferrer`,target:`_blank`,children:`Open preview`}),(t.local_path||t.s3_key)&&(0,X.jsxs)(`button`,{onClick:()=>void v(),type:`button`,children:[`Copy `,t.local_path?`local path`:`S3 key`]}),(0,X.jsx)(`button`,{"aria-label":e?`Remove ${t.title} from lineage`:`Root cannot be removed from lineage`,className:`danger`,disabled:!e,onClick:()=>a(t),type:`button`,children:e?`Remove from lineage`:`Root cannot be removed`})]})]})]})}function Wm({actions:e,attempts:t,node:n,onClose:r,onPromoteAttempt:i,project:a}){let o=(0,p.useMemo)(()=>[...t].sort((e,t)=>t.attempt_index-e.attempt_index),[t]),s=o.find(e=>e.is_current)||o[0],[c,l]=(0,p.useState)(s?.id),u=(0,p.useRef)(null),d=(0,p.useRef)(null);(0,p.useEffect)(()=>{let e=document.body.style.overflow,t=document.activeElement instanceof HTMLElement?document.activeElement:null;return document.body.style.overflow=`hidden`,u.current?.focus(),()=>{document.body.style.overflow=e,t?.focus()}},[]),(0,p.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){e.preventDefault(),r();return}e.key===`Tab`&&qm(e,d)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r]),(0,p.useEffect)(()=>{l(s?.id)},[s?.id,n.asset_id]);let f=o.find(e=>e.id===c)||s,m=Jm(a,n,f);return(0,X.jsx)(`div`,{className:`lineage-attempt-backdrop`,onClick:r,children:(0,X.jsxs)(`section`,{"aria-labelledby":`lineage-attempt-title`,"aria-modal":`true`,className:`lineage-attempt-modal`,onClick:e=>e.stopPropagation(),ref:d,role:`dialog`,tabIndex:-1,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{id:`lineage-attempt-title`,children:`Attempt history`}),(0,X.jsx)(`strong`,{children:n.title}),(0,X.jsx)(`code`,{children:n.asset_id})]}),(0,X.jsx)(`button`,{onClick:r,ref:u,type:`button`,children:`Close`})]}),(0,X.jsxs)(`div`,{className:`lineage-attempt-body`,children:[(0,X.jsx)(`div`,{className:`lineage-attempt-preview`,children:m?(0,X.jsx)(`img`,{src:m,alt:n.title}):(0,X.jsx)(`span`,{children:f?.source||n.media_type})}),(0,X.jsx)(`div`,{"aria-label":`Attempt versions`,className:`lineage-attempt-list`,role:`listbox`,children:o.map(e=>{let t=Jm(a,n,e),r=e.id===f?.id;return(0,X.jsxs)(`article`,{"aria-selected":r,className:`lineage-attempt-item ${e.is_current?`current`:``} ${r?`selected`:``}`,onClick:()=>l(e.id),onKeyDown:t=>Gm(t,()=>l(e.id)),role:`option`,tabIndex:0,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`strong`,{children:[`v`,e.attempt_index]}),(0,X.jsxs)(`div`,{className:`lineage-attempt-flags`,children:[r&&(0,X.jsx)(`span`,{className:`viewing`,children:`viewing`}),e.is_current&&(0,X.jsx)(`span`,{children:`current`})]})]}),(0,X.jsxs)(`div`,{className:`lineage-attempt-row`,children:[(0,X.jsx)(`div`,{className:`lineage-attempt-thumb`,children:t?(0,X.jsx)(`img`,{src:t,alt:``,loading:`lazy`}):(0,X.jsx)(`span`,{children:e.source})}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Source`}),(0,X.jsx)(`dd`,{children:e.source})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Asset`}),(0,X.jsx)(`dd`,{children:e.asset_id})]}),e.file_path&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`File`}),(0,X.jsx)(`dd`,{children:e.file_path})]}),e.generation_job_id&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Job`}),(0,X.jsx)(`dd`,{children:e.generation_job_id})]}),e.prompt&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Prompt`}),(0,X.jsx)(`dd`,{children:e.prompt})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Created`}),(0,X.jsx)(`dd`,{children:e.created_at})]})]})]}),!e.is_current&&i&&(0,X.jsx)(`button`,{className:`lineage-attempt-promote`,onClick:t=>{t.stopPropagation(),i(e)},onKeyDown:e=>Km(e),type:`button`,children:`Set current`})]},e.id)})})]}),e&&(0,X.jsx)(Um,{canRemoveFromLineage:e.canRemoveFromLineage,node:n,onClearAllNext:e.onClearAllNext,onClearNext:e.onClearNext,onOpenNode:e.onOpenNode,onRemoveFromLineage:e.onRemoveFromLineage,onReplaceNext:e.onReplaceNext,onReview:e.onReview,onSelectNext:e.onSelectNext,onToast:e.onToast,selectedCount:e.selectedCount,selectionFull:e.selectionFull,snapshot:e.snapshot})]})})}function Gm(e,t){e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),t())}function Km(e){e.key!==`Enter`&&e.key!==` `||e.stopPropagation()}function qm(e,t){let n=t.current;if(!n)return;let r=Array.from(n.querySelectorAll(`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hasAttribute(`disabled`)&&!e.hidden);if(r.length===0){e.preventDefault(),n.focus();return}let i=r[0],a=r[r.length-1],o=document.activeElement;e.shiftKey&&o===i?(e.preventDefault(),a.focus()):!e.shiftKey&&o===a&&(e.preventDefault(),i.focus())}function Jm(e,t,n){if(!n)return t.preview_url;if(n.file_path)return`/api/assets/local-preview?${new URLSearchParams({project:e,path:n.file_path}).toString()}`;if(n.asset_id===t.asset_id)return t.preview_url}var Ym={plan:0,import:1,error:2};function Xm({node:e,canRemoveFromLineage:t,onClearAllNext:n,onClearNext:r,onClose:i,onOpenNode:a,onRemoveFromLineage:o,onReplaceNext:s,onReview:c,onSelectNext:l,onToast:u,selectedCount:d,selectionFull:f,snapshot:m}){let h=m.edges.filter(t=>t.child_asset_id===e.asset_id).map(e=>m.nodes.find(t=>t.asset_id===e.parent_asset_id)).filter(e=>!!e),_=m.edges.filter(t=>t.parent_asset_id===e.asset_id).map(e=>m.nodes.find(t=>t.asset_id===e.child_asset_id)).filter(e=>!!e),v=ve({hasLocal:!!e.local_path,hasS3:!!e.s3_key}),[y,b]=(0,p.useState)(null),[x,S]=(0,p.useState)(null),[C,w]=(0,p.useState)(!1),[T,E]=(0,p.useState)(!1),D=!!(e.preview_url&&(e.media_type===`image`||e.media_type===`gif`));(0,p.useEffect)(()=>{let t=!1,n=new URLSearchParams({assetId:e.asset_id,limit:`6`,project:m.project,rootAssetId:m.root_asset_id});return b(null),S(null),w(!0),g(`/api/generation/jobs?${n.toString()}`).then(e=>{t||b(e)}).catch(e=>{t||S(e instanceof Error?e.message:String(e))}).finally(()=>{t||w(!1)}),()=>{t=!0}},[e.asset_id,m.project,m.root_asset_id]),(0,p.useEffect)(()=>{if(!T)return;let e=e=>{e.key===`Escape`&&E(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[T]);function O(e){a(e)}return(0,X.jsx)(`div`,{className:`lineage-detail-backdrop`,onClick:i,children:(0,X.jsxs)(`section`,{"aria-labelledby":`lineage-detail-title`,"aria-modal":`true`,className:`lineage-detail-modal`,onClick:e=>e.stopPropagation(),role:`dialog`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{id:`lineage-detail-title`,children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id})]}),(0,X.jsx)(`button`,{onClick:i,title:`Close detail`,children:`Close`})]}),(0,X.jsxs)(`div`,{className:`lineage-detail-body`,children:[(0,X.jsx)(`div`,{className:`lineage-detail-preview-shell`,children:(0,X.jsxs)(`div`,{className:`lineage-detail-preview`,children:[D?(0,X.jsx)(`img`,{src:e.preview_url,alt:e.title}):e.preview_url&&e.media_type===`video`?(0,X.jsx)(`video`,{src:e.preview_url,controls:!0}):(0,X.jsxs)(`div`,{className:`lineage-preview-empty`,children:[(0,X.jsx)(`strong`,{children:e.media_type}),(0,X.jsx)(`span`,{children:e.s3_key?`Preview available from Assets when signed.`:v.description})]}),D&&(0,X.jsx)(`button`,{"aria-label":`Expand image`,className:`lineage-detail-expand-preview`,onClick:()=>E(!0),title:`Expand image`,type:`button`,children:(0,X.jsx)(te,{"aria-hidden":`true`,size:17,strokeWidth:2.4})})]})}),(0,X.jsxs)(`aside`,{className:`lineage-detail-sidebar`,"aria-label":`Node details`,children:[(0,X.jsxs)(`details`,{className:`lineage-detail-disclosure`,children:[(0,X.jsxs)(`summary`,{children:[(0,X.jsx)(`span`,{children:`Asset details`}),(0,X.jsxs)(`small`,{children:[v.label,` · `,e.review_state]})]}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Storage`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`span`,{className:`storage-chip ${v.kind}`,children:v.label})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Source`}),(0,X.jsx)(`dd`,{children:e.source})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Channel`}),(0,X.jsx)(`dd`,{children:e.channel||`none`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Campaign`}),(0,X.jsx)(`dd`,{children:e.campaign||`none`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Status`}),(0,X.jsx)(`dd`,{children:e.status})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Review`}),(0,X.jsx)(`dd`,{children:e.review_state})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Latest`}),(0,X.jsx)(`dd`,{children:e.is_latest?`yes`:`no`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Next variation`}),(0,X.jsx)(`dd`,{children:e.user_selected?`yes`:`no`})]}),e.local_path&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Local path`}),(0,X.jsx)(`dd`,{children:e.local_path})]}),e.s3_key&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`S3 key`}),(0,X.jsx)(`dd`,{children:e.s3_key})]}),e.selection_note&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Rationale`}),(0,X.jsx)(`dd`,{children:e.selection_note})]}),e.review_notes&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Notes`}),(0,X.jsx)(`dd`,{children:e.review_notes})]})]})]}),(0,X.jsxs)(`details`,{className:`lineage-detail-disclosure`,children:[(0,X.jsxs)(`summary`,{children:[(0,X.jsx)(`span`,{children:`Lineage context`}),(0,X.jsxs)(`small`,{children:[h.length||`No`,` parent · `,_.length||`No`,` children`]})]}),(0,X.jsxs)(`section`,{className:`lineage-detail-context`,children:[(0,X.jsxs)(`p`,{children:[h.length||`No`,` parent · `,_.length||`No`,` children · `,e.is_latest?`latest leaf`:`branch point`]}),e.user_selected&&!e.is_latest&&(0,X.jsx)(`div`,{className:`lineage-detail-warning`,role:`status`,children:`This asset is selected for next variation but is not a latest leaf. Keep it for an intentional branch, or replace it with a newer leaf before continuing.`}),(0,X.jsxs)(`div`,{className:`lineage-relation-list`,children:[h.map(e=>(0,X.jsxs)(`button`,{"aria-label":`Open parent ${e.title}`,className:`lineage-relation-button`,onClick:()=>O(e.asset_id),children:[(0,X.jsx)(`span`,{children:`View parent`}),(0,X.jsx)(`strong`,{children:e.title})]},e.asset_id)),_.map(e=>(0,X.jsxs)(`button`,{"aria-label":`Open child ${e.title}`,className:`lineage-relation-button`,onClick:()=>O(e.asset_id),children:[(0,X.jsx)(`span`,{children:`View child`}),(0,X.jsx)(`strong`,{children:e.title})]},e.asset_id))]})]})]}),(0,X.jsxs)(`details`,{className:`lineage-detail-proof`,"data-testid":`lineage-generation-proof`,children:[(0,X.jsxs)(`summary`,{children:[(0,X.jsx)(`span`,{children:`Generation proof`}),(0,X.jsx)(`small`,{children:y?.jobs.length?`${y.jobs.length} receipt group${y.jobs.length===1?``:`s`}`:`Collapsed`})]}),(0,X.jsxs)(`div`,{className:`lineage-detail-proof-content`,children:[C&&(0,X.jsx)(`p`,{children:`Loading receipt proof...`}),x&&(0,X.jsx)(`p`,{className:`lineage-proof-error`,children:x}),!C&&!x&&y&&y.jobs.length===0&&(0,X.jsx)(`p`,{children:`No generation receipts for this node yet.`}),!C&&!x&&y?.jobs.map(e=>(0,X.jsxs)(`article`,{className:`lineage-proof-job`,children:[(0,X.jsxs)(`div`,{className:`lineage-proof-job-head`,children:[(0,X.jsx)(`strong`,{children:e.id}),(0,X.jsx)(`span`,{children:e.status})]}),(0,X.jsx)(`p`,{children:e.prompt}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Receipts`}),(0,X.jsx)(`dd`,{children:[...e.receipts].sort((e,t)=>Ym[e.receipt_type]-Ym[t.receipt_type]).map(e=>`${e.receipt_type}: ${e.status}`).join(` · `)||`none`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Parents`}),(0,X.jsx)(`dd`,{children:e.inputs.map(e=>e.asset_id).join(`, `)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Outputs`}),(0,X.jsx)(`dd`,{children:e.outputs.length||`none yet`})]})]}),e.outputs.length>0&&(0,X.jsx)(`div`,{className:`lineage-proof-output-list`,children:e.outputs.map(e=>(0,X.jsxs)(`div`,{className:`lineage-proof-output`,children:[(0,X.jsxs)(`span`,{children:[`Output `,e.output_index]}),(0,X.jsx)(`strong`,{children:e.imported_asset_id}),(0,X.jsx)(`code`,{children:e.file_path}),(0,X.jsxs)(`small`,{children:[`parent `,e.parent_asset_id]})]},e.id))})]},e.id))]})]})]})]}),T&&D&&(0,X.jsx)(`div`,{"aria-modal":`true`,className:`lineage-image-lightbox`,onClick:()=>E(!1),role:`dialog`,children:(0,X.jsxs)(`div`,{className:`lineage-image-lightbox-content`,onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(`button`,{onClick:()=>E(!1),type:`button`,children:`Close image`}),(0,X.jsx)(`img`,{src:e.preview_url,alt:e.title})]})}),(0,X.jsx)(Um,{canRemoveFromLineage:t,node:e,onClearAllNext:n,onClearNext:r,onOpenNode:O,onRemoveFromLineage:o,onReplaceNext:s,onReview:c,onSelectNext:l,onToast:u,selectedCount:d,selectionFull:f,snapshot:m})]})})}var Zm=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`EdgeSummaryValidationError`}};function Qm(e){if(e==null)return;if(typeof e!=`string`)throw new Zm(`not_text`,`Edge summary must be text`);let t=e.trim().split(/\s+/u).filter(Boolean);if(t.length!==0){if(t.length>2)throw new Zm(`too_many_words`,`Edge summary must contain at most 2 words`);return t.join(` `)}}function $m({childTitle:e,edge:t,onClose:n,onSubmit:r,parentTitle:i,returnFocus:a}){let[o,s]=(0,p.useState)(t.summary||``),[c,l]=(0,p.useState)(``),[u,d]=(0,p.useState)(!1),f=(0,p.useRef)(null),m=(0,p.useRef)(null),h=(0,p.useMemo)(()=>eh(o),[o]),g=o.trim()?o.trim().split(/\s+/u).length:0,_=h.value===t.summary;(0,p.useEffect)(()=>{let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,f.current?.focus(),()=>{document.body.style.overflow=e,a?.focus()}},[a]),(0,p.useEffect)(()=>{s(t.summary||``)},[t.id,t.summary,t.summary_updated_at]),(0,p.useEffect)(()=>{let e=e=>{if(e.key===`Escape`&&!u){e.preventDefault(),n();return}e.key===`Tab`&&nh(e,m)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[n,u]);async function v(e){e.preventDefault(),!(!h.value||h.error||_)&&await b(()=>r(`set`,h.value))}async function y(){t.summary&&await b(()=>r(`clear`))}async function b(e){l(``),d(!0);try{await e()}catch(e){l(e instanceof Error?e.message:String(e))}finally{d(!1)}}let x=h.error?h.error:g===0?t.summary?`Blank input is not a clear action. Use Clear label.`:`Enter one or two words.`:`${g} of 2 words`;return(0,X.jsx)(`div`,{className:`lineage-edge-summary-backdrop`,onClick:()=>{u||n()},children:(0,X.jsxs)(`section`,{"aria-describedby":`lineage-edge-summary-guidance lineage-edge-summary-provenance`,"aria-labelledby":`lineage-edge-summary-title`,"aria-modal":`true`,className:`lineage-edge-summary-dialog`,onClick:e=>e.stopPropagation(),ref:m,role:`dialog`,tabIndex:-1,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{id:`lineage-edge-summary-title`,children:`Edit edge label`}),(0,X.jsxs)(`p`,{children:[i,` `,(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),` `,e]})]}),(0,X.jsx)(`button`,{disabled:u,onClick:n,type:`button`,children:`Close`})]}),(0,X.jsxs)(`form`,{onSubmit:e=>void v(e),children:[(0,X.jsx)(`label`,{htmlFor:`lineage-edge-summary-input`,children:`Edge label`}),(0,X.jsx)(`input`,{"aria-invalid":!!h.error,autoComplete:`off`,disabled:u,id:`lineage-edge-summary-input`,onChange:e=>{s(e.target.value),l(``)},placeholder:`Two words max`,ref:f,value:o}),(0,X.jsx)(`p`,{className:h.error?`invalid`:``,id:`lineage-edge-summary-guidance`,children:x}),(0,X.jsx)(`p`,{id:`lineage-edge-summary-provenance`,children:th(t)}),c&&(0,X.jsx)(`p`,{className:`lineage-edge-summary-error`,role:`alert`,children:c}),(0,X.jsxs)(`div`,{className:`lineage-edge-summary-actions`,children:[(0,X.jsx)(`button`,{disabled:u||!h.value||!!h.error||_,type:`submit`,children:u?`Saving…`:`Save label`}),t.summary&&(0,X.jsx)(`button`,{className:`clear`,disabled:u,onClick:()=>void y(),type:`button`,children:`Clear label`}),(0,X.jsx)(`button`,{disabled:u,onClick:n,type:`button`,children:`Cancel`})]})]})]})})}function eh(e){try{return{value:Qm(e)}}catch(e){if(e instanceof Zm)return{error:e.message};throw e}}function th(e){return e.summary?e.summary_created_by===`agent`&&e.summary_updated_by===`human`?`Agent-generated · Human-edited`:e.summary_updated_by===`agent`?`Agent-generated`:e.summary_updated_by===`human`?`Human-authored`:`Existing edge label`:e.summary_updated_by===`human`?`Label cleared by a person`:`This edge is unlabeled`}function nh(e,t){let n=t.current;if(!n)return;let r=Array.from(n.querySelectorAll(`button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden);if(r.length===0)return;let i=r[0],a=r[r.length-1];e.shiftKey&&document.activeElement===i?(e.preventDefault(),a.focus()):!e.shiftKey&&document.activeElement===a&&(e.preventDefault(),i.focus())}function rh(e,t,n=8){let r=new URLSearchParams({page:`1`,pageSize:String(n),project:e,source:`all`}),i=t.trim();return i&&r.set(`q`,i),`/api/assets?${r.toString()}`}function ih(e){return`${e.title||e.asset_id} lineage`}function ah(e,t,n,r){return{project:e,rootAssetId:t.asset_id,title:n.trim(),notes:r.trim()||void 0,activate:!0,confirmWrite:!0}}function oh(e){return e.local?.relative_path&&e.s3?.key?`local + S3`:e.local?.relative_path?`local only`:e.s3?.key?`S3 backed`:e.source||`catalog`}function sh({onClose:e,onCreated:t,onToast:n,open:r,project:i}){let[a,o]=(0,p.useState)([]),[s,c]=(0,p.useState)(!1),[l,u]=(0,p.useState)(``),[d,f]=(0,p.useState)(``),[m,h]=(0,p.useState)(null),[_,v]=(0,p.useState)(!1),[y,b]=(0,p.useState)(``);(0,p.useEffect)(()=>{if(!r)return;let e=!0,t=window.setTimeout(()=>{c(!0),g(rh(i,d)).then(t=>{e&&o(t.assets)}).catch(t=>{e&&n(`error`,t instanceof Error?t.message:String(t))}).finally(()=>{e&&c(!1)})},180);return()=>{e=!1,window.clearTimeout(t)}},[n,r,i,d]),(0,p.useEffect)(()=>{m&&b(ih(m))},[m]);async function x(r){if(r.preventDefault(),!(!m||!y.trim())){v(!0);try{t((await g(`/api/lineage-workspaces`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(ah(i,m,y,l))})).workspace),e()}catch(e){n(`error`,e instanceof Error?e.message:String(e))}finally{v(!1)}}}return r?(0,X.jsx)(`div`,{className:`lineage-new-backdrop`,role:`presentation`,children:(0,X.jsxs)(`form`,{"aria-label":`New lineage`,className:`lineage-new-modal`,onSubmit:e=>void x(e),children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{children:`New lineage`}),(0,X.jsx)(`p`,{children:`Choose the asset that starts this iteration tree.`})]}),(0,X.jsx)(`button`,{"aria-label":`Close new lineage`,className:`icon-button`,onClick:e,type:`button`,children:`×`})]}),(0,X.jsxs)(`label`,{className:`lineage-new-search`,children:[(0,X.jsx)(`span`,{children:`Root asset`}),(0,X.jsx)(`input`,{autoFocus:!0,onChange:e=>f(e.target.value),placeholder:`Search by title, id, campaign, channel...`,value:d})]}),(0,X.jsxs)(`div`,{className:`lineage-new-results`,role:`listbox`,children:[a.map(e=>(0,X.jsxs)(`button`,{"aria-selected":m?.asset_id===e.asset_id,className:m?.asset_id===e.asset_id?`selected`:``,onClick:()=>h(e),type:`button`,children:[(0,X.jsx)(`strong`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),(0,X.jsxs)(`span`,{children:[e.channel,` · `,e.content_type,` · `,oh(e)]})]},e.asset_id)),s&&(0,X.jsx)(`p`,{children:`Searching...`}),!s&&a.length===0&&(0,X.jsx)(`p`,{children:`No matching assets found.`})]}),(0,X.jsxs)(`label`,{className:`lineage-new-field`,children:[(0,X.jsx)(`span`,{children:`Name`}),(0,X.jsx)(`input`,{disabled:!m,onChange:e=>b(e.target.value),value:y})]}),(0,X.jsxs)(`label`,{className:`lineage-new-field`,children:[(0,X.jsx)(`span`,{children:`Notes`}),(0,X.jsx)(`textarea`,{onChange:e=>u(e.target.value),placeholder:`Optional context for future agents`,value:l})]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{className:`secondary-button`,onClick:e,type:`button`,children:`Cancel`}),(0,X.jsx)(`button`,{className:`primary-button`,disabled:!m||!y.trim()||_,type:`submit`,children:_?`Creating...`:`Create lineage`})]})]})}):null}function ch({atEnd:e,onClose:t,onPlayPause:n,onRestart:r,onScrub:i,onSpeed:a,playing:o,speed:s,stageIndex:c,totalStages:l}){let u=Math.max(0,c),d=o?`Pause replay`:e?`Replay from start`:`Play replay`;return(0,X.jsxs)(`section`,{"aria-label":`Lineage growth replay`,className:`lineage-replay-controls`,"data-testid":`lineage-replay-controls`,children:[(0,X.jsxs)(`div`,{className:`lineage-replay-controls-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:`Replay growth`}),(0,X.jsxs)(`output`,{"aria-live":`polite`,children:[`Stage `,u+1,` of `,l]})]}),(0,X.jsx)(`button`,{className:`lineage-replay-close`,onClick:t,type:`button`,children:`Return to live`})]}),(0,X.jsxs)(`label`,{className:`lineage-replay-scrubber`,children:[(0,X.jsx)(`span`,{children:`Growth stage`}),(0,X.jsx)(`input`,{"aria-label":`Replay stage`,max:Math.max(0,l-1),min:0,onChange:e=>i(Number(e.target.value)),step:1,type:`range`,value:u})]}),(0,X.jsxs)(`div`,{className:`lineage-replay-actions`,children:[(0,X.jsx)(`button`,{"aria-label":d,onClick:n,type:`button`,children:o?`Pause`:e?`Replay`:`Play`}),(0,X.jsx)(`button`,{onClick:r,type:`button`,children:`Restart`}),(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`span`,{children:`Speed`}),(0,X.jsxs)(`select`,{"aria-label":`Replay speed`,onChange:e=>a(Number(e.target.value)),value:s,children:[(0,X.jsx)(`option`,{value:.5,children:`0.5×`}),(0,X.jsx)(`option`,{value:1,children:`1×`}),(0,X.jsx)(`option`,{value:2,children:`2×`})]})]})]})]})}function lh({node:e}){return(0,X.jsx)(`span`,{className:`lineage-candidate-meta`,children:[e.channel,e.status,e.review_state].filter(Boolean).map(e=>(0,X.jsx)(`span`,{children:e},e))})}function uh({brief:e,cli:t=null,nextBase:n,onRefreshBrief:r,onToast:i,project:a,rerollTargets:o=[],rootAssetId:s}){let c=e?.handoff?.next_command||Z(t,`next --project ${ph(a)} --root ${ph(s)}`),l=e?.handoff?.next_command?`${hh(e.handoff.next_command)} reroll list --project ${ph(a)} --root ${ph(s)}${mh(e.handoff.next_command)} --json`:Z(t,`reroll list --project ${ph(a)} --root ${ph(s)}`),u=n?`${n.title} (${n.asset_id})`:`No asset chosen; CLI will report candidates or fallback.`,d=[{label:`next command`,text:c},n&&{label:`variation source`,text:n.asset_id}].filter(e=>!!e),f=[e?.handoff?.inspect_command&&{label:`inspect command`,text:e.handoff.inspect_command},e?.handoff?.link_child_command&&{label:`link-child command`,text:e.handoff.link_child_command},e?.brief?.prompt&&{label:`agent brief`,text:e.brief.prompt}].filter(e=>!!e),p=f.map(e=>`${e.label}:\n${e.text}`).join(`
12
+
13
+ `),m=e=>e===`variation source`?`Copy source`:e===`agent brief`?`Copy prompt`:e===`link-child command`?`Copy link command`:`Copy command`,h=fh(a,s);async function _(e,t){try{await Bm(e),i(`ok`,`Copied ${t}`)}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}async function v(){try{let t=await g(`/api/agent-claims`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentName:`Copied Lineage handoff`,channel:n?.channel,project:a,scopeType:`lineage_workspace`,targetId:h,targetTitle:n?`${n.title} lineage`:`Lineage workspace ${s}`,ttl:`20m`})});await Bm(_h(t.claim_token,c,e,p)),i(`ok`,`Copied claim-aware handoff for ${t.claim.id}`)}catch(e){i(`error`,e instanceof Error?e.message:String(e))}}return(0,X.jsxs)(`section`,{className:`lineage-handoff-panel`,"data-testid":`lineage-handoff-panel`,children:[(0,X.jsx)(`h3`,{children:`Agent handoff`}),(0,X.jsxs)(`div`,{className:`lineage-handoff-base ${n&&!n.is_latest?`branch`:``}`,children:[(0,X.jsx)(`span`,{children:n?`Agent will evolve`:`Choose a variation source`}),(0,X.jsx)(`strong`,{children:u}),n&&(0,X.jsx)(`small`,{children:[n.channel,n.status,n.review_state].filter(Boolean).join(` / `)}),n&&!n.is_latest&&(0,X.jsx)(`p`,{children:`Branch from here: this asset is not a latest leaf.`})]}),d.map(e=>(0,X.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,X.jsx)(`code`,{children:e.text}),(0,X.jsx)(`button`,{"aria-label":`Copy ${e.label}`,onClick:()=>void _(e.text,e.label),children:m(e.label)})]},e.label)),o.length>0&&(0,X.jsxs)(`div`,{className:`lineage-brief-group`,children:[(0,X.jsxs)(`div`,{className:`lineage-brief-head`,children:[(0,X.jsx)(`h4`,{children:`Re-roll queue`}),(0,X.jsx)(`button`,{"aria-label":`Copy re-roll queue handoff`,onClick:()=>void _(dh(l,o),`re-roll queue`),children:`Copy queue`})]}),(0,X.jsx)(`p`,{children:`Use this for repair work. Import outputs with reroll import; do not link them as lineage children.`}),(0,X.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,X.jsx)(`code`,{children:l}),(0,X.jsx)(`button`,{"aria-label":`Copy reroll list command`,onClick:()=>void _(l,`reroll list command`),children:`Copy command`})]}),o.map(e=>(0,X.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,X.jsxs)(`code`,{children:[e.asset_id,e.reroll_request?.notes?`: ${e.reroll_request.notes}`:``]}),(0,X.jsx)(`button`,{"aria-label":`Copy re-roll target ${e.asset_id}`,onClick:()=>void _(e.asset_id,`re-roll target`),children:`Copy target`})]},e.asset_id))]}),f.length>0&&(0,X.jsxs)(`div`,{className:`lineage-brief-group`,children:[(0,X.jsxs)(`div`,{className:`lineage-brief-head`,children:[(0,X.jsx)(`h4`,{children:`Generated brief`}),(0,X.jsx)(`button`,{"aria-label":`Copy full generated brief`,onClick:()=>void _(p,`full brief`),children:`Copy all`})]}),(0,X.jsx)(`p`,{children:`Use this bundle when asking an agent to continue from the chosen asset.`}),(0,X.jsx)(`button`,{"aria-label":`Copy claim-aware handoff`,className:`lineage-claim-handoff-button`,onClick:()=>v(),children:`Copy claim handoff`}),(0,X.jsxs)(`details`,{children:[(0,X.jsx)(`summary`,{children:`Commands and prompt`}),f.map(e=>(0,X.jsxs)(`div`,{className:`lineage-copy-row`,children:[(0,X.jsx)(`code`,{children:e.text}),(0,X.jsx)(`button`,{"aria-label":`Copy ${e.label}`,onClick:()=>void _(e.text,e.label),children:m(e.label)})]},e.label))]})]}),(0,X.jsx)(`button`,{"aria-label":f.length>0?`Regenerate agent brief`:`Generate agent brief`,onClick:r,children:f.length>0?`Regenerate brief`:`Generate brief`})]})}function dh(e,t){return[e,`For each pending target, ask for or use a target-specific repair prompt.`,`Run reroll plan for one target at a time, generate one file under .asset-scratch, then run reroll import.`,`Do not use link-child for re-roll outputs.`,...t.map(e=>`Target ${e.asset_id}: ${e.title}${e.reroll_request?.notes?` (${e.reroll_request.notes})`:``}`)].join(`
14
+ `)}function fh(e,t){return`${e}:lineage-workspace:${t}`}function ph(e){return`'${e.replace(/'/g,`'\\''`)}'`}function mh(e){let t=/\s--(db|profile)\s+('[^']*(?:'\\''[^']*)*'|"[^"]*"|\S+)/.exec(e);return t?` --${t[1]} ${t[2]}`:``}function hh(e){let t=/\s(?:next|inspect|link-child)\s/.exec(e);if(!t)throw Error(`Verified Lineage launcher missing from handoff command`);return e.slice(0,t.index)}function gh(e){return e.includes(`--claim-token`)?e:/\s--json$/.test(e)?e.replace(/\s--json$/,` --claim-token "$LINEAGE_CLAIM_TOKEN" --json`):`${e} --claim-token "$LINEAGE_CLAIM_TOKEN"`}function _h(e,t,n,r){let i=n?.handoff?.link_child_command||n?.handoff?.next_command||t,a=mh(i),o=`${hh(i)} agent heartbeat --claim-token "$LINEAGE_CLAIM_TOKEN"${a} --json`;return[`export LINEAGE_CLAIM_TOKEN=${ph(e)}`,o,t,n?.handoff?.inspect_command,n?.handoff?.link_child_command?gh(n.handoff.link_child_command):void 0,r?`Agent brief:\n${r}`:void 0].filter(e=>!!e).join(`
15
+
16
+ `)}function vh(e){let t=Ne(),{activeNode:n,brief:r,childAssetId:i,clearNextVariation:a,closePanel:o,latestNodes:s,linkChild:c,markReview:l,noteDirty:u,onSelectedAsset:d,nextVariationLimit:f,onToast:p,project:m,refreshBrief:h,saveRationale:g,selectNextBase:_,selectedNode:v,selectedNodes:y,selectionFull:b,refreshLineage:x,replaceNextVariation:S,selectionNote:C,setActiveNodeId:w,setChildAssetId:T,setDetailNodeId:E,setSelected:D,setSelectionNote:O,sideOpen:k,snapshot:A}=e,j=n?ve({hasLocal:!!n.local_path,hasS3:!!n.s3_key}):null,M=y.filter(e=>!e.is_latest),N=A.nodes.filter(e=>e.reroll_request?.status===`pending`);return(0,X.jsxs)(`aside`,{"aria-hidden":!k,className:`lineage-side ${k?``:`collapsed`}`,id:`lineage-selection-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-side-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{children:`Next variation`}),(0,X.jsx)(`p`,{className:`muted-copy`,children:`Choose what the agent will evolve next; double-click nodes for full details.`})]}),(0,X.jsx)(`button`,{"aria-label":`Close lineage selection panel`,className:`icon-button`,onClick:o,type:`button`,children:`×`})]}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Using for next variation`}),(0,X.jsxs)(`span`,{className:`lineage-count-pill ${b?`full`:``}`,children:[y.length,`/`,f]})]}),y.length>0&&(0,X.jsx)(`div`,{className:`lineage-panel-action-row`,children:(0,X.jsx)(`button`,{onClick:()=>void a(),type:`button`,children:`Clear all`})}),M.length>0&&(0,X.jsxs)(`div`,{className:`lineage-selection-warning`,role:`status`,children:[M.length,` selected asset`,M.length===1?` is`:`s are`,` not latest. This is valid for branching, but clear or replace it if you meant to continue from the newest leaves.`]}),y.length>0?y.map(e=>(0,X.jsxs)(`div`,{className:`lineage-candidate selected`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect asset used for next variation ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),(0,X.jsx)(lh,{node:e})]}),!e.is_latest&&(0,X.jsx)(`span`,{className:`lineage-candidate-warning`,children:`Not latest`}),(0,X.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[y.length>1&&(0,X.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>S(e),children:`Use only this`}),(0,X.jsx)(`button`,{className:`lineage-candidate-action remove`,onClick:()=>void a(e.asset_id),children:`Remove`})]})]},e.asset_id)):(0,X.jsxs)(`p`,{className:`muted-copy`,children:[`Choose up to `,f,` assets to guide the next generation.`]}),y.length>1&&(0,X.jsx)(`p`,{className:`muted-copy`,children:`The agent will use these as separate next-variation bases; imported outputs should link back to the matching selected parent.`})]}),(0,X.jsx)(yh,{activeNode:n,onSelectedAsset:d,onToast:p,project:m,refreshLineage:x,setActiveNodeId:w,snapshot:A}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Re-roll queue`}),(0,X.jsx)(`span`,{className:`lineage-count-pill`,children:N.length})]}),N.length>0?N.map(e=>(0,X.jsx)(`div`,{className:`lineage-candidate ${e.asset_id===n?.asset_id?`active`:``}`,children:(0,X.jsxs)(`button`,{"aria-label":`Inspect re-roll target ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),e.reroll_request?.notes&&(0,X.jsx)(`small`,{children:e.reroll_request.notes})]})},e.asset_id)):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No pending re-roll targets.`})]}),(0,X.jsxs)(`section`,{className:`lineage-next-panel`,children:[(0,X.jsx)(`h3`,{children:`Latest candidates`}),s.length>0?s.map(e=>{let t=!e.user_selected&&b;return(0,X.jsxs)(`div`,{className:`lineage-candidate ${e.asset_id===n?.asset_id?`active`:``} ${e.user_selected?`selected`:``}`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect ${e.title}`,className:`lineage-candidate-main`,onClick:()=>{w(e.asset_id),d(e.asset_id)},children:[(0,X.jsx)(`span`,{children:e.title}),(0,X.jsx)(`code`,{children:e.asset_id}),(0,X.jsx)(lh,{node:e})]}),(0,X.jsxs)(`div`,{className:`lineage-candidate-actions`,children:[(0,X.jsx)(`button`,{"aria-label":e.user_selected?`Remove ${e.title} from next variation`:`Use ${e.title} for next variation`,className:`lineage-candidate-action ${e.user_selected?`remove`:``}`,disabled:t,onClick:()=>e.user_selected?void a(e.asset_id):_(e),children:e.user_selected?`Remove`:t?`Selection full`:`Use for next variation`}),!e.user_selected&&y.length>0&&(0,X.jsx)(`button`,{className:`lineage-candidate-action secondary`,onClick:()=>S(e),children:`Replace selection`})]})]},e.asset_id)}):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No latest leaves yet.`})]}),(0,X.jsx)(uh,{brief:r,cli:t,nextBase:v,onRefreshBrief:()=>void h(),onToast:p,project:m,rerollTargets:N,rootAssetId:A.root_asset_id}),(0,X.jsx)(`h3`,{children:`Inspecting`}),n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`strong`,{children:n.title}),(0,X.jsx)(`code`,{children:n.asset_id}),(0,X.jsxs)(`dl`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Storage`}),(0,X.jsx)(`dd`,{children:j&&(0,X.jsx)(`span`,{className:`storage-chip ${j.kind}`,children:j.label})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Source`}),(0,X.jsx)(`dd`,{children:n.source})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Review`}),(0,X.jsx)(`dd`,{children:n.review_state})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Latest`}),(0,X.jsx)(`dd`,{children:n.is_latest?`yes`:`no`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Next variation`}),(0,X.jsx)(`dd`,{children:n.user_selected?`yes`:`no`})]})]}),n.user_selected&&!n.is_latest&&(0,X.jsx)(`div`,{className:`lineage-selection-warning`,role:`status`,children:`This selected asset is not a latest leaf. Keep it selected to branch from an earlier idea, or replace it with the current inspected asset.`}),(0,X.jsxs)(`label`,{className:`lineage-note-field`,children:[`Variation rationale`,(0,X.jsx)(`textarea`,{value:C,onChange:e=>O(e.target.value),placeholder:`Why should the next generation branch from this asset?`}),(0,X.jsx)(`span`,{className:`lineage-note-status ${u?`dirty`:``}`,children:n.user_selected?u?`Unsaved rationale`:`Rationale saved for next variation`:`Rationale saves when this is used for next variation`})]}),(0,X.jsxs)(`div`,{className:`lineage-side-actions`,children:[(0,X.jsx)(`button`,{"aria-label":n.user_selected?`Remove ${n.title} from next variation`:`Use ${n.title} for next variation`,className:`primary-lite`,disabled:!n.user_selected&&b,onClick:()=>n.user_selected?void a(n.asset_id):D(),children:n.user_selected?`Remove from next variation`:b?`Selection full`:`Use for next variation`}),n.user_selected&&y.length>1&&(0,X.jsx)(`button`,{onClick:()=>S(n,C),children:`Use only this`}),!n.user_selected&&y.length>0&&(0,X.jsx)(`button`,{onClick:()=>S(n,C),children:`Replace selection`}),(0,X.jsx)(`button`,{disabled:!n.user_selected||!u,onClick:g,children:`Save rationale`}),(0,X.jsx)(`button`,{"aria-label":`Open detail for ${n.title}`,onClick:()=>E(n.asset_id),children:`Open detail`}),(0,X.jsx)(`button`,{"aria-label":`Approve ${n.title}`,onClick:()=>void l(`approved`),children:`Approve`}),(0,X.jsx)(`button`,{"aria-label":`Reject ${n.title}`,onClick:()=>void l(`rejected`),children:`Reject`}),(0,X.jsx)(`button`,{"aria-label":`Ignore ${n.title}`,onClick:()=>void l(`ignored`),children:`Ignore`})]}),(0,X.jsxs)(`form`,{className:`lineage-link-form`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,X.jsxs)(`label`,{children:[`Child asset ID`,(0,X.jsx)(`input`,{value:i,onChange:e=>T(e.target.value),placeholder:`local-... or catalog id`})]}),(0,X.jsx)(`button`,{disabled:!i.trim(),type:`submit`,children:`Link child`})]})]}):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No lineage node selected.`})]})}function yh({activeNode:e,onSelectedAsset:t,onToast:n,project:r,refreshLineage:i,setActiveNodeId:a,snapshot:o}){let s=(0,p.useMemo)(()=>Sh(o.tasks||[]),[o.tasks]),c=s.filter(e=>Ch(e)).length,l=(0,p.useMemo)(()=>new Map(o.nodes.map(e=>[e.asset_id,e])),[o.nodes]);return(0,X.jsxs)(`section`,{className:`lineage-next-panel lineage-task-queue-panel`,children:[(0,X.jsxs)(`div`,{className:`lineage-panel-title-row`,children:[(0,X.jsx)(`h3`,{children:`Task queue`}),(0,X.jsx)(`span`,{className:`lineage-count-pill`,children:c})]}),s.length>0?s.map(o=>(0,X.jsx)(bh,{active:o.target_asset_id===e?.asset_id,node:l.get(o.target_asset_id),onInspect:()=>{a(o.target_asset_id),t(o.target_asset_id)},onToast:n,project:r,refreshLineage:i,task:o},`${o.id}:${o.updated_at}`)):(0,X.jsx)(`p`,{className:`muted-copy`,children:`No open lineage tasks.`})]})}function bh({active:e,node:t,onInspect:n,onToast:r,project:i,refreshLineage:a,task:o}){let s=o.status===`claimed`||o.status===`in_progress`,c=o.status===`pending`,[l,u]=(0,p.useState)(o.instructions||``),[d,f]=(0,p.useState)(``),[m,h]=(0,p.useState)(!1);(0,p.useEffect)(()=>u(o.instructions||``),[o.id,o.instructions]);async function _(e,t,n){h(!0);try{return await g(e,{body:JSON.stringify({project:i,...t}),headers:{"Content-Type":`application/json`},method:`POST`}),r(`ok`,n),await a(),!0}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),!1}finally{h(!1)}}async function v(e){e.preventDefault(),await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/instructions`,{instructions:l},`Updated ${Th(o)} instructions`)}async function y(e){e.preventDefault();let t=d.trim();t&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/comment`,{actor:`human`,message:t},`Commented on ${Th(o)}`)&&f(``)}async function b(){window.confirm(`Unlock ${Th(o)} for human edits?`)&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/override`,{actor:`human`,reason:`Human unlocked task from lineage UI.`},`Unlocked ${Th(o)}`)}async function x(){window.confirm(s?`Cancel ${Th(o)} while an agent is working?`:`Cancel ${Th(o)}?`)&&await _(`/api/lineage/tasks/${encodeURIComponent(o.id)}/cancel`,{actor:`human`,confirmWrite:!0,override:s},`Cancelled ${Th(o)}`)}return(0,X.jsxs)(`article`,{className:`lineage-task-card ${e?`active`:``} ${s?`locked`:o.status}`,children:[(0,X.jsxs)(`button`,{"aria-label":`Inspect task target ${t?.title||o.target_asset_id}`,className:`lineage-task-target`,onClick:n,type:`button`,children:[(0,X.jsx)(`span`,{children:t?.title||o.target_asset_id}),(0,X.jsx)(`code`,{children:o.target_asset_id})]}),(0,X.jsxs)(`div`,{className:`lineage-task-meta`,children:[(0,X.jsx)(`span`,{className:`lineage-task-status ${o.status}`,children:wh(o.status)}),(0,X.jsx)(`span`,{children:o.task_type})]}),c?(0,X.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:v,children:[(0,X.jsxs)(`label`,{children:[`Instructions`,(0,X.jsx)(`textarea`,{"aria-label":`Instructions for ${o.id}`,value:l,onChange:e=>u(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,X.jsx)(`button`,{disabled:m||l===(o.instructions||``),type:`submit`,children:`Save instructions`}),(0,X.jsx)(`button`,{disabled:m,onClick:x,type:`button`,children:`Cancel`})]})]}):(0,X.jsxs)(`div`,{className:`lineage-task-locked-body`,children:[(0,X.jsxs)(`label`,{children:[`Instructions`,(0,X.jsx)(`textarea`,{"aria-label":`Locked instructions for ${o.id}`,disabled:!0,readOnly:!0,value:l||`No instructions.`})]}),s&&(0,X.jsx)(xh,{claim:o.active_claim}),s&&(0,X.jsxs)(`form`,{className:`lineage-task-form`,onSubmit:y,children:[(0,X.jsxs)(`label`,{children:[`Comment`,(0,X.jsx)(`textarea`,{"aria-label":`Comment for ${o.id}`,value:d,onChange:e=>f(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`lineage-task-actions`,children:[(0,X.jsx)(`button`,{disabled:m||!d.trim(),type:`submit`,children:`Add comment`}),(0,X.jsx)(`button`,{disabled:m,onClick:b,type:`button`,children:`Unlock`}),(0,X.jsx)(`button`,{disabled:m,onClick:x,type:`button`,children:`Cancel`})]})]})]})]})}function xh({claim:e}){return e?(0,X.jsxs)(`p`,{className:`lineage-task-claim ${e.derived_state===`active`?`active`:e.derived_state}`,children:[(0,X.jsxs)(`span`,{children:[wh(e.derived_state),` claim`]}),(0,X.jsx)(`strong`,{children:e.agent_name})]}):(0,X.jsx)(`p`,{className:`lineage-task-claim`,children:`Claimed by agent`})}function Sh(e){return[...e].sort((e,t)=>{let n=+!Ch(e),r=+!Ch(t);return n===r?e.created_at.localeCompare(t.created_at):n-r})}function Ch(e){return e.status===`pending`||e.status===`claimed`||e.status===`in_progress`}function wh(e){return e.replace(/_/g,` `)}function Th(e){return`${e.task_type} task`}function Eh(e,t){return e?.root_asset_id||t||``}function Dh(e){return`${e.title} (${e.root_asset_id})`}function Oh(e,t){let n=`${t.project}:lineage-workspace:${t.root_asset_id}`;return e.filter(e=>e.project!==t.project||e.status!==`active`||e.derived_state===`expired`?!1:e.scope_type===`lineage_workspace`?e.target_id===t.id||e.target_id===n:e.scope_type===`project_channel`)}function kh(e){return e.some(e=>e.derived_state===`stale`)?`stale`:e.some(e=>e.derived_state===`idle`)?`idle`:`active`}function Ah(e){let t=kh(e);return e.length===1?`${t===`active`?`Claimed`:t===`idle`?`Idle claim`:`Stale claim`} by ${e[0].agent_name}`:`${e.length} active claims`}function jh({activeWorkspace:e,closeSignal:t,loading:n,onNewLineage:r,onRefresh:i,onSelect:a,workspaces:o}){let[s,c]=(0,p.useState)(!1),[l,u]=(0,p.useState)([]),d=(0,p.useRef)(null),f=e?.project||o[0]?.project||``;(0,p.useEffect)(()=>{function e(e){d.current?.contains(e.target)||c(!1)}function t(e){e.key===`Escape`&&c(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t,!0)}},[]),(0,p.useEffect)(()=>{c(!1)},[t]),(0,p.useEffect)(()=>{if(!f){u([]);return}let e=!1;return g(`/api/agent-claims?${new URLSearchParams({project:f})}`).then(t=>{e||u(t.claims)}).catch(()=>{e||u([])}),()=>{e=!0}},[f,t,o.length]);function m(e){c(!1),a(e)}let h=e?Oh(l,e):[];return(0,X.jsxs)(`section`,{"aria-label":`Lineage workspace picker`,className:`lineage-workspace-picker`,ref:d,children:[(0,X.jsxs)(`button`,{"aria-expanded":s,"aria-haspopup":`listbox`,className:`lineage-workspace-trigger`,disabled:n,onClick:()=>c(e=>!e),onKeyDown:e=>{e.key===`Escape`&&c(!1)},type:`button`,children:[(0,X.jsx)(`span`,{children:`Workspace`}),(0,X.jsx)(`strong`,{children:e?.title||`No workspace selected`}),(0,X.jsx)(`code`,{children:e?.root_asset_id||`Start with New lineage`}),(0,X.jsx)(Nh,{claims:h})]}),s&&(0,X.jsxs)(`div`,{className:`lineage-workspace-menu`,children:[(0,X.jsxs)(`div`,{className:`lineage-workspace-options`,role:`listbox`,children:[o.length===0&&(0,X.jsx)(`p`,{children:`No workspaces yet.`}),o.map(t=>(0,X.jsx)(Mh,{active:e?.id===t.id,claims:Oh(l,t),onSelect:()=>m(t.id),workspace:t},t.id))]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{className:`secondary-button`,disabled:n,onClick:i,type:`button`,children:`Refresh`}),(0,X.jsx)(`button`,{className:`primary-button`,onClick:()=>{c(!1),r()},type:`button`,children:`New lineage`})]})]})]})}function Mh({active:e,claims:t,onSelect:n,workspace:r}){return(0,X.jsxs)(`button`,{"aria-selected":e,className:e?`active`:``,onClick:n,role:`option`,type:`button`,children:[(0,X.jsx)(`strong`,{children:r.title}),(0,X.jsx)(`code`,{children:r.root_asset_id}),(0,X.jsx)(`span`,{children:Dh(r)}),(0,X.jsx)(Nh,{claims:t})]})}function Nh({claims:e}){return e.length===0?null:(0,X.jsxs)(`small`,{className:`lineage-workspace-claim ${kh(e)}`,children:[(0,X.jsx)(se,{size:13}),(0,X.jsx)(`span`,{children:Ah(e)})]})}function Ph({activeWorkspace:e,actionsOpen:t,closeSignal:n,demoSeedStatus:r,edgeSummariesVisible:i,graphDirection:a,loading:o,onArchiveWorkspace:s,onActionsOpenChange:c,onDownloadSwissifierMedia:l,onEdgeSummariesVisible:u,onFitGraph:d,onGraphDirection:f,onIndexLocal:m,onNewLineage:h,onRefreshLineage:g,onRefreshWorkspaces:_,onReplayGrowth:v,onRestoreDemoMedia:y,onRestoreSwissifierMedia:b,onSeedDemo:x,onSeedSwissifierDemo:S,onSelectWorkspace:C,onTidyGraph:w,onToggleNextPanel:T,sideOpen:E,replayActive:D,snapshot:O,swissifierDemoStatus:k,workspaceLoading:A,workspaceProgress:j,workspaceRootAssetId:M,workspaces:N}){let P=r?`${r.present}/${r.total} SVG placeholders`:`Checking media`,F=k?`${k.present}/${k.total} PNG images`:`Checking media`,I=!!(k&&k.present===k.total),L=!!(k?.download_available&&!I),R=j===`downloading`?`Downloading rich demo media`:j===`downloaded`?`Rich demo media ready to seed`:j===`seeding`?`Creating rich demo workspace`:j===`indexing`?`Indexing 14 rich demo images`:j===`ready`?`Rich demo ready`:j===`error`?`Rich demo setup failed`:null,z=A||[`downloading`,`seeding`,`indexing`].includes(j||``),B=R||(O?`${O.nodes.length} nodes · ${O.edges.length} links`:M||`Choose a lineage workspace`);(0,p.useEffect)(()=>{c(!1)},[n,c]),(0,p.useEffect)(()=>{function e(e){e.key===`Escape`&&c(!1)}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[c]);function V(e){c(!1),e()}function H(e){e.key===`Escape`&&(e.preventDefault(),c(!1))}return(0,X.jsxs)(`header`,{className:`lineage-header`,children:[(0,X.jsxs)(`div`,{className:`lineage-primary-controls`,children:[(0,X.jsx)(jh,{activeWorkspace:e,closeSignal:n,loading:z,onNewLineage:h,onRefresh:_,onSelect:C,workspaces:N}),(0,X.jsx)(`p`,{className:`lineage-toolbar-context`,children:B}),(0,X.jsx)(`button`,{"aria-pressed":D,className:`secondary-button lineage-replay-launch`,disabled:D||!O||O.nodes.length<2||O.edges.length===0,onClick:v,type:`button`,children:`Replay growth`}),(0,X.jsx)(`button`,{className:`primary-button`,onClick:h,type:`button`,children:`New lineage`})]}),(0,X.jsxs)(`details`,{className:`lineage-overflow`,onToggle:e=>c(e.currentTarget.open),open:t,children:[(0,X.jsx)(`summary`,{onKeyDown:H,tabIndex:0,children:`Actions`}),(0,X.jsxs)(`div`,{children:[!e&&(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(x),type:`button`,children:`Load demo lineage`}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`QA seed media`}),(0,X.jsx)(`span`,{children:F})]}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`Basic SVG demo`}),(0,X.jsx)(`span`,{children:P})]}),(0,X.jsx)(`button`,{disabled:z||r?.present===r?.total,onClick:y,type:`button`,children:`Restore basic media`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(x),type:`button`,children:`Load SVG placeholder demo`}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`Swissifier rich demo`}),(0,X.jsx)(`span`,{children:F})]}),(0,X.jsx)(`button`,{disabled:z||!L,onClick:l,type:`button`,children:`Download rich images`}),(0,X.jsx)(`button`,{disabled:z||I,onClick:b,type:`button`,children:`Restore rich media`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(S),type:`button`,children:`Load rich image demo`}),(0,X.jsxs)(`label`,{className:`lineage-action-select`,children:[(0,X.jsx)(`span`,{children:`Direction`}),(0,X.jsxs)(`select`,{"aria-label":`Lineage graph direction`,disabled:!O||o,onChange:e=>f(e.target.value),value:a,children:[(0,X.jsx)(`option`,{value:`LR`,children:`Left to right`}),(0,X.jsx)(`option`,{value:`TB`,children:`Top to bottom`}),(0,X.jsx)(`option`,{value:`RL`,children:`Right to left`}),(0,X.jsx)(`option`,{value:`BT`,children:`Bottom to top`})]})]}),(0,X.jsx)(`button`,{"aria-pressed":i,disabled:!O,onClick:()=>V(u),type:`button`,children:i?`Hide edge labels`:`Show edge labels`}),(0,X.jsx)(`button`,{disabled:!O,onClick:()=>V(d),type:`button`,children:`Fit graph`}),(0,X.jsx)(`button`,{disabled:!O,onClick:()=>V(w),type:`button`,children:`Tidy tree`}),(0,X.jsx)(`button`,{"aria-controls":`lineage-selection-panel`,"aria-expanded":E,disabled:!O,onClick:()=>V(T),type:`button`,children:`Manage selection`}),(0,X.jsx)(`button`,{disabled:z||!e,onClick:()=>V(s),type:`button`,children:`Archive current lineage`}),(0,X.jsx)(`button`,{disabled:o||z,onClick:()=>V(m),type:`button`,children:`Index local`}),(0,X.jsx)(`button`,{disabled:o||!O,onClick:()=>V(g),type:`button`,children:`Refresh graph`}),(0,X.jsx)(`button`,{disabled:z,onClick:()=>V(_),type:`button`,children:`Refresh workspaces`})]})]})]})}async function Fh(e,t,n){await g(`/api/lineage/layout`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({confirmWrite:!0,positions:n,project:e,rootAssetId:t})})}function Ih(e,t,n){return hd(e.filter(e=>e.type!==`remove`),t)}function Lh(e,t){return!e?.user_selected||t!==`rejected`&&t!==`ignored`?null:{confirmation:`${e.title} is being used for next variation. Marking it ${t} will remove it from next variation.`,clearsSelection:!0}}var Rh=Object.defineProperty,zh=(e,t,n)=>t in e?Rh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Bh=(e,t)=>{for(var n in t)Rh(e,n,{get:t[n],enumerable:!0})},Vh=(e,t,n)=>zh(e,typeof t==`symbol`?t:t+``,n),Hh={};Bh(Hh,{Graph:()=>Gh,alg:()=>rg,json:()=>Qh,version:()=>Zh});var Uh=Object.defineProperty,Wh=(e,t)=>{for(var n in t)Uh(e,n,{get:t[n],enumerable:!0})},Gh=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected=`directed`in e?e.directed:!0,this._isMultigraph=`multigraph`in e?e.multigraph:!1,this._isCompound=`compound`in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[`\0`]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e==`function`?this._defaultNodeLabelFn=e:this._defaultNodeLabelFn=()=>e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(e=>{t===void 0?this.setNode(e):this.setNode(e,t)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=`\0`,this._children[e]={},this._children[`\0`][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(e=>{this.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw Error(`Cannot set parent in a non-compound graph`);if(t===void 0)t=`\0`;else{t+=``;for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw Error(`Setting `+t+` as parent of `+e+` would create a cycle`);this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!==`\0`)return t}}children(e=`\0`){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e===`\0`)return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let t of this.successors(e))n.add(t);return Array.from(n.values())}}isLeaf(e){let t;return t=this.isDirected()?this.successors(e):this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([n,r])=>{e(n)&&t.setNode(n,r)}),Object.values(this._edgeObjs).forEach(e=>{t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,this.edge(e))});let n={},r=e=>{let i=this.parent(e);return!i||t.hasNode(i)?(n[e]=i??void 0,i??void 0):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,r(e))),t}setDefaultEdgeLabel(e){return typeof e==`function`?this._defaultEdgeLabelFn=e:this._defaultEdgeLabelFn=()=>e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((e,n)=>(t===void 0?this.setEdge(e,n):this.setEdge(e,n,t),n)),this}setEdge(e,t,n,r){let i,a,o,s,c=!1;typeof e==`object`&&e&&`v`in e?(i=e.v,a=e.w,o=e.name,arguments.length===2&&(s=t,c=!0)):(i=e,a=t,o=r,arguments.length>2&&(s=n,c=!0)),i=``+i,a=``+a,o!==void 0&&(o=``+o);let l=Jh(this._isDirected,i,a,o);if(l in this._edgeLabels)return c&&(this._edgeLabels[l]=s),this;if(o!==void 0&&!this._isMultigraph)throw Error(`Cannot set a named edge when isMultigraph = false`);this.setNode(i),this.setNode(a),this._edgeLabels[l]=c?s:this._defaultEdgeLabelFn(i,a,o);let u=Yh(this._isDirected,i,a,o);return i=u.v,a=u.w,Object.freeze(u),this._edgeObjs[l]=u,Kh(this._preds[a],i),Kh(this._sucs[i],a),this._in[a][l]=u,this._out[i][l]=u,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r==`object`?r:{label:r}}hasEdge(e,t,n){return(arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?Xh(this._isDirected,e):Jh(this._isDirected,e,t,n),i=this._edgeObjs[r];if(i){let e=i.v,t=i.w;delete this._edgeLabels[r],delete this._edgeObjs[r],qh(this._preds[t],e),qh(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(e=>e.v===t&&e.w===n||e.v===n&&e.w===t):r}};function Kh(e,t){e[t]?e[t]++:e[t]=1}function qh(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function Jh(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}return i+``+a+``+(r===void 0?`\0`:r)}function Yh(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}let o={v:i,w:a};return r&&(o.name=r),o}function Xh(e,t){return Jh(e,t.v,t.w,t.name)}var Zh=`4.0.1`,Qh={};Wh(Qh,{read:()=>ng,write:()=>$h});function $h(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:eg(e),edges:tg(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function eg(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),i={v:t};return n!==void 0&&(i.value=n),r!==void 0&&(i.parent=r),i})}function tg(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ng(e){let t=new Gh(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}var rg={};Wh(rg,{CycleException:()=>vg,bellmanFord:()=>ag,components:()=>sg,dijkstra:()=>ug,dijkstraAll:()=>fg,findCycles:()=>mg,floydWarshall:()=>gg,isAcyclic:()=>bg,postorder:()=>wg,preorder:()=>Tg,prim:()=>Eg,shortestPaths:()=>Dg,tarjan:()=>pg,topsort:()=>yg});var ig=()=>1;function ag(e,t,n,r){return og(e,String(t),n||ig,r||function(t){return e.outEdges(t)})}function og(e,t,n,r){let i={},a,o=0,s=e.nodes(),c=function(e){let t=n(e);i[e.v].distance+t<i[e.w].distance&&(i[e.w]={distance:i[e.v].distance+t,predecessor:e.v},a=!0)},l=function(){s.forEach(function(e){r(e).forEach(function(t){let n=t.v===e?t.v:t.w,r=n===t.v?t.w:t.v;c({v:n,w:r})})})};s.forEach(function(e){i[e]={distance:e===t?0:1/0,predecessor:``}});let u=s.length;for(let e=1;e<u&&(a=!1,o++,l(),a);e++);if(o===u-1&&(a=!1,l(),a))throw Error(`The graph contains a negative weight cycle`);return i}function sg(e){let t={},n=[],r;function i(n){n in t||(t[n]=!0,r.push(n),e.successors(n).forEach(i),e.predecessors(n).forEach(i))}return e.nodes().forEach(function(e){r=[],i(e),r.length&&n.push(r)}),n}var cg=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw Error(`Queue underflow`);return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let e=this._arr,i=e.length;return n[r]=i,e.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,i=e;n<t.length&&(i=t[n].priority<t[i].priority?n:i,r<t.length&&(i=t[r].priority<t[i].priority?r:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,i=n[e],a=n[t];n[e]=a,n[t]=i,r[a.key]=e,r[i.key]=t}},lg=()=>1;function ug(e,t,n,r){return dg(e,String(t),n||lg,r||function(t){return e.outEdges(t)})}function dg(e,t,n,r){let i={},a=new cg,o,s,c=function(e){let t=e.v===o?e.w:e.v,r=i[t],c=n(e),l=s.distance+c;if(c<0)throw Error(`dijkstra does not allow negative edge weights. Bad edge: `+e+` Weight: `+c);l<r.distance&&(r.distance=l,r.predecessor=o,a.decrease(t,l))};for(e.nodes().forEach(function(e){let n=e===t?0:1/0;i[e]={distance:n,predecessor:``},a.add(e,n)});a.size()>0&&(o=a.removeMin(),s=i[o],s.distance!==1/0);)r(o).forEach(c);return i}function fg(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=ug(e,i,t,n),r},{})}function pg(e){let t=0,n=[],r={},i=[];function a(o){let s=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(e){e in r?r[e].onStack&&(s.lowlink=Math.min(s.lowlink,r[e].index)):(a(e),s.lowlink=Math.min(s.lowlink,r[e].lowlink))}),s.lowlink===s.index){let e=[],t;do t=n.pop(),r[t].onStack=!1,e.push(t);while(o!==t);i.push(e)}}return e.nodes().forEach(function(e){e in r||a(e)}),i}function mg(e){return pg(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var hg=()=>1;function gg(e,t,n){return _g(e,t||hg,n||function(t){return e.outEdges(t)})}function _g(e,t,n){let r={},i=e.nodes();return i.forEach(function(e){r[e]={},r[e][e]={distance:0,predecessor:``},i.forEach(function(t){e!==t&&(r[e][t]={distance:1/0,predecessor:``})}),n(e).forEach(function(n){let i=n.v===e?n.w:n.v,a=t(n);r[e][i]={distance:a,predecessor:e}})}),i.forEach(function(e){let t=r[e];i.forEach(function(n){let a=r[n];i.forEach(function(n){let r=a[e],i=t[n],o=a[n],s=r.distance+i.distance;s<o.distance&&(o.distance=s,o.predecessor=i.predecessor)})})}),r}var vg=class extends Error{constructor(...e){super(...e)}};function yg(e){let t={},n={},r=[];function i(a){if(a in n)throw new vg;a in t||(n[a]=!0,t[a]=!0,e.predecessors(a).forEach(i),delete n[a],r.push(a))}if(e.sinks().forEach(i),Object.keys(t).length!==e.nodeCount())throw new vg;return r}function bg(e){try{yg(e)}catch(e){if(e instanceof vg)return!1;throw e}return!0}function xg(e,t,n,r,i){Array.isArray(t)||(t=[t]);let a=(t=>(e.isDirected()?e.successors(t):e.neighbors(t))??[]),o={};return t.forEach(function(t){if(!e.hasNode(t))throw Error(`Graph does not have node: `+t);i=Sg(e,t,n===`post`,o,a,r,i)}),i}function Sg(e,t,n,r,i,a,o){return t in r||(r[t]=!0,n||(o=a(o,t)),i(t).forEach(function(t){o=Sg(e,t,n,r,i,a,o)}),n&&(o=a(o,t))),o}function Cg(e,t,n){return xg(e,t,n,function(e,t){return e.push(t),e},[])}function wg(e,t){return Cg(e,t,`post`)}function Tg(e,t){return Cg(e,t,`pre`)}function Eg(e,t){let n=new Gh,r={},i=new cg,a;function o(e){let n=e.v===a?e.w:e.v,o=i.priority(n);if(o!==void 0){let s=t(e);s<o&&(r[n]=a,i.decrease(n,s))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(e){i.add(e,1/0),n.setNode(e)}),i.decrease(e.nodes()[0],0);let s=!1;for(;i.size()>0;){if(a=i.removeMin(),a in r)n.setEdge(a,r[a]);else{if(s)throw Error(`Input graph is not connected: `+e);s=!0}e.nodeEdges(a).forEach(o)}return n}function Dg(e,t,n,r){return Og(e,t,n,r??(t=>e.outEdges(t)??[]))}function Og(e,t,n,r){if(n===void 0)return ug(e,t,n,r);let i=!1,a=e.nodes();for(let o=0;o<a.length;o++){let s=r(a[o]);for(let e=0;e<s.length;e++){let t=s[e],r=t.v===a[o]?t.v:t.w;n({v:r,w:r===t.v?t.w:t.v})<0&&(i=!0)}if(i)return ag(e,t,n,r)}return ug(e,t,n,r)}function kg(e,t,n,r){let i=r;for(;e.hasNode(i);)i=Gg(r);return n.dummy=t,e.setNode(i,n),i}function Ag(e){let t=new Gh().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},i=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})}),t}function jg(e){let t=new Gh({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Mg(e,t){let n=e.x,r=e.y,i=t.x-n,a=t.y-r,o=e.width/2,s=e.height/2;if(!i&&!a)throw Error(`Not possible to find intersection inside of the rectangle`);let c,l;return Math.abs(a)*o>Math.abs(i)*s?(a<0&&(s=-s),c=s*i/a,l=s):(i<0&&(o=-o),c=o,l=o*a/i),{x:n+c,y:r+l}}function Ng(e){let t=Kg(Bg(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),i=r.rank;i!==void 0&&(t[i]||(t[i]=[]),t[i][r.order]=n)}),t}function Pg(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MAX_VALUE:n}),n=zg(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,`rank`)&&(r.rank-=n)})}function Fg(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>e!==void 0),n=zg(Math.min,t),r=[];e.nodes().forEach(t=>{let i=e.node(t).rank-n;r[i]||(r[i]=[]),r[i].push(t)});let i=0,a=e.graph().nodeRankFactor;Array.from(r).forEach((t,n)=>{t===void 0&&n%a!==0?--i:t!==void 0&&i&&t.forEach(t=>e.node(t).rank+=i)})}function Ig(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),kg(e,`border`,i,t)}function Lg(e,t=Rg){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}var Rg=65535;function zg(e,t){return t.length>Rg?e(...Lg(t).map(t=>e(...t))):e(...t)}function Bg(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MIN_VALUE:n});return zg(Math.max,t)}function Vg(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}function Hg(e,t){let n=Date.now();try{return t()}finally{console.log(e+` time: `+(Date.now()-n)+`ms`)}}function Ug(e,t){return t()}var Wg=0;function Gg(e){return e+(``+ ++Wg)}function Kg(e,t,n=1){t??(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);let i=[];for(let t=e;r(t);t+=n)i.push(t);return i}function qg(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function Jg(e,t){let n;return n=typeof t==`string`?e=>e[t]:t,Object.entries(e).reduce((e,[t,r])=>(e[t]=n(r,t),e),{})}function Yg(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}var Xg=`\0`,Zg=class{constructor(){Vh(this,`_sentinel`);let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Qg(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Qg(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,$g)),n=n._prev;return`[`+e.join(`, `)+`]`}};function Qg(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function $g(e,t){if(e!==`_next`&&e!==`_prev`)return t}var e_=Zg,t_=()=>1;function n_(e,t){if(e.nodeCount()<=1)return[];let n=a_(e,t||t_);return r_(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function r_(e,t,n){let r=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)i_(e,t,n,o);for(;o=i.dequeue();)i_(e,t,n,o);if(e.nodeCount()){for(let i=t.length-2;i>0;--i)if(o=t[i]?.dequeue(),o){r=r.concat(i_(e,t,n,o,!0)||[]);break}}}return r}function i_(e,t,n,r,i){let a=[],o=i?a:void 0;return(e.inEdges(r.v)||[]).forEach(r=>{let o=e.edge(r),s=e.node(r.v);i&&a.push({v:r.v,w:r.w}),s.out-=o,o_(t,n,s)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),a=r.w,o=e.node(a);o.in-=i,o_(t,n,o)}),e.removeNode(r.v),o}function a_(e,t){let n=new Gh,r=0,i=0;e.nodes().forEach(e=>{n.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let a=n.edge(e.v,e.w)||0,o=t(e),s=a+o;n.setEdge(e.v,e.w,s);let c=n.node(e.v),l=n.node(e.w);i=Math.max(i,c.out+=o),r=Math.max(r,l.in+=o)});let a=s_(i+r+3).map(()=>new e_),o=r+1;return n.nodes().forEach(e=>{o_(a,o,n.node(e))}),{graph:n,buckets:a,zeroIdx:o}}function o_(e,t,n){var r,i,a;n.out?n.in?(a=e[n.out-n.in+t])==null||a.enqueue(n):(i=e[e.length-1])==null||i.enqueue(n):(r=e[0])==null||r.enqueue(n)}function s_(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function c_(e){(e.graph().acyclicer===`greedy`?n_(e,t(e)):l_(e)).forEach(t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,Gg(`rev`))});function t(e){return t=>e.edge(t).weight}}function l_(e){let t=[],n={},r={};function i(a){Object.hasOwn(r,a)||(r[a]=!0,n[a]=!0,e.outEdges(a).forEach(e=>{Object.hasOwn(n,e.w)?t.push(e):i(e.w)}),delete n[a])}return e.nodes().forEach(i),t}function u_(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function d_(e){e.graph().dummyChains=[],e.edges().forEach(t=>f_(e,t))}function f_(e,t){let n=t.v,r=e.node(n).rank,i=t.w,a=e.node(i).rank,o=t.name,s=e.edge(t),c=s.labelRank;if(a===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r<a;++d,++r)s.points=[],u={width:0,height:0,edgeLabel:s,edgeObj:t,rank:r},l=kg(e,`edge`,u,`_d`),r===c&&(u.width=s.width,u.height=s.height,u.dummy=`edge-label`,u.labelpos=s.labelpos),e.setEdge(n,l,{weight:s.weight},o),d===0&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,i,{weight:s.weight},o)}function p_(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,i;for(e.setEdge(n.edgeObj,r);n.dummy;)i=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy===`edge-label`&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=i,n=e.node(t)})}function m_(e){let t={};function n(r){let i=e.node(r);if(Object.hasOwn(t,r))return i.rank;t[r]=!0;let a=e.outEdges(r),o=a?a.map(t=>t==null?1/0:n(t.w)-e.edge(t).minlen):[],s=zg(Math.min,o);return s===1/0&&(s=0),i.rank=s}e.sources().forEach(n)}function h_(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var g_=__;function __(e){let t=new Gh({directed:!1}),n=e.nodes();if(n.length===0)throw Error(`Graph must have at least one node`);let r=n[0],i=e.nodeCount();t.setNode(r,{});let a,o;for(;v_(t,e)<i&&(a=y_(t,e),a);)o=t.hasNode(a.v)?h_(e,a):-h_(e,a),b_(t,e,o);return t}function v_(e,t){function n(r){let i=t.nodeEdges(r);i&&i.forEach(i=>{let a=i.v,o=r===a?i.w:a;!e.hasNode(o)&&!h_(t,i)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function y_(e,t){return t.edges().reduce((n,r)=>{let i=1/0;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=h_(t,r)),i<n[0]?[i,r]:n},[1/0,null])[1]}function b_(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:x_,postorder:S_}=rg,C_=w_;w_.initLowLimValues=O_,w_.initCutValues=T_,w_.calcCutValue=D_,w_.leaveEdge=A_,w_.enterEdge=j_,w_.exchangeEdges=M_;function w_(e){e=Ag(e),m_(e);let t=g_(e);O_(t),T_(t,e);let n,r;for(;n=A_(t);)r=j_(t,e,n),M_(t,e,n,r)}function T_(e,t){let n=S_(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>E_(e,t,n))}function E_(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=D_(e,t,n)}function D_(e,t,n){let r=e.node(n).parent,i=!0,a=t.edge(n,r),o=0;a||=(i=!1,t.edge(r,n)),o=a.weight;let s=t.nodeEdges(n);return s&&s.forEach(a=>{let s=a.v===n,c=s?a.w:a.v;if(c!==r){let r=s===i,l=t.edge(a).weight;if(o+=r?l:-l,P_(e,n,c)){let t=e.edge(n,c).cutvalue;o+=r?-t:t}}}),o}function O_(e,t){arguments.length<2&&(t=e.nodes()[0]),k_(e,{},1,t)}function k_(e,t,n,r,i){let a=n,o=e.node(r);t[r]=!0;let s=e.neighbors(r);return s&&s.forEach(i=>{Object.hasOwn(t,i)||(n=k_(e,t,n,i,r))}),o.low=a,o.lim=n++,i?o.parent=i:delete o.parent,n}function A_(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function j_(e,t,n){let r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);let a=e.node(r),o=e.node(i),s=a,c=!1;return a.lim>o.lim&&(s=o,c=!0),t.edges().filter(t=>c===F_(e,e.node(t.v),s)&&c!==F_(e,e.node(t.w),s)).reduce((e,n)=>h_(t,n)<h_(t,e)?n:e)}function M_(e,t,n,r){let i=n.v,a=n.w;e.removeEdge(i,a),e.setEdge(r.v,r.w,{}),O_(e),T_(e,t),N_(e,t)}function N_(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=x_(e,[n]);r=r.slice(1),r.forEach(n=>{let r=e.node(n).parent,i=t.edge(n,r),a=!1;i||(i=t.edge(r,n),a=!0),t.node(n).rank=t.node(r).rank+(a?i.minlen:-i.minlen)})}function P_(e,t,n){return e.hasEdge(t,n)}function F_(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var I_=L_;function L_(e){let t=e.graph().ranker;if(typeof t==`function`)return t(e);switch(t){case`network-simplex`:B_(e);break;case`tight-tree`:z_(e);break;case`longest-path`:R_(e);break;case`none`:break;default:B_(e)}}var R_=m_;function z_(e){m_(e),g_(e)}function B_(e){C_(e)}var V_=H_;function H_(e){let t=W_(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,a=U_(e,t,i.v,i.w),o=a.path,s=a.lca,c=0,l=o[c],u=!0;for(;n!==i.w;){if(r=e.node(n),u){for(;(l=o[c])!==s&&e.node(l).maxRank<r.rank;)c++;l===s&&(u=!1)}if(!u){for(;c<o.length-1&&e.node(o[c+1]).minRank<=r.rank;)c++;l=o[c]}l!==void 0&&e.setParent(n,l),n=e.successors(n)[0]}})}function U_(e,t,n,r){let i=[],a=[],o=Math.min(t[n].low,t[r].low),s=Math.max(t[n].lim,t[r].lim),c;c=n;do c=e.parent(c),i.push(c);while(c&&(t[c].low>o||s>t[c].lim));let l=c,u=r;for(;(u=e.parent(u))!==l;)a.push(u);return{path:i.concat(a.reverse()),lca:l}}function W_(e){let t={},n=0;function r(i){let a=n;e.children(i).forEach(r),t[i]={low:a,lim:n++}}return e.children(Xg).forEach(r),t}function G_(e){let t=kg(e,`root`,{},`_root`),n=q_(e),r=Object.values(n),i=zg(Math.max,r)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let o=J_(e)+1;e.children(Xg).forEach(r=>K_(e,t,a,o,i,n,r)),e.graph().nodeRankFactor=a}function K_(e,t,n,r,i,a,o){let s=e.children(o);if(!s.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ig(e,`_bt`),l=Ig(e,`_bb`),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,s.forEach(s=>{K_(e,t,n,r,i,a,s);let u=e.node(s),d=u.borderTop?u.borderTop:s,f=u.borderBottom?u.borderBottom:s,p=u.borderTop?r:2*r,m=d===f?i-(a[o]??0)+1:1;e.setEdge(c,d,{weight:p,minlen:m,nestingEdge:!0}),e.setEdge(f,l,{weight:p,minlen:m,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:i+(a[o]??0)})}function q_(e){let t={};function n(r,i){let a=e.children(r);a&&a.length&&a.forEach(e=>n(e,i+1)),t[r]=i}return e.children(Xg).forEach(e=>n(e,1)),t}function J_(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function Y_(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var X_=Z_;function Z_(e){function t(n){let r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(i,`minRank`)){i.borderLeft=[],i.borderRight=[];for(let t=i.minRank,r=i.maxRank+1;t<r;++t)Q_(e,`borderLeft`,`_bl`,n,i,t),Q_(e,`borderRight`,`_br`,n,i,t)}}e.children(Xg).forEach(t)}function Q_(e,t,n,r,i,a){let o={width:0,height:0,rank:a,borderType:t},s=i[t][a-1],c=kg(e,`border`,o,n);i[t][a]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}function $_(e){let t=e.graph().rankdir?.toLowerCase();(t===`lr`||t===`rl`)&&tv(e)}function ev(e){let t=e.graph().rankdir?.toLowerCase();(t===`bt`||t===`rl`)&&rv(e),(t===`lr`||t===`rl`)&&(av(e),tv(e))}function tv(e){e.nodes().forEach(t=>nv(e.node(t))),e.edges().forEach(t=>nv(e.edge(t)))}function nv(e){let t=e.width;e.width=e.height,e.height=t}function rv(e){e.nodes().forEach(t=>iv(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(iv),Object.hasOwn(r,`y`)&&iv(r)})}function iv(e){e.y=-e.y}function av(e){e.nodes().forEach(t=>ov(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(ov),Object.hasOwn(r,`x`)&&ov(r)})}function ov(e){let t=e.x;e.x=e.y,e.y=t}function sv(e){let t={},n=e.nodes().filter(t=>!e.children(t).length),r=n.map(t=>e.node(t).rank),i=Kg(zg(Math.max,r)+1).map(()=>[]);function a(n){if(t[n])return;t[n]=!0;let r=e.node(n);i[r.rank].push(n);let o=e.successors(n);o&&o.forEach(a)}return n.sort((t,n)=>e.node(t).rank-e.node(n).rank).forEach(a),i}function cv(e,t){let n=0;for(let r=1;r<t.length;++r)n+=lv(e,t[r-1],t[r]);return n}function lv(e,t,n){let r=Yg(n,n.map((e,t)=>t)),i=t.flatMap(t=>{let n=e.outEdges(t);return n?n.map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos):[]}),a=1;for(;a<n.length;)a<<=1;let o=2*a-1;--a;let s=Array(o).fill(0),c=0;return i.forEach(e=>{let t=e.pos+a;s[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=s[t+1]),t=t-1>>1,s[t]+=e.weight;c+=e.weight*n}),c}function uv(e,t=[]){return t.map(t=>{let n=e.inEdges(t);if(!n||!n.length)return{v:t};{let r=n.reduce((t,n)=>{let r=e.edge(n),i=e.node(n.v);return{sum:t.sum+r.weight*i.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}})}function dv(e,t){let n={};return e.forEach((e,t)=>{let r={indegree:0,in:[],out:[],vs:[e.v],i:t};e.barycenter!==void 0&&(r.barycenter=e.barycenter,r.weight=e.weight),n[e.v]=r}),t.edges().forEach(e=>{let t=n[e.v],r=n[e.w];t!==void 0&&r!==void 0&&(r.indegree++,t.out.push(r))}),fv(Object.values(n).filter(e=>!e.indegree))}function fv(e){let t=[];function n(e){return t=>{t.merged||(t.barycenter===void 0||e.barycenter===void 0||t.barycenter>=e.barycenter)&&pv(e,t)}}function r(t){return n=>{n.in.push(t),--n.indegree===0&&e.push(n)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter(e=>!e.merged).map(e=>qg(e,[`vs`,`i`,`barycenter`,`weight`]))}function pv(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function mv(e,t){let n=Vg(e,e=>Object.hasOwn(e,`barycenter`)),r=n.lhs,i=n.rhs.sort((e,t)=>t.i-e.i),a=[],o=0,s=0,c=0;r.sort(gv(!!t)),c=hv(a,i,c),r.forEach(e=>{c+=e.vs.length,a.push(e.vs),o+=e.barycenter*e.weight,s+=e.weight,c=hv(a,i,c)});let l={vs:a.flat(1)};return s&&(l.barycenter=o/s,l.weight=s),l}function hv(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function gv(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function _v(e,t,n,r){let i=e.children(t),a=e.node(t),o=a?a.borderLeft:void 0,s=a?a.borderRight:void 0,c={};o&&(i=i.filter(e=>e!==o&&e!==s));let l=uv(e,i);l.forEach(t=>{if(e.children(t.v).length){let i=_v(e,t.v,n,r);c[t.v]=i,Object.hasOwn(i,`barycenter`)&&yv(t,i)}});let u=dv(l,n);vv(u,c);let d=mv(u,r);if(o&&s){d.vs=[o,d.vs,s].flat(1);let t=e.predecessors(o);if(t&&t.length){let n=e.node(t[0]),r=e.predecessors(s),i=e.node(r[0]);Object.hasOwn(d,`barycenter`)||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+n.order+i.order)/(d.weight+2),d.weight+=2}}return d}function vv(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}function yv(e,t){e.barycenter===void 0?(e.barycenter=t.barycenter,e.weight=t.weight):(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight)}function bv(e,t,n,r){r||=e.nodes();let i=xv(e),a=new Gh({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let o=e.node(r),s=e.parent(r);if(o.rank===t||o.minRank<=t&&t<=o.maxRank){a.setNode(r),a.setParent(r,s||i);let c=e[n](r);c&&c.forEach(t=>{let n=t.v===r?t.w:t.v,i=a.edge(n,r),o=i===void 0?0:i.weight;a.setEdge(n,r,{weight:e.edge(t).weight+o})}),Object.hasOwn(o,`minRank`)&&a.setNode(r,{borderLeft:o.borderLeft[t],borderRight:o.borderRight[t]})}}),a}function xv(e){let t;for(;e.hasNode(t=Gg(`_root`)););return t}function Sv(e,t,n){let r={},i;n.forEach(n=>{let a=e.parent(n),o,s;for(;a;){if(o=e.parent(a),o?(s=r[o],r[o]=a):(s=i,i=a),s&&s!==a){t.setEdge(s,a);return}a=o}})}function Cv(e,t={}){if(typeof t.customOrder==`function`){t.customOrder(e,Cv);return}let n=Bg(e),r=wv(e,Kg(1,n+1),`inEdges`),i=wv(e,Kg(n-1,-1,-1),`outEdges`),a=sv(e);if(Ev(e,a),t.disableOptimalOrderHeuristic)return;let o=1/0,s,c=t.constraints||[];for(let t=0,n=0;n<4;++t,++n){Tv(t%2?r:i,t%4>=2,c),a=Ng(e);let l=cv(e,a);l<o?(n=0,s=Object.assign({},a),o=l):l===o&&(s=structuredClone(a))}Ev(e,s)}function wv(e,t,n){let r=new Map,i=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(let t of e.nodes()){let n=e.node(t);if(typeof n.rank==`number`&&i(n.rank,t),typeof n.minRank==`number`&&typeof n.maxRank==`number`)for(let e=n.minRank;e<=n.maxRank;e++)e!==n.rank&&i(e,t)}return t.map(function(t){return bv(e,t,n,r.get(t)||[])})}function Tv(e,t,n){let r=new Gh;e.forEach(function(e){n.forEach(e=>r.setEdge(e.left,e.right));let i=e.graph().root,a=_v(e,i,r,t);a.vs.forEach((t,n)=>e.node(t).order=n),Sv(e,r,a.vs)})}function Ev(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function Dv(e,t){let n={};function r(t,r){let i=0,a=0,o=t.length,s=r[r.length-1];return r.forEach((t,c)=>{let l=kv(e,t),u=l?e.node(l).order:o;(l||t===s)&&(r.slice(a,c+1).forEach(t=>{let r=e.predecessors(t);r&&r.forEach(r=>{let a=e.node(r),o=a.order;(o<i||u<o)&&!(a.dummy&&e.node(t).dummy)&&Av(n,r,t)})}),a=c+1,i=u)}),r}return t.length&&t.reduce(r),n}function Ov(e,t){let n={};function r(t,r,i,a,o){Kg(r,i).forEach(r=>{let i=t[r];if(i!==void 0&&e.node(i).dummy){let t=e.predecessors(i);t&&t.forEach(t=>{if(t===void 0)return;let r=e.node(t);r.dummy&&(r.order<a||r.order>o)&&Av(n,t,i)})}})}function i(t,n){let i=-1,a=-1,o=0;return n.forEach((s,c)=>{if(e.node(s).dummy===`border`){let t=e.predecessors(s);if(t&&t.length){let s=t[0];if(s===void 0)return;a=e.node(s).order,r(n,o,c,i,a),o=c,i=a}}r(n,o,n.length,a,t.length)}),n}return t.length&&t.reduce(i),n}function kv(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}function Av(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function jv(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function Mv(e,t,n,r){let i={},a={},o={};return t.forEach(e=>{e.forEach((e,t)=>{i[e]=e,a[e]=e,o[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let s=r(e);if(s&&s.length){let r=s.sort((e,t)=>{let n=o[e],r=o[t];return(n===void 0?0:n)-(r===void 0?0:r)}),c=(r.length-1)/2;for(let s=Math.floor(c),l=Math.ceil(c);s<=l;++s){let c=r[s];if(c===void 0)continue;let l=o[c];if(l!==void 0&&a[e]===e&&t<l&&!jv(n,e,c)){let n=i[c];n!==void 0&&(a[c]=e,a[e]=i[e]=n,t=l)}}}})}),{root:i,align:a}}function Nv(e,t,n,r,i=!1){let a={},o=Pv(e,t,n,i),s=i?`borderLeft`:`borderRight`;function c(e,t){let n=o.nodes().slice(),r={},i=n.pop();for(;i;){if(r[i])e(i);else{r[i]=!0,n.push(i);for(let e of t(i))n.push(e)}i=n.pop()}}function l(e){let t=o.inEdges(e);t?a[e]=t.reduce((e,t)=>{let n=a[t.v]??0,r=o.edge(t);return Math.max(e,n+(r===void 0?0:r))},0):a[e]=0}function u(t){let n=o.outEdges(t),r=1/0;n&&(r=n.reduce((e,t)=>{let n=a[t.w],r=o.edge(t);return Math.min(e,(n===void 0?0:n)-(r===void 0?0:r))},1/0));let i=e.node(t);r!==1/0&&i.borderType!==s&&(a[t]=Math.max(a[t]===void 0?0:a[t],r))}function d(e){return o.predecessors(e)||[]}function f(e){return o.successors(e)||[]}return c(l,d),c(u,f),Object.keys(r).forEach(e=>{let t=n[e];t!==void 0&&(a[e]=a[t]??0)}),a}function Pv(e,t,n,r){let i=new Gh,a=e.graph(),o=zv(a.nodesep,a.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let a=n[t];if(a!==void 0){if(i.setNode(a),r!==void 0){let s=n[r];if(s!==void 0){let n=i.edge(s,a);i.setEdge(s,a,Math.max(o(e,t,r),n||0))}}r=t}})}),i}function Fv(e,t){return Object.values(t).reduce((t,n)=>{let r=-1/0,i=1/0;Object.entries(n).forEach(([t,n])=>{let a=Bv(e,t)/2;r=Math.max(n+a,r),i=Math.min(n-a,i)});let a=r-i;return a<t[0]&&(t=[a,n]),t},[1/0,null])[1]}function Iv(e,t){let n=Object.values(t),r=zg(Math.min,n),i=zg(Math.max,n);[`u`,`d`].forEach(n=>{[`l`,`r`].forEach(a=>{let o=n+a,s=e[o];if(!s||s===t)return;let c=Object.values(s),l=r-zg(Math.min,c);a!==`l`&&(l=i-zg(Math.max,c)),l&&(e[o]=Jg(s,e=>e+l))})})}function Lv(e,t=void 0){let n=e.ul;return n?Jg(n,(n,r)=>{if(t){let n=e[t.toLowerCase()];if(n&&n[r]!==void 0)return n[r]}let i=Object.values(e).map(e=>{let t=e[r];return t===void 0?0:t}).sort((e,t)=>e-t);return((i[1]??0)+(i[2]??0))/2}):{}}function Rv(e){let t=Ng(e),n=Object.assign(Dv(e,t),Ov(e,t)),r={},i;return[`u`,`d`].forEach(a=>{i=a===`u`?t:Object.values(t).reverse(),[`l`,`r`].forEach(t=>{t===`r`&&(i=i.map(e=>Object.values(e).reverse()));let o=Mv(e,i,n,t=>(a===`u`?e.predecessors(t):e.successors(t))||[]),s=Nv(e,i,o.root,o.align,t===`r`);t===`r`&&(s=Jg(s,e=>-e)),r[a+t]=s})}),Iv(r,Fv(e,r)),Lv(r,e.graph().align)}function zv(e,t,n){return(r,i,a)=>{let o=r.node(i),s=r.node(a),c=0,l;if(c+=o.width/2,Object.hasOwn(o,`labelpos`))switch(o.labelpos.toLowerCase()){case`l`:l=-o.width/2;break;case`r`:l=o.width/2;break}if(l&&(c+=n?l:-l),l=void 0,c+=(o.dummy?t:e)/2,c+=(s.dummy?t:e)/2,c+=s.width/2,Object.hasOwn(s,`labelpos`))switch(s.labelpos.toLowerCase()){case`l`:l=s.width/2;break;case`r`:l=-s.width/2;break}return l&&(c+=n?l:-l),c}}function Bv(e,t){return e.node(t).width}function Vv(e){e=jg(e),Hv(e),Object.entries(Rv(e)).forEach(([t,n])=>e.node(t).x=n)}function Hv(e){let t=Ng(e),n=e.graph(),r=n.ranksep,i=n.rankalign,a=0;t.forEach(t=>{let n=t.reduce((t,n)=>{let r=e.node(n).height??0;return t>r?t:r},0);t.forEach(t=>{let r=e.node(t);i===`top`?r.y=a+r.height/2:i===`bottom`?r.y=a+n-r.height/2:r.y=a+n/2}),a+=n+r})}function Uv(e,t={}){let n=t.debugTiming?Hg:Ug;return n(`layout`,()=>{let r=n(` buildLayoutGraph`,()=>ey(e));return n(` runLayout`,()=>Wv(r,n,t)),n(` updateInputGraph`,()=>Gv(e,r)),r})}function Wv(e,t,n){t(` makeSpaceForEdgeLabels`,()=>ty(e)),t(` removeSelfEdges`,()=>uy(e)),t(` acyclic`,()=>c_(e)),t(` nestingGraph.run`,()=>G_(e)),t(` rank`,()=>I_(jg(e))),t(` injectEdgeLabelProxies`,()=>ny(e)),t(` removeEmptyRanks`,()=>Fg(e)),t(` nestingGraph.cleanup`,()=>Y_(e)),t(` normalizeRanks`,()=>Pg(e)),t(` assignRankMinMax`,()=>ry(e)),t(` removeEdgeLabelProxies`,()=>iy(e)),t(` normalize.run`,()=>d_(e)),t(` parentDummyChains`,()=>V_(e)),t(` addBorderSegments`,()=>X_(e)),t(` order`,()=>Cv(e,n)),t(` insertSelfEdges`,()=>dy(e)),t(` adjustCoordinateSystem`,()=>$_(e)),t(` position`,()=>Vv(e)),t(` positionSelfEdges`,()=>fy(e)),t(` removeBorderNodes`,()=>ly(e)),t(` normalize.undo`,()=>p_(e)),t(` fixupEdgeLabelCoords`,()=>sy(e)),t(` undoCoordinateSystem`,()=>ev(e)),t(` translateGraph`,()=>ay(e)),t(` assignNodeIntersects`,()=>oy(e)),t(` reversePoints`,()=>cy(e)),t(` acyclic.undo`,()=>u_(e))}function Gv(e,t){e.nodes().forEach(n=>{let r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,r.order=i.order,r.rank=i.rank,t.children(n).length&&(r.width=i.width,r.height=i.height))}),e.edges().forEach(n=>{let r=e.edge(n),i=t.edge(n);r.points=i.points,Object.hasOwn(i,`x`)&&(r.x=i.x,r.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var Kv=[`nodesep`,`edgesep`,`ranksep`,`marginx`,`marginy`],qv={ranksep:50,edgesep:20,nodesep:50,rankdir:`TB`,rankalign:`center`},Jv=[`acyclicer`,`ranker`,`rankdir`,`align`,`rankalign`],Yv=[`width`,`height`,`rank`],Xv={width:0,height:0},Zv=[`minlen`,`weight`,`width`,`height`,`labeloffset`],Qv={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:`r`},$v=[`labelpos`];function ey(e){let t=new Gh({multigraph:!0,compound:!0}),n=my(e.graph());return t.setGraph(Object.assign({},qv,py(n,Kv),qg(n,Jv))),e.nodes().forEach(n=>{let r=py(my(e.node(n)),Yv);Object.keys(Xv).forEach(e=>{r[e]===void 0&&(r[e]=Xv[e])}),t.setNode(n,r);let i=e.parent(n);i!==void 0&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=my(e.edge(n));t.setEdge(n,Object.assign({},Qv,py(r,Zv),qg(r,$v)))}),t}function ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!==`c`&&(t.rankdir===`TB`||t.rankdir===`BT`?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function ny(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);kg(e,`edge-proxy`,{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},`_ep`)}})}function ry(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function iy(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`edge-proxy`){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function ay(e){let t=1/0,n=0,r=1/0,i=0,a=e.graph(),o=a.marginx||0,s=a.marginy||0;function c(e){let a=e.x,o=e.y,s=e.width,c=e.height;t=Math.min(t,a-s/2),n=Math.max(n,a+s/2),r=Math.min(r,o-c/2),i=Math.max(i,o+c/2)}e.nodes().forEach(t=>c(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);Object.hasOwn(n,`x`)&&c(n)}),t-=o,r-=s,e.nodes().forEach(n=>{let i=e.node(n);i.x-=t,i.y-=r}),e.edges().forEach(n=>{let i=e.edge(n);i.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(i,`x`)&&(i.x-=t),Object.hasOwn(i,`y`)&&(i.y-=r)}),a.width=n-t+o,a.height=i-r+s}function oy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),i=e.node(t.w),a,o;n.points?(a=n.points[0],o=n.points[n.points.length-1]):(n.points=[],a=i,o=r),n.points.unshift(Mg(r,a)),n.points.push(Mg(i,o))})}function sy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,`x`))switch((n.labelpos===`l`||n.labelpos===`r`)&&(n.width-=n.labeloffset),n.labelpos){case`l`:n.x-=n.width/2+n.labeloffset;break;case`r`:n.x+=n.width/2+n.labeloffset;break}})}function cy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function ly(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),a=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-a.x),n.height=Math.abs(i.y-r.y),n.x=a.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy===`border`&&e.removeNode(t)})}function uy(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||=[],n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function dy(e){Ng(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);i.order=r+n,(i.selfEdges||[]).forEach(t=>{kg(e,`selfedge`,{width:t.label.width,height:t.label.height,rank:i.rank,order:r+ ++n,e:t.e,label:t.label},`_se`)}),delete i.selfEdges})})}function fy(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`selfedge`){let r=n,i=e.node(r.e.v),a=i.x+i.width/2,o=i.y,s=n.x-a,c=i.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:a+2*s/3,y:o-c},{x:a+5*s/6,y:o-c},{x:a+s,y:o},{x:a+5*s/6,y:o+c},{x:a+2*s/3,y:o+c}],r.label.x=n.x,r.label.y=n.y}})}function py(e,t){return Jg(qg(e,t),Number)}function my(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{typeof e==`string`&&(e=e.toLowerCase()),t[e]=n}),t}var hy=212,gy=164;function _y(e,t,n=`LR`,r=!0){if(!e)return{nodes:[],edges:[]};let i=xy(e,n),a=vy(n),o=by(e,t),s=e.nodes.map(n=>({id:n.asset_id,initialHeight:gy,initialWidth:hy,measured:{height:gy,width:hy},type:`assetNode`,height:gy,position:n.position||i.get(n.asset_id)||{x:0,y:0},sourcePosition:a.source,targetPosition:a.target,width:hy,data:{...n,active:n.asset_id===t,focusRole:o.roles.get(n.asset_id)||`none`,root:n.asset_id===e.root_asset_id,sourcePosition:a.source,targetPosition:a.target}})),c=new Map(e.nodes.map(e=>[e.asset_id,e.title]));return{nodes:s,edges:e.edges.map(t=>{let n=t.summary?`lineage-edge-summary`:``,i=[o.edgeClasses.get(t.id),n].filter(Boolean).join(` `)||void 0,a=`${c.get(t.parent_asset_id)||t.parent_asset_id} to ${c.get(t.child_asset_id)||t.child_asset_id}`;return{ariaLabel:t.summary?`${a}: ${t.summary}`:a,ariaRole:`button`,className:i,domAttributes:{"aria-keyshortcuts":`Enter Space`},focusable:!0,id:t.id,markerEnd:{type:Bs.ArrowClosed},source:t.parent_asset_id,target:t.child_asset_id,type:`smoothstep`,animated:e.selected.includes(t.child_asset_id),...t.summary&&r?{label:t.summary,labelBgBorderRadius:4,labelBgPadding:[5,3],labelShowBg:!0}:{}}})}}function vy(e){return{BT:{source:Q.Top,target:Q.Bottom},LR:{source:Q.Right,target:Q.Left},RL:{source:Q.Left,target:Q.Right},TB:{source:Q.Bottom,target:Q.Top}}[e]}function yy(e,t=`LR`){if(!e)return`lineage-empty`;let n=e.nodes.map(e=>e.asset_id).sort().join(`,`),r=e.edges.map(e=>e.id).sort().join(`,`);return`${e.root_asset_id}:${t}:${n}:${r}`}function by(e,t){let n=new Map,r=new Map;if(!t||!e.nodes.some(e=>e.asset_id===t))return{edgeClasses:r,roles:n};n.set(t,`active`);for(let i of e.edges)i.child_asset_id===t&&(n.has(i.parent_asset_id)||n.set(i.parent_asset_id,`parent`),r.set(i.id,`lineage-edge-focus lineage-edge-focus-parent`)),i.parent_asset_id===t&&(n.has(i.child_asset_id)||n.set(i.child_asset_id,`child`),r.set(i.id,`lineage-edge-focus lineage-edge-focus-child`));return{edgeClasses:r,roles:n}}function xy(e,t=`LR`){let n=new Hh.Graph;n.setGraph({marginx:40,marginy:40,nodesep:80,rankdir:t,ranksep:110}),n.setDefaultEdgeLabel(()=>({}));for(let t of e.nodes)n.setNode(t.asset_id,{height:gy,width:hy});for(let t of e.edges)n.setEdge(t.parent_asset_id,t.child_asset_id);return Uv(n),new Map(e.nodes.map(e=>{let t=n.node(e.asset_id);return[e.asset_id,{x:Math.round((t?.x||hy/2)-hy/2),y:Math.round((t?.y||gy/2)-gy/2)}]}))}function Sy(e){return!!(e&&e.nodes.length>1&&e.edges.length>0)}function Cy(e){let t=new Set(e.nodes.map(e=>e.asset_id));if(t.size===0)return{stages:[]};let n=[...t].sort(Dy),r=t.has(e.root_asset_id)?e.root_asset_id:n[0],i=new Set([r]),a=new Set,o=e.edges.filter(e=>t.has(e.parent_asset_id)&&t.has(e.child_asset_id)).sort(Ey),s=[Ty(0,i,a,[r],[])];for(;i.size<t.size||o.length>0;){let e=o.findIndex(e=>i.has(e.parent_asset_id));if(e>=0){let[t]=o.splice(e,1);a.add(t.id);let n=i.has(t.child_asset_id)?[]:[t.child_asset_id];i.add(t.child_asset_id),s.push(Ty(s.length,i,a,n,[t.id]));continue}let t=n.find(e=>!i.has(e));if(t){i.add(t),s.push(Ty(s.length,i,a,[t],[]));continue}break}return{stages:s}}function wy(e,t,n,r,i){let a=n.stages,o=a.length-1,s=Math.max(-1,Math.min(r,o)),c=s>=0?a[s]:void 0,l=s<o?a[s+1]:void 0,u=new Set(c?.nodeIds||[]),d=new Set(c?.edgeIds||[]),f=new Set,p=new Set;if(l&&(i===`edge`||i===`node`))for(let e of l.enteringEdgeIds)i===`edge`?p.add(e):d.add(e);if(l&&i===`node`)for(let e of l.enteringNodeIds)f.add(e);let m=s===o&&i===`settled`,h=new Map(e.map(e=>[e.id,f.has(e.id)?`entering`:u.has(e.id)?`visible`:`future`])),g=new Map(t.map(e=>[e.id,p.has(e.id)?`entering`:d.has(e.id)?`visible`:`future`]));return{nodes:e.map(e=>({...e,data:{...e.data,replayInteractive:m,replayState:h.get(e.id)||`future`}})),edges:t.map(e=>{let t=g.get(e.id)||`future`;return{...e,className:[e.className,`lineage-edge-replay-${t}`].filter(Boolean).join(` `),domAttributes:{...e.domAttributes,"aria-hidden":t===`future`?!0:void 0},focusable:m?e.focusable:!1}}),projection:{edgeStates:g,interactive:m,nodeStates:h}}}function Ty(e,t,n,r,i){return{edgeIds:[...n],enteringEdgeIds:i,enteringNodeIds:r,index:e,nodeIds:[...t]}}function Ey(e,t){return Dy(e.created_at||``,t.created_at||``)||Dy(e.id,t.id)}function Dy(e,t){return e.localeCompare(t)}function Oy(e,t){(0,p.useEffect)(()=>{function n(n){n.key===`Escape`&&e&&t()}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function ky({asset:e,onResetLineage:t,onSelectedAsset:n,onToast:r,project:i}){let a=(0,p.useRef)(i),[o,s]=(0,p.useState)(null),[c,l]=(0,p.useState)(null),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(!1),h=o?.project===i,_=h?o:null,v=(_?.workspaces||[]).filter(e=>e.status!==`archived`),y=_?.active_workspace||v[0]||null,b=Eh(y,h&&_?.workspaces.length===0?e?.asset_id:void 0);(0,p.useEffect)(()=>{a.current=i,s(null),l(null),d(null)},[i]);let x=(0,p.useCallback)(async()=>{m(!0);try{let e=await g(`/api/lineage-workspaces?${new URLSearchParams({project:i}).toString()}`);e.project===a.current&&s(e)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}},[r,i]),S=(0,p.useCallback)(async()=>{try{let e=new URLSearchParams({project:i}),[t,n]=await Promise.all([g(`/api/lineage-workspaces/demo/media?${e.toString()}`),g(`/api/lineage-workspaces/demo/swissifier/media?${e.toString()}`)]);if(a.current!==i)return;l(t.status),d(n.status)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}},[r,i]);async function C(e){if(e){m(!0);try{let a=await g(`/api/lineage-workspaces/${encodeURIComponent(e)}/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});t(),await x(),n(a.workspace.root_asset_id),r(`ok`,`Using ${a.workspace.title}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}}async function w(e={}){m(!0);try{let a=await g(`/api/lineage-workspaces/demo/seed`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return t(),await x(),await S(),n(a.workspace?.root_asset_id||a.root_asset_id),e.quiet||r(`ok`,`Seeded demo lineage workspace`),a}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),null}finally{m(!1)}}async function T(e={}){m(!0);try{let a=await g(`/api/lineage-workspaces/demo/swissifier/seed`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return t(),await x(),await S(),n(a.workspace?.root_asset_id||a.root_asset_id),e.quiet||r(`ok`,`Seeded Swissifier demo lineage`),a}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),null}finally{m(!1)}}async function E(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/media/restore`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});await S(),r(`ok`,`Restored ${e.result.restored||0} demo media file${e.result.restored===1?``:`s`}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}async function D(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/swissifier/media/restore`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});await S(),e.result.source_required?r(`error`,`Set ${e.result.source_env||`LINEAGE_SWISSIFIER_MEDIA_DIR`} to restore Swissifier media`):r(`ok`,`Restored ${e.result.restored||0} Swissifier media file${e.result.restored===1?``:`s`}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}async function O(){m(!0);try{let e=await g(`/api/lineage-workspaces/demo/swissifier/media/download`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})});return e.result.media_status?d(e.result.media_status):await S(),e.result.download_available?(r(`ok`,`Downloaded ${e.result.restored||0} Swissifier media file${e.result.restored===1?``:`s`}`),!0):(r(`error`,`Swissifier media download is not configured`),!1)}catch(e){return r(`error`,e instanceof Error?e.message:String(e)),!1}finally{m(!1)}}async function k(){if(y&&window.confirm(`Archive ${y.title}? This hides it from the picker and clears its next-variation selection.`)){m(!0);try{await g(`/api/lineage-workspaces/${encodeURIComponent(y.id)}/archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})}),t(),await x(),await S(),r(`ok`,`Archived ${y.title}`)}catch(e){r(`error`,e instanceof Error?e.message:String(e))}finally{m(!1)}}}function A(e){s(t=>({project:i,active_workspace:e,workspaces:[e,...(t?.workspaces||[]).filter(t=>t.id!==e.id)],fetchedAt:new Date().toISOString()})),t(),n(e.root_asset_id),r(`ok`,`Using ${e.title}`)}return{activateWorkspace:C,activeWorkspace:y,archiveWorkspace:k,demoSeedStatus:c,downloadSwissifierDemoMedia:O,handleWorkspaceCreated:A,refreshDemoSeedStatus:S,refreshWorkspaces:x,restoreDemoSeedMedia:E,restoreSwissifierDemoMedia:D,seedDemoWorkspace:w,seedSwissifierDemoWorkspace:T,swissifierDemoStatus:u,visibleWorkspaces:v,workspaceLoading:f,workspaceRootAssetId:b}}function Ay(e,t,n){let r=(0,p.useRef)(!1),i=(0,p.useRef)(``),a=(0,p.useRef)(!1),o=(0,p.useRef)(``),s=(0,p.useCallback)((t=0)=>{window.setTimeout(()=>{e&&(r.current=!0,e.fitView({maxZoom:.9,padding:.32}),window.setTimeout(()=>{r.current=!1},450))},t)},[e]),c=(0,p.useCallback)(()=>{r.current||(a.current=!0)},[]);return(0,p.useEffect)(()=>{if(!t||!e)return;o.current!==t&&(o.current=t,a.current=!1,i.current=``);let r=`${t}:${n?`side-open`:`side-closed`}`;i.current!==r&&(i.current=r,a.current||s(280))},[s,e,t,n]),{fitGraph:s,markViewportInteraction:c}}function jy({actionsOpen:e,asset:t,onActionsOpenChange:n,onAssetsChanged:r,project:i,onSelectedAsset:a,onToast:o}){let[s,c]=(0,p.useState)(null),[l,u]=(0,p.useState)(null),[d,f]=(0,p.useState)(``),[m,_]=(0,p.useState)(null),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)([]),[S]=(0,p.useState)(Cm),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)([]),[D,O]=(0,p.useState)(!0),[k,A]=(0,p.useState)(null),[j,M]=(0,p.useState)(`LR`),[N,P]=(0,p.useState)(``),[F,I]=(0,p.useState)(null),[L,R]=(0,p.useState)(!1),[z,B]=(0,p.useState)(!1),[V,H]=(0,p.useState)(!1),[U,W,ee]=Bp([]),[te,ne]=Vp([]),[re,ie]=(0,p.useState)(null),[ae,oe]=(0,p.useState)(!1),[se,G]=(0,p.useState)(null),[ce,le]=(0,p.useState)(0),[K,ue]=(0,p.useState)(null),[de,q]=(0,p.useState)(-1),[fe,pe]=(0,p.useState)(`settled`),[me,J]=(0,p.useState)(!1),[he,Y]=(0,p.useState)(1),[ge,_e]=(0,p.useState)(!1),ve=(0,p.useMemo)(()=>K?Cy(K):{stages:[]},[K]),ye=ve.stages.length-1,be=!!(K&&de===ye&&fe===`settled`),xe=K&&!be?K:s,Se=s?.nodes.find(e=>e.asset_id===l)||s?.nodes[0],Ce=s?.edges.find(e=>e.id===k?.edgeId),we=s?.nodes.filter(e=>s.latest.includes(e.asset_id))||[],Te=s?.selected.map(e=>s.nodes.find(t=>t.asset_id===e)).filter(e=>!!e)||[],Ee=Te[0],De=Te.length>=3,Oe=s?.nodes.find(e=>e.asset_id===m)||null,ke=s?.nodes.find(e=>e.asset_id===v)||null,Ae=s?.nodes.find(e=>e.asset_id===F?.assetId),je=S&&!Oe&&!ke&&!Ce&&(!K||be),Me=!!(Se&&N!==(Se.selection_note||``)),Ne=(0,p.useRef)(null),Z=(0,p.useRef)([]),Pe=(0,p.useRef)(``),Fe=(0,p.useRef)(``),{fitGraph:Ie,markViewportInteraction:Le}=Ay(re,s?.root_asset_id,z),Re=(0,p.useCallback)(()=>{le(e=>e+1),I(null)},[]),ze=(0,p.useRef)(i);(0,p.useEffect)(()=>{ze.current=i},[i]);let Be=(0,p.useCallback)(()=>{u(null),Re()},[Re]),Ve=(0,p.useCallback)(()=>{c(null),u(null),w(null),ue(null),J(!1),pe(`settled`),q(-1)},[]),{activateWorkspace:He,activeWorkspace:Ue,archiveWorkspace:We,demoSeedStatus:Ge,downloadSwissifierDemoMedia:Ke,handleWorkspaceCreated:qe,refreshDemoSeedStatus:Je,refreshWorkspaces:Ye,restoreDemoSeedMedia:Xe,restoreSwissifierDemoMedia:Ze,seedDemoWorkspace:Qe,seedSwissifierDemoWorkspace:$e,swissifierDemoStatus:et,visibleWorkspaces:tt,workspaceLoading:nt,workspaceRootAssetId:rt}=ky({asset:t,onResetLineage:Ve,onSelectedAsset:a,onToast:o,project:i});Fe.current=rt,(0,p.useEffect)(()=>{Je()},[Je]);let it=(0,p.useCallback)(async(e={})=>{let t=e.rootAssetId||rt;if(!t)return!1;e.quiet||oe(!0);try{let n=new URLSearchParams({project:i}),[r,a]=await Promise.all([g(`/api/lineage/${t}?${n.toString()}`),g(`/api/agent-claims?${n.toString()}`)]);return!e.rootAssetId&&Fe.current!==t?!1:(c(r),E(a.claims),e.quiet||w(null),u(t=>Rm(t,r.nodes,r.active_asset_id,!!e.quiet)),!0)}catch(n){return!e.rootAssetId&&Fe.current!==t||!e.quiet&&ze.current===i&&(c(null),o(`error`,n instanceof Error?n.message:String(n))),!1}finally{!e.quiet&&ze.current===i&&oe(!1)}},[o,i,rt]),at=(0,p.useCallback)(()=>{!s||!Sy(s)||(Ne.current&&window.clearTimeout(Ne.current),Re(),u(null),_(null),y(null),x([]),A(null),B(!1),H(!1),ue(s),q(-1),pe(`node`),J(!0))},[Re,s]),ot=(0,p.useCallback)(()=>{ue(null),q(-1),pe(`settled`),J(!1),it({quiet:!0})},[it]),st=(0,p.useCallback)(()=>{be&&s&&ue(s),q(-1),pe(`node`),J(!0)},[be,s]),ct=(0,p.useCallback)(()=>{if(be){st();return}J(e=>!e)},[be,st]),lt=(0,p.useCallback)(e=>{J(!1),pe(`settled`),q(Math.max(0,Math.min(e,ye)))},[ye]);async function ut(){G(null),oe(!0);try{o(`ok`,`Indexed ${(await g(`/api/index/local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i})})).summary.total} assets`),await Ye(),await it()}catch(e){o(`error`,e instanceof Error?e.message:String(e))}finally{oe(!1)}}async function dt(){Re(),G(null);let e=await Qe();if(e)try{await r?.(),await it({rootAssetId:e.workspace?.root_asset_id||e.root_asset_id})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function ft(){Re(),G(`seeding`);let e=await $e();if(!e){G(`error`);return}try{G(`indexing`),await r?.(),await it({rootAssetId:e.workspace?.root_asset_id||e.root_asset_id})||G(`error`)}catch(e){G(`error`),o(`error`,e instanceof Error?e.message:String(e))}}async function pt(){G(`downloading`);let e=await Ke();G(e?`downloaded`:`error`)}async function mt(e,t,n){try{await g(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,...t})}),o(`ok`,n),await it()}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function ht(){Se&&_t(Se,N)}function gt(){Se?.user_selected&&_t(Se,N)}async function _t(e,t=e.selection_note||``){if(!e.user_selected&&De){o(`error`,`Choose at most 3 assets for next variation`);return}await mt(`/api/selection`,{assetId:e.asset_id,rootAssetId:s?.root_asset_id,mode:e.user_selected?`remove`:`add`,notes:t,confirmWrite:!0},e.user_selected?`Removed ${e.asset_id} from next variation`:`Using ${e.asset_id} for next variation`)}async function vt(e,t=e.selection_note||``){await mt(`/api/selection`,{assetId:e.asset_id,rootAssetId:s?.root_asset_id,mode:`replace`,notes:t,confirmWrite:!0},`Using only ${e.asset_id} for next variation`)}async function yt(e){if(s){if(e){await mt(`/api/selection`,{assetId:e,rootAssetId:s.root_asset_id,mode:`remove`,confirmWrite:!0},`Removed ${e} from next variation`);return}Te.length>0&&await mt(`/api/selection`,{rootAssetId:s.root_asset_id,clear:!0,confirmWrite:!0},`Removed all assets from next variation`)}}function bt(){if(Ne.current&&window.clearTimeout(Ne.current),z){B(!1),Ne.current=window.setTimeout(()=>H(!1),260);return}H(!0),window.requestAnimationFrame(()=>B(!0))}async function xt(e,t=Se?.asset_id){if(!t)return;let n=s?.nodes.find(e=>e.asset_id===t),r=Lh(n,e);r&&!window.confirm(r.confirmation)||(r&&await yt(t),mt(`/api/reviews/${t}`,{reviewState:e,confirmWrite:!0},`Marked ${t} ${e}`))}async function St(e){s&&await mt(`/api/lineage/${s.root_asset_id}/rerolls/${e.asset_id}`,{confirmWrite:!0,requestedBy:`human`},`Marked ${e.asset_id} for re-roll`)}async function Ct(e){s&&await mt(`/api/lineage/${s.root_asset_id}/rerolls/${e.asset_id}/cancel`,{confirmWrite:!0},`Cleared re-roll request for ${e.asset_id}`)}async function wt(e){if(s)try{let t=new URLSearchParams({project:i}),n=await g(`/api/lineage/${s.root_asset_id}/attempts/${e}?${t.toString()}`);x(n.attempts),y(e)}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function Tt(){y(null),x([])}function Et(e){Tt(),_(e)}async function Dt(e){if(!(!s||!v))try{let t=await g(`/api/lineage/${s.root_asset_id}/attempts/${v}/promote`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,attemptId:e.id,confirmWrite:!0})});x(t.attempts),o(`ok`,`Set v${e.attempt_index} as current`),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Ot(){!Se||!d.trim()||(await mt(`/api/lineage/link`,{childAssetId:d.trim(),confirmWrite:!0,parentAssetId:Se.asset_id},`Linked ${d.trim()} from ${Se.asset_id}`),f(``))}async function kt(e,t){if(Ce)try{let n=await g(`/api/lineage/edges/${encodeURIComponent(Ce.id)}/summary`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:e,confirmWrite:!0,expectedSummaryUpdatedAt:Ce.summary_updated_at||null,project:i,...e===`set`?{summary:t}:{}})});await it({quiet:!0}),o(`ok`,n.message),A(null)}catch(e){throw e instanceof h&&e.status===409&&e.message.includes(`Edge summary changed since it was opened`)?(await it({quiet:!0}),Error(`This edge changed elsewhere. The current label has been reloaded; review it and retry.`,{cause:e})):e}}async function At(e){if(!s)return;if(e.asset_id===s.root_asset_id){o(`error`,`Root lineage node cannot be removed. Archive this workspace or start a new lineage instead.`);return}let t=s.edges.filter(t=>t.parent_asset_id===e.asset_id).length,n=s.edges.filter(t=>t.child_asset_id===e.asset_id).length,r=t>0&&n>0?` Its ${t} child${t===1?``:`ren`} will be reconnected to its parent${n===1?``:`s`}.`:``;window.confirm(`Remove "${e.title}" from this lineage? This keeps the asset file and S3 object intact.${r}`)&&(await mt(`/api/lineage/remove-node`,{assetId:e.asset_id,rootAssetId:s.root_asset_id,confirmWrite:!0},`Removed ${e.asset_id} from lineage`),I(null),_(t=>t===e.asset_id?null:t),u(t=>t===e.asset_id?s.root_asset_id:t))}async function jt(e){if(s)try{await Fh(i,s.root_asset_id,[{assetId:e.id,x:e.position.x,y:e.position.y}])}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Mt(){if(!s)return;let e=[...xy(s,j)].map(([e,t])=>({assetId:e,...t}));Pt(e),W(t=>t.map(t=>({...t,position:e.find(e=>e.assetId===t.id)||t.position})));try{await Fh(i,s.root_asset_id,e),o(`ok`,`Tidied ${e.length} lineage nodes`),Ie(80),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function Nt(e){if(!s)return;let t=[...xy(s,e)].map(([e,t])=>({assetId:e,...t}));Pt(t),M(e),W(e=>e.map(e=>({...e,position:t.find(t=>t.assetId===e.id)||e.position})));try{await Fh(i,s.root_asset_id,t),o(`ok`,`Rotated lineage graph ${Ny(e).toLowerCase()}`),Ie(80),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}function Pt(e){let t=new Map(e.map(e=>[e.assetId,{x:e.x,y:e.y}]));c(e=>e&&{...e,nodes:e.nodes.map(e=>({...e,position:t.get(e.asset_id)||e.position}))})}async function Ft(){if(s)try{let e=new URLSearchParams({project:i});w(await g(`/api/lineage/${s.root_asset_id}/brief?${e.toString()}`))}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}async function It(e,t,n){try{await g(`/api/agent-claims/${t.id}/${e}`,{body:JSON.stringify({project:i,...n}),headers:{"Content-Type":`application/json`},method:`POST`}),o(`ok`,`Updated claim ${t.id}`),await it({quiet:!0})}catch(e){o(`error`,e instanceof Error?e.message:String(e))}}(0,p.useEffect)(()=>{Ye()},[Ye]),(0,p.useEffect)(()=>{it()},[it]),(0,p.useEffect)(()=>{rt||Ve()},[Ve,rt]),(0,p.useEffect)(()=>{if(!s)return;let e=window.setInterval(()=>void it({quiet:!0}),8e3);return()=>window.clearInterval(e)},[it,s?.root_asset_id]),(0,p.useEffect)(()=>{let e=window.matchMedia?.(`(prefers-reduced-motion: reduce)`);if(!e)return;let t=()=>_e(e.matches);return t(),e.addEventListener?.(`change`,t),()=>e.removeEventListener?.(`change`,t)},[]),(0,p.useEffect)(()=>{if(!K||!me||ye<0)return;let e=Math.min(de+1,ye);if(fe===`settled`&&de>=ye){J(!1);return}let t=ve.stages[e],n=ge?40:void 0,r=n??120/he,i=()=>{let e=t.enteringEdgeIds.length>0?`edge`:`node`;pe(e)};fe===`edge`?(r=n??320/he,i=()=>{t.enteringNodeIds.length>0?pe(`node`):(q(e),pe(`settled`))}):fe===`node`&&(r=n??200/he,i=()=>{q(e),pe(`settled`)});let a=window.setTimeout(i,r);return()=>window.clearTimeout(a)},[ge,ye,fe,me,K,he,de,ve.stages]);let Lt=(0,p.useMemo)(()=>_y(xe,l,j,D),[l,D,j,xe]),Rt=(0,p.useMemo)(()=>K&&!be?wy(Lt.nodes,Lt.edges,ve,de,fe):Lt,[Lt,be,fe,K,de,ve]),zt=(0,p.useMemo)(()=>yy(xe,j),[j,xe]);Z.current=Rt.edges;let Bt=(0,p.useCallback)(e=>{ne(t=>Ih(e,t,Z.current))},[ne]),Vt=(0,p.useCallback)(e=>{e.key===`Escape`&&Re()},[Re]);return(0,p.useEffect)(()=>{P(Se?.selection_note||``)},[Se?.asset_id,Se?.selection_note]),(0,p.useEffect)(()=>{let e=Pe.current!==zt;Pe.current=zt,W(t=>Rt.nodes.map(n=>({...n,position:e?n.position:t.find(e=>e.id===n.id)?.position||n.position}))),ne(Rt.edges)},[Rt.edges,Rt.nodes,zt,ne,W]),(0,p.useEffect)(()=>{se!==`indexing`||!s?.nodes.length||Pe.current!==zt||U.length!==s.nodes.length||G(`ready`)},[U.length,zt,s,se]),Oy(!!l,Be),(0,p.useEffect)(()=>()=>{Ne.current&&window.clearTimeout(Ne.current)},[]),(0,p.useEffect)(()=>{Ve(),G(null)},[i,Ve]),(0,X.jsxs)(`section`,{className:`lineage-view`,onKeyDownCapture:Vt,children:[(0,X.jsx)(Ph,{actionsOpen:e,activeWorkspace:Ue,closeSignal:ce,edgeSummariesVisible:D,loading:ae,graphDirection:j,demoSeedStatus:Ge,onArchiveWorkspace:()=>{G(null),We()},onActionsOpenChange:n,onFitGraph:()=>Ie(),onIndexLocal:()=>void ut(),onGraphDirection:e=>void Nt(e),onNewLineage:()=>{G(null),R(!0)},onRefreshLineage:()=>void it(),onRefreshWorkspaces:()=>void Ye(),onReplayGrowth:at,onRestoreDemoMedia:()=>void Xe(),onRestoreSwissifierMedia:()=>void Ze(),onDownloadSwissifierMedia:()=>void pt(),onEdgeSummariesVisible:()=>O(e=>!e),onSeedDemo:()=>void dt(),onSeedSwissifierDemo:()=>void ft(),onSelectWorkspace:e=>{G(null),He(e)},onTidyGraph:()=>void Mt(),onToggleNextPanel:bt,replayActive:!!K,sideOpen:z,snapshot:s,swissifierDemoStatus:et,workspaceLoading:nt,workspaceProgress:se,workspaceRootAssetId:rt,workspaces:tt}),(0,X.jsxs)(`div`,{className:`lineage-workbench`,"data-testid":`lineage-workbench`,children:[(0,X.jsxs)(`div`,{className:`lineage-canvas ${l?`focus-active`:``} ${K?`lineage-replay-active`:``} ${be?`lineage-replay-interactive`:``} ${K&&!me?`lineage-replay-paused`:``}`,style:K?{"--lineage-replay-edge-duration":`${ge?1:320/he}ms`,"--lineage-replay-node-duration":`${ge?1:200/he}ms`}:void 0,children:[K&&ve.stages.length>0&&(0,X.jsx)(ch,{atEnd:be,onClose:ot,onPlayPause:ct,onRestart:st,onScrub:lt,onSpeed:Y,playing:me,speed:he,stageIndex:de,totalStages:ve.stages.length}),(0,X.jsx)(Nm,{flowEdges:xe?te:[],flowNodes:xe?U:[],graphKey:zt,hoverPreviewsEnabled:je,loading:ae,onEdgesChange:Bt,onEdgeEdit:(e,t)=>A({edgeId:e,returnFocus:t}),onClearFocus:Be,onIndexNow:()=>void ut(),onNewLineage:()=>{G(null),R(!0)},onSeedDemo:()=>void dt(),onNodeActionMenu:(e,t,n)=>I(e?{assetId:e,x:t,y:n}:null),onNodeInspect:e=>{Re(),u(e)},onNodeOpenDetail:_,onNodeOpenHistory:e=>void wt(e),onNodePosition:e=>void jt(e),onNodesChange:ee,onReady:ie,onSelectedAsset:a,onToggleBranch:e=>e.user_selected?yt(e.asset_id):_t(e),onToggleReroll:e=>e.reroll_request?.status===`pending`?Ct(e):St(e),onViewportInteraction:Le,replayInteractive:!K||be,selectionFull:De,workspaceProgress:se,workspaceRootAssetId:rt})]}),V&&s&&(0,X.jsx)(vh,{activeNode:Se,brief:C,childAssetId:d,clearNextVariation:yt,closePanel:bt,latestNodes:we,linkChild:Ot,markReview:xt,nextVariationLimit:3,noteDirty:Me,onSelectedAsset:a,onToast:o,project:i,refreshBrief:Ft,refreshLineage:async()=>{await it({quiet:!0})},saveRationale:gt,replaceNextVariation:vt,selectNextBase:_t,selectedNode:Ee,selectedNodes:Te,selectionFull:De,selectionNote:N,setActiveNodeId:u,setChildAssetId:f,setDetailNodeId:_,setSelected:ht,setSelectionNote:P,sideOpen:z,snapshot:s}),F&&Ae&&s&&(0,X.jsx)(Pm,{canRemoveFromLineage:Ae.asset_id!==s.root_asset_id,claims:My(T,i,s.root_asset_id),node:Ae,onClaimControl:(e,t,n)=>{It(e,t,n)},onClearAllNext:()=>void yt(),onClearNext:()=>void yt(Ae.asset_id),onClearReroll:()=>void Ct(Ae),onClose:()=>I(null),onMarkReroll:()=>void St(Ae),onOpenDetail:()=>_(Ae.asset_id),onRemoveFromLineage:()=>void At(Ae),onReplaceNext:()=>vt(Ae),onReview:e=>void xt(e,Ae.asset_id),onSelectNext:()=>_t(Ae),position:F,selectedCount:Te.length,selectionFull:De})]}),ke&&s&&(0,X.jsx)(Wm,{actions:{canRemoveFromLineage:ke.asset_id!==s.root_asset_id,onClearAllNext:()=>void yt(),onClearNext:()=>void yt(ke.asset_id),onOpenNode:Et,onRemoveFromLineage:e=>void At(e),onReplaceNext:vt,onReview:xt,onSelectNext:_t,onToast:o,selectedCount:Te.length,selectionFull:De,snapshot:s},attempts:b,node:ke,onClose:Tt,onPromoteAttempt:Dt,project:i}),Oe&&s&&(0,X.jsx)(Xm,{canRemoveFromLineage:Oe.asset_id!==s.root_asset_id,node:Oe,onClearAllNext:()=>void yt(),onClearNext:()=>void yt(Oe.asset_id),onClose:()=>_(null),onOpenNode:_,onRemoveFromLineage:e=>void At(e),onReplaceNext:vt,onReview:xt,onSelectNext:_t,onToast:o,selectedCount:Te.length,selectionFull:De,snapshot:s}),Ce&&k&&s&&(0,X.jsx)($m,{childTitle:s.nodes.find(e=>e.asset_id===Ce.child_asset_id)?.title||Ce.child_asset_id,edge:Ce,onClose:()=>A(null),onSubmit:kt,parentTitle:s.nodes.find(e=>e.asset_id===Ce.parent_asset_id)?.title||Ce.parent_asset_id,returnFocus:k.returnFocus}),(0,X.jsx)(sh,{onClose:()=>R(!1),onCreated:qe,onToast:o,open:L,project:i})]})}function My(e,t,n){let r=`${t}:lineage-workspace:${n}`;return e.filter(e=>e.project!==t||e.status!==`active`||e.derived_state===`expired`?!1:e.scope_type===`lineage_workspace`?e.target_id===r:e.scope_type===`project_channel`)}function Ny(e){return{BT:`bottom to top`,LR:`left to right`,RL:`right to left`,TB:`top to bottom`}[e]}function Py({assets:e,onClose:t,onDone:n,onError:r,project:i}){let a=e[0],[o,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(!1),[u,d]=(0,p.useState)([]),[f,m]=(0,p.useState)({audience:a?.audience||`local-review`,campaign:a?.campaign||`local-review`,channel:a?.channel===`local`?`meta`:a?.channel||`meta`,cta:a?.cta||`Review before upload`,status:`working`}),h=e.filter(e=>!Iy(e)),_=h.length>0||e.length===0;function v(e,t){m(n=>({...n,[e]:t}))}function y(e,t){let n=pe(e.title)||e.asset_id;return{...f,assetId:n,confirmWrite:o,dryRun:t,hook:e.hook,notes:e.notes,path:e.local?.relative_path,project:i,title:e.title,type:e.content_type,utmContent:e.utm_content||n.replaceAll(`-`,`_`)}}async function b(t){if(_){r(`Local backup is locked until every selected local asset is approved.`);return}l(!0);try{let r=[];for(let n of e){if(!n.local?.relative_path)throw Error(`${n.asset_id} has no local path`);let e=await g(`/api/assets/local-backup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(y(n,t))});r.push(e.message)}t?d(r):await n(`Backed up ${e.length} local asset${e.length===1?``:`s`}`)}catch(e){r(e instanceof Error?e.message:String(e))}finally{l(!1)}}return(0,X.jsx)(`div`,{className:`drawer-backdrop`,children:(0,X.jsxs)(`section`,{className:`local-backup-drawer`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Back up local assets`}),(0,X.jsx)(`p`,{children:i})]}),(0,X.jsx)(`button`,{onClick:t,children:`Close`})]}),(0,X.jsx)(`div`,{className:`local-backup-list`,children:e.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:pe(e.title)||e.asset_id}),(0,X.jsx)(`span`,{children:e.local?.relative_path}),(0,X.jsxs)(`span`,{children:[`Review: `,Ly(Fy(e))]})]},e.asset_id))}),_&&(0,X.jsxs)(`div`,{className:`local-backup-warning`,role:`alert`,children:[(0,X.jsx)(`strong`,{children:`Backup is locked until local review is approved.`}),e.length===0?(0,X.jsx)(`span`,{children:`No local assets are selected.`}):null,h.map(e=>(0,X.jsxs)(`span`,{children:[pe(e.title)||e.asset_id,`: `,Ly(Fy(e))]},e.asset_id))]}),(0,X.jsxs)(`div`,{className:`form-grid`,children:[(0,X.jsxs)(`label`,{children:[`Campaign`,(0,X.jsx)(`input`,{value:f.campaign,onChange:e=>v(`campaign`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Channel`,(0,X.jsx)(`input`,{value:f.channel,onChange:e=>v(`channel`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Audience`,(0,X.jsx)(`input`,{value:f.audience,onChange:e=>v(`audience`,e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`Status`,(0,X.jsxs)(`select`,{value:f.status,onChange:e=>v(`status`,e.target.value),children:[(0,X.jsx)(`option`,{children:`working`}),(0,X.jsx)(`option`,{children:`published`})]})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,X.jsx)(`input`,{value:f.cta,onChange:e=>v(`cta`,e.target.value)})]})]}),u.length>0&&(0,X.jsx)(`div`,{className:`local-backup-preview`,children:u.map(e=>(0,X.jsx)(`span`,{children:e},e))}),(0,X.jsxs)(`label`,{className:`confirm-line`,children:[(0,X.jsx)(`input`,{checked:o,type:`checkbox`,onChange:e=>s(e.target.checked)}),(0,X.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{disabled:c||_,onClick:()=>void b(!0),children:`Dry run`}),(0,X.jsxs)(`button`,{className:`primary-button`,disabled:c||_||!o,onClick:()=>void b(!1),children:[c?(0,X.jsx)(ee,{className:`spin`,size:16}):(0,X.jsx)(E,{size:16}),`Back up`]})]})]})})}function Fy(e){return e.review?.review_state||`unreviewed`}function Iy(e){return!!e.local?.relative_path&&Fy(e)===`approved`}function Ly(e){return e===`needs_revision`?`needs revision`:e}var Ry=[[`unreviewed`,`Needs review`],[`approved`,`Approved keepers`],[`needs_revision`,`Needs revision`],[`rejected`,`Rejected or ignored`]];function zy(e){let t=e.assets.filter(e=>e.local?.relative_path&&!e.s3?.key),n=t.filter(e=>Hy(e)===`approved`),r=e.selectedBackupIds.length,i=Z(e.cli||null,`local queue --project '${e.project}'`);function a(){for(let t of n)e.onQueueBackup(t)}return(0,X.jsxs)(`section`,{className:`local-backup-queue`,children:[(0,X.jsxs)(`header`,{className:`backup-queue-head`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Local Backup Queue`}),(0,X.jsx)(`p`,{children:`Review local-only candidates, select approved keepers, then back them up intentionally.`}),(0,X.jsxs)(`p`,{children:[e.snapshot?.catalog.default_bucket||`No bucket loaded`,` · refreshed `,fe(e.snapshot?.fetchedAt)]})]}),(0,X.jsxs)(`div`,{className:`backup-queue-actions`,children:[(0,X.jsxs)(`button`,{disabled:n.length===0,onClick:a,type:`button`,children:[(0,X.jsx)(w,{size:15}),` Select approved`]}),(0,X.jsxs)(`button`,{disabled:r===0,onClick:e.onOpenBackup,type:`button`,children:[(0,X.jsx)(E,{size:15}),` Back up selected`]})]})]}),(0,X.jsxs)(`div`,{className:`backup-queue-stats`,"aria-label":`Local backup queue summary`,children:[(0,X.jsx)(Vy,{label:`Local only`,value:t.length}),(0,X.jsx)(Vy,{label:`Needs review`,value:t.filter(e=>Hy(e)===`unreviewed`).length}),(0,X.jsx)(Vy,{label:`Approved`,value:n.length}),(0,X.jsx)(Vy,{label:`Selected`,value:r})]}),(0,X.jsxs)(`div`,{className:`handoff-strip`,children:[(0,X.jsx)(`code`,{children:i}),(0,X.jsxs)(`button`,{onClick:()=>void e.onCopy(i,`local backup queue command`),type:`button`,children:[(0,X.jsx)(T,{size:14}),` Copy`]})]}),t.length===0?(0,X.jsx)(`div`,{className:`backup-empty`,children:`No local-only assets are waiting for review or backup.`}):(0,X.jsx)(`div`,{className:`backup-queue-grid`,children:Ry.map(([n,r])=>(0,X.jsxs)(`section`,{className:`backup-queue-lane`,children:[(0,X.jsx)(`h3`,{children:r}),t.filter(e=>Uy(e)===n).map(t=>(0,X.jsx)(By,{asset:t,onLocalReview:e.onLocalReview,onQueueBackup:e.onQueueBackup,onSelectAsset:e.onSelectAsset,selected:e.selected?.asset_id===t.asset_id,selectedForBackup:e.selectedBackupIds.includes(t.asset_id)},t.asset_id))]},n))}),(0,X.jsxs)(`footer`,{className:`pagination-bar`,children:[(0,X.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page<=1,onClick:()=>e.setPage(e=>Math.max(e-1,1)),type:`button`,children:`Previous`}),(0,X.jsxs)(`span`,{children:[e.snapshot?.pagination.page||e.page,` of `,e.snapshot?.pagination.totalPages||1]}),(0,X.jsx)(`button`,{disabled:!e.snapshot||e.snapshot.pagination.page>=e.snapshot.pagination.totalPages,onClick:()=>e.setPage(e=>e+1),type:`button`,children:`Next`}),(0,X.jsxs)(`label`,{children:[`Per page`,(0,X.jsx)(`select`,{onChange:t=>e.setPageSize(Number(t.target.value)),value:e.pageSize,children:[10,25,50,100].map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]})]})]})}function By(e){let t=Hy(e.asset),n=ye(e.asset),r=t===`approved`;return(0,X.jsxs)(`article`,{className:`backup-queue-card ${e.selected?`selected`:``}`,children:[(0,X.jsx)(`strong`,{children:e.asset.title}),(0,X.jsx)(`code`,{children:e.asset.asset_id}),(0,X.jsx)(`small`,{children:e.asset.local?.relative_path}),(0,X.jsxs)(`div`,{className:`backup-card-meta`,children:[(0,X.jsx)(`span`,{children:n.label}),(0,X.jsx)(`span`,{children:Wy(t)}),(0,X.jsx)(`span`,{children:q(e.asset.local?.size_bytes)})]}),(0,X.jsxs)(`div`,{className:`backup-card-actions`,children:[(0,X.jsx)(`button`,{onClick:()=>e.onSelectAsset(e.asset),type:`button`,children:`Open`}),(0,X.jsx)(`button`,{"aria-pressed":t===`approved`,onClick:()=>void e.onLocalReview(e.asset,`approved`),type:`button`,children:`Approve`}),(0,X.jsx)(`button`,{"aria-pressed":t===`needs_revision`,onClick:()=>void e.onLocalReview(e.asset,`needs_revision`),type:`button`,children:`Revise`}),(0,X.jsx)(`button`,{"aria-pressed":t===`rejected`,onClick:()=>void e.onLocalReview(e.asset,`rejected`),type:`button`,children:`Reject`}),(0,X.jsx)(`button`,{disabled:!r,onClick:()=>e.onQueueBackup(e.asset),type:`button`,children:e.selectedForBackup?`Selected`:r?`Select backup`:`Approve first`})]})]})}function Vy({label:e,value:t}){return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:t}),(0,X.jsx)(`span`,{children:e})]})}function Hy(e){return e.review?.review_state||`unreviewed`}function Uy(e){let t=Hy(e);return t===`ignored`?`rejected`:t}function Wy(e){return e===`needs_revision`?`needs revision`:e}function Gy({assets:e,onClear:t,onOpen:n}){return e.length===0?null:(0,X.jsxs)(`div`,{className:`local-selection-toolbar`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`strong`,{children:[e.length,` local keeper`,e.length===1?``:`s`,` selected`]}),(0,X.jsx)(`span`,{children:`Ready for S3 backup preflight`})]}),(0,X.jsxs)(`button`,{onClick:n,children:[(0,X.jsx)(E,{size:16}),`Back up selected`]}),(0,X.jsx)(`button`,{"aria-label":`Clear local backup selection`,className:`icon-lite`,onClick:t,children:(0,X.jsx)(de,{size:16})})]})}function Ky(e){return e.find(e=>qy(e)>0)?.channel||e[0]?.channel}function qy(e){return e.totals.needsQa+e.totals.approvedLocal+e.totals.needsRevision+e.totals.rejectedLocal}var Jy=[[`needsQa`,`Needs QA`],[`approvedLocal`,`Approved`],[`needsRevision`,`Revise`],[`rejectedLocal`,`Rejected`],[`readyToPost`,`S3 ready`],[`scheduled`,`Scheduled`],[`posted`,`Posted`]];function Yy(e){let[t,n]=(0,p.useState)(null),[r,i]=(0,p.useState)(null),[a,o]=(0,p.useState)(null),[s,c]=(0,p.useState)([]),[l,u]=(0,p.useState)(``);async function d(){try{let t=new URLSearchParams({project:e.project,limit:`4`});e.channel!==`all`&&t.set(`channel`,e.channel),n(await g(`/api/review/queue?${t.toString()}`)),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}}if((0,p.useEffect)(()=>{d()},[e.project,e.channel]),r)return(0,X.jsx)(`section`,{className:`review-queue`,children:(0,X.jsx)(`div`,{className:`toast error`,children:r})});if(!t)return(0,X.jsx)(`section`,{className:`review-queue`,children:(0,X.jsx)(`div`,{className:`asset-board`,children:(0,X.jsx)(`div`,{className:`board-head`,children:(0,X.jsx)(`h2`,{children:`Loading review queue`})})})});let f=t.totals.needsQa+t.totals.approvedLocal+t.totals.needsRevision+t.totals.rejectedLocal,m=new Set(t.lanes.flatMap(e=>[...e.needsQa,...e.approvedLocal,...e.needsRevision,...e.rejectedLocal]).map(e=>e.asset_id)),h=s.filter(e=>m.has(e)),_=Ky(t.lanes);function v(e){c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function y(t){if(h.length!==0){o(`batch`);try{await g(`/api/local-review/batch`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({assetIds:h,confirmWrite:!0,notes:l,project:e.project,reviewState:t})}),c(e=>e.filter(e=>!m.has(e))),u(``),await d()}finally{o(null)}}}return(0,X.jsxs)(`section`,{className:`review-queue`,children:[(0,X.jsxs)(`div`,{className:`review-summary`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{children:[t.project,` review queue`]}),(0,X.jsx)(`p`,{children:`Local-first queue for demo assets, channel posting state, and agent handoff.`}),(0,X.jsxs)(`p`,{children:[t.totals.channels,` channels · refreshed `,fe(t.fetchedAt)]})]}),(0,X.jsx)(Xy,{label:`Local review`,value:f}),(0,X.jsx)(Xy,{label:`S3 ready`,value:t.totals.readyToPost}),(0,X.jsx)(Xy,{label:`Scheduled`,value:t.totals.scheduled}),(0,X.jsx)(Xy,{label:`Posted`,value:t.totals.posted})]}),h.length>0?(0,X.jsxs)(`div`,{className:`batch-review-strip`,"aria-label":`Batch local review actions`,children:[(0,X.jsxs)(`strong`,{children:[h.length,` selected`]}),(0,X.jsx)(`textarea`,{"aria-label":`Shared batch review notes`,onChange:e=>u(e.target.value),placeholder:`Shared review notes`,rows:2,value:l}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`approved`),type:`button`,children:`Approve`}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`needs_revision`),type:`button`,children:`Needs revision`}),(0,X.jsx)(`button`,{disabled:h.length===0||a===`batch`,onClick:()=>void y(`rejected`),type:`button`,children:`Reject`})]}):null,(0,X.jsx)(`div`,{className:`queue-lanes`,children:t.lanes.map(t=>(0,X.jsxs)(`details`,{className:`queue-lane`,open:e.channel!==`all`||t.channel===_,children:[(0,X.jsxs)(`summary`,{children:[(0,X.jsx)(`h3`,{children:t.channel}),(0,X.jsxs)(`div`,{className:`lane-counts`,children:[(0,X.jsxs)(`span`,{children:[t.totals.needsQa,` qa`]}),(0,X.jsxs)(`span`,{children:[t.totals.approvedLocal,` approved`]}),(0,X.jsxs)(`span`,{children:[t.totals.needsRevision,` revise`]}),(0,X.jsxs)(`span`,{children:[t.totals.readyToPost,` ready`]}),(0,X.jsxs)(`span`,{children:[t.totals.scheduled,` scheduled`]}),(0,X.jsxs)(`span`,{children:[t.totals.posted,` posted`]})]})]}),(0,X.jsxs)(`div`,{className:`queue-columns`,children:[Jy.filter(([e])=>t[e].length>0).map(([n,r])=>(0,X.jsx)(Zy,{assets:t[n],label:r,onCopy:e.onCopy,onLocalReview:async(t,n)=>{o(t.asset_id);try{await e.onLocalReview(t,n),await d()}finally{o(null)}},onOpenBackup:e.onOpenBackup,onSelectAsset:e.onSelectAsset,pendingReview:a,selected:e.selected,selectedReviewIds:h,onToggleReviewSelection:v},n)),Jy.every(([e])=>t[e].length===0)&&(0,X.jsx)(`p`,{className:`review-empty`,children:`No items in this channel.`})]})]},t.channel))})]})}function Xy({label:e,value:t}){return(0,X.jsxs)(`div`,{className:`queue-stat`,children:[(0,X.jsx)(`strong`,{children:t}),(0,X.jsx)(`span`,{children:e})]})}function Zy(e){return(0,X.jsxs)(`div`,{className:`queue-column`,children:[(0,X.jsx)(`h4`,{children:e.label}),e.assets.map(t=>(0,X.jsx)(Qy,{asset:t,onCopy:e.onCopy,onLocalReview:e.onLocalReview,onOpenBackup:e.onOpenBackup,onSelectAsset:e.onSelectAsset,onToggleReviewSelection:e.onToggleReviewSelection,pendingReview:e.pendingReview===t.asset_id,selected:e.selected?.asset_id===t.asset_id,selectedForReview:e.selectedReviewIds.includes(t.asset_id)},t.asset_id))]})}function Qy(e){let t=Ne(),n=ye(e.asset),r=e.asset.local?$y(e.asset):null,i=r===`approved`,a=e.asset.source===`local`?Z(t,`local inspect --asset-id '${e.asset.asset_id}'`):Z(t,`inspect --asset-id '${e.asset.asset_id}'`);return(0,X.jsxs)(`article`,{className:`queue-card ${e.selected?`selected`:``}`,onClick:()=>e.onSelectAsset(e.asset),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&e.onSelectAsset(e.asset)},role:`button`,tabIndex:0,children:[r?(0,X.jsxs)(`label`,{className:`confirm-line`,onClick:e=>e.stopPropagation(),onKeyDown:ib,children:[(0,X.jsx)(`input`,{checked:e.selectedForReview,onChange:()=>e.onToggleReviewSelection(e.asset.asset_id),type:`checkbox`}),(0,X.jsx)(`span`,{children:`Select for batch review`})]}):null,(0,X.jsx)(`strong`,{children:e.asset.title}),(0,X.jsx)(`small`,{children:e.asset.asset_id}),(0,X.jsxs)(`div`,{className:`lane-counts`,children:[(0,X.jsx)(`span`,{className:`storage-chip ${n.kind}`,children:n.label}),(0,X.jsx)(`span`,{className:`queue-tag`,children:Te(e.asset)}),r?(0,X.jsx)(`span`,{className:`review-chip ${r}`,children:eb(r)}):null]}),r?(0,X.jsxs)(`div`,{className:`review-actions`,"aria-label":`Local review actions for ${e.asset.title}`,onKeyDown:ib,children:[(0,X.jsx)(`button`,{"aria-pressed":r===`approved`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`approved`),children:`Approve`}),(0,X.jsx)(`button`,{"aria-pressed":r===`needs_revision`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`needs_revision`),children:`Needs revision`}),(0,X.jsx)(`button`,{"aria-pressed":r===`rejected`,disabled:e.pendingReview,type:`button`,onClick:t=>nb(t,e.onLocalReview,e.asset,`rejected`),children:`Reject`})]}):null,(0,X.jsxs)(`div`,{className:`queue-actions`,onKeyDown:ib,children:[(0,X.jsx)(`button`,{type:`button`,onClick:t=>tb(t,e.onCopy,a),children:`Copy inspect`}),e.asset.local?i?(0,X.jsx)(`button`,{type:`button`,onClick:t=>rb(t,e.onOpenBackup,e.asset),children:`Back up`}):(0,X.jsx)(`span`,{className:`backup-locked`,title:`Approve this local asset before backup`,children:`Backup locked until approved.`}):null]})]})}function $y(e){return e.review?.review_state||`unreviewed`}function eb(e){return e===`needs_revision`?`needs revision`:e}function tb(e,t,n){e.stopPropagation(),t(n,`inspect command`)}function nb(e,t,n,r){e.stopPropagation(),t(n,r)}function rb(e,t,n){e.stopPropagation(),t(n)}function ib(e){(e.key===`Enter`||e.key===` `)&&e.stopPropagation()}var ab={channel:`dev`,version:`0.1.20`},ob={cloud:D,image_generator:V,scheduler:oe},sb={cloud:`Cloud storage`,image_generator:`Image generation`,scheduler:`Social scheduling`},cb=[{adapterType:`cloud`,ariaLabel:`Cloud storage settings`},{adapterType:`scheduler`,ariaLabel:`Social scheduling settings`},{adapterType:`image_generator`,ariaLabel:`Image generation settings`}];function lb(e){return typeof e==`boolean`?e?`on`:`off`:typeof e==`number`?String(e):typeof e==`string`?e||`not set`:JSON.stringify(e)}function ub(e){return Object.entries(e.safe_config).filter(([e])=>![`secret`,`token`,`password`,`credential`,`apiKey`].includes(e))}function db(e){return e.health_status===`configured`?`ok`:e.health_status===`missing_config`?`warn`:`muted`}function fb(e){return(0,X.jsx)(`button`,{"aria-checked":e.checked,"aria-label":e.label,className:`settings-switch ${e.checked?`on`:``}`,disabled:e.disabled,onClick:e.onClick,role:`switch`,type:`button`,children:(0,X.jsx)(`span`,{})})}function pb(e){let[t,n]=(0,p.useState)(null),[r,i]=(0,p.useState)(null),[a,s]=(0,p.useState)(!0),[c,l]=(0,p.useState)(``),[u,d]=(0,p.useState)(Cm);function f(){let t=!u;if(!wm(t)){e.onToast(`error`,`Browser storage is unavailable, so the hover preview preference could not be saved`);return}d(t),e.onToast(`ok`,`Lineage hover previews ${t?`enabled`:`disabled`}`)}async function m(){s(!0);try{let[t,r]=await Promise.all([g(`/api/adapters/settings?project=${encodeURIComponent(e.project)}`),g(`/api/runtime`)]);n(t),i(r.runtime)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{s(!1)}}async function h(t){let r=`${t.adapter_type}:${t.provider}`;l(r);try{let r=await g(`/api/adapters/settings/${t.adapter_type}/${t.provider}`,{body:JSON.stringify({confirmWrite:!0,enabled:!t.enabled,project:e.project,safeConfig:t.safe_config}),headers:{"Content-Type":`application/json`},method:`POST`});n(e=>e&&{...e,settings:e.settings.map(e=>e.adapter_type===r.setting.adapter_type&&e.provider===r.setting.provider?r.setting:e)}),e.onToast(`ok`,`${sb[t.adapter_type]} ${r.setting.enabled?`enabled`:`disabled`}`)}catch(t){e.onToast(`error`,t instanceof Error?t.message:String(t))}finally{l(``)}}return(0,p.useEffect)(()=>{m()},[e.project]),(0,X.jsxs)(`section`,{className:`settings-view`,children:[(0,X.jsxs)(`header`,{className:`settings-header`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Settings`}),(0,X.jsxs)(`p`,{children:[`Adapter switches, safe local preferences, and credential-source status for `,e.project,`.`]})]}),(0,X.jsxs)(`button`,{className:`secondary-button`,disabled:a,onClick:()=>void m(),type:`button`,children:[a?(0,X.jsx)(ee,{className:`spin`,size:17}):(0,X.jsx)(o,{size:17}),`Refresh`]})]}),(0,X.jsxs)(`div`,{className:`settings-sections`,children:[(0,X.jsxs)(`section`,{"aria-label":`Release information`,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:`Release`}),(0,X.jsxs)(`dl`,{className:`settings-release`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Version`}),(0,X.jsx)(`dd`,{children:r?.version||ab.version})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Channel`}),(0,X.jsx)(`dd`,{children:r?.channel||ab.channel})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Profile`}),(0,X.jsx)(`dd`,{children:r?.profile.id||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Environment`}),(0,X.jsx)(`dd`,{children:r?.profile.environment||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Binding`}),(0,X.jsx)(`dd`,{children:r?r.profile.bound?`bound`:`legacy unbound`:`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Git`}),(0,X.jsx)(`dd`,{children:r?.git_sha||`not available`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Assets`}),(0,X.jsx)(`dd`,{className:`settings-path`,children:r?.asset_root||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`SQLite`}),(0,X.jsx)(`dd`,{className:`settings-path`,children:r?.database.path||`loading`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Database`}),(0,X.jsx)(`dd`,{children:r?.database.exists?`${r.database.projects??0} projects / ${r.database.workspaces??0} workspaces`:`not created yet`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Schema`}),(0,X.jsx)(`dd`,{children:r?`${r.schema.migration_keys.length} migration marker(s)`:`loading`})]})]})]}),(0,X.jsxs)(`section`,{"aria-label":`Lineage experience settings`,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:`Lineage experience`}),(0,X.jsx)(`div`,{className:`settings-grid`,children:(0,X.jsx)(`article`,{className:`settings-card`,children:(0,X.jsxs)(`div`,{className:`settings-card-head`,children:[(0,X.jsx)(`span`,{className:`settings-icon`,children:(0,X.jsx)(N,{size:19})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{children:`Hover previews`}),(0,X.jsx)(`p`,{children:`Show the full asset and quick Branch/Re-roll/Details actions when hovering over or focusing a lineage node. Double-click details remain available when this is off.`})]}),(0,X.jsx)(fb,{checked:u,label:`Enable lineage hover previews`,onClick:f})]})})})]}),cb.map(e=>(0,X.jsxs)(`section`,{"aria-label":e.ariaLabel,className:`settings-section`,children:[(0,X.jsx)(`h3`,{children:sb[e.adapterType]}),(0,X.jsx)(`div`,{className:`settings-grid`,children:(t?.settings||[]).filter(t=>t.adapter_type===e.adapterType).map(e=>{let t=ob[e.adapter_type],n=`Enable ${e.label===`Buffer`?`Buffer scheduling`:e.label}`,r=c===`${e.adapter_type}:${e.provider}`;return(0,X.jsxs)(`article`,{className:`settings-card`,children:[(0,X.jsxs)(`div`,{className:`settings-card-head`,children:[(0,X.jsx)(`span`,{className:`settings-icon`,children:(0,X.jsx)(t,{size:19})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h4`,{children:e.label}),(0,X.jsx)(`p`,{children:e.description})]}),(0,X.jsx)(fb,{checked:e.enabled,disabled:r,label:n,onClick:()=>void h(e)})]}),(0,X.jsxs)(`dl`,{className:`settings-meta`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Status`}),(0,X.jsxs)(`dd`,{className:db(e),children:[e.health_status===`configured`?(0,X.jsx)(w,{size:14}):(0,X.jsx)(C,{size:14}),e.health_status.replace(/_/g,` `)]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Credential source`}),(0,X.jsx)(`dd`,{children:e.credential.label})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`dt`,{children:`Secret ref`}),(0,X.jsx)(`dd`,{children:e.credential.secret_ref||`none`})]})]}),ub(e).length>0&&(0,X.jsx)(`div`,{className:`settings-config`,children:ub(e).map(([e,t])=>(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e}),lb(t)]},e))})]},`${e.adapter_type}:${e.provider}`)})})]},e.adapterType)),a&&!t&&(0,X.jsx)(`div`,{className:`settings-loading`,children:`Loading settings...`})]})]})}var mb=`Lineage`,hb=`Local-first creative lineage workspace`;function gb(e){let{channel:t,channels:n,placementStatus:r,project:i,projects:a,setChannel:o,setPlacementStatus:s,setProject:c,setSource:l,setStatus:u,source:d,status:f}=e,[m,h]=(0,p.useState)(!1),[g,_]=(0,p.useState)(!0),v=a.length?a.map(e=>e.project):[i];return(0,X.jsxs)(`aside`,{className:`sidebar ${g?``:`collapsed`}`,children:[(0,X.jsx)(`button`,{"aria-label":g?`Collapse sidebar`:`Expand sidebar`,className:`sidebar-collapse-toggle`,onClick:()=>_(e=>!e),type:`button`,children:g?(0,X.jsx)(ne,{size:16}):(0,X.jsx)(re,{size:16})}),(0,X.jsxs)(`div`,{className:`brand`,children:[(0,X.jsx)(`div`,{className:`brand-mark`,"aria-label":hb,children:`L`}),(0,X.jsxs)(`div`,{className:`brand-copy`,children:[(0,X.jsx)(`h1`,{children:mb}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{children:i}),(0,X.jsxs)(`span`,{"aria-label":`Lineage version ${ab.version}`,className:`brand-version`,title:`Lineage version ${ab.version}, ${ab.channel} channel`,children:[`v`,ab.version]})]})]})]}),(0,X.jsxs)(`button`,{"aria-controls":`mobile-sidebar-controls`,"aria-expanded":m,className:`mobile-filter-toggle`,onClick:()=>h(e=>!e),type:`button`,children:[(0,X.jsx)(G,{size:16}),`Filters`,(0,X.jsx)(S,{className:m?`open`:``,size:16})]}),(0,X.jsxs)(`div`,{className:`sidebar-mobile-collapse`,"data-open":m,id:`mobile-sidebar-controls`,children:[(0,X.jsxs)(`div`,{className:`side-section`,children:[(0,X.jsx)(`h2`,{children:`Project`}),(0,X.jsx)(_b,{id:`asset-project-filter`,label:`Project`,value:i,values:v,onChange:c})]}),(0,X.jsxs)(`section`,{className:`side-section`,children:[(0,X.jsx)(`h2`,{children:`Filters`}),(0,X.jsx)(_b,{id:`asset-source-filter`,label:`Source`,value:d,values:Y,onChange:e=>l(e)}),(0,X.jsx)(_b,{id:`asset-status-filter`,label:`Status`,value:f,values:J,onChange:e=>u(e)}),(0,X.jsx)(_b,{id:`asset-channel-filter`,label:`Channel`,value:t,values:n,onChange:o}),(0,X.jsx)(_b,{id:`asset-placement-filter`,label:`Placement`,value:r,values:he,onChange:e=>s(e)})]})]})]})}function _b({id:e,label:t,value:n,values:r,onChange:i}){return(0,X.jsxs)(`label`,{htmlFor:e,children:[t,(0,X.jsx)(`select`,{"aria-label":t,id:e,value:n,onChange:e=>i(e.target.value),children:r.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]})}var vb=[{label:`Lineage`,view:`lineage`},{label:`Review`,view:`review`},{label:`Assets`,view:`assets`},{label:`Agents`,view:`agents`},{label:`Settings`,view:`settings`}],yb=[{label:`Ledger`,view:`ledger`},{label:`Content batches`,view:`content`},{label:`Backup queue`,view:`backup`}];function bb(e){let t=yb.some(t=>t.view===e.view);function n(t){e.setView(t),e.onMoreOpenChange(!1)}function r(t){e.setView(t),e.onMoreOpenChange(!1)}return(0,X.jsxs)(`header`,{className:`topbar`,children:[(0,X.jsxs)(`div`,{className:`view-tabs`,role:`tablist`,"aria-label":`${mb} views`,children:[vb.map(t=>(0,X.jsx)(`button`,{"aria-pressed":e.view===t.view,className:e.view===t.view?`active`:``,onClick:()=>n(t.view),type:`button`,children:t.label},t.view)),(0,X.jsxs)(`div`,{className:`more-menu`,children:[(0,X.jsxs)(`button`,{"aria-expanded":e.moreOpen,"aria-haspopup":`menu`,"aria-pressed":t,className:t?`active`:``,onClick:()=>e.onMoreOpenChange(!e.moreOpen),type:`button`,children:[(0,X.jsx)(j,{size:16}),` More `,(0,X.jsx)(S,{className:e.moreOpen?`open`:``,size:15})]}),e.moreOpen&&(0,X.jsx)(`div`,{className:`more-menu-popover`,role:`menu`,children:yb.map(t=>(0,X.jsx)(`button`,{"aria-pressed":e.view===t.view,onClick:()=>r(t.view),role:`menuitem`,type:`button`,children:t.label},t.view))})]})]}),(0,X.jsx)(xb,{runtime:e.runtime,unavailable:e.runtimeIdentityUnavailable}),(0,X.jsxs)(`div`,{className:`searchbox`,children:[(0,X.jsx)(ae,{size:17}),(0,X.jsx)(`input`,{onChange:t=>e.setQuery(t.target.value),placeholder:`Search assets, campaigns, hooks`,value:e.query})]}),e.view!==`lineage`&&(0,X.jsxs)(`button`,{"aria-expanded":e.assetDetailsOpen,className:`secondary-button`,disabled:!e.canInspectAsset,onClick:()=>{e.onMoreOpenChange(!1),e.setAssetDetailsOpen(!e.assetDetailsOpen)},type:`button`,children:[(0,X.jsx)(I,{size:17}),`Details`]}),(0,X.jsx)(`button`,{className:`icon-button`,disabled:e.loading,onClick:()=>void e.refresh(),title:`Refresh current page`,children:e.loading?(0,X.jsx)(ee,{className:`spin`,size:18}):(0,X.jsx)(o,{size:18})}),(0,X.jsxs)(`button`,{className:`primary-button`,onClick:()=>e.setUploadOpen(!0),children:[(0,X.jsx)(ue,{size:17}),`Upload`]})]})}function xb(e){if(e.unavailable)return(0,X.jsx)(`div`,{"aria-label":`Lineage runtime identity unavailable`,className:`runtime-identity-badge unavailable`,children:`IDENTITY UNAVAILABLE`});if(!e.runtime)return(0,X.jsx)(`div`,{"aria-label":`Loading Lineage runtime identity`,className:`runtime-identity-badge loading`,children:`IDENTITY LOADING`});let{profile:t}=e.runtime,n=t.bound?``:` · UNBOUND`,r=[`${t.environment.toUpperCase()} profile ${t.id}${t.bound?``:` (unbound)`}`,`Channel ${e.runtime.channel}`,`Version ${e.runtime.version}`,t.warning].filter(Boolean).join(` · `);return(0,X.jsxs)(`div`,{"aria-label":`Lineage ${t.environment} profile ${t.id}${t.bound?``:` unbound`}`,className:`runtime-identity-badge ${t.environment} ${t.bound?`bound`:`unbound`}`,"data-profile-id":t.id,title:r,children:[(0,X.jsx)(`strong`,{children:t.environment.toUpperCase()}),(0,X.jsxs)(`span`,{children:[t.id,n]})]})}function Sb({toast:e,onDismiss:t}){return(0,X.jsxs)(`div`,{className:`toast ${e.type}`,role:`status`,children:[e.type===`ok`?(0,X.jsx)(w,{size:16}):(0,X.jsx)(se,{size:16}),(0,X.jsx)(`span`,{children:e.message}),(0,X.jsx)(`button`,{onClick:t,children:`Dismiss`})]})}var Cb=200*1024*1024;function wb({channels:e,project:t,onClose:n,onUploaded:r,onError:i}){let[a,o]=(0,p.useState)({assetId:``,audience:`short-form-creators`,campaign:`2026-06-organic-traffic-test`,channel:e[0]||`meta`,cta:``,hook:``,status:`working`,title:``,type:`image`,utmContent:``}),[s,c]=(0,p.useState)(null),[l,u]=(0,p.useState)(!1),[d,f]=(0,p.useState)(!1);function m(e,t){o(n=>({...n,[e]:t}))}function h(e){o(t=>({...t,assetId:t.assetId||pe(`demo-${t.channel}-${e}`),title:e,utmContent:t.utmContent||pe(e).replaceAll(`-`,`_`)}))}function _(e){if(!e){c(null);return}if(e.size>Cb){i(`File is larger than ${q(Cb)}`);return}c(e)}async function v(e){if(e.preventDefault(),!s)return i(`Choose a file before uploading`);f(!0);try{let e=new FormData;Object.entries({project:t,...a,confirmWrite:String(l)}).forEach(([t,n])=>e.append(t,n)),e.append(`file`,s),await r((await g(`/api/assets/upload`,{method:`POST`,body:e})).message)}catch(e){i(e instanceof Error?e.message:String(e))}finally{f(!1)}}return(0,X.jsx)(`div`,{className:`drawer-backdrop`,children:(0,X.jsxs)(`form`,{className:`upload-drawer`,onSubmit:v,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{children:`Upload asset`}),(0,X.jsx)(`p`,{children:t})]}),(0,X.jsx)(`button`,{type:`button`,onClick:n,children:`Close`})]}),(0,X.jsxs)(`label`,{className:`file-drop`,children:[(0,X.jsx)(ue,{size:20}),(0,X.jsx)(`span`,{children:s?s.name:`Choose creative export up to ${q(Cb)}`}),(0,X.jsx)(`input`,{type:`file`,onChange:e=>_(e.target.files?.[0])})]}),(0,X.jsxs)(`div`,{className:`form-grid`,children:[(0,X.jsxs)(`label`,{children:[`Title`,(0,X.jsx)(`input`,{value:a.title,onChange:e=>h(e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Asset ID`,(0,X.jsx)(`input`,{value:a.assetId,onChange:e=>m(`assetId`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Campaign`,(0,X.jsx)(`input`,{value:a.campaign,onChange:e=>m(`campaign`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Channel`,(0,X.jsx)(`select`,{value:a.channel,onChange:e=>m(`channel`,e.target.value),children:e.map(e=>(0,X.jsx)(`option`,{children:e},e))})]}),(0,X.jsxs)(`label`,{children:[`Audience`,(0,X.jsx)(`input`,{value:a.audience,onChange:e=>m(`audience`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Status`,(0,X.jsxs)(`select`,{value:a.status,onChange:e=>m(`status`,e.target.value),children:[(0,X.jsx)(`option`,{children:`working`}),(0,X.jsx)(`option`,{children:`published`})]})]}),(0,X.jsxs)(`label`,{children:[`Type`,(0,X.jsx)(`select`,{value:a.type,onChange:e=>m(`type`,e.target.value),children:ge.map(e=>(0,X.jsx)(`option`,{children:e},e))})]}),(0,X.jsxs)(`label`,{children:[`UTM content`,(0,X.jsx)(`input`,{value:a.utmContent,onChange:e=>m(`utmContent`,e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`Hook`,(0,X.jsx)(`input`,{value:a.hook,onChange:e=>m(`hook`,e.target.value)})]}),(0,X.jsxs)(`label`,{className:`wide`,children:[`CTA`,(0,X.jsx)(`input`,{value:a.cta,onChange:e=>m(`cta`,e.target.value),required:!0})]})]}),(0,X.jsxs)(`label`,{className:`confirm-line`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked)}),(0,X.jsx)(`span`,{children:`Confirm write to the production asset bucket`})]}),(0,X.jsxs)(`footer`,{children:[(0,X.jsx)(`button`,{type:`button`,onClick:n,children:`Cancel`}),(0,X.jsxs)(`button`,{className:`primary-button`,disabled:d||!l,children:[d?(0,X.jsx)(ee,{className:`spin`,size:16}):(0,X.jsx)(ue,{size:16}),`Upload`]})]})]})})}function Tb(e,t){let n=`${e} ${t}`.toLowerCase();return n.includes(`agent`)||n.includes(`command`)||n.includes(`selection`)||n.includes(`next context`)}function Eb(){return typeof window>`u`?me:new URLSearchParams(window.location.search).get(`project`)||`demo-project`}function Db(){let[e,t]=(0,p.useState)(null),[n,r]=(0,p.useState)(null),[i,a]=(0,p.useState)(Eb),[o,s]=(0,p.useState)([]),[c,l]=(0,p.useState)(`all`),[u,d]=(0,p.useState)(`all`),[f,m]=(0,p.useState)(`local`),[h,y]=(0,p.useState)(`all`),[b,x]=(0,p.useState)(``),[S,C]=(0,p.useState)(1),[w,T]=(0,p.useState)(10),[E,D]=(0,p.useState)(!1),[O,k]=(0,p.useState)(!0),[A,j]=(0,p.useState)(null),[M,N]=(0,p.useState)(null),[P,F]=(0,p.useState)({}),[I,L]=(0,p.useState)({}),[R,z]=(0,p.useState)([]),[B,V]=(0,p.useState)([]),[H,U]=(0,p.useState)(!1),[W,ee]=(0,p.useState)(!1),[te,ne]=(0,p.useState)(`lineage`),[re,ie]=(0,p.useState)(!1),[ae,oe]=(0,p.useState)(null),[se,G]=(0,p.useState)(0),[ce,le]=(0,p.useState)(null),[K,ue]=(0,p.useState)(!1),[de,q]=(0,p.useState)(null),fe=(0,p.useCallback)(e=>{q(t=>e?`lineage-actions`:t===`lineage-actions`?null:t)},[]),pe=(0,p.useCallback)(e=>{q(t=>e?`topbar-more`:t===`topbar-more`?null:t)},[]),me=(0,p.useCallback)((e,t)=>{j({type:e,message:t})},[]),J=e?.catalog.project===i?e:null,he=J?.assets||[],Y=xe(he,n)||(ae?.project===i&&ae.asset_id===n?ae:void 0),ge=Y?.asset_id||``,_e=[...B.filter(e=>R.includes(e.asset_id)),...he.filter(e=>R.includes(e.asset_id)&&e.local?.relative_path)].filter((e,t,n)=>n.findIndex(t=>t.asset_id===e.asset_id)===t),ve=Y&&P[Y.asset_id]||null,ye=(0,p.useMemo)(()=>[`all`,...J?.facets.channels||[]],[J]),be=(0,p.useMemo)(()=>({assets:J?.catalog.asset_count||0,live:J?.liveObjects.length||0,orphan:J?.orphanObjects.length||0,size:J?.facets.totalSizeBytes||0}),[J]);async function Ce(){try{let e=await g(`/api/projects`);s(e.projects),a(t=>e.projects.some(e=>e.project===t)?t:e.projects[0]?.project||`demo-project`)}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}async function we(){try{let e=await g(`/api/runtime`);le(e.runtime),ue(!1)}catch{le(null),ue(!0)}}async function Te(){k(!0);try{let e=await g(`/api/assets?${Ee()}`);t(e),r(t=>xe(e.assets,t)?.asset_id||(t&&ae?.asset_id===t?t:null)),F({}),L({})}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}finally{k(!1)}}function Ee(){let e=new URLSearchParams({project:i,page:String(S),pageSize:String(w),live:String(E),source:f});return c!==`all`&&e.set(`status`,c),u!==`all`&&e.set(`placementStatus`,u),h!==`all`&&e.set(`channel`,h),b.trim()&&e.set(`q`,b.trim()),e.toString()}async function De(e){try{let t=await e();j({type:`ok`,message:t.message}),F({}),await Te()}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}async function Oe(e,t={}){if(!Se(e))return null;let n=P[e.asset_id];if(n)return t.open&&window.open(n,`_blank`,`noopener,noreferrer`),n;if(e.local?.relative_path){let n=`/api/assets/local-preview?${new URLSearchParams({project:i,path:e.local.relative_path}).toString()}`;return F(t=>({...t,[e.asset_id]:n})),L(t=>({...t,[e.asset_id]:``})),t.open&&window.open(n,`_blank`,`noopener,noreferrer`),n}try{let n=await g(`/api/assets/presign`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,assetId:e.asset_id,expiresIn:900})});return F(t=>({...t,[e.asset_id]:n.url})),L(t=>({...t,[e.asset_id]:``})),t.open&&window.open(n.url,`_blank`,`noopener,noreferrer`),n.url}catch(n){let r=n instanceof Error?n.message:String(n);return L(t=>({...t,[e.asset_id]:r})),t.quiet||j({type:`error`,message:`Preview unavailable. Check S3 credentials or pull the asset locally.`}),null}}async function ke(e,t){try{let n=await Bm(e);j({type:`ok`,message:n.method===`fallback`?`Copied ${t} using browser fallback`:`Copied ${t}`}),N(Tb(t,e)?{label:t,text:e}:null)}catch(n){N(Tb(t,e)?{label:t,text:e}:null),j({type:`error`,message:n instanceof Error?n.message:String(n)})}}async function je(e){let t=await Oe(e,{quiet:!0});t&&await ke(t,`preview link`)}function Ne(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t:[...t,e.asset_id]),V(t=>t.some(t=>t.asset_id===e.asset_id)?t:[...t,e]))}function Z(e){oe(e),r(e.asset_id),ie(!0)}async function Pe(e){r(e),ie(!0);let t=he.find(t=>t.asset_id===e);if(t){oe(t);return}try{let t=await g(`/api/assets/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,assetIds:[e]})});t.assets[0]&&oe(t.assets[0])}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}function Fe(){m(`local`),l(`all`),d(`all`),x(``),ne(`backup`)}async function Ie(e){try{e.assetId&&r(e.assetId),e.view===`lineage`&&e.workspaceId&&await g(`/api/lineage-workspaces/${encodeURIComponent(e.workspaceId)}/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project:i,confirmWrite:!0})}),ie(!1),ne(e.view),j({type:`ok`,message:`Opened ${e.claim.target_title||e.claim.target_id}`})}catch(e){j({type:`error`,message:e instanceof Error?e.message:String(e)})}}function Le(e){e.local?.relative_path&&(z(t=>t.includes(e.asset_id)?t.filter(t=>t!==e.asset_id):[...t,e.asset_id]),V(t=>t.filter(t=>t.asset_id!==e.asset_id)))}return(0,p.useEffect)(()=>{Ce(),we()},[]),(0,p.useEffect)(()=>{let e=new URLSearchParams(window.location.search);e.get(`project`)!==i&&(e.set(`project`,i),window.history.replaceState(null,``,`${window.location.pathname}?${e.toString()}${window.location.hash}`))},[i]),(0,p.useEffect)(()=>{j(null),N(null),oe(null),ie(!1)},[i]),(0,p.useEffect)(()=>{Te()},[S,w,i,c,u,f,h,b,E]),(0,p.useEffect)(()=>{C(1)},[i,c,u,f,h,b,w]),(0,p.useEffect)(()=>{!Se(Y)||P[Y.asset_id]||Oe(Y,{quiet:!0})},[Y?.asset_id,Y?.s3?.version_id,P]),(0,p.useEffect)(()=>{if(A?.type!==`ok`)return;let e=window.setTimeout(()=>j(null),2600);return()=>window.clearTimeout(e)},[A?.message,A?.type]),(0,p.useEffect)(()=>{te===`backup`&&(m(`local`),l(`all`),d(`all`))},[te]),(0,p.useEffect)(()=>{q(null)},[te]),(0,p.useEffect)(()=>{ge||ie(!1)},[ge]),(0,X.jsx)(Me,{runtime:ce,children:(0,X.jsxs)(`div`,{className:`app-shell ${te===`lineage`?`lineage-mode`:``}`,children:[(0,X.jsx)(gb,{channel:h,channels:ye,liveSync:E,placementStatus:u,project:i,projects:o,setChannel:y,setPlacementStatus:d,setProject:a,setSource:m,setStatus:l,setView:ne,showBackupQueue:Fe,source:f,snapshot:J,status:c,totals:be}),(0,X.jsxs)(`main`,{className:`workspace`,children:[(0,X.jsx)(bb,{assetDetailsOpen:re,canInspectAsset:!!Y,loading:O,moreOpen:de===`topbar-more`,onMoreOpenChange:pe,query:b,refresh:Te,runtime:ce,runtimeIdentityUnavailable:K,setAssetDetailsOpen:ie,setQuery:x,setUploadOpen:ee,setView:e=>e===`backup`?Fe():ne(e),view:te}),A&&(0,X.jsx)(Sb,{toast:A,onDismiss:()=>j(null)}),M&&(0,X.jsx)(Ct,{copiedText:M,onDismiss:()=>N(null)}),(0,X.jsx)(Ot,{onCopy:ke,project:i,refreshKey:se,selectedAsset:Y,view:te}),te===`review`?(0,X.jsx)(Yy,{channel:h,onCopy:ke,onLocalReview:async(e,t)=>{await De(()=>_(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:e=>{Ne(e),U(!0)},onSelectAsset:e=>{Z(e)},project:i,selected:Y}):te===`ledger`?(0,X.jsx)(Vt,{project:i,query:b,onOpenAsset:Pe}):te===`content`?(0,X.jsx)(_t,{onCopy:ke,onOpenAsset:Pe,onToast:me,onWorkTargetsChanged:()=>G(e=>e+1),project:i,selectedAsset:Y}):te===`agents`?(0,X.jsx)(ze,{onCopy:ke,onOpenWork:Ie,project:i}):te===`backup`?(0,X.jsx)(zy,{assets:he,cli:ce?.cli,onCopy:ke,onLocalReview:async(e,t)=>{await De(()=>_(`/api/local-review/${e.asset_id}`,i,{reviewState:t,confirmWrite:!0}))},onOpenBackup:()=>U(!0),onQueueBackup:Ne,onSelectAsset:e=>{Z(e)},page:S,pageSize:w,project:i,selected:Y,selectedBackupIds:R,setPage:C,setPageSize:T,snapshot:J}):te===`assets`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Gy,{assets:_e,onClear:()=>{z([]),V([])},onOpen:()=>U(!0)}),(0,X.jsx)(Re,{assets:he,liveSync:E,onCopy:ke,onSelectionChanged:()=>G(e=>e+1),page:S,pageSize:w,previewUrls:P,project:i,selected:Y,setLiveSync:D,setPage:C,setPageSize:T,setSelectedId:r,snapshot:J,source:f,totals:be})]}):te===`settings`?(0,X.jsx)(pb,{onToast:me,project:i}):(0,X.jsx)(jy,{asset:Y,actionsOpen:de===`lineage-actions`,onAssetsChanged:Te,onActionsOpenChange:fe,onSelectedAsset:r,onToast:me,project:i})]}),te!==`lineage`&&re&&(0,X.jsx)(Ae,{asset:Y,onArchive:e=>void De(()=>_(`/api/assets/archive`,i,{assetId:e.asset_id,confirmArchive:!0})),onClose:()=>ie(!1),onCopy:(e,t)=>void ke(e,t),onCopyPreview:e=>void je(e),onDelete:(e,t)=>void De(()=>_(`/api/assets/delete-object`,i,{assetId:e.asset_id,confirmation:t})),onPlacement:(e,t,n)=>void De(()=>_(`/api/assets/placement`,i,{assetId:e.asset_id,channel:e.channel,...v(n),status:t,confirmWrite:!0})),onPresign:e=>void Oe(e,{open:!0}),onPromote:e=>void De(()=>_(`/api/assets/promote`,i,{assetId:e.asset_id,confirmWrite:!0})),onPull:e=>void De(()=>_(`/api/assets/pull`,i,{assetId:e.asset_id,out:`.asset-scratch`})),onToggleBackup:Le,previewError:Y&&I[Y.asset_id]||null,previewUrl:ve,selectedForBackup:Y?R.includes(Y.asset_id):!1}),W&&(0,X.jsx)(wb,{channels:ye.filter(e=>e!==`all`),project:i,onClose:()=>ee(!1),onError:e=>j({type:`error`,message:e}),onUploaded:async e=>{j({type:`ok`,message:e}),ee(!1),await Te()}}),H&&(0,X.jsx)(Py,{assets:_e,project:i,onClose:()=>U(!1),onError:e=>j({type:`error`,message:e}),onDone:async e=>{j({type:`ok`,message:e}),z([]),V([]),U(!1),await Te()}})]})})}(0,m.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(p.StrictMode,{children:(0,X.jsx)(Db,{})}));