@theclearsky/react-blender-nodes 0.0.10 → 0.0.11
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/README.md +144 -3
- package/dist/react-blender-nodes.es.js +1 -1
- package/dist/react-blender-nodes.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,11 +7,15 @@
|
|
|
7
7
|
a flexible and customizable node-based graph editor for web applications.
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://bundlejs.com/?q=%40theclearsky%2Freact-blender-nodes"><img src="https://deno.bundlejs.com/?q=%40theclearsky%2Freact-blender-nodes&badge=detailed&badge-style=for-the-badge" alt="spring-easing's badge" /></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
10
14
|

|
|
11
15
|
|
|
12
16
|
## Quick Links
|
|
13
17
|
|
|
14
|
-
- [](https://theclearsky.github.io/react-blender-nodes/?path=/story/
|
|
18
|
+
- [](https://theclearsky.github.io/react-blender-nodes/?path=/story/organisms-fullgraph--with-runner) -
|
|
15
19
|
Interactive examples and component playground
|
|
16
20
|
- [](https://www.npmjs.com/package/@theclearsky/react-blender-nodes) -
|
|
17
21
|
Install and use in your project
|
|
@@ -180,7 +184,7 @@ https://github.com/user-attachments/assets/72d9384a-e9ca-4223-906a-dc422fb66f49
|
|
|
180
184
|
conversions
|
|
181
185
|
- **Cycle Detection**: Prevent infinite loops in your node graphs
|
|
182
186
|
- **Multiple Data Types**: Support for diverse data structures
|
|
183
|
-
- Basic types: `string`, `number`
|
|
187
|
+
- Basic types: `string`, `number`, `boolean`
|
|
184
188
|
- Complex types: Custom objects with Zod schemas
|
|
185
189
|
- Special types: `inferFromConnection`, `noEquivalent`
|
|
186
190
|
- **Runtime Safety**: Catch type errors before they break your application
|
|
@@ -247,6 +251,110 @@ const functionImplementations = makeFunctionImplementationsWithAutoInfer({
|
|
|
247
251
|
/>;
|
|
248
252
|
```
|
|
249
253
|
|
|
254
|
+
### useNodeRunner Hook
|
|
255
|
+
|
|
256
|
+
For advanced control over graph execution, use the `useNodeRunner` hook directly
|
|
257
|
+
instead of relying on the built-in runner UI:
|
|
258
|
+
|
|
259
|
+
```tsx
|
|
260
|
+
import { FullGraph, useFullGraph, useNodeRunner } from 'react-blender-nodes';
|
|
261
|
+
|
|
262
|
+
function MyExecutableGraph() {
|
|
263
|
+
const { state, dispatch } = useFullGraph(initialState);
|
|
264
|
+
|
|
265
|
+
const {
|
|
266
|
+
// State
|
|
267
|
+
runnerState, // 'idle' | 'compiling' | 'running' | 'paused' | 'completed' | 'errored'
|
|
268
|
+
nodeVisualStates, // Map<nodeId, 'idle' | 'running' | 'completed' | 'errored' | 'skipped'>
|
|
269
|
+
executionRecord, // Full execution recording with per-step timing and I/O snapshots
|
|
270
|
+
currentStepIndex, // Index of the currently active/viewed step
|
|
271
|
+
|
|
272
|
+
// Actions
|
|
273
|
+
run, // Start execution (mode-aware: instant or step-by-step)
|
|
274
|
+
pause, // Pause during step-by-step execution
|
|
275
|
+
resume, // Resume paused step-by-step execution
|
|
276
|
+
step, // Advance one step (starts a new run if idle)
|
|
277
|
+
stop, // Abort the current execution
|
|
278
|
+
reset, // Clear all execution state back to idle
|
|
279
|
+
replayTo, // Seek to a specific step index in a completed recording
|
|
280
|
+
loadRecord, // Load an imported ExecutionRecord (validates against current graph)
|
|
281
|
+
|
|
282
|
+
// Settings
|
|
283
|
+
mode, // Current execution mode: 'instant' | 'stepByStep'
|
|
284
|
+
setMode, // Switch execution mode
|
|
285
|
+
maxLoopIterations, // Max iterations before a loop is force-stopped
|
|
286
|
+
setMaxLoopIterations,
|
|
287
|
+
} = useNodeRunner({
|
|
288
|
+
state,
|
|
289
|
+
functionImplementations,
|
|
290
|
+
options: { maxLoopIterations: 100 },
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<div>
|
|
295
|
+
<button onClick={run}>Run</button>
|
|
296
|
+
<button onClick={step}>Step</button>
|
|
297
|
+
<button onClick={pause}>Pause</button>
|
|
298
|
+
<button onClick={resume}>Resume</button>
|
|
299
|
+
<button onClick={stop}>Stop</button>
|
|
300
|
+
<button onClick={reset}>Reset</button>
|
|
301
|
+
<p>Status: {runnerState}</p>
|
|
302
|
+
<FullGraph state={state} dispatch={dispatch} />
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Import/Export & Automatic Repair
|
|
309
|
+
|
|
310
|
+
Graph state and execution recordings can be exported to JSON and re-imported
|
|
311
|
+
later. On import, the library validates the structure and can automatically
|
|
312
|
+
repair common issues via opt-in repair strategies.
|
|
313
|
+
|
|
314
|
+
#### State Import Repair Strategies
|
|
315
|
+
|
|
316
|
+
Pass a `repair` object to `importGraphState` to enable automatic fixes:
|
|
317
|
+
|
|
318
|
+
```tsx
|
|
319
|
+
import { importGraphState } from 'react-blender-nodes';
|
|
320
|
+
|
|
321
|
+
const result = importGraphState(json, {
|
|
322
|
+
dataTypes: myDataTypes,
|
|
323
|
+
typeOfNodes: myTypeOfNodes,
|
|
324
|
+
repair: {
|
|
325
|
+
removeOrphanEdges: true, // Remove edges whose source or target node doesn't exist
|
|
326
|
+
removeDuplicateNodeIds: true, // Deduplicate nodes with the same ID (keep first)
|
|
327
|
+
removeDuplicateEdgeIds: true, // Deduplicate edges with the same ID (keep first)
|
|
328
|
+
fillMissingDefaults: true, // Fill missing optional fields (viewport, etc.) with defaults
|
|
329
|
+
rehydrateDataTypeObjects: true, // Rebuild handle dataType objects from provided dataTypes
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
if (result.success) {
|
|
334
|
+
// result.data is the repaired State
|
|
335
|
+
// result.warnings contains info about what was repaired
|
|
336
|
+
} else {
|
|
337
|
+
// result.errors contains fatal validation issues
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### Recording Import Repair Strategies
|
|
342
|
+
|
|
343
|
+
Pass a `repair` object to `importExecutionRecord` for recording-specific fixes:
|
|
344
|
+
|
|
345
|
+
```tsx
|
|
346
|
+
import { importExecutionRecord } from 'react-blender-nodes';
|
|
347
|
+
|
|
348
|
+
const result = importExecutionRecord(json, {
|
|
349
|
+
repair: {
|
|
350
|
+
sanitizeNonSerializableValues: true, // Replace non-serializable values with "[non-serializable]"
|
|
351
|
+
removeOrphanSteps: true, // Remove steps referencing nodes not present in the record
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
All repair strategies default to `false` and must be explicitly enabled.
|
|
357
|
+
|
|
250
358
|
## Usage Examples
|
|
251
359
|
|
|
252
360
|
### Smart Type System with Validation
|
|
@@ -452,8 +560,22 @@ The main graph editor component with full ReactFlow integration.
|
|
|
452
560
|
|
|
453
561
|
```tsx
|
|
454
562
|
interface FullGraphProps {
|
|
563
|
+
/** The current state of the graph including nodes, edges, and type definitions */
|
|
455
564
|
state: State;
|
|
565
|
+
/** Dispatch function for updating the graph state */
|
|
456
566
|
dispatch: Dispatch;
|
|
567
|
+
/** Function implementations for each node type, enables the runner when provided */
|
|
568
|
+
functionImplementations?: FunctionImplementations;
|
|
569
|
+
/** Called when state is successfully imported. Receives the raw parsed state. */
|
|
570
|
+
onStateImported?: (importedState: State) => void;
|
|
571
|
+
/** Called when a recording is successfully imported. Receives the parsed ExecutionRecord. */
|
|
572
|
+
onRecordingImported?: (record: ExecutionRecord) => void;
|
|
573
|
+
/** Called when import validation fails. Receives the error messages. */
|
|
574
|
+
onImportError?: (errors: string[]) => void;
|
|
575
|
+
/** Controlled execution record. When provided, FullGraph uses this instead of internal state. */
|
|
576
|
+
executionRecord?: ExecutionRecord | null;
|
|
577
|
+
/** Called whenever the execution record changes (run completes, reset, load, etc.). */
|
|
578
|
+
onExecutionRecordChange?: (record: ExecutionRecord | null) => void;
|
|
457
579
|
}
|
|
458
580
|
```
|
|
459
581
|
|
|
@@ -463,17 +585,36 @@ Customizable node component with dynamic inputs and outputs.
|
|
|
463
585
|
|
|
464
586
|
```tsx
|
|
465
587
|
interface ConfigurableNodeProps {
|
|
588
|
+
/** Unique identifier for the node (shown when enableDebugMode is true) */
|
|
589
|
+
id?: string;
|
|
590
|
+
/** Display name of the node */
|
|
466
591
|
name?: string;
|
|
592
|
+
/** Background color of the node header */
|
|
467
593
|
headerColor?: string;
|
|
594
|
+
/** Array of inputs and input panels */
|
|
468
595
|
inputs?: (ConfigurableNodeInput | ConfigurableNodeInputPanel)[];
|
|
596
|
+
/** Array of output sockets */
|
|
469
597
|
outputs?: ConfigurableNodeOutput[];
|
|
598
|
+
/** Whether the node is currently inside a ReactFlow context */
|
|
470
599
|
isCurrentlyInsideReactFlow?: boolean;
|
|
600
|
+
/** Props for the node resizer component */
|
|
601
|
+
nodeResizerProps?: NodeResizerWithMoreControlsProps;
|
|
602
|
+
/** Node type unique id */
|
|
603
|
+
nodeTypeUniqueId?: string;
|
|
604
|
+
/** Whether to show the node open button (used by node groups) */
|
|
605
|
+
showNodeOpenButton?: boolean;
|
|
606
|
+
/** Runner visual state for this node (undefined = no runner overlay) */
|
|
607
|
+
runnerVisualState?: NodeVisualState;
|
|
608
|
+
/** Errors from the runner for this node */
|
|
609
|
+
runnerErrors?: ReadonlyArray<GraphError>;
|
|
610
|
+
/** Warnings from the runner for this node */
|
|
611
|
+
runnerWarnings?: ReadonlyArray<string>;
|
|
471
612
|
}
|
|
472
613
|
```
|
|
473
614
|
|
|
474
615
|
## 🔗 Links
|
|
475
616
|
|
|
476
|
-
- [📖 Storybook Documentation](https://theclearsky.github.io/react-blender-nodes/?path=/story/
|
|
617
|
+
- [📖 Storybook Documentation](https://theclearsky.github.io/react-blender-nodes/?path=/story/organisms-fullgraph--with-runner)
|
|
477
618
|
- [📦 NPM Package](https://www.npmjs.com/package/@theclearsky/react-blender-nodes)
|
|
478
619
|
- [🐛 Report Issues](https://github.com/TheClearSky/react-blender-nodes/issues)
|
|
479
620
|
- [💡 Request Features](https://github.com/TheClearSky/react-blender-nodes/discussions)
|
|
@@ -24683,7 +24683,7 @@ function FV({
|
|
|
24683
24683
|
) : /* @__PURE__ */ y.jsx(
|
|
24684
24684
|
"span",
|
|
24685
24685
|
{
|
|
24686
|
-
className: "flex items-center justify-center text-[9px] font-medium text-[#eee] select-none",
|
|
24686
|
+
className: "flex items-center justify-center text-[9px] font-medium text-[#eee] select-none w-full",
|
|
24687
24687
|
style: { lineHeight: `${s}px` },
|
|
24688
24688
|
children: e.iteration
|
|
24689
24689
|
}
|
|
@@ -301,5 +301,5 @@ if(f&&(a&&u)!==(l&&d)){const g=d?n:t,h=d?"input":"output",m=Cr(e.dataTypes,e.nod
|
|
|
301
301
|
`)}function sb({icon:e,content:t,iconClassName:n}){const{refs:r,floatingStyles:i,context:s,arrowRef:a,getReferenceProps:l,getFloatingProps:u,isMounted:d,transitionStyles:f}=ob({placement:"top",offsetPx:10,hoverDelay:{open:150,close:0},transitionDuration:150});return y.jsxs(y.Fragment,{children:[y.jsx("div",{ref:r.setReference,className:ye("absolute top-1 right-1 z-10 cursor-pointer pointer-events-auto",n),...l(),children:e}),d&&y.jsx("div",{ref:r.setFloating,style:{...i,zIndex:50},...u(),children:y.jsxs("div",{style:f,className:"max-w-xs rounded-md bg-[#181818] border border-secondary-dark-gray px-3 py-2 text-[14px] leading-[18px] font-main text-primary-white shadow-lg whitespace-pre-wrap pointer-events-auto",children:[t,y.jsx(Ww,{ref:a,context:s,width:10,height:5,fill:"#181818",strokeWidth:1,stroke:"var(--color-secondary-dark-gray)"})]})})]})}function ab({visualState:e,errors:t,warnings:n,children:r}){const i=t&&t.length>0?t.map(a=>ib(a)).join(`
|
|
302
302
|
|
|
303
303
|
`):void 0,s=n&&n.length>0?n.join(`
|
|
304
|
-
`):void 0;return y.jsxs("div",{className:"relative",children:[y.jsx("div",{className:ye("absolute inset-0 rounded-md pointer-events-none z-10 transition-[outline-color,box-shadow,opacity] duration-200",e==="idle"&&"[outline:5px_solid_transparent] shadow-none",e==="running"&&"[outline:5px_dashed_var(--color-primary-blue)] animate-[running-glow_2s_ease-in-out_infinite]",e==="completed"&&"[outline:5px_solid_var(--color-status-completed)] shadow-[0_0_12px_rgba(76,175,80,0.3)]",e==="errored"&&"[outline:5px_solid_var(--color-status-errored)] shadow-[0_0_12px_rgba(255,68,68,0.3)]",e==="skipped"&&"[outline:5px_dashed_var(--color-secondary-dark-gray)] opacity-50",e==="warning"&&"[outline:5px_solid_var(--color-status-warning)] shadow-[0_0_12px_rgba(255,165,0,0.3)]")}),e==="errored"&&i&&y.jsx(sb,{icon:y.jsx(R_,{className:"w-5 h-5 text-[#FF4444]"}),content:i}),e==="warning"&&s&&y.jsx(sb,{icon:y.jsx(ng,{className:"w-5 h-5 text-[#FFA500]"}),content:s}),e==="skipped"&&y.jsx("div",{className:"absolute inset-0 rounded-md bg-black/30 pointer-events-none z-10"}),r]})}function cb({orientation:e="horizontal",disabled:t=!1,scrollSpeedPxPerFrame:n=14,observeChildren:r=!0}={}){const i=T.useRef(null),[s,a]=T.useState(!1),[l,u]=T.useState(!1),d=T.useRef(null),f=T.useRef(null),g=T.useCallback(()=>e==="vertical"?{pos:"scrollTop",size:"clientHeight",full:"scrollHeight"}:{pos:"scrollLeft",size:"clientWidth",full:"scrollWidth"},[e]),h=T.useCallback(()=>{const b=i.current;if(!b||t){a(!1),u(!1);return}const S=g(),N=b[S.pos],w=b[S.size],I=b[S.full];a(N>0),u(N+w<I-1)},[t,g]),m=T.useCallback(()=>{d.current!==null&&(cancelAnimationFrame(d.current),d.current=null),f.current=null},[]),x=T.useCallback(()=>{const b=i.current;if(!b||!f.current||t){m();return}const S=g(),N=f.current==="start"?-1:1;if(S.pos==="scrollLeft"?b.scrollLeft+=N*n:b.scrollTop+=N*n,h(),N<0&&!s||N>0&&!l){m();return}d.current=requestAnimationFrame(x)},[l,s,t,g,n,m,h]),v=T.useCallback(b=>{t||f.current!==b&&(f.current=b,d.current!==null&&cancelAnimationFrame(d.current),d.current=requestAnimationFrame(x))},[t,x]);return T.useEffect(()=>{h();const b=i.current;if(!b)return;const S=()=>h();b.addEventListener("scroll",S,{passive:!0});let N=null;"ResizeObserver"in window&&(N=new ResizeObserver(()=>h()),N.observe(b));const w=()=>h();window.addEventListener("resize",w);const I=()=>m();return window.addEventListener("pointerup",I),window.addEventListener("touchend",I),()=>{b.removeEventListener("scroll",S),window.removeEventListener("resize",w),window.removeEventListener("pointerup",I),window.removeEventListener("touchend",I),N&&N.disconnect()}},[h,m]),T.useEffect(()=>{const b=requestAnimationFrame(h);return()=>cancelAnimationFrame(b)},[h]),T.useEffect(()=>{if(!r)return;const b=i.current;if(!b)return;const S=new MutationObserver(()=>h());return S.observe(b,{childList:!0,subtree:!0}),()=>S.disconnect()},[r,h]),{listRef:i,canScrollStart:s,canScrollEnd:l,startAutoScroll:v,stopAutoScroll:m}}const Rf=T.forwardRef(({children:e,orientation:t="horizontal",className:n,scrollAreaClassName:r,showArrows:i=!0,disabled:s=!1,ariaLabel:a,scrollSpeedPxPerFrame:l=14,observeChildren:u=!0},d)=>{const{listRef:f,canScrollStart:g,canScrollEnd:h,startAutoScroll:m,stopAutoScroll:x}=cb({orientation:t,disabled:s,scrollSpeedPxPerFrame:l,observeChildren:u});T.useImperativeHandle(d,()=>f.current);const v=i&&g&&!s,b=i&&h&&!s,S=t==="horizontal"?"overflow-x-scroll overflow-y-hidden flex items-center gap-2 whitespace-nowrap":"overflow-y-scroll overflow-x-hidden flex flex-col items-start gap-2";return y.jsxs("div",{className:ye("relative w-full h-full",n),children:[v&&y.jsx(Qn,{className:ye("h-[44px] border-secondary-dark-gray bg-primary-black absolute z-10",t==="horizontal"?"left-0 top-1/2 -translate-y-1/2":"top-0 left-1/2 -translate-x-1/2"),disabled:!v,onMouseDown:()=>m("start"),onMouseUp:x,onMouseLeave:x,onTouchStart:()=>m("start"),onTouchEnd:x,children:t==="horizontal"?y.jsx(iu,{}):y.jsx(su,{})}),y.jsx("div",{ref:f,"aria-label":a,className:ye("no-scrollbar w-full h-full",S,r),children:e}),b&&y.jsx(Qn,{className:ye("h-[44px] border-secondary-dark-gray bg-primary-black absolute z-10",t==="horizontal"?"right-0 top-1/2 -translate-y-1/2":"bottom-0 left-1/2 -translate-x-1/2"),disabled:!b,onMouseDown:()=>m("end"),onMouseUp:x,onMouseLeave:x,onTouchStart:()=>m("end"),onTouchEnd:x,children:t==="horizontal"?y.jsx(zr,{}):y.jsx(Ei,{})})]})});Rf.displayName="ScrollableButtonContainer";function sn({content:e,children:t,infoIcon:n=!1,placement:r="bottom",maxWidth:i=240,className:s,style:a,as:l="span",triggerProps:u}){const[d,f]=T.useState(!1),g=T.useRef(null),h=T.useRef(null),{refs:m,floatingStyles:x,context:v}=Wc({open:d,onOpenChange:f,middleware:[Oi(6),Ri(),Pi({padding:8}),Vu({element:h})],whileElementsMounted:Mi,placement:r});T.useEffect(()=>{g.current&&m.setPositionReference(g.current)},[m]);const{isMounted:b,styles:S}=rb(v,{duration:120,initial:{opacity:0,transform:"translateY(-3px)"}});return y.jsxs(y.Fragment,{children:[y.jsxs(l,{ref:g,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),className:ye("inline-flex items-center gap-1.5",s),style:a,...u,children:[n&&y.jsx(L_,{className:"h-3.5 w-3.5 shrink-0 text-primary-white"}),t]}),b&&y.jsx(Jw,{children:y.jsx("div",{ref:m.setFloating,style:{...x,pointerEvents:"none",zIndex:50},children:y.jsxs("div",{style:{...S,maxWidth:`${i}px`},className:"rounded-md border-[1.25px] border-primary-white/60 bg-tooltip-bg px-3 py-2 text-[12px] text-primary-white shadow-2xl backdrop-blur-sm",children:[e,y.jsx(Ww,{ref:h,context:v,width:8,height:4,fill:"var(--color-tooltip-bg)",strokeWidth:1,stroke:"var(--color-secondary-dark-gray)"})]})})})]})}function lb({onMove:e,onClick:t,clickThreshold:n=2,enabled:r=!0,preventDefaultAndStopPropagation:i=!0}={}){const[s,a]=T.useState(!1),[l,u]=T.useState(null),d=T.useRef(null),f=T.useRef(null),g=T.useCallback(h=>{u(h)},[]);return T.useEffect(()=>{if(!l||!r)return;const h=m=>{i&&(m.preventDefault(),m.stopPropagation()),d.current={x:m.clientX,y:m.clientY},f.current={width:l.clientWidth,height:l.clientHeight},a(!0);const x=b=>{i&&(b.preventDefault(),b.stopPropagation()),document.removeEventListener("mouseup",x),document.removeEventListener("mousemove",v),a(!1),d.current&&Math.sqrt((b.clientX-d.current.x)**2+(b.clientY-d.current.y)**2)<n&&t?.()},v=b=>{i&&(b.preventDefault(),b.stopPropagation());const S=b.movementX,N=b.movementY,w=f.current?.width||1,I=f.current?.height||1,k=S/w,A=N/I;e?.(S,N,k,A,w,I)};document.addEventListener("mouseup",x),document.addEventListener("mousemove",v)};return l.addEventListener("mousedown",h),()=>{l.removeEventListener("mousedown",h)}},[l,r,e,t,n,i]),{isDragging:s,dragRef:g}}const ni=T.forwardRef(({name:e="Input",value:t,onChange:n=()=>{},className:r,min:i,max:s,step:a,size:l="normal",decimals:u},d)=>{const f=l==="small",g=u??(f?1:4),[h,m]=T.useState(t??0),[x,v]=T.useState(!1),b=T.useRef(0),S=T.useRef(0),N=t??h,w=T.useRef(0);T.useEffect(()=>{if(a!==void 0)w.current=Math.abs(a);else if(i!==void 0&&s!==void 0)w.current=Math.abs(s-i);else{const W=Math.pow(10,-g);w.current=Math.max(Math.abs(parseFloat((N||1).toString())),W)}},[N,a,g,s,i]);const{isDragging:I,dragRef:k}=lb({onMove:(W,z,Y,J,ie)=>{const ee=W/(ie+60);b.current+=ee,Math.abs(b.current)>.05&&Date.now()-S.current>50&&(S.current=Date.now(),A(w.current*b.current),b.current=0)},onClick:U,clickThreshold:2});function A(W){m(z=>{let Y=z+W;return i!==void 0&&Y<=i?Y=i:s!==void 0&&Y>=s&&(Y=s),n(Y),Y})}function M(W=.1){A(w.current*W)}function B(W=.1){A(-w.current*W)}function U(){v(!0)}function q(W){A(W-N),v(!1)}const D=I,$=i!==void 0&&s!==void 0&&N!==void 0&&s!==i?(N-i)/(s-i)*100:-1,F=$!==-1?`linear-gradient(90deg,#4772b3 ${$}%, #545454 ${$}%)`:"",E=f?"h-[22px]":"h-[44px]",P=f?`${E} w-[18px]`:`${E} w-[30px]`,L=f?"h-3 w-3":"",j=f?"text-[10px]":"",O=f?`${E} rounded-none px-1.5 flex-1 justify-between grid grid-cols-[repeat(2,auto)] bg-transparent gap-1`:`${E} rounded-none pl-1.5 pr-0 flex-1 justify-between grid grid-cols-[repeat(2,auto)] bg-transparent`;return x?y.jsx(ws,{className:ye("w-full",f&&"h-[22px] text-[11px] px-1.5"),placeholder:e,value:N,allowOnlyNumbers:!0,numberOfDecimals:g,onChange:W=>q(W),ref:d}):y.jsxs("div",{className:ye("flex items-center gap-0 group/lightParentGroupBasedHover w-max bg-primary-gray",f?"rounded-sm":"rounded-md",r),style:F!==""?{background:F}:{},ref:d,children:[y.jsx(Qn,{color:"lightParentGroupBasedHover",className:ye(P,"rounded-r-none p-0 shrink-0 bg-transparent",j),onClick:()=>B(.1),"aria-label":`Decrement ${e}`,applyHoverStyles:!D,children:y.jsx(iu,{className:L||void 0})}),y.jsxs(Qn,{color:"lightParentGroupBasedHover",className:ye(O,j),applyHoverStyles:!D,ref:k,children:[y.jsx("span",{className:"truncate text-left",children:e}),y.jsx("span",{className:"truncate tabular-nums",children:N.toFixed(g)})]}),y.jsx(Qn,{color:"lightParentGroupBasedHover",className:ye(P,"rounded-l-none p-0 shrink-0 bg-transparent",j),onClick:()=>M(.1),"aria-label":`Increment ${e}`,applyHoverStyles:!D,children:y.jsx(zr,{className:L||void 0})})]})});ni.displayName="SliderNumberInput";const ub=100,db=100,Lf=75,fb=100;function q2(e,t){const[n,r]=T.useState(null),i=T.useRef(new Map),s=T.useRef(null),a=T.useRef(!1),l=T.useCallback(()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),[u,d]=T.useState(null),[f,g]=T.useState(null),h=T.useRef(null),m=T.useRef(null),x=T.useRef(null),[v,b]=T.useState(null),S=T.useRef(null),N=T.useRef(null),w=T.useRef(!1),I=T.useRef(!1),[k,A]=T.useState(null),M=T.useRef(null),B=T.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null),m.current&&(cancelAnimationFrame(m.current),m.current=null)},[]),U=T.useCallback(ee=>{const ce=x.current;if(ee!==ce){if(x.current=ee,B(),ce!==null&&ee!==null){I.current=!0;const ge=e.find(Q=>Q.id===ce);ge?.subItems&&d(ge.subItems),g("initial")}else if(I.current=!1,g(null),d(null),ee===null){const ge=e.find(Q=>Q.id===ce);ge?.subItems?(A(ge.subItems),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{A(null),w.current=!1,b(null),M.current=null},ub)):(w.current=!1,b(null))}else M.current&&(clearTimeout(M.current),M.current=null),A(null);r(ee)}},[e,B]);T.useEffect(()=>{if(f==="initial")return m.current=requestAnimationFrame(()=>{m.current=requestAnimationFrame(()=>{g("animating"),m.current=null,h.current=setTimeout(()=>{g(null),d(null),I.current=!1,h.current=null},db)})}),B},[f,B]);const D=(n?e.find(ee=>ee.id===n):null)?.subItems??null;T.useLayoutEffect(()=>{N.current&&N.current.disconnect();const ee=S.current;if(!ee||!n)return;const ce=new ResizeObserver(ge=>{const Q=ge[0];if(!Q)return;const{width:te,height:ne}=Q.contentRect;te>0&&ne>0&&(w.current=!0,b({w:te,h:ne}))});return ce.observe(ee),N.current=ce,()=>ce.disconnect()},[n]);const $=n?i.current.get(n):null,{refs:F,floatingStyles:E,placement:P}=Wc({open:n!==null,onOpenChange:ee=>{ee||U(null)},strategy:"fixed",placement:"right-start",middleware:[Oi(5),Ri({fallbackPlacements:["left-start"]}),Pi({padding:8})],whileElementsMounted:Mi});T.useLayoutEffect(()=>{$&&F.setReference($)},[$,F]);const L=T.useCallback(ee=>{ee.onClick&&ee.onClick(),t&&t(ee)},[t]),j=T.useCallback(ee=>{l(),ee!==n&&(n===null?ee!==null&&(s.current=setTimeout(()=>{U(ee),s.current=null},Lf)):ee!==null?s.current=setTimeout(()=>{U(ee),s.current=null},fb):s.current=setTimeout(()=>{a.current||U(null),s.current=null},fb))},[n,l,U]),O=T.useCallback(()=>{a.current=!0,l()},[l]),W=T.useCallback(()=>{a.current=!1,l(),s.current=setTimeout(()=>{U(null),s.current=null},Lf)},[l,U]),z=T.useCallback(()=>{a.current||(l(),s.current=setTimeout(()=>{a.current||U(null),s.current=null},Lf))},[l,U]),Y=T.useCallback(ee=>ce=>{ce?i.current.set(ee,ce):i.current.delete(ee)},[]),J=n!==null,ie=v!==null?{width:v.w,height:v.h,overflow:"hidden"}:{};return{activeSubmenuId:n,activeSubItems:D,prevSubItems:u,exitSubItems:k,crossfadePhase:f,containerSize:v,isSwitching:I.current,isOpen:J,panelSizeStyles:ie,incomingRef:S,floatingRefs:F,floatingStyles:E,placement:P,handleItemClick:L,handleHover:j,handleFloatingMouseEnter:O,handleFloatingMouseLeave:W,handleListMouseLeave:z,makeItemRef:Y,SUBMENU_DURATION_MS:ub,CONTENT_FADE_DURATION_MS:db}}const Y2=({item:e,index:t,onItemClick:n,onHover:r,itemRef:i,itemTransitionStyle:s})=>{const a=e.subItems&&e.subItems.length>0;return y.jsxs("li",{className:"relative",children:[e.separator&&t>0&&y.jsx("div",{className:"border-t border-gray-600 m-0"}),y.jsxs("div",{ref:i,className:ye("flex items-center justify-between gap-2 px-3 py-1.25 hover:bg-[#3F3F3F] cursor-pointer","transition-colors duration-150"),style:s,onClick:()=>n(e),onMouseEnter:()=>r(a?e.id:null),children:[y.jsxs("div",{className:"flex items-center gap-2",children:[e.icon&&y.jsx("span",{className:"text-primary-white w-3 h-3 flex items-center justify-center",children:e.icon}),y.jsx("span",{className:"text-sm leading-3.5 text-primary-white font-main",children:e.label})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[e.shortcut&&y.jsx("span",{className:"text-sm leading-3.5 text-gray-400 font-mono",children:e.shortcut}),a&&y.jsx(zr,{className:"w-3 h-3 text-gray-400"})]})]})]})},Gc=({subItems:e,onItemClick:t,className:n,bare:r=!1,itemTransitionStyle:i})=>{const{activeSubItems:s,prevSubItems:a,exitSubItems:l,crossfadePhase:u,isSwitching:d,isOpen:f,panelSizeStyles:g,incomingRef:h,floatingRefs:m,floatingStyles:x,placement:v,handleItemClick:b,handleHover:S,handleFloatingMouseEnter:N,handleFloatingMouseLeave:w,handleListMouseLeave:I,makeItemRef:k,SUBMENU_DURATION_MS:A,CONTENT_FADE_DURATION_MS:M}=q2(e,t),B=e.some(U=>U.subItems&&U.subItems.length>0);return y.jsxs(y.Fragment,{children:[y.jsx("ul",{className:ye("min-w-48 py-1",!r&&"bg-[#181818] border border-none rounded-md shadow-lg",n),onMouseLeave:I,children:e.map((U,q)=>y.jsx(Y2,{item:U,index:q,onItemClick:b,onHover:S,itemRef:k(U.id),itemTransitionStyle:i},U.id))}),B&&y.jsx(Jw,{children:y.jsx("div",{ref:m.setFloating,style:{...x,transitionProperty:d?"opacity, transform, translate":"opacity, translate",transitionDuration:`${A}ms`,transitionTimingFunction:"ease-out"},className:ye("z-50",f?"opacity-100 translate-x-0":ye("opacity-0 pointer-events-none",v.startsWith("right")?"-translate-x-[20px]":"translate-x-[20px]")),onMouseEnter:N,onMouseLeave:w,children:y.jsx("div",{className:"bg-[#181818] rounded-md shadow-lg ml-1",style:{...g,transitionProperty:"opacity, translate, width, height",transitionDuration:`${A}ms`,transitionTimingFunction:"ease-out"},children:y.jsxs("div",{className:"relative",children:[u!==null&&a&&y.jsx("div",{className:"absolute inset-0",style:{pointerEvents:"none"},children:y.jsx(Gc,{subItems:a,onItemClick:t,bare:!0,itemTransitionStyle:u==="initial"?{opacity:1,transform:"translateX(0)"}:{opacity:0,transform:"translateX(10%)",transition:`opacity ${M}ms ease-out, transform ${M}ms ease-out`}})}),s&&y.jsx("div",{ref:h,children:y.jsx(Gc,{subItems:s,onItemClick:t,bare:!0,itemTransitionStyle:u==="initial"?{opacity:0,transform:"translateX(-10%)"}:u==="animating"?{opacity:1,transform:"translateX(0)",transition:`opacity ${M}ms ease-out, transform ${M}ms ease-out`}:void 0})}),!s&&l&&y.jsx(Gc,{subItems:l,onItemClick:t,bare:!0})]})})})})]})},pb=({subItems:e,className:t,onItemClick:n})=>y.jsx("div",{className:ye("relative",t),children:y.jsx(Gc,{subItems:e,onItemClick:n})});function Df(e){return e.kind==="leaf"?e.priority:e.children.length===0?0:Math.max(...e.children.map(Df))}function jf(e){return e.kind==="leaf"?e.insertionIndex:e.children.length===0?1/0:Math.min(...e.children.map(jf))}function hb(e){e.sort((t,n)=>{const r=Df(n)-Df(t);return r!==0?r:jf(t)-jf(n)});for(const t of e)t.kind==="folder"&&hb(t.children)}function gb(e){const t=[];for(const n of e)if(n.kind==="leaf")t.push(n.item);else{const r=gb(n.children);r.length>0&&t.push({id:`folder-${n.label}`,label:n.label,subItems:r})}return t}function mb({typeOfNodes:e,dispatch:t,setContextMenu:n,contextMenuPosition:r,isRecursionAllowed:i=!0,currentNodeType:s}){const a=Object.keys(e);if(a.length===0)return[];function l(g,h){if(h||!s)return g;const m=ew({typeOfNodes:e},s);return g.filter(x=>!m.has(x))}const u=l(a,i),d=[];for(let g=0;g<u.length;g++){const h=u[g],m=e[h],x=m.locationInContextMenu??[],v=m.priorityInContextMenu??0,b={kind:"leaf",item:{id:`add-${String(h)}`,label:m.name,onClick:()=>{t({type:ft.ADD_NODE_AND_SELECT,payload:{type:h,position:r}}),n({isOpen:!1,position:{x:0,y:0}})}},priority:v,insertionIndex:g};if(x.length===0)d.push(b);else{let S=d;for(const N of x){let w=S.find(I=>I.kind==="folder"&&I.label===N);w||(w={kind:"folder",label:N,children:[]},S.push(w)),S=w.children}S.push(b)}}hb(d);const f=gb(d);return[{id:"add-node",label:"Add Node",icon:T.createElement(Jh,{className:"w-4 h-4"}),subItems:f}]}const yb=_T,$f=T.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(vy,{ref:r,className:ye("flex h-[44px] w-full items-center justify-between rounded-md border cursor-pointer border-secondary-dark-gray bg-primary-black px-4 py-2 text-[27px] leading-[27px] font-main text-primary-white data-[placeholder]:text-[#6B6B6B] focus:outline-none focus-visible:ring-1 focus-visible:ring-white disabled:cursor-not-allowed disabled:opacity-50",e),...n,children:[y.jsx("span",{className:"text-left truncate",children:t}),y.jsx(NT,{asChild:!0,children:y.jsx(Ei,{className:"h-6 w-6 shrink-0 ml-2"})})]}));$f.displayName=vy.displayName;const Hf=T.forwardRef(({className:e,...t},n)=>y.jsx(_y,{ref:n,className:ye("flex cursor-default items-center justify-center py-1",e),...t,children:y.jsx(su,{className:"h-4 w-4"})}));Hf.displayName=_y.displayName;const Bf=T.forwardRef(({className:e,...t},n)=>y.jsx(Ny,{ref:n,className:ye("flex cursor-default items-center justify-center py-1",e),...t,children:y.jsx(Ei,{className:"h-4 w-4"})}));Bf.displayName=Ny.displayName;const Vf=T.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>y.jsx(IT,{children:y.jsxs(wy,{ref:i,className:ye("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-secondary-dark-gray bg-[#181818] text-primary-white shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[y.jsx(Hf,{}),y.jsx(ET,{className:ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),y.jsx(Bf,{})]})}));Vf.displayName=wy.displayName;const vb=T.forwardRef(({className:e,...t},n)=>y.jsx(by,{ref:n,className:ye("py-1.5 px-2 text-[27px] leading-[27px] font-main font-semibold text-primary-white",e),...t}));vb.displayName=by.displayName;const qc=T.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(Sy,{ref:r,className:ye("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-4 pr-2 text-[27px] leading-[27px] font-main text-primary-white outline-none focus:bg-[#3F3F3F] focus:text-primary-white data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[y.jsx(CT,{children:t}),y.jsx("span",{className:"ml-auto",children:y.jsx(AT,{children:y.jsx(sa,{className:"h-5 w-5 ml-2 mr-1",strokeWidth:2.5})})})]}));qc.displayName=Sy.displayName;const xb=T.forwardRef(({className:e,...t},n)=>y.jsx(Iy,{ref:n,className:ye("-mx-1 my-1 h-px bg-secondary-dark-gray",e),...t}));xb.displayName=Iy.displayName;const X2=TT,Ff=T.forwardRef(({className:e,...t},n)=>y.jsx(xy,{ref:n,className:ye(e),...t}));Ff.displayName=xy.displayName;const K2={small:{wrapper:"rounded-sm border border-secondary-dark-gray/80",button:"px-2.5 py-0.5 text-[12px]",divider:"border-l border-secondary-dark-gray/50",activeBg:"bg-primary-blue text-white",inactiveBg:"bg-[#1a1a1a] text-secondary-light-gray hover:bg-primary-dark-gray hover:text-primary-white"},normal:{wrapper:"rounded-md border border-runner-timeline-box-border bg-runner-inset-bg p-[3px]",button:"rounded px-3.5 py-1 text-[13px]",divider:"",activeBg:"bg-primary-blue text-white",inactiveBg:"bg-[#1a1a1a] text-secondary-light-gray"}};function zf({options:e,value:t,onChange:n,disabled:r=!1,size:i="normal",className:s}){const a=K2[i];return y.jsx("div",{className:ye("flex overflow-hidden",a.wrapper,s),children:e.map((l,u)=>y.jsx("button",{type:"button",onClick:()=>n(l.value),disabled:r,className:ye("btn-press font-medium transition-all duration-100",a.button,u>0&&a.divider,t===l.value?a.activeBg:a.inactiveBg,r&&t!==l.value&&"cursor-not-allowed opacity-50",!r&&t!==l.value&&i==="normal"&&"hover:text-primary-white"),children:l.label},l.value))})}const Z2=[{value:"instant",label:"Instant"},{value:"stepByStep",label:"Step-by-Step"}],J2={idle:{color:"bg-secondary-dark-gray",pulse:!1,label:"Idle"},compiling:{color:"bg-primary-blue",pulse:!0,label:"Compiling"},running:{color:"bg-status-completed",pulse:!0,label:"Running"},paused:{color:"bg-status-warning",pulse:!1,label:"Paused"},completed:{color:"bg-status-completed",pulse:!1,label:"Completed"},errored:{color:"bg-status-errored",pulse:!1,label:"Error"}};function Ns({icon:e,onClick:t,disabled:n,active:r=!1,variant:i="default",title:s}){const a=i==="play";return y.jsx("button",{type:"button",onClick:t,disabled:n,title:s,className:ye("btn-press flex items-center justify-center transition-all duration-100",a?"h-8 w-8 rounded-md bg-primary-blue text-white shadow-[0_0_12px_rgba(74,120,194,0.4)]":"h-7 w-7 rounded",n&&"cursor-not-allowed opacity-30",!n&&!r&&!a&&"hover:bg-primary-dark-gray hover:text-white",!n&&a&&"hover:brightness-110",r&&!a&&"bg-primary-blue shadow-[0_0_8px_rgba(71,114,179,0.5)]",!n&&"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary-blue"),children:e})}function wb({runnerState:e,onRun:t,onPause:n,onStep:r,onStop:i,onReset:s,mode:a,onModeChange:l,maxLoopIterations:u,onMaxLoopIterationsChange:d}){const f=J2[e],g=e==="idle"||e==="completed"||e==="errored",h=e==="idle"||e==="errored",m=e==="running",x=e==="paused"||e==="idle"||e==="errored",v=e==="running"||e==="paused",b=e==="completed"||e==="errored";return y.jsxs("div",{className:"flex h-11 w-full items-center gap-2 border-b border-secondary-dark-gray bg-runner-toolbar-bg px-3",children:[y.jsxs("div",{className:"flex w-[140px] items-center gap-2.5",children:[y.jsxs("div",{className:"relative flex items-center justify-center",children:[y.jsx("div",{className:ye("h-2.5 w-2.5 rounded-full transition-colors duration-200",f.color,f.pulse&&"animate-pulse",f.pulse&&"shadow-[0_0_8px_currentColor]")}),f.pulse&&y.jsx("div",{className:ye("absolute h-2.5 w-2.5 animate-ping rounded-full opacity-50",f.color)})]}),y.jsx("span",{className:"text-[14px] text-primary-white",children:f.label})]}),y.jsx("div",{className:"mx-3 h-6 w-px bg-secondary-dark-gray"}),y.jsxs("div",{className:"flex items-center gap-3",children:[y.jsx(Ns,{icon:y.jsx(au,{className:"h-3.5 w-3.5 fill-current"}),onClick:t,disabled:!h,active:e==="running",variant:"play",title:"Run"}),y.jsx(Ns,{icon:y.jsx(H_,{className:"h-4 w-4 text-primary-white"}),onClick:n,disabled:!m,title:"Pause"}),y.jsx(Ns,{icon:y.jsx(V_,{className:"h-4 w-4 text-primary-white"}),onClick:r,disabled:!x,title:"Step"}),y.jsx(Ns,{icon:y.jsx(tg,{className:"h-4 w-4 text-primary-white"}),onClick:i,disabled:!v,title:"Stop"}),y.jsx(Ns,{icon:y.jsx(B_,{className:"h-4 w-4 text-primary-white"}),onClick:s,disabled:!b,title:"Reset"})]}),y.jsx("div",{className:"mx-3 h-6 w-px bg-secondary-dark-gray"}),y.jsx(sn,{content:"Instant runs the entire graph at once, then enables replay. Step-by-Step pauses after each node so you can inspect intermediate values.",children:y.jsx(zf,{options:Z2,value:a,onChange:l,disabled:!g,size:"small"})}),y.jsx(sn,{content:"Maximum loop iterations before the runner throws an error. Protects against infinite loops.",children:y.jsx("div",{className:ye("ml-4",!g&&"pointer-events-none opacity-50"),children:y.jsx(ni,{name:"Max Loops",value:u,onChange:S=>d(Math.max(1,Math.round(S))),size:"small",decimals:0})})})]})}const bb=T.createContext(null);function Q2({children:e}){const[t,n]=T.useState(null),[r,i]=T.useState(!0),[s,a]=T.useState(!0),[l,u]=T.useState(!0),[d,f]=T.useState("execution"),[g,h]=T.useState(!1),[m,x]=T.useState(new Map),[v,b]=T.useState(2),S=T.useCallback(()=>{const I={};for(const[k,A]of m)I[k]=A;return{selectedStepIndex:t,edgeValuesAnimated:r,panelOpen:s,autoScroll:l,timeMode:d,timelineCollapsed:g,selectedIterations:I,autoplayIntervalSec:v}},[t,r,s,l,d,g,m,v]),N=T.useCallback(I=>{I.selectedStepIndex!==void 0&&n(I.selectedStepIndex),I.edgeValuesAnimated!==void 0&&i(I.edgeValuesAnimated),I.panelOpen!==void 0&&a(I.panelOpen),I.autoScroll!==void 0&&u(I.autoScroll),I.timeMode!==void 0&&f(I.timeMode),I.timelineCollapsed!==void 0&&h(I.timelineCollapsed),I.selectedIterations&&x(new Map(Object.entries(I.selectedIterations).map(([k,A])=>[k,A]))),I.autoplayIntervalSec!==void 0&&b(I.autoplayIntervalSec)},[]),w=T.useMemo(()=>({selectedStepIndex:t,setSelectedStepIndex:n,edgeValuesAnimated:r,setEdgeValuesAnimated:i,isRunnerPanelOpen:s,setIsRunnerPanelOpen:a,autoScroll:l,setAutoScroll:u,timeMode:d,setTimeMode:f,timelineCollapsed:g,setTimelineCollapsed:h,selectedIterations:m,setSelectedIterations:x,autoplayIntervalSec:v,setAutoplayIntervalSec:b,getViewState:S,restoreViewState:N}),[t,r,s,l,d,g,m,v,S,N]);return y.jsx(bb.Provider,{value:w,children:e})}function Uf(){const e=T.useContext(bb);if(!e)throw new Error("useRecordingViewState must be used within a RecordingViewStateProvider");return e}const Is=.5,Wf=1e4,eD=.003,Sb=3;function tD({adjustedTotalDuration:e,timePadRightMs:t,gutterWidth:n}){const r=T.useRef(null),i=T.useRef(!1),s=T.useRef(0),a=T.useRef(0),[l,u]=T.useState(0),d=T.useRef(null),f=T.useRef(null),g=r.current;if(g!==f.current&&(d.current&&(d.current.disconnect(),d.current=null),f.current=g,g)){u(g.clientWidth);const P=new ResizeObserver(L=>{const j=L[0];j&&u(j.contentRect.width)});P.observe(g),d.current=P}T.useEffect(()=>()=>{d.current?.disconnect()},[]);const[h,m]=T.useState(!0),[x,v]=T.useState(Is),b=T.useMemo(()=>{const P=l-n;return P<=0||e<=0?Is:Math.max(Is,Math.min(Wf,P/(e*(1+t))))},[l,n,e,t]),S=h?b:x,N=T.useRef(b);T.useLayoutEffect(()=>{if(!h||N.current===b)return;N.current=b;const P=r.current;P&&(P.scrollLeft=0)},[h,b]);const w=T.useRef(null);T.useLayoutEffect(()=>{w.current!==null&&r.current&&(r.current.scrollLeft=w.current,w.current=null)});const I=T.useCallback(()=>{m(!0);const P=r.current;P&&(P.scrollLeft=0)},[]),k=T.useCallback(P=>{const L=r.current;if(!L)return;const j=L.scrollLeft+(L.clientWidth-n)/2,O=h?b:x,W=j/O,z=Math.max(Is,Math.min(Wf,O*P));w.current=W*z-(L.clientWidth-n)/2,m(!1),v(z)},[n,h,b,x]),A=T.useRef(S);A.current=S;const M=T.useRef(n);M.current=n;const B=T.useRef(h);B.current=h;const U=T.useRef(null);U.current||(U.current=P=>{if(!P.shiftKey)return;P.preventDefault();const L=r.current;if(!L)return;const j=M.current,O=L.getBoundingClientRect(),W=P.clientX-O.left+L.scrollLeft-j,z=A.current,Y=W/z,J=-P.deltaY*eD,ie=Math.pow(2,J),ee=Math.max(Is,Math.min(Wf,z*ie));w.current=Y*ee-(P.clientX-O.left-j),m(!1),v(ee)});const q=T.useRef(null);T.useEffect(()=>{const P=r.current,L=U.current;if(P!==q.current)return q.current&&q.current.removeEventListener("wheel",L),q.current=P,P&&P.addEventListener("wheel",L,{passive:!1}),()=>{q.current&&(q.current.removeEventListener("wheel",L),q.current=null)}});const D=T.useRef(0),$=T.useRef(0),F=T.useRef(!1),E=T.useCallback(P=>{if(P.button!==0&&P.button!==1)return;const L=r.current;if(!L)return;P.preventDefault(),i.current=!0,F.current=!1,s.current=P.clientX,D.current=P.clientY,a.current=L.scrollLeft,$.current=L.scrollTop,L.style.cursor="grabbing",document.body.style.userSelect="none";const j=W=>{if(!i.current)return;W.preventDefault();const z=W.clientX-s.current,Y=W.clientY-D.current;(Math.abs(z)>Sb||Math.abs(Y)>Sb)&&(F.current=!0),L.scrollLeft=a.current-z,L.scrollTop=$.current-Y},O=()=>{i.current=!1,L.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",O),document.removeEventListener("mouseleave",O),requestAnimationFrame(()=>{F.current=!1})};document.addEventListener("mousemove",j),document.addEventListener("mouseup",O),document.addEventListener("mouseleave",O)},[]);return{timeScale:S,scrollContainerRef:r,fitToView:I,zoomBy:k,handlePanStart:E,didPanMoveRef:F}}const nD=6;function _b(e,t){const n=e.startTime*t,r=Math.max(e.duration*t,nD);return n+r/2}function Nb(e,t,n){if(t.length===0)return null;let r=t[0].stepIndex,i=1/0;for(const s of t){const a=_b(s,n),l=Math.abs(a-e);l<i&&(i=l,r=s.stepIndex)}return r}function rD({steps:e,timeScale:t,contentWidth:n,currentStepIndex:r,scrollContainerRef:i,gutterWidth:s,onScrubTo:a}){const[l,u]=T.useState(null),[d,f]=T.useState(null),g=T.useRef(null),h=l!==null,m=T.useRef(!1),x=T.useRef(r);x.current!==r&&!h&&(m.current=!0),x.current=r;const v=e[r],b=v?_b(v,t):0,S=l??b,N=T.useCallback(A=>{const M=i.current;if(!M||e.length===0)return;const B=M.getBoundingClientRect(),U=A-B.left+M.scrollLeft-s,q=Math.max(0,Math.min(U,n));u(q);const D=Nb(q,e,t);g.current=D,f(D),D!==null&&a(D);const $=E=>{const P=M.getBoundingClientRect(),L=E.clientX-P.left+M.scrollLeft-s,j=Math.max(0,Math.min(L,n));u(j);const O=Nb(j,e,t);O!==g.current&&O!==null&&a(O),g.current=O,f(O)},F=()=>{document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",F),g.current!==null&&a(g.current),g.current=null,u(null),f(null),m.current=!0,setTimeout(()=>{m.current=!1},200)};document.addEventListener("mousemove",$),document.addEventListener("mouseup",F)},[e,t,n,s,i,a]),w=T.useCallback(A=>{A.stopPropagation(),N(A.clientX)},[N]),I=T.useCallback(A=>{A.stopPropagation(),A.preventDefault(),N(A.clientX)},[N]),k=T.useCallback(()=>{m.current=!1},[]);return{scrubberPx:S,isDraggingScrubber:h,nearestDragStepIndex:d,isSnapping:m.current,startScrubDrag:N,handleRulerScrubDown:w,handleScrubberMouseDown:I,onSnapTransitionEnd:k}}const Es=28,Ts=3,Yc=4,oD=32,Gf=6,Ib=0,Eb=.15,Tb=48,Cb=50,Ab=18,iD=[{value:"execution",label:"Execution"},{value:"wallClock",label:"Wall Clock"}],sD={completed:"bg-runner-bar-completed",errored:"bg-runner-bar-errored",skipped:"bg-status-skipped"},aD={completed:"text-status-completed",errored:"text-status-errored",skipped:"text-secondary-light-gray"},cD={completed:"Done",errored:"Error",skipped:"Skipped"};function kb(e){const t=Math.pow(10,Math.floor(Math.log10(e))),n=e/t;return n<=1?t:n<=2?2*t:n<=5?5*t:10*t}function Mb(e){return e===0||e<0?"0":e<1?`${(e*1e3).toFixed(0)}µs`:e<1e3?`${e.toFixed(e<10?1:0)}ms`:`${(e/1e3).toFixed(2)}s`}function lD(e){return e.estimatedTiming?"< 0.1ms":`${e.duration.toFixed(2)}ms`}function uD(e){const t=new Map;for(const n of e){const r=t.get(n.concurrencyLevel);r?r.push(n):t.set(n.concurrencyLevel,[n])}return t}const Ob={loopStart:0,preStop:1,loopStop:2,postStop:3,loopEnd:4};function dD(e,t){const n=e.loopPhase?Ob[e.loopPhase]:1,r=t.loopPhase?Ob[t.loopPhase]:1;return n!==r?n-r:e.startTime-t.startTime}function Pb(e,t,n){const r=t.iterations.map(i=>{const s=i.stepRecords;if(s.length===0)return{...i,adjustedStartTime:i.startTime,adjustedEndTime:i.endTime,adjustedDuration:i.duration};let a=1/0,l=-1/0;for(const u of s){const d=n?u.startTime-u.pauseAdjustment:u.startTime,f=n?u.endTime-u.pauseAdjustment:u.endTime;d<a&&(a=d),f>l&&(l=f)}return{...i,adjustedStartTime:a,adjustedEndTime:l,adjustedDuration:l-a}});return{kind:"loop",loopStructureId:e,loopRecord:t,adjustedIterations:r,iterations:t.iterations.map(i=>({iteration:i.iteration,conditionValue:i.conditionValue,steps:[...i.stepRecords].sort(dD).map(s=>({...s,startTime:n?s.startTime-s.pauseAdjustment:s.startTime,endTime:n?s.endTime-s.pauseAdjustment:s.endTime,loopStructureId:void 0,loopIteration:void 0})),nestedLoopRecords:i.nestedLoopRecords}))}}function Rb(e,t,n){const r=[];let i=[];const s=new Map;for(const a of e)if(a.loopStructureId!==void 0&&a.loopIteration!==void 0){const u=a.loopStructureId,d=t.get(u);if(!d)continue;if(!s.has(u)&&i.length>0&&(r.push({kind:"flat",steps:i}),i=[]),!s.has(u)){const f=Pb(u,d,n);s.set(u,f),r.push(f)}}else{if(a.loopStructureId!==void 0&&!t.has(a.loopStructureId))continue;i.push(a)}i.length>0&&r.push({kind:"flat",steps:i});for(const[a,l]of t){if(s.has(a))continue;const u=Pb(a,l,n),d=l.iterations[0]?.startTime??0;let f=r.length;for(let g=r.length-1;g>=0;g--){const h=r[g];if((h.kind==="flat"?h.steps[0]?.startTime??0:h.loopRecord.iterations[0]?.startTime??0)<=d){if(h.kind==="flat"){const x=h.steps.filter(b=>b.startTime<=d),v=h.steps.filter(b=>b.startTime>d);if(x.length>0&&v.length>0){r.splice(g,1,{kind:"flat",steps:x},u,{kind:"flat",steps:v}),f=-1;break}}f=g+1;break}}f>=0&&r.splice(f,0,u)}return r}function fD({step:e}){return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("span",{className:"text-[12px] font-semibold text-primary-white",children:e.nodeTypeName}),y.jsx("span",{className:ye("text-[10px] font-medium",aD[e.status]),children:cD[e.status]})]}),y.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-secondary-light-gray",children:[y.jsx("span",{className:"font-mono tabular-nums",children:lD(e)}),y.jsx("span",{className:"text-secondary-dark-gray",children:"·"}),y.jsxs("span",{children:["Step ",e.stepIndex]}),e.loopIteration!==void 0&&y.jsxs(y.Fragment,{children:[y.jsx("span",{className:"text-secondary-dark-gray",children:"·"}),y.jsxs("span",{children:["Iter ",e.loopIteration]})]})]})]})}function pD({step:e,timeScale:t,timeOffset:n=0,isSelected:r,isSnapped:i,isNearestDragTarget:s,onClick:a,onScrubTo:l,subRowTop:u,subRowHeight:d}){const f=(e.startTime-n)*t,g=Math.max(e.duration*t,Gf),h=g>Cb&&d>=Ab;return y.jsx(sn,{as:"div",placement:"top",content:y.jsx(fD,{step:e}),className:ye("timeline-block absolute cursor-pointer rounded-[2px]",sD[e.status],r&&"z-10 ring-1 ring-white ring-offset-0",!r&&i&&!s&&"z-10 ring-2 ring-primary-blue ring-offset-0 shadow-[0_0_12px_rgba(71,114,179,0.4)]",!r&&s&&"z-10 ring-1 ring-white/70 ring-offset-0 brightness-125 shadow-[0_0_20px_rgba(71,114,179,0.7)]"),style:{left:`${f}px`,width:`${g}px`,top:`${u}px`,height:`${d}px`},triggerProps:{"data-step-index":e.stepIndex,onClick:m=>{m.stopPropagation(),a()},onContextMenu:m=>{m.preventDefault(),m.stopPropagation(),l()}},children:h&&y.jsx("span",{className:"block truncate px-2 text-[12px] font-normal text-[#eee] drop-shadow-sm select-none",style:{lineHeight:`${d}px`},children:e.nodeTypeName})})}function hD({steps:e,timeScale:t,timeOffset:n=0,contentWidth:r,selectedStepIndex:i,currentStepIndex:s,nearestDragStepIndex:a,onStepClick:l,onScrubTo:u}){const d=e.length,f=d>1?(d-1)*Yc:0,g=d>1?Es+(d-1)*(Es-Ts*2)+f:Es,h=g-Ts*2-f,m=d>0?h/d:h;return y.jsx("div",{className:"relative",style:{height:`${g}px`,width:`${r}px`,marginBottom:`${Yc}px`},children:e.map((x,v)=>y.jsx(pD,{step:x,timeScale:t,timeOffset:n,isSelected:i===x.stepIndex,isSnapped:s===x.stepIndex,isNearestDragTarget:a===x.stepIndex,onClick:()=>l(x),onScrubTo:()=>u(x.stepIndex),subRowTop:Ts+v*(m+Yc),subRowHeight:m},`${x.nodeId}-${x.stepIndex}`))})}function Lb({steps:e,timeScale:t,contentWidth:n,selectedStepIndex:r,currentStepIndex:i,nearestDragStepIndex:s,onStepClick:a,onScrubTo:l}){const u=T.useMemo(()=>uD(e),[e]),d=T.useMemo(()=>Array.from(u.keys()).sort((f,g)=>f-g),[u]);return e.length===0?null:y.jsx(y.Fragment,{children:d.map(f=>{const g=u.get(f);return g?y.jsx(hD,{steps:g,timeScale:t,contentWidth:n,selectedStepIndex:r,currentStepIndex:i,nearestDragStepIndex:s,onStepClick:a,onScrubTo:l},`flat-${f}`):null})})}function gD({iterRecord:e,iterDisplay:t,loopRecord:n}){const r=e.iteration===n.totalIterations-1&&e.conditionValue===!0;return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsxs("span",{className:"text-[12px] font-semibold text-primary-white",children:["Loop Iteration ",e.iteration]}),r?y.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-status-errored",children:[y.jsx(ng,{className:"h-2.5 w-2.5"})," max exceeded"]}):e.conditionValue?y.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-status-completed",children:[y.jsx(sa,{className:"h-2.5 w-2.5"})," continues"]}):y.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-secondary-light-gray",children:[y.jsx(aa,{className:"h-2.5 w-2.5"})," exits"]})]}),y.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-secondary-light-gray",children:[y.jsxs("span",{className:"font-mono tabular-nums",children:[e.duration.toFixed(2),"ms"]}),y.jsx("span",{className:"text-secondary-dark-gray",children:"·"}),y.jsxs("span",{children:[t.steps.length," steps"]})]})]})}function mD({segment:e,timeScale:t,contentWidth:n,selectedIteration:r,onSelectIteration:i,selectedStepIndex:s}){const{loopRecord:a,iterations:l}=e,u=a.iterations.length>0&&a.iterations[a.iterations.length-1].conditionValue===!0;return y.jsx("div",{className:"relative",style:{height:`${Es}px`,width:`${n}px`,marginBottom:`${Yc}px`},children:e.adjustedIterations.map((d,f)=>{const g=l[f];if(!g)return null;const h=d.adjustedStartTime*t,m=Math.max(d.adjustedDuration*t,Gf),x=r===d.iteration,v=u&&f===a.iterations.length-1,b=s!==null&&g.steps.some(w=>w.stepIndex===s),S=Es-Ts*2,N=m>Cb&&S>=Ab;return y.jsx(yD,{iterRecord:d,iterDisplay:g,loopRecord:a,left:h,width:m,blockHeight:S,showLabel:N,isSelected:x,isLastAndError:v,hasSelectedStep:b,onSelect:()=>i(d.iteration)},d.iteration)})})}function yD({iterRecord:e,iterDisplay:t,loopRecord:n,left:r,width:i,blockHeight:s,showLabel:a,isSelected:l,isLastAndError:u,hasSelectedStep:d,onSelect:f}){return y.jsx(sn,{as:"div",placement:"top",content:y.jsx(gD,{iterRecord:e,iterDisplay:t,loopRecord:n}),className:ye("absolute cursor-pointer rounded-[2px] bg-[#8c52d1]/60",l&&"z-10 ring-1 ring-[#8c52d1] ring-offset-0 bg-[#8c52d1]/80",!l&&d&&"z-10 ring-1 ring-white/50 ring-offset-0",u&&"border border-status-errored/50"),style:{left:`${r}px`,width:`${i}px`,top:`${Ts}px`,height:`${s}px`},triggerProps:{onClick:g=>{g.stopPropagation(),f()}},children:a?y.jsxs("span",{className:"flex items-center gap-1 truncate px-2 text-[11px] font-normal text-[#eee] drop-shadow-sm select-none",style:{lineHeight:`${s}px`},children:[y.jsx(Qh,{className:"h-2.5 w-2.5 flex-shrink-0"}),"Iter ",e.iteration]}):y.jsx("span",{className:"flex items-center justify-center text-[9px] font-medium text-[#eee] select-none",style:{lineHeight:`${s}px`},children:e.iteration})})}function vD({iteration:e,nestedLoopRecords:t,adjustForPause:n,selectedIterations:r,onSelectIteration:i,timeScale:s,contentWidth:a,selectedStepIndex:l,currentStepIndex:u,nearestDragStepIndex:d,onStepClick:f,onScrubTo:g}){const{steps:h}=e,m=T.useMemo(()=>Rb(h,t,n),[h,t,n]);return m.length===0?y.jsx("div",{className:"py-2 text-center text-[10px] text-secondary-light-gray",children:"No steps in this iteration"}):y.jsx("div",{className:"relative pb-1",style:{minHeight:"40px"},children:y.jsx("div",{className:"relative",style:{width:`${a}px`},children:m.map((x,v)=>{if(x.kind==="flat")return y.jsx(Lb,{steps:x.steps,timeScale:s,contentWidth:a,selectedStepIndex:l,currentStepIndex:u,nearestDragStepIndex:d,onStepClick:f,onScrubTo:g},`iter-${e.iteration}-flat-${v}`);const b=x.loopStructureId,S=r.get(b)??null;return y.jsx(Db,{segment:x,timeScale:s,contentWidth:a,selectedIteration:S,onSelectIteration:N=>{const w=r.get(b);i(b,w===N?null:N)},selectedStepIndex:l,currentStepIndex:u,nearestDragStepIndex:d,onStepClick:f,onScrubTo:g,adjustForPause:n,selectedIterations:r,onNestedSelectIteration:i},`iter-${e.iteration}-loop-${b}`)})})})}function Db({segment:e,timeScale:t,contentWidth:n,selectedIteration:r,onSelectIteration:i,selectedStepIndex:s,currentStepIndex:a,nearestDragStepIndex:l,onStepClick:u,onScrubTo:d,adjustForPause:f,selectedIterations:g,onNestedSelectIteration:h}){const{iterations:m}=e,x=r!==null?m[r]??null:null;return y.jsxs("div",{children:[y.jsx(mD,{segment:e,timeScale:t,contentWidth:n,selectedIteration:r,onSelectIteration:i,selectedStepIndex:s}),x&&y.jsxs("div",{className:"mb-1",children:[y.jsxs("div",{className:"sticky left-0 z-[5] ml-4 flex w-fit items-center gap-2 rounded-t-[3px] border border-b-0 border-[#8c52d1]/30 bg-runner-timeline-box-bg px-2 py-1 text-[10px]",children:[y.jsx(Qh,{className:"h-2.5 w-2.5 text-[#8c52d1]"}),y.jsxs("span",{className:"font-medium text-primary-white",children:["Iteration ",x.iteration]}),y.jsxs("span",{className:"text-secondary-light-gray",children:[x.steps.length," step",x.steps.length!==1?"s":""]}),x.conditionValue?y.jsxs("span",{className:"flex items-center gap-0.5 text-status-completed/70",children:[y.jsx(sa,{className:"h-2.5 w-2.5"})," continues"]}):y.jsxs("span",{className:"flex items-center gap-0.5 text-secondary-light-gray",children:[y.jsx(aa,{className:"h-2.5 w-2.5"})," exits"]})]}),y.jsx("div",{className:"-mt-px rounded-[3px] border border-[#8c52d1]/30 bg-runner-timeline-box-bg/50",children:y.jsx(vD,{iteration:x,nestedLoopRecords:x.nestedLoopRecords,adjustForPause:f,selectedIterations:g,onSelectIteration:h,timeScale:t,contentWidth:n,selectedStepIndex:s,currentStepIndex:a,nearestDragStepIndex:l,onStepClick:u,onScrubTo:d})})]})]})}function xD({timeScale:e,contentWidth:t,totalDuration:n,onScrubDown:r}){const i=Tb/e,s=kb(i),a=[];for(let l=0;l<=n+s;l+=s)a.push(l);return y.jsx("div",{className:"relative border-b border-[#3a3a3a] bg-runner-ruler-bg",style:{height:`${oD}px`,width:`${t}px`},children:y.jsx("div",{className:"relative h-full cursor-ew-resize select-none",onMouseDown:r,children:a.map(l=>{const u=l*e;return u>t?null:y.jsxs("div",{className:"absolute bottom-1 -translate-x-1/2",style:{left:`${u}px`},children:[y.jsx("span",{className:"font-mono text-[11px] tabular-nums text-[#9a9a9a] select-none whitespace-nowrap",children:Mb(l)}),y.jsx("div",{className:"absolute -bottom-1 left-1/2 h-1 w-px bg-[#555]"})]},l)})})})}function wD({timeScale:e,contentWidth:t,totalDuration:n}){const r=Tb/e,i=kb(r),s=[];for(let a=0;a<=n+i;a+=i){const l=a*e;l<=t&&s.push(l)}return y.jsx("div",{className:"pointer-events-none absolute inset-0",children:s.map(a=>y.jsx("div",{className:"absolute top-0 bottom-0 w-px bg-runner-grid-line",style:{left:`${a}px`}},a))})}function bD({timeMs:e,isDragging:t}){return y.jsxs("div",{className:"flex flex-col items-center",children:[y.jsx("div",{className:ye("rounded px-1.5 py-0.5 font-mono text-[11px] text-white whitespace-nowrap",t?"bg-[#6a9be0]":"bg-runner-scrubber-blue"),children:Mb(e)}),y.jsx("div",{className:"h-0 w-0 border-l-[4px] border-r-[4px] border-t-[4px] border-l-transparent border-r-transparent border-t-runner-scrubber-blue"})]})}function jb({record:e,currentStepIndex:t,onScrubTo:n,onStepClick:r,selectedStepIndex:i,onNavigateToNode:s}){const{autoScroll:a,setAutoScroll:l,timeMode:u,setTimeMode:d,timelineCollapsed:f,setTimelineCollapsed:g,selectedIterations:h,setSelectedIterations:m,autoplayIntervalSec:x,setAutoplayIntervalSec:v}=Uf(),b=(e?.totalPauseDuration??0)>0,S=T.useMemo(()=>e?u==="wallClock"?e.steps:e.steps.map(ae=>({...ae,startTime:ae.startTime-ae.pauseAdjustment,endTime:ae.endTime-ae.pauseAdjustment})):[],[e,u]),N=e?u==="execution"?e.totalDuration-e.totalPauseDuration:e.totalDuration:0,w=T.useMemo(()=>e?Rb(S,e.loopRecords,u==="execution"):[],[S,e,u]),I=T.useRef(!1);T.useEffect(()=>{if(I.current||w.length===0)return;const ae=w.find(Ie=>Ie.kind==="loop");ae&&(I.current=!0,m(new Map([[ae.loopStructureId,0]])))},[w]),T.useEffect(()=>{if(i===null||!e)return;const ae=e.steps.find(Ie=>Ie.stepIndex===i);ae?.loopStructureId!==void 0&&ae.loopIteration!==void 0&&m(Ie=>{const Be=new Map(Ie);return Be.set(ae.loopStructureId,ae.loopIteration),Be})},[i,e]);const{timeScale:k,scrollContainerRef:A,fitToView:M,zoomBy:B,handlePanStart:U,didPanMoveRef:q}=tD({adjustedTotalDuration:N,timePadRightMs:Eb,gutterWidth:Ib}),D=N+N*Eb,$=D*k,{scrubberPx:F,isDraggingScrubber:E,nearestDragStepIndex:P,isSnapping:L,handleRulerScrubDown:j,handleScrubberMouseDown:O,onSnapTransitionEnd:W}=rD({steps:S,timeScale:k,contentWidth:$,currentStepIndex:t,scrollContainerRef:A,gutterWidth:Ib,onScrubTo:n}),z=T.useCallback(ae=>{q.current||r(ae)},[r,q]),Y=k>0?F/k:0,J=T.useRef(null),[ie,ee]=T.useState(!1),ce=T.useRef(null),ge=i??t,Q=e!==null&&ge>0,te=e!==null&&ge<e.steps.length-1,ne=T.useCallback(ae=>{const Ie=A.current;if(!Ie||k<=0)return;const Be=S.find(Nt=>Nt.stepIndex===ae.stepIndex),Ue=(Be?Be.startTime:ae.startTime-ae.pauseAdjustment)*k,Ze=Be?Be.endTime-Be.startTime:ae.duration,pt=Math.max(Ze*k,Gf),Cn=Ue+pt/2,cn=Math.max(0,Cn-Ie.clientWidth/2);setTimeout(()=>{const Nt=A.current;if(!Nt)return;let $t=Nt.scrollTop;const ln=Nt.querySelector(`[data-step-index="${ae.stepIndex}"]`);if(ln){const Or=Nt.getBoundingClientRect(),Un=ln.getBoundingClientRect(),fo=Un.top+Un.height/2,po=Or.top+Or.height/2,Pr=fo-po;Math.abs(Pr)>4&&($t=Nt.scrollTop+Pr)}Nt.scrollTo({left:cn,top:$t,behavior:"smooth"})},50)},[A,k,S]),oe=T.useCallback(ae=>{ae.loopStructureId!==void 0&&ae.loopIteration!==void 0&&m(Ie=>{if(Ie.get(ae.loopStructureId)===ae.loopIteration)return Ie;const Be=new Map(Ie);return Be.set(ae.loopStructureId,ae.loopIteration),Be})},[m]),pe=T.useCallback(()=>{if(!e||ge<=0)return;const ae=e.steps[ge-1];ae&&(oe(ae),r(ae),a&&(s?.(ae.nodeId),ne(ae)))},[e,ge,r,s,ne,a,oe]),le=T.useCallback(()=>{if(!e||ge>=e.steps.length-1)return;const ae=e.steps[ge+1];ae&&(oe(ae),r(ae),a&&(s?.(ae.nodeId),ne(ae)))},[e,ge,r,s,ne,a,oe]),ve=T.useCallback(()=>{if(!e||e.steps.length===0)return;ee(!1);const ae=e.steps[0];oe(ae),r(ae),a&&(s?.(ae.nodeId),ne(ae))},[e,r,s,ne,a,oe]),me=T.useCallback(()=>{if(!e||e.steps.length===0)return;ee(!1);const ae=e.steps[e.steps.length-1];oe(ae),r(ae),a&&(s?.(ae.nodeId),ne(ae))},[e,r,s,ne,a,oe]);T.useEffect(()=>{!ie||!e||ge>=e.steps.length-1&&ee(!1)},[ie,ge,e]),T.useEffect(()=>{if(ie&&e)return ce.current=setInterval(()=>{le()},x*1e3),()=>{ce.current&&clearInterval(ce.current)};ce.current&&(clearInterval(ce.current),ce.current=null)},[ie,x,e,le]);const Oe=T.useCallback(()=>{ee(ae=>!ae)},[]),Ce=T.useRef(t);return T.useEffect(()=>{if(Ce.current===t||(Ce.current=t,!a||!e||i!==null||E))return;const ae=e.steps[t];ae&&(oe(ae),s?.(ae.nodeId),ne(ae))},[t,a,e,i,E,oe,s,ne]),e?y.jsxs("div",{className:"flex h-full flex-col bg-runner-toolbar-bg",children:[y.jsxs("div",{className:"flex h-12 items-center justify-between px-4",children:[y.jsxs("div",{className:"flex items-center gap-3",children:[y.jsxs("button",{type:"button",onClick:()=>g(!f),className:"btn-press flex items-center gap-2 rounded px-1.5 py-1 text-[14px] text-primary-white transition-colors hover:bg-primary-dark-gray/50",children:[y.jsx("span",{className:ye("transition-transform duration-150",!f&&"rotate-90"),children:y.jsx(zr,{className:"h-3 w-3 text-secondary-light-gray"})}),"Timeline"]}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsxs("div",{className:"flex items-center",children:[y.jsx("button",{type:"button",disabled:!Q,onClick:ve,className:ye("btn-press rounded-l-md border border-secondary-dark-gray/80 px-1 py-0.5 transition-colors",Q?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:"Go to first step",children:y.jsx(O_,{className:"h-3.5 w-3.5"})}),y.jsx("button",{type:"button",disabled:!Q,onClick:pe,className:ye("btn-press border border-l-0 border-secondary-dark-gray/80 px-1 py-0.5 transition-colors",Q?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:"Previous step",children:y.jsx(iu,{className:"h-3.5 w-3.5"})}),y.jsx("button",{type:"button",disabled:!e||e.steps.length===0,onClick:Oe,className:ye("btn-press border border-l-0 border-secondary-dark-gray/80 px-1.5 py-0.5 transition-colors",ie?"bg-primary-blue text-white hover:bg-primary-blue/80":e&&e.steps.length>0?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:ie?"Stop autoplay":"Autoplay",children:ie?y.jsx(tg,{className:"h-3 w-3"}):y.jsx(au,{className:"h-3.5 w-3.5"})}),y.jsx("button",{type:"button",disabled:!te,onClick:le,className:ye("btn-press border border-l-0 border-secondary-dark-gray/80 px-1 py-0.5 transition-colors",te?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:"Next step",children:y.jsx(zr,{className:"h-3.5 w-3.5"})}),y.jsx("button",{type:"button",disabled:!te,onClick:me,className:ye("btn-press rounded-r-md border border-l-0 border-secondary-dark-gray/80 px-1 py-0.5 transition-colors",te?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:"Go to last step",children:y.jsx(P_,{className:"h-3.5 w-3.5"})})]}),y.jsx(sn,{content:"Seconds between each step during autoplay. Drag or click to adjust (0.5s–30s).",children:y.jsx(ni,{name:"Interval",value:x,onChange:ae=>v(Math.max(.5,ae)),min:.5,max:30,size:"small"})}),y.jsx(sn,{content:"Automatically scroll the timeline and canvas to follow the selected step",children:y.jsxs("label",{className:"flex cursor-pointer items-center gap-1 text-[12px] text-secondary-light-gray select-none",children:[y.jsx("input",{type:"checkbox",checked:a,onChange:ae=>l(ae.target.checked),className:"h-3 w-3 cursor-pointer rounded-sm accent-primary-blue"}),y.jsx("span",{className:"text-primary-white",children:"Auto-scroll"})]})})]})]}),y.jsxs("div",{className:"flex items-center gap-3",children:[b&&y.jsx(sn,{content:y.jsxs("div",{className:"space-y-1.5 text-[12px] leading-relaxed text-primary-white",children:[y.jsxs("div",{children:[y.jsx("span",{className:"font-semibold",children:"Execution"})," — Shows only computation time with pauses removed. Best for step-by-step mode."]}),y.jsxs("div",{children:[y.jsx("span",{className:"font-semibold",children:"Wall Clock"})," — Shows real elapsed time including pauses between steps."]})]}),children:y.jsx(zf,{options:iD,value:u,onChange:d,size:"small"})}),y.jsxs("div",{className:"flex items-center gap-2 font-mono text-[12px] text-primary-white",children:[y.jsx(sn,{content:"Total execution duration",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(F_,{className:"h-3.5 w-3.5"}),y.jsxs("span",{className:"tabular-nums",children:[N.toFixed(2),"ms"]})]})}),y.jsx("span",{children:"·"}),y.jsx(sn,{content:"Total number of executed steps",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(D_,{className:"h-3.5 w-3.5"}),y.jsxs("span",{children:[e.steps.length," steps"]})]})}),e.compilationDuration>0&&y.jsxs(y.Fragment,{children:[y.jsx("span",{children:"·"}),y.jsx(sn,{content:"JIT warmup time — absorbed before execution to ensure accurate step timings",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(z_,{className:"h-3.5 w-3.5"}),y.jsxs("span",{children:["JIT ",e.compilationDuration.toFixed(1),"ms"]})]})})]})]}),y.jsx("button",{type:"button",onClick:()=>B(1.5),className:"btn-press text-primary-white transition-colors hover:text-primary-blue",title:"Zoom In",children:y.jsx(U_,{className:"h-4 w-4"})}),y.jsx("button",{type:"button",onClick:()=>B(1/1.5),className:"btn-press text-primary-white transition-colors hover:text-primary-blue",title:"Zoom Out",children:y.jsx(W_,{className:"h-4 w-4"})}),y.jsx("button",{type:"button",onClick:M,className:"btn-press text-primary-white transition-colors hover:text-primary-blue",title:"Fit to View",children:y.jsx(j_,{className:"h-4 w-4"})})]})]}),!f&&y.jsx("div",{className:"min-h-0 flex-1 px-4 pb-4",children:y.jsx("div",{className:"flex h-full flex-col overflow-hidden rounded-md border border-runner-timeline-box-border bg-runner-timeline-box-bg",children:y.jsx("div",{ref:A,className:"timeline-scrollbar min-h-0 flex-1 overflow-x-auto overflow-y-auto",onMouseDown:U,children:y.jsxs("div",{className:"relative flex min-h-full flex-col",style:{minWidth:`${$}px`},children:[y.jsxs("div",{className:"sticky top-0 z-20",children:[y.jsx(xD,{timeScale:k,contentWidth:$,totalDuration:D,onScrubDown:j}),y.jsx("div",{className:"pointer-events-none absolute inset-y-0",style:{left:`${F}px`,transition:L?"left 150ms ease-out":"none"},children:y.jsx("div",{className:"pointer-events-auto absolute left-1/2 -translate-x-1/2 cursor-ew-resize",style:{top:"2px"},onMouseDown:O,children:y.jsx(bD,{timeMs:Y,isDragging:E})})})]}),y.jsxs("div",{ref:J,className:"relative",style:{minHeight:"120px"},children:[y.jsx(wD,{timeScale:k,contentWidth:$,totalDuration:D}),y.jsx("div",{className:"pt-3",children:w.map((ae,Ie)=>{if(ae.kind==="flat")return y.jsx(Lb,{steps:ae.steps,timeScale:k,contentWidth:$,selectedStepIndex:i,currentStepIndex:t,nearestDragStepIndex:P,onStepClick:z,onScrubTo:n},`flat-${Ie}`);const Be=ae.loopStructureId,Qe=h.get(Be)??null;return y.jsx(Db,{segment:ae,timeScale:k,contentWidth:$,selectedIteration:Qe,onSelectIteration:Ue=>{m(Ze=>{const pt=new Map(Ze);return Ze.get(Be)===Ue?pt.delete(Be):pt.set(Be,Ue),pt})},selectedStepIndex:i,currentStepIndex:t,nearestDragStepIndex:P,onStepClick:z,onScrubTo:n,adjustForPause:u==="execution",selectedIterations:h,onNestedSelectIteration:(Ue,Ze)=>{m(pt=>{const Cn=new Map(pt);return Ze===null?Cn.delete(Ue):Cn.set(Ue,Ze),Cn})}},`loop-${Be}`)})})]}),y.jsxs("div",{className:"pointer-events-none absolute inset-y-0 z-[15]",style:{left:`${F}px`,transition:L?"left 150ms ease-out":"none"},onTransitionEnd:W,children:[y.jsx("div",{className:"pointer-events-auto absolute left-1/2 top-0 bottom-0 w-0.5 -translate-x-1/2 cursor-ew-resize",onMouseDown:O}),y.jsx("div",{className:"pointer-events-none absolute left-1/2 top-0 bottom-0 w-px -translate-x-1/2",style:{backgroundColor:E?"rgba(74, 133, 255, 0.7)":"rgba(74, 133, 255, 0.5)"}})]})]})})})})]}):y.jsxs("div",{className:"flex h-full flex-col bg-runner-toolbar-bg",children:[y.jsx("div",{className:"flex h-12 items-center justify-between bg-runner-toolbar-bg px-4",children:y.jsxs("div",{className:"flex items-center gap-2 text-[14px] text-primary-white",children:[y.jsx(zr,{className:"h-3 w-3 text-secondary-light-gray"}),"Timeline"]})}),y.jsx("div",{className:"flex-1 p-4 pt-0",children:y.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 rounded-md border border-runner-timeline-box-border bg-runner-timeline-box-bg",children:[y.jsxs("div",{className:"flex items-center gap-1.5",children:[y.jsx("div",{className:"h-1.5 w-6 rounded-full bg-secondary-dark-gray"}),y.jsx("div",{className:"h-1.5 w-10 rounded-full bg-secondary-dark-gray"}),y.jsx("div",{className:"h-1.5 w-4 rounded-full bg-secondary-dark-gray"})]}),y.jsx("span",{className:"text-[11px] text-secondary-light-gray",children:"No execution record to display"})]})})]})}function SD(e){return e===void 0?"undefined":e===null?"null":typeof e=="boolean"?"boolean":typeof e=="number"?"number":typeof e=="string"?"string":e instanceof Map?`Map(${e.size})`:Array.isArray(e)?`Array(${e.length})`:typeof e=="function"?"function":`Object(${Object.keys(e).length})`}function _D(e){if(e==null)return!1;const t=typeof e;return t==="object"||t==="function"}function Cs(e,t){if(t&&_D(e))return SD(e);if(e===void 0)return"undefined";if(e===null)return"null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number")return String(e);if(typeof e=="string")return`"${e}"`;if(e instanceof Map)return`Map { ${Array.from(e.entries()).map(([r,i])=>`${String(r)}: ${Cs(i,t)}`).join(", ")} }`;if(Array.isArray(e))return`[${e.map(n=>Cs(n,t)).join(", ")}]`;try{return JSON.stringify(e,null,2)}catch{return String(e)}}const ND={completed:{bg:"bg-runner-bar-completed",text:"text-[#e0f0e0]",label:"Completed"},errored:{bg:"bg-runner-bar-errored",text:"text-[#f0e0e0]",label:"Error"},skipped:{bg:"bg-[#888888]/30",text:"text-[#888888]",label:"Skipped"}};function ID({status:e}){const t=ND[e];return y.jsx("span",{className:ye("rounded-full px-3 py-1 text-[13px] font-medium",t.bg,t.text),children:t.label})}function ED({conn:e,hideComplex:t,debugMode:n}){return y.jsxs("div",{className:"flex flex-col gap-1.5",children:[y.jsxs("div",{className:"text-[13px]",children:[y.jsx("span",{className:"text-[#9a9a9a]",children:"Coming From–"})," ",y.jsxs("span",{className:"text-primary-white/80",children:[e.sourceNodeName," / ",e.sourceHandleName]})]}),n&&y.jsxs("div",{className:"text-[9px] text-secondary-dark-gray",children:["nodeId: ",e.sourceNodeId," · handleId: ",e.sourceHandleId]}),y.jsx("div",{className:"rounded-md border border-runner-value-border bg-runner-value-bg px-3 py-2 font-mono text-[14px] text-primary-white",children:Cs(e.value,t)})]})}function TD({handleName:e,handleValue:t,hideComplex:n,debugMode:r}){return y.jsxs("div",{className:"flex flex-col gap-1.5",children:[y.jsxs("div",{className:"text-[14px] text-primary-white",children:[e," ",y.jsxs("span",{className:"text-secondary-light-gray",children:["(",t.dataTypeId,")"]})]}),t.connections.length>0?t.connections.map((i,s)=>y.jsx(ED,{conn:i,hideComplex:n,debugMode:r},`${i.sourceNodeId}-${i.sourceHandleId}-${s}`)):t.isDefault?y.jsx("div",{className:"rounded-md border border-runner-value-border bg-runner-value-bg px-3 py-2 font-mono text-[14px] text-primary-white",children:Cs(t.defaultValue,n)}):y.jsx("span",{className:"text-[13px] italic text-secondary-light-gray",children:"No value"})]})}function CD({handleName:e,handleValue:t,hideComplex:n}){return y.jsxs("div",{className:"flex flex-col gap-1.5",children:[y.jsxs("div",{className:"text-[14px] text-primary-white",children:[e," ",y.jsxs("span",{className:"text-secondary-light-gray",children:["(",t.dataTypeId,")"]})]}),y.jsx("div",{className:"rounded-md border border-runner-value-border bg-runner-value-bg px-3 py-2 font-mono text-[14px] text-primary-white",children:Cs(t.value,n)})]})}function $b({stepRecord:e,onClose:t,loopRecords:n,hideComplexValues:r=!1,debugMode:i=!1,edgeValuesAnimated:s,onEdgeValuesAnimatedChange:a}){if(!e)return null;const l=Array.from(e.inputValues.entries()),u=Array.from(e.outputValues.entries());return y.jsxs("div",{className:"flex w-[340px] animate-slide-in-right flex-col bg-runner-panel-bg",children:[y.jsxs("div",{className:"flex items-center justify-between border-b border-secondary-dark-gray px-4 py-3",children:[y.jsxs("div",{className:"flex items-center gap-2.5",children:[y.jsx($_,{className:"h-5 w-5 text-primary-white"}),y.jsx("span",{className:"text-[15px] tracking-wide text-primary-white",children:e.nodeTypeName})]}),y.jsxs("div",{className:"flex items-center gap-3",children:[a&&y.jsx(sn,{content:"Animate edge value badges along the connection path instead of showing them statically",children:y.jsxs("label",{className:"flex cursor-pointer items-center gap-1.5 text-[12px] text-secondary-light-gray select-none",children:[y.jsx("input",{type:"checkbox",checked:s??!0,onChange:d=>a(d.target.checked),className:"h-3 w-3 accent-primary-blue"}),y.jsx("span",{className:"text-primary-white",children:"Animate"})]})}),y.jsx("button",{type:"button",onClick:t,className:"btn-press rounded p-1 text-secondary-light-gray transition-colors hover:text-primary-white","aria-label":"Close",children:y.jsx(aa,{className:"h-3.5 w-3.5"})})]})]}),y.jsxs("div",{className:"flex flex-col gap-3 border-b border-secondary-dark-gray px-4 py-3.5",children:[y.jsxs("div",{className:"flex items-center justify-between rounded-md border border-runner-value-border px-3 py-2",children:[y.jsx(ID,{status:e.status}),y.jsx("span",{className:"font-mono text-[13px] text-secondary-light-gray",children:e.estimatedTiming?"< 0.1ms":`${e.duration.toFixed(2)}ms`})]}),y.jsxs("div",{className:"rounded-md border border-runner-value-border bg-runner-timeline-box-bg px-3 py-2.5",children:[y.jsxs("div",{className:"text-center text-[13px] text-secondary-light-gray",children:[e.startTime.toFixed(2),"ms"," ",y.jsx("span",{className:"text-secondary-dark-gray",children:"→"})," ",e.endTime.toFixed(2),"ms"]}),y.jsxs("div",{className:"relative mt-2 h-1.5 w-full overflow-hidden rounded-full bg-[#333]",children:[y.jsx("div",{className:"absolute h-full rounded-full bg-secondary-light-gray/50",style:{left:"20%",width:"55%"}}),y.jsx("div",{className:"absolute h-full w-0.5 bg-secondary-light-gray",style:{left:"77%"}})]})]}),(e.loopIteration!==void 0||e.groupNodeId)&&y.jsxs("div",{className:"flex flex-col gap-2",children:[e.loopIteration!==void 0&&(()=>{const d=e.loopStructureId&&n?n.get(e.loopStructureId):void 0,f=d?.iterations[e.loopIteration];return y.jsxs("div",{className:"rounded-md border border-runner-value-border px-3 py-2",children:[y.jsxs("div",{className:"text-[12px] text-primary-white",children:["Loop iteration ",e.loopIteration+1,d?` of ${d.totalIterations}`:""]}),f&&y.jsxs("div",{className:"mt-1 text-[10px] text-secondary-light-gray",children:["Condition:"," ",f.conditionValue?"true (continues)":"false (exits)"]})]})})(),e.groupNodeId&&y.jsxs("div",{className:"text-[11px] text-secondary-light-gray",children:["Group: ",e.groupNodeId,e.groupDepth!==void 0&&` (depth ${e.groupDepth})`]})]}),i&&y.jsxs("div",{className:"text-[9px] text-secondary-dark-gray",children:["nodeId: ",e.nodeId," · typeId: ",e.nodeTypeId]})]}),y.jsxs(Fy,{type:"multiple",defaultValue:["inputs","outputs"],className:"w-full",children:[y.jsxs(nd,{value:"inputs",className:"border-b border-secondary-dark-gray",children:[y.jsx(rd,{className:"gap-1.5 border-b border-secondary-dark-gray bg-runner-section-header-bg px-4 py-2.5 text-[14px] text-primary-white hover:no-underline [&>svg]:text-secondary-light-gray",children:"Inputs"}),y.jsx(od,{className:"p-4",children:y.jsx("div",{className:"flex flex-col gap-4 bg-runner-panel-bg",children:l.length>0?l.map(([d,f],g)=>y.jsxs("div",{children:[g>0&&y.jsx("div",{className:"-mx-4 mb-4 h-px bg-secondary-dark-gray"}),y.jsx(TD,{handleName:d,handleValue:f,hideComplex:r,debugMode:i})]},d)):y.jsx("div",{className:"text-[13px] italic text-secondary-light-gray",children:"No inputs"})})})]}),y.jsxs(nd,{value:"outputs",className:"border-b border-secondary-dark-gray",children:[y.jsx(rd,{className:"gap-1.5 border-b border-secondary-dark-gray bg-runner-section-header-bg px-4 py-2.5 text-[14px] text-primary-white hover:no-underline [&>svg]:text-secondary-light-gray",children:"Outputs"}),y.jsx(od,{className:"p-4",children:y.jsx("div",{className:"flex flex-col gap-4 bg-runner-panel-bg",children:u.length>0?u.map(([d,f],g)=>y.jsxs("div",{children:[g>0&&y.jsx("div",{className:"-mx-4 mb-4 h-px bg-secondary-dark-gray"}),y.jsx(CD,{handleName:d,handleValue:f,hideComplex:r})]},d)):y.jsx("div",{className:"text-[13px] italic text-secondary-light-gray",children:"No outputs"})})})]})]}),e.error&&y.jsx("div",{className:"p-4",children:y.jsxs("div",{className:"rounded-md border border-status-errored/30 bg-status-errored/10 p-2.5",children:[y.jsx("div",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-status-errored",children:"Error"}),y.jsx("div",{className:"whitespace-pre-wrap font-mono text-[11px] text-status-errored",children:ib(e.error)})]})})]})}const Hb=({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:s})=>{const{fromHandle:a}=V0(),l=of(a?.nodeId||""),u=T.useMemo(()=>!a?.id||!l?.data?void 0:on(a?.id,l?.data)?.value?.handleColor??"#A1A1A1",[a?.id,l?.data]),[d]=bc({sourceX:e,sourceY:t,sourcePosition:i,targetX:n,targetY:r,targetPosition:s});return y.jsx(Jo,{path:d,className:"stroke-7! in-[g.selected]:brightness-150",style:{stroke:u||"#A1A1A1"},focusable:!0})};Hb.displayName="ConfigurableConnection";const AD=150,kD=({isOpen:e,position:t,onClose:n,items:r})=>{const[i,s]=T.useState(!1),a=T.useRef(null);T.useEffect(()=>(a.current&&(clearTimeout(a.current),a.current=null),e?s(!0):i&&(a.current=setTimeout(()=>s(!1),AD)),()=>{a.current&&clearTimeout(a.current)}),[e]);const{refs:l,floatingStyles:u,context:d}=Wc({open:e,onOpenChange:h=>{h||n()},placement:"bottom-start",middleware:[Oi(5),Ri({fallbackPlacements:["top-start"]}),Pi({padding:8})],whileElementsMounted:Mi}),f=eb(d),{getFloatingProps:g}=tb([f]);return T.useEffect(()=>{e&&l.setReference({getBoundingClientRect:()=>({x:t.x,y:t.y,width:1,height:1,top:t.y,right:t.x+1,bottom:t.y+1,left:t.x})})},[e,t,l]),i?y.jsx("div",{ref:l.setFloating,style:{...u,contain:"layout"},className:ye("z-50 transition-opacity ease-out",e?"opacity-100 duration-100":"opacity-0 duration-150"),onClick:h=>h.stopPropagation(),...g(),children:y.jsx(pb,{subItems:r})}):null};function MD({onExportState:e,onImportState:t,onExportRecording:n,onImportRecording:r,closeMenu:i}){return[{id:"import-export",label:"Import/Export",icon:T.createElement(k_,{className:"w-4 h-4"}),separator:!0,subItems:[{id:"export-state",label:"Export State",icon:T.createElement(Zh,{className:"w-4 h-4"}),onClick:()=>{e(),i()}},{id:"import-state",label:"Import State",icon:T.createElement(Kh,{className:"w-4 h-4"}),onClick:()=>{t(),i()}},{id:"export-recording",label:"Export Recording",icon:T.createElement(Zh,{className:"w-4 h-4"}),separator:!0,onClick:()=>{n(),i()}},{id:"import-recording",label:"Import Recording",icon:T.createElement(Kh,{className:"w-4 h-4"}),onClick:()=>{r(),i()}}]}]}const Bb="add-new-node-group"+rn(10),OD=({value:e,setValue:t,nodeGroups:n,handleAddNewGroup:r,enableBackButton:i,handleBack:s,openedNodeGroupStack:a})=>{const l=u=>{if(u===Bb){r?.();return}t(u)};return y.jsxs("div",{className:"absolute top-0 left-0 scale-75 origin-top-left flex items-center gap-3 m-2 max-w-full",children:[y.jsx(Qn,{className:"h-[44px] border-secondary-dark-gray bg-primary-black shrink-0",disabled:!i,onClick:s,children:y.jsx(M_,{})}),y.jsxs(yb,{value:e,onValueChange:l,children:[y.jsx($f,{className:"hover:bg-primary-dark-gray shrink-0 w-fit",children:y.jsx(Ff,{placeholder:"Node Group"})}),y.jsxs(Vf,{className:"scale-75 origin-top-left",children:[y.jsx(qc,{value:Bb,className:"pl-2",children:y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(Jh,{}),y.jsx("p",{className:"truncate",children:"Add New Node Group"})]})}),n.map(u=>y.jsx(qc,{value:u.id,children:u.name},u.id))]})]}),y.jsx(Rf,{orientation:"horizontal",className:"relative flex-1 min-w-0",scrollAreaClassName:"text-[27px] leading-[27px] font-main whitespace-nowrap text-primary-white flex gap-2 items-center overflow-x-scroll no-scrollbar overflow-y-hidden",children:a.map((u,d)=>y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("div",{children:u.name}),d<a.length-1&&y.jsx(zr,{className:"shrink-0"})]},u.id))})]})},PD={configurableNode:rp},RD={configurableEdge:_f};function Vb(e,t,n){if(e.length===0)return[];const r=new Map;for(const l of e){const u=n.get(l);r.set(l,u?u.size:0)}let i=[];for(const l of e)r.get(l)===0&&i.push(l);const s=[];let a=0;for(;i.length>0;){const l=i;s.push(l),a+=l.length;const u=[];for(const d of l){const f=t.get(d);if(f)for(const g of f){if(!r.has(g))continue;const h=(r.get(g)??0)-1;r.set(g,h),h===0&&u.push(g)}}i=u}if(a<e.length){const l=new Set;for(const d of s)for(const f of d)l.add(f);const u=e.filter(d=>!l.has(d));u.length>0&&s.push(u)}return s}const Fb=20;function zb(e){const t=[];if(!e)return t;for(const n of e)if("inputs"in n&&n.inputs)for(const r of n.inputs)r.id&&t.push(r.id);else n.id&&t.push(n.id);return t}function Ub(e){const t=[];if(!e)return t;for(const n of e)n.id&&t.push(n.id);return t}function Wb(e,t,n,r,i,s=0){if(s>=Fb)return{groupScopes:[],groupNodeIds:new Set,warnings:[`Maximum group nesting depth (${Fb}) exceeded. Possible recursive group.`]};const a=[],l=new Set,u=[];for(const d of t){const f=d.data.nodeTypeUniqueId;if(!f)continue;const g=e.typeOfNodes[f];if(!g?.subtree)continue;l.add(d.id);const h=g.subtree;for(const w of h.nodes){const I=w.data.nodeTypeUniqueId;if(!I)continue;const k=e.typeOfNodes[I];if(!ri(I)&&(!kr(n,I)||!n[I])){const A=k?.name??I,M=g.name;u.push(`Node type "${A}" inside group "${M}" has no function implementation.`)}}const m={...e,nodes:h.nodes,edges:h.edges,openedNodeGroupStack:void 0},x=i(m,n,{maxLoopIterations:r},s+1);for(const w of x.warnings)u.push(`[Group "${g.name}"] ${w}`);const v=new Map,b=new Map,S=h.nodes.find(w=>w.data.nodeTypeUniqueId===Te.groupInput),N=h.nodes.find(w=>w.data.nodeTypeUniqueId===Te.groupOutput);if(S){const w=zb(d.data.inputs),I=Ub(S.data.outputs),k=Math.min(w.length,I.length);for(let A=0;A<k;A++)v.set(w[A],I[A])}if(N){const w=zb(N.data.inputs),I=Ub(d.data.outputs),k=Math.min(w.length,I.length);for(let A=0;A<k;A++)b.set(w[A],I[A])}a.push({kind:"group",groupNodeId:d.id,groupNodeTypeId:f,groupNodeTypeName:g.name,innerPlan:x,inputMapping:v,outputMapping:b,concurrencyLevel:0})}return{groupScopes:a,groupNodeIds:l,warnings:u}}function ri(e){return e===Te.loopStart||e===Te.loopStop||e===Te.loopEnd||e===Te.groupInput||e===Te.groupOutput}function Gb(e){return e===Te.groupInput||e===Te.groupOutput}function kr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function LD(e,t,n,r,i,s,a=0){const l=t.filter(v=>v.data.nodeTypeUniqueId===Te.loopStart),u=[];for(const v of l){const b=ei(e,v);if(!b)continue;const{loopStart:S,loopStop:N,loopEnd:w}=b,{nodesInRegionStartToStop:I,nodesInRegionStopToEnd:k}=ff(e,b),A=new Set([...I,...k]);u.push({loopStartId:S.id,loopStopId:N.id,loopEndId:w.id,bodyNodeIds:I,postStopBodyNodeIds:k,allBodyNodeIds:A})}const d=new Set;for(const v of u)for(const b of u)v!==b&&b.allBodyNodeIds.has(v.loopStartId)&&d.add(v.loopStartId);const f=new Map;for(const v of u)f.set(v.loopStartId,v);function g(v,b,S,N){const w=new Set(b.map(E=>E.loopStartId)),I=new Map;for(const E of b){const P=E.loopStartId;I.set(E.loopStartId,P),I.set(E.loopStopId,P),I.set(E.loopEndId,P);for(const L of E.allBodyNodeIds)I.set(L,P)}const k=[...Array.from(v).filter(E=>!N.has(E)),...w];if(k.length===0)return[];const A=new Set(k),M=new Map,B=new Map;for(const E of k)M.set(E,new Set),B.set(E,new Set);for(const E of n){if(qf(E,t))continue;let P=E.source,L=E.target;const j=I.get(P);j&&(P=j);const O=I.get(L);O&&(L=O),P!==L&&A.has(P)&&A.has(L)&&(M.get(P)?.add(L),B.get(L)?.add(P))}const U=Vb(k,M,B),q=k.filter(E=>!w.has(E)).map(E=>t.find(P=>P.id===E)).filter(E=>E!=null),{groupScopes:D}=Wb(e,q,i,r,s,a+1),$=new Map(D.map(E=>[E.groupNodeId,E])),F=[];for(let E=0;E<U.length;E++){const P=U[E];for(const L of P){if(w.has(L)){const Y=S.get(L);Y&&F.push({...Y,concurrencyLevel:E});continue}const j=t.find(Y=>Y.id===L);if(!j)continue;const O=j.data.nodeTypeUniqueId;if(!O||Gb(O))continue;const W=$.get(L);if(W){F.push({...W,concurrencyLevel:E});continue}const z=e.typeOfNodes[O];F.push({kind:"standard",nodeId:L,nodeTypeId:O,nodeTypeName:z?.name??O,concurrencyLevel:E})}}return F}function h(v){const{loopStartId:b,loopStopId:S,loopEndId:N,bodyNodeIds:w,postStopBodyNodeIds:I,allBodyNodeIds:k}=v,A=[],M=new Set;for(const F of u)if(F!==v&&k.has(F.loopStartId)){A.push(F),M.add(F.loopStartId),M.add(F.loopStopId),M.add(F.loopEndId);for(const E of F.allBodyNodeIds)M.add(E)}const B=new Map;for(const F of A)B.set(F.loopStartId,h(F));const U=A.filter(F=>w.has(F.loopStartId)),q=A.filter(F=>I.has(F.loopStartId)),D=g(w,U,B,M),$=g(I,q,B,M);return{kind:"loop",loopStartNodeId:b,loopStopNodeId:S,loopEndNodeId:N,preStopSteps:D,postStopSteps:$,maxIterations:r,concurrencyLevel:0}}const m=[],x=new Set;for(const v of u)if(!d.has(v.loopStartId)){m.push(h(v)),x.add(v.loopStartId),x.add(v.loopStopId),x.add(v.loopEndId);for(const b of v.allBodyNodeIds)x.add(b)}return{loopBlocks:m,loopNodeIds:x}}function qf(e,t){if(!e.sourceHandle)return!1;const n=t.find(g=>g.id===e.source);if(!n)return!1;const r=n.data.nodeTypeUniqueId;if(!r||!Tt(r))return!1;const i=e.sourceHandle,s=n.data.outputs;if(!s)return!1;for(const g of s)if("id"in g&&g.id===i&&g.dataType?.dataTypeUniqueId===ze.bindLoopNodes)return!0;const a=t.find(g=>g.id===e.target);if(!a)return!1;const l=a.data.nodeTypeUniqueId;if(!l||!Tt(l))return!1;const u=e.targetHandle;if(!u)return!1;const d=a.data.inputs;if(!d)return!1;const f=d.flatMap(g=>"inputs"in g?g.inputs:[g]);for(const g of f)if("id"in g&&g.id===u&&g.dataType?.dataTypeUniqueId===ze.bindLoopNodes)return!0;return!1}const qb=100;function Yf(e,t,n,r){const i=n?.maxLoopIterations??qb,s=[],{nodes:a,edges:l}=Mt(e);if(a.length===0)return{levels:[],inputResolutionMap:new Map,outputDistributionMap:new Map,nodeCount:0,warnings:[]};const u=new Map,d=new Map;for(const D of l){const $=D.sourceHandle,F=D.targetHandle;if(!$||!F||qf(D,a))continue;const E=`${D.target}:${F}`;let P=u.get(E);P||(P=[],u.set(E,P)),P.push({edgeId:D.id,sourceNodeId:D.source,sourceHandleId:$});const L=`${D.source}:${$}`;let j=d.get(L);j||(j=[],d.set(L,j)),j.push({edgeId:D.id,targetNodeId:D.target,targetHandleId:F})}for(const D of a){const $=D.data.nodeTypeUniqueId;if(!$||Tt($)||ri($))continue;const F=e.typeOfNodes[$];if(!F?.subtree&&(!kr(t,$)||!t[$])){const E=F?.name??$;s.push(`Node type "${E}" (${$}) has no function implementation.`)}}const{loopBlocks:f,loopNodeIds:g}=LD(e,a,l,i,t,Yf,r??0),{groupScopes:h,groupNodeIds:m,warnings:x}=Wb(e,a,t,i,Yf,r??0);for(const D of x)s.push(D);const v=new Map(h.map(D=>[D.groupNodeId,D])),b=new Map(f.map(D=>[D.loopStartNodeId,D])),S=new Set;for(const D of a){const $=D.data.nodeTypeUniqueId;$&&Gb($)&&S.add(D.id)}const N=new Map;for(const D of f){const $=D.loopStartNodeId;N.set(D.loopStartNodeId,$),N.set(D.loopStopNodeId,$),N.set(D.loopEndNodeId,$);for(const F of[...D.preStopSteps,...D.postStopSteps])F.kind==="standard"&&N.set(F.nodeId,$)}const w=new Set(f.map(D=>D.loopStartNodeId)),I=[...a.map(D=>D.id).filter(D=>!g.has(D)&&!S.has(D)),...w],k=new Set(I),A=new Map,M=new Map;for(const D of I)A.set(D,new Set),M.set(D,new Set);for(const D of l){if(!D.sourceHandle||!D.targetHandle||qf(D,a))continue;let $=D.source,F=D.target;const E=N.get($);E&&($=E);const P=N.get(F);P&&(F=P),$!==F&&k.has($)&&k.has(F)&&(A.get($)?.add(F),M.get(F)?.add($))}const B=Vb(I,A,M),U=[];for(let D=0;D<B.length;D++){const $=B[D],F=[];for(const E of $){if(w.has(E)){const W=b.get(E);W&&F.push({...W,concurrencyLevel:D});continue}const P=v.get(E);if(P){F.push({...P,concurrencyLevel:D});continue}const L=a.find(W=>W.id===E);if(!L)continue;const j=L.data.nodeTypeUniqueId;if(!j)continue;const O=e.typeOfNodes[j];F.push({kind:"standard",nodeId:E,nodeTypeId:j,nodeTypeName:O?.name??j,concurrencyLevel:D})}F.length>0&&U.push(F)}let q=0;for(const D of U)for(const $ of D)$.kind==="standard"?q++:$.kind==="loop"?q+=3+$.preStopSteps.length+$.postStopSteps.length:$.kind==="group"&&(q+=1+$.innerPlan.nodeCount);return{levels:U,inputResolutionMap:u,outputDistributionMap:d,nodeCount:q,warnings:s}}function Tn(e,t){return`${e}:${t}`}function Xc(e){const t=[];if(!e)return t;for(const n of e)if("inputs"in n)for(const r of n.inputs)t.push(r);else t.push(n);return t}class Kc{store;prefix;parent;constructor(t="",n=null){this.store=new Map,this.prefix=t,this.parent=n}set(t,n,r){this.store.set(this.prefix+Tn(t,n),r)}get(t,n){const r=this.prefix+Tn(t,n);if(this.store.has(r))return this.store.get(r);if(this.parent)return this.parent.get(t,n)}has(t,n){const r=this.prefix+Tn(t,n);return this.store.has(r)?!0:this.parent?this.parent.has(t,n):!1}resolveInputs(t,n,r,i){const s=new Map,a=Xc(n.inputs);for(const l of a){if(!l.id||!l.name)continue;const u=l.id,d=l.name,f=l.inferredDataType?.dataTypeUniqueId??l.dataType?.dataTypeUniqueId??"",g=Tn(t,u),h=r.get(g);if(h&&h.length>0){const m=[];for(const x of h){const v=i.get(x.sourceNodeId),S=(v?.data.outputs??[]).find(N=>N.id===x.sourceHandleId);m.push({value:this.get(x.sourceNodeId,x.sourceHandleId),sourceNodeId:x.sourceNodeId,sourceNodeName:v?.typeOfNode?.name??"",sourceNodeTypeId:v?.data.nodeTypeUniqueId??"",sourceHandleId:x.sourceHandleId,sourceHandleName:S?.name??"",sourceDataTypeId:S?.inferredDataType?.dataTypeUniqueId??S?.dataType?.dataTypeUniqueId??"",edgeId:x.edgeId})}s.set(d,{connections:m,handleId:u,handleName:d,dataTypeId:f,isDefault:!1})}else l.allowInput&&l.value!==void 0?s.set(d,{connections:[],handleId:u,handleName:d,dataTypeId:f,isDefault:!0,defaultValue:l.value}):s.set(d,{connections:[],handleId:u,handleName:d,dataTypeId:f,isDefault:!0,defaultValue:void 0})}return s}buildOutputInfo(t,n,r){const i=new Map,s=n.outputs;if(!s)return i;for(const a of s){if(!a.id||!a.name)continue;const l=a.id,u=a.name,d=a.inferredDataType?.dataTypeUniqueId??a.dataType?.dataTypeUniqueId??"",f=Tn(t,l),g=r.get(f)??[];i.set(u,{handleId:l,handleName:u,dataTypeId:d,connections:g.map(h=>({targetNodeId:h.targetNodeId,targetHandleId:h.targetHandleId,edgeId:h.edgeId}))})}return i}snapshot(){return new Map(this.store)}createScope(t){return new Kc(`${t}>`,this)}clearScope(t){const n=`${t}>`;for(const r of this.store.keys())r.startsWith(n)&&this.store.delete(r)}}class DD{lastTimestamp=0;minIncrement;constructor(t=.001){this.minIncrement=t}now(){const t=performance.now(),n=Math.max(t,this.lastTimestamp+this.minIncrement);return this.lastTimestamp=n,n}}class Yb{startTime=0;steps=[];errors=[];concurrencyLevels=[];loopRecords=new Map;groupRecords=new Map;id;timer=new DD;rawStartTimes=new Map;pausedAt=null;totalPauseDuration=0;scopeStack=[];pendingLevelStart=0;pendingLevelNodeIds=[];pendingLoopIterations=new Map;pendingLoopStructures=new Map;loopNestingStack=[];pendingNestedLoopStructures=new Map;completedNestedLoopRecords=new Map;constructor(){this.id=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`run-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}start(){this.startTime=this.timer.now()}pause(){this.pausedAt===null&&(this.pausedAt=this.timer.now())}resume(){this.pausedAt!==null&&(this.totalPauseDuration+=this.timer.now()-this.pausedAt,this.pausedAt=null)}getEffectivePauseDuration(){return this.pausedAt!==null?this.totalPauseDuration+(this.timer.now()-this.pausedAt):this.totalPauseDuration}beginStep(t){this.resume();const n=this.steps.length,r=this.timer.now();return this.rawStartTimes.set(n,performance.now()),this.steps.push({stepIndex:n,nodeId:t.nodeId,nodeTypeId:t.nodeTypeId,nodeTypeName:t.nodeTypeName,concurrencyLevel:t.concurrencyLevel,startTime:r-this.startTime,endTime:0,duration:0,pauseAdjustment:this.totalPauseDuration,status:"completed",inputValues:new Map,outputValues:new Map,loopIteration:t.loopIteration,loopStructureId:t.loopStructureId,parentLoopStructureId:t.parentLoopStructureId,parentLoopIteration:t.parentLoopIteration,groupNodeId:t.groupNodeId,groupDepth:t.groupDepth,loopPhase:t.loopPhase,inputSource:t.inputSource}),n}addStepToPendingIteration(t){if(t.loopStructureId!==void 0){const n=this.pendingLoopIterations.get(t.loopStructureId);if(n){n.stepRecords.push(t);return}}if(this.loopNestingStack.length>0){const n=this.loopNestingStack[this.loopNestingStack.length-1],r=this.pendingLoopIterations.get(n.loopStructureId);r&&r.stepRecords.push(t)}}completeStep(t,n,r){const i=this.steps[t];if(!i)return;const s=performance.now(),a=this.timer.now();i.endTime=a-this.startTime,i.duration=i.endTime-i.startTime,i.status="completed",i.inputValues=n,i.outputValues=r;const l=this.rawStartTimes.get(t);l!==void 0&&s===l&&(i.estimatedTiming=!0),this.rawStartTimes.delete(t),this.addStepToPendingIteration(i)}errorStep(t,n,r){const i=this.steps[t];if(!i)return;const s=performance.now(),a=this.timer.now();i.endTime=a-this.startTime,i.duration=i.endTime-i.startTime,i.status="errored",i.inputValues=r,i.error=n;const l=this.rawStartTimes.get(t);l!==void 0&&s===l&&(i.estimatedTiming=!0),this.rawStartTimes.delete(t),this.errors.push(n),this.addStepToPendingIteration(i)}skipStep(t){const n=this.steps[t];if(!n)return;const r=this.timer.now();n.endTime=r-this.startTime,n.duration=0,n.status="skipped",this.rawStartTimes.delete(t),this.addStepToPendingIteration(n)}beginLevel(t,n){this.pendingLevelStart=this.timer.now(),this.pendingLevelNodeIds=n}completeLevel(t){const n=this.timer.now();this.concurrencyLevels.push({level:t,startTime:this.pendingLevelStart-this.startTime,endTime:n-this.startTime,duration:n-this.pendingLevelStart,nodeIds:this.pendingLevelNodeIds})}beginLoopStructure(t,n,r,i){const s={loopStartNodeId:n,loopStopNodeId:r,loopEndNodeId:i,iterations:[],startTime:this.timer.now()};if(this.loopNestingStack.length>0){const a=this.loopNestingStack[this.loopNestingStack.length-1],l=`${a.loopStructureId}:${a.iteration}:${t}`;this.pendingNestedLoopStructures.set(l,s)}else this.pendingLoopStructures.set(t,s)}beginLoopIteration(t,n){this.loopNestingStack.push({loopStructureId:t,iteration:n}),this.pendingLoopIterations.set(t,{iteration:n,startTime:this.timer.now(),stepRecords:[]})}completeLoopIteration(t,n,r){this.loopNestingStack.pop();const i=this.pendingLoopIterations.get(t);if(!i)return;const s=new Map,a=`${t}:${n}:`;for(const[f,g]of this.completedNestedLoopRecords)if(f.startsWith(a)){const h=f.slice(a.length);s.set(h,g)}for(const f of s.keys())this.completedNestedLoopRecords.delete(`${a}${f}`);const l=this.timer.now(),u={iteration:n,startTime:i.startTime-this.startTime,endTime:l-this.startTime,duration:l-i.startTime,conditionValue:r,stepRecords:i.stepRecords,nestedLoopRecords:s},d=this.pendingLoopStructures.get(t)??this.findPendingStructure(t);d&&d.iterations.push(u),this.pendingLoopIterations.delete(t)}findPendingStructure(t){for(const[n,r]of this.pendingNestedLoopStructures)if(n.endsWith(`:${t}`))return r}completeLoopStructure(t){let n=this.pendingLoopStructures.get(t),r=null;if(!n){for(const[a,l]of this.pendingNestedLoopStructures)if(a.endsWith(`:${t}`)){n=l,r=a;break}}if(!n)return;const i=this.timer.now(),s={loopStructureId:t,loopStartNodeId:n.loopStartNodeId,loopStopNodeId:n.loopStopNodeId,loopEndNodeId:n.loopEndNodeId,iterations:n.iterations,totalIterations:n.iterations.length,startTime:n.startTime-this.startTime,endTime:i-this.startTime,duration:i-n.startTime};r?(this.completedNestedLoopRecords.set(r,s),this.pendingNestedLoopStructures.delete(r)):(this.loopRecords.set(t,s),this.pendingLoopStructures.delete(t))}beginGroup(t,n){}completeGroup(t,n,r,i,s){this.groupRecords.set(t,{groupNodeId:t,groupNodeTypeId:n,innerRecord:r,inputMapping:i,outputMapping:s})}getLatestStep(){return this.steps.length>0?this.steps[this.steps.length-1]:void 0}stepCount(){return this.steps.length}getStep(t){return this.steps[t]}beginScope(){const t=[...this.loopNestingStack];this.loopNestingStack.length=0,this.scopeStack.push({startStepIndex:this.steps.length,startErrorIndex:this.errors.length,startLoopRecordKeys:new Set(this.loopRecords.keys()),startGroupRecordKeys:new Set(this.groupRecords.keys()),startNestedLoopKeys:new Set(this.completedNestedLoopRecords.keys()),savedNestingStack:t,startTime:this.timer.now()})}endScope(t,n){const r=this.scopeStack.pop();if(!r)throw new Error("ExecutionRecorder.endScope() called without matching beginScope()");this.loopNestingStack.length=0;for(const d of r.savedNestingStack)this.loopNestingStack.push(d);const i=this.timer.now(),s=this.steps.slice(r.startStepIndex),a=this.errors.slice(r.startErrorIndex),l=new Map;for(const[d,f]of this.loopRecords)r.startLoopRecordKeys.has(d)||l.set(d,f);const u=new Map;for(const[d,f]of this.groupRecords)r.startGroupRecordKeys.has(d)||u.set(d,f);return{id:`${this.id}-scope-${r.startStepIndex}`,startTime:r.startTime,endTime:i,totalDuration:i-r.startTime,compilationDuration:0,totalPauseDuration:this.getEffectivePauseDuration(),status:t,steps:s,errors:a,concurrencyLevels:[],loopRecords:l,groupRecords:u,finalValues:n}}snapshotPendingLoopRecords(t){const n=new Map(this.loopRecords),r=(i,s)=>{const a=this.pendingLoopIterations.get(i),l=[...s.iterations];if(a){const u=new Map,d=`${i}:${a.iteration}:`;for(const[f,g]of this.completedNestedLoopRecords)f.startsWith(d)&&u.set(f.slice(d.length),g);for(const[f,g]of this.pendingNestedLoopStructures)if(f.startsWith(d)){const h=f.slice(d.length);u.has(h)||u.set(h,r(h,g))}l.push({iteration:a.iteration,startTime:a.startTime-this.startTime,endTime:t-this.startTime,duration:t-a.startTime,conditionValue:!0,stepRecords:[...a.stepRecords],nestedLoopRecords:u})}return{loopStructureId:i,loopStartNodeId:s.loopStartNodeId,loopStopNodeId:s.loopStopNodeId,loopEndNodeId:s.loopEndNodeId,iterations:l,totalIterations:l.length,startTime:s.startTime-this.startTime,endTime:t-this.startTime,duration:t-s.startTime}};for(const[i,s]of this.pendingLoopStructures)n.has(i)||n.set(i,r(i,s));return n}snapshot(t,n){const r=this.timer.now();return{id:this.id,startTime:this.startTime,endTime:r,totalDuration:r-this.startTime,compilationDuration:0,totalPauseDuration:this.getEffectivePauseDuration(),status:t,steps:[...this.steps],errors:[...this.errors],concurrencyLevels:[...this.concurrencyLevels],loopRecords:this.snapshotPendingLoopRecords(r),groupRecords:new Map(this.groupRecords),finalValues:n}}finalize(t,n,r=0){const i=this.timer.now();return{id:this.id,startTime:this.startTime,endTime:i,totalDuration:i-this.startTime,compilationDuration:r,totalPauseDuration:this.getEffectivePauseDuration(),status:t,steps:this.steps,errors:this.errors,concurrencyLevels:this.concurrencyLevels,loopRecords:this.loopRecords,groupRecords:this.groupRecords,finalValues:n}}}class jD{pendingPayload=null;pendingPushResolve=null;pendingPullResolve=null;pendingPullReject=null;closed=!1;error=void 0;push(t){if(this.closed)return Promise.resolve();if(this.pendingPullResolve){const n=this.pendingPullResolve;return this.pendingPullResolve=null,this.pendingPullReject=null,n(t),new Promise(r=>{this.pendingPushResolve=r})}return this.pendingPayload=t,new Promise(n=>{this.pendingPushResolve=n})}pull(){if(this.error!==void 0)return Promise.reject(this.error);if(this.pendingPayload){const t=this.pendingPayload;if(this.pendingPayload=null,this.pendingPushResolve){const n=this.pendingPushResolve;this.pendingPushResolve=null,n()}return Promise.resolve(t)}return this.closed?Promise.resolve(null):new Promise((t,n)=>{if(this.pendingPullResolve=t,this.pendingPullReject=n,this.pendingPushResolve){const r=this.pendingPushResolve;this.pendingPushResolve=null,r()}})}close(){this.closed=!0,this.pendingPullResolve&&(this.pendingPullResolve(null),this.pendingPullResolve=null,this.pendingPullReject=null),this.pendingPushResolve&&(this.pendingPushResolve(),this.pendingPushResolve=null)}closeWithError(t){this.closed=!0,this.error=t,this.pendingPullReject&&(this.pendingPullReject(t),this.pendingPullResolve=null,this.pendingPullReject=null),this.pendingPushResolve&&(this.pendingPushResolve(),this.pendingPushResolve=null)}}function Xb(e,t){const n=new Map;function r(i){for(const s of i)if(s.kind==="standard"){const a=t.nodes.find(d=>d.id===s.nodeId);if(!a)continue;const l=a.data.nodeTypeUniqueId;if(!l)continue;const u=t.typeOfNodes[l];n.set(s.nodeId,{data:a.data,typeOfNode:u,nodeTypeId:s.nodeTypeId,nodeTypeName:s.nodeTypeName,concurrencyLevel:s.concurrencyLevel})}else if(s.kind==="loop"){for(const a of[s.loopStartNodeId,s.loopStopNodeId,s.loopEndNodeId]){const l=t.nodes.find(f=>f.id===a);if(!l)continue;const u=l.data.nodeTypeUniqueId;if(!u)continue;const d=t.typeOfNodes[u];n.set(a,{data:l.data,typeOfNode:d,nodeTypeId:u,nodeTypeName:d?.name??u,concurrencyLevel:s.concurrencyLevel})}r(s.preStopSteps),r(s.postStopSteps)}else if(s.kind==="group"){const a=t.nodes.find(d=>d.id===s.groupNodeId);if(!a)continue;const l=a.data.nodeTypeUniqueId;if(!l)continue;const u=t.typeOfNodes[l];n.set(s.groupNodeId,{data:a.data,typeOfNode:u,nodeTypeId:s.groupNodeTypeId,nodeTypeName:s.groupNodeTypeName,concurrencyLevel:s.concurrencyLevel})}}for(const i of e.levels)r(i);return n}function Mr(e){const t=new Map;for(const[n,r]of e){const i=r.connections.map(s=>({value:s.value,sourceNodeId:s.sourceNodeId,sourceNodeName:s.sourceNodeName,sourceHandleId:s.sourceHandleId,sourceHandleName:s.sourceHandleName,sourceDataTypeId:s.sourceDataTypeId}));t.set(n,{connections:i,dataTypeId:r.dataTypeId,isDefault:r.isDefault,defaultValue:r.defaultValue})}return t}function Zc(e,t){const n=new Map;for(const[r,i]of e){const s=t.get(r);n.set(r,{value:i,dataTypeId:s?.dataTypeId??"",targetCount:s?.connections.length??0})}return n}function Jc(e,t,n){for(const[r,i]of t){const s=r.indexOf(":");if(!(s===-1||r.substring(0,s)!==e)){for(const l of i)if(n.has(l.sourceNodeId))return!0}}return!1}function Kb(e){const t=[];for(const n of e)n.kind==="standard"?t.push(n.nodeId):n.kind==="loop"?t.push(n.loopStartNodeId):n.kind==="group"&&t.push(n.groupNodeId);return t}function Xf(e,t,n){const r=e.beginStep(t);n.status==="errored"?e.errorStep(r,n.error,new Map):e.completeStep(r,new Map,new Map)}async function As(e,t,n,r,i,s,a,l,u,d,f,g){const{nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:v}=e;l(h,"running");const b=n.beginStep({nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:v,loopIteration:d?.loopIteration,loopStructureId:d?.loopStructureId,groupNodeId:f?.groupNodeId,groupDepth:f?.groupDepth,loopPhase:g}),S=performance.now(),N=a.get(h);if(!N){const M=zn({error:new Error(`Node "${h}" not found in state`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:[],timestamp:performance.now()-S,duration:0});throw n.errorStep(b,M,new Map),l(h,"errored"),M}const w=t.resolveInputs(h,N.data,r.inputResolutionMap,a),I=t.buildOutputInfo(h,N.data,r.outputDistributionMap);if(ri(m)){n.completeStep(b,Mr(w),new Map),l(h,"completed");return}if(!kr(i,m)){const M=zn({error:new Error(`No function implementation for node type "${x}" (${m})`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:Pf(h,r.inputResolutionMap,a),timestamp:performance.now()-S,duration:performance.now()-S,loopContext:d?{loopStructureId:d.loopStructureId,iteration:d.loopIteration,maxIterations:d.maxIterations}:void 0,groupContext:f?{groupNodeId:f.groupNodeId,groupNodeTypeId:f.groupNodeTypeId,depth:f.groupDepth}:void 0});throw n.errorStep(b,M,Mr(w)),l(h,"errored"),M}const k=i[m];if(!k){const M=zn({error:new Error(`No function implementation for node type "${x}" (${m})`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:Pf(h,r.inputResolutionMap,a),timestamp:performance.now()-S,duration:performance.now()-S,loopContext:d?{loopStructureId:d.loopStructureId,iteration:d.loopIteration,maxIterations:d.maxIterations}:void 0,groupContext:f?{groupNodeId:f.groupNodeId,groupNodeTypeId:f.groupNodeTypeId,depth:f.groupDepth}:void 0});throw n.errorStep(b,M,Mr(w)),l(h,"errored"),M}const A={nodeId:h,nodeTypeId:m,nodeTypeName:x,state:s,loopIteration:d?.loopIteration,groupDepth:f?.groupDepth,abortSignal:u};try{const M=await k(w,I,A);if(!(M instanceof Map))throw new Error(`Function implementation for "${x}" must return a Map, got ${typeof M}`);for(const[B,U]of M){const q=I.get(B);q&&t.set(h,q.handleId,U)}n.completeStep(b,Mr(w),Zc(M,I)),l(h,"completed")}catch(M){const B=performance.now()-S,U=zn({error:M,nodeId:h,nodeTypeId:m,nodeTypeName:x,path:Pf(h,r.inputResolutionMap,a),timestamp:B,duration:B,loopContext:d?{loopStructureId:d.loopStructureId,iteration:d.loopIteration,maxIterations:d.maxIterations}:void 0,groupContext:f?{groupNodeId:f.groupNodeId,groupNodeTypeId:f.groupNodeTypeId,depth:f.groupDepth}:void 0});throw n.errorStep(b,U,Mr(w)),l(h,"errored"),U}}const $D=new Set([ze.bindLoopNodes,ze.loopInfer,ze.condition]);function Zb(e){return e.inferredDataType?.dataTypeUniqueId??e.dataType?.dataTypeUniqueId}function oi(e){return e.filter(t=>{const n=Zb(t);return t.id&&n&&!$D.has(n)}).map(t=>t.id)}function HD(e){return e.find(t=>Zb(t)===ze.condition)?.id}async function Kf(e,t,n,r,i,s,a,l,u,d,f,g){const{loopStartNodeId:h,loopStopNodeId:m,loopEndNodeId:x,preStopSteps:v,postStopSteps:b,maxIterations:S}=e,N=h,w=a.get(h),I=a.get(m),k=a.get(x);if(!w||!I||!k){const oe=zn({error:new Error("Loop structure nodes not found in state"),nodeId:h,nodeTypeId:"loop",nodeTypeName:"Loop",path:[],timestamp:0,duration:0,loopContext:{loopStructureId:N,iteration:0,maxIterations:S}}),pe=n.beginStep({nodeId:h,nodeTypeId:"loop",nodeTypeName:"Loop",concurrencyLevel:e.concurrencyLevel});throw n.errorStep(pe,oe,new Map),u(h,"errored"),u(m,"errored"),u(x,"errored"),l.add(h),l.add(m),l.add(x),oe}const A=Xc(w.data.inputs),M=w.data.outputs??[],B=Xc(I.data.inputs),U=I.data.outputs??[],q=Xc(k.data.inputs),D=k.data.outputs??[],$=oi(A),F=oi(M),E=oi(B),P=oi(U),L=oi(q),j=oi(D),O=HD(B),W=$.length;if(W===0||F.length!==W||E.length!==W||P.length!==W||L.length!==W||j.length!==W||!O){const oe=zn({error:new Error(`Loop structure has mismatched data handle counts (start in=${$.length}, start out=${F.length}, stop in=${E.length}, stop out=${P.length}, end in=${L.length}, end out=${j.length})`),nodeId:h,nodeTypeId:w.nodeTypeId,nodeTypeName:w.nodeTypeName,path:[],timestamp:0,duration:0,loopContext:{loopStructureId:N,iteration:0,maxIterations:S}}),pe=n.beginStep({nodeId:h,nodeTypeId:w.nodeTypeId,nodeTypeName:w.nodeTypeName,concurrencyLevel:e.concurrencyLevel});throw n.errorStep(pe,oe,new Map),u(h,"errored"),l.add(h),l.add(m),l.add(x),oe}const z=new Array(W);for(let oe=0;oe<W;oe++){const pe=Tn(h,$[oe]),ve=(r.inputResolutionMap.get(pe)??[]).filter(me=>me.sourceNodeId!==m);ve.length>0&&(z[oe]=t.get(ve[0].sourceNodeId,ve[0].sourceHandleId))}n.beginLoopStructure(N,h,m,x);const Y=f?{parentLoopStructureId:f.loopStructureId,parentLoopIteration:f.loopIteration}:{},J=t.buildOutputInfo(h,w.data,r.outputDistributionMap),ie=t.buildOutputInfo(m,I.data,r.outputDistributionMap);u(h,"running"),u(m,"running");function ee(oe){const pe=new Map;for(const le of oe){const ve=pe.get(le.concurrencyLevel);ve?ve.push(le):pe.set(le.concurrencyLevel,[le])}return[...pe.entries()].sort((le,ve)=>le[0]-ve[0])}const ce=ee(v),ge=ee(b),Q=t.buildOutputInfo(x,k.data,r.outputDistributionMap);async function te(oe,pe,le,ve){for(const[,me]of oe){if(d.aborted)break;const Oe=[],Ce=[];for(const ae of me){const Ie=an(ae);Jc(Ie,r.inputResolutionMap,pe)?Ce.push(ae):Oe.push(ae)}for(const ae of Ce){const Ie=an(ae);u(Ie,"skipped"),pe.add(Ie);const Be=n.beginStep({nodeId:Ie,nodeTypeId:Qc(ae),nodeTypeName:el(ae),concurrencyLevel:ae.concurrencyLevel,loopIteration:le,loopStructureId:N,loopPhase:ve,...Y});n.skipStep(Be),await g?.()}if(g)for(const ae of Oe){if(d.aborted)break;try{ae.kind==="standard"?(await As(ae,t,n,r,i,s,a,u,d,{loopIteration:le,loopStructureId:N,maxIterations:S},void 0,ve),await g()):await ks(ae,t,n,r,i,s,a,pe,u,d,{loopIteration:le,loopStructureId:N},g)}catch{pe.add(an(ae))}}else{const ae=await Promise.allSettled(Oe.map(Ie=>Ie.kind==="standard"?As(Ie,t,n,r,i,s,a,u,d,{loopIteration:le,loopStructureId:N,maxIterations:S},void 0,ve):ks(Ie,t,n,r,i,s,a,pe,u,d,{loopIteration:le,loopStructureId:N})));for(let Ie=0;Ie<ae.length;Ie++)ae[Ie].status==="rejected"&&pe.add(an(Oe[Ie]))}}}let ne=!1;for(let oe=0;oe<S&&!d.aborted;oe++){n.beginLoopIteration(N,oe);for(let Ce=0;Ce<W;Ce++)t.set(h,F[Ce],z[Ce]);const pe=oe===0?"upstream":"feedback";{const Ce=n.beginStep({nodeId:h,nodeTypeId:w.nodeTypeId,nodeTypeName:w.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopIteration:oe,loopStructureId:N,loopPhase:"loopStart",inputSource:pe,...Y}),ae=t.resolveInputs(h,w.data,r.inputResolutionMap,a),Ie=new Map;for(const[Qe,Ue]of ae)if(pe==="upstream"){const Ze=Ue.connections.filter(pt=>pt.sourceNodeId!==m);Ie.set(Qe,{...Ue,connections:Ze})}else{const Ze=Ue.connections.filter(pt=>pt.sourceNodeId===m);Ie.set(Qe,{...Ue,connections:Ze})}const Be=new Map;for(const[Qe,Ue]of J){const Ze=F.indexOf(Ue.handleId);Ze>=0&&Be.set(Qe,z[Ze])}n.completeStep(Ce,Mr(Ie),Zc(Be,J)),await g?.()}const le=new Set;await te(ce,le,oe,"preStop");const ve=Tn(m,O),me=r.inputResolutionMap.get(ve);let Oe=!1;me&&me.length>0&&(me.some(ae=>le.has(ae.sourceNodeId))||(Oe=!!t.get(me[0].sourceNodeId,me[0].sourceHandleId)));for(let Ce=0;Ce<W;Ce++){const ae=Tn(m,E[Ce]),Ie=r.inputResolutionMap.get(ae);let Be;Ie&&Ie.length>0&&(Be=t.get(Ie[0].sourceNodeId,Ie[0].sourceHandleId)),t.set(m,P[Ce],Be),z[Ce]=Be}{const Ce=n.beginStep({nodeId:m,nodeTypeId:I.nodeTypeId,nodeTypeName:I.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopIteration:oe,loopStructureId:N,loopPhase:"loopStop",...Y}),ae=t.resolveInputs(m,I.data,r.inputResolutionMap,a),Ie=new Map;for(const[Be,Qe]of ie){const Ue=P.indexOf(Qe.handleId);Ue>=0&&Ie.set(Be,z[Ue])}n.completeStep(Ce,Mr(ae),Zc(Ie,ie)),await g?.()}if(Oe&&ge.length>0){await te(ge,le,oe,"postStop");for(let Ce=0;Ce<W;Ce++){const ae=Tn(x,L[Ce]),Ie=r.inputResolutionMap.get(ae);Ie&&Ie.length>0&&(z[Ce]=t.get(Ie[0].sourceNodeId,Ie[0].sourceHandleId))}}{const Ce=!Oe;if(Ce)for(let Qe=0;Qe<W;Qe++)t.set(x,j[Qe],z[Qe]);const ae=n.beginStep({nodeId:x,nodeTypeId:k.nodeTypeId,nodeTypeName:k.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopIteration:oe,loopStructureId:N,loopPhase:"loopEnd",...Y}),Ie=t.resolveInputs(x,k.data,r.inputResolutionMap,a),Be=new Map;if(Ce)for(const[Qe,Ue]of Q){const Ze=j.indexOf(Ue.handleId);Ze>=0&&Be.set(Qe,z[Ze])}n.completeStep(ae,Mr(Ie),Zc(Be,Q)),await g?.()}if(ne=Oe,n.completeLoopIteration(N,oe,Oe),!Oe)break}if(ne&&S>0){const oe=zn({error:new Error(`Loop exceeded maximum iterations (${S})`),nodeId:m,nodeTypeId:I.nodeTypeId,nodeTypeName:I.nodeTypeName,path:[],timestamp:0,duration:0,loopContext:{loopStructureId:N,iteration:S-1,maxIterations:S}}),pe=n.beginStep({nodeId:m,nodeTypeId:I.nodeTypeId,nodeTypeName:I.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopStructureId:N,loopIteration:S-1,...Y});throw n.errorStep(pe,oe,new Map),Xf(n,{nodeId:x,nodeTypeId:k.nodeTypeId,nodeTypeName:k.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopStructureId:N,...Y},{status:"errored",error:oe}),u(m,"errored"),u(x,"errored"),l.add(h),l.add(m),l.add(x),n.completeLoopStructure(N),oe}u(h,"completed"),u(m,"completed"),u(x,"completed"),n.completeLoopStructure(N)}function BD(e,t){return{...e,nodes:t.nodes,edges:t.edges,openedNodeGroupStack:void 0}}async function Zf(e,t,n,r,i,s,a,l,u,d,f=1,g){const{groupNodeId:h,groupNodeTypeId:m,groupNodeTypeName:x,innerPlan:v}=e;if(u(h,"running"),!kr(s.typeOfNodes,m)){const D=zn({error:new Error(`Group node type "${x}" not found in type definitions`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:[],timestamp:0,duration:0,groupContext:{groupNodeId:h,groupNodeTypeId:m,depth:f}}),$=n.beginStep({nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:e.concurrencyLevel,groupNodeId:h,groupDepth:f});throw n.errorStep($,D,new Map),u(h,"errored"),l.add(h),D}const S=s.typeOfNodes[m].subtree;if(!S){const D=zn({error:new Error(`Group node type "${x}" has no subtree definition`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:[],timestamp:0,duration:0,groupContext:{groupNodeId:h,groupNodeTypeId:m,depth:f}}),$=n.beginStep({nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:e.concurrencyLevel,groupNodeId:h,groupDepth:f});throw n.errorStep($,D,new Map),u(h,"errored"),l.add(h),D}const N=BD(s,S),w=new Map;for(const D of S.nodes){const $=D.data.nodeTypeUniqueId;if(!$)continue;const F=kr(s.typeOfNodes,$)?s.typeOfNodes[$]:void 0;w.set(D.id,{data:D.data,typeOfNode:F,nodeTypeId:$,nodeTypeName:F?.name??$,concurrencyLevel:-1})}for(const D of v.levels)for(const $ of D)if($.kind==="standard"){const F=w.get($.nodeId);F&&(F.concurrencyLevel=$.concurrencyLevel)}const I=t.createScope(h),k=S.inputNodeId;if(k)for(const[D,$]of e.inputMapping){const F=Tn(h,D),E=r.inputResolutionMap.get(F);if(E&&E.length>0){const P=t.get(E[0].sourceNodeId,E[0].sourceHandleId);I.set(k,$,P)}}n.beginGroup(h,m),n.beginScope();let A=!1;const M=new Set;for(let D=0;D<v.levels.length&&!d.aborted;D++){const $=v.levels[D],F=[],E=[];for(const P of $){const L=an(P);Jc(L,v.inputResolutionMap,M)?E.push(P):F.push(P)}for(const P of E){const L=an(P);u(L,"skipped"),M.add(L);const j=n.beginStep({nodeId:L,nodeTypeId:Qc(P),nodeTypeName:el(P),concurrencyLevel:P.concurrencyLevel,groupNodeId:h,groupDepth:f});n.skipStep(j),await g?.()}if(g)for(const P of F){if(d.aborted)break;try{P.kind==="standard"?(await As(P,I,n,v,i,N,w,u,d,void 0,{groupNodeId:h,groupNodeTypeId:m,groupDepth:f}),await g()):P.kind==="group"?await Zf(P,I,n,v,i,N,w,M,u,d,f+1,g):await Kf(P,I,n,v,i,N,w,M,u,d,void 0,g)}catch{M.add(an(P))}}else{const P=await Promise.allSettled(F.map(L=>L.kind==="standard"?As(L,I,n,v,i,N,w,u,d,void 0,{groupNodeId:h,groupNodeTypeId:m,groupDepth:f}):L.kind==="group"?Zf(L,I,n,v,i,N,w,M,u,d,f+1):Kf(L,I,n,v,i,N,w,M,u,d)));for(let L=0;L<P.length;L++)P[L].status==="rejected"&&(A=!0,M.add(an(F[L])))}}const B=S.outputNodeId;if(B)for(const[D,$]of e.outputMapping){const F=Tn(B,D),E=v.inputResolutionMap.get(F);if(E&&E.length>0){const P=I.get(E[0].sourceNodeId,E[0].sourceHandleId);t.set(h,$,P)}}const U=n.endScope(A?"errored":"completed",I.snapshot());n.completeGroup(h,m,U,e.inputMapping,e.outputMapping);const q={nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:e.concurrencyLevel,groupNodeId:h,groupDepth:f};if(A){const D=zn({error:new Error(`Group "${x}" inner execution had errors`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:[],timestamp:0,duration:0,groupContext:{groupNodeId:h,groupNodeTypeId:m,depth:f}});Xf(n,q,{status:"errored",error:D}),u(h,"errored"),l.add(h)}else Xf(n,q,{status:"completed"}),u(h,"completed")}async function ks(e,t,n,r,i,s,a,l,u,d,f,g){switch(e.kind){case"standard":await As(e,t,n,r,i,s,a,u,d),await g?.();return;case"loop":return Kf(e,t,n,r,i,s,a,l,u,d,f,g);case"group":return Zf(e,t,n,r,i,s,a,l,u,d,void 0,g)}}async function VD(e,t,n,r){const{onNodeStateChange:i,abortSignal:s}=r,a=new Kc,l=new Yb,u=new Set,d=Xb(e,n),f=performance.now();{const x="__jit_warmup__";a.set(x,x,0),a.get(x,x);const v=new Map;v.set(x,0),v.get(x),v.delete(x),await Promise.allSettled([Promise.resolve(0)]),a.set(x,x,void 0)}const g=performance.now()-f;l.start();let h=!1;for(let x=0;x<e.levels.length;x++){if(s.aborted)return l.finalize("cancelled",a.snapshot(),g);const v=e.levels[x],b=Kb(v);l.beginLevel(x,b);const S=[],N=[];for(const I of v){const k=an(I);Jc(k,e.inputResolutionMap,u)?N.push(I):S.push(I)}for(const I of N){const k=an(I);i(k,"skipped"),u.add(k);const A=l.beginStep({nodeId:k,nodeTypeId:Qc(I),nodeTypeName:el(I),concurrencyLevel:I.concurrencyLevel});l.skipStep(A)}const w=await Promise.allSettled(S.map(I=>ks(I,a,l,e,t,n,d,u,i,s)));for(let I=0;I<w.length;I++)if(w[I].status==="rejected"){h=!0;const A=an(S[I]);u.add(A)}l.completeLevel(x)}const m=s.aborted?"cancelled":h?"errored":"completed";return l.finalize(m,a.snapshot(),g)}async function*FD(e,t,n,r){const{onNodeStateChange:i,abortSignal:s}=r,a=new Kc,l=new Yb,u=new Set,d=Xb(e,n),f=performance.now();{const x="__jit_warmup__";a.set(x,x,0),a.get(x,x),await Promise.allSettled([Promise.resolve(0)]),a.set(x,x,void 0)}const g=performance.now()-f;l.start();let h=!1;for(let x=0;x<e.levels.length;x++){if(s.aborted)return l.resume(),l.finalize("cancelled",a.snapshot(),g);const v=e.levels[x],b=Kb(v);l.beginLevel(x,b);for(const S of v){if(s.aborted)return l.resume(),l.finalize("cancelled",a.snapshot(),g);const N=an(S);if(Jc(N,e.inputResolutionMap,u)){i(N,"skipped"),u.add(N);const w=l.beginStep({nodeId:N,nodeTypeId:Qc(S),nodeTypeName:el(S),concurrencyLevel:S.concurrencyLevel});l.skipStep(w);continue}if(S.kind==="standard"){try{await ks(S,a,l,e,t,n,d,u,i,s)}catch{h=!0,u.add(N)}const w=l.getLatestStep();w&&(l.pause(),yield{stepRecord:w,partialRecord:l.snapshot(h?"errored":"completed",a.snapshot())})}else{const w=new jD,k=ks(S,a,l,e,t,n,d,u,i,s,void 0,async()=>{const A=l.getLatestStep();A&&(l.pause(),await w.push({stepRecord:A,partialRecord:l.snapshot(h?"errored":"completed",a.snapshot())}))}).then(()=>w.close(),A=>{h=!0,u.add(N),w.closeWithError(A)});try{for(;;){const A=await w.pull();if(A===null)break;yield A}}catch{h=!0,u.add(N)}await k}}l.completeLevel(x)}l.resume();const m=s.aborted?"cancelled":h?"errored":"completed";return l.finalize(m,a.snapshot(),g)}function an(e){switch(e.kind){case"standard":return e.nodeId;case"loop":return e.loopStartNodeId;case"group":return e.groupNodeId}}function Qc(e){switch(e.kind){case"standard":return e.nodeTypeId;case"loop":return"loop";case"group":return e.groupNodeTypeId}}function el(e){switch(e.kind){case"standard":return e.nodeTypeName;case"loop":return"Loop";case"group":return e.groupNodeTypeName}}const Ms=new Map,zD=new Map,Os=new Map;function ii(e,t){const n=new Map;for(const r of e.steps)r.stepIndex<t?n.set(r.nodeId,r.status==="errored"?"errored":r.status==="skipped"?"skipped":"completed"):r.stepIndex===t?n.set(r.nodeId,"running"):n.has(r.nodeId)||n.set(r.nodeId,"idle");for(const[,r]of e.loopRecords){const i=[];for(const l of r.iterations)for(const u of l.stepRecords)i.push(u.stepIndex);if(i.length===0)continue;const s=Math.min(...i),a=Math.max(...i);t>=s&&t<=a&&(n.set(r.loopStartNodeId,"running"),n.set(r.loopStopNodeId,"running"))}for(const[r,i]of e.groupRecords){const s=i.innerRecord.steps;if(s.length===0)continue;const a=s.map(d=>d.stepIndex),l=Math.min(...a),u=Math.max(...a);t>=l&&t<=u&&n.set(r,"running")}return n}function UD(e,t){const n=new Map;for(const r of e.nodes){const i=r.data.nodeTypeUniqueId;if(!i)continue;const s=e.typeOfNodes[i];if(!ri(i)&&!Tt(i)&&!s?.subtree&&(!kr(t,i)||!t[i])){const a=s?.name??i,l=n.get(r.id);l?l.push(`No function implementation for node type "${a}"`):n.set(r.id,[`No function implementation for node type "${a}"`])}}return n}function Jf(e){const t=new Map;for(const n of e.errors){const r=t.get(n.nodeId);r?r.push(n):t.set(n.nodeId,[n])}return t}function WD(e,t){const n=[],r=[];if(e.steps.length===0)return r.push("Recording has no execution steps."),{valid:!1,warnings:n,errors:r};const i=new Set(t.nodes.map(f=>f.id)),s=new Set(Object.keys(t.typeOfNodes)),a=new Set,l=new Set;for(const f of e.steps)i.has(f.nodeId)||a.add(f.nodeId),!ri(f.nodeTypeId)&&!Tt(f.nodeTypeId)&&!s.has(f.nodeTypeId)&&l.add(f.nodeTypeId);a.size>0&&n.push(`Recording references ${a.size} node(s) not in the current graph: ${[...a].join(", ")}`),l.size>0&&n.push(`Recording references ${l.size} node type(s) not in the current graph: ${[...l].join(", ")}`);const u=new Set(e.steps.map(f=>f.nodeId)),d=[];for(const f of t.nodes){const g=f.data.nodeTypeUniqueId;g&&(ri(g)||Tt(g)||t.typeOfNodes[g]?.subtree||u.has(f.id)||d.push(f.id))}return d.length>0&&n.push(`${d.length} node(s) in the current graph were not in the recording: ${d.join(", ")}`),{valid:!0,warnings:n,errors:r}}function GD({state:e,functionImplementations:t,options:n,executionRecord:r,onExecutionRecordChange:i}){const s=r!==void 0,[a,l]=T.useState(null),u=s?r:a,d=T.useRef(u??null),f=T.useCallback(ne=>{d.current=ne,s||l(ne),i?.(ne)},[s,i]),[g,h]=T.useState(()=>u?"completed":"idle"),[m,x]=T.useState(()=>u?ii(u,Math.max(0,u.steps.length-1)):Ms),[v,b]=T.useState(zD),[S,N]=T.useState(()=>u?Jf(u):Os),[w,I]=T.useState(()=>u?Math.max(0,u.steps.length-1):0),[k,A]=T.useState("instant"),[M,B]=T.useState(n?.maxLoopIterations??qb),U=T.useRef(null),q=T.useRef(null),D=T.useRef(new Map),$=T.useRef(!1),F=T.useRef(!0);T.useEffect(()=>(F.current=!0,()=>{F.current=!1,U.current?.abort(),q.current=null,$.current=!1}),[]);const E=T.useRef(u);if(s&&u!==E.current&&u!==d.current)if(E.current=u,u){const ne=Math.max(0,u.steps.length-1);I(ne),N(Jf(u));const oe=ii(u,ne);D.current=new Map(oe),x(oe),h(u.status==="cancelled"||u.errors.length>0?"errored":"completed")}else I(0),N(Os),D.current=new Map,x(Ms),h("idle");else s&&u!==E.current&&(E.current=u);T.useEffect(()=>{const ne=UD(e,t);b(ne)},[e.nodes,e.typeOfNodes,t]);const P=T.useCallback(()=>{F.current&&x(new Map(D.current))},[]),L=T.useCallback((ne,oe)=>{D.current.set(ne,oe)},[]),j=T.useCallback(()=>{try{return Yf(e,t,{maxLoopIterations:M})}catch{return F.current&&h("errored"),null}},[e,t,M]),O=T.useCallback(ne=>{if(!F.current)return;f(ne),I(Math.max(0,ne.steps.length-1));const oe=Jf(ne);N(oe);const pe=new Map;for(const le of ne.steps)pe.set(le.nodeId,le.status==="errored"?"errored":le.status==="skipped"?"skipped":"completed");D.current=pe,x(pe),q.current=null,h(ne.status==="cancelled"||ne.errors.length>0?"errored":"completed")},[]),W=T.useCallback(async()=>{D.current=new Map,x(Ms),N(Os),f(null),I(0),U.current?.abort();const ne=new AbortController;U.current=ne,h("compiling");const oe=j();if(oe&&F.current){h("running");try{const pe=await VD(oe,t,e,{onNodeStateChange:L,abortSignal:ne.signal});if(!F.current)return;O(pe)}catch{F.current&&(P(),h("errored"))}}},[e,t,j,L,P,O]),z=T.useCallback(async()=>{D.current=new Map,x(Ms),N(Os),f(null),I(0),U.current?.abort();const ne=new AbortController;U.current=ne,h("compiling");const oe=j();if(!oe||!F.current)return;h("running");const pe=FD(oe,t,e,{onNodeStateChange:L,abortSignal:ne.signal});q.current=pe;try{const le=await pe.next();if(!F.current)return;if(le.done)O(le.value);else{const{stepRecord:ve,partialRecord:me}=le.value;f(me),I(ve.stepIndex),x(ii(me,ve.stepIndex)),h("paused")}}catch{F.current&&(P(),h("errored"),q.current=null)}},[e,t,j,L,P,O]),Y=T.useCallback(()=>{k==="instant"?W():z()},[k,W,z]),J=T.useCallback(()=>{const ne=q.current;if(!ne){z();return}h("running"),(async()=>{try{const oe=await ne.next();if(!F.current)return;if(oe.done)O(oe.value);else{const{stepRecord:pe,partialRecord:le}=oe.value;f(le),I(pe.stepIndex),x(ii(le,pe.stepIndex)),h("paused")}}catch{F.current&&(P(),h("errored"),q.current=null)}})()},[z,P,O]),ie=T.useCallback(()=>{$.current=!1,F.current&&h("paused")},[]),ee=T.useCallback(()=>{const ne=q.current;ne&&($.current=!0,h("running"),(async()=>{for(;$.current;)try{const oe=await ne.next();if(!F.current)return;if(oe.done){$.current=!1,O(oe.value);return}const{stepRecord:pe,partialRecord:le}=oe.value;f(le),I(pe.stepIndex),x(ii(le,pe.stepIndex))}catch{$.current=!1,F.current&&(P(),h("errored"),q.current=null);return}F.current&&h("paused")})())},[P,O]),ce=T.useCallback(()=>{$.current=!1,U.current?.abort(),q.current=null,F.current&&(P(),h("errored"))},[P]),ge=T.useCallback(()=>{$.current=!1,U.current?.abort(),q.current=null,F.current&&(D.current=new Map,h("idle"),x(Ms),N(Os),f(null),I(0))},[]),Q=T.useCallback(ne=>{if(!u)return;const oe=Math.max(0,Math.min(ne,u.steps.length-1));I(oe);const pe=ii(u,oe);D.current=new Map(pe),x(pe)},[u]),te=T.useCallback(ne=>{const oe=WD(ne,e);return oe.valid&&($.current=!1,U.current?.abort(),q.current=null,O(ne)),oe},[e,O]);return{runnerState:g,nodeVisualStates:m,nodeWarnings:v,nodeErrors:S,executionRecord:u,currentStepIndex:w,run:Y,pause:ie,resume:ee,step:J,stop:ce,reset:ge,replayTo:Q,loadRecord:te,mode:k,setMode:A,maxLoopIterations:M,setMaxLoopIterations:B}}const qD=250;function Qf(e,t={}){const{durationMs:n=qD,hiddenTransform:r="translateY(100%)",visibleTransform:i="translateY(0)",easing:s="cubic-bezier(0.32, 0.72, 0, 1)"}=t,[a,l]=T.useState(!1),u=T.useRef(null),d=T.useRef(null);return T.useEffect(()=>{e&&l(!0)},[e]),T.useEffect(()=>{const g=u.current;if(!g||!a)return;d.current&&(g.style.transform=getComputedStyle(g).transform,d.current.cancel(),d.current=null);const h=e?i:r,m=g.animate([{transform:h}],{duration:n,easing:s,fill:"forwards"});d.current=m,e||(m.onfinish=()=>l(!1))},[e,a,n,r,i,s]),{mounted:a,ref:u,style:{transform:r}}}function Jb({initialSize:e,minSize:t,maxSize:n,direction:r="up"}){const[i,s]=T.useState(e),a=T.useRef(!1),l=T.useRef(0),u=T.useRef(0),d=r==="up"||r==="down",f=d?"ns-resize":"ew-resize",g=r==="up"||r==="left"?-1:1,h=T.useCallback(m=>{m.preventDefault(),m.stopPropagation(),a.current=!0,l.current=d?m.clientY:m.clientX,u.current=i,document.body.style.userSelect="none",document.body.style.cursor=f;const x=b=>{if(!a.current)return;const N=((d?b.clientY:b.clientX)-l.current)*g,w=Math.max(t,Math.min(n,u.current+N));s(w)},v=()=>{a.current=!1,document.body.style.userSelect="",document.body.style.cursor="",document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",v)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",v)},[i,t,n,d,f,g]);return{size:i,onMouseDown:h}}const YD=220,XD=80,KD=600;function ZD({runnerState:e,record:t,currentStepIndex:n,onRun:r,onPause:i,onStep:s,onStop:a,onReset:l,mode:u,onModeChange:d,maxLoopIterations:f,onMaxLoopIterationsChange:g,onScrubTo:h,onNavigateToNode:m,panelRef:x,debugMode:v=!1,hideComplexValues:b=!1,className:S}){const{selectedStepIndex:N,setSelectedStepIndex:w,edgeValuesAnimated:I,setEdgeValuesAnimated:k,isRunnerPanelOpen:A,setIsRunnerPanelOpen:M}=Uf(),{size:B,onMouseDown:U}=Jb({initialSize:YD,minSize:XD,maxSize:KD,direction:"up"}),{mounted:q,ref:D,style:$}=Qf(A),F=T.useCallback(Y=>{D.current=Y,x&&(x.current=Y)},[D,x]);T.useEffect(()=>{A||w(null)},[A,w]);const E=N!==null&&t?t.steps.find(Y=>Y.stepIndex===N)??null:null,P=T.useRef(null);E&&(P.current=E);const j=Qf(E!==null,{durationMs:200,hiddenTransform:"translateX(100%)",visibleTransform:"translateX(0)"}),O=E??P.current,W=T.useCallback(Y=>{w(N===Y.stepIndex?null:Y.stepIndex)},[N,w]),z=T.useCallback(()=>{w(null)},[w]);return q?y.jsx("div",{className:"absolute inset-x-0 bottom-0 z-10 overflow-hidden pointer-events-none",children:y.jsxs("div",{ref:F,className:ye("pointer-events-auto","flex flex-col overflow-hidden rounded-t-lg border border-b-0 border-secondary-dark-gray/60 bg-runner-panel-bg shadow-xl",S),style:$,children:[y.jsx("div",{className:"group/resizer flex shrink-0 cursor-ns-resize items-center justify-center border-b border-runner-timeline-box-border bg-[#2b2b2b] py-2 transition-colors hover:bg-[#353535]",onMouseDown:U,children:y.jsxs("div",{className:"flex gap-1.5",children:[y.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-runner-handle-dot transition-colors group-hover/resizer:bg-primary-blue"}),y.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-runner-handle-dot transition-colors group-hover/resizer:bg-primary-blue"}),y.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-runner-handle-dot transition-colors group-hover/resizer:bg-primary-blue"})]})}),y.jsxs("div",{className:"flex shrink-0 items-center",children:[y.jsx("div",{className:"min-w-0 flex-1",children:y.jsx(wb,{runnerState:e,onRun:r,onPause:i,onStep:s,onStop:a,onReset:l,mode:u,onModeChange:d,maxLoopIterations:f,onMaxLoopIterationsChange:g})}),y.jsx("button",{type:"button",onClick:()=>M(!1),className:"btn-press mr-3 shrink-0 rounded p-1.5 text-secondary-light-gray transition-colors hover:bg-primary-dark-gray hover:text-primary-white",title:"Close panel",children:y.jsx(aa,{className:"h-4 w-4"})})]}),y.jsxs("div",{className:"flex min-h-0 overflow-hidden",style:{height:`${B}px`},children:[y.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:y.jsx(jb,{record:t,currentStepIndex:n,onScrubTo:h,onStepClick:W,selectedStepIndex:N,onNavigateToNode:m})}),j.mounted&&O&&y.jsx("div",{ref:j.ref,className:"node-runner-scrollbar shrink-0 overflow-y-auto border-l border-secondary-dark-gray",style:j.style,children:y.jsx($b,{stepRecord:O,onClose:z,loopRecords:t?.loopRecords,hideComplexValues:b,debugMode:v,edgeValuesAnimated:I,onEdgeValuesAnimatedChange:k})})]})]})}):null}function JD({state:e,dispatch:t,functionImplementations:n,children:r,onExecutionRecordRef:i,loadRecordRef:s}){const{executionRecord:a,setExecutionRecord:l}=Tw(),u=GD({state:e,functionImplementations:n,executionRecord:a,onExecutionRecordChange:l}),{getNode:d,setCenter:f,getViewport:g}=Zo(),h=T.useRef(null),m=Uf(),{selectedStepIndex:x,setSelectedStepIndex:v,edgeValuesAnimated:b,isRunnerPanelOpen:S,setIsRunnerPanelOpen:N,getViewState:w,restoreViewState:I}=m,k=T.useCallback(q=>{const D=d(q);if(!D)return;const $=D.position.x+(D.measured?.width??200)/2;let F=D.position.y+(D.measured?.height??100)/2;const E=g().zoom,P=h.current?.offsetHeight??0;P>0&&(F+=P/(2*E)),f($,F,{duration:300,zoom:E})},[d,f,g]);T.useEffect(()=>(s&&(s.current=q=>{const D=u.loadRecord(q);return D.valid&&q.viewState&&(I(q.viewState),q.viewState.runMode!==void 0&&u.setMode(q.viewState.runMode),q.viewState.maxLoopIterations!==void 0&&u.setMaxLoopIterations(q.viewState.maxLoopIterations)),D}),()=>{s&&(s.current=null)}),[s,u.loadRecord,u.setMode,u.setMaxLoopIterations,I]);const A=T.useMemo(()=>{const q=new Map;for(const[D,$]of u.nodeVisualStates)q.set(D,{visualState:$});for(const[D,$]of u.nodeWarnings){const F=q.get(D);F?q.set(D,{...F,warnings:$}):q.set(D,{visualState:"warning",warnings:$})}for(const[D,$]of u.nodeErrors){const F=q.get(D);F?q.set(D,{...F,errors:$}):q.set(D,{visualState:"errored",errors:$})}return q},[u.nodeVisualStates,u.nodeWarnings,u.nodeErrors]),M=T.useCallback(q=>{u.setMode(q)},[u.setMode]),B=T.useCallback(()=>{u.runnerState==="paused"?u.resume():u.run()},[u.runnerState,u.run,u.resume]);T.useEffect(()=>{(u.runnerState==="compiling"||u.runnerState==="idle")&&v(null)},[u.runnerState]),T.useEffect(()=>{x!==null&&u.replayTo(x)},[x,u.replayTo]);const U=T.useMemo(()=>x===null||!u.executionRecord?null:u.executionRecord.steps.find(q=>q.stepIndex===x)??null,[x,u.executionRecord]);return T.useEffect(()=>(i&&(i.current=()=>{const q=u.executionRecord;if(!q)return null;const D={...w(),runMode:u.mode,maxLoopIterations:u.maxLoopIterations};return{...q,viewState:D}}),()=>{i&&(i.current=null)}),[i,u.executionRecord,w,u.mode,u.maxLoopIterations]),y.jsxs(uo.Provider,{value:Sf({state:e,dispatch:t},A,U,b),children:[r,y.jsx(ZD,{runnerState:u.runnerState,record:u.executionRecord,currentStepIndex:u.currentStepIndex,onRun:B,onPause:u.pause,onStep:u.step,onStop:u.stop,onReset:u.reset,mode:u.mode,onModeChange:M,maxLoopIterations:u.maxLoopIterations,onMaxLoopIterationsChange:u.setMaxLoopIterations,onScrubTo:u.replayTo,onNavigateToNode:k,panelRef:h}),!S&&y.jsxs("button",{type:"button",onClick:()=>N(!0),className:"btn-press absolute bottom-4 left-1/2 z-10 flex -translate-x-1/2 items-center gap-2 rounded-lg border border-secondary-dark-gray/60 bg-secondary-black/90 px-4 py-2 text-[12px] font-medium text-primary-white shadow-xl backdrop-blur-sm transition-colors hover:bg-primary-dark-gray",title:"Open runner panel",children:[y.jsx(au,{className:"h-3.5 w-3.5"}),"Runner"]})]})}function Qb(e,t){const n=new Blob([e],{type:"application/json"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}function QD({state:e,dispatch:t,functionImplementations:n,onStateImported:r,onRecordingImported:i,onImportError:s}){const a=T.useRef(null),l=T.useRef(null),[u,d]=T.useState(0),f=T.useRef(null),g=T.useRef(null),h=T.useCallback(()=>{const D=bw(e,{pretty:!0});Qb(D,"graph-state.json")},[e]),m=T.useCallback(D=>{const $=Iw(D,{dataTypes:e.dataTypes,typeOfNodes:e.typeOfNodes,repair:{removeOrphanEdges:!0,removeDuplicateNodeIds:!0,removeDuplicateEdgeIds:!0,fillMissingDefaults:!0,rehydrateDataTypeObjects:!0}});if($.success){const F={...$.data,dataTypes:e.dataTypes,typeOfNodes:e.typeOfNodes};t({type:ft.REPLACE_STATE,payload:{state:F}}),d(E=>E+1),r?.(F)}else s?.($.errors.map(F=>`${F.path}: ${F.message}`))},[e.dataTypes,e.typeOfNodes,t,r,s]),x=T.useCallback(()=>{const D=a.current?.();if(!D)return;const $=Nw(D,{pretty:!0});Qb($,"execution-recording.json")},[]),v=T.useCallback(D=>{const $=Ew(D,{repair:{sanitizeNonSerializableValues:!0,removeOrphanSteps:!0}});if($.success){const F=l.current?.($.data);if(F&&!F.valid){s?.(F.errors);return}F?.warnings.length&&console.warn("Recording import warnings:",F.warnings),i?.($.data)}else s?.($.errors.map(F=>`${F.path}: ${F.message}`))},[i,s]),[b,S]=T.useState({isOpen:!1,position:{x:0,y:0}}),N=T.useMemo(()=>{const D=[];for(const $ of Object.keys(e.typeOfNodes)){if(!kr(e.typeOfNodes,$))continue;const F=e.typeOfNodes[$];F?.subtree!==void 0&&D.push({id:$,name:F.name})}return D},[e.typeOfNodes]),w=T.useMemo(()=>e.openedNodeGroupStack?.[e.openedNodeGroupStack.length-1],[e.openedNodeGroupStack]),{screenToFlowPosition:I,fitView:k}=Zo(),A=T.useCallback(()=>{S({isOpen:!1,position:{x:0,y:0}})},[]),M=T.useMemo(()=>[...mb({typeOfNodes:e.typeOfNodes,dispatch:t,setContextMenu:S,contextMenuPosition:I(b.position),currentNodeType:w?.nodeType,isRecursionAllowed:!e.enableRecursionChecking}),...MD({onExportState:h,onImportState:()=>f.current?.click(),onExportRecording:x,onImportRecording:()=>g.current?.click(),closeMenu:A})],[e.typeOfNodes,t,S,b.position,w?.nodeType,e.enableRecursionChecking,h,x,A,I]),B=T.useCallback(D=>{D.preventDefault();const $={x:D.clientX,y:D.clientY};S({isOpen:!0,position:$})},[]),U=T.useMemo(()=>Mt(e),[e.nodes,e.edges,e.openedNodeGroupStack,e.typeOfNodes]);T.useEffect(()=>{e.viewport===void 0&&(U.nodes.length>0?k({maxZoom:.5,minZoom:.1}):t({type:ft.SET_VIEWPORT,payload:{viewport:{x:0,y:0,zoom:.45}}}))},[e.viewport]);const q=y.jsxs(y.Fragment,{children:[y.jsxs(KR,{nodes:U.nodes,edges:U.edges,onNodesChange:D=>t({type:ft.UPDATE_NODE_BY_REACT_FLOW,payload:{changes:D}}),onEdgesChange:D=>t({type:ft.UPDATE_EDGES_BY_REACT_FLOW,payload:{changes:D}}),onConnect:D=>t({type:ft.ADD_EDGE_BY_REACT_FLOW,payload:{edge:D}}),maxZoom:1,minZoom:.1,proOptions:{hideAttribution:!0},colorMode:"dark",selectNodesOnDrag:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectionMode:Uo.Partial,nodeTypes:PD,edgeTypes:RD,deleteKeyCode:["Backspace","Delete","x"],connectionLineComponent:Hb,onContextMenu:B,onClick:A,viewport:e.viewport,onViewportChange:D=>t({type:ft.SET_VIEWPORT,payload:{viewport:D}}),onBeforeDelete:async({nodes:D,edges:$})=>{const F=Mt(e);return!!DL({...e,...F},D,$).validation.isValid},children:[y.jsx(lL,{}),y.jsx(nL,{}),y.jsx(SL,{pannable:!0})]},u),y.jsx(kD,{isOpen:b.isOpen,position:b.position,onClose:A,items:M}),y.jsx(OD,{nodeGroups:N,value:w?.nodeType??"",setValue:D=>{kr(e.typeOfNodes,D)&&t({type:ft.OPEN_NODE_GROUP,payload:{nodeType:D}})},handleAddNewGroup:()=>t({type:ft.ADD_NODE_GROUP}),enableBackButton:(e.openedNodeGroupStack?.length||0)>0,handleBack:()=>t({type:ft.CLOSE_NODE_GROUP}),openedNodeGroupStack:(e.openedNodeGroupStack||[]).map(D=>({id:D.nodeType+("nodeId"in D?D.nodeId:""),name:e.typeOfNodes[D.nodeType].name}))})]});return y.jsxs("div",{style:{width:"100%",height:"100%"},className:"relative",children:[n?y.jsx(Q2,{children:y.jsx(JD,{state:e,dispatch:t,functionImplementations:n,onExecutionRecordRef:a,loadRecordRef:l,children:q})}):q,y.jsx("input",{ref:f,type:"file",accept:".json",className:"hidden",onChange:D=>{const $=D.target.files?.[0];if(!$)return;const F=new FileReader;F.onload=E=>{const P=E.target?.result;typeof P=="string"&&m(P)},F.readAsText($),D.target.value=""}}),y.jsx("input",{ref:g,type:"file",accept:".json",className:"hidden",onChange:D=>{const $=D.target.files?.[0];if(!$)return;const F=new FileReader;F.onload=E=>{const P=E.target?.result;typeof P=="string"&&v(P)},F.readAsText($),D.target.value=""}})]})}function ej({state:e,dispatch:t,functionImplementations:n,onStateImported:r,onRecordingImported:i,onImportError:s,executionRecord:a,onExecutionRecordChange:l}){const u=T.useCallback(()=>{},[]),d=T.useMemo(()=>({executionRecord:a??null,setExecutionRecord:l??u}),[a,l,u]);return y.jsx(G0,{children:y.jsx(uo.Provider,{value:Sf({state:e,dispatch:t}),children:y.jsx(bf.Provider,{value:d,children:y.jsx(QD,{state:e,dispatch:t,functionImplementations:n,onStateImported:r,onRecordingImported:i,onImportError:s})})})})}const tt=["circle","square","rectangle","list","grid","diamond","trapezium","hexagon","star","cross","zigzag","sparkle","parallelogram"],Ct={[tt[0]]:tt[0],[tt[1]]:tt[1],[tt[2]]:tt[2],[tt[3]]:tt[3],[tt[4]]:tt[4],[tt[5]]:tt[5],[tt[6]]:tt[6],[tt[7]]:tt[7],[tt[8]]:tt[8],[tt[9]]:tt[9],[tt[10]]:tt[10],[tt[11]]:tt[11],[tt[12]]:tt[12]},tl=(e,t,n,r="black",i=2)=>y.jsxs("div",{className:ye("relative",n),children:[y.jsx("div",{className:"absolute",style:{top:-i,left:-i,right:-i,bottom:-i,backgroundColor:r,clipPath:e}}),y.jsx("div",{className:"absolute inset-0",style:{backgroundColor:t,clipPath:e}})]}),eS=(e=Ct.circle,t="#A1A1A1",n)=>{const r="border-2 border-black",i="border-1 border-black",s={backgroundColor:t};switch(e){case Ct.circle:return y.jsx("div",{className:ye("w-6 h-6 rounded-full",r,n),style:s});case Ct.square:return y.jsx("div",{className:ye("w-6 h-6",r,n),style:s});case Ct.rectangle:return y.jsx("div",{className:ye("w-4 h-8",r,n),style:s});case Ct.list:return y.jsx("div",{className:ye("w-6 h-6 flex flex-col justify-center gap-0.5",n),children:[0,1,2].map(a=>y.jsx("div",{className:ye("w-full h-2",i),style:s},a))});case Ct.grid:return y.jsx("div",{className:ye("w-6 h-6 grid grid-cols-2 gap-0.5",n),children:[0,1,2,3].map(a=>y.jsx("div",{className:ye("w-full h-full",i),style:s},a))});case Ct.diamond:return y.jsx("div",{className:ye("w-6 h-6 rotate-45",r,n),style:s});case Ct.trapezium:return tl("polygon(25% 0%, 75% 0%, 100% 100%, 0% 100%)",t,ye("w-6 h-6",n));case Ct.hexagon:return tl("polygon(-50% 50%,50% 100%,150% 50%,50% 0)",t,ye("w-5 h-6",n));case Ct.star:return tl("polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%)",t,ye("w-6 h-6",n));case Ct.cross:return y.jsxs("div",{className:ye("w-6 h-6 relative",n),children:[y.jsx("div",{className:ye("absolute top-1/2 left-0 w-full h-2 -translate-y-1/2",i),style:s}),y.jsx("div",{className:ye("absolute left-1/2 top-0 w-2 h-full -translate-x-1/2",i),style:s})]});case Ct.zigzag:return y.jsx("div",{className:ye("w-6 h-6",n),style:{...s,width:"calc(4px + 24px/(2*tan(90deg/2)))",minHeight:"24px",mask:"4px 50%/100% 24px repeat-y conic-gradient(from calc(90deg - 90deg/2) at left, #0000, #000 1deg calc(90deg - 1deg), #0000 90deg) exclude, 0 50%/100% 24px repeat-y conic-gradient(from calc(90deg - 90deg/2) at left, #0000, #000 1deg calc(90deg - 1deg), #0000 90deg)",border:"2px solid black"}});case Ct.sparkle:return y.jsx("div",{className:ye("w-6 h-6",n),style:{...s,mask:"radial-gradient(#0000 71%, #000 72%) 10000% 10000%/99.5% 99.5%",border:"2px solid black"}});case Ct.parallelogram:return tl("polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%)",t,ye("w-6 h-6",n));default:return y.jsx("div",{className:ye("w-6 h-6 rounded-full",r,n),style:s})}},nl=T.forwardRef(({type:e,position:t,id:n,color:r,shape:i=Ct.circle,maxConnections:s,isCurrentlyInsideReactFlow:a=!1,className:l,...u},d)=>{const f=a?q0({handleId:n,handleType:e}):[];if(a){const g=s!==void 0?f.length<s:void 0;return y.jsx(ds,{type:e,position:t,id:n,className:ye("!w-6 !h-6 !border-none !bg-transparent !pointer-events-auto",l),style:{backgroundColor:"transparent"},isConnectable:g,isConnectableStart:g,isConnectableEnd:g,...u,ref:d,children:y.jsx("div",{className:ye("pointer-events-none flex justify-center"),children:eS(i,r||"#A1A1A1",l)})})}return y.jsx("div",{className:ye("absolute",t===Ne.Right&&"right-0 top-1/2 -translate-y-1/2 translate-x-1/2",t===Ne.Left&&"left-0 top-1/2 -translate-y-1/2 -translate-x-1/2"),...u,ref:d,children:eS(i,r||"#A1A1A1",l)})});nl.displayName="ContextAwareHandle";const ep=T.forwardRef(({className:e,...t},n)=>y.jsx(Cu,{"data-slot":"checkbox",className:ye("peer bg-primary-gray border-transparent data-[state=checked]:bg-primary-blue data-[state=checked]:text-primary-white focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-7 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,ref:n,children:y.jsx(sm,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:y.jsx(sa,{className:"size-6",strokeWidth:3.5})})}));ep.displayName=Cu.displayName;const tS=({input:e})=>{const t=Zo(),n=us();return e.type==="string"?y.jsx(ws,{placeholder:e.name,value:e.value,onChange:r=>{e.onChange?.(r),t.setNodes(i=>i.map(s=>s.id===n?{...s,data:uf(s.data,e.id,{value:r},!0,!1,!1)}:s))},allowOnlyNumbers:!1,className:"w-full"}):e.type==="number"?y.jsx(ni,{name:e.name,value:e.value,onChange:r=>{e.onChange?.(r),t.setNodes(i=>i.map(s=>s.id===n?{...s,data:uf(s.data,e.id,{value:r},!0,!1,!1)}:s))},className:"w-full"}):e.type==="boolean"?y.jsxs("div",{className:"flex items-center gap-2 w-full",children:[y.jsx(ep,{checked:e.value,onCheckedChange:r=>{r!=="indeterminate"&&(e.onChange?.(r),t.setNodes(i=>i.map(s=>s.id===n?{...s,data:uf(s.data,e.id,{value:r},!0,!1,!1)}:s)))}}),y.jsx("p",{className:"text-primary-white text-[27px] leading-[27px] font-main truncate",children:e.name})]}):null},nS=({input:e,isCurrentlyInsideReactFlow:t})=>t?y.jsx(tS,{input:e}):e.type==="string"?y.jsx(ws,{placeholder:e.name,value:e.value,onChange:e.onChange,allowOnlyNumbers:!1,className:"w-full"}):e.type==="number"?y.jsx(ni,{name:e.name,value:e.value,onChange:e.onChange,className:"w-full"}):e.type==="boolean"?y.jsxs("div",{className:"flex items-center gap-2 w-full",children:[y.jsx(ep,{checked:e.value,onCheckedChange:n=>{n!=="indeterminate"&&e.onChange?.(n)}}),y.jsx("p",{className:"text-primary-white text-[27px] leading-[27px] font-main truncate",children:e.name})]}):null,rS=({})=>{const e=T.useContext(uo),t=us(),n=()=>{e?.allProps?.dispatch&&t&&e.allProps.dispatch({type:ft.OPEN_NODE_GROUP,payload:{nodeId:t}})};return y.jsx(eg,{strokeWidth:2.5,className:"shrink-0 w-7 h-7 aspect-square cursor-pointer hover:opacity-80",onClick:n})},oS=({showButton:e=!1,isCurrentlyInsideReactFlow:t})=>e?t?y.jsx(rS,{}):y.jsx(eg,{strokeWidth:2.5,className:"shrink-0 w-7 h-7 aspect-square cursor-pointer hover:opacity-80"}):y.jsx(y.Fragment,{}),tp=T.forwardRef(({input:e,isCurrentlyInsideReactFlow:t,hide:n=!1},r)=>{const i=t?q0({handleId:e.id}):[],s=t&&i.some(l=>l.targetHandle===e.id),a=e.allowInput&&!s;return y.jsxs("div",{ref:r,className:ye("text-primary-white text-[27px] leading-[27px] font-main relative px-6 flex flex-row py-3",n&&"h-0 overflow-hidden py-0",a&&"py-1"),children:[y.jsx(nl,{type:"target",position:Ne.Left,id:e.id,color:e.handleColor,shape:e.handleShape,maxConnections:e.maxConnections,isCurrentlyInsideReactFlow:t}),y.jsxs("div",{className:"flex-1 flex items-center gap-3 w-full",children:[!a&&y.jsx("div",{className:"truncate",children:e.name||""}),a&&y.jsx("div",{className:"flex-1 w-full",children:y.jsx(nS,{input:e,isCurrentlyInsideReactFlow:t})})]})]},e.id)});tp.displayName="RenderInput";const iS=T.forwardRef(({output:e,isCurrentlyInsideReactFlow:t},n)=>y.jsxs("div",{ref:n,className:"text-primary-white text-[27px] leading-[27px] font-main relative px-6 flex flex-row justify-end py-3",children:[y.jsx("div",{className:"truncate text-right",children:e.name||""}),y.jsx(nl,{type:"source",position:Ne.Right,id:e.id,color:e.handleColor,shape:e.handleShape,maxConnections:e.maxConnections,isCurrentlyInsideReactFlow:t})]},e.id));iS.displayName="RenderOutput";const sS=T.forwardRef(({panel:e,isCurrentlyInsideReactFlow:t,isOpen:n,onToggle:r},i)=>y.jsxs("div",{ref:i,className:"flex flex-col",children:[y.jsxs(Qn,{onClick:s=>{s.stopPropagation(),s.preventDefault(),r()},className:"bg-transparent border-none hover:bg-primary-gray rounded-none justify-start",children:[n?y.jsx(su,{className:"w-6 h-6 shrink-0 mr-2"}):y.jsx(Ei,{className:"w-6 h-6 shrink-0 mr-2"}),y.jsx("span",{className:"truncate",children:e.name})]}),y.jsx("div",{className:ye("flex flex-col bg-[#272727]",!n&&"h-0 overflow-hidden"),children:e.inputs.map(s=>y.jsx(tp,{input:s,isCurrentlyInsideReactFlow:t,hide:!n},s.id))})]},e.id));sS.displayName="RenderInputPanel";const np=T.forwardRef(({id:e,name:t="Node",headerColor:n="#79461D",inputs:r=[],outputs:i=[],isCurrentlyInsideReactFlow:s=!1,className:a,nodeResizerProps:l={},nodeTypeUniqueId:u,showNodeOpenButton:d=!1,runnerVisualState:f,runnerErrors:g,runnerWarnings:h,...m},x)=>{const[v,b]=T.useState(new Set),S=T.useContext(uo),N=I=>{b(k=>{const A=new Set(k);return A.has(I)?A.delete(I):A.add(I),A})},w=y.jsxs("div",{tabIndex:0,className:ye("flex flex-col gap-0 rounded-md w-max border-[1.5px] border-transparent focus:border-white","in-[.selected]:border-white",a),...m,ref:x,children:[y.jsxs("div",{className:`text-primary-white text-left text-[27px] leading-[27px] font-main \\
|
|
304
|
+
`):void 0;return y.jsxs("div",{className:"relative",children:[y.jsx("div",{className:ye("absolute inset-0 rounded-md pointer-events-none z-10 transition-[outline-color,box-shadow,opacity] duration-200",e==="idle"&&"[outline:5px_solid_transparent] shadow-none",e==="running"&&"[outline:5px_dashed_var(--color-primary-blue)] animate-[running-glow_2s_ease-in-out_infinite]",e==="completed"&&"[outline:5px_solid_var(--color-status-completed)] shadow-[0_0_12px_rgba(76,175,80,0.3)]",e==="errored"&&"[outline:5px_solid_var(--color-status-errored)] shadow-[0_0_12px_rgba(255,68,68,0.3)]",e==="skipped"&&"[outline:5px_dashed_var(--color-secondary-dark-gray)] opacity-50",e==="warning"&&"[outline:5px_solid_var(--color-status-warning)] shadow-[0_0_12px_rgba(255,165,0,0.3)]")}),e==="errored"&&i&&y.jsx(sb,{icon:y.jsx(R_,{className:"w-5 h-5 text-[#FF4444]"}),content:i}),e==="warning"&&s&&y.jsx(sb,{icon:y.jsx(ng,{className:"w-5 h-5 text-[#FFA500]"}),content:s}),e==="skipped"&&y.jsx("div",{className:"absolute inset-0 rounded-md bg-black/30 pointer-events-none z-10"}),r]})}function cb({orientation:e="horizontal",disabled:t=!1,scrollSpeedPxPerFrame:n=14,observeChildren:r=!0}={}){const i=T.useRef(null),[s,a]=T.useState(!1),[l,u]=T.useState(!1),d=T.useRef(null),f=T.useRef(null),g=T.useCallback(()=>e==="vertical"?{pos:"scrollTop",size:"clientHeight",full:"scrollHeight"}:{pos:"scrollLeft",size:"clientWidth",full:"scrollWidth"},[e]),h=T.useCallback(()=>{const b=i.current;if(!b||t){a(!1),u(!1);return}const S=g(),N=b[S.pos],w=b[S.size],I=b[S.full];a(N>0),u(N+w<I-1)},[t,g]),m=T.useCallback(()=>{d.current!==null&&(cancelAnimationFrame(d.current),d.current=null),f.current=null},[]),x=T.useCallback(()=>{const b=i.current;if(!b||!f.current||t){m();return}const S=g(),N=f.current==="start"?-1:1;if(S.pos==="scrollLeft"?b.scrollLeft+=N*n:b.scrollTop+=N*n,h(),N<0&&!s||N>0&&!l){m();return}d.current=requestAnimationFrame(x)},[l,s,t,g,n,m,h]),v=T.useCallback(b=>{t||f.current!==b&&(f.current=b,d.current!==null&&cancelAnimationFrame(d.current),d.current=requestAnimationFrame(x))},[t,x]);return T.useEffect(()=>{h();const b=i.current;if(!b)return;const S=()=>h();b.addEventListener("scroll",S,{passive:!0});let N=null;"ResizeObserver"in window&&(N=new ResizeObserver(()=>h()),N.observe(b));const w=()=>h();window.addEventListener("resize",w);const I=()=>m();return window.addEventListener("pointerup",I),window.addEventListener("touchend",I),()=>{b.removeEventListener("scroll",S),window.removeEventListener("resize",w),window.removeEventListener("pointerup",I),window.removeEventListener("touchend",I),N&&N.disconnect()}},[h,m]),T.useEffect(()=>{const b=requestAnimationFrame(h);return()=>cancelAnimationFrame(b)},[h]),T.useEffect(()=>{if(!r)return;const b=i.current;if(!b)return;const S=new MutationObserver(()=>h());return S.observe(b,{childList:!0,subtree:!0}),()=>S.disconnect()},[r,h]),{listRef:i,canScrollStart:s,canScrollEnd:l,startAutoScroll:v,stopAutoScroll:m}}const Rf=T.forwardRef(({children:e,orientation:t="horizontal",className:n,scrollAreaClassName:r,showArrows:i=!0,disabled:s=!1,ariaLabel:a,scrollSpeedPxPerFrame:l=14,observeChildren:u=!0},d)=>{const{listRef:f,canScrollStart:g,canScrollEnd:h,startAutoScroll:m,stopAutoScroll:x}=cb({orientation:t,disabled:s,scrollSpeedPxPerFrame:l,observeChildren:u});T.useImperativeHandle(d,()=>f.current);const v=i&&g&&!s,b=i&&h&&!s,S=t==="horizontal"?"overflow-x-scroll overflow-y-hidden flex items-center gap-2 whitespace-nowrap":"overflow-y-scroll overflow-x-hidden flex flex-col items-start gap-2";return y.jsxs("div",{className:ye("relative w-full h-full",n),children:[v&&y.jsx(Qn,{className:ye("h-[44px] border-secondary-dark-gray bg-primary-black absolute z-10",t==="horizontal"?"left-0 top-1/2 -translate-y-1/2":"top-0 left-1/2 -translate-x-1/2"),disabled:!v,onMouseDown:()=>m("start"),onMouseUp:x,onMouseLeave:x,onTouchStart:()=>m("start"),onTouchEnd:x,children:t==="horizontal"?y.jsx(iu,{}):y.jsx(su,{})}),y.jsx("div",{ref:f,"aria-label":a,className:ye("no-scrollbar w-full h-full",S,r),children:e}),b&&y.jsx(Qn,{className:ye("h-[44px] border-secondary-dark-gray bg-primary-black absolute z-10",t==="horizontal"?"right-0 top-1/2 -translate-y-1/2":"bottom-0 left-1/2 -translate-x-1/2"),disabled:!b,onMouseDown:()=>m("end"),onMouseUp:x,onMouseLeave:x,onTouchStart:()=>m("end"),onTouchEnd:x,children:t==="horizontal"?y.jsx(zr,{}):y.jsx(Ei,{})})]})});Rf.displayName="ScrollableButtonContainer";function sn({content:e,children:t,infoIcon:n=!1,placement:r="bottom",maxWidth:i=240,className:s,style:a,as:l="span",triggerProps:u}){const[d,f]=T.useState(!1),g=T.useRef(null),h=T.useRef(null),{refs:m,floatingStyles:x,context:v}=Wc({open:d,onOpenChange:f,middleware:[Oi(6),Ri(),Pi({padding:8}),Vu({element:h})],whileElementsMounted:Mi,placement:r});T.useEffect(()=>{g.current&&m.setPositionReference(g.current)},[m]);const{isMounted:b,styles:S}=rb(v,{duration:120,initial:{opacity:0,transform:"translateY(-3px)"}});return y.jsxs(y.Fragment,{children:[y.jsxs(l,{ref:g,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),className:ye("inline-flex items-center gap-1.5",s),style:a,...u,children:[n&&y.jsx(L_,{className:"h-3.5 w-3.5 shrink-0 text-primary-white"}),t]}),b&&y.jsx(Jw,{children:y.jsx("div",{ref:m.setFloating,style:{...x,pointerEvents:"none",zIndex:50},children:y.jsxs("div",{style:{...S,maxWidth:`${i}px`},className:"rounded-md border-[1.25px] border-primary-white/60 bg-tooltip-bg px-3 py-2 text-[12px] text-primary-white shadow-2xl backdrop-blur-sm",children:[e,y.jsx(Ww,{ref:h,context:v,width:8,height:4,fill:"var(--color-tooltip-bg)",strokeWidth:1,stroke:"var(--color-secondary-dark-gray)"})]})})})]})}function lb({onMove:e,onClick:t,clickThreshold:n=2,enabled:r=!0,preventDefaultAndStopPropagation:i=!0}={}){const[s,a]=T.useState(!1),[l,u]=T.useState(null),d=T.useRef(null),f=T.useRef(null),g=T.useCallback(h=>{u(h)},[]);return T.useEffect(()=>{if(!l||!r)return;const h=m=>{i&&(m.preventDefault(),m.stopPropagation()),d.current={x:m.clientX,y:m.clientY},f.current={width:l.clientWidth,height:l.clientHeight},a(!0);const x=b=>{i&&(b.preventDefault(),b.stopPropagation()),document.removeEventListener("mouseup",x),document.removeEventListener("mousemove",v),a(!1),d.current&&Math.sqrt((b.clientX-d.current.x)**2+(b.clientY-d.current.y)**2)<n&&t?.()},v=b=>{i&&(b.preventDefault(),b.stopPropagation());const S=b.movementX,N=b.movementY,w=f.current?.width||1,I=f.current?.height||1,k=S/w,A=N/I;e?.(S,N,k,A,w,I)};document.addEventListener("mouseup",x),document.addEventListener("mousemove",v)};return l.addEventListener("mousedown",h),()=>{l.removeEventListener("mousedown",h)}},[l,r,e,t,n,i]),{isDragging:s,dragRef:g}}const ni=T.forwardRef(({name:e="Input",value:t,onChange:n=()=>{},className:r,min:i,max:s,step:a,size:l="normal",decimals:u},d)=>{const f=l==="small",g=u??(f?1:4),[h,m]=T.useState(t??0),[x,v]=T.useState(!1),b=T.useRef(0),S=T.useRef(0),N=t??h,w=T.useRef(0);T.useEffect(()=>{if(a!==void 0)w.current=Math.abs(a);else if(i!==void 0&&s!==void 0)w.current=Math.abs(s-i);else{const W=Math.pow(10,-g);w.current=Math.max(Math.abs(parseFloat((N||1).toString())),W)}},[N,a,g,s,i]);const{isDragging:I,dragRef:k}=lb({onMove:(W,z,Y,J,ie)=>{const ee=W/(ie+60);b.current+=ee,Math.abs(b.current)>.05&&Date.now()-S.current>50&&(S.current=Date.now(),A(w.current*b.current),b.current=0)},onClick:U,clickThreshold:2});function A(W){m(z=>{let Y=z+W;return i!==void 0&&Y<=i?Y=i:s!==void 0&&Y>=s&&(Y=s),n(Y),Y})}function M(W=.1){A(w.current*W)}function B(W=.1){A(-w.current*W)}function U(){v(!0)}function q(W){A(W-N),v(!1)}const D=I,$=i!==void 0&&s!==void 0&&N!==void 0&&s!==i?(N-i)/(s-i)*100:-1,F=$!==-1?`linear-gradient(90deg,#4772b3 ${$}%, #545454 ${$}%)`:"",E=f?"h-[22px]":"h-[44px]",P=f?`${E} w-[18px]`:`${E} w-[30px]`,L=f?"h-3 w-3":"",j=f?"text-[10px]":"",O=f?`${E} rounded-none px-1.5 flex-1 justify-between grid grid-cols-[repeat(2,auto)] bg-transparent gap-1`:`${E} rounded-none pl-1.5 pr-0 flex-1 justify-between grid grid-cols-[repeat(2,auto)] bg-transparent`;return x?y.jsx(ws,{className:ye("w-full",f&&"h-[22px] text-[11px] px-1.5"),placeholder:e,value:N,allowOnlyNumbers:!0,numberOfDecimals:g,onChange:W=>q(W),ref:d}):y.jsxs("div",{className:ye("flex items-center gap-0 group/lightParentGroupBasedHover w-max bg-primary-gray",f?"rounded-sm":"rounded-md",r),style:F!==""?{background:F}:{},ref:d,children:[y.jsx(Qn,{color:"lightParentGroupBasedHover",className:ye(P,"rounded-r-none p-0 shrink-0 bg-transparent",j),onClick:()=>B(.1),"aria-label":`Decrement ${e}`,applyHoverStyles:!D,children:y.jsx(iu,{className:L||void 0})}),y.jsxs(Qn,{color:"lightParentGroupBasedHover",className:ye(O,j),applyHoverStyles:!D,ref:k,children:[y.jsx("span",{className:"truncate text-left",children:e}),y.jsx("span",{className:"truncate tabular-nums",children:N.toFixed(g)})]}),y.jsx(Qn,{color:"lightParentGroupBasedHover",className:ye(P,"rounded-l-none p-0 shrink-0 bg-transparent",j),onClick:()=>M(.1),"aria-label":`Increment ${e}`,applyHoverStyles:!D,children:y.jsx(zr,{className:L||void 0})})]})});ni.displayName="SliderNumberInput";const ub=100,db=100,Lf=75,fb=100;function q2(e,t){const[n,r]=T.useState(null),i=T.useRef(new Map),s=T.useRef(null),a=T.useRef(!1),l=T.useCallback(()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),[u,d]=T.useState(null),[f,g]=T.useState(null),h=T.useRef(null),m=T.useRef(null),x=T.useRef(null),[v,b]=T.useState(null),S=T.useRef(null),N=T.useRef(null),w=T.useRef(!1),I=T.useRef(!1),[k,A]=T.useState(null),M=T.useRef(null),B=T.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null),m.current&&(cancelAnimationFrame(m.current),m.current=null)},[]),U=T.useCallback(ee=>{const ce=x.current;if(ee!==ce){if(x.current=ee,B(),ce!==null&&ee!==null){I.current=!0;const ge=e.find(Q=>Q.id===ce);ge?.subItems&&d(ge.subItems),g("initial")}else if(I.current=!1,g(null),d(null),ee===null){const ge=e.find(Q=>Q.id===ce);ge?.subItems?(A(ge.subItems),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{A(null),w.current=!1,b(null),M.current=null},ub)):(w.current=!1,b(null))}else M.current&&(clearTimeout(M.current),M.current=null),A(null);r(ee)}},[e,B]);T.useEffect(()=>{if(f==="initial")return m.current=requestAnimationFrame(()=>{m.current=requestAnimationFrame(()=>{g("animating"),m.current=null,h.current=setTimeout(()=>{g(null),d(null),I.current=!1,h.current=null},db)})}),B},[f,B]);const D=(n?e.find(ee=>ee.id===n):null)?.subItems??null;T.useLayoutEffect(()=>{N.current&&N.current.disconnect();const ee=S.current;if(!ee||!n)return;const ce=new ResizeObserver(ge=>{const Q=ge[0];if(!Q)return;const{width:te,height:ne}=Q.contentRect;te>0&&ne>0&&(w.current=!0,b({w:te,h:ne}))});return ce.observe(ee),N.current=ce,()=>ce.disconnect()},[n]);const $=n?i.current.get(n):null,{refs:F,floatingStyles:E,placement:P}=Wc({open:n!==null,onOpenChange:ee=>{ee||U(null)},strategy:"fixed",placement:"right-start",middleware:[Oi(5),Ri({fallbackPlacements:["left-start"]}),Pi({padding:8})],whileElementsMounted:Mi});T.useLayoutEffect(()=>{$&&F.setReference($)},[$,F]);const L=T.useCallback(ee=>{ee.onClick&&ee.onClick(),t&&t(ee)},[t]),j=T.useCallback(ee=>{l(),ee!==n&&(n===null?ee!==null&&(s.current=setTimeout(()=>{U(ee),s.current=null},Lf)):ee!==null?s.current=setTimeout(()=>{U(ee),s.current=null},fb):s.current=setTimeout(()=>{a.current||U(null),s.current=null},fb))},[n,l,U]),O=T.useCallback(()=>{a.current=!0,l()},[l]),W=T.useCallback(()=>{a.current=!1,l(),s.current=setTimeout(()=>{U(null),s.current=null},Lf)},[l,U]),z=T.useCallback(()=>{a.current||(l(),s.current=setTimeout(()=>{a.current||U(null),s.current=null},Lf))},[l,U]),Y=T.useCallback(ee=>ce=>{ce?i.current.set(ee,ce):i.current.delete(ee)},[]),J=n!==null,ie=v!==null?{width:v.w,height:v.h,overflow:"hidden"}:{};return{activeSubmenuId:n,activeSubItems:D,prevSubItems:u,exitSubItems:k,crossfadePhase:f,containerSize:v,isSwitching:I.current,isOpen:J,panelSizeStyles:ie,incomingRef:S,floatingRefs:F,floatingStyles:E,placement:P,handleItemClick:L,handleHover:j,handleFloatingMouseEnter:O,handleFloatingMouseLeave:W,handleListMouseLeave:z,makeItemRef:Y,SUBMENU_DURATION_MS:ub,CONTENT_FADE_DURATION_MS:db}}const Y2=({item:e,index:t,onItemClick:n,onHover:r,itemRef:i,itemTransitionStyle:s})=>{const a=e.subItems&&e.subItems.length>0;return y.jsxs("li",{className:"relative",children:[e.separator&&t>0&&y.jsx("div",{className:"border-t border-gray-600 m-0"}),y.jsxs("div",{ref:i,className:ye("flex items-center justify-between gap-2 px-3 py-1.25 hover:bg-[#3F3F3F] cursor-pointer","transition-colors duration-150"),style:s,onClick:()=>n(e),onMouseEnter:()=>r(a?e.id:null),children:[y.jsxs("div",{className:"flex items-center gap-2",children:[e.icon&&y.jsx("span",{className:"text-primary-white w-3 h-3 flex items-center justify-center",children:e.icon}),y.jsx("span",{className:"text-sm leading-3.5 text-primary-white font-main",children:e.label})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[e.shortcut&&y.jsx("span",{className:"text-sm leading-3.5 text-gray-400 font-mono",children:e.shortcut}),a&&y.jsx(zr,{className:"w-3 h-3 text-gray-400"})]})]})]})},Gc=({subItems:e,onItemClick:t,className:n,bare:r=!1,itemTransitionStyle:i})=>{const{activeSubItems:s,prevSubItems:a,exitSubItems:l,crossfadePhase:u,isSwitching:d,isOpen:f,panelSizeStyles:g,incomingRef:h,floatingRefs:m,floatingStyles:x,placement:v,handleItemClick:b,handleHover:S,handleFloatingMouseEnter:N,handleFloatingMouseLeave:w,handleListMouseLeave:I,makeItemRef:k,SUBMENU_DURATION_MS:A,CONTENT_FADE_DURATION_MS:M}=q2(e,t),B=e.some(U=>U.subItems&&U.subItems.length>0);return y.jsxs(y.Fragment,{children:[y.jsx("ul",{className:ye("min-w-48 py-1",!r&&"bg-[#181818] border border-none rounded-md shadow-lg",n),onMouseLeave:I,children:e.map((U,q)=>y.jsx(Y2,{item:U,index:q,onItemClick:b,onHover:S,itemRef:k(U.id),itemTransitionStyle:i},U.id))}),B&&y.jsx(Jw,{children:y.jsx("div",{ref:m.setFloating,style:{...x,transitionProperty:d?"opacity, transform, translate":"opacity, translate",transitionDuration:`${A}ms`,transitionTimingFunction:"ease-out"},className:ye("z-50",f?"opacity-100 translate-x-0":ye("opacity-0 pointer-events-none",v.startsWith("right")?"-translate-x-[20px]":"translate-x-[20px]")),onMouseEnter:N,onMouseLeave:w,children:y.jsx("div",{className:"bg-[#181818] rounded-md shadow-lg ml-1",style:{...g,transitionProperty:"opacity, translate, width, height",transitionDuration:`${A}ms`,transitionTimingFunction:"ease-out"},children:y.jsxs("div",{className:"relative",children:[u!==null&&a&&y.jsx("div",{className:"absolute inset-0",style:{pointerEvents:"none"},children:y.jsx(Gc,{subItems:a,onItemClick:t,bare:!0,itemTransitionStyle:u==="initial"?{opacity:1,transform:"translateX(0)"}:{opacity:0,transform:"translateX(10%)",transition:`opacity ${M}ms ease-out, transform ${M}ms ease-out`}})}),s&&y.jsx("div",{ref:h,children:y.jsx(Gc,{subItems:s,onItemClick:t,bare:!0,itemTransitionStyle:u==="initial"?{opacity:0,transform:"translateX(-10%)"}:u==="animating"?{opacity:1,transform:"translateX(0)",transition:`opacity ${M}ms ease-out, transform ${M}ms ease-out`}:void 0})}),!s&&l&&y.jsx(Gc,{subItems:l,onItemClick:t,bare:!0})]})})})})]})},pb=({subItems:e,className:t,onItemClick:n})=>y.jsx("div",{className:ye("relative",t),children:y.jsx(Gc,{subItems:e,onItemClick:n})});function Df(e){return e.kind==="leaf"?e.priority:e.children.length===0?0:Math.max(...e.children.map(Df))}function jf(e){return e.kind==="leaf"?e.insertionIndex:e.children.length===0?1/0:Math.min(...e.children.map(jf))}function hb(e){e.sort((t,n)=>{const r=Df(n)-Df(t);return r!==0?r:jf(t)-jf(n)});for(const t of e)t.kind==="folder"&&hb(t.children)}function gb(e){const t=[];for(const n of e)if(n.kind==="leaf")t.push(n.item);else{const r=gb(n.children);r.length>0&&t.push({id:`folder-${n.label}`,label:n.label,subItems:r})}return t}function mb({typeOfNodes:e,dispatch:t,setContextMenu:n,contextMenuPosition:r,isRecursionAllowed:i=!0,currentNodeType:s}){const a=Object.keys(e);if(a.length===0)return[];function l(g,h){if(h||!s)return g;const m=ew({typeOfNodes:e},s);return g.filter(x=>!m.has(x))}const u=l(a,i),d=[];for(let g=0;g<u.length;g++){const h=u[g],m=e[h],x=m.locationInContextMenu??[],v=m.priorityInContextMenu??0,b={kind:"leaf",item:{id:`add-${String(h)}`,label:m.name,onClick:()=>{t({type:ft.ADD_NODE_AND_SELECT,payload:{type:h,position:r}}),n({isOpen:!1,position:{x:0,y:0}})}},priority:v,insertionIndex:g};if(x.length===0)d.push(b);else{let S=d;for(const N of x){let w=S.find(I=>I.kind==="folder"&&I.label===N);w||(w={kind:"folder",label:N,children:[]},S.push(w)),S=w.children}S.push(b)}}hb(d);const f=gb(d);return[{id:"add-node",label:"Add Node",icon:T.createElement(Jh,{className:"w-4 h-4"}),subItems:f}]}const yb=_T,$f=T.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(vy,{ref:r,className:ye("flex h-[44px] w-full items-center justify-between rounded-md border cursor-pointer border-secondary-dark-gray bg-primary-black px-4 py-2 text-[27px] leading-[27px] font-main text-primary-white data-[placeholder]:text-[#6B6B6B] focus:outline-none focus-visible:ring-1 focus-visible:ring-white disabled:cursor-not-allowed disabled:opacity-50",e),...n,children:[y.jsx("span",{className:"text-left truncate",children:t}),y.jsx(NT,{asChild:!0,children:y.jsx(Ei,{className:"h-6 w-6 shrink-0 ml-2"})})]}));$f.displayName=vy.displayName;const Hf=T.forwardRef(({className:e,...t},n)=>y.jsx(_y,{ref:n,className:ye("flex cursor-default items-center justify-center py-1",e),...t,children:y.jsx(su,{className:"h-4 w-4"})}));Hf.displayName=_y.displayName;const Bf=T.forwardRef(({className:e,...t},n)=>y.jsx(Ny,{ref:n,className:ye("flex cursor-default items-center justify-center py-1",e),...t,children:y.jsx(Ei,{className:"h-4 w-4"})}));Bf.displayName=Ny.displayName;const Vf=T.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>y.jsx(IT,{children:y.jsxs(wy,{ref:i,className:ye("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-secondary-dark-gray bg-[#181818] text-primary-white shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[y.jsx(Hf,{}),y.jsx(ET,{className:ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),y.jsx(Bf,{})]})}));Vf.displayName=wy.displayName;const vb=T.forwardRef(({className:e,...t},n)=>y.jsx(by,{ref:n,className:ye("py-1.5 px-2 text-[27px] leading-[27px] font-main font-semibold text-primary-white",e),...t}));vb.displayName=by.displayName;const qc=T.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(Sy,{ref:r,className:ye("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-4 pr-2 text-[27px] leading-[27px] font-main text-primary-white outline-none focus:bg-[#3F3F3F] focus:text-primary-white data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[y.jsx(CT,{children:t}),y.jsx("span",{className:"ml-auto",children:y.jsx(AT,{children:y.jsx(sa,{className:"h-5 w-5 ml-2 mr-1",strokeWidth:2.5})})})]}));qc.displayName=Sy.displayName;const xb=T.forwardRef(({className:e,...t},n)=>y.jsx(Iy,{ref:n,className:ye("-mx-1 my-1 h-px bg-secondary-dark-gray",e),...t}));xb.displayName=Iy.displayName;const X2=TT,Ff=T.forwardRef(({className:e,...t},n)=>y.jsx(xy,{ref:n,className:ye(e),...t}));Ff.displayName=xy.displayName;const K2={small:{wrapper:"rounded-sm border border-secondary-dark-gray/80",button:"px-2.5 py-0.5 text-[12px]",divider:"border-l border-secondary-dark-gray/50",activeBg:"bg-primary-blue text-white",inactiveBg:"bg-[#1a1a1a] text-secondary-light-gray hover:bg-primary-dark-gray hover:text-primary-white"},normal:{wrapper:"rounded-md border border-runner-timeline-box-border bg-runner-inset-bg p-[3px]",button:"rounded px-3.5 py-1 text-[13px]",divider:"",activeBg:"bg-primary-blue text-white",inactiveBg:"bg-[#1a1a1a] text-secondary-light-gray"}};function zf({options:e,value:t,onChange:n,disabled:r=!1,size:i="normal",className:s}){const a=K2[i];return y.jsx("div",{className:ye("flex overflow-hidden",a.wrapper,s),children:e.map((l,u)=>y.jsx("button",{type:"button",onClick:()=>n(l.value),disabled:r,className:ye("btn-press font-medium transition-all duration-100",a.button,u>0&&a.divider,t===l.value?a.activeBg:a.inactiveBg,r&&t!==l.value&&"cursor-not-allowed opacity-50",!r&&t!==l.value&&i==="normal"&&"hover:text-primary-white"),children:l.label},l.value))})}const Z2=[{value:"instant",label:"Instant"},{value:"stepByStep",label:"Step-by-Step"}],J2={idle:{color:"bg-secondary-dark-gray",pulse:!1,label:"Idle"},compiling:{color:"bg-primary-blue",pulse:!0,label:"Compiling"},running:{color:"bg-status-completed",pulse:!0,label:"Running"},paused:{color:"bg-status-warning",pulse:!1,label:"Paused"},completed:{color:"bg-status-completed",pulse:!1,label:"Completed"},errored:{color:"bg-status-errored",pulse:!1,label:"Error"}};function Ns({icon:e,onClick:t,disabled:n,active:r=!1,variant:i="default",title:s}){const a=i==="play";return y.jsx("button",{type:"button",onClick:t,disabled:n,title:s,className:ye("btn-press flex items-center justify-center transition-all duration-100",a?"h-8 w-8 rounded-md bg-primary-blue text-white shadow-[0_0_12px_rgba(74,120,194,0.4)]":"h-7 w-7 rounded",n&&"cursor-not-allowed opacity-30",!n&&!r&&!a&&"hover:bg-primary-dark-gray hover:text-white",!n&&a&&"hover:brightness-110",r&&!a&&"bg-primary-blue shadow-[0_0_8px_rgba(71,114,179,0.5)]",!n&&"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary-blue"),children:e})}function wb({runnerState:e,onRun:t,onPause:n,onStep:r,onStop:i,onReset:s,mode:a,onModeChange:l,maxLoopIterations:u,onMaxLoopIterationsChange:d}){const f=J2[e],g=e==="idle"||e==="completed"||e==="errored",h=e==="idle"||e==="errored",m=e==="running",x=e==="paused"||e==="idle"||e==="errored",v=e==="running"||e==="paused",b=e==="completed"||e==="errored";return y.jsxs("div",{className:"flex h-11 w-full items-center gap-2 border-b border-secondary-dark-gray bg-runner-toolbar-bg px-3",children:[y.jsxs("div",{className:"flex w-[140px] items-center gap-2.5",children:[y.jsxs("div",{className:"relative flex items-center justify-center",children:[y.jsx("div",{className:ye("h-2.5 w-2.5 rounded-full transition-colors duration-200",f.color,f.pulse&&"animate-pulse",f.pulse&&"shadow-[0_0_8px_currentColor]")}),f.pulse&&y.jsx("div",{className:ye("absolute h-2.5 w-2.5 animate-ping rounded-full opacity-50",f.color)})]}),y.jsx("span",{className:"text-[14px] text-primary-white",children:f.label})]}),y.jsx("div",{className:"mx-3 h-6 w-px bg-secondary-dark-gray"}),y.jsxs("div",{className:"flex items-center gap-3",children:[y.jsx(Ns,{icon:y.jsx(au,{className:"h-3.5 w-3.5 fill-current"}),onClick:t,disabled:!h,active:e==="running",variant:"play",title:"Run"}),y.jsx(Ns,{icon:y.jsx(H_,{className:"h-4 w-4 text-primary-white"}),onClick:n,disabled:!m,title:"Pause"}),y.jsx(Ns,{icon:y.jsx(V_,{className:"h-4 w-4 text-primary-white"}),onClick:r,disabled:!x,title:"Step"}),y.jsx(Ns,{icon:y.jsx(tg,{className:"h-4 w-4 text-primary-white"}),onClick:i,disabled:!v,title:"Stop"}),y.jsx(Ns,{icon:y.jsx(B_,{className:"h-4 w-4 text-primary-white"}),onClick:s,disabled:!b,title:"Reset"})]}),y.jsx("div",{className:"mx-3 h-6 w-px bg-secondary-dark-gray"}),y.jsx(sn,{content:"Instant runs the entire graph at once, then enables replay. Step-by-Step pauses after each node so you can inspect intermediate values.",children:y.jsx(zf,{options:Z2,value:a,onChange:l,disabled:!g,size:"small"})}),y.jsx(sn,{content:"Maximum loop iterations before the runner throws an error. Protects against infinite loops.",children:y.jsx("div",{className:ye("ml-4",!g&&"pointer-events-none opacity-50"),children:y.jsx(ni,{name:"Max Loops",value:u,onChange:S=>d(Math.max(1,Math.round(S))),size:"small",decimals:0})})})]})}const bb=T.createContext(null);function Q2({children:e}){const[t,n]=T.useState(null),[r,i]=T.useState(!0),[s,a]=T.useState(!0),[l,u]=T.useState(!0),[d,f]=T.useState("execution"),[g,h]=T.useState(!1),[m,x]=T.useState(new Map),[v,b]=T.useState(2),S=T.useCallback(()=>{const I={};for(const[k,A]of m)I[k]=A;return{selectedStepIndex:t,edgeValuesAnimated:r,panelOpen:s,autoScroll:l,timeMode:d,timelineCollapsed:g,selectedIterations:I,autoplayIntervalSec:v}},[t,r,s,l,d,g,m,v]),N=T.useCallback(I=>{I.selectedStepIndex!==void 0&&n(I.selectedStepIndex),I.edgeValuesAnimated!==void 0&&i(I.edgeValuesAnimated),I.panelOpen!==void 0&&a(I.panelOpen),I.autoScroll!==void 0&&u(I.autoScroll),I.timeMode!==void 0&&f(I.timeMode),I.timelineCollapsed!==void 0&&h(I.timelineCollapsed),I.selectedIterations&&x(new Map(Object.entries(I.selectedIterations).map(([k,A])=>[k,A]))),I.autoplayIntervalSec!==void 0&&b(I.autoplayIntervalSec)},[]),w=T.useMemo(()=>({selectedStepIndex:t,setSelectedStepIndex:n,edgeValuesAnimated:r,setEdgeValuesAnimated:i,isRunnerPanelOpen:s,setIsRunnerPanelOpen:a,autoScroll:l,setAutoScroll:u,timeMode:d,setTimeMode:f,timelineCollapsed:g,setTimelineCollapsed:h,selectedIterations:m,setSelectedIterations:x,autoplayIntervalSec:v,setAutoplayIntervalSec:b,getViewState:S,restoreViewState:N}),[t,r,s,l,d,g,m,v,S,N]);return y.jsx(bb.Provider,{value:w,children:e})}function Uf(){const e=T.useContext(bb);if(!e)throw new Error("useRecordingViewState must be used within a RecordingViewStateProvider");return e}const Is=.5,Wf=1e4,eD=.003,Sb=3;function tD({adjustedTotalDuration:e,timePadRightMs:t,gutterWidth:n}){const r=T.useRef(null),i=T.useRef(!1),s=T.useRef(0),a=T.useRef(0),[l,u]=T.useState(0),d=T.useRef(null),f=T.useRef(null),g=r.current;if(g!==f.current&&(d.current&&(d.current.disconnect(),d.current=null),f.current=g,g)){u(g.clientWidth);const P=new ResizeObserver(L=>{const j=L[0];j&&u(j.contentRect.width)});P.observe(g),d.current=P}T.useEffect(()=>()=>{d.current?.disconnect()},[]);const[h,m]=T.useState(!0),[x,v]=T.useState(Is),b=T.useMemo(()=>{const P=l-n;return P<=0||e<=0?Is:Math.max(Is,Math.min(Wf,P/(e*(1+t))))},[l,n,e,t]),S=h?b:x,N=T.useRef(b);T.useLayoutEffect(()=>{if(!h||N.current===b)return;N.current=b;const P=r.current;P&&(P.scrollLeft=0)},[h,b]);const w=T.useRef(null);T.useLayoutEffect(()=>{w.current!==null&&r.current&&(r.current.scrollLeft=w.current,w.current=null)});const I=T.useCallback(()=>{m(!0);const P=r.current;P&&(P.scrollLeft=0)},[]),k=T.useCallback(P=>{const L=r.current;if(!L)return;const j=L.scrollLeft+(L.clientWidth-n)/2,O=h?b:x,W=j/O,z=Math.max(Is,Math.min(Wf,O*P));w.current=W*z-(L.clientWidth-n)/2,m(!1),v(z)},[n,h,b,x]),A=T.useRef(S);A.current=S;const M=T.useRef(n);M.current=n;const B=T.useRef(h);B.current=h;const U=T.useRef(null);U.current||(U.current=P=>{if(!P.shiftKey)return;P.preventDefault();const L=r.current;if(!L)return;const j=M.current,O=L.getBoundingClientRect(),W=P.clientX-O.left+L.scrollLeft-j,z=A.current,Y=W/z,J=-P.deltaY*eD,ie=Math.pow(2,J),ee=Math.max(Is,Math.min(Wf,z*ie));w.current=Y*ee-(P.clientX-O.left-j),m(!1),v(ee)});const q=T.useRef(null);T.useEffect(()=>{const P=r.current,L=U.current;if(P!==q.current)return q.current&&q.current.removeEventListener("wheel",L),q.current=P,P&&P.addEventListener("wheel",L,{passive:!1}),()=>{q.current&&(q.current.removeEventListener("wheel",L),q.current=null)}});const D=T.useRef(0),$=T.useRef(0),F=T.useRef(!1),E=T.useCallback(P=>{if(P.button!==0&&P.button!==1)return;const L=r.current;if(!L)return;P.preventDefault(),i.current=!0,F.current=!1,s.current=P.clientX,D.current=P.clientY,a.current=L.scrollLeft,$.current=L.scrollTop,L.style.cursor="grabbing",document.body.style.userSelect="none";const j=W=>{if(!i.current)return;W.preventDefault();const z=W.clientX-s.current,Y=W.clientY-D.current;(Math.abs(z)>Sb||Math.abs(Y)>Sb)&&(F.current=!0),L.scrollLeft=a.current-z,L.scrollTop=$.current-Y},O=()=>{i.current=!1,L.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",O),document.removeEventListener("mouseleave",O),requestAnimationFrame(()=>{F.current=!1})};document.addEventListener("mousemove",j),document.addEventListener("mouseup",O),document.addEventListener("mouseleave",O)},[]);return{timeScale:S,scrollContainerRef:r,fitToView:I,zoomBy:k,handlePanStart:E,didPanMoveRef:F}}const nD=6;function _b(e,t){const n=e.startTime*t,r=Math.max(e.duration*t,nD);return n+r/2}function Nb(e,t,n){if(t.length===0)return null;let r=t[0].stepIndex,i=1/0;for(const s of t){const a=_b(s,n),l=Math.abs(a-e);l<i&&(i=l,r=s.stepIndex)}return r}function rD({steps:e,timeScale:t,contentWidth:n,currentStepIndex:r,scrollContainerRef:i,gutterWidth:s,onScrubTo:a}){const[l,u]=T.useState(null),[d,f]=T.useState(null),g=T.useRef(null),h=l!==null,m=T.useRef(!1),x=T.useRef(r);x.current!==r&&!h&&(m.current=!0),x.current=r;const v=e[r],b=v?_b(v,t):0,S=l??b,N=T.useCallback(A=>{const M=i.current;if(!M||e.length===0)return;const B=M.getBoundingClientRect(),U=A-B.left+M.scrollLeft-s,q=Math.max(0,Math.min(U,n));u(q);const D=Nb(q,e,t);g.current=D,f(D),D!==null&&a(D);const $=E=>{const P=M.getBoundingClientRect(),L=E.clientX-P.left+M.scrollLeft-s,j=Math.max(0,Math.min(L,n));u(j);const O=Nb(j,e,t);O!==g.current&&O!==null&&a(O),g.current=O,f(O)},F=()=>{document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",F),g.current!==null&&a(g.current),g.current=null,u(null),f(null),m.current=!0,setTimeout(()=>{m.current=!1},200)};document.addEventListener("mousemove",$),document.addEventListener("mouseup",F)},[e,t,n,s,i,a]),w=T.useCallback(A=>{A.stopPropagation(),N(A.clientX)},[N]),I=T.useCallback(A=>{A.stopPropagation(),A.preventDefault(),N(A.clientX)},[N]),k=T.useCallback(()=>{m.current=!1},[]);return{scrubberPx:S,isDraggingScrubber:h,nearestDragStepIndex:d,isSnapping:m.current,startScrubDrag:N,handleRulerScrubDown:w,handleScrubberMouseDown:I,onSnapTransitionEnd:k}}const Es=28,Ts=3,Yc=4,oD=32,Gf=6,Ib=0,Eb=.15,Tb=48,Cb=50,Ab=18,iD=[{value:"execution",label:"Execution"},{value:"wallClock",label:"Wall Clock"}],sD={completed:"bg-runner-bar-completed",errored:"bg-runner-bar-errored",skipped:"bg-status-skipped"},aD={completed:"text-status-completed",errored:"text-status-errored",skipped:"text-secondary-light-gray"},cD={completed:"Done",errored:"Error",skipped:"Skipped"};function kb(e){const t=Math.pow(10,Math.floor(Math.log10(e))),n=e/t;return n<=1?t:n<=2?2*t:n<=5?5*t:10*t}function Mb(e){return e===0||e<0?"0":e<1?`${(e*1e3).toFixed(0)}µs`:e<1e3?`${e.toFixed(e<10?1:0)}ms`:`${(e/1e3).toFixed(2)}s`}function lD(e){return e.estimatedTiming?"< 0.1ms":`${e.duration.toFixed(2)}ms`}function uD(e){const t=new Map;for(const n of e){const r=t.get(n.concurrencyLevel);r?r.push(n):t.set(n.concurrencyLevel,[n])}return t}const Ob={loopStart:0,preStop:1,loopStop:2,postStop:3,loopEnd:4};function dD(e,t){const n=e.loopPhase?Ob[e.loopPhase]:1,r=t.loopPhase?Ob[t.loopPhase]:1;return n!==r?n-r:e.startTime-t.startTime}function Pb(e,t,n){const r=t.iterations.map(i=>{const s=i.stepRecords;if(s.length===0)return{...i,adjustedStartTime:i.startTime,adjustedEndTime:i.endTime,adjustedDuration:i.duration};let a=1/0,l=-1/0;for(const u of s){const d=n?u.startTime-u.pauseAdjustment:u.startTime,f=n?u.endTime-u.pauseAdjustment:u.endTime;d<a&&(a=d),f>l&&(l=f)}return{...i,adjustedStartTime:a,adjustedEndTime:l,adjustedDuration:l-a}});return{kind:"loop",loopStructureId:e,loopRecord:t,adjustedIterations:r,iterations:t.iterations.map(i=>({iteration:i.iteration,conditionValue:i.conditionValue,steps:[...i.stepRecords].sort(dD).map(s=>({...s,startTime:n?s.startTime-s.pauseAdjustment:s.startTime,endTime:n?s.endTime-s.pauseAdjustment:s.endTime,loopStructureId:void 0,loopIteration:void 0})),nestedLoopRecords:i.nestedLoopRecords}))}}function Rb(e,t,n){const r=[];let i=[];const s=new Map;for(const a of e)if(a.loopStructureId!==void 0&&a.loopIteration!==void 0){const u=a.loopStructureId,d=t.get(u);if(!d)continue;if(!s.has(u)&&i.length>0&&(r.push({kind:"flat",steps:i}),i=[]),!s.has(u)){const f=Pb(u,d,n);s.set(u,f),r.push(f)}}else{if(a.loopStructureId!==void 0&&!t.has(a.loopStructureId))continue;i.push(a)}i.length>0&&r.push({kind:"flat",steps:i});for(const[a,l]of t){if(s.has(a))continue;const u=Pb(a,l,n),d=l.iterations[0]?.startTime??0;let f=r.length;for(let g=r.length-1;g>=0;g--){const h=r[g];if((h.kind==="flat"?h.steps[0]?.startTime??0:h.loopRecord.iterations[0]?.startTime??0)<=d){if(h.kind==="flat"){const x=h.steps.filter(b=>b.startTime<=d),v=h.steps.filter(b=>b.startTime>d);if(x.length>0&&v.length>0){r.splice(g,1,{kind:"flat",steps:x},u,{kind:"flat",steps:v}),f=-1;break}}f=g+1;break}}f>=0&&r.splice(f,0,u)}return r}function fD({step:e}){return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("span",{className:"text-[12px] font-semibold text-primary-white",children:e.nodeTypeName}),y.jsx("span",{className:ye("text-[10px] font-medium",aD[e.status]),children:cD[e.status]})]}),y.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-secondary-light-gray",children:[y.jsx("span",{className:"font-mono tabular-nums",children:lD(e)}),y.jsx("span",{className:"text-secondary-dark-gray",children:"·"}),y.jsxs("span",{children:["Step ",e.stepIndex]}),e.loopIteration!==void 0&&y.jsxs(y.Fragment,{children:[y.jsx("span",{className:"text-secondary-dark-gray",children:"·"}),y.jsxs("span",{children:["Iter ",e.loopIteration]})]})]})]})}function pD({step:e,timeScale:t,timeOffset:n=0,isSelected:r,isSnapped:i,isNearestDragTarget:s,onClick:a,onScrubTo:l,subRowTop:u,subRowHeight:d}){const f=(e.startTime-n)*t,g=Math.max(e.duration*t,Gf),h=g>Cb&&d>=Ab;return y.jsx(sn,{as:"div",placement:"top",content:y.jsx(fD,{step:e}),className:ye("timeline-block absolute cursor-pointer rounded-[2px]",sD[e.status],r&&"z-10 ring-1 ring-white ring-offset-0",!r&&i&&!s&&"z-10 ring-2 ring-primary-blue ring-offset-0 shadow-[0_0_12px_rgba(71,114,179,0.4)]",!r&&s&&"z-10 ring-1 ring-white/70 ring-offset-0 brightness-125 shadow-[0_0_20px_rgba(71,114,179,0.7)]"),style:{left:`${f}px`,width:`${g}px`,top:`${u}px`,height:`${d}px`},triggerProps:{"data-step-index":e.stepIndex,onClick:m=>{m.stopPropagation(),a()},onContextMenu:m=>{m.preventDefault(),m.stopPropagation(),l()}},children:h&&y.jsx("span",{className:"block truncate px-2 text-[12px] font-normal text-[#eee] drop-shadow-sm select-none",style:{lineHeight:`${d}px`},children:e.nodeTypeName})})}function hD({steps:e,timeScale:t,timeOffset:n=0,contentWidth:r,selectedStepIndex:i,currentStepIndex:s,nearestDragStepIndex:a,onStepClick:l,onScrubTo:u}){const d=e.length,f=d>1?(d-1)*Yc:0,g=d>1?Es+(d-1)*(Es-Ts*2)+f:Es,h=g-Ts*2-f,m=d>0?h/d:h;return y.jsx("div",{className:"relative",style:{height:`${g}px`,width:`${r}px`,marginBottom:`${Yc}px`},children:e.map((x,v)=>y.jsx(pD,{step:x,timeScale:t,timeOffset:n,isSelected:i===x.stepIndex,isSnapped:s===x.stepIndex,isNearestDragTarget:a===x.stepIndex,onClick:()=>l(x),onScrubTo:()=>u(x.stepIndex),subRowTop:Ts+v*(m+Yc),subRowHeight:m},`${x.nodeId}-${x.stepIndex}`))})}function Lb({steps:e,timeScale:t,contentWidth:n,selectedStepIndex:r,currentStepIndex:i,nearestDragStepIndex:s,onStepClick:a,onScrubTo:l}){const u=T.useMemo(()=>uD(e),[e]),d=T.useMemo(()=>Array.from(u.keys()).sort((f,g)=>f-g),[u]);return e.length===0?null:y.jsx(y.Fragment,{children:d.map(f=>{const g=u.get(f);return g?y.jsx(hD,{steps:g,timeScale:t,contentWidth:n,selectedStepIndex:r,currentStepIndex:i,nearestDragStepIndex:s,onStepClick:a,onScrubTo:l},`flat-${f}`):null})})}function gD({iterRecord:e,iterDisplay:t,loopRecord:n}){const r=e.iteration===n.totalIterations-1&&e.conditionValue===!0;return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsxs("span",{className:"text-[12px] font-semibold text-primary-white",children:["Loop Iteration ",e.iteration]}),r?y.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-status-errored",children:[y.jsx(ng,{className:"h-2.5 w-2.5"})," max exceeded"]}):e.conditionValue?y.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-status-completed",children:[y.jsx(sa,{className:"h-2.5 w-2.5"})," continues"]}):y.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-secondary-light-gray",children:[y.jsx(aa,{className:"h-2.5 w-2.5"})," exits"]})]}),y.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-secondary-light-gray",children:[y.jsxs("span",{className:"font-mono tabular-nums",children:[e.duration.toFixed(2),"ms"]}),y.jsx("span",{className:"text-secondary-dark-gray",children:"·"}),y.jsxs("span",{children:[t.steps.length," steps"]})]})]})}function mD({segment:e,timeScale:t,contentWidth:n,selectedIteration:r,onSelectIteration:i,selectedStepIndex:s}){const{loopRecord:a,iterations:l}=e,u=a.iterations.length>0&&a.iterations[a.iterations.length-1].conditionValue===!0;return y.jsx("div",{className:"relative",style:{height:`${Es}px`,width:`${n}px`,marginBottom:`${Yc}px`},children:e.adjustedIterations.map((d,f)=>{const g=l[f];if(!g)return null;const h=d.adjustedStartTime*t,m=Math.max(d.adjustedDuration*t,Gf),x=r===d.iteration,v=u&&f===a.iterations.length-1,b=s!==null&&g.steps.some(w=>w.stepIndex===s),S=Es-Ts*2,N=m>Cb&&S>=Ab;return y.jsx(yD,{iterRecord:d,iterDisplay:g,loopRecord:a,left:h,width:m,blockHeight:S,showLabel:N,isSelected:x,isLastAndError:v,hasSelectedStep:b,onSelect:()=>i(d.iteration)},d.iteration)})})}function yD({iterRecord:e,iterDisplay:t,loopRecord:n,left:r,width:i,blockHeight:s,showLabel:a,isSelected:l,isLastAndError:u,hasSelectedStep:d,onSelect:f}){return y.jsx(sn,{as:"div",placement:"top",content:y.jsx(gD,{iterRecord:e,iterDisplay:t,loopRecord:n}),className:ye("absolute cursor-pointer rounded-[2px] bg-[#8c52d1]/60",l&&"z-10 ring-1 ring-[#8c52d1] ring-offset-0 bg-[#8c52d1]/80",!l&&d&&"z-10 ring-1 ring-white/50 ring-offset-0",u&&"border border-status-errored/50"),style:{left:`${r}px`,width:`${i}px`,top:`${Ts}px`,height:`${s}px`},triggerProps:{onClick:g=>{g.stopPropagation(),f()}},children:a?y.jsxs("span",{className:"flex items-center gap-1 truncate px-2 text-[11px] font-normal text-[#eee] drop-shadow-sm select-none",style:{lineHeight:`${s}px`},children:[y.jsx(Qh,{className:"h-2.5 w-2.5 flex-shrink-0"}),"Iter ",e.iteration]}):y.jsx("span",{className:"flex items-center justify-center text-[9px] font-medium text-[#eee] select-none w-full",style:{lineHeight:`${s}px`},children:e.iteration})})}function vD({iteration:e,nestedLoopRecords:t,adjustForPause:n,selectedIterations:r,onSelectIteration:i,timeScale:s,contentWidth:a,selectedStepIndex:l,currentStepIndex:u,nearestDragStepIndex:d,onStepClick:f,onScrubTo:g}){const{steps:h}=e,m=T.useMemo(()=>Rb(h,t,n),[h,t,n]);return m.length===0?y.jsx("div",{className:"py-2 text-center text-[10px] text-secondary-light-gray",children:"No steps in this iteration"}):y.jsx("div",{className:"relative pb-1",style:{minHeight:"40px"},children:y.jsx("div",{className:"relative",style:{width:`${a}px`},children:m.map((x,v)=>{if(x.kind==="flat")return y.jsx(Lb,{steps:x.steps,timeScale:s,contentWidth:a,selectedStepIndex:l,currentStepIndex:u,nearestDragStepIndex:d,onStepClick:f,onScrubTo:g},`iter-${e.iteration}-flat-${v}`);const b=x.loopStructureId,S=r.get(b)??null;return y.jsx(Db,{segment:x,timeScale:s,contentWidth:a,selectedIteration:S,onSelectIteration:N=>{const w=r.get(b);i(b,w===N?null:N)},selectedStepIndex:l,currentStepIndex:u,nearestDragStepIndex:d,onStepClick:f,onScrubTo:g,adjustForPause:n,selectedIterations:r,onNestedSelectIteration:i},`iter-${e.iteration}-loop-${b}`)})})})}function Db({segment:e,timeScale:t,contentWidth:n,selectedIteration:r,onSelectIteration:i,selectedStepIndex:s,currentStepIndex:a,nearestDragStepIndex:l,onStepClick:u,onScrubTo:d,adjustForPause:f,selectedIterations:g,onNestedSelectIteration:h}){const{iterations:m}=e,x=r!==null?m[r]??null:null;return y.jsxs("div",{children:[y.jsx(mD,{segment:e,timeScale:t,contentWidth:n,selectedIteration:r,onSelectIteration:i,selectedStepIndex:s}),x&&y.jsxs("div",{className:"mb-1",children:[y.jsxs("div",{className:"sticky left-0 z-[5] ml-4 flex w-fit items-center gap-2 rounded-t-[3px] border border-b-0 border-[#8c52d1]/30 bg-runner-timeline-box-bg px-2 py-1 text-[10px]",children:[y.jsx(Qh,{className:"h-2.5 w-2.5 text-[#8c52d1]"}),y.jsxs("span",{className:"font-medium text-primary-white",children:["Iteration ",x.iteration]}),y.jsxs("span",{className:"text-secondary-light-gray",children:[x.steps.length," step",x.steps.length!==1?"s":""]}),x.conditionValue?y.jsxs("span",{className:"flex items-center gap-0.5 text-status-completed/70",children:[y.jsx(sa,{className:"h-2.5 w-2.5"})," continues"]}):y.jsxs("span",{className:"flex items-center gap-0.5 text-secondary-light-gray",children:[y.jsx(aa,{className:"h-2.5 w-2.5"})," exits"]})]}),y.jsx("div",{className:"-mt-px rounded-[3px] border border-[#8c52d1]/30 bg-runner-timeline-box-bg/50",children:y.jsx(vD,{iteration:x,nestedLoopRecords:x.nestedLoopRecords,adjustForPause:f,selectedIterations:g,onSelectIteration:h,timeScale:t,contentWidth:n,selectedStepIndex:s,currentStepIndex:a,nearestDragStepIndex:l,onStepClick:u,onScrubTo:d})})]})]})}function xD({timeScale:e,contentWidth:t,totalDuration:n,onScrubDown:r}){const i=Tb/e,s=kb(i),a=[];for(let l=0;l<=n+s;l+=s)a.push(l);return y.jsx("div",{className:"relative border-b border-[#3a3a3a] bg-runner-ruler-bg",style:{height:`${oD}px`,width:`${t}px`},children:y.jsx("div",{className:"relative h-full cursor-ew-resize select-none",onMouseDown:r,children:a.map(l=>{const u=l*e;return u>t?null:y.jsxs("div",{className:"absolute bottom-1 -translate-x-1/2",style:{left:`${u}px`},children:[y.jsx("span",{className:"font-mono text-[11px] tabular-nums text-[#9a9a9a] select-none whitespace-nowrap",children:Mb(l)}),y.jsx("div",{className:"absolute -bottom-1 left-1/2 h-1 w-px bg-[#555]"})]},l)})})})}function wD({timeScale:e,contentWidth:t,totalDuration:n}){const r=Tb/e,i=kb(r),s=[];for(let a=0;a<=n+i;a+=i){const l=a*e;l<=t&&s.push(l)}return y.jsx("div",{className:"pointer-events-none absolute inset-0",children:s.map(a=>y.jsx("div",{className:"absolute top-0 bottom-0 w-px bg-runner-grid-line",style:{left:`${a}px`}},a))})}function bD({timeMs:e,isDragging:t}){return y.jsxs("div",{className:"flex flex-col items-center",children:[y.jsx("div",{className:ye("rounded px-1.5 py-0.5 font-mono text-[11px] text-white whitespace-nowrap",t?"bg-[#6a9be0]":"bg-runner-scrubber-blue"),children:Mb(e)}),y.jsx("div",{className:"h-0 w-0 border-l-[4px] border-r-[4px] border-t-[4px] border-l-transparent border-r-transparent border-t-runner-scrubber-blue"})]})}function jb({record:e,currentStepIndex:t,onScrubTo:n,onStepClick:r,selectedStepIndex:i,onNavigateToNode:s}){const{autoScroll:a,setAutoScroll:l,timeMode:u,setTimeMode:d,timelineCollapsed:f,setTimelineCollapsed:g,selectedIterations:h,setSelectedIterations:m,autoplayIntervalSec:x,setAutoplayIntervalSec:v}=Uf(),b=(e?.totalPauseDuration??0)>0,S=T.useMemo(()=>e?u==="wallClock"?e.steps:e.steps.map(ae=>({...ae,startTime:ae.startTime-ae.pauseAdjustment,endTime:ae.endTime-ae.pauseAdjustment})):[],[e,u]),N=e?u==="execution"?e.totalDuration-e.totalPauseDuration:e.totalDuration:0,w=T.useMemo(()=>e?Rb(S,e.loopRecords,u==="execution"):[],[S,e,u]),I=T.useRef(!1);T.useEffect(()=>{if(I.current||w.length===0)return;const ae=w.find(Ie=>Ie.kind==="loop");ae&&(I.current=!0,m(new Map([[ae.loopStructureId,0]])))},[w]),T.useEffect(()=>{if(i===null||!e)return;const ae=e.steps.find(Ie=>Ie.stepIndex===i);ae?.loopStructureId!==void 0&&ae.loopIteration!==void 0&&m(Ie=>{const Be=new Map(Ie);return Be.set(ae.loopStructureId,ae.loopIteration),Be})},[i,e]);const{timeScale:k,scrollContainerRef:A,fitToView:M,zoomBy:B,handlePanStart:U,didPanMoveRef:q}=tD({adjustedTotalDuration:N,timePadRightMs:Eb,gutterWidth:Ib}),D=N+N*Eb,$=D*k,{scrubberPx:F,isDraggingScrubber:E,nearestDragStepIndex:P,isSnapping:L,handleRulerScrubDown:j,handleScrubberMouseDown:O,onSnapTransitionEnd:W}=rD({steps:S,timeScale:k,contentWidth:$,currentStepIndex:t,scrollContainerRef:A,gutterWidth:Ib,onScrubTo:n}),z=T.useCallback(ae=>{q.current||r(ae)},[r,q]),Y=k>0?F/k:0,J=T.useRef(null),[ie,ee]=T.useState(!1),ce=T.useRef(null),ge=i??t,Q=e!==null&&ge>0,te=e!==null&&ge<e.steps.length-1,ne=T.useCallback(ae=>{const Ie=A.current;if(!Ie||k<=0)return;const Be=S.find(Nt=>Nt.stepIndex===ae.stepIndex),Ue=(Be?Be.startTime:ae.startTime-ae.pauseAdjustment)*k,Ze=Be?Be.endTime-Be.startTime:ae.duration,pt=Math.max(Ze*k,Gf),Cn=Ue+pt/2,cn=Math.max(0,Cn-Ie.clientWidth/2);setTimeout(()=>{const Nt=A.current;if(!Nt)return;let $t=Nt.scrollTop;const ln=Nt.querySelector(`[data-step-index="${ae.stepIndex}"]`);if(ln){const Or=Nt.getBoundingClientRect(),Un=ln.getBoundingClientRect(),fo=Un.top+Un.height/2,po=Or.top+Or.height/2,Pr=fo-po;Math.abs(Pr)>4&&($t=Nt.scrollTop+Pr)}Nt.scrollTo({left:cn,top:$t,behavior:"smooth"})},50)},[A,k,S]),oe=T.useCallback(ae=>{ae.loopStructureId!==void 0&&ae.loopIteration!==void 0&&m(Ie=>{if(Ie.get(ae.loopStructureId)===ae.loopIteration)return Ie;const Be=new Map(Ie);return Be.set(ae.loopStructureId,ae.loopIteration),Be})},[m]),pe=T.useCallback(()=>{if(!e||ge<=0)return;const ae=e.steps[ge-1];ae&&(oe(ae),r(ae),a&&(s?.(ae.nodeId),ne(ae)))},[e,ge,r,s,ne,a,oe]),le=T.useCallback(()=>{if(!e||ge>=e.steps.length-1)return;const ae=e.steps[ge+1];ae&&(oe(ae),r(ae),a&&(s?.(ae.nodeId),ne(ae)))},[e,ge,r,s,ne,a,oe]),ve=T.useCallback(()=>{if(!e||e.steps.length===0)return;ee(!1);const ae=e.steps[0];oe(ae),r(ae),a&&(s?.(ae.nodeId),ne(ae))},[e,r,s,ne,a,oe]),me=T.useCallback(()=>{if(!e||e.steps.length===0)return;ee(!1);const ae=e.steps[e.steps.length-1];oe(ae),r(ae),a&&(s?.(ae.nodeId),ne(ae))},[e,r,s,ne,a,oe]);T.useEffect(()=>{!ie||!e||ge>=e.steps.length-1&&ee(!1)},[ie,ge,e]),T.useEffect(()=>{if(ie&&e)return ce.current=setInterval(()=>{le()},x*1e3),()=>{ce.current&&clearInterval(ce.current)};ce.current&&(clearInterval(ce.current),ce.current=null)},[ie,x,e,le]);const Oe=T.useCallback(()=>{ee(ae=>!ae)},[]),Ce=T.useRef(t);return T.useEffect(()=>{if(Ce.current===t||(Ce.current=t,!a||!e||i!==null||E))return;const ae=e.steps[t];ae&&(oe(ae),s?.(ae.nodeId),ne(ae))},[t,a,e,i,E,oe,s,ne]),e?y.jsxs("div",{className:"flex h-full flex-col bg-runner-toolbar-bg",children:[y.jsxs("div",{className:"flex h-12 items-center justify-between px-4",children:[y.jsxs("div",{className:"flex items-center gap-3",children:[y.jsxs("button",{type:"button",onClick:()=>g(!f),className:"btn-press flex items-center gap-2 rounded px-1.5 py-1 text-[14px] text-primary-white transition-colors hover:bg-primary-dark-gray/50",children:[y.jsx("span",{className:ye("transition-transform duration-150",!f&&"rotate-90"),children:y.jsx(zr,{className:"h-3 w-3 text-secondary-light-gray"})}),"Timeline"]}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsxs("div",{className:"flex items-center",children:[y.jsx("button",{type:"button",disabled:!Q,onClick:ve,className:ye("btn-press rounded-l-md border border-secondary-dark-gray/80 px-1 py-0.5 transition-colors",Q?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:"Go to first step",children:y.jsx(O_,{className:"h-3.5 w-3.5"})}),y.jsx("button",{type:"button",disabled:!Q,onClick:pe,className:ye("btn-press border border-l-0 border-secondary-dark-gray/80 px-1 py-0.5 transition-colors",Q?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:"Previous step",children:y.jsx(iu,{className:"h-3.5 w-3.5"})}),y.jsx("button",{type:"button",disabled:!e||e.steps.length===0,onClick:Oe,className:ye("btn-press border border-l-0 border-secondary-dark-gray/80 px-1.5 py-0.5 transition-colors",ie?"bg-primary-blue text-white hover:bg-primary-blue/80":e&&e.steps.length>0?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:ie?"Stop autoplay":"Autoplay",children:ie?y.jsx(tg,{className:"h-3 w-3"}):y.jsx(au,{className:"h-3.5 w-3.5"})}),y.jsx("button",{type:"button",disabled:!te,onClick:le,className:ye("btn-press border border-l-0 border-secondary-dark-gray/80 px-1 py-0.5 transition-colors",te?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:"Next step",children:y.jsx(zr,{className:"h-3.5 w-3.5"})}),y.jsx("button",{type:"button",disabled:!te,onClick:me,className:ye("btn-press rounded-r-md border border-l-0 border-secondary-dark-gray/80 px-1 py-0.5 transition-colors",te?"bg-primary-dark-gray text-primary-white hover:bg-primary-blue/80":"bg-secondary-black text-secondary-dark-gray pointer-events-none"),title:"Go to last step",children:y.jsx(P_,{className:"h-3.5 w-3.5"})})]}),y.jsx(sn,{content:"Seconds between each step during autoplay. Drag or click to adjust (0.5s–30s).",children:y.jsx(ni,{name:"Interval",value:x,onChange:ae=>v(Math.max(.5,ae)),min:.5,max:30,size:"small"})}),y.jsx(sn,{content:"Automatically scroll the timeline and canvas to follow the selected step",children:y.jsxs("label",{className:"flex cursor-pointer items-center gap-1 text-[12px] text-secondary-light-gray select-none",children:[y.jsx("input",{type:"checkbox",checked:a,onChange:ae=>l(ae.target.checked),className:"h-3 w-3 cursor-pointer rounded-sm accent-primary-blue"}),y.jsx("span",{className:"text-primary-white",children:"Auto-scroll"})]})})]})]}),y.jsxs("div",{className:"flex items-center gap-3",children:[b&&y.jsx(sn,{content:y.jsxs("div",{className:"space-y-1.5 text-[12px] leading-relaxed text-primary-white",children:[y.jsxs("div",{children:[y.jsx("span",{className:"font-semibold",children:"Execution"})," — Shows only computation time with pauses removed. Best for step-by-step mode."]}),y.jsxs("div",{children:[y.jsx("span",{className:"font-semibold",children:"Wall Clock"})," — Shows real elapsed time including pauses between steps."]})]}),children:y.jsx(zf,{options:iD,value:u,onChange:d,size:"small"})}),y.jsxs("div",{className:"flex items-center gap-2 font-mono text-[12px] text-primary-white",children:[y.jsx(sn,{content:"Total execution duration",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(F_,{className:"h-3.5 w-3.5"}),y.jsxs("span",{className:"tabular-nums",children:[N.toFixed(2),"ms"]})]})}),y.jsx("span",{children:"·"}),y.jsx(sn,{content:"Total number of executed steps",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(D_,{className:"h-3.5 w-3.5"}),y.jsxs("span",{children:[e.steps.length," steps"]})]})}),e.compilationDuration>0&&y.jsxs(y.Fragment,{children:[y.jsx("span",{children:"·"}),y.jsx(sn,{content:"JIT warmup time — absorbed before execution to ensure accurate step timings",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(z_,{className:"h-3.5 w-3.5"}),y.jsxs("span",{children:["JIT ",e.compilationDuration.toFixed(1),"ms"]})]})})]})]}),y.jsx("button",{type:"button",onClick:()=>B(1.5),className:"btn-press text-primary-white transition-colors hover:text-primary-blue",title:"Zoom In",children:y.jsx(U_,{className:"h-4 w-4"})}),y.jsx("button",{type:"button",onClick:()=>B(1/1.5),className:"btn-press text-primary-white transition-colors hover:text-primary-blue",title:"Zoom Out",children:y.jsx(W_,{className:"h-4 w-4"})}),y.jsx("button",{type:"button",onClick:M,className:"btn-press text-primary-white transition-colors hover:text-primary-blue",title:"Fit to View",children:y.jsx(j_,{className:"h-4 w-4"})})]})]}),!f&&y.jsx("div",{className:"min-h-0 flex-1 px-4 pb-4",children:y.jsx("div",{className:"flex h-full flex-col overflow-hidden rounded-md border border-runner-timeline-box-border bg-runner-timeline-box-bg",children:y.jsx("div",{ref:A,className:"timeline-scrollbar min-h-0 flex-1 overflow-x-auto overflow-y-auto",onMouseDown:U,children:y.jsxs("div",{className:"relative flex min-h-full flex-col",style:{minWidth:`${$}px`},children:[y.jsxs("div",{className:"sticky top-0 z-20",children:[y.jsx(xD,{timeScale:k,contentWidth:$,totalDuration:D,onScrubDown:j}),y.jsx("div",{className:"pointer-events-none absolute inset-y-0",style:{left:`${F}px`,transition:L?"left 150ms ease-out":"none"},children:y.jsx("div",{className:"pointer-events-auto absolute left-1/2 -translate-x-1/2 cursor-ew-resize",style:{top:"2px"},onMouseDown:O,children:y.jsx(bD,{timeMs:Y,isDragging:E})})})]}),y.jsxs("div",{ref:J,className:"relative",style:{minHeight:"120px"},children:[y.jsx(wD,{timeScale:k,contentWidth:$,totalDuration:D}),y.jsx("div",{className:"pt-3",children:w.map((ae,Ie)=>{if(ae.kind==="flat")return y.jsx(Lb,{steps:ae.steps,timeScale:k,contentWidth:$,selectedStepIndex:i,currentStepIndex:t,nearestDragStepIndex:P,onStepClick:z,onScrubTo:n},`flat-${Ie}`);const Be=ae.loopStructureId,Qe=h.get(Be)??null;return y.jsx(Db,{segment:ae,timeScale:k,contentWidth:$,selectedIteration:Qe,onSelectIteration:Ue=>{m(Ze=>{const pt=new Map(Ze);return Ze.get(Be)===Ue?pt.delete(Be):pt.set(Be,Ue),pt})},selectedStepIndex:i,currentStepIndex:t,nearestDragStepIndex:P,onStepClick:z,onScrubTo:n,adjustForPause:u==="execution",selectedIterations:h,onNestedSelectIteration:(Ue,Ze)=>{m(pt=>{const Cn=new Map(pt);return Ze===null?Cn.delete(Ue):Cn.set(Ue,Ze),Cn})}},`loop-${Be}`)})})]}),y.jsxs("div",{className:"pointer-events-none absolute inset-y-0 z-[15]",style:{left:`${F}px`,transition:L?"left 150ms ease-out":"none"},onTransitionEnd:W,children:[y.jsx("div",{className:"pointer-events-auto absolute left-1/2 top-0 bottom-0 w-0.5 -translate-x-1/2 cursor-ew-resize",onMouseDown:O}),y.jsx("div",{className:"pointer-events-none absolute left-1/2 top-0 bottom-0 w-px -translate-x-1/2",style:{backgroundColor:E?"rgba(74, 133, 255, 0.7)":"rgba(74, 133, 255, 0.5)"}})]})]})})})})]}):y.jsxs("div",{className:"flex h-full flex-col bg-runner-toolbar-bg",children:[y.jsx("div",{className:"flex h-12 items-center justify-between bg-runner-toolbar-bg px-4",children:y.jsxs("div",{className:"flex items-center gap-2 text-[14px] text-primary-white",children:[y.jsx(zr,{className:"h-3 w-3 text-secondary-light-gray"}),"Timeline"]})}),y.jsx("div",{className:"flex-1 p-4 pt-0",children:y.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 rounded-md border border-runner-timeline-box-border bg-runner-timeline-box-bg",children:[y.jsxs("div",{className:"flex items-center gap-1.5",children:[y.jsx("div",{className:"h-1.5 w-6 rounded-full bg-secondary-dark-gray"}),y.jsx("div",{className:"h-1.5 w-10 rounded-full bg-secondary-dark-gray"}),y.jsx("div",{className:"h-1.5 w-4 rounded-full bg-secondary-dark-gray"})]}),y.jsx("span",{className:"text-[11px] text-secondary-light-gray",children:"No execution record to display"})]})})]})}function SD(e){return e===void 0?"undefined":e===null?"null":typeof e=="boolean"?"boolean":typeof e=="number"?"number":typeof e=="string"?"string":e instanceof Map?`Map(${e.size})`:Array.isArray(e)?`Array(${e.length})`:typeof e=="function"?"function":`Object(${Object.keys(e).length})`}function _D(e){if(e==null)return!1;const t=typeof e;return t==="object"||t==="function"}function Cs(e,t){if(t&&_D(e))return SD(e);if(e===void 0)return"undefined";if(e===null)return"null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number")return String(e);if(typeof e=="string")return`"${e}"`;if(e instanceof Map)return`Map { ${Array.from(e.entries()).map(([r,i])=>`${String(r)}: ${Cs(i,t)}`).join(", ")} }`;if(Array.isArray(e))return`[${e.map(n=>Cs(n,t)).join(", ")}]`;try{return JSON.stringify(e,null,2)}catch{return String(e)}}const ND={completed:{bg:"bg-runner-bar-completed",text:"text-[#e0f0e0]",label:"Completed"},errored:{bg:"bg-runner-bar-errored",text:"text-[#f0e0e0]",label:"Error"},skipped:{bg:"bg-[#888888]/30",text:"text-[#888888]",label:"Skipped"}};function ID({status:e}){const t=ND[e];return y.jsx("span",{className:ye("rounded-full px-3 py-1 text-[13px] font-medium",t.bg,t.text),children:t.label})}function ED({conn:e,hideComplex:t,debugMode:n}){return y.jsxs("div",{className:"flex flex-col gap-1.5",children:[y.jsxs("div",{className:"text-[13px]",children:[y.jsx("span",{className:"text-[#9a9a9a]",children:"Coming From–"})," ",y.jsxs("span",{className:"text-primary-white/80",children:[e.sourceNodeName," / ",e.sourceHandleName]})]}),n&&y.jsxs("div",{className:"text-[9px] text-secondary-dark-gray",children:["nodeId: ",e.sourceNodeId," · handleId: ",e.sourceHandleId]}),y.jsx("div",{className:"rounded-md border border-runner-value-border bg-runner-value-bg px-3 py-2 font-mono text-[14px] text-primary-white",children:Cs(e.value,t)})]})}function TD({handleName:e,handleValue:t,hideComplex:n,debugMode:r}){return y.jsxs("div",{className:"flex flex-col gap-1.5",children:[y.jsxs("div",{className:"text-[14px] text-primary-white",children:[e," ",y.jsxs("span",{className:"text-secondary-light-gray",children:["(",t.dataTypeId,")"]})]}),t.connections.length>0?t.connections.map((i,s)=>y.jsx(ED,{conn:i,hideComplex:n,debugMode:r},`${i.sourceNodeId}-${i.sourceHandleId}-${s}`)):t.isDefault?y.jsx("div",{className:"rounded-md border border-runner-value-border bg-runner-value-bg px-3 py-2 font-mono text-[14px] text-primary-white",children:Cs(t.defaultValue,n)}):y.jsx("span",{className:"text-[13px] italic text-secondary-light-gray",children:"No value"})]})}function CD({handleName:e,handleValue:t,hideComplex:n}){return y.jsxs("div",{className:"flex flex-col gap-1.5",children:[y.jsxs("div",{className:"text-[14px] text-primary-white",children:[e," ",y.jsxs("span",{className:"text-secondary-light-gray",children:["(",t.dataTypeId,")"]})]}),y.jsx("div",{className:"rounded-md border border-runner-value-border bg-runner-value-bg px-3 py-2 font-mono text-[14px] text-primary-white",children:Cs(t.value,n)})]})}function $b({stepRecord:e,onClose:t,loopRecords:n,hideComplexValues:r=!1,debugMode:i=!1,edgeValuesAnimated:s,onEdgeValuesAnimatedChange:a}){if(!e)return null;const l=Array.from(e.inputValues.entries()),u=Array.from(e.outputValues.entries());return y.jsxs("div",{className:"flex w-[340px] animate-slide-in-right flex-col bg-runner-panel-bg",children:[y.jsxs("div",{className:"flex items-center justify-between border-b border-secondary-dark-gray px-4 py-3",children:[y.jsxs("div",{className:"flex items-center gap-2.5",children:[y.jsx($_,{className:"h-5 w-5 text-primary-white"}),y.jsx("span",{className:"text-[15px] tracking-wide text-primary-white",children:e.nodeTypeName})]}),y.jsxs("div",{className:"flex items-center gap-3",children:[a&&y.jsx(sn,{content:"Animate edge value badges along the connection path instead of showing them statically",children:y.jsxs("label",{className:"flex cursor-pointer items-center gap-1.5 text-[12px] text-secondary-light-gray select-none",children:[y.jsx("input",{type:"checkbox",checked:s??!0,onChange:d=>a(d.target.checked),className:"h-3 w-3 accent-primary-blue"}),y.jsx("span",{className:"text-primary-white",children:"Animate"})]})}),y.jsx("button",{type:"button",onClick:t,className:"btn-press rounded p-1 text-secondary-light-gray transition-colors hover:text-primary-white","aria-label":"Close",children:y.jsx(aa,{className:"h-3.5 w-3.5"})})]})]}),y.jsxs("div",{className:"flex flex-col gap-3 border-b border-secondary-dark-gray px-4 py-3.5",children:[y.jsxs("div",{className:"flex items-center justify-between rounded-md border border-runner-value-border px-3 py-2",children:[y.jsx(ID,{status:e.status}),y.jsx("span",{className:"font-mono text-[13px] text-secondary-light-gray",children:e.estimatedTiming?"< 0.1ms":`${e.duration.toFixed(2)}ms`})]}),y.jsxs("div",{className:"rounded-md border border-runner-value-border bg-runner-timeline-box-bg px-3 py-2.5",children:[y.jsxs("div",{className:"text-center text-[13px] text-secondary-light-gray",children:[e.startTime.toFixed(2),"ms"," ",y.jsx("span",{className:"text-secondary-dark-gray",children:"→"})," ",e.endTime.toFixed(2),"ms"]}),y.jsxs("div",{className:"relative mt-2 h-1.5 w-full overflow-hidden rounded-full bg-[#333]",children:[y.jsx("div",{className:"absolute h-full rounded-full bg-secondary-light-gray/50",style:{left:"20%",width:"55%"}}),y.jsx("div",{className:"absolute h-full w-0.5 bg-secondary-light-gray",style:{left:"77%"}})]})]}),(e.loopIteration!==void 0||e.groupNodeId)&&y.jsxs("div",{className:"flex flex-col gap-2",children:[e.loopIteration!==void 0&&(()=>{const d=e.loopStructureId&&n?n.get(e.loopStructureId):void 0,f=d?.iterations[e.loopIteration];return y.jsxs("div",{className:"rounded-md border border-runner-value-border px-3 py-2",children:[y.jsxs("div",{className:"text-[12px] text-primary-white",children:["Loop iteration ",e.loopIteration+1,d?` of ${d.totalIterations}`:""]}),f&&y.jsxs("div",{className:"mt-1 text-[10px] text-secondary-light-gray",children:["Condition:"," ",f.conditionValue?"true (continues)":"false (exits)"]})]})})(),e.groupNodeId&&y.jsxs("div",{className:"text-[11px] text-secondary-light-gray",children:["Group: ",e.groupNodeId,e.groupDepth!==void 0&&` (depth ${e.groupDepth})`]})]}),i&&y.jsxs("div",{className:"text-[9px] text-secondary-dark-gray",children:["nodeId: ",e.nodeId," · typeId: ",e.nodeTypeId]})]}),y.jsxs(Fy,{type:"multiple",defaultValue:["inputs","outputs"],className:"w-full",children:[y.jsxs(nd,{value:"inputs",className:"border-b border-secondary-dark-gray",children:[y.jsx(rd,{className:"gap-1.5 border-b border-secondary-dark-gray bg-runner-section-header-bg px-4 py-2.5 text-[14px] text-primary-white hover:no-underline [&>svg]:text-secondary-light-gray",children:"Inputs"}),y.jsx(od,{className:"p-4",children:y.jsx("div",{className:"flex flex-col gap-4 bg-runner-panel-bg",children:l.length>0?l.map(([d,f],g)=>y.jsxs("div",{children:[g>0&&y.jsx("div",{className:"-mx-4 mb-4 h-px bg-secondary-dark-gray"}),y.jsx(TD,{handleName:d,handleValue:f,hideComplex:r,debugMode:i})]},d)):y.jsx("div",{className:"text-[13px] italic text-secondary-light-gray",children:"No inputs"})})})]}),y.jsxs(nd,{value:"outputs",className:"border-b border-secondary-dark-gray",children:[y.jsx(rd,{className:"gap-1.5 border-b border-secondary-dark-gray bg-runner-section-header-bg px-4 py-2.5 text-[14px] text-primary-white hover:no-underline [&>svg]:text-secondary-light-gray",children:"Outputs"}),y.jsx(od,{className:"p-4",children:y.jsx("div",{className:"flex flex-col gap-4 bg-runner-panel-bg",children:u.length>0?u.map(([d,f],g)=>y.jsxs("div",{children:[g>0&&y.jsx("div",{className:"-mx-4 mb-4 h-px bg-secondary-dark-gray"}),y.jsx(CD,{handleName:d,handleValue:f,hideComplex:r})]},d)):y.jsx("div",{className:"text-[13px] italic text-secondary-light-gray",children:"No outputs"})})})]})]}),e.error&&y.jsx("div",{className:"p-4",children:y.jsxs("div",{className:"rounded-md border border-status-errored/30 bg-status-errored/10 p-2.5",children:[y.jsx("div",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-status-errored",children:"Error"}),y.jsx("div",{className:"whitespace-pre-wrap font-mono text-[11px] text-status-errored",children:ib(e.error)})]})})]})}const Hb=({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:s})=>{const{fromHandle:a}=V0(),l=of(a?.nodeId||""),u=T.useMemo(()=>!a?.id||!l?.data?void 0:on(a?.id,l?.data)?.value?.handleColor??"#A1A1A1",[a?.id,l?.data]),[d]=bc({sourceX:e,sourceY:t,sourcePosition:i,targetX:n,targetY:r,targetPosition:s});return y.jsx(Jo,{path:d,className:"stroke-7! in-[g.selected]:brightness-150",style:{stroke:u||"#A1A1A1"},focusable:!0})};Hb.displayName="ConfigurableConnection";const AD=150,kD=({isOpen:e,position:t,onClose:n,items:r})=>{const[i,s]=T.useState(!1),a=T.useRef(null);T.useEffect(()=>(a.current&&(clearTimeout(a.current),a.current=null),e?s(!0):i&&(a.current=setTimeout(()=>s(!1),AD)),()=>{a.current&&clearTimeout(a.current)}),[e]);const{refs:l,floatingStyles:u,context:d}=Wc({open:e,onOpenChange:h=>{h||n()},placement:"bottom-start",middleware:[Oi(5),Ri({fallbackPlacements:["top-start"]}),Pi({padding:8})],whileElementsMounted:Mi}),f=eb(d),{getFloatingProps:g}=tb([f]);return T.useEffect(()=>{e&&l.setReference({getBoundingClientRect:()=>({x:t.x,y:t.y,width:1,height:1,top:t.y,right:t.x+1,bottom:t.y+1,left:t.x})})},[e,t,l]),i?y.jsx("div",{ref:l.setFloating,style:{...u,contain:"layout"},className:ye("z-50 transition-opacity ease-out",e?"opacity-100 duration-100":"opacity-0 duration-150"),onClick:h=>h.stopPropagation(),...g(),children:y.jsx(pb,{subItems:r})}):null};function MD({onExportState:e,onImportState:t,onExportRecording:n,onImportRecording:r,closeMenu:i}){return[{id:"import-export",label:"Import/Export",icon:T.createElement(k_,{className:"w-4 h-4"}),separator:!0,subItems:[{id:"export-state",label:"Export State",icon:T.createElement(Zh,{className:"w-4 h-4"}),onClick:()=>{e(),i()}},{id:"import-state",label:"Import State",icon:T.createElement(Kh,{className:"w-4 h-4"}),onClick:()=>{t(),i()}},{id:"export-recording",label:"Export Recording",icon:T.createElement(Zh,{className:"w-4 h-4"}),separator:!0,onClick:()=>{n(),i()}},{id:"import-recording",label:"Import Recording",icon:T.createElement(Kh,{className:"w-4 h-4"}),onClick:()=>{r(),i()}}]}]}const Bb="add-new-node-group"+rn(10),OD=({value:e,setValue:t,nodeGroups:n,handleAddNewGroup:r,enableBackButton:i,handleBack:s,openedNodeGroupStack:a})=>{const l=u=>{if(u===Bb){r?.();return}t(u)};return y.jsxs("div",{className:"absolute top-0 left-0 scale-75 origin-top-left flex items-center gap-3 m-2 max-w-full",children:[y.jsx(Qn,{className:"h-[44px] border-secondary-dark-gray bg-primary-black shrink-0",disabled:!i,onClick:s,children:y.jsx(M_,{})}),y.jsxs(yb,{value:e,onValueChange:l,children:[y.jsx($f,{className:"hover:bg-primary-dark-gray shrink-0 w-fit",children:y.jsx(Ff,{placeholder:"Node Group"})}),y.jsxs(Vf,{className:"scale-75 origin-top-left",children:[y.jsx(qc,{value:Bb,className:"pl-2",children:y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(Jh,{}),y.jsx("p",{className:"truncate",children:"Add New Node Group"})]})}),n.map(u=>y.jsx(qc,{value:u.id,children:u.name},u.id))]})]}),y.jsx(Rf,{orientation:"horizontal",className:"relative flex-1 min-w-0",scrollAreaClassName:"text-[27px] leading-[27px] font-main whitespace-nowrap text-primary-white flex gap-2 items-center overflow-x-scroll no-scrollbar overflow-y-hidden",children:a.map((u,d)=>y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("div",{children:u.name}),d<a.length-1&&y.jsx(zr,{className:"shrink-0"})]},u.id))})]})},PD={configurableNode:rp},RD={configurableEdge:_f};function Vb(e,t,n){if(e.length===0)return[];const r=new Map;for(const l of e){const u=n.get(l);r.set(l,u?u.size:0)}let i=[];for(const l of e)r.get(l)===0&&i.push(l);const s=[];let a=0;for(;i.length>0;){const l=i;s.push(l),a+=l.length;const u=[];for(const d of l){const f=t.get(d);if(f)for(const g of f){if(!r.has(g))continue;const h=(r.get(g)??0)-1;r.set(g,h),h===0&&u.push(g)}}i=u}if(a<e.length){const l=new Set;for(const d of s)for(const f of d)l.add(f);const u=e.filter(d=>!l.has(d));u.length>0&&s.push(u)}return s}const Fb=20;function zb(e){const t=[];if(!e)return t;for(const n of e)if("inputs"in n&&n.inputs)for(const r of n.inputs)r.id&&t.push(r.id);else n.id&&t.push(n.id);return t}function Ub(e){const t=[];if(!e)return t;for(const n of e)n.id&&t.push(n.id);return t}function Wb(e,t,n,r,i,s=0){if(s>=Fb)return{groupScopes:[],groupNodeIds:new Set,warnings:[`Maximum group nesting depth (${Fb}) exceeded. Possible recursive group.`]};const a=[],l=new Set,u=[];for(const d of t){const f=d.data.nodeTypeUniqueId;if(!f)continue;const g=e.typeOfNodes[f];if(!g?.subtree)continue;l.add(d.id);const h=g.subtree;for(const w of h.nodes){const I=w.data.nodeTypeUniqueId;if(!I)continue;const k=e.typeOfNodes[I];if(!ri(I)&&(!kr(n,I)||!n[I])){const A=k?.name??I,M=g.name;u.push(`Node type "${A}" inside group "${M}" has no function implementation.`)}}const m={...e,nodes:h.nodes,edges:h.edges,openedNodeGroupStack:void 0},x=i(m,n,{maxLoopIterations:r},s+1);for(const w of x.warnings)u.push(`[Group "${g.name}"] ${w}`);const v=new Map,b=new Map,S=h.nodes.find(w=>w.data.nodeTypeUniqueId===Te.groupInput),N=h.nodes.find(w=>w.data.nodeTypeUniqueId===Te.groupOutput);if(S){const w=zb(d.data.inputs),I=Ub(S.data.outputs),k=Math.min(w.length,I.length);for(let A=0;A<k;A++)v.set(w[A],I[A])}if(N){const w=zb(N.data.inputs),I=Ub(d.data.outputs),k=Math.min(w.length,I.length);for(let A=0;A<k;A++)b.set(w[A],I[A])}a.push({kind:"group",groupNodeId:d.id,groupNodeTypeId:f,groupNodeTypeName:g.name,innerPlan:x,inputMapping:v,outputMapping:b,concurrencyLevel:0})}return{groupScopes:a,groupNodeIds:l,warnings:u}}function ri(e){return e===Te.loopStart||e===Te.loopStop||e===Te.loopEnd||e===Te.groupInput||e===Te.groupOutput}function Gb(e){return e===Te.groupInput||e===Te.groupOutput}function kr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function LD(e,t,n,r,i,s,a=0){const l=t.filter(v=>v.data.nodeTypeUniqueId===Te.loopStart),u=[];for(const v of l){const b=ei(e,v);if(!b)continue;const{loopStart:S,loopStop:N,loopEnd:w}=b,{nodesInRegionStartToStop:I,nodesInRegionStopToEnd:k}=ff(e,b),A=new Set([...I,...k]);u.push({loopStartId:S.id,loopStopId:N.id,loopEndId:w.id,bodyNodeIds:I,postStopBodyNodeIds:k,allBodyNodeIds:A})}const d=new Set;for(const v of u)for(const b of u)v!==b&&b.allBodyNodeIds.has(v.loopStartId)&&d.add(v.loopStartId);const f=new Map;for(const v of u)f.set(v.loopStartId,v);function g(v,b,S,N){const w=new Set(b.map(E=>E.loopStartId)),I=new Map;for(const E of b){const P=E.loopStartId;I.set(E.loopStartId,P),I.set(E.loopStopId,P),I.set(E.loopEndId,P);for(const L of E.allBodyNodeIds)I.set(L,P)}const k=[...Array.from(v).filter(E=>!N.has(E)),...w];if(k.length===0)return[];const A=new Set(k),M=new Map,B=new Map;for(const E of k)M.set(E,new Set),B.set(E,new Set);for(const E of n){if(qf(E,t))continue;let P=E.source,L=E.target;const j=I.get(P);j&&(P=j);const O=I.get(L);O&&(L=O),P!==L&&A.has(P)&&A.has(L)&&(M.get(P)?.add(L),B.get(L)?.add(P))}const U=Vb(k,M,B),q=k.filter(E=>!w.has(E)).map(E=>t.find(P=>P.id===E)).filter(E=>E!=null),{groupScopes:D}=Wb(e,q,i,r,s,a+1),$=new Map(D.map(E=>[E.groupNodeId,E])),F=[];for(let E=0;E<U.length;E++){const P=U[E];for(const L of P){if(w.has(L)){const Y=S.get(L);Y&&F.push({...Y,concurrencyLevel:E});continue}const j=t.find(Y=>Y.id===L);if(!j)continue;const O=j.data.nodeTypeUniqueId;if(!O||Gb(O))continue;const W=$.get(L);if(W){F.push({...W,concurrencyLevel:E});continue}const z=e.typeOfNodes[O];F.push({kind:"standard",nodeId:L,nodeTypeId:O,nodeTypeName:z?.name??O,concurrencyLevel:E})}}return F}function h(v){const{loopStartId:b,loopStopId:S,loopEndId:N,bodyNodeIds:w,postStopBodyNodeIds:I,allBodyNodeIds:k}=v,A=[],M=new Set;for(const F of u)if(F!==v&&k.has(F.loopStartId)){A.push(F),M.add(F.loopStartId),M.add(F.loopStopId),M.add(F.loopEndId);for(const E of F.allBodyNodeIds)M.add(E)}const B=new Map;for(const F of A)B.set(F.loopStartId,h(F));const U=A.filter(F=>w.has(F.loopStartId)),q=A.filter(F=>I.has(F.loopStartId)),D=g(w,U,B,M),$=g(I,q,B,M);return{kind:"loop",loopStartNodeId:b,loopStopNodeId:S,loopEndNodeId:N,preStopSteps:D,postStopSteps:$,maxIterations:r,concurrencyLevel:0}}const m=[],x=new Set;for(const v of u)if(!d.has(v.loopStartId)){m.push(h(v)),x.add(v.loopStartId),x.add(v.loopStopId),x.add(v.loopEndId);for(const b of v.allBodyNodeIds)x.add(b)}return{loopBlocks:m,loopNodeIds:x}}function qf(e,t){if(!e.sourceHandle)return!1;const n=t.find(g=>g.id===e.source);if(!n)return!1;const r=n.data.nodeTypeUniqueId;if(!r||!Tt(r))return!1;const i=e.sourceHandle,s=n.data.outputs;if(!s)return!1;for(const g of s)if("id"in g&&g.id===i&&g.dataType?.dataTypeUniqueId===ze.bindLoopNodes)return!0;const a=t.find(g=>g.id===e.target);if(!a)return!1;const l=a.data.nodeTypeUniqueId;if(!l||!Tt(l))return!1;const u=e.targetHandle;if(!u)return!1;const d=a.data.inputs;if(!d)return!1;const f=d.flatMap(g=>"inputs"in g?g.inputs:[g]);for(const g of f)if("id"in g&&g.id===u&&g.dataType?.dataTypeUniqueId===ze.bindLoopNodes)return!0;return!1}const qb=100;function Yf(e,t,n,r){const i=n?.maxLoopIterations??qb,s=[],{nodes:a,edges:l}=Mt(e);if(a.length===0)return{levels:[],inputResolutionMap:new Map,outputDistributionMap:new Map,nodeCount:0,warnings:[]};const u=new Map,d=new Map;for(const D of l){const $=D.sourceHandle,F=D.targetHandle;if(!$||!F||qf(D,a))continue;const E=`${D.target}:${F}`;let P=u.get(E);P||(P=[],u.set(E,P)),P.push({edgeId:D.id,sourceNodeId:D.source,sourceHandleId:$});const L=`${D.source}:${$}`;let j=d.get(L);j||(j=[],d.set(L,j)),j.push({edgeId:D.id,targetNodeId:D.target,targetHandleId:F})}for(const D of a){const $=D.data.nodeTypeUniqueId;if(!$||Tt($)||ri($))continue;const F=e.typeOfNodes[$];if(!F?.subtree&&(!kr(t,$)||!t[$])){const E=F?.name??$;s.push(`Node type "${E}" (${$}) has no function implementation.`)}}const{loopBlocks:f,loopNodeIds:g}=LD(e,a,l,i,t,Yf,r??0),{groupScopes:h,groupNodeIds:m,warnings:x}=Wb(e,a,t,i,Yf,r??0);for(const D of x)s.push(D);const v=new Map(h.map(D=>[D.groupNodeId,D])),b=new Map(f.map(D=>[D.loopStartNodeId,D])),S=new Set;for(const D of a){const $=D.data.nodeTypeUniqueId;$&&Gb($)&&S.add(D.id)}const N=new Map;for(const D of f){const $=D.loopStartNodeId;N.set(D.loopStartNodeId,$),N.set(D.loopStopNodeId,$),N.set(D.loopEndNodeId,$);for(const F of[...D.preStopSteps,...D.postStopSteps])F.kind==="standard"&&N.set(F.nodeId,$)}const w=new Set(f.map(D=>D.loopStartNodeId)),I=[...a.map(D=>D.id).filter(D=>!g.has(D)&&!S.has(D)),...w],k=new Set(I),A=new Map,M=new Map;for(const D of I)A.set(D,new Set),M.set(D,new Set);for(const D of l){if(!D.sourceHandle||!D.targetHandle||qf(D,a))continue;let $=D.source,F=D.target;const E=N.get($);E&&($=E);const P=N.get(F);P&&(F=P),$!==F&&k.has($)&&k.has(F)&&(A.get($)?.add(F),M.get(F)?.add($))}const B=Vb(I,A,M),U=[];for(let D=0;D<B.length;D++){const $=B[D],F=[];for(const E of $){if(w.has(E)){const W=b.get(E);W&&F.push({...W,concurrencyLevel:D});continue}const P=v.get(E);if(P){F.push({...P,concurrencyLevel:D});continue}const L=a.find(W=>W.id===E);if(!L)continue;const j=L.data.nodeTypeUniqueId;if(!j)continue;const O=e.typeOfNodes[j];F.push({kind:"standard",nodeId:E,nodeTypeId:j,nodeTypeName:O?.name??j,concurrencyLevel:D})}F.length>0&&U.push(F)}let q=0;for(const D of U)for(const $ of D)$.kind==="standard"?q++:$.kind==="loop"?q+=3+$.preStopSteps.length+$.postStopSteps.length:$.kind==="group"&&(q+=1+$.innerPlan.nodeCount);return{levels:U,inputResolutionMap:u,outputDistributionMap:d,nodeCount:q,warnings:s}}function Tn(e,t){return`${e}:${t}`}function Xc(e){const t=[];if(!e)return t;for(const n of e)if("inputs"in n)for(const r of n.inputs)t.push(r);else t.push(n);return t}class Kc{store;prefix;parent;constructor(t="",n=null){this.store=new Map,this.prefix=t,this.parent=n}set(t,n,r){this.store.set(this.prefix+Tn(t,n),r)}get(t,n){const r=this.prefix+Tn(t,n);if(this.store.has(r))return this.store.get(r);if(this.parent)return this.parent.get(t,n)}has(t,n){const r=this.prefix+Tn(t,n);return this.store.has(r)?!0:this.parent?this.parent.has(t,n):!1}resolveInputs(t,n,r,i){const s=new Map,a=Xc(n.inputs);for(const l of a){if(!l.id||!l.name)continue;const u=l.id,d=l.name,f=l.inferredDataType?.dataTypeUniqueId??l.dataType?.dataTypeUniqueId??"",g=Tn(t,u),h=r.get(g);if(h&&h.length>0){const m=[];for(const x of h){const v=i.get(x.sourceNodeId),S=(v?.data.outputs??[]).find(N=>N.id===x.sourceHandleId);m.push({value:this.get(x.sourceNodeId,x.sourceHandleId),sourceNodeId:x.sourceNodeId,sourceNodeName:v?.typeOfNode?.name??"",sourceNodeTypeId:v?.data.nodeTypeUniqueId??"",sourceHandleId:x.sourceHandleId,sourceHandleName:S?.name??"",sourceDataTypeId:S?.inferredDataType?.dataTypeUniqueId??S?.dataType?.dataTypeUniqueId??"",edgeId:x.edgeId})}s.set(d,{connections:m,handleId:u,handleName:d,dataTypeId:f,isDefault:!1})}else l.allowInput&&l.value!==void 0?s.set(d,{connections:[],handleId:u,handleName:d,dataTypeId:f,isDefault:!0,defaultValue:l.value}):s.set(d,{connections:[],handleId:u,handleName:d,dataTypeId:f,isDefault:!0,defaultValue:void 0})}return s}buildOutputInfo(t,n,r){const i=new Map,s=n.outputs;if(!s)return i;for(const a of s){if(!a.id||!a.name)continue;const l=a.id,u=a.name,d=a.inferredDataType?.dataTypeUniqueId??a.dataType?.dataTypeUniqueId??"",f=Tn(t,l),g=r.get(f)??[];i.set(u,{handleId:l,handleName:u,dataTypeId:d,connections:g.map(h=>({targetNodeId:h.targetNodeId,targetHandleId:h.targetHandleId,edgeId:h.edgeId}))})}return i}snapshot(){return new Map(this.store)}createScope(t){return new Kc(`${t}>`,this)}clearScope(t){const n=`${t}>`;for(const r of this.store.keys())r.startsWith(n)&&this.store.delete(r)}}class DD{lastTimestamp=0;minIncrement;constructor(t=.001){this.minIncrement=t}now(){const t=performance.now(),n=Math.max(t,this.lastTimestamp+this.minIncrement);return this.lastTimestamp=n,n}}class Yb{startTime=0;steps=[];errors=[];concurrencyLevels=[];loopRecords=new Map;groupRecords=new Map;id;timer=new DD;rawStartTimes=new Map;pausedAt=null;totalPauseDuration=0;scopeStack=[];pendingLevelStart=0;pendingLevelNodeIds=[];pendingLoopIterations=new Map;pendingLoopStructures=new Map;loopNestingStack=[];pendingNestedLoopStructures=new Map;completedNestedLoopRecords=new Map;constructor(){this.id=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`run-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}start(){this.startTime=this.timer.now()}pause(){this.pausedAt===null&&(this.pausedAt=this.timer.now())}resume(){this.pausedAt!==null&&(this.totalPauseDuration+=this.timer.now()-this.pausedAt,this.pausedAt=null)}getEffectivePauseDuration(){return this.pausedAt!==null?this.totalPauseDuration+(this.timer.now()-this.pausedAt):this.totalPauseDuration}beginStep(t){this.resume();const n=this.steps.length,r=this.timer.now();return this.rawStartTimes.set(n,performance.now()),this.steps.push({stepIndex:n,nodeId:t.nodeId,nodeTypeId:t.nodeTypeId,nodeTypeName:t.nodeTypeName,concurrencyLevel:t.concurrencyLevel,startTime:r-this.startTime,endTime:0,duration:0,pauseAdjustment:this.totalPauseDuration,status:"completed",inputValues:new Map,outputValues:new Map,loopIteration:t.loopIteration,loopStructureId:t.loopStructureId,parentLoopStructureId:t.parentLoopStructureId,parentLoopIteration:t.parentLoopIteration,groupNodeId:t.groupNodeId,groupDepth:t.groupDepth,loopPhase:t.loopPhase,inputSource:t.inputSource}),n}addStepToPendingIteration(t){if(t.loopStructureId!==void 0){const n=this.pendingLoopIterations.get(t.loopStructureId);if(n){n.stepRecords.push(t);return}}if(this.loopNestingStack.length>0){const n=this.loopNestingStack[this.loopNestingStack.length-1],r=this.pendingLoopIterations.get(n.loopStructureId);r&&r.stepRecords.push(t)}}completeStep(t,n,r){const i=this.steps[t];if(!i)return;const s=performance.now(),a=this.timer.now();i.endTime=a-this.startTime,i.duration=i.endTime-i.startTime,i.status="completed",i.inputValues=n,i.outputValues=r;const l=this.rawStartTimes.get(t);l!==void 0&&s===l&&(i.estimatedTiming=!0),this.rawStartTimes.delete(t),this.addStepToPendingIteration(i)}errorStep(t,n,r){const i=this.steps[t];if(!i)return;const s=performance.now(),a=this.timer.now();i.endTime=a-this.startTime,i.duration=i.endTime-i.startTime,i.status="errored",i.inputValues=r,i.error=n;const l=this.rawStartTimes.get(t);l!==void 0&&s===l&&(i.estimatedTiming=!0),this.rawStartTimes.delete(t),this.errors.push(n),this.addStepToPendingIteration(i)}skipStep(t){const n=this.steps[t];if(!n)return;const r=this.timer.now();n.endTime=r-this.startTime,n.duration=0,n.status="skipped",this.rawStartTimes.delete(t),this.addStepToPendingIteration(n)}beginLevel(t,n){this.pendingLevelStart=this.timer.now(),this.pendingLevelNodeIds=n}completeLevel(t){const n=this.timer.now();this.concurrencyLevels.push({level:t,startTime:this.pendingLevelStart-this.startTime,endTime:n-this.startTime,duration:n-this.pendingLevelStart,nodeIds:this.pendingLevelNodeIds})}beginLoopStructure(t,n,r,i){const s={loopStartNodeId:n,loopStopNodeId:r,loopEndNodeId:i,iterations:[],startTime:this.timer.now()};if(this.loopNestingStack.length>0){const a=this.loopNestingStack[this.loopNestingStack.length-1],l=`${a.loopStructureId}:${a.iteration}:${t}`;this.pendingNestedLoopStructures.set(l,s)}else this.pendingLoopStructures.set(t,s)}beginLoopIteration(t,n){this.loopNestingStack.push({loopStructureId:t,iteration:n}),this.pendingLoopIterations.set(t,{iteration:n,startTime:this.timer.now(),stepRecords:[]})}completeLoopIteration(t,n,r){this.loopNestingStack.pop();const i=this.pendingLoopIterations.get(t);if(!i)return;const s=new Map,a=`${t}:${n}:`;for(const[f,g]of this.completedNestedLoopRecords)if(f.startsWith(a)){const h=f.slice(a.length);s.set(h,g)}for(const f of s.keys())this.completedNestedLoopRecords.delete(`${a}${f}`);const l=this.timer.now(),u={iteration:n,startTime:i.startTime-this.startTime,endTime:l-this.startTime,duration:l-i.startTime,conditionValue:r,stepRecords:i.stepRecords,nestedLoopRecords:s},d=this.pendingLoopStructures.get(t)??this.findPendingStructure(t);d&&d.iterations.push(u),this.pendingLoopIterations.delete(t)}findPendingStructure(t){for(const[n,r]of this.pendingNestedLoopStructures)if(n.endsWith(`:${t}`))return r}completeLoopStructure(t){let n=this.pendingLoopStructures.get(t),r=null;if(!n){for(const[a,l]of this.pendingNestedLoopStructures)if(a.endsWith(`:${t}`)){n=l,r=a;break}}if(!n)return;const i=this.timer.now(),s={loopStructureId:t,loopStartNodeId:n.loopStartNodeId,loopStopNodeId:n.loopStopNodeId,loopEndNodeId:n.loopEndNodeId,iterations:n.iterations,totalIterations:n.iterations.length,startTime:n.startTime-this.startTime,endTime:i-this.startTime,duration:i-n.startTime};r?(this.completedNestedLoopRecords.set(r,s),this.pendingNestedLoopStructures.delete(r)):(this.loopRecords.set(t,s),this.pendingLoopStructures.delete(t))}beginGroup(t,n){}completeGroup(t,n,r,i,s){this.groupRecords.set(t,{groupNodeId:t,groupNodeTypeId:n,innerRecord:r,inputMapping:i,outputMapping:s})}getLatestStep(){return this.steps.length>0?this.steps[this.steps.length-1]:void 0}stepCount(){return this.steps.length}getStep(t){return this.steps[t]}beginScope(){const t=[...this.loopNestingStack];this.loopNestingStack.length=0,this.scopeStack.push({startStepIndex:this.steps.length,startErrorIndex:this.errors.length,startLoopRecordKeys:new Set(this.loopRecords.keys()),startGroupRecordKeys:new Set(this.groupRecords.keys()),startNestedLoopKeys:new Set(this.completedNestedLoopRecords.keys()),savedNestingStack:t,startTime:this.timer.now()})}endScope(t,n){const r=this.scopeStack.pop();if(!r)throw new Error("ExecutionRecorder.endScope() called without matching beginScope()");this.loopNestingStack.length=0;for(const d of r.savedNestingStack)this.loopNestingStack.push(d);const i=this.timer.now(),s=this.steps.slice(r.startStepIndex),a=this.errors.slice(r.startErrorIndex),l=new Map;for(const[d,f]of this.loopRecords)r.startLoopRecordKeys.has(d)||l.set(d,f);const u=new Map;for(const[d,f]of this.groupRecords)r.startGroupRecordKeys.has(d)||u.set(d,f);return{id:`${this.id}-scope-${r.startStepIndex}`,startTime:r.startTime,endTime:i,totalDuration:i-r.startTime,compilationDuration:0,totalPauseDuration:this.getEffectivePauseDuration(),status:t,steps:s,errors:a,concurrencyLevels:[],loopRecords:l,groupRecords:u,finalValues:n}}snapshotPendingLoopRecords(t){const n=new Map(this.loopRecords),r=(i,s)=>{const a=this.pendingLoopIterations.get(i),l=[...s.iterations];if(a){const u=new Map,d=`${i}:${a.iteration}:`;for(const[f,g]of this.completedNestedLoopRecords)f.startsWith(d)&&u.set(f.slice(d.length),g);for(const[f,g]of this.pendingNestedLoopStructures)if(f.startsWith(d)){const h=f.slice(d.length);u.has(h)||u.set(h,r(h,g))}l.push({iteration:a.iteration,startTime:a.startTime-this.startTime,endTime:t-this.startTime,duration:t-a.startTime,conditionValue:!0,stepRecords:[...a.stepRecords],nestedLoopRecords:u})}return{loopStructureId:i,loopStartNodeId:s.loopStartNodeId,loopStopNodeId:s.loopStopNodeId,loopEndNodeId:s.loopEndNodeId,iterations:l,totalIterations:l.length,startTime:s.startTime-this.startTime,endTime:t-this.startTime,duration:t-s.startTime}};for(const[i,s]of this.pendingLoopStructures)n.has(i)||n.set(i,r(i,s));return n}snapshot(t,n){const r=this.timer.now();return{id:this.id,startTime:this.startTime,endTime:r,totalDuration:r-this.startTime,compilationDuration:0,totalPauseDuration:this.getEffectivePauseDuration(),status:t,steps:[...this.steps],errors:[...this.errors],concurrencyLevels:[...this.concurrencyLevels],loopRecords:this.snapshotPendingLoopRecords(r),groupRecords:new Map(this.groupRecords),finalValues:n}}finalize(t,n,r=0){const i=this.timer.now();return{id:this.id,startTime:this.startTime,endTime:i,totalDuration:i-this.startTime,compilationDuration:r,totalPauseDuration:this.getEffectivePauseDuration(),status:t,steps:this.steps,errors:this.errors,concurrencyLevels:this.concurrencyLevels,loopRecords:this.loopRecords,groupRecords:this.groupRecords,finalValues:n}}}class jD{pendingPayload=null;pendingPushResolve=null;pendingPullResolve=null;pendingPullReject=null;closed=!1;error=void 0;push(t){if(this.closed)return Promise.resolve();if(this.pendingPullResolve){const n=this.pendingPullResolve;return this.pendingPullResolve=null,this.pendingPullReject=null,n(t),new Promise(r=>{this.pendingPushResolve=r})}return this.pendingPayload=t,new Promise(n=>{this.pendingPushResolve=n})}pull(){if(this.error!==void 0)return Promise.reject(this.error);if(this.pendingPayload){const t=this.pendingPayload;if(this.pendingPayload=null,this.pendingPushResolve){const n=this.pendingPushResolve;this.pendingPushResolve=null,n()}return Promise.resolve(t)}return this.closed?Promise.resolve(null):new Promise((t,n)=>{if(this.pendingPullResolve=t,this.pendingPullReject=n,this.pendingPushResolve){const r=this.pendingPushResolve;this.pendingPushResolve=null,r()}})}close(){this.closed=!0,this.pendingPullResolve&&(this.pendingPullResolve(null),this.pendingPullResolve=null,this.pendingPullReject=null),this.pendingPushResolve&&(this.pendingPushResolve(),this.pendingPushResolve=null)}closeWithError(t){this.closed=!0,this.error=t,this.pendingPullReject&&(this.pendingPullReject(t),this.pendingPullResolve=null,this.pendingPullReject=null),this.pendingPushResolve&&(this.pendingPushResolve(),this.pendingPushResolve=null)}}function Xb(e,t){const n=new Map;function r(i){for(const s of i)if(s.kind==="standard"){const a=t.nodes.find(d=>d.id===s.nodeId);if(!a)continue;const l=a.data.nodeTypeUniqueId;if(!l)continue;const u=t.typeOfNodes[l];n.set(s.nodeId,{data:a.data,typeOfNode:u,nodeTypeId:s.nodeTypeId,nodeTypeName:s.nodeTypeName,concurrencyLevel:s.concurrencyLevel})}else if(s.kind==="loop"){for(const a of[s.loopStartNodeId,s.loopStopNodeId,s.loopEndNodeId]){const l=t.nodes.find(f=>f.id===a);if(!l)continue;const u=l.data.nodeTypeUniqueId;if(!u)continue;const d=t.typeOfNodes[u];n.set(a,{data:l.data,typeOfNode:d,nodeTypeId:u,nodeTypeName:d?.name??u,concurrencyLevel:s.concurrencyLevel})}r(s.preStopSteps),r(s.postStopSteps)}else if(s.kind==="group"){const a=t.nodes.find(d=>d.id===s.groupNodeId);if(!a)continue;const l=a.data.nodeTypeUniqueId;if(!l)continue;const u=t.typeOfNodes[l];n.set(s.groupNodeId,{data:a.data,typeOfNode:u,nodeTypeId:s.groupNodeTypeId,nodeTypeName:s.groupNodeTypeName,concurrencyLevel:s.concurrencyLevel})}}for(const i of e.levels)r(i);return n}function Mr(e){const t=new Map;for(const[n,r]of e){const i=r.connections.map(s=>({value:s.value,sourceNodeId:s.sourceNodeId,sourceNodeName:s.sourceNodeName,sourceHandleId:s.sourceHandleId,sourceHandleName:s.sourceHandleName,sourceDataTypeId:s.sourceDataTypeId}));t.set(n,{connections:i,dataTypeId:r.dataTypeId,isDefault:r.isDefault,defaultValue:r.defaultValue})}return t}function Zc(e,t){const n=new Map;for(const[r,i]of e){const s=t.get(r);n.set(r,{value:i,dataTypeId:s?.dataTypeId??"",targetCount:s?.connections.length??0})}return n}function Jc(e,t,n){for(const[r,i]of t){const s=r.indexOf(":");if(!(s===-1||r.substring(0,s)!==e)){for(const l of i)if(n.has(l.sourceNodeId))return!0}}return!1}function Kb(e){const t=[];for(const n of e)n.kind==="standard"?t.push(n.nodeId):n.kind==="loop"?t.push(n.loopStartNodeId):n.kind==="group"&&t.push(n.groupNodeId);return t}function Xf(e,t,n){const r=e.beginStep(t);n.status==="errored"?e.errorStep(r,n.error,new Map):e.completeStep(r,new Map,new Map)}async function As(e,t,n,r,i,s,a,l,u,d,f,g){const{nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:v}=e;l(h,"running");const b=n.beginStep({nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:v,loopIteration:d?.loopIteration,loopStructureId:d?.loopStructureId,groupNodeId:f?.groupNodeId,groupDepth:f?.groupDepth,loopPhase:g}),S=performance.now(),N=a.get(h);if(!N){const M=zn({error:new Error(`Node "${h}" not found in state`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:[],timestamp:performance.now()-S,duration:0});throw n.errorStep(b,M,new Map),l(h,"errored"),M}const w=t.resolveInputs(h,N.data,r.inputResolutionMap,a),I=t.buildOutputInfo(h,N.data,r.outputDistributionMap);if(ri(m)){n.completeStep(b,Mr(w),new Map),l(h,"completed");return}if(!kr(i,m)){const M=zn({error:new Error(`No function implementation for node type "${x}" (${m})`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:Pf(h,r.inputResolutionMap,a),timestamp:performance.now()-S,duration:performance.now()-S,loopContext:d?{loopStructureId:d.loopStructureId,iteration:d.loopIteration,maxIterations:d.maxIterations}:void 0,groupContext:f?{groupNodeId:f.groupNodeId,groupNodeTypeId:f.groupNodeTypeId,depth:f.groupDepth}:void 0});throw n.errorStep(b,M,Mr(w)),l(h,"errored"),M}const k=i[m];if(!k){const M=zn({error:new Error(`No function implementation for node type "${x}" (${m})`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:Pf(h,r.inputResolutionMap,a),timestamp:performance.now()-S,duration:performance.now()-S,loopContext:d?{loopStructureId:d.loopStructureId,iteration:d.loopIteration,maxIterations:d.maxIterations}:void 0,groupContext:f?{groupNodeId:f.groupNodeId,groupNodeTypeId:f.groupNodeTypeId,depth:f.groupDepth}:void 0});throw n.errorStep(b,M,Mr(w)),l(h,"errored"),M}const A={nodeId:h,nodeTypeId:m,nodeTypeName:x,state:s,loopIteration:d?.loopIteration,groupDepth:f?.groupDepth,abortSignal:u};try{const M=await k(w,I,A);if(!(M instanceof Map))throw new Error(`Function implementation for "${x}" must return a Map, got ${typeof M}`);for(const[B,U]of M){const q=I.get(B);q&&t.set(h,q.handleId,U)}n.completeStep(b,Mr(w),Zc(M,I)),l(h,"completed")}catch(M){const B=performance.now()-S,U=zn({error:M,nodeId:h,nodeTypeId:m,nodeTypeName:x,path:Pf(h,r.inputResolutionMap,a),timestamp:B,duration:B,loopContext:d?{loopStructureId:d.loopStructureId,iteration:d.loopIteration,maxIterations:d.maxIterations}:void 0,groupContext:f?{groupNodeId:f.groupNodeId,groupNodeTypeId:f.groupNodeTypeId,depth:f.groupDepth}:void 0});throw n.errorStep(b,U,Mr(w)),l(h,"errored"),U}}const $D=new Set([ze.bindLoopNodes,ze.loopInfer,ze.condition]);function Zb(e){return e.inferredDataType?.dataTypeUniqueId??e.dataType?.dataTypeUniqueId}function oi(e){return e.filter(t=>{const n=Zb(t);return t.id&&n&&!$D.has(n)}).map(t=>t.id)}function HD(e){return e.find(t=>Zb(t)===ze.condition)?.id}async function Kf(e,t,n,r,i,s,a,l,u,d,f,g){const{loopStartNodeId:h,loopStopNodeId:m,loopEndNodeId:x,preStopSteps:v,postStopSteps:b,maxIterations:S}=e,N=h,w=a.get(h),I=a.get(m),k=a.get(x);if(!w||!I||!k){const oe=zn({error:new Error("Loop structure nodes not found in state"),nodeId:h,nodeTypeId:"loop",nodeTypeName:"Loop",path:[],timestamp:0,duration:0,loopContext:{loopStructureId:N,iteration:0,maxIterations:S}}),pe=n.beginStep({nodeId:h,nodeTypeId:"loop",nodeTypeName:"Loop",concurrencyLevel:e.concurrencyLevel});throw n.errorStep(pe,oe,new Map),u(h,"errored"),u(m,"errored"),u(x,"errored"),l.add(h),l.add(m),l.add(x),oe}const A=Xc(w.data.inputs),M=w.data.outputs??[],B=Xc(I.data.inputs),U=I.data.outputs??[],q=Xc(k.data.inputs),D=k.data.outputs??[],$=oi(A),F=oi(M),E=oi(B),P=oi(U),L=oi(q),j=oi(D),O=HD(B),W=$.length;if(W===0||F.length!==W||E.length!==W||P.length!==W||L.length!==W||j.length!==W||!O){const oe=zn({error:new Error(`Loop structure has mismatched data handle counts (start in=${$.length}, start out=${F.length}, stop in=${E.length}, stop out=${P.length}, end in=${L.length}, end out=${j.length})`),nodeId:h,nodeTypeId:w.nodeTypeId,nodeTypeName:w.nodeTypeName,path:[],timestamp:0,duration:0,loopContext:{loopStructureId:N,iteration:0,maxIterations:S}}),pe=n.beginStep({nodeId:h,nodeTypeId:w.nodeTypeId,nodeTypeName:w.nodeTypeName,concurrencyLevel:e.concurrencyLevel});throw n.errorStep(pe,oe,new Map),u(h,"errored"),l.add(h),l.add(m),l.add(x),oe}const z=new Array(W);for(let oe=0;oe<W;oe++){const pe=Tn(h,$[oe]),ve=(r.inputResolutionMap.get(pe)??[]).filter(me=>me.sourceNodeId!==m);ve.length>0&&(z[oe]=t.get(ve[0].sourceNodeId,ve[0].sourceHandleId))}n.beginLoopStructure(N,h,m,x);const Y=f?{parentLoopStructureId:f.loopStructureId,parentLoopIteration:f.loopIteration}:{},J=t.buildOutputInfo(h,w.data,r.outputDistributionMap),ie=t.buildOutputInfo(m,I.data,r.outputDistributionMap);u(h,"running"),u(m,"running");function ee(oe){const pe=new Map;for(const le of oe){const ve=pe.get(le.concurrencyLevel);ve?ve.push(le):pe.set(le.concurrencyLevel,[le])}return[...pe.entries()].sort((le,ve)=>le[0]-ve[0])}const ce=ee(v),ge=ee(b),Q=t.buildOutputInfo(x,k.data,r.outputDistributionMap);async function te(oe,pe,le,ve){for(const[,me]of oe){if(d.aborted)break;const Oe=[],Ce=[];for(const ae of me){const Ie=an(ae);Jc(Ie,r.inputResolutionMap,pe)?Ce.push(ae):Oe.push(ae)}for(const ae of Ce){const Ie=an(ae);u(Ie,"skipped"),pe.add(Ie);const Be=n.beginStep({nodeId:Ie,nodeTypeId:Qc(ae),nodeTypeName:el(ae),concurrencyLevel:ae.concurrencyLevel,loopIteration:le,loopStructureId:N,loopPhase:ve,...Y});n.skipStep(Be),await g?.()}if(g)for(const ae of Oe){if(d.aborted)break;try{ae.kind==="standard"?(await As(ae,t,n,r,i,s,a,u,d,{loopIteration:le,loopStructureId:N,maxIterations:S},void 0,ve),await g()):await ks(ae,t,n,r,i,s,a,pe,u,d,{loopIteration:le,loopStructureId:N},g)}catch{pe.add(an(ae))}}else{const ae=await Promise.allSettled(Oe.map(Ie=>Ie.kind==="standard"?As(Ie,t,n,r,i,s,a,u,d,{loopIteration:le,loopStructureId:N,maxIterations:S},void 0,ve):ks(Ie,t,n,r,i,s,a,pe,u,d,{loopIteration:le,loopStructureId:N})));for(let Ie=0;Ie<ae.length;Ie++)ae[Ie].status==="rejected"&&pe.add(an(Oe[Ie]))}}}let ne=!1;for(let oe=0;oe<S&&!d.aborted;oe++){n.beginLoopIteration(N,oe);for(let Ce=0;Ce<W;Ce++)t.set(h,F[Ce],z[Ce]);const pe=oe===0?"upstream":"feedback";{const Ce=n.beginStep({nodeId:h,nodeTypeId:w.nodeTypeId,nodeTypeName:w.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopIteration:oe,loopStructureId:N,loopPhase:"loopStart",inputSource:pe,...Y}),ae=t.resolveInputs(h,w.data,r.inputResolutionMap,a),Ie=new Map;for(const[Qe,Ue]of ae)if(pe==="upstream"){const Ze=Ue.connections.filter(pt=>pt.sourceNodeId!==m);Ie.set(Qe,{...Ue,connections:Ze})}else{const Ze=Ue.connections.filter(pt=>pt.sourceNodeId===m);Ie.set(Qe,{...Ue,connections:Ze})}const Be=new Map;for(const[Qe,Ue]of J){const Ze=F.indexOf(Ue.handleId);Ze>=0&&Be.set(Qe,z[Ze])}n.completeStep(Ce,Mr(Ie),Zc(Be,J)),await g?.()}const le=new Set;await te(ce,le,oe,"preStop");const ve=Tn(m,O),me=r.inputResolutionMap.get(ve);let Oe=!1;me&&me.length>0&&(me.some(ae=>le.has(ae.sourceNodeId))||(Oe=!!t.get(me[0].sourceNodeId,me[0].sourceHandleId)));for(let Ce=0;Ce<W;Ce++){const ae=Tn(m,E[Ce]),Ie=r.inputResolutionMap.get(ae);let Be;Ie&&Ie.length>0&&(Be=t.get(Ie[0].sourceNodeId,Ie[0].sourceHandleId)),t.set(m,P[Ce],Be),z[Ce]=Be}{const Ce=n.beginStep({nodeId:m,nodeTypeId:I.nodeTypeId,nodeTypeName:I.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopIteration:oe,loopStructureId:N,loopPhase:"loopStop",...Y}),ae=t.resolveInputs(m,I.data,r.inputResolutionMap,a),Ie=new Map;for(const[Be,Qe]of ie){const Ue=P.indexOf(Qe.handleId);Ue>=0&&Ie.set(Be,z[Ue])}n.completeStep(Ce,Mr(ae),Zc(Ie,ie)),await g?.()}if(Oe&&ge.length>0){await te(ge,le,oe,"postStop");for(let Ce=0;Ce<W;Ce++){const ae=Tn(x,L[Ce]),Ie=r.inputResolutionMap.get(ae);Ie&&Ie.length>0&&(z[Ce]=t.get(Ie[0].sourceNodeId,Ie[0].sourceHandleId))}}{const Ce=!Oe;if(Ce)for(let Qe=0;Qe<W;Qe++)t.set(x,j[Qe],z[Qe]);const ae=n.beginStep({nodeId:x,nodeTypeId:k.nodeTypeId,nodeTypeName:k.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopIteration:oe,loopStructureId:N,loopPhase:"loopEnd",...Y}),Ie=t.resolveInputs(x,k.data,r.inputResolutionMap,a),Be=new Map;if(Ce)for(const[Qe,Ue]of Q){const Ze=j.indexOf(Ue.handleId);Ze>=0&&Be.set(Qe,z[Ze])}n.completeStep(ae,Mr(Ie),Zc(Be,Q)),await g?.()}if(ne=Oe,n.completeLoopIteration(N,oe,Oe),!Oe)break}if(ne&&S>0){const oe=zn({error:new Error(`Loop exceeded maximum iterations (${S})`),nodeId:m,nodeTypeId:I.nodeTypeId,nodeTypeName:I.nodeTypeName,path:[],timestamp:0,duration:0,loopContext:{loopStructureId:N,iteration:S-1,maxIterations:S}}),pe=n.beginStep({nodeId:m,nodeTypeId:I.nodeTypeId,nodeTypeName:I.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopStructureId:N,loopIteration:S-1,...Y});throw n.errorStep(pe,oe,new Map),Xf(n,{nodeId:x,nodeTypeId:k.nodeTypeId,nodeTypeName:k.nodeTypeName,concurrencyLevel:e.concurrencyLevel,loopStructureId:N,...Y},{status:"errored",error:oe}),u(m,"errored"),u(x,"errored"),l.add(h),l.add(m),l.add(x),n.completeLoopStructure(N),oe}u(h,"completed"),u(m,"completed"),u(x,"completed"),n.completeLoopStructure(N)}function BD(e,t){return{...e,nodes:t.nodes,edges:t.edges,openedNodeGroupStack:void 0}}async function Zf(e,t,n,r,i,s,a,l,u,d,f=1,g){const{groupNodeId:h,groupNodeTypeId:m,groupNodeTypeName:x,innerPlan:v}=e;if(u(h,"running"),!kr(s.typeOfNodes,m)){const D=zn({error:new Error(`Group node type "${x}" not found in type definitions`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:[],timestamp:0,duration:0,groupContext:{groupNodeId:h,groupNodeTypeId:m,depth:f}}),$=n.beginStep({nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:e.concurrencyLevel,groupNodeId:h,groupDepth:f});throw n.errorStep($,D,new Map),u(h,"errored"),l.add(h),D}const S=s.typeOfNodes[m].subtree;if(!S){const D=zn({error:new Error(`Group node type "${x}" has no subtree definition`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:[],timestamp:0,duration:0,groupContext:{groupNodeId:h,groupNodeTypeId:m,depth:f}}),$=n.beginStep({nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:e.concurrencyLevel,groupNodeId:h,groupDepth:f});throw n.errorStep($,D,new Map),u(h,"errored"),l.add(h),D}const N=BD(s,S),w=new Map;for(const D of S.nodes){const $=D.data.nodeTypeUniqueId;if(!$)continue;const F=kr(s.typeOfNodes,$)?s.typeOfNodes[$]:void 0;w.set(D.id,{data:D.data,typeOfNode:F,nodeTypeId:$,nodeTypeName:F?.name??$,concurrencyLevel:-1})}for(const D of v.levels)for(const $ of D)if($.kind==="standard"){const F=w.get($.nodeId);F&&(F.concurrencyLevel=$.concurrencyLevel)}const I=t.createScope(h),k=S.inputNodeId;if(k)for(const[D,$]of e.inputMapping){const F=Tn(h,D),E=r.inputResolutionMap.get(F);if(E&&E.length>0){const P=t.get(E[0].sourceNodeId,E[0].sourceHandleId);I.set(k,$,P)}}n.beginGroup(h,m),n.beginScope();let A=!1;const M=new Set;for(let D=0;D<v.levels.length&&!d.aborted;D++){const $=v.levels[D],F=[],E=[];for(const P of $){const L=an(P);Jc(L,v.inputResolutionMap,M)?E.push(P):F.push(P)}for(const P of E){const L=an(P);u(L,"skipped"),M.add(L);const j=n.beginStep({nodeId:L,nodeTypeId:Qc(P),nodeTypeName:el(P),concurrencyLevel:P.concurrencyLevel,groupNodeId:h,groupDepth:f});n.skipStep(j),await g?.()}if(g)for(const P of F){if(d.aborted)break;try{P.kind==="standard"?(await As(P,I,n,v,i,N,w,u,d,void 0,{groupNodeId:h,groupNodeTypeId:m,groupDepth:f}),await g()):P.kind==="group"?await Zf(P,I,n,v,i,N,w,M,u,d,f+1,g):await Kf(P,I,n,v,i,N,w,M,u,d,void 0,g)}catch{M.add(an(P))}}else{const P=await Promise.allSettled(F.map(L=>L.kind==="standard"?As(L,I,n,v,i,N,w,u,d,void 0,{groupNodeId:h,groupNodeTypeId:m,groupDepth:f}):L.kind==="group"?Zf(L,I,n,v,i,N,w,M,u,d,f+1):Kf(L,I,n,v,i,N,w,M,u,d)));for(let L=0;L<P.length;L++)P[L].status==="rejected"&&(A=!0,M.add(an(F[L])))}}const B=S.outputNodeId;if(B)for(const[D,$]of e.outputMapping){const F=Tn(B,D),E=v.inputResolutionMap.get(F);if(E&&E.length>0){const P=I.get(E[0].sourceNodeId,E[0].sourceHandleId);t.set(h,$,P)}}const U=n.endScope(A?"errored":"completed",I.snapshot());n.completeGroup(h,m,U,e.inputMapping,e.outputMapping);const q={nodeId:h,nodeTypeId:m,nodeTypeName:x,concurrencyLevel:e.concurrencyLevel,groupNodeId:h,groupDepth:f};if(A){const D=zn({error:new Error(`Group "${x}" inner execution had errors`),nodeId:h,nodeTypeId:m,nodeTypeName:x,path:[],timestamp:0,duration:0,groupContext:{groupNodeId:h,groupNodeTypeId:m,depth:f}});Xf(n,q,{status:"errored",error:D}),u(h,"errored"),l.add(h)}else Xf(n,q,{status:"completed"}),u(h,"completed")}async function ks(e,t,n,r,i,s,a,l,u,d,f,g){switch(e.kind){case"standard":await As(e,t,n,r,i,s,a,u,d),await g?.();return;case"loop":return Kf(e,t,n,r,i,s,a,l,u,d,f,g);case"group":return Zf(e,t,n,r,i,s,a,l,u,d,void 0,g)}}async function VD(e,t,n,r){const{onNodeStateChange:i,abortSignal:s}=r,a=new Kc,l=new Yb,u=new Set,d=Xb(e,n),f=performance.now();{const x="__jit_warmup__";a.set(x,x,0),a.get(x,x);const v=new Map;v.set(x,0),v.get(x),v.delete(x),await Promise.allSettled([Promise.resolve(0)]),a.set(x,x,void 0)}const g=performance.now()-f;l.start();let h=!1;for(let x=0;x<e.levels.length;x++){if(s.aborted)return l.finalize("cancelled",a.snapshot(),g);const v=e.levels[x],b=Kb(v);l.beginLevel(x,b);const S=[],N=[];for(const I of v){const k=an(I);Jc(k,e.inputResolutionMap,u)?N.push(I):S.push(I)}for(const I of N){const k=an(I);i(k,"skipped"),u.add(k);const A=l.beginStep({nodeId:k,nodeTypeId:Qc(I),nodeTypeName:el(I),concurrencyLevel:I.concurrencyLevel});l.skipStep(A)}const w=await Promise.allSettled(S.map(I=>ks(I,a,l,e,t,n,d,u,i,s)));for(let I=0;I<w.length;I++)if(w[I].status==="rejected"){h=!0;const A=an(S[I]);u.add(A)}l.completeLevel(x)}const m=s.aborted?"cancelled":h?"errored":"completed";return l.finalize(m,a.snapshot(),g)}async function*FD(e,t,n,r){const{onNodeStateChange:i,abortSignal:s}=r,a=new Kc,l=new Yb,u=new Set,d=Xb(e,n),f=performance.now();{const x="__jit_warmup__";a.set(x,x,0),a.get(x,x),await Promise.allSettled([Promise.resolve(0)]),a.set(x,x,void 0)}const g=performance.now()-f;l.start();let h=!1;for(let x=0;x<e.levels.length;x++){if(s.aborted)return l.resume(),l.finalize("cancelled",a.snapshot(),g);const v=e.levels[x],b=Kb(v);l.beginLevel(x,b);for(const S of v){if(s.aborted)return l.resume(),l.finalize("cancelled",a.snapshot(),g);const N=an(S);if(Jc(N,e.inputResolutionMap,u)){i(N,"skipped"),u.add(N);const w=l.beginStep({nodeId:N,nodeTypeId:Qc(S),nodeTypeName:el(S),concurrencyLevel:S.concurrencyLevel});l.skipStep(w);continue}if(S.kind==="standard"){try{await ks(S,a,l,e,t,n,d,u,i,s)}catch{h=!0,u.add(N)}const w=l.getLatestStep();w&&(l.pause(),yield{stepRecord:w,partialRecord:l.snapshot(h?"errored":"completed",a.snapshot())})}else{const w=new jD,k=ks(S,a,l,e,t,n,d,u,i,s,void 0,async()=>{const A=l.getLatestStep();A&&(l.pause(),await w.push({stepRecord:A,partialRecord:l.snapshot(h?"errored":"completed",a.snapshot())}))}).then(()=>w.close(),A=>{h=!0,u.add(N),w.closeWithError(A)});try{for(;;){const A=await w.pull();if(A===null)break;yield A}}catch{h=!0,u.add(N)}await k}}l.completeLevel(x)}l.resume();const m=s.aborted?"cancelled":h?"errored":"completed";return l.finalize(m,a.snapshot(),g)}function an(e){switch(e.kind){case"standard":return e.nodeId;case"loop":return e.loopStartNodeId;case"group":return e.groupNodeId}}function Qc(e){switch(e.kind){case"standard":return e.nodeTypeId;case"loop":return"loop";case"group":return e.groupNodeTypeId}}function el(e){switch(e.kind){case"standard":return e.nodeTypeName;case"loop":return"Loop";case"group":return e.groupNodeTypeName}}const Ms=new Map,zD=new Map,Os=new Map;function ii(e,t){const n=new Map;for(const r of e.steps)r.stepIndex<t?n.set(r.nodeId,r.status==="errored"?"errored":r.status==="skipped"?"skipped":"completed"):r.stepIndex===t?n.set(r.nodeId,"running"):n.has(r.nodeId)||n.set(r.nodeId,"idle");for(const[,r]of e.loopRecords){const i=[];for(const l of r.iterations)for(const u of l.stepRecords)i.push(u.stepIndex);if(i.length===0)continue;const s=Math.min(...i),a=Math.max(...i);t>=s&&t<=a&&(n.set(r.loopStartNodeId,"running"),n.set(r.loopStopNodeId,"running"))}for(const[r,i]of e.groupRecords){const s=i.innerRecord.steps;if(s.length===0)continue;const a=s.map(d=>d.stepIndex),l=Math.min(...a),u=Math.max(...a);t>=l&&t<=u&&n.set(r,"running")}return n}function UD(e,t){const n=new Map;for(const r of e.nodes){const i=r.data.nodeTypeUniqueId;if(!i)continue;const s=e.typeOfNodes[i];if(!ri(i)&&!Tt(i)&&!s?.subtree&&(!kr(t,i)||!t[i])){const a=s?.name??i,l=n.get(r.id);l?l.push(`No function implementation for node type "${a}"`):n.set(r.id,[`No function implementation for node type "${a}"`])}}return n}function Jf(e){const t=new Map;for(const n of e.errors){const r=t.get(n.nodeId);r?r.push(n):t.set(n.nodeId,[n])}return t}function WD(e,t){const n=[],r=[];if(e.steps.length===0)return r.push("Recording has no execution steps."),{valid:!1,warnings:n,errors:r};const i=new Set(t.nodes.map(f=>f.id)),s=new Set(Object.keys(t.typeOfNodes)),a=new Set,l=new Set;for(const f of e.steps)i.has(f.nodeId)||a.add(f.nodeId),!ri(f.nodeTypeId)&&!Tt(f.nodeTypeId)&&!s.has(f.nodeTypeId)&&l.add(f.nodeTypeId);a.size>0&&n.push(`Recording references ${a.size} node(s) not in the current graph: ${[...a].join(", ")}`),l.size>0&&n.push(`Recording references ${l.size} node type(s) not in the current graph: ${[...l].join(", ")}`);const u=new Set(e.steps.map(f=>f.nodeId)),d=[];for(const f of t.nodes){const g=f.data.nodeTypeUniqueId;g&&(ri(g)||Tt(g)||t.typeOfNodes[g]?.subtree||u.has(f.id)||d.push(f.id))}return d.length>0&&n.push(`${d.length} node(s) in the current graph were not in the recording: ${d.join(", ")}`),{valid:!0,warnings:n,errors:r}}function GD({state:e,functionImplementations:t,options:n,executionRecord:r,onExecutionRecordChange:i}){const s=r!==void 0,[a,l]=T.useState(null),u=s?r:a,d=T.useRef(u??null),f=T.useCallback(ne=>{d.current=ne,s||l(ne),i?.(ne)},[s,i]),[g,h]=T.useState(()=>u?"completed":"idle"),[m,x]=T.useState(()=>u?ii(u,Math.max(0,u.steps.length-1)):Ms),[v,b]=T.useState(zD),[S,N]=T.useState(()=>u?Jf(u):Os),[w,I]=T.useState(()=>u?Math.max(0,u.steps.length-1):0),[k,A]=T.useState("instant"),[M,B]=T.useState(n?.maxLoopIterations??qb),U=T.useRef(null),q=T.useRef(null),D=T.useRef(new Map),$=T.useRef(!1),F=T.useRef(!0);T.useEffect(()=>(F.current=!0,()=>{F.current=!1,U.current?.abort(),q.current=null,$.current=!1}),[]);const E=T.useRef(u);if(s&&u!==E.current&&u!==d.current)if(E.current=u,u){const ne=Math.max(0,u.steps.length-1);I(ne),N(Jf(u));const oe=ii(u,ne);D.current=new Map(oe),x(oe),h(u.status==="cancelled"||u.errors.length>0?"errored":"completed")}else I(0),N(Os),D.current=new Map,x(Ms),h("idle");else s&&u!==E.current&&(E.current=u);T.useEffect(()=>{const ne=UD(e,t);b(ne)},[e.nodes,e.typeOfNodes,t]);const P=T.useCallback(()=>{F.current&&x(new Map(D.current))},[]),L=T.useCallback((ne,oe)=>{D.current.set(ne,oe)},[]),j=T.useCallback(()=>{try{return Yf(e,t,{maxLoopIterations:M})}catch{return F.current&&h("errored"),null}},[e,t,M]),O=T.useCallback(ne=>{if(!F.current)return;f(ne),I(Math.max(0,ne.steps.length-1));const oe=Jf(ne);N(oe);const pe=new Map;for(const le of ne.steps)pe.set(le.nodeId,le.status==="errored"?"errored":le.status==="skipped"?"skipped":"completed");D.current=pe,x(pe),q.current=null,h(ne.status==="cancelled"||ne.errors.length>0?"errored":"completed")},[]),W=T.useCallback(async()=>{D.current=new Map,x(Ms),N(Os),f(null),I(0),U.current?.abort();const ne=new AbortController;U.current=ne,h("compiling");const oe=j();if(oe&&F.current){h("running");try{const pe=await VD(oe,t,e,{onNodeStateChange:L,abortSignal:ne.signal});if(!F.current)return;O(pe)}catch{F.current&&(P(),h("errored"))}}},[e,t,j,L,P,O]),z=T.useCallback(async()=>{D.current=new Map,x(Ms),N(Os),f(null),I(0),U.current?.abort();const ne=new AbortController;U.current=ne,h("compiling");const oe=j();if(!oe||!F.current)return;h("running");const pe=FD(oe,t,e,{onNodeStateChange:L,abortSignal:ne.signal});q.current=pe;try{const le=await pe.next();if(!F.current)return;if(le.done)O(le.value);else{const{stepRecord:ve,partialRecord:me}=le.value;f(me),I(ve.stepIndex),x(ii(me,ve.stepIndex)),h("paused")}}catch{F.current&&(P(),h("errored"),q.current=null)}},[e,t,j,L,P,O]),Y=T.useCallback(()=>{k==="instant"?W():z()},[k,W,z]),J=T.useCallback(()=>{const ne=q.current;if(!ne){z();return}h("running"),(async()=>{try{const oe=await ne.next();if(!F.current)return;if(oe.done)O(oe.value);else{const{stepRecord:pe,partialRecord:le}=oe.value;f(le),I(pe.stepIndex),x(ii(le,pe.stepIndex)),h("paused")}}catch{F.current&&(P(),h("errored"),q.current=null)}})()},[z,P,O]),ie=T.useCallback(()=>{$.current=!1,F.current&&h("paused")},[]),ee=T.useCallback(()=>{const ne=q.current;ne&&($.current=!0,h("running"),(async()=>{for(;$.current;)try{const oe=await ne.next();if(!F.current)return;if(oe.done){$.current=!1,O(oe.value);return}const{stepRecord:pe,partialRecord:le}=oe.value;f(le),I(pe.stepIndex),x(ii(le,pe.stepIndex))}catch{$.current=!1,F.current&&(P(),h("errored"),q.current=null);return}F.current&&h("paused")})())},[P,O]),ce=T.useCallback(()=>{$.current=!1,U.current?.abort(),q.current=null,F.current&&(P(),h("errored"))},[P]),ge=T.useCallback(()=>{$.current=!1,U.current?.abort(),q.current=null,F.current&&(D.current=new Map,h("idle"),x(Ms),N(Os),f(null),I(0))},[]),Q=T.useCallback(ne=>{if(!u)return;const oe=Math.max(0,Math.min(ne,u.steps.length-1));I(oe);const pe=ii(u,oe);D.current=new Map(pe),x(pe)},[u]),te=T.useCallback(ne=>{const oe=WD(ne,e);return oe.valid&&($.current=!1,U.current?.abort(),q.current=null,O(ne)),oe},[e,O]);return{runnerState:g,nodeVisualStates:m,nodeWarnings:v,nodeErrors:S,executionRecord:u,currentStepIndex:w,run:Y,pause:ie,resume:ee,step:J,stop:ce,reset:ge,replayTo:Q,loadRecord:te,mode:k,setMode:A,maxLoopIterations:M,setMaxLoopIterations:B}}const qD=250;function Qf(e,t={}){const{durationMs:n=qD,hiddenTransform:r="translateY(100%)",visibleTransform:i="translateY(0)",easing:s="cubic-bezier(0.32, 0.72, 0, 1)"}=t,[a,l]=T.useState(!1),u=T.useRef(null),d=T.useRef(null);return T.useEffect(()=>{e&&l(!0)},[e]),T.useEffect(()=>{const g=u.current;if(!g||!a)return;d.current&&(g.style.transform=getComputedStyle(g).transform,d.current.cancel(),d.current=null);const h=e?i:r,m=g.animate([{transform:h}],{duration:n,easing:s,fill:"forwards"});d.current=m,e||(m.onfinish=()=>l(!1))},[e,a,n,r,i,s]),{mounted:a,ref:u,style:{transform:r}}}function Jb({initialSize:e,minSize:t,maxSize:n,direction:r="up"}){const[i,s]=T.useState(e),a=T.useRef(!1),l=T.useRef(0),u=T.useRef(0),d=r==="up"||r==="down",f=d?"ns-resize":"ew-resize",g=r==="up"||r==="left"?-1:1,h=T.useCallback(m=>{m.preventDefault(),m.stopPropagation(),a.current=!0,l.current=d?m.clientY:m.clientX,u.current=i,document.body.style.userSelect="none",document.body.style.cursor=f;const x=b=>{if(!a.current)return;const N=((d?b.clientY:b.clientX)-l.current)*g,w=Math.max(t,Math.min(n,u.current+N));s(w)},v=()=>{a.current=!1,document.body.style.userSelect="",document.body.style.cursor="",document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",v)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",v)},[i,t,n,d,f,g]);return{size:i,onMouseDown:h}}const YD=220,XD=80,KD=600;function ZD({runnerState:e,record:t,currentStepIndex:n,onRun:r,onPause:i,onStep:s,onStop:a,onReset:l,mode:u,onModeChange:d,maxLoopIterations:f,onMaxLoopIterationsChange:g,onScrubTo:h,onNavigateToNode:m,panelRef:x,debugMode:v=!1,hideComplexValues:b=!1,className:S}){const{selectedStepIndex:N,setSelectedStepIndex:w,edgeValuesAnimated:I,setEdgeValuesAnimated:k,isRunnerPanelOpen:A,setIsRunnerPanelOpen:M}=Uf(),{size:B,onMouseDown:U}=Jb({initialSize:YD,minSize:XD,maxSize:KD,direction:"up"}),{mounted:q,ref:D,style:$}=Qf(A),F=T.useCallback(Y=>{D.current=Y,x&&(x.current=Y)},[D,x]);T.useEffect(()=>{A||w(null)},[A,w]);const E=N!==null&&t?t.steps.find(Y=>Y.stepIndex===N)??null:null,P=T.useRef(null);E&&(P.current=E);const j=Qf(E!==null,{durationMs:200,hiddenTransform:"translateX(100%)",visibleTransform:"translateX(0)"}),O=E??P.current,W=T.useCallback(Y=>{w(N===Y.stepIndex?null:Y.stepIndex)},[N,w]),z=T.useCallback(()=>{w(null)},[w]);return q?y.jsx("div",{className:"absolute inset-x-0 bottom-0 z-10 overflow-hidden pointer-events-none",children:y.jsxs("div",{ref:F,className:ye("pointer-events-auto","flex flex-col overflow-hidden rounded-t-lg border border-b-0 border-secondary-dark-gray/60 bg-runner-panel-bg shadow-xl",S),style:$,children:[y.jsx("div",{className:"group/resizer flex shrink-0 cursor-ns-resize items-center justify-center border-b border-runner-timeline-box-border bg-[#2b2b2b] py-2 transition-colors hover:bg-[#353535]",onMouseDown:U,children:y.jsxs("div",{className:"flex gap-1.5",children:[y.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-runner-handle-dot transition-colors group-hover/resizer:bg-primary-blue"}),y.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-runner-handle-dot transition-colors group-hover/resizer:bg-primary-blue"}),y.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-runner-handle-dot transition-colors group-hover/resizer:bg-primary-blue"})]})}),y.jsxs("div",{className:"flex shrink-0 items-center",children:[y.jsx("div",{className:"min-w-0 flex-1",children:y.jsx(wb,{runnerState:e,onRun:r,onPause:i,onStep:s,onStop:a,onReset:l,mode:u,onModeChange:d,maxLoopIterations:f,onMaxLoopIterationsChange:g})}),y.jsx("button",{type:"button",onClick:()=>M(!1),className:"btn-press mr-3 shrink-0 rounded p-1.5 text-secondary-light-gray transition-colors hover:bg-primary-dark-gray hover:text-primary-white",title:"Close panel",children:y.jsx(aa,{className:"h-4 w-4"})})]}),y.jsxs("div",{className:"flex min-h-0 overflow-hidden",style:{height:`${B}px`},children:[y.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:y.jsx(jb,{record:t,currentStepIndex:n,onScrubTo:h,onStepClick:W,selectedStepIndex:N,onNavigateToNode:m})}),j.mounted&&O&&y.jsx("div",{ref:j.ref,className:"node-runner-scrollbar shrink-0 overflow-y-auto border-l border-secondary-dark-gray",style:j.style,children:y.jsx($b,{stepRecord:O,onClose:z,loopRecords:t?.loopRecords,hideComplexValues:b,debugMode:v,edgeValuesAnimated:I,onEdgeValuesAnimatedChange:k})})]})]})}):null}function JD({state:e,dispatch:t,functionImplementations:n,children:r,onExecutionRecordRef:i,loadRecordRef:s}){const{executionRecord:a,setExecutionRecord:l}=Tw(),u=GD({state:e,functionImplementations:n,executionRecord:a,onExecutionRecordChange:l}),{getNode:d,setCenter:f,getViewport:g}=Zo(),h=T.useRef(null),m=Uf(),{selectedStepIndex:x,setSelectedStepIndex:v,edgeValuesAnimated:b,isRunnerPanelOpen:S,setIsRunnerPanelOpen:N,getViewState:w,restoreViewState:I}=m,k=T.useCallback(q=>{const D=d(q);if(!D)return;const $=D.position.x+(D.measured?.width??200)/2;let F=D.position.y+(D.measured?.height??100)/2;const E=g().zoom,P=h.current?.offsetHeight??0;P>0&&(F+=P/(2*E)),f($,F,{duration:300,zoom:E})},[d,f,g]);T.useEffect(()=>(s&&(s.current=q=>{const D=u.loadRecord(q);return D.valid&&q.viewState&&(I(q.viewState),q.viewState.runMode!==void 0&&u.setMode(q.viewState.runMode),q.viewState.maxLoopIterations!==void 0&&u.setMaxLoopIterations(q.viewState.maxLoopIterations)),D}),()=>{s&&(s.current=null)}),[s,u.loadRecord,u.setMode,u.setMaxLoopIterations,I]);const A=T.useMemo(()=>{const q=new Map;for(const[D,$]of u.nodeVisualStates)q.set(D,{visualState:$});for(const[D,$]of u.nodeWarnings){const F=q.get(D);F?q.set(D,{...F,warnings:$}):q.set(D,{visualState:"warning",warnings:$})}for(const[D,$]of u.nodeErrors){const F=q.get(D);F?q.set(D,{...F,errors:$}):q.set(D,{visualState:"errored",errors:$})}return q},[u.nodeVisualStates,u.nodeWarnings,u.nodeErrors]),M=T.useCallback(q=>{u.setMode(q)},[u.setMode]),B=T.useCallback(()=>{u.runnerState==="paused"?u.resume():u.run()},[u.runnerState,u.run,u.resume]);T.useEffect(()=>{(u.runnerState==="compiling"||u.runnerState==="idle")&&v(null)},[u.runnerState]),T.useEffect(()=>{x!==null&&u.replayTo(x)},[x,u.replayTo]);const U=T.useMemo(()=>x===null||!u.executionRecord?null:u.executionRecord.steps.find(q=>q.stepIndex===x)??null,[x,u.executionRecord]);return T.useEffect(()=>(i&&(i.current=()=>{const q=u.executionRecord;if(!q)return null;const D={...w(),runMode:u.mode,maxLoopIterations:u.maxLoopIterations};return{...q,viewState:D}}),()=>{i&&(i.current=null)}),[i,u.executionRecord,w,u.mode,u.maxLoopIterations]),y.jsxs(uo.Provider,{value:Sf({state:e,dispatch:t},A,U,b),children:[r,y.jsx(ZD,{runnerState:u.runnerState,record:u.executionRecord,currentStepIndex:u.currentStepIndex,onRun:B,onPause:u.pause,onStep:u.step,onStop:u.stop,onReset:u.reset,mode:u.mode,onModeChange:M,maxLoopIterations:u.maxLoopIterations,onMaxLoopIterationsChange:u.setMaxLoopIterations,onScrubTo:u.replayTo,onNavigateToNode:k,panelRef:h}),!S&&y.jsxs("button",{type:"button",onClick:()=>N(!0),className:"btn-press absolute bottom-4 left-1/2 z-10 flex -translate-x-1/2 items-center gap-2 rounded-lg border border-secondary-dark-gray/60 bg-secondary-black/90 px-4 py-2 text-[12px] font-medium text-primary-white shadow-xl backdrop-blur-sm transition-colors hover:bg-primary-dark-gray",title:"Open runner panel",children:[y.jsx(au,{className:"h-3.5 w-3.5"}),"Runner"]})]})}function Qb(e,t){const n=new Blob([e],{type:"application/json"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}function QD({state:e,dispatch:t,functionImplementations:n,onStateImported:r,onRecordingImported:i,onImportError:s}){const a=T.useRef(null),l=T.useRef(null),[u,d]=T.useState(0),f=T.useRef(null),g=T.useRef(null),h=T.useCallback(()=>{const D=bw(e,{pretty:!0});Qb(D,"graph-state.json")},[e]),m=T.useCallback(D=>{const $=Iw(D,{dataTypes:e.dataTypes,typeOfNodes:e.typeOfNodes,repair:{removeOrphanEdges:!0,removeDuplicateNodeIds:!0,removeDuplicateEdgeIds:!0,fillMissingDefaults:!0,rehydrateDataTypeObjects:!0}});if($.success){const F={...$.data,dataTypes:e.dataTypes,typeOfNodes:e.typeOfNodes};t({type:ft.REPLACE_STATE,payload:{state:F}}),d(E=>E+1),r?.(F)}else s?.($.errors.map(F=>`${F.path}: ${F.message}`))},[e.dataTypes,e.typeOfNodes,t,r,s]),x=T.useCallback(()=>{const D=a.current?.();if(!D)return;const $=Nw(D,{pretty:!0});Qb($,"execution-recording.json")},[]),v=T.useCallback(D=>{const $=Ew(D,{repair:{sanitizeNonSerializableValues:!0,removeOrphanSteps:!0}});if($.success){const F=l.current?.($.data);if(F&&!F.valid){s?.(F.errors);return}F?.warnings.length&&console.warn("Recording import warnings:",F.warnings),i?.($.data)}else s?.($.errors.map(F=>`${F.path}: ${F.message}`))},[i,s]),[b,S]=T.useState({isOpen:!1,position:{x:0,y:0}}),N=T.useMemo(()=>{const D=[];for(const $ of Object.keys(e.typeOfNodes)){if(!kr(e.typeOfNodes,$))continue;const F=e.typeOfNodes[$];F?.subtree!==void 0&&D.push({id:$,name:F.name})}return D},[e.typeOfNodes]),w=T.useMemo(()=>e.openedNodeGroupStack?.[e.openedNodeGroupStack.length-1],[e.openedNodeGroupStack]),{screenToFlowPosition:I,fitView:k}=Zo(),A=T.useCallback(()=>{S({isOpen:!1,position:{x:0,y:0}})},[]),M=T.useMemo(()=>[...mb({typeOfNodes:e.typeOfNodes,dispatch:t,setContextMenu:S,contextMenuPosition:I(b.position),currentNodeType:w?.nodeType,isRecursionAllowed:!e.enableRecursionChecking}),...MD({onExportState:h,onImportState:()=>f.current?.click(),onExportRecording:x,onImportRecording:()=>g.current?.click(),closeMenu:A})],[e.typeOfNodes,t,S,b.position,w?.nodeType,e.enableRecursionChecking,h,x,A,I]),B=T.useCallback(D=>{D.preventDefault();const $={x:D.clientX,y:D.clientY};S({isOpen:!0,position:$})},[]),U=T.useMemo(()=>Mt(e),[e.nodes,e.edges,e.openedNodeGroupStack,e.typeOfNodes]);T.useEffect(()=>{e.viewport===void 0&&(U.nodes.length>0?k({maxZoom:.5,minZoom:.1}):t({type:ft.SET_VIEWPORT,payload:{viewport:{x:0,y:0,zoom:.45}}}))},[e.viewport]);const q=y.jsxs(y.Fragment,{children:[y.jsxs(KR,{nodes:U.nodes,edges:U.edges,onNodesChange:D=>t({type:ft.UPDATE_NODE_BY_REACT_FLOW,payload:{changes:D}}),onEdgesChange:D=>t({type:ft.UPDATE_EDGES_BY_REACT_FLOW,payload:{changes:D}}),onConnect:D=>t({type:ft.ADD_EDGE_BY_REACT_FLOW,payload:{edge:D}}),maxZoom:1,minZoom:.1,proOptions:{hideAttribution:!0},colorMode:"dark",selectNodesOnDrag:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectionMode:Uo.Partial,nodeTypes:PD,edgeTypes:RD,deleteKeyCode:["Backspace","Delete","x"],connectionLineComponent:Hb,onContextMenu:B,onClick:A,viewport:e.viewport,onViewportChange:D=>t({type:ft.SET_VIEWPORT,payload:{viewport:D}}),onBeforeDelete:async({nodes:D,edges:$})=>{const F=Mt(e);return!!DL({...e,...F},D,$).validation.isValid},children:[y.jsx(lL,{}),y.jsx(nL,{}),y.jsx(SL,{pannable:!0})]},u),y.jsx(kD,{isOpen:b.isOpen,position:b.position,onClose:A,items:M}),y.jsx(OD,{nodeGroups:N,value:w?.nodeType??"",setValue:D=>{kr(e.typeOfNodes,D)&&t({type:ft.OPEN_NODE_GROUP,payload:{nodeType:D}})},handleAddNewGroup:()=>t({type:ft.ADD_NODE_GROUP}),enableBackButton:(e.openedNodeGroupStack?.length||0)>0,handleBack:()=>t({type:ft.CLOSE_NODE_GROUP}),openedNodeGroupStack:(e.openedNodeGroupStack||[]).map(D=>({id:D.nodeType+("nodeId"in D?D.nodeId:""),name:e.typeOfNodes[D.nodeType].name}))})]});return y.jsxs("div",{style:{width:"100%",height:"100%"},className:"relative",children:[n?y.jsx(Q2,{children:y.jsx(JD,{state:e,dispatch:t,functionImplementations:n,onExecutionRecordRef:a,loadRecordRef:l,children:q})}):q,y.jsx("input",{ref:f,type:"file",accept:".json",className:"hidden",onChange:D=>{const $=D.target.files?.[0];if(!$)return;const F=new FileReader;F.onload=E=>{const P=E.target?.result;typeof P=="string"&&m(P)},F.readAsText($),D.target.value=""}}),y.jsx("input",{ref:g,type:"file",accept:".json",className:"hidden",onChange:D=>{const $=D.target.files?.[0];if(!$)return;const F=new FileReader;F.onload=E=>{const P=E.target?.result;typeof P=="string"&&v(P)},F.readAsText($),D.target.value=""}})]})}function ej({state:e,dispatch:t,functionImplementations:n,onStateImported:r,onRecordingImported:i,onImportError:s,executionRecord:a,onExecutionRecordChange:l}){const u=T.useCallback(()=>{},[]),d=T.useMemo(()=>({executionRecord:a??null,setExecutionRecord:l??u}),[a,l,u]);return y.jsx(G0,{children:y.jsx(uo.Provider,{value:Sf({state:e,dispatch:t}),children:y.jsx(bf.Provider,{value:d,children:y.jsx(QD,{state:e,dispatch:t,functionImplementations:n,onStateImported:r,onRecordingImported:i,onImportError:s})})})})}const tt=["circle","square","rectangle","list","grid","diamond","trapezium","hexagon","star","cross","zigzag","sparkle","parallelogram"],Ct={[tt[0]]:tt[0],[tt[1]]:tt[1],[tt[2]]:tt[2],[tt[3]]:tt[3],[tt[4]]:tt[4],[tt[5]]:tt[5],[tt[6]]:tt[6],[tt[7]]:tt[7],[tt[8]]:tt[8],[tt[9]]:tt[9],[tt[10]]:tt[10],[tt[11]]:tt[11],[tt[12]]:tt[12]},tl=(e,t,n,r="black",i=2)=>y.jsxs("div",{className:ye("relative",n),children:[y.jsx("div",{className:"absolute",style:{top:-i,left:-i,right:-i,bottom:-i,backgroundColor:r,clipPath:e}}),y.jsx("div",{className:"absolute inset-0",style:{backgroundColor:t,clipPath:e}})]}),eS=(e=Ct.circle,t="#A1A1A1",n)=>{const r="border-2 border-black",i="border-1 border-black",s={backgroundColor:t};switch(e){case Ct.circle:return y.jsx("div",{className:ye("w-6 h-6 rounded-full",r,n),style:s});case Ct.square:return y.jsx("div",{className:ye("w-6 h-6",r,n),style:s});case Ct.rectangle:return y.jsx("div",{className:ye("w-4 h-8",r,n),style:s});case Ct.list:return y.jsx("div",{className:ye("w-6 h-6 flex flex-col justify-center gap-0.5",n),children:[0,1,2].map(a=>y.jsx("div",{className:ye("w-full h-2",i),style:s},a))});case Ct.grid:return y.jsx("div",{className:ye("w-6 h-6 grid grid-cols-2 gap-0.5",n),children:[0,1,2,3].map(a=>y.jsx("div",{className:ye("w-full h-full",i),style:s},a))});case Ct.diamond:return y.jsx("div",{className:ye("w-6 h-6 rotate-45",r,n),style:s});case Ct.trapezium:return tl("polygon(25% 0%, 75% 0%, 100% 100%, 0% 100%)",t,ye("w-6 h-6",n));case Ct.hexagon:return tl("polygon(-50% 50%,50% 100%,150% 50%,50% 0)",t,ye("w-5 h-6",n));case Ct.star:return tl("polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%)",t,ye("w-6 h-6",n));case Ct.cross:return y.jsxs("div",{className:ye("w-6 h-6 relative",n),children:[y.jsx("div",{className:ye("absolute top-1/2 left-0 w-full h-2 -translate-y-1/2",i),style:s}),y.jsx("div",{className:ye("absolute left-1/2 top-0 w-2 h-full -translate-x-1/2",i),style:s})]});case Ct.zigzag:return y.jsx("div",{className:ye("w-6 h-6",n),style:{...s,width:"calc(4px + 24px/(2*tan(90deg/2)))",minHeight:"24px",mask:"4px 50%/100% 24px repeat-y conic-gradient(from calc(90deg - 90deg/2) at left, #0000, #000 1deg calc(90deg - 1deg), #0000 90deg) exclude, 0 50%/100% 24px repeat-y conic-gradient(from calc(90deg - 90deg/2) at left, #0000, #000 1deg calc(90deg - 1deg), #0000 90deg)",border:"2px solid black"}});case Ct.sparkle:return y.jsx("div",{className:ye("w-6 h-6",n),style:{...s,mask:"radial-gradient(#0000 71%, #000 72%) 10000% 10000%/99.5% 99.5%",border:"2px solid black"}});case Ct.parallelogram:return tl("polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%)",t,ye("w-6 h-6",n));default:return y.jsx("div",{className:ye("w-6 h-6 rounded-full",r,n),style:s})}},nl=T.forwardRef(({type:e,position:t,id:n,color:r,shape:i=Ct.circle,maxConnections:s,isCurrentlyInsideReactFlow:a=!1,className:l,...u},d)=>{const f=a?q0({handleId:n,handleType:e}):[];if(a){const g=s!==void 0?f.length<s:void 0;return y.jsx(ds,{type:e,position:t,id:n,className:ye("!w-6 !h-6 !border-none !bg-transparent !pointer-events-auto",l),style:{backgroundColor:"transparent"},isConnectable:g,isConnectableStart:g,isConnectableEnd:g,...u,ref:d,children:y.jsx("div",{className:ye("pointer-events-none flex justify-center"),children:eS(i,r||"#A1A1A1",l)})})}return y.jsx("div",{className:ye("absolute",t===Ne.Right&&"right-0 top-1/2 -translate-y-1/2 translate-x-1/2",t===Ne.Left&&"left-0 top-1/2 -translate-y-1/2 -translate-x-1/2"),...u,ref:d,children:eS(i,r||"#A1A1A1",l)})});nl.displayName="ContextAwareHandle";const ep=T.forwardRef(({className:e,...t},n)=>y.jsx(Cu,{"data-slot":"checkbox",className:ye("peer bg-primary-gray border-transparent data-[state=checked]:bg-primary-blue data-[state=checked]:text-primary-white focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-7 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,ref:n,children:y.jsx(sm,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:y.jsx(sa,{className:"size-6",strokeWidth:3.5})})}));ep.displayName=Cu.displayName;const tS=({input:e})=>{const t=Zo(),n=us();return e.type==="string"?y.jsx(ws,{placeholder:e.name,value:e.value,onChange:r=>{e.onChange?.(r),t.setNodes(i=>i.map(s=>s.id===n?{...s,data:uf(s.data,e.id,{value:r},!0,!1,!1)}:s))},allowOnlyNumbers:!1,className:"w-full"}):e.type==="number"?y.jsx(ni,{name:e.name,value:e.value,onChange:r=>{e.onChange?.(r),t.setNodes(i=>i.map(s=>s.id===n?{...s,data:uf(s.data,e.id,{value:r},!0,!1,!1)}:s))},className:"w-full"}):e.type==="boolean"?y.jsxs("div",{className:"flex items-center gap-2 w-full",children:[y.jsx(ep,{checked:e.value,onCheckedChange:r=>{r!=="indeterminate"&&(e.onChange?.(r),t.setNodes(i=>i.map(s=>s.id===n?{...s,data:uf(s.data,e.id,{value:r},!0,!1,!1)}:s)))}}),y.jsx("p",{className:"text-primary-white text-[27px] leading-[27px] font-main truncate",children:e.name})]}):null},nS=({input:e,isCurrentlyInsideReactFlow:t})=>t?y.jsx(tS,{input:e}):e.type==="string"?y.jsx(ws,{placeholder:e.name,value:e.value,onChange:e.onChange,allowOnlyNumbers:!1,className:"w-full"}):e.type==="number"?y.jsx(ni,{name:e.name,value:e.value,onChange:e.onChange,className:"w-full"}):e.type==="boolean"?y.jsxs("div",{className:"flex items-center gap-2 w-full",children:[y.jsx(ep,{checked:e.value,onCheckedChange:n=>{n!=="indeterminate"&&e.onChange?.(n)}}),y.jsx("p",{className:"text-primary-white text-[27px] leading-[27px] font-main truncate",children:e.name})]}):null,rS=({})=>{const e=T.useContext(uo),t=us(),n=()=>{e?.allProps?.dispatch&&t&&e.allProps.dispatch({type:ft.OPEN_NODE_GROUP,payload:{nodeId:t}})};return y.jsx(eg,{strokeWidth:2.5,className:"shrink-0 w-7 h-7 aspect-square cursor-pointer hover:opacity-80",onClick:n})},oS=({showButton:e=!1,isCurrentlyInsideReactFlow:t})=>e?t?y.jsx(rS,{}):y.jsx(eg,{strokeWidth:2.5,className:"shrink-0 w-7 h-7 aspect-square cursor-pointer hover:opacity-80"}):y.jsx(y.Fragment,{}),tp=T.forwardRef(({input:e,isCurrentlyInsideReactFlow:t,hide:n=!1},r)=>{const i=t?q0({handleId:e.id}):[],s=t&&i.some(l=>l.targetHandle===e.id),a=e.allowInput&&!s;return y.jsxs("div",{ref:r,className:ye("text-primary-white text-[27px] leading-[27px] font-main relative px-6 flex flex-row py-3",n&&"h-0 overflow-hidden py-0",a&&"py-1"),children:[y.jsx(nl,{type:"target",position:Ne.Left,id:e.id,color:e.handleColor,shape:e.handleShape,maxConnections:e.maxConnections,isCurrentlyInsideReactFlow:t}),y.jsxs("div",{className:"flex-1 flex items-center gap-3 w-full",children:[!a&&y.jsx("div",{className:"truncate",children:e.name||""}),a&&y.jsx("div",{className:"flex-1 w-full",children:y.jsx(nS,{input:e,isCurrentlyInsideReactFlow:t})})]})]},e.id)});tp.displayName="RenderInput";const iS=T.forwardRef(({output:e,isCurrentlyInsideReactFlow:t},n)=>y.jsxs("div",{ref:n,className:"text-primary-white text-[27px] leading-[27px] font-main relative px-6 flex flex-row justify-end py-3",children:[y.jsx("div",{className:"truncate text-right",children:e.name||""}),y.jsx(nl,{type:"source",position:Ne.Right,id:e.id,color:e.handleColor,shape:e.handleShape,maxConnections:e.maxConnections,isCurrentlyInsideReactFlow:t})]},e.id));iS.displayName="RenderOutput";const sS=T.forwardRef(({panel:e,isCurrentlyInsideReactFlow:t,isOpen:n,onToggle:r},i)=>y.jsxs("div",{ref:i,className:"flex flex-col",children:[y.jsxs(Qn,{onClick:s=>{s.stopPropagation(),s.preventDefault(),r()},className:"bg-transparent border-none hover:bg-primary-gray rounded-none justify-start",children:[n?y.jsx(su,{className:"w-6 h-6 shrink-0 mr-2"}):y.jsx(Ei,{className:"w-6 h-6 shrink-0 mr-2"}),y.jsx("span",{className:"truncate",children:e.name})]}),y.jsx("div",{className:ye("flex flex-col bg-[#272727]",!n&&"h-0 overflow-hidden"),children:e.inputs.map(s=>y.jsx(tp,{input:s,isCurrentlyInsideReactFlow:t,hide:!n},s.id))})]},e.id));sS.displayName="RenderInputPanel";const np=T.forwardRef(({id:e,name:t="Node",headerColor:n="#79461D",inputs:r=[],outputs:i=[],isCurrentlyInsideReactFlow:s=!1,className:a,nodeResizerProps:l={},nodeTypeUniqueId:u,showNodeOpenButton:d=!1,runnerVisualState:f,runnerErrors:g,runnerWarnings:h,...m},x)=>{const[v,b]=T.useState(new Set),S=T.useContext(uo),N=I=>{b(k=>{const A=new Set(k);return A.has(I)?A.delete(I):A.add(I),A})},w=y.jsxs("div",{tabIndex:0,className:ye("flex flex-col gap-0 rounded-md w-max border-[1.5px] border-transparent focus:border-white","in-[.selected]:border-white",a),...m,ref:x,children:[y.jsxs("div",{className:`text-primary-white text-left text-[27px] leading-[27px] font-main \\
|
|
305
305
|
px-4 transition-all rounded-t-md truncate flex justify-between items-center`,style:{backgroundColor:n},children:[y.jsx("p",{className:"truncate py-2",children:t}),S?.allProps?.state?.enableDebugMode&&y.jsx("p",{className:"shrink-0 py-2",children:e}),y.jsx(oS,{showButton:d,isCurrentlyInsideReactFlow:s})]}),y.jsxs("div",{className:"min-h-[50px] rounded-b-md bg-primary-dark-gray",children:[s&&y.jsx(kw,{...l}),y.jsx("div",{className:"flex flex-col py-4",children:i.map(I=>y.jsx(iS,{output:I,isCurrentlyInsideReactFlow:s},I.id))}),y.jsx("div",{className:"flex flex-col py-4",children:r.map(I=>{if("inputs"in I){const k=v.has(I.id);return y.jsx(sS,{panel:I,isCurrentlyInsideReactFlow:s,isOpen:k,onToggle:()=>N(I.id)},I.id)}else return y.jsx(tp,{input:I,isCurrentlyInsideReactFlow:s},I.id)})})]})]});return f!==void 0?y.jsx(ab,{visualState:f,errors:g,warnings:h,children:w}):w});np.displayName="ConfigurableNode";const rp=T.forwardRef(({data:e={},id:t},n)=>{const i=T.useContext(uo)?.nodeRunnerStates?.get(t);return y.jsx(np,{isCurrentlyInsideReactFlow:!0,id:t,className:"w-full",...e,runnerVisualState:i?.visualState,runnerErrors:i?.errors,runnerWarnings:i?.warnings,ref:n})});rp.displayName="ConfigurableNodeReactFlowWrapper",fe.Accordion=Fy,fe.AccordionContent=od,fe.AccordionItem=nd,fe.AccordionTrigger=rd,fe.Button=Qn,fe.ButtonToggle=zf,fe.ConfigurableEdge=_f,fe.ConfigurableNode=np,fe.ConfigurableNodeReactFlowWrapper=rp,fe.ContextAwareHandle=nl,fe.ContextAwareInput=nS,fe.ContextAwareOpenButton=oS,fe.ContextMenu=pb,fe.ExecutionStepInspector=$b,fe.ExecutionTimeline=jb,fe.FullGraph=ej,fe.FullGraphContext=uo,fe.Input=ws,fe.NodeResizerWithMoreControls=kw,fe.NodeStatusIndicator=ab,fe.ReactFlowAwareInput=tS,fe.ReactFlowAwareOpenButton=rS,fe.RecordContext=bf,fe.RunControls=wb,fe.ScrollableButtonContainer=Rf,fe.Select=yb,fe.SelectContent=Vf,fe.SelectGroup=X2,fe.SelectItem=qc,fe.SelectLabel=vb,fe.SelectScrollDownButton=Bf,fe.SelectScrollUpButton=Hf,fe.SelectSeparator=xb,fe.SelectTrigger=$f,fe.SelectValue=Ff,fe.SliderNumberInput=ni,fe.Tooltip=sn,fe.actionTypesMap=ft,fe.addAnInputOrOutputToAllNodesOfANodeTypeAcrossStateIncludingSubtrees=dw,fe.addEdgeWithTypeChecking=aw,fe.cn=ye,fe.constructInputOrOutputOfType=Tr,fe.constructInputPanelOfType=J0,fe.constructNodeOfType=ps,fe.constructTypeOfHandleFromIndices=Cr,fe.convertStringToNumber=Gy,fe.createContextValue=Sf,fe.createNodeContextMenu=mb,fe.deserializeExecutionRecord=vf,fe.deserializeGraphError=mf,fe.exportExecutionRecord=Nw,fe.exportGraphState=bw,fe.getAllDependenciesOfNodeTypeRecursively=EL,fe.getAllDependentsOfNodeTypeRecursively=ew,fe.getCurrentNodesAndEdgesFromState=Mt,fe.getDependencyGraphBetweenNodeTypes=hs,fe.getDirectDependenciesOfNodeType=Q0,fe.getDirectDependentsOfNodeType=af,fe.getResultantDataTypeOfHandleConsideringInferredType=lo,fe.groupNodeContextMenu=ow,fe.handleShapesMap=Ct,fe.importExecutionRecord=Ew,fe.importGraphState=Iw,fe.isCoordinateInBox=Wy,fe.isNumberInRange=id,fe.isSupportedUnderlyingType=uC,fe.isValidDataTypeId=fC,fe.loopEndInputInferHandleIndex=Lc,fe.loopEndOutputInferHandleIndex=Dc,fe.loopStartInputInferHandleIndex=Mc,fe.loopStartOutputInferHandleIndex=Oc,fe.loopStopInputInferHandleIndex=Pc,fe.loopStopOutputInferHandleIndex=Rc,fe.mainReducer=fw,fe.makeAllowedConversionsBetweenDataTypesWithAutoInfer=hC,fe.makeDataTypeWithAutoInfer=dC,fe.makeStateWithAutoInfer=gC,fe.makeTypeOfNodeWithAutoInfer=pC,fe.mapToRecord=hf,fe.recordToReadonlyMap=vs,fe.removeEdgeWithTypeChecking=cw,fe.safeSerializeValue=Vn,fe.sanitizeNumberToShowAsText=sd,fe.serializeExecutionRecord=yf,fe.serializeGraphError=gf,fe.setCurrentNodesAndEdgesToStateWithMutatingState=so,fe.standardDataTypeNames=ir,fe.standardDataTypeNamesMap=ze,fe.standardDataTypes=ML,fe.standardNodeContextMenu=Qo,fe.standardNodeTypeNames=In,fe.standardNodeTypeNamesMap=Te,fe.standardNodeTypes=OL,fe.supportedUnderlyingTypesMap=qy,fe.useAutoScroll=cb,fe.useClickedOutside=Aw,fe.useDrag=lb,fe.useFloatingTooltip=ob,fe.useFullGraph=JL,fe.useRecordContext=Tw,fe.useResizeHandle=Jb,fe.useSlideAnimation=Qf,fe.validateExecutionRecordStructure=mw,fe.validateGraphStateStructure=pw,fe.willAddingEdgeCreateCycle=lw,Object.defineProperty(fe,Symbol.toStringTag,{value:"Module"})});
|