{"version":3,"file":"flowAdapter.js","names":[],"sources":["esm/react-flow/flowAdapter.js"],"sourcesContent":["import { nodeKindSpec, resolvePorts } from \"../model/index\";\nimport { graphEdgeType } from \"../edges/GraphEdge\";\nimport { graphNodeMeasure } from \"../nodes/nodeMeasure\";\nfunction toFlowNodes(document, schema, options) {\n  return document.nodes.map((node) => flowNode(node, schema, options));\n}\nfunction flowNode(node, schema, options) {\n  const spec = nodeKindSpec(schema, node.kind);\n  const ports = resolvePorts(schema, node);\n  const measured = graphNodeMeasure({\n    size: options.size,\n    // `PortSpec` is structurally the `GraphNodePort` the measure table reads:\n    // it adds `index`, `dataType` and `arity`, none of which move a number.\n    ports,\n    portSpacingPx: options.portSpacingPx,\n    measure: spec?.measure\n  });\n  return {\n    id: node.id,\n    type: options.nodeType,\n    position: node.position,\n    // `initialWidth` / `initialHeight`, NOT `width` / `height`.\n    //\n    // Measured in Chrome on `NodeGraph/NodeGraph → Main`: React Flow treats\n    // `width` / `height` as USER-SET dimensions and writes them as a hard CSS\n    // size, so a 72 px seed CLAMPED every node to 72 px and the Tamagui body —\n    // which is `overflow: visible` by §7.1 H6 — painted right through the\n    // bottom of its own frame and out of the pane. `initialWidth` is the\n    // dimension React Flow uses only until its ResizeObserver reports a real\n    // one, which is exactly design §5's \"the observer corrects rather than\n    // discovers\". A node the DOCUMENT sizes is a different thing: that is a\n    // user-set dimension and it stays `width` / `height`.\n    initialWidth: measured.width,\n    initialHeight: measured.minHeight,\n    width: node.size?.width,\n    height: node.size?.height,\n    parentId: node.parent,\n    draggable: node.locked ? false : void 0,\n    data: {\n      kind: node.kind,\n      data: node.data,\n      ports,\n      intent: spec?.intent,\n      locked: node.locked\n    }\n  };\n}\nfunction toFlowEdges(document, schema) {\n  return document.edges.map((edge) => flowEdge(edge, schema));\n}\nfunction flowEdge(edge, schema) {\n  const spec = schema.edges[edge.kind];\n  const appearance = spec?.appearance;\n  return {\n    id: edge.id,\n    // ONE registered type, switching on the model kind internally (design §4.4).\n    type: graphEdgeType,\n    source: edge.source.node,\n    sourceHandle: edge.source.port,\n    target: edge.target.node,\n    targetHandle: edge.target.port,\n    data: { kind: edge.kind, appearance, label: edge.label }\n  };\n}\nfunction preserveFlowState(next, previous) {\n  if (previous.length === 0) return next;\n  const before = new Map(previous.map((node) => [node.id, node]));\n  return next.map((node) => {\n    const prior = before.get(node.id);\n    if (!prior) return node;\n    return {\n      ...node,\n      selected: prior.selected,\n      dragging: prior.dragging,\n      // A measured node keeps its measurement. The seed is a starting guess,\n      // and handing the guess back on every commit makes the observer\n      // re-measure the whole canvas each time anything is edited.\n      measured: prior.measured,\n      initialWidth: prior.measured?.width ?? node.initialWidth,\n      initialHeight: prior.measured?.height ?? node.initialHeight\n    };\n  });\n}\nexport {\n  preserveFlowState,\n  toFlowEdges,\n  toFlowNodes\n};\n//# sourceMappingURL=flowAdapter.js.map\n"],"mappings":";;;;;AAGA,SAAS,YAAY,UAAU,QAAQ,SAAS;CAC9C,OAAO,SAAS,MAAM,KAAK,SAAS,SAAS,MAAM,QAAQ,OAAO,CAAC;AACrE;AACA,SAAS,SAAS,MAAM,QAAQ,SAAS;CACvC,MAAM,OAAO,aAAa,QAAQ,KAAK,IAAI;CAC3C,MAAM,QAAQ,aAAa,QAAQ,IAAI;CACvC,MAAM,WAAW,iBAAiB;EAChC,MAAM,QAAQ;EAGd;EACA,eAAe,QAAQ;EACvB,SAAS,MAAM;CACjB,CAAC;CACD,OAAO;EACL,IAAI,KAAK;EACT,MAAM,QAAQ;EACd,UAAU,KAAK;EAYf,cAAc,SAAS;EACvB,eAAe,SAAS;EACxB,OAAO,KAAK,MAAM;EAClB,QAAQ,KAAK,MAAM;EACnB,UAAU,KAAK;EACf,WAAW,KAAK,SAAS,QAAQ,KAAK;EACtC,MAAM;GACJ,MAAM,KAAK;GACX,MAAM,KAAK;GACX;GACA,QAAQ,MAAM;GACd,QAAQ,KAAK;EACf;CACF;AACF;AACA,SAAS,YAAY,UAAU,QAAQ;CACrC,OAAO,SA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