# Node path

Paint a caller routed SVG connection with explicit state.

## Preview

node-path-preview-1.jsx

```jsx
import { useId, useRef as useRef2, useState as useState2 } from "react";
import "react-dom";
import { MoreHorizontal } from "lucide-react";
import { Button, IconButton } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Drawer } from "@/components/ui/drawer";
import { Field } from "@/components/ui/field";
import { NodePath } from "@/components/ui/node-path";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";
import { Popover } from "@/components/ui/popover";
import { Select } from "@/components/ui/select";
import { TooltipHint } from "@/components/ui/tooltip";
import { getGraphConnectorPath } from "@/components/ui/diagram";
import { useLayoutEffect, useRef, useState } from "react";

export default function Example() {
  const { scene, stacked } = useStackedScene();
  const svg = useRef2(null);
  const endpoints = usePortEndpoints(scene, svg, stacked);
  const [connected, setConnected] = useState2(true);
  const prefix = `creative-edge-${useId().replace(/:/g, "")}`;
  const anchor = useRef2(null);
  const [open, setOpen] = useState2(false),
    [mobile, setMobile] = useState2(false),
    [running, setRunning] = useState2(false),
    [focused, setFocused] = useState2(false);
  const [connector, setConnector] = useState2("bezier"),
    [line, setLine] = useState2("solid"),
    [flow, setFlow] = useState2("pulse");
  const [start, setStart] = useState2("none"),
    [end, setEnd] = useState2("none");
  const geometry = getGraphConnectorPath({
    source:
      endpoints?.sources[0] ??
      (stacked
        ? {
            x: 80,
            y: 0,
          }
        : {
            x: 0,
            y: 76,
          }),
    target:
      endpoints?.targets[0] ??
      (stacked
        ? {
            x: 80,
            y: 200,
          }
        : {
            x: 160,
            y: 124,
          }),
    connector,
    direction: stacked ? "down" : "right",
  });
  const route = geometry.path;
  const showEditor = () => {
    setMobile(window.matchMedia("(max-width: 639px)").matches);
    setOpen(true);
  };
  const settings = (
    <div className="creative-edge-settings">
      <Button
        size="sm"
        variant="subtle"
        onClick={() => {
          setConnected((value) => !value);
          setRunning(false);
          setOpen(false);
        }}
      >
        {connected ? "Disconnect" : "Connect"}
      </Button>
      <Choice
        label="Connector"
        value={connector}
        onChange={(value) => setConnector(value)}
        options={connectorOptions}
      />
      <Choice
        label="Line"
        value={line}
        onChange={(value) => setLine(value)}
        options={[
          {
            value: "solid",
            label: "Solid",
          },
          {
            value: "dashed",
            label: "Dashed",
          },
          {
            value: "dotted",
            label: "Dotted",
          },
        ]}
      />
      <Choice
        label="Start marker"
        value={start}
        onChange={(value) => setStart(value)}
        options={markerOptions}
      />
      <Choice
        label="End marker"
        value={end}
        onChange={(value) => setEnd(value)}
        options={markerOptions}
      />
    </div>
  );
  return (
    <div className={`creative-edge-example${""}`}>
      <div
        ref={scene}
        className="creative-edge-scene"
        data-stacked={stacked || undefined}
      >
        <Card.Root variant="outline" className="creative-edge-scene__source">
          <Card.Header>
            <Card.Title>Image brief</Card.Title>
          </Card.Header>
          <Card.Content>
            <p>
              Quiet daylight.
              <br />
              Natural textures.
            </p>
          </Card.Content>
          <NodePortGroup side={stacked ? "bottom" : "right"}>
            <NodePort
              label="Text brief"
              direction="output"
              variant="core"
              dataType="text"
              connected={connected}
              onActivate={showEditor}
            />
          </NodePortGroup>
        </Card.Root>
        <div className="creative-edge-scene__route">
          <svg
            ref={svg}
            viewBox="0 0 160 200"
            preserveAspectRatio="none"
            aria-label="Image brief connected to coastal painting study"
            role="group"
          >
            <Markers prefix={prefix} />
            {connected && (
              <path
                d={route}
                className="creative-edge-hit"
                role="button"
                tabIndex={0}
                aria-label="Edit image connection"
                onFocus={() => setFocused(true)}
                onBlur={() => setFocused(false)}
                onClick={showEditor}
                onKeyDown={(event) => {
                  if (event.key === "Enter" || event.key === " ") {
                    event.preventDefault();
                    showEditor();
                  }
                }}
              />
            )}
            {connected && (
              <NodePath
                d={route}
                line={line}
                status={running ? "running" : "idle"}
                dataType="text"
                flow={flow}
                flowColor="var(--link)"
                selected={focused || open}
                markerStart={
                  start === "none" ? undefined : `url(#${prefix}-${start})`
                }
                markerEnd={
                  end === "none" ? undefined : `url(#${prefix}-${end})`
                }
                action={
                  <TooltipHint content="Edit connection">
                    <IconButton
                      ref={anchor}
                      icon={<MoreHorizontal />}
                      size="icon-xs"
                      variant="subtle"
                      aria-label="Connection settings"
                      onClick={showEditor}
                    />
                  </TooltipHint>
                }
              />
            )}
          </svg>
        </div>
        <Card.Root variant="outline" className="creative-edge-scene__target">
          <Card.Header>
            <Card.Title>Coastal painting study</Card.Title>
          </Card.Header>
          <Card.Content>
            <img
              src="/graph-examples/studio-direction.jpg"
              alt="Studio image in soft daylight"
              draggable={false}
            />
          </Card.Content>
          <NodePortGroup side={stacked ? "top" : "left"}>
            <NodePort
              label="Prompt"
              direction="input"
              variant="core"
              dataType="text"
              connected={connected}
              onActivate={showEditor}
            />
          </NodePortGroup>
        </Card.Root>
      </div>
      <div className="creative-edge-toolbar">
        {false}
        <Button
          size="sm"
          variant="subtle"
          disabled={!connected}
          onClick={() => setRunning((value) => !value)}
        >
          {running ? "Stop" : "Run"}
        </Button>
        <span className="creative-demo-sr" role="status">
          {running ? "Connection running" : "Connection idle"}
        </span>
      </div>
      {mobile ? (
        <Drawer.Root open={open} onOpenChange={setOpen} swipeDirection="down">
          <Drawer.Portal>
            <Drawer.Viewport>
              <Drawer.Backdrop />
              <Drawer.Popup grip>
                <Drawer.Content>
                  <Drawer.Header>
                    <Drawer.Title>Connection settings</Drawer.Title>
                    <Drawer.Close
                      render={
                        <Button size="sm" variant="ghost">
                          Done
                        </Button>
                      }
                    />
                  </Drawer.Header>
                  <Drawer.Core>{settings}</Drawer.Core>
                </Drawer.Content>
              </Drawer.Popup>
            </Drawer.Viewport>
          </Drawer.Portal>
        </Drawer.Root>
      ) : (
        <Popover.Root open={open} onOpenChange={setOpen}>
          <Popover.Portal>
            <Popover.Positioner anchor={anchor.current} side="top">
              <Popover.Popup className="creative-edge-popover">
                <Popover.Arrow />
                <Popover.Header>
                  <Popover.Title>Connection settings</Popover.Title>
                  <Popover.Close />
                </Popover.Header>
                <Popover.Core>{settings}</Popover.Core>
              </Popover.Popup>
            </Popover.Positioner>
          </Popover.Portal>
        </Popover.Root>
      )}
    </div>
  );
}

function useStackedScene() {
  const scene = useRef(null);
  const [stacked, setStacked] = useState(false);
  useLayoutEffect(() => {
    const measure = () => {
      const width = scene.current?.getBoundingClientRect().width;
      if (width) setStacked(width < 520);
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) observer.observe(scene.current);
    return () => observer.disconnect();
  }, []);
  return {
    scene,
    stacked,
  };
}

function usePortEndpoints(scene, svg, stacked = false) {
  const [endpoints, setEndpoints] = useState(null);
  useLayoutEffect(() => {
    const measure = () => {
      const bounds = svg.current?.getBoundingClientRect();
      if (!bounds?.width || !bounds.height || !scene.current) return;
      const points = (direction) =>
        [
          ...scene.current.querySelectorAll(
            `.ui-node-port--${direction} .ui-node-port__indicator`,
          ),
        ].flatMap((port) => {
          const rect = port.getBoundingClientRect();
          return rect.width && rect.height
            ? [
                {
                  x:
                    ((rect.left + rect.width / 2 - bounds.left) * 160) /
                    bounds.width,
                  y:
                    ((rect.top + rect.height / 2 - bounds.top) * 200) /
                    bounds.height,
                },
              ]
            : [];
        });
      const next = {
        sources: points("output"),
        targets: points("input"),
      };
      setEndpoints((current) =>
        JSON.stringify(current) === JSON.stringify(next) ? current : next,
      );
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) {
      observer.observe(scene.current);
      for (const child of scene.current.querySelectorAll(
        ".ui-card, .ui-node-port__indicator",
      ))
        observer.observe(child);
    }
    if (svg.current) observer.observe(svg.current);
    return () => observer.disconnect();
  }, [scene, svg, stacked]);
  return endpoints;
}

var markerOptions = [
  {
    value: "none",
    label: "None",
  },
  {
    value: "open",
    label: "Open arrow",
  },
  {
    value: "arrow",
    label: "Filled arrow",
  },
  {
    value: "dot",
    label: "Dot",
  },
];

var connectorOptions = [
  {
    value: "bezier",
    label: "Curve",
  },
  {
    value: "elbow",
    label: "Elbow",
  },
  {
    value: "straight",
    label: "Straight",
  },
];

function Choice({ label, value, onChange, options, inline = false }) {
  return (
    <Field.Root placement={inline ? "left" : "top"}>
      <Field.Label>{label}</Field.Label>
      <Select.Root
        value={value}
        onValueChange={(next) => next && onChange(next)}
        items={options}
      >
        <Select.Trigger aria-label={label} compact={inline}>
          <Select.Value />
          <Select.Icon />
        </Select.Trigger>
        <Select.Portal>
          <Select.Positioner>
            <Select.Popup>
              {options.map((item) => (
                <Select.Item key={item.value} value={item.value}>
                  <Select.ItemText>{item.label}</Select.ItemText>
                  <Select.ItemIndicator />
                </Select.Item>
              ))}
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
    </Field.Root>
  );
}

function Markers({ prefix }) {
  return (
    <defs>
      {["open", "arrow", "dot"].map((kind) => (
        <marker
          key={kind}
          id={`${prefix}-${kind}`}
          viewBox="0 0 10 10"
          refX={kind === "dot" ? 5 : 9}
          refY="5"
          markerWidth="8"
          markerHeight="8"
          markerUnits="userSpaceOnUse"
          orient="auto-start-reverse"
        >
          {kind === "dot" ? (
            <circle cx="5" cy="5" r="3" fill="var(--muted-foreground)" />
          ) : (
            <path
              d={kind === "open" ? "M1 1L9 5L1 9" : "M1 1L9 5L1 9Z"}
              fill={kind === "open" ? "none" : "var(--muted-foreground)"}
              stroke="var(--muted-foreground)"
              strokeWidth="1.5"
              strokeLinejoin="round"
            />
          )}
        </marker>
      ))}
    </defs>
  );
}

```

node-path-preview-1.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.creative-demo-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.creative-edge-example {
  box-sizing: border-box;
  width: 760px;
  max-width: 100%;
  padding: 24px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-edge-scene {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(64px, .8fr) minmax(0, 1fr);
  align-items: center;
  gap: 0;
  min-width: 0;
}
.creative-edge-scene > .ui-card {
  position: relative;
  z-index: 1;
  min-width: 0;
}
.creative-edge-scene .ui-card__title {
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
}
.creative-edge-scene p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 20px;
}
.creative-edge-scene__source {
  transform: translateY(-24px);
}
.creative-edge-scene__target {
  transform: translateY(24px);
}
.creative-edge-scene img {
  display: block;
  width: 100%;
  height: 88px;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.creative-edge-scene__route {
  position: relative;
  height: 200px;
  min-width: 0;
}
.creative-edge-scene__route > svg {
  display: block;
  width: 100%;
  height: 200px;
  overflow: visible;
}
.creative-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 24;
  pointer-events: stroke;
  outline: none;
  cursor: pointer;
}
.creative-edge-scene .creative-edge-scene__action {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
}
.creative-edge-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}
.creative-edge-popover {
  width: 280px;
}
.creative-edge-settings {
  display: grid;
  gap: 16px;
}
.creative-edge-example--thumbnail {
  width: 320px;
  padding: 16px;
}
.creative-edge-example--static-thumbnail {
  box-sizing: border-box;
  width: 100%;
  min-height: 160px;
  padding: 16px;
}
.creative-edge-scene--static-thumbnail {
  grid-template-columns: minmax(0, 1fr) minmax(56px, .6fr) minmax(0, 1fr);
  min-height: 128px;
}
.creative-edge-scene--static-thumbnail > .ui-card {
  padding: 12px;
  gap: 8px;
  transform: none;
}
.creative-edge-scene--static-thumbnail .ui-card__header {
  text-align: center;
}
.creative-edge-scene--static-thumbnail .ui-card__title {
  font-size: 12px;
  line-height: 16px;
  font-weight: 400;
}
.creative-edge-scene--static-thumbnail p {
  font-size: 12px;
  line-height: 16px;
}
.creative-edge-scene--static-thumbnail .creative-edge-scene__route {
  height: 120px;
}
.creative-edge-scene--static-thumbnail .creative-edge-scene__route > svg {
  height: 120px;
}
.creative-edge-example--thumbnail .creative-edge-scene {
  grid-template-columns: minmax(0, 1fr) 72px minmax(0, 1fr);
}
.creative-edge-example--thumbnail .ui-card__title {
  font-size: 12px;
  line-height: 16px;
}
.creative-edge-example--thumbnail p {
  font-size: 11px;
  line-height: 16px;
}
.creative-edge-example--thumbnail img {
  height: 64px;
}
@media (max-width: 560px) {
  .creative-edge-example {
    padding: 16px;
  }
  .creative-edge-scene .ui-card {
    padding: 8px;
    gap: 8px;
    border-radius: var(--radius-md);
  }
  .creative-edge-scene .ui-card__title {
    font-size: 12px;
    line-height: 16px;
  }
  .creative-edge-scene p {
    font-size: 12px;
    line-height: 18px;
  }
}
.creative-edge-example--static-thumbnail .ui-node-port svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}
.creative-edge-example--static-thumbnail .creative-edge-scene > .ui-card {
  padding: 12px;
}

/* apps/web/src/demos/library/edge-path-refinement.css */
.creative-edge-scene > .creative-edge-scene__source {
  padding-inline-end: 36px;
}
.creative-edge-scene > .creative-edge-scene__target {
  padding-inline-start: 36px;
}
.creative-edge-scene[data-stacked] {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}
.creative-edge-scene[data-stacked] > .ui-card {
  box-sizing: border-box;
  width: 100%;
  max-width: 320px;
  padding: 16px;
  transform: none;
}
.creative-edge-scene[data-stacked] > .ui-card:first-child {
  padding-bottom: 40px;
}
.creative-edge-scene[data-stacked] > .ui-card:last-child {
  padding-top: 40px;
}
.creative-edge-scene[data-stacked] > .creative-edge-scene__route {
  width: 160px;
  height: 144px;
}
.creative-edge-scene[data-stacked] .creative-edge-scene__route > svg {
  height: 144px;
}
@media (pointer: coarse) {
  .creative-edge-hit {
    stroke-width: 44;
  }
}
.creative-edge-hit {
  vector-effect: non-scaling-stroke;
  touch-action: manipulation;
}

```

## Design guidance

**Also known as**

Edge path, Graph edge path, Graph edge, Node flow.

These names describe the connection route painted by NodePath. The legacy EdgePath module remains a compatibility re-export.

Use NodePath to paint a supplied SVG route. In the preview, either port opens connection settings, including Connect and Disconnect. Pass an optional action to place a caller-owned control at half the SVG path length. Omit it for a quiet creative canvas. It does not own connector geometry, graph identity, line editing, markers, bundles or execution policy. Import getGraphConnectorPath from @collectivecreation/ghost-ui/components/diagram for common caller-selected routes, and native SVG markers when direction needs an arrow. React Flow remains optional; a custom edge renderer keeps its own transparent interaction path.

## Installation

```sh
npx shadcn@latest add https://ghost-ui.com/r/node-path.json
```

The node-path item includes node-path.tsx and its imported edge-path.css stylesheet, plus the shared theme and foundation dependencies. The stylesheet retains its existing filename.

## Basic usage

```tsx
import { NodePath } from "@collectivecreation/ghost-ui/components/node-path";

<svg viewBox="0 0 240 80">
<defs><marker id="prompt-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" /></marker></defs>
<NodePath d="M 12 40 H 228" status="running" flow="pulse" markerEnd="url(#prompt-arrow)" />
</svg>
```

## Structures

- NodePath (SVG path)

The owner renders an optional casing underlay and one visible path. Pass dataType to paint the edge in the matching port color; a connection then shares one color across the edge and both endpoint ports. Its pulse flow overlays motion on the existing route; dash keeps the existing running dash treatment. Reduced motion and print keep a static running indication. Running is caller supplied; it does not execute work. Use unique IDs for native SVG markers. A cable bundle is several distinct routed paths with a caller-owned tie annotation, not one merged edge.

## Examples

### Routes and markers

Activate the connection menu to change its route, line style and start or end marker. Settings open in a Popover on desktop and a bottom Drawer on mobile. Focus darkens the existing line without increasing its weight.

node-path-routes-and-markers-2.jsx

```jsx
import { useId, useRef as useRef2, useState as useState2 } from "react";
import "react-dom";
import { MoreHorizontal } from "lucide-react";
import { Button, IconButton } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Drawer } from "@/components/ui/drawer";
import { Field } from "@/components/ui/field";
import { NodePath } from "@/components/ui/node-path";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";
import { Popover } from "@/components/ui/popover";
import { Select } from "@/components/ui/select";
import { TooltipHint } from "@/components/ui/tooltip";
import { getGraphConnectorPath } from "@/components/ui/diagram";
import { useLayoutEffect, useRef, useState } from "react";

export default function Example() {
  const { scene, stacked } = useStackedScene();
  const svg = useRef2(null);
  const endpoints = usePortEndpoints(scene, svg, stacked);
  const [connected, setConnected] = useState2(true);
  const prefix = `creative-edge-${useId().replace(/:/g, "")}`;
  const anchor = useRef2(null);
  const [open, setOpen] = useState2(false),
    [mobile, setMobile] = useState2(false),
    [running, setRunning] = useState2(false),
    [focused, setFocused] = useState2(false);
  const [connector, setConnector] = useState2("bezier"),
    [line, setLine] = useState2("solid"),
    [flow, setFlow] = useState2("pulse");
  const [start, setStart] = useState2("none"),
    [end, setEnd] = useState2("arrow");
  const geometry = getGraphConnectorPath({
    source:
      endpoints?.sources[0] ??
      (stacked
        ? {
            x: 80,
            y: 0,
          }
        : {
            x: 0,
            y: 76,
          }),
    target:
      endpoints?.targets[0] ??
      (stacked
        ? {
            x: 80,
            y: 200,
          }
        : {
            x: 160,
            y: 124,
          }),
    connector,
    direction: stacked ? "down" : "right",
  });
  const route = geometry.path;
  const showEditor = () => {
    setMobile(window.matchMedia("(max-width: 639px)").matches);
    setOpen(true);
  };
  const settings = (
    <div className="creative-edge-settings">
      <Button
        size="sm"
        variant="subtle"
        onClick={() => {
          setConnected((value) => !value);
          setRunning(false);
          setOpen(false);
        }}
      >
        {connected ? "Disconnect" : "Connect"}
      </Button>
      <Choice
        label="Connector"
        value={connector}
        onChange={(value) => setConnector(value)}
        options={connectorOptions}
      />
      <Choice
        label="Line"
        value={line}
        onChange={(value) => setLine(value)}
        options={[
          {
            value: "solid",
            label: "Solid",
          },
          {
            value: "dashed",
            label: "Dashed",
          },
          {
            value: "dotted",
            label: "Dotted",
          },
        ]}
      />
      <Choice
        label="Start marker"
        value={start}
        onChange={(value) => setStart(value)}
        options={markerOptions}
      />
      <Choice
        label="End marker"
        value={end}
        onChange={(value) => setEnd(value)}
        options={markerOptions}
      />
    </div>
  );
  return (
    <div className={`creative-edge-example${""}`}>
      <div
        ref={scene}
        className="creative-edge-scene"
        data-stacked={stacked || undefined}
      >
        <Card.Root variant="outline" className="creative-edge-scene__source">
          <Card.Header>
            <Card.Title>Image brief</Card.Title>
          </Card.Header>
          <Card.Content>
            <p>
              Quiet daylight.
              <br />
              Natural textures.
            </p>
          </Card.Content>
          <NodePortGroup side={stacked ? "bottom" : "right"}>
            <NodePort
              label="Text brief"
              direction="output"
              variant="core"
              dataType="text"
              connected={connected}
              onActivate={showEditor}
            />
          </NodePortGroup>
        </Card.Root>
        <div className="creative-edge-scene__route">
          <svg
            ref={svg}
            viewBox="0 0 160 200"
            preserveAspectRatio="none"
            aria-label="Image brief connected to coastal painting study"
            role="group"
          >
            <Markers prefix={prefix} />
            {connected && (
              <path
                d={route}
                className="creative-edge-hit"
                role="button"
                tabIndex={0}
                aria-label="Edit image connection"
                onFocus={() => setFocused(true)}
                onBlur={() => setFocused(false)}
                onClick={showEditor}
                onKeyDown={(event) => {
                  if (event.key === "Enter" || event.key === " ") {
                    event.preventDefault();
                    showEditor();
                  }
                }}
              />
            )}
            {connected && (
              <NodePath
                d={route}
                line={line}
                status={running ? "running" : "idle"}
                dataType="text"
                flow={flow}
                flowColor="var(--link)"
                selected={focused || open}
                markerStart={
                  start === "none" ? undefined : `url(#${prefix}-${start})`
                }
                markerEnd={
                  end === "none" ? undefined : `url(#${prefix}-${end})`
                }
                action={
                  <TooltipHint content="Edit connection">
                    <IconButton
                      ref={anchor}
                      icon={<MoreHorizontal />}
                      size="icon-xs"
                      variant="subtle"
                      aria-label="Connection settings"
                      onClick={showEditor}
                    />
                  </TooltipHint>
                }
              />
            )}
          </svg>
        </div>
        <Card.Root variant="outline" className="creative-edge-scene__target">
          <Card.Header>
            <Card.Title>Coastal painting study</Card.Title>
          </Card.Header>
          <Card.Content>
            <img
              src="/graph-examples/studio-direction.jpg"
              alt="Studio image in soft daylight"
              draggable={false}
            />
          </Card.Content>
          <NodePortGroup side={stacked ? "top" : "left"}>
            <NodePort
              label="Prompt"
              direction="input"
              variant="core"
              dataType="text"
              connected={connected}
              onActivate={showEditor}
            />
          </NodePortGroup>
        </Card.Root>
      </div>
      <div className="creative-edge-toolbar">
        {false}
        <Button
          size="sm"
          variant="subtle"
          disabled={!connected}
          onClick={() => setRunning((value) => !value)}
        >
          {running ? "Stop" : "Run"}
        </Button>
        <span className="creative-demo-sr" role="status">
          {running ? "Connection running" : "Connection idle"}
        </span>
      </div>
      {mobile ? (
        <Drawer.Root open={open} onOpenChange={setOpen} swipeDirection="down">
          <Drawer.Portal>
            <Drawer.Viewport>
              <Drawer.Backdrop />
              <Drawer.Popup grip>
                <Drawer.Content>
                  <Drawer.Header>
                    <Drawer.Title>Connection settings</Drawer.Title>
                    <Drawer.Close
                      render={
                        <Button size="sm" variant="ghost">
                          Done
                        </Button>
                      }
                    />
                  </Drawer.Header>
                  <Drawer.Core>{settings}</Drawer.Core>
                </Drawer.Content>
              </Drawer.Popup>
            </Drawer.Viewport>
          </Drawer.Portal>
        </Drawer.Root>
      ) : (
        <Popover.Root open={open} onOpenChange={setOpen}>
          <Popover.Portal>
            <Popover.Positioner anchor={anchor.current} side="top">
              <Popover.Popup className="creative-edge-popover">
                <Popover.Arrow />
                <Popover.Header>
                  <Popover.Title>Connection settings</Popover.Title>
                  <Popover.Close />
                </Popover.Header>
                <Popover.Core>{settings}</Popover.Core>
              </Popover.Popup>
            </Popover.Positioner>
          </Popover.Portal>
        </Popover.Root>
      )}
    </div>
  );
}

function useStackedScene() {
  const scene = useRef(null);
  const [stacked, setStacked] = useState(false);
  useLayoutEffect(() => {
    const measure = () => {
      const width = scene.current?.getBoundingClientRect().width;
      if (width) setStacked(width < 520);
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) observer.observe(scene.current);
    return () => observer.disconnect();
  }, []);
  return {
    scene,
    stacked,
  };
}

function usePortEndpoints(scene, svg, stacked = false) {
  const [endpoints, setEndpoints] = useState(null);
  useLayoutEffect(() => {
    const measure = () => {
      const bounds = svg.current?.getBoundingClientRect();
      if (!bounds?.width || !bounds.height || !scene.current) return;
      const points = (direction) =>
        [
          ...scene.current.querySelectorAll(
            `.ui-node-port--${direction} .ui-node-port__indicator`,
          ),
        ].flatMap((port) => {
          const rect = port.getBoundingClientRect();
          return rect.width && rect.height
            ? [
                {
                  x:
                    ((rect.left + rect.width / 2 - bounds.left) * 160) /
                    bounds.width,
                  y:
                    ((rect.top + rect.height / 2 - bounds.top) * 200) /
                    bounds.height,
                },
              ]
            : [];
        });
      const next = {
        sources: points("output"),
        targets: points("input"),
      };
      setEndpoints((current) =>
        JSON.stringify(current) === JSON.stringify(next) ? current : next,
      );
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) {
      observer.observe(scene.current);
      for (const child of scene.current.querySelectorAll(
        ".ui-card, .ui-node-port__indicator",
      ))
        observer.observe(child);
    }
    if (svg.current) observer.observe(svg.current);
    return () => observer.disconnect();
  }, [scene, svg, stacked]);
  return endpoints;
}

var markerOptions = [
  {
    value: "none",
    label: "None",
  },
  {
    value: "open",
    label: "Open arrow",
  },
  {
    value: "arrow",
    label: "Filled arrow",
  },
  {
    value: "dot",
    label: "Dot",
  },
];

var connectorOptions = [
  {
    value: "bezier",
    label: "Curve",
  },
  {
    value: "elbow",
    label: "Elbow",
  },
  {
    value: "straight",
    label: "Straight",
  },
];

function Choice({ label, value, onChange, options, inline = false }) {
  return (
    <Field.Root placement={inline ? "left" : "top"}>
      <Field.Label>{label}</Field.Label>
      <Select.Root
        value={value}
        onValueChange={(next) => next && onChange(next)}
        items={options}
      >
        <Select.Trigger aria-label={label} compact={inline}>
          <Select.Value />
          <Select.Icon />
        </Select.Trigger>
        <Select.Portal>
          <Select.Positioner>
            <Select.Popup>
              {options.map((item) => (
                <Select.Item key={item.value} value={item.value}>
                  <Select.ItemText>{item.label}</Select.ItemText>
                  <Select.ItemIndicator />
                </Select.Item>
              ))}
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
    </Field.Root>
  );
}

function Markers({ prefix }) {
  return (
    <defs>
      {["open", "arrow", "dot"].map((kind) => (
        <marker
          key={kind}
          id={`${prefix}-${kind}`}
          viewBox="0 0 10 10"
          refX={kind === "dot" ? 5 : 9}
          refY="5"
          markerWidth="8"
          markerHeight="8"
          markerUnits="userSpaceOnUse"
          orient="auto-start-reverse"
        >
          {kind === "dot" ? (
            <circle cx="5" cy="5" r="3" fill="var(--muted-foreground)" />
          ) : (
            <path
              d={kind === "open" ? "M1 1L9 5L1 9" : "M1 1L9 5L1 9Z"}
              fill={kind === "open" ? "none" : "var(--muted-foreground)"}
              stroke="var(--muted-foreground)"
              strokeWidth="1.5"
              strokeLinejoin="round"
            />
          )}
        </marker>
      ))}
    </defs>
  );
}

```

node-path-routes-and-markers-2.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.creative-demo-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.creative-edge-example {
  box-sizing: border-box;
  width: 760px;
  max-width: 100%;
  padding: 24px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-edge-scene {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(64px, .8fr) minmax(0, 1fr);
  align-items: center;
  gap: 0;
  min-width: 0;
}
.creative-edge-scene > .ui-card {
  position: relative;
  z-index: 1;
  min-width: 0;
}
.creative-edge-scene .ui-card__title {
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
}
.creative-edge-scene p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 20px;
}
.creative-edge-scene__source {
  transform: translateY(-24px);
}
.creative-edge-scene__target {
  transform: translateY(24px);
}
.creative-edge-scene img {
  display: block;
  width: 100%;
  height: 88px;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.creative-edge-scene__route {
  position: relative;
  height: 200px;
  min-width: 0;
}
.creative-edge-scene__route > svg {
  display: block;
  width: 100%;
  height: 200px;
  overflow: visible;
}
.creative-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 24;
  pointer-events: stroke;
  outline: none;
  cursor: pointer;
}
.creative-edge-scene .creative-edge-scene__action {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
}
.creative-edge-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}
.creative-edge-popover {
  width: 280px;
}
.creative-edge-settings {
  display: grid;
  gap: 16px;
}
.creative-edge-example--thumbnail {
  width: 320px;
  padding: 16px;
}
.creative-edge-example--static-thumbnail {
  box-sizing: border-box;
  width: 100%;
  min-height: 160px;
  padding: 16px;
}
.creative-edge-scene--static-thumbnail {
  grid-template-columns: minmax(0, 1fr) minmax(56px, .6fr) minmax(0, 1fr);
  min-height: 128px;
}
.creative-edge-scene--static-thumbnail > .ui-card {
  padding: 12px;
  gap: 8px;
  transform: none;
}
.creative-edge-scene--static-thumbnail .ui-card__header {
  text-align: center;
}
.creative-edge-scene--static-thumbnail .ui-card__title {
  font-size: 12px;
  line-height: 16px;
  font-weight: 400;
}
.creative-edge-scene--static-thumbnail p {
  font-size: 12px;
  line-height: 16px;
}
.creative-edge-scene--static-thumbnail .creative-edge-scene__route {
  height: 120px;
}
.creative-edge-scene--static-thumbnail .creative-edge-scene__route > svg {
  height: 120px;
}
.creative-edge-example--thumbnail .creative-edge-scene {
  grid-template-columns: minmax(0, 1fr) 72px minmax(0, 1fr);
}
.creative-edge-example--thumbnail .ui-card__title {
  font-size: 12px;
  line-height: 16px;
}
.creative-edge-example--thumbnail p {
  font-size: 11px;
  line-height: 16px;
}
.creative-edge-example--thumbnail img {
  height: 64px;
}
@media (max-width: 560px) {
  .creative-edge-example {
    padding: 16px;
  }
  .creative-edge-scene .ui-card {
    padding: 8px;
    gap: 8px;
    border-radius: var(--radius-md);
  }
  .creative-edge-scene .ui-card__title {
    font-size: 12px;
    line-height: 16px;
  }
  .creative-edge-scene p {
    font-size: 12px;
    line-height: 18px;
  }
}
.creative-edge-example--static-thumbnail .ui-node-port svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}
.creative-edge-example--static-thumbnail .creative-edge-scene > .ui-card {
  padding: 12px;
}

/* apps/web/src/demos/library/edge-path-refinement.css */
.creative-edge-scene > .creative-edge-scene__source {
  padding-inline-end: 36px;
}
.creative-edge-scene > .creative-edge-scene__target {
  padding-inline-start: 36px;
}
.creative-edge-scene[data-stacked] {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}
.creative-edge-scene[data-stacked] > .ui-card {
  box-sizing: border-box;
  width: 100%;
  max-width: 320px;
  padding: 16px;
  transform: none;
}
.creative-edge-scene[data-stacked] > .ui-card:first-child {
  padding-bottom: 40px;
}
.creative-edge-scene[data-stacked] > .ui-card:last-child {
  padding-top: 40px;
}
.creative-edge-scene[data-stacked] > .creative-edge-scene__route {
  width: 160px;
  height: 144px;
}
.creative-edge-scene[data-stacked] .creative-edge-scene__route > svg {
  height: 144px;
}
@media (pointer: coarse) {
  .creative-edge-hit {
    stroke-width: 44;
  }
}
.creative-edge-hit {
  vector-effect: non-scaling-stroke;
  touch-action: manipulation;
}

```

### Cable bundles

Choose Curve, Elbow or Straight, then drag the zip freely or constrain it to X or Y. Arrow keys follow the same movement constraint; Shift moves faster. Separating the cables preserves their endpoints and identities. The EdgeCrossing demo accepts gripSize in CSS pixels (default 18; clamped to 8–32px); routing stays demo-owned.

node-path-cable-bundles-3.jsx

```jsx
import { useRef as useRef2, useState as useState2 } from "react";
import { flushSync } from "react-dom";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Field } from "@/components/ui/field";
import { NodePath } from "@/components/ui/node-path";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";
import { Select } from "@/components/ui/select";
import { getGraphConnectorPath } from "@/components/ui/diagram";
import { useLayoutEffect, useRef, useState } from "react";

export default function Example() {
  return (
    <>
      <EdgeCrossing />
    </>
  );
}

function useStackedScene() {
  const scene = useRef(null);
  const [stacked, setStacked] = useState(false);
  useLayoutEffect(() => {
    const measure = () => {
      const width = scene.current?.getBoundingClientRect().width;
      if (width) setStacked(width < 520);
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) observer.observe(scene.current);
    return () => observer.disconnect();
  }, []);
  return {
    scene,
    stacked,
  };
}

function usePortEndpoints(scene, svg, stacked = false) {
  const [endpoints, setEndpoints] = useState(null);
  useLayoutEffect(() => {
    const measure = () => {
      const bounds = svg.current?.getBoundingClientRect();
      if (!bounds?.width || !bounds.height || !scene.current) return;
      const points = (direction) =>
        [
          ...scene.current.querySelectorAll(
            `.ui-node-port--${direction} .ui-node-port__indicator`,
          ),
        ].flatMap((port) => {
          const rect = port.getBoundingClientRect();
          return rect.width && rect.height
            ? [
                {
                  x:
                    ((rect.left + rect.width / 2 - bounds.left) * 160) /
                    bounds.width,
                  y:
                    ((rect.top + rect.height / 2 - bounds.top) * 200) /
                    bounds.height,
                },
              ]
            : [];
        });
      const next = {
        sources: points("output"),
        targets: points("input"),
      };
      setEndpoints((current) =>
        JSON.stringify(current) === JSON.stringify(next) ? current : next,
      );
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) {
      observer.observe(scene.current);
      for (const child of scene.current.querySelectorAll(
        ".ui-card, .ui-node-port__indicator",
      ))
        observer.observe(child);
    }
    if (svg.current) observer.observe(svg.current);
    return () => observer.disconnect();
  }, [scene, svg, stacked]);
  return endpoints;
}

var connectorOptions = [
  {
    value: "bezier",
    label: "Curve",
  },
  {
    value: "elbow",
    label: "Elbow",
  },
  {
    value: "straight",
    label: "Straight",
  },
];

function Choice({ label, value, onChange, options, inline = false }) {
  return (
    <Field.Root placement={"left"}>
      <Field.Label>{label}</Field.Label>
      <Select.Root
        value={value}
        onValueChange={(next) => next && onChange(next)}
        items={options}
      >
        <Select.Trigger aria-label={label} compact={true}>
          <Select.Value />
          <Select.Icon />
        </Select.Trigger>
        <Select.Portal>
          <Select.Positioner>
            <Select.Popup>
              {options.map((item) => (
                <Select.Item key={item.value} value={item.value}>
                  <Select.ItemText>{item.label}</Select.ItemText>
                  <Select.ItemIndicator />
                </Select.Item>
              ))}
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
    </Field.Root>
  );
}

function EdgeCrossing({ gripSize = 18 } = {}) {
  const { scene, stacked } = useStackedScene();
  const [bundled, setBundled] = useState2(true);
  const [connector, setConnector] = useState2("bezier");
  const [movement, setMovement] = useState2("both");
  const [tie, setTie] = useState2({
    x: 80,
    y: 100,
  });
  const activePointer = useRef2(null);
  const svg = useRef2(null);
  const endpoints = usePortEndpoints(scene, svg, stacked);
  const constrainTie = ({ x, y }, current) => {
    const width = svg.current?.getBoundingClientRect().width || 160;
    const inset = Math.min(80, Math.max(24, 3520 / width));
    return {
      x:
        movement === "y"
          ? current.x
          : Math.min(160 - inset, Math.max(inset, x)),
      y: movement === "x" ? current.y : Math.min(160, Math.max(40, y)),
    };
  };
  const visibleGripSize = Number.isFinite(18)
    ? Math.min(32, Math.max(8, 18))
    : 18;
  const point = (clientX, clientY) => {
    const rect = svg.current?.getBoundingClientRect();
    if (!rect?.width || !rect.height) return null;
    return {
      x: ((clientX - rect.left) * 160) / rect.width,
      y: ((clientY - rect.top) * 200) / rect.height,
    };
  };
  const cablePath = (index, tie2) => {
    const y = 76 + index * 24,
      x = 56 + index * 24;
    const lane = (stacked ? tie2.x : tie2.y) + (index - 1) * 3;
    const source =
        endpoints?.sources[index] ??
        (stacked
          ? {
              x,
              y: 0,
            }
          : {
              x: 0,
              y,
            }),
      target =
        endpoints?.targets[index] ??
        (stacked
          ? {
              x,
              y: 200,
            }
          : {
              x: 160,
              y,
            });
    let d;
    if (connector === "bezier") {
      d = stacked
        ? bundled
          ? `M${source.x} ${source.y} C${source.x} ${source.y + (tie2.y - source.y) * 0.45} ${lane} ${tie2.y - 10} ${lane} ${tie2.y} C${lane} ${tie2.y + 10} ${target.x} ${target.y - (target.y - tie2.y) * 0.45} ${target.x} ${target.y}`
          : `M${source.x} ${source.y} C${source.x - 32 + index * 18} 65 ${target.x + 32 - index * 18} 135 ${target.x} ${target.y}`
        : bundled
          ? `M${source.x} ${source.y} C${source.x + (tie2.x - source.x) * 0.45} ${source.y} ${tie2.x - 10} ${lane} ${tie2.x} ${lane} C${tie2.x + 10} ${lane} ${target.x - (target.x - tie2.x) * 0.45} ${target.y} ${target.x} ${target.y}`
          : `M${source.x} ${source.y} C52 ${source.y - 32 + index * 18} 108 ${target.y + 32 - index * 18} ${target.x} ${target.y}`;
    } else if (bundled && connector === "straight") {
      d = `M${source.x} ${source.y} L${stacked ? lane : tie2.x} ${stacked ? tie2.y : lane} L${target.x} ${target.y}`;
    } else {
      d = getGraphConnectorPath({
        source,
        target,
        connector,
        direction: stacked ? "down" : "right",
        points: bundled
          ? stacked
            ? [
                {
                  x: lane,
                  y: tie2.y - 10,
                },
                {
                  x: lane,
                  y: tie2.y + 10,
                },
              ]
            : [
                {
                  x: tie2.x - 10,
                  y: lane,
                },
                {
                  x: tie2.x + 10,
                  y: lane,
                },
              ]
          : undefined,
      }).path;
    }
    return d;
  };
  const finishDrag = (pointerId, element) => {
    const drag = activePointer.current;
    if (drag?.id !== pointerId) return;
    activePointer.current = null;
    flushSync(() => setTie(drag.position));
    element.style.transform = "";
  };
  const finishTracking = () => {
    const grip = svg.current?.parentElement?.querySelector(
      ".creative-cable-grip",
    );
    if (activePointer.current && grip)
      finishDrag(activePointer.current.id, grip);
  };
  return (
    <div data-preview-wide className="creative-edge-example">
      <div
        ref={scene}
        className="creative-cable-scene"
        data-stacked={stacked || undefined}
      >
        <Card.Root variant="outline">
          <Card.Header>
            <Card.Title>Studio</Card.Title>
          </Card.Header>
          <Card.Content>
            <p>3 takes</p>
          </Card.Content>
          <NodePortGroup side={stacked ? "bottom" : "right"} gap={24}>
            {[0, 1, 2].map((index) => (
              <NodePort
                key={index}
                label={`Variation ${index + 1}`}
                direction="output"
                variant="core"
                showLabel={false}
                dataType="image"
                connected
              />
            ))}
          </NodePortGroup>
        </Card.Root>
        <div className="creative-cable-scene__route">
          <svg
            ref={svg}
            viewBox="0 0 160 200"
            preserveAspectRatio="none"
            role="img"
            aria-label="Three distinct image connections"
          >
            {[0, 1, 2].map((index) => (
              <NodePath
                key={index}
                className="creative-cable-path"
                d={cablePath(index, activePointer.current?.position ?? tie)}
                casing={false}
                dataType="image"
              />
            ))}
          </svg>
          {bundled && (
            <button
              type="button"
              className="creative-cable-grip"
              aria-label="Move cable tie"
              data-movement={movement}
              style={{
                left: `${(tie.x / 160) * 100}%`,
                top: `${(tie.y / 200) * 100}%`,
                "--creative-cable-grip-size": `${visibleGripSize}px`,
              }}
              onPointerDown={(event) => {
                if (
                  !event.isPrimary ||
                  event.button !== 0 ||
                  activePointer.current
                )
                  return;
                const position = point(event.clientX, event.clientY);
                if (!position) return;
                activePointer.current = {
                  id: event.pointerId,
                  offsetX: tie.x - position.x,
                  offsetY: tie.y - position.y,
                  position: tie,
                };
                event.currentTarget.setPointerCapture(event.pointerId);
              }}
              onPointerMove={(event) => {
                const drag = activePointer.current;
                if (!drag || drag.id !== event.pointerId) return;
                const position = point(event.clientX, event.clientY);
                if (!position) return;
                const next = constrainTie(
                  {
                    x: position.x + drag.offsetX,
                    y: position.y + drag.offsetY,
                  },
                  drag.position,
                );
                drag.position = next;
                const bounds = svg.current.getBoundingClientRect();
                event.currentTarget.style.transform = `translate(${((next.x - tie.x) * bounds.width) / 160}px, ${((next.y - tie.y) * bounds.height) / 200}px)`;
                svg.current
                  .querySelectorAll(".creative-cable-path")
                  .forEach((path, index) =>
                    path.setAttribute("d", cablePath(index, next)),
                  );
              }}
              onPointerUp={(event) =>
                finishDrag(event.pointerId, event.currentTarget)
              }
              onPointerCancel={(event) =>
                finishDrag(event.pointerId, event.currentTarget)
              }
              onLostPointerCapture={(event) =>
                finishDrag(event.pointerId, event.currentTarget)
              }
              onKeyDown={(event) => {
                if (activePointer.current) return;
                const step = event.shiftKey ? 10 : 1;
                const moves = {
                  ArrowLeft: [-step, 0],
                  ArrowRight: [step, 0],
                  ArrowUp: [0, -step],
                  ArrowDown: [0, step],
                };
                const move = moves[event.key];
                if (!move) return;
                event.preventDefault();
                setTie((current) =>
                  constrainTie(
                    {
                      x: current.x + move[0],
                      y: current.y + move[1],
                    },
                    current,
                  ),
                );
              }}
            />
          )}
        </div>
        <Card.Root variant="outline">
          <Card.Header>
            <Card.Title>Images</Card.Title>
          </Card.Header>
          <Card.Content>
            <p>3 inputs</p>
          </Card.Content>
          <NodePortGroup side={stacked ? "top" : "left"} gap={24}>
            {[0, 1, 2].map((index) => (
              <NodePort
                key={index}
                label={`Image ${index + 1}`}
                direction="input"
                variant="core"
                showLabel={false}
                dataType="image"
                connected
              />
            ))}
          </NodePortGroup>
        </Card.Root>
      </div>
      <div className="creative-edge-toolbar creative-cable-controls">
        <Choice
          inline
          label="Line"
          value={connector}
          onChange={(value) => {
            finishTracking();
            setConnector(value);
          }}
          options={connectorOptions}
        />
        <Choice
          inline
          label="Movement"
          value={movement}
          onChange={(value) => {
            finishTracking();
            setMovement(value);
          }}
          options={[
            {
              value: "both",
              label: "Free",
            },
            {
              value: "x",
              label: "X only",
            },
            {
              value: "y",
              label: "Y only",
            },
          ]}
        />
        <Button
          size="sm"
          variant="subtle"
          aria-pressed={bundled}
          onClick={() => {
            finishTracking();
            setBundled((value) => !value);
          }}
        >
          {bundled ? "Separate cables" : "Bundle cables"}
        </Button>
      </div>
    </div>
  );
}

```

node-path-cable-bundles-3.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.creative-edge-example {
  box-sizing: border-box;
  width: 760px;
  max-width: 100%;
  padding: 24px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-cable-scene {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(64px, .8fr) minmax(0, 1fr);
  align-items: center;
  gap: 0;
  min-width: 0;
}
.creative-cable-scene > .ui-card {
  position: relative;
  z-index: 1;
  min-width: 0;
}
.creative-cable-scene .ui-card__title {
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
}
.creative-cable-scene p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 20px;
}
.creative-cable-scene__route > svg {
  display: block;
  width: 100%;
  height: 200px;
  overflow: visible;
}
.creative-edge-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}
.creative-cable-scene__route {
  position: relative;
  height: 200px;
  min-width: 0;
}
.creative-cable-grip {
  position: absolute;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: grab;
  touch-action: none;
  translate: -50% -50%;
}
.creative-cable-grip::before {
  width: 4px;
  height: var(--creative-cable-grip-size);
  border-radius: var(--radius-pill);
  background: var(--border);
  content: "";
}
.creative-cable-grip:active {
  cursor: grabbing;
}
.creative-cable-grip:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
@media (max-width: 560px) {
  .creative-edge-example {
    padding: 16px;
  }
  .creative-cable-scene .ui-card {
    padding: 8px;
    gap: 8px;
    border-radius: var(--radius-md);
  }
  .creative-cable-scene .ui-card__title {
    font-size: 12px;
    line-height: 16px;
  }
  .creative-cable-scene p {
    font-size: 12px;
    line-height: 18px;
  }
}

/* apps/web/src/demos/library/edge-path-refinement.css */
.creative-cable-scene > .ui-card:first-child {
  padding-inline-end: 36px;
}
.creative-cable-scene > .ui-card:last-child {
  padding-inline-start: 36px;
}
.creative-cable-scene > .ui-card {
  min-height: 88px;
  justify-content: center;
}
.creative-cable-scene .creative-cable-grip {
  border-radius: 0;
  z-index: 2;
}
.creative-cable-scene .creative-cable-grip[data-movement=x] {
  cursor: ew-resize;
}
.creative-cable-scene .creative-cable-grip[data-movement=y] {
  cursor: ns-resize;
}
.creative-cable-controls {
  gap: 12px;
}
.creative-cable-controls > .ui-field[data-placement=left] {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.creative-cable-controls .ui-label {
  white-space: nowrap;
}
.creative-cable-controls .ui-select-trigger {
  height: calc(var(--space-6) + var(--space-1));
  min-height: calc(var(--space-6) + var(--space-1));
  border-radius: var(--radius-control-sm);
  padding-inline: var(--space-2);
  font-size: var(--font-size-caption);
}
.creative-edge-example:has([data-stacked]) > .creative-cable-controls {
  flex-direction: column;
  align-items: stretch;
}
.creative-edge-example:has([data-stacked]) > .creative-cable-controls > .ui-field {
  width: 100%;
  flex-direction: column;
  align-items: stretch;
}
.creative-edge-example:has([data-stacked]) > .creative-cable-controls .ui-label {
  width: 100%;
  text-align: left;
}
.creative-edge-example:has([data-stacked]) > .creative-cable-controls .ui-select-trigger,
.creative-edge-example:has([data-stacked]) > .creative-cable-controls > .ui-button {
  box-sizing: border-box;
  width: 100%;
}
.creative-cable-scene[data-stacked] {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}
.creative-cable-scene[data-stacked] > .ui-card {
  box-sizing: border-box;
  width: 100%;
  max-width: 320px;
  padding: 16px;
  transform: none;
}
.creative-cable-scene[data-stacked] > .ui-card:first-child {
  padding-bottom: 40px;
}
.creative-cable-scene[data-stacked] > .ui-card:last-child {
  padding-top: 40px;
}
.creative-cable-scene[data-stacked] > .creative-cable-scene__route {
  width: 160px;
  height: 144px;
}
.creative-cable-scene[data-stacked] .creative-cable-scene__route > svg {
  height: 144px;
}
.creative-cable-scene[data-stacked] .creative-cable-grip::before {
  transform: rotate(90deg);
}
.creative-cable-grip {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.creative-cable-grip:active {
  cursor: grabbing;
}

```

### Running flow

Choose moving dashes or a short pulse over the solid route. Run and Stop change only the example state. Reduced motion keeps a static indication.

node-path-running-flow-4.jsx

```jsx
import { useId, useRef as useRef2, useState as useState2 } from "react";
import "react-dom";
import { MoreHorizontal } from "lucide-react";
import { Button, IconButton } from "@/components/ui/button";
import { ButtonGroup } from "@/components/ui/button-group";
import { Card } from "@/components/ui/card";
import { Drawer } from "@/components/ui/drawer";
import { Field } from "@/components/ui/field";
import { NodePath } from "@/components/ui/node-path";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";
import { Popover } from "@/components/ui/popover";
import { Select } from "@/components/ui/select";
import { TooltipHint } from "@/components/ui/tooltip";
import { getGraphConnectorPath } from "@/components/ui/diagram";
import { useLayoutEffect, useRef, useState } from "react";

export default function Example() {
  const { scene, stacked } = useStackedScene();
  const svg = useRef2(null);
  const endpoints = usePortEndpoints(scene, svg, stacked);
  const [connected, setConnected] = useState2(true);
  const prefix = `creative-edge-${useId().replace(/:/g, "")}`;
  const anchor = useRef2(null);
  const [open, setOpen] = useState2(false),
    [mobile, setMobile] = useState2(false),
    [running, setRunning] = useState2(false),
    [focused, setFocused] = useState2(false);
  const [connector, setConnector] = useState2("bezier"),
    [line, setLine] = useState2("solid"),
    [flow, setFlow] = useState2("pulse");
  const [start, setStart] = useState2("none"),
    [end, setEnd] = useState2("none");
  const geometry = getGraphConnectorPath({
    source:
      endpoints?.sources[0] ??
      (stacked
        ? {
            x: 80,
            y: 0,
          }
        : {
            x: 0,
            y: 76,
          }),
    target:
      endpoints?.targets[0] ??
      (stacked
        ? {
            x: 80,
            y: 200,
          }
        : {
            x: 160,
            y: 124,
          }),
    connector,
    direction: stacked ? "down" : "right",
  });
  const route = geometry.path;
  const showEditor = () => {
    setMobile(window.matchMedia("(max-width: 639px)").matches);
    setOpen(true);
  };
  const settings = (
    <div className="creative-edge-settings">
      <Button
        size="sm"
        variant="subtle"
        onClick={() => {
          setConnected((value) => !value);
          setRunning(false);
          setOpen(false);
        }}
      >
        {connected ? "Disconnect" : "Connect"}
      </Button>
      <Choice
        label="Connector"
        value={connector}
        onChange={(value) => setConnector(value)}
        options={connectorOptions}
      />
      <Choice
        label="Line"
        value={line}
        onChange={(value) => setLine(value)}
        options={[
          {
            value: "solid",
            label: "Solid",
          },
          {
            value: "dashed",
            label: "Dashed",
          },
          {
            value: "dotted",
            label: "Dotted",
          },
        ]}
      />
      <Choice
        label="Start marker"
        value={start}
        onChange={(value) => setStart(value)}
        options={markerOptions}
      />
      <Choice
        label="End marker"
        value={end}
        onChange={(value) => setEnd(value)}
        options={markerOptions}
      />
    </div>
  );
  return (
    <div className={`creative-edge-example${""}`}>
      <div
        ref={scene}
        className="creative-edge-scene"
        data-stacked={stacked || undefined}
      >
        <Card.Root variant="outline" className="creative-edge-scene__source">
          <Card.Header>
            <Card.Title>Image brief</Card.Title>
          </Card.Header>
          <Card.Content>
            <p>
              Quiet daylight.
              <br />
              Natural textures.
            </p>
          </Card.Content>
          <NodePortGroup side={stacked ? "bottom" : "right"}>
            <NodePort
              label="Text brief"
              direction="output"
              variant="core"
              dataType="text"
              connected={connected}
              onActivate={showEditor}
            />
          </NodePortGroup>
        </Card.Root>
        <div className="creative-edge-scene__route">
          <svg
            ref={svg}
            viewBox="0 0 160 200"
            preserveAspectRatio="none"
            aria-label="Image brief connected to coastal painting study"
            role="group"
          >
            <Markers prefix={prefix} />
            {connected && (
              <path
                d={route}
                className="creative-edge-hit"
                role="button"
                tabIndex={0}
                aria-label="Edit image connection"
                onFocus={() => setFocused(true)}
                onBlur={() => setFocused(false)}
                onClick={showEditor}
                onKeyDown={(event) => {
                  if (event.key === "Enter" || event.key === " ") {
                    event.preventDefault();
                    showEditor();
                  }
                }}
              />
            )}
            {connected && (
              <NodePath
                d={route}
                line={line}
                status={running ? "running" : "idle"}
                dataType="text"
                flow={flow}
                flowColor="var(--link)"
                selected={focused || open}
                markerStart={
                  start === "none" ? undefined : `url(#${prefix}-${start})`
                }
                markerEnd={
                  end === "none" ? undefined : `url(#${prefix}-${end})`
                }
                action={
                  <TooltipHint content="Edit connection">
                    <IconButton
                      ref={anchor}
                      icon={<MoreHorizontal />}
                      size="icon-xs"
                      variant="subtle"
                      aria-label="Connection settings"
                      onClick={showEditor}
                    />
                  </TooltipHint>
                }
              />
            )}
          </svg>
        </div>
        <Card.Root variant="outline" className="creative-edge-scene__target">
          <Card.Header>
            <Card.Title>Coastal painting study</Card.Title>
          </Card.Header>
          <Card.Content>
            <img
              src="/graph-examples/studio-direction.jpg"
              alt="Studio image in soft daylight"
              draggable={false}
            />
          </Card.Content>
          <NodePortGroup side={stacked ? "top" : "left"}>
            <NodePort
              label="Prompt"
              direction="input"
              variant="core"
              dataType="text"
              connected={connected}
              onActivate={showEditor}
            />
          </NodePortGroup>
        </Card.Root>
      </div>
      <div className="creative-edge-toolbar">
        <ButtonGroup aria-label="Running line treatment">
          {["dash", "pulse"].map((value) => (
            <Button
              key={value}
              size="sm"
              variant={flow === value ? "subtle" : "ghost"}
              aria-pressed={flow === value}
              onClick={() => setFlow(value)}
            >
              {value === "dash" ? "Dashed flow" : "Solid with pulse"}
            </Button>
          ))}
        </ButtonGroup>
        <Button
          size="sm"
          variant="subtle"
          disabled={!connected}
          onClick={() => setRunning((value) => !value)}
        >
          {running ? "Stop" : "Run"}
        </Button>
        <span className="creative-demo-sr" role="status">
          {running ? "Connection running" : "Connection idle"}
        </span>
      </div>
      {mobile ? (
        <Drawer.Root open={open} onOpenChange={setOpen} swipeDirection="down">
          <Drawer.Portal>
            <Drawer.Viewport>
              <Drawer.Backdrop />
              <Drawer.Popup grip>
                <Drawer.Content>
                  <Drawer.Header>
                    <Drawer.Title>Connection settings</Drawer.Title>
                    <Drawer.Close
                      render={
                        <Button size="sm" variant="ghost">
                          Done
                        </Button>
                      }
                    />
                  </Drawer.Header>
                  <Drawer.Core>{settings}</Drawer.Core>
                </Drawer.Content>
              </Drawer.Popup>
            </Drawer.Viewport>
          </Drawer.Portal>
        </Drawer.Root>
      ) : (
        <Popover.Root open={open} onOpenChange={setOpen}>
          <Popover.Portal>
            <Popover.Positioner anchor={anchor.current} side="top">
              <Popover.Popup className="creative-edge-popover">
                <Popover.Arrow />
                <Popover.Header>
                  <Popover.Title>Connection settings</Popover.Title>
                  <Popover.Close />
                </Popover.Header>
                <Popover.Core>{settings}</Popover.Core>
              </Popover.Popup>
            </Popover.Positioner>
          </Popover.Portal>
        </Popover.Root>
      )}
    </div>
  );
}

function useStackedScene() {
  const scene = useRef(null);
  const [stacked, setStacked] = useState(false);
  useLayoutEffect(() => {
    const measure = () => {
      const width = scene.current?.getBoundingClientRect().width;
      if (width) setStacked(width < 520);
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) observer.observe(scene.current);
    return () => observer.disconnect();
  }, []);
  return {
    scene,
    stacked,
  };
}

function usePortEndpoints(scene, svg, stacked = false) {
  const [endpoints, setEndpoints] = useState(null);
  useLayoutEffect(() => {
    const measure = () => {
      const bounds = svg.current?.getBoundingClientRect();
      if (!bounds?.width || !bounds.height || !scene.current) return;
      const points = (direction) =>
        [
          ...scene.current.querySelectorAll(
            `.ui-node-port--${direction} .ui-node-port__indicator`,
          ),
        ].flatMap((port) => {
          const rect = port.getBoundingClientRect();
          return rect.width && rect.height
            ? [
                {
                  x:
                    ((rect.left + rect.width / 2 - bounds.left) * 160) /
                    bounds.width,
                  y:
                    ((rect.top + rect.height / 2 - bounds.top) * 200) /
                    bounds.height,
                },
              ]
            : [];
        });
      const next = {
        sources: points("output"),
        targets: points("input"),
      };
      setEndpoints((current) =>
        JSON.stringify(current) === JSON.stringify(next) ? current : next,
      );
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) {
      observer.observe(scene.current);
      for (const child of scene.current.querySelectorAll(
        ".ui-card, .ui-node-port__indicator",
      ))
        observer.observe(child);
    }
    if (svg.current) observer.observe(svg.current);
    return () => observer.disconnect();
  }, [scene, svg, stacked]);
  return endpoints;
}

var markerOptions = [
  {
    value: "none",
    label: "None",
  },
  {
    value: "open",
    label: "Open arrow",
  },
  {
    value: "arrow",
    label: "Filled arrow",
  },
  {
    value: "dot",
    label: "Dot",
  },
];

var connectorOptions = [
  {
    value: "bezier",
    label: "Curve",
  },
  {
    value: "elbow",
    label: "Elbow",
  },
  {
    value: "straight",
    label: "Straight",
  },
];

function Choice({ label, value, onChange, options, inline = false }) {
  return (
    <Field.Root placement={inline ? "left" : "top"}>
      <Field.Label>{label}</Field.Label>
      <Select.Root
        value={value}
        onValueChange={(next) => next && onChange(next)}
        items={options}
      >
        <Select.Trigger aria-label={label} compact={inline}>
          <Select.Value />
          <Select.Icon />
        </Select.Trigger>
        <Select.Portal>
          <Select.Positioner>
            <Select.Popup>
              {options.map((item) => (
                <Select.Item key={item.value} value={item.value}>
                  <Select.ItemText>{item.label}</Select.ItemText>
                  <Select.ItemIndicator />
                </Select.Item>
              ))}
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
    </Field.Root>
  );
}

function Markers({ prefix }) {
  return (
    <defs>
      {["open", "arrow", "dot"].map((kind) => (
        <marker
          key={kind}
          id={`${prefix}-${kind}`}
          viewBox="0 0 10 10"
          refX={kind === "dot" ? 5 : 9}
          refY="5"
          markerWidth="8"
          markerHeight="8"
          markerUnits="userSpaceOnUse"
          orient="auto-start-reverse"
        >
          {kind === "dot" ? (
            <circle cx="5" cy="5" r="3" fill="var(--muted-foreground)" />
          ) : (
            <path
              d={kind === "open" ? "M1 1L9 5L1 9" : "M1 1L9 5L1 9Z"}
              fill={kind === "open" ? "none" : "var(--muted-foreground)"}
              stroke="var(--muted-foreground)"
              strokeWidth="1.5"
              strokeLinejoin="round"
            />
          )}
        </marker>
      ))}
    </defs>
  );
}

```

node-path-running-flow-4.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.creative-demo-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.creative-edge-example {
  box-sizing: border-box;
  width: 760px;
  max-width: 100%;
  padding: 24px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-edge-scene {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(64px, .8fr) minmax(0, 1fr);
  align-items: center;
  gap: 0;
  min-width: 0;
}
.creative-edge-scene > .ui-card {
  position: relative;
  z-index: 1;
  min-width: 0;
}
.creative-edge-scene .ui-card__title {
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
}
.creative-edge-scene p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 20px;
}
.creative-edge-scene__source {
  transform: translateY(-24px);
}
.creative-edge-scene__target {
  transform: translateY(24px);
}
.creative-edge-scene img {
  display: block;
  width: 100%;
  height: 88px;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.creative-edge-scene__route {
  position: relative;
  height: 200px;
  min-width: 0;
}
.creative-edge-scene__route > svg {
  display: block;
  width: 100%;
  height: 200px;
  overflow: visible;
}
.creative-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 24;
  pointer-events: stroke;
  outline: none;
  cursor: pointer;
}
.creative-edge-scene .creative-edge-scene__action {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
}
.creative-edge-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}
.creative-edge-popover {
  width: 280px;
}
.creative-edge-settings {
  display: grid;
  gap: 16px;
}
.creative-edge-example--thumbnail {
  width: 320px;
  padding: 16px;
}
.creative-edge-example--static-thumbnail {
  box-sizing: border-box;
  width: 100%;
  min-height: 160px;
  padding: 16px;
}
.creative-edge-scene--static-thumbnail {
  grid-template-columns: minmax(0, 1fr) minmax(56px, .6fr) minmax(0, 1fr);
  min-height: 128px;
}
.creative-edge-scene--static-thumbnail > .ui-card {
  padding: 12px;
  gap: 8px;
  transform: none;
}
.creative-edge-scene--static-thumbnail .ui-card__header {
  text-align: center;
}
.creative-edge-scene--static-thumbnail .ui-card__title {
  font-size: 12px;
  line-height: 16px;
  font-weight: 400;
}
.creative-edge-scene--static-thumbnail p {
  font-size: 12px;
  line-height: 16px;
}
.creative-edge-scene--static-thumbnail .creative-edge-scene__route {
  height: 120px;
}
.creative-edge-scene--static-thumbnail .creative-edge-scene__route > svg {
  height: 120px;
}
.creative-edge-example--thumbnail .creative-edge-scene {
  grid-template-columns: minmax(0, 1fr) 72px minmax(0, 1fr);
}
.creative-edge-example--thumbnail .ui-card__title {
  font-size: 12px;
  line-height: 16px;
}
.creative-edge-example--thumbnail p {
  font-size: 11px;
  line-height: 16px;
}
.creative-edge-example--thumbnail img {
  height: 64px;
}
@media (max-width: 560px) {
  .creative-edge-example {
    padding: 16px;
  }
  .creative-edge-scene .ui-card {
    padding: 8px;
    gap: 8px;
    border-radius: var(--radius-md);
  }
  .creative-edge-scene .ui-card__title {
    font-size: 12px;
    line-height: 16px;
  }
  .creative-edge-scene p {
    font-size: 12px;
    line-height: 18px;
  }
}
.creative-edge-example--static-thumbnail .ui-node-port svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}
.creative-edge-example--static-thumbnail .creative-edge-scene > .ui-card {
  padding: 12px;
}

/* apps/web/src/demos/library/edge-path-refinement.css */
.creative-edge-scene > .creative-edge-scene__source {
  padding-inline-end: 36px;
}
.creative-edge-scene > .creative-edge-scene__target {
  padding-inline-start: 36px;
}
.creative-edge-scene[data-stacked] {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}
.creative-edge-scene[data-stacked] > .ui-card {
  box-sizing: border-box;
  width: 100%;
  max-width: 320px;
  padding: 16px;
  transform: none;
}
.creative-edge-scene[data-stacked] > .ui-card:first-child {
  padding-bottom: 40px;
}
.creative-edge-scene[data-stacked] > .ui-card:last-child {
  padding-top: 40px;
}
.creative-edge-scene[data-stacked] > .creative-edge-scene__route {
  width: 160px;
  height: 144px;
}
.creative-edge-scene[data-stacked] .creative-edge-scene__route > svg {
  height: 144px;
}
@media (pointer: coarse) {
  .creative-edge-hit {
    stroke-width: 44;
  }
}
.creative-edge-hit {
  vector-effect: non-scaling-stroke;
  touch-action: manipulation;
}

```

## API reference

NodePath API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| action | ReactNode | — | Optional caller-owned control at half the path length. Omit to hide it. A direct Ghost IconButton gets a compact 24×16px face with a 44px target. |
| d | string | — | Required SVG path data supplied by the caller. |
| line | 'solid' \| 'dashed' \| 'dotted' | 'solid' | Independent line style. |
| status | 'idle' \| 'running' \| 'success' \| 'error' | 'idle' | Explicit paint state; running enables the selected flow treatment. |
| flow | 'dash' \| 'pulse' | 'dash' | Dash retains running dashes; pulse moves a short highlight over the authored base line. |
| flowColor | string | — | Optional caller emphasis for the decorative pulse. |
| dataType | string | — | Optional content type that paints the edge in the matching port color so both ends of a connection share one color. Omit for a neutral edge. |
| selected | boolean | false | Darkens the visible 1.5px line independently from status. |
| casing | boolean | true | Paints a 5px, aria-hidden, pointer-free underlay before the visible path. Set false to omit it; the caller surface is `--graph-edge-surface` or `--background`. Casing clarifies crossings but does not route them. |
| native SVG path props and ref | SVGProps<SVGPathElement>; SVGPathElement | — | Forwards marker options, style, className, aria/data attributes and ref to the visible path. The stroke stays the same width when the SVG scales. |
