ziya 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ziya might be problematic. Click here for more details.

Files changed (73) hide show
  1. app/agents/agent.py +71 -73
  2. app/agents/direct_streaming.py +1 -1
  3. app/agents/prompts.py +1 -1
  4. app/agents/prompts_manager.py +14 -10
  5. app/agents/wrappers/google_direct.py +31 -1
  6. app/agents/wrappers/nova_tool_execution.py +2 -2
  7. app/agents/wrappers/nova_wrapper.py +1 -1
  8. app/agents/wrappers/ziya_bedrock.py +53 -31
  9. app/config/models_config.py +61 -20
  10. app/config/shell_config.py +5 -1
  11. app/extensions/prompt_extensions/claude_extensions.py +27 -5
  12. app/extensions/prompt_extensions/mcp_prompt_extensions.py +82 -56
  13. app/main.py +5 -3
  14. app/mcp/client.py +19 -10
  15. app/mcp/manager.py +68 -10
  16. app/mcp/tools.py +8 -9
  17. app/mcp_servers/shell_server.py +3 -3
  18. app/middleware/streaming.py +29 -41
  19. app/routes/file_validation.py +35 -0
  20. app/routes/mcp_routes.py +54 -8
  21. app/server.py +525 -614
  22. app/streaming_tool_executor.py +748 -137
  23. app/templates/asset-manifest.json +20 -20
  24. app/templates/index.html +1 -1
  25. app/templates/static/css/{main.0297bfee.css → main.e7109b49.css} +2 -2
  26. app/templates/static/css/main.e7109b49.css.map +1 -0
  27. app/templates/static/js/14386.65fcfe53.chunk.js +2 -0
  28. app/templates/static/js/14386.65fcfe53.chunk.js.map +1 -0
  29. app/templates/static/js/35589.0368973a.chunk.js +2 -0
  30. app/templates/static/js/35589.0368973a.chunk.js.map +1 -0
  31. app/templates/static/js/{50295.ab92f61b.chunk.js → 50295.90aca393.chunk.js} +3 -3
  32. app/templates/static/js/50295.90aca393.chunk.js.map +1 -0
  33. app/templates/static/js/55734.5f0fd567.chunk.js +2 -0
  34. app/templates/static/js/55734.5f0fd567.chunk.js.map +1 -0
  35. app/templates/static/js/58542.57fed736.chunk.js +2 -0
  36. app/templates/static/js/58542.57fed736.chunk.js.map +1 -0
  37. app/templates/static/js/{68418.2554bb1e.chunk.js → 68418.f7b4d2d9.chunk.js} +3 -3
  38. app/templates/static/js/68418.f7b4d2d9.chunk.js.map +1 -0
  39. app/templates/static/js/99948.b280eda0.chunk.js +2 -0
  40. app/templates/static/js/99948.b280eda0.chunk.js.map +1 -0
  41. app/templates/static/js/main.e075582c.js +3 -0
  42. app/templates/static/js/main.e075582c.js.map +1 -0
  43. app/utils/code_util.py +5 -2
  44. app/utils/context_cache.py +11 -0
  45. app/utils/conversation_filter.py +90 -0
  46. app/utils/custom_bedrock.py +43 -1
  47. app/utils/diff_utils/validation/validators.py +32 -22
  48. app/utils/file_cache.py +5 -3
  49. app/utils/precision_prompt_system.py +116 -0
  50. app/utils/streaming_optimizer.py +100 -0
  51. {ziya-0.3.0.dist-info → ziya-0.3.2.dist-info}/METADATA +3 -2
  52. {ziya-0.3.0.dist-info → ziya-0.3.2.dist-info}/RECORD +59 -55
  53. app/templates/static/css/main.0297bfee.css.map +0 -1
  54. app/templates/static/js/14386.567bf803.chunk.js +0 -2
  55. app/templates/static/js/14386.567bf803.chunk.js.map +0 -1
  56. app/templates/static/js/35589.278ecda2.chunk.js +0 -2
  57. app/templates/static/js/35589.278ecda2.chunk.js.map +0 -1
  58. app/templates/static/js/50295.ab92f61b.chunk.js.map +0 -1
  59. app/templates/static/js/55734.90d8bd52.chunk.js +0 -2
  60. app/templates/static/js/55734.90d8bd52.chunk.js.map +0 -1
  61. app/templates/static/js/58542.08fb5cf4.chunk.js +0 -2
  62. app/templates/static/js/58542.08fb5cf4.chunk.js.map +0 -1
  63. app/templates/static/js/68418.2554bb1e.chunk.js.map +0 -1
  64. app/templates/static/js/99948.71670e91.chunk.js +0 -2
  65. app/templates/static/js/99948.71670e91.chunk.js.map +0 -1
  66. app/templates/static/js/main.1d79eac2.js +0 -3
  67. app/templates/static/js/main.1d79eac2.js.map +0 -1
  68. /app/templates/static/js/{50295.ab92f61b.chunk.js.LICENSE.txt → 50295.90aca393.chunk.js.LICENSE.txt} +0 -0
  69. /app/templates/static/js/{68418.2554bb1e.chunk.js.LICENSE.txt → 68418.f7b4d2d9.chunk.js.LICENSE.txt} +0 -0
  70. /app/templates/static/js/{main.1d79eac2.js.LICENSE.txt → main.e075582c.js.LICENSE.txt} +0 -0
  71. {ziya-0.3.0.dist-info → ziya-0.3.2.dist-info}/WHEEL +0 -0
  72. {ziya-0.3.0.dist-info → ziya-0.3.2.dist-info}/entry_points.txt +0 -0
  73. {ziya-0.3.0.dist-info → ziya-0.3.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,2 +0,0 @@
1
- "use strict";(self.webpackChunkfrontend=self.webpackChunkfrontend||[]).push([[55734],{55734:(e,t,n)=>{n.d(t,{J:()=>V});var o=n(89379),r=n(65043),i=n(55727),a=n(91686),s=n(85672),c=n(51252);const l=e=>"object"===typeof e&&"network"===e.type&&Array.isArray(e.nodes)&&Array.isArray(e.links)&&e.nodes.length>=0&&e.nodes.every((e=>"string"===typeof e.id))&&e.links.length>=0&&e.links.every((e=>"string"===typeof e.source&&"string"===typeof e.target)),d={name:"network-diagram",priority:1,sizingConfig:{sizingStrategy:"responsive",needsDynamicHeight:!1,needsOverflowVisible:!1,observeResize:!1,containerStyles:{height:"400px",overflow:"auto"}},canHandle:l,render:(e,t,n)=>{var o;if(console.debug("Network diagram plugin rendering:",{spec:n}),!l(n))throw new Error("Invalid network diagram specification");console.debug("Network diagram render:",{nodeCount:n.nodes.length,linkCount:n.links.length,groupCount:null===(o=n.groups)||void 0===o?void 0:o.length});try{var r;const o=t.select(e).selectAll("*").remove().append("svg").attr("width",n.width).attr("height",n.height).attr("viewBox",[0,0,n.width,n.height]);if(null!==(r=n.groups)&&void 0!==r&&r.length){const e=o.selectAll(".board").data(n.groups).enter().append("g").attr("class","board").attr("transform","translate(0,0)");e.append("rect").attr("x",(e=>"modem_board"===e.id?180:680)).attr("y",50).attr("width",(e=>"modem_board"===e.id?350:200)).attr("height",500).attr("fill","none").attr("stroke","#666").attr("stroke-dasharray","5,5"),e.append("text").attr("x",(e=>"modem_board"===e.id?200:700)).attr("y",80).text((e=>e.label)).attr("fill","#666")}}catch(i){throw console.error("Network diagram render error:",i),t.select(e).selectAll("*").remove(),i}}},g={top:20,right:20,bottom:30,left:40},p={name:"basic-chart",priority:10,sizingConfig:{sizingStrategy:"responsive",needsDynamicHeight:!1,needsOverflowVisible:!1,observeResize:!1,containerStyles:{height:"400px",overflow:"auto"}},canHandle:e=>"object"===typeof e&&("bar"===e.type||"line"===e.type||"scatter"===e.type||"bubble"===e.type),render:(e,t,n)=>{console.debug("Basic chart plugin rendering:",n);try{t.select(e).selectAll("*").remove();const o=n.margin||g,r=(n.width||600)-o.left-o.right,i=(n.height||400)-o.top-o.bottom,a=t.select(e).append("svg").attr("width",r+o.left+o.right).attr("height",i+o.top+o.bottom).append("g").attr("transform","translate(".concat(o.left,",").concat(o.top,")")),s=Array.isArray(n.data)?n.data:[],c=t.scaleBand().range([0,r]).domain(n.data.map((e=>e.label))).padding(.1),l=t.scaleLinear().range([i,0]).domain([0,t.max(n.data,(e=>e.value))]);if(a.append("g").attr("transform","translate(0,".concat(i,")")).call(t.axisBottom(c)),a.append("g").call(t.axisLeft(l)),"bar"===n.type)a.selectAll("rect").data(s).join("rect").attr("x",(e=>c(e.label))).attr("y",(e=>l(e.value))).attr("width",c.bandwidth()).attr("height",(e=>i-l(e.value))).attr("fill",(e=>e.color||"steelblue"));else if("line"===n.type||"scatter"===n.type){const e=t.line().x((e=>c(e.label)+c.bandwidth()/2)).y((e=>l(e.value)));"line"===n.type&&a.append("path").datum(s).attr("fill","none").attr("stroke","steelblue").attr("stroke-width",2).attr("d",e),a.selectAll("circle").data(s).join("circle").attr("cx",(e=>c(e.label)+c.bandwidth()/2)).attr("cy",(e=>l(e.value))).attr("r","bubble"===n.type?e=>e.size||5:4).attr("fill",(e=>e.color||"steelblue")).attr("stroke","#fff").attr("stroke-width",1)}}catch(o){throw console.error("Basic chart render error:",o),o}}};var u=n(60082),m=n(24784);function f(e,t){const n="type: ".concat(t);if(!e.includes(n)||!e.includes("definition:"))return e;console.log("\ud83d\udd27 Detected YAML-wrapped ".concat(t," definition, extracting content..."));const o=e.split("\n");let r=!1;const i=[];for(const s of o)if("definition: |"===s.trim()||s.trim().startsWith("definition: |"))r=!0;else if(r){const e=s.replace(/^ /,"");i.push(e)}const a=i.join("\n").trim();return console.log("\u2705 Extracted ".concat(t," definition (").concat(a.length," chars):"),a.substring(0,200)),a}function h(e,t){if(!e||0===e.trim().length)return!1;const n=f(e,t);switch(t.toLowerCase()){case"mermaid":return function(e){const t=e.trim().split("\n");if(t.length<2)return!1;const n=t[0].trim().toLowerCase();if(n.startsWith("graph")||n.startsWith("flowchart")){return e.split("{").length-1===e.split("}").length-1}return t.length>=3&&!e.endsWith("```")}(n);case"graphviz":return function(e){if(!e||0===e.trim().length)return!1;const t=e.split("{").length-1,n=e.split("}").length-1;return t===n&&t>0&&e.includes("}")}(n);case"vega-lite":return function(e){if(!e||0===e.trim().length)return!1;try{const t=JSON.parse(e);if(!t||"object"!==typeof t)return!1;const n=void 0!==t.data,o=t.mark||t.layer||t.concat||t.facet||t.repeat;return n&&o}catch(t){return!1}}(n);default:return n.trim().split("\n").length>=2&&!n.endsWith("```")}}const y=14,b=1;const v=new class{constructor(){this.queue=[],this.isProcessing=!1}async enqueue(e){return new Promise(((t,n)=>{this.queue.push((async()=>{try{const n=await e();t(n)}catch(o){n(o)}})),this.processQueue()}))}async processQueue(){if(this.isProcessing||0===this.queue.length)return;this.isProcessing=!0;const e=this.queue.shift();await e(),this.isProcessing=!1,this.processQueue()}};(0,m.Ay)(u.N),"undefined"!==typeof window&&window.mermaid&&(0,m.Ay)(window.mermaid);const x={name:"mermaid-renderer",priority:5,sizingConfig:{sizingStrategy:"auto-expand",needsDynamicHeight:!0,needsOverflowVisible:!0,observeResize:!0,containerStyles:{width:"100%",height:"auto",overflow:"visible"}},canHandle:e=>(e=>"object"===typeof e&&null!==e&&"mermaid"===e.type&&"string"===typeof e.definition&&e.definition.trim().length>0)(e),isDefinitionComplete:e=>{if(!e||0===e.trim().length)return!1;const t=e.trim().split("\n");if(t.length<2)return!1;const n=t[0].trim().toLowerCase();if(n.startsWith("graph")||n.startsWith("flowchart")){const t=e.split("{").length-1;return t===e.split("}").length-1&&t>0}return t.length>=3&&!e.endsWith("```")},render:async(e,t,o,r)=>v.enqueue((async()=>await async function(e,t,o,r){console.log("\ud83c\udfaf MERMAID SINGLE RENDER with spec:",o),console.log("Mermaid plugin render called with spec type: ".concat(o.type,", definition length: ").concat(o.definition.length)),console.log("\ud83d\udcca DIAGRAM PREVIEW:",o.definition.substring(0,100).replace(/\n/g,"\\n")),console.log("\ud83d\udd0d HAS HTML TAGS:",o.definition.includes("<br"));let i=!1;try{e.innerHTML="";const t=document.createElement("div");if(t.className="mermaid-loading-spinner",t.style.cssText="\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n padding: 2em;\n min-height: 150px;\n width: 100%;\n ",t.innerHTML='\n <div style="\n border: 4px solid rgba(0, 0, 0, 0.1);\n border-top: 4px solid '.concat(r?"#4cc9f0":"#3498db",';\n border-radius: 50%;\n width: 40px;\n height: 40px;\n animation: mermaid-spin 1s linear infinite;\n margin-bottom: 15px;\n "></div>\n <div style="font-family: system-ui, -apple-system, sans-serif; color: ').concat(r?"#eceff4":"#333333",';">\n Rendering diagram...\n </div>\n '),e.appendChild(t),o.isStreaming&&!o.isMarkdownBlockClosed&&!o.forceRender){console.log("Mermaid: Markdown block still open, letting content display as code");try{e.innerHTML=""}catch(s){console.warn("Could not remove loading spinner:",s)}return}if(!o.definition||o.definition.trim().length<10)return void console.log("Mermaid: Definition too short, waiting for more content");let n=f(o.definition,"mermaid");console.log("Raw definition (first 200 chars):",n.substring(0,200));n.trim().split("\n")[0].toLowerCase().replace(/^(\w+).*$/,"$1").toLowerCase();const a=e.id||e.className||"mermaid",l="".concat(a,"-").concat(Date.now(),"-").concat(Math.random().toString(16).substring(2,10));let d;u.N.initialize({startOnLoad:!1,theme:r?"dark":"default",securityLevel:"loose",fontFamily:'"Arial", sans-serif',fontSize:14,themeVariables:r?{primaryColor:"#88c0d0",primaryTextColor:"#ffffff",primaryBorderColor:"#88c0d0",lineColor:"#88c0d0",secondaryColor:"#5e81ac",tertiaryColor:"#2e3440",textColor:"#eceff4",loopTextColor:"#eceff4",mainBkg:"#3b4252",secondBkg:"#434c5e",nodeBorder:"#88c0d0",edgeLabelBackground:"#4c566a",altBackground:"#2e3440",nodeBkg:"#3b4252",clusterBkg:"#2e3440",titleColor:"#88c0d0",classText:"#ffffff",labelColor:"#ffffff",actorBkg:"#4c566a",actorBorder:"#88c0d0",activationBkg:"#5e81ac",sectionBkgColor:"#3b4252",altSectionBkgColor:"#434c5e",gridColor:"#eceff4",todayLineColor:"#88c0d0"}:{},flowchart:{htmlLabels:!0,curve:"basis",padding:15,nodeSpacing:50,rankSpacing:50,diagramPadding:8},sequence:{diagramMarginX:50,diagramMarginY:30,actorMargin:50,width:150,height:65,boxMargin:10,boxTextMargin:5,noteMargin:10,messageMargin:35,mirrorActors:!0,bottomMarginAdj:1,useMaxWidth:!0},gantt:{titleTopMargin:25,barHeight:20,barGap:4,topPadding:50,leftPadding:75,gridLineStartPadding:35,fontSize:11,sectionFontSize:11,numberSectionStyles:4,axisFormat:"%Y-%m-%d",topAxis:!1}}),console.log("Attempting to render mermaid with ID: ".concat(l));try{const e=await u.N.render(l,n);if(!e||"object"!==typeof e)throw console.error("Invalid mermaid render result:",e),new Error("Mermaid render returned invalid result");if(console.log("Mermaid render result:",e),d=e.svg,!d||""===d.trim())throw console.error("Empty SVG returned from Mermaid render - likely parse error"),console.error("Definition that failed (first 500 chars):",n.substring(0,500)),new Error("Mermaid parsing failed - empty SVG returned. This usually indicates syntax errors in the diagram definition.");if(d.length<100||!d.includes("<svg"))throw console.error("SVG appears to be malformed or too short:",d.substring(0,200)),new Error("Mermaid returned malformed SVG - likely parsing error");if(i=!0,console.log("Mermaid render successful, got SVG of length: ".concat(d.length)),d.includes("syntax error")||d.includes("Parse error"))throw new Error("Mermaid syntax error in diagram")}catch(c){throw console.error("Error rendering mermaid diagram:",c),(c=c instanceof Error?c:new Error(String(c)))instanceof Error&&(console.error("Error name:",c.name),console.error("Error message:",c.message),console.error("Error stack:",c.stack)),console.error("Failed definition (first 500 chars):",n.substring(0,500)),console.error("Raw definition that failed:",n.substring(0,500)),c}if(!document.querySelector("#mermaid-spinner-keyframes")){const e=document.createElement("style");e.id="mermaid-spinner-keyframes",e.textContent="\n @keyframes mermaid-spin {\n 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); }\n }\n ",document.head.appendChild(e)}const g=document.createElement("div");g.className="mermaid-wrapper",g.style.cssText="\n width: 100%;\n max-width: 100%;\n overflow: auto;\n padding: 1em;\n display: flex;\n justify-content: center;\n ",g.innerHTML=d;try{t&&t.parentNode===e&&e.removeChild(t)}catch(s){console.warn("Could not remove loading spinner (this is normal for multiple renders):",s instanceof Error?s.message:String(s))}if(e.appendChild(g),!i)return;const p=g.querySelector("svg");if(!p)throw new Error("Failed to get SVG element after rendering");const m=e=>{e.querySelectorAll("style").forEach((t=>{((t.textContent||"").match(/\.(\w+)\s*{([^}]*)}/g)||[]).forEach((t=>{const n=t.match(/\.(\w+)\s*{/),o=t.match(/{([^}]*)}/);if(n&&o){const t=n[1],r=o[1].trim();e.querySelectorAll(".".concat(t)).forEach((e=>{r.split(";").forEach((t=>{const[n,o]=t.split(":").map((e=>e.trim()));n&&o&&e.style.setProperty(n,o)}))}))}}))}))},h=e=>{e.querySelectorAll("text").forEach((e=>{let t=e.parentElement;for(;t&&!t.classList.contains("node")&&!t.classList.contains("cluster");)t=t.parentElement;if(t){const n=t.querySelector("rect, circle, polygon, path");if(n){const t=n.getAttribute("stroke"),o=n.getAttribute("fill");if(t&&"none"!==t&&"#333"!==t&&"#333333"!==t)e.setAttribute("fill",t);else if(o&&"none"!==o){const t=function(e){const t=(e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(e);if(!t)return"#000000";if(t.r>200&&t.g>200&&t.b<100)return"#000000";if(t.r>220&&t.g>200&&t.b>150)return"#000000";return(.299*t.r+.587*t.g+.114*t.b)/255>.4?"#000000":"#ffffff"}(o);e.setAttribute("fill",t)}else e.setAttribute("fill","#000000")}}})),e.querySelectorAll(".edgeLabel text").forEach((e=>{const t=e.getAttribute("fill");t&&"#ffffff"!==t&&"white"!==t&&"#eceff4"!==t||e.setAttribute("fill","#000000")})),e.querySelectorAll("text").forEach((e=>{var t;const n=null===(t=e.closest("g"))||void 0===t?void 0:t.querySelector("rect");if(n){const t=n.getAttribute("fill");if(t&&"none"!==t){const n=function(e){const t=(e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(e);if(!t)return"#000000";if(t.r>200&&t.g>200&&t.b<100)return"#000000";if(t.r>220&&t.g>200&&t.b>150)return"#000000";return(.299*t.r+.587*t.g+.114*t.b)/255>.4?"#000000":"#ffffff"}(t);e.setAttribute("fill",n)}}}))};r&&p?requestAnimationFrame((()=>{p.querySelectorAll(".edgePath path").forEach((e=>{e.setAttribute("stroke","#88c0d0"),e.setAttribute("stroke-width","1.5px")})),p.querySelectorAll("defs marker path").forEach((e=>{e.setAttribute("stroke","#88c0d0"),e.setAttribute("fill","#88c0d0")})),p.querySelectorAll("line, path:not([fill])").forEach((e=>{e.setAttribute("stroke","#88c0d0"),e.setAttribute("stroke-width","1.5px")})),h(p),p.querySelectorAll("path.path, path.messageText, .flowchart-link").forEach((e=>{e.setAttribute("stroke","#88c0d0"),e.setAttribute("stroke-width","1.5px")})),p.querySelectorAll(".node rect, .node circle, .node polygon, .node path").forEach((e=>{e.setAttribute("stroke","#81a1c1"),e.setAttribute("fill","#5e81ac")})),p.querySelectorAll(".cluster rect").forEach((e=>{e.setAttribute("stroke","#81a1c1"),e.setAttribute("fill","#4c566a")})),m(p)})):m(p);const v=e=>{const t=e.match(/\d+/g);if(!t||t.length<3)return.5;const[n,o,r]=t.map((e=>{const t=parseInt(e)/255;return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)}));return.2126*n+.7152*o+.0722*r},x=(e,t)=>{const n=v(e),o=v(t);return(Math.max(n,o)+.05)/(Math.min(n,o)+.05)};setTimeout((()=>{console.log("\ud83d\udd0d TEXT VISIBILITY FIX: Starting analysis");const t=e.querySelectorAll("foreignObject");console.log("Found ".concat(t.length," foreignObject elements"));let n=0,o=0,r=0;t.forEach(((t,i)=>{const a=t.querySelectorAll("div, span");console.log("ForeignObject ".concat(i,": contains ").concat(a.length," text elements")),a.forEach((i=>{var a;const s=null===(a=i.textContent)||void 0===a?void 0:a.trim();if(!s)return;o++,console.log("Text element ".concat(o,': "').concat(s,'"'));const c=window.getComputedStyle(i).color;console.log(" Text color: ".concat(c));let l=null,d=i,g=0;for(;d&&d!==t;){const e=window.getComputedStyle(d).backgroundColor;if(console.log(" Level ".concat(g,": element ").concat(d.tagName,", bg: ").concat(e)),e&&"rgba(0, 0, 0, 0)"!==e&&"transparent"!==e){l=e,console.log(" Found background: ".concat(l));break}d=d.parentElement,g++}if(!l){console.log(" No background in DOM hierarchy, checking SVG siblings");const e=t.parentElement;if(e){console.log(" Parent group: ".concat(e.tagName));const t=e.querySelectorAll("rect, circle, polygon, path, ellipse");console.log(" Found ".concat(t.length," shape elements in parent group"));for(const e of t){const t=e.getAttribute("fill"),n=window.getComputedStyle(e).fill;if(console.log(" Shape ".concat(e.tagName,': fill="').concat(t,'" computed="').concat(n,'"')),t&&"none"!==t&&"transparent"!==t){l=t,console.log(" Found SVG background: ".concat(l));break}if(n&&"none"!==n&&"transparent"!==n&&"rgb(0, 0, 0)"!==n){l=n,console.log(" Found computed SVG background: ".concat(l));break}}}}if(!l){console.log(" Still no background, searching entire SVG");const t=e.querySelectorAll("rect, circle, polygon, path, ellipse");console.log(" Found ".concat(t.length," total shapes in SVG"));const n=new Set;t.forEach(((e,t)=>{const o=e.getAttribute("fill"),r=window.getComputedStyle(e).fill;o&&"none"!==o&&n.add(o),r&&"none"!==r&&"rgb(0, 0, 0)"!==r&&n.add(r),t<10&&console.log(" All shapes ".concat(t,": ").concat(e.tagName,' fill="').concat(o,'" computed="').concat(r,'"'))})),console.log(" All unique colors found:",Array.from(n))}if(l){r++,console.log(" Background found: ".concat(l));const e=function(e){if(!e||"none"===e||"transparent"===e)return!1;let t;if(console.log(" Checking if background is problematic: ".concat(e)),e.startsWith("rgb(")){const n=e.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!n)return!1;{const[,o,r,i]=n;t=[o,r,i].map((e=>parseInt(e).toString(16).padStart(2,"0"))).join("").toUpperCase(),console.log(" Converted RGB ".concat(e," to hex: ").concat(t))}}else t=e.toUpperCase();t.startsWith("#")&&(t=t.substring(1));const n=["FFEA2E","FFB50D","FFF58C","FFF59D","FFF0D9","E2F4E2","F0DDF3","DBF2FE","FFF7DA","DDEFFD","FDC0C8","F5A9D1","D4EA8C","FFEB3B"].includes(t);return console.log(" ".concat(t," in problematic list: ").concat(n)),n}(l);if(console.log(" Is problematic: ".concat(e)),e){const e=x(c,l);console.log(" Contrast ratio: ".concat(e.toFixed(2))),e<3?(console.log(' \ud83d\udd27 FIXING: "'.concat(s,'" - poor contrast (').concat(e.toFixed(2),")")),i.style.color="#000000",i.style.setProperty("color","#000000","important"),n++):console.log(' \u2713 SKIPPING: "'.concat(s,'" - good contrast (').concat(e.toFixed(2),")"))}}else console.log(' No background found for: "'.concat(s,'"'))}))})),console.log("\ud83d\udd0d SUMMARY: Processed ".concat(o," text elements, ").concat(r," had backgrounds, fixed ").concat(n))}),1e3),requestAnimationFrame((()=>{const e=p.querySelectorAll("text");if(0===e.length)return;const t=window.getComputedStyle(e[0]),n=parseFloat(t.fontSize),o=y/n,r=Math.min(o,b);p.style.transform="scale(".concat(r,")"),p.style.transformOrigin="center center",p.style.width="100%",p.style.height="auto";const i=p.getAttribute("style")||"";if(i.includes("transform: scale")){const e=i.replace(/transform:\s*scale\([^)]+\);?/g,"");p.setAttribute("style",e),p.style.transform="scale(".concat(r,")")}}));const w=document.createElement("div");w.className="diagram-actions";const k=document.createElement("button");k.innerHTML="\u2197\ufe0f Open",k.className="diagram-action-button mermaid-open-button",k.onclick=()=>{const e=g.querySelector("svg");if(!e)return;const t=e;let n=600,o=400;try{const e=t.getBBox();n=Math.max(e.width+50,400),o=Math.max(e.height+100,300)}catch(s){console.warn("Could not get SVG dimensions, using defaults",s)}const r=(new XMLSerializer).serializeToString(e),i='\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset="UTF-8">\n <title>Mermaid Diagram</title>\n <style>\n :root {\n --bg-color: #f8f9fa;\n --text-color: #212529;\n --toolbar-bg: #f1f3f5;\n --toolbar-border: #dee2e6;\n --button-bg: #4361ee;\n --button-hover: #3a0ca3;\n }\n \n [data-theme="dark"] {\n --bg-color: #212529;\n --text-color: #f8f9fa;\n --toolbar-bg: #343a40;\n --toolbar-border: #495057;\n --button-bg: #4361ee;\n --button-hover: #5a72f0;\n }\n \n body {\n margin: 0;\n padding: 0;\n display: flex;\n flex-direction: column;\n height: 100vh;\n background-color: var(--bg-color);\n color: var(--text-color);\n font-family: system-ui, -apple-system, sans-serif;\n transition: background-color 0.3s ease, color 0.3s ease;\n }\n \n .toolbar {\n background-color: var(--toolbar-bg);\n border-bottom: 1px solid var(--toolbar-border);\n padding: 8px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n transition: background-color 0.3s ease, border-color 0.3s ease;\n }\n \n .toolbar button {\n background-color: var(--button-bg);\n color: white;\n border: none;\n border-radius: 4px;\n padding: 6px 12px;\n cursor: pointer;\n margin-right: 8px;\n font-size: 14px;\n transition: background-color 0.3s ease;\n }\n \n .toolbar button:hover {\n background-color: var(--button-hover);\n }\n \n .theme-toggle {\n background-color: transparent;\n border: 1px solid var(--text-color);\n color: var(--text-color);\n padding: 4px 8px;\n font-size: 12px;\n }\n \n .theme-toggle:hover {\n background-color: var(--text-color);\n color: var(--bg-color);\n }\n \n .container {\n flex: 1;\n display: flex;\n justify-content: center;\n align-items: center;\n overflow: auto;\n padding: 20px;\n }\n \n svg {\n max-width: 100%;\n max-height: 100%;\n height: auto;\n width: auto;\n transition: all 0.3s ease;\n }\n </style>\n </head>\n <body data-theme="light">\n <div class="toolbar">\n <div>\n <button onclick="zoomIn()">Zoom In</button>\n <button onclick="zoomOut()">Zoom Out</button>\n <button onclick="resetZoom()">Reset</button>\n <button class="theme-toggle" onclick="toggleTheme()">\ud83c\udf19 Dark</button>\n </div>\n <div>\n <button onclick="downloadSvg()">Download SVG</button>\n </div>\n </div>\n <div class="container" id="svg-container">\n '.concat(r,"\n </div>\n <script>\n const svg = document.querySelector('svg');\n let currentScale = 1;\n let isDarkMode = false;\n \n // Make sure SVG is responsive\n svg.setAttribute('width', '100%');\n svg.setAttribute('height', '100%');\n svg.style.maxWidth = '100%';\n svg.style.maxHeight = '100%';\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n \n function zoomIn() {\n currentScale *= 1.2;\n svg.style.transform = `scale(${currentScale})`;\n }\n \n function zoomOut() {\n currentScale /= 1.2;\n svg.style.transform = `scale(${currentScale})`;\n }\n \n function resetZoom() {\n currentScale = 1;\n svg.style.transform = 'scale(1)';\n }\n \n function toggleTheme() {\n isDarkMode = !isDarkMode;\n const body = document.body;\n const themeButton = document.querySelector('.theme-toggle');\n \n if (isDarkMode) {\n body.setAttribute('data-theme', 'dark');\n themeButton.textContent = '\u2600\ufe0f Light';\n } else {\n body.setAttribute('data-theme', 'light');\n themeButton.textContent = '\ud83c\udf19 Dark';\n }\n \n // Re-render Mermaid diagram with new theme\n reRenderMermaidDiagram();\n }\n \n function reRenderMermaidDiagram() {\n const svgContainer = document.getElementById('svg-container');\n const currentSvg = svgContainer.querySelector('svg');\n \n if (!currentSvg) return;\n \n // Apply Mermaid-specific theme styling\n applyMermaidTheme(currentSvg, isDarkMode);\n }\n \n function applyMermaidTheme(svgElement, isDark) {\n const darkTheme = {\n primaryColor: '#88c0d0',\n primaryTextColor: '#ffffff',\n primaryBorderColor: '#88c0d0',\n lineColor: '#88c0d0',\n secondaryColor: '#5e81ac',\n tertiaryColor: '#2e3440',\n textColor: '#eceff4',\n mainBkg: '#3b4252',\n secondBkg: '#434c5e',\n nodeBorder: '#88c0d0',\n edgeLabelBackground: '#4c566a',\n altBackground: '#2e3440',\n nodeBkg: '#3b4252',\n clusterBkg: '#2e3440'\n };\n \n const lightTheme = {\n primaryColor: '#1890ff',\n primaryTextColor: '#000000',\n primaryBorderColor: '#1890ff',\n lineColor: '#333333',\n secondaryColor: '#f0f0f0',\n tertiaryColor: '#ffffff',\n textColor: '#333333',\n mainBkg: '#ffffff',\n secondBkg: '#f8f9fa',\n nodeBorder: '#cccccc',\n edgeLabelBackground: '#ffffff',\n altBackground: '#f5f5f5',\n nodeBkg: '#ffffff',\n clusterBkg: '#f8f9fa'\n };\n \n const colors = isDark ? darkTheme : lightTheme;\n \n // Apply theme to Mermaid elements\n svgElement.querySelectorAll('.edgePath path').forEach(el => {\n el.setAttribute('stroke', colors.lineColor);\n el.setAttribute('stroke-width', '1.5px');\n });\n \n svgElement.querySelectorAll('defs marker path').forEach(el => {\n el.setAttribute('stroke', colors.lineColor);\n el.setAttribute('fill', colors.lineColor);\n });\n \n svgElement.querySelectorAll('.node rect, .node circle, .node polygon, .node path').forEach(el => {\n el.setAttribute('stroke', colors.nodeBorder);\n el.setAttribute('fill', colors.nodeBkg);\n });\n \n svgElement.querySelectorAll('.cluster rect').forEach(el => {\n el.setAttribute('stroke', colors.nodeBorder);\n el.setAttribute('fill', colors.clusterBkg);\n });\n \n // Text styling - node labels should contrast with node background\n svgElement.querySelectorAll('.node .label text, .cluster .label text').forEach(el => {\n el.setAttribute('fill', isDark ? '#000000' : '#333333');\n });\n \n // Edge labels and other text should use theme text color\n svgElement.querySelectorAll('.edgeLabel text, text:not(.node .label text):not(.cluster .label text)').forEach(el => {\n el.setAttribute('fill', colors.textColor);\n });\n \n // Flow chart links\n svgElement.querySelectorAll('.flowchart-link, path.path, path.messageText').forEach(el => {\n el.setAttribute('stroke', colors.lineColor);\n el.setAttribute('stroke-width', '1.5px');\n });\n }\n \n function downloadSvg() {\n const svgData = new XMLSerializer().serializeToString(svg);\n const svgBlob = new Blob([svgData], {type: 'image/svg+xml'});\n const url = URL.createObjectURL(svgBlob);\n \n const link = document.createElement('a');\n link.href = url;\n link.download = 'mermaid-diagram-").concat(Date.now(),".svg';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n \n setTimeout(() => URL.revokeObjectURL(url), 1000);\n }\n \n // Initialize theme based on system preference\n if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {\n toggleTheme();\n }\n <\/script>\n </body>\n </html>\n "),a=new Blob([i],{type:"text/html"}),c=URL.createObjectURL(a),l=window.open(c,"MermaidDiagram","width=".concat(n,",height=").concat(o,",resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no"));l&&l.focus(),setTimeout((()=>URL.revokeObjectURL(c)),1e4)},w.appendChild(k);const S=document.createElement("button");S.innerHTML="\ud83d\udcbe Save",S.className="diagram-action-button mermaid-save-button",S.onclick=()=>{const e=g.querySelector("svg");if(!e)return;const t=(new XMLSerializer).serializeToString(e),n='<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'.concat(t),o=new Blob([n],{type:"image/svg+xml"}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download="mermaid-diagram-".concat(Date.now(),".svg"),document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout((()=>URL.revokeObjectURL(r)),1e3)},w.appendChild(S);let E=!1;const A=g.innerHTML,C=document.createElement("button");C.innerHTML=E?"\ud83c\udfa8 View":"\ud83d\udcdd Source",C.className="diagram-action-button mermaid-source-button",C.onclick=()=>{E=!E,C.innerHTML=E?"\ud83c\udfa8 View":"\ud83d\udcdd Source",g.innerHTML=E?'<pre style="\n background-color: '.concat(r?"#1f1f1f":"#f6f8fa",";\n padding: 16px;\n border-radius: 4px;\n overflow: auto;\n color: ").concat(r?"#e6e6e6":"#24292e",';\n "><code>').concat(o.definition,"</code></pre>"):A},w.appendChild(C),e.insertBefore(w,g)}catch(l){var a;console.error("Mermaid rendering error:",l);const i=e.querySelector(".mermaid-loading-spinner");i&&e.removeChild(i),e.innerHTML.includes("Rendering diagram")&&(e.innerHTML="");const s=((null===(a=o.definition.trim().split("\n")[0])||void 0===a?void 0:a.trim())||"").split(" ")[0];let c="Mermaid Rendering Error",g="There was an error rendering the diagram.";const p=l.message||"";if(p.includes("Parse error")||p.includes("Expecting"))c="Mermaid Syntax Error",g="There is a syntax error in the Mermaid diagram definition. The diagram may have malformed connections or invalid characters.";else if(p.includes("Lexical error")||p.includes("Unrecognized text"))c="Mermaid Lexical Error",g="Mermaid encountered unrecognized text or invalid syntax in the diagram definition.";else if(p.includes("empty SVG returned"))try{const{detectSupportedDiagramTypes:e,normalizeDiagramType:t}=await Promise.resolve().then(n.bind(n,24784)),o=e(u.N),r=t(s,u.N);console.log("Type detection debug:",{diagramType:s,normalizedType:r,supportedTypesSize:o.size,supportedTypes:Array.from(o),hasOriginal:o.has(s),hasNormalized:o.has(r)}),0===o.size?(console.warn("Type detection returned empty set, falling back to parsing error"),c="Mermaid Parsing Error",g="Mermaid parsing failed - this usually indicates syntax errors in the diagram definition."):!s||o.has(s)||o.has(r)?(c="Mermaid Parsing Error",g="Mermaid parsing failed - this usually indicates syntax errors in the diagram definition."):(c="Unsupported Diagram Type",g='The diagram type "'.concat(s,"\" is not supported in the current version of Mermaid. This may be a beta feature that hasn't been released yet."))}catch(d){console.warn("Could not detect supported types:",d),c="Mermaid Parsing Error",g="Mermaid parsing failed - this usually indicates syntax errors in the diagram definition."}if(!o.isStreaming||o.forceRender){e.innerHTML='\n <div class="mermaid-error">\n <strong>'.concat(c,":</strong>\n <p>").concat(g,"</p>\n <pre>").concat(l.message||"Unknown error","</pre>\n <details>\n <summary>Show Definition</summary>\n <pre><code>").concat(o.definition,"</code></pre>\n </details>\n </div>\n ");const n=document.createElement("button");n.innerHTML="\ud83d\udcdd View Source",n.className="diagram-action-button mermaid-source-button",n.style.cssText="\n background-color: #4361ee;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 10px 5px;\n cursor: pointer;\n display: inline-block;\n ";const i=document.createElement("button");i.innerHTML="\ud83d\udd04 Retry Rendering",i.className="diagram-action-button mermaid-retry-button",i.style.cssText="\n background-color: #4361ee;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 10px auto;\n cursor: pointer;\n display: block;\n ";const a=document.createElement("div");a.style.textAlign="center",a.appendChild(n),a.appendChild(i),e.appendChild(a),i.onclick=()=>x.render(e,t,o,r),n.onclick=()=>{if(e.querySelector(".mermaid-error")){e.innerHTML='<pre style="\n background-color: '.concat(r?"#1f1f1f":"#f6f8fa",";\n padding: 16px;\n border-radius: 4px;\n overflow: auto;\n color: ").concat(r?"#e6e6e6":"#24292e",';\n "><code>').concat(o.definition,"</code></pre>");const n=document.createElement("button");n.innerHTML="\u2b05\ufe0f Back to Error",n.className="diagram-action-button",n.style.cssText="\n background-color: #4361ee;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 10px auto;\n cursor: pointer;\n display: block;\n ",n.onclick=()=>x.render(e,t,o,r),e.appendChild(n)}}}}}(e,t,o,r)))};var w=n(44826);const k=new WeakMap,S={name:"graphviz-renderer",priority:5,sizingConfig:{sizingStrategy:"auto-expand",needsDynamicHeight:!0,needsOverflowVisible:!0,observeResize:!0,containerStyles:{width:"100%",height:"auto",overflow:"visible"}},canHandle:e=>"object"===typeof e&&null!==e&&"graphviz"===e.type&&"string"===typeof e.definition&&e.definition.trim().length>0,isDefinitionComplete:e=>{if(!e||0===e.trim().length)return!1;const t=e.split("{").length-1;return t===e.split("}").length-1&&t>0&&e.includes("}")},render:async(e,t,n,o)=>{try{const i=null!==e.querySelector("svg"),a=document.createElement("div");if(a.innerHTML='\n <div style="\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n padding: 2em;\n width: 100%;\n height: 100%;\n min-height: 150px;\n ">\n <div style="\n border: 4px solid rgba(0, 0, 0, 0.1);\n border-top: 4px solid '.concat(o?"#4cc9f0":"#3498db",';\n border-radius: 50%;\n width: 40px;\n height: 40px;\n animation: graphviz-spin 1s linear infinite;\n margin-bottom: 15px;\n "></div>\n <div style="\n font-family: system-ui, -apple-system, sans-serif;\n color: ').concat(o?"#eceff4":"#333333",';\n ">Rendering Visualization...</div>\n </div>\n <style>\n @keyframes graphviz-spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n '),e.innerHTML=a.innerHTML,n.isStreaming&&!n.isMarkdownBlockClosed&&!n.forceRender){console.log("Graphviz: Markdown block still open, letting content display as code");try{e.innerHTML=""}catch(r){console.warn("Could not remove loading spinner:",r)}return}if(!n.definition||n.definition.trim().length<10)return void console.log("Graphviz: Definition too short, waiting for more content");if(i&&n.isStreaming)return;console.log("Rendering Graphviz diagram with ".concat(n.definition.length," chars")),k.set(e,o);const s={light:{text:"#333333",stroke:"#555555",nodeFill:"#f5f5f5",nodeBorder:"#999999",edgeColor:"#333333",background:"transparent",labelText:"#333333",clusterBg:"#f0f0f0",clusterBorder:"#cccccc"},dark:{text:"#ffffff",stroke:"#00b7ff",nodeFill:"#2a3990",nodeBorder:"#4cc9f0",edgeColor:"#f72585",background:"transparent",labelText:"#ffffff",clusterBg:"#1a1a2e",clusterBorder:"#4cc9f0",nodeColors:["#4361ee","#3a0ca3","#7209b7","#f72585","#4cc9f0","#06d6a0","#118ab2"]}},c=o?s.dark:s.light,l=await w.KJ();let d=f(n.definition,"graphviz");d=d.replace(/label\s*=\s*"((?:\\"|[^"])*)"/g,((e,t)=>{const n=t.replace(/\\"/g,'"').replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/\\n/g,"<br/>").replace(/\n/g,"<br/>");return"label=<".concat(n,">")}));let g=d;if(d.match(/^(\s*(?:di)?graph\s+[^{]*{)/)){const e=o?"#ffffff":"#000000";g=d.replace(/^(\s*(?:di)?graph\s+[^{]*{)/,'$1\n bgcolor="transparent";\n node [color="'.concat(c.nodeBorder,'", style="filled", fillcolor="').concat(c.nodeFill,'", penwidth=1.5];\n edge [color="').concat(c.edgeColor,'", fontcolor="').concat(e,'", penwidth=1.5];\n graph [fontcolor="').concat(e,'", color="').concat(c.clusterBorder,'", fontname="Arial"];'));const t=n.definition.match(/^\s*label\s*=\s*"([^"]+)"/m);if(t){const n=t[1];g=g.replace(/^\s*label\s*=\s*"([^"]+)"/m,' label=<<font color="'.concat(e,'">').concat(n,"</font>>"))}}const p=await l.renderSVGElement(g),u=p.getElementsByTagName("*");let m=0;const h=o?s.dark.nodeColors:[],y=new Map,b=new Map;for(let e=0;e<u.length;e++){const t=u[e];if("polygon"===t.tagName&&t.parentElement&&t.parentElement.classList.contains("cluster")){const e=t.getAttribute("fill");if(e&&(b.set(t.parentElement,e),o&&E(e))){const n=C(e);t.setAttribute("fill",n),t.setAttribute("stroke",c.clusterBorder),t.setAttribute("data-original-fill",e),t.setAttribute("data-darkened","true")}}}for(let e=0;e<u.length;e++){const t=u[e];if(("ellipse"===t.tagName||"polygon"===t.tagName)&&"none"!==t.getAttribute("fill")){const e=t.getAttribute("fill");if(e&&y.set(t,e),o){if(e&&E(e))if("#ffffff"===e.toLowerCase()||"white"===e.toLowerCase()||A(e)>.9)if(h.length>0){const n=m%h.length;t.setAttribute("fill",h[n]),t.setAttribute("data-original-fill",e),t.setAttribute("data-darkened","true"),m++}else t.setAttribute("fill",c.nodeFill),t.setAttribute("data-original-fill",e),t.setAttribute("data-darkened","true");else{const n=C(e);t.setAttribute("fill",n),t.setAttribute("data-original-fill",e),t.setAttribute("data-darkened","true")}t.setAttribute("stroke",c.nodeBorder),t.setAttribute("stroke-width","1.5")}}}for(let e=0;e<u.length;e++){const t=u[e];if("text"===t.tagName){const e=o?"#ffffff":"#000000";t.setAttribute("fill",e);const n=t.parentElement;if(n){const o=n.querySelector("ellipse, polygon");if(o){const e=o.getAttribute("fill");if(e){const n=E(e);t.setAttribute("fill",n?"#000000":"#ffffff")}t.setAttribute("data-bg-color",e||"unknown"),t.setAttribute("data-is-light",E(e||"")?"true":"false")}else if(n.classList.contains("cluster")){const e=n.querySelector("polygon");if(e){const n=e.getAttribute("fill");if(n){const e=E(n);t.setAttribute("fill",e?"#000000":"#ffffff")}}}else n.classList.contains("edge")&&t.setAttribute("fill",e)}n&&n.classList.contains("graph")&&t.setAttribute("fill",e)}else"path"===t.tagName?t.getAttribute("fill")&&"none"!==t.getAttribute("fill")||(t.setAttribute("stroke",c.edgeColor),t.setAttribute("stroke-width","1.5")):"polygon"===t.tagName&&t.classList.contains("arrow")&&(t.setAttribute("fill",c.edgeColor),t.setAttribute("stroke",c.edgeColor))}e.innerHTML="";const v=document.createElement("div");v.className="graphviz-wrapper",v.style.cssText="\n width: 100%;\n max-width: 100%;\n overflow: auto;\n padding: 1em;\n display: flex;\n justify-content: center;\n ",v.appendChild(p),e.appendChild(v);const x=document.createElement("div");x.className="diagram-actions";const L=document.createElement("button");L.innerHTML="\u2197\ufe0f Open",L.className="diagram-action-button graphviz-open-button",L.onclick=()=>{const e=p;let t=600,n=400;try{const o=e.getBBox();t=Math.max(o.width+50,400),n=Math.max(o.height+100,300)}catch(r){console.warn("Could not get SVG dimensions, using defaults",r)}const o=(new XMLSerializer).serializeToString(p),i='\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset="UTF-8">\n <title>Graphviz Diagram</title>\n <style>\n body {\n margin: 0;\n padding: 0;\n display: flex;\n flex-direction: column;\n height: 100vh;\n background-color: #f8f9fa;\n font-family: system-ui, -apple-system, sans-serif;\n }\n .toolbar {\n background-color: #f1f3f5;\n border-bottom: 1px solid #dee2e6;\n padding: 8px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n .toolbar button {\n background-color: #4361ee;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 6px 12px;\n cursor: pointer;\n margin-right: 8px;\n font-size: 14px;\n }\n .toolbar button:hover {\n background-color: #3a0ca3;\n }\n .container {\n flex: 1;\n display: flex;\n justify-content: center;\n align-items: center;\n overflow: auto;\n padding: 20px;\n }\n svg {\n max-width: 100%;\n max-height: 100%;\n height: auto;\n width: auto;\n }\n @media (prefers-color-scheme: dark) {\n body {\n background-color: #212529;\n color: #f8f9fa;\n }\n .toolbar {\n background-color: #343a40;\n border-bottom: 1px solid #495057;\n }\n }\n </style>\n </head>\n <body>\n <div class="toolbar">\n <div>\n <button onclick="zoomIn()">Zoom In</button>\n <button onclick="zoomOut()">Zoom Out</button>\n <button onclick="resetZoom()">Reset</button>\n </div>\n <div>\n <button onclick="downloadSvg()">Download SVG</button>\n </div>\n </div>\n <div class="container" id="svg-container">\n '.concat(o,"\n </div>\n <script>\n const svg = document.querySelector('svg');\n let currentScale = 1;\n \n // Make sure SVG is responsive\n svg.setAttribute('width', '100%');\n svg.setAttribute('height', '100%');\n svg.style.maxWidth = '100%';\n svg.style.maxHeight = '100%';\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n \n function zoomIn() {\n currentScale *= 1.2;\n svg.style.transform = `scale(${currentScale})`;\n }\n \n function zoomOut() {\n currentScale /= 1.2;\n svg.style.transform = `scale(${currentScale})`;\n }\n \n function resetZoom() {\n currentScale = 1;\n svg.style.transform = 'scale(1)';\n }\n \n function downloadSvg() {\n const svgData = new XMLSerializer().serializeToString(svg);\n const svgBlob = new Blob([svgData], {type: 'image/svg+xml'});\n const url = URL.createObjectURL(svgBlob);\n \n const link = document.createElement('a');\n link.href = url;\n link.download = 'graphviz-diagram.svg';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n \n setTimeout(() => URL.revokeObjectURL(url), 1000);\n }\n <\/script>\n </body>\n </html>\n "),a=new Blob([i],{type:"text/html"}),s=URL.createObjectURL(a),c=window.open(s,"GraphvizDiagram","width=".concat(t,",height=").concat(n,",resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no"));c&&c.focus(),setTimeout((()=>URL.revokeObjectURL(s)),1e4)},x.appendChild(L);const T=document.createElement("button");T.innerHTML="\ud83d\udcbe Save",T.className="diagram-action-button graphviz-save-button",T.onclick=()=>{const e=(new XMLSerializer).serializeToString(p),t='<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'.concat(e),n=new Blob([t],{type:"image/svg+xml"}),o=URL.createObjectURL(n),r=document.createElement("a");r.href=o,r.download="graphviz-diagram-".concat(Date.now(),".svg"),document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout((()=>URL.revokeObjectURL(o)),1e3)},x.appendChild(T);let R=!1;const I=v.innerHTML,M=document.createElement("button");M.innerHTML=R?"\ud83c\udfa8 View":"\ud83d\udcdd Source",M.className="diagram-action-button graphviz-source-button",M.onclick=()=>{R=!R,M.innerHTML=R?"\ud83c\udfa8 View":"\ud83d\udcdd Source",v.innerHTML=R?'<pre style="\n background-color: '.concat(o?"#1f1f1f":"#f6f8fa",";\n padding: 16px;\n border-radius: 4px;\n overflow: auto;\n color: ").concat(o?"#e6e6e6":"#24292e",';\n "><code>').concat(n.definition,"</code></pre>"):I},x.appendChild(M),e.insertBefore(x,v);const F=document.createElement("button");F.innerHTML=o?"\u2600\ufe0f Light":"\ud83c\udf19 Dark",F.className="diagram-action-button graphviz-theme-button",F.onclick=()=>{S.render(e,t,n,!o)},x.appendChild(F)}catch(i){console.error("Graphviz rendering error:",i),n.isStreaming&&e.querySelector("svg")||(e.innerHTML='\n <div class="graphviz-error">\n <strong>Graphviz Error:</strong>\n <pre>'.concat(i instanceof Error?i.message:"Unknown error","</pre>\n <details>\n <summary>Show Definition</summary>\n <pre><code>").concat(n.definition,"</code></pre>\n </details>\n </div>\n "))}}};function E(e){if(!e||"transparent"===e||"none"===e)return!1;if(["white","lightblue","lightgreen","lightgrey","lightgray","pink","#aed6f1","#d4e6f1","#d5f5e3","#f5f5f5","#e6e6e6","#f0f0f0","#ffffff","#f8f9fa","#e9ecef","#dee2e6","#ced4da","#adb5bd"].some((t=>t.toLowerCase()===e.toLowerCase())))return!0;return A(e)>.5}function A(e){let t,n,o;if(e.startsWith("#")){const r=e.substring(1);3===r.length?(t=parseInt(r[0]+r[0],16),n=parseInt(r[1]+r[1],16),o=parseInt(r[2]+r[2],16)):(t=parseInt(r.substring(0,2),16),n=parseInt(r.substring(2,4),16),o=parseInt(r.substring(4,6),16))}else{if(!e.startsWith("rgb"))return 0;{const r=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)/);if(!r)return 0;t=parseInt(r[1],10),n=parseInt(r[2],10),o=parseInt(r[3],10)}}return(.299*t+.587*n+.114*o)/255}function C(e){const t={white:"#2e3440",lightblue:"#5e81ac",lightgreen:"#8fbcbb",lightgrey:"#4c566a",lightgray:"#4c566a",pink:"#b48ead"};if(t[e.toLowerCase()])return t[e.toLowerCase()];try{let t,n,o;if(e.startsWith("#")){const r=e.substring(1);3===r.length?(t=parseInt(r[0]+r[0],16),n=parseInt(r[1]+r[1],16),o=parseInt(r[2]+r[2],16)):(t=parseInt(r.substring(0,2),16),n=parseInt(r.substring(2,4),16),o=parseInt(r.substring(4,6),16))}else{if(!e.startsWith("rgb"))return"#2e3440";{const r=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)/);if(!r)return"#2e3440";t=parseInt(r[1],10),n=parseInt(r[2],10),o=parseInt(r[3],10)}}return t=Math.max(Math.floor(.4*t),0),n=Math.max(Math.floor(.4*n),0),o=Math.max(Math.floor(.4*o),0),"#".concat(t.toString(16).padStart(2,"0")).concat(n.toString(16).padStart(2,"0")).concat(o.toString(16).padStart(2,"0"))}catch(n){return"#2e3440"}}var L=n(80045),T=n(66158);const R=["facet","transform","layer","mark","encoding"],I=["mark","encoding"],M=e=>"object"===typeof e&&null!==e&&(!e.type||!["mermaid","graphviz","network","d2","joint"].includes(e.type))&&("vega-lite"===e.type||e.$schema&&"string"===typeof e.$schema&&e.$schema.includes("vega-lite")||e.mark&&(e.encoding||e.data)||e.layer&&Array.isArray(e.layer)||e.vconcat&&Array.isArray(e.vconcat)||e.hconcat&&Array.isArray(e.hconcat)||e.facet&&e.spec);function F(e){if(null!==e&&void 0!==e){if(Array.isArray(e))return e.map(F).filter((e=>void 0!==e));if("object"===typeof e){const t={};for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const o=F(e[n]);void 0!==o&&(t[n]=o)}return t}return e}}const N=e=>{if(!e||0===e.trim().length)return!1;const t=e.trim();if(t.endsWith(",")||t.endsWith("{")||t.endsWith("["))return!1;if(t.includes('"$')&&!t.includes('"$schema"'))return!1;try{const t=JSON.parse(e);if(!t||"object"!==typeof t)return!1;if(t.$schema&&"string"===typeof t.$schema&&!t.$schema.endsWith(".json"))return!1;const n=void 0!==t.data,o=t.mark||t.layer||t.concat||t.facet||t.repeat;return n&&o}catch(n){return!1}},D={name:"vega-lite-renderer",priority:8,sizingConfig:{sizingStrategy:"content-driven",needsDynamicHeight:!0,needsOverflowVisible:!0,observeResize:!0,containerStyles:{width:"100%",height:"auto"}},canHandle:e=>(e=>{if("string"===typeof e)try{const t=JSON.parse(e);return M(t)}catch(t){return!1}return M(e)})(e),isDefinitionComplete:e=>N(e),render:async(e,t,n,r)=>{console.log("Vega-Lite plugin render called with spec:",n),console.log("Vega-Lite streaming state:",{isStreaming:n.isStreaming,isMarkdownBlockClosed:n.isMarkdownBlockClosed,forceRender:n.forceRender});const i=e._vegaView;i&&(i.finalize(),delete e._vegaView),e.innerHTML="";e.querySelectorAll(".vega-embed").forEach((e=>{e.parentNode&&e.parentNode.removeChild(e)}));const a=document.createElement("div");if(a.className="vega-lite-loading-spinner",a.style.cssText="\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n padding: 2em;\n min-height: 150px;\n width: 100%;\n ",a.innerHTML='\n <div style="\n border: 4px solid rgba(0, 0, 0, 0.1);\n border-top: 4px solid '.concat(r?"#4cc9f0":"#3498db",';\n border-radius: 50%;\n width: 40px;\n height: 40px;\n animation: vega-lite-spin 1s linear infinite;\n margin-bottom: 15px;\n "></div>\n <div style="font-family: system-ui, -apple-system, sans-serif; color: ').concat(r?"#eceff4":"#333333",';">\n Loading Vega-Lite visualization...\n </div>\n '),e.appendChild(a),!document.querySelector("#vega-lite-spinner-keyframes")){const e=document.createElement("style");e.id="vega-lite-spinner-keyframes",e.textContent="\n @keyframes vega-lite-spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n ",document.head.appendChild(e)}let s=!1;const c=n.$schema&&(n.data||n.datasets)&&(n.mark||n.layer||n.vconcat||n.hconcat||n.facet||n.repeat);if(c)console.log("Vega-Lite: Complete object spec detected, proceeding with render"),s=!1;else if(n.definition)if(n.definition){const e=n.definition||JSON.stringify(n);if(e&&0!==e.trim().length){const t=h(e,"vega-lite");console.log("Vega-Lite definition completeness check:",{isComplete:t,definitionLength:e.length,definitionPreview:e.substring(0,100)}),t||n.forceRender||(console.log("Vega-Lite: Waiting due to incomplete definition",{isStreaming:n.isStreaming,isMarkdownBlockClosed:n.isMarkdownBlockClosed}),s=!0),(e.includes("Unterminated string")||e.includes("Unexpected end"))&&(console.log("Vega-Lite: Waiting due to JSON parsing indicators"),s=!0)}else console.log("Vega-Lite: Waiting due to empty definition",{isStreaming:n.isStreaming,isMarkdownBlockClosed:n.isMarkdownBlockClosed}),s=!n.forceRender}else c||(console.log("Vega-Lite: Waiting due to missing definition",{isStreaming:n.isStreaming,isMarkdownBlockClosed:n.isMarkdownBlockClosed}),s=!n.forceRender);if(n.isMarkdownBlockClosed&&(c||n.definition&&n.definition.trim().length>0)&&(console.log("Vega-Lite: Markdown block closed with content, forcing render"),s=!1),!n.isStreaming||n.isMarkdownBlockClosed||n.forceRender||(console.log("Vega-Lite: Waiting due to active streaming state"),s=!0),console.log("Vega-Lite: After all checks, shouldWaitForComplete =",s),console.log("Vega-Lite: About to check shouldWaitForComplete condition..."),s){console.log("Vega-Lite: Inside shouldWaitForComplete block");const i=document.createElement("div");i.style.cssText="\n text-align: center; \n padding: 20px; \n background-color: ".concat(r?"#1f1f1f":"#f6f8fa","; \n border: 1px dashed #ccc; \n border-radius: 4px;\n position: relative;\n "),i.innerHTML='\n <p>Waiting for complete Vega-Lite specification...</p>\n <div style="margin-top: 15px;">\n <button class="vega-lite-retry-btn" style="\n background-color: #4361ee;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 0 5px;\n cursor: pointer;\n font-size: 14px;\n ">\ud83d\udd04 Force Render</button>\n <button class="vega-lite-source-btn" style="\n background-color: #6c757d;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 0 5px;\n cursor: pointer;\n font-size: 14px;\n ">\ud83d\udcdd View Source</button>\n </div>\n ',e.innerHTML="",e.appendChild(i);const a=i.querySelector(".vega-lite-retry-btn"),s=i.querySelector(".vega-lite-source-btn");return a&&(a.onclick=()=>{console.log("Force rendering Vega-Lite visualization");const i=(0,o.A)((0,o.A)({},n),{},{forceRender:!0});D.render(e,t,i,r)}),void(s&&(s.onclick=()=>{console.log("Showing Vega-Lite source for debugging");const i=n.definition||JSON.stringify(n,null,2);e.innerHTML='\n <div style="\n background-color: '.concat(r?"#1f1f1f":"#f6f8fa",";\n border: 1px solid ").concat(r?"#444":"#e1e4e8",';\n border-radius: 6px;\n padding: 16px;\n margin: 10px 0;\n ">\n <div style="margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center;">\n <strong style="color: ').concat(r?"#f8f9fa":"#24292e",';">Vega-Lite Source:</strong>\n <div>\n <button class="force-render-from-source" style="\n background-color: #28a745;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 6px 12px;\n margin-right: 8px;\n cursor: pointer;\n font-size: 13px;\n ">\ud83d\udd04 Force Render</button>\n <button class="expand-source" style="\n background-color: #6c757d;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 6px 12px;\n cursor: pointer;\n font-size: 13px;\n ">\ud83d\udcc4 Expand</button>\n </div>\n </div>\n <pre style="\n background-color: ').concat(r?"#0d1117":"#f6f8fa",";\n padding: 12px;\n border-radius: 4px;\n overflow: auto;\n max-height: 300px;\n margin: 0;\n border: 1px solid ").concat(r?"#30363d":"#e1e4e8",";\n font-family: 'SFMono-Regular', 'Monaco', 'Inconsolata', 'Liberation Mono', 'Courier New', monospace;\n font-size: 13px;\n line-height: 1.45;\n color: ").concat(r?"#e6edf3":"#24292f",';\n "><code>').concat(i,'</code></pre>\n <div style="margin-top: 12px; font-size: 13px; color: ').concat(r?"#8b949e":"#656d76",';">\n <strong>Debug Info:</strong><br>\n \u2022 Streaming: ').concat(n.isStreaming?"Yes":"No","<br>\n \u2022 Block Closed: ").concat(n.isMarkdownBlockClosed?"Yes":"No","<br>\n \u2022 Definition Length: ").concat(i.length," characters<br>\n \u2022 Complete Object: ").concat(c?"Yes":"No","\n </div>\n </div>\n "),setTimeout((()=>{const i=e.querySelector(".force-render-from-source"),a=e.querySelector(".expand-source");i&&(i.onclick=()=>{console.log("Force rendering from source view");const i=(0,o.A)((0,o.A)({},n),{},{forceRender:!0});D.render(e,t,i,r)}),a&&(a.onclick=()=>{const t=e.querySelector("pre");if(t){const e="none"===t.style.maxHeight;t.style.maxHeight=e?"300px":"none",a.textContent=e?"\ud83d\udcc4 Expand":"\ud83d\udcc4 Collapse"}})}),0)}))}let l;console.log("Vega-Lite: Past shouldWaitForComplete check, about to declare vegaSpec"),console.log("Vega-Lite: Proceeding with spec processing...");const d=e=>{var t,n;if(!e||"object"!==typeof e)return e;const o=JSON.parse(JSON.stringify(e));if(console.log("\ud83d\udd27 VEGA-PREPROCESS: Starting comprehensive preprocessing"),null!==(t=o.encoding)&&void 0!==t&&t.shape){var r,i,a,s;console.log("\ud83d\udd27 VEGA-PREPROCESS: Found shape encoding, analyzing...");const e=o.encoding.shape;let t=!1;if("ordinal"===e.type&&null!==(r=o.data)&&void 0!==r&&r.values){const n=o.data.values.map((t=>t[e.field])).filter((e=>void 0!==e));n.length>0&&n.every((e=>"number"===typeof e))&&(console.log("\ud83d\udd27 VEGA-PREPROCESS: Removing ordinal shape encoding with numeric data"),t=!0)}null!==(i=e.scale)&&void 0!==i&&null!==(a=i.range)&&void 0!==a&&a.some((e=>"string"===typeof e&&e.includes("triangle")))&&(console.log("\ud83d\udd27 VEGA-PREPROCESS: Removing shape encoding with problematic triangle shapes"),t=!0),e.field&&null!==(s=o.data)&&void 0!==s&&s.values||(console.log("\ud83d\udd27 VEGA-PREPROCESS: Removing shape encoding without proper field/data"),t=!0),t&&(delete o.encoding.shape,console.log("\ud83d\udd27 VEGA-PREPROCESS: Removed problematic shape encoding"))}if(o.encoding&&null!==(n=o.data)&&void 0!==n&&n.values&&Array.isArray(o.data.values)&&o.data.values.length>0){const e=Object.keys(o.data.values[0]);console.log("\ud83d\udd27 VEGA-PREPROCESS: Available fields:",e),Object.keys(o.encoding).forEach((t=>{const n=o.encoding[t];null!==n&&void 0!==n&&n.field&&!e.includes(n.field)&&(console.log("\ud83d\udd27 VEGA-PREPROCESS: Removing ".concat(t," encoding with invalid field: ").concat(n.field)),delete o.encoding[t])}))}return["x","y","color","fill","stroke","opacity","size"].forEach((e=>{var t,n,r;if(null!==(t=o.encoding)&&void 0!==t&&null!==(n=t[e])&&void 0!==n&&null!==(r=n.scale)&&void 0!==r&&r.domain){const t=o.encoding[e].scale.domain;if(Array.isArray(t)){const n=t.filter((e=>null!==e&&void 0!==e));n.length!==t.length&&(console.log("\ud83d\udd27 VEGA-PREPROCESS: Cleaned null values from ".concat(e," domain")),n.length>0?o.encoding[e].scale.domain=n:delete o.encoding[e].scale.domain)}else null!==t&&void 0!==t||(console.log("\ud83d\udd27 VEGA-PREPROCESS: Removed null ".concat(e," domain")),delete o.encoding[e].scale.domain)}})),o.$schema||(o.$schema="https://vega.github.io/schema/vega-lite/v5.json"),console.log("\ud83d\udd27 VEGA-PREPROCESS: Preprocessing complete"),o};if("string"===typeof n){const e=f(n,"vega-lite");try{const t=JSON.parse(e);l=d(F(t))}catch(ue){throw console.debug("Vega-Lite: JSON parse error during processing:",ue),ue}}else if(n.definition){const e=f(n.definition,"vega-lite");try{const t=JSON.parse(e);l=d(F(t))}catch(ue){throw console.debug("Vega-Lite: JSON parse error during processing:",ue),ue}}else{const e=F((0,o.A)({},n));["type","isStreaming","forceRender","definition"].forEach((t=>delete e[t])),l=d(e)}console.log("Vega-Lite: Spec processed, starting try block for rendering...");try{var g,p,u,m,y,b,v,x,w,k,S,E,A,C,M,q,B,z,$,W,P,V,j,H,U,X,G,Y,J,K;if(l.$schema&&l.$schema.includes("v4")&&(console.log("SCHEMA FIX: Upgrading old v4 schema to v5 for better compatibility"),l.$schema="https://vega.github.io/schema/vega-lite/v5.json"),"file"===(null===(g=l.encoding)||void 0===g||null===(p=g.x)||void 0===p?void 0:p.field)&&null!==(u=l.data)&&void 0!==u&&u.values){l.data.values.length>20&&(console.log("FILE COUNT FIX: Too many files for x-axis, limiting to top 20"),l.data.values=l.data.values.slice(0,20))}if(null!==(m=l.encoding)&&void 0!==m&&m.shape){var _;const e=l.encoding.shape;if(console.log("SHAPE FIX: Processing shape encoding:",JSON.stringify(e,null,2)),null!==(_=l.data)&&void 0!==_&&_.values&&Array.isArray(l.data.values)){var Q;const t=l.data.values.map((t=>t[e.field])).filter((e=>null!==e&&void 0!==e));if(0===t.length||"ordinal"===e.type&&t.every((e=>"number"===typeof e)))console.log("SHAPE FIX: Removing problematic shape encoding"),delete l.encoding.shape;else if(null!==(Q=e.scale)&&void 0!==Q&&Q.range){const n=["circle","square","cross","diamond","triangle-up","triangle-down","triangle-right","triangle-left"];l.encoding.shape.scale.range=e.scale.range.map((e=>n.includes(e)?e:"circle")).slice(0,Math.min(e.scale.range.length,t.length))}}else console.log("SHAPE FIX: No data available, removing shape encoding as safety measure"),delete l.encoding.shape}if(["color","fill","stroke","opacity","size"].forEach((e=>{var t,n,o;if(null!==(t=l.encoding)&&void 0!==t&&null!==(n=t[e])&&void 0!==n&&null!==(o=n.scale)&&void 0!==o&&o.domain){const t=l.encoding[e].scale.domain;(null===t||Array.isArray(t)&&t.some((e=>null===e||void 0===e)))&&(console.log("DOMAIN FIX: Removing null values from ".concat(e," domain")),Array.isArray(t)?l.encoding[e].scale.domain=t.filter((e=>null!==e&&void 0!==e)):delete l.encoding[e].scale.domain)}})),null!==(y=l.data)&&void 0!==y&&y.values&&Array.isArray(l.data.values)){const e=l.data.values.filter((e=>e&&"object"===typeof e&&Object.values(e).some((e=>null!==e&&void 0!==e))));e.length<l.data.values.length&&(console.log("DATA FIX: Cleaned ".concat(l.data.values.length-e.length," empty rows")),l.data.values=e)}console.log("\ud83d\udd27 VEGA-POST-PROCESS: Starting additional fixes"),void 0!==(null===(b=l.encoding)||void 0===b||null===(v=b.x)||void 0===v||null===(x=v.axis)||void 0===x?void 0:x.labelLimit)&&l.encoding.x.axis.labelLimit<=0&&(console.log("\ud83d\udd27 VEGA-POST-PROCESS: Fixing problematic axis labelLimit"),delete l.encoding.x.axis.labelLimit);try{let e=JSON.stringify(l);e=e.replace(/"#(green|red|orange|blue|yellow|purple|black|white|gray|grey|cyan|magenta|pink|brown|violet|indigo|gold|silver)"/gi,'"$1"'),l=JSON.parse(e)}catch(me){console.warn("Could not apply color fix to Vega-Lite spec",me)}if(!l||"object"!==typeof l)throw new Error("Invalid Vega-Lite specification: spec must be an object");if(!l.data&&!l.datasets)throw new Error("Invalid Vega-Lite specification: missing data or datasets");if(!l.mark&&!l.layer&&!l.vconcat&&!l.hconcat&&!l.facet&&!l.repeat&&!l.transform)throw new Error("Invalid Vega-Lite specification: missing mark or composition");const t=e.getBoundingClientRect(),n=Math.max(t.width-40,400),i=Math.max(t.height||400,300);if(l.width||0===l.width||(l.width=n),l.height||0===l.height||l.vconcat||l.hconcat||l.facet||(l.height=Math.min(.8*i,500)),l.autosize?l.autosize&&"object"===typeof l.autosize&&(l.autosize=(0,o.A)({},l.autosize)):l.autosize={type:"fit",contains:"content"},(l.width&&l.width>0||l.height&&l.height>0)&&(l.autosize={type:"fit",contains:"content"}),l.layer&&l.layer.forEach((e=>{var t,n;null!==(t=e.encoding)&&void 0!==t&&t.x&&!e.encoding.x.axis&&(e.encoding.x.axis={labelAngle:0,labelLimit:0,labelFontSize:11}),null!==(n=e.encoding)&&void 0!==n&&n.y&&!e.encoding.y.axis&&(e.encoding.y.axis={labelLimit:0,labelFontSize:11})})),l.$schema||(l.$schema="https://vega.github.io/schema/vega-lite/v5.json"),null!==(w=l.encoding)&&void 0!==w&&w.theta&&null!==(k=l.encoding)&&void 0!==k&&k.radius&&(l.mark={type:"arc",innerRadius:20,outerRadius:100},l.encoding={theta:{field:"level",type:"quantitative",scale:{type:"linear",range:[0,6.28]}},radius:{field:"level",type:"quantitative",scale:{type:"linear",range:[20,100]}},color:{field:"skill",type:"nominal"},tooltip:[{field:"skill",type:"nominal"},{field:"level",type:"quantitative",title:"Mastery Level"}]}),l.transform&&l.transform.some((e=>e.density))){if(console.log("Processing violin plot specification"),l.encoding){if(l.encoding.x&&l.encoding.y&&("value"!==l.encoding.x.field||"density"!==l.encoding.y.field)){var Z,ee,te;console.log("Fixing violin plot field mappings for density transform");const e=null===(Z=l.transform.find((e=>e.density)))||void 0===Z||null===(ee=Z.groupby)||void 0===ee?void 0:ee[0];l.encoding=(0,o.A)((0,o.A)((0,o.A)({x:{field:"value",type:"quantitative",title:(null===(te=l.encoding.y)||void 0===te?void 0:te.title)||"Value"},y:{field:"density",type:"quantitative",title:"Density"}},e&&l.encoding.color&&{color:(0,o.A)((0,o.A)({},l.encoding.color),{},{field:e})}),e&&l.encoding.column&&{column:(0,o.A)((0,o.A)({},l.encoding.column),{},{field:e})}),e&&l.encoding.row&&{row:(0,o.A)((0,o.A)({},l.encoding.row),{},{field:e})})}}(!l.mark||"string"===typeof l.mark&&"area"===l.mark)&&(l.mark={type:"area",opacity:.7})}l.width&&l.width<200&&(l.width=400),l.height&&l.height<250&&(l.height=300);const s=e=>{if(e&&"object"===typeof e){if(Array.isArray(e))return e.map(s);{const t={};for(const[n,o]of Object.entries(e))"signal"===n&&"string"===typeof o&&o.includes("tier_focus")?console.log("Removing invalid signal reference:",o):t[n]=s(o);return t}}return e};var ne,oe;if(l=s(l),l.mark&&("rect"===l.mark.type||"rect"===l.mark)&&l.params&&l.params.some((e=>e.bind&&"select"===e.bind.input))&&l.transform&&l.transform.some((e=>e.aggregate))&&l.encoding&&l.encoding.y&&!l.encoding.x&&!l.encoding.color&&(console.log("Fixing treemap chart x and color encodings"),l.encoding.x={field:"total_budget",type:"quantitative",title:"Budget"},l.encoding.color={field:"display_category",type:"nominal",title:"Category"}),l.transform&&null!==(S=l.data)&&void 0!==S&&S.values&&null!==(E=l.data.values[0])&&void 0!==E&&E.lat&&null!==(A=l.data.values[0])&&void 0!==A&&A.lon)console.log("Fixing population density plot sequence and coordinates"),l.transform.forEach((e=>{e.calculate&&e.calculate.includes("datum.count")&&(e.calculate=e.calculate.replace("datum.count","datum.dot_count"),console.log("Fixed sequence transform to use dot_count"))})),!l.encoding||"lat"!==(null===(ne=l.encoding.x)||void 0===ne?void 0:ne.field)&&"lon"!==(null===(oe=l.encoding.y)||void 0===oe?void 0:oe.field)||(l.encoding.x={field:"jittered_lon",type:"quantitative",axis:null},l.encoding.y={field:"jittered_lat",type:"quantitative",axis:null},console.log("Fixed x/y encodings to use jittered coordinates"));if(l.transform&&l.transform.some((e=>e.sequence&&e.sequence.stop&&e.sequence.stop.expr))){console.log("Fixing sequence transform with expression");const e=l.transform.findIndex((e=>e.sequence));if(e>=0){const t=l.transform[e];l.transform[e]={flatten:[t.as||"unit"]},l.transform.splice(e,0,{calculate:"sequence(1, datum.count + 1)",as:t.as||"unit"})}}if(l.transform&&Array.isArray(l.transform)&&l.transform.forEach(((e,t)=>{if(e.calculate&&e.calculate.includes("indexOf(")){console.log("Fixing indexOf usage in transform ".concat(t,": ").concat(e.calculate));let n=e.calculate.replace(/indexOf\(\[([^\]]+)\],\s*([^)]+)\)/g,((e,t,n)=>{console.log("Match found: ".concat(e,", Array: ").concat(t,", Field: ").concat(n));const o=t.split(",").map((e=>e.trim().replace(/['"]/g,"")));console.log("Parsed items:",o);const r=o.map(((e,t)=>"".concat(n.trim()," == '").concat(e,"' ? ").concat(t))).join(" : "),i="(".concat(r," : -1)");return console.log("Generated replacement: ".concat(i)),i}));e.calculate=n,console.log("Final calculate: ".concat(n))}})),null!==(C=l.encoding)&&void 0!==C&&C.strokeDash&&"nominal"===l.encoding.strokeDash.type&&!l.encoding.strokeDash.scale&&(console.log("Fixing strokeDash encoding scale"),l.encoding.strokeDash.scale={range:[[1,0],[5,5]]}),l.transform&&Array.isArray(l.transform)){const e=l.transform.some((e=>e.window)),t=l.transform.some((e=>e.calculate&&e.calculate.includes("skill_index")));if(e&&t){console.log("Fixing radar chart transform order");const e=l.transform.filter((e=>e.window)),t=l.transform.filter((e=>!e.window));l.transform=[...e,...t]}}if(l.mark&&("bar"===l.mark.type||"bar"===l.mark)&&l.transform&&l.transform.some((e=>e.fold&&e.fold.includes("male")&&e.fold.includes("female")))&&l.encoding&&l.encoding.y&&!l.encoding.x&&!l.encoding.color&&(console.log("Fixing population pyramid chart x and color encodings"),l.encoding.x={field:"signed_population",type:"quantitative",title:"Population",axis:{format:"~s"}},l.encoding.color={field:"gender",type:"nominal",scale:{domain:["male","female"],range:["#4575b4","#d73027"]},title:"Gender"}),l.mark&&("bar"===l.mark.type||"bar"===l.mark)&&l.params&&l.params.some((e=>e.bind&&"select"===e.bind.input))&&l.transform&&l.transform.some((e=>e.calculate&&e.calculate.includes("drill_level")))&&l.encoding&&l.encoding.color&&!l.encoding.x&&!l.encoding.y&&(console.log("Fixing hierarchical drill-down chart x,y encodings"),l.encoding.x={field:"display_category",type:"nominal",title:"Category"},l.encoding.y={field:"total_value",type:"quantitative",title:"Value"}),!l.mark||"rect"!==l.mark.type&&"rect"!==l.mark||!l.transform||!l.transform.some((e=>e.aggregate&&e.groupby&&2===e.groupby.length&&e.groupby.every((e=>e.bin))))||!l.encoding||l.encoding.x||l.encoding.y||l.encoding.color||(console.log("Fixing 2D histogram x,y,color encodings"),l.encoding.x={field:"x_center",type:"quantitative",title:"X"},l.encoding.y={field:"y_center",type:"quantitative",title:"Y"},l.encoding.color={field:"count",type:"quantitative",scale:{scheme:"blues"},title:"Count"}),l.layer&&Array.isArray(l.layer)&&l.layer.forEach(((e,t)=>{e.transform&&e.transform.some((e=>e.density))&&e.mark&&("area"===e.mark.type||"area"===e.mark)&&e.encoding&&e.encoding.x&&"value"===e.encoding.x.field&&(console.log("Fixing violin layer ".concat(t," field references")),e.encoding.x={field:"value",type:"quantitative",title:e.encoding.x.title||"Value"},e.encoding.xOffset&&(delete e.encoding.xOffset,console.log("Removed xOffset from violin layer ".concat(t))))})),l.facet&&l.spec&&l.spec.layer&&l.spec.layer.some((e=>e.mark&&"arc"===e.mark.type))&&(console.log("Fixing multi-layer gauge chart encodings"),l.spec.layer.forEach(((e,t)=>{var n,o;e.mark&&"arc"===e.mark.type&&(e.mark.theta2&&null!==(n=e.encoding)&&void 0!==n&&null!==(o=n.color)&&void 0!==o&&o.value?(e.encoding.theta&&(delete e.encoding.theta,console.log("Removed theta encoding from background arc layer ".concat(t))),e.encoding.theta2&&(delete e.encoding.theta2,console.log("Removed theta2 encoding from background arc layer ".concat(t)))):e.encoding&&e.encoding.theta&&e.encoding.theta.field&&!e.encoding.theta2&&(e.encoding.theta2={value:0},console.log("Added theta2 to data arc layer ".concat(t))))}))),l.mark&&("circle"===l.mark.type||"circle"===l.mark)&&l.transform&&l.transform.some((e=>e.sequence))&&l.encoding&&l.encoding.x&&l.encoding.y&&("x"===l.encoding.x.field||"y"===l.encoding.y.field)&&null!==(M=l.data)&&void 0!==M&&M.values&&null!==(q=l.data.values[0])&&void 0!==q&&q.lat&&null!==(B=l.data.values[0])&&void 0!==B&&B.lon&&(console.log("Fixing geographic dot density plot x,y field references"),l.encoding.x={field:"jittered_lon",type:"quantitative",axis:null},l.encoding.y={field:"jittered_lat",type:"quantitative",axis:null}),l.mark&&("rect"===l.mark.type||"rect"===l.mark)&&l.encoding&&l.encoding.x&&"weekday"===l.encoding.x.field&&!l.encoding.y&&l.transform&&l.transform.some((e=>e.calculate&&e.calculate.includes("week(")))&&(console.log("Fixing annual calendar chart y-axis encoding"),l.encoding.y={field:"week",type:"ordinal",title:"Week of Year"}),l.mark&&("circle"===l.mark.type||"circle"===l.mark)&&l.transform&&l.transform.some((e=>e.aggregate&&e.groupby&&e.groupby.some((e=>e.bin))))&&l.encoding&&!l.encoding.x&&!l.encoding.y&&(console.log("Fixing hexbin plot x,y,size encodings"),l.encoding.x={field:"x_center",type:"quantitative",title:"X"},l.encoding.y={field:"y_center",type:"quantitative",title:"Y"},l.encoding.size={field:"count",type:"quantitative",title:"Count",scale:{range:[50,500]}}),l.mark&&("bar"===l.mark.type||"bar"===l.mark)&&l.encoding&&l.encoding.color&&!l.encoding.x&&!l.encoding.y&&null!==(z=l.data)&&void 0!==z&&z.values&&l.data.values.length>0){console.log("Fixing stacked bar chart x,y encodings");const e=l.data.values[0],t=Object.keys(e),n=t.find((t=>"string"===typeof e[t]&&t!==l.encoding.color.field)),o=t.find((t=>"number"===typeof e[t]&&(t.includes("revenue")||t.includes("value")||t.includes("amount"))));n&&o&&(l.encoding.x={field:n,type:"nominal",title:n.charAt(0).toUpperCase()+n.slice(1)},l.encoding.y={field:o,type:"quantitative",title:o.charAt(0).toUpperCase()+o.slice(1)})}if(l.mark&&("circle"===l.mark.type||"circle"===l.mark)&&l.transform&&l.transform.some((e=>e.calculate&&(e.calculate.includes("cos(")||e.calculate.includes("sin("))))&&l.encoding&&!l.encoding.x&&!l.encoding.y&&(console.log("Fixing spiral chart x,y encodings"),l.encoding.x={field:"x",type:"quantitative",axis:null},l.encoding.y={field:"y",type:"quantitative",axis:null}),l.mark&&("bar"===l.mark.type||"bar"===l.mark)&&l.transform&&l.transform.some((e=>e.fold&&e.fold.includes("positive")&&e.fold.includes("negative")))&&l.encoding&&l.encoding.y&&!l.encoding.x&&!l.encoding.color&&(console.log("Fixing diverging bar chart x and color encodings"),l.encoding.x={field:"value",type:"quantitative",title:"Value"},l.encoding.color={field:"sentiment",type:"nominal",scale:{domain:["positive","negative"],range:["#2ca02c","#d62728"]},title:"Sentiment"}),l.mark&&("point"===l.mark.type||"point"===l.mark||"circle"===l.mark.type)&&null!==($=l.data)&&void 0!==$&&$.values&&(null===(W=l.encoding)||void 0===W||!W.x)&&(null===(P=l.encoding)||void 0===P||!P.y)){console.log("Fixing scatter plot x,y encodings");const e=l.data.values[0],t=Object.keys(e).filter((t=>"number"===typeof e[t]));t.length>=2&&(l.encoding=l.encoding||{},l.encoding.x={field:t[0],type:"quantitative"},l.encoding.y={field:t[1],type:"quantitative"})}if(l.mark&&("line"===l.mark.type||"line"===l.mark)&&null!==(V=l.data)&&void 0!==V&&V.values&&(null===(j=l.encoding)||void 0===j||!j.x)&&(null===(H=l.encoding)||void 0===H||!H.y)&&(null===(U=l.transform)||void 0===U||!U.some((e=>e.fold)))){console.log("Fixing line chart x,y encodings");const e=l.data.values[0],t=Object.keys(e),n=t.find((t=>e[t]&&(t.includes("date")||t.includes("time")||"string"===typeof e[t]&&e[t].match(/\d{4}-\d{2}-\d{2}/)))),o=t.find((t=>"number"===typeof e[t]));n&&o&&(l.encoding=l.encoding||{},l.encoding.x={field:n,type:"temporal"},l.encoding.y={field:o,type:"quantitative"})}if(l.mark&&("rect"===l.mark.type||"rect"===l.mark)&&null!==(X=l.encoding)&&void 0!==X&&X.color&&(null===(G=l.encoding)||void 0===G||!G.x)&&(null===(Y=l.encoding)||void 0===Y||!Y.y)&&(null===(J=l.transform)||void 0===J||!J.some((e=>e.calculate&&(e.calculate.includes("day(")||e.calculate.includes("week(")))))){var re,ie;console.log("Fixing heatmap x,y encodings");const e=null===(re=l.data)||void 0===re||null===(ie=re.values)||void 0===ie?void 0:ie[0];if(e){const t=Object.keys(e).filter((t=>"string"===typeof e[t]||"number"===typeof e[t]));t.length>=2&&(l.encoding.x={field:t[0],type:"nominal"},l.encoding.y={field:t[1],type:"nominal"})}}if(l.mark&&("area"===l.mark.type||"area"===l.mark)&&l.transform&&l.transform.some((e=>e.density))&&l.encoding&&!l.encoding.x&&!l.encoding.y&&(console.log("Fixing violin plot x,y encodings"),l.encoding.x={field:"value",type:"quantitative",title:"Response Time"},l.encoding.y={field:"density",type:"quantitative",title:"Density"}),"bar"===l.mark&&l.encoding&&l.encoding.x&&l.encoding.x.bin&&l.encoding.y&&"count"===l.encoding.y.aggregate&&(console.log("Fixing histogram aggregate count encoding"),l.encoding.y={aggregate:"count",type:"quantitative",title:l.encoding.y.title||"Count"},delete l.encoding.y.field),l.mark&&("rect"===l.mark.type||"rect"===l.mark)&&l.transform&&l.transform.some((e=>e.calculate&&(e.calculate.includes("day(")||e.calculate.includes("week("))))&&l.encoding&&l.encoding.color&&!l.encoding.x&&!l.encoding.y&&(console.log("Fixing calendar heatmap x,y encodings"),l.encoding.x={field:"day",type:"ordinal",title:"Day of Week"},l.encoding.y={field:"week",type:"ordinal",title:"Week"}),l.mark&&("line"===l.mark.type||"line"===l.mark)&&l.transform&&l.transform.some((e=>e.fold))&&l.encoding&&l.encoding.detail&&!l.encoding.x&&!l.encoding.y&&(console.log("Fixing parallel coordinates chart x,y encodings"),l.encoding.x={field:"dimension",type:"nominal",title:"Dimensions"},l.encoding.y={field:"value",type:"quantitative",title:"Value"}),l.mark&&("circle"===l.mark.type||"circle"===l.mark)&&l.transform&&l.transform.some((e=>e.sequence))&&l.encoding&&!l.encoding.x&&!l.encoding.y&&(console.log("Fixing isotope chart x,y encodings"),l.encoding.x={field:"x",type:"ordinal",axis:null},l.encoding.y={field:"y",type:"ordinal",axis:null}),"bar"===l.mark&&l.transform&&l.transform.some((e=>e.window&&e.window.some((e=>"sum"===e.op))))&&l.encoding&&l.encoding.x&&!l.encoding.y&&(console.log("Fixing waterfall chart y-axis encoding"),l.encoding.y={field:"previous_sum",type:"quantitative",title:"Value"},l.encoding.y2={field:"sum",type:"quantitative"}),l.mark&&("bar"===l.mark||"bar"===l.mark.type)&&l.encoding&&l.encoding.x&&!l.encoding.y){var ae,se;console.log("Fixing bar chart missing y-axis encoding");const e=null===(ae=l.transform)||void 0===ae||null===(se=ae.find((e=>e.calculate&&e.as)))||void 0===se?void 0:se.as,t=["flow","source","target","category","group"];let n=e;var ce;if(!n)if(null!==(ce=l.data)&&void 0!==ce&&ce.values&&l.data.values.length>0){const e=l.data.values[0];n=t.find((t=>e.hasOwnProperty(t)))}n&&(l.encoding.y={field:n,type:"nominal",title:n.charAt(0).toUpperCase()+n.slice(1)},console.log("Added y-axis encoding with field: ".concat(n)))}if((l.layer||l.facet||l.vconcat||l.hconcat)&&l.params){const e=l.params.filter((e=>e.select));if(e.length>0){console.log("Found top-level selection parameters in composite chart, applying fix");const t=JSON.parse(JSON.stringify(l));delete t.params,t.layer?(t.layer[0].params||(t.layer[0].params=[]),t.layer[0].params.push(...e),console.log("Moved selection parameters to first layer")):t.facet?(t.spec.params||(t.spec.params=[]),t.spec.params.push(...e),console.log("Moved selection parameters to facet spec")):t.vconcat?(t.vconcat[0].params||(t.vconcat[0].params=[]),t.vconcat[0].params.push(...e),console.log("Moved selection parameters to first vconcat view")):t.hconcat&&(t.hconcat[0].params||(t.hconcat[0].params=[]),t.hconcat[0].params.push(...e),console.log("Moved selection parameters to first hconcat view")),l=t}}if(l.facet&&l.transform&&!l.spec){console.log("Found top-level facet with transforms, moving transforms to spec"),console.log("Original spec:",JSON.stringify(l,null,2));const{facet:e,transform:t,layer:n,mark:r,encoding:i}=l,a=(0,L.A)(l,R),s=(0,o.A)((0,o.A)({},a),{},{facet:e,spec:(0,o.A)((0,o.A)((0,o.A)({transform:t},n&&{layer:n}),r&&{mark:r}),i&&{encoding:i})});l=s,console.log("Corrected facet specification structure:"),console.log("New spec:",JSON.stringify(l,null,2))}if(null!==(K=l.encoding)&&void 0!==K&&K.facet){console.log("Found facet in encoding, moving to top level"),console.log("Original spec:",JSON.stringify(l,null,2));const e=l.encoding.facet,{mark:t,encoding:n}=l,r=(0,L.A)(l,I),i=(0,o.A)({},n);delete i.facet;const a=(0,o.A)((0,o.A)({},r),{},{facet:e,spec:{mark:t,encoding:i}});l=a,console.log("Corrected facet specification structure:"),console.log("New spec:",JSON.stringify(l,null,2))}const c=e=>{var t;const n=e.height||400,r=.6*n,i=Math.floor(r/20);console.log("Legend optimization: Chart height=".concat(n,", Max legend height=").concat(r,", Max items per column=").concat(i));const a=(e,t,n)=>{if(!e[t]||!e[t].field)return;const r=e[t].field,a=((e,t)=>{if(!t||!Array.isArray(t))return 0;const n=new Set;return t.forEach((t=>{void 0!==t[e]&&null!==t[e]&&n.add(t[e])})),n.size})(r,n);if(a>i){const n=Math.ceil(a/i),s=Math.min(n,3);console.log("Applying legend wrapping to ".concat(t,' field "').concat(r,'": ').concat(a," items -> ").concat(s," columns")),e[t].legend||(e[t].legend={}),e[t].legend=(0,o.A)((0,o.A)({},e[t].legend),{},{columns:s,symbolLimit:0,labelLimit:80,titleLimit:100,orient:"bottom",offset:5,padding:3,rowPadding:2,columnPadding:6})}},s=(null===(t=e.data)||void 0===t?void 0:t.values)||[];e.encoding&&["color","fill","stroke","shape","size","opacity"].forEach((t=>{a(e.encoding,t,s)})),e.layer&&Array.isArray(e.layer)&&e.layer.forEach(((e,t)=>{if(e.encoding){var n;const t=(null===(n=e.data)||void 0===n?void 0:n.values)||s;["color","fill","stroke","shape","size","opacity"].forEach((n=>{a(e.encoding,n,t)}))}}))};c(l),0!==l.width&&0!==l.height||(delete l.width,delete l.height),l.resolve&&l.resolve.scale&&delete l.resolve;const d=(0,o.A)((0,o.A)((0,o.A)({actions:!1,theme:r?"dark":"excel",renderer:"svg",scaleFactor:1},(!l.width||0===l.width)&&{width:n}),(!l.height||0===l.height)&&{height:.6*i}),{},{config:{view:(0,o.A)((0,o.A)((0,o.A)({},(!l.width||0===l.width)&&{continuousWidth:n}),(!l.height||0===l.height)&&{continuousHeight:.6*i}),{},{stroke:"transparent"})}});if(l.encoding&&0===Object.keys(l.encoding).length)throw new Error("Invalid Vega-Lite specification: all encoding channels were invalid and removed");(l.vconcat||l.hconcat||l.facet)&&(e.style.minHeight="".concat(i,"px"));try{a&&a.parentNode&&e.removeChild(a)}catch(me){console.warn("Could not remove loading spinner (this is normal for multiple renders):",me instanceof Error?me.message:String(me))}const f=document.createElement("div");f.style.width="100%",f.style.maxWidth="100%",f.style.overflow="hidden",f.style.boxSizing="border-box",e.appendChild(f);const h=l,F=JSON.parse(JSON.stringify(h));console.log("Vega-Lite: About to call vegaEmbed with finalSpec:",F),F.transform&&F.transform.some((e=>e.density))&&console.log("Final spec being sent to vega-embed for violin plot:",JSON.stringify(F,null,2));try{var le,de;if(F.encoding&&null!==(le=F.data)&&void 0!==le&&le.values&&Array.isArray(F.data.values)&&F.data.values.length>0){const e=new Set;Object.keys(F.data.values[0]).forEach((t=>e.add(t))),Object.values(F.encoding).forEach((t=>{null===t||void 0===t||!t.field||e.has(t.field)||F.transform||console.warn("Field '".concat(t.field,"' referenced in encoding but not found in data"))}))}else F.transform?console.log("Spec uses transforms, skipping field validation"):null!==(de=F.data)&&void 0!==de&&de.url?console.log("Spec uses external data, skipping field validation"):console.log("Skipping field validation for this spec type")}catch(fe){console.warn("Spec validation warning:",fe)}const N=await(0,T.Ay)(f,F,d);console.log("Vega-Lite: vegaEmbed completed successfully:",N),F.transform&&F.transform.some((e=>e.density))&&(console.log("Violin plot vega-embed result:",N),console.log("Violin plot SVG element:",f.querySelector("svg")),console.log("Violin plot container dimensions:",f.getBoundingClientRect())),e._vegaView=N.view,setTimeout((()=>{const t=f.querySelector(".vega-embed");if(t){const n=t.offsetHeight;t.offsetWidth;let o=e.parentElement;for(;o&&o.classList.contains("d3-container");){const e=o;e.offsetHeight<n&&(e.style.height="".concat(n+20,"px"),e.style.minHeight="".concat(n+20,"px")),o=o.parentElement}}}),100);const D=()=>{const t=f.querySelector(".vega-embed"),n=f.querySelector("svg");if(console.log("Setting up Vega-Lite specific resizing:",{vegaEmbedDiv:!!t,vegaSvg:!!n,renderContainer:f.getBoundingClientRect(),container:e.getBoundingClientRect()}),t||n){const o=t||n;new ResizeObserver((t=>{for(const n of t){const t=n.contentRect.height,o=n.contentRect.width;console.log("Vega-Lite element resized: ".concat(o,"x").concat(t));let r=e.parentElement;for(;r&&(r.classList.contains("d3-container")||r.classList.contains("vega-lite-container"));){const e=r,n=e.getBoundingClientRect().height;console.log("Parent ".concat(e.className,": current=").concat(n,", needed=").concat(t+40)),n<t+40&&(e.style.height="".concat(t+40,"px"),e.style.minHeight="".concat(t+40,"px"),e.style.overflow="visible",console.log("Updated parent ".concat(e.className," height to ").concat(t+40,"px"))),r=r.parentElement}}})).observe(o),console.log("Vega-Lite resize observer attached to:",o.tagName,o.className)}},O=new MutationObserver((e=>{e.forEach((e=>{"childList"===e.type&&e.addedNodes.forEach((e=>{if(e.nodeType===Node.ELEMENT_NODE){const t=e;(t.classList.contains("vega-embed")||"svg"===t.tagName.toLowerCase())&&(console.log("Vega-Lite element added via mutation observer:",t.tagName,t.className),setTimeout(D,100))}}))}))}));O.observe(f,{childList:!0,subtree:!0}),setTimeout((()=>{O.disconnect()}),5e3),setTimeout(D,100),setTimeout(D,500),setTimeout(D,1e3),setTimeout((()=>{const t=f.querySelector(".vega-embed");if(t){const n=t.getBoundingClientRect();console.log("Immediate Vega-Lite size check:",n);let o=e.parentElement;for(;o&&o.classList.contains("d3-container");){const e=o.getBoundingClientRect();console.log("Parent ".concat(o.className," size:"),e),e.height<n.height+40&&(o.style.height="".concat(n.height+40,"px"),o.style.minHeight="".concat(n.height+40,"px"),console.log("Immediately adjusted parent ".concat(o.className," to ").concat(n.height+40,"px"))),o=o.parentElement}}}),200);const ge=f.querySelector(".vega-embed"),pe=document.createElement("div");pe.className="diagram-actions",pe.style.cssText="\n position: absolute;\n top: -4px;\n right: 8px;\n z-index: 1000;\n opacity: 0;\n transition: opacity 0.2s ease-in-out;\n ",e.style.position="relative";const ue=document.createElement("button");ue.innerHTML="\u2197\ufe0f Open",ue.className="diagram-action-button vega-lite-open-button",ue.onclick=()=>{let t=null===ge||void 0===ge?void 0:ge.querySelector("svg");if(t||(t=e.querySelector("svg")),!t)return;console.log("Opening Vega-Lite visualization in popup");const n=t;let o=800,i=600;try{const e=n.getBBox();o=Math.max(e.width+100,600),i=Math.max(e.height+150,400)}catch(me){console.warn("Could not get SVG dimensions, using defaults",me)}const a=(new XMLSerializer).serializeToString(t),s='\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset="UTF-8">\n <title>Vega-Lite Visualization</title>\n <style>\n :root {\n --bg-color: #f8f9fa;\n --text-color: #212529;\n --toolbar-bg: #f1f3f5;\n --toolbar-border: #dee2e6;\n --button-bg: #4361ee;\n --button-hover: #3a0ca3;\n }\n \n [data-theme="dark"] {\n --bg-color: #212529;\n --text-color: #f8f9fa;\n --toolbar-bg: #343a40;\n --toolbar-border: #495057;\n --button-bg: #4361ee;\n --button-hover: #5a72f0;\n }\n \n body {\n margin: 0;\n padding: 0;\n display: flex;\n flex-direction: column;\n height: 100vh;\n background-color: var(--bg-color);\n color: var(--text-color);\n font-family: system-ui, -apple-system, sans-serif;\n transition: background-color 0.3s ease, color 0.3s ease;\n }\n \n .toolbar {\n background-color: var(--toolbar-bg);\n border-bottom: 1px solid var(--toolbar-border);\n padding: 8px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n transition: background-color 0.3s ease, border-color 0.3s ease;\n }\n \n .toolbar button {\n background-color: var(--button-bg);\n color: white;\n border: none;\n border-radius: 4px;\n padding: 6px 12px;\n cursor: pointer;\n margin-right: 8px;\n font-size: 14px;\n transition: background-color 0.3s ease;\n }\n \n .toolbar button:hover {\n background-color: var(--button-hover);\n }\n \n .theme-toggle {\n background-color: transparent;\n border: 1px solid var(--text-color);\n color: var(--text-color);\n padding: 4px 8px;\n font-size: 12px;\n }\n \n .theme-toggle:hover {\n background-color: var(--text-color);\n color: var(--bg-color);\n }\n \n .container {\n flex: 1;\n display: flex;\n justify-content: center;\n align-items: center;\n overflow: auto;\n padding: 20px;\n }\n \n svg {\n max-width: 100%;\n max-height: 100%;\n height: auto;\n width: auto;\n transition: all 0.3s ease;\n }\n </style>\n </head>\n <body data-theme="'.concat(r?"dark":"light",'">\n <div class="toolbar">\n <div>\n <button onclick="zoomIn()">Zoom In</button>\n <button onclick="zoomOut()">Zoom Out</button>\n <button onclick="resetZoom()">Reset</button>\n <button class="theme-toggle" onclick="toggleTheme()">').concat(r?"\u2600\ufe0f Light":"\ud83c\udf19 Dark",'</button>\n </div>\n <div>\n <button onclick="downloadSvg()">Download SVG</button>\n <button onclick="downloadSpec()">Download Spec</button>\n </div>\n </div>\n <div class="container" id="svg-container">\n ').concat(a,"\n </div>\n <script>\n const svg = document.querySelector('svg');\n let currentScale = 1;\n let isDarkMode = ").concat(r,";\n \n // Store the original Vega-Lite spec\n const vegaSpec = ").concat(JSON.stringify(l,null,2),";\n \n // Make sure SVG is responsive\n svg.setAttribute('width', '100%');\n svg.setAttribute('height', '100%');\n svg.style.maxWidth = '100%';\n svg.style.maxHeight = '100%';\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n \n function zoomIn() {\n currentScale *= 1.2;\n svg.style.transform = `scale(${currentScale})`;\n }\n \n function zoomOut() {\n currentScale /= 1.2;\n svg.style.transform = `scale(${currentScale})`;\n }\n \n function resetZoom() {\n currentScale = 1;\n svg.style.transform = 'scale(1)';\n }\n \n function toggleTheme() {\n isDarkMode = !isDarkMode;\n const body = document.body;\n const themeButton = document.querySelector('.theme-toggle');\n \n if (isDarkMode) {\n body.setAttribute('data-theme', 'dark');\n themeButton.textContent = '\u2600\ufe0f Light';\n } else {\n body.setAttribute('data-theme', 'light');\n themeButton.textContent = '\ud83c\udf19 Dark';\n }\n \n // Re-render Vega-Lite visualization with new theme\n reRenderVegaVisualization();\n }\n \n function reRenderVegaVisualization() {\n const container = document.getElementById('svg-container');\n if (!container) return;\n \n // Clear the container\n container.innerHTML = '';\n \n // Import vega-embed dynamically in the popup\n import('https://cdn.jsdelivr.net/npm/vega-embed@6').then(vegaEmbedModule => {\n const vegaEmbed = vegaEmbedModule.default || vegaEmbedModule;\n \n // Re-render with new theme\n vegaEmbed(container, vegaSpec, {\n actions: false,\n theme: isDarkMode ? 'dark' : 'excel',\n renderer: 'svg',\n scaleFactor: 1\n }).then(result => {\n // Make sure SVG is responsive\n const svg = container.querySelector('svg');\n if (svg) {\n svg.setAttribute('width', '100%');\n svg.setAttribute('height', '100%');\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n }\n });\n });\n }\n \n function downloadSvg() {\n const svgData = new XMLSerializer().serializeToString(svg);\n const svgDoc = `<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n${svgData}`;\n \n const svgBlob = new Blob([svgDoc], {type: 'image/svg+xml'});\n const url = URL.createObjectURL(svgBlob);\n \n const link = document.createElement('a');\n link.href = url;\n link.download = 'vega-lite-visualization-").concat(Date.now(),".svg';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n \n setTimeout(() => URL.revokeObjectURL(url), 1000);\n }\n \n function downloadSpec() {\n const specBlob = new Blob([JSON.stringify(vegaSpec, null, 2)], {type: 'application/json'});\n const url = URL.createObjectURL(specBlob);\n \n const link = document.createElement('a');\n link.href = url;\n link.download = 'vega-lite-spec-").concat(Date.now(),".json';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n \n setTimeout(() => URL.revokeObjectURL(url), 1000);\n }\n <\/script>\n </body>\n </html>\n "),c=new Blob([s],{type:"text/html"}),d=URL.createObjectURL(c),g=window.open(d,"VegaLiteVisualization","width=".concat(o,",height=").concat(i,",resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no"));g?(g.focus(),console.log("Popup window opened successfully")):(console.error("Failed to open popup window - popup blocked?"),alert("Popup blocked! Please allow popups for this site to open the visualization.")),setTimeout((()=>URL.revokeObjectURL(d)),1e4)},pe.appendChild(ue);const he=document.createElement("button");he.innerHTML="\ud83d\udcbe Save",he.className="diagram-action-button vega-lite-save-button",he.onclick=()=>{let t=null===ge||void 0===ge?void 0:ge.querySelector("svg");if(t||(t=e.querySelector("svg")),!t)return;console.log("Saving Vega-Lite visualization as SVG");const n=(new XMLSerializer).serializeToString(t),o='<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'.concat(n),r=new Blob([o],{type:"image/svg+xml"}),i=URL.createObjectURL(r),a=document.createElement("a");a.href=i,a.download="vega-lite-visualization-".concat(Date.now(),".svg"),document.body.appendChild(a),console.log("Triggering download for:",a.download),a.click(),document.body.removeChild(a),setTimeout((()=>URL.revokeObjectURL(i)),1e3)},pe.appendChild(he);let ye=!1;const be=ge,ve=document.createElement("button");ve.innerHTML=ye?"\ud83c\udfa8 View":"\ud83d\udcdd Source",ve.className="diagram-action-button vega-lite-source-button",ve.onclick=()=>{if(ye=!ye,ve.innerHTML=ye?"\ud83c\udfa8 View":"\ud83d\udcdd Source",ye){be&&(ge.style.display="none");const t=document.createElement("pre");t.style.cssText="\n background-color: ".concat(r?"#1f1f1f":"#f6f8fa",";\n padding: 16px;\n border-radius: 4px;\n overflow: auto;\n width: 100%;\n height: auto;\n max-height: 80vh;\n margin: 0;\n box-sizing: border-box;\n color: ").concat(r?"#e6e6e6":"#24292e",";\n "),t.innerHTML="<code>".concat(JSON.stringify(l,null,2),"</code>"),e.innerHTML="",e.appendChild(t);let n=e.parentElement;for(;n&&(n.classList.contains("d3-container")||n.classList.contains("vega-lite-renderer-container"));){const e=n;e.style.height="auto",e.style.minHeight="auto",e.style.overflow="auto",n=n.parentElement}pe.parentNode!==e&&e.insertBefore(pe,e.firstChild)}else{const t=e.querySelector("pre");t&&e.removeChild(t),be?(be.style.display="",be.parentNode!==e&&e.appendChild(be)):(0,T.Ay)(e,l,d),e.insertBefore(pe,e.firstChild);let n=e.parentElement;for(;n&&(n.classList.contains("d3-container")||n.classList.contains("vega-lite-renderer-container"));){n.style.height="",n=n.parentElement}}},pe.appendChild(ve),e.style.position="relative",e.insertBefore(pe,e.firstChild),e.addEventListener("mouseenter",(()=>pe.style.opacity="1")),e.addEventListener("mouseleave",(()=>pe.style.opacity="0")),setTimeout((()=>{const t=e.querySelector("svg"),n=e.querySelector(".vega-embed"),o=e.querySelector("svg"),r=e.querySelector(".vega-embed");if(o&&r){const e=r.getBoundingClientRect(),t=o.getBoundingClientRect(),n=e.width/t.width,i=e.height/t.height,a=Math.min(n,i);if(a>1.2){const e=Math.min(a,2.5);o.style.transform="scale(".concat(e,")"),o.style.transformOrigin="center center",console.log("Scaled SVG by ".concat(e,"x to reduce wasted space"))}}const i=e.querySelector("svg"),a=e.querySelector(".vega-embed");if(i&&a&&(i.style.width="100%",i.style.height="100%",i.removeAttribute("width"),i.removeAttribute("height"),i.setAttribute("preserveAspectRatio","xMidYMid meet"),console.log("Made SVG responsive to fill vega-embed container")),n&&(n.style.maxWidth="100%",n.style.overflow="hidden"),t){const n=l.width&&l.width>0,o=l.height&&l.height>0;n||(t.style.width="100%",t.style.maxWidth="100%"),o||(t.style.height="auto"),t.style.display="block",console.log(">>> vegaLitePlugin: SVG sizing applied:",{svgWidth:t.style.width,containerWidth:e.getBoundingClientRect().width,svgRect:t.getBoundingClientRect()})}if(n){l.width&&l.width>0||(n.style.width="100%",n.style.maxWidth="100%")}let s=e.parentElement;for(;s&&s.classList.contains("d3-container");)s.style.width="100%",s.style.maxWidth="100%",s=s.parentElement;if(window.debugVegaLite={container:e,svgElement:t,vegaEmbedDiv:n,getSVGActualSize:()=>{if(!t)return null;const e=t.getBoundingClientRect(),n=t.getAttribute("viewBox"),[o,r,i,a]=n?n.split(" ").map(Number):[0,0,0,0];return{actualWidth:e.width,actualHeight:e.height,viewBoxWidth:i,viewBoxHeight:a,scaleRatio:e.width/i}},inspect:()=>{console.log("=== Vega-Lite Debug Info ==="),console.log("Container:",e),console.log("SVG Element:",t),console.log("Vega Embed Div:",n),t&&(console.log("SVG getBoundingClientRect():",t.getBoundingClientRect()),console.log("SVG viewBox:",t.getAttribute("viewBox")),console.log("SVG style:",t.style.cssText),console.log("SVG computed style:",window.getComputedStyle(t))),n&&(console.log("Embed div getBoundingClientRect():",n.getBoundingClientRect()),console.log("Embed div style:",n.style.cssText),console.log("Embed div computed style:",window.getComputedStyle(n))),console.log("Container getBoundingClientRect():",e.getBoundingClientRect());const o=null===t||void 0===t?void 0:t.getBoundingClientRect(),r=e.getBoundingClientRect();o&&r&&console.log("SVG overflow check:",{svgBottom:o.bottom,containerBottom:r.bottom,isOverflowing:o.bottom>r.bottom,overflowAmount:o.bottom-r.bottom});let i=e.parentElement,a=0;for(;i&&a<3;){const e=i.getBoundingClientRect();console.log("Parent level ".concat(a,":"),{element:i,className:i.className,rect:e,style:i.style.cssText,computedHeight:window.getComputedStyle(i).height}),i=i.parentElement,a++}}},console.log("Vega-Lite debugging available: window.debugVegaLite.inspect()"),t){const o=t.getAttribute("viewBox");let r=680,i=774;if(o){const[,,e,t]=o.split(" ").map(Number);r=e,i=t}else{const e=t.getAttribute("width"),n=t.getAttribute("height");e&&n&&(r=parseFloat(e),i=parseFloat(n))}console.log("SVG content dimensions:",{svgWidth:r,svgHeight:i,viewBox:o});const a=l.width&&l.width>0,s=l.height&&l.height>0;if(a||(t.style.width="100%",t.style.maxWidth="100%"),s||(t.style.height="auto"),t.style.overflow="visible",n){if(!s){const e=n.getBoundingClientRect().width,t=i/r,o=e*t;n.style.height="".concat(o,"px"),n.style.minHeight="".concat(o,"px"),console.log("Container sizing:",{containerWidth:e,aspectRatio:t,neededHeight:o})}n.style.display="block",n.style.overflow="visible"}const c=()=>{const n=t.getBoundingClientRect().height;let o=e.parentElement;for(;o&&o.classList.contains("d3-container");){const e=o;e.getBoundingClientRect().height<n+40&&(e.style.height="".concat(n+40,"px"),e.style.minHeight="".concat(n+40,"px"),console.log("Force resized parent ".concat(e.className," to ").concat(n+40,"px"))),o=o.parentElement}};if(setTimeout(c,100),setTimeout(c,500),!s){let t=e.parentElement;for(;t;){if(t.classList.contains("vega-lite-renderer-container")){t.style.height="auto",t.style.minHeight="".concat(i,"px"),t.style.overflow="visible",console.log("Updated Vega-Lite parent container:",t.className,"to height: auto, minHeight:",i);break}t=t.parentElement}}(l.vconcat||l.hconcat||l.facet)&&(t.setAttribute("preserveAspectRatio","xMidYMid meet"),setTimeout((()=>{e.style.display="none",e.offsetHeight,e.style.display=""}),100)),console.log("Vega-Lite visualization rendered successfully")}}),100)}catch(he){console.error("Vega-Lite rendering error:",he),console.log("Vega-Lite error context:",{isStreaming:n.isStreaming,isMarkdownBlockClosed:n.isMarkdownBlockClosed,forceRender:n.forceRender});const i=he instanceof Error&&(he.message.includes("Unterminated string")||he.message.includes("Unexpected end of JSON input")||he.message.includes("Unexpected token")),a=n.definition&&!N(n.definition);if(!n.forceRender&&(n.isStreaming&&!n.isMarkdownBlockClosed||n.isStreaming&&a)||!n.definition||0===n.definition.trim().length||i&&!n.forceRender){var ge,pe;console.debug("Suppressing Vega-Lite streaming error:",he instanceof Error?he.message:String(he));const i=document.createElement("div");i.style.cssText="\n text-align: center; \n padding: 20px; \n background-color: ".concat(r?"#1f1f1f":"#f6f8fa","; \n border: 1px dashed #ccc; \n border-radius: 4px;\n position: relative;\n "),i.innerHTML='\n <p>Waiting for complete Vega-Lite specification...</p>\n <div style="margin-top: 15px;">\n <button class="vega-lite-force-retry-btn" style="\n background-color: #dc3545;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 0 5px;\n cursor: pointer;\n font-size: 14px;\n ">\ud83d\udd04 Force Render Anyway</button>\n <button id="vega-lite-debug-source-'.concat(Date.now(),'" style="\n background-color: #6c757d;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 0 5px;\n cursor: pointer;\n font-size: 14px;\n ">\ud83d\udd0d Debug Source</button>\n </div>\n <div style="margin-top: 10px; font-size: 12px; color: ').concat(r?"#8b949e":"#656d76",';">\n Error: ').concat(he instanceof Error?he.message:String(he),"\n </div>\n "),e.innerHTML="",e.appendChild(i);const a=null===(ge=i.querySelector('[id^="vega-lite-force-retry-"]'))||void 0===ge?void 0:ge.id,s=null===(pe=i.querySelector('[id^="vega-lite-debug-source-"]'))||void 0===pe?void 0:pe.id;if(a){const i=document.getElementById(a);i&&(i.onclick=()=>{console.log("Force rendering Vega-Lite despite streaming error");const i=(0,o.A)((0,o.A)({},n),{},{forceRender:!0});D.render(e,t,i,r)})}if(s){const t=document.getElementById(s);t&&(t.onclick=()=>{O(e,n,r,he instanceof Error?he:new Error(String(he)))})}return}l&&l.transform&&l.transform.some((e=>e.density||e.kde))&&console.error("Violin plot specific error details:",{hasData:!!l.data,hasTransform:!!l.transform,hasMark:!!l.mark,transformTypes:l.transform.map((e=>Object.keys(e)))}),he instanceof Error&&console.error("Error details:",{message:he.message,stack:he.stack});try{const t=e.querySelector(".vega-lite-loading-spinner");t&&t.parentNode&&e.removeChild(t)}catch(me){console.warn("Could not remove loading spinner during error handling:",me instanceof Error?me.message:String(me))}!function(e,t,n,r){const i=t.definition||JSON.stringify(t,null,2),a=t.$schema&&(t.data||t.datasets)&&(t.mark||t.layer||t.vconcat||t.hconcat||t.facet||t.repeat);e.innerHTML='\n <div class="vega-lite-error" style="\n padding: 16px;\n margin: 16px 0;\n border-radius: 6px;\n background-color: '.concat(n?"#2a1f1f":"#fff2f0",";\n border: 1px solid ").concat(n?"#a61d24":"#ffa39e",";\n color: ").concat(n?"#ff7875":"#cf1322",';\n ">\n <div style="margin-bottom: 15px;">\n <strong>Vega-Lite Rendering Error:</strong>\n <p>').concat(r.message||"Unknown error",'</p>\n </div>\n \n <div style="margin-bottom: 15px;">\n <button class="vega-lite-retry-error-btn" style="\n background-color: #28a745;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 0 5px;\n cursor: pointer;\n font-size: 14px;\n ">\ud83d\udd04 Retry Rendering</button>\n <button class="vega-lite-show-source-btn" style="\n background-color: #007bff;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 0 5px;\n cursor: pointer;\n font-size: 14px;\n ">\ud83d\udcdd Show Source</button>\n <button class="vega-lite-force-render-btn" style="\n background-color: #dc3545;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 0 5px;\n cursor: pointer;\n font-size: 14px;\n ">\u26a1 Force Render</button>\n </div>\n \n <div style="font-size: 13px; color: ').concat(n?"#8b949e":"#656d76",';">\n <strong>Debug Info:</strong><br>\n \u2022 Streaming: ').concat(t.isStreaming?"Yes":"No","<br>\n \u2022 Block Closed: ").concat(t.isMarkdownBlockClosed?"Yes":"No","<br>\n \u2022 Definition Length: ").concat(i.length," characters<br>\n \u2022 Complete Object: ").concat(a?"Yes":"No","<br>\n \u2022 Error Type: ").concat(r.constructor.name,"\n </div>\n </div>\n ");const s=e.querySelector(".vega-lite-retry-error-btn"),c=e.querySelector(".vega-lite-show-source-btn"),l=e.querySelector(".vega-lite-force-render-btn");s&&(s.onclick=()=>D.render(e,null,t,n));c&&(c.onclick=()=>O(e,t,n,r));l&&(l.onclick=()=>{const r=(0,o.A)((0,o.A)({},t),{},{forceRender:!0});D.render(e,null,r,n)})}(e,n,r,he instanceof Error?he:new Error(String(he))),setTimeout((()=>{const t=e.querySelector(".vega-lite-error, .vega-lite-debug");if(t){const n=t.getBoundingClientRect();console.log("Error container size:",n);let o=e.parentElement;for(;o&&(o.classList.contains("d3-container")||o.classList.contains("vega-lite-renderer-container"));){const e=o;e.classList.contains("vega-lite-renderer-container")&&(e.style.height="auto",e.style.minHeight="".concat(n.height+40,"px"),e.style.overflow="visible",e.style.maxHeight&&(e.style.maxHeight="none"),console.log("Updated parent ".concat(e.className," height to ").concat(n.height+40,"px for error display"))),o=o.parentElement}}}),100)}}};function O(e,t,n,r){const i=t.definition||JSON.stringify(t,null,2),a=t.$schema&&(t.data||t.datasets)&&(t.mark||t.layer||t.vconcat||t.hconcat||t.facet||t.repeat);e.innerHTML='\n <div class="vega-lite-debug" style="\n background-color: '.concat(n?"#1f1f1f":"#f6f8fa",";\n border: 1px solid ").concat(n?"#444":"#e1e4e8",';\n border-radius: 6px;\n padding: 16px;\n margin: 10px 0;\n ">\n <div style="margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center;">\n <strong style="color: ').concat(n?"#f8f9fa":"#24292e",';">Vega-Lite Debug View</strong>\n <div>\n <button class="vega-lite-debug-retry-btn" style="\n background-color: #28a745;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 6px 12px;\n margin-right: 8px;\n cursor: pointer;\n font-size: 13px;\n ">\ud83d\udd04 Retry</button>\n <button id="vega-lite-debug-force-').concat(Date.now(),'" style="\n background-color: #dc3545;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 6px 12px;\n cursor: pointer;\n font-size: 13px;\n ">\u26a1 Force Render</button>\n </div>\n </div>\n \n ').concat(r?'\n <div style="\n background-color: '.concat(n?"#2d1b1b":"#ffeaea",";\n border: 1px solid ").concat(n?"#a61d24":"#ffa39e",';\n border-radius: 4px;\n padding: 12px;\n margin-bottom: 15px;\n ">\n <strong style="color: ').concat(n?"#ff7875":"#cf1322",';">Error Details:</strong><br>\n <code style="color: ').concat(n?"#ffa7cc":"#d1242f",';">').concat(r.message,"</code>\n </div>\n "):"",'\n \n <div style="margin-bottom: 15px;">\n <strong style="color: ').concat(n?"#f8f9fa":"#24292e",';">Debug Information:</strong><br>\n <div style="font-size: 13px; color: ').concat(n?"#8b949e":"#656d76",'; margin-top: 8px;">\n \u2022 Streaming State: ').concat(t.isStreaming?"Active":"Inactive","<br>\n \u2022 Markdown Block: ").concat(t.isMarkdownBlockClosed?"Closed":"Open","<br>\n \u2022 Force Render: ").concat(t.forceRender?"Yes":"No","<br>\n \u2022 Definition Length: ").concat(i.length," characters<br>\n \u2022 Complete Object: ").concat(a?"Yes":"No","<br>\n \u2022 Has Schema: ").concat(t.$schema?"Yes":"No","<br>\n \u2022 Has Data: ").concat(t.data||t.datasets?"Yes":"No","<br>\n \u2022 Has Mark/Layer: ").concat(t.mark||t.layer?"Yes":"No",'\n </div>\n </div>\n \n <details open>\n <summary style="cursor: pointer; margin-bottom: 10px; color: ').concat(n?"#f8f9fa":"#24292e",';">\n <strong>Source Specification</strong>\n </summary>\n <pre style="\n background-color: ').concat(n?"#0d1117":"#f6f8fa",";\n padding: 12px;\n border-radius: 4px;\n overflow: auto;\n max-height: 400px;\n margin: 0;\n border: 1px solid ").concat(n?"#30363d":"#e1e4e8",";\n font-family: 'SFMono-Regular', 'Monaco', 'Inconsolata', 'Liberation Mono', 'Courier New', monospace;\n font-size: 13px;\n line-height: 1.45;\n color: ").concat(n?"#e6edf3":"#24292f",';\n "><code>').concat(i,"</code></pre>\n </details>\n </div>\n ");const s=e.querySelector(".vega-lite-debug-retry-btn"),c=e.querySelector(".vega-lite-debug-force-btn");s&&(s.onclick=()=>D.render(e,null,t,n)),c&&(c.onclick=()=>{(0,o.A)((0,o.A)({},t),{},{forceRender:!0})}),setTimeout((()=>{const t=e.querySelector(".vega-lite-debug");if(t){const n=t.getBoundingClientRect();console.log("Debug container size:",n);let o=e.parentElement;for(;o&&(o.classList.contains("d3-container")||o.classList.contains("vega-lite-renderer-container"));){const e=o;e.style.height="auto",e.style.minHeight="".concat(Math.max(n.height+40,400),"px"),e.style.overflow="visible",e.style.maxHeight&&(e.style.maxHeight="none"),console.log("Updated parent ".concat(e.className," height to ").concat(n.height+40,"px for debug display")),o=o.parentElement}}}),100)}const q=[d,p,x,S,D];q.forEach((e=>{if(!e.name)throw new Error("Plugin missing required name property");if("number"!==typeof e.priority)throw new Error("Plugin ".concat(e.name," missing required priority number"));if("function"!==typeof e.canHandle)throw new Error("Plugin ".concat(e.name," missing required canHandle function"));if("function"!==typeof e.render)throw new Error("Plugin ".concat(e.name," missing required render function"))}));const B=Object.freeze(q);class z{constructor(){this.resizeObservers=new Map,this.cleanupFunctions=new Set}applySizingConfig(e,t,n){switch(t.containerStyles&&Object.assign(e.style,t.containerStyles),t.sizingStrategy){case"responsive":e.style.width="100%",e.style.maxWidth="100%",t.needsDynamicHeight&&(e.style.height="auto",e.style.minHeight=t.minHeight?"".concat(t.minHeight,"px"):"auto");break;case"content-driven":e.style.width="100%",e.style.height="auto",e.style.minHeight="auto";break;case"auto-expand":e.style.width="100%",e.style.height="auto",e.style.minHeight=t.minHeight?"".concat(t.minHeight,"px"):"200px";break;default:t.minWidth&&(e.style.minWidth="".concat(t.minWidth,"px")),t.minHeight&&(e.style.minHeight="".concat(t.minHeight,"px"))}t.needsOverflowVisible&&(e.style.overflow="visible",this.updateParentOverflow(e)),t.observeResize&&this.setupResizeObserver(e,t)}updateParentOverflow(e){let t=e.parentElement;for(;t&&(t.classList.contains("d3-container")||t.classList.contains("vega-lite-container"));)t.style.overflow="visible",t=t.parentElement}setupResizeObserver(e,t){const n=new ResizeObserver((n=>{for(const o of n){const n=o.contentRect.height,r=o.contentRect.width;this.adjustParentContainers(e,r,n,t)}}));setTimeout((()=>{const t=e.querySelector("svg, .vega-embed, .mermaid, .graphviz");t&&(n.observe(t),this.resizeObservers.set(e,n))}),100)}adjustParentContainers(e,t,n,o){if(!o.needsDynamicHeight)return;let r=e.parentElement;for(;r&&(r.classList.contains("d3-container")||r.classList.contains("vega-lite-container"));){const e=r;e.getBoundingClientRect().height<n+40&&(e.style.height="".concat(n+40,"px"),e.style.minHeight="".concat(n+40,"px")),e.style.width&&"auto"!==e.style.width||(e.style.width="100%",e.style.maxWidth="100%"),r=r.parentElement}}cleanup(){this.resizeObservers.forEach((e=>e.disconnect())),this.resizeObservers.clear(),this.cleanupFunctions.forEach((e=>e())),this.cleanupFunctions.clear()}addCleanupFunction(e){this.cleanupFunctions.add(e)}}var $=n(70579);function W(e){if(e.visualizationType){const t=B.find((t=>t.name===e.visualizationType));if(t)return t}const t=B.filter((t=>t.canHandle(e))).sort(((e,t)=>t.priority-e.priority));if(t.length>0)return console.debug("Found ".concat(t.length," matching plugins:"),t.map((e=>"".concat(e.name," (priority: ").concat(e.priority,")")))),t[0]}function P(e){if(void 0!==e){if(null===e)return null;if(Array.isArray(e))return e.map(P).filter((e=>void 0!==e));if("object"===typeof e){const t={};for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const o=P(e[n]);void 0!==o&&(t[n]=o)}return t}return e}}const V=e=>{let{spec:t,width:n=600,height:l=400,containerId:d,type:g="auto",onLoad:p,onError:u,isStreaming:m=!1,forceRender:f=!1,isMarkdownBlockClosed:y=!0,config:b={}}=e;const{isDarkMode:v}=(0,i.D)(),x=(0,r.useRef)(null),w=(0,r.useRef)(null),k=(0,r.useRef)(null),[S,E]=(0,r.useState)(!0),[A,C]=(0,r.useState)(null),[L,T]=(0,r.useState)(!1),[R,I]=(0,r.useState)(!1),[M,F]=(0,r.useState)([]),N=(0,r.useRef)(null),D=(0,r.useRef)(null),[O,q]=(0,r.useState)(!1),B=(0,r.useRef)(0),V=(0,r.useRef)(!0),j=(0,r.useRef)(null),H=(0,r.useRef)(null),U=(0,r.useRef)(null),X=(0,r.useRef)(null),[G,Y]=(0,r.useState)(!1),J=(0,r.useRef)(v),K=(0,r.useRef)(!1),_=(0,r.useRef)([]),[Q,Z]=(0,r.useState)(null),ee=(0,r.useRef)(null);(0,r.useEffect)((()=>{j.current=t}),[t]),(0,r.useEffect)((()=>{if(t&&!Q){const e=W(t),n=function(e,t){const n={width:600,height:400};if(!e||"object"!==typeof e)return n;if(e.width&&e.height)return{width:e.width,height:e.height};if("mermaid-renderer"===(null===t||void 0===t?void 0:t.name)&&e.definition){const t=e.definition.split("\n").length,n=e.definition.length/t;return{width:Math.min(Math.max(8*n,400),1200),height:Math.min(Math.max(25*t,200),800)}}return n}(t,e);Z(n),console.debug("Reserved size for diagram:",n)}}),[t,Q]),(0,r.useEffect)((()=>()=>{ee.current&&(ee.current.cleanup(),ee.current=null),V.current=!1,console.debug("D3Renderer cleanup triggered"),_.current.forEach((e=>{try{e()}catch(t){console.warn("Error during cleanup:",t)}})),_.current=[];try{k.current&&(k.current.finalize(),k.current=null)}catch(e){console.warn("Error finalizing Vega view:",e)}try{D.current&&(D.current.stop(),D.current=null),w.current&&(c.select(w.current).selectAll("*").on(".",null),w.current.innerHTML="")}catch(e){console.warn("Error cleaning up D3:",e)}}),[]);const te=(0,r.useCallback)((async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(V.current){G||Y(!0),R&&m||K.current||E(!0);try{if(_.current.forEach((e=>e())),_.current=[],!t)throw new Error("No specification provided");let a,s,d=!m||y||e,u=m&&!y&&!e;try{if("string"===typeof t){if(console.debug("Parsing string spec:",t.substring(0,100)+"..."),s=t.replace(/\r\n/g,"\n").split("\n").map((e=>e.trim())).filter((e=>!e.trim().startsWith("//")&&""!==e.trim())),!s.length)return void E(!0);const e=s.join("\n").replace(/\/\*[\s\S]*?\*\//g,"");a=JSON.parse(e)}else console.debug("Using object spec directly"),a=t}catch(r){return m&&!y?(H.current="string"===typeof t?t:null,S&&!K.current&&E(!1),void T(!0)):(E(!0),void console.debug("Waiting for complete spec:",r))}if(a){const e=a.type||"";if(m&&!y){const n=W(a);if(null!==n&&void 0!==n&&n.isDefinitionComplete&&"string"===typeof t){const e=n.isDefinitionComplete(t);console.debug("Checking if ".concat(n.name," definition is complete:"),e),e||(d=!1)}else if("mermaid"===e||"graphviz"===e){h(a.definition||"",e)||(d=!1)}}d&&(X.current=a)}if(T(u),!d)return;if(I(!0),console.debug("D3Renderer: Successfully parsed spec:",{type:a.type,renderer:a.renderer}),!a)return;const f=W(a);if("d3"===g||"d3"===a.renderer||"function"===typeof a.render||f){const t=w.current;if(!t)return;const r=W(a);if(U.current=r||null,null!==r&&void 0!==r&&r.sizingConfig&&!ee.current&&(ee.current=new z,ee.current.applySizingConfig(t,r.sizingConfig,v),_.current.push((()=>{var e;null===(e=ee.current)||void 0===e||e.cleanup()}))),D.current)try{D.current.stop(),D.current=null}catch(i){console.warn("Error cleaning up simulation:",i)}t.style.width="".concat(n,"px"),t.style.height="".concat(l,"px"),t.style.position="relative",t.style.overflow="hidden";("graphviz-renderer"===(null===r||void 0===r?void 0:r.name)||"mermaid-renderer"===(null===r||void 0===r?void 0:r.name))&&(t.style.width="100%",t.style.height="auto",t.style.minHeight="unset",t.style.overflow="visible");const s=document.createElement("div");s.style.width="100%",s.style.height="auto";let d=!1;try{t.firstChild&&t.removeChild(t.firstChild);const r=P(a);if("function"===typeof a.render){const e=r.render.call(r,s,c);d=!0,"function"===typeof e&&(N.current=e,_.current.push(e)),D.current&&_.current.push((()=>{D.current&&(D.current.stop(),D.current=null)}))}else if("network"===r.type){const t=W(r);t&&(t.render(s,c,(0,o.A)((0,o.A)({},r),{},{width:n||600,height:l||400,isStreaming:m,isMarkdownBlockClosed:y,forceRender:e}),v),d=!0)}else{const t=()=>{s&&s.parentNode&&(s.innerHTML="")};_.current.push(t);const n=W(r);if(!n)throw new Error("No render function or compatible plugin found");console.debug("Using plugin:",n.name),n.render(s,c,(0,o.A)((0,o.A)({},r),{},{isStreaming:m,isMarkdownBlockClosed:y,forceRender:e}),v),d=!0,V.current&&C(null)}}catch(A){console.error("D3 render error:",A),V.current&&(C(A instanceof Error?A.message:"Render failed"),F([A instanceof Error?A.message:"Unknown error"]))}if(d&&(t.innerHTML="",t.appendChild(s)),!d)throw new Error("Render did not complete successfully");if(A&&"mermaid-renderer"===(null===r||void 0===r?void 0:r.name)){const e=document.createElement("button");e.innerHTML="\ud83d\udd04 Retry Rendering",e.className="diagram-action-button mermaid-retry-button",e.style.cssText="\n background-color: #4361ee;\n color: white;\n border: none;\n border-radius: 4px;\n padding: 8px 16px;\n margin: 10px auto;\n cursor: pointer;\n display: block;\n ",e.onclick=()=>te(),t.appendChild(e)}return V.current&&E(!1),C(null),null===p||void 0===p||p(),void(K.current=!0)}}catch(i){m&&!y?(console.debug("Suppressing streaming error:",i.message),K.current||T(!0)):(console.error("Visualization error:",i),V.current&&(C(i.message),E(!1)))}}}),[t,g,n,l,v,m,y,b,p,u,S,R,V,G,A]);(0,r.useEffect)((()=>{if(!V.current)return;if(!K.current||!m&&y||f){const e=++B.current;console.debug("Starting render #".concat(e)),te(f)}}),[t,m,y,f,te]),(0,r.useEffect)((()=>{j.current&&K.current&&G&&v!==J.current&&(console.log("Theme changed, re-rendering visualization"),setTimeout((()=>{te()}),100))}),[v,te]);const ne=(0,r.useMemo)((()=>{const e="object"===typeof t&&null!==t?W(t):void 0;return"d3"===g||"object"===typeof t&&("d3"===(null===t||void 0===t?void 0:t.renderer)||!!e)}),[g,t]),oe=(0,r.useMemo)((()=>"object"===typeof t&&null!==t?W(t):void 0),[t]),re=(0,r.useMemo)((()=>{var e;const t=oe;if(null!==t&&void 0!==t&&null!==(e=t.sizingConfig)&&void 0!==e&&e.containerStyles){const e=t.sizingConfig.containerStyles;return"auto-expand"===t.sizingConfig.sizingStrategy?(0,o.A)((0,o.A)({},e),{},{height:"auto",minHeight:"auto",overflow:t.sizingConfig.needsOverflowVisible?"visible":e.overflow||"auto"}):e}return{height:l||"400px",overflow:"auto"}}),[oe,l]),ie=(0,o.A)({position:"relative",width:"100%",maxWidth:"100%",height:"auto",display:"block",margin:"1em 0",padding:0,boxSizing:"border-box",minWidth:"100%"},Q&&!K.current?{minHeight:"".concat(Q.height,"px"),minWidth:"".concat(Math.min(Q.width,800),"px")}:{});return(0,$.jsxs)("div",{id:d||"d3-container",style:ie,className:"d3-container ".concat(m?"streaming":""),"data-render-id":B.current,"data-visualization-type":"object"===typeof t&&null!==t&&void 0!==t&&t.type?t.type:"unknown",children:[!m||y||K.current?(0,$.jsx)($.Fragment,{children:L&&(0,$.jsx)("div",{style:{textAlign:"center",padding:"20px",backgroundColor:v?"#1f1f1f":"#f6f8fa",border:"1px dashed #ccc",borderRadius:"4px"},children:(0,$.jsx)("p",{children:"Waiting for complete diagram definition..."})})}):(0,$.jsx)("div",{style:{textAlign:"center",padding:"20px",backgroundColor:v?"#1f1f1f":"#f6f8fa",border:"1px dashed #ccc",borderRadius:"4px"},children:(0,$.jsxs)("p",{children:["Waiting for complete ","object"===typeof t&&null!==t&&void 0!==t&&t.type?t.type:"diagram"," definition..."]})}),ne?(0,$.jsx)("div",{ref:w,className:"d3-container ".concat(null!==oe&&void 0!==oe&&oe.name?"".concat(oe.name,"-container"):""),style:(0,o.A)({width:"100%",display:"flex",flexDirection:"column",alignItems:"center",position:"relative",boxSizing:"border-box"},re)}):(0,$.jsxs)("div",{ref:x,id:"vega-container",className:"vega-lite-container",style:{width:"100%",minWidth:"100%",maxWidth:"100%",display:ne?"none":"block",position:"relative",height:l||"100%"},children:[(S||!t)&&!G&&(0,$.jsxs)("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.1)"},children:[(0,$.jsx)(a.A,{size:"large"}),(0,$.jsx)("div",{style:{marginTop:"10px",color:v?"#ffffff":"#000000"},children:"Preparing visualization..."})]}),A&&!m&&y&&(0,$.jsxs)("pre",{style:{padding:"16px",margin:"8px",backgroundColor:v?"#2a1215":"#fff1f0",border:"1px solid ".concat(v?"#5c2223":"#ffa39e"),borderRadius:"4px",color:v?"#ff4d4f":"#cf1322",whiteSpace:"pre-wrap",wordWrap:"break-word",maxHeight:"200px",overflowY:"auto",fontSize:"14px",lineHeight:"1.5",fontFamily:"monospace"},children:[(0,$.jsx)("strong",{children:"Error:"}),M.map(((e,t)=>(0,$.jsx)("div",{children:e},t)))]})]}),(0,$.jsx)(s.A,{title:"Visualization Source",open:O,onCancel:()=>q(!1),footer:null,width:800,children:(0,$.jsx)("pre",{style:{backgroundColor:v?"#1f1f1f":"#f6f8fa",padding:"16px",borderRadius:"4px",overflow:"auto",maxHeight:"60vh",color:v?"#e6e6e6":"#24292e"},children:(0,$.jsx)("code",{children:"string"===typeof t?t:JSON.stringify(t,null,2)})})}),(0,$.jsx)(s.A,{title:"Visualization Source",open:O,onCancel:()=>q(!1),footer:null,width:800,children:(0,$.jsx)("pre",{style:{backgroundColor:v?"#1f1f1f":"#f6f8fa",padding:"16px",borderRadius:"4px",overflow:"auto",maxHeight:"60vh",color:v?"#e6e6e6":"#24292e"},children:(0,$.jsx)("code",{children:"string"===typeof t?t:JSON.stringify(t,null,2)})})})]})}},24784:(e,t,n)=>{n.d(t,{Ay:()=>u,detectSupportedDiagramTypes:()=>s,normalizeDiagramType:()=>c});const o=[],r=[];let i=null,a=null;function s(e){if(i&&a===e)return i;const t=new Set;if(!e||!e.parse)return console.warn("Mermaid not properly initialized for type detection"),t;const n=[{type:"flowchart",def:"flowchart TD\n A --\x3e B"},{type:"graph",def:"graph TD\n A --\x3e B"},{type:"sequenceDiagram",def:"sequenceDiagram\n A->>B: message"},{type:"classDiagram",def:"classDiagram\n class A"},{type:"stateDiagram",def:"stateDiagram-v2\n [*] --\x3e A"},{type:"erDiagram",def:"erDiagram\n A { int id }"},{type:"journey",def:"journey\n title Test\n section A\n Task: 5: User"},{type:"gantt",def:"gantt\n title Test\n dateFormat YYYY-MM-DD\n Task: 2024-01-01, 1d"},{type:"pie",def:'pie title Test\n "A": 50\n "B": 50'},{type:"gitgraph",def:'gitgraph\n commit id: "Initial"'},{type:"requirementDiagram",def:"requirementDiagram\n requirement test {\n id: 1\n text: test\n risk: low\n verifymethod: test\n }"},{type:"timeline",def:"timeline\n title Test\n 2024: Event"},{type:"mindmap",def:"mindmap\n root\n A\n B"},{type:"quadrantChart",def:'quadrantChart\n title Test\n x-axis Low --\x3e High\n y-axis Low --\x3e High\n "A": [0.5, 0.5]'},{type:"xychart",def:"xychart-beta\n title Test\n x-axis [A, B]\n y-axis Test 0 --\x3e 10\n line Test [1, 2]"},{type:"xychart-beta",def:"xychart-beta\n title Test\n x-axis [A, B]\n y-axis Test 0 --\x3e 10\n line Test [1, 2]"},{type:"sankey",def:"sankey-beta\n A,B,10"},{type:"sankey-beta",def:"sankey-beta\n A,B,10"},{type:"block",def:"block-beta\n A[Test]"},{type:"block-beta",def:"block-beta\n A[Test]"},{type:"packet",def:"packet-beta\n title Test\n 0-7: Test"},{type:"packet-beta",def:"packet-beta\n title Test\n 0-7: Test"},{type:"architecture",def:"architecture-beta\n service test[Test]"},{type:"architecture-beta",def:"architecture-beta\n service test[Test]"}];for(const r of n)try{e.parse(r.def),t.add(r.type)}catch(o){}return i=t,a=e,console.log("Detected supported diagram types:",Array.from(t)),t}function c(e,t){const n=s(t);if(n.has(e))return e;if(e.endsWith("-beta")){const t=e.replace("-beta","");if(n.has(t))return t}if(!e.endsWith("-beta")){const t=e+"-beta";if(n.has(t))return t}return e}function l(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n={process:e,priority:t.priority||10,diagramTypes:t.diagramTypes||["*"],name:t.name||"preprocessor-".concat(o.length)};return o.push(n),o.sort(((e,t)=>t.priority-e.priority)),()=>{const e=o.findIndex((e=>e===n));-1!==e&&o.splice(e,1)}}function d(e,t,n){let r=e;if(!t){t=e.trim().split("\n")[0].trim().replace(/^(\w+).*$/,"$1")}let i=t;if(n&&(i=c(t,n),i!==t)){const e=r.split("\n");e[0].trim().startsWith(t)&&(e[0]=e[0].replace(t,i),r=e.join("\n"))}for(const s of o)if(s.diagramTypes.includes("*")||s.diagramTypes.includes(i))try{const e=s.process(r,i);e&&(r=e)}catch(a){console.warn("Preprocessor ".concat(s.name," failed:"),a)}return r}function g(){l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;console.log("\ud83d\udd0d NODE-QUOTE-FIX: Processing node labels with quotes and parentheses");let n=e.replace(/(\w+)(\{|\[)([^}\]]*?)(\}|\])/g,((e,t,n,o,r)=>{let i=o;return i=i.replace(/"/g,""),i=i.replace(/\(/g,"- ").replace(/\)/g,""),i=i.replace(/\s+/g," ").trim(),console.log("\ud83d\udd0d NODE-QUOTE-FIX: Fixed node ".concat(t,': "').concat(o,'" -> "').concat(i,'"')),"".concat(t).concat(n).concat(i).concat(r)}));return n=n.replace(/;(\s*$)/gm,"$1"),console.log("\ud83d\udd0d NODE-QUOTE-FIX: Processing complete"),n}),{name:"node-quote-parentheses-fix",priority:600,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if(!e.trim().startsWith("sankey"))return e;const n=e.split("\n").map((e=>e.trim())).filter((e=>e));if(0===n.length)return e;const o=[];o.push(n[0]);for(let r=1;r<n.length;r++){const e=n[r];if(e&&!e.startsWith("%%")&&e.includes(",")){const t=e.split(",").map((e=>e.trim()));t.length>=3&&o.push("".concat(t[0],",").concat(t[1],",").concat(t[2]))}}return console.log("\ud83d\udd0d CRITICAL-SANKEY-FORMAT-FIX: Processing complete"),o.join("\n")}),{name:"sankey-format-fix",priority:700,diagramTypes:["sankey"]}),l(((e,t)=>{if("requirementdiagram"!==t&&!e.trim().startsWith("requirementDiagram"))return e;console.log("\ud83d\udd0d REQUIREMENT-MASTER-FIX: Processing requirement diagram");let n=e;n.trim().startsWith("requirementDiagram")||(n="requirementDiagram\n"+n);const o=n.split("\n"),r=[];let i=!1;for(const a of o){const e=a.trim();if(e||!i)if(e.startsWith("requirementDiagram"))r.push(e);else if(e.match(/^(requirement|functionalreq|performancereq|interfacereq|physicalreq|designconstraint)\s+\w+\s*\{/))i&&r.push(" }"),i=!0,r.push(" "+e);else if("}"===e&&i)r.push(" }"),i=!1;else if(i&&e.match(/^(id|text|risk|verifymethod):/)){const t=e.match(/^(\w+):\s*(.+)$/);if(t){const[,e,n]=t,o=n.replace(/^["']|["']$/g,""),i=["id","text"].includes(e);r.push(" ".concat(e,": ").concat(i?'"'.concat(o,'"'):o))}}else i||!(e.startsWith("element ")||e.includes(" - ")||e.includes(" -> "))?e&&!i&&r.push(" "+e):r.push(" "+e)}return i&&r.push(" }"),console.log("\ud83d\udd0d REQUIREMENT-MASTER-FIX: Processing complete"),r.join("\n")}),{name:"requirement-master-fix",priority:650,diagramTypes:["requirementdiagram"]}),l(((e,t)=>{if(!e.trim().startsWith("requirementDiagram"))return e;console.log("\ud83d\udd0d REQUIREMENT-ID-FIX: Fixing ID format and properties");let n=e;return n=n.replace(/(\s+id:\s*)([A-Z]+-\d+)/g,((e,t,n)=>{const o=n.replace(/-/g,"");return"".concat(t).concat(o)})),n=n.replace(/verifymethod:/g,"verifyMethod:"),console.log("\ud83d\udd0d REQUIREMENT-ID-FIX: Processing complete"),n}),{name:"requirement-id-fix",priority:500,diagramTypes:["requirementDiagram"]}),l(((e,t)=>{if(!e.trim().startsWith("sequenceDiagram"))return e;console.log("\ud83d\udd0d SEQUENCE-BREAK-FIX: Removing invalid break statements");let n=e;return n=n.replace(/^(\s*)break\s+.*$/gm,""),n=n.replace(/\n\s*\n\s*\n/g,"\n\n"),console.log("\ud83d\udd0d SEQUENCE-BREAK-FIX: Processing complete"),n}),{name:"sequence-break-fix",priority:500,diagramTypes:["sequenceDiagram"]}),l(((e,t)=>{if(!e.trim().startsWith("packet")&&!e.trim().startsWith("packet-beta"))return e;console.log("\ud83d\udd0d PACKET-SYNTAX-FIX: Adding quotes to packet fields");let n=e;return n=n.replace(/^(\d+(-\d+)?): ([^"\n].*)$/gm,'$1: "$3"'),n=n.replace(/^title ([^"\n].*)$/gm,'title "$1"'),console.log("\ud83d\udd0d PACKET-SYNTAX-FIX: Processing complete"),n}),{name:"packet-syntax-fix",priority:500,diagramTypes:["packet","packet-beta"]}),l(((e,t)=>{if(!e.trim().startsWith("gitgraph"))return e;console.log("\ud83d\udd0d GITGRAPH-FIX: Processing gitgraph syntax");let n=e;return n.includes("gitgraph:")||(n=n.replace("gitgraph","gitgraph:")),console.log("\ud83d\udd0d GITGRAPH-FIX: Processing complete"),n}),{name:"gitgraph-fix",priority:500,diagramTypes:["gitgraph"]}),l(((e,t)=>{if(!e.trim().startsWith("block-beta")&&!e.trim().startsWith("block"))return e;console.log("\ud83d\udd0d BLOCK-QUOTE-FIX: Fixing double quotes and complex labels");let n=e;return n=n.replace(/(\w+)\[""([^"]*)""\]/g,'$1["$2"]'),n=n.replace(/\["?\("([^"]*?)(?:<br\/?>([^"]*?))?"?\)?"?\]/g,'["$1$2"]'),console.log("\ud83d\udd0d BLOCK-QUOTE-FIX: Processing complete"),n}),{name:"block-quote-fix",priority:600,diagramTypes:["block-beta","block"]}),l(((e,t)=>{if(!e.trim().startsWith("sequenceDiagram"))return e;console.log("\ud83d\udd0d SEQUENCE-FIX: Processing sequence diagram");let n=e;return n=n.replace(/\u2022/g,"-"),n=n.replace(/(critical[\s\S]*?)option\s+[^\n]*\n([\s\S]*?)end/g,((e,t,n)=>e)),n=n.replace(/(alt[\s\S]*?)option\s+[^\n]*\n/g,"$1"),console.log("\ud83d\udd0d SEQUENCE-FIX: Processing complete"),n}),{name:"sequence-fix",priority:550,diagramTypes:["sequencediagram"]}),l(((e,t)=>{if("statediagram"!==t&&"statediagram-v2"!==t&&!e.trim().startsWith("stateDiagram"))return e;console.log("\ud83d\udd0d CRITICAL-STATE-FIX: Fixing divider syntax errors");let n=e;return n=n.replace(/^\s*--\s*$/gm,""),console.log("\ud83d\udd0d CRITICAL-STATE-FIX: Processing complete"),n}),{name:"critical-state-divider-fix",priority:555,diagramTypes:["statediagram","statediagram-v2"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;console.log("\ud83d\udd0d QUOTED-STYLE-FIX: Removing invalid quoted style statements");let n=e;const o=[];return n=n.replace(/style\s+"([^"]+)"\s+fill:[^;\n]*/g,((e,t)=>(o.push(t),console.log("\ud83d\udd0d QUOTED-STYLE-FIX: Removing invalid style statement: ".concat(e)),""))),o.length>0&&console.log("\ud83d\udd0d QUOTED-STYLE-FIX: Removed ".concat(o.length," invalid style statements")),console.log("\ud83d\udd0d QUOTED-STYLE-FIX: Processing complete"),n}),{name:"quoted-style-fix",priority:500,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;console.log("\ud83d\udd0d NAMING-CONFLICT-FIX: Checking for subgraph/node naming conflicts");const n=new Set,o=e.matchAll(/subgraph\s+"([^"]+)"/g),r=e.matchAll(/subgraph\s+(\w+)\s*(?:\["[^"]+"\])?/g);for(const c of o)n.add(c[1]);for(const c of r)n.add(c[1]);const i=new Set,a=e.matchAll(/(\w+)\[/g);for(const c of a)i.add(c[1]);console.log("\ud83d\udd0d NAMING-CONFLICT-FIX: Found subgraphs:",Array.from(n)),console.log("\ud83d\udd0d NAMING-CONFLICT-FIX: Found node IDs:",Array.from(i));let s=e;for(const c of n)if(i.has(c)){console.log('\ud83d\udd0d NAMING-CONFLICT-FIX: Found conflict - subgraph "'.concat(c,'" has node with same ID'));const e="".concat(c,"Node"),t=new RegExp("\\b".concat(c,"\\["),"g");s=s.replace(t,"".concat(e,"["));const n=new RegExp("\\b".concat(c,'\\b(?!\\s*\\[|"\\s*$)'),"g");s=s.replace(n,((t,n)=>s.substring(Math.max(0,n-20),n).includes("subgraph")?t:e)),console.log('\ud83d\udd0d NAMING-CONFLICT-FIX: Renamed conflicting node from "'.concat(c,'" to "').concat(e,'"'))}return console.log("\ud83d\udd0d NAMING-CONFLICT-FIX: Processing complete"),s}),{name:"naming-conflict-fix",priority:480,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;console.log("\ud83d\udd0d NODE-LABEL-FIX: Processing node labels with numbered lists");const n=e.replace(/(\w+)\[([^\]]*?)\]/g,((e,t,n)=>{if(n.match(/^\s*\d+\.\s/)){console.log("\ud83d\udd0d NODE-LABEL-FIX: Fixing numbered list in node:",t);const e=n.split("\n").map((e=>e.replace(/^(\s*)(\d+)\.\s*(.*)$/,"$1$2\\. $3"))).join("<br/>");return"".concat(t,"[").concat(e,"]")}return e}));return console.log("\ud83d\udd0d NODE-LABEL-FIX: Processing complete"),n}),{name:"node-label-numbered-list-fix",priority:470,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;console.log("\ud83d\udd0d MULTILINE-NODE-FIX: Processing multi-line node labels");const n=e.replace(/(\w+)\[([^\]]*?)\]/g,((e,t,n)=>{if(n.includes("\n")&&!n.includes("<br/>")){console.log("\ud83d\udd0d MULTILINE-NODE-FIX: Fixing node:",t);const e=n.split("\n").map((e=>e.trim())).filter((e=>e.length>0)).join("<br/>");return"".concat(t,"[").concat(e,"]")}return e}));return console.log("\ud83d\udd0d MULTILINE-NODE-FIX: Processing complete"),n}),{name:"multiline-node-fix",priority:460,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;console.log("\ud83d\udd0d LINKSTYLE-FIX: Checking for invalid linkStyle references");const n=e.match(/(-->|---|-.->|--[xo]>|->>|-->>|<--|<<-)/g),o=n?n.length:0;console.log("\ud83d\udd0d LINKSTYLE-FIX: Found",o,"links in definition"),n&&console.log("\ud83d\udd0d LINKSTYLE-FIX: Arrow types found:",n);const r=e.split("\n").map((e=>{const t=e.match(/^\s*linkStyle\s+(\d+(?:,\d+)*)/);if(t){const n=t[1].split(",").map((e=>parseInt(e.trim()))),r=n.filter((e=>e<o));if(r.length!==n.length&&console.log("\ud83d\udd0d LINKSTYLE-FIX: Removing invalid link references:",n.filter((e=>e>=o))),0===r.length)return console.log("\ud83d\udd0d LINKSTYLE-FIX: Removing entire linkStyle line (no valid links)"),"";const i="linkStyle ".concat(r.join(","));return e.replace(/linkStyle\s+\d+(?:,\d+)*/,i)}return e})).filter((e=>""!==e)).join("\n");return console.log("\ud83d\udd0d LINKSTYLE-FIX: Processing complete"),r}),{name:"linkstyle-fix",priority:450,diagramTypes:["flowchart","graph"]}),l(((e,t)=>"flowchart"===t||"graph"===t||e.trim().startsWith("flowchart")||e.trim().startsWith("graph")?e.replace(/(\w+)\s*\|([^|]+)\|\s*(\w+)/g,"$1 --\x3e|$2| $3"):e),{name:"pipe-syntax-fix",priority:300,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;const n=new Set,o=/([a-zA-Z0-9][^\[\(\n]*:[^\[\(\n]*?)(\[|\()/g;let r;for(;null!==(r=o.exec(e));){const e=r[1].trim();e.startsWith('"')||e.endsWith('"')||n.add(e)}if(0===n.size)return e;let i=e;return n.forEach((e=>{const t=e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),n=new RegExp("(?<=^|\\s)(".concat(t,")(?=[\\s;\\[\\(]|$)"),"g");i=i.replace(n,'"'.concat(e,'"'))})),i}),{name:"colon-in-node-id-fix",priority:155,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Skipping non-flowchart diagram type:",t),e;console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Processing flowchart/graph"),console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Input definition (first 500 chars):",e.substring(0,500));const n=e.replace(/(-->|-\.->|--[xo]>|---|->>|-->>)\s*\|([^|]*?)\|/g,((e,t,n)=>{console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Found match:",{match:e,arrow:t,label:n});let o=n.trim();if(o.startsWith('"')&&o.endsWith('"'))return console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Label already quoted, skipping:",o),e;if(!o)return console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Empty label, returning arrow only"),t;let r=o.replace(/"/g,"#quot;").replace(/^(\d+)\.\s*(.*)$/,"$1\\. $2").replace(/^[-*]\s*(.*)$/,"\\$1 $2");r=r.replace(/\[/g,"(").replace(/\]/g,")");const i="".concat(t,'|"').concat(r,'"|');return console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Transformed:",{original:e,result:i}),i}));return console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Processing complete"),console.log("\ud83d\udd0d LINK-LABEL-SANITIZER: Final result (first 500 chars):",n.substring(0,500)),n}),{name:"link-label-sanitizer",priority:350,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{console.log("\ud83d\udd0d UNICODE-FIX: Processing problematic Unicode characters");let n=e;n=n.replace(/\u2022/g,"-"),n=n.replace(/[\u2022\u2023\u2043]/g,"-"),n=n.replace(/[\u2013\u2014]/g,"-"),n=n.replace(/[\u201C\u201D]/g,'"'),n=n.replace(/[\u2018\u2019]/g,"'");const o=n.split("\n");return n=o.map((e=>e.trim().match(/-->\s*$|--->\s*$|\|\s*$/)&&!e.includes("subgraph")?(console.log("\ud83d\udd0d UNICODE-FIX: Removing incomplete connection:",e.trim()),""):e)).filter((e=>""!==e)).join("\n"),console.log("\ud83d\udd0d UNICODE-FIX: Processing complete"),n}),{name:"unicode-and-incomplete-connection-fix",priority:490,diagramTypes:["*"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;console.log("\ud83d\udd0d ARROW-LABEL-CLEANER: Processing edge labels with arrow characters");const n=e.replace(/(==>|-->|-\.->|--[xo]>|---|->>|-->>)\s*\|([^|]*?)\|/g,((e,t,n)=>{console.log("\ud83d\udd0d ARROW-LABEL-CLEANER: Found match:",{match:e,arrow:t,label:n});let o=n.trim();if(o.startsWith('"')&&o.endsWith('"'))return console.log("\ud83d\udd0d ARROW-LABEL-CLEANER: Label already quoted, skipping:",o),e;let r=o.replace(/-->/g,"").replace(/<--/g,"").replace(/==>/g,"").replace(/<=/g,"").replace(/-\.->/g,"").replace(/<-\.-/g,"").trim();const i="".concat(t,'|"').concat(r,'"|');return console.log("\ud83d\udd0d ARROW-LABEL-CLEANER: Cleaned:",{original:e,result:i}),i}));return console.log("\ud83d\udd0d ARROW-LABEL-CLEANER: Processing complete"),n}),{name:"arrow-label-cleaner",priority:360,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;const n=e.split("\n");let o="";(n[0].trim().startsWith("graph")||n[0].trim().startsWith("flowchart"))&&(o=n[0]+"\n",n.shift());return o+n.join("\n").replace(/^(\s*)(\w+)\s*(--+>?)\s*(\|.*?\|)?\s*(\w+)(\[[^\]]*\])(\s*)$/gm,((e,t,n,o,r,i,a)=>{const s=r?" ".concat(r):"";return["".concat(t).concat(i).concat(a),"".concat(t).concat(n," ").concat(o).concat(s," ").concat(i)].join("\n")}))}),{name:"link-target-definition-fix",priority:255,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("classdiagram"!==t&&!e.trim().startsWith("classDiagram"))return e;let n=e;return n=n.replace(/^(\s*)(\w+)\s*>\s*(\w+)\s*$/gm,"$1$2 --|> $3"),n=n.replace(/(class\s+\w+\s*{\s*)>\s*/g,"$1"),n=n.replace(/}\s*>\s*(\w+)\s*{/g,"}\n $1 --|> "),n=n.replace(/}\s*(\w+)\s*{/g,"}\n\n class $1 {"),n}),{name:"class-diagram-inheritance-fix",priority:190,diagramTypes:["classdiagram"]}),l(((e,t)=>"flowchart"===t||e.trim().startsWith("flowchart")||e.trim().startsWith("graph")?e.replace(/\|'([^']*)'\|/g,'|"$1"|'):e),{name:"link-label-single-quote-fix",priority:145,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("classDiagram"!==t&&!e.trim().startsWith("classDiagram"))return e;let n=e;return n=n.replace(/(\s+)>\s*(\w+)/g,"$1--|> $2"),n=n.replace(/^\s*>\s*$/gm,""),n=n.replace(/}\s*>\s*(\w+)\s*{/g,"}\n $1 --|> "),n=n.replace(/(class\s+\w+\s*{\s*)>\s*/g,"$1"),n=n.replace(/(\w+)\s*{\s*<<enumeration>>/g,"$1 {\n <<enumeration>>"),n=n.replace(/\+(\w+)\([^)]*\)\s*(\w+)\*/g,"+$1() $2"),n=n.replace(/}\s*(\w+)\s*{/g,"}\n\n class $1 {"),n}),{name:"class-diagram-syntax-fix",priority:180,diagramTypes:["classdiagram"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;const n=e.split("\n"),o=[];for(let r=0;r<n.length;r++){let e=n[r];if(e.trim().startsWith("subgraph")||"end"===e.trim()){o.push(e);continue}const t=/^(\s*)(\w+)\s*(\[|\()(["']?)([\s\S]*?)(\4)(\]|\))(\s*.*)$/,i=e.match(t);if(i){const[,e,t,n,r,a,s,c,l]=i;let d="".concat(e).concat(t).concat(n),g=a;r&&s?(""===g.trim()&&(g=" "),d+="".concat(r).concat(g).concat(s)):d+=g,d+="".concat(c);let p=d;const u=l.trim();u&&(p+=l);!u||!u.startsWith(":::")&&u.match(/^(-->|---|~~~|\.-|\.\.-|o--|--o|x--)/);o.push(p)}else o.push(e)}return o.join("\n")}),{name:"flowchart-node-termination-fix",priority:185,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{const n=e.split("\n");let o=!1,r=!1;return n.length>0&&"---"===n[0].trim()&&(o=!0),n.map((e=>o?("---"===e.trim()&&(o=!1),e):!r&&e.trim().startsWith("gitgraph")?(r=!0,e.replace("gitgraph","gitGraph")):e)).join("\n")}),{name:"gitgraph-syntax-fix",priority:140,diagramTypes:["gitgraph"]}),l(((e,t)=>"xychart"===t||e.trim().startsWith("xychart")?e.replace(/"{2,}/g,'"'):e),{name:"xychart-quotes-fix",priority:140,diagramTypes:["xychart"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;let n=e;return n=n.replace(/(\w+)-->/g,"$1 --\x3e"),n=n.replace(/-->(\w+)/g,"--\x3e $1"),n}),{name:"flowchart-arrow-spacing-fix",priority:195,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&!e.startsWith("flowchart ")&&!e.startsWith("graph "))return e;let n=e;return n=n.replace(/(\w+)\s*-->\s*(\w+)\{([^}]*?)-->\|([^|]+)\|\s*(\w+)\[/g,"$1 --\x3e $2{$3}\n $2 --\x3e|$4| $5["),n=n.replace(/(\w+)\{([^}]*?)-->\|([^|]+)\|/g,"$1{$2}\n $1 --\x3e|$3|"),n=n.replace(/(\w+)\{([^}]*?)\s+\|([^|]+)\|\s*(\w+)\[/g,"$1{$2}\n $1 --\x3e|$3| $4["),n}),{name:"flowchart-edge-label-fix",priority:210,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&!e.startsWith("flowchart ")&&!e.startsWith("graph "))return e;let n=e;return console.log("Quote cleanup - before:",n.substring(0,200)),n=n.replace(/(\w+)(\s*)\[([\s\S]*?)\]/g,((e,t,o,r)=>{if(n.substring(Math.max(0,n.indexOf(e)-50),n.indexOf(e)).includes("subgraph")&&1===o.length)return console.log("Skipping subgraph display name: ".concat(t).concat(o,"[").concat(r,"]")),e;const i=t+o;if(r.match(/^"[^"]*"$/))return e;if(r.includes('""')||r.match(/"{2,}/)||r.includes('\\"')||r.match(/^".*".*"/)){const e=r.replace(/^"+|"+$/g,"").replace(/\\"/g,'"').replace(/"{2,}/g,'"').replace(/\\+$/g,"");return console.log("Cleaning quotes for ".concat(i,': "').concat(r,'" -> "').concat(e,'"')),"".concat(i,'["').concat(e,'"]')}return e})),console.log("Quote cleanup - after:",n.substring(0,200)),n}),{name:"quote-cleanup-flowchart",priority:200,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&!e.startsWith("flowchart")&&!e.startsWith("graph"))return e;let n=e;return n=n.replace(/class\s+(\w+)\s+subgraph-(\w+)/g,"class $1 subgraph_$2"),n=n.replace(/classDef\s+subgraph-(\w+)/g,"classDef style_$1"),n=n.replace(/subgraph(\w+)/g,"subgraph $1"),n}),{name:"subgraph-syntax-fix",priority:130,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&!e.startsWith("flowchart")&&!e.startsWith("graph"))return e;let n=e;return console.log("Mixed node shapes - processing:",n.substring(0,200)),n=n.replace(/(\w+)(\[|\()([\s\S]*?)(\]|\))/g,((e,t,o,r,i)=>{if(n.substring(Math.max(0,n.indexOf(e)-50),n.indexOf(e)).includes("subgraph"))return console.log("Skipping subgraph display name in special-char fix: ".concat(t).concat(o).concat(r).concat(i)),e;if("["===o&&"]"!==i||"("===o&&")"!==i)return console.log("Malformed brackets in special-char fix: ".concat(e)),e;if(r.match(/^"[\s\S]*"$/))return e;if(/[()\/\n<>&:\.,']/.test(r)||r.includes("<br>")){const e=r.replace(/"/g,"#quot;").replace(/\n/g,"<br/>");return console.log("Adding quotes for special chars: ".concat(t).concat(o).concat(r).concat(i," -> ").concat(t).concat(o,'"').concat(e,'"').concat(i)),"".concat(t).concat(o,'"').concat(e,'"').concat(i)}return e})),console.log("Mixed node shapes - result:",n.substring(0,200)),console.log("Final processed definition length:",n.length),n}),{name:"special-char-in-node-label-fix",priority:135,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("flowchart"!==t&&"graph"!==t&&!e.trim().startsWith("flowchart")&&!e.trim().startsWith("graph"))return e;console.log("\ud83d\udd0d SUBGRAPH-STYLE-SPACING: Fixing spacing between subgraph end and style statements");let n=e;return n=n.replace(/(\s+)}\s*\n/g,"$1end\n"),n=n.replace(/(\s+)}\s*$/g,"$1end"),n=n.replace(/(end\s*)(style\s+)/g,"$1\n $2"),console.log("\ud83d\udd0d SUBGRAPH-STYLE-SPACING: Processing complete"),n}),{name:"subgraph-style-spacing-fix",priority:160,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{let n=e;return n=n.replace(/\[([^"\]]*)"([^"\]]*)"([^"\]]*)\]/g,((e,t,n,o)=>"[".concat(t,'"').concat(n,'"').concat(o,"]"))),n}),{name:"quoted-text-fix",priority:125,diagramTypes:["*"]}),l(((e,t)=>{if("flowchart"!==t&&!e.startsWith("flowchart")&&!e.startsWith("graph"))return e;let n=e;return n=n.replace(/^flowchart\s+/m,"graph "),n=n.replace(/note\s+on\s+link.*?:/gi,"%%note removed:"),n=n.replace(/\[Send\s+"DONE"\s+Marker\]/g,"[Send DONE Marker]"),n=n.replace(/(\s+-->\s+)class(\s*;|\s*\[|\s*$|\s+-->)/gm,'$1"class"$2'),n=n.replace(/(\w+)\s*-->\s*(\w+)\[([^\]]+)\]/g,((e,t,n,o)=>/[\/\[\]]/.test(o)?"".concat(t," --\x3e ").concat(n,'["').concat(o,'"]'):"".concat(t," --\x3e ").concat(n,"[").concat(o,"]"))),n=n.replace(/end\[([^\]]+)\]/g,'endNode["$1"]'),n=n.replace(/SendDone\[([^\]]+)\]/g,'sendDoneNode["$1"]'),n}),{name:"flowchart-fix",priority:120,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{if("requirement"!==t)return e;let n=e.split("\n"),o=[];for(let r=0;r<n.length;r++){let e=n[r].trim();e.match(/^\s*id:/i)&&(e=e.replace(/id:\s*([^,]+)/,'id: "$1"')),e.match(/^\s*text:/i)&&(e=e.replace(/text:\s*([^,]+)/,'text: "$1"')),o.push(e)}return o.join("\n")}),{name:"requirement-diagram-fix",priority:110,diagramTypes:["requirement"]}),l(((e,t)=>{if("xychart"!==t)return e;let n=e.split("\n"),o=[];for(let r=0;r<n.length;r++){let e=n[r].trim();e.includes("[")&&e.includes("]")&&(e=e.replace(/\[(.*?)\]/,'"[$1]"')),o.push(e)}return o.join("\n")}),{name:"xychart-array-format-fix",priority:110,diagramTypes:["xychart"]}),l(((e,t)=>{if("gantt"!==t&&!e.trim().startsWith("gantt"))return e;console.log("\ud83d\udd0d GANTT-FIX: Processing gantt diagram task definitions");let n=e;if(!n.includes("section ")){console.log("\ud83d\udd0d GANTT-FIX: Adding missing section structure");const e=n.split("\n"),t=e.some((e=>e.trim().startsWith("title")))?e.findIndex((e=>e.trim().startsWith("title"))):0,o=Math.max(t+1,3);e.splice(o,0," section Tasks"),n=e.join("\n")}if(n.includes("dateFormat X")||n.includes("dateFormat X")){n.match(/:\s*\w+,\s*\w+,\s*\d*[hm]/)?(console.log("\ud83d\udd0d GANTT-FIX: Detected time-based gantt chart, using appropriate format"),n=n.replace(/dateFormat\s+X/g,"dateFormat X"),console.log("\ud83d\udd0d GANTT-FIX: Converting time strings to minute numbers for Mermaid compatibility")):(console.log("\ud83d\udd0d GANTT-FIX: Replacing Unix timestamp dateFormat with YYYY-MM-DD"),n=n.replace(/dateFormat\s+X/g,"dateFormat YYYY-MM-DD"),n.includes("axisFormat %s")&&(n=n.replace(/axisFormat %s/g,"axisFormat %Y-%m-%d")))}const o=n.split("\n"),r=[];let i=1;for(let s=0;s<o.length;s++){const e=o[s],t=e.trim();if(!t||t.startsWith("gantt")||t.startsWith("title")||t.startsWith("dateFormat")||t.startsWith("axisFormat")||t.startsWith("section")||t.startsWith("%%"))r.push(e);else if(t.includes(":")){const e=t.indexOf(":"),n=t.substring(0,e).trim(),o=t.substring(e+1).trim().split(",").map((e=>e.trim()));if(2===o.length&&!isNaN(parseInt(o[0]))&&!isNaN(parseInt(o[1]))){console.log("\ud83d\udd0d GANTT-FIX: Converting simple numeric format for task: ".concat(n));const e=parseInt(o[0]),t=parseInt(o[1]),a=Math.max(1,t-e);1===i?r.push(" ".concat(n," :done, t").concat(i,", 2024-01-01, ").concat(a,"d")):r.push(" ".concat(n," :done, t").concat(i,", after t").concat(i-1,", ").concat(a,"d")),i++;continue}if(o.length>=3);else{console.log("\ud83d\udd0d GANTT-FIX: Adding default format for incomplete task: ".concat(n));const e="t".concat(i);r.push(" ".concat(n," :done, ").concat(e,", 2024-01-01, 1d")),i++}}else r.push(e)}const a=r.join("\n");return console.log("\ud83d\udd0d GANTT-FIX: Processing complete"),a}),{name:"gantt-task-definition-fix",diagramTypes:["gantt"]}),l(((e,t)=>{if(!e.trim().startsWith("sankey"))return e;console.log("\ud83d\udd0d SANKEY-FIX: Processing sankey diagram");let n=e.split("\n"),o=[];for(let r of n){let e=r.trim();if(e)if(e.startsWith("sankey"))o.push(e);else if(e.includes(",")){const t=e.split(",").map((e=>e.trim()));t.length>=3&&o.push(" ".concat(t[0],",").concat(t[1],",").concat(t[2]))}}return console.log("\ud83d\udd0d SANKEY-FIX: Processing complete"),o.join("\n")}),{name:"sankey-format-fix",priority:315,diagramTypes:["sankey"]}),l(((e,t)=>{if(!e.trim().startsWith("block"))return e;console.log("\ud83d\udd0d BLOCK-COMPREHENSIVE-FIX: Processing block diagram node labels");let n=e;return n=n.replace(/(\w+)\["?\("([^"]+?)<br\/>([^"]+?)"\)/g,'$1["$2 $3"]'),n=n.replace(/\["?\("([^"]+)"\)/g,'["$1"]'),n=n.replace(/\[""([^"]+)""\]/g,'["$1"]'),console.log("\ud83d\udd0d BLOCK-COMPREHENSIVE-FIX: Processing complete"),n}),{name:"block-advanced-node-fix",priority:325,diagramTypes:["block"]}),l(((e,t)=>{if(!e.trim().startsWith("block"))return e;console.log("\ud83d\udd0d BLOCK-DIAGRAM-FIX: Processing block diagram node labels");let n=e;return n=n.replace(/\["?\(["`]([^"`)]+)["`]([^"]*)["`]\]/g,'["$1$2"]'),n=n.replace(/\["?\("([^"]+)"([^"]*?)"\]/g,'["$1$2"]'),n=n.replace(/\["\("([^"]+)<br\/>([^"]+)"\)/g,'["$1 $2"]'),console.log("\ud83d\udd0d BLOCK-DIAGRAM-FIX: Processing complete"),n}),{name:"block-basic-node-label-fix",priority:320,diagramTypes:["block"]}),l(((e,t)=>{if(!e.trim().startsWith("classDiagram"))return e;console.log("\ud83d\udd0d CLASS-CARDINALITY-FIX: Processing class diagram cardinality relationships");let n=e;return[{pattern:/\|\|--o\{/g,replacement:"||--o{"},{pattern:/(\w+)\s+\|\|--o\{\s+(\w+)\s*:\s*(.+)/g,replacement:"$1 ||--o{ $2 : $3"},{pattern:/(\w+)\s+\|\|--\|\|\s*\{\s+(\w+)/g,replacement:"$1 ||--o{ $2"},{pattern:/\|\|--\|\|\{/g,replacement:"||--o{"},{pattern:/\|\|--\|\|/g,replacement:"--\x3e"}].forEach((e=>{let{pattern:t,replacement:o}=e;const r=(n.match(t)||[]).length;r>0&&(n=n.replace(t,o),console.log("\ud83d\udd0d CLASS-CARDINALITY-FIX: Fixed ".concat(r," instances of ").concat(t.source)))})),n=n.replace(/(\w+)\s+\|\|--o\{\s+(\w+)\s*:\s*(.+?)(\s*)$/gm,"$1 ||--o{ $2 : $3$4"),console.log("\ud83d\udd0d CLASS-CARDINALITY-FIX: Processing complete"),n}),{name:"class-cardinality-relationship-fix",priority:510,diagramTypes:["classdiagram"]}),l(((e,t)=>{if(!e.trim().startsWith("classDiagram"))return e;console.log("\ud83d\udd0d CLASS-COMPREHENSIVE-FIX: Processing class diagram relationships");let n=e;return[{pattern:/\|\|--\|\|/g,replacement:"--\x3e"},{pattern:/\|\|\s*--\s*\|\|/g,replacement:"--\x3e"},{pattern:/\|\|-->/g,replacement:"--\x3e"},{pattern:/--\|\|/g,replacement:"--\x3e"},{pattern:/<\|\|--\|\|>/g,replacement:"<--\x3e"},{pattern:/\|\|==\|\|/g,replacement:"--\x3e"},{pattern:/\|\|\.\.>\|\|/g,replacement:"..>"},{pattern:/\|\|<\.\.\|\|/g,replacement:"<.."}].forEach((e=>{let{pattern:t,replacement:o}=e;const r=(n.match(t)||[]).length;r>0&&(n=n.replace(t,o),console.log("\ud83d\udd0d CLASS-COMPREHENSIVE-FIX: Fixed ".concat(r," instances of ").concat(t.source)))})),n=n.replace(/(\w+)\s+(\|\|--\|\||\|\|-\|\||--\|\|--)\s+(\w+)/g,"$1 --\x3e $3"),console.log("\ud83d\udd0d CLASS-COMPREHENSIVE-FIX: Processing complete"),n}),{name:"class-invalid-relationship-fix",priority:500,diagramTypes:["classdiagram"]}),l(((e,t)=>{if(!e.trim().startsWith("sequenceDiagram"))return e;console.log("\ud83d\udd0d CRITICAL-SEQUENCE-FIX: Processing comprehensive sequence diagram alt/else/critical structure");const n=e.split("\n"),o=[];let r=!1,i=!1,a=!1,s=0,c=!1,l=!1;for(let f=0;f<n.length;f++){const e=n[f],t=e.trim();if(t.startsWith("option ")){if(i){o.push(e);continue}{var d;console.log('\ud83d\udd0d CRITICAL-SEQUENCE-FIX: Converting invalid option to else: "'.concat(t,'"'));const n=(null===(d=e.match(/^\s*/))||void 0===d?void 0:d[0])||"";r&&!c&&(o.push("".concat(n,"else")),c=!0);continue}}if(t.startsWith("alt "))r=!0,s++,c=!1,l=!1,o.push(e);else if(t.startsWith("critical "))i=!0,s++,c=!1,l=!1,o.push(e);else if(t.startsWith("par "))a=!0,s++,o.push(e);else if("end"===t&&s>0)s--,0===s&&(r=!1,i=!1,a=!1,c=!1),l=!1,o.push(e);else if(a&&"and"===t)o.push(e);else if(i&&t.startsWith("option "))o.push(e);else if(r&&t.startsWith("break "))l=!0,o.push(e);else if(r&&t.startsWith("else ")){var g;console.log('\ud83d\udd0d CRITICAL-SEQUENCE-FIX: Converting "'.concat(t,'" -> "else"'));const n=(null===(g=e.match(/^\s*/))||void 0===g?void 0:g[0])||"";if(l){console.log('\ud83d\udd0d CRITICAL-SEQUENCE-FIX: Skipping else after break: "'.concat(t,'"'));continue}c?o.push("".concat(n,"Note over DB: Alternative path")):(o.push("".concat(n,"else")),c=!0)}else if(r&&"else"===t)if(l){var p;const t=(null===(p=e.match(/^\s*/))||void 0===p?void 0:p[0])||"";o.push("".concat(t,"Note over DB: Break terminated this path"))}else if(c){var u;const t=(null===(u=e.match(/^\s*/))||void 0===u?void 0:u[0])||"";o.push("".concat(t,"Note over DB: Alternative path"))}else{var m;((null===(m=e.match(/^\s*/))||void 0===m?void 0:m[0])||"").length<4?o.push(" else"):o.push(e),c=!0}else o.push(e)}return console.log("\ud83d\udd0d CRITICAL-SEQUENCE-FIX: Processing complete"),o.join("\n")}),{name:"sequence-comprehensive-else-fix",priority:590,diagramTypes:["sequencediagram"]}),l(((e,t)=>{if(!e.trim().startsWith("timeline"))return e;let n=e.split("\n"),o=[],r=!1;for(let i of n){let e=i.trim();e&&(e.startsWith("timeline")?o.push(e):e.startsWith("title ")?o.push(" "+e):e.startsWith("section ")?(o.push(" "+e),r=!0):r&&e.includes(" : ")?o.push(" "+e):e&&o.push(" "+e))}return o.join("\n")}),{name:"timeline-syntax-fix",priority:120,diagramTypes:["timeline"]}),l(((e,t)=>{if("gantt"!==t&&!e.trim().startsWith("gantt"))return e;let n=e;return n=n.replace(/(\d+)s/g,"$1"),n.includes("dateFormat")||(n=n.replace(/^gantt/,"gantt\n dateFormat YYYY-MM-DD")),n.includes("axisFormat")||(n=n.replace(/dateFormat[^\n]*/,"$&\n axisFormat %Y-%m-%d")),n}),{name:"gantt-date-format-fix",priority:120,diagramTypes:["gantt"]}),l(((e,t)=>{if("sequencediagram"!==t.toLowerCase()&&!e.trim().startsWith("sequenceDiagram"))return e;console.log("Running sequence diagram note formatter");const n=e.split("\n"),o=[];let r=0;for(;r<n.length;){const e=n[r],t=e.trim();if(t.startsWith("Note over ")||t.startsWith("Note left of ")||t.startsWith("Note right of ")){const i=t.match(/^(Note (?:over|left of|right of) [^:]+):\s*(.*)$/);if(i){const[,e,t]=i;let a=t,s=r+1;for(;s<n.length;){const e=n[s].trim();if(e.match(/^(participant|Note|activate|deactivate|\w+->>|\w+-->>|loop|alt|opt|par|and|else|end)/)||""===e&&s+1<n.length&&n[s+1].trim().match(/^(participant|Note|activate|deactivate|\w+->>|\w+-->>|loop|alt|opt|par|and|else|end)/))break;""!==e&&(a+="<br/>"+e),s++}a&&(a=a.replace(/\r\n/g,"\n").replace(/\r/g,"\n").split("\n").map((e=>{const t=e.trim();return 0===t.length?" ":t})).join("<br/>").replace(/<(?!br\/?>)[^>]*>/g,"").replace(/"/g,"'").replace(/\{/g,"(").replace(/\}/g,")").replace(/(\d+)\.\s*/g,"$1. ").replace(/-\s*/g,"\u2022 ").trim()),o.push(" ".concat(e,": ").concat(a)),r=s}else o.push(e),r++}else o.push(e),r++}return o.join("\n")}),{name:"sequence-diagram-note-formatter",priority:300,diagramTypes:["sequencediagram"]}),l(((e,t)=>{if(!t.toLowerCase().startsWith("statediagram")&&!e.trim().startsWith("stateDiagram"))return e;const n=e.split("\n"),o=[];let r=!1;for(const i of n){const e=i.trim();if(e.match(/^note\s+(right of|left of|over)\s+\w+/))r=!0,o.push(i);else if("end note"!==e)if(r){const e=i.replace(/^(\s*)-\s+/,"$1\u2022 ");o.push(e)}else o.push(i);else r=!1,o.push(i)}return o.join("\n")})),l(((e,t)=>{if("sequencediagram"!==t.toLowerCase()&&!e.trim().startsWith("sequenceDiagram"))return e;console.log("Running sequence diagram participant name fixer");const n=e.split("\n"),o=[];for(const r of n){let e=r;const t=r.trim();if(t.startsWith("participant ")){const n=t.match(/^participant\s+(.+)$/);if(n){const t=n[1];e=" participant ".concat(t)}}o.push(e)}return o.join("\n")}),{name:"sequence-diagram-participant-fixer",priority:290,diagramTypes:["sequencediagram"]}),l(((e,t)=>e),{name:"beta-diagram-fallback",priority:290,diagramTypes:["*"]}),l(((e,t)=>{let n=e;return n=n.replace(/(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s*$/gm,"$1 --\x3e $2\n $2 --\x3e $3\n $3 --\x3e $4"),n}),{name:"incomplete-connection-fix",priority:90,diagramTypes:["flowchart","graph"]}),l(((e,t)=>{let n=e;return n=n.replace(/C\["Load User Profil$/m,'C["Load User Profile"]'),n=n.replace(/(\w+)\["([^"]*?)$/gm,'$1["$2"]'),n=n.replace(/}\s*>\s*(\w+)\s*{/g,"}\n $1 --|> "),n=n.replace(/(class\s+\w+\s*{\s*)>\s*/g,"$1"),n=n.replace(/^(\s*)(\w+)\s*--\|>\s*([A-Z_]+)\s*$/gm,((e,t,o,r)=>n.match(new RegExp("class\\s+".concat(r,"\\s*\\{"),"m"))?e:"".concat(t,"%% ").concat(e.trim()))),n}),{name:"parsing-error-fix",priority:85,diagramTypes:["*"]}),l(((e,t)=>e.replace(/classDef\s+(\w+)\s+([^:]+):([^,]+),([^:]+):([^,\n]+)/g,((e,t,n,o,r,i)=>"classDef ".concat(t," ").concat(n,":").concat(o,",").concat(r,":").concat(i)))),{name:"classdef-color-fix",priority:100,diagramTypes:["*"]}),l(((e,t)=>e.replace(/classDef\s+(\w+)\s+((?:[a-zA-Z]+:"[^"]+",?)+)/g,((e,t,n)=>{const o=n.replace(/:"/g,":").replace(/"/g,"");return"classDef ".concat(t," ").concat(o)}))),{name:"classdef-quotes-fix",priority:110,diagramTypes:["*"]}),l(((e,t)=>{let n=e;return n=n.replace(/\[([^\]]*\/[^\]]*)\]/g,'["$1"]'),n}),{name:"node-slash-fix",priority:95,diagramTypes:["*"]}),l(((e,t)=>{const n=e.split("\n"),o=new Set;for(const a of n){if(t&&"stateDiagram"!==t&&"stateDiagram-v2"!==t&&!a.match(/^\s*stateDiagram/i))continue;const e=a.match(/\b(\w+)\b\s*:/g)||[],n=a.match(/\b(\w+)\b\s*-->/g)||[];e.forEach((e=>{const t=e.replace(/\s*:$/,"").trim();o.add(t)})),n.forEach((e=>{const t=e.replace(/\s*-->$/,"").trim();o.add(t)}))}const r=[...n],i=n.findIndex((e=>e.trim().match(/^stateDiagram(?:-v2)?/i)));if(-1!==i){const e=Array.from(o).map((e=>" ".concat(e,": ").concat(e))).join("\n");e&&r.splice(i+1,0,e)}return r.join("\n")}),{name:"state-shape-fix",priority:90,diagramTypes:["statediagram","statediagram-v2"]}),l((e=>{let t=e;return t=t.replace(/(\w+)(\s*\n\s*[A-Z])/g,"$1\n$2"),t=t.replace(/(\w+)-->/g,"$1 --\x3e"),t=t.replace(/-->(\w+)/g,"--\x3e $1"),t=t.replace(/Note(\w+):/g,"Note $1:"),t=t.replace(/\[DONE\]/g,'"DONE"'),t=t.replace(/(\w+)\[([^\]]+)\]/g,((e,t,n)=>n.includes('"')?"".concat(t,"[").concat(n,"]"):"".concat(t,'["').concat(n,'"]'))),t}),{name:"syntax-fixer",priority:50,diagramTypes:["*"]}),l(((e,t)=>{if(!e.includes("classDef")&&!e.includes("style "))return e;let n=e;return n=n.replace(/classDef\s+(\w+)\s+fill:(#[a-fA-F0-9]{6}),stroke:(#[a-fA-F0-9]{6}),stroke-width:(\d+px)/g,((e,t,n,o,r)=>"classDef ".concat(t," fill:").concat(n,",stroke:").concat(o,",stroke-width:").concat(r,",color:").concat(o))),n=n.replace(/style\s+(\w+)\s+fill:(#[a-fA-F0-9]{6}),stroke:(#[a-fA-F0-9]{6}),stroke-width:(\d+px)/g,((e,t,n,o,r)=>{const i=function(e){const t=(e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(e);if(!t)return e;return(.299*t.r+.587*t.g+.114*t.b)/255>.5?"#000000":e}(o);return"style ".concat(t," fill:").concat(n,",stroke:").concat(o,",stroke-width:").concat(r,",color:").concat(i)})),n=n.replace(/(stroke:#333)/g,"stroke:#000000"),n}),{name:"dark-mode-text-visibility-fix",priority:105,diagramTypes:["*"]}),function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n={handle:e,priority:t.priority||10,errorTypes:t.errorTypes||["*"],name:t.name||"error-handler-".concat(r.length)};r.push(n),r.sort(((e,t)=>t.priority-e.priority))}(((e,t)=>{const{container:n,definition:o,diagramType:r}=t;if(!n)return!1;n.innerHTML='\n <div class="mermaid-error-recovery" style="\n border: 1px solid #f0ad4e;\n border-radius: 4px;\n padding: 15px;\n margin: 10px 0;\n background-color: #fcf8e3;\n ">\n <div style="margin-bottom: 10px; color: #8a6d3b;">\n <strong>Diagram Rendering Error:</strong> '.concat(e.message||"Unknown error",'\n </div>\n <div style="margin-bottom: 15px;">\n <button id="toggle-source-').concat(Date.now(),'" style="\n background-color: #f0ad4e;\n color: white;\n border: none;\n padding: 5px 10px;\n border-radius: 3px;\n cursor: pointer;\n ">Show Source</button>\n </div>\n <div id="source-container-').concat(Date.now(),'" style="display: none;">\n <pre style="\n background-color: #f5f5f5;\n padding: 10px;\n border-radius: 4px;\n overflow: auto;\n max-height: 300px;\n "><code>').concat(o.replace(/</g,"<").replace(/>/g,">"),"</code></pre>\n </div>\n </div>\n ");const i=n.querySelector("#toggle-source-".concat(Date.now())),a=n.querySelector("#source-container-".concat(Date.now()));return i&&a&&i.addEventListener("click",(()=>{const e="none"===a.style.display;a.style.display=e?"block":"none",i.textContent=e?"Hide Source":"Show Source"})),!0}),{name:"fallback-renderer",priority:0,errorTypes:["*"]}),console.log("Mermaid enhancer initialized with default preprocessors and error handlers")}function p(e){if(!e)return void console.error("Mermaid library not provided");const t=e.render;e.render=async function(n,o){try{var i;let r;const p=o.trim().split("\n");let u=(null===(i=p[0])||void 0===i?void 0:i.trim())||"";if("---"===u&&p.length>1){var a;let e=!0,t="";for(let n=1;n<p.length;n++){const o=p[n].trim();if(e)"---"===o&&(e=!1);else if(o){t=o;break}}u=t||(null===(a=p[0])||void 0===a?void 0:a.trim())||""}r=u.split(" ")[0].toLowerCase(),console.log("Mermaid preprocessing debug:",{originalType:r,definition:o.substring(0,100)+"..."});const m=d(o,r,e);if(console.log("After preprocessing:",{originalType:r,processedLength:m.length,processedStart:m.substring(0,100)+"..."}),!m||0===m.trim().length)throw new Error("Empty definition after preprocessing");(m.includes("\u2022 ")||m.includes("\u2022"))&&console.warn("Definition still contains bullet characters after preprocessing");const f=m.trim()+"\n%% PROCESSED-".concat(Date.now());if(console.log("\ud83d\udd0d FINAL-DEF: About to render with processed definition:"),console.log("\ud83d\udd0d FINAL-DEF: Length:",f.length),console.log("\ud83d\udd0d FINAL-DEF: Content:",f),e.mermaidAPI&&"function"===typeof e.mermaidAPI.render){console.log("\ud83d\udd0d BYPASS: Using mermaidAPI.render directly to avoid internal preprocessing");try{const t=await e.mermaidAPI.render(n,f),o="string"===typeof t?t:t.svg||"";return console.log("\ud83d\udd0d BYPASS: Direct API render successful, SVG length:",o.length),{svg:o,bindFunctions:()=>{}}}catch(g){console.log("\ud83d\udd0d BYPASS: Direct API render failed, falling back to original method:",g instanceof Error?g.message:String(g))}}console.log("\ud83d\udd0d FALLBACK: Using original render method");for(var s=arguments.length,c=new Array(s>2?s-2:0),l=2;l<s;l++)c[l-2]=arguments[l];const h=await t.call(this,n,f,...c);return console.log("\ud83d\udd0d RENDER-RESULT: Mermaid render completed, result type:",typeof h),h&&"object"===typeof h&&h.svg?h:(console.warn("Mermaid render returned unexpected result:",h),{svg:"",bindFunctions:()=>{}})}catch(p){console.error("Mermaid rendering error:",p);const e=function(e,t){const n=e.name||"Error";let o=!1;for(const a of r)if(a.errorTypes.includes("*")||a.errorTypes.includes(n))try{if(a.handle(e,t)){o=!0;break}}catch(i){console.warn("Error handler ".concat(a.name," failed:"),i)}return o}(p,{container:document.getElementById(n)||void 0,definition:o,diagramType:o.trim().split("\n")[0].trim(),error:p});if(!e)throw p;return{svg:"",bindFunctions:()=>{}}}}}function u(e){if(g(),e)p(e);else if("undefined"!==typeof window){const e=setInterval((()=>{window.mermaid&&(p(window.mermaid),clearInterval(e))}),100);setTimeout((()=>{clearInterval(e)}),1e4)}l(((e,t)=>{if(!e.trim().startsWith("classDiagram"))return e;console.log("\ud83d\udd0d CLASS-CONSOLIDATED-FIX: Processing all class diagram relationship issues");let n=e;n=n.replace(/(\w+)\s+\|\|--o\{\s+(\w+)\s*:\s*(.+)/g,"$1 --\x3e $2 : $3"),n=n.replace(/(\w+)\s+\}\|--\|\{\s+(\w+)\s*:\s*(.+)/g,"$1 --\x3e $2 : $3");return[{pattern:/\|\|--\|\|/g,replacement:"--\x3e"},{pattern:/\|\|\s*--\s*\|\|/g,replacement:"--\x3e"},{pattern:/\|\|-->/g,replacement:"--\x3e"},{pattern:/--\|\|/g,replacement:"--\x3e"},{pattern:/<\|\|--\|\|>/g,replacement:"<--\x3e"},{pattern:/\|\|==\|\|/g,replacement:"--\x3e"},{pattern:/\|\|\.\.>\|\|/g,replacement:"..>"},{pattern:/\|\|<\.\.\|\|/g,replacement:"<.."}].forEach((e=>{let{pattern:t,replacement:o}=e;const r=(n.match(t)||[]).length;r>0&&(n=n.replace(t,o),console.log("\ud83d\udd0d CLASS-CONSOLIDATED-FIX: Fixed ".concat(r," instances of ").concat(t.source)))})),n=n.replace(/(\w+)\s+(-->|<--|<\|--|-->\||<\|--\|>)\s*$/gm,""),n=n.replace(/^\s*(-->|<--|<\|--|-->\||<\|--\|>)\s*$/gm,""),console.log("\ud83d\udd0d CLASS-CONSOLIDATED-FIX: Processing complete"),n}),{name:"class-consolidated-relationship-fix",priority:520,diagramTypes:["classdiagram"]}),l(((e,t)=>{if("classdiagram"!==t.toLowerCase()&&!e.trim().startsWith("classDiagram"))return e;console.log("\ud83d\udd0d CLASS-RELATIONSHIP-FIX: Running class diagram relationship fixer (priority 85)");let n=e;return n=n.replace(/\|\|--\|\|/g,"--\x3e"),n=n.replace(/\|\|\s*--\s*\|\|/g,"--\x3e"),n=n.replace(/\|\|-->/g,"--\x3e"),n=n.replace(/--\|\|/g,"--\x3e"),n=n.replace(/<\|\|--\|\|>/g,"<--\x3e"),console.log("\ud83d\udd0d CLASS-RELATIONSHIP-FIX: Processing complete"),n}),{name:"class-relationship-syntax-fix-2",priority:440,diagramTypes:["classdiagram"]}),l(((e,t)=>{if("classdiagram"!==t.toLowerCase()&&!e.trim().startsWith("classDiagram"))return e;console.log("\ud83d\udd0d CLASS-RELATIONSHIP-FIX: Running class diagram relationship fixer (priority 85)");let n=e;const o=(n.match(/\|\|--\|\|/g)||[]).length;console.log("\ud83d\udd0d CLASS-RELATIONSHIP-FIX: Found ".concat(o," instances of ||--||")),n=n.replace(/\|\|--\|\|/g,"--\x3e"),n=n.replace(/\|\|\s*--\s*\|\|/g,"--\x3e");const r=(n.match(/\|\|--\|\|/g)||[]).length;console.log("\ud83d\udd0d CLASS-RELATIONSHIP-FIX: After replacement: ".concat(r," instances remaining"));const i=n.split("\n"),a=[];let s=!1;for(const c of i){let e=c;const t=c.trim();if(t.match(/class\s+\w+\s*{/)?s=!0:s&&"}"===t&&(s=!1),!s){const n=t.match(/^(\w+)\s+([<>])\s+(\w+)$/);if(n){const[,o,r,i]=n,a=">"===r?"--\x3e":"<--";e="".concat(o," ").concat(a," ").concat(i),console.log('Fixed relationship syntax: "'.concat(t,'" -> "').concat(e,'"'))}const o=t.match(/^(\w+)\s+--\s+(\w+)$/);if(o){const[,n,r]=o;e="".concat(n," --\x3e ").concat(r),console.log('Fixed missing arrow: "'.concat(t,'" -> "').concat(e,'"'))}}a.push(e)}return n}),{name:"class-diagram-legacy-relationship-fixer",priority:85,diagramTypes:["classdiagram"]}),l(((e,t)=>{if("sequencediagram"!==t.toLowerCase()&&!e.trim().startsWith("sequenceDiagram"))return e;let n=e;return["opt","alt","loop","par","and","else","end"].forEach((e=>{const t=new RegExp("(->>|--\x3e>|->>\\+|--\x3e>\\+|->>-|--\x3e>-)(\\s*)".concat(e,"\\b"),"gi");n=n.replace(t,((t,n,o)=>"".concat(n).concat(o,'"').concat(e,'"')));const o=new RegExp("^(\\s*)".concat(e,"\\b(\\s*)(->>|--\x3e>|->>\\+|--\x3e>\\+|->>-|--\x3e>-)"),"gim");n=n.replace(o,((t,n,o,r)=>"".concat(n,'"').concat(e,'"').concat(o).concat(r)))})),n}),{name:"sequence-diagram-keyword-participant-fix",priority:285,diagramTypes:["sequencediagram"]})}}}]);
2
- //# sourceMappingURL=55734.90d8bd52.chunk.js.map