{"version":3,"file":"graphVars.js","names":[],"sources":["esm/theme/graphVars.js"],"sourcesContent":["import {\n  MIN_PRESS_TARGET,\n  hairlineWidth,\n  cssAnimationConfig\n} from \"@multiplatform.one/theme\";\nimport { edgeStrokeWidths } from \"../edges/edgeStyle\";\nimport { graphNodeSize } from \"../nodes/nodeMeasure\";\nconst xyVarAllowlist = {\n  \"--xy-node-background-color\": \"binds only to .react-flow__node-input/-default/-output/-group; a Tamagui GraphNode carries none of those classes and takes its fill from the knobProps spread\",\n  \"--xy-node-border\": \"same four built-in node classes; a GraphNode's border comes from knobProps.controlBorderOutlined / .surface\",\n  \"--xy-node-border-radius\": \"same four built-in node classes; a GraphNode's radius rides the CONTAINER-CAP law in graphNode.ts\",\n  \"--xy-node-color\": \"same four built-in node classes; a GraphNode's text colour comes from knobProps.body\",\n  \"--xy-node-boxshadow-hover\": \"same four built-in node classes, hover only; a GraphNode's elevation comes from knobProps.elevationChrome\",\n  \"--xy-node-boxshadow-selected\": \"same four built-in node classes, selected only; selection chrome is painted by GraphNode itself\",\n  \"--xy-node-group-background-color\": \"binds only to .react-flow__node-group; this package registers no group node type\"\n};\nconst spaceTokenPx = {\n  \"0\": 0,\n  \"1\": 2,\n  \"2\": 7,\n  \"3\": 13,\n  \"4\": 18,\n  \"5\": 24,\n  \"6\": 32\n};\nconst graphTransitionCss = Object.fromEntries(\n  Object.entries(cssAnimationConfig).map(([name, timing]) => [name, `opacity ${timing}`])\n);\nconst handlePaintedPx = {\n  small: 8,\n  medium: 10,\n  large: 12\n};\nfunction clamp255(value) {\n  return Math.max(0, Math.min(255, Math.round(value)));\n}\nfunction roundAlpha(value) {\n  return Math.round(Math.max(0, Math.min(1, value)) * 1e3) / 1e3;\n}\nfunction withAlpha(color2, alpha) {\n  if (!color2) return void 0;\n  const text = color2.trim();\n  const a = roundAlpha(alpha);\n  const hex = /^#([0-9a-fA-F]{3,8})$/.exec(text);\n  if (hex) {\n    const digits = hex[1];\n    let r;\n    let g;\n    let b;\n    if (digits.length === 3 || digits.length === 4) {\n      r = Number.parseInt(digits[0] + digits[0], 16);\n      g = Number.parseInt(digits[1] + digits[1], 16);\n      b = Number.parseInt(digits[2] + digits[2], 16);\n    } else if (digits.length === 6 || digits.length === 8) {\n      r = Number.parseInt(digits.slice(0, 2), 16);\n      g = Number.parseInt(digits.slice(2, 4), 16);\n      b = Number.parseInt(digits.slice(4, 6), 16);\n    } else {\n      return void 0;\n    }\n    return `rgba(${clamp255(r)}, ${clamp255(g)}, ${clamp255(b)}, ${a})`;\n  }\n  const rgb = /^rgba?\\(([^)]+)\\)$/.exec(text);\n  if (rgb) {\n    const parts = rgb[1].split(/[\\s,/]+/).filter(Boolean);\n    if (parts.length < 3) return void 0;\n    return `rgba(${parts[0]}, ${parts[1]}, ${parts[2]}, ${a})`;\n  }\n  const hsl = /^hsla?\\(([^)]+)\\)$/.exec(text);\n  if (hsl) {\n    const parts = hsl[1].split(/[,/]+/).map((part) => part.trim()).filter(Boolean);\n    if (parts.length < 3) return void 0;\n    return `hsla(${parts[0]}, ${parts[1]}, ${parts[2]}, ${a})`;\n  }\n  return void 0;\n}\nfunction toCss(value, theme) {\n  if (!value) return void 0;\n  return theme.css(value.startsWith(\"$\") ? value.slice(1) : value) ?? value;\n}\nfunction warnOnce(message) {\n  if (process.env.NODE_ENV === \"production\") return;\n  console.warn(`[@multiplatform.one/node-graph] ${message}`);\n}\nconst shadowTokenRef = /\\$[\\w.-]+/g;\nfunction elevationBoxShadow(resolved, theme) {\n  const { boxShadow } = resolved.knobProps.elevationChrome;\n  if (!boxShadow) return { css: \"none\", colors: [] };\n  const colors = [];\n  let unresolved;\n  const css = boxShadow.replaceAll(shadowTokenRef, (token) => {\n    const reference = theme.css(token.slice(1));\n    if (!reference) {\n      unresolved ??= token;\n      return token;\n    }\n    colors.push(reference);\n    return reference;\n  });\n  if (unresolved) {\n    warnOnce(\n      `elevation shadow colour ${JSON.stringify(unresolved)} is not a key this theme carries, so --xy-controls-box-shadow falls back to none`\n    );\n    return { css: \"none\", colors: [] };\n  }\n  return { css, colors };\n}\nfunction color(value, fallback) {\n  return { kind: \"color\", color: value ?? fallback };\n}\nfunction graphVarValues(resolved, theme, options) {\n  const { knobProps, control, text } = resolved;\n  const themeColor = (key, fallback = \"currentColor\") => theme.css(key) ?? fallback;\n  const outline = themeColor(\"outline-color\", themeColor(\"border-color\"));\n  const bodyColor = toCss(knobProps.body.color, theme) ?? themeColor(\"color\");\n  const hoverBackground = toCss(control.backgroundColor?.hover, theme);\n  const hoverColor = toCss(text.color?.hover, theme);\n  const edgeStrokeWidth = edgeStrokeWidths[knobProps.borderWidthStop];\n  const selectionFill = withAlpha(theme.raw(\"outline-color\") ?? theme.raw(\"border-color\"), 0.12);\n  const maskFill = withAlpha(theme.raw(\"color-1\"), 0.7);\n  const shadow = elevationBoxShadow(resolved, theme);\n  const handlePainted = handlePaintedPx[graphNodeSize(knobProps.sizeToken)] ?? 10;\n  const handleHit = options?.pointer === \"fine\" ? Math.max(handlePainted, 24) : MIN_PRESS_TARGET;\n  const nodeGap = spaceTokenPx[knobProps.gap.gap] ?? 18;\n  const nodePadding = spaceTokenPx[knobProps.panelPadding.padding] ?? 18;\n  return {\n    // ── edges ──\n    \"--xy-edge-stroke\": color(theme.css(\"color-9\"), \"currentColor\"),\n    \"--xy-edge-stroke-selected\": { kind: \"color\", color: outline },\n    \"--xy-edge-stroke-width\": { kind: \"length\", px: edgeStrokeWidth },\n    \"--xy-connectionline-stroke\": { kind: \"color\", color: outline },\n    \"--xy-connectionline-stroke-width\": { kind: \"length\", px: edgeStrokeWidth + 1 },\n    \"--xy-edge-label-background-color\": color(\n      toCss(knobProps.cardSurface.backgroundColor, theme),\n      themeColor(\"color-1\")\n    ),\n    \"--xy-edge-label-color\": { kind: \"color\", color: bodyColor },\n    // ── handles ──\n    \"--xy-handle-background-color\": color(theme.css(\"color-1\"), \"transparent\"),\n    \"--xy-handle-border-color\": color(theme.css(\"color-8\"), themeColor(\"border-color\")),\n    // ── selection ──\n    \"--xy-selection-background-color\": color(selectionFill, \"transparent\"),\n    \"--xy-selection-border\": {\n      kind: \"composite\",\n      css: `1px dashed ${outline}`,\n      colors: [outline]\n    },\n    // ── canvas ──\n    \"--xy-background-color\": color(\n      toCss(knobProps.surface.backgroundColor, theme),\n      themeColor(\"color-1\")\n    ),\n    \"--xy-background-pattern-color\": color(theme.css(\"color-4\"), themeColor(\"border-color\")),\n    // ── minimap ──\n    \"--xy-minimap-background-color\": color(\n      toCss(knobProps.elevatedSurface.backgroundColor, theme),\n      themeColor(\"color-1\")\n    ),\n    \"--xy-minimap-node-background-color\": color(theme.css(\"color-6\"), themeColor(\"border-color\")),\n    \"--xy-minimap-node-stroke-color\": color(theme.css(\"border-color\"), \"currentColor\"),\n    \"--xy-minimap-node-stroke-width\": { kind: \"length\", px: knobProps.surface.borderWidth },\n    \"--xy-minimap-mask-background-color\": color(maskFill, \"transparent\"),\n    \"--xy-minimap-mask-stroke-color\": { kind: \"color\", color: outline },\n    \"--xy-minimap-mask-stroke-width\": { kind: \"length\", px: hairlineWidth },\n    // ── controls ──\n    \"--xy-controls-button-background-color\": color(\n      toCss(knobProps.elevatedSurface.backgroundColor, theme),\n      themeColor(\"color-1\")\n    ),\n    \"--xy-controls-button-background-color-hover\": color(\n      hoverBackground ?? theme.css(\"color-4\"),\n      themeColor(\"border-color\")\n    ),\n    \"--xy-controls-button-color\": { kind: \"color\", color: bodyColor },\n    \"--xy-controls-button-color-hover\": { kind: \"color\", color: hoverColor ?? bodyColor },\n    \"--xy-controls-button-border-color\": color(\n      toCss(knobProps.elevatedSurface.borderColor, theme) ?? theme.css(\"border-color\"),\n      \"currentColor\"\n    ),\n    \"--xy-controls-box-shadow\": { kind: \"composite\", css: shadow.css, colors: shadow.colors },\n    // ── attribution / resize ──\n    \"--xy-attribution-background-color\": { kind: \"color\", color: \"transparent\" },\n    \"--xy-resize-background-color\": { kind: \"color\", color: outline },\n    // ── the mpo-owned layer, for what React Flow has no variable for ──\n    \"--mpo-graph-handle-size\": { kind: \"length\", px: handlePainted },\n    \"--mpo-graph-handle-hit\": { kind: \"length\", px: handleHit },\n    \"--mpo-graph-guide-color\": { kind: \"color\", color: outline },\n    // hairlineWidth, NOT divided by pixelRatio: CSS px inside a WebView are\n    // already density-independent, and dividing would ask for a 0.167 px line\n    // on a 3x phone. A guide is a divider, which is what the token is for.\n    \"--mpo-graph-guide-width\": { kind: \"length\", px: hairlineWidth },\n    \"--mpo-graph-node-gap\": { kind: \"length\", px: nodeGap },\n    \"--mpo-graph-node-padding\": { kind: \"length\", px: nodePadding },\n    \"--mpo-graph-port-spacing\": { kind: \"length\", px: Math.max(handleHit, nodeGap) },\n    \"--mpo-graph-transition\": {\n      kind: \"composite\",\n      css: knobProps.motion.control.transition ? graphTransitionCss[String(knobProps.motion.control.transition)] ?? \"none\" : \"none\",\n      colors: []\n    }\n  };\n}\nfunction graphVarCss(value) {\n  switch (value.kind) {\n    case \"color\":\n      return value.color;\n    case \"length\":\n      return `${value.px}px`;\n    default:\n      return value.css;\n  }\n}\nfunction graphCssVars(resolved, theme, options) {\n  const out = {};\n  for (const [name, value] of Object.entries(graphVarValues(resolved, theme, options))) {\n    out[name] = graphVarCss(value);\n  }\n  return out;\n}\nexport {\n  elevationBoxShadow,\n  graphCssVars,\n  graphTransitionCss,\n  graphVarCss,\n  graphVarValues,\n  handlePaintedPx,\n  spaceTokenPx,\n  withAlpha,\n  xyVarAllowlist\n};\n//# sourceMappingURL=graphVars.js.map\n"],"mappings":";;;;;AAOA,MAAM,iBAAiB;CACrB,8BAA8B;CAC9B,oBAAoB;CACpB,2BAA2B;CAC3B,mBAAmB;CACnB,6BAA6B;CAC7B,gCAAgC;CAChC,oCAAoC;AACtC;AACA,MAAM,eAAe;CACnB,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACP;AACA,MAAM,qBAAqB,OAAO,YAChC,OAAO,QAAQ,kBAAkB,CAAC,CAA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