@dilipod/ui 0.4.33 → 0.4.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import { clsx } from 'clsx';
10
10
  import { twMerge } from 'tailwind-merge';
11
11
  import * as SheetPrimitive from '@radix-ui/react-dialog';
12
12
  import * as react_star from '@phosphor-icons/react';
13
- import { X, CaretDown, Circle, CaretLeft, DotsThree, CaretRight, Check, House, Info, WarningCircle, Play, Download, Folder, ArrowSquareOut, CircleNotch, File, FileVideo, Lightning, CheckCircle, CaretUp, Plus, PaperPlaneTilt, Eye, TreeStructure, Code, PencilSimple, WebhooksLogo, Copy, CloudArrowUp, CloudArrowDown, ArrowsClockwise, DownloadSimple, ClockCounterClockwise, ArrowsLeftRight, Minus, Pencil, Robot, MagnifyingGlass, FilmStrip, FileText, ImageSquare, TextT, Target, Crosshair, ListNumbers, Wrench, Clock, TrendUp, CurrencyEur, Sparkle, Plugs, ShieldCheck, FileImage, FilePdf, FileDoc, Question, Warning, Trash, Globe, GitBranch, Package, Timer, VideoCamera, Lightbulb } from '@phosphor-icons/react';
13
+ import { X, CaretDown, Circle, CaretLeft, DotsThree, CaretRight, Check, House, Info, WarningCircle, CircleNotch, Play, Download, Folder, ArrowSquareOut, File, FileVideo, Lightning, CheckCircle, CaretUp, Plus, PaperPlaneTilt, Eye, TreeStructure, Code, PencilSimple, WebhooksLogo, Copy, CloudArrowUp, CloudArrowDown, ArrowsClockwise, DownloadSimple, ClockCounterClockwise, ArrowsLeftRight, Minus, Pencil, Robot, MagnifyingGlass, FilmStrip, FileText, ImageSquare, TextT, Target, Crosshair, ListNumbers, Wrench, Clock, TrendUp, CurrencyEur, Sparkle, Plugs, ShieldCheck, FileImage, FilePdf, FileDoc, Question, Warning, Trash, Globe, GitBranch, Package, Timer, VideoCamera, Lightbulb } from '@phosphor-icons/react';
14
14
  import 'react-dom';
15
15
  import * as SwitchPrimitive from '@radix-ui/react-switch';
16
16
  import * as SliderPrimitive from '@radix-ui/react-slider';
@@ -652,7 +652,7 @@ var sheetVariants = cva(
652
652
  }
653
653
  }
654
654
  );
655
- var SheetContent = React51.forwardRef(({ side = "right", className, children, ...props }, ref) => /* @__PURE__ */ jsxs(SheetPortal, { children: [
655
+ var SheetContent = React51.forwardRef(({ side = "right", className, children, hideClose, ...props }, ref) => /* @__PURE__ */ jsxs(SheetPortal, { children: [
656
656
  /* @__PURE__ */ jsx(SheetOverlay, {}),
657
657
  /* @__PURE__ */ jsxs(
658
658
  SheetPrimitive.Content,
@@ -662,6 +662,7 @@ var SheetContent = React51.forwardRef(({ side = "right", className, children, ..
662
662
  ...props,
663
663
  children: [
664
664
  children,
665
+ !hideClose && // @ts-expect-error - Radix Dialog Close accepts className and children at runtime
665
666
  /* @__PURE__ */ jsxs(SheetPrimitive.Close, { className: "absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none data-[state=open]:bg-gray-100", children: [
666
667
  /* @__PURE__ */ jsx(X, { className: "h-4 w-4" }),
667
668
  /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
@@ -3956,7 +3957,8 @@ function FilePreview({
3956
3957
  const FileIcon = getFileIcon(file.type);
3957
3958
  const typeLabel = getTypeLabel(file.type);
3958
3959
  const sizeLabel = formatSize(file.size);
3959
- const isPreviewable = canPreview(file);
3960
+ const isProcessing = file.processing === true;
3961
+ const isPreviewable = !isProcessing && canPreview(file);
3960
3962
  const previewType = getPreviewType(file);
3961
3963
  return /* @__PURE__ */ jsxs(
3962
3964
  "div",
@@ -3966,20 +3968,20 @@ function FilePreview({
3966
3968
  children: [
3967
3969
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 min-w-0", children: [
3968
3970
  /* @__PURE__ */ jsxs("div", { className: "relative shrink-0", children: [
3969
- /* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-sm bg-white border border-gray-200 flex items-center justify-center", children: /* @__PURE__ */ jsx(FileIcon, { className: "w-5 h-5 text-[var(--cyan)]", weight: "fill" }) }),
3970
- previewType === "video" && /* @__PURE__ */ jsx(Play, { className: "absolute -bottom-0.5 -right-0.5 w-3.5 h-3.5 text-[var(--cyan)] bg-white rounded-full", weight: "fill" })
3971
+ /* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-sm bg-white border border-gray-200 flex items-center justify-center", children: isProcessing ? /* @__PURE__ */ jsx(CircleNotch, { className: "w-5 h-5 text-[var(--cyan)] animate-spin" }) : /* @__PURE__ */ jsx(FileIcon, { className: "w-5 h-5 text-[var(--cyan)]", weight: "fill" }) }),
3972
+ !isProcessing && previewType === "video" && /* @__PURE__ */ jsx(Play, { className: "absolute -bottom-0.5 -right-0.5 w-3.5 h-3.5 text-[var(--cyan)] bg-white rounded-full", weight: "fill" })
3971
3973
  ] }),
3972
3974
  /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
3973
3975
  /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-[var(--black)] truncate", children: file.filename }),
3974
- /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
3976
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: isProcessing ? /* @__PURE__ */ jsx("span", { className: "text-amber-600", children: "Processing video \u2014 this takes about a minute" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3975
3977
  typeLabel,
3976
3978
  " \xB7 ",
3977
3979
  sizeLabel,
3978
3980
  isPreviewable && /* @__PURE__ */ jsx("span", { className: "text-[var(--cyan)] ml-1", children: "\xB7 Click to preview" })
3979
- ] })
3981
+ ] }) })
3980
3982
  ] })
3981
3983
  ] }),
3982
- /* @__PURE__ */ jsx(
3984
+ !isProcessing && /* @__PURE__ */ jsx(
3983
3985
  "button",
3984
3986
  {
3985
3987
  onClick: (e) => handleDownload(e, file),
@@ -6252,190 +6254,383 @@ function WorkflowViewer({
6252
6254
  ] })
6253
6255
  ] });
6254
6256
  }
6255
- function parseMermaidFlowchart(mermaid) {
6256
- const nodes = /* @__PURE__ */ new Map();
6257
- const edges = [];
6258
- const lines = mermaid.split(/\\n|\n/).map((l) => l.trim()).filter((l) => l && !l.startsWith("flowchart") && !l.startsWith("graph"));
6259
- function parseNodeDef(str) {
6260
- const decisionMatch = str.match(/^([A-Za-z0-9_]+)\{(.+?)\}$/);
6261
- if (decisionMatch) return { id: decisionMatch[1], label: decisionMatch[2], type: "decision" };
6262
- const bracketMatch = str.match(/^([A-Za-z0-9_]+)\[?\(?\[?(.+?)\]?\)?\]?$/);
6263
- if (bracketMatch) {
6264
- const label = bracketMatch[2];
6265
- const isTerminal = /^(start|end|begin|finish|done)$/i.test(label);
6266
- return { id: bracketMatch[1], label, type: isTerminal ? "terminal" : "action" };
6257
+ var NODE_WIDTH = 180;
6258
+ var NODE_HEIGHT = 44;
6259
+ var DIAMOND_SIZE = 72;
6260
+ var X_GAP = 50;
6261
+ var Y_GAP = 64;
6262
+ var PADDING = 40;
6263
+ var FONT_SIZE = 11;
6264
+ var CHAR_WIDTH = 6.2;
6265
+ var LINE_HEIGHT = 14;
6266
+ function stripQuotes(s) {
6267
+ const t = s.trim();
6268
+ if (t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'")) {
6269
+ return t.slice(1, -1);
6270
+ }
6271
+ return t;
6272
+ }
6273
+ function parseNodeRef(raw) {
6274
+ const s = raw.trim();
6275
+ const decision = s.match(/^([A-Za-z0-9_]+)\{(.+)\}$/);
6276
+ if (decision) return { id: decision[1], label: stripQuotes(decision[2]), type: "decision" };
6277
+ const stadium = s.match(/^([A-Za-z0-9_]+)\(\[(.+)\]\)$/);
6278
+ if (stadium) return { id: stadium[1], label: stripQuotes(stadium[2]), type: "terminal" };
6279
+ const circle = s.match(/^([A-Za-z0-9_]+)\(\((.+)\)\)$/);
6280
+ if (circle) return { id: circle[1], label: stripQuotes(circle[2]), type: "terminal" };
6281
+ const rounded = s.match(/^([A-Za-z0-9_]+)\(([^[(].+?)\)$/);
6282
+ if (rounded) return { id: rounded[1], label: stripQuotes(rounded[2]), type: "action" };
6283
+ const rect = s.match(/^([A-Za-z0-9_]+)\[([^(].+?)\]$/);
6284
+ if (rect) {
6285
+ const label = stripQuotes(rect[2]);
6286
+ const isTerminal = /^(start|end|begin|finish|done|stop)$/i.test(label);
6287
+ return { id: rect[1], label, type: isTerminal ? "terminal" : "action" };
6288
+ }
6289
+ const bareId = s.match(/^([A-Za-z0-9_]+)$/);
6290
+ if (bareId) return { id: bareId[1] };
6291
+ return { id: s };
6292
+ }
6293
+ function registerNode(map, ref) {
6294
+ if (!ref.id) return;
6295
+ const existing = map.get(ref.id);
6296
+ if (existing) {
6297
+ if (ref.label && existing.label === existing.id) {
6298
+ existing.label = ref.label;
6267
6299
  }
6268
- return { id: str.trim() };
6300
+ if (ref.type && ref.type !== "action" && existing.type === "action") {
6301
+ existing.type = ref.type;
6302
+ }
6303
+ return;
6269
6304
  }
6305
+ map.set(ref.id, {
6306
+ id: ref.id,
6307
+ label: ref.label || ref.id,
6308
+ type: ref.type || "action"
6309
+ });
6310
+ }
6311
+ function parseMermaidFlowchart(mermaid) {
6312
+ const nodeMap = /* @__PURE__ */ new Map();
6313
+ const edges = [];
6314
+ const lines = mermaid.split(/\\n|\n/).map((l) => l.trim()).filter((l) => l && !l.startsWith("%%"));
6270
6315
  for (const line of lines) {
6271
- const edgeMatch = line.match(/^(.+?)\s*-->(?:\|(.+?)\|)?\s*(.+)$/);
6272
- if (!edgeMatch) continue;
6273
- const leftRaw = edgeMatch[1].trim();
6274
- const edgeLabel = edgeMatch[2]?.trim();
6275
- const rightRaw = edgeMatch[3].trim();
6276
- const left = parseNodeDef(leftRaw);
6277
- const right = parseNodeDef(rightRaw);
6278
- if (left.label && !nodes.has(left.id)) {
6279
- nodes.set(left.id, { id: left.id, label: left.label, type: left.type || "action" });
6316
+ if (/^(flowchart|graph|subgraph|end|style|classDef|class|click|linkStyle)\b/i.test(line)) continue;
6317
+ const edgeMatch = line.match(
6318
+ /^(.+?)\s*(?:-->|==>|-\.->|---)\s*(?:\|([^|]*)\|)?\s*(.+)$/
6319
+ );
6320
+ if (edgeMatch) {
6321
+ const leftNode = parseNodeRef(edgeMatch[1].trim());
6322
+ const edgeLabel = edgeMatch[2]?.trim() || void 0;
6323
+ const rightNode = parseNodeRef(edgeMatch[3].trim());
6324
+ registerNode(nodeMap, leftNode);
6325
+ registerNode(nodeMap, rightNode);
6326
+ edges.push({ from: leftNode.id, to: rightNode.id, label: edgeLabel });
6327
+ continue;
6280
6328
  }
6281
- if (right.label && !nodes.has(right.id)) {
6282
- nodes.set(right.id, { id: right.id, label: right.label, type: right.type || "action" });
6329
+ const nodeDef = parseNodeRef(line);
6330
+ if (nodeDef.label) {
6331
+ registerNode(nodeMap, nodeDef);
6283
6332
  }
6284
- if (!nodes.has(left.id)) {
6285
- nodes.set(left.id, { id: left.id, label: left.id, type: "action" });
6333
+ }
6334
+ return { nodes: Array.from(nodeMap.values()), edges };
6335
+ }
6336
+ function computeLayout(nodes, edges) {
6337
+ if (nodes.length === 0) return { layoutNodes: [], svgWidth: 0, svgHeight: 0 };
6338
+ const forward = /* @__PURE__ */ new Map();
6339
+ const backward = /* @__PURE__ */ new Map();
6340
+ for (const e of edges) {
6341
+ if (!forward.has(e.from)) forward.set(e.from, []);
6342
+ forward.get(e.from).push(e.to);
6343
+ if (!backward.has(e.to)) backward.set(e.to, []);
6344
+ backward.get(e.to).push(e.from);
6345
+ }
6346
+ const roots = nodes.filter((n) => !backward.has(n.id) || backward.get(n.id).length === 0);
6347
+ if (roots.length === 0) roots.push(nodes[0]);
6348
+ const layers = /* @__PURE__ */ new Map();
6349
+ const queue = [];
6350
+ for (const r of roots) {
6351
+ layers.set(r.id, 0);
6352
+ queue.push(r.id);
6353
+ }
6354
+ const visited = /* @__PURE__ */ new Set();
6355
+ while (queue.length > 0) {
6356
+ const id = queue.shift();
6357
+ if (visited.has(id)) continue;
6358
+ visited.add(id);
6359
+ const myLayer = layers.get(id) || 0;
6360
+ for (const child of forward.get(id) || []) {
6361
+ const childLayer = layers.get(child);
6362
+ if (childLayer === void 0 || myLayer + 1 > childLayer) {
6363
+ layers.set(child, myLayer + 1);
6364
+ }
6365
+ if (!visited.has(child)) queue.push(child);
6286
6366
  }
6287
- if (!nodes.has(right.id)) {
6288
- nodes.set(right.id, { id: right.id, label: right.id, type: "action" });
6367
+ }
6368
+ const maxLayer = Math.max(0, ...Array.from(layers.values()));
6369
+ for (const n of nodes) {
6370
+ if (!layers.has(n.id)) layers.set(n.id, maxLayer + 1);
6371
+ }
6372
+ const nodesByLayer = /* @__PURE__ */ new Map();
6373
+ for (const n of nodes) {
6374
+ const layer = layers.get(n.id);
6375
+ if (!nodesByLayer.has(layer)) nodesByLayer.set(layer, []);
6376
+ nodesByLayer.get(layer).push(n);
6377
+ }
6378
+ const sortedLayers = Array.from(nodesByLayer.keys()).sort((a, b) => a - b);
6379
+ const posInLayer = /* @__PURE__ */ new Map();
6380
+ for (let li = 0; li < sortedLayers.length; li++) {
6381
+ const layer = sortedLayers[li];
6382
+ const nodesInLayer = nodesByLayer.get(layer);
6383
+ if (li > 0) {
6384
+ nodesInLayer.sort((a, b) => {
6385
+ const parentsA = backward.get(a.id) || [];
6386
+ const parentsB = backward.get(b.id) || [];
6387
+ const avgA = parentsA.length > 0 ? parentsA.reduce((s, p) => s + (posInLayer.get(p) ?? 0), 0) / parentsA.length : 0;
6388
+ const avgB = parentsB.length > 0 ? parentsB.reduce((s, p) => s + (posInLayer.get(p) ?? 0), 0) / parentsB.length : 0;
6389
+ return avgA - avgB;
6390
+ });
6289
6391
  }
6290
- edges.push({ from: left.id, to: right.id, label: edgeLabel });
6392
+ nodesInLayer.forEach((n, i) => posInLayer.set(n.id, i));
6393
+ }
6394
+ const layoutNodes = [];
6395
+ for (const layer of sortedLayers) {
6396
+ const nodesInLayer = nodesByLayer.get(layer);
6397
+ const widths = nodesInLayer.map((n) => nodeWidth(n));
6398
+ const heights = nodesInLayer.map((n) => nodeHeight(n));
6399
+ const totalWidth = widths.reduce((s, w) => s + w, 0) + (nodesInLayer.length - 1) * X_GAP;
6400
+ let startX = -totalWidth / 2;
6401
+ nodesInLayer.forEach((n, i) => {
6402
+ layoutNodes.push({
6403
+ id: n.id,
6404
+ x: startX + widths[i] / 2,
6405
+ y: layer * (NODE_HEIGHT + Y_GAP),
6406
+ width: widths[i],
6407
+ height: heights[i],
6408
+ layer,
6409
+ node: n
6410
+ });
6411
+ startX += widths[i] + X_GAP;
6412
+ });
6291
6413
  }
6292
- return { nodes: Array.from(nodes.values()), edges };
6414
+ const minX = Math.min(...layoutNodes.map((n) => n.x - n.width / 2));
6415
+ const minY = Math.min(...layoutNodes.map((n) => n.y - n.height / 2));
6416
+ const offsetX = PADDING - minX;
6417
+ const offsetY = PADDING - minY;
6418
+ for (const n of layoutNodes) {
6419
+ n.x += offsetX;
6420
+ n.y += offsetY;
6421
+ }
6422
+ const svgWidth = Math.max(...layoutNodes.map((n) => n.x + n.width / 2)) + PADDING;
6423
+ const svgHeight = Math.max(...layoutNodes.map((n) => n.y + n.height / 2)) + PADDING;
6424
+ return { layoutNodes, svgWidth, svgHeight };
6425
+ }
6426
+ function nodeWidth(n) {
6427
+ if (n.type === "decision") return Math.max(DIAMOND_SIZE * 1.4, 100);
6428
+ const textWidth = n.label.length * CHAR_WIDTH + 32;
6429
+ return Math.max(100, Math.min(NODE_WIDTH, textWidth));
6293
6430
  }
6294
- function findMergePoint(branchStarts, outgoing) {
6295
- const reachable = /* @__PURE__ */ new Map();
6296
- for (const start of branchStarts) {
6297
- const q2 = [start];
6298
- const seen2 = /* @__PURE__ */ new Set();
6299
- while (q2.length > 0) {
6300
- const id = q2.shift();
6301
- if (seen2.has(id)) continue;
6302
- seen2.add(id);
6303
- if (!reachable.has(id)) reachable.set(id, /* @__PURE__ */ new Set());
6304
- reachable.get(id).add(start);
6305
- const outs = outgoing.get(id) || [];
6306
- for (const e of outs) q2.push(e.to);
6431
+ function nodeHeight(n) {
6432
+ if (n.type === "decision") return DIAMOND_SIZE;
6433
+ const w = nodeWidth(n);
6434
+ const lines = wrapText(n.label, w - 24);
6435
+ return Math.max(NODE_HEIGHT, lines.length * LINE_HEIGHT + 16);
6436
+ }
6437
+ function wrapText(text, maxPixelWidth) {
6438
+ const charsPerLine = Math.max(8, Math.floor(maxPixelWidth / CHAR_WIDTH));
6439
+ if (text.length <= charsPerLine) return [text];
6440
+ const words = text.split(" ");
6441
+ const lines = [];
6442
+ let cur = "";
6443
+ for (const word of words) {
6444
+ const test = cur ? `${cur} ${word}` : word;
6445
+ if (test.length > charsPerLine && cur) {
6446
+ lines.push(cur);
6447
+ cur = word;
6448
+ } else {
6449
+ cur = test;
6307
6450
  }
6308
6451
  }
6309
- const allBranches = new Set(branchStarts);
6310
- const q = [branchStarts[0]];
6311
- const seen = /* @__PURE__ */ new Set();
6312
- while (q.length > 0) {
6313
- const id = q.shift();
6314
- if (seen.has(id)) continue;
6315
- seen.add(id);
6316
- if (!allBranches.has(id) && reachable.get(id)?.size === branchStarts.length) {
6317
- return id;
6452
+ if (cur) lines.push(cur);
6453
+ if (lines.length > 3) {
6454
+ lines.length = 3;
6455
+ lines[2] = lines[2].slice(0, -1) + "\u2026";
6456
+ }
6457
+ return lines;
6458
+ }
6459
+ function computeEdgePath(from, to) {
6460
+ let startX = from.x;
6461
+ let startY = from.y + from.height / 2;
6462
+ if (from.node.type === "decision") {
6463
+ const dx = to.x - from.x;
6464
+ const halfDiamond = DIAMOND_SIZE / 2;
6465
+ if (Math.abs(dx) > halfDiamond) {
6466
+ startX = from.x + (dx > 0 ? halfDiamond : -halfDiamond);
6467
+ startY = from.y;
6318
6468
  }
6319
- const outs = outgoing.get(id) || [];
6320
- for (const e of outs) q.push(e.to);
6321
6469
  }
6322
- return null;
6470
+ const endX = to.x;
6471
+ const endY = to.y - to.height / 2;
6472
+ const midY = (startY + endY) / 2;
6473
+ return `M ${startX} ${startY} C ${startX} ${midY}, ${endX} ${midY}, ${endX} ${endY}`;
6323
6474
  }
6324
- function buildLayout(startId, outgoing, incoming, nodeMap, visited) {
6325
- const items = [];
6326
- let currentId = startId;
6327
- while (currentId) {
6328
- if (visited.has(currentId)) break;
6329
- const node = nodeMap.get(currentId);
6330
- if (!node) break;
6331
- const outs = outgoing.get(currentId) || [];
6332
- if (outs.length <= 1) {
6333
- visited.add(currentId);
6334
- items.push({ type: "node", nodeId: currentId });
6335
- if (outs.length === 1) {
6336
- const nextId = outs[0].to;
6337
- if (visited.has(nextId)) break;
6338
- items.push({ type: "arrow", label: outs[0].label });
6339
- currentId = nextId;
6340
- } else {
6341
- currentId = null;
6342
- }
6343
- } else {
6344
- visited.add(currentId);
6345
- items.push({ type: "node", nodeId: currentId });
6346
- const branchStarts = outs.map((e) => e.to);
6347
- const mergeId = findMergePoint(branchStarts, outgoing);
6348
- const branches = [];
6349
- for (const edge of outs) {
6350
- if (visited.has(edge.to) && edge.to !== mergeId) {
6351
- branches.push({ label: edge.label, items: [] });
6352
- continue;
6353
- }
6354
- const branchItems = buildLayout(edge.to, outgoing, incoming, nodeMap, visited);
6355
- branches.push({ label: edge.label, items: branchItems });
6356
- }
6357
- items.push({ type: "branch", decision: currentId, branches, mergeId });
6358
- if (mergeId && !visited.has(mergeId)) {
6359
- items.push({ type: "arrow" });
6360
- currentId = mergeId;
6361
- } else {
6362
- currentId = null;
6475
+ function SvgDefs() {
6476
+ return /* @__PURE__ */ jsxs("defs", { children: [
6477
+ /* @__PURE__ */ jsx(
6478
+ "marker",
6479
+ {
6480
+ id: "fc-arrowhead",
6481
+ viewBox: "0 0 10 7",
6482
+ refX: "10",
6483
+ refY: "3.5",
6484
+ markerWidth: "8",
6485
+ markerHeight: "6",
6486
+ orient: "auto-start-reverse",
6487
+ children: /* @__PURE__ */ jsx("polygon", { points: "0 0, 10 3.5, 0 7", fill: "#D1D5DB" })
6363
6488
  }
6489
+ ),
6490
+ /* @__PURE__ */ jsx("filter", { id: "fc-shadow", x: "-4%", y: "-4%", width: "108%", height: "116%", children: /* @__PURE__ */ jsx("feDropShadow", { dx: "0", dy: "1", stdDeviation: "1.5", floodOpacity: "0.07" }) })
6491
+ ] });
6492
+ }
6493
+ function TextBlock({ lines, x, y, fill, fontSize }) {
6494
+ const startY = y - (lines.length - 1) * LINE_HEIGHT / 2;
6495
+ return /* @__PURE__ */ jsx(
6496
+ "text",
6497
+ {
6498
+ x,
6499
+ textAnchor: "middle",
6500
+ fill,
6501
+ style: { fontSize: `${fontSize}px`, fontFamily: "var(--font-outfit, system-ui, sans-serif)", fontWeight: 500 },
6502
+ children: lines.map((line, i) => /* @__PURE__ */ jsx("tspan", { x, y: startY + i * LINE_HEIGHT, children: line }, i))
6364
6503
  }
6365
- }
6366
- return items;
6504
+ );
6367
6505
  }
6368
- function FlowArrow({ label }) {
6369
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center", children: [
6370
- label && /* @__PURE__ */ jsx("span", { className: "text-[10px] font-medium text-purple-600 bg-purple-50 px-1.5 py-0.5 rounded mb-0.5", children: label }),
6371
- /* @__PURE__ */ jsx("div", { className: "w-px h-4 bg-gray-300" }),
6372
- /* @__PURE__ */ jsx("div", { className: "w-0 h-0 border-l-[4px] border-r-[4px] border-t-[5px] border-l-transparent border-r-transparent border-t-gray-300" })
6506
+ function ActionNodeSvg({ n }) {
6507
+ const lines = wrapText(n.node.label, n.width - 24);
6508
+ return /* @__PURE__ */ jsxs("g", { children: [
6509
+ /* @__PURE__ */ jsx(
6510
+ "rect",
6511
+ {
6512
+ x: n.x - n.width / 2,
6513
+ y: n.y - n.height / 2,
6514
+ width: n.width,
6515
+ height: n.height,
6516
+ rx: 3,
6517
+ fill: "white",
6518
+ stroke: "#E5E7EB",
6519
+ strokeWidth: 1,
6520
+ filter: "url(#fc-shadow)"
6521
+ }
6522
+ ),
6523
+ /* @__PURE__ */ jsx(TextBlock, { lines, x: n.x, y: n.y, fill: "#0A0A0A", fontSize: FONT_SIZE })
6373
6524
  ] });
6374
6525
  }
6375
- function FlowNodeBox({ node }) {
6376
- if (node.type === "decision") {
6377
- return /* @__PURE__ */ jsxs(
6378
- "div",
6526
+ function DecisionNodeSvg({ n }) {
6527
+ const half = DIAMOND_SIZE / 2;
6528
+ const points = `${n.x},${n.y - half} ${n.x + half},${n.y} ${n.x},${n.y + half} ${n.x - half},${n.y}`;
6529
+ const lines = wrapText(n.node.label, DIAMOND_SIZE - 16);
6530
+ return /* @__PURE__ */ jsxs("g", { children: [
6531
+ /* @__PURE__ */ jsx(
6532
+ "polygon",
6379
6533
  {
6380
- className: "bg-amber-50 border-2 border-amber-300 rounded-lg px-4 py-2.5 text-xs font-medium text-amber-800 text-center my-1",
6381
- style: { minWidth: "120px" },
6382
- children: [
6383
- /* @__PURE__ */ jsx("span", { className: "text-amber-400 mr-1", children: "\u25C7" }),
6384
- node.label
6385
- ]
6534
+ points,
6535
+ fill: "#FFFBEB",
6536
+ stroke: "#FCD34D",
6537
+ strokeWidth: 2
6386
6538
  }
6387
- );
6388
- }
6389
- if (node.type === "terminal") {
6390
- return /* @__PURE__ */ jsx("div", { className: "bg-gray-100 border border-gray-200 rounded-full px-5 py-1.5 text-xs font-medium text-gray-500 text-center my-1", children: node.label });
6391
- }
6392
- return /* @__PURE__ */ jsx("div", { className: "bg-white border border-gray-200 rounded-sm px-4 py-2 text-xs font-medium text-[var(--black)] text-center shadow-sm my-1 max-w-[220px]", children: node.label });
6539
+ ),
6540
+ /* @__PURE__ */ jsx(TextBlock, { lines, x: n.x, y: n.y, fill: "#92400E", fontSize: 10 })
6541
+ ] });
6393
6542
  }
6394
- function RenderLayoutItems({ items, nodeMap }) {
6395
- return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, i) => {
6396
- if (item.type === "node") {
6397
- const node = nodeMap.get(item.nodeId);
6398
- if (!node) return null;
6399
- return /* @__PURE__ */ jsx(FlowNodeBox, { node }, `node-${item.nodeId}`);
6400
- }
6401
- if (item.type === "arrow") {
6402
- return /* @__PURE__ */ jsx(FlowArrow, { label: item.label }, `arrow-${i}`);
6403
- }
6404
- if (item.type === "branch") {
6405
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center w-full", children: [
6406
- /* @__PURE__ */ jsx("div", { className: "w-px h-3 bg-gray-300" }),
6407
- /* @__PURE__ */ jsx("div", { className: "flex items-start justify-center gap-6 w-full", children: item.branches.map((branch, j) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center min-w-[100px]", children: [
6408
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center", children: [
6409
- branch.label && /* @__PURE__ */ jsx("span", { className: "text-[10px] font-medium text-purple-600 bg-purple-50 px-1.5 py-0.5 rounded mb-1", children: branch.label }),
6410
- /* @__PURE__ */ jsx("div", { className: "w-0 h-0 border-l-[4px] border-r-[4px] border-t-[5px] border-l-transparent border-r-transparent border-t-gray-300" })
6411
- ] }),
6412
- /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center", children: /* @__PURE__ */ jsx(RenderLayoutItems, { items: branch.items, nodeMap }) })
6413
- ] }, j)) }),
6414
- item.mergeId && /* @__PURE__ */ jsx("div", { className: "w-px h-3 bg-gray-300" })
6415
- ] }, `branch-${item.decision}-${i}`);
6416
- }
6417
- return null;
6418
- }) });
6543
+ function TerminalNodeSvg({ n }) {
6544
+ return /* @__PURE__ */ jsxs("g", { children: [
6545
+ /* @__PURE__ */ jsx(
6546
+ "rect",
6547
+ {
6548
+ x: n.x - n.width / 2,
6549
+ y: n.y - n.height / 2,
6550
+ width: n.width,
6551
+ height: n.height,
6552
+ rx: n.height / 2,
6553
+ fill: "#F3F4F6",
6554
+ stroke: "#E5E7EB",
6555
+ strokeWidth: 1
6556
+ }
6557
+ ),
6558
+ /* @__PURE__ */ jsx(TextBlock, { lines: [n.node.label], x: n.x, y: n.y, fill: "#6B7280", fontSize: FONT_SIZE })
6559
+ ] });
6560
+ }
6561
+ function EdgeSvg({ from, to, label }) {
6562
+ const path = computeEdgePath(from, to);
6563
+ const midX = (from.x + to.x) / 2;
6564
+ const midY = (from.y + from.height / 2 + to.y - to.height / 2) / 2;
6565
+ return /* @__PURE__ */ jsxs("g", { children: [
6566
+ /* @__PURE__ */ jsx(
6567
+ "path",
6568
+ {
6569
+ d: path,
6570
+ fill: "none",
6571
+ stroke: "#D1D5DB",
6572
+ strokeWidth: 1.5,
6573
+ markerEnd: "url(#fc-arrowhead)"
6574
+ }
6575
+ ),
6576
+ label && /* @__PURE__ */ jsxs("g", { children: [
6577
+ /* @__PURE__ */ jsx(
6578
+ "rect",
6579
+ {
6580
+ x: midX - label.length * CHAR_WIDTH / 2 - 6,
6581
+ y: midY - 9,
6582
+ width: label.length * CHAR_WIDTH + 12,
6583
+ height: 18,
6584
+ rx: 9,
6585
+ fill: "#F5F3FF"
6586
+ }
6587
+ ),
6588
+ /* @__PURE__ */ jsx(
6589
+ "text",
6590
+ {
6591
+ x: midX,
6592
+ y: midY + 1,
6593
+ textAnchor: "middle",
6594
+ dominantBaseline: "central",
6595
+ fill: "#7C3AED",
6596
+ style: { fontSize: "10px", fontFamily: "var(--font-outfit, system-ui, sans-serif)", fontWeight: 500 },
6597
+ children: label
6598
+ }
6599
+ )
6600
+ ] })
6601
+ ] });
6419
6602
  }
6420
6603
  function FlowchartDiagram({ mermaid, className }) {
6421
6604
  const { nodes, edges } = parseMermaidFlowchart(mermaid);
6422
6605
  if (nodes.length === 0) {
6423
6606
  return /* @__PURE__ */ jsx("pre", { className: "text-xs bg-white border border-gray-100 rounded-sm p-3 overflow-x-auto whitespace-pre-wrap", children: mermaid });
6424
6607
  }
6425
- const outgoing = /* @__PURE__ */ new Map();
6426
- const incoming = /* @__PURE__ */ new Map();
6427
- for (const edge of edges) {
6428
- if (!outgoing.has(edge.from)) outgoing.set(edge.from, []);
6429
- outgoing.get(edge.from).push(edge);
6430
- if (!incoming.has(edge.to)) incoming.set(edge.to, []);
6431
- incoming.get(edge.to).push(edge);
6432
- }
6433
- const nodeMap = new Map(nodes.map((n) => [n.id, n]));
6434
- const roots = nodes.filter((n) => !incoming.has(n.id) || incoming.get(n.id).length === 0);
6435
- const startId = roots.length > 0 ? roots[0].id : nodes[0].id;
6436
- const visited = /* @__PURE__ */ new Set();
6437
- const layout = buildLayout(startId, outgoing, incoming, nodeMap, visited);
6438
- return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center py-2", children: /* @__PURE__ */ jsx(RenderLayoutItems, { items: layout, nodeMap }) }) });
6608
+ const { layoutNodes, svgWidth, svgHeight } = computeLayout(nodes, edges);
6609
+ const nodeById = new Map(layoutNodes.map((n) => [n.id, n]));
6610
+ return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxs(
6611
+ "svg",
6612
+ {
6613
+ width: svgWidth,
6614
+ height: svgHeight,
6615
+ viewBox: `0 0 ${svgWidth} ${svgHeight}`,
6616
+ xmlns: "http://www.w3.org/2000/svg",
6617
+ className: "block",
6618
+ children: [
6619
+ /* @__PURE__ */ jsx(SvgDefs, {}),
6620
+ edges.map((e, i) => {
6621
+ const fromNode = nodeById.get(e.from);
6622
+ const toNode = nodeById.get(e.to);
6623
+ if (!fromNode || !toNode) return null;
6624
+ return /* @__PURE__ */ jsx(EdgeSvg, { from: fromNode, to: toNode, label: e.label }, `e-${i}`);
6625
+ }),
6626
+ layoutNodes.map((n) => {
6627
+ if (n.node.type === "decision") return /* @__PURE__ */ jsx(DecisionNodeSvg, { n }, n.id);
6628
+ if (n.node.type === "terminal") return /* @__PURE__ */ jsx(TerminalNodeSvg, { n }, n.id);
6629
+ return /* @__PURE__ */ jsx(ActionNodeSvg, { n }, n.id);
6630
+ })
6631
+ ]
6632
+ }
6633
+ ) }) });
6439
6634
  }
6440
6635
  var frequencyLabels = {
6441
6636
  multiple_daily: "occurrence",