{"version":3,"file":"ConnectionPuck.js","names":[],"sources":["jsx/react-flow/ConnectionPuck.js"],"sourcesContent":["import { transitionProps, useResolvedKnobs } from \"@multiplatform.one/theme\";\nimport { SizableText, XStack } from \"tamagui\";\nimport { isLegalTarget } from \"../interaction/legalTargets\";\nimport { resolvePorts } from \"../model/index\";\nimport { useStore } from \"./xy\";\nimport { jsx } from \"react/jsx-runtime\";\nconst keySeparator = \"\\0\";\nfunction portOf(document, schema, ref) {\n  const node = document.nodes.find((candidate) => candidate.id === ref.node);\n  if (!node) return void 0;\n  return resolvePorts(schema, node).find((candidate) => candidate.id === ref.port);\n}\nfunction splitKey(key) {\n  const at = key.indexOf(keySeparator);\n  return { node: key.slice(0, at), port: key.slice(at + 1) };\n}\nfunction connectionPuckLabel(opts) {\n  const { document, schema, source, candidate, nodeLabel } = opts;\n  if (!source) return null;\n  const legal = candidate ? isLegalTarget({ document, schema, source, target: candidate }) : false;\n  const name = (ref) => {\n    const spec = portOf(document, schema, ref);\n    return `${nodeLabel?.(ref.node) ?? ref.node} / ${spec?.label ?? ref.port}`;\n  };\n  return {\n    legal,\n    target: legal && candidate ? `${candidate.node}:${candidate.port}` : \"\",\n    // An illegal candidate falls back to naming the SOURCE rather than going\n    // blank: a puck that disappears the moment the finger drifts over a\n    // refused port reads as a broken overlay, not as a refusal.\n    text: legal && candidate ? name(candidate) : `from ${name(source)}`\n  };\n}\nfunction ConnectionPuck({\n  document,\n  schema,\n  nodeLabel,\n  intent\n}) {\n  const { knobProps } = useResolvedKnobs({ component: \"ConnectionPuck\", intent });\n  const fromKey = useStore(\n    (state) => state.connection.inProgress ? `${state.connection.fromHandle.nodeId}${keySeparator}${state.connection.fromHandle.id ?? \"\"}` : null\n  );\n  const toKey = useStore(\n    (state) => state.connection.inProgress && state.connection.toHandle ? `${state.connection.toHandle.nodeId}${keySeparator}${state.connection.toHandle.id ?? \"\"}` : null\n  );\n  const label = connectionPuckLabel({\n    document,\n    schema,\n    source: fromKey ? splitKey(fromKey) : null,\n    candidate: toKey ? splitKey(toKey) : null,\n    nodeLabel\n  });\n  if (!label) return null;\n  return /* @__PURE__ */ jsx(\n    XStack,\n    {\n      position: \"absolute\",\n      top: \"3\",\n      left: \"50%\",\n      transform: \"translateX(-50%)\",\n      zIndex: 5,\n      pointerEvents: \"none\",\n      ...knobProps.elevatedSurface,\n      ...knobProps.containerRadius,\n      ...knobProps.panelPadding,\n      ...knobProps.gap,\n      ...knobProps.elevationChrome,\n      alignItems: \"center\",\n      opacity: label.legal ? 1 : 0.7,\n      ...transitionProps(knobProps.motion.overlay),\n      \"data-graph-connection-puck\": \"\",\n      \"data-graph-puck-target\": label.target,\n      \"data-graph-puck-legal\": String(label.legal),\n      children: /* @__PURE__ */ jsx(SizableText, { ...knobProps.label, numberOfLines: 1, children: label.text })\n    }\n  );\n}\nexport {\n  ConnectionPuck,\n  connectionPuckLabel\n};\n//# sourceMappingURL=ConnectionPuck.js.map\n"],"mappings":";;;;;;;;AAMA,MAAM,eAAe;AACrB,SAAS,OAAO,UAAU,QAAQ,KAAK;CACrC,MAAM,OAAO,SAAS,MAAM,MAAM,cAAc,UAAU,OAAO,IAAI,IAAI;CACzE,IAAI,CAAC,MAAM,OAAO,KAAK;CACvB,OAAO,aAAa,QAAQ,IAAI,CAAC,CAAC,MAAM,cAAc,UAAU,OAAO,IAAI,IAAI;AACjF;AACA,SAAS,SAAS,KAAK;CACrB,MAAM,KAAK,IAAI,QAAQ,YAAY;CACnC,OAAO;EAAE,MAAM,IAAI,MAAM,GAAG,EAAE;EAAG,MAAM,IAAI,MAAM,KAAK,CAAC;CAAE;AAC3D;AACA,SAAS,oBAAoB,MAAM;CACjC,MAAM,EAAE,UAAU,QAAQ,QAAQ,WAAW,cAAc;CAC3D,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,QAAQ,YAAY,cAAc;EAAE;EAAU;EAAQ;EAAQ,QAAQ;CAAU,CAAC,IAAI;CAC3F,MAAM,QAAQ,QAAQ;EACpB,MAAM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