@tuongaz/seeflow 0.1.28 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web/assets/index-CAzJGV0H.css +1 -0
- package/dist/web/assets/{index--9KvdiJU.js → index-DsvK7YK4.js} +2 -2
- package/dist/web/assets/{index.es-CehYgUiq.js → index.es-DaLRJeHV.js} +1 -1
- package/dist/web/assets/{jspdf.es.min-CaFlbpn0.js → jspdf.es.min-DwwAghh7.js} +3 -3
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/index-XIY68z9O.css +0 -1
|
@@ -7832,7 +7832,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
7832
7832
|
`))+1))}const i="#".repeat(o),s=n.enter("headingAtx"),c=n.enter("phrasing");a.move(i+" ");let l=n.containerPhrasing(e,{before:"# ",after:`
|
|
7833
7833
|
`,...a.current()});return/^[\t ]/.test(l)&&(l=Y2(l.charCodeAt(0))+l.slice(1)),l=l?i+" "+l:i,n.options.closeAtx&&(l+=" "+i),c(),s(),l}T1e.peek=UTe;function T1e(e){return e.value||""}function UTe(){return"<"}j1e.peek=WTe;function j1e(e,t,n,r){const o=nU(n),a=o==='"'?"Quote":"Apostrophe",i=n.enter("image");let s=n.enter("label");const c=n.createTracker(r);let l=c.move("![");return l+=c.move(n.safe(e.alt,{before:l,after:"]",...c.current()})),l+=c.move("]("),s(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(s=n.enter("destinationLiteral"),l+=c.move("<"),l+=c.move(n.safe(e.url,{before:l,after:">",...c.current()})),l+=c.move(">")):(s=n.enter("destinationRaw"),l+=c.move(n.safe(e.url,{before:l,after:e.title?" ":")",...c.current()}))),s(),e.title&&(s=n.enter(`title${a}`),l+=c.move(" "+o),l+=c.move(n.safe(e.title,{before:l,after:o,...c.current()})),l+=c.move(o),s()),l+=c.move(")"),i(),l}function WTe(){return"!"}N1e.peek=GTe;function N1e(e,t,n,r){const o=e.referenceType,a=n.enter("imageReference");let i=n.enter("label");const s=n.createTracker(r);let c=s.move("![");const l=n.safe(e.alt,{before:c,after:"]",...s.current()});c+=s.move(l+"]["),i();const u=n.stack;n.stack=[],i=n.enter("reference");const d=n.safe(n.associationId(e),{before:c,after:"]",...s.current()});return i(),n.stack=u,a(),o==="full"||!l||l!==d?c+=s.move(d+"]"):o==="shortcut"?c=c.slice(0,-1):c+=s.move("]"),c}function GTe(){return"!"}z1e.peek=KTe;function z1e(e,t,n){let r=e.value||"",o="`",a=-1;for(;new RegExp("(^|[^`])"+o+"([^`]|$)").test(r);)o+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++a<n.unsafe.length;){const i=n.unsafe[a],s=n.compilePattern(i);let c;if(i.atBreak)for(;c=s.exec(r);){let l=c.index;r.charCodeAt(l)===10&&r.charCodeAt(l-1)===13&&l--,r=r.slice(0,l)+" "+r.slice(c.index+1)}}return o+r+o}function KTe(){return"`"}function D1e(e,t){const n=G$(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}q1e.peek=ZTe;function q1e(e,t,n,r){const o=nU(n),a=o==='"'?"Quote":"Apostrophe",i=n.createTracker(r);let s,c;if(D1e(e,n)){const u=n.stack;n.stack=[],s=n.enter("autolink");let d=i.move("<");return d+=i.move(n.containerPhrasing(e,{before:d,after:">",...i.current()})),d+=i.move(">"),s(),n.stack=u,d}s=n.enter("link"),c=n.enter("label");let l=i.move("[");return l+=i.move(n.containerPhrasing(e,{before:l,after:"](",...i.current()})),l+=i.move("]("),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=n.enter("destinationLiteral"),l+=i.move("<"),l+=i.move(n.safe(e.url,{before:l,after:">",...i.current()})),l+=i.move(">")):(c=n.enter("destinationRaw"),l+=i.move(n.safe(e.url,{before:l,after:e.title?" ":")",...i.current()}))),c(),e.title&&(c=n.enter(`title${a}`),l+=i.move(" "+o),l+=i.move(n.safe(e.title,{before:l,after:o,...i.current()})),l+=i.move(o),c()),l+=i.move(")"),s(),l}function ZTe(e,t,n){return D1e(e,n)?"<":"["}O1e.peek=XTe;function O1e(e,t,n,r){const o=e.referenceType,a=n.enter("linkReference");let i=n.enter("label");const s=n.createTracker(r);let c=s.move("[");const l=n.containerPhrasing(e,{before:c,after:"]",...s.current()});c+=s.move(l+"]["),i();const u=n.stack;n.stack=[],i=n.enter("reference");const d=n.safe(n.associationId(e),{before:c,after:"]",...s.current()});return i(),n.stack=u,a(),o==="full"||!l||l!==d?c+=s.move(d+"]"):o==="shortcut"?c=c.slice(0,-1):c+=s.move("]"),c}function XTe(){return"["}function rU(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function YTe(e){const t=rU(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function QTe(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function F1e(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function JTe(e,t,n,r){const o=n.enter("list"),a=n.bulletCurrent;let i=e.ordered?QTe(n):rU(n);const s=e.ordered?i==="."?")":".":YTe(n);let c=t&&n.bulletLastUsed?i===n.bulletLastUsed:!1;if(!e.ordered){const u=e.children?e.children[0]:void 0;if((i==="*"||i==="-")&&u&&(!u.children||!u.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(c=!0),F1e(n)===i&&u){let d=-1;for(;++d<e.children.length;){const f=e.children[d];if(f&&f.type==="listItem"&&f.children&&f.children[0]&&f.children[0].type==="thematicBreak"){c=!0;break}}}}c&&(i=s),n.bulletCurrent=i;const l=n.containerFlow(e,r);return n.bulletLastUsed=i,n.bulletCurrent=a,o(),l}function eje(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function tje(e,t,n,r){const o=eje(n);let a=n.bulletCurrent||rU(n);t&&t.type==="list"&&t.ordered&&(a=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+a);let i=a.length+1;(o==="tab"||o==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(i=Math.ceil(i/4)*4);const s=n.createTracker(r);s.move(a+" ".repeat(i-a.length)),s.shift(i);const c=n.enter("listItem"),l=n.indentLines(n.containerFlow(e,s.current()),u);return c(),l;function u(d,f,p){return f?(p?"":" ".repeat(i))+d:(p?a:a+" ".repeat(i-a.length))+d}}function nje(e,t,n,r){const o=n.enter("paragraph"),a=n.enter("phrasing"),i=n.containerPhrasing(e,r);return a(),o(),i}const rje=XT(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function oje(e,t,n,r){return(e.children.some(function(i){return rje(i)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function aje(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}H1e.peek=ije;function H1e(e,t,n,r){const o=aje(n),a=n.enter("strong"),i=n.createTracker(r),s=i.move(o+o);let c=i.move(n.containerPhrasing(e,{after:o,before:s,...i.current()}));const l=c.charCodeAt(0),u=wR(r.before.charCodeAt(r.before.length-1),l,o);u.inside&&(c=Y2(l)+c.slice(1));const d=c.charCodeAt(c.length-1),f=wR(r.after.charCodeAt(0),d,o);f.inside&&(c=c.slice(0,-1)+Y2(d));const p=i.move(o+o);return a(),n.attentionEncodeSurroundingInfo={after:f.outside,before:u.outside},s+c+p}function ije(e,t,n){return n.options.strong||"*"}function sje(e,t,n,r){return n.safe(e.value,r)}function cje(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function lje(e,t,n){const r=(F1e(n)+(n.options.ruleSpaces?" ":"")).repeat(cje(n));return n.options.ruleSpaces?r.slice(0,-1):r}const B1e={blockquote:RTe,break:Tee,code:qTe,definition:FTe,emphasis:R1e,hardBreak:Tee,heading:$Te,html:T1e,image:j1e,imageReference:N1e,inlineCode:z1e,link:q1e,linkReference:O1e,list:JTe,listItem:tje,paragraph:nje,root:oje,strong:H1e,text:sje,thematicBreak:lje};function uje(){return{enter:{table:dje,tableData:jee,tableHeader:jee,tableRow:fje},exit:{codeText:pje,table:hje,tableData:gF,tableHeader:gF,tableRow:gF}}}function dje(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function hje(e){this.exit(e),this.data.inTable=void 0}function fje(e){this.enter({type:"tableRow",children:[]},e)}function gF(e){this.exit(e)}function jee(e){this.enter({type:"tableCell",children:[]},e)}function pje(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,yje));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function yje(e,t){return t==="|"?t:e}function mje(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,o=t.stringLength,a=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
7834
7834
|
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:f,table:i,tableCell:c,tableRow:s}};function i(p,y,k,w){return l(u(p,k,w),p.align)}function s(p,y,k,w){const v=d(p,k,w),M=l([v]);return M.slice(0,M.indexOf(`
|
|
7835
|
-
`))}function c(p,y,k,w){const v=k.enter("tableCell"),M=k.enter("phrasing"),x=k.containerPhrasing(p,{...w,before:a,after:a});return M(),v(),x}function l(p,y){return PTe(p,{align:y,alignDelimiters:r,padding:n,stringLength:o})}function u(p,y,k){const w=p.children;let v=-1;const M=[],x=y.enter("table");for(;++v<w.length;)M[v]=d(w[v],y,k);return x(),M}function d(p,y,k){const w=p.children;let v=-1;const M=[],x=y.enter("tableRow");for(;++v<w.length;)M[v]=c(w[v],p,y,k);return x(),M}function f(p,y,k){let w=B1e.inlineCode(p,y,k);return k.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function gje(){return{exit:{taskListCheckValueChecked:Nee,taskListCheckValueUnchecked:Nee,paragraph:vje}}}function kje(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:xje}}}function Nee(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function vje(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const o=t.children;let a=-1,i;for(;++a<o.length;){const s=o[a];if(s.type==="paragraph"){i=s;break}}i===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function xje(e,t,n,r){const o=e.children[0],a=typeof e.checked=="boolean"&&o&&o.type==="paragraph",i="["+(e.checked?"x":" ")+"] ",s=n.createTracker(r);a&&s.move(i);let c=B1e.listItem(e,t,n,{...r,...s.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),c;function l(u){return u+i}}function wje(){return[JRe(),xTe(),CTe(),uje(),gje()]}function Mje(e){return{extensions:[eTe(),wTe(e),STe(),mje(e),kje()]}}const bje={tokenize:Aje,partial:!0},V1e={tokenize:Pje,partial:!0},$1e={tokenize:_je,partial:!0},U1e={tokenize:Rje,partial:!0},Cje={tokenize:Tje,partial:!0},W1e={name:"wwwAutolink",tokenize:Ije,previous:K1e},G1e={name:"protocolAutolink",tokenize:Eje,previous:Z1e},fa={name:"emailAutolink",tokenize:Lje,previous:X1e},_o={};function Sje(){return{text:_o}}let Pi=48;for(;Pi<123;)_o[Pi]=fa,Pi++,Pi===58?Pi=65:Pi===91&&(Pi=97);_o[43]=fa;_o[45]=fa;_o[46]=fa;_o[95]=fa;_o[72]=[fa,G1e];_o[104]=[fa,G1e];_o[87]=[fa,W1e];_o[119]=[fa,W1e];function Lje(e,t,n){const r=this;let o,a;return i;function i(d){return!gB(d)||!X1e.call(r,r.previous)||oU(r.events)?n(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),s(d))}function s(d){return gB(d)?(e.consume(d),s):d===64?(e.consume(d),c):n(d)}function c(d){return d===46?e.check(Cje,u,l)(d):d===45||d===95||cn(d)?(a=!0,e.consume(d),c):u(d)}function l(d){return e.consume(d),o=!0,c}function u(d){return a&&o&&yn(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):n(d)}}function Ije(e,t,n){const r=this;return o;function o(i){return i!==87&&i!==119||!K1e.call(r,r.previous)||oU(r.events)?n(i):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(bje,e.attempt(V1e,e.attempt($1e,a),n),n)(i))}function a(i){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(i)}}function Eje(e,t,n){const r=this;let o="",a=!1;return i;function i(d){return(d===72||d===104)&&Z1e.call(r,r.previous)&&!oU(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),o+=String.fromCodePoint(d),e.consume(d),s):n(d)}function s(d){if(yn(d)&&o.length<5)return o+=String.fromCodePoint(d),e.consume(d),s;if(d===58){const f=o.toLowerCase();if(f==="http"||f==="https")return e.consume(d),c}return n(d)}function c(d){return d===47?(e.consume(d),a?l:(a=!0,c)):n(d)}function l(d){return d===null||kR(d)||ft(d)||Eu(d)||GT(d)?n(d):e.attempt(V1e,e.attempt($1e,u),n)(d)}function u(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function Aje(e,t,n){let r=0;return o;function o(i){return(i===87||i===119)&&r<3?(r++,e.consume(i),o):i===46&&r===3?(e.consume(i),a):n(i)}function a(i){return i===null?n(i):t(i)}}function Pje(e,t,n){let r,o,a;return i;function i(l){return l===46||l===95?e.check(U1e,c,s)(l):l===null||ft(l)||Eu(l)||l!==45&>(l)?c(l):(a=!0,e.consume(l),i)}function s(l){return l===95?r=!0:(o=r,r=void 0),e.consume(l),i}function c(l){return o||r||!a?n(l):t(l)}}function _je(e,t){let n=0,r=0;return o;function o(i){return i===40?(n++,e.consume(i),o):i===41&&r<n?a(i):i===33||i===34||i===38||i===39||i===41||i===42||i===44||i===46||i===58||i===59||i===60||i===63||i===93||i===95||i===126?e.check(U1e,t,a)(i):i===null||ft(i)||Eu(i)?t(i):(e.consume(i),o)}function a(i){return i===41&&r++,e.consume(i),o}}function Rje(e,t,n){return r;function r(s){return s===33||s===34||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===63||s===95||s===126?(e.consume(s),r):s===38?(e.consume(s),a):s===93?(e.consume(s),o):s===60||s===null||ft(s)||Eu(s)?t(s):n(s)}function o(s){return s===null||s===40||s===91||ft(s)||Eu(s)?t(s):r(s)}function a(s){return yn(s)?i(s):n(s)}function i(s){return s===59?(e.consume(s),r):yn(s)?(e.consume(s),i):n(s)}}function Tje(e,t,n){return r;function r(a){return e.consume(a),o}function o(a){return cn(a)?n(a):t(a)}}function K1e(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ft(e)}function Z1e(e){return!yn(e)}function X1e(e){return!(e===47||gB(e))}function gB(e){return e===43||e===45||e===46||e===95||cn(e)}function oU(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const jje={tokenize:Bje,partial:!0};function Nje(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Oje,continuation:{tokenize:Fje},exit:Hje}},text:{91:{name:"gfmFootnoteCall",tokenize:qje},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:zje,resolveTo:Dje}}}}function zje(e,t,n){const r=this;let o=r.events.length;const a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i;for(;o--;){const c=r.events[o][1];if(c.type==="labelImage"){i=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return s;function s(c){if(!i||!i._balanced)return n(c);const l=qr(r.sliceSerialize({start:i.end,end:r.now()}));return l.codePointAt(0)!==94||!a.includes(l.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function Dje(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},e[e.length-1][1].start)},i={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",o,t],["exit",o,t],["enter",a,t],["enter",i,t],["exit",i,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...s),e}function qje(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a=0,i;return s;function s(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),c}function c(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",l)}function l(d){if(a>999||d===93&&!i||d===null||d===91||ft(d))return n(d);if(d===93){e.exit("chunkString");const f=e.exit("gfmFootnoteCallString");return o.includes(qr(r.sliceSerialize(f)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return ft(d)||(i=!0),a++,e.consume(d),d===92?u:l}function u(d){return d===91||d===92||d===93?(e.consume(d),a++,l):l(d)}}function Oje(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a,i=0,s;return c;function c(y){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(y),e.exit("gfmFootnoteDefinitionLabelMarker"),l}function l(y){return y===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(y),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",u):n(y)}function u(y){if(i>999||y===93&&!s||y===null||y===91||ft(y))return n(y);if(y===93){e.exit("chunkString");const k=e.exit("gfmFootnoteDefinitionLabelString");return a=qr(r.sliceSerialize(k)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(y),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),f}return ft(y)||(s=!0),i++,e.consume(y),y===92?d:u}function d(y){return y===91||y===92||y===93?(e.consume(y),i++,u):u(y)}function f(y){return y===58?(e.enter("definitionMarker"),e.consume(y),e.exit("definitionMarker"),o.includes(a)||o.push(a),tt(e,p,"gfmFootnoteDefinitionWhitespace")):n(y)}function p(y){return t(y)}}function Fje(e,t,n){return e.check(Ff,t,e.attempt(jje,t,n))}function Hje(e){e.exit("gfmFootnoteDefinition")}function Bje(e,t,n){const r=this;return tt(e,o,"gfmFootnoteDefinitionIndent",5);function o(a){const i=r.events[r.events.length-1];return i&&i[1].type==="gfmFootnoteDefinitionIndent"&&i[2].sliceSerialize(i[1],!0).length===4?t(a):n(a)}}function Vje(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:a,resolveAll:o};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function o(i,s){let c=-1;for(;++c<i.length;)if(i[c][0]==="enter"&&i[c][1].type==="strikethroughSequenceTemporary"&&i[c][1]._close){let l=c;for(;l--;)if(i[l][0]==="exit"&&i[l][1].type==="strikethroughSequenceTemporary"&&i[l][1]._open&&i[c][1].end.offset-i[c][1].start.offset===i[l][1].end.offset-i[l][1].start.offset){i[c][1].type="strikethroughSequence",i[l][1].type="strikethroughSequence";const u={type:"strikethrough",start:Object.assign({},i[l][1].start),end:Object.assign({},i[c][1].end)},d={type:"strikethroughText",start:Object.assign({},i[l][1].end),end:Object.assign({},i[c][1].start)},f=[["enter",u,s],["enter",i[l][1],s],["exit",i[l][1],s],["enter",d,s]],p=s.parser.constructs.insideSpan.null;p&&Xn(f,f.length,0,KT(p,i.slice(l+1,c),s)),Xn(f,f.length,0,[["exit",d,s],["enter",i[c][1],s],["exit",i[c][1],s],["exit",u,s]]),Xn(i,l-1,c-l+3,f),c=l+f.length-2;break}}for(c=-1;++c<i.length;)i[c][1].type==="strikethroughSequenceTemporary"&&(i[c][1].type="data");return i}function a(i,s,c){const l=this.previous,u=this.events;let d=0;return f;function f(y){return l===126&&u[u.length-1][1].type!=="characterEscape"?c(y):(i.enter("strikethroughSequenceTemporary"),p(y))}function p(y){const k=md(l);if(y===126)return d>1?c(y):(i.consume(y),d++,p);if(d<2&&!n)return c(y);const w=i.exit("strikethroughSequenceTemporary"),v=md(y);return w._open=!v||v===2&&!!k,w._close=!k||k===2&&!!v,s(y)}}}class $je{constructor(){this.map=[]}add(t,n,r){Uje(this,t,n,r)}consume(t){if(this.map.sort(function(a,i){return a[0]-i[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let o=r.pop();for(;o;){for(const a of o)t.push(a);o=r.pop()}this.map.length=0}}function Uje(e,t,n,r){let o=0;if(!(n===0&&r.length===0)){for(;o<e.map.length;){if(e.map[o][0]===t){e.map[o][1]+=n,e.map[o][2].push(...r);return}o+=1}e.map.push([t,n,r])}}function Wje(e,t){let n=!1;const r=[];for(;t<e.length;){const o=e[t];if(n){if(o[0]==="enter")o[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(o[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const a=r.length-1;r[a]=r[a]==="left"?"center":"right"}}else if(o[1].type==="tableDelimiterRow")break}else o[0]==="enter"&&o[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function Gje(){return{flow:{null:{name:"table",tokenize:Kje,resolveAll:Zje}}}}function Kje(e,t,n){const r=this;let o=0,a=0,i;return s;function s(E){let P=r.events.length-1;for(;P>-1;){const R=r.events[P][1].type;if(R==="lineEnding"||R==="linePrefix")P--;else break}const A=P>-1?r.events[P][1].type:null,U=A==="tableHead"||A==="tableRow"?C:c;return U===C&&r.parser.lazy[r.now().line]?n(E):U(E)}function c(E){return e.enter("tableHead"),e.enter("tableRow"),l(E)}function l(E){return E===124||(i=!0,a+=1),u(E)}function u(E){return E===null?n(E):ze(E)?a>1?(a=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(E),e.exit("lineEnding"),p):n(E):Ye(E)?tt(e,u,"whitespace")(E):(a+=1,i&&(i=!1,o+=1),E===124?(e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),i=!0,u):(e.enter("data"),d(E)))}function d(E){return E===null||E===124||ft(E)?(e.exit("data"),u(E)):(e.consume(E),E===92?f:d)}function f(E){return E===92||E===124?(e.consume(E),d):d(E)}function p(E){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(E):(e.enter("tableDelimiterRow"),i=!1,Ye(E)?tt(e,y,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(E):y(E))}function y(E){return E===45||E===58?w(E):E===124?(i=!0,e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),k):S(E)}function k(E){return Ye(E)?tt(e,w,"whitespace")(E):w(E)}function w(E){return E===58?(a+=1,i=!0,e.enter("tableDelimiterMarker"),e.consume(E),e.exit("tableDelimiterMarker"),v):E===45?(a+=1,v(E)):E===null||ze(E)?b(E):S(E)}function v(E){return E===45?(e.enter("tableDelimiterFiller"),M(E)):S(E)}function M(E){return E===45?(e.consume(E),M):E===58?(i=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(E),e.exit("tableDelimiterMarker"),x):(e.exit("tableDelimiterFiller"),x(E))}function x(E){return Ye(E)?tt(e,b,"whitespace")(E):b(E)}function b(E){return E===124?y(E):E===null||ze(E)?!i||o!==a?S(E):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(E)):S(E)}function S(E){return n(E)}function C(E){return e.enter("tableRow"),L(E)}function L(E){return E===124?(e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),L):E===null||ze(E)?(e.exit("tableRow"),t(E)):Ye(E)?tt(e,L,"whitespace")(E):(e.enter("data"),_(E))}function _(E){return E===null||E===124||ft(E)?(e.exit("data"),L(E)):(e.consume(E),E===92?T:_)}function T(E){return E===92||E===124?(e.consume(E),_):_(E)}}function Zje(e,t){let n=-1,r=!0,o=0,a=[0,0,0,0],i=[0,0,0,0],s=!1,c=0,l,u,d;const f=new $je;for(;++n<e.length;){const p=e[n],y=p[1];p[0]==="enter"?y.type==="tableHead"?(s=!1,c!==0&&(zee(f,t,c,l,u),u=void 0,c=0),l={type:"table",start:Object.assign({},y.start),end:Object.assign({},y.end)},f.add(n,0,[["enter",l,t]])):y.type==="tableRow"||y.type==="tableDelimiterRow"?(r=!0,d=void 0,a=[0,0,0,0],i=[0,n+1,0,0],s&&(s=!1,u={type:"tableBody",start:Object.assign({},y.start),end:Object.assign({},y.end)},f.add(n,0,[["enter",u,t]])),o=y.type==="tableDelimiterRow"?2:u?3:1):o&&(y.type==="data"||y.type==="tableDelimiterMarker"||y.type==="tableDelimiterFiller")?(r=!1,i[2]===0&&(a[1]!==0&&(i[0]=i[1],d=U0(f,t,a,o,void 0,d),a=[0,0,0,0]),i[2]=n)):y.type==="tableCellDivider"&&(r?r=!1:(a[1]!==0&&(i[0]=i[1],d=U0(f,t,a,o,void 0,d)),a=i,i=[a[1],n,0,0])):y.type==="tableHead"?(s=!0,c=n):y.type==="tableRow"||y.type==="tableDelimiterRow"?(c=n,a[1]!==0?(i[0]=i[1],d=U0(f,t,a,o,n,d)):i[1]!==0&&(d=U0(f,t,i,o,n,d)),o=0):o&&(y.type==="data"||y.type==="tableDelimiterMarker"||y.type==="tableDelimiterFiller")&&(i[3]=n)}for(c!==0&&zee(f,t,c,l,u),f.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Wje(t.events,n))}return e}function U0(e,t,n,r,o,a){const i=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",s="tableContent";n[0]!==0&&(a.end=Object.assign({},d1(t.events,n[0])),e.add(n[0],0,[["exit",a,t]]));const c=d1(t.events,n[1]);if(a={type:i,start:Object.assign({},c),end:Object.assign({},c)},e.add(n[1],0,[["enter",a,t]]),n[2]!==0){const l=d1(t.events,n[2]),u=d1(t.events,n[3]),d={type:s,start:Object.assign({},l),end:Object.assign({},u)};if(e.add(n[2],0,[["enter",d,t]]),r!==2){const f=t.events[n[2]],p=t.events[n[3]];if(f[1].end=Object.assign({},p[1].end),f[1].type="chunkText",f[1].contentType="text",n[3]>n[2]+1){const y=n[2]+1,k=n[3]-n[2]-1;e.add(y,k,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return o!==void 0&&(a.end=Object.assign({},d1(t.events,o)),e.add(o,0,[["exit",a,t]]),a=void 0),a}function zee(e,t,n,r,o){const a=[],i=d1(t.events,n);o&&(o.end=Object.assign({},i),a.push(["exit",o,t])),r.end=Object.assign({},i),a.push(["exit",r,t]),e.add(n+1,0,a)}function d1(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const Xje={name:"tasklistCheck",tokenize:Qje};function Yje(){return{text:{91:Xje}}}function Qje(e,t,n){const r=this;return o;function o(c){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(c):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),a)}function a(c){return ft(c)?(e.enter("taskListCheckValueUnchecked"),e.consume(c),e.exit("taskListCheckValueUnchecked"),i):c===88||c===120?(e.enter("taskListCheckValueChecked"),e.consume(c),e.exit("taskListCheckValueChecked"),i):n(c)}function i(c){return c===93?(e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),s):n(c)}function s(c){return ze(c)?t(c):Ye(c)?e.check({tokenize:Jje},t,n)(c):n(c)}}function Jje(e,t,n){return tt(e,r,"whitespace");function r(o){return o===null?n(o):t(o)}}function eNe(e){return i1e([Sje(),Nje(),Vje(e),Gje(),Yje()])}const tNe={};function nNe(e){const t=this,n=e||tNe,r=t.data(),o=r.micromarkExtensions||(r.micromarkExtensions=[]),a=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),i=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);o.push(eNe(n)),a.push(wje()),i.push(Mje(n))}function rNe({flowId:e,node:t,connector:n,adapter:r,onNameChange:o,onDescriptionChange:a,onDetailChange:i,onIconChange:s,statusReport:c,onClose:l}){const u=(t==null?void 0:t.type)==="shapeNode"&&t.data.shape==="text",d=(t==null?void 0:t.type)==="shapeNode"?t.data.shape:void 0,f=d==="ellipse"||d==="sticky",p=u?null:t,y=p!==null||n!==null,k=p&&"name"in p.data?p.data.name??"":"",w=(p==null?void 0:p.data.description)??"",v=(p==null?void 0:p.data.detail)??"",M=p!==null&&!f,x=p!==null&&(p.type==="playNode"||p.type==="stateNode"),b=x&&typeof s=="function",S=x&&p&&"icon"in p.data?p.data.icon??null:null,[C,L]=g.useState(()=>tMe()),_=E=>{E.preventDefault(),rMe(C,E.clientX,{onWidth:L,onCommit:nMe})},T={"--detail-panel-w":`${C}px`};return m.jsx(NIe,{open:y,modal:!1,onOpenChange:E=>{E||l()},children:m.jsxs(pue,{side:"right",className:"sf:overflow-y-auto sf:bg-card/94 sf:backdrop-blur-[14px] sf:border-border sf:shadow-[-12px_0_40px_-12px_rgba(0,0,0,0.6)] sf:sm:w-(--detail-panel-w)! sf:sm:max-w-(--detail-panel-w)!",style:T,"data-testid":"detail-panel",onEscapeKeyDown:E=>{var A;const P=document.activeElement;(A=P==null?void 0:P.getAttribute("data-testid"))!=null&&A.endsWith("-editor")&&E.preventDefault()},onInteractOutside:E=>{var U;const P=document.activeElement;(U=P==null?void 0:P.getAttribute("data-testid"))!=null&&U.endsWith("-editor")&&P.blur();const A=E.target;A!=null&&A.closest(".react-flow__resize-control")&&E.preventDefault(),A!=null&&A.closest("[data-radix-popper-content-wrapper]")&&E.preventDefault(),A!=null&&A.closest('[data-testid="canvas-style-strip"]')&&E.preventDefault(),A!=null&&A.closest(".react-flow__node")&&E.preventDefault(),A!=null&&A.closest(".react-flow__edge")&&E.preventDefault()},children:[m.jsx("div",{"aria-label":"Resize detail panel",onPointerDown:_,"data-testid":"detail-panel-resize-handle",className:"sf:absolute sf:inset-y-0 sf:left-0 sf:z-10 sf:hidden sf:w-1.5 sf:cursor-col-resize sf:bg-transparent sf:transition-colors sf:hover:bg-border sf:sm:block"}),p?m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-4",children:[m.jsxs("div",{className:"sf:-mx-6 sf:-mt-6 sf:flex sf:flex-col sf:gap-2 sf:border-b sf:border-border/60 sf:bg-card/60 sf:px-6 sf:pb-4 sf:pt-5",children:[m.jsx("span",{className:"sf:font-mono sf:text-[10px] sf:font-medium sf:uppercase sf:tracking-[0.18em] sf:text-muted-foreground/70",children:"Node"}),M?m.jsx(v_,{"data-testid":"detail-panel-title",children:m.jsxs("div",{className:"sf:flex sf:items-center sf:gap-2",children:[b&&s?m.jsx(oNe,{nodeId:p.id,icon:S,onChange:s}):x&&S?m.jsx("span",{"data-testid":"detail-panel-icon-readonly","aria-hidden":!0,className:"sf:inline-flex sf:h-7 sf:w-7 sf:shrink-0 sf:items-center sf:justify-center sf:text-foreground/90",children:m.jsx(Cu,{name:S,size:16})}):null,m.jsx("div",{className:"sf:min-w-0 sf:flex-1",children:m.jsx(kF,{nodeId:p.id,value:k,placeholder:"Name",multiline:!1,ariaLabel:"Name",testIdBase:"detail-panel-name",onSave:o,textClassName:"sf:text-lg sf:font-semibold sf:tracking-tight sf:text-foreground/95"})})]})}):m.jsx(v_,{"data-testid":"detail-panel-title",className:"sf:sr-only",children:p.id}),m.jsxs(tB,{className:"sf:sr-only",children:[p.id," · ",p.type]})]}),m.jsxs("div",{className:"sf:mt-0 sf:flex sf:flex-col sf:gap-3",children:[c?m.jsx(cNe,{report:c}):null,m.jsx(kF,{nodeId:p.id,value:w,placeholder:"Short description shown on the node body",multiline:!0,ariaLabel:"Description",testIdBase:"detail-panel-description",onSave:a,textClassName:"sf:text-[13px] sf:leading-relaxed sf:text-muted-foreground"}),m.jsx(kF,{nodeId:p.id,value:v,placeholder:"Long-form notes, context, anything…",multiline:!0,ariaLabel:"Detail",testIdBase:"detail-panel-detail",onSave:i,markdown:!0,textClassName:"sf:text-sm sf:leading-relaxed sf:text-foreground/90"}),p.type==="htmlNode"&&e?m.jsx(aNe,{adapter:r,htmlPath:p.data.htmlPath}):null]})]}):n?m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-4",children:[m.jsxs("div",{className:"sf:-mx-6 sf:-mt-6 sf:flex sf:flex-col sf:gap-2 sf:border-b sf:border-border/60 sf:bg-card/60 sf:px-6 sf:pb-4 sf:pt-5",children:[m.jsx("span",{className:"sf:font-mono sf:text-[10px] sf:font-medium sf:uppercase sf:tracking-[0.18em] sf:text-muted-foreground/70",children:"Connector"}),m.jsx(v_,{"data-testid":"detail-panel-title",className:"sf:text-lg sf:font-semibold sf:tracking-tight sf:text-foreground/95",children:n.label??"Connector"}),m.jsxs(tB,{className:"sf:sr-only",children:[n.id," · ",n.kind]})]}),m.jsx("div",{className:"sf:mt-0 sf:flex sf:flex-col sf:gap-3",children:m.jsx(lNe,{connector:n})})]}):null]})})}function kF({nodeId:e,value:t,placeholder:n,multiline:r,ariaLabel:o,testIdBase:a,onSave:i,textClassName:s,markdown:c=!1}){const[l,u]=g.useState(!1),d=g.useRef(null),f=g.useRef(!1);g.useEffect(()=>{if(!l)return;const S=d.current;if(!S)return;S.textContent=t,S.focus();const C=window.getSelection();if(C){const L=document.createRange();L.selectNodeContents(S),L.collapse(!1),C.removeAllRanges(),C.addRange(L)}},[l,t]);const p=t==="";if(!i)return m.jsx("div",{"data-testid":a,"aria-label":o,className:ae("sf:w-full sf:rounded-md sf:px-2 sf:py-1.5 sf:text-sm",p?"sf:italic sf:text-muted-foreground/50":"text-foreground",!c&&"sf:whitespace-pre-wrap sf:wrap-break-word",s),children:p?n:c?m.jsx(Dee,{value:t}):t});const y=()=>{var C;const S=((C=d.current)==null?void 0:C.textContent)??t;i(e,S),u(!1)},k=()=>{u(!1)},w=S=>{if(S.stopPropagation(),S.nativeEvent.stopPropagation(),S.key==="Escape"){S.preventDefault(),f.current=!0,k();return}if(S.key==="Enter"){if(S.preventDefault(),S.shiftKey||!r){y();return}document.execCommand("insertText",!1,`
|
|
7835
|
+
`))}function c(p,y,k,w){const v=k.enter("tableCell"),M=k.enter("phrasing"),x=k.containerPhrasing(p,{...w,before:a,after:a});return M(),v(),x}function l(p,y){return PTe(p,{align:y,alignDelimiters:r,padding:n,stringLength:o})}function u(p,y,k){const w=p.children;let v=-1;const M=[],x=y.enter("table");for(;++v<w.length;)M[v]=d(w[v],y,k);return x(),M}function d(p,y,k){const w=p.children;let v=-1;const M=[],x=y.enter("tableRow");for(;++v<w.length;)M[v]=c(w[v],p,y,k);return x(),M}function f(p,y,k){let w=B1e.inlineCode(p,y,k);return k.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function gje(){return{exit:{taskListCheckValueChecked:Nee,taskListCheckValueUnchecked:Nee,paragraph:vje}}}function kje(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:xje}}}function Nee(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function vje(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const o=t.children;let a=-1,i;for(;++a<o.length;){const s=o[a];if(s.type==="paragraph"){i=s;break}}i===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function xje(e,t,n,r){const o=e.children[0],a=typeof e.checked=="boolean"&&o&&o.type==="paragraph",i="["+(e.checked?"x":" ")+"] ",s=n.createTracker(r);a&&s.move(i);let c=B1e.listItem(e,t,n,{...r,...s.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),c;function l(u){return u+i}}function wje(){return[JRe(),xTe(),CTe(),uje(),gje()]}function Mje(e){return{extensions:[eTe(),wTe(e),STe(),mje(e),kje()]}}const bje={tokenize:Aje,partial:!0},V1e={tokenize:Pje,partial:!0},$1e={tokenize:_je,partial:!0},U1e={tokenize:Rje,partial:!0},Cje={tokenize:Tje,partial:!0},W1e={name:"wwwAutolink",tokenize:Ije,previous:K1e},G1e={name:"protocolAutolink",tokenize:Eje,previous:Z1e},fa={name:"emailAutolink",tokenize:Lje,previous:X1e},_o={};function Sje(){return{text:_o}}let Pi=48;for(;Pi<123;)_o[Pi]=fa,Pi++,Pi===58?Pi=65:Pi===91&&(Pi=97);_o[43]=fa;_o[45]=fa;_o[46]=fa;_o[95]=fa;_o[72]=[fa,G1e];_o[104]=[fa,G1e];_o[87]=[fa,W1e];_o[119]=[fa,W1e];function Lje(e,t,n){const r=this;let o,a;return i;function i(d){return!gB(d)||!X1e.call(r,r.previous)||oU(r.events)?n(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),s(d))}function s(d){return gB(d)?(e.consume(d),s):d===64?(e.consume(d),c):n(d)}function c(d){return d===46?e.check(Cje,u,l)(d):d===45||d===95||cn(d)?(a=!0,e.consume(d),c):u(d)}function l(d){return e.consume(d),o=!0,c}function u(d){return a&&o&&yn(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):n(d)}}function Ije(e,t,n){const r=this;return o;function o(i){return i!==87&&i!==119||!K1e.call(r,r.previous)||oU(r.events)?n(i):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(bje,e.attempt(V1e,e.attempt($1e,a),n),n)(i))}function a(i){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(i)}}function Eje(e,t,n){const r=this;let o="",a=!1;return i;function i(d){return(d===72||d===104)&&Z1e.call(r,r.previous)&&!oU(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),o+=String.fromCodePoint(d),e.consume(d),s):n(d)}function s(d){if(yn(d)&&o.length<5)return o+=String.fromCodePoint(d),e.consume(d),s;if(d===58){const f=o.toLowerCase();if(f==="http"||f==="https")return e.consume(d),c}return n(d)}function c(d){return d===47?(e.consume(d),a?l:(a=!0,c)):n(d)}function l(d){return d===null||kR(d)||ft(d)||Eu(d)||GT(d)?n(d):e.attempt(V1e,e.attempt($1e,u),n)(d)}function u(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function Aje(e,t,n){let r=0;return o;function o(i){return(i===87||i===119)&&r<3?(r++,e.consume(i),o):i===46&&r===3?(e.consume(i),a):n(i)}function a(i){return i===null?n(i):t(i)}}function Pje(e,t,n){let r,o,a;return i;function i(l){return l===46||l===95?e.check(U1e,c,s)(l):l===null||ft(l)||Eu(l)||l!==45&>(l)?c(l):(a=!0,e.consume(l),i)}function s(l){return l===95?r=!0:(o=r,r=void 0),e.consume(l),i}function c(l){return o||r||!a?n(l):t(l)}}function _je(e,t){let n=0,r=0;return o;function o(i){return i===40?(n++,e.consume(i),o):i===41&&r<n?a(i):i===33||i===34||i===38||i===39||i===41||i===42||i===44||i===46||i===58||i===59||i===60||i===63||i===93||i===95||i===126?e.check(U1e,t,a)(i):i===null||ft(i)||Eu(i)?t(i):(e.consume(i),o)}function a(i){return i===41&&r++,e.consume(i),o}}function Rje(e,t,n){return r;function r(s){return s===33||s===34||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===63||s===95||s===126?(e.consume(s),r):s===38?(e.consume(s),a):s===93?(e.consume(s),o):s===60||s===null||ft(s)||Eu(s)?t(s):n(s)}function o(s){return s===null||s===40||s===91||ft(s)||Eu(s)?t(s):r(s)}function a(s){return yn(s)?i(s):n(s)}function i(s){return s===59?(e.consume(s),r):yn(s)?(e.consume(s),i):n(s)}}function Tje(e,t,n){return r;function r(a){return e.consume(a),o}function o(a){return cn(a)?n(a):t(a)}}function K1e(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ft(e)}function Z1e(e){return!yn(e)}function X1e(e){return!(e===47||gB(e))}function gB(e){return e===43||e===45||e===46||e===95||cn(e)}function oU(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const jje={tokenize:Bje,partial:!0};function Nje(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Oje,continuation:{tokenize:Fje},exit:Hje}},text:{91:{name:"gfmFootnoteCall",tokenize:qje},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:zje,resolveTo:Dje}}}}function zje(e,t,n){const r=this;let o=r.events.length;const a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i;for(;o--;){const c=r.events[o][1];if(c.type==="labelImage"){i=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return s;function s(c){if(!i||!i._balanced)return n(c);const l=qr(r.sliceSerialize({start:i.end,end:r.now()}));return l.codePointAt(0)!==94||!a.includes(l.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function Dje(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},e[e.length-1][1].start)},i={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",o,t],["exit",o,t],["enter",a,t],["enter",i,t],["exit",i,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...s),e}function qje(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a=0,i;return s;function s(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),c}function c(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",l)}function l(d){if(a>999||d===93&&!i||d===null||d===91||ft(d))return n(d);if(d===93){e.exit("chunkString");const f=e.exit("gfmFootnoteCallString");return o.includes(qr(r.sliceSerialize(f)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return ft(d)||(i=!0),a++,e.consume(d),d===92?u:l}function u(d){return d===91||d===92||d===93?(e.consume(d),a++,l):l(d)}}function Oje(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a,i=0,s;return c;function c(y){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(y),e.exit("gfmFootnoteDefinitionLabelMarker"),l}function l(y){return y===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(y),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",u):n(y)}function u(y){if(i>999||y===93&&!s||y===null||y===91||ft(y))return n(y);if(y===93){e.exit("chunkString");const k=e.exit("gfmFootnoteDefinitionLabelString");return a=qr(r.sliceSerialize(k)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(y),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),f}return ft(y)||(s=!0),i++,e.consume(y),y===92?d:u}function d(y){return y===91||y===92||y===93?(e.consume(y),i++,u):u(y)}function f(y){return y===58?(e.enter("definitionMarker"),e.consume(y),e.exit("definitionMarker"),o.includes(a)||o.push(a),tt(e,p,"gfmFootnoteDefinitionWhitespace")):n(y)}function p(y){return t(y)}}function Fje(e,t,n){return e.check(Ff,t,e.attempt(jje,t,n))}function Hje(e){e.exit("gfmFootnoteDefinition")}function Bje(e,t,n){const r=this;return tt(e,o,"gfmFootnoteDefinitionIndent",5);function o(a){const i=r.events[r.events.length-1];return i&&i[1].type==="gfmFootnoteDefinitionIndent"&&i[2].sliceSerialize(i[1],!0).length===4?t(a):n(a)}}function Vje(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:a,resolveAll:o};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function o(i,s){let c=-1;for(;++c<i.length;)if(i[c][0]==="enter"&&i[c][1].type==="strikethroughSequenceTemporary"&&i[c][1]._close){let l=c;for(;l--;)if(i[l][0]==="exit"&&i[l][1].type==="strikethroughSequenceTemporary"&&i[l][1]._open&&i[c][1].end.offset-i[c][1].start.offset===i[l][1].end.offset-i[l][1].start.offset){i[c][1].type="strikethroughSequence",i[l][1].type="strikethroughSequence";const u={type:"strikethrough",start:Object.assign({},i[l][1].start),end:Object.assign({},i[c][1].end)},d={type:"strikethroughText",start:Object.assign({},i[l][1].end),end:Object.assign({},i[c][1].start)},f=[["enter",u,s],["enter",i[l][1],s],["exit",i[l][1],s],["enter",d,s]],p=s.parser.constructs.insideSpan.null;p&&Xn(f,f.length,0,KT(p,i.slice(l+1,c),s)),Xn(f,f.length,0,[["exit",d,s],["enter",i[c][1],s],["exit",i[c][1],s],["exit",u,s]]),Xn(i,l-1,c-l+3,f),c=l+f.length-2;break}}for(c=-1;++c<i.length;)i[c][1].type==="strikethroughSequenceTemporary"&&(i[c][1].type="data");return i}function a(i,s,c){const l=this.previous,u=this.events;let d=0;return f;function f(y){return l===126&&u[u.length-1][1].type!=="characterEscape"?c(y):(i.enter("strikethroughSequenceTemporary"),p(y))}function p(y){const k=md(l);if(y===126)return d>1?c(y):(i.consume(y),d++,p);if(d<2&&!n)return c(y);const w=i.exit("strikethroughSequenceTemporary"),v=md(y);return w._open=!v||v===2&&!!k,w._close=!k||k===2&&!!v,s(y)}}}class $je{constructor(){this.map=[]}add(t,n,r){Uje(this,t,n,r)}consume(t){if(this.map.sort(function(a,i){return a[0]-i[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let o=r.pop();for(;o;){for(const a of o)t.push(a);o=r.pop()}this.map.length=0}}function Uje(e,t,n,r){let o=0;if(!(n===0&&r.length===0)){for(;o<e.map.length;){if(e.map[o][0]===t){e.map[o][1]+=n,e.map[o][2].push(...r);return}o+=1}e.map.push([t,n,r])}}function Wje(e,t){let n=!1;const r=[];for(;t<e.length;){const o=e[t];if(n){if(o[0]==="enter")o[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(o[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const a=r.length-1;r[a]=r[a]==="left"?"center":"right"}}else if(o[1].type==="tableDelimiterRow")break}else o[0]==="enter"&&o[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function Gje(){return{flow:{null:{name:"table",tokenize:Kje,resolveAll:Zje}}}}function Kje(e,t,n){const r=this;let o=0,a=0,i;return s;function s(E){let P=r.events.length-1;for(;P>-1;){const R=r.events[P][1].type;if(R==="lineEnding"||R==="linePrefix")P--;else break}const A=P>-1?r.events[P][1].type:null,U=A==="tableHead"||A==="tableRow"?C:c;return U===C&&r.parser.lazy[r.now().line]?n(E):U(E)}function c(E){return e.enter("tableHead"),e.enter("tableRow"),l(E)}function l(E){return E===124||(i=!0,a+=1),u(E)}function u(E){return E===null?n(E):ze(E)?a>1?(a=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(E),e.exit("lineEnding"),p):n(E):Ye(E)?tt(e,u,"whitespace")(E):(a+=1,i&&(i=!1,o+=1),E===124?(e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),i=!0,u):(e.enter("data"),d(E)))}function d(E){return E===null||E===124||ft(E)?(e.exit("data"),u(E)):(e.consume(E),E===92?f:d)}function f(E){return E===92||E===124?(e.consume(E),d):d(E)}function p(E){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(E):(e.enter("tableDelimiterRow"),i=!1,Ye(E)?tt(e,y,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(E):y(E))}function y(E){return E===45||E===58?w(E):E===124?(i=!0,e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),k):S(E)}function k(E){return Ye(E)?tt(e,w,"whitespace")(E):w(E)}function w(E){return E===58?(a+=1,i=!0,e.enter("tableDelimiterMarker"),e.consume(E),e.exit("tableDelimiterMarker"),v):E===45?(a+=1,v(E)):E===null||ze(E)?b(E):S(E)}function v(E){return E===45?(e.enter("tableDelimiterFiller"),M(E)):S(E)}function M(E){return E===45?(e.consume(E),M):E===58?(i=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(E),e.exit("tableDelimiterMarker"),x):(e.exit("tableDelimiterFiller"),x(E))}function x(E){return Ye(E)?tt(e,b,"whitespace")(E):b(E)}function b(E){return E===124?y(E):E===null||ze(E)?!i||o!==a?S(E):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(E)):S(E)}function S(E){return n(E)}function C(E){return e.enter("tableRow"),L(E)}function L(E){return E===124?(e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),L):E===null||ze(E)?(e.exit("tableRow"),t(E)):Ye(E)?tt(e,L,"whitespace")(E):(e.enter("data"),_(E))}function _(E){return E===null||E===124||ft(E)?(e.exit("data"),L(E)):(e.consume(E),E===92?T:_)}function T(E){return E===92||E===124?(e.consume(E),_):_(E)}}function Zje(e,t){let n=-1,r=!0,o=0,a=[0,0,0,0],i=[0,0,0,0],s=!1,c=0,l,u,d;const f=new $je;for(;++n<e.length;){const p=e[n],y=p[1];p[0]==="enter"?y.type==="tableHead"?(s=!1,c!==0&&(zee(f,t,c,l,u),u=void 0,c=0),l={type:"table",start:Object.assign({},y.start),end:Object.assign({},y.end)},f.add(n,0,[["enter",l,t]])):y.type==="tableRow"||y.type==="tableDelimiterRow"?(r=!0,d=void 0,a=[0,0,0,0],i=[0,n+1,0,0],s&&(s=!1,u={type:"tableBody",start:Object.assign({},y.start),end:Object.assign({},y.end)},f.add(n,0,[["enter",u,t]])),o=y.type==="tableDelimiterRow"?2:u?3:1):o&&(y.type==="data"||y.type==="tableDelimiterMarker"||y.type==="tableDelimiterFiller")?(r=!1,i[2]===0&&(a[1]!==0&&(i[0]=i[1],d=U0(f,t,a,o,void 0,d),a=[0,0,0,0]),i[2]=n)):y.type==="tableCellDivider"&&(r?r=!1:(a[1]!==0&&(i[0]=i[1],d=U0(f,t,a,o,void 0,d)),a=i,i=[a[1],n,0,0])):y.type==="tableHead"?(s=!0,c=n):y.type==="tableRow"||y.type==="tableDelimiterRow"?(c=n,a[1]!==0?(i[0]=i[1],d=U0(f,t,a,o,n,d)):i[1]!==0&&(d=U0(f,t,i,o,n,d)),o=0):o&&(y.type==="data"||y.type==="tableDelimiterMarker"||y.type==="tableDelimiterFiller")&&(i[3]=n)}for(c!==0&&zee(f,t,c,l,u),f.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Wje(t.events,n))}return e}function U0(e,t,n,r,o,a){const i=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",s="tableContent";n[0]!==0&&(a.end=Object.assign({},d1(t.events,n[0])),e.add(n[0],0,[["exit",a,t]]));const c=d1(t.events,n[1]);if(a={type:i,start:Object.assign({},c),end:Object.assign({},c)},e.add(n[1],0,[["enter",a,t]]),n[2]!==0){const l=d1(t.events,n[2]),u=d1(t.events,n[3]),d={type:s,start:Object.assign({},l),end:Object.assign({},u)};if(e.add(n[2],0,[["enter",d,t]]),r!==2){const f=t.events[n[2]],p=t.events[n[3]];if(f[1].end=Object.assign({},p[1].end),f[1].type="chunkText",f[1].contentType="text",n[3]>n[2]+1){const y=n[2]+1,k=n[3]-n[2]-1;e.add(y,k,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return o!==void 0&&(a.end=Object.assign({},d1(t.events,o)),e.add(o,0,[["exit",a,t]]),a=void 0),a}function zee(e,t,n,r,o){const a=[],i=d1(t.events,n);o&&(o.end=Object.assign({},i),a.push(["exit",o,t])),r.end=Object.assign({},i),a.push(["exit",r,t]),e.add(n+1,0,a)}function d1(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const Xje={name:"tasklistCheck",tokenize:Qje};function Yje(){return{text:{91:Xje}}}function Qje(e,t,n){const r=this;return o;function o(c){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(c):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),a)}function a(c){return ft(c)?(e.enter("taskListCheckValueUnchecked"),e.consume(c),e.exit("taskListCheckValueUnchecked"),i):c===88||c===120?(e.enter("taskListCheckValueChecked"),e.consume(c),e.exit("taskListCheckValueChecked"),i):n(c)}function i(c){return c===93?(e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),s):n(c)}function s(c){return ze(c)?t(c):Ye(c)?e.check({tokenize:Jje},t,n)(c):n(c)}}function Jje(e,t,n){return tt(e,r,"whitespace");function r(o){return o===null?n(o):t(o)}}function eNe(e){return i1e([Sje(),Nje(),Vje(e),Gje(),Yje()])}const tNe={};function nNe(e){const t=this,n=e||tNe,r=t.data(),o=r.micromarkExtensions||(r.micromarkExtensions=[]),a=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),i=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);o.push(eNe(n)),a.push(wje()),i.push(Mje(n))}function rNe({flowId:e,node:t,connector:n,adapter:r,onNameChange:o,onDescriptionChange:a,onDetailChange:i,onIconChange:s,statusReport:c,onClose:l}){const u=(t==null?void 0:t.type)==="shapeNode"&&t.data.shape==="text",d=(t==null?void 0:t.type)==="shapeNode"?t.data.shape:void 0,f=d==="ellipse"||d==="sticky",p=u?null:t,y=p!==null||n!==null,k=p&&"name"in p.data?p.data.name??"":"",w=(p==null?void 0:p.data.description)??"",v=(p==null?void 0:p.data.detail)??"",M=p!==null&&!f,x=p!==null&&(p.type==="playNode"||p.type==="stateNode"),b=x&&typeof s=="function",S=x&&p&&"icon"in p.data?p.data.icon??null:null,[C,L]=g.useState(()=>tMe()),_=E=>{E.preventDefault(),rMe(C,E.clientX,{onWidth:L,onCommit:nMe})},T={"--detail-panel-w":`${C}px`};return m.jsx(NIe,{open:y,modal:!1,onOpenChange:E=>{E||l()},children:m.jsxs(pue,{side:"right",className:"sf:w-full! sf:max-w-full! sf:overflow-y-auto sf:bg-card/94 sf:backdrop-blur-[14px] sf:border-border sf:shadow-[-12px_0_40px_-12px_rgba(0,0,0,0.6)] sf:sm:w-(--detail-panel-w)! sf:sm:max-w-(--detail-panel-w)!",style:T,"data-testid":"detail-panel",onEscapeKeyDown:E=>{var A;const P=document.activeElement;(A=P==null?void 0:P.getAttribute("data-testid"))!=null&&A.endsWith("-editor")&&E.preventDefault()},onInteractOutside:E=>{var U;const P=document.activeElement;(U=P==null?void 0:P.getAttribute("data-testid"))!=null&&U.endsWith("-editor")&&P.blur();const A=E.target;A!=null&&A.closest(".react-flow__resize-control")&&E.preventDefault(),A!=null&&A.closest("[data-radix-popper-content-wrapper]")&&E.preventDefault(),A!=null&&A.closest('[data-testid="canvas-style-strip"]')&&E.preventDefault(),A!=null&&A.closest(".react-flow__node")&&E.preventDefault(),A!=null&&A.closest(".react-flow__edge")&&E.preventDefault()},children:[m.jsx("div",{"aria-label":"Resize detail panel",onPointerDown:_,"data-testid":"detail-panel-resize-handle",className:"sf:absolute sf:inset-y-0 sf:left-0 sf:z-10 sf:hidden sf:w-1.5 sf:cursor-col-resize sf:bg-transparent sf:transition-colors sf:hover:bg-border sf:sm:block"}),p?m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-4",children:[m.jsxs("div",{className:"sf:-mx-6 sf:-mt-6 sf:flex sf:flex-col sf:border-b sf:border-border/60 sf:bg-card/60 sf:px-6 sf:pb-2.5 sf:pt-3 sf:pr-12",children:[M?m.jsx(v_,{"data-testid":"detail-panel-title",children:m.jsxs("div",{className:"sf:flex sf:items-center sf:gap-2",children:[b&&s?m.jsx(oNe,{nodeId:p.id,icon:S,onChange:s}):x&&S?m.jsx("span",{"data-testid":"detail-panel-icon-readonly","aria-hidden":!0,className:"sf:inline-flex sf:h-7 sf:w-7 sf:shrink-0 sf:items-center sf:justify-center sf:text-foreground/90",children:m.jsx(Cu,{name:S,size:16})}):null,m.jsx("div",{className:"sf:min-w-0 sf:flex-1",children:m.jsx(kF,{nodeId:p.id,value:k,placeholder:"Name",multiline:!1,ariaLabel:"Name",testIdBase:"detail-panel-name",onSave:o,textClassName:"sf:text-lg sf:font-semibold sf:tracking-tight sf:text-foreground/95"})})]})}):m.jsx(v_,{"data-testid":"detail-panel-title",className:"sf:sr-only",children:p.id}),m.jsxs(tB,{className:"sf:sr-only",children:[p.id," · ",p.type]})]}),m.jsxs("div",{className:"sf:mt-0 sf:flex sf:flex-col sf:gap-3",children:[c?m.jsx(cNe,{report:c}):null,m.jsx(kF,{nodeId:p.id,value:w,placeholder:"Short description shown on the node body",multiline:!0,ariaLabel:"Description",testIdBase:"detail-panel-description",onSave:a,textClassName:"sf:text-[13px] sf:leading-relaxed sf:text-muted-foreground"}),m.jsx(kF,{nodeId:p.id,value:v,placeholder:"Long-form notes, context, anything…",multiline:!0,ariaLabel:"Detail",testIdBase:"detail-panel-detail",onSave:i,markdown:!0,textClassName:"sf:text-sm sf:leading-relaxed sf:text-foreground/90"}),p.type==="htmlNode"&&e?m.jsx(aNe,{adapter:r,htmlPath:p.data.htmlPath}):null]})]}):n?m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-4",children:[m.jsxs("div",{className:"sf:-mx-6 sf:-mt-6 sf:flex sf:flex-col sf:border-b sf:border-border/60 sf:bg-card/60 sf:px-6 sf:pb-2.5 sf:pt-3 sf:pr-12",children:[m.jsx(v_,{"data-testid":"detail-panel-title",className:"sf:text-lg sf:font-semibold sf:tracking-tight sf:text-foreground/95",children:n.label??"Connector"}),m.jsxs(tB,{className:"sf:sr-only",children:[n.id," · ",n.kind]})]}),m.jsx("div",{className:"sf:mt-0 sf:flex sf:flex-col sf:gap-3",children:m.jsx(lNe,{connector:n})})]}):null]})})}function kF({nodeId:e,value:t,placeholder:n,multiline:r,ariaLabel:o,testIdBase:a,onSave:i,textClassName:s,markdown:c=!1}){const[l,u]=g.useState(!1),d=g.useRef(null),f=g.useRef(!1);g.useEffect(()=>{if(!l)return;const S=d.current;if(!S)return;S.textContent=t,S.focus();const C=window.getSelection();if(C){const L=document.createRange();L.selectNodeContents(S),L.collapse(!1),C.removeAllRanges(),C.addRange(L)}},[l,t]);const p=t==="";if(!i)return m.jsx("div",{"data-testid":a,"aria-label":o,className:ae("sf:w-full sf:rounded-md sf:px-2 sf:py-1.5 sf:text-sm",p?"sf:italic sf:text-muted-foreground/50":"text-foreground",!c&&"sf:whitespace-pre-wrap sf:wrap-break-word",s),children:p?n:c?m.jsx(Dee,{value:t}):t});const y=()=>{var C;const S=((C=d.current)==null?void 0:C.textContent)??t;i(e,S),u(!1)},k=()=>{u(!1)},w=S=>{if(S.stopPropagation(),S.nativeEvent.stopPropagation(),S.key==="Escape"){S.preventDefault(),f.current=!0,k();return}if(S.key==="Enter"){if(S.preventDefault(),S.shiftKey||!r){y();return}document.execCommand("insertText",!1,`
|
|
7836
7836
|
`)}},v=S=>{S.preventDefault();const C=S.clipboardData.getData("text/plain");document.execCommand("insertText",!1,C)},M=S=>{},x=()=>{if(f.current){f.current=!1;return}y()},b=()=>{l||u(!0)};return m.jsx("div",{className:"relative","data-testid":a,"data-editing":l?"true":"false",children:l?m.jsx("div",{ref:d,contentEditable:"plaintext-only",suppressContentEditableWarning:!0,spellCheck:!1,tabIndex:0,onKeyDown:w,onPaste:v,onInput:M,onBlur:x,"data-testid":`${a}-editor`,className:ae("sf:block sf:w-full sf:whitespace-pre-wrap sf:wrap-break-word sf:rounded-md sf:px-2 sf:py-1.5 sf:text-sm sf:outline-hidden",s),role:"textbox","aria-multiline":r?"true":"false","aria-label":o}):m.jsx("button",{type:"button",onClick:b,"aria-label":`Edit ${o.toLowerCase()}`,className:ae("sf:block sf:w-full sf:cursor-text sf:rounded-md sf:px-2 sf:py-1.5 sf:text-left sf:text-sm sf:transition-colors sf:hover:bg-muted/50",p?"sf:italic sf:text-muted-foreground/50":"text-foreground",!c&&"sf:whitespace-pre-wrap sf:wrap-break-word",s),children:p?n:c?m.jsx(Dee,{value:t}):t})})}function oNe({nodeId:e,icon:t,onChange:n}){const[r,o]=g.useState(!1);return m.jsx(ET,{open:r,onOpenChange:o,onPick:a=>{n(e,a),o(!1)},anchor:m.jsx("button",{type:"button","data-testid":"detail-panel-icon-trigger","aria-label":t?"Change icon":"Add icon","aria-pressed":r,className:ae("sf:inline-flex sf:h-7 sf:w-7 sf:shrink-0 sf:items-center sf:justify-center sf:rounded-md sf:text-foreground sf:transition-colors",t?"sf:hover:bg-muted":"sf:border sf:border-dashed sf:border-muted-foreground/40 sf:text-muted-foreground/60 sf:hover:border-muted-foreground sf:hover:text-foreground","sf:focus-visible:outline-hidden sf:focus-visible:ring-2 sf:focus-visible:ring-ring sf:focus-visible:ring-offset-1"),children:t?m.jsx(Cu,{name:t,size:16,"aria-hidden":!0}):m.jsx(Wh,{className:"sf:h-4 sf:w-4","aria-hidden":!0})})})}function aNe({adapter:e,htmlPath:t}){const[n,r]=g.useState({kind:"idle"}),o=typeof(e==null?void 0:e.openFile)=="function",a=typeof(e==null?void 0:e.revealFile)=="function",i=async s=>{var c,l;r({kind:"pending"});try{s==="open"?await((c=e==null?void 0:e.openFile)==null?void 0:c.call(e,t)):await((l=e==null?void 0:e.revealFile)==null?void 0:l.call(e,t)),r({kind:"idle"})}catch(u){r({kind:"error",message:u instanceof Error?u.message:String(u)})}};return m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-2 sf:rounded-md sf:border sf:bg-card sf:px-3 sf:py-2 sf:text-xs","data-testid":"detail-panel-html-node",children:[m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-1",children:[m.jsx("span",{className:"sf:font-mono sf:text-[11px] sf:text-muted-foreground sf:uppercase sf:tracking-widest",children:"Path"}),m.jsx("code",{"data-testid":"detail-panel-html-path",className:"sf:block sf:break-all sf:rounded sf:bg-muted/40 sf:px-2 sf:py-1 sf:font-mono sf:text-[11px]",children:t})]}),o||a?m.jsxs("div",{className:"sf:flex sf:flex-wrap sf:items-center sf:gap-2",children:[o?m.jsxs(Ft,{type:"button",size:"sm",variant:"outline",className:"sf:h-7 sf:gap-1.5 sf:px-2",onClick:()=>{i("open")},disabled:n.kind==="pending","data-testid":"detail-panel-html-open","aria-label":"Open in editor",children:[m.jsx(Qh,{className:"sf:h-3.5 sf:w-3.5"}),"Open in editor"]}):null,a?m.jsxs(Ft,{type:"button",size:"sm",variant:"outline",className:"sf:h-7 sf:gap-1.5 sf:px-2",onClick:()=>{i("reveal")},disabled:n.kind==="pending","data-testid":"detail-panel-html-reveal","aria-label":"Reveal in Finder/Explorer",children:[m.jsx(Uh,{className:"sf:h-3.5 sf:w-3.5"}),"Reveal"]}):null]}):null,n.kind==="error"?m.jsx("div",{"data-testid":"detail-panel-html-status","data-status":n.kind,className:ae("sf:text-[11px] sf:text-destructive"),children:n.message??""}):null]})}function iNe(e,t){const n=Math.max(0,t-e);if(n<1e3)return"just now";const r=Math.floor(n/1e3);if(r<60)return`${r}s ago`;const o=Math.floor(r/60);if(o<60)return`${o}m ago`;const a=Math.floor(o/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}function sNe(e){if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function cNe({report:e,now:t=Date.now()}){const n=e.data?Object.entries(e.data):[];return m.jsxs("section",{className:"sf:flex sf:flex-col sf:gap-2 sf:rounded-md sf:border sf:bg-card sf:px-3 sf:py-2 sf:text-xs","data-testid":"detail-panel-status","data-state":e.state,children:[m.jsxs("div",{className:"sf:flex sf:items-center sf:justify-between sf:gap-2",children:[m.jsx(oce,{state:e.state,summary:e.summary,"data-testid":"detail-panel-status-badge"}),m.jsx("span",{className:"sf:shrink-0 sf:text-[10px] sf:text-muted-foreground","data-testid":"detail-panel-status-relative-time",children:`Last updated: ${iNe(e.ts,t)}`})]}),e.detail?m.jsx("div",{"data-testid":"detail-panel-status-detail",className:"sf:whitespace-pre-wrap sf:wrap-break-word sf:rounded sf:bg-muted/40 sf:px-2 sf:py-1 sf:text-[11px] sf:text-foreground",children:e.detail}):null,n.length>0?m.jsx("dl",{"data-testid":"detail-panel-status-data",className:"sf:grid sf:grid-cols-[auto_1fr] sf:gap-x-3 sf:gap-y-1 sf:text-[11px]",children:n.map(([r,o])=>m.jsxs("div",{className:"contents","data-testid":"detail-panel-status-data-row",children:[m.jsx("dt",{className:"sf:truncate sf:font-medium sf:text-muted-foreground",children:r}),m.jsx("dd",{className:"sf:break-all sf:font-mono sf:text-foreground",children:sNe(o)})]},r))}):null]})}function Dee({value:e}){return m.jsx(VRe,{remarkPlugins:[nNe],components:{h1:({children:t})=>m.jsx("h1",{className:"sf:mb-1 sf:text-base sf:font-bold sf:leading-snug",children:t}),h2:({children:t})=>m.jsx("h2",{className:"sf:mb-1 sf:text-sm sf:font-semibold sf:leading-snug",children:t}),h3:({children:t})=>m.jsx("h3",{className:"sf:mb-0.5 sf:text-sm sf:font-medium sf:leading-snug",children:t}),p:({children:t})=>m.jsx("p",{className:"sf:mb-2 sf:last:mb-0 sf:leading-relaxed",children:t}),ul:({children:t})=>m.jsx("ul",{className:"sf:mb-2 sf:list-disc sf:pl-4 sf:last:mb-0",children:t}),ol:({children:t})=>m.jsx("ol",{className:"sf:mb-2 sf:list-decimal sf:pl-4 sf:last:mb-0",children:t}),li:({children:t})=>m.jsx("li",{className:"mb-0.5",children:t}),code:({children:t,className:n})=>(n==null?void 0:n.includes("language-"))?m.jsx("code",{className:"sf:block sf:overflow-x-auto sf:rounded sf:bg-muted/60 sf:px-2 sf:py-1 sf:font-mono sf:text-xs",children:t}):m.jsx("code",{className:"sf:rounded sf:bg-muted/60 sf:px-1 sf:py-0.5 sf:font-mono sf:text-xs",children:t}),pre:({children:t})=>m.jsx("pre",{className:"sf:mb-2 sf:last:mb-0",children:t}),blockquote:({children:t})=>m.jsx("blockquote",{className:"sf:mb-2 sf:border-l-2 sf:border-muted-foreground/30 sf:pl-3 sf:italic sf:text-muted-foreground sf:last:mb-0",children:t}),a:({href:t,children:n})=>m.jsx("a",{href:t,target:"_blank",rel:"noreferrer",className:"sf:text-primary sf:underline sf:underline-offset-2",children:n}),strong:({children:t})=>m.jsx("strong",{className:"font-semibold",children:t}),em:({children:t})=>m.jsx("em",{className:"italic",children:t}),hr:()=>m.jsx("hr",{className:"sf:my-2 sf:border-border"}),table:({children:t})=>m.jsx("div",{className:"sf:mb-2 sf:overflow-x-auto sf:last:mb-0",children:m.jsx("table",{className:"sf:w-full sf:border-collapse sf:text-xs",children:t})}),th:({children:t})=>m.jsx("th",{className:"sf:border sf:border-border sf:bg-muted/40 sf:px-2 sf:py-1 sf:text-left sf:font-medium",children:t}),td:({children:t})=>m.jsx("td",{className:"sf:border sf:border-border sf:px-2 sf:py-1",children:t})},children:e})}function lNe({connector:e}){return m.jsx("div",{className:"sf:rounded-md sf:border sf:bg-card sf:px-3 sf:py-2 sf:text-xs",children:m.jsxs("dl",{className:"divide-y",children:[m.jsx(so,{label:"Source",value:e.source}),m.jsx(so,{label:"Target",value:e.target}),m.jsx(so,{label:"Kind",value:e.kind}),e.label?m.jsx(so,{label:"Label",value:e.label}):null,e.style?m.jsx(so,{label:"Style",value:e.style}):null,e.color?m.jsx(so,{label:"Color",value:e.color}):null,e.direction?m.jsx(so,{label:"Direction",value:e.direction}):null,e.kind==="http"&&e.url?m.jsx(so,{label:"URL",value:`${e.method??"GET"} ${e.url}`}):null,e.kind==="event"?m.jsx(so,{label:"Event",value:e.eventName}):null,e.kind==="queue"?m.jsx(so,{label:"Queue",value:e.queueName}):null]})})}function so({label:e,value:t}){return m.jsxs("div",{className:"sf:flex sf:items-start sf:gap-3 sf:py-2 sf:first:pt-0 sf:last:pb-0",children:[m.jsx("dt",{className:"sf:w-20 sf:shrink-0 sf:font-medium sf:text-muted-foreground",children:e}),m.jsx("dd",{className:"sf:flex-1 sf:break-all sf:font-mono",children:t})]})}const uNe="https://seeflow.dev/embed",dNe=e=>`${uNe}/${encodeURIComponent(e)}`,hNe=e=>e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<"),fNe=e=>[`<iframe src="${hNe(e)}"`,' width="100%"',' height="600"',' style="border:0"',' allow="fullscreen"',' loading="lazy"></iframe>'].join(`
|
|
7837
7837
|
`),pNe="Embed this canvas",yNe="Paste this iframe into any page to embed the canvas.",mNe="Copy snippet",gNe="Copied!",kNe="Press ⌘C to copy",vNe="Close",xNe=1500;function wNe({open:e,onOpenChange:t,projectId:n}){const r=fNe(dNe(n)),[o,a]=g.useState("idle"),i=g.useRef(null),s=g.useCallback(async()=>{try{await navigator.clipboard.writeText(r),a("copied"),setTimeout(()=>a("idle"),xNe)}catch{a("fallback");const c=i.current;c&&(c.focus(),c.select())}},[r]);return m.jsx(NT,{open:e,onOpenChange:t,children:m.jsxs(Ef,{"data-testid":"embed-dialog-content",children:[m.jsxs(Af,{children:[m.jsx(Pf,{children:pNe}),m.jsx(_f,{children:yNe})]}),m.jsx("textarea",{ref:i,"data-testid":"embed-dialog-snippet",readOnly:!0,rows:7,value:r,spellCheck:!1,onFocus:c=>c.currentTarget.select(),className:"sf:w-full sf:resize-none sf:rounded-md sf:border sf:border-border sf:bg-background sf:p-3 sf:font-mono sf:text-xs sf:leading-relaxed sf:text-foreground sf:focus:outline-hidden sf:focus:ring-2 sf:focus:ring-ring"}),o==="fallback"?m.jsx("p",{"data-testid":"embed-dialog-fallback-hint",className:"sf:text-xs sf:text-muted-foreground",children:kNe}):null,m.jsxs(pd,{children:[m.jsx(Ft,{variant:"outline","data-testid":"embed-dialog-close",onClick:()=>t(!1),children:vNe}),m.jsx(Ft,{"data-testid":"embed-dialog-copy",onClick:s,children:o==="copied"?gNe:mNe})]})]})})}const qee="Share / download",MNe="Download PDF",bNe="Download PNG",CNe="Embed",SNe="Export to seeflow.dev";function LNe({mode:e,projectId:t,enableEmbed:n,onDownloadPdf:r,onDownloadPng:o,onExportToCloud:a,embedOpen:i,onEmbedOpenChange:s}){const[c,l]=g.useState(!1),[u,d]=g.useState(!1),[f,p]=g.useState(!1),y=i!==void 0,k=y?i:f,w=g.useCallback(L=>{y||p(L),s==null||s(L)},[y,s]),v=g.useCallback(()=>{!r||c||(l(!0),Promise.resolve(r()).finally(()=>l(!1)))},[r,c]),M=g.useCallback(()=>{!o||u||(d(!0),Promise.resolve(o()).finally(()=>d(!1)))},[o,u]),x=!!r,b=!!o,S=n&&typeof t=="string"&&t.length>0,C=e==="edit"&&!!a;return!x&&!b&&!S&&!C?null:m.jsxs(m.Fragment,{children:[m.jsxs(cIe,{children:[m.jsx(lIe,{asChild:!0,children:m.jsx("button",{type:"button","data-testid":"share-menu-trigger","aria-label":qee,title:qee,className:ae("sf:inline-flex sf:h-8 sf:w-8 sf:items-center sf:justify-center sf:rounded-md sf:border sf:border-border sf:bg-background/95 sf:text-muted-foreground sf:shadow-md sf:backdrop-blur-sm sf:transition-colors","sf:hover:bg-accent sf:hover:text-accent-foreground","sf:focus-visible:outline-hidden sf:focus-visible:ring-2 sf:focus-visible:ring-ring"),children:m.jsx(a2,{className:"sf:h-4 sf:w-4","aria-hidden":"true"})})}),m.jsxs(Jle,{align:"end","data-testid":"share-menu-content",onCloseAutoFocus:L=>{L.preventDefault()},children:[x?m.jsxs(Lh,{"data-testid":"share-menu-pdf",disabled:c,onSelect:L=>{L.preventDefault(),v()},children:[c?m.jsx(Rr,{className:"sf:h-4 sf:w-4 sf:animate-spin","aria-hidden":"true"}):m.jsx($h,{className:"sf:h-4 sf:w-4","aria-hidden":"true"}),m.jsx("span",{children:MNe})]}):null,b?m.jsxs(Lh,{"data-testid":"share-menu-png",disabled:u,onSelect:L=>{L.preventDefault(),M()},children:[u?m.jsx(Rr,{className:"sf:h-4 sf:w-4 sf:animate-spin","aria-hidden":"true"}):m.jsx(Gh,{className:"sf:h-4 sf:w-4","aria-hidden":"true"}),m.jsx("span",{children:bNe})]}):null,S?m.jsxs(Lh,{"data-testid":"share-menu-embed",onSelect:L=>{L.preventDefault(),w(!0)},children:[m.jsx(z1,{className:"sf:h-4 sf:w-4","aria-hidden":"true"}),m.jsx("span",{children:CNe})]}):null,C?m.jsxs(Lh,{"data-testid":"share-menu-export-cloud",onSelect:()=>{a==null||a()},children:[m.jsx(l2,{className:"sf:h-4 sf:w-4","aria-hidden":"true"}),m.jsx("span",{children:SNe})]}):null]})]}),S&&t?m.jsx(wNe,{open:k,onOpenChange:w,projectId:t}):null]})}function INe({onRestartDemo:e}){const[t,n]=g.useState(!1),r=g.useCallback(()=>{t||(n(!0),Promise.resolve(e()).finally(()=>{n(!1)}))},[e,t]);return m.jsxs(zf,{children:[m.jsx(Df,{asChild:!0,children:m.jsx(Ft,{"data-testid":"header-restart-demo",type:"button",variant:"ghost",size:"icon","aria-label":"Restart demo",title:"Restart demo",disabled:t,onClick:r,className:"sf:h-8 sf:w-8",children:t?m.jsx(Rr,{className:"sf:h-4 sf:w-4 sf:animate-spin","aria-hidden":"true"}):m.jsx(t2,{className:"sf:h-4 sf:w-4","aria-hidden":"true"})})}),m.jsx(qd,{side:"bottom",children:"Restart demo"})]})}const ENe=8;function ANe(e){let t=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,a=!1;for(const i of e){const s=i.data.width,c=i.data.height;s===void 0||c===void 0||(a=!0,i.position.x<t&&(t=i.position.x),i.position.y<n&&(n=i.position.y),i.position.x+s>r&&(r=i.position.x+s),i.position.y+c>o&&(o=i.position.y+c))}return a?{x:t,y:n,width:r-t,height:o-n}:null}function PNe(e){return e.length>=2}function _Ne({selectedNodes:e,onMultiResize:t,paddingPx:n=ENe}){gT();const[r,o]=g.useState(null),[a,i]=g.useState(null);if(g.useRef(!1),g.useRef(null),!PNe(e))return null;const s=ANe(e);if(!s)return null;const c=a??s;return c.x-n,c.y-n,c.width+n*2,c.height+n*2,null}const Oee=22,Fee=11,Hee=3,Bee=2,vF=8,RNe={http:"solid",event:"dashed",queue:"dotted",default:"solid"},Y1e=["default","slate","blue","green","amber","red","purple","pink"],W0=[{value:"solid",icon:gR,label:"Solid",testId:"style-tab-border-style-solid"},{value:"dashed",icon:uue,label:"Dashed",testId:"style-tab-border-style-dashed"},{value:"dotted",icon:due,label:"Dotted",testId:"style-tab-border-style-dotted"}],Vee=[{value:"solid",icon:gR,label:"Solid",testId:"style-tab-edge-style-solid"},{value:"dashed",icon:uue,label:"Dashed",testId:"style-tab-edge-style-dashed"},{value:"dotted",icon:due,label:"Dotted",testId:"style-tab-edge-style-dotted"}],$ee=[{value:"curve",icon:hue,label:"Curve",testId:"style-tab-edge-path-curve"},{value:"step",icon:jIe,label:"Zigzag",testId:"style-tab-edge-path-step"}],Uee=[{value:"none",icon:Xh,label:"None",testId:"style-tab-direction-none"},{value:"backward",icon:Yh,label:"Backward",testId:"style-tab-direction-backward"},{value:"forward",icon:T1,label:"Forward",testId:"style-tab-direction-forward"},{value:"both",icon:Dh,label:"Both",testId:"style-tab-direction-both"}];function TNe({nodes:e,connectors:t,onStyleNode:n,onStyleNodePreview:r,onStyleNodes:o,onStyleNodesPreview:a,onStyleConnector:i,onStyleConnectorPreview:s,onRequestIconReplace:c}){const l=e.length>0,u=t.length>0;if(!l&&!u)return null;const d=l&&!u,f=!l&&u,p=e[0],y=t[0],k=e.filter(ue=>ue.type!=="iconNode"),w=k[0],v=d&&e.every(ue=>ue.type==="iconNode"),M=v?e.find(ue=>ue.type==="iconNode"):void 0,x=d&&e.every(ue=>ue.type==="imageNode"),b=d&&(p==null?void 0:p.type)==="shapeNode"&&p.data.shape==="text",S=(f?y==null?void 0:y.color:w==null?void 0:w.data.borderColor)??"default",C=(w==null?void 0:w.data.backgroundColor)??"default",L=(w==null?void 0:w.data.borderStyle)??"solid",_=y?y.style??RNe[y.kind]:"solid",T=(y==null?void 0:y.direction)??"forward",E=(y==null?void 0:y.path)??"curve",P=ue=>{for(const ge of e)n(ge.id,{borderColor:ue});for(const ge of t)i(ge.id,{color:ue})},A=ue=>{for(const ge of e)n(ge.id,{backgroundColor:ue})},U=ue=>{for(const ge of e)n(ge.id,{borderStyle:ue});for(const ge of t)i(ge.id,{style:ue})},R=ue=>{for(const ge of e)n(ge.id,{borderSize:ue});for(const ge of t)i(ge.id,{borderSize:ue})},H=ue=>{for(const ge of e)r==null||r(ge.id,{borderSize:ue});for(const ge of t)s==null||s(ge.id,{borderSize:ue})},F=ue=>{if(e.length>1&&o)o(e.map(ge=>ge.id),{fontSize:ue});else for(const ge of e)n(ge.id,{fontSize:ue})},V=ue=>{if(e.length>1&&a)a(e.map(ge=>ge.id),{fontSize:ue});else for(const ge of e)r==null||r(ge.id,{fontSize:ue})},z=k.length>1&&new Set(k.map(ue=>ue.data.fontSize??Oee)).size>1,N=ue=>{if(e.length>1&&o)o(e.map(ge=>ge.id),{textColor:ue});else for(const ge of e)n(ge.id,{textColor:ue})},I=(w==null?void 0:w.data.textColor)??(b?(w==null?void 0:w.data.borderColor)??"default":"default"),G=ue=>{for(const ge of t)i(ge.id,{fontSize:ue})},q=ue=>{for(const ge of t)s==null||s(ge.id,{fontSize:ue})},j=t.length>1&&new Set(t.map(ue=>ue.fontSize??Fee)).size>1,W=ue=>{for(const ge of e)n(ge.id,{cornerRadius:ue})},X=ue=>{for(const ge of e)r==null||r(ge.id,{cornerRadius:ue})},Y=k.length>1&&new Set(k.map(ue=>ue.data.cornerRadius??vF)).size>1,oe=ue=>{for(const ge of t)i(ge.id,{path:ue})},re=ue=>{for(const ge of t)i(ge.id,{direction:ue})},ie=ue=>{for(const ge of e)n(ge.id,{color:ue})},we=(M==null?void 0:M.data.color)??"default",ke=f?(y==null?void 0:y.borderSize)??Bee:(w==null?void 0:w.data.borderSize)??Hee,ve=f?Bee:Hee,xe=f?"edge":"border",ee=f?"Connector color":b?"Color":"Border color",se=f?"connector color":b?"color":"border color",qe=f?"style-tab-edge-color-trigger":b?"style-tab-color-trigger":"style-tab-border-color-trigger",Le=f||b?"style-tab-color":"style-tab-border-color";if(v){const ue=!!c&&e.length===1&&!!M,ge=()=>{M&&c&&c(M.id)};return m.jsx(p2,{delayDuration:300,children:m.jsxs("div",{"data-testid":"canvas-style-strip",className:"sf:pointer-events-auto sf:flex sf:flex-col sf:items-center sf:gap-1 sf:rounded-lg sf:border sf:border-border sf:bg-background/95 sf:p-1 sf:shadow-md sf:backdrop-blur",children:[m.jsx(Wee,{testId:"style-strip-icon-color",tooltip:"Icon color",ariaLabel:"icon color",activeToken:we,previewKind:"edge",tokenTestIdPrefix:"style-tab-icon-color",innerTestId:"style-tab-icon-color-trigger",onSelect:ie}),ue?m.jsxs(zf,{children:[m.jsx(Df,{asChild:!0,children:m.jsx("button",{type:"button","data-testid":"style-strip-change-icon","aria-label":"change icon",title:"Change icon",onClick:ge,className:ae("sf:inline-flex sf:h-8 sf:w-8 sf:items-center sf:justify-center sf:rounded-md sf:text-muted-foreground sf:transition-colors sf:hover:bg-accent sf:hover:text-accent-foreground","sf:focus-visible:outline-hidden sf:focus-visible:ring-2 sf:focus-visible:ring-ring sf:focus-visible:ring-offset-1"),children:m.jsx(q1,{className:"sf:h-4 sf:w-4"})})}),m.jsx(qd,{side:"right",className:"sf:px-2 sf:py-1 sf:text-xs",children:"Change icon"})]}):null]})})}if(x){const ue=e[0],ge=(ue==null?void 0:ue.data.borderColor)??"default",be=(ue==null?void 0:ue.data.borderStyle)??"solid",De=(ue==null?void 0:ue.data.borderWidth)??1,ne=Oe=>{for(const Te of e)n(Te.id,{borderColor:Oe})},he=Oe=>{for(const Te of e)n(Te.id,{borderStyle:Oe})},Ee=Oe=>{for(const Te of e)n(Te.id,{borderWidth:Oe})},Be=Oe=>{for(const Te of e)r==null||r(Te.id,{borderWidth:Oe})},Ge=Oe=>{for(const Te of e)n(Te.id,{cornerRadius:Oe})},Pt=Oe=>{for(const Te of e)r==null||r(Te.id,{cornerRadius:Oe})};return m.jsx(p2,{delayDuration:300,children:m.jsxs("div",{"data-testid":"canvas-style-strip",className:"sf:pointer-events-auto sf:flex sf:flex-col sf:items-center sf:gap-1 sf:rounded-lg sf:border sf:border-border sf:bg-background/95 sf:p-1 sf:shadow-md sf:backdrop-blur",children:[m.jsx(Wee,{testId:"style-strip-image-border-color",tooltip:"Border color",ariaLabel:"image border color",activeToken:ge,previewKind:"border",tokenTestIdPrefix:"style-tab-image-border-color",innerTestId:"style-tab-image-border-color-trigger",onSelect:ne}),m.jsx($o,{testId:"style-strip-image-border-style",tooltip:"Border style",ariaLabel:"image border style",renderIcon:()=>{var Te;const Oe=((Te=W0.find(_t=>_t.value===be))==null?void 0:Te.icon)??gR;return m.jsx(Oe,{className:"sf:h-4 sf:w-4"})},children:m.jsx(ah,{ariaLabel:"Border style",value:be,onChange:he,options:W0})}),m.jsx($o,{testId:"style-strip-image-border-width",tooltip:"Border width",ariaLabel:"image border width",renderIcon:()=>m.jsx("span",{className:"sf:font-mono sf:text-[10px] sf:tabular-nums",children:De}),children:m.jsx(ch,{value:ue==null?void 0:ue.data.borderWidth,defaultValue:1,min:1,max:8,suffix:"px",onPreview:Be,onCommit:Ee,testId:"style-tab-image-border-width-slider"})}),m.jsx($o,{testId:"style-strip-image-corner-radius",tooltip:"Corners",ariaLabel:"image corner radius",renderIcon:()=>m.jsx(D1,{className:"sf:h-4 sf:w-4"}),children:m.jsx(ch,{value:ue==null?void 0:ue.data.cornerRadius,defaultValue:vF,min:0,max:32,suffix:"px",onPreview:Pt,onCommit:Ge,testId:"style-tab-image-corner-radius-slider"})})]})})}const ut=d&&!b,Je=!b,ce=!f,Q=()=>{if(f){const be=zh[S].edge;return m.jsx("span",{className:"sf:inline-block sf:h-5 sf:w-5 sf:rounded-full sf:ring-1 sf:ring-border",style:{backgroundColor:be}})}const ue=zh[S].border,ge=zh[C].background;return m.jsx("span",{className:"sf:inline-block sf:h-5 sf:w-5 sf:rounded-md sf:ring-1 sf:ring-border",style:{backgroundColor:ge,border:`2px solid ${ue}`}})};return m.jsx(p2,{delayDuration:300,children:m.jsxs("div",{"data-testid":"canvas-style-strip",className:"sf:pointer-events-auto sf:flex sf:flex-col sf:items-center sf:gap-1 sf:rounded-lg sf:border sf:border-border sf:bg-background/95 sf:p-1 sf:shadow-md sf:backdrop-blur",children:[b?null:m.jsx($o,{testId:"style-strip-colors",tooltip:"Colors",ariaLabel:"colors",renderIcon:Q,children:m.jsxs("div",{className:"sf:flex sf:w-56 sf:flex-col sf:gap-3",children:[m.jsx(a1,{label:ee,children:m.jsx(xF,{testId:"style-strip-border-color",activeToken:S,previewKind:xe,tokenTestIdPrefix:Le,innerTestId:qe,ariaLabel:se,onSelect:P})}),ut?m.jsx(a1,{label:"Fill",children:m.jsx(xF,{testId:"style-strip-fill",activeToken:C,previewKind:"background",tokenTestIdPrefix:"style-tab-background-color",innerTestId:"style-tab-background-color-trigger",ariaLabel:"fill",onSelect:A})}):null]})}),Je?m.jsx($o,{testId:"style-strip-border",tooltip:f?"Connector":"Border",ariaLabel:f?"connector":"border",renderIcon:()=>{var ge,be;const ue=(f?(ge=Vee.find(De=>De.value===_))==null?void 0:ge.icon:(be=W0.find(De=>De.value===L))==null?void 0:be.icon)??gR;return m.jsx(ue,{className:"sf:h-4 sf:w-4"})},children:m.jsxs("div",{className:"sf:flex sf:w-56 sf:flex-col sf:gap-3",children:[m.jsx(a1,{label:"Style",testId:"style-strip-border-style",children:f?m.jsx(ah,{ariaLabel:"Connector style",value:_,onChange:ue=>U(ue),options:Vee}):m.jsx(ah,{ariaLabel:"Border style",value:L,onChange:ue=>U(ue),options:W0})}),m.jsx(a1,{label:"Width",testId:"style-strip-border-size",children:m.jsx(ch,{value:ke,defaultValue:ve,min:1,max:8,suffix:"px",onPreview:H,onCommit:R,testId:f?"style-tab-stroke-width-slider":"style-tab-border-size-slider"})})]})}):null,l||f?m.jsx($o,{testId:"style-strip-text",tooltip:"Text",ariaLabel:"text",renderIcon:()=>m.jsx(O1,{className:"sf:h-4 sf:w-4"}),children:m.jsxs("div",{className:"sf:flex sf:w-56 sf:flex-col sf:gap-3",children:[m.jsx(a1,{label:"Size",testId:f?"style-strip-connector-font-size":"style-strip-font-size",children:m.jsx(ch,{value:f?y==null?void 0:y.fontSize:w==null?void 0:w.data.fontSize,defaultValue:f?Fee:Oee,min:f?8:10,max:32,suffix:"px",indeterminate:f?j:z,onPreview:f?q:V,onCommit:f?G:F,testId:f?"style-tab-connector-font-size-slider":"style-tab-font-size-slider"})}),ce?m.jsx(a1,{label:"Color",children:m.jsx(xF,{testId:"style-strip-text-color",activeToken:I,previewKind:"edge",tokenTestIdPrefix:"style-tab-text-color",innerTestId:"style-tab-text-color-trigger",ariaLabel:"text color",onSelect:N})}):null]})}):null,l&&!b?m.jsx($o,{testId:"style-strip-corner-radius",tooltip:"Corners",ariaLabel:"corner radius",renderIcon:()=>m.jsx(D1,{className:"sf:h-4 sf:w-4"}),children:m.jsx(ch,{value:w==null?void 0:w.data.cornerRadius,defaultValue:vF,min:0,max:32,suffix:"px",indeterminate:Y,onPreview:X,onCommit:W,testId:"style-tab-corner-radius-slider"})}):null,f?m.jsx($o,{testId:"style-strip-path",tooltip:"Connector path",ariaLabel:"connector path",renderIcon:()=>{var ge;const ue=((ge=$ee.find(be=>be.value===E))==null?void 0:ge.icon)??hue;return m.jsx(ue,{className:"sf:h-4 sf:w-4"})},children:m.jsx(ah,{ariaLabel:"Connector path",value:E,onChange:oe,options:$ee})}):null,f?m.jsx($o,{testId:"style-strip-direction",tooltip:"Direction",ariaLabel:"direction",renderIcon:()=>{var ge;const ue=((ge=Uee.find(be=>be.value===T))==null?void 0:ge.icon)??T1;return m.jsx(ue,{className:"sf:h-4 sf:w-4"})},children:m.jsx(ah,{ariaLabel:"Connector direction",value:T,onChange:re,options:Uee})}):null]})})}function Q1e(e,t){const n=zh[e];return t==="background"?{backgroundColor:n.background,borderColor:n.border}:t==="edge"?{backgroundColor:n.edge,borderColor:n.edge}:{borderColor:n.border,backgroundColor:n.background}}function jNe(e,t){const n=zh[e];return t==="background"?{backgroundColor:n.background}:t==="edge"?{backgroundColor:n.edge}:{backgroundColor:n.border}}function Wee({testId:e,tooltip:t,ariaLabel:n,activeToken:r,previewKind:o,tokenTestIdPrefix:a,innerTestId:i,onSelect:s}){const[c,l]=g.useState(!1),u=r==="default";return m.jsxs(zd,{open:c,onOpenChange:l,children:[m.jsxs(zf,{children:[m.jsx(Df,{asChild:!0,children:m.jsx(wf,{asChild:!0,children:m.jsx("button",{type:"button","data-testid":e,"data-active-token":r,"aria-label":`${n}: ${r}`,title:t,className:ae("sf:group sf:relative sf:inline-flex sf:h-8 sf:w-8 sf:items-center sf:justify-center sf:rounded-md sf:text-muted-foreground sf:transition-colors sf:hover:bg-accent sf:hover:text-accent-foreground","sf:focus-visible:outline-hidden sf:focus-visible:ring-2 sf:focus-visible:ring-ring sf:focus-visible:ring-offset-1"),children:m.jsx("span",{"data-testid":i,className:"sf:relative sf:h-5 sf:w-5 sf:rounded-full sf:ring-1 sf:ring-border",style:jNe(r,o),children:u?m.jsx("span",{"aria-hidden":"true",className:"sf:pointer-events-none sf:absolute sf:inset-0 sf:rounded-full",style:{backgroundImage:"linear-gradient(45deg, transparent 45%, currentColor 45%, currentColor 55%, transparent 55%)",color:"hsl(var(--muted-foreground))",opacity:.5}}):null})})})}),m.jsx(qd,{side:"right",className:"sf:px-2 sf:py-1 sf:text-xs",children:t})]}),m.jsx(qu,{side:"right",align:"start",className:"sf:w-auto sf:p-2","data-testid":`${i}-popover`,children:m.jsx("div",{className:"sf:grid sf:grid-cols-4 sf:gap-1.5",children:Y1e.map(d=>{const f=r===d;return m.jsx("button",{type:"button",onClick:()=>{s(d),l(!1)},"data-testid":`${a}-${d}`,"data-active":f,"aria-label":`${n} ${d}`,"aria-pressed":f,title:d,className:ae("sf:relative sf:flex sf:h-7 sf:w-7 sf:items-center sf:justify-center sf:rounded-full sf:border-2 sf:transition-all",f?"sf:ring-2 sf:ring-ring sf:ring-offset-2 sf:ring-offset-popover":"sf:hover:scale-110"),style:Q1e(d,o),children:f?m.jsx(Mo,{className:"sf:h-3 sf:w-3 sf:drop-shadow-sm",style:{color:"hsl(var(--foreground))"}}):null},d)})})})]})}function xF({testId:e,activeToken:t,previewKind:n,tokenTestIdPrefix:r,innerTestId:o,ariaLabel:a,onSelect:i}){return m.jsx("div",{"data-testid":e,"data-active-token":t,"data-inner-testid":o,className:"sf:grid sf:grid-cols-4 sf:gap-1.5",children:Y1e.map(s=>{const c=t===s;return m.jsx("button",{type:"button",onClick:()=>i(s),"data-testid":`${r}-${s}`,"data-active":c,"aria-label":`${a} ${s}`,"aria-pressed":c,title:s,className:ae("sf:relative sf:flex sf:h-7 sf:w-7 sf:items-center sf:justify-center sf:rounded-full sf:border-2 sf:transition-all",c?"sf:ring-2 sf:ring-ring sf:ring-offset-2 sf:ring-offset-popover":"sf:hover:scale-110"),style:Q1e(s,n),children:c?m.jsx(Mo,{className:"sf:h-3 sf:w-3 sf:drop-shadow-sm",style:{color:"hsl(var(--foreground))"}}):null},s)})})}function a1({label:e,testId:t,children:n}){return m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-1.5","data-testid":t,children:[m.jsx("div",{className:"sf:text-[11px] sf:font-medium sf:uppercase sf:tracking-wide sf:text-muted-foreground",children:e}),n]})}function $o({testId:e,tooltip:t,ariaLabel:n,renderIcon:r,children:o}){const[a,i]=g.useState(!1);return m.jsxs(zd,{open:a,onOpenChange:i,children:[m.jsxs(zf,{children:[m.jsx(Df,{asChild:!0,children:m.jsx(wf,{asChild:!0,children:m.jsx("button",{type:"button","data-testid":e,"aria-label":n,title:t,className:ae("sf:inline-flex sf:h-8 sf:w-8 sf:items-center sf:justify-center sf:rounded-md sf:text-muted-foreground sf:transition-colors sf:hover:bg-accent sf:hover:text-accent-foreground","sf:focus-visible:outline-hidden sf:focus-visible:ring-2 sf:focus-visible:ring-ring sf:focus-visible:ring-offset-1"),children:r()})})}),m.jsx(qd,{side:"right",className:"sf:px-2 sf:py-1 sf:text-xs",children:t})]}),m.jsx(qu,{side:"right",align:"start",className:"sf:w-auto sf:p-3",children:o})]})}function ch({value:e,defaultValue:t,min:n,max:r,suffix:o,indeterminate:a,onPreview:i,onCommit:s,testId:c}){const l=e??t,[u,d]=g.useState(l),[f,p]=g.useState(!1);g.useEffect(()=>{d(l),p(!1)},[l]);const y=a&&!f;return m.jsxs("div",{className:"sf:flex sf:w-48 sf:items-center sf:gap-3",children:[m.jsx(_ue,{min:n,max:r,step:1,value:[u],onValueChange:([k])=>{const w=k??n;d(w),p(!0),i==null||i(w)},onValueCommit:([k])=>s(k??n),"data-testid":c,"data-indeterminate":y?"true":void 0,className:ae("sf:flex-1",y&&"sf:opacity-60")}),m.jsx("span",{"data-testid":`${c}-value`,className:"sf:w-12 sf:shrink-0 sf:text-right sf:text-xs sf:tabular-nums sf:text-muted-foreground",children:y?"Mixed":m.jsxs(m.Fragment,{children:[u,o]})})]})}const NNe="modulepreload",zNe=function(e){return"/"+e},Gee={},DNe=function(t,n,r){let o=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),s=(i==null?void 0:i.nonce)||(i==null?void 0:i.getAttribute("nonce"));o=Promise.allSettled(n.map(c=>{if(c=zNe(c),c in Gee)return;Gee[c]=!0;const l=c.endsWith(".css"),u=l?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${u}`))return;const d=document.createElement("link");if(d.rel=l?"stylesheet":NNe,l||(d.as="script"),d.crossOrigin="",d.href=c,s&&d.setAttribute("nonce",s),document.head.appendChild(d),l)return new Promise((f,p)=>{d.addEventListener("load",f),d.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${c}`)))})}))}function a(i){const s=new Event("vite:preloadError",{cancelable:!0});if(s.payload=i,window.dispatchEvent(s),!s.defaultPrevented)throw i}return o.then(i=>{for(const s of i||[])s.status==="rejected"&&a(s.reason);return t().catch(a)})};function qNe(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),r=n.createElement("base"),o=n.createElement("a");return n.head.appendChild(r),n.body.appendChild(o),t&&(r.href=t),o.href=e,o.href}const ONe=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function ri(e){const t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}let i1=null;function J1e(e={}){return i1||(e.includeStyleProperties?(i1=e.includeStyleProperties,i1):(i1=ri(window.getComputedStyle(document.documentElement)),i1))}function MR(e,t){const r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function FNe(e){const t=MR(e,"border-left-width"),n=MR(e,"border-right-width");return e.clientWidth+t+n}function HNe(e){const t=MR(e,"border-top-width"),n=MR(e,"border-bottom-width");return e.clientHeight+t+n}function ede(e,t={}){const n=t.width||FNe(e),r=t.height||HNe(e);return{width:n,height:r}}function BNe(){let e,t;try{t=process}catch{}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const On=16384;function VNe(e){(e.width>On||e.height>On)&&(e.width>On&&e.height>On?e.width>e.height?(e.height*=On/e.width,e.width=On):(e.width*=On/e.height,e.height=On):e.width>On?(e.height*=On/e.width,e.width=On):(e.width*=On/e.height,e.height=On))}function bR(e){return new Promise((t,n)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin="anonymous",r.decoding="async",r.src=e})}async function $Ne(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function UNe(e,t,n){const r="http://www.w3.org/2000/svg",o=document.createElementNS(r,"svg"),a=document.createElementNS(r,"foreignObject");return o.setAttribute("width",`${t}`),o.setAttribute("height",`${n}`),o.setAttribute("viewBox",`0 0 ${t} ${n}`),a.setAttribute("width","100%"),a.setAttribute("height","100%"),a.setAttribute("x","0"),a.setAttribute("y","0"),a.setAttribute("externalResourcesRequired","true"),o.appendChild(a),a.appendChild(e),$Ne(o)}const _n=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||_n(n,t)};function WNe(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function GNe(e,t){return J1e(t).map(n=>{const r=e.getPropertyValue(n),o=e.getPropertyPriority(n);return`${n}: ${r}${o?" !important":""};`}).join(" ")}function KNe(e,t,n,r){const o=`.${e}:${t}`,a=n.cssText?WNe(n):GNe(n,r);return document.createTextNode(`${o}{${a}}`)}function Kee(e,t,n,r){const o=window.getComputedStyle(e,n),a=o.getPropertyValue("content");if(a===""||a==="none")return;const i=ONe();try{t.className=`${t.className} ${i}`}catch{return}const s=document.createElement("style");s.appendChild(KNe(i,n,o,r)),t.appendChild(s)}function ZNe(e,t,n){Kee(e,t,":before",n),Kee(e,t,":after",n)}const Zee="application/font-woff",Xee="image/jpeg",XNe={woff:Zee,woff2:Zee,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:Xee,jpeg:Xee,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function YNe(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function aU(e){const t=YNe(e).toLowerCase();return XNe[t]||""}function QNe(e){return e.split(/,/)[1]}function kB(e){return e.search(/^(data:)/)!==-1}function JNe(e,t){return`data:${t};base64,${e}`}async function tde(e,t,n){const r=await fetch(e,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const o=await r.blob();return new Promise((a,i)=>{const s=new FileReader;s.onerror=i,s.onloadend=()=>{try{a(n({res:r,result:s.result}))}catch(c){i(c)}},s.readAsDataURL(o)})}const wF={};function eze(e,t,n){let r=e.replace(/\?.*/,"");return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function iU(e,t,n){const r=eze(e,t,n.includeQueryParams);if(wF[r]!=null)return wF[r];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let o;try{const a=await tde(e,n.fetchRequestInit,({res:i,result:s})=>(t||(t=i.headers.get("Content-Type")||""),QNe(s)));o=JNe(a,t)}catch(a){o=n.imagePlaceholder||"";let i=`Failed to fetch resource: ${e}`;a&&(i=typeof a=="string"?a:a.message),i&&console.warn(i)}return wF[r]=o,o}async function tze(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):bR(t)}async function nze(e,t){if(e.currentSrc){const a=document.createElement("canvas"),i=a.getContext("2d");a.width=e.clientWidth,a.height=e.clientHeight,i==null||i.drawImage(e,0,0,a.width,a.height);const s=a.toDataURL();return bR(s)}const n=e.poster,r=aU(n),o=await iU(n,r,t);return bR(o)}async function rze(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await QT(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function oze(e,t){return _n(e,HTMLCanvasElement)?tze(e):_n(e,HTMLVideoElement)?nze(e,t):_n(e,HTMLIFrameElement)?rze(e,t):e.cloneNode(nde(e))}const aze=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",nde=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function ize(e,t,n){var r,o;if(nde(t))return t;let a=[];return aze(e)&&e.assignedNodes?a=ri(e.assignedNodes()):_n(e,HTMLIFrameElement)&&(!((r=e.contentDocument)===null||r===void 0)&&r.body)?a=ri(e.contentDocument.body.childNodes):a=ri(((o=e.shadowRoot)!==null&&o!==void 0?o:e).childNodes),a.length===0||_n(e,HTMLVideoElement)||await a.reduce((i,s)=>i.then(()=>QT(s,n)).then(c=>{c&&t.appendChild(c)}),Promise.resolve()),t}function sze(e,t,n){const r=t.style;if(!r)return;const o=window.getComputedStyle(e);o.cssText?(r.cssText=o.cssText,r.transformOrigin=o.transformOrigin):J1e(n).forEach(a=>{let i=o.getPropertyValue(a);a==="font-size"&&i.endsWith("px")&&(i=`${Math.floor(parseFloat(i.substring(0,i.length-2)))-.1}px`),_n(e,HTMLIFrameElement)&&a==="display"&&i==="inline"&&(i="block"),a==="d"&&t.getAttribute("d")&&(i=`path(${t.getAttribute("d")})`),r.setProperty(a,i,o.getPropertyPriority(a))})}function cze(e,t){_n(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),_n(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function lze(e,t){if(_n(e,HTMLSelectElement)){const n=t,r=Array.from(n.children).find(o=>e.value===o.getAttribute("value"));r&&r.setAttribute("selected","")}}function uze(e,t,n){return _n(t,Element)&&(sze(e,t,n),ZNe(e,t,n),cze(e,t),lze(e,t)),t}async function dze(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const r={};for(let a=0;a<n.length;a++){const s=n[a].getAttribute("xlink:href");if(s){const c=e.querySelector(s),l=document.querySelector(s);!c&&l&&!r[s]&&(r[s]=await QT(l,t,!0))}}const o=Object.values(r);if(o.length){const a="http://www.w3.org/1999/xhtml",i=document.createElementNS(a,"svg");i.setAttribute("xmlns",a),i.style.position="absolute",i.style.width="0",i.style.height="0",i.style.overflow="hidden",i.style.display="none";const s=document.createElementNS(a,"defs");i.appendChild(s);for(let c=0;c<o.length;c++)s.appendChild(o[c]);e.appendChild(i)}return e}async function QT(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(r=>oze(r,t)).then(r=>ize(e,r,t)).then(r=>uze(e,r,t)).then(r=>dze(r,t))}const rde=/url\((['"]?)([^'"]+?)\1\)/g,hze=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,fze=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function pze(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function yze(e){const t=[];return e.replace(rde,(n,r,o)=>(t.push(o),n)),t.filter(n=>!kB(n))}async function mze(e,t,n,r,o){try{const a=n?qNe(t,n):t,i=aU(t);let s;return o||(s=await iU(a,i,r)),e.replace(pze(t),`$1${s}$3`)}catch{}return e}function gze(e,{preferredFontFormat:t}){return t?e.replace(fze,n=>{for(;;){const[r,,o]=hze.exec(n)||[];if(!o)return"";if(o===t)return`src: ${r};`}}):e}function ode(e){return e.search(rde)!==-1}async function ade(e,t,n){if(!ode(e))return e;const r=gze(e,n);return yze(r).reduce((a,i)=>a.then(s=>mze(s,i,t,n)),Promise.resolve(r))}async function s1(e,t,n){var r;const o=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(e);if(o){const a=await ade(o,null,n);return t.style.setProperty(e,a,t.style.getPropertyPriority(e)),!0}return!1}async function kze(e,t){await s1("background",e,t)||await s1("background-image",e,t),await s1("mask",e,t)||await s1("-webkit-mask",e,t)||await s1("mask-image",e,t)||await s1("-webkit-mask-image",e,t)}async function vze(e,t){const n=_n(e,HTMLImageElement);if(!(n&&!kB(e.src))&&!(_n(e,SVGImageElement)&&!kB(e.href.baseVal)))return;const r=n?e.src:e.href.baseVal,o=await iU(r,aU(r),t);await new Promise((a,i)=>{e.onload=a,e.onerror=t.onImageErrorHandler?(...c)=>{try{a(t.onImageErrorHandler(...c))}catch(l){i(l)}}:i;const s=e;s.decode&&(s.decode=a),s.loading==="lazy"&&(s.loading="eager"),n?(e.srcset="",e.src=o):e.href.baseVal=o})}async function xze(e,t){const r=ri(e.childNodes).map(o=>ide(o,t));await Promise.all(r).then(()=>e)}async function ide(e,t){_n(e,Element)&&(await kze(e,t),await vze(e,t),await xze(e,t))}function wze(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const r=t.style;return r!=null&&Object.keys(r).forEach(o=>{n[o]=r[o]}),e}const Yee={};async function Qee(e){let t=Yee[e];if(t!=null)return t;const r=await(await fetch(e)).text();return t={url:e,cssText:r},Yee[e]=t,t}async function Jee(e,t){let n=e.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,a=(n.match(/url\([^)]+\)/g)||[]).map(async i=>{let s=i.replace(r,"$1");return s.startsWith("https://")||(s=new URL(s,e.url).href),tde(s,t.fetchRequestInit,({result:c})=>(n=n.replace(i,`url(${c})`),[i,c]))});return Promise.all(a).then(()=>n)}function ete(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let r=e.replace(n,"");const o=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const c=o.exec(r);if(c===null)break;t.push(c[0])}r=r.replace(o,"");const a=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,i="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",s=new RegExp(i,"gi");for(;;){let c=a.exec(r);if(c===null){if(c=s.exec(r),c===null)break;a.lastIndex=s.lastIndex}else s.lastIndex=a.lastIndex;t.push(c[0])}return t}async function Mze(e,t){const n=[],r=[];return e.forEach(o=>{if("cssRules"in o)try{ri(o.cssRules||[]).forEach((a,i)=>{if(a.type===CSSRule.IMPORT_RULE){let s=i+1;const c=a.href,l=Qee(c).then(u=>Jee(u,t)).then(u=>ete(u).forEach(d=>{try{o.insertRule(d,d.startsWith("@import")?s+=1:o.cssRules.length)}catch(f){console.error("Error inserting rule from remote css",{rule:d,error:f})}})).catch(u=>{console.error("Error loading remote css",u.toString())});r.push(l)}})}catch(a){const i=e.find(s=>s.href==null)||document.styleSheets[0];o.href!=null&&r.push(Qee(o.href).then(s=>Jee(s,t)).then(s=>ete(s).forEach(c=>{i.insertRule(c,i.cssRules.length)})).catch(s=>{console.error("Error loading remote stylesheet",s)})),console.error("Error inlining remote css file",a)}}),Promise.all(r).then(()=>(e.forEach(o=>{if("cssRules"in o)try{ri(o.cssRules||[]).forEach(a=>{n.push(a)})}catch(a){console.error(`Error while reading CSS rules from ${o.href}`,a)}}),n))}function bze(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>ode(t.style.getPropertyValue("src")))}async function Cze(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=ri(e.ownerDocument.styleSheets),r=await Mze(n,t);return bze(r)}function sde(e){return e.trim().replace(/["']/g,"")}function Sze(e){const t=new Set;function n(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(a=>{t.add(sde(a))}),Array.from(r.children).forEach(a=>{a instanceof HTMLElement&&n(a)})}return n(e),t}async function Lze(e,t){const n=await Cze(e,t),r=Sze(e);return(await Promise.all(n.filter(a=>r.has(sde(a.style.fontFamily))).map(a=>{const i=a.parentStyleSheet?a.parentStyleSheet.href:null;return ade(a.cssText,i,t)}))).join(`
|
|
7838
|
-
`)}async function Ize(e,t){const n=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await Lze(e,t);if(n){const r=document.createElement("style"),o=document.createTextNode(n);r.appendChild(o),e.firstChild?e.insertBefore(r,e.firstChild):e.appendChild(r)}}async function Eze(e,t={}){const{width:n,height:r}=ede(e,t),o=await QT(e,t,!0);return await Ize(o,t),await ide(o,t),wze(o,t),await UNe(o,n,r)}async function Aze(e,t={}){const{width:n,height:r}=ede(e,t),o=await Eze(e,t),a=await bR(o),i=document.createElement("canvas"),s=i.getContext("2d"),c=t.pixelRatio||BNe(),l=t.canvasWidth||n,u=t.canvasHeight||r;return i.width=l*c,i.height=u*c,t.skipAutoScale||VNe(i),i.style.width=`${l}`,i.style.height=`${u}`,t.backgroundColor&&(s.fillStyle=t.backgroundColor,s.fillRect(0,0,i.width,i.height)),s.drawImage(a,0,0,i.width,i.height),i}async function Pze(e,t={}){return(await Aze(e,t)).toDataURL()}const _ze=e=>e instanceof Element?!(e.classList.contains("react-flow__minimap")||e.classList.contains("react-flow__controls")||e.classList.contains("react-flow__panel")):!0,Rze=async e=>{const t=await Pze(e,{cacheBust:!0,filter:_ze}),n=await new Promise((r,o)=>{const a=new Image;a.onload=()=>r({width:a.naturalWidth,height:a.naturalHeight}),a.onerror=()=>o(new Error("Failed to decode captured image")),a.src=t});return{dataUrl:t,...n}},Tze=(e,t)=>{const n=document.createElement("a");n.href=e,n.download=t,n.rel="noopener",document.body.appendChild(n),n.click(),n.remove()},jze=e=>{const t=e.replace(/[^A-Za-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"");return t.length>0?t.slice(0,80):"canvas"},tte=(e,t)=>`${jze(e??"canvas")}.${t}`,Nze=({projectId:e,getReactFlow:t})=>{const[n,r]=g.useState(null),o=g.useCallback(()=>r(null),[]),a=g.useCallback(async()=>{const l=t();if(!l)return null;const u=document.querySelector(".react-flow__viewport");if(!u)return null;const d=l.getViewport();try{return await l.fitView({duration:0,padding:.1}),await new Promise(f=>requestAnimationFrame(()=>f())),await Rze(u)}finally{l.setViewport(d,{duration:0})}},[t]),i=g.useCallback(async()=>{r(null);try{const l=await a();if(!l)return;Tze(l.dataUrl,tte(e,"png"))}catch(l){r(l instanceof Error?l.message:String(l))}},[a,e]),s=g.useCallback(async()=>{r(null);try{const l=await a();if(!l)return;const{jsPDF:u}=await DNe(async()=>{const{jsPDF:p}=await import("./jspdf.es.min-CaFlbpn0.js").then(y=>y.j);return{jsPDF:p}},[]),d=l.width>l.height?"landscape":"portrait",f=new u({orientation:d,unit:"px",format:[l.width,l.height],hotfixes:["px_scaling"]});f.addImage(l.dataUrl,"PNG",0,0,l.width,l.height),f.save(tte(e,"pdf"))}catch(l){r(l instanceof Error?l.message:String(l))}},[a,e]),c=g.useCallback(async()=>{const l=await a();return l==null?void 0:l.dataUrl},[a]);return{exportPdf:s,exportPng:i,capturePreview:c,lastError:n,clearError:o}},zze={showToolbar:!0,showStyleStrip:!0,showDetailPanel:!0,showStatusBadges:!0,showResizeHandles:!0,showControls:!0,showShareMenu:!0,showRestart:!0,enableKeyboard:!0,enableContextMenu:!0,enableDragDrop:!0,enableImageDrop:!0,enableZoom:!0,enablePan:!0,enableSelection:!0,enableNodeMove:!0,enableEmbed:!1},Dze={showToolbar:!1,showStyleStrip:!1,showDetailPanel:!1,showStatusBadges:!0,showResizeHandles:!1,showControls:!0,showShareMenu:!0,showRestart:!1,enableKeyboard:!1,enableContextMenu:!1,enableDragDrop:!1,enableImageDrop:!1,enableZoom:!0,enablePan:!0,enableSelection:!0,enableNodeMove:!0,enableEmbed:!1},qze={showToolbar:!1,showStyleStrip:!1,showDetailPanel:!1,showStatusBadges:!1,showResizeHandles:!1,showControls:!1,showShareMenu:!1,showRestart:!1,enableKeyboard:!1,enableContextMenu:!1,enableDragDrop:!1,enableImageDrop:!1,enableZoom:!1,enablePan:!1,enableSelection:!1,enableNodeMove:!1,enableEmbed:!1};function Oze(e){const t=e.mode==="edit"?zze:e.mode==="mini"?qze:Dze;return{showToolbar:e.showToolbar??t.showToolbar,showStyleStrip:e.showStyleStrip??t.showStyleStrip,showDetailPanel:e.showDetailPanel??t.showDetailPanel,showStatusBadges:e.showStatusBadges??t.showStatusBadges,showResizeHandles:e.showResizeHandles??t.showResizeHandles,showControls:e.showControls??t.showControls,showShareMenu:e.showShareMenu??t.showShareMenu,showRestart:e.showRestart??t.showRestart,enableKeyboard:e.enableKeyboard??t.enableKeyboard,enableContextMenu:e.enableContextMenu??t.enableContextMenu,enableDragDrop:e.enableDragDrop??t.enableDragDrop,enableImageDrop:e.enableImageDrop??t.enableImageDrop,enableZoom:e.enableZoom??t.enableZoom,enablePan:e.enablePan??t.enablePan,enableSelection:e.enableSelection??t.enableSelection,enableNodeMove:e.enableNodeMove??t.enableNodeMove,enableEmbed:e.enableEmbed??t.enableEmbed}}const nte=40,lh={padding:.15,duration:300,includeHiddenNodes:!1};function Fze(e){return e===void 0||e===!1?{onMount:!1,onExternalNodeChange:!1}:e===!0?{onMount:!0,onExternalNodeChange:!0}:{onMount:e.onMount??!0,onExternalNodeChange:e.onExternalNodeChange??!0}}const rte=e=>{if("clientX"in e)return{clientX:e.clientX,clientY:e.clientY};const t=e.changedTouches[0]??e.touches[0];return t?{clientX:t.clientX,clientY:t.clientY}:null},Hze=(e,t)=>{var r;const n=document.elementsFromPoint(e,t);for(const o of n){const a=(r=o.closest)==null?void 0:r.call(o,".react-flow__node");if(a)return a}return null},cde=15,MF=(e,t,n)=>{const r=Hze(t,n);if(r)return r;if(!e)return null;let o=null,a=cde;const i=e.querySelectorAll(".react-flow__node");for(const s of i){const c=s.getBoundingClientRect();if(c.width===0||c.height===0)continue;const l=Math.max(c.left-t,0,t-c.right),u=Math.max(c.top-n,0,n-c.bottom),d=Math.hypot(l,u);d<=a&&(o=s,a=d)}return o};function ote(e,t,n,r,o){if(e==="source"?(r==null?void 0:r.targetPin)!==void 0||(r==null?void 0:r.targetHandleAutoPicked)===!1:(r==null?void 0:r.sourcePin)!==void 0||(r==null?void 0:r.sourceHandleAutoPicked)===!1)return;const i=e==="source"?n:t,s=e==="source"?t:n,c=o(i),l=o(s);if(!c||!l)return;const u=c.measured.width??c.width??0,d=c.measured.height??c.height??0,f=l.measured.width??l.width??0,p=l.measured.height??l.height??0;if(u===0||d===0||f===0||p===0)return;const y={x:c.internals.positionAbsolute.x,y:c.internals.positionAbsolute.y,w:u,h:d},k={x:l.internals.positionAbsolute.x+f/2,y:l.internals.positionAbsolute.y+p/2};return oMe(y,iR(y,k))}function Bze(e,t,n,r){if(r===null)return"no-op";const o=e==="source"?t:n;return r===(e==="source"?n:t)?"self-loop":r===o?"pin-own":"reconnect-and-pin"}const Vze=(e,t)=>{if(!t)return e;const n=t.data?{...e.data,...t.data}:e.data;return{...e,...t,data:n}},$ze=(e,t)=>t?{...e,...t}:e,Uze={playNode:mCe,stateNode:qCe,shapeNode:PCe,imageNode:abe,iconNode:yMe,htmlNode:ebe},Wze={editableEdge:HCe},Gze={zIndex:0},Kze=8,ate=(e,t)=>e?typeof e=="string"?`url('#${e}')`:`url('#${`${t?`${t}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`}')`:void 0,Zze=e=>function({fromX:n,fromY:r,toX:o,toY:a,fromPosition:i,toPosition:s,connectionLineStyle:c}){const l=He(G=>e.current?G.edges.find(q=>q.reconnectable===!0)??null:null),u=l==null?void 0:l.data,d=He(G=>{var j;const q=G.connection;return((j=q==null?void 0:q.fromHandle)==null?void 0:j.nodeId)??null}),f=He(G=>l!=null&&l.source?G.nodeLookup.get(l.source)??null:null),p=He(G=>l!=null&&l.target?G.nodeLookup.get(l.target)??null:null),y=He(G=>d?G.nodeLookup.get(d)??null:null),k=(l==null?void 0:l.source)===d,w=l?k?f:p:y,v=k?p:f,M=k?u==null?void 0:u.sourcePin:u==null?void 0:u.targetPin,x=k?u==null?void 0:u.sourceHandleAutoPicked:u==null?void 0:u.targetHandleAutoPicked;let b=n,S=r,C=i;if(w){const G=w.measured.width??w.width??0,q=w.measured.height??w.height??0;if(G>0&&q>0){const j={x:w.internals.positionAbsolute.x,y:w.internals.positionAbsolute.y,w:G,h:q};let W=null;if(M)W=sR(j,M);else if(x!==!1&&v){const X=v.measured.width??v.width??0,Y=v.measured.height??v.height??0;if(X>0&&Y>0){const oe={x:v.internals.positionAbsolute.x+X/2,y:v.internals.positionAbsolute.y+Y/2};W=iR(j,oe)}}W&&(b=W.x,S=W.y,C=ite[W.side])}}const L=He(G=>G.transform[2]),_=He(G=>G.nodeLookup),T=He(G=>{var q;return((q=G.connection.toHandle)==null?void 0:q.nodeId)??null});let E=o,P=a,A=s;if(L>0){const G=cde/L,q=l?k?l.target:l.source:null;let j=null;if(T&&T!==q){const W=_.get(T)??null;W&&(j=W)}if(!j){let W=G;for(const X of _.values()){if(q&&X.id===q||w&&X.id===w.id)continue;const Y=X.measured.width??X.width??0,oe=X.measured.height??X.height??0;if(Y===0||oe===0)continue;const re=X.internals.positionAbsolute.x,ie=X.internals.positionAbsolute.y,we=Math.max(re-o,0,o-(re+Y)),ke=Math.max(ie-a,0,a-(ie+oe)),ve=Math.hypot(we,ke);ve<=W&&(W=ve,j=X)}}if(!j&&l&&w){const W=w.measured.width??w.width??0,X=w.measured.height??w.height??0;if(W>0&&X>0){const Y=w.internals.positionAbsolute.x,oe=w.internals.positionAbsolute.y,re=Math.max(Y-o,0,o-(Y+W)),ie=Math.max(oe-a,0,a-(oe+X));Math.hypot(re,ie)<=G&&(j=w)}}if(j){const W=j.measured.width??j.width??0,X=j.measured.height??j.height??0;if(W>0&&X>0){const Y=OH({x:j.internals.positionAbsolute.x,y:j.internals.positionAbsolute.y,w:W,h:X},{x:o,y:a}),oe=sR({x:j.internals.positionAbsolute.x,y:j.internals.positionAbsolute.y,w:W,h:X},Y);E=oe.x,P=oe.y,A=ite[oe.side]}}}const U=(u==null?void 0:u.path)==="step",[R]=U?$2({sourceX:b,sourceY:S,sourcePosition:C,targetX:E,targetY:P,targetPosition:A,borderRadius:Kze}):fT({sourceX:b,sourceY:S,sourcePosition:C,targetX:E,targetY:P,targetPosition:A}),H=(l==null?void 0:l.style)??c??void 0,F=He(G=>G.rfId),V=k?l==null?void 0:l.markerStart:l==null?void 0:l.markerEnd,z=k?l==null?void 0:l.markerEnd:l==null?void 0:l.markerStart,N=ate(V,F),I=ate(z,F);return m.jsx("path",{d:R,fill:"none",className:"react-flow__connection-path",style:H,markerStart:N,markerEnd:I})},ite={top:me.Top,right:me.Right,bottom:me.Bottom,left:me.Left};function Xze({storeApiRef:e}){const t=gt();return g.useEffect(()=>(e.current=t,()=>{e.current===t&&(e.current=null)}),[t,e]),null}function Yze({wrapperRef:e}){const t=He(r=>r.transform[2]),n=e.current;return n&&n.style.setProperty("--rf-zoom",String(t)),null}const Qze=new Set(["INPUT","TEXTAREA","SELECT"]),lde=e=>e?Qze.has(e.tagName)?!0:e instanceof HTMLElement&&e.isContentEditable:!1;function Jze(e){const{event:t,selectedNodeIds:n,hasClipboard:r,activeElement:o,onCopySelection:a,onPasteSelection:i}=e;if(!(t.metaKey||t.ctrlKey)||t.shiftKey||t.altKey)return!1;const s=t.key.toLowerCase();return s!=="c"&&s!=="v"||lde(o)?!1:s==="c"?n.length===0||!a?!1:(t.preventDefault(),a([...n]),!0):!r||!i?!1:(t.preventDefault(),i(),!0)}const ste=(e,t)=>{var n;return((n=e==null?void 0:e[t])==null?void 0:n.status)??"idle"},eDe=(e,t)=>{var n;return(n=e==null?void 0:e[t])==null?void 0:n.status},tDe=(e,t)=>{var n,r;return((n=e==null?void 0:e[t])==null?void 0:n.status)==="error"?(r=e[t])==null?void 0:r.error:void 0};function nDe(e,t){var vU,xU;const{mode:n,adapter:r,projectId:o,fileBaseUrl:a,nodes:i,connectors:s,selectedNodeIds:c,selectedConnectorIds:l,onSelectionChange:u,runtime:d,onPlayNode:f,onNodePositionChange:p,onNodePositionsChange:y,onNodeResize:k,onHtmlNodeFitToContent:w,onMultiResize:v,onNodeNameChange:M,onNodeDescriptionChange:x,onConnectorLabelChange:b,onCreateShapeNode:S,onCreateImageFromFile:C,onRetryImageUpload:L,onCreateHtmlNode:_,onCreateConnector:T,onReconnectConnector:E,onReorderNode:P,onDeleteNode:A,onCopyNode:U,onPasteAt:R,hasClipboard:H,onCopySelection:F,onPasteSelection:V,selectedNodes:z,selectedConnectors:N,onStyleNode:I,onStyleNodePreview:G,onStyleNodes:q,onStyleNodesPreview:j,onStyleConnector:W,onStyleConnectorPreview:X,onRfInit:Y,onTidy:oe,onNodeClick:re,onConnectorClick:ie,onPaneClick:we,onCreateAndConnectFromPane:ke,pendingEditNodeId:ve,iconPickerOpen:xe,onOpenIconPicker:ee,onCloseIconPicker:se,onPickIcon:qe,onRequestIconReplace:Le,onPinEndpoint:ut,onUnpinEndpoint:Je,onToggleNodeLock:ce,activeShape:Q,onSelectShape:ue,disableSidebar:ge,statusReport:be,onNameChange:De,onDescriptionChange:ne,onDetailChange:he,onIconChange:Ee,autoFitView:Be,autoFitViewSignal:Ge,customIcons:Pt,onExportToCloud:Oe,onRestartDemo:Te,showToolbar:_t,showStyleStrip:nr,showDetailPanel:Nt,showStatusBadges:Nn,showResizeHandles:tn,showControls:Bu,showShareMenu:Vu,showRestart:pa,enableKeyboard:ya,enableContextMenu:Gr,enableDragDrop:ki,enableImageDrop:ma,enableZoom:gr,enablePan:Kr,enableSelection:kr,enableNodeMove:$u,enableEmbed:Uu}=e,Fe=g.useMemo(()=>Oze({mode:n,showToolbar:_t,showStyleStrip:nr,showDetailPanel:Nt,showStatusBadges:Nn,showResizeHandles:tn,showControls:Bu,showShareMenu:Vu,showRestart:pa,enableKeyboard:ya,enableContextMenu:Gr,enableDragDrop:ki,enableImageDrop:ma,enableZoom:gr,enablePan:Kr,enableSelection:kr,enableNodeMove:$u,enableEmbed:Uu}),[n,_t,nr,Nt,Nn,tn,Bu,Vu,pa,ya,Gr,ki,ma,gr,Kr,kr,$u,Uu]),bt=n==="edit",Zr=g.useRef(Fe);g.useEffect(()=>{Zr.current=Fe},[Fe]);const Xr=Be??(n==="mini"?!0:void 0),zn=g.useMemo(()=>Fze(Xr),[Xr]),vr=d==null?void 0:d.runs,Ro=d==null?void 0:d.statuses,rr=(vU=d==null?void 0:d.pendingOverrides)==null?void 0:vU.nodes,Yr=(xU=d==null?void 0:d.pendingOverrides)==null?void 0:xU.connectors,hn=g.useRef(null),zt=g.useRef(null),To=g.useRef(!1),xr=g.useRef(!1),vi=g.useRef(!1),xi=g.useRef(zn);xi.current=zn,g.useEffect(()=>{if(To.current||!zn.onMount||i.length===0)return;const K=zt.current;K&&(K.fitView(lh),To.current=!0)},[i,zn.onMount]);const jo=g.useRef(null),Lt=Q,wi=ue,Dn=g.useRef(new Map),ga=g.useCallback((K,J)=>(Dn.current.set(K,J),()=>{Dn.current.get(K)===J&&Dn.current.delete(K)}),[]),[or,wr]=g.useState(!1),Wu=g.useRef(!1);g.useEffect(()=>{Wu.current=or},[or]);const Mi=g.useRef(!1),bi=g.useRef(!1),ka=g.useRef(!1),[Mn,Qr]=g.useState(null),Jr=g.useRef(null);g.useEffect(()=>{Jr.current=Mn},[Mn]),g.useCallback(()=>{Qr(null)},[]);const Gu=g.useMemo(()=>Zze(ka),[]),No=g.useRef(null),ar=g.useRef(null),bn=g.useCallback(K=>{const J=hn.current;if(!J){No.current=K;return}const le=No.current;if(le&&le!==K){const de=J.querySelector(`.react-flow__node[data-id="${CSS.escape(le)}"]`);de==null||de.removeAttribute("data-connect-source")}if(K){const de=J.querySelector(`.react-flow__node[data-id="${CSS.escape(K)}"]`);de==null||de.setAttribute("data-connect-source","true")}No.current=K},[]),fn=g.useCallback(K=>{const J=hn.current,le=ar.current;if(le!==K){if(J&&le){const de=J.querySelector(`.react-flow__node[data-id="${CSS.escape(le)}"]`);de==null||de.removeAttribute("data-connect-target")}if(J&&K){const de=J.querySelector(`.react-flow__node[data-id="${CSS.escape(K)}"]`);de==null||de.setAttribute("data-connect-target","true")}ar.current=K}},[]),va=g.useCallback(()=>{bn(null),fn(null)},[bn,fn]);g.useEffect(()=>{if(!or){fn(null);return}const K=J=>{const le=MF(hn.current,J.clientX,J.clientY),de=(le==null?void 0:le.getAttribute("data-id"))??null;if(de&&de===No.current){fn(null);return}fn(de)};return document.addEventListener("pointermove",K),()=>{document.removeEventListener("pointermove",K)}},[or,fn]);const[ir,eo]=g.useState(null),[to,zo]=g.useState(null),rt=g.useRef(null),no=g.useRef(null),qn=g.useRef(null),nn=g.useRef(!1);g.useEffect(()=>{rt.current=Lt},[Lt]);const ro=g.useCallback(()=>{wi(null),eo(null),zo(null),rt.current=null,no.current=null,qn.current=null,nn.current=!1},[wi]);g.useEffect(()=>{if(!Fe.enableKeyboard)return;const K=J=>{var ye,Ne;if(J.key!=="Escape"||lde(document.activeElement))return;if(rt.current){J.preventDefault(),ro();return}if(Wu.current){J.preventDefault(),Mi.current=!0,bi.current=!0;try{(ye=jo.current)==null||ye.getState().cancelConnection()}catch{}document.dispatchEvent(new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,button:0})),wr(!1);return}if(Jr.current){J.preventDefault(),Qr(null);return}const le=br.current.size>0,de=qo.current.size>0;(le||de)&&(J.preventDefault(),(Ne=ao.current)==null||Ne.call(ao,[],[]))};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[ro,Fe.enableKeyboard]),g.useEffect(()=>{if(!Fe.enableKeyboard)return;const K=J=>{Jze({event:J,selectedNodeIds:c,hasClipboard:!!H,activeElement:document.activeElement,onCopySelection:F,onPasteSelection:V})};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[c,H,F,V,Fe.enableKeyboard]);const Ku=g.useCallback(K=>{var de,ye;if(!rt.current)return;const J=K.target;if(!(J!=null&&J.classList.contains("react-flow__pane")))return;const le={x:K.clientX,y:K.clientY};nn.current=!0,no.current=le,qn.current=le,eo(le),zo(le);try{(ye=(de=K.currentTarget).setPointerCapture)==null||ye.call(de,K.pointerId)}catch{}K.preventDefault(),K.stopPropagation()},[]),ej=g.useCallback(K=>{if(!nn.current)return;const J={x:K.clientX,y:K.clientY};qn.current=J,zo(J)},[]),Bf=g.useCallback(K=>{var Sa,wU;if(!nn.current)return;nn.current=!1;try{(wU=(Sa=K.currentTarget).releasePointerCapture)==null||wU.call(Sa,K.pointerId)}catch{}const J=no.current,le=qn.current,de=rt.current,ye=zt.current;if(ro(),!J||!le||!de||!ye)return;const Ne=Math.min(J.x,le.x),Me=Math.min(J.y,le.y),Ae=Math.max(J.x,le.x),et=Math.max(J.y,le.y),ht=Ae-Ne,qt=et-Me,Re=ye.screenToFlowPosition({x:Ne,y:Me}),ot=ye.screenToFlowPosition({x:Ae,y:et}),Ze=ot.x-Re.x,Ii=ot.y-Re.y,Ca=ht<nte||qt<nte,Oo=Ca?fR[de].width:Ze,Jf=Ca?fR[de].height:Ii;S==null||S(de,Re,{width:Oo,height:Jf})},[ro,S]),Do=g.useRef(!1),Zu=g.useRef(!1),Bd=g.useRef(new Map),xa=g.useCallback(()=>{var K;xr.current&&(Zu.current||Do.current||(xr.current=!1,(K=zt.current)==null||K.fitView(lh)))},[]),Vd=g.useCallback(K=>{Zu.current=K,K||xa()},[xa]);g.useEffect(()=>{var K;if(!vi.current){vi.current=!0;return}if(xi.current.onExternalNodeChange){if(Zu.current||Do.current){xr.current=!0;return}(K=zt.current)==null||K.fitView(lh)}},[Ge]);const $d=!!P||!!A||!!U||!!R||!!Je,[O,B]=g.useState(null),[Z,$]=g.useState(!1),[D,te]=g.useState(null),[Pe,Ce]=g.useState(null),Xe=g.useRef(null),Dt=g.useRef(null);g.useEffect(()=>{if(!O)return;const K=Dt.current;if(!K)return;const J=new MouseEvent("contextmenu",{clientX:O.x,clientY:O.y,bubbles:!0,cancelable:!0,button:2,buttons:2});K.dispatchEvent(J)},[O]);const Xt=g.useCallback(K=>{const J=Xe.current;!J||!P||P(J,K)},[P]),Gt=g.useCallback(()=>{const K=Xe.current;!K||!A||A(K)},[A]),Mr=g.useCallback(()=>{const K=Xe.current;!K||!U||U(K)},[U]),wa=g.useCallback(()=>{const K=Xe.current;!K||!Le||Le(K)},[Le]),Xu=g.useCallback(()=>{if(!ce)return;const K=Xe.current,J=K?[K]:[...c];J.length!==0&&ce(J)},[ce,c]);g.useCallback((K,J,le,de,ye)=>{Zr.current.enableContextMenu&&(Xe.current=null,$(!1),te(null),Ce({connectorId:K,kind:J,pinned:le}),B({x:de,y:ye}))},[]);const _e=g.useCallback(()=>{const K=Pe;!K||!Je||Je(K.connectorId,K.kind)},[Pe,Je]),it=g.useCallback(()=>{if(!R)return;const K=O,J=zt.current;if(!K||!J)return;const le=J.screenToFlowPosition({x:K.x,y:K.y});R(le)},[O,R]),je=typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent||""),st=je?"⌘C":"Ctrl+C",rn=je?"⌘V":"Ctrl+V",Yt=g.useMemo(()=>new Set(c),[c]),Ci=g.useMemo(()=>{const K=new Set;for(const J of i)J.data.locked===!0&&K.add(J.id);return K},[i]),oo=g.useMemo(()=>new Set(l),[l]),tj=g.useMemo(()=>{if(c.length<2)return[];const K=rr,J=[];for(const le of c){const de=i.find(Ae=>Ae.id===le);if(!de)continue;const ye=K==null?void 0:K[le],Ne=(ye==null?void 0:ye.data)??{},Me=de.data;J.push({id:le,position:(ye==null?void 0:ye.position)??de.position,data:{width:Ne.width??Me.width,height:Ne.height??Me.height,locked:Ne.locked??Me.locked}})}return J},[i,rr,c]),Vf=z??[],$f=g.useMemo(()=>{const K=ye=>{const Ne=bt?void 0:Bd.current.get(ye.id),Me={id:ye.id,type:ye.type,position:Ne??ye.position,data:{...ye.data,projectId:o,fileBaseUrl:a,onRetryUpload:L,status:eDe(vr,ye.id),errorMessage:tDe(vr,ye.id),statusReport:Ro==null?void 0:Ro[ye.id],onPlay:f,onResize:k,setResizing:Vd,onFitToContent:ye.type==="htmlNode"?w:void 0,onNameChange:(()=>{if(bt&&!(ye.type==="shapeNode"&&ye.data.shape==="ellipse"))return M})(),onDescriptionChange:(()=>{if(bt){if(ye.type==="shapeNode"){const Ae=ye.data.shape;return Ae==="rectangle"||Ae==="ellipse"||Ae==="sticky"?x:void 0}if(!(ye.type==="imageNode"||ye.type==="iconNode"))return x}})(),onIconChange:(()=>{if(bt&&!(ye.type!=="playNode"&&ye.type!=="stateNode"))return Ee})(),autoEditOnMount:ve===ye.id?!0:void 0},selected:Yt.has(ye.id)};return ye.data.width!==void 0&&(Me.width=ye.data.width),ye.data.height!==void 0&&(Me.height=ye.data.height),Yt.has(ye.id)||(Me.connectable=!1),ye.data.locked===!0&&(Me.draggable=!1),Me},J=i.map(ye=>K(Vze(ye,rr==null?void 0:rr[ye.id]))),le=new Set(i.map(ye=>ye.id)),de=[];if(rr)for(const[ye,Ne]of Object.entries(rr)){if(le.has(ye))continue;const Me=Ne;typeof Me.type!="string"||!Me.position||!Me.data||de.push(K({...Me,id:ye}))}return[...J,...de]},[o,a,i,Yt,vr,Ro,f,k,w,Vd,rr,M,x,Ee,L,ve,bt]),[nj,rj]=g.useState($f);g.useEffect(()=>{Do.current||Zu.current||rj($f)},[$f]),g.useEffect(()=>{Ud.current=nj},[nj]);const br=g.useRef(Yt);g.useEffect(()=>{br.current=Yt},[Yt]);const ao=g.useRef(u);g.useEffect(()=>{ao.current=u},[u]);const qo=g.useRef(oo);g.useEffect(()=>{qo.current=oo},[oo]);const Ud=g.useRef($f),Si=g.useRef(!1),Uf=g.useRef(new Set),Wf=g.useRef(new Set),oj=g.useRef(new Set),aj=g.useRef(new Set),Ma=g.useRef(null),Lde=g.useCallback(K=>{var ot;const J=Si.current?oj.current:(ot=Ma.current)!=null&&ot.shift?Ma.current.nodeIds:null,le=J&&J.size>0?K.filter(Ze=>Ze.type!=="select"?!0:!(Ze.selected===!1&&J.has(Ze.id))):K,de=new Set;for(const Ze of le)Ze.type==="select"&&de.add(Ze.id);const ye=Sie(le,Ud.current),Ne=br.current,Me=Si.current||Ne.size===0?ye:ye.map(Ze=>Ne.has(Ze.id)&&!de.has(Ze.id)&&!Ze.selected?{...Ze,selected:!0}:Ze);if(Ud.current=Me,rj(Me),de.size===0)return;if(Si.current){for(const Ze of le)Ze.type==="select"&&(Ze.selected?Uf.current.add(Ze.id):Uf.current.delete(Ze.id));return}const Ae=ao.current;if(!Ae)return;const et=Me.filter(Ze=>Ze.selected).map(Ze=>Ze.id),ht=br.current;ht.size===et.length&&et.every(Ze=>ht.has(Ze))||(br.current=new Set(et),Ae(et,[...qo.current]))},[]),Gf=g.useRef([]),Ide=g.useCallback(K=>{var qt;const J=Si.current?aj.current:(qt=Ma.current)!=null&&qt.shift?Ma.current.edgeIds:null,le=J&&J.size>0?K.filter(Re=>Re.type!=="select"?!0:!(Re.selected===!1&&J.has(Re.id))):K,de=new Set;for(const Re of le)Re.type==="select"&&de.add(Re.id);if(de.size===0)return;if(Si.current){for(const Re of le)Re.type==="select"&&(Re.selected?Wf.current.add(Re.id):Wf.current.delete(Re.id));return}const ye=ao.current;if(!ye)return;const Me=Lie(le,Gf.current).filter(Re=>Re.selected).map(Re=>Re.id),Ae=qo.current;Ae.size===Me.length&&Me.every(Re=>Ae.has(Re))||(qo.current=new Set(Me),ye([...br.current],Me))},[]),Ede=g.useCallback(K=>{Si.current=!0;const J=Ma.current,le=(J==null?void 0:J.shift)??(K.shiftKey||K.metaKey||K.ctrlKey);oj.current=le?new Set((J==null?void 0:J.nodeIds)??br.current):new Set,aj.current=le?new Set((J==null?void 0:J.edgeIds)??qo.current):new Set,Uf.current=new Set(oj.current),Wf.current=new Set(aj.current)},[]),Ade=g.useCallback(()=>{Si.current=!1,Ma.current=null;const K=ao.current;if(!K)return;const J=[...Uf.current],le=new Set(J),de=new Set(Wf.current);for(const et of Gf.current)le.has(et.source)&&le.has(et.target)&&de.add(et.id);const ye=br.current,Ne=qo.current,Me=ye.size===le.size&&J.every(et=>ye.has(et)),Ae=Ne.size===de.size&&[...de].every(et=>Ne.has(et));Me&&Ae||(br.current=new Set(J),qo.current=new Set(de),K(J,[...de]))},[]),Pde=g.useCallback(K=>{if(Ma.current=null,rt.current||K.button!==0)return;const J=K.target;J!=null&&J.classList.contains("react-flow__pane")&&(Ma.current={shift:K.shiftKey||K.metaKey||K.ctrlKey,nodeIds:new Set(br.current),edgeIds:new Set(qo.current)})},[]),_de=g.useCallback(K=>{if(!Zr.current.enableContextMenu||br.current.size<2)return;const le=K.target;le!==Dt.current&&(le!=null&&le.closest(".seeflow-connector-endpoint-dot")||(K.preventDefault(),K.stopPropagation(),Xe.current=null,$(!0),te(null),Ce(null),B({x:K.clientX,y:K.clientY})))},[]),Rde=g.useCallback(K=>{const J=K.dataTransfer;if(!J)return;const le=J.types?Array.from(J.types):[],de=le.includes("Files"),ye=le.includes(OJ),Ne=de&&!!C&&Fe.enableImageDrop,Me=ye&&!!_&&Fe.enableDragDrop;if(!(!Ne&&!Me)){K.preventDefault();try{J.dropEffect="copy"}catch{}}},[C,_,Fe.enableImageDrop,Fe.enableDragDrop]),Tde=g.useCallback(K=>{const J=K.dataTransfer;if((J!=null&&J.types?Array.from(J.types):[]).includes(OJ)&&_&&Fe.enableDragDrop){K.preventDefault();const Ne=zt.current;if(!Ne)return;const Me=Ne.screenToFlowPosition({x:K.clientX,y:K.clientY});_({position:Me});return}if(!C||!Fe.enableImageDrop)return;const ye={x:K.clientX,y:K.clientY};K.preventDefault(),Wke({dataTransfer:J,clientPos:ye,rfInstance:zt.current,computeDims:Gke,dispatch:C})},[C,_,Fe.enableImageDrop,Fe.enableDragDrop]),uU=!!E,dU=oo.size===1?[...oo][0]:null,ij=g.useMemo(()=>{const K=Ae=>{const et=ste(vr,Ae.source)==="running"||ste(vr,Ae.target)==="running",ht=oo.has(Ae.id),qt=J8e(Ae,et,ht);ht&&(qt.selected=!0);const Re=uU&&Ae.id===dU,ot=Re?{...qt,reconnectable:!0}:qt;return{...ot,data:{...ot.data,onLabelChange:bt?b:void 0,reconnectable:Re,registerEditHandle:ga}}},J=new Set(s.map(Ae=>Ae.id)),le=s.map(Ae=>K($ze(Ae,Yr==null?void 0:Yr[Ae.id]))),de=[];if(Yr)for(const[Ae,et]of Object.entries(Yr)){if(J.has(Ae))continue;const ht=et;typeof ht.source!="string"||typeof ht.target!="string"||typeof ht.kind!="string"||de.push(K({...ht,id:Ae}))}const ye=[...le,...de],Ne=[],Me=[];for(const Ae of ye)oo.has(Ae.id)?Me.push(Ae):Ne.push(Ae);return[...Ne,...Me]},[s,vr,oo,dU,Yr,b,uU,ga,bt]);g.useEffect(()=>{Gf.current=ij},[ij]);const jde=g.useCallback(()=>{const K=zt.current,J=Ud.current;if(J.length<2)return;const le=J.map(Re=>{var Oo;const ot=(Oo=K==null?void 0:K.getInternalNode(Re.id))==null?void 0:Oo.measured,Ze=Re.data,Ii=(ot==null?void 0:ot.width)??Ze.width??200,Ca=(ot==null?void 0:ot.height)??Ze.height??120;return{id:Re.id,width:Ii,height:Ca,position:Re.position}}),de=Gf.current.map(Re=>({source:Re.source,target:Re.target})),ye=rae(le,de);let Ne=Number.POSITIVE_INFINITY,Me=Number.POSITIVE_INFINITY,Ae=Number.POSITIVE_INFINITY,et=Number.POSITIVE_INFINITY;for(const Re of le){Re.position.x<Ne&&(Ne=Re.position.x),Re.position.y<Me&&(Me=Re.position.y);const ot=ye.get(Re.id);ot&&(ot.x<Ae&&(Ae=ot.x),ot.y<et&&(et=ot.y))}const ht=Number.isFinite(Ne)&&Number.isFinite(Ae)?Ne-Ae:0,qt=Number.isFinite(Me)&&Number.isFinite(et)?Me-et:0;rj(Re=>Re.map(ot=>{const Ze=ye.get(ot.id);return Ze?{...ot,position:{x:Ze.x+ht,y:Ze.y+qt}}:ot}))},[]),Kf=oe??(bt?void 0:jde),Zf=g.useRef(!1),hU=g.useRef(null),Nde=g.useCallback(K=>{var Ae;if(!bt||!T)return;const{source:J,target:le}=K;if(!J||!le||J===le)return;Zf.current=!0;const de=((Ae=hU.current)==null?void 0:Ae.nodeId)??null,ye=de!==null&&de===le&&de!==J;T(ye?le:J,ye?J:le)},[T,bt]),sj=g.useCallback(K=>{const J=le=>{if(!le)return!1;const de=Ud.current.find(ye=>ye.id===le);return de?de.type==="shapeNode"&&de.data.shape==="text":!1};return!J(K.source)&&!J(K.target)},[]),zde=g.useCallback((K,J)=>{var qt;wr(!1),va();const le=Zf.current;if(Zf.current=!1,le||ka.current)return;if(Mi.current){Mi.current=!1;return}if(!T)return;const de=(qt=J.fromNode)==null?void 0:qt.id,ye=J.fromHandle;if(!de||!ye)return;const Ne=rte(K);if(!Ne)return;const Me=MF(hn.current,Ne.clientX,Ne.clientY);if(!Me)return;const Ae=Me.getAttribute("data-id");if(!Ae||Ae===de||!sj({source:de,target:Ae,sourceHandle:null,targetHandle:null}))return;let et;const ht=zt.current;if(ht){const Re=ht.getInternalNode(Ae);if(Re){const ot=Re.measured.width??Re.width??0,Ze=Re.measured.height??Re.height??0;if(ot>0&&Ze>0){const Ii=ht.screenToFlowPosition({x:Ne.clientX,y:Ne.clientY});et=OH({x:Re.internals.positionAbsolute.x,y:Re.internals.positionAbsolute.y,w:ot,h:Ze},Ii)}}}T(de,Ae,et?{targetPin:et}:void 0)},[T,va,sj]),Xf=g.useRef(!1),Dde=g.useCallback((K,J)=>{if(!E)return;const{source:le,target:de,sourceHandle:ye,targetHandle:Ne}=J;if(!le||!de||le===de)return;const Me={};if(le!==K.source&&(Me.source=le),de!==K.target&&(Me.target=de),typeof ye=="string"&&ye!==K.sourceHandle&&(Me.sourceHandle=ye),typeof Ne=="string"&&Ne!==K.targetHandle&&(Me.targetHandle=Ne),Me.source===void 0&&Me.target===void 0&&Me.sourceHandle===void 0&&Me.targetHandle===void 0)return;(Me.source!==void 0||Me.sourceHandle!==void 0)&&(Me.sourceHandleAutoPicked=!1),(Me.target!==void 0||Me.targetHandle!==void 0)&&(Me.targetHandleAutoPicked=!1);const Ae=zt.current;if(!(Me.source===void 0&&Me.target===void 0)&&Ae){const ht=Me.source!==void 0?"source":"target",qt=ote(ht,K.source,K.target,K.data,Re=>Ae.getInternalNode(Re)??null);qt&&(ht==="source"?Me.targetPin=qt:Me.sourcePin=qt)}Xf.current=!0,E(K.id,Me)},[E]),qde=g.useCallback((K,J,le,de)=>{var Jf;wr(!1),va(),ka.current=!1;const ye=Xf.current;if(Xf.current=!1,ye)return;if(bi.current){bi.current=!1;return}if(!E)return;const Ne=rte(K);let Me=((Jf=de.toNode)==null?void 0:Jf.id)??null;if(!Me&&Ne){const Sa=MF(hn.current,Ne.clientX,Ne.clientY);Me=(Sa==null?void 0:Sa.getAttribute("data-id"))??null}const Ae=le==="source"?"target":"source",et=Bze(Ae,J.source,J.target,Me);if(et==="no-op"||et==="self-loop"||!Ne)return;const ht=zt.current;if(!ht)return;const qt=et==="pin-own"?Ae==="source"?J.source:J.target:Me,Re=ht.getInternalNode(qt);if(!Re)return;const ot=Re.measured.width??Re.width??0,Ze=Re.measured.height??Re.height??0;if(ot===0||Ze===0)return;const Ii=ht.screenToFlowPosition({x:Ne.clientX,y:Ne.clientY}),Ca=OH({x:Re.internals.positionAbsolute.x,y:Re.internals.positionAbsolute.y,w:ot,h:Ze},Ii);if(et==="pin-own"){if(!ut)return;ut(J.id,Ae,Ca);return}const Oo=ote(Ae,J.source,J.target,J.data,Sa=>ht.getInternalNode(Sa)??null);Ae==="source"?E(J.id,{source:Me,sourceHandle:null,sourceHandleAutoPicked:!1,sourcePin:Ca,...Oo?{targetPin:Oo}:{}}):E(J.id,{target:Me,targetHandle:null,targetHandleAutoPicked:!1,targetPin:Ca,...Oo?{sourcePin:Oo}:{}})},[E,va,ut]),Li=g.useMemo(()=>{var Ae;if(!ir||!to)return null;const K=(Ae=hn.current)==null?void 0:Ae.getBoundingClientRect(),J=(K==null?void 0:K.left)??0,le=(K==null?void 0:K.top)??0,de=Math.min(ir.x,to.x),ye=Math.min(ir.y,to.y),Ne=Math.abs(to.x-ir.x),Me=Math.abs(to.y-ir.y);return{left:de-J,top:ye-le,width:Ne,height:Me}},[ir,to]),Ode=Lt?ace(Lt):"",Fde=Lt?ice(Lt):void 0,Hde=Lt==="text",[fU,pU]=g.useState(!1),[Bde,Yf]=g.useState(!1),[Vde,yU]=g.useState(!1),ba=Nze({projectId:o,getReactFlow:()=>zt.current});g.useImperativeHandle(t,()=>({exportPdf:ba.exportPdf,exportPng:ba.exportPng,openEmbedDialog:()=>yU(!0),capturePreview:ba.capturePreview}),[ba.exportPdf,ba.exportPng,ba.capturePreview]),g.useEffect(()=>{if(!Fe.enableKeyboard)return;const K=de=>{if(!de)return!1;const ye=de.tagName;return ye==="INPUT"||ye==="TEXTAREA"||ye==="SELECT"?!0:de instanceof HTMLElement&&de.isContentEditable},J=de=>{de.code==="Space"&&(K(document.activeElement)||(de.preventDefault(),pU(!0)))},le=de=>{de.code==="Space"&&(pU(!1),Yf(!1))};return window.addEventListener("keydown",J),window.addEventListener("keyup",le),()=>{window.removeEventListener("keydown",J),window.removeEventListener("keyup",le)}},[Fe.enableKeyboard]);const Qf=g.useCallback(K=>{if(K.length!==0){if(!bt){const J=Bd.current;for(const le of K)J.set(le.id,{x:le.position.x,y:le.position.y});return}if(K.length===1){const J=K[0];J&&p&&p(J.id,{x:J.position.x,y:J.position.y});return}if(y){y(K.map(J=>({id:J.id,position:{x:J.position.x,y:J.position.y}})));return}if(p)for(const J of K)p(J.id,{x:J.position.x,y:J.position.y})}},[p,y,bt]),$de=g.useCallback((K,J,le)=>{Do.current=!1,Qf(le),xa()},[Qf,xa]),Ude=g.useCallback(()=>{Do.current=!0},[]),Wde=g.useCallback((K,J)=>{Do.current=!1,Qf(J),xa()},[Qf,xa]),Gde=g.useCallback((K,J)=>{re==null||re(J.id)},[re]),Kde=g.useCallback(K=>{we==null||we()},[we]),Zde=g.useCallback((K,J)=>{ie==null||ie(J.id)},[ie]),mU=Lt?"crosshair":fU?Bde?"grabbing":"grab":void 0,gU=c[0],kU=l[0],Xde=gU?i.find(K=>K.id===gU)??null:null,Yde=kU?s.find(K=>K.id===kU)??null:null,Qde=o??null,Jde=Fe.showDetailPanel&&!ge,ehe=g.useMemo(()=>({custom:Pt??{}}),[Pt]);return m.jsx(GMe,{value:ehe,children:m.jsx("div",{"data-testid":"seeflow-canvas","data-mode":n,ref:hn,className:"seeflow-canvas-root sf:relative sf:h-full sf:w-full",style:mU?{cursor:mU}:void 0,onPointerDownCapture:Pde,onPointerDown:K=>{fU&&Yf(!0),Ku(K)},onPointerMove:ej,onPointerUp:K=>{Yf(!1),Bf(K)},onPointerCancel:()=>{nn.current=!1,no.current=null,qn.current=null,eo(null),zo(null),Yf(!1)},onContextMenuCapture:_de,onDragOver:Rde,onDrop:Tde,children:m.jsxs(K9e,{containerRef:hn,children:[m.jsxs(y8e,{nodes:nj,edges:ij,onNodesChange:Lde,nodeTypes:Uze,edgeTypes:Wze,proOptions:{hideAttribution:!0},fitView:!0,minZoom:n==="mini"?.05:.5,nodesDraggable:(bt?!!p:!0)&&!Lt&&Fe.enableNodeMove,nodesConnectable:bt&&!!T&&!Lt,deleteKeyCode:bt?["Backspace","Delete"]:null,zoomOnScroll:Fe.enableZoom,zoomOnPinch:Fe.enableZoom,className:or?"seeflow-connecting":void 0,onConnect:bt?Nde:void 0,isValidConnection:sj,onConnectStart:(K,J)=>{wr(!0),Zf.current=!1,hU.current={nodeId:J.nodeId??null,handleType:J.handleType??null},bn(J.nodeId??null)},onConnectEnd:zde,onReconnect:bt&&E?Dde:void 0,onReconnectStart:(K,J,le)=>{wr(!0),Xf.current=!1,ka.current=!0;const de=le==="source"?J.source:J.target;bn(de)},onReconnectEnd:qde,connectionLineComponent:Gu,connectionLineStyle:{strokeWidth:2},connectionRadius:32,reconnectRadius:10,edgesReconnectable:!1,elevateNodesOnSelect:!1,elementsSelectable:!Lt&&Fe.enableSelection,selectNodesOnDrag:!1,nodeClickDistance:5,selectionOnDrag:!Lt&&Fe.enableSelection,panOnDrag:Lt?!1:Fe.enablePan?[1,2]:!1,selectionMode:od.Partial,selectionKeyCode:null,multiSelectionKeyCode:Lt?null:["Meta","Shift"],panActivationKeyCode:Lt?null:"Space",onSelectionStart:Ede,onSelectionEnd:Ade,defaultEdgeOptions:Gze,zoomOnDoubleClick:!1,onInit:K=>{zt.current=K;const J=hn.current;J&&J.style.setProperty("--rf-zoom",String(K.getZoom())),!To.current&&zn.onMount&&i.length>0&&(K.fitView(lh),To.current=!0),Y==null||Y(K)},onMove:(K,J)=>{Jr.current&&Qr(null);const le=hn.current;le&&le.style.setProperty("--rf-zoom",String(J.zoom))},onEdgesChange:Ide,onNodeDragStart:()=>{Do.current=!0},onNodeDragStop:$de,onSelectionDragStart:Ude,onSelectionDragStop:Wde,onNodeClick:Gde,onEdgeClick:Zde,onEdgeDoubleClick:(K,J)=>{var le;(le=Dn.current.get(J.id))==null||le()},onPaneClick:Kde,onNodeContextMenu:Fe.enableContextMenu&&$d?(K,J)=>{K.preventDefault(),Xe.current=J.id,$(!0),te(J.type??null),Ce(null),B({x:K.clientX,y:K.clientY})}:void 0,onPaneContextMenu:Fe.enableContextMenu&&R?K=>{K.preventDefault(),Xe.current=null,$(!1),te(null),Ce(null),B({x:K.clientX,y:K.clientY})}:void 0,children:[m.jsx(Xze,{storeApiRef:jo}),m.jsx(Yze,{wrapperRef:hn}),m.jsx(S8e,{gap:12,size:.6}),Fe.showControls?m.jsxs(R8e,{showInteractive:!1,showFitView:!1,children:[m.jsx(L1,{"data-testid":"controls-fit-view","aria-label":"Fit view",title:"Fit view",disabled:i.length===0,onClick:()=>{var K;(K=zt.current)==null||K.fitView(lh)},children:m.jsx(N1,{className:"sf:h-3 sf:w-3","aria-hidden":"true"})}),m.jsx(L1,{"data-testid":"controls-tidy","aria-label":"Tidy layout (⌘⇧L)",title:"Tidy layout (⌘⇧L)",disabled:!Kf,onClick:()=>Kf==null?void 0:Kf(),children:m.jsx(Kh,{className:"sf:h-3 sf:w-3","aria-hidden":"true"})})]}):null,Fe.showResizeHandles?m.jsx(_Ne,{selectedNodes:tj,onMultiResize:v}):null,Fe.showToolbar&&S||Fe.showStyleStrip&&I&&W?m.jsx(ld,{position:"top-left",children:m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-2",children:[Fe.showToolbar&&S?m.jsx(uEe,{activeShape:Lt,onSelectShape:wi,iconPickerOpen:xe??!1,onOpenIconPicker:ee,onCloseIconPicker:se,onPickIcon:qe}):null,Fe.showStyleStrip&&I&&W?m.jsx(TNe,{nodes:Vf,connectors:N??[],onStyleNode:I,onStyleNodePreview:G,onStyleNodes:q,onStyleNodesPreview:j,onStyleConnector:W,onStyleConnectorPreview:X,onRequestIconReplace:Le}):null]})}):null,Fe.showShareMenu||Fe.showRestart&&Te?m.jsx(ld,{position:"top-right",children:m.jsxs("div",{className:"sf:flex sf:items-center sf:gap-1",children:[Fe.showRestart&&Te?m.jsx(INe,{onRestartDemo:Te}):null,Fe.showShareMenu?m.jsx(LNe,{mode:n==="mini"?"view":n,projectId:o,enableEmbed:Fe.enableEmbed,onDownloadPdf:ba.exportPdf,onDownloadPng:ba.exportPng,onExportToCloud:Oe,embedOpen:Vde,onEmbedOpenChange:yU}):null]})}):null]}),Li?m.jsx("div",{"data-testid":"canvas-draw-ghost","data-ghost-shape":Lt??void 0,"aria-hidden":!0,className:ae("sf:pointer-events-none sf:absolute sf:z-10",Ode,Hde?"sf:rounded-sm sf:border sf:border-dashed sf:border-muted-foreground/40":""),style:{...Fde,left:Li.left,top:Li.top,width:Li.width,height:Li.height},children:(()=>{const K=Lt?M$[Lt]:void 0;return K?m.jsx(K,{width:Li.width,height:Li.height,borderColor:ct(void 0,"node").borderColor,backgroundColor:rf,borderSize:i$}):null})()}):null,Fe.enableContextMenu&&$d?m.jsxs(jLe,{onOpenChange:K=>{K||(B(null),Xe.current=null,te(null),Ce(null))},children:[m.jsx(NLe,{asChild:!0,children:m.jsx("div",{ref:Dt,"data-testid":"node-context-menu-trigger","aria-hidden":!0,className:"sf:pointer-events-none sf:fixed",style:{left:(O==null?void 0:O.x)??0,top:(O==null?void 0:O.y)??0,width:0,height:0}})}),m.jsxs(Fle,{"data-testid":"node-context-menu",children:[Pe!=null&&Pe.pinned&&Je?m.jsx(Ir,{"data-testid":"connector-endpoint-context-menu-unpin",onSelect:_e,children:"Unpin"}):null,Z&&U?m.jsxs(Ir,{"data-testid":"node-context-menu-copy",onSelect:Mr,children:["Copy",m.jsx(QH,{children:st})]}):null,R?m.jsxs(Ir,{"data-testid":"node-context-menu-paste",disabled:!H,onSelect:it,children:["Paste",m.jsx(QH,{children:rn})]}):null,Z&&(U||R)&&(D==="iconNode"&&Le||P||A)?m.jsx(Sh,{}):null,Z&&D==="iconNode"&&Le?m.jsx(Ir,{"data-testid":"node-context-menu-change-icon",onSelect:wa,children:"Change icon"}):null,Z&&D==="iconNode"&&Le&&(P||A)?m.jsx(Sh,{}):null,Z&&P?m.jsxs(m.Fragment,{children:[m.jsx(Ir,{"data-testid":"node-context-menu-to-front",onSelect:()=>Xt({op:"toFront"}),children:"Bring to front"}),m.jsx(Ir,{"data-testid":"node-context-menu-forward",onSelect:()=>Xt({op:"forward"}),children:"Bring forward"}),m.jsx(Ir,{"data-testid":"node-context-menu-backward",onSelect:()=>Xt({op:"backward"}),children:"Send backward"}),m.jsx(Ir,{"data-testid":"node-context-menu-to-back",onSelect:()=>Xt({op:"toBack"}),children:"Send to back"})]}):null,Z&&P&&(ce||A)?m.jsx(Sh,{}):null,Z&&ce?(()=>{const K=Xe.current,J=K?[K]:c,le=J.length>0&&J.every(de=>Ci.has(de))?"Unlock":"Lock";return m.jsx(Ir,{"data-testid":"node-context-menu-toggle-lock",onSelect:Xu,disabled:J.length===0,children:le})})():null,Z&&ce&&A?m.jsx(Sh,{}):null,Z&&A?m.jsx(Ir,{"data-testid":"node-context-menu-delete",onSelect:Gt,disabled:Xe.current?Ci.has(Xe.current):!1,children:"Delete"}):null]})]}):null,ke?m.jsxs(zd,{open:!!Mn,onOpenChange:K=>{K||Qr(null)},children:[m.jsx(Z9e,{asChild:!0,children:m.jsx("div",{"data-testid":"drop-popover-anchor","aria-hidden":!0,className:"sf:pointer-events-none sf:fixed",style:{left:(Mn==null?void 0:Mn.clientX)??0,top:(Mn==null?void 0:Mn.clientY)??0,width:0,height:0}})}),m.jsx(qu,{"data-testid":"drop-popover",align:"start",side:"bottom",sideOffset:4,className:"sf:w-auto sf:p-1",onOpenAutoFocus:K=>{K.preventDefault()},children:m.jsx("div",{role:"menu","aria-label":"Create connected node",className:"sf:flex sf:flex-col sf:gap-0.5",children:lEe.map(({shape:K,label:J,Icon:le})=>m.jsxs("button",{type:"button",role:"menuitem","data-testid":`drop-popover-shape-${K}`,onClick:()=>{const de=Mn;de&&(ke({sourceNodeId:de.sourceNodeId,position:{x:de.flowX,y:de.flowY},shape:K}),Qr(null))},className:ae("sf:flex sf:items-center sf:gap-2 sf:rounded-sm sf:px-2 sf:py-1.5 sf:text-left sf:text-sm","sf:hover:bg-accent sf:hover:text-accent-foreground","sf:focus:bg-accent sf:focus:text-accent-foreground sf:focus:outline-hidden"),children:[m.jsx(le,{className:"sf:h-4 sf:w-4 sf:text-muted-foreground","aria-hidden":"true"}),m.jsx("span",{children:J})]},K))})})]}):null,Jde?m.jsx(rNe,{flowId:Qde,node:Xde,connector:Yde,adapter:r??null,statusReport:be,onNameChange:De,onDescriptionChange:ne,onDetailChange:he,onIconChange:Ee,onClose:()=>{var K;(K=ao.current)==null||K.call(ao,[],[])}}):null]})})})}const rDe=g.forwardRef(nDe);function oDe({open:e,onOpenChange:t,onCreated:n}){const[r,o]=g.useState(""),[a,i]=g.useState(null),[s,c]=g.useState(!1);g.useEffect(()=>{e&&(o(""),i(null),c(!1))},[e]);const l=r.trim(),u=l.length>0&&!s,d=async f=>{if(f.preventDefault(),!!u){c(!0),i(null);try{const p=await Pfe({name:l});n(p),t(!1)}catch(p){i(p instanceof Error?p.message:String(p)),c(!1)}}};return m.jsx(NT,{open:e,onOpenChange:t,children:m.jsxs(Ef,{className:"sm:max-w-md","data-testid":"create-project-dialog",onOpenAutoFocus:f=>{f.preventDefault();const p=document.querySelector('[data-testid="create-project-name-input"]');p==null||p.focus()},children:[m.jsxs(Af,{children:[m.jsx(Pf,{children:"Create new project"}),m.jsxs(_f,{children:["The project will be created at ",m.jsx("code",{children:"~/.seeflow/<slug>"}),"."]})]}),m.jsxs("form",{onSubmit:d,className:"flex flex-col gap-4",children:[m.jsxs("label",{className:"flex flex-col gap-1.5 text-sm",children:[m.jsx("span",{className:"font-medium",children:"Project name"}),m.jsx("input",{type:"text",required:!0,autoComplete:"off",spellCheck:!1,value:r,onChange:f=>o(f.target.value),"data-testid":"create-project-name-input",className:"rounded-md border bg-background px-3 py-2 text-sm outline-hidden ring-offset-background focus:border-ring focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"})]}),a?m.jsx("div",{role:"alert","data-testid":"create-project-error",className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:a}):null,m.jsxs(pd,{children:[m.jsx(Ft,{type:"button",variant:"ghost",onClick:()=>t(!1),disabled:s,children:"Cancel"}),m.jsx(Ft,{type:"submit",disabled:!u,"data-testid":"create-project-submit",children:s?"Creating…":"Create project"})]})]})]})})}const vB="seeflow:navigate",aDe=e=>(window.addEventListener("popstate",e),window.addEventListener(vB,e),()=>{window.removeEventListener("popstate",e),window.removeEventListener(vB,e)}),cte=()=>window.location.pathname,iDe=()=>g.useSyncExternalStore(aDe,cte,cte),gd=e=>{e!==window.location.pathname&&(window.history.pushState({},"",e),window.dispatchEvent(new Event(vB)))};function sDe({demos:e,currentSlug:t,onProjectCreated:n,onProjectUnregistered:r}){const[o,a]=g.useState(!1),[i,s]=g.useState(!1),[c,l]=g.useState(null),[u,d]=g.useState(!1),[f,p]=g.useState(null);g.useEffect(()=>{const x=b=>{b.key==="k"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),a(S=>!S))};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[]);const y=e.find(x=>x.slug===t),k=x=>{n==null||n(x),gd(`/d/${x.slug}`)},w=x=>{l(x),p(null)},v=()=>{u||(l(null),p(null))},M=async()=>{if(c){d(!0),p(null);try{await Afe(c.id);const x=c.id;l(null),r==null||r(x)}catch(x){p(x instanceof Error?x.message:String(x))}finally{d(!1)}}};return m.jsxs(m.Fragment,{children:[m.jsxs(zd,{open:o,onOpenChange:a,children:[m.jsx(wf,{asChild:!0,children:m.jsxs(Ft,{type:"button",variant:"outline",size:"sm","aria-label":"Switch demo","aria-expanded":o,className:"gap-2","data-testid":"project-switcher-trigger",children:[m.jsx("span",{className:"max-w-[180px] truncate text-sm",children:(y==null?void 0:y.name)??"Select demo"}),m.jsx(Dce,{children:"⌘K"}),m.jsx(Oh,{className:"h-3.5 w-3.5 opacity-60"})]})}),m.jsx(qu,{align:"end",sideOffset:6,className:"w-[320px] p-0","data-testid":"project-switcher-popover",children:m.jsxs(Rce,{children:[m.jsx(Tce,{placeholder:"Search demos..."}),m.jsxs(jce,{children:[m.jsx(Nce,{children:"No demos."}),e.length>0?m.jsx(KH,{heading:"Demos",children:e.map(x=>m.jsxs(ZH,{value:`${x.name} ${x.slug}`,onSelect:()=>{a(!1),gd(`/d/${x.slug}`)},className:"group flex items-center justify-between gap-2",children:[m.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-0.5",children:[m.jsx("span",{className:"font-medium",children:x.name}),m.jsx("span",{className:"w-full truncate text-xs text-muted-foreground",children:x.repoPath})]}),m.jsx("button",{type:"button","aria-label":`Unregister ${x.name}`,className:"shrink-0 rounded p-0.5 opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring",onClick:b=>{b.stopPropagation(),a(!1),w(x)},children:m.jsx(c2,{className:"h-3.5 w-3.5"})})]},x.id))}):null,e.length>0?m.jsx(zce,{}):null,m.jsx(KH,{children:m.jsxs(ZH,{value:"+ create new project",onSelect:()=>{a(!1),s(!0)},"data-testid":"project-switcher-create",className:"flex items-center gap-2 text-sm",children:[m.jsx(Jh,{className:"h-4 w-4 opacity-70"}),m.jsx("span",{className:"font-medium",children:"Create new project"})]})})]})]})})]}),m.jsx(oDe,{open:i,onOpenChange:s,onCreated:k}),m.jsx(NT,{open:c!==null,onOpenChange:x=>{x||v()},children:m.jsxs(Ef,{className:"sm:max-w-md","data-testid":"unregister-project-dialog",children:[m.jsxs(Af,{children:[m.jsx(Pf,{children:"Unregister project?"}),m.jsxs(_f,{children:["This removes ",m.jsx("strong",{children:c==null?void 0:c.name})," from SeeFlow. Your files at"," ",m.jsx("code",{className:"text-xs",children:c==null?void 0:c.repoPath})," will not be deleted."]})]}),f?m.jsx("div",{role:"alert","data-testid":"unregister-project-error",className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:f}):null,m.jsxs(pd,{children:[m.jsx(Ft,{type:"button",variant:"ghost",onClick:v,disabled:u,children:"Cancel"}),m.jsx(Ft,{type:"button",variant:"destructive",onClick:M,disabled:u,"data-testid":"unregister-project-confirm",children:u?"Unregistering…":"Unregister"})]})]})})]})}function cDe({demos:e,currentSlug:t,onProjectCreated:n,onProjectUnregistered:r}){return m.jsxs("header",{className:"relative flex h-14 shrink-0 items-center justify-between border-b border-border/60 bg-background/85 px-5 backdrop-blur-md shadow-[0_4px_12px_-6px_rgba(0,0,0,0.6)]",children:[m.jsxs("button",{type:"button",onClick:()=>gd("/"),className:"-ml-1.5 flex items-center gap-2 rounded-md px-1.5 py-1 text-base font-bold tracking-tight transition-colors hover:bg-muted/60",children:[m.jsx(d2,{size:18,strokeWidth:2.25,className:"text-emerald-400"}),"SeeFlow"]}),m.jsx("div",{className:"flex items-center gap-3",children:m.jsx(sDe,{demos:e,currentSlug:t,onProjectCreated:n,onProjectUnregistered:r})})]})}const lDe=e=>{const[t,n]=g.useState(null),[r,o]=g.useState(e!==null),[a,i]=g.useState(null),s=g.useCallback(()=>{e&&(o(!0),qre(e).then(c=>{n(c),i(null)}).catch(c=>{console.error("[useDemoData] failed",c),i(String(c))}).finally(()=>o(!1)))},[e]);return g.useEffect(()=>{if(!e){n(null),o(!1);return}s()},[e,s]),{detail:t,loading:r,error:a,refresh:s}},uDe=()=>{const[e,t]=g.useState(null),[n,r]=g.useState(null),o=g.useCallback(()=>Efe().then(a=>{t(a),r(null)}).catch(a=>{console.error("[useDemos] failed",a),t([]),r(String(a))}),[]);return g.useEffect(()=>{o()},[o]),{demos:e,error:n,refresh:o}},dDe=5,hDe={"node:running":"running","node:done":"done","node:error":"error"},fDe=(e,t)=>{if(t.type==="reset")return{};const n=e[t.nodeId]??[],r=[t.entry,...n].slice(0,dDe);return{...e,[t.nodeId]:r}},pDe=e=>{const[t,n]=g.useReducer(fDe,{}),r=g.useRef(n);r.current=n,g.useEffect(()=>{r.current({type:"reset"})},[e]);const o=g.useCallback(i=>{const s=hDe[i.type];if(!s)return;const c=typeof i.nodeId=="string"?i.nodeId:null;if(!c)return;const l=typeof i.runId=="string"?i.runId:void 0,u=typeof i.ts=="number"?i.ts:Date.now();r.current({type:"append",nodeId:c,entry:{status:s,ts:u,runId:l}})},[]),a=g.useCallback(()=>{r.current({type:"reset"})},[]);return{events:t,apply:o,reset:a}},yDe=(e,t)=>{var n,r;switch(t.type){case"reset":return{};case"running":return{...e,[t.nodeId]:{status:"running",runId:t.runId,ts:t.ts??Date.now()}};case"done":return{...e,[t.nodeId]:{...e[t.nodeId],status:"done",runId:t.runId??((n=e[t.nodeId])==null?void 0:n.runId),responseStatus:t.responseStatus,body:t.body,ts:t.ts??Date.now()}};case"error":return{...e,[t.nodeId]:{...e[t.nodeId],status:"error",runId:t.runId??((r=e[t.nodeId])==null?void 0:r.runId),error:t.message,ts:t.ts??Date.now()}}}},mDe=e=>{const[t,n]=g.useReducer(yDe,{}),r=g.useRef(n);r.current=n,g.useEffect(()=>{r.current({type:"reset"})},[e]);const o=g.useCallback(i=>{const s=typeof i.nodeId=="string"?i.nodeId:null;if(!s)return;const c=typeof i.runId=="string"?i.runId:void 0;if(i.type==="node:running"){r.current({type:"running",nodeId:s,runId:c,ts:i.ts});return}if(i.type==="node:done"){const l=typeof i.status=="number"?i.status:void 0;r.current({type:"done",nodeId:s,runId:c,responseStatus:l,body:i.body,ts:i.ts});return}if(i.type==="node:error"){const l=typeof i.message=="string"?i.message:void 0;r.current({type:"error",nodeId:s,runId:c,message:l,ts:i.ts})}},[]),a=g.useCallback(()=>{r.current({type:"reset"})},[]);return{runs:t,apply:o,reset:a}},gDe=new Set(["ok","warn","error","pending"]),kDe=(e,t)=>{if(t.type!=="node:status")return e;const n=typeof t.nodeId=="string"?t.nodeId:null;if(!n||typeof t.state!="string"||!gDe.has(t.state))return e;const r=typeof t.summary=="string"?t.summary:void 0,o=typeof t.detail=="string"?t.detail:void 0,a=t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:void 0,i=typeof t.ts=="number"?t.ts:Date.now();return{...e,[n]:{state:t.state,summary:r,detail:o,data:a,ts:i}}},vDe=(e,t)=>{switch(t.type){case"reset":return{};case"event":return kDe(e,t.event)}},xDe=e=>{const[t,n]=g.useReducer(vDe,{}),r=g.useRef(n);r.current=n,g.useEffect(()=>{r.current({type:"reset"})},[e]);const o=g.useCallback(i=>{r.current({type:"event",event:i})},[]),a=g.useCallback(()=>{r.current({type:"reset"})},[]);return{statusByNode:t,apply:o,reset:a}},wDe=(e,t={})=>{const[n,r]=g.useState(null),[o,a]=g.useState(!1),{onReload:i,onEvent:s}=t;return g.useEffect(()=>{if(!e){r(null),a(!1);return}const c=`/api/events?flowId=${encodeURIComponent(e)}`,l=new EventSource(c);l.addEventListener("open",()=>a(!0)),l.addEventListener("error",()=>a(!1)),l.addEventListener("hello",()=>{i==null||i()}),l.addEventListener("flow:reload",u=>{const d=lte(u,"flow:reload");r(d),s==null||s(d),i==null||i()});for(const u of["node:running","node:done","node:error","node:status"])l.addEventListener(u,d=>{s==null||s(lte(d,u))});return()=>{l.close()}},[e,i,s]),{lastReload:n,connected:o}},lte=(e,t)=>{try{const n=JSON.parse(e.data);return{type:t,ts:Date.now(),...n}}catch{return{type:t,ts:Date.now()}}},ude="seeflow:last-project",MDe=()=>{if(typeof window>"u")return null;try{return window.localStorage.getItem(ude)}catch{return null}},ute=e=>{if(!(typeof window>"u"))try{window.localStorage.setItem(ude,e)}catch{}},bDe=(e,t)=>{if(e.length===0)return null;if(e.length===1)return e[0]??null;if(t){const n=e.find(r=>r.id===t);if(n)return n}return null},dte=["File","Edit","View","Tools","Layout","Selection","Help"],dde="seeflow:command-palette:recent",hde=5,fde=new Map(o$.map(e=>[e.id,e])),CDe=e=>typeof e=="string"&&fde.has(e),hte=()=>{if(typeof window>"u")return[];try{const e=window.localStorage.getItem(dde);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(CDe).slice(0,hde):[]}catch{return[]}},SDe=e=>{if(!(typeof window>"u"))try{window.localStorage.setItem(dde,JSON.stringify(e))}catch{}},fte=(e,t)=>e.enabled?e.enabled(t):!0,LDe=(e,t)=>t.length===0?!0:`${e.label} ${e.description??""}`.toLowerCase().includes(t);function IDe({open:e,onOpenChange:t,runCommand:n,ctx:r}){const[o,a]=g.useState(""),[i,s]=g.useState(0),[c,l]=g.useState(()=>hte()),u=g.useRef(null),d=g.useRef(null);g.useEffect(()=>{e&&(a(""),s(0),l(hte()))},[e]);const{groups:f,flat:p}=g.useMemo(()=>{const b=o.trim().toLowerCase();if(b.length===0){if(c.length===0)return{groups:[],flat:[]};const T=[];for(const P of c){const A=fde.get(P);A&&T.push({cmd:A,enabled:fte(A,r)})}return{groups:[{category:"Recent",rows:T}],flat:T}}const S=new Map;for(const T of o$){if(!LDe(T,b))continue;const E={cmd:T,enabled:fte(T,r)},P=S.get(T.category);P?P.push(E):S.set(T.category,[E])}const L=[...dte.filter(T=>S.has(T)),...Array.from(S.keys()).filter(T=>!dte.includes(T))].map(T=>({category:T,rows:S.get(T)??[]})),_=L.flatMap(T=>T.rows);return{groups:L,flat:_}},[o,r,c]);g.useEffect(()=>{if(p.length===0){s(0);return}s(b=>{var C;let S=b;if(S>=p.length&&(S=0),!((C=p[S])!=null&&C.enabled)){const L=p.findIndex(_=>_.enabled);L!==-1&&(S=L)}return S})},[p]);const y=g.useCallback(b=>{p.length!==0&&s(S=>{var L;let C=S;for(let _=0;_<p.length;_++)if(C=(C+b+p.length)%p.length,(L=p[C])!=null&&L.enabled)return C;return S})},[p]),k=g.useCallback(b=>{l(S=>{const C=[b,...S.filter(L=>L!==b)].slice(0,hde);return SDe(C),C})},[]),w=g.useCallback(b=>{const S=p[b];!S||!S.enabled||(k(S.cmd.id),n(S.cmd.id),t(!1))},[p,t,k,n]),v=g.useCallback(b=>{if(b.key==="ArrowDown"){b.preventDefault(),y(1);return}if(b.key==="ArrowUp"){b.preventDefault(),y(-1);return}b.key==="Enter"&&(b.preventDefault(),w(i))},[w,i,y]);g.useEffect(()=>{if(!e)return;const b=d.current;if(!b)return;const S=b.querySelector(`[data-command-row-index="${i}"]`);S&&typeof S.scrollIntoView=="function"&&S.scrollIntoView({block:"nearest"})},[i,e]);const x=o.trim().length>0;return m.jsx(PT,{open:e,onOpenChange:t,children:m.jsx(_T,{children:m.jsxs(Dd,{className:ae("fixed left-0 right-0 top-[20%] z-50 mx-auto w-[480px] max-w-[90vw] border border-border bg-card shadow-lg duration-200","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","sm:rounded-lg"),"data-testid":"command-palette",onOpenAutoFocus:b=>{var S;b.preventDefault(),(S=u.current)==null||S.focus()},children:[m.jsx("div",{className:ae("border-b",p.length===0&&!x&&"border-b-0"),children:m.jsx("input",{ref:u,type:"text",value:o,onChange:b=>a(b.target.value),onKeyDown:v,placeholder:"Type a command…","data-testid":"command-palette-input","aria-label":"Search commands",autoComplete:"off",spellCheck:!1,className:"w-full bg-transparent px-4 py-3 text-sm outline-hidden placeholder:text-muted-foreground"})}),m.jsx("div",{ref:d,"data-testid":"command-palette-list","data-empty":p.length===0?"true":"false",className:ae("max-h-[50vh] overflow-y-auto",p.length>0?"py-1":"","seeflow-no-scrollbar"),children:p.length===0?x?m.jsxs("div",{"data-testid":"command-palette-empty",className:"px-4 py-6 text-center text-sm text-muted-foreground",children:['No commands match "',o,'"']}):null:(()=>{let b=-1;return f.map(S=>m.jsxs("div",{className:"py-1",children:[m.jsx("div",{className:"px-3 pb-1 pt-2 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:S.category}),S.rows.map(C=>{b+=1;const L=b,_=L===i;return m.jsxs("button",{type:"button","data-testid":`command-palette-row-${C.cmd.id}`,"data-command-row-index":L,"data-highlighted":_?"true":"false","aria-disabled":C.enabled?void 0:!0,disabled:!C.enabled,onMouseEnter:()=>{C.enabled&&s(L)},onClick:()=>w(L),className:ae("flex w-full items-center justify-between gap-3 px-3 py-2 text-left text-sm outline-hidden",C.enabled?"cursor-pointer text-foreground hover:bg-muted":"cursor-not-allowed text-muted-foreground/50",_&&C.enabled?"bg-muted":""),children:[m.jsxs("div",{className:"flex min-w-0 flex-col",children:[m.jsx("span",{className:"truncate font-medium",children:C.cmd.label}),C.cmd.description?m.jsx("span",{className:"truncate text-xs text-muted-foreground",children:C.cmd.description}):null]}),C.cmd.shortcut?m.jsx("kbd",{"data-testid":`command-palette-shortcut-${C.cmd.id}`,className:"shrink-0 rounded border bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:C.cmd.shortcut}):null]},C.cmd.id)})]},S.category))})()})]})})})}var un=Uint8Array,Gn=Uint16Array,sU=Int32Array,cU=new un([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),lU=new un([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),pte=new un([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),pde=function(e,t){for(var n=new Gn(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var o=new sU(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)o[a]=a-n[r]<<5|r;return{b:n,r:o}},yde=pde(cU,2),EDe=yde.b,xB=yde.r;EDe[28]=258,xB[258]=28;var ADe=pde(lU,0),yte=ADe.r,wB=new Gn(32768);for(var xt=0;xt<32768;++xt){var Ta=(xt&43690)>>1|(xt&21845)<<1;Ta=(Ta&52428)>>2|(Ta&13107)<<2,Ta=(Ta&61680)>>4|(Ta&3855)<<4,wB[xt]=((Ta&65280)>>8|(Ta&255)<<8)>>1}var k2=function(e,t,n){for(var r=e.length,o=0,a=new Gn(t);o<r;++o)e[o]&&++a[e[o]-1];var i=new Gn(t);for(o=1;o<t;++o)i[o]=i[o-1]+a[o-1]<<1;var s;if(n){s=new Gn(1<<t);var c=15-t;for(o=0;o<r;++o)if(e[o])for(var l=o<<4|e[o],u=t-e[o],d=i[e[o]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[wB[d]>>c]=l}else for(s=new Gn(r),o=0;o<r;++o)e[o]&&(s[o]=wB[i[e[o]-1]++]>>15-e[o]);return s},Au=new un(288);for(var xt=0;xt<144;++xt)Au[xt]=8;for(var xt=144;xt<256;++xt)Au[xt]=9;for(var xt=256;xt<280;++xt)Au[xt]=7;for(var xt=280;xt<288;++xt)Au[xt]=8;var CR=new un(32);for(var xt=0;xt<32;++xt)CR[xt]=5;var PDe=k2(Au,9,0),_De=k2(CR,5,0),mde=function(e){return(e+7)/8|0},gde=function(e,t,n){return(n==null||n>e.length)&&(n=e.length),new un(e.subarray(t,n))},RDe=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],JT=function(e,t,n){var r=new Error(t||RDe[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,JT),!n)throw r;return r},Uo=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},uh=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8,e[r+2]|=n>>16},bF=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var o=n.length,a=n.slice();if(!o)return{t:vde,l:0};if(o==1){var i=new un(n[0].s+1);return i[n[0].s]=1,{t:i,l:1}}n.sort(function(S,C){return S.f-C.f}),n.push({s:-1,f:25001});var s=n[0],c=n[1],l=0,u=1,d=2;for(n[0]={s:-1,f:s.f+c.f,l:s,r:c};u!=o-1;)s=n[n[l].f<n[d].f?l++:d++],c=n[l!=u&&n[l].f<n[d].f?l++:d++],n[u++]={s:-1,f:s.f+c.f,l:s,r:c};for(var f=a[0].s,r=1;r<o;++r)a[r].s>f&&(f=a[r].s);var p=new Gn(f+1),y=MB(n[u-1],p,0);if(y>t){var r=0,k=0,w=y-t,v=1<<w;for(a.sort(function(C,L){return p[L.s]-p[C.s]||C.f-L.f});r<o;++r){var M=a[r].s;if(p[M]>t)k+=v-(1<<y-p[M]),p[M]=t;else break}for(k>>=w;k>0;){var x=a[r].s;p[x]<t?k-=1<<t-p[x]++-1:++r}for(;r>=0&&k;--r){var b=a[r].s;p[b]==t&&(--p[b],++k)}y=t}return{t:new un(p),l:y}},MB=function(e,t,n){return e.s==-1?Math.max(MB(e.l,t,n+1),MB(e.r,t,n+1)):t[e.s]=n},mte=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new Gn(++t),r=0,o=e[0],a=1,i=function(c){n[r++]=c},s=1;s<=t;++s)if(e[s]==o&&s!=t)++a;else{if(!o&&a>2){for(;a>138;a-=138)i(32754);a>2&&(i(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(i(o),--a;a>6;a-=6)i(8304);a>2&&(i(a-3<<5|8208),a=0)}for(;a--;)i(o);a=1,o=e[s]}return{c:n.subarray(0,r),n:t}},dh=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},kde=function(e,t,n){var r=n.length,o=mde(t+2);e[o]=r&255,e[o+1]=r>>8,e[o+2]=e[o]^255,e[o+3]=e[o+1]^255;for(var a=0;a<r;++a)e[o+a+4]=n[a];return(o+4+r)*8},gte=function(e,t,n,r,o,a,i,s,c,l,u){Uo(t,u++,n),++o[256];for(var d=bF(o,15),f=d.t,p=d.l,y=bF(a,15),k=y.t,w=y.l,v=mte(f),M=v.c,x=v.n,b=mte(k),S=b.c,C=b.n,L=new Gn(19),_=0;_<M.length;++_)++L[M[_]&31];for(var _=0;_<S.length;++_)++L[S[_]&31];for(var T=bF(L,7),E=T.t,P=T.l,A=19;A>4&&!E[pte[A-1]];--A);var U=l+5<<3,R=dh(o,Au)+dh(a,CR)+i,H=dh(o,f)+dh(a,k)+i+14+3*A+dh(L,E)+2*L[16]+3*L[17]+7*L[18];if(c>=0&&U<=R&&U<=H)return kde(t,u,e.subarray(c,c+l));var F,V,z,N;if(Uo(t,u,1+(H<R)),u+=2,H<R){F=k2(f,p,0),V=f,z=k2(k,w,0),N=k;var I=k2(E,P,0);Uo(t,u,x-257),Uo(t,u+5,C-1),Uo(t,u+10,A-4),u+=14;for(var _=0;_<A;++_)Uo(t,u+3*_,E[pte[_]]);u+=3*A;for(var G=[M,S],q=0;q<2;++q)for(var j=G[q],_=0;_<j.length;++_){var W=j[_]&31;Uo(t,u,I[W]),u+=E[W],W>15&&(Uo(t,u,j[_]>>5&127),u+=j[_]>>12)}}else F=PDe,V=Au,z=_De,N=CR;for(var _=0;_<s;++_){var X=r[_];if(X>255){var W=X>>18&31;uh(t,u,F[W+257]),u+=V[W+257],W>7&&(Uo(t,u,X>>23&31),u+=cU[W]);var Y=X&31;uh(t,u,z[Y]),u+=N[Y],Y>3&&(uh(t,u,X>>5&8191),u+=lU[Y])}else uh(t,u,F[X]),u+=V[X]}return uh(t,u,F[256]),u+V[256]},TDe=new sU([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),vde=new un(0),jDe=function(e,t,n,r,o,a){var i=a.z||e.length,s=new un(r+i+5*(1+Math.ceil(i/7e3))+o),c=s.subarray(r,s.length-o),l=a.l,u=(a.r||0)&7;if(t){u&&(c[0]=a.r>>3);for(var d=TDe[t-1],f=d>>13,p=d&8191,y=(1<<n)-1,k=a.p||new Gn(32768),w=a.h||new Gn(y+1),v=Math.ceil(n/3),M=2*v,x=function(ee){return(e[ee]^e[ee+1]<<v^e[ee+2]<<M)&y},b=new sU(25e3),S=new Gn(288),C=new Gn(32),L=0,_=0,T=a.i||0,E=0,P=a.w||0,A=0;T+2<i;++T){var U=x(T),R=T&32767,H=w[U];if(k[R]=H,w[U]=R,P<=T){var F=i-T;if((L>7e3||E>24576)&&(F>423||!l)){u=gte(e,c,0,b,S,C,_,E,A,T-A,u),E=L=_=0,A=T;for(var V=0;V<286;++V)S[V]=0;for(var V=0;V<30;++V)C[V]=0}var z=2,N=0,I=p,G=R-H&32767;if(F>2&&U==x(T-G))for(var q=Math.min(f,F)-1,j=Math.min(32767,T),W=Math.min(258,F);G<=j&&--I&&R!=H;){if(e[T+z]==e[T+z-G]){for(var X=0;X<W&&e[T+X]==e[T+X-G];++X);if(X>z){if(z=X,N=G,X>q)break;for(var Y=Math.min(G,X-2),oe=0,V=0;V<Y;++V){var re=T-G+V&32767,ie=k[re],we=re-ie&32767;we>oe&&(oe=we,H=re)}}}R=H,H=k[R],G+=R-H&32767}if(N){b[E++]=268435456|xB[z]<<18|yte[N];var ke=xB[z]&31,ve=yte[N]&31;_+=cU[ke]+lU[ve],++S[257+ke],++C[ve],P=T+z,++L}else b[E++]=e[T],++S[e[T]]}}for(T=Math.max(T,P);T<i;++T)b[E++]=e[T],++S[e[T]];u=gte(e,c,l,b,S,C,_,E,A,T-A,u),l||(a.r=u&7|c[u/8|0]<<3,u-=7,a.h=w,a.p=k,a.i=T,a.w=P)}else{for(var T=a.w||0;T<i+l;T+=65535){var xe=T+65535;xe>=i&&(c[u/8|0]=l,xe=i),u=kde(c,u+1,e.subarray(T,xe))}a.i=i}return gde(s,0,r+mde(u)+o)},NDe=function(){for(var e=new Int32Array(256),t=0;t<256;++t){for(var n=t,r=9;--r;)n=(n&1&&-306674912)^n>>>1;e[t]=n}return e}(),zDe=function(){var e=-1;return{p:function(t){for(var n=e,r=0;r<t.length;++r)n=NDe[n&255^t[r]]^n>>>8;e=n},d:function(){return~e}}},xde=function(){var e=1,t=0;return{p:function(n){for(var r=e,o=t,a=n.length|0,i=0;i!=a;){for(var s=Math.min(i+2655,a);i<s;++i)o+=r+=n[i];r=(r&65535)+15*(r>>16),o=(o&65535)+15*(o>>16)}e=r,t=o},d:function(){return e%=65521,t%=65521,(e&255)<<24|(e&65280)<<8|(t&255)<<8|t>>8}}},wde=function(e,t,n,r,o){if(!o&&(o={l:1},t.dictionary)){var a=t.dictionary.subarray(-32768),i=new un(a.length+e.length);i.set(a),i.set(e,a.length),e=i,o.w=a.length}return jDe(e,t.level==null?6:t.level,t.mem==null?o.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+t.mem,n,r,o)},Mde=function(e,t){var n={};for(var r in e)n[r]=e[r];for(var r in t)n[r]=t[r];return n},$t=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},DDe=function(e,t){var n=t.level,r=n==0?0:n<6?1:n==9?3:2;if(e[0]=120,e[1]=r<<6|(t.dictionary&&32),e[1]|=31-(e[0]<<8|e[1])%31,t.dictionary){var o=xde();o.p(t.dictionary),$t(e,2,o.d())}};function qDe(e,t){return wde(e,t||{},0,0)}function Lqe(e,t){t||(t={});var n=xde();n.p(e);var r=wde(e,t,t.dictionary?6:2,4);return DDe(r,t),$t(r,r.length-4,n.d()),r}var bde=function(e,t,n,r){for(var o in e){var a=e[o],i=t+o,s=r;Array.isArray(a)&&(s=Mde(r,a[1]),a=a[0]),a instanceof un?n[i]=[a,s]:(n[i+="/"]=[new un(0),s],bde(a,i,n,r))}},kte=typeof TextEncoder<"u"&&new TextEncoder,ODe=typeof TextDecoder<"u"&&new TextDecoder,FDe=0;try{ODe.decode(vde,{stream:!0}),FDe=1}catch{}function bB(e,t){var n;if(kte)return kte.encode(e);for(var r=e.length,o=new un(e.length+(e.length>>1)),a=0,i=function(l){o[a++]=l},n=0;n<r;++n){if(a+5>o.length){var s=new un(a+8+(r-n<<1));s.set(o),o=s}var c=e.charCodeAt(n);c<128||t?i(c):c<2048?(i(192|c>>6),i(128|c&63)):c>55295&&c<57344?(c=65536+(c&1047552)|e.charCodeAt(++n)&1023,i(240|c>>18),i(128|c>>12&63),i(128|c>>6&63),i(128|c&63)):(i(224|c>>12),i(128|c>>6&63),i(128|c&63))}return gde(o,0,a)}var CB=function(e){var t=0;if(e)for(var n in e){var r=e[n].length;r>65535&&JT(9),t+=r+4}return t},vte=function(e,t,n,r,o,a,i,s){var c=r.length,l=n.extra,u=s&&s.length,d=CB(l);$t(e,t,i!=null?33639248:67324752),t+=4,i!=null&&(e[t++]=20,e[t++]=n.os),e[t]=20,t+=2,e[t++]=n.flag<<1|(a<0&&8),e[t++]=o&&8,e[t++]=n.compression&255,e[t++]=n.compression>>8;var f=new Date(n.mtime==null?Date.now():n.mtime),p=f.getFullYear()-1980;if((p<0||p>119)&&JT(10),$t(e,t,p<<25|f.getMonth()+1<<21|f.getDate()<<16|f.getHours()<<11|f.getMinutes()<<5|f.getSeconds()>>1),t+=4,a!=-1&&($t(e,t,n.crc),$t(e,t+4,a<0?-a-2:a),$t(e,t+8,n.size)),$t(e,t+12,c),$t(e,t+14,d),t+=16,i!=null&&($t(e,t,u),$t(e,t+6,n.attrs),$t(e,t+10,i),t+=14),e.set(r,t),t+=c,d)for(var y in l){var k=l[y],w=k.length;$t(e,t,+y),$t(e,t+2,w),e.set(k,t+4),t+=4+w}return u&&(e.set(s,t),t+=u),t},HDe=function(e,t,n,r,o){$t(e,t,101010256),$t(e,t+8,n),$t(e,t+10,n),$t(e,t+12,r),$t(e,t+16,o)};function BDe(e,t){t||(t={});var n={},r=[];bde(e,"",n,t);var o=0,a=0;for(var i in n){var s=n[i],c=s[0],l=s[1],u=l.level==0?0:8,d=bB(i),f=d.length,p=l.comment,y=p&&bB(p),k=y&&y.length,w=CB(l.extra);f>65535&&JT(11);var v=u?qDe(c,l):c,M=v.length,x=zDe();x.p(c),r.push(Mde(l,{size:c.length,crc:x.d(),c:v,f:d,m:y,u:f!=i.length||y&&p.length!=k,o,compression:u})),o+=30+f+w+M,a+=76+2*(f+w)+(k||0)+M}for(var b=new un(a+22),S=o,C=a-o,L=0;L<r.length;++L){var d=r[L];vte(b,d.o,d,d.f,d.u,d.c.length);var _=30+d.f.length+CB(d.extra);b.set(d.c,d.o+_),vte(b,o,d,d.f,d.u,d.c.length,d.o,d.m),o+=16+_+(d.m?d.m.length:0)}return HDe(b,o,r.length,C,S),b}const VDe="https://seeflow.dev/api";async function $De(e,t,n,r,o){const a=await qre(e);if(!a.flow)throw new Error("Flow has no data");const i=a.flow,s=new Set,c=[];for(const y of i.nodes)y.type==="imageNode"&&y.data.path&&!s.has(y.data.path)?(s.add(y.data.path),c.push(y.data.path)):y.type==="htmlNode"&&y.data.htmlPath&&!s.has(y.data.htmlPath)&&(s.add(y.data.htmlPath),c.push(y.data.htmlPath));const u={[r==="link"?"seeflow.private.json":"seeflow.json"]:bB(JSON.stringify(i))};if(o){const y=o.split(",")[1];y&&(u["preview.png"]=Uint8Array.from(atob(y),k=>k.charCodeAt(0)))}for(const y of c){const k=await fetch(`/api/projects/${encodeURIComponent(e)}/files/${y}`);k.ok&&(u[`files/${y}`]=new Uint8Array(await k.arrayBuffer()))}const d=BDe(u),f=await fetch(`${VDe}/flows?email=${encodeURIComponent(t)}&name=${encodeURIComponent(n)}`,{method:"POST",headers:{"content-type":"application/zip"},body:d.buffer});if(!f.ok)throw new Error(`Export failed with status ${f.status}`);const p=await f.json();if(typeof p.url!="string")throw new Error("Invalid response from cloud API: missing url");return{shareUrl:p.url}}function UDe(e){return g.useCallback((t,n,r,o)=>$De(e,t,n,r,o),[e])}const xte="seeflow.export.email",wte="seeflow.export.name",Mte="seeflow.export.visibility";function WDe({open:e,onOpenChange:t,projectId:n,onCapturePreview:r}){const[o,a]=g.useState(""),[i,s]=g.useState(""),[c,l]=g.useState("public"),[u,d]=g.useState({kind:"idle"}),[f,p]=g.useState(!1),y=UDe(n);g.useEffect(()=>{e&&(a(localStorage.getItem(xte)??""),s(localStorage.getItem(wte)??""),l(localStorage.getItem(Mte)??"public"),d({kind:"idle"}),p(!1))},[e]);const k=g.useCallback(async()=>{d({kind:"loading"});try{const x=await(r==null?void 0:r()),{shareUrl:b}=await y(o.trim(),i.trim(),c,x);localStorage.setItem(xte,o.trim()),localStorage.setItem(wte,i.trim()),localStorage.setItem(Mte,c),d({kind:"done",shareUrl:b})}catch(x){d({kind:"error",message:x instanceof Error?x.message:String(x)})}},[y,o,i,c,r]),w=g.useCallback(async()=>{if(u.kind==="done")try{await navigator.clipboard.writeText(u.shareUrl),p(!0),setTimeout(()=>p(!1),2e3)}catch(x){console.error("Failed to copy to clipboard:",x)}},[u]),v=u.kind==="loading",M=o.trim().length>0&&i.trim().length>0;return m.jsx(NT,{open:e,onOpenChange:t,children:m.jsxs(Ef,{className:"sm:max-w-md","data-testid":"export-dialog",onOpenAutoFocus:x=>{x.preventDefault();const b=document.querySelector('[data-testid="export-email-input"]');b==null||b.focus()},children:[m.jsxs(Af,{children:[m.jsx(Pf,{children:"Export to seeflow.dev"}),m.jsx(_f,{children:"Upload this diagram to the cloud and get a shareable link."})]}),u.kind!=="done"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex flex-col gap-4",children:[m.jsxs("label",{className:"flex flex-col gap-1.5 text-sm",children:[m.jsx("span",{className:"font-medium",children:"Email"}),m.jsx("input",{type:"email",required:!0,autoComplete:"email",value:o,onChange:x=>a(x.target.value),disabled:v,"data-testid":"export-email-input",className:"rounded-md border bg-background px-3 py-2 text-sm outline-hidden ring-offset-background focus:border-ring focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"We'll use this to let you manage your flows in the future."})]}),m.jsxs("label",{className:"flex flex-col gap-1.5 text-sm",children:[m.jsx("span",{className:"font-medium",children:"Flow Name"}),m.jsx("input",{type:"text",required:!0,value:i,onChange:x=>s(x.target.value),disabled:v,"data-testid":"export-name-input",className:"rounded-md border bg-background px-3 py-2 text-sm outline-hidden ring-offset-background focus:border-ring focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"})]}),m.jsxs("label",{className:"flex flex-col gap-1.5 text-sm",children:[m.jsx("span",{className:"font-medium",children:"Visibility"}),m.jsxs("select",{value:c,onChange:x=>l(x.target.value),disabled:v,"data-testid":"export-visibility-select",className:"rounded-md border bg-background px-3 py-2 text-sm outline-hidden ring-offset-background focus:border-ring focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",children:[m.jsx("option",{value:"public",children:"Public — anyone can discover it"}),m.jsx("option",{value:"link",children:"Anyone with the link"})]})]}),u.kind==="error"?m.jsx("div",{role:"alert","data-testid":"export-error",className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:u.message}):null]}),m.jsx(pd,{children:u.kind==="error"?m.jsxs(m.Fragment,{children:[m.jsx(Ft,{type:"button",variant:"ghost",onClick:()=>t(!1),"data-testid":"export-cancel",children:"Cancel"}),m.jsx(Ft,{type:"button",onClick:()=>d({kind:"idle"}),"data-testid":"export-retry",children:"Try again"})]}):m.jsxs(m.Fragment,{children:[m.jsx(Ft,{type:"button",variant:"ghost",onClick:()=>t(!1),disabled:v,"data-testid":"export-cancel",children:"Cancel"}),m.jsx(Ft,{type:"button",onClick:k,disabled:v||!M,"data-testid":"export-submit",children:v?m.jsxs(m.Fragment,{children:[m.jsx(Rr,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}),m.jsx("span",{children:"Uploading…"})]}):"Export"})]})})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex flex-col gap-3",children:[m.jsx("p",{className:"text-sm text-muted-foreground",children:"Your diagram is live. Share this link:"}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx("input",{type:"text",readOnly:!0,value:u.shareUrl,"data-testid":"export-share-url",className:"min-w-0 flex-1 rounded-md border bg-muted px-3 py-2 text-sm outline-hidden"}),m.jsx(Ft,{type:"button",variant:"outline",size:"icon",onClick:w,"aria-label":"Copy link","data-testid":"export-copy",children:f?m.jsx(Mo,{className:"h-4 w-4","aria-hidden":"true"}):m.jsx(j1,{className:"h-4 w-4","aria-hidden":"true"})}),m.jsx(Ft,{type:"button",variant:"outline",size:"icon",onClick:()=>window.open(u.shareUrl,"_blank"),"aria-label":"View in new tab","data-testid":"export-view",children:m.jsx(Vh,{className:"h-4 w-4","aria-hidden":"true"})})]})]}),m.jsx(pd,{children:m.jsx(Ft,{type:"button",onClick:()=>t(!1),"data-testid":"export-done",children:"Done"})})]})]})})}const GDe=(e,t)=>{if(e.has(t))return e;const n=new Set(e);return n.add(t),n},KDe=(e,t)=>{if(t.length===0)return e;let n=!1;const r=new Set(e);for(const o of t)r.has(o)||(r.add(o),n=!0);return n?r:e},ZDe=(e,t)=>{if(!e.has(t))return e;const n=new Set(e);return n.delete(t),n},XDe=(e,t)=>{if(t.length===0)return e;let n=!1;const r=new Set(e);for(const o of t)r.has(o)&&(r.delete(o),n=!0);return n?r:e},YDe=(e,t)=>{if(e.size===0)return e;const n=new Set(t.map(a=>a.id));let r=!1;const o=new Set(e);for(const a of o)n.has(a)||(o.delete(a),r=!0);return r?o:e},bte=()=>{const[e,t]=g.useState(()=>new Set),n=g.useCallback(c=>{t(l=>GDe(l,c))},[]),r=g.useCallback(c=>{t(l=>KDe(l,c))},[]),o=g.useCallback(c=>{t(l=>ZDe(l,c))},[]),a=g.useCallback(c=>{t(l=>XDe(l,c))},[]),i=g.useCallback(c=>{t(l=>YDe(l,c))},[]),s=g.useCallback(()=>t(new Set),[]);return{ids:e,mark:n,markMany:r,unmark:o,unmarkMany:a,pruneAgainst:i,reset:s}},QDe=(e,t)=>e===t?!0:e==null||t==null||typeof e!=typeof t||typeof e!="object"?!1:JSON.stringify(e)===JSON.stringify(t),JDe=(e,t,n)=>({...e,[t]:{...e[t],...n}}),eqe=(e,t)=>{if(!(t in e))return e;const n={...e};return delete n[t],n},tqe=(e,t)=>{const n=Object.entries(e);if(n.length===0)return e;const r=new Map(t.map(i=>[i.id,i]));let o=!1;const a={...e};for(const[i,s]of n){const c=r.get(i);if(!c)continue;const l={};let u=!1;for(const d of Object.keys(s))QDe(s[d],c[d])?o=!0:(l[d]=s[d],u=!0);u?a[i]=l:(o=!0,delete a[i])}return o?a:e},Cte=()=>{const[e,t]=g.useState({}),n=g.useCallback((i,s)=>{t(c=>JDe(c,i,s))},[]),r=g.useCallback(i=>{t(s=>eqe(s,i))},[]),o=g.useCallback(i=>{t(s=>tqe(s,i))},[]),a=g.useCallback(()=>t({}),[]);return{overrides:e,setOverride:n,dropOverride:r,pruneAgainst:o,reset:a}},nqe=500,rqe=500,oqe={stack:[],cursor:0},aqe=(e,t,n)=>{const r=Date.now(),o=nqe,a=rqe,{stack:i,cursor:s}=e;if(t.coalesceKey&&s>0){const u=i[s-1];if(u&&u.coalesceKey===t.coalesceKey&&r-u.capturedAt<=a){const d=i.slice(0,s);return d[s-1]={...u,do:t.do,capturedAt:r},{stack:d,cursor:s}}}const c=i.slice(0,s);c.push({...t,capturedAt:r});let l=s+1;for(;c.length>o;)c.shift(),l-=1;return l<0&&(l=0),{stack:c,cursor:l}},iqe=e=>e.cursor===0?{state:e,entry:void 0}:{state:{...e,cursor:e.cursor-1},entry:e.stack[e.cursor-1]},sqe=e=>e.cursor===e.stack.length?{state:e,entry:void 0}:{state:{...e,cursor:e.cursor+1},entry:e.stack[e.cursor]},cqe=()=>({stack:[],cursor:0}),lqe=e=>{if(e.cursor===0)return e;const t=e.stack.slice();return t.splice(e.cursor-1,1),{stack:t,cursor:e.cursor-1}},uqe=(e,t)=>t.state,dqe=()=>{const[e,t]=g.useReducer(uqe,oqe),n=g.useRef(e);n.current=e;const r=g.useRef(Promise.resolve()),o=g.useRef(0),a=g.useCallback(p=>{p!==n.current&&(n.current=p,t({type:"replace",state:p}))},[]),i=g.useCallback(p=>{const y={do:p.do,undo:p.undo,coalesceKey:p.coalesceKey,capturedAt:p.capturedAt??Date.now()};a(aqe(n.current,y))},[a]),s=g.useCallback(()=>{o.current=Date.now();const p=r.current.then(()=>{const y=iqe(n.current);if(y.entry)return a(y.state),{entry:y.entry}});return r.current=p.then(()=>{},()=>{}),p},[a]),c=g.useCallback(()=>{o.current=Date.now();const p=r.current.then(()=>{const y=sqe(n.current);if(y.entry)return a(y.state),{entry:y.entry}});return r.current=p.then(()=>{},()=>{}),p},[a]),l=g.useCallback(()=>{a(cqe())},[a]),u=g.useCallback(()=>{a(lqe(n.current))},[a]),d=g.useCallback(()=>{o.current=Date.now()},[]),f=g.useCallback(()=>o.current,[]);return{push:i,undo:s,redo:c,clear:l,dropTop:u,canUndo:e.cursor>0,canRedo:e.cursor<e.stack.length,markMutation:d,lastMutationAt:f}};function hqe({nodes:e,connectors:t,flowPos:n,nodeIdGen:r,connectorIdGen:o,defaultOffset:a={x:24,y:24}}){const i=new Map;for(const p of e)i.set(p.id,r(p.id));let s=Number.POSITIVE_INFINITY,c=Number.POSITIVE_INFINITY;for(const p of e)p.position.x<s&&(s=p.position.x),p.position.y<c&&(c=p.position.y);Number.isFinite(s)||(s=0),Number.isFinite(c)||(c=0);const l=n?n.x-s:a.x,u=n?n.y-c:a.y,d=e.map(p=>{const y=i.get(p.id);if(y===void 0)throw new Error(`paste id missing for ${p.id}`);return{...p,id:y,position:{x:p.position.x+l,y:p.position.y+u}}}),f=t.map(p=>{const y=o(p.id);return{...p,id:y,source:i.get(p.source)??p.source,target:i.get(p.target)??p.target}});return{newNodes:d,newConnectors:f,idMap:i}}const fqe=e=>({type:"imageNode",position:e.position,data:{path:"",alt:e.originalFilename,width:e.dims.width,height:e.dims.height,_uploading:!0}}),pqe=e=>({type:"imageNode",data:Cde(e)}),yqe=e=>({type:"imageNode",position:e.position,data:{path:"",alt:e.originalFilename,width:e.dims.width,height:e.dims.height,_uploadError:e.message}}),Cde=e=>({...TMe(e.path,e.dims,e.lastUsed),alt:e.originalFilename}),mqe=async(e,t)=>{const{nodeId:n,flowId:r,file:o,originalFilename:a,position:i,dims:s,lastUsed:c}=e;t.rememberRetry(n,{file:o,originalFilename:a,position:i,dims:s}),t.setOverride(n,fqe({position:i,dims:s,originalFilename:a}));let l;try{l=(await t.upload(r,o,a)).path}catch(p){const y=p instanceof Error?p.message:String(p);throw t.setOverride(n,yqe({position:i,dims:s,originalFilename:a,message:y})),p}t.setOverride(n,pqe({path:l,dims:s,originalFilename:a,lastUsed:c}));const u=Cde({path:l,dims:s,originalFilename:a,lastUsed:c}),d={id:n,type:"imageNode",position:i,data:u},{id:f}=await t.createNode(r,d);t.forgetRetry(n),t.pushUndo&&t.pushUndo({do:async()=>{await t.createNode(r,{...d,id:f})},undo:async()=>{await t.deleteNode(r,f)}})},gqe=new Set(["INPUT","TEXTAREA","SELECT"]),Lr=e=>e?gqe.has(e.tagName)?!0:e instanceof HTMLElement&&e.isContentEditable:!1,kqe=(e,t,n)=>{const r=e.indexOf(t);if(r<0)return null;const o=e.length,a=[...e];switch(n.op){case"forward":{if(r>=o-1)return null;const i=a[r],s=a[r+1];return i===void 0||s===void 0?null:(a[r]=s,a[r+1]=i,a)}case"backward":{if(r<=0)return null;const i=a[r],s=a[r-1];return i===void 0||s===void 0?null:(a[r]=s,a[r-1]=i,a)}case"toFront":{if(r===o-1)return null;const[i]=a.splice(r,1);return i===void 0?null:(a.push(i),a)}case"toBack":{if(r===0)return null;const[i]=a.splice(r,1);return i===void 0?null:(a.unshift(i),a)}case"toIndex":{const i=Math.min(Math.max(n.index,0),o-1);if(i===r)return null;const[s]=a.splice(r,1);return s===void 0?null:(a.splice(i,0,s),a)}}};function vqe({slug:e,demos:t,detail:n,loading:r,runs:o,nodeEvents:a,statusByNode:i,onPlayNode:s,onRestartDemo:c}){var Vd,$d;const l=t.find(O=>O.slug===e),[u,d]=g.useState([]),[f,p]=g.useState([]),[y,k]=g.useState(null),w=g.useRef(u),v=g.useRef(f);g.useEffect(()=>{w.current=u},[u]),g.useEffect(()=>{v.current=f},[f]);const M=g.useRef(null),x=g.useRef(null),b=g.useRef(null),S=Cte(),C=Cte(),L=bte(),_=bte(),[T,E]=g.useState(null),[P,A]=g.useState(null),[U,R]=g.useState(null),H=g.useRef(null);g.useEffect(()=>{H.current=U},[U]);const[F,V]=g.useState(!1),[z,N]=g.useState(0),I=g.useRef(null),G=g.useRef(null),q=g.useCallback(O=>{G.current=O},[]),j=dqe(),{push:W,dropTop:X,markMutation:Y,clear:oe,lastMutationAt:re}=j,{reset:ie}=S,{reset:we}=C,{reset:ke}=L,{reset:ve}=_;g.useEffect(()=>{d([]),p([]),k(null),ie(),we(),ke(),ve(),E(null),A(null),Jr.current=null,No(!1),xr.current.clear(),j.clear()},[n==null?void 0:n.id]);const xe=g.useCallback((O,B)=>{d(O),p(B)},[]),ee=(Vd=n==null?void 0:n.flow)==null?void 0:Vd.nodes,se=($d=n==null?void 0:n.flow)==null?void 0:$d.connectors,{pruneAgainst:qe}=S,{pruneAgainst:Le}=C,{pruneAgainst:ut}=L,{pruneAgainst:Je}=_;g.useEffect(()=>{ee&&(qe(ee),ut(ee)),Date.now()-re()>2e3&&oe()},[ee,qe,ut,re,oe]),g.useEffect(()=>{if(!ee)return;const O=I.current,B=new Set(ee.map(te=>te.id));if(I.current=B,O===null)return;const Z=S.overrides,$=L.ids;let D=!1;for(const te of B)if(!O.has(te)&&!(te in Z)){D=!0;break}if(!D){for(const te of O)if(!B.has(te)&&!$.has(te)){D=!0;break}}D&&N(te=>te+1)},[ee]),g.useEffect(()=>{se&&(Le(se),Je(se)),Date.now()-re()>2e3&&oe()},[se,Le,Je,re,oe]),g.useEffect(()=>{if(!(!ee||!T)&&ee.length===T.length){for(let O=0;O<ee.length;O++){const B=ee[O],Z=T[O];if(!B||B.id!==Z)return}E(null)}},[ee,T]);const ce=(n==null?void 0:n.id)??null,Q=g.useMemo(()=>ce?jMe({baseUrl:"",flowId:ce}):null,[ce]),[ue,ge]=g.useState(!1),{setOverride:be,dropOverride:De}=S,ne=g.useRef(S.overrides);g.useEffect(()=>{ne.current=S.overrides},[S.overrides]);const he=g.useCallback((O,B)=>{var $;if(!ce||!Q)return;const Z=($=ee==null?void 0:ee.find(D=>D.id===O))==null?void 0:$.position;be(O,{position:B}),A(null),Y(),Z&&W({do:async()=>{await Q.updateNodePosition(O,B)},undo:async()=>{await Q.updateNodePosition(O,Z)},coalesceKey:`node:${O}:position`}),Q.updateNodePosition(O,B).catch(D=>{De(O),Z&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateNodePosition failed",D)})},[ce,Q,ee,be,De,W,X,Y]),Ee=g.useCallback(O=>{if(!ce||!Q||O.length===0)return;const B=ne.current,Z=O.map($=>{var Pe;const D=ee==null?void 0:ee.find(Ce=>Ce.id===$.id);if(!D)return null;const te=((Pe=B[$.id])==null?void 0:Pe.position)??D.position;return{id:$.id,prev:te,next:$.position}}).filter($=>$!==null);if(Z.length!==0){for(const $ of Z)be($.id,{position:$.next});A(null),Y(),W({do:async()=>{await Promise.allSettled(Z.map($=>Q.updateNodePosition($.id,$.next)))},undo:async()=>{await Promise.allSettled(Z.map($=>Q.updateNodePosition($.id,$.prev)))}}),Promise.all(Z.map(async $=>{try{return await Q.updateNodePosition($.id,$.next),null}catch(D){return De($.id),D instanceof Error?D.message:String(D)}})).then($=>{const D=$.find(te=>te!==null);D&&A(D)})}},[ce,Q,ee,be,De,W,Y]),Be=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(te=>te.id===O),$=Z?{width:Z.data.width,height:Z.data.height,position:{x:Z.position.x,y:Z.position.y}}:void 0,D={width:B.width,height:B.height,position:{x:B.x,y:B.y}};be(O,{position:D.position,data:{width:D.width,height:D.height}}),A(null),Y(),$&&W({do:async()=>{await Q.updateNode(O,D)},undo:async()=>{await Q.updateNode(O,$)},coalesceKey:`node:${O}:resize`}),Q.updateNode(O,D).catch(te=>{De(O),$&&X(),A(te instanceof Error?te.message:String(te)),console.error("updateNode resize failed",te)})},[ce,Q,ee,be,De,W,X,Y]),Ge=g.useCallback(O=>{if(!ce||!Q)return;const B=ee==null?void 0:ee.find(D=>D.id===O);if(!B)return;const Z={autoSize:B.data.autoSize,width:B.data.width,height:B.data.height},$={autoSize:!0};be(O,{data:{autoSize:!0,width:void 0,height:void 0}}),A(null),Y(),W({do:async()=>{await Q.updateNode(O,$)},undo:async()=>{await Q.updateNode(O,Z)},coalesceKey:`node:${O}:fit-to-content`}),Q.updateNode(O,$).catch(D=>{De(O),X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode (fit-to-content) failed",D)})},[ce,Q,ee,be,De,W,X,Y]),Pt=g.useCallback(O=>{if(!ce||!Q||O.length===0)return;const B=[];for(const $ of O){const D=ee==null?void 0:ee.find(Xe=>Xe.id===$.id);if(!D)continue;const te=D.data,Pe={position:{x:D.position.x,y:D.position.y}};te.width!==void 0&&(Pe.width=te.width),te.height!==void 0&&(Pe.height=te.height);const Ce={position:$.position};$.width!==void 0&&(Ce.width=$.width),$.height!==void 0&&(Ce.height=$.height),B.push({id:$.id,prev:Pe,next:Ce})}if(B.length===0)return;for(const $ of B){const D={};$.next.width!==void 0&&(D.width=$.next.width),$.next.height!==void 0&&(D.height=$.next.height),be($.id,{position:$.next.position,...Object.keys(D).length>0?{data:D}:{}})}A(null),Y();const Z=B.map($=>$.id).sort();W({do:async()=>{await Promise.allSettled(B.map($=>Q.updateNode($.id,$.next)))},undo:async()=>{await Promise.allSettled(B.map($=>Q.updateNode($.id,$.prev)))},coalesceKey:`multi:resize:${Z.join(",")}`}),Promise.all(B.map(async $=>{try{return await Q.updateNode($.id,$.next),null}catch(D){return De($.id),D instanceof Error?D.message:String(D)}})).then($=>{const D=$.find(te=>te!==null);D&&A(D)})},[ce,Q,ee,be,De,W,Y]),{setOverride:Oe,dropOverride:Te}=C,_t=g.useCallback((O,B)=>{be(O,{data:B})},[be]),nr=g.useCallback((O,B)=>{for(const Z of O)be(Z,{data:B})},[be]),Nt=g.useCallback((O,B)=>{Oe(O,B)},[Oe]),Nn=g.useCallback((O,B)=>{if(!ce||!Q)return;ZQ(Ei,B);const Z=ee==null?void 0:ee.find(D=>D.id===O);let $=null;if(Z){$={};const D=Z.data;for(const te of Object.keys(B))$[te]=D[te]}if(be(O,{data:B}),A(null),Y(),$){const D=$;W({do:async()=>{await Q.updateNode(O,B)},undo:async()=>{await Q.updateNode(O,D)},coalesceKey:`node:${O}:style`})}Q.updateNode(O,B).catch(D=>{De(O),$&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode style failed",D)})},[ce,Q,ee,be,De,W,X,Y]),tn=g.useCallback((O,B)=>{if(!ce||!Q||O.length===0)return;ZQ(Ei,B);const Z=O.map($=>{const D=ee==null?void 0:ee.find(Ce=>Ce.id===$);if(!D)return null;const te=D.data,Pe={};for(const Ce of Object.keys(B))Pe[Ce]=te[Ce];return{id:$,prev:Pe}}).filter($=>$!==null);if(Z.length!==0){for(const $ of Z)be($.id,{data:B});A(null),Y(),W({do:async()=>{await Promise.allSettled(Z.map($=>Q.updateNode($.id,B)))},undo:async()=>{await Promise.allSettled(Z.map($=>Q.updateNode($.id,$.prev)))}}),Promise.all(Z.map(async $=>{try{return await Q.updateNode($.id,B),null}catch(D){return De($.id),D instanceof Error?D.message:String(D)}})).then($=>{const D=$.find(te=>te!==null);D&&A(D)})}},[ce,Q,ee,be,De,W,Y]),Bu=g.useCallback(O=>{if(!ce||!Q||O.length===0)return;const B=O.map(D=>{const te=ee==null?void 0:ee.find(Ce=>Ce.id===D);if(!te)return null;const Pe=te.data;return{id:D,prev:Pe.locked===!0}}).filter(D=>D!==null);if(B.length===0)return;const Z=B.some(D=>!D.prev),$=B.filter(D=>D.prev!==Z);if($.length!==0){for(const D of $)be(D.id,{data:{locked:Z}});A(null),Y(),W({do:async()=>{await Promise.allSettled($.map(D=>Q.updateNode(D.id,{locked:Z})))},undo:async()=>{await Promise.allSettled($.map(D=>Q.updateNode(D.id,{locked:D.prev})))}}),Promise.all($.map(async D=>{try{return await Q.updateNode(D.id,{locked:Z}),null}catch(te){return De(D.id),te instanceof Error?te.message:String(te)}})).then(D=>{const te=D.find(Pe=>Pe!==null);te&&A(te)})}},[ce,Q,ee,be,De,W,Y]),Vu=g.useCallback((O,B)=>{if(!ce||!Q)return;EMe(Ei,B);const Z=se==null?void 0:se.find(D=>D.id===O);let $=null;if(Z){$={};const D=Z;for(const te of Object.keys(B))$[te]=D[te]}if(Oe(O,B),A(null),Y(),$){const D=$;W({do:async()=>{await Q.updateConnector(O,B)},undo:async()=>{await Q.updateConnector(O,D)},coalesceKey:`connector:${O}:style`})}Q.updateConnector(O,B).catch(D=>{Te(O),$&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateConnector failed",D)})},[ce,Q,se,Oe,Te,W,X,Y]),{mark:pa,markMany:ya,unmark:Gr,unmarkMany:ki}=L,{mark:ma,markMany:gr,unmark:Kr,unmarkMany:kr}=_,$u=g.useCallback(O=>{if(!ce||!Q)return;const B=ee==null?void 0:ee.find(Ce=>Ce.id===O);if(!B||B.data.locked===!0)return;const Z=(se??[]).filter(Ce=>Ce.source===O||Ce.target===O),$=Z.map(Ce=>Ce.id),D=new Set($);A(null),pa(O),$.length>0&&gr($),d(Ce=>Ce.filter(Xe=>Xe!==O)),p(Ce=>Ce.filter(Xe=>!D.has(Xe))),Y();const te=B,Pe=Z;W({do:async()=>{pa(O),$.length>0&&gr($),await Q.deleteNode(O)},undo:async()=>{Gr(O),$.length>0&&kr($),await Q.createNode({id:te.id,type:te.type,position:te.position,data:te.data});for(const Ce of Pe)await Q.createConnector({...Ce,id:Ce.id})}}),Q.deleteNode(O).catch(Ce=>{Gr(O),$.length>0&&kr($),X(),A(Ce instanceof Error?Ce.message:String(Ce)),console.error("deleteNode failed",Ce)})},[ce,Q,ee,se,pa,gr,Gr,kr,W,X,Y]),Uu=g.useCallback((O,B)=>{if(!ce||!Q||!ee)return;const Z=T??ee.map(te=>te.id),$=kqe(Z,O,B);if(!$)return;const D=Z.indexOf(O);E($),A(null),Y(),W({do:async()=>{await Q.reorderNode(O,B)},undo:async()=>{await Q.reorderNode(O,{op:"toIndex",index:D})}}),Q.reorderNode(O,B).catch(te=>{E(null),X(),A(te instanceof Error?te.message:String(te)),console.error("reorderNode failed",te)})},[ce,Q,ee,T,W,X,Y]);g.useCallback(O=>{if(!ce||!Q)return;const B=se==null?void 0:se.find($=>$.id===O);if(!B)return;A(null),ma(O),p($=>$.filter(D=>D!==O)),Y();const Z=B;W({do:async()=>{ma(O),await Q.deleteConnector(O)},undo:async()=>{Kr(O),await Q.createConnector({...Z,id:Z.id})}}),Q.deleteConnector(O).catch($=>{Kr(O),X(),A($ instanceof Error?$.message:String($)),console.error("deleteConnector failed",$)})},[ce,Q,se,ma,Kr,W,X,Y]);const Fe=g.useCallback((O,B)=>{if(!ce||!Q||O.length===0&&B.length===0)return;const Z=O,$=new Set((ee??[]).filter(_e=>_e.data.locked===!0).map(_e=>_e.id)),D=Z.filter(_e=>!$.has(_e)),te=new Set(D),Pe=D.map(_e=>ee==null?void 0:ee.find(it=>it.id===_e)).filter(_e=>!!_e),Ce=(se??[]).filter(_e=>te.has(_e.source)||te.has(_e.target)),Xe=new Set(Ce.map(_e=>_e.id)),Dt=B.map(_e=>se==null?void 0:se.find(it=>it.id===_e)).filter(_e=>!!_e).filter(_e=>!Xe.has(_e.id)).filter(_e=>!($.has(_e.source)&&$.has(_e.target)));if(Pe.length===0&&Ce.length===0&&Dt.length===0)return;A(null);const Xt=Pe.map(_e=>_e.id),Gt=[...Ce.map(_e=>_e.id),...Dt.map(_e=>_e.id)];Xt.length>0&&ya(Xt),Gt.length>0&&gr(Gt);const Mr=Pe;d(_e=>_e.filter(it=>!te.has(it)));const wa=new Set(Dt.map(_e=>_e.id));p(_e=>_e.filter(it=>!wa.has(it)&&!Xe.has(it))),Y(),W({do:async()=>{Xt.length>0&&ya(Xt),Gt.length>0&&gr(Gt);for(const _e of Mr)await Q.deleteNode(_e.id).catch(()=>{});await Promise.allSettled(Dt.map(_e=>Q.deleteConnector(_e.id)))},undo:async()=>{Xt.length>0&&ki(Xt),Gt.length>0&&kr(Gt);for(let _e=Mr.length-1;_e>=0;_e--){const it=Mr[_e];it&&await Q.createNode({id:it.id,type:it.type,position:it.position,data:it.data})}for(const _e of[...Ce,...Dt])await Q.createConnector({..._e,id:_e.id})}});const Xu=new Map;for(const _e of Pe)Xu.set(_e.id,Ce.filter(it=>it.source===_e.id||it.target===_e.id).map(it=>it.id));(async()=>{const _e=[];for(const je of Mr)try{await Q.deleteNode(je.id)}catch(st){Gr(je.id);const rn=Xu.get(je.id)??[];rn.length>0&&kr(rn),_e.push(st instanceof Error?st.message:String(st))}const it=await Promise.all(Dt.map(async je=>{try{return await Q.deleteConnector(je.id),null}catch(st){return Kr(je.id),st instanceof Error?st.message:String(st)}}));for(const je of it)je!==null&&_e.push(je);_e.length>0&&_e[0]!==void 0&&A(_e[0])})()},[ce,Q,ee,se,ya,gr,Gr,ki,Kr,kr,W,Y]);g.useEffect(()=>{M.current=Fe},[Fe]),g.useEffect(()=>{const O=B=>{if(B.key!=="Delete"&&B.key!=="Backspace"||Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]'))return;const Z=w.current,$=v.current;Z.length===0&&$.length===0||(B.preventDefault(),Fe(Z,$))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[Fe]);const{undo:bt,redo:Zr,canUndo:Xr,canRedo:zn}=j;g.useEffect(()=>{const O=async B=>{if((B.metaKey||B.ctrlKey)&&B.key.toLowerCase()==="z"&&!Lr(document.activeElement)){if(B.preventDefault(),B.shiftKey){if(!zn)return;try{const Z=await Zr();Z!=null&&Z.entry&&await Z.entry.do()}catch(Z){A(Z instanceof Error?Z.message:String(Z)),console.error("redo failed",Z)}return}if(Xr)try{const Z=await bt();Z!=null&&Z.entry&&await Z.entry.undo()}catch(Z){A(Z instanceof Error?Z.message:String(Z)),console.error("undo failed",Z)}}};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[bt,Zr,Xr,zn]);const vr=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(te=>te.id===O),D=(Z&&"name"in Z.data?Z.data.name:void 0)??"";be(O,{data:{name:B}}),A(null),Y(),Z&&W({do:async()=>{await Q.updateNode(O,{name:B})},undo:async()=>{await Q.updateNode(O,{name:D})},coalesceKey:`node:${O}:name`}),Q.updateNode(O,{name:B}).catch(te=>{Z&&X(),A(te instanceof Error?te.message:String(te)),console.error("updateNode name failed",te)})},[ce,Q,ee,be,W,X,Y]),Ro=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(D=>D.id===O);if(!Z)return;const $=Z.data.description??"";be(O,{data:{description:B}}),A(null),Y(),W({do:async()=>{await Q.updateNode(O,{description:B})},undo:async()=>{await Q.updateNode(O,{description:$})},coalesceKey:`node:${O}:description`}),Q.updateNode(O,{description:B}).catch(D=>{X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode description failed",D)})},[ce,Q,ee,be,W,X,Y]),rr=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(D=>D.id===O);if(!Z)return;const $=Z.data.detail??"";be(O,{data:{detail:B}}),A(null),Y(),W({do:async()=>{await Q.updateNode(O,{detail:B})},undo:async()=>{await Q.updateNode(O,{detail:$})},coalesceKey:`node:${O}:detail`}),Q.updateNode(O,{detail:B}).catch(D=>{X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode detail failed",D)})},[ce,Q,ee,be,W,X,Y]),Yr=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(D=>D.id===O);if(!Z)return;const $="icon"in Z.data?Z.data.icon??null:null;be(O,{data:{icon:B??void 0}}),A(null),Y(),W({do:async()=>{await Q.updateNode(O,{icon:B})},undo:async()=>{await Q.updateNode(O,{icon:$})},coalesceKey:`node:${O}:icon`}),Q.updateNode(O,{icon:B}).catch(D=>{X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode icon failed",D)})},[ce,Q,ee,be,W,X,Y]),hn=g.useCallback((O,B,Z)=>{if(!ce||!Q)return;A(null);const $=`node-${crypto.randomUUID()}`,D=YQ(O,Z,E0(Ei).node),te={id:$,type:"shapeNode",position:B,data:D};be($,{id:$,type:"shapeNode",position:B,data:D}),Y(),Q.createNode(te).then(({id:Ce})=>{W({do:async()=>{await Q.createNode({...te,id:Ce})},undo:async()=>{await Q.deleteNode(Ce)}})}).catch(Ce=>{De($),A(Ce instanceof Error?Ce.message:String(Ce)),console.error("createNode failed",Ce)})},[ce,Q,be,De,W,Y]),zt=g.useCallback((O,B)=>{if(!ce||!Q)return;A(null);const Z=`node-${crypto.randomUUID()}`,$={icon:O,width:ud.width,height:ud.height},D={id:Z,type:"iconNode",position:B,data:$};be(Z,{id:Z,type:"iconNode",position:B,data:$}),d([Z]),Y(),Q.createNode(D).then(({id:Pe})=>{W({do:async()=>{await Q.createNode({...D,id:Pe})},undo:async()=>{await Q.deleteNode(Pe)}})}).catch(Pe=>{De(Z),A(Pe instanceof Error?Pe.message:String(Pe)),console.error("createNode (icon) failed",Pe)})},[ce,Q,be,De,W,Y]),To=g.useCallback(O=>{if(!ce||!Q)return;A(null);const B=`node-${crypto.randomUUID()}`,Z=`blocks/${B}.html`,$={id:B,type:"htmlNode",position:O.position,data:{}},D={id:B,type:"htmlNode",position:O.position,data:{htmlPath:Z}};be(B,D),d([B]),Y(),Q.createNode($).then(({id:te})=>{W({do:async()=>{await Q.createNode({...$,id:te})},undo:async()=>{await Q.deleteNode(te)}})}).catch(te=>{De(B),A(te instanceof Error?te.message:String(te)),console.error("createNode (htmlNode) failed",te)})},[ce,Q,be,De,W,Y]),xr=g.useRef(new Map),vi=g.useCallback((O,B)=>{xr.current.set(O,B)},[]),xi=g.useCallback(O=>{xr.current.delete(O)},[]),jo=g.useCallback(O=>{!ce||!Q||(A(null),Y(),mqe({...O,flowId:ce,lastUsed:E0(Ei).node},{upload:(B,Z,$)=>Q.uploadImage(Z,$),createNode:async(B,Z)=>{const{id:$}=await Q.createNode(Z);return{id:$}},deleteNode:async(B,Z)=>(await Q.deleteNode(Z),{ok:!0}),setOverride:be,pushUndo:W,rememberRetry:vi,forgetRetry:xi}).catch(B=>{console.error("image-upload-flow failed",B)}))},[ce,Q,be,W,Y,vi,xi]),Lt=g.useCallback(O=>{if(!ce||!Q)return;const B=`node-${crypto.randomUUID()}`;jo({nodeId:B,...O})},[ce,Q,jo]),wi=g.useCallback(O=>{const B=xr.current.get(O);B&&jo({nodeId:O,...B})},[jo]),[Dn,ga]=g.useState({open:!1,mode:"insert"}),or=g.useCallback((O,B)=>{ga({open:!0,mode:O,nodeId:B})},[]),wr=g.useCallback(()=>{ga(O=>({...O,open:!1}))},[]),Wu=g.useCallback(()=>{or("insert")},[or]),Mi=g.useCallback(O=>or("replace",O),[or]),bi=g.useCallback(O=>{if(kMe(O),Dn.mode==="replace"&&Dn.nodeId){if(ce&&Q){const B=Dn.nodeId,Z=ee==null?void 0:ee.find(D=>D.id===B),$=(Z==null?void 0:Z.type)==="iconNode"?Z.data.icon:void 0;if(be(B,{data:{icon:O}}),A(null),Y(),$!==void 0){const D=$;W({do:async()=>{await Q.updateNode(B,{icon:O})},undo:async()=>{await Q.updateNode(B,{icon:D})},coalesceKey:`node:${B}:icon`})}Q.updateNode(B,{icon:O}).catch(D=>{De(B),$!==void 0&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode (icon replace) failed",D)})}}else{const B=G.current;if(B&&ce){const Z=mMe(B,{width:window.innerWidth,height:window.innerHeight});zt(O,Z)}}wr()},[Dn.mode,Dn.nodeId,ce,Q,ee,be,De,W,X,Y,zt,wr]),ka=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=se==null?void 0:se.find(D=>D.id===O),$=Z==null?void 0:Z.label;Oe(O,{label:B}),A(null),Y(),Z&&W({do:async()=>{await Q.updateConnector(O,{label:B})},undo:async()=>{await Q.updateConnector(O,{label:$})},coalesceKey:`connector:${O}:label`}),Q.updateConnector(O,{label:B}).catch(D=>{Z&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateConnector label failed",D)})},[ce,Q,se,Oe,W,X,Y]),Mn=g.useCallback((O,B,Z)=>{if(!ce||!Q)return;const $=`conn-${crypto.randomUUID()}`,D=Z==null?void 0:Z.targetPin,te=E0(Ei).connector,Pe={id:$,source:O,target:B,sourceHandleAutoPicked:!0,targetHandleAutoPicked:!0,...D?{targetPin:D}:{},...te,kind:"default"},Ce={id:$,source:O,target:B,sourceHandleAutoPicked:!0,targetHandleAutoPicked:!0,...D?{targetPin:D}:{},...te,kind:"default"};Oe($,Pe),A(null),Y(),Q.createConnector(Ce).then(({id:Xe})=>{W({do:async()=>{await Q.createConnector({...Ce,id:Xe})},undo:async()=>{await Q.deleteConnector(Xe)}})}).catch(Xe=>{Te($),A(Xe instanceof Error?Xe.message:String(Xe)),console.error("createConnector failed",Xe)})},[ce,Q,Oe,Te,W,Y]),Qr=g.useCallback(({sourceNodeId:O,position:B,shape:Z})=>{if(!ce||!Q)return;A(null);const $=`node-${crypto.randomUUID()}`,D=`conn-${crypto.randomUUID()}`,te=fR[Z],Pe=E0(Ei),Ce=YQ(Z,te,Pe.node),Xe={id:$,type:"shapeNode",position:B,data:Ce},Dt={id:D,source:O,target:$,sourceHandleAutoPicked:!0,targetHandleAutoPicked:!0,...Pe.connector,kind:"default"};be($,{id:$,type:"shapeNode",position:B,data:Ce}),Oe(D,Dt),k($),Y(),(async()=>{try{await Q.createNode(Xe),await Q.createConnector(Dt),W({do:async()=>{await Q.createNode(Xe),await Q.createConnector(Dt)},undo:async()=>{Te(D),De($),await Q.deleteConnector(D).catch(()=>{}),await Q.deleteNode($).catch(()=>{})}})}catch(Gt){De($),Te(D),A(Gt instanceof Error?Gt.message:String(Gt)),console.error("createAndConnectFromPane failed",Gt)}})()},[ce,Q,be,De,Oe,Te,W,Y]),Jr=g.useRef(null),[Gu,No]=g.useState(!1),ar=g.useCallback(O=>{if(!ee)return;const B=new Set(O),Z=ee.filter(D=>B.has(D.id));if(Z.length===0)return;const $=(se??[]).filter(D=>B.has(D.source)&&B.has(D.target));Jr.current=JSON.parse(JSON.stringify({nodes:Z,connectors:$})),No(!0)},[ee,se]),bn=g.useCallback(O=>{if(!ce||!Q)return;const B=Jr.current;if(!B||B.nodes.length===0)return;const{newNodes:Z,newConnectors:$}=hqe({nodes:B.nodes,connectors:B.connectors,flowPos:O,nodeIdGen:()=>`node-${crypto.randomUUID()}`,connectorIdGen:()=>`conn-${crypto.randomUUID()}`});for(const D of Z)be(D.id,D);for(const D of $)Oe(D.id,D);d(Z.map(D=>D.id)),p($.map(D=>D.id)),A(null),Y(),(async()=>{try{for(const D of Z)await Q.createNode({id:D.id,type:D.type,position:D.position,data:D.data});for(const D of $)await Q.createConnector(D);W({do:async()=>{for(const D of Z)await Q.createNode({id:D.id,type:D.type,position:D.position,data:D.data});for(const D of $)await Q.createConnector(D)},undo:async()=>{await Promise.allSettled($.map(D=>Q.deleteConnector(D.id))),await Promise.allSettled(Z.map(D=>Q.deleteNode(D.id)))}})}catch(D){for(const te of Z)De(te.id);for(const te of $)Te(te.id);A(D instanceof Error?D.message:String(D)),console.error("paste failed",D)}})()},[ce,Q,be,De,Oe,Te,Y,W]);g.useEffect(()=>{const O=B=>{const Z=LMe({event:B,isEditableActive:Lr(document.activeElement),hasNodes:!!ee&&ee.length>0,hasConnectors:!!se&&se.length>0,selectedIds:w.current,hasClipboard:!!Jr.current});if(Z.type!=="noop"&&!(Z.type==="copy"||Z.type==="paste")){if(B.preventDefault(),Z.type==="selectAll"){d((ee??[]).map($=>$.id)),p((se??[]).map($=>$.id));return}ar([...Z.ids]),bn(null)}};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[ee,se,ar,bn]),g.useEffect(()=>{const O=B=>{const Z=bMe(B);if(!Z||Lr(document.activeElement))return;const $=w.current;if($.length===0)return;const D=S.overrides,te=(ee??[]).map(Ce=>{var Dt;const Xe=((Dt=D[Ce.id])==null?void 0:Dt.position)??Ce.position;return{id:Ce.id,position:Xe}}),Pe=SMe(Z,$,te);if(Pe.length!==0)if(B.preventDefault(),Pe.length===1){const Ce=Pe[0];Ce&&he(Ce.id,Ce.position)}else Ee(Pe)};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[ee,S.overrides,he,Ee]),g.useEffect(()=>{const O=B=>{const Z=CMe(B);if(!Z||Lr(document.activeElement))return;B.preventDefault();const $=G.current;$&&(Z==="fit"?$.fitView({padding:.2,duration:200}):Z==="in"?$.zoomIn({duration:150}):$.zoomOut({duration:150}))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]);const fn=g.useCallback(O=>{if(!ce||!Q||!ee)return;const B=S.overrides,Z=G.current,$=O==="selection"?new Set(w.current):null,D=$?ee.filter(je=>$.has(je.id)):ee;if(D.length<2)return;const te=new Set(D.map(je=>je.id)),Pe=(se??[]).filter(je=>te.has(je.source)&&te.has(je.target)),Ce=D.map(je=>{var Vf;const st=((Vf=B[je.id])==null?void 0:Vf.position)??je.position,rn=Z==null?void 0:Z.getInternalNode(je.id),Yt=rn==null?void 0:rn.measured,Ci=je.data,oo=(Yt==null?void 0:Yt.width)??Ci.width??200,tj=(Yt==null?void 0:Yt.height)??Ci.height??120;return{id:je.id,width:oo,height:tj,position:st}}),Xe=Pe.map(je=>({source:je.source,target:je.target})),Dt=rae(Ce,Xe);let Xt=Number.POSITIVE_INFINITY,Gt=Number.POSITIVE_INFINITY,Mr=Number.POSITIVE_INFINITY,wa=Number.POSITIVE_INFINITY;for(const je of Ce){je.position.x<Xt&&(Xt=je.position.x),je.position.y<Gt&&(Gt=je.position.y);const st=Dt.get(je.id);st&&(st.x<Mr&&(Mr=st.x),st.y<wa&&(wa=st.y))}const Xu=Number.isFinite(Xt)&&Number.isFinite(Mr)?Xt-Mr:0,_e=Number.isFinite(Gt)&&Number.isFinite(wa)?Gt-wa:0,it=[];for(const je of Ce){const st=Dt.get(je.id);if(!st)continue;const rn={x:st.x+Xu,y:st.y+_e},Yt=rn.x-je.position.x,Ci=rn.y-je.position.y;Math.abs(Yt)<1&&Math.abs(Ci)<1||it.push({id:je.id,prev:je.position,next:rn})}if(it.length!==0){A(null);for(const je of it)be(je.id,{position:je.next});Y(),W({do:async()=>{await Promise.allSettled(it.map(je=>Q.updateNodePosition(je.id,je.next)))},undo:async()=>{await Promise.allSettled(it.map(je=>Q.updateNodePosition(je.id,je.prev)))}}),Promise.all(it.map(async je=>{try{return await Q.updateNodePosition(je.id,je.next),null}catch(st){return De(je.id),st instanceof Error?st.message:String(st)}})).then(je=>{const st=je.filter(Yt=>Yt!==null),rn=st[0];rn&&(A(st.length===1?rn:`${st.length} node updates failed (first: ${rn})`),console.error("Tidy: some updateNodePosition calls failed",st))})}},[ce,Q,ee,se,S.overrides,be,De,W,Y]);g.useEffect(()=>{const O=B=>{if(!(B.metaKey||B.ctrlKey)||!B.shiftKey||B.altKey||B.key.toLowerCase()!=="l"||Lr(document.activeElement))return;B.preventDefault();const Z=w.current.length>0?"selection":"all";fn(Z)};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[fn]);const va=g.useCallback(()=>{const O=w.current.length>0?"selection":"all";fn(O)},[fn]);g.useEffect(()=>{const O=B=>{if(Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]'))return;const Z=IMe(B);if(Z===null)return;const $=Z==="select"?null:Z;if(H.current===$){R(null);return}R($)};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]),g.useEffect(()=>{const O=B=>{B.key==="Escape"&&(Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]')||(w.current.length>0&&d([]),v.current.length>0&&p([]),H.current!==null&&R(null)))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]),g.useEffect(()=>{const O=B=>{if(B.key.toLowerCase()!=="f"||B.metaKey||B.ctrlKey||B.shiftKey||B.altKey||Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]'))return;const Z=w.current;if(Z.length===0)return;const $=G.current;$&&$.fitView({nodes:Z.map(D=>({id:D})),padding:.2,duration:200})};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]),g.useEffect(()=>{const O=B=>{if(B.key!=="1"||B.metaKey||B.ctrlKey||B.shiftKey||B.altKey||Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]'))return;const Z=G.current;if(!Z)return;const{x:$,y:D}=Z.getViewport();Z.setViewport({x:$,y:D,zoom:1},{duration:150})};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]);const ir=g.useCallback(O=>{var B,Z,$;switch(O){case"tool.select":R(null);return;case"tool.rectangle":R("rectangle");return;case"tool.ellipse":R("ellipse");return;case"tool.text":R("text");return;case"tool.sticky":R("sticky");return;case"tool.database":R("database");return;case"edit.undo":{if(!Xr)return;(async()=>{try{const D=await bt();D!=null&&D.entry&&await D.entry.undo()}catch(D){A(D instanceof Error?D.message:String(D)),console.error("undo failed",D)}})();return}case"edit.redo":{if(!zn)return;(async()=>{try{const D=await Zr();D!=null&&D.entry&&await D.entry.do()}catch(D){A(D instanceof Error?D.message:String(D)),console.error("redo failed",D)}})();return}case"edit.copy":{const D=w.current;if(D.length===0)return;ar([...D]);return}case"edit.paste":bn(null);return;case"edit.duplicate":{const D=w.current;if(D.length===0)return;ar([...D]),bn(null);return}case"edit.delete":{const D=w.current,te=v.current;if(D.length===0&&te.length===0)return;Fe([...D],[...te]);return}case"edit.selectAll":d((ee??[]).map(D=>D.id)),p((se??[]).map(D=>D.id));return;case"view.fit":{const D=G.current;if(!D)return;D.fitView({padding:.2,duration:200});return}case"view.zoomIn":{const D=G.current;if(!D)return;D.zoomIn({duration:150});return}case"view.zoomOut":{const D=G.current;if(!D)return;D.zoomOut({duration:150});return}case"view.zoom100":{const D=G.current;if(!D)return;const{x:te,y:Pe}=D.getViewport();D.setViewport({x:te,y:Pe,zoom:1},{duration:150});return}case"view.zoomToSelection":{const D=w.current;if(D.length===0)return;const te=G.current;if(!te)return;te.fitView({nodes:D.map(Pe=>({id:Pe})),padding:.2,duration:200});return}case"layout.tidy":{const D=w.current.length>0?"selection":"all";fn(D);return}case"selection.deselect":w.current.length>0&&d([]),v.current.length>0&&p([]),H.current!==null&&R(null);return;case"help.commandPalette":V(!0);return;case"export.pdf":{(B=b.current)==null||B.exportPdf();return}case"export.png":{(Z=b.current)==null||Z.exportPng();return}case"session.reset":{($=x.current)==null||$.call(x);return}}},[Xr,zn,bt,Zr,ar,bn,Fe,ee,se,fn]);g.useEffect(()=>{const O=B=>{(B.metaKey||B.ctrlKey)&&(B.shiftKey||B.altKey||B.key.toLowerCase()==="p"&&(B.preventDefault(),!Lr(document.activeElement)&&ir("help.commandPalette")))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[ir]),g.useEffect(()=>{x.current=c??null},[c]);const eo=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=se==null?void 0:se.find(te=>te.id===O),$=Z?{source:Z.source,target:Z.target,sourceHandle:Z.sourceHandle,targetHandle:Z.targetHandle,sourceHandleAutoPicked:Z.sourceHandleAutoPicked,targetHandleAutoPicked:Z.targetHandleAutoPicked,sourcePin:Z.sourcePin??null,targetPin:Z.targetPin??null}:null,D={...B.source!==void 0?{source:B.source}:{},...B.target!==void 0?{target:B.target}:{},...B.sourceHandle!==void 0?{sourceHandle:B.sourceHandle===null?void 0:B.sourceHandle}:{},...B.targetHandle!==void 0?{targetHandle:B.targetHandle===null?void 0:B.targetHandle}:{},...B.sourceHandleAutoPicked!==void 0?{sourceHandleAutoPicked:B.sourceHandleAutoPicked}:{},...B.targetHandleAutoPicked!==void 0?{targetHandleAutoPicked:B.targetHandleAutoPicked}:{},...B.sourcePin!==void 0?{sourcePin:B.sourcePin===null?void 0:B.sourcePin}:{},...B.targetPin!==void 0?{targetPin:B.targetPin===null?void 0:B.targetPin}:{}};if(Oe(O,D),A(null),Y(),$){const te=$;W({do:async()=>{await Q.updateConnector(O,B)},undo:async()=>{await Q.updateConnector(O,te)},coalesceKey:`connector:${O}:reconnect`})}Q.updateConnector(O,B).catch(te=>{Te(O),$&&X(),A(te instanceof Error?te.message:String(te)),console.error("updateConnector reconnect failed",te)})},[ce,Q,se,Oe,Te,W,X,Y]),to=g.useCallback((O,B,Z)=>{if(!ce||!Q)return;const $=se==null?void 0:se.find(Pe=>Pe.id===O),D=$?B==="source"?$.sourcePin:$.targetPin:void 0,te=B==="source"?"sourcePin":"targetPin";if(Oe(O,{[te]:Z}),A(null),Y(),$){const Pe={[te]:D??null};W({do:async()=>{await Q.updateConnector(O,{[te]:Z})},undo:async()=>{await Q.updateConnector(O,Pe)},coalesceKey:`connector:${O}:${te}`})}Q.updateConnector(O,{[te]:Z}).catch(Pe=>{Te(O),$&&X(),A(Pe instanceof Error?Pe.message:String(Pe)),console.error("updateConnector pin failed",Pe)})},[ce,Q,se,Oe,Te,W,X,Y]),zo=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=se==null?void 0:se.find(te=>te.id===O),$=Z?B==="source"?Z.sourcePin:Z.targetPin:void 0;if(!$)return;const D=B==="source"?"sourcePin":"targetPin";Oe(O,{[D]:void 0}),A(null),Y(),W({do:async()=>{await Q.updateConnector(O,{[D]:null})},undo:async()=>{await Q.updateConnector(O,{[D]:$})}}),Q.updateConnector(O,{[D]:null}).catch(te=>{Te(O),X(),A(te instanceof Error?te.message:String(te)),console.error("updateConnector unpin failed",te)})},[ce,Q,se,Oe,Te,W,X,Y]),rt=n==null?void 0:n.flow,no=S.overrides,qn=C.overrides,nn=L.ids,ro=_.ids,Ku=g.useMemo(()=>{if(!rt||u.length===0)return[];const O=new Map(rt.nodes.map(Z=>[Z.id,Z])),B=[];for(const Z of u){const $=O.get(Z);if(!$)continue;const D=no[Z];if(!D){B.push($);continue}const te=D.data?{...$.data,...D.data}:$.data;B.push({...$,...D,data:te})}return B},[rt,u,no]),ej=g.useMemo(()=>{if(!rt||f.length===0)return[];const O=new Map(rt.connectors.map(Z=>[Z.id,Z])),B=[];for(const Z of f){const $=O.get(Z);if(!$)continue;const D=qn[Z];B.push(D?{...$,...D}:$)}return B},[rt,f,qn]),Bf=g.useMemo(()=>{if(!rt)return null;if(!T)return rt.nodes;const O=new Map(rt.nodes.map($=>[$.id,$])),B=[],Z=new Set;for(const $ of T){const D=O.get($);D&&(B.push(D),Z.add($))}for(const $ of rt.nodes)Z.has($.id)||B.push($);return B},[rt,T]),Do=g.useMemo(()=>{const O=Bf??(rt==null?void 0:rt.nodes)??null;return O?nn.size===0?O:O.filter(B=>!nn.has(B.id)):null},[Bf,rt,nn]),Zu=g.useMemo(()=>{const O=(rt==null?void 0:rt.connectors)??null;return O?ro.size===0&&nn.size===0?O:O.filter(B=>!ro.has(B.id)&&!nn.has(B.source)&&!nn.has(B.target)):null},[rt,ro,nn]);if(!l)return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[m.jsxs("p",{className:"text-sm font-medium",children:["Unknown demo: ",e]}),m.jsx("p",{className:"text-xs text-muted-foreground",children:"The slug may have been removed. Re-register from the project repo to bring it back."})]});if(r&&!n)return m.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-muted-foreground",children:"Loading demo…"});const Bd=u[0],xa=Bd?i[Bd]:void 0;return m.jsxs("div",{className:"relative h-full w-full",children:[n&&!n.valid?m.jsxs("div",{"data-testid":"demo-error-banner",className:"absolute inset-x-0 top-0 z-10 border-b border-rose-500/40 bg-rose-50 px-4 py-2 text-xs text-rose-900 shadow-xs dark:bg-rose-950/40 dark:text-rose-100",children:[m.jsx("span",{className:"font-medium uppercase tracking-wide",children:"Invalid demo: "}),m.jsx("span",{className:"font-mono",children:n.error})]}):null,rt&&Q?m.jsx(rDe,{ref:b,mode:"edit",adapter:Q,projectId:ce??void 0,enableEmbed:!1,onExportToCloud:ce?()=>ge(!0):void 0,onRestartDemo:c,nodes:Do??rt.nodes,connectors:Zu??rt.connectors,selectedNodeIds:u,selectedConnectorIds:f,onSelectionChange:xe,runtime:{runs:o,statuses:i,pendingOverrides:{nodes:no,connectors:qn}},onPlayNode:s,onNodePositionChange:he,onNodePositionsChange:Ee,onNodeResize:Be,onHtmlNodeFitToContent:Ge,onMultiResize:Pt,onNodeNameChange:vr,onNodeDescriptionChange:Ro,onConnectorLabelChange:ka,onCreateShapeNode:hn,onCreateImageFromFile:ce?Lt:void 0,onRetryImageUpload:ce?wi:void 0,onCreateHtmlNode:ce?To:void 0,iconPickerOpen:Dn.open,onOpenIconPicker:ce?Wu:void 0,onCloseIconPicker:ce?wr:void 0,onPickIcon:ce?bi:void 0,onRequestIconReplace:ce?Mi:void 0,onCreateConnector:Mn,onReconnectConnector:eo,onPinEndpoint:ce?to:void 0,onUnpinEndpoint:ce?zo:void 0,onReorderNode:Uu,onDeleteNode:$u,onCopyNode:O=>ar([O]),onPasteAt:bn,onCopySelection:ce?ar:void 0,onPasteSelection:ce?()=>bn(null):void 0,onToggleNodeLock:ce?Bu:void 0,hasClipboard:Gu,selectedNodes:Ku,selectedConnectors:ej,onStyleNode:Nn,onStyleNodePreview:_t,onStyleNodes:tn,onStyleNodesPreview:nr,onStyleConnector:Vu,onStyleConnectorPreview:Nt,onRfInit:q,onTidy:ee?va:void 0,onCreateAndConnectFromPane:Qr,pendingEditNodeId:y,activeShape:U,onSelectShape:R,statusReport:xa,onNameChange:vr,onDescriptionChange:Ro,onDetailChange:rr,onIconChange:Yr,autoFitView:!0,autoFitViewSignal:z}):m.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-muted-foreground",children:"No demo data yet."}),P?m.jsxs("div",{"data-testid":"edit-error-banner",className:"absolute inset-x-0 bottom-4 z-20 mx-auto w-fit max-w-[80%] rounded-md border border-rose-500/50 bg-rose-50 px-3 py-2 text-xs text-rose-900 shadow-md dark:bg-rose-950/60 dark:text-rose-100",children:[m.jsx("span",{className:"font-medium",children:"Couldn't save change: "}),m.jsx("span",{className:"font-mono",children:P}),m.jsx("button",{type:"button",className:"ml-3 underline underline-offset-2",onClick:()=>A(null),children:"Dismiss"})]}):null,m.jsx(IDe,{open:F,onOpenChange:V,runCommand:ir,ctx:{hasSelection:u.length>0||f.length>0,canUndo:Xr,canRedo:zn,hasClipboard:Gu,canExportDemo:!!ce,canResetSession:!!c}}),ce?m.jsx(WDe,{open:ue,onOpenChange:ge,projectId:ce,onCapturePreview:()=>{var O;return((O=b.current)==null?void 0:O.capturePreview())??Promise.resolve(void 0)}}):null]})}const Ste="npx seeflow register --path .";function xqe(){const[e,t]=g.useState(!1),n=async()=>{try{await navigator.clipboard.writeText(Ste),t(!0),setTimeout(()=>t(!1),1200)}catch(r){console.error("[empty-state] copy failed",r)}};return m.jsx("div",{"data-testid":"seeflow-empty-state",className:"flex h-full w-full items-center justify-center bg-background p-6",children:m.jsxs("div",{className:"flex max-w-lg flex-col items-center gap-6 text-center",children:[m.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-muted",children:m.jsx(s2,{className:"h-6 w-6 text-muted-foreground"})}),m.jsxs("div",{className:"space-y-2",children:[m.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:"No demos registered yet"}),m.jsxs("p",{className:"text-sm text-muted-foreground",children:["Point SeeFlow at any folder containing a"," ",m.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:".seeflow/seeflow.json"})," ","file and it'll appear here."]})]}),m.jsxs("div",{className:"flex w-full items-center gap-2 rounded-md border border-border bg-card px-3 py-2 font-mono text-sm",children:[m.jsx("span",{className:"text-muted-foreground select-none",children:"$"}),m.jsx("code",{className:"flex-1 truncate text-left",children:Ste}),m.jsx(Ft,{type:"button",variant:"ghost",size:"sm",onClick:n,"aria-label":"Copy register command",children:e?m.jsx(Mo,{className:"h-4 w-4"}):m.jsx(j1,{className:"h-4 w-4"})})]})]})})}function wqe({demos:e}){return e.length===0?m.jsx(xqe,{}):m.jsx("div",{className:"flex h-full w-full items-start justify-center overflow-y-auto bg-background p-8",children:m.jsxs("div",{"data-testid":"studio-home-picker",className:"flex w-full max-w-2xl flex-col gap-6 pt-8",children:[m.jsxs("div",{className:"space-y-1",children:[m.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Open a demo"}),m.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.length," demos registered — pick one to load its canvas."]})]}),m.jsx("ul",{className:"flex flex-col gap-2",children:e.map(t=>m.jsx("li",{children:m.jsxs("button",{type:"button",onClick:()=>gd(`/d/${t.slug}`),"data-testid":`studio-home-demo-${t.slug}`,className:"flex w-full flex-col items-start gap-0.5 rounded-lg border border-border bg-card px-4 py-3 text-left transition-colors hover:border-input",style:{boxShadow:"var(--shadow-card)"},children:[m.jsx("span",{className:"text-sm font-medium",children:t.name}),m.jsx("span",{className:"truncate text-xs text-muted-foreground",children:t.repoPath})]})},t.id))})]})})}const Mqe=e=>{if(!e.startsWith("/d/"))return null;const t=e.slice(3);return t.length>0?decodeURIComponent(t):null};function bqe(){const e=iDe(),{demos:t,refresh:n}=uDe(),r=Mqe(e),o=r?(t??[]).find(C=>C.slug===r):void 0,a=(o==null?void 0:o.id)??null,{detail:i,loading:s,refresh:c}=lDe(a),{runs:l,apply:u}=mDe(a),{events:d,apply:f}=pDe(a),{statusByNode:p,apply:y,reset:k}=xDe(a),w=g.useCallback(()=>{k(),c(),n()},[c,n,k]),v=g.useCallback(C=>{u(C),f(C),y(C)},[u,f,y]);wDe(a,{onReload:w,onEvent:v});const M=g.useCallback(async()=>{if(a)try{await _fe(a)}catch(C){console.error("Failed to restart demo:",C)}},[a]),x=g.useCallback(C=>{ute(C.id),n()},[n]),b=g.useCallback(async C=>{await n(),a===C&&gd("/")},[n,a]);g.useEffect(()=>{if(e!=="/"||t===null)return;const C=bDe(t,MDe());C&&gd(`/d/${C.slug}`)},[e,t]),g.useEffect(()=>{o&&ute(o.id)},[o]);const S=g.useCallback(C=>{a&&Rfe(a,C).catch(L=>{u({type:"node:error",nodeId:C,message:L instanceof Error?L.message:String(L),ts:Date.now()})})},[a,u]);return t===null?m.jsx("div",{className:"flex h-full w-full items-center justify-center bg-background text-sm text-muted-foreground",children:"Loading…"}):m.jsx(p2,{delayDuration:150,children:m.jsxs("div",{className:"flex h-full w-full flex-col bg-background text-foreground",children:[m.jsx(cDe,{demos:t,currentSlug:r??void 0,onProjectCreated:x,onProjectUnregistered:b}),m.jsx("main",{className:"min-h-0 flex-1",children:r?m.jsx(vqe,{slug:r,demos:t,detail:i,loading:s,runs:l,nodeEvents:d,statusByNode:p,onPlayNode:S,onRestartDemo:a?M:void 0}):m.jsx(wqe,{demos:t})})]})})}const Sde=document.getElementById("root");if(!Sde)throw new Error("Root element #root not found");CF.createRoot(Sde).render(m.jsx(fo.StrictMode,{children:m.jsx(bqe,{})}));export{DNe as _,$a as c,kd as g,Lqe as z};
|
|
7838
|
+
`)}async function Ize(e,t){const n=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await Lze(e,t);if(n){const r=document.createElement("style"),o=document.createTextNode(n);r.appendChild(o),e.firstChild?e.insertBefore(r,e.firstChild):e.appendChild(r)}}async function Eze(e,t={}){const{width:n,height:r}=ede(e,t),o=await QT(e,t,!0);return await Ize(o,t),await ide(o,t),wze(o,t),await UNe(o,n,r)}async function Aze(e,t={}){const{width:n,height:r}=ede(e,t),o=await Eze(e,t),a=await bR(o),i=document.createElement("canvas"),s=i.getContext("2d"),c=t.pixelRatio||BNe(),l=t.canvasWidth||n,u=t.canvasHeight||r;return i.width=l*c,i.height=u*c,t.skipAutoScale||VNe(i),i.style.width=`${l}`,i.style.height=`${u}`,t.backgroundColor&&(s.fillStyle=t.backgroundColor,s.fillRect(0,0,i.width,i.height)),s.drawImage(a,0,0,i.width,i.height),i}async function Pze(e,t={}){return(await Aze(e,t)).toDataURL()}const _ze=e=>e instanceof Element?!(e.classList.contains("react-flow__minimap")||e.classList.contains("react-flow__controls")||e.classList.contains("react-flow__panel")):!0,Rze=async e=>{const t=await Pze(e,{cacheBust:!0,filter:_ze}),n=await new Promise((r,o)=>{const a=new Image;a.onload=()=>r({width:a.naturalWidth,height:a.naturalHeight}),a.onerror=()=>o(new Error("Failed to decode captured image")),a.src=t});return{dataUrl:t,...n}},Tze=(e,t)=>{const n=document.createElement("a");n.href=e,n.download=t,n.rel="noopener",document.body.appendChild(n),n.click(),n.remove()},jze=e=>{const t=e.replace(/[^A-Za-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"");return t.length>0?t.slice(0,80):"canvas"},tte=(e,t)=>`${jze(e??"canvas")}.${t}`,Nze=({projectId:e,getReactFlow:t})=>{const[n,r]=g.useState(null),o=g.useCallback(()=>r(null),[]),a=g.useCallback(async()=>{const l=t();if(!l)return null;const u=document.querySelector(".react-flow__viewport");if(!u)return null;const d=l.getViewport();try{return await l.fitView({duration:0,padding:.1}),await new Promise(f=>requestAnimationFrame(()=>f())),await Rze(u)}finally{l.setViewport(d,{duration:0})}},[t]),i=g.useCallback(async()=>{r(null);try{const l=await a();if(!l)return;Tze(l.dataUrl,tte(e,"png"))}catch(l){r(l instanceof Error?l.message:String(l))}},[a,e]),s=g.useCallback(async()=>{r(null);try{const l=await a();if(!l)return;const{jsPDF:u}=await DNe(async()=>{const{jsPDF:p}=await import("./jspdf.es.min-DwwAghh7.js").then(y=>y.j);return{jsPDF:p}},[]),d=l.width>l.height?"landscape":"portrait",f=new u({orientation:d,unit:"px",format:[l.width,l.height],hotfixes:["px_scaling"]});f.addImage(l.dataUrl,"PNG",0,0,l.width,l.height),f.save(tte(e,"pdf"))}catch(l){r(l instanceof Error?l.message:String(l))}},[a,e]),c=g.useCallback(async()=>{const l=await a();return l==null?void 0:l.dataUrl},[a]);return{exportPdf:s,exportPng:i,capturePreview:c,lastError:n,clearError:o}},zze={showToolbar:!0,showStyleStrip:!0,showDetailPanel:!0,showStatusBadges:!0,showResizeHandles:!0,showControls:!0,showShareMenu:!0,showRestart:!0,enableKeyboard:!0,enableContextMenu:!0,enableDragDrop:!0,enableImageDrop:!0,enableZoom:!0,enablePan:!0,enableSelection:!0,enableNodeMove:!0,enableEmbed:!1},Dze={showToolbar:!1,showStyleStrip:!1,showDetailPanel:!1,showStatusBadges:!0,showResizeHandles:!1,showControls:!0,showShareMenu:!0,showRestart:!1,enableKeyboard:!1,enableContextMenu:!1,enableDragDrop:!1,enableImageDrop:!1,enableZoom:!0,enablePan:!0,enableSelection:!0,enableNodeMove:!0,enableEmbed:!1},qze={showToolbar:!1,showStyleStrip:!1,showDetailPanel:!1,showStatusBadges:!1,showResizeHandles:!1,showControls:!1,showShareMenu:!1,showRestart:!1,enableKeyboard:!1,enableContextMenu:!1,enableDragDrop:!1,enableImageDrop:!1,enableZoom:!1,enablePan:!1,enableSelection:!1,enableNodeMove:!1,enableEmbed:!1};function Oze(e){const t=e.mode==="edit"?zze:e.mode==="mini"?qze:Dze;return{showToolbar:e.showToolbar??t.showToolbar,showStyleStrip:e.showStyleStrip??t.showStyleStrip,showDetailPanel:e.showDetailPanel??t.showDetailPanel,showStatusBadges:e.showStatusBadges??t.showStatusBadges,showResizeHandles:e.showResizeHandles??t.showResizeHandles,showControls:e.showControls??t.showControls,showShareMenu:e.showShareMenu??t.showShareMenu,showRestart:e.showRestart??t.showRestart,enableKeyboard:e.enableKeyboard??t.enableKeyboard,enableContextMenu:e.enableContextMenu??t.enableContextMenu,enableDragDrop:e.enableDragDrop??t.enableDragDrop,enableImageDrop:e.enableImageDrop??t.enableImageDrop,enableZoom:e.enableZoom??t.enableZoom,enablePan:e.enablePan??t.enablePan,enableSelection:e.enableSelection??t.enableSelection,enableNodeMove:e.enableNodeMove??t.enableNodeMove,enableEmbed:e.enableEmbed??t.enableEmbed}}const nte=40,lh={padding:.15,duration:300,includeHiddenNodes:!1};function Fze(e){return e===void 0||e===!1?{onMount:!1,onExternalNodeChange:!1}:e===!0?{onMount:!0,onExternalNodeChange:!0}:{onMount:e.onMount??!0,onExternalNodeChange:e.onExternalNodeChange??!0}}const rte=e=>{if("clientX"in e)return{clientX:e.clientX,clientY:e.clientY};const t=e.changedTouches[0]??e.touches[0];return t?{clientX:t.clientX,clientY:t.clientY}:null},Hze=(e,t)=>{var r;const n=document.elementsFromPoint(e,t);for(const o of n){const a=(r=o.closest)==null?void 0:r.call(o,".react-flow__node");if(a)return a}return null},cde=15,MF=(e,t,n)=>{const r=Hze(t,n);if(r)return r;if(!e)return null;let o=null,a=cde;const i=e.querySelectorAll(".react-flow__node");for(const s of i){const c=s.getBoundingClientRect();if(c.width===0||c.height===0)continue;const l=Math.max(c.left-t,0,t-c.right),u=Math.max(c.top-n,0,n-c.bottom),d=Math.hypot(l,u);d<=a&&(o=s,a=d)}return o};function ote(e,t,n,r,o){if(e==="source"?(r==null?void 0:r.targetPin)!==void 0||(r==null?void 0:r.targetHandleAutoPicked)===!1:(r==null?void 0:r.sourcePin)!==void 0||(r==null?void 0:r.sourceHandleAutoPicked)===!1)return;const i=e==="source"?n:t,s=e==="source"?t:n,c=o(i),l=o(s);if(!c||!l)return;const u=c.measured.width??c.width??0,d=c.measured.height??c.height??0,f=l.measured.width??l.width??0,p=l.measured.height??l.height??0;if(u===0||d===0||f===0||p===0)return;const y={x:c.internals.positionAbsolute.x,y:c.internals.positionAbsolute.y,w:u,h:d},k={x:l.internals.positionAbsolute.x+f/2,y:l.internals.positionAbsolute.y+p/2};return oMe(y,iR(y,k))}function Bze(e,t,n,r){if(r===null)return"no-op";const o=e==="source"?t:n;return r===(e==="source"?n:t)?"self-loop":r===o?"pin-own":"reconnect-and-pin"}const Vze=(e,t)=>{if(!t)return e;const n=t.data?{...e.data,...t.data}:e.data;return{...e,...t,data:n}},$ze=(e,t)=>t?{...e,...t}:e,Uze={playNode:mCe,stateNode:qCe,shapeNode:PCe,imageNode:abe,iconNode:yMe,htmlNode:ebe},Wze={editableEdge:HCe},Gze={zIndex:0},Kze=8,ate=(e,t)=>e?typeof e=="string"?`url('#${e}')`:`url('#${`${t?`${t}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`}')`:void 0,Zze=e=>function({fromX:n,fromY:r,toX:o,toY:a,fromPosition:i,toPosition:s,connectionLineStyle:c}){const l=He(G=>e.current?G.edges.find(q=>q.reconnectable===!0)??null:null),u=l==null?void 0:l.data,d=He(G=>{var j;const q=G.connection;return((j=q==null?void 0:q.fromHandle)==null?void 0:j.nodeId)??null}),f=He(G=>l!=null&&l.source?G.nodeLookup.get(l.source)??null:null),p=He(G=>l!=null&&l.target?G.nodeLookup.get(l.target)??null:null),y=He(G=>d?G.nodeLookup.get(d)??null:null),k=(l==null?void 0:l.source)===d,w=l?k?f:p:y,v=k?p:f,M=k?u==null?void 0:u.sourcePin:u==null?void 0:u.targetPin,x=k?u==null?void 0:u.sourceHandleAutoPicked:u==null?void 0:u.targetHandleAutoPicked;let b=n,S=r,C=i;if(w){const G=w.measured.width??w.width??0,q=w.measured.height??w.height??0;if(G>0&&q>0){const j={x:w.internals.positionAbsolute.x,y:w.internals.positionAbsolute.y,w:G,h:q};let W=null;if(M)W=sR(j,M);else if(x!==!1&&v){const X=v.measured.width??v.width??0,Y=v.measured.height??v.height??0;if(X>0&&Y>0){const oe={x:v.internals.positionAbsolute.x+X/2,y:v.internals.positionAbsolute.y+Y/2};W=iR(j,oe)}}W&&(b=W.x,S=W.y,C=ite[W.side])}}const L=He(G=>G.transform[2]),_=He(G=>G.nodeLookup),T=He(G=>{var q;return((q=G.connection.toHandle)==null?void 0:q.nodeId)??null});let E=o,P=a,A=s;if(L>0){const G=cde/L,q=l?k?l.target:l.source:null;let j=null;if(T&&T!==q){const W=_.get(T)??null;W&&(j=W)}if(!j){let W=G;for(const X of _.values()){if(q&&X.id===q||w&&X.id===w.id)continue;const Y=X.measured.width??X.width??0,oe=X.measured.height??X.height??0;if(Y===0||oe===0)continue;const re=X.internals.positionAbsolute.x,ie=X.internals.positionAbsolute.y,we=Math.max(re-o,0,o-(re+Y)),ke=Math.max(ie-a,0,a-(ie+oe)),ve=Math.hypot(we,ke);ve<=W&&(W=ve,j=X)}}if(!j&&l&&w){const W=w.measured.width??w.width??0,X=w.measured.height??w.height??0;if(W>0&&X>0){const Y=w.internals.positionAbsolute.x,oe=w.internals.positionAbsolute.y,re=Math.max(Y-o,0,o-(Y+W)),ie=Math.max(oe-a,0,a-(oe+X));Math.hypot(re,ie)<=G&&(j=w)}}if(j){const W=j.measured.width??j.width??0,X=j.measured.height??j.height??0;if(W>0&&X>0){const Y=OH({x:j.internals.positionAbsolute.x,y:j.internals.positionAbsolute.y,w:W,h:X},{x:o,y:a}),oe=sR({x:j.internals.positionAbsolute.x,y:j.internals.positionAbsolute.y,w:W,h:X},Y);E=oe.x,P=oe.y,A=ite[oe.side]}}}const U=(u==null?void 0:u.path)==="step",[R]=U?$2({sourceX:b,sourceY:S,sourcePosition:C,targetX:E,targetY:P,targetPosition:A,borderRadius:Kze}):fT({sourceX:b,sourceY:S,sourcePosition:C,targetX:E,targetY:P,targetPosition:A}),H=(l==null?void 0:l.style)??c??void 0,F=He(G=>G.rfId),V=k?l==null?void 0:l.markerStart:l==null?void 0:l.markerEnd,z=k?l==null?void 0:l.markerEnd:l==null?void 0:l.markerStart,N=ate(V,F),I=ate(z,F);return m.jsx("path",{d:R,fill:"none",className:"react-flow__connection-path",style:H,markerStart:N,markerEnd:I})},ite={top:me.Top,right:me.Right,bottom:me.Bottom,left:me.Left};function Xze({storeApiRef:e}){const t=gt();return g.useEffect(()=>(e.current=t,()=>{e.current===t&&(e.current=null)}),[t,e]),null}function Yze({wrapperRef:e}){const t=He(r=>r.transform[2]),n=e.current;return n&&n.style.setProperty("--rf-zoom",String(t)),null}const Qze=new Set(["INPUT","TEXTAREA","SELECT"]),lde=e=>e?Qze.has(e.tagName)?!0:e instanceof HTMLElement&&e.isContentEditable:!1;function Jze(e){const{event:t,selectedNodeIds:n,hasClipboard:r,activeElement:o,onCopySelection:a,onPasteSelection:i}=e;if(!(t.metaKey||t.ctrlKey)||t.shiftKey||t.altKey)return!1;const s=t.key.toLowerCase();return s!=="c"&&s!=="v"||lde(o)?!1:s==="c"?n.length===0||!a?!1:(t.preventDefault(),a([...n]),!0):!r||!i?!1:(t.preventDefault(),i(),!0)}const ste=(e,t)=>{var n;return((n=e==null?void 0:e[t])==null?void 0:n.status)??"idle"},eDe=(e,t)=>{var n;return(n=e==null?void 0:e[t])==null?void 0:n.status},tDe=(e,t)=>{var n,r;return((n=e==null?void 0:e[t])==null?void 0:n.status)==="error"?(r=e[t])==null?void 0:r.error:void 0};function nDe(e,t){var vU,xU;const{mode:n,adapter:r,projectId:o,fileBaseUrl:a,nodes:i,connectors:s,selectedNodeIds:c,selectedConnectorIds:l,onSelectionChange:u,runtime:d,onPlayNode:f,onNodePositionChange:p,onNodePositionsChange:y,onNodeResize:k,onHtmlNodeFitToContent:w,onMultiResize:v,onNodeNameChange:M,onNodeDescriptionChange:x,onConnectorLabelChange:b,onCreateShapeNode:S,onCreateImageFromFile:C,onRetryImageUpload:L,onCreateHtmlNode:_,onCreateConnector:T,onReconnectConnector:E,onReorderNode:P,onDeleteNode:A,onCopyNode:U,onPasteAt:R,hasClipboard:H,onCopySelection:F,onPasteSelection:V,selectedNodes:z,selectedConnectors:N,onStyleNode:I,onStyleNodePreview:G,onStyleNodes:q,onStyleNodesPreview:j,onStyleConnector:W,onStyleConnectorPreview:X,onRfInit:Y,onTidy:oe,onNodeClick:re,onConnectorClick:ie,onPaneClick:we,onCreateAndConnectFromPane:ke,pendingEditNodeId:ve,iconPickerOpen:xe,onOpenIconPicker:ee,onCloseIconPicker:se,onPickIcon:qe,onRequestIconReplace:Le,onPinEndpoint:ut,onUnpinEndpoint:Je,onToggleNodeLock:ce,activeShape:Q,onSelectShape:ue,disableSidebar:ge,statusReport:be,onNameChange:De,onDescriptionChange:ne,onDetailChange:he,onIconChange:Ee,autoFitView:Be,autoFitViewSignal:Ge,customIcons:Pt,onExportToCloud:Oe,onRestartDemo:Te,showToolbar:_t,showStyleStrip:nr,showDetailPanel:Nt,showStatusBadges:Nn,showResizeHandles:tn,showControls:Bu,showShareMenu:Vu,showRestart:pa,enableKeyboard:ya,enableContextMenu:Gr,enableDragDrop:ki,enableImageDrop:ma,enableZoom:gr,enablePan:Kr,enableSelection:kr,enableNodeMove:$u,enableEmbed:Uu}=e,Fe=g.useMemo(()=>Oze({mode:n,showToolbar:_t,showStyleStrip:nr,showDetailPanel:Nt,showStatusBadges:Nn,showResizeHandles:tn,showControls:Bu,showShareMenu:Vu,showRestart:pa,enableKeyboard:ya,enableContextMenu:Gr,enableDragDrop:ki,enableImageDrop:ma,enableZoom:gr,enablePan:Kr,enableSelection:kr,enableNodeMove:$u,enableEmbed:Uu}),[n,_t,nr,Nt,Nn,tn,Bu,Vu,pa,ya,Gr,ki,ma,gr,Kr,kr,$u,Uu]),bt=n==="edit",Zr=g.useRef(Fe);g.useEffect(()=>{Zr.current=Fe},[Fe]);const Xr=Be??(n==="mini"?!0:void 0),zn=g.useMemo(()=>Fze(Xr),[Xr]),vr=d==null?void 0:d.runs,Ro=d==null?void 0:d.statuses,rr=(vU=d==null?void 0:d.pendingOverrides)==null?void 0:vU.nodes,Yr=(xU=d==null?void 0:d.pendingOverrides)==null?void 0:xU.connectors,hn=g.useRef(null),zt=g.useRef(null),To=g.useRef(!1),xr=g.useRef(!1),vi=g.useRef(!1),xi=g.useRef(zn);xi.current=zn,g.useEffect(()=>{if(To.current||!zn.onMount||i.length===0)return;const K=zt.current;K&&(K.fitView(lh),To.current=!0)},[i,zn.onMount]);const jo=g.useRef(null),Lt=Q,wi=ue,Dn=g.useRef(new Map),ga=g.useCallback((K,J)=>(Dn.current.set(K,J),()=>{Dn.current.get(K)===J&&Dn.current.delete(K)}),[]),[or,wr]=g.useState(!1),Wu=g.useRef(!1);g.useEffect(()=>{Wu.current=or},[or]);const Mi=g.useRef(!1),bi=g.useRef(!1),ka=g.useRef(!1),[Mn,Qr]=g.useState(null),Jr=g.useRef(null);g.useEffect(()=>{Jr.current=Mn},[Mn]),g.useCallback(()=>{Qr(null)},[]);const Gu=g.useMemo(()=>Zze(ka),[]),No=g.useRef(null),ar=g.useRef(null),bn=g.useCallback(K=>{const J=hn.current;if(!J){No.current=K;return}const le=No.current;if(le&&le!==K){const de=J.querySelector(`.react-flow__node[data-id="${CSS.escape(le)}"]`);de==null||de.removeAttribute("data-connect-source")}if(K){const de=J.querySelector(`.react-flow__node[data-id="${CSS.escape(K)}"]`);de==null||de.setAttribute("data-connect-source","true")}No.current=K},[]),fn=g.useCallback(K=>{const J=hn.current,le=ar.current;if(le!==K){if(J&&le){const de=J.querySelector(`.react-flow__node[data-id="${CSS.escape(le)}"]`);de==null||de.removeAttribute("data-connect-target")}if(J&&K){const de=J.querySelector(`.react-flow__node[data-id="${CSS.escape(K)}"]`);de==null||de.setAttribute("data-connect-target","true")}ar.current=K}},[]),va=g.useCallback(()=>{bn(null),fn(null)},[bn,fn]);g.useEffect(()=>{if(!or){fn(null);return}const K=J=>{const le=MF(hn.current,J.clientX,J.clientY),de=(le==null?void 0:le.getAttribute("data-id"))??null;if(de&&de===No.current){fn(null);return}fn(de)};return document.addEventListener("pointermove",K),()=>{document.removeEventListener("pointermove",K)}},[or,fn]);const[ir,eo]=g.useState(null),[to,zo]=g.useState(null),rt=g.useRef(null),no=g.useRef(null),qn=g.useRef(null),nn=g.useRef(!1);g.useEffect(()=>{rt.current=Lt},[Lt]);const ro=g.useCallback(()=>{wi(null),eo(null),zo(null),rt.current=null,no.current=null,qn.current=null,nn.current=!1},[wi]);g.useEffect(()=>{if(!Fe.enableKeyboard)return;const K=J=>{var ye,Ne;if(J.key!=="Escape"||lde(document.activeElement))return;if(rt.current){J.preventDefault(),ro();return}if(Wu.current){J.preventDefault(),Mi.current=!0,bi.current=!0;try{(ye=jo.current)==null||ye.getState().cancelConnection()}catch{}document.dispatchEvent(new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,button:0})),wr(!1);return}if(Jr.current){J.preventDefault(),Qr(null);return}const le=br.current.size>0,de=qo.current.size>0;(le||de)&&(J.preventDefault(),(Ne=ao.current)==null||Ne.call(ao,[],[]))};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[ro,Fe.enableKeyboard]),g.useEffect(()=>{if(!Fe.enableKeyboard)return;const K=J=>{Jze({event:J,selectedNodeIds:c,hasClipboard:!!H,activeElement:document.activeElement,onCopySelection:F,onPasteSelection:V})};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[c,H,F,V,Fe.enableKeyboard]);const Ku=g.useCallback(K=>{var de,ye;if(!rt.current)return;const J=K.target;if(!(J!=null&&J.classList.contains("react-flow__pane")))return;const le={x:K.clientX,y:K.clientY};nn.current=!0,no.current=le,qn.current=le,eo(le),zo(le);try{(ye=(de=K.currentTarget).setPointerCapture)==null||ye.call(de,K.pointerId)}catch{}K.preventDefault(),K.stopPropagation()},[]),ej=g.useCallback(K=>{if(!nn.current)return;const J={x:K.clientX,y:K.clientY};qn.current=J,zo(J)},[]),Bf=g.useCallback(K=>{var Sa,wU;if(!nn.current)return;nn.current=!1;try{(wU=(Sa=K.currentTarget).releasePointerCapture)==null||wU.call(Sa,K.pointerId)}catch{}const J=no.current,le=qn.current,de=rt.current,ye=zt.current;if(ro(),!J||!le||!de||!ye)return;const Ne=Math.min(J.x,le.x),Me=Math.min(J.y,le.y),Ae=Math.max(J.x,le.x),et=Math.max(J.y,le.y),ht=Ae-Ne,qt=et-Me,Re=ye.screenToFlowPosition({x:Ne,y:Me}),ot=ye.screenToFlowPosition({x:Ae,y:et}),Ze=ot.x-Re.x,Ii=ot.y-Re.y,Ca=ht<nte||qt<nte,Oo=Ca?fR[de].width:Ze,Jf=Ca?fR[de].height:Ii;S==null||S(de,Re,{width:Oo,height:Jf})},[ro,S]),Do=g.useRef(!1),Zu=g.useRef(!1),Bd=g.useRef(new Map),xa=g.useCallback(()=>{var K;xr.current&&(Zu.current||Do.current||(xr.current=!1,(K=zt.current)==null||K.fitView(lh)))},[]),Vd=g.useCallback(K=>{Zu.current=K,K||xa()},[xa]);g.useEffect(()=>{var K;if(!vi.current){vi.current=!0;return}if(xi.current.onExternalNodeChange){if(Zu.current||Do.current){xr.current=!0;return}(K=zt.current)==null||K.fitView(lh)}},[Ge]);const $d=!!P||!!A||!!U||!!R||!!Je,[O,B]=g.useState(null),[Z,$]=g.useState(!1),[D,te]=g.useState(null),[Pe,Ce]=g.useState(null),Xe=g.useRef(null),Dt=g.useRef(null);g.useEffect(()=>{if(!O)return;const K=Dt.current;if(!K)return;const J=new MouseEvent("contextmenu",{clientX:O.x,clientY:O.y,bubbles:!0,cancelable:!0,button:2,buttons:2});K.dispatchEvent(J)},[O]);const Xt=g.useCallback(K=>{const J=Xe.current;!J||!P||P(J,K)},[P]),Gt=g.useCallback(()=>{const K=Xe.current;!K||!A||A(K)},[A]),Mr=g.useCallback(()=>{const K=Xe.current;!K||!U||U(K)},[U]),wa=g.useCallback(()=>{const K=Xe.current;!K||!Le||Le(K)},[Le]),Xu=g.useCallback(()=>{if(!ce)return;const K=Xe.current,J=K?[K]:[...c];J.length!==0&&ce(J)},[ce,c]);g.useCallback((K,J,le,de,ye)=>{Zr.current.enableContextMenu&&(Xe.current=null,$(!1),te(null),Ce({connectorId:K,kind:J,pinned:le}),B({x:de,y:ye}))},[]);const _e=g.useCallback(()=>{const K=Pe;!K||!Je||Je(K.connectorId,K.kind)},[Pe,Je]),it=g.useCallback(()=>{if(!R)return;const K=O,J=zt.current;if(!K||!J)return;const le=J.screenToFlowPosition({x:K.x,y:K.y});R(le)},[O,R]),je=typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent||""),st=je?"⌘C":"Ctrl+C",rn=je?"⌘V":"Ctrl+V",Yt=g.useMemo(()=>new Set(c),[c]),Ci=g.useMemo(()=>{const K=new Set;for(const J of i)J.data.locked===!0&&K.add(J.id);return K},[i]),oo=g.useMemo(()=>new Set(l),[l]),tj=g.useMemo(()=>{if(c.length<2)return[];const K=rr,J=[];for(const le of c){const de=i.find(Ae=>Ae.id===le);if(!de)continue;const ye=K==null?void 0:K[le],Ne=(ye==null?void 0:ye.data)??{},Me=de.data;J.push({id:le,position:(ye==null?void 0:ye.position)??de.position,data:{width:Ne.width??Me.width,height:Ne.height??Me.height,locked:Ne.locked??Me.locked}})}return J},[i,rr,c]),Vf=z??[],$f=g.useMemo(()=>{const K=ye=>{const Ne=bt?void 0:Bd.current.get(ye.id),Me={id:ye.id,type:ye.type,position:Ne??ye.position,data:{...ye.data,projectId:o,fileBaseUrl:a,onRetryUpload:L,status:eDe(vr,ye.id),errorMessage:tDe(vr,ye.id),statusReport:Ro==null?void 0:Ro[ye.id],onPlay:f,onResize:k,setResizing:Vd,onFitToContent:ye.type==="htmlNode"?w:void 0,onNameChange:(()=>{if(bt&&!(ye.type==="shapeNode"&&ye.data.shape==="ellipse"))return M})(),onDescriptionChange:(()=>{if(bt){if(ye.type==="shapeNode"){const Ae=ye.data.shape;return Ae==="rectangle"||Ae==="ellipse"||Ae==="sticky"?x:void 0}if(!(ye.type==="imageNode"||ye.type==="iconNode"))return x}})(),onIconChange:(()=>{if(bt&&!(ye.type!=="playNode"&&ye.type!=="stateNode"))return Ee})(),autoEditOnMount:ve===ye.id?!0:void 0},selected:Yt.has(ye.id)};return ye.data.width!==void 0&&(Me.width=ye.data.width),ye.data.height!==void 0&&(Me.height=ye.data.height),Yt.has(ye.id)||(Me.connectable=!1),ye.data.locked===!0&&(Me.draggable=!1),Me},J=i.map(ye=>K(Vze(ye,rr==null?void 0:rr[ye.id]))),le=new Set(i.map(ye=>ye.id)),de=[];if(rr)for(const[ye,Ne]of Object.entries(rr)){if(le.has(ye))continue;const Me=Ne;typeof Me.type!="string"||!Me.position||!Me.data||de.push(K({...Me,id:ye}))}return[...J,...de]},[o,a,i,Yt,vr,Ro,f,k,w,Vd,rr,M,x,Ee,L,ve,bt]),[nj,rj]=g.useState($f);g.useEffect(()=>{Do.current||Zu.current||rj($f)},[$f]),g.useEffect(()=>{Ud.current=nj},[nj]);const br=g.useRef(Yt);g.useEffect(()=>{br.current=Yt},[Yt]);const ao=g.useRef(u);g.useEffect(()=>{ao.current=u},[u]);const qo=g.useRef(oo);g.useEffect(()=>{qo.current=oo},[oo]);const Ud=g.useRef($f),Si=g.useRef(!1),Uf=g.useRef(new Set),Wf=g.useRef(new Set),oj=g.useRef(new Set),aj=g.useRef(new Set),Ma=g.useRef(null),Lde=g.useCallback(K=>{var ot;const J=Si.current?oj.current:(ot=Ma.current)!=null&&ot.shift?Ma.current.nodeIds:null,le=J&&J.size>0?K.filter(Ze=>Ze.type!=="select"?!0:!(Ze.selected===!1&&J.has(Ze.id))):K,de=new Set;for(const Ze of le)Ze.type==="select"&&de.add(Ze.id);const ye=Sie(le,Ud.current),Ne=br.current,Me=Si.current||Ne.size===0?ye:ye.map(Ze=>Ne.has(Ze.id)&&!de.has(Ze.id)&&!Ze.selected?{...Ze,selected:!0}:Ze);if(Ud.current=Me,rj(Me),de.size===0)return;if(Si.current){for(const Ze of le)Ze.type==="select"&&(Ze.selected?Uf.current.add(Ze.id):Uf.current.delete(Ze.id));return}const Ae=ao.current;if(!Ae)return;const et=Me.filter(Ze=>Ze.selected).map(Ze=>Ze.id),ht=br.current;ht.size===et.length&&et.every(Ze=>ht.has(Ze))||(br.current=new Set(et),Ae(et,[...qo.current]))},[]),Gf=g.useRef([]),Ide=g.useCallback(K=>{var qt;const J=Si.current?aj.current:(qt=Ma.current)!=null&&qt.shift?Ma.current.edgeIds:null,le=J&&J.size>0?K.filter(Re=>Re.type!=="select"?!0:!(Re.selected===!1&&J.has(Re.id))):K,de=new Set;for(const Re of le)Re.type==="select"&&de.add(Re.id);if(de.size===0)return;if(Si.current){for(const Re of le)Re.type==="select"&&(Re.selected?Wf.current.add(Re.id):Wf.current.delete(Re.id));return}const ye=ao.current;if(!ye)return;const Me=Lie(le,Gf.current).filter(Re=>Re.selected).map(Re=>Re.id),Ae=qo.current;Ae.size===Me.length&&Me.every(Re=>Ae.has(Re))||(qo.current=new Set(Me),ye([...br.current],Me))},[]),Ede=g.useCallback(K=>{Si.current=!0;const J=Ma.current,le=(J==null?void 0:J.shift)??(K.shiftKey||K.metaKey||K.ctrlKey);oj.current=le?new Set((J==null?void 0:J.nodeIds)??br.current):new Set,aj.current=le?new Set((J==null?void 0:J.edgeIds)??qo.current):new Set,Uf.current=new Set(oj.current),Wf.current=new Set(aj.current)},[]),Ade=g.useCallback(()=>{Si.current=!1,Ma.current=null;const K=ao.current;if(!K)return;const J=[...Uf.current],le=new Set(J),de=new Set(Wf.current);for(const et of Gf.current)le.has(et.source)&&le.has(et.target)&&de.add(et.id);const ye=br.current,Ne=qo.current,Me=ye.size===le.size&&J.every(et=>ye.has(et)),Ae=Ne.size===de.size&&[...de].every(et=>Ne.has(et));Me&&Ae||(br.current=new Set(J),qo.current=new Set(de),K(J,[...de]))},[]),Pde=g.useCallback(K=>{if(Ma.current=null,rt.current||K.button!==0)return;const J=K.target;J!=null&&J.classList.contains("react-flow__pane")&&(Ma.current={shift:K.shiftKey||K.metaKey||K.ctrlKey,nodeIds:new Set(br.current),edgeIds:new Set(qo.current)})},[]),_de=g.useCallback(K=>{if(!Zr.current.enableContextMenu||br.current.size<2)return;const le=K.target;le!==Dt.current&&(le!=null&&le.closest(".seeflow-connector-endpoint-dot")||(K.preventDefault(),K.stopPropagation(),Xe.current=null,$(!0),te(null),Ce(null),B({x:K.clientX,y:K.clientY})))},[]),Rde=g.useCallback(K=>{const J=K.dataTransfer;if(!J)return;const le=J.types?Array.from(J.types):[],de=le.includes("Files"),ye=le.includes(OJ),Ne=de&&!!C&&Fe.enableImageDrop,Me=ye&&!!_&&Fe.enableDragDrop;if(!(!Ne&&!Me)){K.preventDefault();try{J.dropEffect="copy"}catch{}}},[C,_,Fe.enableImageDrop,Fe.enableDragDrop]),Tde=g.useCallback(K=>{const J=K.dataTransfer;if((J!=null&&J.types?Array.from(J.types):[]).includes(OJ)&&_&&Fe.enableDragDrop){K.preventDefault();const Ne=zt.current;if(!Ne)return;const Me=Ne.screenToFlowPosition({x:K.clientX,y:K.clientY});_({position:Me});return}if(!C||!Fe.enableImageDrop)return;const ye={x:K.clientX,y:K.clientY};K.preventDefault(),Wke({dataTransfer:J,clientPos:ye,rfInstance:zt.current,computeDims:Gke,dispatch:C})},[C,_,Fe.enableImageDrop,Fe.enableDragDrop]),uU=!!E,dU=oo.size===1?[...oo][0]:null,ij=g.useMemo(()=>{const K=Ae=>{const et=ste(vr,Ae.source)==="running"||ste(vr,Ae.target)==="running",ht=oo.has(Ae.id),qt=J8e(Ae,et,ht);ht&&(qt.selected=!0);const Re=uU&&Ae.id===dU,ot=Re?{...qt,reconnectable:!0}:qt;return{...ot,data:{...ot.data,onLabelChange:bt?b:void 0,reconnectable:Re,registerEditHandle:ga}}},J=new Set(s.map(Ae=>Ae.id)),le=s.map(Ae=>K($ze(Ae,Yr==null?void 0:Yr[Ae.id]))),de=[];if(Yr)for(const[Ae,et]of Object.entries(Yr)){if(J.has(Ae))continue;const ht=et;typeof ht.source!="string"||typeof ht.target!="string"||typeof ht.kind!="string"||de.push(K({...ht,id:Ae}))}const ye=[...le,...de],Ne=[],Me=[];for(const Ae of ye)oo.has(Ae.id)?Me.push(Ae):Ne.push(Ae);return[...Ne,...Me]},[s,vr,oo,dU,Yr,b,uU,ga,bt]);g.useEffect(()=>{Gf.current=ij},[ij]);const jde=g.useCallback(()=>{const K=zt.current,J=Ud.current;if(J.length<2)return;const le=J.map(Re=>{var Oo;const ot=(Oo=K==null?void 0:K.getInternalNode(Re.id))==null?void 0:Oo.measured,Ze=Re.data,Ii=(ot==null?void 0:ot.width)??Ze.width??200,Ca=(ot==null?void 0:ot.height)??Ze.height??120;return{id:Re.id,width:Ii,height:Ca,position:Re.position}}),de=Gf.current.map(Re=>({source:Re.source,target:Re.target})),ye=rae(le,de);let Ne=Number.POSITIVE_INFINITY,Me=Number.POSITIVE_INFINITY,Ae=Number.POSITIVE_INFINITY,et=Number.POSITIVE_INFINITY;for(const Re of le){Re.position.x<Ne&&(Ne=Re.position.x),Re.position.y<Me&&(Me=Re.position.y);const ot=ye.get(Re.id);ot&&(ot.x<Ae&&(Ae=ot.x),ot.y<et&&(et=ot.y))}const ht=Number.isFinite(Ne)&&Number.isFinite(Ae)?Ne-Ae:0,qt=Number.isFinite(Me)&&Number.isFinite(et)?Me-et:0;rj(Re=>Re.map(ot=>{const Ze=ye.get(ot.id);return Ze?{...ot,position:{x:Ze.x+ht,y:Ze.y+qt}}:ot}))},[]),Kf=oe??(bt?void 0:jde),Zf=g.useRef(!1),hU=g.useRef(null),Nde=g.useCallback(K=>{var Ae;if(!bt||!T)return;const{source:J,target:le}=K;if(!J||!le||J===le)return;Zf.current=!0;const de=((Ae=hU.current)==null?void 0:Ae.nodeId)??null,ye=de!==null&&de===le&&de!==J;T(ye?le:J,ye?J:le)},[T,bt]),sj=g.useCallback(K=>{const J=le=>{if(!le)return!1;const de=Ud.current.find(ye=>ye.id===le);return de?de.type==="shapeNode"&&de.data.shape==="text":!1};return!J(K.source)&&!J(K.target)},[]),zde=g.useCallback((K,J)=>{var qt;wr(!1),va();const le=Zf.current;if(Zf.current=!1,le||ka.current)return;if(Mi.current){Mi.current=!1;return}if(!T)return;const de=(qt=J.fromNode)==null?void 0:qt.id,ye=J.fromHandle;if(!de||!ye)return;const Ne=rte(K);if(!Ne)return;const Me=MF(hn.current,Ne.clientX,Ne.clientY);if(!Me)return;const Ae=Me.getAttribute("data-id");if(!Ae||Ae===de||!sj({source:de,target:Ae,sourceHandle:null,targetHandle:null}))return;let et;const ht=zt.current;if(ht){const Re=ht.getInternalNode(Ae);if(Re){const ot=Re.measured.width??Re.width??0,Ze=Re.measured.height??Re.height??0;if(ot>0&&Ze>0){const Ii=ht.screenToFlowPosition({x:Ne.clientX,y:Ne.clientY});et=OH({x:Re.internals.positionAbsolute.x,y:Re.internals.positionAbsolute.y,w:ot,h:Ze},Ii)}}}T(de,Ae,et?{targetPin:et}:void 0)},[T,va,sj]),Xf=g.useRef(!1),Dde=g.useCallback((K,J)=>{if(!E)return;const{source:le,target:de,sourceHandle:ye,targetHandle:Ne}=J;if(!le||!de||le===de)return;const Me={};if(le!==K.source&&(Me.source=le),de!==K.target&&(Me.target=de),typeof ye=="string"&&ye!==K.sourceHandle&&(Me.sourceHandle=ye),typeof Ne=="string"&&Ne!==K.targetHandle&&(Me.targetHandle=Ne),Me.source===void 0&&Me.target===void 0&&Me.sourceHandle===void 0&&Me.targetHandle===void 0)return;(Me.source!==void 0||Me.sourceHandle!==void 0)&&(Me.sourceHandleAutoPicked=!1),(Me.target!==void 0||Me.targetHandle!==void 0)&&(Me.targetHandleAutoPicked=!1);const Ae=zt.current;if(!(Me.source===void 0&&Me.target===void 0)&&Ae){const ht=Me.source!==void 0?"source":"target",qt=ote(ht,K.source,K.target,K.data,Re=>Ae.getInternalNode(Re)??null);qt&&(ht==="source"?Me.targetPin=qt:Me.sourcePin=qt)}Xf.current=!0,E(K.id,Me)},[E]),qde=g.useCallback((K,J,le,de)=>{var Jf;wr(!1),va(),ka.current=!1;const ye=Xf.current;if(Xf.current=!1,ye)return;if(bi.current){bi.current=!1;return}if(!E)return;const Ne=rte(K);let Me=((Jf=de.toNode)==null?void 0:Jf.id)??null;if(!Me&&Ne){const Sa=MF(hn.current,Ne.clientX,Ne.clientY);Me=(Sa==null?void 0:Sa.getAttribute("data-id"))??null}const Ae=le==="source"?"target":"source",et=Bze(Ae,J.source,J.target,Me);if(et==="no-op"||et==="self-loop"||!Ne)return;const ht=zt.current;if(!ht)return;const qt=et==="pin-own"?Ae==="source"?J.source:J.target:Me,Re=ht.getInternalNode(qt);if(!Re)return;const ot=Re.measured.width??Re.width??0,Ze=Re.measured.height??Re.height??0;if(ot===0||Ze===0)return;const Ii=ht.screenToFlowPosition({x:Ne.clientX,y:Ne.clientY}),Ca=OH({x:Re.internals.positionAbsolute.x,y:Re.internals.positionAbsolute.y,w:ot,h:Ze},Ii);if(et==="pin-own"){if(!ut)return;ut(J.id,Ae,Ca);return}const Oo=ote(Ae,J.source,J.target,J.data,Sa=>ht.getInternalNode(Sa)??null);Ae==="source"?E(J.id,{source:Me,sourceHandle:null,sourceHandleAutoPicked:!1,sourcePin:Ca,...Oo?{targetPin:Oo}:{}}):E(J.id,{target:Me,targetHandle:null,targetHandleAutoPicked:!1,targetPin:Ca,...Oo?{sourcePin:Oo}:{}})},[E,va,ut]),Li=g.useMemo(()=>{var Ae;if(!ir||!to)return null;const K=(Ae=hn.current)==null?void 0:Ae.getBoundingClientRect(),J=(K==null?void 0:K.left)??0,le=(K==null?void 0:K.top)??0,de=Math.min(ir.x,to.x),ye=Math.min(ir.y,to.y),Ne=Math.abs(to.x-ir.x),Me=Math.abs(to.y-ir.y);return{left:de-J,top:ye-le,width:Ne,height:Me}},[ir,to]),Ode=Lt?ace(Lt):"",Fde=Lt?ice(Lt):void 0,Hde=Lt==="text",[fU,pU]=g.useState(!1),[Bde,Yf]=g.useState(!1),[Vde,yU]=g.useState(!1),ba=Nze({projectId:o,getReactFlow:()=>zt.current});g.useImperativeHandle(t,()=>({exportPdf:ba.exportPdf,exportPng:ba.exportPng,openEmbedDialog:()=>yU(!0),capturePreview:ba.capturePreview}),[ba.exportPdf,ba.exportPng,ba.capturePreview]),g.useEffect(()=>{if(!Fe.enableKeyboard)return;const K=de=>{if(!de)return!1;const ye=de.tagName;return ye==="INPUT"||ye==="TEXTAREA"||ye==="SELECT"?!0:de instanceof HTMLElement&&de.isContentEditable},J=de=>{de.code==="Space"&&(K(document.activeElement)||(de.preventDefault(),pU(!0)))},le=de=>{de.code==="Space"&&(pU(!1),Yf(!1))};return window.addEventListener("keydown",J),window.addEventListener("keyup",le),()=>{window.removeEventListener("keydown",J),window.removeEventListener("keyup",le)}},[Fe.enableKeyboard]);const Qf=g.useCallback(K=>{if(K.length!==0){if(!bt){const J=Bd.current;for(const le of K)J.set(le.id,{x:le.position.x,y:le.position.y});return}if(K.length===1){const J=K[0];J&&p&&p(J.id,{x:J.position.x,y:J.position.y});return}if(y){y(K.map(J=>({id:J.id,position:{x:J.position.x,y:J.position.y}})));return}if(p)for(const J of K)p(J.id,{x:J.position.x,y:J.position.y})}},[p,y,bt]),$de=g.useCallback((K,J,le)=>{Do.current=!1,Qf(le),xa()},[Qf,xa]),Ude=g.useCallback(()=>{Do.current=!0},[]),Wde=g.useCallback((K,J)=>{Do.current=!1,Qf(J),xa()},[Qf,xa]),Gde=g.useCallback((K,J)=>{re==null||re(J.id)},[re]),Kde=g.useCallback(K=>{we==null||we()},[we]),Zde=g.useCallback((K,J)=>{ie==null||ie(J.id)},[ie]),mU=Lt?"crosshair":fU?Bde?"grabbing":"grab":void 0,gU=c[0],kU=l[0],Xde=gU?i.find(K=>K.id===gU)??null:null,Yde=kU?s.find(K=>K.id===kU)??null:null,Qde=o??null,Jde=Fe.showDetailPanel&&!ge,ehe=g.useMemo(()=>({custom:Pt??{}}),[Pt]);return m.jsx(GMe,{value:ehe,children:m.jsx("div",{"data-testid":"seeflow-canvas","data-mode":n,ref:hn,className:"seeflow-canvas-root sf:relative sf:h-full sf:w-full",style:mU?{cursor:mU}:void 0,onPointerDownCapture:Pde,onPointerDown:K=>{fU&&Yf(!0),Ku(K)},onPointerMove:ej,onPointerUp:K=>{Yf(!1),Bf(K)},onPointerCancel:()=>{nn.current=!1,no.current=null,qn.current=null,eo(null),zo(null),Yf(!1)},onContextMenuCapture:_de,onDragOver:Rde,onDrop:Tde,children:m.jsxs(K9e,{containerRef:hn,children:[m.jsxs(y8e,{nodes:nj,edges:ij,onNodesChange:Lde,nodeTypes:Uze,edgeTypes:Wze,proOptions:{hideAttribution:!0},fitView:!0,minZoom:n==="mini"?.05:.5,nodesDraggable:(bt?!!p:!0)&&!Lt&&Fe.enableNodeMove,nodesConnectable:bt&&!!T&&!Lt,deleteKeyCode:bt?["Backspace","Delete"]:null,zoomOnScroll:Fe.enableZoom,zoomOnPinch:Fe.enableZoom,className:or?"seeflow-connecting":void 0,onConnect:bt?Nde:void 0,isValidConnection:sj,onConnectStart:(K,J)=>{wr(!0),Zf.current=!1,hU.current={nodeId:J.nodeId??null,handleType:J.handleType??null},bn(J.nodeId??null)},onConnectEnd:zde,onReconnect:bt&&E?Dde:void 0,onReconnectStart:(K,J,le)=>{wr(!0),Xf.current=!1,ka.current=!0;const de=le==="source"?J.source:J.target;bn(de)},onReconnectEnd:qde,connectionLineComponent:Gu,connectionLineStyle:{strokeWidth:2},connectionRadius:32,reconnectRadius:10,edgesReconnectable:!1,elevateNodesOnSelect:!1,elementsSelectable:!Lt&&Fe.enableSelection,selectNodesOnDrag:!1,nodeClickDistance:5,selectionOnDrag:!Lt&&Fe.enableSelection,panOnDrag:Lt?!1:Fe.enablePan?[1,2]:!1,selectionMode:od.Partial,selectionKeyCode:null,multiSelectionKeyCode:Lt?null:["Meta","Shift"],panActivationKeyCode:Lt?null:"Space",onSelectionStart:Ede,onSelectionEnd:Ade,defaultEdgeOptions:Gze,zoomOnDoubleClick:!1,onInit:K=>{zt.current=K;const J=hn.current;J&&J.style.setProperty("--rf-zoom",String(K.getZoom())),!To.current&&zn.onMount&&i.length>0&&(K.fitView(lh),To.current=!0),Y==null||Y(K)},onMove:(K,J)=>{Jr.current&&Qr(null);const le=hn.current;le&&le.style.setProperty("--rf-zoom",String(J.zoom))},onEdgesChange:Ide,onNodeDragStart:()=>{Do.current=!0},onNodeDragStop:$de,onSelectionDragStart:Ude,onSelectionDragStop:Wde,onNodeClick:Gde,onEdgeClick:Zde,onEdgeDoubleClick:(K,J)=>{var le;(le=Dn.current.get(J.id))==null||le()},onPaneClick:Kde,onNodeContextMenu:Fe.enableContextMenu&&$d?(K,J)=>{K.preventDefault(),Xe.current=J.id,$(!0),te(J.type??null),Ce(null),B({x:K.clientX,y:K.clientY})}:void 0,onPaneContextMenu:Fe.enableContextMenu&&R?K=>{K.preventDefault(),Xe.current=null,$(!1),te(null),Ce(null),B({x:K.clientX,y:K.clientY})}:void 0,children:[m.jsx(Xze,{storeApiRef:jo}),m.jsx(Yze,{wrapperRef:hn}),m.jsx(S8e,{gap:12,size:.6}),Fe.showControls?m.jsxs(R8e,{showInteractive:!1,showFitView:!1,children:[m.jsx(L1,{"data-testid":"controls-fit-view","aria-label":"Fit view",title:"Fit view",disabled:i.length===0,onClick:()=>{var K;(K=zt.current)==null||K.fitView(lh)},children:m.jsx(N1,{className:"sf:h-3 sf:w-3","aria-hidden":"true"})}),m.jsx(L1,{"data-testid":"controls-tidy","aria-label":"Tidy layout (⌘⇧L)",title:"Tidy layout (⌘⇧L)",disabled:!Kf,onClick:()=>Kf==null?void 0:Kf(),children:m.jsx(Kh,{className:"sf:h-3 sf:w-3","aria-hidden":"true"})})]}):null,Fe.showResizeHandles?m.jsx(_Ne,{selectedNodes:tj,onMultiResize:v}):null,Fe.showToolbar&&S||Fe.showStyleStrip&&I&&W?m.jsx(ld,{position:"top-left",children:m.jsxs("div",{className:"sf:flex sf:flex-col sf:gap-2",children:[Fe.showToolbar&&S?m.jsx(uEe,{activeShape:Lt,onSelectShape:wi,iconPickerOpen:xe??!1,onOpenIconPicker:ee,onCloseIconPicker:se,onPickIcon:qe}):null,Fe.showStyleStrip&&I&&W?m.jsx(TNe,{nodes:Vf,connectors:N??[],onStyleNode:I,onStyleNodePreview:G,onStyleNodes:q,onStyleNodesPreview:j,onStyleConnector:W,onStyleConnectorPreview:X,onRequestIconReplace:Le}):null]})}):null,Fe.showShareMenu||Fe.showRestart&&Te?m.jsx(ld,{position:"top-right",children:m.jsxs("div",{className:"sf:flex sf:items-center sf:gap-1",children:[Fe.showRestart&&Te?m.jsx(INe,{onRestartDemo:Te}):null,Fe.showShareMenu?m.jsx(LNe,{mode:n==="mini"?"view":n,projectId:o,enableEmbed:Fe.enableEmbed,onDownloadPdf:ba.exportPdf,onDownloadPng:ba.exportPng,onExportToCloud:Oe,embedOpen:Vde,onEmbedOpenChange:yU}):null]})}):null]}),Li?m.jsx("div",{"data-testid":"canvas-draw-ghost","data-ghost-shape":Lt??void 0,"aria-hidden":!0,className:ae("sf:pointer-events-none sf:absolute sf:z-10",Ode,Hde?"sf:rounded-sm sf:border sf:border-dashed sf:border-muted-foreground/40":""),style:{...Fde,left:Li.left,top:Li.top,width:Li.width,height:Li.height},children:(()=>{const K=Lt?M$[Lt]:void 0;return K?m.jsx(K,{width:Li.width,height:Li.height,borderColor:ct(void 0,"node").borderColor,backgroundColor:rf,borderSize:i$}):null})()}):null,Fe.enableContextMenu&&$d?m.jsxs(jLe,{onOpenChange:K=>{K||(B(null),Xe.current=null,te(null),Ce(null))},children:[m.jsx(NLe,{asChild:!0,children:m.jsx("div",{ref:Dt,"data-testid":"node-context-menu-trigger","aria-hidden":!0,className:"sf:pointer-events-none sf:fixed",style:{left:(O==null?void 0:O.x)??0,top:(O==null?void 0:O.y)??0,width:0,height:0}})}),m.jsxs(Fle,{"data-testid":"node-context-menu",children:[Pe!=null&&Pe.pinned&&Je?m.jsx(Ir,{"data-testid":"connector-endpoint-context-menu-unpin",onSelect:_e,children:"Unpin"}):null,Z&&U?m.jsxs(Ir,{"data-testid":"node-context-menu-copy",onSelect:Mr,children:["Copy",m.jsx(QH,{children:st})]}):null,R?m.jsxs(Ir,{"data-testid":"node-context-menu-paste",disabled:!H,onSelect:it,children:["Paste",m.jsx(QH,{children:rn})]}):null,Z&&(U||R)&&(D==="iconNode"&&Le||P||A)?m.jsx(Sh,{}):null,Z&&D==="iconNode"&&Le?m.jsx(Ir,{"data-testid":"node-context-menu-change-icon",onSelect:wa,children:"Change icon"}):null,Z&&D==="iconNode"&&Le&&(P||A)?m.jsx(Sh,{}):null,Z&&P?m.jsxs(m.Fragment,{children:[m.jsx(Ir,{"data-testid":"node-context-menu-to-front",onSelect:()=>Xt({op:"toFront"}),children:"Bring to front"}),m.jsx(Ir,{"data-testid":"node-context-menu-forward",onSelect:()=>Xt({op:"forward"}),children:"Bring forward"}),m.jsx(Ir,{"data-testid":"node-context-menu-backward",onSelect:()=>Xt({op:"backward"}),children:"Send backward"}),m.jsx(Ir,{"data-testid":"node-context-menu-to-back",onSelect:()=>Xt({op:"toBack"}),children:"Send to back"})]}):null,Z&&P&&(ce||A)?m.jsx(Sh,{}):null,Z&&ce?(()=>{const K=Xe.current,J=K?[K]:c,le=J.length>0&&J.every(de=>Ci.has(de))?"Unlock":"Lock";return m.jsx(Ir,{"data-testid":"node-context-menu-toggle-lock",onSelect:Xu,disabled:J.length===0,children:le})})():null,Z&&ce&&A?m.jsx(Sh,{}):null,Z&&A?m.jsx(Ir,{"data-testid":"node-context-menu-delete",onSelect:Gt,disabled:Xe.current?Ci.has(Xe.current):!1,children:"Delete"}):null]})]}):null,ke?m.jsxs(zd,{open:!!Mn,onOpenChange:K=>{K||Qr(null)},children:[m.jsx(Z9e,{asChild:!0,children:m.jsx("div",{"data-testid":"drop-popover-anchor","aria-hidden":!0,className:"sf:pointer-events-none sf:fixed",style:{left:(Mn==null?void 0:Mn.clientX)??0,top:(Mn==null?void 0:Mn.clientY)??0,width:0,height:0}})}),m.jsx(qu,{"data-testid":"drop-popover",align:"start",side:"bottom",sideOffset:4,className:"sf:w-auto sf:p-1",onOpenAutoFocus:K=>{K.preventDefault()},children:m.jsx("div",{role:"menu","aria-label":"Create connected node",className:"sf:flex sf:flex-col sf:gap-0.5",children:lEe.map(({shape:K,label:J,Icon:le})=>m.jsxs("button",{type:"button",role:"menuitem","data-testid":`drop-popover-shape-${K}`,onClick:()=>{const de=Mn;de&&(ke({sourceNodeId:de.sourceNodeId,position:{x:de.flowX,y:de.flowY},shape:K}),Qr(null))},className:ae("sf:flex sf:items-center sf:gap-2 sf:rounded-sm sf:px-2 sf:py-1.5 sf:text-left sf:text-sm","sf:hover:bg-accent sf:hover:text-accent-foreground","sf:focus:bg-accent sf:focus:text-accent-foreground sf:focus:outline-hidden"),children:[m.jsx(le,{className:"sf:h-4 sf:w-4 sf:text-muted-foreground","aria-hidden":"true"}),m.jsx("span",{children:J})]},K))})})]}):null,Jde?m.jsx(rNe,{flowId:Qde,node:Xde,connector:Yde,adapter:r??null,statusReport:be,onNameChange:De,onDescriptionChange:ne,onDetailChange:he,onIconChange:Ee,onClose:()=>{var K;(K=ao.current)==null||K.call(ao,[],[])}}):null]})})})}const rDe=g.forwardRef(nDe);function oDe({open:e,onOpenChange:t,onCreated:n}){const[r,o]=g.useState(""),[a,i]=g.useState(null),[s,c]=g.useState(!1);g.useEffect(()=>{e&&(o(""),i(null),c(!1))},[e]);const l=r.trim(),u=l.length>0&&!s,d=async f=>{if(f.preventDefault(),!!u){c(!0),i(null);try{const p=await Pfe({name:l});n(p),t(!1)}catch(p){i(p instanceof Error?p.message:String(p)),c(!1)}}};return m.jsx(NT,{open:e,onOpenChange:t,children:m.jsxs(Ef,{className:"sm:max-w-md","data-testid":"create-project-dialog",onOpenAutoFocus:f=>{f.preventDefault();const p=document.querySelector('[data-testid="create-project-name-input"]');p==null||p.focus()},children:[m.jsxs(Af,{children:[m.jsx(Pf,{children:"Create new project"}),m.jsxs(_f,{children:["The project will be created at ",m.jsx("code",{children:"~/.seeflow/<slug>"}),"."]})]}),m.jsxs("form",{onSubmit:d,className:"flex flex-col gap-4",children:[m.jsxs("label",{className:"flex flex-col gap-1.5 text-sm",children:[m.jsx("span",{className:"font-medium",children:"Project name"}),m.jsx("input",{type:"text",required:!0,autoComplete:"off",spellCheck:!1,value:r,onChange:f=>o(f.target.value),"data-testid":"create-project-name-input",className:"rounded-md border bg-background px-3 py-2 text-sm outline-hidden ring-offset-background focus:border-ring focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"})]}),a?m.jsx("div",{role:"alert","data-testid":"create-project-error",className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:a}):null,m.jsxs(pd,{children:[m.jsx(Ft,{type:"button",variant:"ghost",onClick:()=>t(!1),disabled:s,children:"Cancel"}),m.jsx(Ft,{type:"submit",disabled:!u,"data-testid":"create-project-submit",children:s?"Creating…":"Create project"})]})]})]})})}const vB="seeflow:navigate",aDe=e=>(window.addEventListener("popstate",e),window.addEventListener(vB,e),()=>{window.removeEventListener("popstate",e),window.removeEventListener(vB,e)}),cte=()=>window.location.pathname,iDe=()=>g.useSyncExternalStore(aDe,cte,cte),gd=e=>{e!==window.location.pathname&&(window.history.pushState({},"",e),window.dispatchEvent(new Event(vB)))};function sDe({demos:e,currentSlug:t,onProjectCreated:n,onProjectUnregistered:r}){const[o,a]=g.useState(!1),[i,s]=g.useState(!1),[c,l]=g.useState(null),[u,d]=g.useState(!1),[f,p]=g.useState(null);g.useEffect(()=>{const x=b=>{b.key==="k"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),a(S=>!S))};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[]);const y=e.find(x=>x.slug===t),k=x=>{n==null||n(x),gd(`/d/${x.slug}`)},w=x=>{l(x),p(null)},v=()=>{u||(l(null),p(null))},M=async()=>{if(c){d(!0),p(null);try{await Afe(c.id);const x=c.id;l(null),r==null||r(x)}catch(x){p(x instanceof Error?x.message:String(x))}finally{d(!1)}}};return m.jsxs(m.Fragment,{children:[m.jsxs(zd,{open:o,onOpenChange:a,children:[m.jsx(wf,{asChild:!0,children:m.jsxs(Ft,{type:"button",variant:"outline",size:"sm","aria-label":"Switch demo","aria-expanded":o,className:"gap-2","data-testid":"project-switcher-trigger",children:[m.jsx("span",{className:"max-w-[180px] truncate text-sm",children:(y==null?void 0:y.name)??"Select demo"}),m.jsx(Dce,{children:"⌘K"}),m.jsx(Oh,{className:"h-3.5 w-3.5 opacity-60"})]})}),m.jsx(qu,{align:"end",sideOffset:6,className:"w-[320px] p-0","data-testid":"project-switcher-popover",children:m.jsxs(Rce,{children:[m.jsx(Tce,{placeholder:"Search demos..."}),m.jsxs(jce,{children:[m.jsx(Nce,{children:"No demos."}),e.length>0?m.jsx(KH,{heading:"Demos",children:e.map(x=>m.jsxs(ZH,{value:`${x.name} ${x.slug}`,onSelect:()=>{a(!1),gd(`/d/${x.slug}`)},className:"group flex items-center justify-between gap-2",children:[m.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-0.5",children:[m.jsx("span",{className:"font-medium",children:x.name}),m.jsx("span",{className:"w-full truncate text-xs text-muted-foreground",children:x.repoPath})]}),m.jsx("button",{type:"button","aria-label":`Unregister ${x.name}`,className:"shrink-0 rounded p-0.5 opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring",onClick:b=>{b.stopPropagation(),a(!1),w(x)},children:m.jsx(c2,{className:"h-3.5 w-3.5"})})]},x.id))}):null,e.length>0?m.jsx(zce,{}):null,m.jsx(KH,{children:m.jsxs(ZH,{value:"+ create new project",onSelect:()=>{a(!1),s(!0)},"data-testid":"project-switcher-create",className:"flex items-center gap-2 text-sm",children:[m.jsx(Jh,{className:"h-4 w-4 opacity-70"}),m.jsx("span",{className:"font-medium",children:"Create new project"})]})})]})]})})]}),m.jsx(oDe,{open:i,onOpenChange:s,onCreated:k}),m.jsx(NT,{open:c!==null,onOpenChange:x=>{x||v()},children:m.jsxs(Ef,{className:"sm:max-w-md","data-testid":"unregister-project-dialog",children:[m.jsxs(Af,{children:[m.jsx(Pf,{children:"Unregister project?"}),m.jsxs(_f,{children:["This removes ",m.jsx("strong",{children:c==null?void 0:c.name})," from SeeFlow. Your files at"," ",m.jsx("code",{className:"text-xs",children:c==null?void 0:c.repoPath})," will not be deleted."]})]}),f?m.jsx("div",{role:"alert","data-testid":"unregister-project-error",className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:f}):null,m.jsxs(pd,{children:[m.jsx(Ft,{type:"button",variant:"ghost",onClick:v,disabled:u,children:"Cancel"}),m.jsx(Ft,{type:"button",variant:"destructive",onClick:M,disabled:u,"data-testid":"unregister-project-confirm",children:u?"Unregistering…":"Unregister"})]})]})})]})}function cDe({demos:e,currentSlug:t,onProjectCreated:n,onProjectUnregistered:r}){return m.jsxs("header",{className:"relative flex h-14 shrink-0 items-center justify-between border-b border-border/60 bg-background/85 px-5 backdrop-blur-md shadow-[0_4px_12px_-6px_rgba(0,0,0,0.6)]",children:[m.jsxs("button",{type:"button",onClick:()=>gd("/"),className:"-ml-1.5 flex items-center gap-2 rounded-md px-1.5 py-1 text-base font-bold tracking-tight transition-colors hover:bg-muted/60",children:[m.jsx(d2,{size:18,strokeWidth:2.25,className:"text-emerald-400"}),"SeeFlow"]}),m.jsx("div",{className:"flex items-center gap-3",children:m.jsx(sDe,{demos:e,currentSlug:t,onProjectCreated:n,onProjectUnregistered:r})})]})}const lDe=e=>{const[t,n]=g.useState(null),[r,o]=g.useState(e!==null),[a,i]=g.useState(null),s=g.useCallback(()=>{e&&(o(!0),qre(e).then(c=>{n(c),i(null)}).catch(c=>{console.error("[useDemoData] failed",c),i(String(c))}).finally(()=>o(!1)))},[e]);return g.useEffect(()=>{if(!e){n(null),o(!1);return}s()},[e,s]),{detail:t,loading:r,error:a,refresh:s}},uDe=()=>{const[e,t]=g.useState(null),[n,r]=g.useState(null),o=g.useCallback(()=>Efe().then(a=>{t(a),r(null)}).catch(a=>{console.error("[useDemos] failed",a),t([]),r(String(a))}),[]);return g.useEffect(()=>{o()},[o]),{demos:e,error:n,refresh:o}},dDe=5,hDe={"node:running":"running","node:done":"done","node:error":"error"},fDe=(e,t)=>{if(t.type==="reset")return{};const n=e[t.nodeId]??[],r=[t.entry,...n].slice(0,dDe);return{...e,[t.nodeId]:r}},pDe=e=>{const[t,n]=g.useReducer(fDe,{}),r=g.useRef(n);r.current=n,g.useEffect(()=>{r.current({type:"reset"})},[e]);const o=g.useCallback(i=>{const s=hDe[i.type];if(!s)return;const c=typeof i.nodeId=="string"?i.nodeId:null;if(!c)return;const l=typeof i.runId=="string"?i.runId:void 0,u=typeof i.ts=="number"?i.ts:Date.now();r.current({type:"append",nodeId:c,entry:{status:s,ts:u,runId:l}})},[]),a=g.useCallback(()=>{r.current({type:"reset"})},[]);return{events:t,apply:o,reset:a}},yDe=(e,t)=>{var n,r;switch(t.type){case"reset":return{};case"running":return{...e,[t.nodeId]:{status:"running",runId:t.runId,ts:t.ts??Date.now()}};case"done":return{...e,[t.nodeId]:{...e[t.nodeId],status:"done",runId:t.runId??((n=e[t.nodeId])==null?void 0:n.runId),responseStatus:t.responseStatus,body:t.body,ts:t.ts??Date.now()}};case"error":return{...e,[t.nodeId]:{...e[t.nodeId],status:"error",runId:t.runId??((r=e[t.nodeId])==null?void 0:r.runId),error:t.message,ts:t.ts??Date.now()}}}},mDe=e=>{const[t,n]=g.useReducer(yDe,{}),r=g.useRef(n);r.current=n,g.useEffect(()=>{r.current({type:"reset"})},[e]);const o=g.useCallback(i=>{const s=typeof i.nodeId=="string"?i.nodeId:null;if(!s)return;const c=typeof i.runId=="string"?i.runId:void 0;if(i.type==="node:running"){r.current({type:"running",nodeId:s,runId:c,ts:i.ts});return}if(i.type==="node:done"){const l=typeof i.status=="number"?i.status:void 0;r.current({type:"done",nodeId:s,runId:c,responseStatus:l,body:i.body,ts:i.ts});return}if(i.type==="node:error"){const l=typeof i.message=="string"?i.message:void 0;r.current({type:"error",nodeId:s,runId:c,message:l,ts:i.ts})}},[]),a=g.useCallback(()=>{r.current({type:"reset"})},[]);return{runs:t,apply:o,reset:a}},gDe=new Set(["ok","warn","error","pending"]),kDe=(e,t)=>{if(t.type!=="node:status")return e;const n=typeof t.nodeId=="string"?t.nodeId:null;if(!n||typeof t.state!="string"||!gDe.has(t.state))return e;const r=typeof t.summary=="string"?t.summary:void 0,o=typeof t.detail=="string"?t.detail:void 0,a=t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:void 0,i=typeof t.ts=="number"?t.ts:Date.now();return{...e,[n]:{state:t.state,summary:r,detail:o,data:a,ts:i}}},vDe=(e,t)=>{switch(t.type){case"reset":return{};case"event":return kDe(e,t.event)}},xDe=e=>{const[t,n]=g.useReducer(vDe,{}),r=g.useRef(n);r.current=n,g.useEffect(()=>{r.current({type:"reset"})},[e]);const o=g.useCallback(i=>{r.current({type:"event",event:i})},[]),a=g.useCallback(()=>{r.current({type:"reset"})},[]);return{statusByNode:t,apply:o,reset:a}},wDe=(e,t={})=>{const[n,r]=g.useState(null),[o,a]=g.useState(!1),{onReload:i,onEvent:s}=t;return g.useEffect(()=>{if(!e){r(null),a(!1);return}const c=`/api/events?flowId=${encodeURIComponent(e)}`,l=new EventSource(c);l.addEventListener("open",()=>a(!0)),l.addEventListener("error",()=>a(!1)),l.addEventListener("hello",()=>{i==null||i()}),l.addEventListener("flow:reload",u=>{const d=lte(u,"flow:reload");r(d),s==null||s(d),i==null||i()});for(const u of["node:running","node:done","node:error","node:status"])l.addEventListener(u,d=>{s==null||s(lte(d,u))});return()=>{l.close()}},[e,i,s]),{lastReload:n,connected:o}},lte=(e,t)=>{try{const n=JSON.parse(e.data);return{type:t,ts:Date.now(),...n}}catch{return{type:t,ts:Date.now()}}},ude="seeflow:last-project",MDe=()=>{if(typeof window>"u")return null;try{return window.localStorage.getItem(ude)}catch{return null}},ute=e=>{if(!(typeof window>"u"))try{window.localStorage.setItem(ude,e)}catch{}},bDe=(e,t)=>{if(e.length===0)return null;if(e.length===1)return e[0]??null;if(t){const n=e.find(r=>r.id===t);if(n)return n}return null},dte=["File","Edit","View","Tools","Layout","Selection","Help"],dde="seeflow:command-palette:recent",hde=5,fde=new Map(o$.map(e=>[e.id,e])),CDe=e=>typeof e=="string"&&fde.has(e),hte=()=>{if(typeof window>"u")return[];try{const e=window.localStorage.getItem(dde);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(CDe).slice(0,hde):[]}catch{return[]}},SDe=e=>{if(!(typeof window>"u"))try{window.localStorage.setItem(dde,JSON.stringify(e))}catch{}},fte=(e,t)=>e.enabled?e.enabled(t):!0,LDe=(e,t)=>t.length===0?!0:`${e.label} ${e.description??""}`.toLowerCase().includes(t);function IDe({open:e,onOpenChange:t,runCommand:n,ctx:r}){const[o,a]=g.useState(""),[i,s]=g.useState(0),[c,l]=g.useState(()=>hte()),u=g.useRef(null),d=g.useRef(null);g.useEffect(()=>{e&&(a(""),s(0),l(hte()))},[e]);const{groups:f,flat:p}=g.useMemo(()=>{const b=o.trim().toLowerCase();if(b.length===0){if(c.length===0)return{groups:[],flat:[]};const T=[];for(const P of c){const A=fde.get(P);A&&T.push({cmd:A,enabled:fte(A,r)})}return{groups:[{category:"Recent",rows:T}],flat:T}}const S=new Map;for(const T of o$){if(!LDe(T,b))continue;const E={cmd:T,enabled:fte(T,r)},P=S.get(T.category);P?P.push(E):S.set(T.category,[E])}const L=[...dte.filter(T=>S.has(T)),...Array.from(S.keys()).filter(T=>!dte.includes(T))].map(T=>({category:T,rows:S.get(T)??[]})),_=L.flatMap(T=>T.rows);return{groups:L,flat:_}},[o,r,c]);g.useEffect(()=>{if(p.length===0){s(0);return}s(b=>{var C;let S=b;if(S>=p.length&&(S=0),!((C=p[S])!=null&&C.enabled)){const L=p.findIndex(_=>_.enabled);L!==-1&&(S=L)}return S})},[p]);const y=g.useCallback(b=>{p.length!==0&&s(S=>{var L;let C=S;for(let _=0;_<p.length;_++)if(C=(C+b+p.length)%p.length,(L=p[C])!=null&&L.enabled)return C;return S})},[p]),k=g.useCallback(b=>{l(S=>{const C=[b,...S.filter(L=>L!==b)].slice(0,hde);return SDe(C),C})},[]),w=g.useCallback(b=>{const S=p[b];!S||!S.enabled||(k(S.cmd.id),n(S.cmd.id),t(!1))},[p,t,k,n]),v=g.useCallback(b=>{if(b.key==="ArrowDown"){b.preventDefault(),y(1);return}if(b.key==="ArrowUp"){b.preventDefault(),y(-1);return}b.key==="Enter"&&(b.preventDefault(),w(i))},[w,i,y]);g.useEffect(()=>{if(!e)return;const b=d.current;if(!b)return;const S=b.querySelector(`[data-command-row-index="${i}"]`);S&&typeof S.scrollIntoView=="function"&&S.scrollIntoView({block:"nearest"})},[i,e]);const x=o.trim().length>0;return m.jsx(PT,{open:e,onOpenChange:t,children:m.jsx(_T,{children:m.jsxs(Dd,{className:ae("fixed left-0 right-0 top-[20%] z-50 mx-auto w-[480px] max-w-[90vw] border border-border bg-card shadow-lg duration-200","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","sm:rounded-lg"),"data-testid":"command-palette",onOpenAutoFocus:b=>{var S;b.preventDefault(),(S=u.current)==null||S.focus()},children:[m.jsx("div",{className:ae("border-b",p.length===0&&!x&&"border-b-0"),children:m.jsx("input",{ref:u,type:"text",value:o,onChange:b=>a(b.target.value),onKeyDown:v,placeholder:"Type a command…","data-testid":"command-palette-input","aria-label":"Search commands",autoComplete:"off",spellCheck:!1,className:"w-full bg-transparent px-4 py-3 text-sm outline-hidden placeholder:text-muted-foreground"})}),m.jsx("div",{ref:d,"data-testid":"command-palette-list","data-empty":p.length===0?"true":"false",className:ae("max-h-[50vh] overflow-y-auto",p.length>0?"py-1":"","seeflow-no-scrollbar"),children:p.length===0?x?m.jsxs("div",{"data-testid":"command-palette-empty",className:"px-4 py-6 text-center text-sm text-muted-foreground",children:['No commands match "',o,'"']}):null:(()=>{let b=-1;return f.map(S=>m.jsxs("div",{className:"py-1",children:[m.jsx("div",{className:"px-3 pb-1 pt-2 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:S.category}),S.rows.map(C=>{b+=1;const L=b,_=L===i;return m.jsxs("button",{type:"button","data-testid":`command-palette-row-${C.cmd.id}`,"data-command-row-index":L,"data-highlighted":_?"true":"false","aria-disabled":C.enabled?void 0:!0,disabled:!C.enabled,onMouseEnter:()=>{C.enabled&&s(L)},onClick:()=>w(L),className:ae("flex w-full items-center justify-between gap-3 px-3 py-2 text-left text-sm outline-hidden",C.enabled?"cursor-pointer text-foreground hover:bg-muted":"cursor-not-allowed text-muted-foreground/50",_&&C.enabled?"bg-muted":""),children:[m.jsxs("div",{className:"flex min-w-0 flex-col",children:[m.jsx("span",{className:"truncate font-medium",children:C.cmd.label}),C.cmd.description?m.jsx("span",{className:"truncate text-xs text-muted-foreground",children:C.cmd.description}):null]}),C.cmd.shortcut?m.jsx("kbd",{"data-testid":`command-palette-shortcut-${C.cmd.id}`,className:"shrink-0 rounded border bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:C.cmd.shortcut}):null]},C.cmd.id)})]},S.category))})()})]})})})}var un=Uint8Array,Gn=Uint16Array,sU=Int32Array,cU=new un([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),lU=new un([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),pte=new un([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),pde=function(e,t){for(var n=new Gn(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var o=new sU(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)o[a]=a-n[r]<<5|r;return{b:n,r:o}},yde=pde(cU,2),EDe=yde.b,xB=yde.r;EDe[28]=258,xB[258]=28;var ADe=pde(lU,0),yte=ADe.r,wB=new Gn(32768);for(var xt=0;xt<32768;++xt){var Ta=(xt&43690)>>1|(xt&21845)<<1;Ta=(Ta&52428)>>2|(Ta&13107)<<2,Ta=(Ta&61680)>>4|(Ta&3855)<<4,wB[xt]=((Ta&65280)>>8|(Ta&255)<<8)>>1}var k2=function(e,t,n){for(var r=e.length,o=0,a=new Gn(t);o<r;++o)e[o]&&++a[e[o]-1];var i=new Gn(t);for(o=1;o<t;++o)i[o]=i[o-1]+a[o-1]<<1;var s;if(n){s=new Gn(1<<t);var c=15-t;for(o=0;o<r;++o)if(e[o])for(var l=o<<4|e[o],u=t-e[o],d=i[e[o]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[wB[d]>>c]=l}else for(s=new Gn(r),o=0;o<r;++o)e[o]&&(s[o]=wB[i[e[o]-1]++]>>15-e[o]);return s},Au=new un(288);for(var xt=0;xt<144;++xt)Au[xt]=8;for(var xt=144;xt<256;++xt)Au[xt]=9;for(var xt=256;xt<280;++xt)Au[xt]=7;for(var xt=280;xt<288;++xt)Au[xt]=8;var CR=new un(32);for(var xt=0;xt<32;++xt)CR[xt]=5;var PDe=k2(Au,9,0),_De=k2(CR,5,0),mde=function(e){return(e+7)/8|0},gde=function(e,t,n){return(n==null||n>e.length)&&(n=e.length),new un(e.subarray(t,n))},RDe=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],JT=function(e,t,n){var r=new Error(t||RDe[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,JT),!n)throw r;return r},Uo=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},uh=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8,e[r+2]|=n>>16},bF=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var o=n.length,a=n.slice();if(!o)return{t:vde,l:0};if(o==1){var i=new un(n[0].s+1);return i[n[0].s]=1,{t:i,l:1}}n.sort(function(S,C){return S.f-C.f}),n.push({s:-1,f:25001});var s=n[0],c=n[1],l=0,u=1,d=2;for(n[0]={s:-1,f:s.f+c.f,l:s,r:c};u!=o-1;)s=n[n[l].f<n[d].f?l++:d++],c=n[l!=u&&n[l].f<n[d].f?l++:d++],n[u++]={s:-1,f:s.f+c.f,l:s,r:c};for(var f=a[0].s,r=1;r<o;++r)a[r].s>f&&(f=a[r].s);var p=new Gn(f+1),y=MB(n[u-1],p,0);if(y>t){var r=0,k=0,w=y-t,v=1<<w;for(a.sort(function(C,L){return p[L.s]-p[C.s]||C.f-L.f});r<o;++r){var M=a[r].s;if(p[M]>t)k+=v-(1<<y-p[M]),p[M]=t;else break}for(k>>=w;k>0;){var x=a[r].s;p[x]<t?k-=1<<t-p[x]++-1:++r}for(;r>=0&&k;--r){var b=a[r].s;p[b]==t&&(--p[b],++k)}y=t}return{t:new un(p),l:y}},MB=function(e,t,n){return e.s==-1?Math.max(MB(e.l,t,n+1),MB(e.r,t,n+1)):t[e.s]=n},mte=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new Gn(++t),r=0,o=e[0],a=1,i=function(c){n[r++]=c},s=1;s<=t;++s)if(e[s]==o&&s!=t)++a;else{if(!o&&a>2){for(;a>138;a-=138)i(32754);a>2&&(i(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(i(o),--a;a>6;a-=6)i(8304);a>2&&(i(a-3<<5|8208),a=0)}for(;a--;)i(o);a=1,o=e[s]}return{c:n.subarray(0,r),n:t}},dh=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},kde=function(e,t,n){var r=n.length,o=mde(t+2);e[o]=r&255,e[o+1]=r>>8,e[o+2]=e[o]^255,e[o+3]=e[o+1]^255;for(var a=0;a<r;++a)e[o+a+4]=n[a];return(o+4+r)*8},gte=function(e,t,n,r,o,a,i,s,c,l,u){Uo(t,u++,n),++o[256];for(var d=bF(o,15),f=d.t,p=d.l,y=bF(a,15),k=y.t,w=y.l,v=mte(f),M=v.c,x=v.n,b=mte(k),S=b.c,C=b.n,L=new Gn(19),_=0;_<M.length;++_)++L[M[_]&31];for(var _=0;_<S.length;++_)++L[S[_]&31];for(var T=bF(L,7),E=T.t,P=T.l,A=19;A>4&&!E[pte[A-1]];--A);var U=l+5<<3,R=dh(o,Au)+dh(a,CR)+i,H=dh(o,f)+dh(a,k)+i+14+3*A+dh(L,E)+2*L[16]+3*L[17]+7*L[18];if(c>=0&&U<=R&&U<=H)return kde(t,u,e.subarray(c,c+l));var F,V,z,N;if(Uo(t,u,1+(H<R)),u+=2,H<R){F=k2(f,p,0),V=f,z=k2(k,w,0),N=k;var I=k2(E,P,0);Uo(t,u,x-257),Uo(t,u+5,C-1),Uo(t,u+10,A-4),u+=14;for(var _=0;_<A;++_)Uo(t,u+3*_,E[pte[_]]);u+=3*A;for(var G=[M,S],q=0;q<2;++q)for(var j=G[q],_=0;_<j.length;++_){var W=j[_]&31;Uo(t,u,I[W]),u+=E[W],W>15&&(Uo(t,u,j[_]>>5&127),u+=j[_]>>12)}}else F=PDe,V=Au,z=_De,N=CR;for(var _=0;_<s;++_){var X=r[_];if(X>255){var W=X>>18&31;uh(t,u,F[W+257]),u+=V[W+257],W>7&&(Uo(t,u,X>>23&31),u+=cU[W]);var Y=X&31;uh(t,u,z[Y]),u+=N[Y],Y>3&&(uh(t,u,X>>5&8191),u+=lU[Y])}else uh(t,u,F[X]),u+=V[X]}return uh(t,u,F[256]),u+V[256]},TDe=new sU([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),vde=new un(0),jDe=function(e,t,n,r,o,a){var i=a.z||e.length,s=new un(r+i+5*(1+Math.ceil(i/7e3))+o),c=s.subarray(r,s.length-o),l=a.l,u=(a.r||0)&7;if(t){u&&(c[0]=a.r>>3);for(var d=TDe[t-1],f=d>>13,p=d&8191,y=(1<<n)-1,k=a.p||new Gn(32768),w=a.h||new Gn(y+1),v=Math.ceil(n/3),M=2*v,x=function(ee){return(e[ee]^e[ee+1]<<v^e[ee+2]<<M)&y},b=new sU(25e3),S=new Gn(288),C=new Gn(32),L=0,_=0,T=a.i||0,E=0,P=a.w||0,A=0;T+2<i;++T){var U=x(T),R=T&32767,H=w[U];if(k[R]=H,w[U]=R,P<=T){var F=i-T;if((L>7e3||E>24576)&&(F>423||!l)){u=gte(e,c,0,b,S,C,_,E,A,T-A,u),E=L=_=0,A=T;for(var V=0;V<286;++V)S[V]=0;for(var V=0;V<30;++V)C[V]=0}var z=2,N=0,I=p,G=R-H&32767;if(F>2&&U==x(T-G))for(var q=Math.min(f,F)-1,j=Math.min(32767,T),W=Math.min(258,F);G<=j&&--I&&R!=H;){if(e[T+z]==e[T+z-G]){for(var X=0;X<W&&e[T+X]==e[T+X-G];++X);if(X>z){if(z=X,N=G,X>q)break;for(var Y=Math.min(G,X-2),oe=0,V=0;V<Y;++V){var re=T-G+V&32767,ie=k[re],we=re-ie&32767;we>oe&&(oe=we,H=re)}}}R=H,H=k[R],G+=R-H&32767}if(N){b[E++]=268435456|xB[z]<<18|yte[N];var ke=xB[z]&31,ve=yte[N]&31;_+=cU[ke]+lU[ve],++S[257+ke],++C[ve],P=T+z,++L}else b[E++]=e[T],++S[e[T]]}}for(T=Math.max(T,P);T<i;++T)b[E++]=e[T],++S[e[T]];u=gte(e,c,l,b,S,C,_,E,A,T-A,u),l||(a.r=u&7|c[u/8|0]<<3,u-=7,a.h=w,a.p=k,a.i=T,a.w=P)}else{for(var T=a.w||0;T<i+l;T+=65535){var xe=T+65535;xe>=i&&(c[u/8|0]=l,xe=i),u=kde(c,u+1,e.subarray(T,xe))}a.i=i}return gde(s,0,r+mde(u)+o)},NDe=function(){for(var e=new Int32Array(256),t=0;t<256;++t){for(var n=t,r=9;--r;)n=(n&1&&-306674912)^n>>>1;e[t]=n}return e}(),zDe=function(){var e=-1;return{p:function(t){for(var n=e,r=0;r<t.length;++r)n=NDe[n&255^t[r]]^n>>>8;e=n},d:function(){return~e}}},xde=function(){var e=1,t=0;return{p:function(n){for(var r=e,o=t,a=n.length|0,i=0;i!=a;){for(var s=Math.min(i+2655,a);i<s;++i)o+=r+=n[i];r=(r&65535)+15*(r>>16),o=(o&65535)+15*(o>>16)}e=r,t=o},d:function(){return e%=65521,t%=65521,(e&255)<<24|(e&65280)<<8|(t&255)<<8|t>>8}}},wde=function(e,t,n,r,o){if(!o&&(o={l:1},t.dictionary)){var a=t.dictionary.subarray(-32768),i=new un(a.length+e.length);i.set(a),i.set(e,a.length),e=i,o.w=a.length}return jDe(e,t.level==null?6:t.level,t.mem==null?o.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+t.mem,n,r,o)},Mde=function(e,t){var n={};for(var r in e)n[r]=e[r];for(var r in t)n[r]=t[r];return n},$t=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},DDe=function(e,t){var n=t.level,r=n==0?0:n<6?1:n==9?3:2;if(e[0]=120,e[1]=r<<6|(t.dictionary&&32),e[1]|=31-(e[0]<<8|e[1])%31,t.dictionary){var o=xde();o.p(t.dictionary),$t(e,2,o.d())}};function qDe(e,t){return wde(e,t||{},0,0)}function Lqe(e,t){t||(t={});var n=xde();n.p(e);var r=wde(e,t,t.dictionary?6:2,4);return DDe(r,t),$t(r,r.length-4,n.d()),r}var bde=function(e,t,n,r){for(var o in e){var a=e[o],i=t+o,s=r;Array.isArray(a)&&(s=Mde(r,a[1]),a=a[0]),a instanceof un?n[i]=[a,s]:(n[i+="/"]=[new un(0),s],bde(a,i,n,r))}},kte=typeof TextEncoder<"u"&&new TextEncoder,ODe=typeof TextDecoder<"u"&&new TextDecoder,FDe=0;try{ODe.decode(vde,{stream:!0}),FDe=1}catch{}function bB(e,t){var n;if(kte)return kte.encode(e);for(var r=e.length,o=new un(e.length+(e.length>>1)),a=0,i=function(l){o[a++]=l},n=0;n<r;++n){if(a+5>o.length){var s=new un(a+8+(r-n<<1));s.set(o),o=s}var c=e.charCodeAt(n);c<128||t?i(c):c<2048?(i(192|c>>6),i(128|c&63)):c>55295&&c<57344?(c=65536+(c&1047552)|e.charCodeAt(++n)&1023,i(240|c>>18),i(128|c>>12&63),i(128|c>>6&63),i(128|c&63)):(i(224|c>>12),i(128|c>>6&63),i(128|c&63))}return gde(o,0,a)}var CB=function(e){var t=0;if(e)for(var n in e){var r=e[n].length;r>65535&&JT(9),t+=r+4}return t},vte=function(e,t,n,r,o,a,i,s){var c=r.length,l=n.extra,u=s&&s.length,d=CB(l);$t(e,t,i!=null?33639248:67324752),t+=4,i!=null&&(e[t++]=20,e[t++]=n.os),e[t]=20,t+=2,e[t++]=n.flag<<1|(a<0&&8),e[t++]=o&&8,e[t++]=n.compression&255,e[t++]=n.compression>>8;var f=new Date(n.mtime==null?Date.now():n.mtime),p=f.getFullYear()-1980;if((p<0||p>119)&&JT(10),$t(e,t,p<<25|f.getMonth()+1<<21|f.getDate()<<16|f.getHours()<<11|f.getMinutes()<<5|f.getSeconds()>>1),t+=4,a!=-1&&($t(e,t,n.crc),$t(e,t+4,a<0?-a-2:a),$t(e,t+8,n.size)),$t(e,t+12,c),$t(e,t+14,d),t+=16,i!=null&&($t(e,t,u),$t(e,t+6,n.attrs),$t(e,t+10,i),t+=14),e.set(r,t),t+=c,d)for(var y in l){var k=l[y],w=k.length;$t(e,t,+y),$t(e,t+2,w),e.set(k,t+4),t+=4+w}return u&&(e.set(s,t),t+=u),t},HDe=function(e,t,n,r,o){$t(e,t,101010256),$t(e,t+8,n),$t(e,t+10,n),$t(e,t+12,r),$t(e,t+16,o)};function BDe(e,t){t||(t={});var n={},r=[];bde(e,"",n,t);var o=0,a=0;for(var i in n){var s=n[i],c=s[0],l=s[1],u=l.level==0?0:8,d=bB(i),f=d.length,p=l.comment,y=p&&bB(p),k=y&&y.length,w=CB(l.extra);f>65535&&JT(11);var v=u?qDe(c,l):c,M=v.length,x=zDe();x.p(c),r.push(Mde(l,{size:c.length,crc:x.d(),c:v,f:d,m:y,u:f!=i.length||y&&p.length!=k,o,compression:u})),o+=30+f+w+M,a+=76+2*(f+w)+(k||0)+M}for(var b=new un(a+22),S=o,C=a-o,L=0;L<r.length;++L){var d=r[L];vte(b,d.o,d,d.f,d.u,d.c.length);var _=30+d.f.length+CB(d.extra);b.set(d.c,d.o+_),vte(b,o,d,d.f,d.u,d.c.length,d.o,d.m),o+=16+_+(d.m?d.m.length:0)}return HDe(b,o,r.length,C,S),b}const VDe="https://seeflow.dev/api";async function $De(e,t,n,r,o){const a=await qre(e);if(!a.flow)throw new Error("Flow has no data");const i=a.flow,s=new Set,c=[];for(const y of i.nodes)y.type==="imageNode"&&y.data.path&&!s.has(y.data.path)?(s.add(y.data.path),c.push(y.data.path)):y.type==="htmlNode"&&y.data.htmlPath&&!s.has(y.data.htmlPath)&&(s.add(y.data.htmlPath),c.push(y.data.htmlPath));const u={[r==="link"?"seeflow.private.json":"seeflow.json"]:bB(JSON.stringify(i))};if(o){const y=o.split(",")[1];y&&(u["preview.png"]=Uint8Array.from(atob(y),k=>k.charCodeAt(0)))}for(const y of c){const k=await fetch(`/api/projects/${encodeURIComponent(e)}/files/${y}`);k.ok&&(u[`files/${y}`]=new Uint8Array(await k.arrayBuffer()))}const d=BDe(u),f=await fetch(`${VDe}/flows?email=${encodeURIComponent(t)}&name=${encodeURIComponent(n)}`,{method:"POST",headers:{"content-type":"application/zip"},body:d.buffer});if(!f.ok)throw new Error(`Export failed with status ${f.status}`);const p=await f.json();if(typeof p.url!="string")throw new Error("Invalid response from cloud API: missing url");return{shareUrl:p.url}}function UDe(e){return g.useCallback((t,n,r,o)=>$De(e,t,n,r,o),[e])}const xte="seeflow.export.email",wte="seeflow.export.name",Mte="seeflow.export.visibility";function WDe({open:e,onOpenChange:t,projectId:n,onCapturePreview:r}){const[o,a]=g.useState(""),[i,s]=g.useState(""),[c,l]=g.useState("public"),[u,d]=g.useState({kind:"idle"}),[f,p]=g.useState(!1),y=UDe(n);g.useEffect(()=>{e&&(a(localStorage.getItem(xte)??""),s(localStorage.getItem(wte)??""),l(localStorage.getItem(Mte)??"public"),d({kind:"idle"}),p(!1))},[e]);const k=g.useCallback(async()=>{d({kind:"loading"});try{const x=await(r==null?void 0:r()),{shareUrl:b}=await y(o.trim(),i.trim(),c,x);localStorage.setItem(xte,o.trim()),localStorage.setItem(wte,i.trim()),localStorage.setItem(Mte,c),d({kind:"done",shareUrl:b})}catch(x){d({kind:"error",message:x instanceof Error?x.message:String(x)})}},[y,o,i,c,r]),w=g.useCallback(async()=>{if(u.kind==="done")try{await navigator.clipboard.writeText(u.shareUrl),p(!0),setTimeout(()=>p(!1),2e3)}catch(x){console.error("Failed to copy to clipboard:",x)}},[u]),v=u.kind==="loading",M=o.trim().length>0&&i.trim().length>0;return m.jsx(NT,{open:e,onOpenChange:t,children:m.jsxs(Ef,{className:"sm:max-w-md","data-testid":"export-dialog",onOpenAutoFocus:x=>{x.preventDefault();const b=document.querySelector('[data-testid="export-email-input"]');b==null||b.focus()},children:[m.jsxs(Af,{children:[m.jsx(Pf,{children:"Export to seeflow.dev"}),m.jsx(_f,{children:"Upload this diagram to the cloud and get a shareable link."})]}),u.kind!=="done"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex flex-col gap-4",children:[m.jsxs("label",{className:"flex flex-col gap-1.5 text-sm",children:[m.jsx("span",{className:"font-medium",children:"Email"}),m.jsx("input",{type:"email",required:!0,autoComplete:"email",value:o,onChange:x=>a(x.target.value),disabled:v,"data-testid":"export-email-input",className:"rounded-md border bg-background px-3 py-2 text-sm outline-hidden ring-offset-background focus:border-ring focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"We'll use this to let you manage your flows in the future."})]}),m.jsxs("label",{className:"flex flex-col gap-1.5 text-sm",children:[m.jsx("span",{className:"font-medium",children:"Flow Name"}),m.jsx("input",{type:"text",required:!0,value:i,onChange:x=>s(x.target.value),disabled:v,"data-testid":"export-name-input",className:"rounded-md border bg-background px-3 py-2 text-sm outline-hidden ring-offset-background focus:border-ring focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"})]}),m.jsxs("label",{className:"flex flex-col gap-1.5 text-sm",children:[m.jsx("span",{className:"font-medium",children:"Visibility"}),m.jsxs("select",{value:c,onChange:x=>l(x.target.value),disabled:v,"data-testid":"export-visibility-select",className:"rounded-md border bg-background px-3 py-2 text-sm outline-hidden ring-offset-background focus:border-ring focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",children:[m.jsx("option",{value:"public",children:"Public — anyone can discover it"}),m.jsx("option",{value:"link",children:"Anyone with the link"})]})]}),u.kind==="error"?m.jsx("div",{role:"alert","data-testid":"export-error",className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:u.message}):null]}),m.jsx(pd,{children:u.kind==="error"?m.jsxs(m.Fragment,{children:[m.jsx(Ft,{type:"button",variant:"ghost",onClick:()=>t(!1),"data-testid":"export-cancel",children:"Cancel"}),m.jsx(Ft,{type:"button",onClick:()=>d({kind:"idle"}),"data-testid":"export-retry",children:"Try again"})]}):m.jsxs(m.Fragment,{children:[m.jsx(Ft,{type:"button",variant:"ghost",onClick:()=>t(!1),disabled:v,"data-testid":"export-cancel",children:"Cancel"}),m.jsx(Ft,{type:"button",onClick:k,disabled:v||!M,"data-testid":"export-submit",children:v?m.jsxs(m.Fragment,{children:[m.jsx(Rr,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}),m.jsx("span",{children:"Uploading…"})]}):"Export"})]})})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex flex-col gap-3",children:[m.jsx("p",{className:"text-sm text-muted-foreground",children:"Your diagram is live. Share this link:"}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx("input",{type:"text",readOnly:!0,value:u.shareUrl,"data-testid":"export-share-url",className:"min-w-0 flex-1 rounded-md border bg-muted px-3 py-2 text-sm outline-hidden"}),m.jsx(Ft,{type:"button",variant:"outline",size:"icon",onClick:w,"aria-label":"Copy link","data-testid":"export-copy",children:f?m.jsx(Mo,{className:"h-4 w-4","aria-hidden":"true"}):m.jsx(j1,{className:"h-4 w-4","aria-hidden":"true"})}),m.jsx(Ft,{type:"button",variant:"outline",size:"icon",onClick:()=>window.open(u.shareUrl,"_blank"),"aria-label":"View in new tab","data-testid":"export-view",children:m.jsx(Vh,{className:"h-4 w-4","aria-hidden":"true"})})]})]}),m.jsx(pd,{children:m.jsx(Ft,{type:"button",onClick:()=>t(!1),"data-testid":"export-done",children:"Done"})})]})]})})}const GDe=(e,t)=>{if(e.has(t))return e;const n=new Set(e);return n.add(t),n},KDe=(e,t)=>{if(t.length===0)return e;let n=!1;const r=new Set(e);for(const o of t)r.has(o)||(r.add(o),n=!0);return n?r:e},ZDe=(e,t)=>{if(!e.has(t))return e;const n=new Set(e);return n.delete(t),n},XDe=(e,t)=>{if(t.length===0)return e;let n=!1;const r=new Set(e);for(const o of t)r.has(o)&&(r.delete(o),n=!0);return n?r:e},YDe=(e,t)=>{if(e.size===0)return e;const n=new Set(t.map(a=>a.id));let r=!1;const o=new Set(e);for(const a of o)n.has(a)||(o.delete(a),r=!0);return r?o:e},bte=()=>{const[e,t]=g.useState(()=>new Set),n=g.useCallback(c=>{t(l=>GDe(l,c))},[]),r=g.useCallback(c=>{t(l=>KDe(l,c))},[]),o=g.useCallback(c=>{t(l=>ZDe(l,c))},[]),a=g.useCallback(c=>{t(l=>XDe(l,c))},[]),i=g.useCallback(c=>{t(l=>YDe(l,c))},[]),s=g.useCallback(()=>t(new Set),[]);return{ids:e,mark:n,markMany:r,unmark:o,unmarkMany:a,pruneAgainst:i,reset:s}},QDe=(e,t)=>e===t?!0:e==null||t==null||typeof e!=typeof t||typeof e!="object"?!1:JSON.stringify(e)===JSON.stringify(t),JDe=(e,t,n)=>({...e,[t]:{...e[t],...n}}),eqe=(e,t)=>{if(!(t in e))return e;const n={...e};return delete n[t],n},tqe=(e,t)=>{const n=Object.entries(e);if(n.length===0)return e;const r=new Map(t.map(i=>[i.id,i]));let o=!1;const a={...e};for(const[i,s]of n){const c=r.get(i);if(!c)continue;const l={};let u=!1;for(const d of Object.keys(s))QDe(s[d],c[d])?o=!0:(l[d]=s[d],u=!0);u?a[i]=l:(o=!0,delete a[i])}return o?a:e},Cte=()=>{const[e,t]=g.useState({}),n=g.useCallback((i,s)=>{t(c=>JDe(c,i,s))},[]),r=g.useCallback(i=>{t(s=>eqe(s,i))},[]),o=g.useCallback(i=>{t(s=>tqe(s,i))},[]),a=g.useCallback(()=>t({}),[]);return{overrides:e,setOverride:n,dropOverride:r,pruneAgainst:o,reset:a}},nqe=500,rqe=500,oqe={stack:[],cursor:0},aqe=(e,t,n)=>{const r=Date.now(),o=nqe,a=rqe,{stack:i,cursor:s}=e;if(t.coalesceKey&&s>0){const u=i[s-1];if(u&&u.coalesceKey===t.coalesceKey&&r-u.capturedAt<=a){const d=i.slice(0,s);return d[s-1]={...u,do:t.do,capturedAt:r},{stack:d,cursor:s}}}const c=i.slice(0,s);c.push({...t,capturedAt:r});let l=s+1;for(;c.length>o;)c.shift(),l-=1;return l<0&&(l=0),{stack:c,cursor:l}},iqe=e=>e.cursor===0?{state:e,entry:void 0}:{state:{...e,cursor:e.cursor-1},entry:e.stack[e.cursor-1]},sqe=e=>e.cursor===e.stack.length?{state:e,entry:void 0}:{state:{...e,cursor:e.cursor+1},entry:e.stack[e.cursor]},cqe=()=>({stack:[],cursor:0}),lqe=e=>{if(e.cursor===0)return e;const t=e.stack.slice();return t.splice(e.cursor-1,1),{stack:t,cursor:e.cursor-1}},uqe=(e,t)=>t.state,dqe=()=>{const[e,t]=g.useReducer(uqe,oqe),n=g.useRef(e);n.current=e;const r=g.useRef(Promise.resolve()),o=g.useRef(0),a=g.useCallback(p=>{p!==n.current&&(n.current=p,t({type:"replace",state:p}))},[]),i=g.useCallback(p=>{const y={do:p.do,undo:p.undo,coalesceKey:p.coalesceKey,capturedAt:p.capturedAt??Date.now()};a(aqe(n.current,y))},[a]),s=g.useCallback(()=>{o.current=Date.now();const p=r.current.then(()=>{const y=iqe(n.current);if(y.entry)return a(y.state),{entry:y.entry}});return r.current=p.then(()=>{},()=>{}),p},[a]),c=g.useCallback(()=>{o.current=Date.now();const p=r.current.then(()=>{const y=sqe(n.current);if(y.entry)return a(y.state),{entry:y.entry}});return r.current=p.then(()=>{},()=>{}),p},[a]),l=g.useCallback(()=>{a(cqe())},[a]),u=g.useCallback(()=>{a(lqe(n.current))},[a]),d=g.useCallback(()=>{o.current=Date.now()},[]),f=g.useCallback(()=>o.current,[]);return{push:i,undo:s,redo:c,clear:l,dropTop:u,canUndo:e.cursor>0,canRedo:e.cursor<e.stack.length,markMutation:d,lastMutationAt:f}};function hqe({nodes:e,connectors:t,flowPos:n,nodeIdGen:r,connectorIdGen:o,defaultOffset:a={x:24,y:24}}){const i=new Map;for(const p of e)i.set(p.id,r(p.id));let s=Number.POSITIVE_INFINITY,c=Number.POSITIVE_INFINITY;for(const p of e)p.position.x<s&&(s=p.position.x),p.position.y<c&&(c=p.position.y);Number.isFinite(s)||(s=0),Number.isFinite(c)||(c=0);const l=n?n.x-s:a.x,u=n?n.y-c:a.y,d=e.map(p=>{const y=i.get(p.id);if(y===void 0)throw new Error(`paste id missing for ${p.id}`);return{...p,id:y,position:{x:p.position.x+l,y:p.position.y+u}}}),f=t.map(p=>{const y=o(p.id);return{...p,id:y,source:i.get(p.source)??p.source,target:i.get(p.target)??p.target}});return{newNodes:d,newConnectors:f,idMap:i}}const fqe=e=>({type:"imageNode",position:e.position,data:{path:"",alt:e.originalFilename,width:e.dims.width,height:e.dims.height,_uploading:!0}}),pqe=e=>({type:"imageNode",data:Cde(e)}),yqe=e=>({type:"imageNode",position:e.position,data:{path:"",alt:e.originalFilename,width:e.dims.width,height:e.dims.height,_uploadError:e.message}}),Cde=e=>({...TMe(e.path,e.dims,e.lastUsed),alt:e.originalFilename}),mqe=async(e,t)=>{const{nodeId:n,flowId:r,file:o,originalFilename:a,position:i,dims:s,lastUsed:c}=e;t.rememberRetry(n,{file:o,originalFilename:a,position:i,dims:s}),t.setOverride(n,fqe({position:i,dims:s,originalFilename:a}));let l;try{l=(await t.upload(r,o,a)).path}catch(p){const y=p instanceof Error?p.message:String(p);throw t.setOverride(n,yqe({position:i,dims:s,originalFilename:a,message:y})),p}t.setOverride(n,pqe({path:l,dims:s,originalFilename:a,lastUsed:c}));const u=Cde({path:l,dims:s,originalFilename:a,lastUsed:c}),d={id:n,type:"imageNode",position:i,data:u},{id:f}=await t.createNode(r,d);t.forgetRetry(n),t.pushUndo&&t.pushUndo({do:async()=>{await t.createNode(r,{...d,id:f})},undo:async()=>{await t.deleteNode(r,f)}})},gqe=new Set(["INPUT","TEXTAREA","SELECT"]),Lr=e=>e?gqe.has(e.tagName)?!0:e instanceof HTMLElement&&e.isContentEditable:!1,kqe=(e,t,n)=>{const r=e.indexOf(t);if(r<0)return null;const o=e.length,a=[...e];switch(n.op){case"forward":{if(r>=o-1)return null;const i=a[r],s=a[r+1];return i===void 0||s===void 0?null:(a[r]=s,a[r+1]=i,a)}case"backward":{if(r<=0)return null;const i=a[r],s=a[r-1];return i===void 0||s===void 0?null:(a[r]=s,a[r-1]=i,a)}case"toFront":{if(r===o-1)return null;const[i]=a.splice(r,1);return i===void 0?null:(a.push(i),a)}case"toBack":{if(r===0)return null;const[i]=a.splice(r,1);return i===void 0?null:(a.unshift(i),a)}case"toIndex":{const i=Math.min(Math.max(n.index,0),o-1);if(i===r)return null;const[s]=a.splice(r,1);return s===void 0?null:(a.splice(i,0,s),a)}}};function vqe({slug:e,demos:t,detail:n,loading:r,runs:o,nodeEvents:a,statusByNode:i,onPlayNode:s,onRestartDemo:c}){var Vd,$d;const l=t.find(O=>O.slug===e),[u,d]=g.useState([]),[f,p]=g.useState([]),[y,k]=g.useState(null),w=g.useRef(u),v=g.useRef(f);g.useEffect(()=>{w.current=u},[u]),g.useEffect(()=>{v.current=f},[f]);const M=g.useRef(null),x=g.useRef(null),b=g.useRef(null),S=Cte(),C=Cte(),L=bte(),_=bte(),[T,E]=g.useState(null),[P,A]=g.useState(null),[U,R]=g.useState(null),H=g.useRef(null);g.useEffect(()=>{H.current=U},[U]);const[F,V]=g.useState(!1),[z,N]=g.useState(0),I=g.useRef(null),G=g.useRef(null),q=g.useCallback(O=>{G.current=O},[]),j=dqe(),{push:W,dropTop:X,markMutation:Y,clear:oe,lastMutationAt:re}=j,{reset:ie}=S,{reset:we}=C,{reset:ke}=L,{reset:ve}=_;g.useEffect(()=>{d([]),p([]),k(null),ie(),we(),ke(),ve(),E(null),A(null),Jr.current=null,No(!1),xr.current.clear(),j.clear()},[n==null?void 0:n.id]);const xe=g.useCallback((O,B)=>{d(O),p(B)},[]),ee=(Vd=n==null?void 0:n.flow)==null?void 0:Vd.nodes,se=($d=n==null?void 0:n.flow)==null?void 0:$d.connectors,{pruneAgainst:qe}=S,{pruneAgainst:Le}=C,{pruneAgainst:ut}=L,{pruneAgainst:Je}=_;g.useEffect(()=>{ee&&(qe(ee),ut(ee)),Date.now()-re()>2e3&&oe()},[ee,qe,ut,re,oe]),g.useEffect(()=>{if(!ee)return;const O=I.current,B=new Set(ee.map(te=>te.id));if(I.current=B,O===null)return;const Z=S.overrides,$=L.ids;let D=!1;for(const te of B)if(!O.has(te)&&!(te in Z)){D=!0;break}if(!D){for(const te of O)if(!B.has(te)&&!$.has(te)){D=!0;break}}D&&N(te=>te+1)},[ee]),g.useEffect(()=>{se&&(Le(se),Je(se)),Date.now()-re()>2e3&&oe()},[se,Le,Je,re,oe]),g.useEffect(()=>{if(!(!ee||!T)&&ee.length===T.length){for(let O=0;O<ee.length;O++){const B=ee[O],Z=T[O];if(!B||B.id!==Z)return}E(null)}},[ee,T]);const ce=(n==null?void 0:n.id)??null,Q=g.useMemo(()=>ce?jMe({baseUrl:"",flowId:ce}):null,[ce]),[ue,ge]=g.useState(!1),{setOverride:be,dropOverride:De}=S,ne=g.useRef(S.overrides);g.useEffect(()=>{ne.current=S.overrides},[S.overrides]);const he=g.useCallback((O,B)=>{var $;if(!ce||!Q)return;const Z=($=ee==null?void 0:ee.find(D=>D.id===O))==null?void 0:$.position;be(O,{position:B}),A(null),Y(),Z&&W({do:async()=>{await Q.updateNodePosition(O,B)},undo:async()=>{await Q.updateNodePosition(O,Z)},coalesceKey:`node:${O}:position`}),Q.updateNodePosition(O,B).catch(D=>{De(O),Z&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateNodePosition failed",D)})},[ce,Q,ee,be,De,W,X,Y]),Ee=g.useCallback(O=>{if(!ce||!Q||O.length===0)return;const B=ne.current,Z=O.map($=>{var Pe;const D=ee==null?void 0:ee.find(Ce=>Ce.id===$.id);if(!D)return null;const te=((Pe=B[$.id])==null?void 0:Pe.position)??D.position;return{id:$.id,prev:te,next:$.position}}).filter($=>$!==null);if(Z.length!==0){for(const $ of Z)be($.id,{position:$.next});A(null),Y(),W({do:async()=>{await Promise.allSettled(Z.map($=>Q.updateNodePosition($.id,$.next)))},undo:async()=>{await Promise.allSettled(Z.map($=>Q.updateNodePosition($.id,$.prev)))}}),Promise.all(Z.map(async $=>{try{return await Q.updateNodePosition($.id,$.next),null}catch(D){return De($.id),D instanceof Error?D.message:String(D)}})).then($=>{const D=$.find(te=>te!==null);D&&A(D)})}},[ce,Q,ee,be,De,W,Y]),Be=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(te=>te.id===O),$=Z?{width:Z.data.width,height:Z.data.height,position:{x:Z.position.x,y:Z.position.y}}:void 0,D={width:B.width,height:B.height,position:{x:B.x,y:B.y}};be(O,{position:D.position,data:{width:D.width,height:D.height}}),A(null),Y(),$&&W({do:async()=>{await Q.updateNode(O,D)},undo:async()=>{await Q.updateNode(O,$)},coalesceKey:`node:${O}:resize`}),Q.updateNode(O,D).catch(te=>{De(O),$&&X(),A(te instanceof Error?te.message:String(te)),console.error("updateNode resize failed",te)})},[ce,Q,ee,be,De,W,X,Y]),Ge=g.useCallback(O=>{if(!ce||!Q)return;const B=ee==null?void 0:ee.find(D=>D.id===O);if(!B)return;const Z={autoSize:B.data.autoSize,width:B.data.width,height:B.data.height},$={autoSize:!0};be(O,{data:{autoSize:!0,width:void 0,height:void 0}}),A(null),Y(),W({do:async()=>{await Q.updateNode(O,$)},undo:async()=>{await Q.updateNode(O,Z)},coalesceKey:`node:${O}:fit-to-content`}),Q.updateNode(O,$).catch(D=>{De(O),X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode (fit-to-content) failed",D)})},[ce,Q,ee,be,De,W,X,Y]),Pt=g.useCallback(O=>{if(!ce||!Q||O.length===0)return;const B=[];for(const $ of O){const D=ee==null?void 0:ee.find(Xe=>Xe.id===$.id);if(!D)continue;const te=D.data,Pe={position:{x:D.position.x,y:D.position.y}};te.width!==void 0&&(Pe.width=te.width),te.height!==void 0&&(Pe.height=te.height);const Ce={position:$.position};$.width!==void 0&&(Ce.width=$.width),$.height!==void 0&&(Ce.height=$.height),B.push({id:$.id,prev:Pe,next:Ce})}if(B.length===0)return;for(const $ of B){const D={};$.next.width!==void 0&&(D.width=$.next.width),$.next.height!==void 0&&(D.height=$.next.height),be($.id,{position:$.next.position,...Object.keys(D).length>0?{data:D}:{}})}A(null),Y();const Z=B.map($=>$.id).sort();W({do:async()=>{await Promise.allSettled(B.map($=>Q.updateNode($.id,$.next)))},undo:async()=>{await Promise.allSettled(B.map($=>Q.updateNode($.id,$.prev)))},coalesceKey:`multi:resize:${Z.join(",")}`}),Promise.all(B.map(async $=>{try{return await Q.updateNode($.id,$.next),null}catch(D){return De($.id),D instanceof Error?D.message:String(D)}})).then($=>{const D=$.find(te=>te!==null);D&&A(D)})},[ce,Q,ee,be,De,W,Y]),{setOverride:Oe,dropOverride:Te}=C,_t=g.useCallback((O,B)=>{be(O,{data:B})},[be]),nr=g.useCallback((O,B)=>{for(const Z of O)be(Z,{data:B})},[be]),Nt=g.useCallback((O,B)=>{Oe(O,B)},[Oe]),Nn=g.useCallback((O,B)=>{if(!ce||!Q)return;ZQ(Ei,B);const Z=ee==null?void 0:ee.find(D=>D.id===O);let $=null;if(Z){$={};const D=Z.data;for(const te of Object.keys(B))$[te]=D[te]}if(be(O,{data:B}),A(null),Y(),$){const D=$;W({do:async()=>{await Q.updateNode(O,B)},undo:async()=>{await Q.updateNode(O,D)},coalesceKey:`node:${O}:style`})}Q.updateNode(O,B).catch(D=>{De(O),$&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode style failed",D)})},[ce,Q,ee,be,De,W,X,Y]),tn=g.useCallback((O,B)=>{if(!ce||!Q||O.length===0)return;ZQ(Ei,B);const Z=O.map($=>{const D=ee==null?void 0:ee.find(Ce=>Ce.id===$);if(!D)return null;const te=D.data,Pe={};for(const Ce of Object.keys(B))Pe[Ce]=te[Ce];return{id:$,prev:Pe}}).filter($=>$!==null);if(Z.length!==0){for(const $ of Z)be($.id,{data:B});A(null),Y(),W({do:async()=>{await Promise.allSettled(Z.map($=>Q.updateNode($.id,B)))},undo:async()=>{await Promise.allSettled(Z.map($=>Q.updateNode($.id,$.prev)))}}),Promise.all(Z.map(async $=>{try{return await Q.updateNode($.id,B),null}catch(D){return De($.id),D instanceof Error?D.message:String(D)}})).then($=>{const D=$.find(te=>te!==null);D&&A(D)})}},[ce,Q,ee,be,De,W,Y]),Bu=g.useCallback(O=>{if(!ce||!Q||O.length===0)return;const B=O.map(D=>{const te=ee==null?void 0:ee.find(Ce=>Ce.id===D);if(!te)return null;const Pe=te.data;return{id:D,prev:Pe.locked===!0}}).filter(D=>D!==null);if(B.length===0)return;const Z=B.some(D=>!D.prev),$=B.filter(D=>D.prev!==Z);if($.length!==0){for(const D of $)be(D.id,{data:{locked:Z}});A(null),Y(),W({do:async()=>{await Promise.allSettled($.map(D=>Q.updateNode(D.id,{locked:Z})))},undo:async()=>{await Promise.allSettled($.map(D=>Q.updateNode(D.id,{locked:D.prev})))}}),Promise.all($.map(async D=>{try{return await Q.updateNode(D.id,{locked:Z}),null}catch(te){return De(D.id),te instanceof Error?te.message:String(te)}})).then(D=>{const te=D.find(Pe=>Pe!==null);te&&A(te)})}},[ce,Q,ee,be,De,W,Y]),Vu=g.useCallback((O,B)=>{if(!ce||!Q)return;EMe(Ei,B);const Z=se==null?void 0:se.find(D=>D.id===O);let $=null;if(Z){$={};const D=Z;for(const te of Object.keys(B))$[te]=D[te]}if(Oe(O,B),A(null),Y(),$){const D=$;W({do:async()=>{await Q.updateConnector(O,B)},undo:async()=>{await Q.updateConnector(O,D)},coalesceKey:`connector:${O}:style`})}Q.updateConnector(O,B).catch(D=>{Te(O),$&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateConnector failed",D)})},[ce,Q,se,Oe,Te,W,X,Y]),{mark:pa,markMany:ya,unmark:Gr,unmarkMany:ki}=L,{mark:ma,markMany:gr,unmark:Kr,unmarkMany:kr}=_,$u=g.useCallback(O=>{if(!ce||!Q)return;const B=ee==null?void 0:ee.find(Ce=>Ce.id===O);if(!B||B.data.locked===!0)return;const Z=(se??[]).filter(Ce=>Ce.source===O||Ce.target===O),$=Z.map(Ce=>Ce.id),D=new Set($);A(null),pa(O),$.length>0&&gr($),d(Ce=>Ce.filter(Xe=>Xe!==O)),p(Ce=>Ce.filter(Xe=>!D.has(Xe))),Y();const te=B,Pe=Z;W({do:async()=>{pa(O),$.length>0&&gr($),await Q.deleteNode(O)},undo:async()=>{Gr(O),$.length>0&&kr($),await Q.createNode({id:te.id,type:te.type,position:te.position,data:te.data});for(const Ce of Pe)await Q.createConnector({...Ce,id:Ce.id})}}),Q.deleteNode(O).catch(Ce=>{Gr(O),$.length>0&&kr($),X(),A(Ce instanceof Error?Ce.message:String(Ce)),console.error("deleteNode failed",Ce)})},[ce,Q,ee,se,pa,gr,Gr,kr,W,X,Y]),Uu=g.useCallback((O,B)=>{if(!ce||!Q||!ee)return;const Z=T??ee.map(te=>te.id),$=kqe(Z,O,B);if(!$)return;const D=Z.indexOf(O);E($),A(null),Y(),W({do:async()=>{await Q.reorderNode(O,B)},undo:async()=>{await Q.reorderNode(O,{op:"toIndex",index:D})}}),Q.reorderNode(O,B).catch(te=>{E(null),X(),A(te instanceof Error?te.message:String(te)),console.error("reorderNode failed",te)})},[ce,Q,ee,T,W,X,Y]);g.useCallback(O=>{if(!ce||!Q)return;const B=se==null?void 0:se.find($=>$.id===O);if(!B)return;A(null),ma(O),p($=>$.filter(D=>D!==O)),Y();const Z=B;W({do:async()=>{ma(O),await Q.deleteConnector(O)},undo:async()=>{Kr(O),await Q.createConnector({...Z,id:Z.id})}}),Q.deleteConnector(O).catch($=>{Kr(O),X(),A($ instanceof Error?$.message:String($)),console.error("deleteConnector failed",$)})},[ce,Q,se,ma,Kr,W,X,Y]);const Fe=g.useCallback((O,B)=>{if(!ce||!Q||O.length===0&&B.length===0)return;const Z=O,$=new Set((ee??[]).filter(_e=>_e.data.locked===!0).map(_e=>_e.id)),D=Z.filter(_e=>!$.has(_e)),te=new Set(D),Pe=D.map(_e=>ee==null?void 0:ee.find(it=>it.id===_e)).filter(_e=>!!_e),Ce=(se??[]).filter(_e=>te.has(_e.source)||te.has(_e.target)),Xe=new Set(Ce.map(_e=>_e.id)),Dt=B.map(_e=>se==null?void 0:se.find(it=>it.id===_e)).filter(_e=>!!_e).filter(_e=>!Xe.has(_e.id)).filter(_e=>!($.has(_e.source)&&$.has(_e.target)));if(Pe.length===0&&Ce.length===0&&Dt.length===0)return;A(null);const Xt=Pe.map(_e=>_e.id),Gt=[...Ce.map(_e=>_e.id),...Dt.map(_e=>_e.id)];Xt.length>0&&ya(Xt),Gt.length>0&&gr(Gt);const Mr=Pe;d(_e=>_e.filter(it=>!te.has(it)));const wa=new Set(Dt.map(_e=>_e.id));p(_e=>_e.filter(it=>!wa.has(it)&&!Xe.has(it))),Y(),W({do:async()=>{Xt.length>0&&ya(Xt),Gt.length>0&&gr(Gt);for(const _e of Mr)await Q.deleteNode(_e.id).catch(()=>{});await Promise.allSettled(Dt.map(_e=>Q.deleteConnector(_e.id)))},undo:async()=>{Xt.length>0&&ki(Xt),Gt.length>0&&kr(Gt);for(let _e=Mr.length-1;_e>=0;_e--){const it=Mr[_e];it&&await Q.createNode({id:it.id,type:it.type,position:it.position,data:it.data})}for(const _e of[...Ce,...Dt])await Q.createConnector({..._e,id:_e.id})}});const Xu=new Map;for(const _e of Pe)Xu.set(_e.id,Ce.filter(it=>it.source===_e.id||it.target===_e.id).map(it=>it.id));(async()=>{const _e=[];for(const je of Mr)try{await Q.deleteNode(je.id)}catch(st){Gr(je.id);const rn=Xu.get(je.id)??[];rn.length>0&&kr(rn),_e.push(st instanceof Error?st.message:String(st))}const it=await Promise.all(Dt.map(async je=>{try{return await Q.deleteConnector(je.id),null}catch(st){return Kr(je.id),st instanceof Error?st.message:String(st)}}));for(const je of it)je!==null&&_e.push(je);_e.length>0&&_e[0]!==void 0&&A(_e[0])})()},[ce,Q,ee,se,ya,gr,Gr,ki,Kr,kr,W,Y]);g.useEffect(()=>{M.current=Fe},[Fe]),g.useEffect(()=>{const O=B=>{if(B.key!=="Delete"&&B.key!=="Backspace"||Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]'))return;const Z=w.current,$=v.current;Z.length===0&&$.length===0||(B.preventDefault(),Fe(Z,$))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[Fe]);const{undo:bt,redo:Zr,canUndo:Xr,canRedo:zn}=j;g.useEffect(()=>{const O=async B=>{if((B.metaKey||B.ctrlKey)&&B.key.toLowerCase()==="z"&&!Lr(document.activeElement)){if(B.preventDefault(),B.shiftKey){if(!zn)return;try{const Z=await Zr();Z!=null&&Z.entry&&await Z.entry.do()}catch(Z){A(Z instanceof Error?Z.message:String(Z)),console.error("redo failed",Z)}return}if(Xr)try{const Z=await bt();Z!=null&&Z.entry&&await Z.entry.undo()}catch(Z){A(Z instanceof Error?Z.message:String(Z)),console.error("undo failed",Z)}}};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[bt,Zr,Xr,zn]);const vr=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(te=>te.id===O),D=(Z&&"name"in Z.data?Z.data.name:void 0)??"";be(O,{data:{name:B}}),A(null),Y(),Z&&W({do:async()=>{await Q.updateNode(O,{name:B})},undo:async()=>{await Q.updateNode(O,{name:D})},coalesceKey:`node:${O}:name`}),Q.updateNode(O,{name:B}).catch(te=>{Z&&X(),A(te instanceof Error?te.message:String(te)),console.error("updateNode name failed",te)})},[ce,Q,ee,be,W,X,Y]),Ro=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(D=>D.id===O);if(!Z)return;const $=Z.data.description??"";be(O,{data:{description:B}}),A(null),Y(),W({do:async()=>{await Q.updateNode(O,{description:B})},undo:async()=>{await Q.updateNode(O,{description:$})},coalesceKey:`node:${O}:description`}),Q.updateNode(O,{description:B}).catch(D=>{X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode description failed",D)})},[ce,Q,ee,be,W,X,Y]),rr=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(D=>D.id===O);if(!Z)return;const $=Z.data.detail??"";be(O,{data:{detail:B}}),A(null),Y(),W({do:async()=>{await Q.updateNode(O,{detail:B})},undo:async()=>{await Q.updateNode(O,{detail:$})},coalesceKey:`node:${O}:detail`}),Q.updateNode(O,{detail:B}).catch(D=>{X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode detail failed",D)})},[ce,Q,ee,be,W,X,Y]),Yr=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=ee==null?void 0:ee.find(D=>D.id===O);if(!Z)return;const $="icon"in Z.data?Z.data.icon??null:null;be(O,{data:{icon:B??void 0}}),A(null),Y(),W({do:async()=>{await Q.updateNode(O,{icon:B})},undo:async()=>{await Q.updateNode(O,{icon:$})},coalesceKey:`node:${O}:icon`}),Q.updateNode(O,{icon:B}).catch(D=>{X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode icon failed",D)})},[ce,Q,ee,be,W,X,Y]),hn=g.useCallback((O,B,Z)=>{if(!ce||!Q)return;A(null);const $=`node-${crypto.randomUUID()}`,D=YQ(O,Z,E0(Ei).node),te={id:$,type:"shapeNode",position:B,data:D};be($,{id:$,type:"shapeNode",position:B,data:D}),Y(),Q.createNode(te).then(({id:Ce})=>{W({do:async()=>{await Q.createNode({...te,id:Ce})},undo:async()=>{await Q.deleteNode(Ce)}})}).catch(Ce=>{De($),A(Ce instanceof Error?Ce.message:String(Ce)),console.error("createNode failed",Ce)})},[ce,Q,be,De,W,Y]),zt=g.useCallback((O,B)=>{if(!ce||!Q)return;A(null);const Z=`node-${crypto.randomUUID()}`,$={icon:O,width:ud.width,height:ud.height},D={id:Z,type:"iconNode",position:B,data:$};be(Z,{id:Z,type:"iconNode",position:B,data:$}),d([Z]),Y(),Q.createNode(D).then(({id:Pe})=>{W({do:async()=>{await Q.createNode({...D,id:Pe})},undo:async()=>{await Q.deleteNode(Pe)}})}).catch(Pe=>{De(Z),A(Pe instanceof Error?Pe.message:String(Pe)),console.error("createNode (icon) failed",Pe)})},[ce,Q,be,De,W,Y]),To=g.useCallback(O=>{if(!ce||!Q)return;A(null);const B=`node-${crypto.randomUUID()}`,Z=`blocks/${B}.html`,$={id:B,type:"htmlNode",position:O.position,data:{}},D={id:B,type:"htmlNode",position:O.position,data:{htmlPath:Z}};be(B,D),d([B]),Y(),Q.createNode($).then(({id:te})=>{W({do:async()=>{await Q.createNode({...$,id:te})},undo:async()=>{await Q.deleteNode(te)}})}).catch(te=>{De(B),A(te instanceof Error?te.message:String(te)),console.error("createNode (htmlNode) failed",te)})},[ce,Q,be,De,W,Y]),xr=g.useRef(new Map),vi=g.useCallback((O,B)=>{xr.current.set(O,B)},[]),xi=g.useCallback(O=>{xr.current.delete(O)},[]),jo=g.useCallback(O=>{!ce||!Q||(A(null),Y(),mqe({...O,flowId:ce,lastUsed:E0(Ei).node},{upload:(B,Z,$)=>Q.uploadImage(Z,$),createNode:async(B,Z)=>{const{id:$}=await Q.createNode(Z);return{id:$}},deleteNode:async(B,Z)=>(await Q.deleteNode(Z),{ok:!0}),setOverride:be,pushUndo:W,rememberRetry:vi,forgetRetry:xi}).catch(B=>{console.error("image-upload-flow failed",B)}))},[ce,Q,be,W,Y,vi,xi]),Lt=g.useCallback(O=>{if(!ce||!Q)return;const B=`node-${crypto.randomUUID()}`;jo({nodeId:B,...O})},[ce,Q,jo]),wi=g.useCallback(O=>{const B=xr.current.get(O);B&&jo({nodeId:O,...B})},[jo]),[Dn,ga]=g.useState({open:!1,mode:"insert"}),or=g.useCallback((O,B)=>{ga({open:!0,mode:O,nodeId:B})},[]),wr=g.useCallback(()=>{ga(O=>({...O,open:!1}))},[]),Wu=g.useCallback(()=>{or("insert")},[or]),Mi=g.useCallback(O=>or("replace",O),[or]),bi=g.useCallback(O=>{if(kMe(O),Dn.mode==="replace"&&Dn.nodeId){if(ce&&Q){const B=Dn.nodeId,Z=ee==null?void 0:ee.find(D=>D.id===B),$=(Z==null?void 0:Z.type)==="iconNode"?Z.data.icon:void 0;if(be(B,{data:{icon:O}}),A(null),Y(),$!==void 0){const D=$;W({do:async()=>{await Q.updateNode(B,{icon:O})},undo:async()=>{await Q.updateNode(B,{icon:D})},coalesceKey:`node:${B}:icon`})}Q.updateNode(B,{icon:O}).catch(D=>{De(B),$!==void 0&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateNode (icon replace) failed",D)})}}else{const B=G.current;if(B&&ce){const Z=mMe(B,{width:window.innerWidth,height:window.innerHeight});zt(O,Z)}}wr()},[Dn.mode,Dn.nodeId,ce,Q,ee,be,De,W,X,Y,zt,wr]),ka=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=se==null?void 0:se.find(D=>D.id===O),$=Z==null?void 0:Z.label;Oe(O,{label:B}),A(null),Y(),Z&&W({do:async()=>{await Q.updateConnector(O,{label:B})},undo:async()=>{await Q.updateConnector(O,{label:$})},coalesceKey:`connector:${O}:label`}),Q.updateConnector(O,{label:B}).catch(D=>{Z&&X(),A(D instanceof Error?D.message:String(D)),console.error("updateConnector label failed",D)})},[ce,Q,se,Oe,W,X,Y]),Mn=g.useCallback((O,B,Z)=>{if(!ce||!Q)return;const $=`conn-${crypto.randomUUID()}`,D=Z==null?void 0:Z.targetPin,te=E0(Ei).connector,Pe={id:$,source:O,target:B,sourceHandleAutoPicked:!0,targetHandleAutoPicked:!0,...D?{targetPin:D}:{},...te,kind:"default"},Ce={id:$,source:O,target:B,sourceHandleAutoPicked:!0,targetHandleAutoPicked:!0,...D?{targetPin:D}:{},...te,kind:"default"};Oe($,Pe),A(null),Y(),Q.createConnector(Ce).then(({id:Xe})=>{W({do:async()=>{await Q.createConnector({...Ce,id:Xe})},undo:async()=>{await Q.deleteConnector(Xe)}})}).catch(Xe=>{Te($),A(Xe instanceof Error?Xe.message:String(Xe)),console.error("createConnector failed",Xe)})},[ce,Q,Oe,Te,W,Y]),Qr=g.useCallback(({sourceNodeId:O,position:B,shape:Z})=>{if(!ce||!Q)return;A(null);const $=`node-${crypto.randomUUID()}`,D=`conn-${crypto.randomUUID()}`,te=fR[Z],Pe=E0(Ei),Ce=YQ(Z,te,Pe.node),Xe={id:$,type:"shapeNode",position:B,data:Ce},Dt={id:D,source:O,target:$,sourceHandleAutoPicked:!0,targetHandleAutoPicked:!0,...Pe.connector,kind:"default"};be($,{id:$,type:"shapeNode",position:B,data:Ce}),Oe(D,Dt),k($),Y(),(async()=>{try{await Q.createNode(Xe),await Q.createConnector(Dt),W({do:async()=>{await Q.createNode(Xe),await Q.createConnector(Dt)},undo:async()=>{Te(D),De($),await Q.deleteConnector(D).catch(()=>{}),await Q.deleteNode($).catch(()=>{})}})}catch(Gt){De($),Te(D),A(Gt instanceof Error?Gt.message:String(Gt)),console.error("createAndConnectFromPane failed",Gt)}})()},[ce,Q,be,De,Oe,Te,W,Y]),Jr=g.useRef(null),[Gu,No]=g.useState(!1),ar=g.useCallback(O=>{if(!ee)return;const B=new Set(O),Z=ee.filter(D=>B.has(D.id));if(Z.length===0)return;const $=(se??[]).filter(D=>B.has(D.source)&&B.has(D.target));Jr.current=JSON.parse(JSON.stringify({nodes:Z,connectors:$})),No(!0)},[ee,se]),bn=g.useCallback(O=>{if(!ce||!Q)return;const B=Jr.current;if(!B||B.nodes.length===0)return;const{newNodes:Z,newConnectors:$}=hqe({nodes:B.nodes,connectors:B.connectors,flowPos:O,nodeIdGen:()=>`node-${crypto.randomUUID()}`,connectorIdGen:()=>`conn-${crypto.randomUUID()}`});for(const D of Z)be(D.id,D);for(const D of $)Oe(D.id,D);d(Z.map(D=>D.id)),p($.map(D=>D.id)),A(null),Y(),(async()=>{try{for(const D of Z)await Q.createNode({id:D.id,type:D.type,position:D.position,data:D.data});for(const D of $)await Q.createConnector(D);W({do:async()=>{for(const D of Z)await Q.createNode({id:D.id,type:D.type,position:D.position,data:D.data});for(const D of $)await Q.createConnector(D)},undo:async()=>{await Promise.allSettled($.map(D=>Q.deleteConnector(D.id))),await Promise.allSettled(Z.map(D=>Q.deleteNode(D.id)))}})}catch(D){for(const te of Z)De(te.id);for(const te of $)Te(te.id);A(D instanceof Error?D.message:String(D)),console.error("paste failed",D)}})()},[ce,Q,be,De,Oe,Te,Y,W]);g.useEffect(()=>{const O=B=>{const Z=LMe({event:B,isEditableActive:Lr(document.activeElement),hasNodes:!!ee&&ee.length>0,hasConnectors:!!se&&se.length>0,selectedIds:w.current,hasClipboard:!!Jr.current});if(Z.type!=="noop"&&!(Z.type==="copy"||Z.type==="paste")){if(B.preventDefault(),Z.type==="selectAll"){d((ee??[]).map($=>$.id)),p((se??[]).map($=>$.id));return}ar([...Z.ids]),bn(null)}};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[ee,se,ar,bn]),g.useEffect(()=>{const O=B=>{const Z=bMe(B);if(!Z||Lr(document.activeElement))return;const $=w.current;if($.length===0)return;const D=S.overrides,te=(ee??[]).map(Ce=>{var Dt;const Xe=((Dt=D[Ce.id])==null?void 0:Dt.position)??Ce.position;return{id:Ce.id,position:Xe}}),Pe=SMe(Z,$,te);if(Pe.length!==0)if(B.preventDefault(),Pe.length===1){const Ce=Pe[0];Ce&&he(Ce.id,Ce.position)}else Ee(Pe)};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[ee,S.overrides,he,Ee]),g.useEffect(()=>{const O=B=>{const Z=CMe(B);if(!Z||Lr(document.activeElement))return;B.preventDefault();const $=G.current;$&&(Z==="fit"?$.fitView({padding:.2,duration:200}):Z==="in"?$.zoomIn({duration:150}):$.zoomOut({duration:150}))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]);const fn=g.useCallback(O=>{if(!ce||!Q||!ee)return;const B=S.overrides,Z=G.current,$=O==="selection"?new Set(w.current):null,D=$?ee.filter(je=>$.has(je.id)):ee;if(D.length<2)return;const te=new Set(D.map(je=>je.id)),Pe=(se??[]).filter(je=>te.has(je.source)&&te.has(je.target)),Ce=D.map(je=>{var Vf;const st=((Vf=B[je.id])==null?void 0:Vf.position)??je.position,rn=Z==null?void 0:Z.getInternalNode(je.id),Yt=rn==null?void 0:rn.measured,Ci=je.data,oo=(Yt==null?void 0:Yt.width)??Ci.width??200,tj=(Yt==null?void 0:Yt.height)??Ci.height??120;return{id:je.id,width:oo,height:tj,position:st}}),Xe=Pe.map(je=>({source:je.source,target:je.target})),Dt=rae(Ce,Xe);let Xt=Number.POSITIVE_INFINITY,Gt=Number.POSITIVE_INFINITY,Mr=Number.POSITIVE_INFINITY,wa=Number.POSITIVE_INFINITY;for(const je of Ce){je.position.x<Xt&&(Xt=je.position.x),je.position.y<Gt&&(Gt=je.position.y);const st=Dt.get(je.id);st&&(st.x<Mr&&(Mr=st.x),st.y<wa&&(wa=st.y))}const Xu=Number.isFinite(Xt)&&Number.isFinite(Mr)?Xt-Mr:0,_e=Number.isFinite(Gt)&&Number.isFinite(wa)?Gt-wa:0,it=[];for(const je of Ce){const st=Dt.get(je.id);if(!st)continue;const rn={x:st.x+Xu,y:st.y+_e},Yt=rn.x-je.position.x,Ci=rn.y-je.position.y;Math.abs(Yt)<1&&Math.abs(Ci)<1||it.push({id:je.id,prev:je.position,next:rn})}if(it.length!==0){A(null);for(const je of it)be(je.id,{position:je.next});Y(),W({do:async()=>{await Promise.allSettled(it.map(je=>Q.updateNodePosition(je.id,je.next)))},undo:async()=>{await Promise.allSettled(it.map(je=>Q.updateNodePosition(je.id,je.prev)))}}),Promise.all(it.map(async je=>{try{return await Q.updateNodePosition(je.id,je.next),null}catch(st){return De(je.id),st instanceof Error?st.message:String(st)}})).then(je=>{const st=je.filter(Yt=>Yt!==null),rn=st[0];rn&&(A(st.length===1?rn:`${st.length} node updates failed (first: ${rn})`),console.error("Tidy: some updateNodePosition calls failed",st))})}},[ce,Q,ee,se,S.overrides,be,De,W,Y]);g.useEffect(()=>{const O=B=>{if(!(B.metaKey||B.ctrlKey)||!B.shiftKey||B.altKey||B.key.toLowerCase()!=="l"||Lr(document.activeElement))return;B.preventDefault();const Z=w.current.length>0?"selection":"all";fn(Z)};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[fn]);const va=g.useCallback(()=>{const O=w.current.length>0?"selection":"all";fn(O)},[fn]);g.useEffect(()=>{const O=B=>{if(Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]'))return;const Z=IMe(B);if(Z===null)return;const $=Z==="select"?null:Z;if(H.current===$){R(null);return}R($)};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]),g.useEffect(()=>{const O=B=>{B.key==="Escape"&&(Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]')||(w.current.length>0&&d([]),v.current.length>0&&p([]),H.current!==null&&R(null)))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]),g.useEffect(()=>{const O=B=>{if(B.key.toLowerCase()!=="f"||B.metaKey||B.ctrlKey||B.shiftKey||B.altKey||Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]'))return;const Z=w.current;if(Z.length===0)return;const $=G.current;$&&$.fitView({nodes:Z.map(D=>({id:D})),padding:.2,duration:200})};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]),g.useEffect(()=>{const O=B=>{if(B.key!=="1"||B.metaKey||B.ctrlKey||B.shiftKey||B.altKey||Lr(document.activeElement)||document.querySelector('[data-testid="inline-edit-input"]'))return;const Z=G.current;if(!Z)return;const{x:$,y:D}=Z.getViewport();Z.setViewport({x:$,y:D,zoom:1},{duration:150})};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]);const ir=g.useCallback(O=>{var B,Z,$;switch(O){case"tool.select":R(null);return;case"tool.rectangle":R("rectangle");return;case"tool.ellipse":R("ellipse");return;case"tool.text":R("text");return;case"tool.sticky":R("sticky");return;case"tool.database":R("database");return;case"edit.undo":{if(!Xr)return;(async()=>{try{const D=await bt();D!=null&&D.entry&&await D.entry.undo()}catch(D){A(D instanceof Error?D.message:String(D)),console.error("undo failed",D)}})();return}case"edit.redo":{if(!zn)return;(async()=>{try{const D=await Zr();D!=null&&D.entry&&await D.entry.do()}catch(D){A(D instanceof Error?D.message:String(D)),console.error("redo failed",D)}})();return}case"edit.copy":{const D=w.current;if(D.length===0)return;ar([...D]);return}case"edit.paste":bn(null);return;case"edit.duplicate":{const D=w.current;if(D.length===0)return;ar([...D]),bn(null);return}case"edit.delete":{const D=w.current,te=v.current;if(D.length===0&&te.length===0)return;Fe([...D],[...te]);return}case"edit.selectAll":d((ee??[]).map(D=>D.id)),p((se??[]).map(D=>D.id));return;case"view.fit":{const D=G.current;if(!D)return;D.fitView({padding:.2,duration:200});return}case"view.zoomIn":{const D=G.current;if(!D)return;D.zoomIn({duration:150});return}case"view.zoomOut":{const D=G.current;if(!D)return;D.zoomOut({duration:150});return}case"view.zoom100":{const D=G.current;if(!D)return;const{x:te,y:Pe}=D.getViewport();D.setViewport({x:te,y:Pe,zoom:1},{duration:150});return}case"view.zoomToSelection":{const D=w.current;if(D.length===0)return;const te=G.current;if(!te)return;te.fitView({nodes:D.map(Pe=>({id:Pe})),padding:.2,duration:200});return}case"layout.tidy":{const D=w.current.length>0?"selection":"all";fn(D);return}case"selection.deselect":w.current.length>0&&d([]),v.current.length>0&&p([]),H.current!==null&&R(null);return;case"help.commandPalette":V(!0);return;case"export.pdf":{(B=b.current)==null||B.exportPdf();return}case"export.png":{(Z=b.current)==null||Z.exportPng();return}case"session.reset":{($=x.current)==null||$.call(x);return}}},[Xr,zn,bt,Zr,ar,bn,Fe,ee,se,fn]);g.useEffect(()=>{const O=B=>{(B.metaKey||B.ctrlKey)&&(B.shiftKey||B.altKey||B.key.toLowerCase()==="p"&&(B.preventDefault(),!Lr(document.activeElement)&&ir("help.commandPalette")))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[ir]),g.useEffect(()=>{x.current=c??null},[c]);const eo=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=se==null?void 0:se.find(te=>te.id===O),$=Z?{source:Z.source,target:Z.target,sourceHandle:Z.sourceHandle,targetHandle:Z.targetHandle,sourceHandleAutoPicked:Z.sourceHandleAutoPicked,targetHandleAutoPicked:Z.targetHandleAutoPicked,sourcePin:Z.sourcePin??null,targetPin:Z.targetPin??null}:null,D={...B.source!==void 0?{source:B.source}:{},...B.target!==void 0?{target:B.target}:{},...B.sourceHandle!==void 0?{sourceHandle:B.sourceHandle===null?void 0:B.sourceHandle}:{},...B.targetHandle!==void 0?{targetHandle:B.targetHandle===null?void 0:B.targetHandle}:{},...B.sourceHandleAutoPicked!==void 0?{sourceHandleAutoPicked:B.sourceHandleAutoPicked}:{},...B.targetHandleAutoPicked!==void 0?{targetHandleAutoPicked:B.targetHandleAutoPicked}:{},...B.sourcePin!==void 0?{sourcePin:B.sourcePin===null?void 0:B.sourcePin}:{},...B.targetPin!==void 0?{targetPin:B.targetPin===null?void 0:B.targetPin}:{}};if(Oe(O,D),A(null),Y(),$){const te=$;W({do:async()=>{await Q.updateConnector(O,B)},undo:async()=>{await Q.updateConnector(O,te)},coalesceKey:`connector:${O}:reconnect`})}Q.updateConnector(O,B).catch(te=>{Te(O),$&&X(),A(te instanceof Error?te.message:String(te)),console.error("updateConnector reconnect failed",te)})},[ce,Q,se,Oe,Te,W,X,Y]),to=g.useCallback((O,B,Z)=>{if(!ce||!Q)return;const $=se==null?void 0:se.find(Pe=>Pe.id===O),D=$?B==="source"?$.sourcePin:$.targetPin:void 0,te=B==="source"?"sourcePin":"targetPin";if(Oe(O,{[te]:Z}),A(null),Y(),$){const Pe={[te]:D??null};W({do:async()=>{await Q.updateConnector(O,{[te]:Z})},undo:async()=>{await Q.updateConnector(O,Pe)},coalesceKey:`connector:${O}:${te}`})}Q.updateConnector(O,{[te]:Z}).catch(Pe=>{Te(O),$&&X(),A(Pe instanceof Error?Pe.message:String(Pe)),console.error("updateConnector pin failed",Pe)})},[ce,Q,se,Oe,Te,W,X,Y]),zo=g.useCallback((O,B)=>{if(!ce||!Q)return;const Z=se==null?void 0:se.find(te=>te.id===O),$=Z?B==="source"?Z.sourcePin:Z.targetPin:void 0;if(!$)return;const D=B==="source"?"sourcePin":"targetPin";Oe(O,{[D]:void 0}),A(null),Y(),W({do:async()=>{await Q.updateConnector(O,{[D]:null})},undo:async()=>{await Q.updateConnector(O,{[D]:$})}}),Q.updateConnector(O,{[D]:null}).catch(te=>{Te(O),X(),A(te instanceof Error?te.message:String(te)),console.error("updateConnector unpin failed",te)})},[ce,Q,se,Oe,Te,W,X,Y]),rt=n==null?void 0:n.flow,no=S.overrides,qn=C.overrides,nn=L.ids,ro=_.ids,Ku=g.useMemo(()=>{if(!rt||u.length===0)return[];const O=new Map(rt.nodes.map(Z=>[Z.id,Z])),B=[];for(const Z of u){const $=O.get(Z);if(!$)continue;const D=no[Z];if(!D){B.push($);continue}const te=D.data?{...$.data,...D.data}:$.data;B.push({...$,...D,data:te})}return B},[rt,u,no]),ej=g.useMemo(()=>{if(!rt||f.length===0)return[];const O=new Map(rt.connectors.map(Z=>[Z.id,Z])),B=[];for(const Z of f){const $=O.get(Z);if(!$)continue;const D=qn[Z];B.push(D?{...$,...D}:$)}return B},[rt,f,qn]),Bf=g.useMemo(()=>{if(!rt)return null;if(!T)return rt.nodes;const O=new Map(rt.nodes.map($=>[$.id,$])),B=[],Z=new Set;for(const $ of T){const D=O.get($);D&&(B.push(D),Z.add($))}for(const $ of rt.nodes)Z.has($.id)||B.push($);return B},[rt,T]),Do=g.useMemo(()=>{const O=Bf??(rt==null?void 0:rt.nodes)??null;return O?nn.size===0?O:O.filter(B=>!nn.has(B.id)):null},[Bf,rt,nn]),Zu=g.useMemo(()=>{const O=(rt==null?void 0:rt.connectors)??null;return O?ro.size===0&&nn.size===0?O:O.filter(B=>!ro.has(B.id)&&!nn.has(B.source)&&!nn.has(B.target)):null},[rt,ro,nn]);if(!l)return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[m.jsxs("p",{className:"text-sm font-medium",children:["Unknown demo: ",e]}),m.jsx("p",{className:"text-xs text-muted-foreground",children:"The slug may have been removed. Re-register from the project repo to bring it back."})]});if(r&&!n)return m.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-muted-foreground",children:"Loading demo…"});const Bd=u[0],xa=Bd?i[Bd]:void 0;return m.jsxs("div",{className:"relative h-full w-full",children:[n&&!n.valid?m.jsxs("div",{"data-testid":"demo-error-banner",className:"absolute inset-x-0 top-0 z-10 border-b border-rose-500/40 bg-rose-50 px-4 py-2 text-xs text-rose-900 shadow-xs dark:bg-rose-950/40 dark:text-rose-100",children:[m.jsx("span",{className:"font-medium uppercase tracking-wide",children:"Invalid demo: "}),m.jsx("span",{className:"font-mono",children:n.error})]}):null,rt&&Q?m.jsx(rDe,{ref:b,mode:"edit",adapter:Q,projectId:ce??void 0,enableEmbed:!1,onExportToCloud:ce?()=>ge(!0):void 0,onRestartDemo:c,nodes:Do??rt.nodes,connectors:Zu??rt.connectors,selectedNodeIds:u,selectedConnectorIds:f,onSelectionChange:xe,runtime:{runs:o,statuses:i,pendingOverrides:{nodes:no,connectors:qn}},onPlayNode:s,onNodePositionChange:he,onNodePositionsChange:Ee,onNodeResize:Be,onHtmlNodeFitToContent:Ge,onMultiResize:Pt,onNodeNameChange:vr,onNodeDescriptionChange:Ro,onConnectorLabelChange:ka,onCreateShapeNode:hn,onCreateImageFromFile:ce?Lt:void 0,onRetryImageUpload:ce?wi:void 0,onCreateHtmlNode:ce?To:void 0,iconPickerOpen:Dn.open,onOpenIconPicker:ce?Wu:void 0,onCloseIconPicker:ce?wr:void 0,onPickIcon:ce?bi:void 0,onRequestIconReplace:ce?Mi:void 0,onCreateConnector:Mn,onReconnectConnector:eo,onPinEndpoint:ce?to:void 0,onUnpinEndpoint:ce?zo:void 0,onReorderNode:Uu,onDeleteNode:$u,onCopyNode:O=>ar([O]),onPasteAt:bn,onCopySelection:ce?ar:void 0,onPasteSelection:ce?()=>bn(null):void 0,onToggleNodeLock:ce?Bu:void 0,hasClipboard:Gu,selectedNodes:Ku,selectedConnectors:ej,onStyleNode:Nn,onStyleNodePreview:_t,onStyleNodes:tn,onStyleNodesPreview:nr,onStyleConnector:Vu,onStyleConnectorPreview:Nt,onRfInit:q,onTidy:ee?va:void 0,onCreateAndConnectFromPane:Qr,pendingEditNodeId:y,activeShape:U,onSelectShape:R,statusReport:xa,onNameChange:vr,onDescriptionChange:Ro,onDetailChange:rr,onIconChange:Yr,autoFitView:!0,autoFitViewSignal:z}):m.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-muted-foreground",children:"No demo data yet."}),P?m.jsxs("div",{"data-testid":"edit-error-banner",className:"absolute inset-x-0 bottom-4 z-20 mx-auto w-fit max-w-[80%] rounded-md border border-rose-500/50 bg-rose-50 px-3 py-2 text-xs text-rose-900 shadow-md dark:bg-rose-950/60 dark:text-rose-100",children:[m.jsx("span",{className:"font-medium",children:"Couldn't save change: "}),m.jsx("span",{className:"font-mono",children:P}),m.jsx("button",{type:"button",className:"ml-3 underline underline-offset-2",onClick:()=>A(null),children:"Dismiss"})]}):null,m.jsx(IDe,{open:F,onOpenChange:V,runCommand:ir,ctx:{hasSelection:u.length>0||f.length>0,canUndo:Xr,canRedo:zn,hasClipboard:Gu,canExportDemo:!!ce,canResetSession:!!c}}),ce?m.jsx(WDe,{open:ue,onOpenChange:ge,projectId:ce,onCapturePreview:()=>{var O;return((O=b.current)==null?void 0:O.capturePreview())??Promise.resolve(void 0)}}):null]})}const Ste="npx seeflow register --path .";function xqe(){const[e,t]=g.useState(!1),n=async()=>{try{await navigator.clipboard.writeText(Ste),t(!0),setTimeout(()=>t(!1),1200)}catch(r){console.error("[empty-state] copy failed",r)}};return m.jsx("div",{"data-testid":"seeflow-empty-state",className:"flex h-full w-full items-center justify-center bg-background p-6",children:m.jsxs("div",{className:"flex max-w-lg flex-col items-center gap-6 text-center",children:[m.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-muted",children:m.jsx(s2,{className:"h-6 w-6 text-muted-foreground"})}),m.jsxs("div",{className:"space-y-2",children:[m.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:"No demos registered yet"}),m.jsxs("p",{className:"text-sm text-muted-foreground",children:["Point SeeFlow at any folder containing a"," ",m.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:".seeflow/seeflow.json"})," ","file and it'll appear here."]})]}),m.jsxs("div",{className:"flex w-full items-center gap-2 rounded-md border border-border bg-card px-3 py-2 font-mono text-sm",children:[m.jsx("span",{className:"text-muted-foreground select-none",children:"$"}),m.jsx("code",{className:"flex-1 truncate text-left",children:Ste}),m.jsx(Ft,{type:"button",variant:"ghost",size:"sm",onClick:n,"aria-label":"Copy register command",children:e?m.jsx(Mo,{className:"h-4 w-4"}):m.jsx(j1,{className:"h-4 w-4"})})]})]})})}function wqe({demos:e}){return e.length===0?m.jsx(xqe,{}):m.jsx("div",{className:"flex h-full w-full items-start justify-center overflow-y-auto bg-background p-8",children:m.jsxs("div",{"data-testid":"studio-home-picker",className:"flex w-full max-w-2xl flex-col gap-6 pt-8",children:[m.jsxs("div",{className:"space-y-1",children:[m.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Open a demo"}),m.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.length," demos registered — pick one to load its canvas."]})]}),m.jsx("ul",{className:"flex flex-col gap-2",children:e.map(t=>m.jsx("li",{children:m.jsxs("button",{type:"button",onClick:()=>gd(`/d/${t.slug}`),"data-testid":`studio-home-demo-${t.slug}`,className:"flex w-full flex-col items-start gap-0.5 rounded-lg border border-border bg-card px-4 py-3 text-left transition-colors hover:border-input",style:{boxShadow:"var(--shadow-card)"},children:[m.jsx("span",{className:"text-sm font-medium",children:t.name}),m.jsx("span",{className:"truncate text-xs text-muted-foreground",children:t.repoPath})]})},t.id))})]})})}const Mqe=e=>{if(!e.startsWith("/d/"))return null;const t=e.slice(3);return t.length>0?decodeURIComponent(t):null};function bqe(){const e=iDe(),{demos:t,refresh:n}=uDe(),r=Mqe(e),o=r?(t??[]).find(C=>C.slug===r):void 0,a=(o==null?void 0:o.id)??null,{detail:i,loading:s,refresh:c}=lDe(a),{runs:l,apply:u}=mDe(a),{events:d,apply:f}=pDe(a),{statusByNode:p,apply:y,reset:k}=xDe(a),w=g.useCallback(()=>{k(),c(),n()},[c,n,k]),v=g.useCallback(C=>{u(C),f(C),y(C)},[u,f,y]);wDe(a,{onReload:w,onEvent:v});const M=g.useCallback(async()=>{if(a)try{await _fe(a)}catch(C){console.error("Failed to restart demo:",C)}},[a]),x=g.useCallback(C=>{ute(C.id),n()},[n]),b=g.useCallback(async C=>{await n(),a===C&&gd("/")},[n,a]);g.useEffect(()=>{if(e!=="/"||t===null)return;const C=bDe(t,MDe());C&&gd(`/d/${C.slug}`)},[e,t]),g.useEffect(()=>{o&&ute(o.id)},[o]);const S=g.useCallback(C=>{a&&Rfe(a,C).catch(L=>{u({type:"node:error",nodeId:C,message:L instanceof Error?L.message:String(L),ts:Date.now()})})},[a,u]);return t===null?m.jsx("div",{className:"flex h-full w-full items-center justify-center bg-background text-sm text-muted-foreground",children:"Loading…"}):m.jsx(p2,{delayDuration:150,children:m.jsxs("div",{className:"flex h-full w-full flex-col bg-background text-foreground",children:[m.jsx(cDe,{demos:t,currentSlug:r??void 0,onProjectCreated:x,onProjectUnregistered:b}),m.jsx("main",{className:"min-h-0 flex-1",children:r?m.jsx(vqe,{slug:r,demos:t,detail:i,loading:s,runs:l,nodeEvents:d,statusByNode:p,onPlayNode:S,onRestartDemo:a?M:void 0}):m.jsx(wqe,{demos:t})})]})})}const Sde=document.getElementById("root");if(!Sde)throw new Error("Root element #root not found");CF.createRoot(Sde).render(m.jsx(fo.StrictMode,{children:m.jsx(bqe,{})}));export{DNe as _,$a as c,kd as g,Lqe as z};
|