{"version":3,"file":"CodeToFlowchart-3OF-wAs8.js","sources":["../../components/features/CodeToFlowchart.tsx"],"sourcesContent":["\nimport React, { useState, useCallback, useEffect } from 'react';\nimport { generateFlowchart } from '../../services/geminiService';\nimport { MapIcon } from '../icons/FeatureIcons';\nimport { LoadingSpinner } from './shared/LoadingSpinner';\nimport mermaid from 'mermaid';\n\nmermaid.initialize({\n startOnLoad: false,\n theme: 'dark',\n darkMode: true,\n securityLevel: 'loose',\n themeVariables: {\n background: '#1e293b', // slate-800\n primaryColor: '#334155', // slate-700\n primaryTextColor: '#cbd5e1', // slate-300\n lineColor: '#64748b', // slate-500\n textColor: '#cbd5e1',\n },\n});\n\nconst exampleCode = `function checkNumber(num) {\n if (num > 0) {\n return \"Positive\";\n } else if (num < 0) {\n return \"Negative\";\n } else {\n return \"Zero\";\n }\n}`;\n\nexport const CodeToFlowchart: React.FC = () => {\n const [code, setCode] = useState(exampleCode);\n const [mermaidCode, setMermaidCode] = useState('');\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState('');\n const chartRef = React.useRef(null);\n\n const handleGenerate = useCallback(async () => {\n if (!code.trim()) {\n setError('Please enter some code.');\n return;\n }\n setIsLoading(true);\n setError('');\n setMermaidCode('');\n if(chartRef.current) chartRef.current.innerHTML = '';\n\n try {\n const result = await generateFlowchart(code);\n setMermaidCode(result.mermaidCode);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred.';\n setError(`Failed to generate flowchart: ${errorMessage}`);\n } finally {\n setIsLoading(false);\n }\n }, [code]);\n \n useEffect(() => {\n if (mermaidCode && chartRef.current) {\n try {\n mermaid.render('mermaid-chart', mermaidCode).then(({ svg }) => {\n if (chartRef.current) {\n chartRef.current.innerHTML = svg;\n }\n });\n } catch (e) {\n if (e instanceof Error) setError(`Mermaid render error: ${e.message}`);\n console.error(e);\n }\n }\n }, [mermaidCode]);\n\n return (\n
\n
\n

\n \n Code to Flowchart\n

\n

Turn your code's logic into a visual flowchart with AI.

\n
\n
\n
\n \n setCode(e.target.value)}\n className=\"flex-grow p-4 bg-slate-900 border border-slate-700 rounded-md resize-none font-mono text-sm\"\n />\n \n {isLoading ? : 'Generate Flowchart'}\n \n
\n
\n \n
\n {isLoading && }\n {error &&

{error}

}\n
\n {!isLoading && !mermaidCode && !error &&
Flowchart will appear here.
}\n
\n
\n
\n
\n );\n};\n"],"names":["mermaid","exampleCode","CodeToFlowchart","code","setCode","useState","mermaidCode","setMermaidCode","isLoading","setIsLoading","error","setError","chartRef","React","handleGenerate","useCallback","result","generateFlowchart","err","errorMessage","useEffect","svg","e","jsxs","jsx","MapIcon","LoadingSpinner"],"mappings":"86EAOAA,EAAQ,WAAW,CACf,YAAa,GACb,MAAO,OACP,SAAU,GACV,cAAe,QACf,eAAgB,CACZ,WAAY,UACZ,aAAc,UACd,iBAAkB,UAClB,UAAW,UACX,UAAW,SAAA,CAEnB,CAAC,EAED,MAAMC,EAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAUPC,GAA4B,IAAM,CAC3C,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAAAA,SAAiBJ,CAAW,EAC9C,CAACK,EAAaC,CAAc,EAAIF,EAAAA,SAAiB,EAAE,EACnD,CAACG,EAAWC,CAAY,EAAIJ,EAAAA,SAAkB,EAAK,EACnD,CAACK,EAAOC,CAAQ,EAAIN,EAAAA,SAAiB,EAAE,EACvCO,EAAWC,EAAM,OAAuB,IAAI,EAE5CC,EAAiBC,EAAAA,YAAY,SAAY,CAC3C,GAAI,CAACZ,EAAK,OAAQ,CACdQ,EAAS,yBAAyB,EAClC,MACJ,CACAF,EAAa,EAAI,EACjBE,EAAS,EAAE,EACXJ,EAAe,EAAE,EACdK,EAAS,UAASA,EAAS,QAAQ,UAAY,IAElD,GAAI,CACA,MAAMI,EAAS,MAAMC,EAAkBd,CAAI,EAC3CI,EAAeS,EAAO,WAAW,CACrC,OAASE,EAAK,CACV,MAAMC,EAAeD,aAAe,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