@mcurcio/patchbay 0.8.0 → 0.10.0

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.
Files changed (51) hide show
  1. package/README.md +11 -2
  2. package/dist/composites.css +1 -1
  3. package/dist/composites.js +399 -254
  4. package/dist/composites.js.map +1 -1
  5. package/dist/graph.css +1 -1
  6. package/dist/graph.js +593 -286
  7. package/dist/graph.js.map +1 -1
  8. package/dist/hooks.js.map +1 -1
  9. package/dist/primitives.css +1 -1
  10. package/dist/primitives.js +143 -126
  11. package/dist/primitives.js.map +1 -1
  12. package/dist/shell.css +1 -1
  13. package/dist/shell.js +96 -71
  14. package/dist/shell.js.map +1 -1
  15. package/dist/types/composites/banner/Banner.d.ts +2 -2
  16. package/dist/types/composites/change-list/ChangeList.d.ts +44 -0
  17. package/dist/types/composites/change-list/index.d.ts +2 -0
  18. package/dist/types/composites/diagnostic-list/DiagnosticList.d.ts +23 -0
  19. package/dist/types/composites/diagnostic-list/index.d.ts +2 -0
  20. package/dist/types/composites/index.d.ts +2 -0
  21. package/dist/types/composites/status-words/StatusWords.d.ts +1 -1
  22. package/dist/types/graph/add-at/useAddAt.d.ts +11 -5
  23. package/dist/types/graph/canvas-tools/CanvasTools.d.ts +7 -2
  24. package/dist/types/graph/connect-hints/connectTargets.d.ts +22 -0
  25. package/dist/types/graph/connect-hints/index.d.ts +3 -1
  26. package/dist/types/graph/connect-hints/useConnectHints.d.ts +9 -0
  27. package/dist/types/graph/connect-status/ConnectStatus.d.ts +30 -0
  28. package/dist/types/graph/connect-status/index.d.ts +2 -0
  29. package/dist/types/graph/context-at/index.d.ts +2 -0
  30. package/dist/types/graph/context-at/useContextAt.d.ts +43 -0
  31. package/dist/types/graph/empty-canvas-hint/EmptyCanvasHint.d.ts +33 -0
  32. package/dist/types/graph/empty-canvas-hint/index.d.ts +2 -0
  33. package/dist/types/graph/follow-fit/useFollowFit.d.ts +1 -0
  34. package/dist/types/graph/ghost-node/GhostNode.d.ts +32 -0
  35. package/dist/types/graph/ghost-node/index.d.ts +2 -0
  36. package/dist/types/graph/ghost-wire/GhostWire.d.ts +1 -1
  37. package/dist/types/graph/index.d.ts +4 -0
  38. package/dist/types/graph/meter/Meter.d.ts +8 -1
  39. package/dist/types/graph/meter/index.d.ts +1 -1
  40. package/dist/types/graph/wire/Wire.d.ts +4 -4
  41. package/dist/types/hooks/use-toasts/toastQueue.d.ts +1 -1
  42. package/dist/types/primitives/glyph/Glyph.d.ts +14 -0
  43. package/dist/types/primitives/glyph/index.d.ts +2 -0
  44. package/dist/types/primitives/icon-button/index.d.ts +1 -0
  45. package/dist/types/primitives/index.d.ts +1 -0
  46. package/dist/types/primitives/key-value/KeyValue.d.ts +3 -3
  47. package/dist/types/primitives/sheet/Sheet.d.ts +9 -3
  48. package/dist/types/primitives/spinner/Spinner.d.ts +1 -1
  49. package/dist/types/shell/app-shell/AppShell.d.ts +9 -1
  50. package/package.json +1 -1
  51. /package/dist/types/primitives/{dialog → icon-button}/CloseGlyph.d.ts +0 -0
package/dist/graph.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"graph.js","names":["_Fragment","_Fragment","_Fragment","isPane","target","endOf","event","touch","elementAt","x","y","useAddAt","enabled","options","useReactFlow","latest","useRef","origin","useMemo","add","on","toFlow","nodeId","handleType","from","state","end","fallback","slowMotionMs","value","element","parsed","defaultCanvasToolsLabels","glyph","path","glyphs","CanvasTools","words","labels","flow","store","useStoreApi","duration","tool","keys","keyShortcuts","name","IconButton","pressed","act","Fragment","Panel","className","ToolGroup","onFit","fitOptions","onTidy","onMinimap","minimap","children","MiniMap","minimapNodeClassName","mergeFlowProps","objects","values","handlers","object","list","merged","only","args","each","ConnectHintsContext","createContext","ConnectHints","useConnectHintsValue","useContext","verdictKey","to","samePort","a","b","useConnectHints","rule","canConnect","verdicts","setOrigin","useState","judge","kept","key","known","verdict","flowProps","connection","side","port","at","allMeasured","node","useFollowFit","width","useStore","height","measured","following","setFollowing","fittedFor","land","useCallback","last","fit","now","stop","movedFrom","viewport","GhostWire","labelX","labelY","getBezierPath","sourceX","sourceY","sourcePosition","targetX","targetY","targetPosition","tone","data","label","BaseEdge","EdgeLabelRenderer","defaultMeterScale","meterTitleEveryMs","toDb","linear","meterFraction","db","floor","formatDb","defaultMeterTitle","peakDb","rmsDb","defaultMeterLabels","silent","createPainter","scale","initial","level","frame","hovered","titledAt","stale","tickAt","falling","fallen","writeTitle","clipped","paint","tick","lit","\"peak\"","\"clipped\"","run","wake","next","moved","peak","rms","Meter","rest","painter","attach","useLiveValue","subscribe","read","useImperativeHandle","ref","mid","hot","zones","classes","zoneStyle","style","orientation","onPointerEnter","onPointerLeave","knownHints","PortRow","ownHint","ownReason","isInput","drag","useNodeId","fromDrag","id","hint","reason","shown","refused","Handle","Position","connectable","typeLabel","problem","WarnMark","trailing","defaultNodeBoxLabels","knownChanges","NodeBox","titleId","useId","layout","ports","inputs","outputs","changeWord","change","hasPorts","inputRows","outputRows","disabled","failed","selected","title","subtitle","Badge","status","line","footer","usePortsMeasured","updateNodeInternals","useUpdateNodeInternals","NODE_WIDTH","NODE_HEADER","NODE_LINE","NODE_ROW","NODE_PAD","NODE_FOOTER","HANDLE_SIZE","HANDLE_HIT","nodePortRows","nodeBoxSize","rows","ARROW_LENGTH","ARROW_HALF","emphasisOf","arrowPath","dx","dy","baseX","baseY","px","py","WireBody","memo","arrow","interactionWidth","Wire","showArrow","emphasis"],"sources":["../src/graph/add-at/useAddAt.ts","../src/graph/canvas-tools/motion.ts","../src/graph/canvas-tools/CanvasTools.tsx","../src/graph/connect-hints/mergeFlowProps.ts","../src/graph/connect-hints/useConnectHints.tsx","../src/graph/follow-fit/useFollowFit.ts","../src/graph/ghost-wire/GhostWire.tsx","../src/graph/meter/Meter.tsx","../src/graph/port-row/PortRow.tsx","../src/graph/node-box/NodeBox.tsx","../src/graph/node-box/geometry.ts","../src/graph/wire/Wire.tsx"],"sourcesContent":["// Adding at a place on the canvas (docs/graph.md#useaddat): a double-click on empty canvas, or a wire dropped there,\n// asks the app to add a node at that point, in flow coordinates, with the port the wire came from. Only the pane\n// counts: a double-click or a drop on a node, an edge, a handle or a panel is not empty canvas.\nimport { type OnConnectEnd, type OnConnectStart, useReactFlow } from \"@xyflow/react\";\nimport { type MouseEvent as ReactMouseEvent, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type { PortRef } from \"../connect-hints\";\nimport type { PortSide } from \"../port-row\";\n\n/** A point in flow coordinates. */\nexport type FlowPoint = { x: number; y: number };\n\n/** Called with where to add, and the port a dropped wire came from (absent for a double-click). */\nexport type OnAddAt = (point: FlowPoint, from?: PortRef & { side: PortSide }) => void;\n\n/** The props `useAddAt` gives `<ReactFlow>`. */\nexport type AddAtFlowProps = {\n onDoubleClick: (event: ReactMouseEvent<HTMLDivElement>) => void;\n onConnectStart: OnConnectStart;\n onConnectEnd: OnConnectEnd;\n zoomOnDoubleClick: false;\n};\n\nexport type AddAtOptions = {\n /** false switches adding off (as while the graph is read-only); true by default. */\n enabled?: boolean;\n};\n\n/** Whether the element is this canvas's empty pane, not anything drawn on it. */\nconst isPane = (target: EventTarget | null) =>\n target instanceof Element && target.classList.contains(\"react-flow__pane\");\n\n/** Where a mouse or touch event ended, in the window's coordinates; a touch's end is in `changedTouches`. */\nfunction endOf(event: MouseEvent | TouchEvent): { x: number; y: number } | null {\n if (\"changedTouches\" in event) {\n const touch = event.changedTouches[0];\n return touch === undefined ? null : { x: touch.clientX, y: touch.clientY };\n }\n return { x: event.clientX, y: event.clientY };\n}\n\n/** The element at a point in the window, or null where the browser cannot say. */\nconst elementAt = ({ x, y }: { x: number; y: number }) =>\n typeof document.elementFromPoint === \"function\" ? document.elementFromPoint(x, y) : null;\n\n/**\n * Calls `onAddAt` for a double-click on empty canvas and for a wire dropped there where no handle took it. Its\n * `flowProps` go to `<ReactFlow>` (through `mergeFlowProps` with others); it turns React Flow's zoom on double-click\n * off, as the double-click is the add.\n */\nexport function useAddAt(onAddAt: OnAddAt, options: AddAtOptions = {}): { flowProps: AddAtFlowProps } {\n const enabled = options.enabled ?? true;\n const { screenToFlowPosition } = useReactFlow();\n const latest = useRef({ onAddAt, enabled, screenToFlowPosition });\n useLayoutEffect(() => {\n latest.current = { onAddAt, enabled, screenToFlowPosition };\n });\n // The handle the wire in progress began at; null outside a drag.\n const origin = useRef<(PortRef & { side: PortSide }) | null>(null);\n\n const flowProps = useMemo<AddAtFlowProps>(\n () => ({\n onDoubleClick: (event) => {\n const { onAddAt: add, enabled: on, screenToFlowPosition: toFlow } = latest.current;\n if (!on || !isPane(event.target)) return;\n add(toFlow({ x: event.clientX, y: event.clientY }));\n },\n onConnectStart: (_event, { nodeId, handleId, handleType }) => {\n origin.current =\n nodeId === null ? null : { nodeId, handleId, side: handleType === \"target\" ? \"input\" : \"output\" };\n },\n onConnectEnd: (event, state) => {\n const from = origin.current;\n origin.current = null;\n const { onAddAt: add, enabled: on, screenToFlowPosition: toFlow } = latest.current;\n if (!on || from === null || state.toHandle !== null) return;\n const end = endOf(event);\n if (end === null) return;\n // A mouse's up is on the element under it; a touch's end is on the element it began on, so ask the page.\n const target = \"changedTouches\" in event ? elementAt(end) : event.target;\n if (!isPane(target)) return;\n add(toFlow(end), from);\n },\n zoomOnDoubleClick: false,\n }),\n [],\n );\n\n return { flowProps };\n}\n","// How long a view move takes that a person asked for (a zoom, a fit; docs/graph.md#canvastools): the canvas's\n// --pb-motion-slow, which tokens.css sets to 0 ms under reduced motion, so a brand's duration and the person's wish\n// both hold. Read from the canvas's element at the move, since a brand or the theme can change it at any time.\n\nconst fallback = 180;\n\n/** `--pb-motion-slow` on `element` in milliseconds; without the tokens loaded, 180 ms, or 0 under reduced motion. */\nexport function slowMotionMs(element: Element | null | undefined): number {\n const value =\n element === null || element === undefined ? \"\" : getComputedStyle(element).getPropertyValue(\"--pb-motion-slow\");\n const parsed = /^\\s*(\\d+(?:\\.\\d+)?)(ms|s)\\s*$/.exec(value);\n if (parsed !== null) return Number(parsed[1]) * (parsed[2] === \"s\" ? 1000 : 1);\n const reduced =\n typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n return reduced ? 0 : fallback;\n}\n","// A canvas's tools (docs/graph.md#canvastools), a child of the app's own <ReactFlow>: zoom, fit, and when the app\n// gives them, tidy and the minimap, as one ToolGroup in React Flow's <Panel>, and React Flow's <MiniMap> while the\n// minimap is on. The layout behind tidy and the minimap's state are the app's; the zoom and fit move the view through\n// React Flow over --pb-motion-slow, at once under reduced motion.\nimport {\n type FitViewOptions,\n MiniMap,\n type Node,\n Panel,\n type PanelPosition,\n useReactFlow,\n useStoreApi,\n} from \"@xyflow/react\";\nimport type { ReactNode } from \"react\";\nimport { IconButton, ToolGroup } from \"../../primitives\";\nimport { slowMotionMs } from \"./motion\";\nimport \"./CanvasTools.css\";\n\n/** The tools' words, each replaceable. */\nexport interface CanvasToolsLabels {\n /** The tool group's accessible name: \"Canvas\". */\n toolbar: string;\n zoomIn: string;\n zoomOut: string;\n fit: string;\n tidy: string;\n minimap: string;\n}\n\nexport const defaultCanvasToolsLabels: CanvasToolsLabels = {\n toolbar: \"Canvas\",\n zoomIn: \"Zoom in\",\n zoomOut: \"Zoom out\",\n fit: \"Fit the view\",\n tidy: \"Tidy the layout\",\n minimap: \"Minimap\",\n};\n\n/** The app's own key bindings for the tools, as `aria-keyshortcuts` values: shown, not bound. */\nexport type CanvasToolsShortcuts = Partial<Record<\"zoomIn\" | \"zoomOut\" | \"fit\" | \"tidy\" | \"minimap\", string>>;\n\nexport type CanvasToolsProps<NodeType extends Node = Node> = {\n /** Where the panel sits on the canvas, React Flow's `PanelPosition`: \"bottom-left\" by default. */\n position?: PanelPosition | (string & {});\n /** React Flow's fit options for the fit tool. */\n fitOptions?: FitViewOptions<NodeType>;\n /** Replaces the fit tool's own fit (pass useFollowFit's `fit`, so the tool also resumes following). */\n onFit?: () => void;\n /** The tidy tool, shown only when given: the layout is the app's. */\n onTidy?: () => void;\n /** Whether the minimap is on: the minimap tool is pressed and React Flow's <MiniMap> is drawn. */\n minimap?: boolean;\n /** The minimap tool, shown only when given: called with the state a press asks for. */\n onMinimap?: (next: boolean) => void;\n /** The class of each node's shape in the minimap, so the app colours it by the node's state. */\n minimapNodeClassName?: string | ((node: NodeType) => string);\n keyShortcuts?: CanvasToolsShortcuts;\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<CanvasToolsLabels>;\n /** Added to the panel's own `pb-canvas-tools` class. */\n className?: string;\n /** More tools (IconButtons) after patchbay's. */\n children?: ReactNode;\n};\n\nconst glyph = (path: string) => (\n <svg viewBox=\"0 0 16 16\" width=\"14\" height=\"14\" aria-hidden=\"true\">\n <path d={path} fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n);\n\nconst glyphs = {\n zoomIn: glyph(\"M3 8h10M8 3v10\"),\n zoomOut: glyph(\"M3 8h10\"),\n fit: glyph(\"M2 6V2h4M10 2h4v4M14 10v4h-4M6 14H2v-4\"),\n tidy: glyph(\"M2 2h5v5H2zM9 2h5v5H9zM2 9h5v5H2zM9 9h5v5H9z\"),\n minimap: glyph(\"M1.5 3h13v10h-13zM8.5 8h4v3h-4z\"),\n};\n\nexport function CanvasTools<NodeType extends Node = Node>({\n position = \"bottom-left\",\n fitOptions,\n onFit,\n onTidy,\n minimap = false,\n onMinimap,\n minimapNodeClassName,\n keyShortcuts,\n labels,\n className,\n children,\n}: CanvasToolsProps<NodeType>) {\n const words = { ...defaultCanvasToolsLabels, ...labels };\n const flow = useReactFlow<NodeType>();\n const store = useStoreApi<NodeType>();\n const duration = () => slowMotionMs(store.getState().domNode);\n\n const tool = (name: keyof CanvasToolsShortcuts, act: () => void, pressed?: boolean) => {\n const keys = keyShortcuts?.[name];\n return (\n <IconButton\n label={words[name]}\n title={keys === undefined || keys === \"\" ? words[name] : `${words[name]} (${keys})`}\n aria-keyshortcuts={keys === \"\" ? undefined : keys}\n aria-pressed={pressed}\n onClick={act}\n >\n {glyphs[name]}\n </IconButton>\n );\n };\n\n return (\n <>\n <Panel\n position={position as PanelPosition}\n className={className === undefined ? \"pb-canvas-tools\" : `pb-canvas-tools ${className}`}\n >\n <ToolGroup label={words.toolbar}>\n {tool(\"zoomIn\", () => void flow.zoomIn({ duration: duration() }))}\n {tool(\"zoomOut\", () => void flow.zoomOut({ duration: duration() }))}\n {tool(\"fit\", () => {\n if (onFit !== undefined) onFit();\n else void flow.fitView({ ...fitOptions, duration: duration() });\n })}\n {onTidy !== undefined && tool(\"tidy\", onTidy)}\n {onMinimap !== undefined &&\n tool(\n \"minimap\",\n () => {\n onMinimap(!minimap);\n },\n minimap,\n )}\n {children}\n </ToolGroup>\n </Panel>\n {minimap && (\n <MiniMap<NodeType>\n className=\"pb-canvas-minimap\"\n ariaLabel={words.minimap}\n nodeClassName={minimapNodeClassName}\n />\n )}\n </>\n );\n}\n","// Joins the props several hooks give <ReactFlow> (docs/graph.md#mergeflowprops), so each hook's handler still runs\n// when two of them, or the app, handle the same event.\n\ntype UnionToIntersection<U> = (U extends unknown ? (each: U) => void : never) extends (each: infer I) => void\n ? I\n : never;\n\n/** The objects' props together: each handler is every object's handler for that name. */\nexport type MergedFlowProps<T extends readonly (object | undefined)[]> = UnionToIntersection<\n Exclude<T[number], undefined>\n>;\n\ntype Handler = (...args: unknown[]) => unknown;\n\n/**\n * One object of `<ReactFlow>` props from several: a handler given by more than one object calls each in order, and\n * `isValidConnection` accepts only when each accepts (it stops at the first that refuses). Any other prop is the last\n * object's that gives it; `undefined` gives nothing.\n */\nexport function mergeFlowProps<const T extends readonly (object | undefined)[]>(...objects: T): MergedFlowProps<T> {\n const values = new Map<string, unknown>();\n const handlers = new Map<string, Handler[]>();\n for (const object of objects) {\n if (object === undefined) continue;\n for (const [name, value] of Object.entries(object)) {\n if (value === undefined) continue;\n if (typeof value === \"function\") {\n const list = handlers.get(name) ?? [];\n list.push(value as Handler);\n handlers.set(name, list);\n values.delete(name);\n } else {\n values.set(name, value);\n handlers.delete(name);\n }\n }\n }\n const merged: Record<string, unknown> = Object.fromEntries(values);\n for (const [name, list] of handlers) {\n const [only] = list;\n if (list.length === 1 && only !== undefined) merged[name] = only;\n else if (name === \"isValidConnection\")\n merged[name] = (...args: unknown[]) => list.every((each) => each(...args) === true);\n else\n merged[name] = (...args: unknown[]) => {\n for (const each of list) each(...args);\n };\n }\n return merged as MergedFlowProps<T>;\n}\n","// One rule for which ports may be joined (docs/graph.md#useconnecthints), used both for the hints every PortRow shows\n// while a wire is dragged and for React Flow's own check on the drop. The state changes twice per drag, at its start\n// and its end, never per pointer move; each candidate handle's verdict is asked of the rule once per drag and kept.\nimport type { Connection, Edge, OnConnectEnd, OnConnectStart } from \"@xyflow/react\";\nimport { createContext, type ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { PortHint, PortSide } from \"../port-row\";\n\n/** One handle: its node's id and its handle id (`null` for a handle without one). */\nexport type PortRef = { nodeId: string; handleId: string | null };\n\n/**\n * Whether a wire may join `from` (always the output) to `to` (always the input), whichever end the drag began at:\n * `true` accepts, `false` refuses, a string refuses and is the reason.\n */\nexport type CanConnect = (from: PortRef, to: PortRef) => boolean | string;\n\n/** What one handle shows while a wire is dragged, and why when it refuses. */\nexport type PortHintOf = { hint: PortHint; reason?: string };\n\n/** The drag in progress, as `<ConnectHints>` hands it to every `PortRow`; `null` while no wire is dragged. */\nexport type ConnectHintsValue = {\n /** The handle the drag began at, and its side. */\n origin: PortRef & { side: PortSide };\n /** The hint for one handle: `origin`, `ok` or `no` (with its reason) on the other side, `null` on the origin's. */\n hintFor: (port: PortRef, side: PortSide) => PortHintOf;\n} | null;\n\n/** The handlers `useConnectHints` gives `<ReactFlow>`. */\nexport type ConnectHintsFlowProps = {\n onConnectStart: OnConnectStart;\n onConnectEnd: OnConnectEnd;\n isValidConnection: (connection: Edge | Connection) => boolean;\n};\n\nconst ConnectHintsContext = createContext<ConnectHintsValue>(null);\n\n/** Hands a drag's hints to every `PortRow` inside it. */\nexport function ConnectHints({ value, children }: { value: ConnectHintsValue; children?: ReactNode }) {\n return <ConnectHintsContext value={value}>{children}</ConnectHintsContext>;\n}\n\n/** The drag's hints from the nearest `<ConnectHints>`, or `null` outside one or while no wire is dragged. */\nexport function useConnectHintsValue(): ConnectHintsValue {\n return useContext(ConnectHintsContext);\n}\n\nconst verdictKey = (from: PortRef, to: PortRef) => JSON.stringify([from.nodeId, from.handleId, to.nodeId, to.handleId]);\n\nconst samePort = (a: PortRef, b: PortRef) => a.nodeId === b.nodeId && a.handleId === b.handleId;\n\n/**\n * Tracks a wire's drag from React Flow's connect start to its end and judges each candidate handle by `canConnect`.\n * `flowProps` goes to `<ReactFlow>` (through `mergeFlowProps` with others), `value` to `<ConnectHints>`.\n */\nexport function useConnectHints(canConnect: CanConnect): {\n value: ConnectHintsValue;\n flowProps: ConnectHintsFlowProps;\n} {\n const rule = useRef(canConnect);\n useLayoutEffect(() => {\n rule.current = canConnect;\n });\n // The verdicts of the drag in progress, so each candidate is judged once per drag; none outside a drag.\n const verdicts = useRef<Map<string, boolean | string> | null>(null);\n const [origin, setOrigin] = useState<(PortRef & { side: PortSide }) | null>(null);\n\n const judge = useMemo(\n () =>\n (from: PortRef, to: PortRef): boolean | string => {\n const kept = verdicts.current;\n if (kept === null) return rule.current(from, to);\n const key = verdictKey(from, to);\n const known = kept.get(key);\n if (known !== undefined) return known;\n const verdict = rule.current(from, to);\n kept.set(key, verdict);\n return verdict;\n },\n [],\n );\n\n const flowProps = useMemo<ConnectHintsFlowProps>(\n () => ({\n onConnectStart: (_event, { nodeId, handleId, handleType }) => {\n if (nodeId === null) return;\n verdicts.current = new Map();\n setOrigin({ nodeId, handleId, side: handleType === \"target\" ? \"input\" : \"output\" });\n },\n onConnectEnd: () => {\n verdicts.current = null;\n setOrigin(null);\n },\n isValidConnection: (connection) =>\n judge(\n { nodeId: connection.source, handleId: connection.sourceHandle ?? null },\n { nodeId: connection.target, handleId: connection.targetHandle ?? null },\n ) === true,\n }),\n [judge],\n );\n\n const value = useMemo<ConnectHintsValue>(() => {\n if (origin === null) return null;\n return {\n origin,\n hintFor: (port, side) => {\n if (side === origin.side) return { hint: samePort(port, origin) ? \"origin\" : null };\n const at: PortRef = { nodeId: origin.nodeId, handleId: origin.handleId };\n const verdict = side === \"input\" ? judge(at, port) : judge(port, at);\n if (verdict === true) return { hint: \"ok\" };\n return typeof verdict === \"string\" ? { hint: \"no\", reason: verdict } : { hint: \"no\" };\n },\n };\n }, [origin, judge]);\n\n return { value, flowProps };\n}\n","// Keeping the whole graph in view until the person takes the view over (docs/graph.md#usefollowfit). While following,\n// the view fits again when the app's key changes or the canvas changes size, each time once every node is measured;\n// a move the person makes (one that changes the viewport, not a press that moves nothing) stops it, as does stop(),\n// and fit() fits and follows again. onFitted comes in the frame after each fit lands.\nimport {\n type FitViewOptions,\n type Node,\n type OnMove,\n type ReactFlowState,\n type Viewport,\n useReactFlow,\n useStore,\n useStoreApi,\n} from \"@xyflow/react\";\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport { slowMotionMs } from \"../canvas-tools/motion\";\n\nexport type FollowFitOptions<NodeType extends Node = Node> = {\n /** The app's value that changes when nodes are added, removed or laid out; a change fits again while following. */\n key: unknown;\n /** React Flow's fit options, for every fit. */\n fitOptions?: FitViewOptions<NodeType>;\n /** Called with the viewport after each fit has landed, in the frame after the viewport is set. */\n onFitted?: (viewport: Viewport) => void;\n};\n\n/** The props `useFollowFit` gives `<ReactFlow>`. */\nexport type FollowFitFlowProps = { onMoveStart: OnMove; onMoveEnd: OnMove };\n\nexport type FollowFit = {\n /** Whether the view fits again on its own: true from the start, false once the person moves the view. */\n following: boolean;\n /** Fits now, moving as the fit tool does, and follows again. */\n fit: () => void;\n /** Stops following, as the person's own move does: for an app that moves the view itself (going to a node). */\n stop: () => void;\n flowProps: FollowFitFlowProps;\n};\n\n/** Whether every node React Flow shows has been measured (none counts as all). */\nconst allMeasured = (state: ReactFlowState) => {\n for (const node of state.nodeLookup.values()) {\n if (node.hidden !== true && (node.measured.width === undefined || node.measured.height === undefined)) return false;\n }\n return true;\n};\n\ntype Fitted = { key: unknown; width: number; height: number };\n\nexport function useFollowFit<NodeType extends Node = Node>({\n key,\n fitOptions,\n onFitted,\n}: FollowFitOptions<NodeType>): FollowFit {\n const flow = useReactFlow<NodeType>();\n const store = useStoreApi();\n const width = useStore((state) => state.width);\n const height = useStore((state) => state.height);\n const measured = useStore(allMeasured);\n const [following, setFollowing] = useState(true);\n const latest = useRef({ key, width, height, fitOptions, onFitted });\n useLayoutEffect(() => {\n latest.current = { key, width, height, fitOptions, onFitted };\n });\n // What the last fit was for, so a render that changes none of it does not fit again.\n const fittedFor = useRef<Fitted | null>(null);\n\n const land = useCallback(\n async (duration: number) => {\n // With no node there is nothing to fit, and the view stays; onFitted still says the layout is ready.\n if (store.getState().nodeLookup.size > 0) await flow.fitView({ ...latest.current.fitOptions, duration });\n requestAnimationFrame(() => {\n latest.current.onFitted?.(flow.getViewport());\n });\n },\n [flow, store],\n );\n\n useEffect(() => {\n if (!following || width === 0 || height === 0) return;\n // The store, not this render's `measured`, which only wakes the effect: nodes React Flow took in this commit (its\n // effects run before this one) are in the store but not yet measured, while this render still says all were.\n if (!allMeasured(store.getState())) return;\n const last = fittedFor.current;\n if (last !== null && Object.is(last.key, key) && last.width === width && last.height === height) return;\n fittedFor.current = { key, width, height };\n void land(0);\n }, [following, key, width, height, measured, store, land]);\n\n const fit = useCallback(() => {\n const now = latest.current;\n fittedFor.current = { key: now.key, width: now.width, height: now.height };\n setFollowing(true);\n void land(slowMotionMs(store.getState().domNode));\n }, [land, store]);\n\n const stop = useCallback(() => {\n setFollowing(false);\n }, []);\n\n // Where the person's move began. React Flow starts a move on every press on the pane, also one that moves nothing (a\n // click to deselect, a double-click to add), so following stops only when the move ends somewhere else.\n const movedFrom = useRef<Viewport | null>(null);\n const flowProps = useMemo<FollowFitFlowProps>(\n () => ({\n // A move made by code (a fit, a zoom from a tool) has no event; only the person's own move counts.\n // A move by code that starts or ends during the person's (a fit landing mid-wheel) leaves theirs as it was.\n onMoveStart: (event, viewport) => {\n if (event !== null) movedFrom.current = viewport;\n },\n onMoveEnd: (event, viewport) => {\n if (event === null) return;\n const from = movedFrom.current;\n movedFrom.current = null;\n if (from === null) return;\n if (from.x !== viewport.x || from.y !== viewport.y || from.zoom !== viewport.zoom) setFollowing(false);\n },\n }),\n [],\n );\n\n return { following, fit, stop, flowProps };\n}\n","// A ghost wire (docs/graph.md#ghostwire): a request on its way, before the app's graph holds the edge. An edge type the\n// app registers as `ghost`; it draws with React Flow's BaseEdge but has no hit path and takes no pointer events, so it\n// can be neither hovered nor clicked. How long a refused one stays is the app's: it removes the edge.\nimport { BaseEdge, type Edge, EdgeLabelRenderer, type EdgeProps, getBezierPath } from \"@xyflow/react\";\nimport { type ReactNode, useMemo } from \"react\";\nimport \"./GhostWire.css\";\n\n/** `pending` (the default) or `refused`; any other string is drawn as `pending`. */\nexport type GhostWireTone = \"pending\" | \"refused\" | (string & {});\n\n/** A ghost wire's look, as React Flow's edge `data`. */\nexport type GhostWireData = {\n /** `pending` (dashed in the quiet tone, dimmed) or `refused` (the error tone). */\n tone?: GhostWireTone;\n /** At the midpoint, on the raised surface; it takes no pointer events. */\n label?: ReactNode;\n};\n\n/** An edge drawn by `GhostWire`: register it as `edgeTypes={{ ghost: GhostWire }}`. */\nexport type GhostWireEdge = Edge<GhostWireData, \"ghost\">;\n\n/** Draws a request's wire between two handles while it is on its way. */\nexport function GhostWire({\n id,\n sourceX,\n sourceY,\n targetX,\n targetY,\n sourcePosition,\n targetPosition,\n data,\n}: EdgeProps<GhostWireEdge>) {\n const [path, labelX, labelY] = useMemo(\n () => getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition }),\n [sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition],\n );\n const tone = data?.tone === \"refused\" ? \"refused\" : \"pending\";\n const label = data?.label;\n return (\n <>\n <g className=\"pb-ghost-wire\" data-tone={tone} aria-hidden=\"true\">\n <BaseEdge id={id} path={path} className=\"pb-ghost-wire-path\" interactionWidth={0} />\n </g>\n {label !== undefined && label !== null && (\n <EdgeLabelRenderer>\n <div\n className=\"pb-ghost-wire-label\"\n data-tone={tone}\n style={{ transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)` }}\n >\n {label}\n </div>\n </EdgeLabelRenderer>\n )}\n </>\n );\n}\n","// A level bar on a decibel scale (docs/graph.md#meter). It is painted through refs and never re-renders through\n// React for a level: useLiveValue hands each new value to paint(), which sets CSS variables and data attributes on\n// the element, and requestAnimationFrame runs only while something moves (a new value, a held tick that will fall, a\n// lit clip lamp counting down). Times come from performance.now(), a monotonic clock.\nimport {\n type ComponentPropsWithoutRef,\n type CSSProperties,\n type Ref,\n useCallback,\n useImperativeHandle,\n useLayoutEffect,\n useState,\n} from \"react\";\nimport { type LiveSubscribe, useLiveValue } from \"../../hooks\";\nimport \"./Meter.css\";\n\n/** Which way the bar fills: an open enum, and one it does not know is drawn horizontal. */\nexport type MeterOrientation = \"horizontal\" | \"vertical\" | (string & {});\n\n/** Writes the tooltip from the current peak and RMS in dBFS (`-Infinity` for silence) and whether the lamp is lit. */\nexport type MeterTitle = (peakDb: number, rmsDb: number, clipped: boolean) => string;\n\n/** What a parent can do to a meter through its `ref`. */\nexport type MeterHandle = {\n /** Empties the bar and clears the held peak and the clip lamp, as when the source closes. */\n reset(): void;\n};\n\nexport type MeterProps = Omit<ComponentPropsWithoutRef<\"div\">, \"children\" | \"title\" | \"role\"> & {\n /** Adds a listener that means a new value is ready to read; returns what removes it. */\n subscribe: LiveSubscribe;\n /** The current `[peak, rms]` as linear amplitude, 1.0 being 0 dBFS. Not a number, or 0 and below, is silence. */\n read: () => readonly [peak: number, rms: number];\n /** `horizontal` (the default) or `vertical`. */\n orientation?: MeterOrientation;\n /** dBFS at the bar's empty end; the full end is 0 dBFS. -60 by default. */\n floor?: number;\n /** `[mid, hot]` in dBFS, where the bar turns from `--pb-meter-low` to `--pb-meter-mid` and to `--pb-meter-hot`. */\n zones?: readonly [mid: number, hot: number];\n /** How long the peak tick holds the highest peak, in ms. 1500 by default. */\n holdMs?: number;\n /** How fast the tick then falls toward the current peak, in dB a second. 20 by default. */\n fallDbPerS?: number;\n /** A peak at or above this linear amplitude lights the clip lamp. 1.0 (0 dBFS) by default. */\n clipAt?: number;\n /** How long the lamp stays lit after the last such peak, in ms. 2000 by default. */\n clipHoldMs?: number;\n /** The accessible name (\"Level\" by default); the numbers are never announced. */\n label?: string;\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<MeterLabels>;\n /** `reset()`, for when the source closes. */\n ref?: Ref<MeterHandle>;\n};\n\n/** The scale's defaults, each a prop. */\nexport const defaultMeterScale = {\n floor: -60,\n zones: [-18, -6] as const,\n holdMs: 1500,\n fallDbPerS: 20,\n clipAt: 1,\n clipHoldMs: 2000,\n} as const;\n\n/** How often, at most, the tooltip is refreshed while the pointer is over the meter, in ms. */\nexport const meterTitleEveryMs = 250;\n\n/** A linear amplitude in dBFS; not a number, or 0 and below, is silence (`-Infinity`). */\nexport function toDb(linear: number): number {\n return Number.isFinite(linear) && linear > 0 ? 20 * Math.log10(linear) : linear === Infinity ? Infinity : -Infinity;\n}\n\n/** Where a level in dBFS sits on a bar from `floor` (0) to 0 dBFS (1), clamped. */\nexport function meterFraction(db: number, floor: number): number {\n if (Number.isNaN(db) || floor >= 0) return 0;\n return Math.min(1, Math.max(0, (db - floor) / -floor));\n}\n\nconst formatDb = (db: number) => (db === -Infinity ? \"−∞\" : db.toFixed(1));\n\n/** The English tooltip: \"peak -12.0 dB, rms -18.3 dB\", with −∞ for silence. */\nexport const defaultMeterTitle: MeterTitle = (peakDb, rmsDb) =>\n `peak ${formatDb(peakDb)} dB, rms ${formatDb(rmsDb)} dB`;\n\n/** The meter's own words, each replaceable. */\nexport interface MeterLabels {\n /** Writes the tooltip from the level: `defaultMeterTitle`, \"peak -12.0 dB, rms -18.3 dB\". */\n title: MeterTitle;\n}\n\nexport const defaultMeterLabels: MeterLabels = {\n title: defaultMeterTitle,\n};\n\ntype Level = {\n peakDb: number;\n rmsDb: number;\n /** The tick's level when it was last set, and when; it holds, then falls from there. */\n heldDb: number;\n heldAt: number;\n /** When the last peak at or above `clipAt` came, or -Infinity. */\n clippedAt: number;\n};\n\ntype Scale = Required<Pick<MeterProps, \"floor\" | \"holdMs\" | \"fallDbPerS\" | \"clipAt\" | \"clipHoldMs\">> & MeterLabels;\n\nconst silent = (): Level => ({\n peakDb: -Infinity,\n rmsDb: -Infinity,\n heldDb: -Infinity,\n heldAt: -Infinity,\n clippedAt: -Infinity,\n});\n\n/**\n * The meter's moving parts outside React: the level, the held tick and the lamp, the frame loop and the tooltip.\n * One is made per mounted meter; it paints into whatever element `attach` gave it.\n */\nfunction createPainter(initial: Scale) {\n let element: HTMLElement | null = null;\n let scale = initial;\n let level = silent();\n let frame: number | undefined;\n let hovered = false;\n let titledAt = -Infinity;\n /** A level came since the tooltip was last written. */\n let stale = false;\n\n /** The tick's level at `now`: the held peak, then falling at the set rate, never below the current peak. */\n const tickAt = (now: number) => {\n const falling = Math.max(0, now - level.heldAt - scale.holdMs);\n const fallen = falling === 0 ? level.heldDb : level.heldDb - (Math.max(0, scale.fallDbPerS) * falling) / 1000;\n return Math.max(level.peakDb, fallen);\n };\n\n const writeTitle = (now: number) => {\n if (element === null) return;\n const clipped = now - level.clippedAt < scale.clipHoldMs;\n element.title = scale.title(level.peakDb, level.rmsDb, clipped);\n titledAt = now;\n stale = false;\n };\n\n /** Draws the level at `now`; says whether anything will still move. */\n const paint = (now: number) => {\n if (element === null) return false;\n const tick = tickAt(now);\n const lit = now - level.clippedAt < scale.clipHoldMs;\n element.style.setProperty(\"--pb-meter-level\", String(meterFraction(level.rmsDb, scale.floor)));\n element.style.setProperty(\"--pb-meter-tick\", String(meterFraction(tick, scale.floor)));\n element.dataset[\"peak\"] = tick > scale.floor ? \"shown\" : \"hidden\";\n element.dataset[\"clipped\"] = String(lit);\n if (hovered && now - titledAt >= meterTitleEveryMs) writeTitle(now);\n // Still moving while the tick is above the current peak and the floor (held, or falling), or the lamp is lit; and,\n // while hovered, until the tooltip has caught up with the last level.\n return (tick > level.peakDb && tick > scale.floor) || lit || (hovered && stale);\n };\n\n const run = () => {\n frame = undefined;\n if (paint(performance.now())) frame = requestAnimationFrame(run);\n };\n\n const wake = () => {\n if (frame === undefined && element !== null) frame = requestAnimationFrame(run);\n };\n\n const stop = () => {\n if (frame !== undefined) cancelAnimationFrame(frame);\n frame = undefined;\n };\n\n return {\n attach(next: HTMLElement | null) {\n element = next;\n if (next === null) stop();\n else wake();\n },\n setScale(next: Scale) {\n const moved =\n next.floor !== scale.floor ||\n next.holdMs !== scale.holdMs ||\n next.fallDbPerS !== scale.fallDbPerS ||\n next.clipHoldMs !== scale.clipHoldMs;\n scale = next;\n if (moved) wake();\n },\n take: ([peak, rms]: readonly [number, number]) => {\n const now = performance.now();\n const peakDb = toDb(peak);\n const tick = tickAt(now);\n level.peakDb = peakDb;\n level.rmsDb = toDb(rms);\n if (peakDb >= tick) {\n level.heldDb = peakDb;\n level.heldAt = now;\n }\n if (peak >= scale.clipAt) level.clippedAt = now;\n stale = true;\n wake();\n },\n reset: () => {\n level = silent();\n stop();\n const now = performance.now();\n paint(now);\n if (hovered) writeTitle(now);\n },\n hover(on: boolean) {\n hovered = on;\n if (on) writeTitle(performance.now());\n },\n };\n}\n\nexport function Meter({\n subscribe,\n read,\n orientation = \"horizontal\",\n floor = defaultMeterScale.floor,\n zones = defaultMeterScale.zones,\n holdMs = defaultMeterScale.holdMs,\n fallDbPerS = defaultMeterScale.fallDbPerS,\n clipAt = defaultMeterScale.clipAt,\n clipHoldMs = defaultMeterScale.clipHoldMs,\n label = \"Level\",\n labels,\n ref,\n className,\n style,\n onPointerEnter,\n onPointerLeave,\n ...rest\n}: MeterProps) {\n const { title } = { ...defaultMeterLabels, ...labels };\n const [painter] = useState(() => createPainter({ floor, holdMs, fallDbPerS, clipAt, clipHoldMs, title }));\n // Every render hands the painter the scale and words; a new scale redraws the level on it.\n useLayoutEffect(() => {\n painter.setScale({ floor, holdMs, fallDbPerS, clipAt, clipHoldMs, title });\n });\n const attach = useCallback(\n (element: HTMLDivElement | null) => {\n painter.attach(element);\n },\n [painter],\n );\n useLiveValue(subscribe, read, painter.take);\n useImperativeHandle(ref, () => ({ reset: painter.reset }), [painter]);\n\n const [mid, hot] = zones;\n const classes = className === undefined ? \"pb-meter\" : `pb-meter ${className}`;\n const zoneStyle = {\n ...style,\n \"--pb-meter-mid-at\": String(meterFraction(mid, floor)),\n \"--pb-meter-hot-at\": String(meterFraction(hot, floor)),\n } as CSSProperties;\n\n return (\n <div\n {...rest}\n ref={attach}\n className={classes}\n role=\"img\"\n aria-label={label}\n data-orientation={orientation}\n data-peak=\"hidden\"\n data-clipped=\"false\"\n style={zoneStyle}\n onPointerEnter={(event) => {\n painter.hover(true);\n onPointerEnter?.(event);\n }}\n onPointerLeave={(event) => {\n painter.hover(false);\n onPointerLeave?.(event);\n }}\n >\n <span className=\"pb-meter-track\" aria-hidden=\"true\">\n <span className=\"pb-meter-bar\" />\n <span className=\"pb-meter-peak\" />\n </span>\n <span className=\"pb-meter-lamp\" aria-hidden=\"true\" />\n </div>\n );\n}\n","// One port of a node (docs/graph.md#portrow): its React Flow handle at the box's edge and its words. NodeBox draws its\n// rows with it; an app drawing a box of its own may use it alone, inside a React Flow node. React Flow's own handle\n// classes stay on the handle, so its connection logic and connectionRadius work as on any handle.\nimport { Handle, Position, useNodeId } from \"@xyflow/react\";\nimport type { ReactNode } from \"react\";\nimport { WarnMark } from \"../../primitives\";\nimport { useConnectHintsValue } from \"../connect-hints/useConnectHints\";\nimport \"./PortRow.css\";\n\n/** Which side of the box a port is on: an input is a target handle on the left edge, an output a source on the right. */\nexport type PortSide = \"input\" | \"output\";\n\n/**\n * What a port shows while a wire is dragged: `origin` the handle the drag began at, `ok` a handle that accepts it,\n * `no` one that refuses it, `null` no drag. An open enum; one it does not know is drawn as `null`.\n */\nexport type PortHint = \"ok\" | \"no\" | \"origin\" | null | (string & {});\n\nexport type PortRowProps = {\n /** The handle id, passed to React Flow's `<Handle id>` unchanged (the app's own scheme). */\n id: string;\n /** `input` (a target handle on the left edge) or `output` (a source handle on the right edge). */\n side: PortSide;\n /** The port's name; a string is also its tooltip. */\n label: ReactNode;\n /** After the label in the muted code face: the port's type. */\n typeLabel?: ReactNode;\n /** While a wire is dragged: `origin`, `ok`, `no`, or `null` for no drag. Given, it wins over `<ConnectHints>`'. */\n hint?: PortHint;\n /** Why the port refuses the wire: the handle's and the row's tooltip while `hint` is `no`. */\n reason?: string;\n /** A problem with the port: a warning mark beside the label, with these as its words. */\n problem?: string;\n /** A slot at the row's inner end, toward the box's centre (a `Meter`). */\n trailing?: ReactNode;\n /** Whether a wire may start or end here; true by default (`<Handle isConnectable>`). */\n connectable?: boolean;\n};\n\nconst knownHints: readonly string[] = [\"ok\", \"no\", \"origin\"];\n\n/** Draws one port: its handle at the edge, its label and type, a problem's mark and a trailing slot. */\nexport function PortRow({\n id,\n side,\n label,\n typeLabel,\n hint: ownHint,\n reason: ownReason,\n problem,\n trailing,\n connectable = true,\n}: PortRowProps) {\n const isInput = side !== \"output\";\n const drag = useConnectHintsValue();\n const nodeId = useNodeId();\n // A hint given as a prop wins; otherwise the drag in progress says, judged once per drag for this handle.\n const fromDrag =\n ownHint === undefined && drag !== null && nodeId !== null\n ? drag.hintFor({ nodeId, handleId: id }, isInput ? \"input\" : \"output\")\n : undefined;\n const hint = fromDrag === undefined ? (ownHint ?? null) : fromDrag.hint;\n const reason = fromDrag === undefined ? ownReason : (fromDrag.reason ?? ownReason);\n const shown = hint !== null && knownHints.includes(hint) ? hint : undefined;\n const refused = shown === \"no\" && reason !== undefined ? reason : undefined;\n return (\n <div\n className=\"pb-port-row\"\n data-side={isInput ? \"input\" : \"output\"}\n data-hint={shown}\n title={refused ?? (typeof label === \"string\" ? label : undefined)}\n >\n <Handle\n id={id}\n type={isInput ? \"target\" : \"source\"}\n position={isInput ? Position.Left : Position.Right}\n isConnectable={connectable}\n className=\"pb-port-handle\"\n data-hint={shown}\n title={refused}\n />\n <span className=\"pb-port-words\">\n <span className=\"pb-port-label\">{label}</span>\n {typeLabel !== undefined && <code className=\"pb-port-type\">{typeLabel}</code>}\n {problem !== undefined && <WarnMark label={problem} title={problem} />}\n </span>\n {trailing !== undefined && <span className=\"pb-port-trailing\">{trailing}</span>}\n </div>\n );\n}\n","// A node's box (docs/graph.md#nodebox): the body of an app's own React Flow node type, a header (title, subtitle, a\n// change's badge and a status slot), a line saying why the node is silent, its ports as PortRows, and a footer. Its\n// sizes come from the --pb-node-* tokens, the same values as the geometry constants an app lays its nodes out with\n// (nodeBoxSize), so a rendered box is the size the layout made room for.\nimport { useNodeId, useUpdateNodeInternals } from \"@xyflow/react\";\nimport { type ComponentPropsWithoutRef, type CSSProperties, type ReactNode, useEffect, useId, useRef } from \"react\";\nimport { Badge } from \"../../primitives\";\nimport { PortRow, type PortRowProps } from \"../port-row\";\nimport type { NodePorts } from \"./geometry\";\nimport \"./NodeBox.css\";\n\n/** A box's stripe down its start edge: an open enum, and one it does not know is drawn in `--pb-line-strong`. */\nexport type NodeBoxTone = \"ok\" | \"warn\" | \"err\" | \"quiet\" | \"off\" | \"accent\" | \"muted\" | (string & {});\n\n/** An edit not yet applied: an open enum, and one it does not know is a plain border with its own string as the word. */\nexport type NodeBoxChange = \"added\" | \"removed\" | \"renamed\" | \"changed\" | (string & {});\n\n/** The box's own words, each replaceable: the change badge's word for each known change. */\nexport interface NodeBoxLabels {\n added: string;\n removed: string;\n renamed: string;\n changed: string;\n}\n\nexport const defaultNodeBoxLabels: NodeBoxLabels = {\n added: \"added\",\n removed: \"removed\",\n renamed: \"renamed\",\n changed: \"changed\",\n};\n\n/** One port of a box: a `PortRow`'s props without `side`, which `NodeBox` sets. */\nexport type PortSpec = Omit<PortRowProps, \"side\">;\n\nexport type NodeBoxProps = Omit<ComponentPropsWithoutRef<\"div\">, \"title\" | \"children\" | \"role\"> & {\n /** The node's name, one line cut with an ellipsis; a string is also the header's tooltip. Names the box's group. */\n title: ReactNode;\n /** The second header line, muted: the node's type. */\n subtitle?: ReactNode;\n /** The stripe down the box's start edge, in the tone's colour; none, or one it does not know, in `--pb-line-strong`. */\n tone?: NodeBoxTone;\n /** A dashed border, the stripe hatched and the words muted. Drawing only: whether its ports connect is the app's. */\n disabled?: boolean;\n /** The border in `--pb-err` and the header on `--pb-err-soft`; the reason goes in `line`. */\n failed?: boolean;\n /** An edit not yet applied: a 2 px border in its tone and a badge with its word; `removed` strikes the title. */\n change?: NodeBoxChange;\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<NodeBoxLabels>;\n /** A slot at the header's end (a `Pill`). */\n status?: ReactNode;\n /** One row under the header saying why the node is silent; a string is also its tooltip. */\n line?: ReactNode;\n /** The input ports, keyed by `id`. */\n inputs?: readonly PortSpec[];\n /** The output ports, keyed by `id`. */\n outputs?: readonly PortSpec[];\n /** `stacked` (the default: the inputs' rows, then the outputs') or `side-by-side` (two columns). */\n ports?: NodePorts;\n /** A slot: one row at the foot (badges). */\n footer?: ReactNode;\n /** Selected, from React Flow's `NodeProps`: a 2 px outline in the accent. */\n selected?: boolean;\n /** Its width in px; `NODE_WIDTH` by default. */\n width?: number;\n};\n\nconst knownChanges: readonly string[] = [\"added\", \"removed\", \"renamed\", \"changed\"];\n\n/** Draws a node's box; render it inside a React Flow node. */\nexport function NodeBox({\n title,\n subtitle,\n tone,\n disabled = false,\n failed = false,\n change,\n labels,\n status,\n line,\n inputs = [],\n outputs = [],\n ports = \"stacked\",\n footer,\n selected = false,\n width,\n className,\n style,\n ...rest\n}: NodeBoxProps) {\n const titleId = useId();\n const layout = ports === \"side-by-side\" ? \"side-by-side\" : \"stacked\";\n usePortsMeasured(inputs, outputs, layout);\n\n const words = { ...defaultNodeBoxLabels, ...labels };\n const changeWord =\n change === undefined ? undefined : knownChanges.includes(change) ? words[change as keyof NodeBoxLabels] : change;\n const hasPorts = inputs.length > 0 || outputs.length > 0;\n const inputRows = inputs.map((port) => <PortRow key={port.id} {...port} side=\"input\" />);\n const outputRows = outputs.map((port) => <PortRow key={port.id} {...port} side=\"output\" />);\n\n return (\n <div\n {...rest}\n className={className === undefined ? \"pb-node-box\" : `pb-node-box ${className}`}\n role=\"group\"\n aria-labelledby={titleId}\n data-tone={tone}\n data-change={change}\n data-disabled={disabled ? \"\" : undefined}\n data-failed={failed ? \"\" : undefined}\n data-selected={selected ? \"\" : undefined}\n style={width === undefined ? style : ({ ...style, width: `${width}px` } satisfies CSSProperties)}\n >\n <div className=\"pb-node-header\">\n <div className=\"pb-node-heading\">\n <span id={titleId} className=\"pb-node-title\" title={typeof title === \"string\" ? title : undefined}>\n {title}\n </span>\n {subtitle !== undefined && <span className=\"pb-node-subtitle\">{subtitle}</span>}\n </div>\n {changeWord !== undefined && (\n <Badge tone={change ?? \"\"} className=\"pb-node-change\">\n {changeWord}\n </Badge>\n )}\n {status !== undefined && <div className=\"pb-node-status\">{status}</div>}\n </div>\n {line !== undefined && (\n <div className=\"pb-node-line\" title={typeof line === \"string\" ? line : undefined}>\n {line}\n </div>\n )}\n {hasPorts &&\n (layout === \"side-by-side\" ? (\n <div className=\"pb-node-ports\" data-ports=\"side-by-side\">\n <div className=\"pb-node-column\" data-side=\"input\">\n {inputRows}\n </div>\n <div className=\"pb-node-column\" data-side=\"output\">\n {outputRows}\n </div>\n </div>\n ) : (\n <div className=\"pb-node-ports\" data-ports=\"stacked\">\n {inputRows}\n {outputRows}\n </div>\n ))}\n {footer !== undefined && <div className=\"pb-node-footer\">{footer}</div>}\n </div>\n );\n}\n\n/**\n * Asks React Flow to measure the node's handles again when its ordered port ids or their layout change, so a handle\n * added or moved is where a wire meets it. React Flow measures a node's handles itself when the node first renders.\n */\nfunction usePortsMeasured(inputs: readonly PortSpec[], outputs: readonly PortSpec[], layout: string) {\n const nodeId = useNodeId();\n const updateNodeInternals = useUpdateNodeInternals();\n const key = JSON.stringify([layout, inputs.map((port) => port.id), outputs.map((port) => port.id)]);\n const measured = useRef(key);\n useEffect(() => {\n if (measured.current === key) return;\n measured.current = key;\n if (nodeId !== null) updateNodeInternals(nodeId);\n }, [key, nodeId, updateNodeInternals]);\n}\n","// A node box's geometry (docs/graph.md#geometry). An app sizes its nodes before they render (dagre and ELK take\n// sizes), so the sizes are fixed: these constants are what layout code reads, and tokens.css holds the same values as\n// --pb-node-* tokens, which NodeBox and PortRow size themselves from. geometry.test.ts holds each token equal to its\n// constant, and tokens.test.ts fails on a brand that sets one.\n\n/** The default width of a node box, in px; `NodeBox`'s `width` overrides it per node (`--pb-node-width`). */\nexport const NODE_WIDTH = 240;\n/** The header (title and subtitle), with or without a subtitle, in px (`--pb-node-header`). */\nexport const NODE_HEADER = 46;\n/** The `line` row, when there is one, in px (`--pb-node-line`). */\nexport const NODE_LINE = 22;\n/** One port row, in px (`--pb-node-row`). */\nexport const NODE_ROW = 22;\n/** The space above the first port row and below the last, in px (`--pb-node-pad`). */\nexport const NODE_PAD = 8;\n/** The footer, when there is one, in px (`--pb-node-footer`). */\nexport const NODE_FOOTER = 28;\n/** A handle's dot, in px (`--pb-node-handle`). */\nexport const HANDLE_SIZE = 10;\n/** A handle's hit area, centred on the dot, in px (`--pb-node-handle-hit`); 32 px on a touch screen. */\nexport const HANDLE_HIT = 20;\n\n/**\n * How a node box lays out its ports: `stacked` (the inputs' rows, then the outputs') or `side-by-side` (two columns,\n * row n of each on one line). An open enum; one it does not know is stacked.\n */\nexport type NodePorts = \"stacked\" | \"side-by-side\" | (string & {});\n\n/** What decides a node box's size: its port counts, their layout, and whether it has a line and a footer. */\nexport type NodeBoxShape = {\n /** How many input ports. */\n inputs: number;\n /** How many output ports. */\n outputs: number;\n /** How the ports are laid out. */\n ports: NodePorts;\n /** Whether it has a `line` row. */\n line: boolean;\n /** Whether it has a footer. */\n footer: boolean;\n /** Its width in px; `NODE_WIDTH` by default. */\n width?: number;\n};\n\n/** How many port rows a box draws: inputs plus outputs stacked, the larger of the two side by side. */\nexport function nodePortRows(inputs: number, outputs: number, ports: NodePorts): number {\n return ports === \"side-by-side\" ? Math.max(inputs, outputs) : inputs + outputs;\n}\n\n/**\n * A node box's size in px, the one formula layout code sizes nodes with: the header, the line when there is one, the\n * port rows and the padding above and below them when there are ports, and the footer when there is one. The box's\n * 1 px border is inside it; the selection ring is outside.\n */\nexport function nodeBoxSize({ inputs, outputs, ports, line, footer, width = NODE_WIDTH }: NodeBoxShape): {\n width: number;\n height: number;\n} {\n const rows = nodePortRows(Math.max(0, inputs), Math.max(0, outputs), ports);\n const height =\n NODE_HEADER + (line ? NODE_LINE : 0) + (rows > 0 ? 2 * NODE_PAD + rows * NODE_ROW : 0) + (footer ? NODE_FOOTER : 0);\n return { width, height };\n}\n","// A wire (docs/graph.md#wire): an edge type an app registers in edgeTypes, its look from the edge's data. The visible\n// path is React Flow's BaseEdge, so its react-flow__edge-path class and selection stay; the hit path keeps\n// react-flow__edge-interaction and carries the tooltip. The path is rebuilt only when an end moves: the level arrives\n// as --pb-wire-emphasis on the wire's group, so a change of level restyles it without touching the path.\nimport { BaseEdge, type Edge, EdgeLabelRenderer, type EdgeProps, getBezierPath, Position } from \"@xyflow/react\";\nimport { type CSSProperties, memo, type ReactNode, useMemo } from \"react\";\nimport type { PillTone } from \"../../primitives\";\nimport \"./Wire.css\";\n\n/** Pill's tones, the changes, `pending` and `refused`; any other string is drawn in the edge stroke. */\nexport type WireTone = PillTone | \"added\" | \"removed\" | \"changed\" | \"pending\" | \"refused\" | (string & {});\n\n/** A wire's look, as React Flow's edge `data`. */\nexport type WireData = {\n /** The stroke's tone; none, or one it does not know, is React Flow's edge stroke. */\n tone?: WireTone;\n /** The signal's level, 0 to 1 (clamped; not a number is 0): thickness and brightness. None is the plain wire. */\n emphasis?: number;\n /** Dashes: an edit not yet saved. */\n dashed?: boolean;\n /** Dots moving along the wire toward the input; not drawn under reduced motion. */\n flow?: boolean;\n /** An arrowhead at the input end, facing the handle's side. */\n arrow?: boolean;\n /** At the midpoint, on the raised surface; it takes no pointer events. */\n label?: ReactNode;\n /** The wire's tooltip, on its hit path. */\n title?: string;\n};\n\n/** An edge drawn by `Wire`: register it as `edgeTypes={{ wire: Wire }}`. */\nexport type WireEdge = Edge<WireData, \"wire\">;\n\n/** The arrowhead's length along the wire and half its width, in px. */\nconst ARROW_LENGTH = 8;\nconst ARROW_HALF = 4;\n\n/** A level as the wire draws it: 0 to 1, anything not a number 0. */\nfunction emphasisOf(value: unknown): number {\n if (typeof value !== \"number\" || Number.isNaN(value)) return 0;\n return Math.min(1, Math.max(0, value));\n}\n\n/** A triangle with its tip on the handle, pointing into the node from the side the handle is on. */\nfunction arrowPath(x: number, y: number, side: Position): string {\n // The way back from the tip, away from the node.\n const dx = side === Position.Left ? -1 : side === Position.Right ? 1 : 0;\n const dy = side === Position.Top ? -1 : side === Position.Bottom ? 1 : 0;\n const baseX = x + dx * ARROW_LENGTH;\n const baseY = y + dy * ARROW_LENGTH;\n // Perpendicular to the direction, for the base's two corners.\n const px = -dy * ARROW_HALF;\n const py = dx * ARROW_HALF;\n return `M ${x} ${y} L ${baseX + px} ${baseY + py} L ${baseX - px} ${baseY - py} Z`;\n}\n\ntype WireBodyProps = {\n id: string;\n path: string;\n flow: boolean;\n arrow: string | undefined;\n title: string | undefined;\n interactionWidth: number;\n markerStart: string | undefined;\n markerEnd: string | undefined;\n style: CSSProperties | undefined;\n};\n\n/** The paths, which change only when an end, the flow, the arrow or the tooltip does. */\nconst WireBody = memo(function WireBody({\n id,\n path,\n flow,\n arrow,\n title,\n interactionWidth,\n markerStart,\n markerEnd,\n style,\n}: WireBodyProps) {\n return (\n <>\n <BaseEdge\n id={id}\n path={path}\n className=\"pb-wire-path\"\n interactionWidth={0}\n markerStart={markerStart}\n markerEnd={markerEnd}\n style={style}\n />\n {flow && <path d={path} fill=\"none\" className=\"pb-wire-flow\" aria-hidden=\"true\" />}\n {arrow !== undefined && <path d={arrow} className=\"pb-wire-arrow\" aria-hidden=\"true\" />}\n {interactionWidth > 0 && (\n <path\n d={path}\n fill=\"none\"\n strokeOpacity={0}\n strokeWidth={interactionWidth}\n className=\"react-flow__edge-interaction\"\n >\n {title !== undefined && <title>{title}</title>}\n </path>\n )}\n </>\n );\n});\n\n/** Draws a wire between two handles: its tone, level, dashes, flow, arrow, label and tooltip from the edge's data. */\nexport function Wire({\n id,\n sourceX,\n sourceY,\n targetX,\n targetY,\n sourcePosition,\n targetPosition,\n data,\n selected,\n interactionWidth = 20,\n markerStart,\n markerEnd,\n style,\n}: EdgeProps<WireEdge>) {\n const [path, labelX, labelY] = useMemo(\n () => getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition }),\n [sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition],\n );\n const showArrow = data?.arrow === true;\n const arrow = useMemo(\n () => (showArrow ? arrowPath(targetX, targetY, targetPosition) : undefined),\n [showArrow, targetX, targetY, targetPosition],\n );\n const emphasis = data?.emphasis === undefined ? undefined : emphasisOf(data.emphasis);\n const level = emphasis === undefined ? undefined : ({ \"--pb-wire-emphasis\": emphasis } as CSSProperties);\n const label = data?.label;\n return (\n <>\n <g\n className=\"pb-wire\"\n data-tone={data?.tone}\n data-selected={selected === true ? \"\" : undefined}\n data-dashed={data?.dashed === true ? \"\" : undefined}\n data-emphasis={emphasis === undefined ? undefined : \"\"}\n style={level}\n >\n <WireBody\n id={id}\n path={path}\n flow={data?.flow === true}\n arrow={arrow}\n title={data?.title}\n interactionWidth={interactionWidth}\n markerStart={markerStart}\n markerEnd={markerEnd}\n style={style}\n />\n </g>\n {label !== undefined && label !== null && (\n <EdgeLabelRenderer>\n <div\n className=\"pb-wire-label\"\n data-tone={data?.tone}\n style={{ transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)` }}\n >\n {label}\n </div>\n </EdgeLabelRenderer>\n )}\n </>\n );\n}\n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A,GAAM;GACK;GACL;GACF;GACJ;EACR,CAAA;CACA,CAAA,GACFC,KAAiC,QAChC,kBAACE,GAAD,EAAA,UACE,kBAAC,OAAD;EACE,WAAU;EACV,aAAWH,GAAM;EACjB,OAAO,EAAE,WAAW,mCAAmCV,EAAO,MAAMC,EAAO,KAAK;EAE/E,UAAAU;CACE,CAAA,EACY,CAAA,CAErB,EAAA,CAAA;AAEN"}
1
+ {"version":3,"file":"graph.js","names":["_Fragment","Panel","Panel","Panel","_Fragment","_Fragment","Panel$1","isPane","target","endOf","event","touch","elementAt","x","y","useAddAt","enabled","options","useReactFlow","latest","useRef","origin","handlers","useMemo","add","on","toFlow","nodeId","handleType","from","state","end","fallback","slowMotionMs","value","element","parsed","defaultCanvasToolsLabels","glyph","Glyph","path","glyphs","CanvasTools","words","labels","flow","store","useStoreApi","duration","onViewMoveRef","onViewMove","useLayoutEffect","useEffect","minimap","pressed","wheel","release","press","wheeled","unsubscribe","zoom","px","py","pzoom","previous","move","tool","keys","keyShortcuts","name","IconButton","act","Fragment","className","ToolGroup","onFit","fitOptions","onTidy","onMinimap","children","MiniMap","minimapNodeClassName","connectTargets","accepted","refused","at","port","candidate","candidates","side","other","verdict","canConnect","mergeFlowProps","objects","values","object","list","merged","only","args","each","ConnectHintsContext","createContext","ConnectHints","useConnectHintsValue","useContext","verdictKey","to","samePort","a","b","useConnectHints","rule","verdicts","setOrigin","useState","setRefused","judge","kept","key","known","flowProps","connection","refusal","fromHandle","toHandle","toInput","defaultConnectStatusLabels","reason","overHandle","id","type","connectStatusWords","over","hint","ConnectStatus","useStore","handleId","text","LONG_PRESS_MS","LONG_PRESS_SLOP","pressedOn","useContextAt","swallow","ask","call","nodeOf","node","context","swallowClick","onClick","stop","onMenu","held","timer","defaultEmptyCanvasHintLabels","gesture","noNodes","EmptyCanvasHint","none","useMediaBreakpoint","empty","gestures","keyLabel","allMeasured","useFollowFit","width","height","measured","following","setFollowing","fittedFor","land","useCallback","last","fit","now","movedFrom","moved","viewport","knownHints","PortRow","ownHint","ownReason","isInput","drag","useNodeId","fromDrag","shown","label","Handle","Position","connectable","typeLabel","problem","WarnMark","trailing","defaultNodeBoxLabels","knownChanges","NodeBox","rest","titleId","useId","layout","ports","inputs","outputs","changeWord","change","hasPorts","inputRows","outputRows","tone","disabled","failed","selected","style","title","subtitle","Badge","status","line","footer","usePortsMeasured","updateNodeInternals","useUpdateNodeInternals","NODE_WIDTH","NODE_HEADER","NODE_LINE","NODE_ROW","NODE_PAD","NODE_FOOTER","HANDLE_SIZE","HANDLE_HIT","nodePortRows","nodeBoxSize","rows","ghostNodeSize","data","GhostNode","GhostWire","labelX","labelY","getBezierPath","sourceX","sourceY","sourcePosition","targetX","targetY","targetPosition","BaseEdge","EdgeLabelRenderer","defaultMeterScale","meterTitleEveryMs","toDb","linear","meterFraction","db","floor","formatMeterDb","defaultMeterTitle","peakDb","rmsDb","defaultMeterLabels","silent","createPainter","scale","initial","level","frame","hovered","titledAt","stale","tickAt","falling","fallen","writeTitle","clipped","paint","tick","lit","\"peak\"","\"clipped\"","run","wake","next","peak","rms","Meter","painter","attach","useLiveValue","subscribe","read","useImperativeHandle","ref","mid","hot","zones","classes","zoneStyle","orientation","onPointerEnter","onPointerLeave","ARROW_LENGTH","ARROW_HALF","CHANGE_TONES","emphasisOf","arrowPath","dx","dy","baseX","baseY","WireBody","memo","arrow","interactionWidth","Wire","showArrow","emphasis","dashed"],"sources":["../src/graph/add-at/useAddAt.ts","../src/graph/canvas-tools/motion.ts","../src/graph/canvas-tools/CanvasTools.tsx","../src/graph/connect-hints/connectTargets.ts","../src/graph/connect-hints/mergeFlowProps.ts","../src/graph/connect-hints/useConnectHints.tsx","../src/graph/connect-status/ConnectStatus.tsx","../src/graph/context-at/useContextAt.ts","../src/graph/empty-canvas-hint/EmptyCanvasHint.tsx","../src/graph/follow-fit/useFollowFit.ts","../src/graph/port-row/PortRow.tsx","../src/graph/node-box/NodeBox.tsx","../src/graph/node-box/geometry.ts","../src/graph/ghost-node/GhostNode.tsx","../src/graph/ghost-wire/GhostWire.tsx","../src/graph/meter/Meter.tsx","../src/graph/wire/Wire.tsx"],"sourcesContent":["// Adding at a place on the canvas (docs/graph.md#useaddat): a double-click on empty canvas, or a wire dropped there,\n// asks the app to add a node at that point, in flow coordinates, with the port the wire came from. Only the pane\n// counts: a double-click or a drop on a node, an edge, a handle or a panel is not empty canvas.\nimport { type OnConnectEnd, type OnConnectStart, useReactFlow } from \"@xyflow/react\";\nimport { type MouseEvent as ReactMouseEvent, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type { PortRef } from \"../connect-hints\";\nimport type { PortSide } from \"../port-row\";\n\n/** A point in flow coordinates. */\nexport type FlowPoint = { x: number; y: number };\n\n/** Called with where to add, and the port a dropped wire came from (absent for a double-click). */\nexport type OnAddAt = (point: FlowPoint, from?: PortRef & { side: PortSide }) => void;\n\n/**\n * The props `useAddAt` gives `<ReactFlow>`. `zoomOnDoubleClick` is false while adding is on, as the double-click is\n * the add, and absent while it is off, so React Flow's own zoom on double-click (or the app's choice) holds.\n */\nexport type AddAtFlowProps = {\n onDoubleClick: (event: ReactMouseEvent<HTMLDivElement>) => void;\n onConnectStart: OnConnectStart;\n onConnectEnd: OnConnectEnd;\n zoomOnDoubleClick?: false;\n};\n\nexport type AddAtOptions = {\n /**\n * false switches adding off (as while the graph is read-only), and gives double-click back to React Flow's zoom;\n * true by default.\n */\n enabled?: boolean;\n};\n\n/** Whether the element is this canvas's empty pane, not anything drawn on it. */\nconst isPane = (target: EventTarget | null) =>\n target instanceof Element && target.classList.contains(\"react-flow__pane\");\n\n/** Where a mouse or touch event ended, in the window's coordinates; a touch's end is in `changedTouches`. */\nfunction endOf(event: MouseEvent | TouchEvent): { x: number; y: number } | null {\n if (\"changedTouches\" in event) {\n const touch = event.changedTouches[0];\n return touch === undefined ? null : { x: touch.clientX, y: touch.clientY };\n }\n return { x: event.clientX, y: event.clientY };\n}\n\n/** The element at a point in the window, or null where the browser cannot say. */\nconst elementAt = ({ x, y }: { x: number; y: number }) =>\n typeof document.elementFromPoint === \"function\" ? document.elementFromPoint(x, y) : null;\n\n/**\n * Calls `onAddAt` for a double-click on empty canvas and for a wire dropped there where no handle took it. Its\n * `flowProps` go to `<ReactFlow>` (through `mergeFlowProps` with others); while adding is on it turns React Flow's\n * zoom on double-click off, as the double-click is the add.\n */\nexport function useAddAt(onAddAt: OnAddAt, options: AddAtOptions = {}): { flowProps: AddAtFlowProps } {\n const enabled = options.enabled ?? true;\n const { screenToFlowPosition } = useReactFlow();\n const latest = useRef({ onAddAt, enabled, screenToFlowPosition });\n useLayoutEffect(() => {\n latest.current = { onAddAt, enabled, screenToFlowPosition };\n });\n // The handle the wire in progress began at; null outside a drag.\n const origin = useRef<(PortRef & { side: PortSide }) | null>(null);\n\n const handlers = useMemo<Omit<AddAtFlowProps, \"zoomOnDoubleClick\">>(\n () => ({\n onDoubleClick: (event) => {\n const { onAddAt: add, enabled: on, screenToFlowPosition: toFlow } = latest.current;\n if (!on || !isPane(event.target)) return;\n add(toFlow({ x: event.clientX, y: event.clientY }));\n },\n onConnectStart: (_event, { nodeId, handleId, handleType }) => {\n origin.current =\n nodeId === null ? null : { nodeId, handleId, side: handleType === \"target\" ? \"input\" : \"output\" };\n },\n onConnectEnd: (event, state) => {\n const from = origin.current;\n origin.current = null;\n const { onAddAt: add, enabled: on, screenToFlowPosition: toFlow } = latest.current;\n if (!on || from === null || state.toHandle !== null) return;\n const end = endOf(event);\n if (end === null) return;\n // A mouse's up is on the element under it; a touch's end is on the element it began on, so ask the page.\n const target = \"changedTouches\" in event ? elementAt(end) : event.target;\n if (!isPane(target)) return;\n add(toFlow(end), from);\n },\n }),\n [],\n );\n // Off, the key is left out rather than set true: an app that turned the zoom off itself keeps it off.\n const flowProps = useMemo<AddAtFlowProps>(\n () => (enabled ? { ...handlers, zoomOnDoubleClick: false } : handlers),\n [enabled, handlers],\n );\n\n return { flowProps };\n}\n","// How long a view move takes that a person asked for (a zoom, a fit; docs/graph.md#canvastools): the canvas's\n// --pb-motion-slow, which tokens.css sets to 0 ms under reduced motion, so a brand's duration and the person's wish\n// both hold. Read from the canvas's element at the move, since a brand or the theme can change it at any time.\n\nconst fallback = 180;\n\n/** `--pb-motion-slow` on `element` in milliseconds; without the tokens loaded, 180 ms, or 0 under reduced motion. */\nexport function slowMotionMs(element: Element | null | undefined): number {\n const value =\n element === null || element === undefined ? \"\" : getComputedStyle(element).getPropertyValue(\"--pb-motion-slow\");\n const parsed = /^\\s*(\\d+(?:\\.\\d+)?)(ms|s)\\s*$/.exec(value);\n if (parsed !== null) return Number(parsed[1]) * (parsed[2] === \"s\" ? 1000 : 1);\n const reduced =\n typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n return reduced ? 0 : fallback;\n}\n","// A canvas's tools (docs/graph.md#canvastools), a child of the app's own <ReactFlow>: zoom, fit, and when the app\n// gives them, tidy and the minimap, as one ToolGroup in React Flow's <Panel>, and React Flow's <MiniMap> while the\n// minimap is on. The layout behind tidy and the minimap's state are the app's; the zoom and fit move the view through\n// React Flow over --pb-motion-slow, at once under reduced motion. The minimap can be dragged and wheeled, as React\n// Flow's own pannable and zoomable minimap; every view move the person makes through the tools (a zoom tool, the\n// minimap) is said through onViewMove, so useFollowFit's stop() can stop following (docs/ux-rules.md#the-view-and-the-canvas,\n// U63): those moves are made by code, and React Flow gives them no event.\nimport {\n type FitViewOptions,\n MiniMap,\n type Node,\n Panel,\n type PanelPosition,\n useReactFlow,\n useStoreApi,\n} from \"@xyflow/react\";\nimport { type ReactNode, useEffect, useLayoutEffect, useRef } from \"react\";\nimport { Glyph, IconButton, ToolGroup } from \"../../primitives\";\nimport { slowMotionMs } from \"./motion\";\nimport \"./CanvasTools.css\";\n\n/** The tools' words, each replaceable. */\nexport interface CanvasToolsLabels {\n /** The tool group's accessible name: \"Canvas\". */\n toolbar: string;\n zoomIn: string;\n zoomOut: string;\n fit: string;\n tidy: string;\n minimap: string;\n}\n\nexport const defaultCanvasToolsLabels: CanvasToolsLabels = {\n toolbar: \"Canvas\",\n zoomIn: \"Zoom in\",\n zoomOut: \"Zoom out\",\n fit: \"Fit the view\",\n tidy: \"Tidy the layout\",\n minimap: \"Minimap\",\n};\n\n/** The app's own key bindings for the tools, as `aria-keyshortcuts` values: shown, not bound. */\nexport type CanvasToolsShortcuts = Partial<Record<\"zoomIn\" | \"zoomOut\" | \"fit\" | \"tidy\" | \"minimap\", string>>;\n\nexport type CanvasToolsProps<NodeType extends Node = Node> = {\n /** Where the panel sits on the canvas, React Flow's `PanelPosition`: \"bottom-left\" by default. */\n position?: PanelPosition | (string & {});\n /** React Flow's fit options for the fit tool. */\n fitOptions?: FitViewOptions<NodeType>;\n /** Replaces the fit tool's own fit (pass useFollowFit's `fit`, so the tool also resumes following). */\n onFit?: () => void;\n /**\n * The person moved the view through the tools: a press of a zoom tool, or a drag or wheel on the minimap that moved\n * it. Pass useFollowFit's `stop`, so these moves stop following as a pan or a wheel on the canvas does.\n */\n onViewMove?: () => void;\n /** The tidy tool, shown only when given: the layout is the app's. */\n onTidy?: () => void;\n /** Whether the minimap is on: the minimap tool is pressed and React Flow's <MiniMap> is drawn. */\n minimap?: boolean;\n /** The minimap tool, shown only when given: called with the state a press asks for. */\n onMinimap?: (next: boolean) => void;\n /** The class of each node's shape in the minimap, so the app colours it by the node's state. */\n minimapNodeClassName?: string | ((node: NodeType) => string);\n keyShortcuts?: CanvasToolsShortcuts;\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<CanvasToolsLabels>;\n /** Added to the panel's own `pb-canvas-tools` class. */\n className?: string;\n /** More tools (IconButtons) after patchbay's. */\n children?: ReactNode;\n};\n\nconst glyph = (path: string) => (\n <Glyph>\n <path d={path} />\n </Glyph>\n);\n\nconst glyphs = {\n zoomIn: glyph(\"M3 8h10M8 3v10\"),\n zoomOut: glyph(\"M3 8h10\"),\n fit: glyph(\"M2 6V2h4M10 2h4v4M14 10v4h-4M6 14H2v-4\"),\n tidy: glyph(\"M2 2h5v5H2zM9 2h5v5H9zM2 9h5v5H2zM9 9h5v5H9z\"),\n minimap: glyph(\"M2 3.5h12v9H2zM8.5 8h3.5v2.5H8.5z\"),\n};\n\nexport function CanvasTools<NodeType extends Node = Node>({\n position = \"bottom-left\",\n fitOptions,\n onFit,\n onViewMove,\n onTidy,\n minimap = false,\n onMinimap,\n minimapNodeClassName,\n keyShortcuts,\n labels,\n className,\n children,\n}: CanvasToolsProps<NodeType>) {\n const words = { ...defaultCanvasToolsLabels, ...labels };\n const flow = useReactFlow<NodeType>();\n const store = useStoreApi<NodeType>();\n const duration = () => slowMotionMs(store.getState().domNode);\n const onViewMoveRef = useRef(onViewMove);\n useLayoutEffect(() => {\n onViewMoveRef.current = onViewMove;\n });\n\n // A drag or wheel on the minimap moves the view by code (React Flow's minimap sets the viewport itself), so the canvas\n // gives that move no event. While a press on the minimap is down, or during a wheel on it, a change of the viewport\n // is the person's.\n useEffect(() => {\n if (!minimap) return;\n const element = store.getState().domNode?.querySelector<HTMLElement>(\".pb-canvas-minimap\");\n if (element === null || element === undefined) return;\n let pressed = false;\n let wheel: ReturnType<typeof setTimeout> | undefined;\n const release = () => {\n pressed = false;\n };\n const press = () => {\n pressed = true;\n window.addEventListener(\"pointerup\", release, { once: true, capture: true });\n window.addEventListener(\"pointercancel\", release, { once: true, capture: true });\n };\n const wheeled = () => {\n // React Flow's minimap zooms within the wheel's own dispatch; the next task is after it.\n clearTimeout(wheel);\n wheel = setTimeout(() => {\n wheel = undefined;\n }, 0);\n };\n element.addEventListener(\"pointerdown\", press, true);\n element.addEventListener(\"wheel\", wheeled, { capture: true, passive: true });\n const unsubscribe = store.subscribe((state, previous) => {\n if (!pressed && wheel === undefined) return;\n const [x, y, zoom] = state.transform;\n const [px, py, pzoom] = previous.transform;\n if (x !== px || y !== py || zoom !== pzoom) onViewMoveRef.current?.();\n });\n return () => {\n unsubscribe();\n clearTimeout(wheel);\n element.removeEventListener(\"pointerdown\", press, true);\n element.removeEventListener(\"wheel\", wheeled, true);\n window.removeEventListener(\"pointerup\", release, true);\n window.removeEventListener(\"pointercancel\", release, true);\n };\n }, [minimap, store]);\n\n const zoom = (move: \"zoomIn\" | \"zoomOut\") => {\n onViewMove?.();\n void flow[move]({ duration: duration() });\n };\n\n const tool = (name: keyof CanvasToolsShortcuts, act: () => void, pressed?: boolean) => {\n const keys = keyShortcuts?.[name];\n return (\n <IconButton\n label={words[name]}\n title={keys === undefined || keys === \"\" ? words[name] : `${words[name]} (${keys})`}\n aria-keyshortcuts={keys === \"\" ? undefined : keys}\n aria-pressed={pressed}\n onClick={act}\n >\n {glyphs[name]}\n </IconButton>\n );\n };\n\n return (\n <>\n <Panel\n position={position as PanelPosition}\n className={className === undefined ? \"pb-canvas-tools\" : `pb-canvas-tools ${className}`}\n >\n <ToolGroup label={words.toolbar}>\n {tool(\"zoomIn\", () => {\n zoom(\"zoomIn\");\n })}\n {tool(\"zoomOut\", () => {\n zoom(\"zoomOut\");\n })}\n {tool(\"fit\", () => {\n if (onFit !== undefined) onFit();\n else void flow.fitView({ ...fitOptions, duration: duration() });\n })}\n {onTidy !== undefined && tool(\"tidy\", onTidy)}\n {onMinimap !== undefined &&\n tool(\n \"minimap\",\n () => {\n onMinimap(!minimap);\n },\n minimap,\n )}\n {children}\n </ToolGroup>\n </Panel>\n {minimap && (\n <MiniMap<NodeType>\n className=\"pb-canvas-minimap\"\n ariaLabel={words.minimap}\n nodeClassName={minimapNodeClassName}\n pannable\n zoomable\n />\n )}\n </>\n );\n}\n","// The keyboard's path for connecting (docs/graph.md#connecttargets): the ports one port may be joined to, judged by the\n// same rule and the same verdicts as the hints and the drop (useConnectHints), so the inspector's \"Connect to\" choice\n// never offers what a drag would refuse (docs/ux-rules.md#live-pending-queued-refused, U56).\nimport type { PortSide } from \"../port-row\";\nimport type { CanConnect, PortRef } from \"./useConnectHints\";\n\n/** A port that might be joined: its handle and its side. The app may carry more (a label, a type) on it. */\nexport type ConnectCandidate = PortRef & { side: PortSide };\n\n/** The candidates the rule accepts for one port, and those it refuses with its reason when it gave one. */\nexport type ConnectTargets<T extends ConnectCandidate> = {\n /** The accepted candidates, in the order given: what a \"Connect to\" choice lists. */\n accepted: T[];\n /** The refused candidates on the other side, in the order given, each with the rule's string when it gave one. */\n refused: { port: T; reason?: string }[];\n};\n\n/**\n * Judges each candidate on the other side of `port` by `canConnect`, the output always first, as a drag would:\n * `true` accepts; `false` or a string refuses, the string being the reason. Candidates on `port`'s own side are not\n * candidates (React Flow's strict connection mode), and are in neither list. Each pair is asked of the rule once.\n */\nexport function connectTargets<T extends ConnectCandidate>(\n port: PortRef,\n side: PortSide,\n candidates: readonly T[],\n canConnect: CanConnect,\n): ConnectTargets<T> {\n const accepted: T[] = [];\n const refused: { port: T; reason?: string }[] = [];\n const at: PortRef = { nodeId: port.nodeId, handleId: port.handleId };\n for (const candidate of candidates) {\n if (candidate.side === side) continue;\n const other: PortRef = { nodeId: candidate.nodeId, handleId: candidate.handleId };\n const verdict = side === \"output\" ? canConnect(at, other) : canConnect(other, at);\n if (verdict === true) accepted.push(candidate);\n else refused.push(typeof verdict === \"string\" ? { port: candidate, reason: verdict } : { port: candidate });\n }\n return { accepted, refused };\n}\n","// Joins the props several hooks give <ReactFlow> (docs/graph.md#mergeflowprops), so each hook's handler still runs\n// when two of them, or the app, handle the same event.\n\ntype UnionToIntersection<U> = (U extends unknown ? (each: U) => void : never) extends (each: infer I) => void\n ? I\n : never;\n\n/** The objects' props together: each handler is every object's handler for that name. */\nexport type MergedFlowProps<T extends readonly (object | undefined)[]> = UnionToIntersection<\n Exclude<T[number], undefined>\n>;\n\ntype Handler = (...args: unknown[]) => unknown;\n\n/**\n * One object of `<ReactFlow>` props from several: a handler given by more than one object calls each in order, and\n * `isValidConnection` accepts only when each accepts (it stops at the first that refuses). Any other prop is the last\n * object's that gives it; `undefined` gives nothing.\n */\nexport function mergeFlowProps<const T extends readonly (object | undefined)[]>(...objects: T): MergedFlowProps<T> {\n const values = new Map<string, unknown>();\n const handlers = new Map<string, Handler[]>();\n for (const object of objects) {\n if (object === undefined) continue;\n for (const [name, value] of Object.entries(object)) {\n if (value === undefined) continue;\n if (typeof value === \"function\") {\n const list = handlers.get(name) ?? [];\n list.push(value as Handler);\n handlers.set(name, list);\n values.delete(name);\n } else {\n values.set(name, value);\n handlers.delete(name);\n }\n }\n }\n const merged: Record<string, unknown> = Object.fromEntries(values);\n for (const [name, list] of handlers) {\n const [only] = list;\n if (list.length === 1 && only !== undefined) merged[name] = only;\n else if (name === \"isValidConnection\")\n merged[name] = (...args: unknown[]) => list.every((each) => each(...args) === true);\n else\n merged[name] = (...args: unknown[]) => {\n for (const each of list) each(...args);\n };\n }\n return merged as MergedFlowProps<T>;\n}\n","// One rule for which ports may be joined (docs/graph.md#useconnecthints), used both for the hints every PortRow shows\n// while a wire is dragged and for React Flow's own check on the drop. The state changes twice per drag, at its start\n// and its end, never per pointer move; each candidate handle's verdict is asked of the rule once per drag and kept. A\n// drop the rule refused is kept, with its reason, until the next drag begins, for the canvas's status line.\nimport type { Connection, Edge, OnConnectEnd, OnConnectStart } from \"@xyflow/react\";\nimport { createContext, type ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { PortHint, PortSide } from \"../port-row\";\n\n/** One handle: its node's id and its handle id (`null` for a handle without one). */\nexport type PortRef = { nodeId: string; handleId: string | null };\n\n/**\n * Whether a wire may join `from` (always the output) to `to` (always the input), whichever end the drag began at:\n * `true` accepts, `false` refuses, a string refuses and is the reason.\n */\nexport type CanConnect = (from: PortRef, to: PortRef) => boolean | string;\n\n/** What one handle shows while a wire is dragged, and why when it refuses. */\nexport type PortHintOf = { hint: PortHint; reason?: string };\n\n/** The drag in progress, as `<ConnectHints>` hands it to every `PortRow`; `null` while no wire is dragged. */\nexport type ConnectHintsValue = {\n /** The handle the drag began at, and its side. */\n origin: PortRef & { side: PortSide };\n /** The hint for one handle: `origin`, `ok` or `no` (with its reason) on the other side, `null` on the origin's. */\n hintFor: (port: PortRef, side: PortSide) => PortHintOf;\n} | null;\n\n/** A drop on a handle the rule refused: that handle, its side, and the rule's reason when it gave one. */\nexport type ConnectRefusal = { port: PortRef & { side: PortSide }; reason?: string };\n\n/** The handlers `useConnectHints` gives `<ReactFlow>`. */\nexport type ConnectHintsFlowProps = {\n onConnectStart: OnConnectStart;\n onConnectEnd: OnConnectEnd;\n isValidConnection: (connection: Edge | Connection) => boolean;\n};\n\nconst ConnectHintsContext = createContext<ConnectHintsValue>(null);\n\n/** Hands a drag's hints to every `PortRow` inside it. */\nexport function ConnectHints({ value, children }: { value: ConnectHintsValue; children?: ReactNode }) {\n return <ConnectHintsContext value={value}>{children}</ConnectHintsContext>;\n}\n\n/** The drag's hints from the nearest `<ConnectHints>`, or `null` outside one or while no wire is dragged. */\nexport function useConnectHintsValue(): ConnectHintsValue {\n return useContext(ConnectHintsContext);\n}\n\nconst verdictKey = (from: PortRef, to: PortRef) => JSON.stringify([from.nodeId, from.handleId, to.nodeId, to.handleId]);\n\nconst samePort = (a: PortRef, b: PortRef) => a.nodeId === b.nodeId && a.handleId === b.handleId;\n\n/**\n * Tracks a wire's drag from React Flow's connect start to its end and judges each candidate handle by `canConnect`.\n * `flowProps` goes to `<ReactFlow>` (through `mergeFlowProps` with others), `value` to `<ConnectHints>`.\n */\nexport function useConnectHints(canConnect: CanConnect): {\n value: ConnectHintsValue;\n /** The last drop the rule refused, until the next drag begins; `null` when the last drag ended otherwise. */\n refused: ConnectRefusal | null;\n flowProps: ConnectHintsFlowProps;\n} {\n const rule = useRef(canConnect);\n useLayoutEffect(() => {\n rule.current = canConnect;\n });\n // The verdicts of the drag in progress, so each candidate is judged once per drag; none outside a drag.\n const verdicts = useRef<Map<string, boolean | string> | null>(null);\n const [origin, setOrigin] = useState<(PortRef & { side: PortSide }) | null>(null);\n const [refused, setRefused] = useState<ConnectRefusal | null>(null);\n\n const judge = useMemo(\n () =>\n (from: PortRef, to: PortRef): boolean | string => {\n const kept = verdicts.current;\n if (kept === null) return rule.current(from, to);\n const key = verdictKey(from, to);\n const known = kept.get(key);\n if (known !== undefined) return known;\n const verdict = rule.current(from, to);\n kept.set(key, verdict);\n return verdict;\n },\n [],\n );\n\n const flowProps = useMemo<ConnectHintsFlowProps>(\n () => ({\n onConnectStart: (_event, { nodeId, handleId, handleType }) => {\n if (nodeId === null) return;\n verdicts.current = new Map();\n setOrigin({ nodeId, handleId, side: handleType === \"target\" ? \"input\" : \"output\" });\n setRefused(null);\n },\n onConnectEnd: (_event, connection) => {\n // A drop on a handle of the other side that the rule refused; a drop on empty canvas, or on the origin's own\n // side (not a candidate), is no refusal.\n const { fromHandle, toHandle } = connection;\n let refusal: ConnectRefusal | null = null;\n if (fromHandle !== null && toHandle !== null && fromHandle.type !== toHandle.type) {\n const from: PortRef = { nodeId: fromHandle.nodeId, handleId: fromHandle.id ?? null };\n const to: PortRef = { nodeId: toHandle.nodeId, handleId: toHandle.id ?? null };\n const toInput = toHandle.type === \"target\";\n const verdict = toInput ? judge(from, to) : judge(to, from);\n if (verdict !== true) {\n const port = { ...to, side: toInput ? (\"input\" as const) : (\"output\" as const) };\n refusal = typeof verdict === \"string\" ? { port, reason: verdict } : { port };\n }\n }\n verdicts.current = null;\n setOrigin(null);\n setRefused(refusal);\n },\n isValidConnection: (connection) =>\n judge(\n { nodeId: connection.source, handleId: connection.sourceHandle ?? null },\n { nodeId: connection.target, handleId: connection.targetHandle ?? null },\n ) === true,\n }),\n [judge],\n );\n\n const value = useMemo<ConnectHintsValue>(() => {\n if (origin === null) return null;\n return {\n origin,\n hintFor: (port, side) => {\n if (side === origin.side) return { hint: samePort(port, origin) ? \"origin\" : null };\n const at: PortRef = { nodeId: origin.nodeId, handleId: origin.handleId };\n const verdict = side === \"input\" ? judge(at, port) : judge(port, at);\n if (verdict === true) return { hint: \"ok\" };\n return typeof verdict === \"string\" ? { hint: \"no\", reason: verdict } : { hint: \"no\" };\n },\n };\n }, [origin, judge]);\n\n return { value, refused, flowProps };\n}\n","// The canvas's status line for connecting (docs/graph.md#connectstatus): while a wire is dragged it says why the port\n// under the pointer (or the finger) refuses it, and after a drop the rule refused, the verdict, until the next drag\n// begins (docs/ux-rules.md#live-pending-queued-refused, U59). Its words come from useConnectHints, the same rule as\n// the ports' hints and the drop check, so it never says what they do not. It is one polite live region, there from\n// the first render with no words (U42), in React Flow's <Panel>, and takes no pointer events.\nimport { Panel, type PanelPosition, type ReactFlowState, useStore } from \"@xyflow/react\";\nimport type { ConnectHintsValue, ConnectRefusal } from \"../connect-hints\";\nimport \"./ConnectStatus.css\";\n\n/** The status line's words, each replaceable. */\nexport interface ConnectStatusLabels {\n /** Over a port that refuses the wire: the rule's reason, or \"This port refuses the wire\" when it gave none. */\n refuses: (reason: string | undefined) => string;\n /** After a drop the rule refused: \"Not connected: \" and the reason, or \"Not connected: that port refuses the wire\". */\n notConnected: (reason: string | undefined) => string;\n}\n\nexport const defaultConnectStatusLabels: ConnectStatusLabels = {\n refuses: (reason) => reason ?? \"This port refuses the wire\",\n notConnected: (reason) => `Not connected: ${reason ?? \"that port refuses the wire\"}`,\n};\n\nexport type ConnectStatusProps = {\n /** `useConnectHints`'s `value`: the drag in progress, or `null`. */\n value: ConnectHintsValue;\n /** `useConnectHints`'s `refused`: the last drop the rule refused, or `null`. */\n refused: ConnectRefusal | null;\n /** Where the line sits on the canvas, React Flow's `PanelPosition`: \"bottom-center\" by default. */\n position?: PanelPosition | (string & {});\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<ConnectStatusLabels>;\n /** Added to the panel's own `pb-connect-status` class. */\n className?: string;\n};\n\n/** The handle the drag is over (within React Flow's connection radius), as one string so a move within it is still. */\nconst overHandle = (state: ReactFlowState): string | null => {\n const connection = state.connection;\n if (!connection.inProgress || connection.toHandle === null) return null;\n const { nodeId, id, type } = connection.toHandle;\n return JSON.stringify([nodeId, id ?? null, type]);\n};\n\n/** What the line says now: why the port under the drag refuses, else a refused drop's verdict, else nothing. */\nexport function connectStatusWords(\n value: ConnectHintsValue,\n refused: ConnectRefusal | null,\n over: { nodeId: string; handleId: string | null; side: \"input\" | \"output\" } | null,\n labels: ConnectStatusLabels = defaultConnectStatusLabels,\n): string {\n if (value !== null) {\n if (over === null) return \"\";\n const { hint, reason } = value.hintFor({ nodeId: over.nodeId, handleId: over.handleId }, over.side);\n return hint === \"no\" ? labels.refuses(reason) : \"\";\n }\n return refused === null ? \"\" : labels.notConnected(refused.reason);\n}\n\nexport function ConnectStatus({ value, refused, position = \"bottom-center\", labels, className }: ConnectStatusProps) {\n const words = { ...defaultConnectStatusLabels, ...labels };\n const key = useStore(overHandle);\n let over: { nodeId: string; handleId: string | null; side: \"input\" | \"output\" } | null = null;\n if (key !== null) {\n const [nodeId, handleId, type] = JSON.parse(key) as [string, string | null, string];\n over = { nodeId, handleId, side: type === \"target\" ? \"input\" : \"output\" };\n }\n const text = connectStatusWords(value, refused, over, words);\n return (\n <Panel\n position={position as PanelPosition}\n className={className === undefined ? \"pb-connect-status\" : `pb-connect-status ${className}`}\n >\n <p className=\"pb-connect-status-text\" role=\"status\">\n {text}\n </p>\n </Panel>\n );\n}\n","// A context menu at a point on the canvas (docs/graph.md#usecontextat): a right-click, or a long-press on a touch\n// screen, on a node or on empty canvas asks the app to open its palette there (docs/ux-rules.md#the-view-and-the-canvas,\n// U66), with the point in flow and window coordinates and the node pressed. React Flow gives the right-click; touch has\n// no contextmenu on every browser (iOS fires none), so the hook times a still press itself, and takes a contextmenu\n// that comes during the press (Android's) as that same long-press, so each press asks once.\nimport { type Node, type NodeMouseHandler, useReactFlow } from \"@xyflow/react\";\nimport {\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport type { FlowPoint } from \"../add-at\";\n\n/** How long a touch is held still to count as a long-press, in ms. */\nexport const LONG_PRESS_MS = 500;\n/** How far, in px, a held touch may move and still count: one that moves further is a pan or a drag. */\nexport const LONG_PRESS_SLOP = 10;\n\n/** Where a context menu was asked for, and on what. */\nexport type ContextAt = {\n /** The point in flow coordinates, as `useAddAt` gives it. */\n point: FlowPoint;\n /** The same point in the window's coordinates, as `CommandPalette`'s `at` takes it. */\n at: { x: number; y: number };\n /** The node pressed, as React Flow holds it; absent on empty canvas. */\n node?: Node;\n /** How it was asked: a right-click, or a long-press on touch. */\n by: \"contextmenu\" | \"long-press\";\n};\n\n/** Called with where a context menu was asked for. */\nexport type OnContextAt = (context: ContextAt) => void;\n\n/** The props `useContextAt` gives `<ReactFlow>`. */\nexport type ContextAtFlowProps = {\n onPaneContextMenu: (event: ReactMouseEvent | MouseEvent) => void;\n onNodeContextMenu: NodeMouseHandler;\n onPointerDown: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerMove: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerUp: (event: ReactPointerEvent<HTMLDivElement>) => void;\n onPointerCancel: (event: ReactPointerEvent<HTMLDivElement>) => void;\n};\n\nexport type ContextAtOptions = {\n /** false switches it off: a right-click is the browser's again, and a long-press nothing; true by default. */\n enabled?: boolean;\n};\n\n/** What a press began on: empty canvas, a node (by id), or anything else (a handle, an edge, a panel). */\nfunction pressedOn(target: EventTarget | null): { node?: string } | null {\n if (!(target instanceof Element)) return null;\n if (target.classList.contains(\"react-flow__pane\")) return {};\n if (target.closest(\".react-flow__handle, .react-flow__panel, .react-flow__edge\") !== null) return null;\n const node = target.closest<HTMLElement>(\".react-flow__node\");\n const id = node?.dataset.id;\n return id === undefined ? null : { node: id };\n}\n\n/** A touch held for a long-press: where it began, its timer, and whether it has asked yet. */\ntype Press = { id: number; x: number; y: number; on: { node?: string }; timer: number; asked: boolean };\n\n/**\n * Calls `onContextAt` for a right-click and for a long-press on touch, on a node or on empty canvas; its `flowProps`\n * go to `<ReactFlow>` (through `mergeFlowProps` with others). The browser's own menu is prevented where it asks.\n */\nexport function useContextAt(\n onContextAt: OnContextAt,\n options: ContextAtOptions = {},\n): { flowProps: ContextAtFlowProps } {\n const enabled = options.enabled ?? true;\n const { screenToFlowPosition, getNode } = useReactFlow();\n const latest = useRef({ onContextAt, enabled, screenToFlowPosition, getNode });\n useLayoutEffect(() => {\n latest.current = { onContextAt, enabled, screenToFlowPosition, getNode };\n });\n const press = useRef<Press | null>(null);\n // The click a lifted long-press makes, swallowed so it neither selects nor clears what the menu is for.\n const swallow = useRef<(() => void) | null>(null);\n\n useEffect(\n () => () => {\n if (press.current !== null) window.clearTimeout(press.current.timer);\n swallow.current?.();\n },\n [],\n );\n\n const flowProps = useMemo<ContextAtFlowProps>(() => {\n const ask = (x: number, y: number, on: { node?: string }, by: ContextAt[\"by\"]) => {\n const { onContextAt: call, screenToFlowPosition: toFlow, getNode: nodeOf } = latest.current;\n const node = on.node === undefined ? undefined : nodeOf(on.node);\n const context: ContextAt = { point: toFlow({ x, y }), at: { x, y }, by };\n call(node === undefined ? context : { ...context, node });\n };\n const end = () => {\n if (press.current !== null) window.clearTimeout(press.current.timer);\n press.current = null;\n };\n /**\n * Swallows the next click, in the capture phase, until the next press begins anywhere on the page: a lift that makes\n * no click must not leave the swallow waiting for the press on the menu the long-press opened.\n */\n const swallowClick = () => {\n swallow.current?.();\n const onClick = (event: MouseEvent) => {\n event.preventDefault();\n event.stopPropagation();\n stop();\n };\n const stop = () => {\n window.removeEventListener(\"click\", onClick, true);\n window.removeEventListener(\"pointerdown\", stop, true);\n swallow.current = null;\n };\n window.addEventListener(\"click\", onClick, true);\n window.addEventListener(\"pointerdown\", stop, true);\n swallow.current = stop;\n };\n /** A contextmenu: during a held touch it is that long-press (once); otherwise a right-click. */\n const onMenu = (event: ReactMouseEvent | MouseEvent, on: { node?: string }) => {\n if (!latest.current.enabled) return;\n event.preventDefault();\n const held = press.current;\n if (held !== null) {\n if (!held.asked) {\n held.asked = true;\n window.clearTimeout(held.timer);\n swallowClick();\n ask(held.x, held.y, held.on, \"long-press\");\n }\n return;\n }\n ask(event.clientX, event.clientY, on, \"contextmenu\");\n };\n return {\n onPaneContextMenu: (event) => {\n onMenu(event, {});\n },\n onNodeContextMenu: (event, node) => {\n onMenu(event, { node: node.id });\n },\n onPointerDown: (event) => {\n swallow.current?.();\n // A second finger is a pinch, not a long-press.\n if (press.current !== null) {\n end();\n return;\n }\n if (!latest.current.enabled || event.pointerType !== \"touch\" || !event.isPrimary) return;\n const on = pressedOn(event.target);\n if (on === null) return;\n const { pointerId: id, clientX: x, clientY: y } = event;\n const timer = window.setTimeout(() => {\n const held = press.current;\n if (held === null || held.id !== id || held.asked) return;\n held.asked = true;\n swallowClick();\n ask(held.x, held.y, held.on, \"long-press\");\n }, LONG_PRESS_MS);\n press.current = { id, x, y, on, timer, asked: false };\n },\n onPointerMove: (event) => {\n const held = press.current;\n if (held === null || held.id !== event.pointerId || held.asked) return;\n if (Math.hypot(event.clientX - held.x, event.clientY - held.y) > LONG_PRESS_SLOP) end();\n },\n onPointerUp: (event) => {\n if (press.current?.id === event.pointerId) end();\n },\n onPointerCancel: (event) => {\n if (press.current?.id === event.pointerId) end();\n },\n };\n }, []);\n\n return { flowProps };\n}\n","// An empty canvas says what to do (docs/graph.md#emptycanvashint): the app's words, and the add gestures, drawn on\n// the canvas itself in React Flow's <Panel>, and gone with the first node (docs/ux-rules.md#states, U35). It reads\n// React Flow's node count unless the app says whether the graph is empty. Its words are not a live region: the canvas\n// says them while it is empty, and a node arriving is news the canvas shows. It takes no pointer events, so a\n// double-click on it still reaches the canvas and adds.\nimport { Panel, type PanelPosition, type ReactFlowState, useStore } from \"@xyflow/react\";\nimport type { ReactNode } from \"react\";\nimport { keyLabel, type Platform, useMediaBreakpoint } from \"../../hooks\";\nimport \"./EmptyCanvasHint.css\";\n\n/** The hint's own words, each replaceable. */\nexport interface EmptyCanvasHintLabels {\n /**\n * The add gestures: \"Double-click to add a node\" with a pointer, \"Double-tap to add a node\" on a touch screen, then\n * \", or press A\" with the app's add key as people read it.\n */\n add: (gesture: \"pointer\" | \"touch\", keys: string | undefined) => string;\n}\n\nexport const defaultEmptyCanvasHintLabels: EmptyCanvasHintLabels = {\n add: (gesture, keys) =>\n `${gesture === \"touch\" ? \"Double-tap\" : \"Double-click\"} to add a node${keys === undefined ? \"\" : `, or press ${keys}`}`,\n};\n\nexport type EmptyCanvasHintProps = {\n /** The app's own words above the gestures (\"This graph has no nodes yet\"); none by default. */\n children?: ReactNode;\n /** Whether the graph is empty; without it, while React Flow holds no nodes. An app drawing a ghost node passes it. */\n empty?: boolean;\n /** Whether adding is on, so the gestures are said (`useAddAt`'s `enabled`); true by default. */\n add?: boolean;\n /** The app's add key (a key string, `\"A\"`), drawn through `keyLabel` after the gestures; the hint binds nothing. */\n keys?: string;\n /** The platform the key is written for; the browser's by default. */\n platform?: Platform;\n /** Where it sits on the canvas, React Flow's `PanelPosition`: \"top-center\" by default. */\n position?: PanelPosition | (string & {});\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<EmptyCanvasHintLabels>;\n /** Added to the panel's own `pb-empty-canvas` class. */\n className?: string;\n};\n\nconst noNodes = (state: ReactFlowState): boolean => state.nodes.length === 0;\n\n/** Says, on an empty canvas, what to do; draws nothing once the graph has a node. */\nexport function EmptyCanvasHint({\n children,\n empty,\n add = true,\n keys,\n platform,\n position = \"top-center\",\n labels,\n className,\n}: EmptyCanvasHintProps) {\n const words = { ...defaultEmptyCanvasHintLabels, ...labels };\n const none = useStore(noNodes);\n const { touch } = useMediaBreakpoint();\n if (!(empty ?? none)) return null;\n const gestures = add\n ? words.add(touch ? \"touch\" : \"pointer\", keys === undefined ? undefined : keyLabel(keys, { platform }))\n : null;\n if (children === undefined && gestures === null) return null;\n return (\n <Panel\n position={position as PanelPosition}\n className={className === undefined ? \"pb-empty-canvas\" : `pb-empty-canvas ${className}`}\n >\n {children !== undefined && <div className=\"pb-empty-canvas-words\">{children}</div>}\n {gestures !== null && <p className=\"pb-empty-canvas-add\">{gestures}</p>}\n </Panel>\n );\n}\n","// Keeping the whole graph in view until the person takes the view over (docs/graph.md#usefollowfit). While following,\n// the view fits again when the app's key changes or the canvas changes size, each time once every node is measured;\n// a move the person makes (once it changes the viewport, not a press that moves nothing) stops it, as does stop(),\n// and fit() fits and follows again. onFitted comes in the frame after each fit lands.\nimport {\n type FitViewOptions,\n type Node,\n type OnMove,\n type ReactFlowState,\n type Viewport,\n useReactFlow,\n useStore,\n useStoreApi,\n} from \"@xyflow/react\";\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport { slowMotionMs } from \"../canvas-tools/motion\";\n\nexport type FollowFitOptions<NodeType extends Node = Node> = {\n /** The app's value that changes when nodes are added, removed or laid out; a change fits again while following. */\n key: unknown;\n /** React Flow's fit options, for every fit. */\n fitOptions?: FitViewOptions<NodeType>;\n /** Called with the viewport after each fit has landed, in the frame after the viewport is set. */\n onFitted?: (viewport: Viewport) => void;\n};\n\n/** The props `useFollowFit` gives `<ReactFlow>`. */\nexport type FollowFitFlowProps = { onMoveStart: OnMove; onMove: OnMove; onMoveEnd: OnMove };\n\nexport type FollowFit = {\n /** Whether the view fits again on its own: true from the start, false once the person moves the view. */\n following: boolean;\n /** Fits now, moving as the fit tool does, and follows again. */\n fit: () => void;\n /** Stops following, as the person's own move does: for an app that moves the view itself (going to a node). */\n stop: () => void;\n flowProps: FollowFitFlowProps;\n};\n\n/** Whether every node React Flow shows has been measured (none counts as all). */\nconst allMeasured = (state: ReactFlowState) => {\n for (const node of state.nodeLookup.values()) {\n if (node.hidden !== true && (node.measured.width === undefined || node.measured.height === undefined)) return false;\n }\n return true;\n};\n\ntype Fitted = { key: unknown; width: number; height: number };\n\nexport function useFollowFit<NodeType extends Node = Node>({\n key,\n fitOptions,\n onFitted,\n}: FollowFitOptions<NodeType>): FollowFit {\n const flow = useReactFlow<NodeType>();\n const store = useStoreApi();\n const width = useStore((state) => state.width);\n const height = useStore((state) => state.height);\n const measured = useStore(allMeasured);\n const [following, setFollowing] = useState(true);\n const latest = useRef({ key, width, height, fitOptions, onFitted });\n useLayoutEffect(() => {\n latest.current = { key, width, height, fitOptions, onFitted };\n });\n // What the last fit was for, so a render that changes none of it does not fit again.\n const fittedFor = useRef<Fitted | null>(null);\n\n const land = useCallback(\n async (duration: number) => {\n // With no node there is nothing to fit, and the view stays; onFitted still says the layout is ready.\n if (store.getState().nodeLookup.size > 0) await flow.fitView({ ...latest.current.fitOptions, duration });\n requestAnimationFrame(() => {\n latest.current.onFitted?.(flow.getViewport());\n });\n },\n [flow, store],\n );\n\n useEffect(() => {\n if (!following || width === 0 || height === 0) return;\n // The store, not this render's `measured`, which only wakes the effect: nodes React Flow took in this commit (its\n // effects run before this one) are in the store but not yet measured, while this render still says all were.\n if (!allMeasured(store.getState())) return;\n const last = fittedFor.current;\n if (last !== null && Object.is(last.key, key) && last.width === width && last.height === height) return;\n fittedFor.current = { key, width, height };\n void land(0);\n }, [following, key, width, height, measured, store, land]);\n\n const fit = useCallback(() => {\n const now = latest.current;\n fittedFor.current = { key: now.key, width: now.width, height: now.height };\n setFollowing(true);\n void land(slowMotionMs(store.getState().domNode));\n }, [land, store]);\n\n const stop = useCallback(() => {\n setFollowing(false);\n }, []);\n\n // Where the person's move began. React Flow starts a move on every press on the pane, also one that moves nothing (a\n // click to deselect, a double-click to add), so following stops only once the person's move has changed the view.\n // Each step of the move counts, not only its end: d3-zoom folds a move by code that lands during the person's (a\n // fit landing mid-wheel) into the person's gesture, so the gesture can end where it began, the person's zoom undone\n // by the fit. A step or an end that changed nothing leaves the start in place: when the wheel interrupts a fit's\n // transition, d3-zoom ends the fit's move with the wheel as its event, after the wheel's own start (React Flow defers\n // each end a task). Each start with an event sets it afresh.\n const movedFrom = useRef<Viewport | null>(null);\n const flowProps = useMemo<FollowFitFlowProps>(() => {\n // A move made by code (a fit, a zoom from a tool, a minimap drag) has no event, so it does not count here; the\n // tools' moves the person asked for reach stop() through CanvasTools' onViewMove.\n const moved: OnMove = (event, viewport) => {\n const from = movedFrom.current;\n if (event === null || from === null) return;\n if (from.x === viewport.x && from.y === viewport.y && from.zoom === viewport.zoom) return;\n movedFrom.current = null;\n setFollowing(false);\n };\n return {\n onMoveStart: (event, viewport) => {\n if (event !== null) movedFrom.current = viewport;\n },\n onMove: moved,\n onMoveEnd: moved,\n };\n }, []);\n\n return { following, fit, stop, flowProps };\n}\n","// One port of a node (docs/graph.md#portrow): its React Flow handle at the box's edge and its words. NodeBox draws its\n// rows with it; an app drawing a box of its own may use it alone, inside a React Flow node. React Flow's own handle\n// classes stay on the handle, so its connection logic and connectionRadius work as on any handle.\nimport { Handle, Position, useNodeId } from \"@xyflow/react\";\nimport type { ReactNode } from \"react\";\nimport { WarnMark } from \"../../primitives\";\nimport { useConnectHintsValue } from \"../connect-hints/useConnectHints\";\nimport \"./PortRow.css\";\n\n/** Which side of the box a port is on: an input is a target handle on the left edge, an output a source on the right. */\nexport type PortSide = \"input\" | \"output\";\n\n/**\n * What a port shows while a wire is dragged: `origin` the handle the drag began at, `ok` a handle that accepts it,\n * `no` one that refuses it, `null` no drag. An open enum; one it does not know is drawn as `null`.\n */\nexport type PortHint = \"ok\" | \"no\" | \"origin\" | null | (string & {});\n\nexport type PortRowProps = {\n /** The handle id, passed to React Flow's `<Handle id>` unchanged (the app's own scheme). */\n id: string;\n /** `input` (a target handle on the left edge) or `output` (a source handle on the right edge). */\n side: PortSide;\n /** The port's name; a string is also its tooltip. */\n label: ReactNode;\n /** After the label in the muted code face: the port's type. */\n typeLabel?: ReactNode;\n /** While a wire is dragged: `origin`, `ok`, `no`, or `null` for no drag. Given, it wins over `<ConnectHints>`'. */\n hint?: PortHint;\n /** Why the port refuses the wire: the handle's and the row's tooltip while `hint` is `no`. */\n reason?: string;\n /** A problem with the port: a warning mark beside the label, with these as its words. */\n problem?: string;\n /** A slot at the row's inner end, toward the box's centre (a `Meter`). */\n trailing?: ReactNode;\n /** Whether a wire may start or end here; true by default (`<Handle isConnectable>`). */\n connectable?: boolean;\n};\n\nconst knownHints: readonly string[] = [\"ok\", \"no\", \"origin\"];\n\n/** Draws one port: its handle at the edge, its label and type, a problem's mark and a trailing slot. */\nexport function PortRow({\n id,\n side,\n label,\n typeLabel,\n hint: ownHint,\n reason: ownReason,\n problem,\n trailing,\n connectable = true,\n}: PortRowProps) {\n const isInput = side !== \"output\";\n const drag = useConnectHintsValue();\n const nodeId = useNodeId();\n // A hint given as a prop wins; otherwise the drag in progress says, judged once per drag for this handle.\n const fromDrag =\n ownHint === undefined && drag !== null && nodeId !== null\n ? drag.hintFor({ nodeId, handleId: id }, isInput ? \"input\" : \"output\")\n : undefined;\n const hint = fromDrag === undefined ? (ownHint ?? null) : fromDrag.hint;\n const reason = fromDrag === undefined ? ownReason : (fromDrag.reason ?? ownReason);\n const shown = hint !== null && knownHints.includes(hint) ? hint : undefined;\n const refused = shown === \"no\" && reason !== undefined ? reason : undefined;\n return (\n <div\n className=\"pb-port-row\"\n data-side={isInput ? \"input\" : \"output\"}\n data-hint={shown}\n title={refused ?? (typeof label === \"string\" ? label : undefined)}\n >\n <Handle\n id={id}\n type={isInput ? \"target\" : \"source\"}\n position={isInput ? Position.Left : Position.Right}\n isConnectable={connectable}\n className=\"pb-port-handle\"\n data-hint={shown}\n title={refused}\n />\n <span className=\"pb-port-words\">\n <span className=\"pb-port-label\">{label}</span>\n {typeLabel !== undefined && <code className=\"pb-port-type\">{typeLabel}</code>}\n {problem !== undefined && <WarnMark label={problem} title={problem} />}\n </span>\n {trailing !== undefined && <span className=\"pb-port-trailing\">{trailing}</span>}\n </div>\n );\n}\n","// A node's box (docs/graph.md#nodebox): the body of an app's own React Flow node type, a header (title, subtitle, a\n// change's badge and a status slot), a line saying why the node is silent, its ports as PortRows, and a footer. Its\n// sizes come from the --pb-node-* tokens, the same values as the geometry constants an app lays its nodes out with\n// (nodeBoxSize), so a rendered box is the size the layout made room for.\nimport { useNodeId, useUpdateNodeInternals } from \"@xyflow/react\";\nimport { type ComponentPropsWithoutRef, type CSSProperties, type ReactNode, useEffect, useId, useRef } from \"react\";\nimport { Badge } from \"../../primitives\";\nimport { PortRow, type PortRowProps } from \"../port-row\";\nimport type { NodePorts } from \"./geometry\";\nimport \"./NodeBox.css\";\n\n/** A box's stripe down its start edge: an open enum, and one it does not know is drawn in `--pb-line-strong`. */\nexport type NodeBoxTone = \"ok\" | \"warn\" | \"err\" | \"quiet\" | \"off\" | \"accent\" | \"muted\" | (string & {});\n\n/** An edit not yet applied: an open enum, and one it does not know is a plain border with its own string as the word. */\nexport type NodeBoxChange = \"added\" | \"removed\" | \"renamed\" | \"changed\" | (string & {});\n\n/** The box's own words, each replaceable: the change badge's word for each known change. */\nexport interface NodeBoxLabels {\n added: string;\n removed: string;\n renamed: string;\n changed: string;\n}\n\nexport const defaultNodeBoxLabels: NodeBoxLabels = {\n added: \"added\",\n removed: \"removed\",\n renamed: \"renamed\",\n changed: \"changed\",\n};\n\n/** One port of a box: a `PortRow`'s props without `side`, which `NodeBox` sets. */\nexport type PortSpec = Omit<PortRowProps, \"side\">;\n\nexport type NodeBoxProps = Omit<ComponentPropsWithoutRef<\"div\">, \"title\" | \"children\" | \"role\"> & {\n /** The node's name, one line cut with an ellipsis; a string is also the header's tooltip. Names the box's group. */\n title: ReactNode;\n /** The second header line, muted: the node's type. */\n subtitle?: ReactNode;\n /** The stripe down the box's start edge, in the tone's colour; none, or one it does not know, in `--pb-line-strong`. */\n tone?: NodeBoxTone;\n /** A dashed border, the stripe hatched and the words muted. Drawing only: whether its ports connect is the app's. */\n disabled?: boolean;\n /** The border in `--pb-err` and the header on `--pb-err-soft`; the reason goes in `line`. */\n failed?: boolean;\n /** An edit not yet applied: a 2 px border in its tone and a badge with its word; `removed` strikes the title. */\n change?: NodeBoxChange;\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<NodeBoxLabels>;\n /** A slot at the header's end (a `Pill`). */\n status?: ReactNode;\n /** One row under the header saying why the node is silent; a string is also its tooltip. */\n line?: ReactNode;\n /** The input ports, keyed by `id`. */\n inputs?: readonly PortSpec[];\n /** The output ports, keyed by `id`. */\n outputs?: readonly PortSpec[];\n /** `stacked` (the default: the inputs' rows, then the outputs') or `side-by-side` (two columns). */\n ports?: NodePorts;\n /** A slot: one row at the foot (badges). */\n footer?: ReactNode;\n /** Selected, from React Flow's `NodeProps`: a 2 px outline in the accent. */\n selected?: boolean;\n /** Its width in px; `NODE_WIDTH` by default. */\n width?: number;\n};\n\nconst knownChanges: readonly string[] = [\"added\", \"removed\", \"renamed\", \"changed\"];\n\n/** Draws a node's box; render it inside a React Flow node. */\nexport function NodeBox({\n title,\n subtitle,\n tone,\n disabled = false,\n failed = false,\n change,\n labels,\n status,\n line,\n inputs = [],\n outputs = [],\n ports = \"stacked\",\n footer,\n selected = false,\n width,\n className,\n style,\n ...rest\n}: NodeBoxProps) {\n const titleId = useId();\n const layout = ports === \"side-by-side\" ? \"side-by-side\" : \"stacked\";\n usePortsMeasured(inputs, outputs, layout);\n\n const words = { ...defaultNodeBoxLabels, ...labels };\n const changeWord =\n change === undefined ? undefined : knownChanges.includes(change) ? words[change as keyof NodeBoxLabels] : change;\n const hasPorts = inputs.length > 0 || outputs.length > 0;\n const inputRows = inputs.map((port) => <PortRow key={port.id} {...port} side=\"input\" />);\n const outputRows = outputs.map((port) => <PortRow key={port.id} {...port} side=\"output\" />);\n\n return (\n <div\n {...rest}\n className={className === undefined ? \"pb-node-box\" : `pb-node-box ${className}`}\n role=\"group\"\n aria-labelledby={titleId}\n data-tone={tone}\n data-change={change}\n data-disabled={disabled ? \"\" : undefined}\n data-failed={failed ? \"\" : undefined}\n data-selected={selected ? \"\" : undefined}\n style={width === undefined ? style : ({ ...style, width: `${width}px` } satisfies CSSProperties)}\n >\n <div className=\"pb-node-header\">\n <div className=\"pb-node-heading\">\n <span id={titleId} className=\"pb-node-title\" title={typeof title === \"string\" ? title : undefined}>\n {title}\n </span>\n {subtitle !== undefined && <span className=\"pb-node-subtitle\">{subtitle}</span>}\n </div>\n {changeWord !== undefined && (\n <Badge tone={change ?? \"\"} className=\"pb-node-change\">\n {changeWord}\n </Badge>\n )}\n {status !== undefined && <div className=\"pb-node-status\">{status}</div>}\n </div>\n {line !== undefined && (\n <div className=\"pb-node-line\" title={typeof line === \"string\" ? line : undefined}>\n {line}\n </div>\n )}\n {hasPorts &&\n (layout === \"side-by-side\" ? (\n <div className=\"pb-node-ports\" data-ports=\"side-by-side\">\n <div className=\"pb-node-column\" data-side=\"input\">\n {inputRows}\n </div>\n <div className=\"pb-node-column\" data-side=\"output\">\n {outputRows}\n </div>\n </div>\n ) : (\n <div className=\"pb-node-ports\" data-ports=\"stacked\">\n {inputRows}\n {outputRows}\n </div>\n ))}\n {footer !== undefined && <div className=\"pb-node-footer\">{footer}</div>}\n </div>\n );\n}\n\n/**\n * Asks React Flow to measure the node's handles again when its ordered port ids or their layout change, so a handle\n * added or moved is where a wire meets it. React Flow measures a node's handles itself when the node first renders.\n */\nfunction usePortsMeasured(inputs: readonly PortSpec[], outputs: readonly PortSpec[], layout: string) {\n const nodeId = useNodeId();\n const updateNodeInternals = useUpdateNodeInternals();\n const key = JSON.stringify([layout, inputs.map((port) => port.id), outputs.map((port) => port.id)]);\n const measured = useRef(key);\n useEffect(() => {\n if (measured.current === key) return;\n measured.current = key;\n if (nodeId !== null) updateNodeInternals(nodeId);\n }, [key, nodeId, updateNodeInternals]);\n}\n","// A node box's geometry (docs/graph.md#geometry). An app sizes its nodes before they render (dagre and ELK take\n// sizes), so the sizes are fixed: these constants are what layout code reads, and tokens.css holds the same values as\n// --pb-node-* tokens, which NodeBox and PortRow size themselves from. geometry.test.ts holds each token equal to its\n// constant, and tokens.test.ts fails on a brand that sets one.\n\n/** The default width of a node box, in px; `NodeBox`'s `width` overrides it per node (`--pb-node-width`). */\nexport const NODE_WIDTH = 240;\n/** The header (title and subtitle), with or without a subtitle, in px (`--pb-node-header`). */\nexport const NODE_HEADER = 46;\n/** The `line` row, when there is one, in px (`--pb-node-line`). */\nexport const NODE_LINE = 22;\n/** One port row, in px (`--pb-node-row`). */\nexport const NODE_ROW = 22;\n/** The space above the first port row and below the last, in px (`--pb-node-pad`). */\nexport const NODE_PAD = 8;\n/** The footer, when there is one, in px (`--pb-node-footer`). */\nexport const NODE_FOOTER = 28;\n/** A handle's dot, in px (`--pb-node-handle`). */\nexport const HANDLE_SIZE = 10;\n/** A handle's hit area, centred on the dot, in px (`--pb-node-handle-hit`); 32 px on a touch screen. */\nexport const HANDLE_HIT = 20;\n\n/**\n * How a node box lays out its ports: `stacked` (the inputs' rows, then the outputs') or `side-by-side` (two columns,\n * row n of each on one line). An open enum; one it does not know is stacked.\n */\nexport type NodePorts = \"stacked\" | \"side-by-side\" | (string & {});\n\n/** What decides a node box's size: its port counts, their layout, and whether it has a line and a footer. */\nexport type NodeBoxShape = {\n /** How many input ports. */\n inputs: number;\n /** How many output ports. */\n outputs: number;\n /** How the ports are laid out. */\n ports: NodePorts;\n /** Whether it has a `line` row. */\n line: boolean;\n /** Whether it has a footer. */\n footer: boolean;\n /** Its width in px; `NODE_WIDTH` by default. */\n width?: number;\n};\n\n/** How many port rows a box draws: inputs plus outputs stacked, the larger of the two side by side. */\nexport function nodePortRows(inputs: number, outputs: number, ports: NodePorts): number {\n return ports === \"side-by-side\" ? Math.max(inputs, outputs) : inputs + outputs;\n}\n\n/**\n * A node box's size in px, the one formula layout code sizes nodes with: the header, the line when there is one, the\n * port rows and the padding above and below them when there are ports, and the footer when there is one. The box's\n * 1 px border is inside it; the selection ring is outside.\n */\nexport function nodeBoxSize({ inputs, outputs, ports, line, footer, width = NODE_WIDTH }: NodeBoxShape): {\n width: number;\n height: number;\n} {\n const rows = nodePortRows(Math.max(0, inputs), Math.max(0, outputs), ports);\n const height =\n NODE_HEADER + (line ? NODE_LINE : 0) + (rows > 0 ? 2 * NODE_PAD + rows * NODE_ROW : 0) + (footer ? NODE_FOOTER : 0);\n return { width, height };\n}\n","// A ghost node (docs/graph.md#ghostnode): an add on its way, before the app's graph holds the node\n// (docs/ux-rules.md#live-pending-queued-refused, U51, U52). A node type the app registers as `ghost` and places at the\n// point the add was asked; it is drawn dashed in the quiet tone and faint, in the room the node will take (the one\n// geometry formula, nodeBoxSize), and takes no pointer events. Its drawing is hidden from screen readers: the busy\n// button that sent the request says it is on its way. The app removes it when the source answers.\nimport type { Node, NodeProps } from \"@xyflow/react\";\nimport type { ReactNode } from \"react\";\nimport { type NodePorts, nodeBoxSize } from \"../node-box\";\nimport \"./GhostNode.css\";\n\n/** A ghost node's look, as React Flow's node `data`: the words and the shape of the node being added. */\nexport type GhostNodeData = {\n /** The node's name, as it will be (`type 2`); one line, cut with an ellipsis. */\n title: ReactNode;\n /** The second header line in the muted colour (its type). */\n subtitle?: ReactNode;\n /** One row under the header (\"Adding\"); none by default. */\n line?: ReactNode;\n /** The input ports the node will have, so the ghost takes its room; none by default. */\n inputs?: number;\n /** The output ports the node will have; none by default. */\n outputs?: number;\n /** How its ports will be laid out; stacked by default. */\n ports?: NodePorts;\n /** Whether it will have a footer; no by default. */\n footer?: boolean;\n /** Its width in px; `NODE_WIDTH` by default. */\n width?: number;\n};\n\n/** A node drawn by `GhostNode`: register it as `nodeTypes={{ ghost: GhostNode }}`. */\nexport type GhostNodeNode = Node<GhostNodeData, \"ghost\">;\n\n/** The ghost's size in px: `nodeBoxSize` of the node it stands for, its `line` counting as the node's line row. */\nexport function ghostNodeSize(data: GhostNodeData): { width: number; height: number } {\n return nodeBoxSize({\n inputs: data.inputs ?? 0,\n outputs: data.outputs ?? 0,\n ports: data.ports ?? \"stacked\",\n line: data.line !== undefined && data.line !== null,\n footer: data.footer ?? false,\n ...(data.width === undefined ? {} : { width: data.width }),\n });\n}\n\n/** Draws an add's node at its point while the request is on its way. */\nexport function GhostNode({ data }: NodeProps<GhostNodeNode>) {\n const { width, height } = ghostNodeSize(data);\n const line = data.line;\n return (\n <div className=\"pb-ghost-node\" aria-hidden=\"true\" style={{ width: `${width}px`, height: `${height}px` }}>\n <div className=\"pb-ghost-node-header\">\n <div className=\"pb-ghost-node-title\">{data.title}</div>\n {data.subtitle !== undefined && data.subtitle !== null && (\n <div className=\"pb-ghost-node-subtitle\">{data.subtitle}</div>\n )}\n </div>\n {line !== undefined && line !== null && <div className=\"pb-ghost-node-line\">{line}</div>}\n </div>\n );\n}\n","// A ghost wire (docs/graph.md#ghostwire): a request on its way, before the app's graph holds the edge. An edge type the\n// app registers as `ghost`; it draws with React Flow's BaseEdge but has no hit path and takes no pointer events, so it\n// can be neither hovered nor clicked. How long a refused one stays is the app's: it removes the edge.\nimport { BaseEdge, type Edge, EdgeLabelRenderer, type EdgeProps, getBezierPath } from \"@xyflow/react\";\nimport { type ReactNode, useMemo } from \"react\";\nimport \"./GhostWire.css\";\n\n/** `pending` (the default) or `refused`; any other string is drawn in the muted stroke, dashed and dimmed. */\nexport type GhostWireTone = \"pending\" | \"refused\" | (string & {});\n\n/** A ghost wire's look, as React Flow's edge `data`. */\nexport type GhostWireData = {\n /** `pending` (dashed in the quiet tone, dimmed) or `refused` (the error tone). */\n tone?: GhostWireTone;\n /** At the midpoint, on the raised surface; it takes no pointer events. */\n label?: ReactNode;\n};\n\n/** An edge drawn by `GhostWire`: register it as `edgeTypes={{ ghost: GhostWire }}`. */\nexport type GhostWireEdge = Edge<GhostWireData, \"ghost\">;\n\n/** Draws a request's wire between two handles while it is on its way. */\nexport function GhostWire({\n id,\n sourceX,\n sourceY,\n targetX,\n targetY,\n sourcePosition,\n targetPosition,\n data,\n}: EdgeProps<GhostWireEdge>) {\n const [path, labelX, labelY] = useMemo(\n () => getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition }),\n [sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition],\n );\n const tone = data?.tone ?? \"pending\";\n const label = data?.label;\n return (\n <>\n <g className=\"pb-ghost-wire\" data-tone={tone} aria-hidden=\"true\">\n <BaseEdge id={id} path={path} className=\"pb-ghost-wire-path\" interactionWidth={0} />\n </g>\n {label !== undefined && label !== null && (\n <EdgeLabelRenderer>\n <div\n className=\"pb-ghost-wire-label\"\n data-tone={tone}\n style={{ transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)` }}\n >\n {label}\n </div>\n </EdgeLabelRenderer>\n )}\n </>\n );\n}\n","// A level bar on a decibel scale (docs/graph.md#meter). It is painted through refs and never re-renders through\n// React for a level: useLiveValue hands each new value to paint(), which sets CSS variables and data attributes on\n// the element, and requestAnimationFrame runs only while something moves (a new value, a held tick that will fall, a\n// lit clip lamp counting down). Times come from performance.now(), a monotonic clock.\nimport {\n type ComponentPropsWithoutRef,\n type CSSProperties,\n type Ref,\n useCallback,\n useImperativeHandle,\n useLayoutEffect,\n useState,\n} from \"react\";\nimport { type LiveSubscribe, useLiveValue } from \"../../hooks\";\nimport \"./Meter.css\";\n\n/** Which way the bar fills: an open enum, and one it does not know is drawn horizontal. */\nexport type MeterOrientation = \"horizontal\" | \"vertical\" | (string & {});\n\n/** Writes the tooltip from the current peak and RMS in dBFS (`-Infinity` for silence) and whether the lamp is lit. */\nexport type MeterTitle = (peakDb: number, rmsDb: number, clipped: boolean) => string;\n\n/** What a parent can do to a meter through its `ref`. */\nexport type MeterHandle = {\n /** Empties the bar and clears the held peak and the clip lamp, as when the source closes. */\n reset(): void;\n};\n\nexport type MeterProps = Omit<ComponentPropsWithoutRef<\"div\">, \"children\" | \"title\" | \"role\"> & {\n /** Adds a listener that means a new value is ready to read; returns what removes it. */\n subscribe: LiveSubscribe;\n /** The current `[peak, rms]` as linear amplitude, 1.0 being 0 dBFS. Not a number, or 0 and below, is silence. */\n read: () => readonly [peak: number, rms: number];\n /** `horizontal` (the default) or `vertical`. */\n orientation?: MeterOrientation;\n /** dBFS at the bar's empty end; the full end is 0 dBFS. -60 by default. */\n floor?: number;\n /** `[mid, hot]` in dBFS, where the bar turns from `--pb-meter-low` to `--pb-meter-mid` and to `--pb-meter-hot`. */\n zones?: readonly [mid: number, hot: number];\n /** How long the peak tick holds the highest peak, in ms. 1500 by default. */\n holdMs?: number;\n /** How fast the tick then falls toward the current peak, in dB a second. 20 by default. */\n fallDbPerS?: number;\n /** A peak at or above this linear amplitude lights the clip lamp. 1.0 (0 dBFS) by default. */\n clipAt?: number;\n /** How long the lamp stays lit after the last such peak, in ms. 2000 by default. */\n clipHoldMs?: number;\n /** The accessible name: what the meter measures (\"Left output\"). Without it, `labels.name`; the numbers are never announced. */\n label?: string;\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<MeterLabels>;\n /** `reset()`, for when the source closes. */\n ref?: Ref<MeterHandle>;\n};\n\n/** The scale's defaults, each a prop. */\nexport const defaultMeterScale = {\n floor: -60,\n zones: [-18, -6] as const,\n holdMs: 1500,\n fallDbPerS: 20,\n clipAt: 1,\n clipHoldMs: 2000,\n} as const;\n\n/** How often, at most, the tooltip is refreshed while the pointer is over the meter, in ms. */\nexport const meterTitleEveryMs = 250;\n\n/** A linear amplitude in dBFS; not a number, or 0 and below, is silence (`-Infinity`). */\nexport function toDb(linear: number): number {\n return Number.isFinite(linear) && linear > 0 ? 20 * Math.log10(linear) : linear === Infinity ? Infinity : -Infinity;\n}\n\n/** Where a level in dBFS sits on a bar from `floor` (0) to 0 dBFS (1), clamped. */\nexport function meterFraction(db: number, floor: number): number {\n if (Number.isNaN(db) || floor >= 0) return 0;\n return Math.min(1, Math.max(0, (db - floor) / -floor));\n}\n\n/**\n * A level in dBFS as the tooltip writes it: one decimal (\"-12.0\"), and \"−∞\" for silence. An app writing a meter's\n * numbers in words (the inspector) uses it, with `toDb`, so they read as the tooltip's.\n */\nexport function formatMeterDb(db: number): string {\n return db === -Infinity ? \"−∞\" : db.toFixed(1);\n}\n\n/** The English tooltip: \"peak -12.0 dB, rms -18.3 dB\", with −∞ for silence. */\nexport const defaultMeterTitle: MeterTitle = (peakDb, rmsDb) =>\n `peak ${formatMeterDb(peakDb)} dB, rms ${formatMeterDb(rmsDb)} dB`;\n\n/** The meter's own words, each replaceable. */\nexport interface MeterLabels {\n /** The accessible name when the app gives no `label`: \"Level\". */\n name: string;\n /** Writes the tooltip from the level: `defaultMeterTitle`, \"peak -12.0 dB, rms -18.3 dB\". */\n title: MeterTitle;\n}\n\nexport const defaultMeterLabels: MeterLabels = {\n name: \"Level\",\n title: defaultMeterTitle,\n};\n\ntype Level = {\n peakDb: number;\n rmsDb: number;\n /** The tick's level when it was last set, and when; it holds, then falls from there. */\n heldDb: number;\n heldAt: number;\n /** When the last peak at or above `clipAt` came, or -Infinity. */\n clippedAt: number;\n};\n\ntype Scale = Required<Pick<MeterProps, \"floor\" | \"holdMs\" | \"fallDbPerS\" | \"clipAt\" | \"clipHoldMs\">> &\n Pick<MeterLabels, \"title\">;\n\nconst silent = (): Level => ({\n peakDb: -Infinity,\n rmsDb: -Infinity,\n heldDb: -Infinity,\n heldAt: -Infinity,\n clippedAt: -Infinity,\n});\n\n/**\n * The meter's moving parts outside React: the level, the held tick and the lamp, the frame loop and the tooltip.\n * One is made per mounted meter; it paints into whatever element `attach` gave it.\n */\nfunction createPainter(initial: Scale) {\n let element: HTMLElement | null = null;\n let scale = initial;\n let level = silent();\n let frame: number | undefined;\n let hovered = false;\n let titledAt = -Infinity;\n /** A level came since the tooltip was last written. */\n let stale = false;\n\n /** The tick's level at `now`: the held peak, then falling at the set rate, never below the current peak. */\n const tickAt = (now: number) => {\n const falling = Math.max(0, now - level.heldAt - scale.holdMs);\n const fallen = falling === 0 ? level.heldDb : level.heldDb - (Math.max(0, scale.fallDbPerS) * falling) / 1000;\n return Math.max(level.peakDb, fallen);\n };\n\n const writeTitle = (now: number) => {\n if (element === null) return;\n const clipped = now - level.clippedAt < scale.clipHoldMs;\n element.title = scale.title(level.peakDb, level.rmsDb, clipped);\n titledAt = now;\n stale = false;\n };\n\n /** Draws the level at `now`; says whether anything will still move. */\n const paint = (now: number) => {\n if (element === null) return false;\n const tick = tickAt(now);\n const lit = now - level.clippedAt < scale.clipHoldMs;\n element.style.setProperty(\"--pb-meter-level\", String(meterFraction(level.rmsDb, scale.floor)));\n element.style.setProperty(\"--pb-meter-tick\", String(meterFraction(tick, scale.floor)));\n element.dataset[\"peak\"] = tick > scale.floor ? \"shown\" : \"hidden\";\n element.dataset[\"clipped\"] = String(lit);\n if (hovered && now - titledAt >= meterTitleEveryMs) writeTitle(now);\n // Still moving while the tick is above the current peak and the floor (held, or falling), or the lamp is lit; and,\n // while hovered, until the tooltip has caught up with the last level.\n return (tick > level.peakDb && tick > scale.floor) || lit || (hovered && stale);\n };\n\n const run = () => {\n frame = undefined;\n if (paint(performance.now())) frame = requestAnimationFrame(run);\n };\n\n const wake = () => {\n if (frame === undefined && element !== null) frame = requestAnimationFrame(run);\n };\n\n const stop = () => {\n if (frame !== undefined) cancelAnimationFrame(frame);\n frame = undefined;\n };\n\n return {\n attach(next: HTMLElement | null) {\n element = next;\n if (next === null) stop();\n else wake();\n },\n setScale(next: Scale) {\n const moved =\n next.floor !== scale.floor ||\n next.holdMs !== scale.holdMs ||\n next.fallDbPerS !== scale.fallDbPerS ||\n next.clipHoldMs !== scale.clipHoldMs;\n scale = next;\n if (moved) wake();\n },\n take: ([peak, rms]: readonly [number, number]) => {\n const now = performance.now();\n const peakDb = toDb(peak);\n const tick = tickAt(now);\n level.peakDb = peakDb;\n level.rmsDb = toDb(rms);\n if (peakDb >= tick) {\n level.heldDb = peakDb;\n level.heldAt = now;\n }\n if (peak >= scale.clipAt) level.clippedAt = now;\n stale = true;\n wake();\n },\n reset: () => {\n level = silent();\n stop();\n const now = performance.now();\n paint(now);\n if (hovered) writeTitle(now);\n },\n hover(on: boolean) {\n hovered = on;\n if (on) writeTitle(performance.now());\n },\n };\n}\n\nexport function Meter({\n subscribe,\n read,\n orientation = \"horizontal\",\n floor = defaultMeterScale.floor,\n zones = defaultMeterScale.zones,\n holdMs = defaultMeterScale.holdMs,\n fallDbPerS = defaultMeterScale.fallDbPerS,\n clipAt = defaultMeterScale.clipAt,\n clipHoldMs = defaultMeterScale.clipHoldMs,\n label,\n labels,\n ref,\n className,\n style,\n onPointerEnter,\n onPointerLeave,\n ...rest\n}: MeterProps) {\n const { name, title } = { ...defaultMeterLabels, ...labels };\n const [painter] = useState(() => createPainter({ floor, holdMs, fallDbPerS, clipAt, clipHoldMs, title }));\n // Every render hands the painter the scale and words; a new scale redraws the level on it.\n useLayoutEffect(() => {\n painter.setScale({ floor, holdMs, fallDbPerS, clipAt, clipHoldMs, title });\n });\n const attach = useCallback(\n (element: HTMLDivElement | null) => {\n painter.attach(element);\n },\n [painter],\n );\n useLiveValue(subscribe, read, painter.take);\n useImperativeHandle(ref, () => ({ reset: painter.reset }), [painter]);\n\n const [mid, hot] = zones;\n const classes = className === undefined ? \"pb-meter\" : `pb-meter ${className}`;\n const zoneStyle = {\n ...style,\n \"--pb-meter-mid-at\": String(meterFraction(mid, floor)),\n \"--pb-meter-hot-at\": String(meterFraction(hot, floor)),\n } as CSSProperties;\n\n return (\n <div\n {...rest}\n ref={attach}\n className={classes}\n role=\"img\"\n aria-label={label ?? name}\n data-orientation={orientation}\n data-peak=\"hidden\"\n data-clipped=\"false\"\n style={zoneStyle}\n onPointerEnter={(event) => {\n painter.hover(true);\n onPointerEnter?.(event);\n }}\n onPointerLeave={(event) => {\n painter.hover(false);\n onPointerLeave?.(event);\n }}\n >\n <span className=\"pb-meter-track\" aria-hidden=\"true\">\n <span className=\"pb-meter-bar\" />\n <span className=\"pb-meter-peak\" />\n </span>\n <span className=\"pb-meter-lamp\" aria-hidden=\"true\" />\n </div>\n );\n}\n","// A wire (docs/graph.md#wire): an edge type an app registers in edgeTypes, its look from the edge's data. The visible\n// path is React Flow's BaseEdge, so its react-flow__edge-path class and selection stay; the hit path keeps\n// react-flow__edge-interaction and carries the tooltip. The path is rebuilt only when an end moves: the level arrives\n// as --pb-wire-emphasis on the wire's group, so a change of level restyles it without touching the path.\nimport { BaseEdge, type Edge, EdgeLabelRenderer, type EdgeProps, getBezierPath, Position } from \"@xyflow/react\";\nimport { type CSSProperties, memo, type ReactNode, useMemo } from \"react\";\nimport type { PillTone } from \"../../primitives\";\nimport \"./Wire.css\";\n\n/** Pill's tones, the changes and `refused`; any other string is drawn in the muted stroke. */\nexport type WireTone = PillTone | \"added\" | \"removed\" | \"renamed\" | \"changed\" | \"refused\" | (string & {});\n\n/** A wire's look, as React Flow's edge `data`. */\nexport type WireData = {\n /** The stroke's tone; none is React Flow's edge stroke, and one it does not know the muted one. */\n tone?: WireTone;\n /** The signal's level, 0 to 1 (clamped; not a number is 0): thickness and brightness. None is the plain wire. */\n emphasis?: number;\n /** Dashes. A change tone is always dashed, whatever this says. */\n dashed?: boolean;\n /** Dots moving along the wire toward the input; not drawn under reduced motion. */\n flow?: boolean;\n /** An arrowhead at the input end, facing the handle's side. */\n arrow?: boolean;\n /** At the midpoint, on the raised surface; it takes no pointer events. */\n label?: ReactNode;\n /** The wire's tooltip, on its hit path. */\n title?: string;\n};\n\n/** An edge drawn by `Wire`: register it as `edgeTypes={{ wire: Wire }}`. */\nexport type WireEdge = Edge<WireData, \"wire\">;\n\n/** The arrowhead's length along the wire and half its width, in px. */\nconst ARROW_LENGTH = 8;\nconst ARROW_HALF = 4;\n\n/** The change tones: a queued edit, always drawn dashed so it never rests on colour alone. */\nconst CHANGE_TONES: ReadonlySet<string> = new Set([\"added\", \"removed\", \"renamed\", \"changed\"]);\n\n/** A level as the wire draws it: 0 to 1, anything not a number 0. */\nfunction emphasisOf(value: unknown): number {\n if (typeof value !== \"number\" || Number.isNaN(value)) return 0;\n return Math.min(1, Math.max(0, value));\n}\n\n/** A triangle with its tip on the handle, pointing into the node from the side the handle is on. */\nfunction arrowPath(x: number, y: number, side: Position): string {\n // The way back from the tip, away from the node.\n const dx = side === Position.Left ? -1 : side === Position.Right ? 1 : 0;\n const dy = side === Position.Top ? -1 : side === Position.Bottom ? 1 : 0;\n const baseX = x + dx * ARROW_LENGTH;\n const baseY = y + dy * ARROW_LENGTH;\n // Perpendicular to the direction, for the base's two corners.\n const px = -dy * ARROW_HALF;\n const py = dx * ARROW_HALF;\n return `M ${x} ${y} L ${baseX + px} ${baseY + py} L ${baseX - px} ${baseY - py} Z`;\n}\n\ntype WireBodyProps = {\n id: string;\n path: string;\n flow: boolean;\n arrow: string | undefined;\n title: string | undefined;\n interactionWidth: number;\n markerStart: string | undefined;\n markerEnd: string | undefined;\n style: CSSProperties | undefined;\n};\n\n/** The paths, which change only when an end, the flow, the arrow or the tooltip does. */\nconst WireBody = memo(function WireBody({\n id,\n path,\n flow,\n arrow,\n title,\n interactionWidth,\n markerStart,\n markerEnd,\n style,\n}: WireBodyProps) {\n return (\n <>\n <path d={path} fill=\"none\" className=\"pb-wire-focus-ring\" aria-hidden=\"true\" />\n <path d={path} fill=\"none\" className=\"pb-wire-focus-gap\" aria-hidden=\"true\" />\n <BaseEdge\n id={id}\n path={path}\n className=\"pb-wire-path\"\n interactionWidth={0}\n markerStart={markerStart}\n markerEnd={markerEnd}\n style={style}\n />\n {flow && <path d={path} fill=\"none\" className=\"pb-wire-flow\" aria-hidden=\"true\" />}\n {arrow !== undefined && <path d={arrow} className=\"pb-wire-arrow\" aria-hidden=\"true\" />}\n {interactionWidth > 0 && (\n <path\n d={path}\n fill=\"none\"\n strokeOpacity={0}\n strokeWidth={interactionWidth}\n className=\"react-flow__edge-interaction\"\n >\n {title !== undefined && <title>{title}</title>}\n </path>\n )}\n </>\n );\n});\n\n/** Draws a wire between two handles: its tone, level, dashes, flow, arrow, label and tooltip from the edge's data. */\nexport function Wire({\n id,\n sourceX,\n sourceY,\n targetX,\n targetY,\n sourcePosition,\n targetPosition,\n data,\n selected,\n interactionWidth = 20,\n markerStart,\n markerEnd,\n style,\n}: EdgeProps<WireEdge>) {\n const [path, labelX, labelY] = useMemo(\n () => getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition }),\n [sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition],\n );\n const showArrow = data?.arrow === true;\n const arrow = useMemo(\n () => (showArrow ? arrowPath(targetX, targetY, targetPosition) : undefined),\n [showArrow, targetX, targetY, targetPosition],\n );\n const emphasis = data?.emphasis === undefined ? undefined : emphasisOf(data.emphasis);\n const level = emphasis === undefined ? undefined : ({ \"--pb-wire-emphasis\": emphasis } as CSSProperties);\n const label = data?.label;\n const dashed = data?.dashed === true || (data?.tone !== undefined && CHANGE_TONES.has(data.tone));\n return (\n <>\n <g\n className=\"pb-wire\"\n data-tone={data?.tone}\n data-selected={selected === true ? \"\" : undefined}\n data-dashed={dashed ? \"\" : undefined}\n data-emphasis={emphasis === undefined ? undefined : \"\"}\n style={level}\n >\n <WireBody\n id={id}\n path={path}\n flow={data?.flow === true}\n arrow={arrow}\n title={data?.title}\n interactionWidth={interactionWidth}\n markerStart={markerStart}\n markerEnd={markerEnd}\n style={style}\n />\n </g>\n {label !== undefined && label !== null && (\n <EdgeLabelRenderer>\n <div\n className=\"pb-wire-label\"\n data-tone={data?.tone}\n style={{ transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)` }}\n >\n {label}\n </div>\n </EdgeLabelRenderer>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;AAkCA,IAAMO,KAAU,MACdC,aAAkB,WAAWA,EAAO,UAAU,SAAS,kBAAkB;AAG3E,SAASC,GAAM,GAAiE;CAC9E,IAAI,oBAAoBC,GAAO;EAC7B,IAAMC,IAAQD,EAAM,eAAe;EACnC,OAAOC,MAAU,KAAA,IAAY,OAAO;GAAE,GAAGA,EAAM;GAAS,GAAGA,EAAM;EAAQ;CAC3E;CACA,OAAO;EAAE,GAAGD,EAAM;EAAS,GAAGA,EAAM;CAAQ;AAC9C;AAGA,IAAME,MAAa,EAAE,MAAG,WACtB,OAAO,SAAS,oBAAqB,aAAa,SAAS,iBAAiBC,GAAGC,CAAC,IAAI;AAOtF,SAAgBC,GAAS,GAAkB,IAAwB,CAAC,GAAkC;CACpG,IAAMC,IAAUC,EAAQ,WAAW,IAC7B,EAAE,4BAAyBC,EAAa,GACxCC,IAASC,EAAO;EAAE;EAAS;EAAS;CAAqB,CAAC;CAChE,QAAsB;EACpB,EAAO,UAAU;GAAE;GAAS;GAAS;EAAqB;CAC5D,CAAC;CAED,IAAMC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