{"version":3,"file":"GraphNode.js","names":[],"sources":["jsx/nodes/GraphNode.js"],"sourcesContent":["import {\n  composeKnobs,\n  panelPaddingPx,\n  pickStates,\n  transitionProps\n} from \"@multiplatform.one/theme\";\nimport { useEffect, useRef } from \"react\";\nimport { useGraphNodeKnobs } from \"../knobs/graphKnobs\";\nimport { SizableText, View, XStack, YStack } from \"tamagui\";\nimport { useUpdateNodeInternals } from \"../react-flow/xy\";\nimport { detailOpacity, isOverview } from \"./lod\";\nimport {\n  containerRadiusPx,\n  graphNodeMinHeight,\n  graphNodeWidth,\n  portSpacing,\n  graphNodeSize\n} from \"./nodeMeasure\";\nimport { jsx, jsxs } from \"react/jsx-runtime\";\nfunction sidePortOverhang(side, framePaddingPx) {\n  return side === \"right\" ? { right: -framePaddingPx } : { left: -framePaddingPx };\n}\nfunction usePortInternals(id, ports) {\n  const updateNodeInternals = useUpdateNodeInternals();\n  const first = useRef(true);\n  useEffect(() => {\n    if (first.current) {\n      first.current = false;\n      return;\n    }\n    updateNodeInternals(id);\n  }, [id, ports, updateNodeInternals]);\n}\nfunction GraphNode({\n  id,\n  title,\n  subtitle,\n  ports,\n  intent,\n  selected = false,\n  dragging = false,\n  measure,\n  renderMode = \"detail\",\n  coarsePointer = false,\n  renderPort,\n  children\n}) {\n  const { knobProps, control } = useGraphNodeKnobs({ intent, selected, dragging });\n  usePortInternals(id, ports);\n  const size = graphNodeSize(knobProps.sizeToken);\n  const portSpacingPx = portSpacing({ coarsePointer });\n  const framePaddingPx = panelPaddingPx();\n  const width = graphNodeWidth({ size, measure });\n  const minHeight = graphNodeMinHeight({ size, ports: ports ?? [], portSpacingPx, measure });\n  const radiusPx = containerRadiusPx(knobProps.containerRadius.borderRadius);\n  const overview = isOverview(renderMode);\n  const fade = detailOpacity(renderMode);\n  return /* @__PURE__ */ jsxs(\n    YStack,\n    {\n      \"data-graph-node\": id,\n      \"data-graph-node-radius\": String(radiusPx),\n      \"data-graph-node-width\": String(width),\n      \"data-graph-node-render-mode\": renderMode,\n      \"data-graph-node-port-spacing\": String(portSpacingPx),\n      ...composeKnobs(\n        knobProps.surface,\n        knobProps.containerRadius,\n        knobProps.panelPadding,\n        knobProps.gap,\n        knobProps.elevationChrome,\n        pickStates(control, \"hover\", \"press\", \"focus-visible\")\n      ),\n      width,\n      minHeight,\n      position: \"relative\",\n      overflow: \"visible\",\n      opacity: dragging ? 0.85 : 1,\n      ...transitionProps(knobProps.motion.control, [\"borderRadius\", \"borderWidth\"]),\n      children: [\n        /* @__PURE__ */ jsxs(XStack, { ...knobProps.gap, alignItems: \"center\", justifyContent: \"space-between\", children: [\n          /* @__PURE__ */ jsx(SizableText, { ...knobProps.label, numberOfLines: 1, \"data-graph-node-title\": \"\", children: title }),\n          selected ? /* @__PURE__ */ jsx(YStack, { \"data-graph-node-selected\": \"\" }) : null\n        ] }),\n        subtitle ? /* @__PURE__ */ jsx(\n          SizableText,\n          {\n            ...knobProps.body,\n            ...knobProps.label,\n            numberOfLines: 2,\n            opacity: 0.75 * fade,\n            children: subtitle\n          }\n        ) : null,\n        ports?.length ? /* @__PURE__ */ jsx(\n          YStack,\n          {\n            \"data-graph-node-ports\": \"\",\n            gap: 0,\n            opacity: fade,\n            pointerEvents: overview ? \"none\" : \"auto\",\n            children: ports.map((port) => /* @__PURE__ */ jsxs(\n              XStack,\n              {\n                \"data-graph-node-port-row\": port.id,\n                \"data-graph-node-port-side\": port.side,\n                height: portSpacingPx,\n                alignItems: \"center\",\n                justifyContent: port.side === \"right\" ? \"flex-end\" : \"flex-start\",\n                position: \"relative\",\n                overflow: \"visible\",\n                children: [\n                  renderPort && (port.side === \"top\" || port.side === \"bottom\") ? renderPort(port) : null,\n                  renderPort && (port.side === \"left\" || port.side === \"right\") ? /* @__PURE__ */ jsx(\n                    View,\n                    {\n                      \"data-graph-node-port-anchor\": port.side,\n                      position: \"absolute\",\n                      top: 0,\n                      bottom: 0,\n                      width: 0,\n                      ...sidePortOverhang(port.side, framePaddingPx),\n                      overflow: \"visible\",\n                      children: renderPort(port)\n                    }\n                  ) : null,\n                  /* @__PURE__ */ jsx(SizableText, { ...knobProps.body, ...knobProps.label, numberOfLines: 1, children: port.label ?? port.id })\n                ]\n              },\n              port.id\n            ))\n          }\n        ) : null,\n        children ? /* @__PURE__ */ jsx(\n          YStack,\n          {\n            \"data-graph-node-children\": \"\",\n            opacity: fade,\n            pointerEvents: overview ? \"none\" : \"auto\",\n            children\n          }\n        ) : null\n      ]\n    }\n  );\n}\nexport {\n  GraphNode\n};\n//# sourceMappingURL=GraphNode.js.map\n"],"mappings":";;;;;;;;;;AAmBA,SAAS,iBAAiB,MAAM,gBAAgB;CAC9C,OAAO,SAAS,UAAU,EAAE,OAAO,CAAC,eAAe,IAAI,EAAE,MAAM,CAAC,eAAe;AACjF;AACA,SAAS,iBAAiB,IAAI,OAAO;CACnC,MAAM,sBAAsB,uBAAuB;CACnD,MAAM,QAAQ,OAAO,IAAI;CACzB,gBAAgB;EACd,IAAI,MAAM,SAAS;GACjB,MAAM,UAAU;GAChB;EACF;EACA,oBAAoB,EAAE;CACxB,GAAG;EAAC;EAAI;EAAO;CAAmB,CAAC;AACrC;AACA,SAAS,UAAU,EACjB,IACA,OACA,UACA,OACA,QACA,WAAW,OACX,WAAW,OACX,SACA,aAAa,UACb,gBAAgB,OAChB,YACA,YACC;CACD,MAAM,EAAE,WAAW,YAAY,kBAAkB;EAAE;EAAQ;EAAU;CAAS,CAAC;CAC/E,iBAAiB,IAAI,KAAK;CAC1B,MAAM,OAAO,cAAc,UAAU,SAAS;CAC9C,MAAM,gBAAgB,YAAY,EAAE,cAAc,CAAC;CACnD,MAAM,iBAAiB,eAAe;CACtC,MAAM,QAAQ,eAAe;EAAE;EAAM;CAAQ,CAAC;CAC9C,MAAM,YAAY,mBAAmB;EAAE;EAAM,OAAO,SAAS,CAAC;EAAG;EAAe;CAAQ,CAAC;CACzF,MAAM,WAAW,kBAAkB,UAAU,gBAAgB,YAAY;CACzE,MAAM,WAAW,WAAW,UA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