@viswa-test/test-citation 0.0.390 → 0.0.391

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.
Files changed (145) hide show
  1. package/dist/cjs/features/CognitiveCompare/CitationAnchor.js +1 -1
  2. package/dist/cjs/features/CognitiveCompare/CitationAnchor.js.map +1 -1
  3. package/dist/cjs/features/CognitiveCompare/CitationRenderer.js +1 -1
  4. package/dist/cjs/features/CognitiveCompare/CitationRenderer.js.map +1 -1
  5. package/dist/cjs/features/CognitiveCompare/CognitiveCompare.js +1 -1
  6. package/dist/cjs/features/CognitiveCompare/CognitiveCompare.js.map +1 -1
  7. package/dist/cjs/features/CognitiveCompare/CognitiveCompareConstants.js +1 -1
  8. package/dist/cjs/features/CognitiveCompare/CognitiveCompareConstants.js.map +1 -1
  9. package/dist/cjs/features/CognitiveCompare/CognitiveComparehelpers.js +1 -1
  10. package/dist/cjs/features/CognitiveCompare/CognitiveComparehelpers.js.map +1 -1
  11. package/dist/cjs/features/CognitiveCompare/CognitivePopup.js +1 -1
  12. package/dist/cjs/features/CognitiveCompare/CognitivePopup.js.map +1 -1
  13. package/dist/cjs/features/CognitiveCompare/CompareContext.js +1 -1
  14. package/dist/cjs/features/CognitiveCompare/CompareContext.js.map +1 -1
  15. package/dist/cjs/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js +1 -1
  16. package/dist/cjs/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js.map +1 -1
  17. package/dist/cjs/features/CognitiveCompare/Guidelines/components/WebGptPanel.js +1 -1
  18. package/dist/cjs/features/CognitiveCompare/Guidelines/components/WebGptPanel.js.map +1 -1
  19. package/dist/cjs/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js +1 -1
  20. package/dist/cjs/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js.map +1 -1
  21. package/dist/cjs/features/CognitiveCompare/components/LHSSectionRow.js +1 -1
  22. package/dist/cjs/features/CognitiveCompare/components/LHSSectionRow.js.map +1 -1
  23. package/dist/cjs/features/CognitiveCompare/components/RHSSectionRow.js +1 -1
  24. package/dist/cjs/features/CognitiveCompare/components/RHSSectionRow.js.map +1 -1
  25. package/dist/cjs/features/CognitiveCompare/components/SectionAccordion.js +1 -1
  26. package/dist/cjs/features/CognitiveCompare/components/SectionAccordion.js.map +1 -1
  27. package/dist/cjs/features/CognitiveCompare/components/SubSectionAccordion.js +1 -1
  28. package/dist/cjs/features/CognitiveCompare/components/SubSectionAccordion.js.map +1 -1
  29. package/dist/cjs/features/CognitiveCompare/components/SvgConnectors.js +1 -1
  30. package/dist/cjs/features/CognitiveCompare/components/SvgConnectors.js.map +1 -1
  31. package/dist/cjs/features/CognitiveCompare/hooks/memoizedMarkdown.js +1 -1
  32. package/dist/cjs/features/CognitiveCompare/hooks/memoizedMarkdown.js.map +1 -1
  33. package/dist/cjs/features/CognitiveCompare/hooks/useCompareData.js +1 -1
  34. package/dist/cjs/features/CognitiveCompare/hooks/useCompareData.js.map +1 -1
  35. package/dist/cjs/features/CognitiveCompare/hooks/useLinesCalculator.js +1 -1
  36. package/dist/cjs/features/CognitiveCompare/hooks/useLinesCalculator.js.map +1 -1
  37. package/dist/cjs/features/CognitiveCompare/hooks/useSideBySide.js +1 -1
  38. package/dist/cjs/features/CognitiveCompare/hooks/useSideBySide.js.map +1 -1
  39. package/dist/cjs/features/PdfViewer/PdfToolbar.js +1 -1
  40. package/dist/cjs/features/PdfViewer/PdfToolbar.js.map +1 -1
  41. package/dist/cjs/features/PdfViewer/PdfViewer.css.js +1 -1
  42. package/dist/cjs/features/PdfViewer/PdfViewer.js +1 -1
  43. package/dist/cjs/features/PdfViewer/PdfViewer.js.map +1 -1
  44. package/dist/cjs/features/PdfViewer/rotationManager.js +1 -1
  45. package/dist/cjs/features/PdfViewer/rotationManager.js.map +1 -1
  46. package/dist/cjs/features/PdfViewer/usePdfHighlight.js +1 -1
  47. package/dist/cjs/features/PdfViewer/usePdfHighlight.js.map +1 -1
  48. package/dist/cjs/features/PdfViewer/zoomStateManager.js +2 -0
  49. package/dist/cjs/features/PdfViewer/zoomStateManager.js.map +1 -0
  50. package/dist/cjs/features/SegmentReviewComponents/CognitiveScoreBadge.js +1 -1
  51. package/dist/cjs/features/SegmentReviewComponents/CognitiveScoreBadge.js.map +1 -1
  52. package/dist/cjs/features/SegmentReviewComponents/reviewStepAdapters.js +1 -1
  53. package/dist/cjs/features/SegmentReviewComponents/reviewStepAdapters.js.map +1 -1
  54. package/dist/features/CognitiveCompare/CitationAnchor.js +1 -1
  55. package/dist/features/CognitiveCompare/CitationAnchor.js.map +1 -1
  56. package/dist/features/CognitiveCompare/CitationRenderer.js +1 -1
  57. package/dist/features/CognitiveCompare/CitationRenderer.js.map +1 -1
  58. package/dist/features/CognitiveCompare/CognitiveCompare.js +1 -1
  59. package/dist/features/CognitiveCompare/CognitiveCompare.js.map +1 -1
  60. package/dist/features/CognitiveCompare/CognitiveCompareConstants.js +1 -1
  61. package/dist/features/CognitiveCompare/CognitiveCompareConstants.js.map +1 -1
  62. package/dist/features/CognitiveCompare/CognitiveComparehelpers.js +1 -1
  63. package/dist/features/CognitiveCompare/CognitiveComparehelpers.js.map +1 -1
  64. package/dist/features/CognitiveCompare/CognitivePopup.js +1 -1
  65. package/dist/features/CognitiveCompare/CognitivePopup.js.map +1 -1
  66. package/dist/features/CognitiveCompare/CompareContext.js +1 -1
  67. package/dist/features/CognitiveCompare/CompareContext.js.map +1 -1
  68. package/dist/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js +1 -1
  69. package/dist/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js.map +1 -1
  70. package/dist/features/CognitiveCompare/Guidelines/components/WebGptPanel.js +1 -1
  71. package/dist/features/CognitiveCompare/Guidelines/components/WebGptPanel.js.map +1 -1
  72. package/dist/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js +1 -1
  73. package/dist/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js.map +1 -1
  74. package/dist/features/CognitiveCompare/components/LHSSectionRow.js +1 -1
  75. package/dist/features/CognitiveCompare/components/LHSSectionRow.js.map +1 -1
  76. package/dist/features/CognitiveCompare/components/RHSSectionRow.js +1 -1
  77. package/dist/features/CognitiveCompare/components/RHSSectionRow.js.map +1 -1
  78. package/dist/features/CognitiveCompare/components/SectionAccordion.js +1 -1
  79. package/dist/features/CognitiveCompare/components/SectionAccordion.js.map +1 -1
  80. package/dist/features/CognitiveCompare/components/SubSectionAccordion.js +1 -1
  81. package/dist/features/CognitiveCompare/components/SubSectionAccordion.js.map +1 -1
  82. package/dist/features/CognitiveCompare/components/SvgConnectors.js +1 -1
  83. package/dist/features/CognitiveCompare/components/SvgConnectors.js.map +1 -1
  84. package/dist/features/CognitiveCompare/hooks/memoizedMarkdown.js +1 -1
  85. package/dist/features/CognitiveCompare/hooks/memoizedMarkdown.js.map +1 -1
  86. package/dist/features/CognitiveCompare/hooks/useCompareData.js +1 -1
  87. package/dist/features/CognitiveCompare/hooks/useCompareData.js.map +1 -1
  88. package/dist/features/CognitiveCompare/hooks/useLinesCalculator.js +1 -1
  89. package/dist/features/CognitiveCompare/hooks/useLinesCalculator.js.map +1 -1
  90. package/dist/features/CognitiveCompare/hooks/useSideBySide.js +1 -1
  91. package/dist/features/CognitiveCompare/hooks/useSideBySide.js.map +1 -1
  92. package/dist/features/PdfViewer/PdfToolbar.js +1 -1
  93. package/dist/features/PdfViewer/PdfToolbar.js.map +1 -1
  94. package/dist/features/PdfViewer/PdfViewer.css.js +1 -1
  95. package/dist/features/PdfViewer/PdfViewer.js +1 -1
  96. package/dist/features/PdfViewer/PdfViewer.js.map +1 -1
  97. package/dist/features/PdfViewer/rotationManager.js +1 -1
  98. package/dist/features/PdfViewer/rotationManager.js.map +1 -1
  99. package/dist/features/PdfViewer/usePdfHighlight.js +1 -1
  100. package/dist/features/PdfViewer/usePdfHighlight.js.map +1 -1
  101. package/dist/features/PdfViewer/zoomStateManager.js +2 -0
  102. package/dist/features/PdfViewer/zoomStateManager.js.map +1 -0
  103. package/dist/features/SegmentReviewComponents/CognitiveScoreBadge.js +1 -1
  104. package/dist/features/SegmentReviewComponents/CognitiveScoreBadge.js.map +1 -1
  105. package/dist/features/SegmentReviewComponents/reviewStepAdapters.js +1 -1
  106. package/dist/features/SegmentReviewComponents/reviewStepAdapters.js.map +1 -1
  107. package/dist/types/features/CognitiveCompare/CitationAnchor.d.ts +0 -2
  108. package/dist/types/features/CognitiveCompare/CitationAnchor.d.ts.map +1 -1
  109. package/dist/types/features/CognitiveCompare/CitationRenderer.d.ts +1 -8
  110. package/dist/types/features/CognitiveCompare/CitationRenderer.d.ts.map +1 -1
  111. package/dist/types/features/CognitiveCompare/CognitiveCompare.d.ts +1 -1
  112. package/dist/types/features/CognitiveCompare/CognitiveCompare.d.ts.map +1 -1
  113. package/dist/types/features/CognitiveCompare/CognitiveCompareConstants.d.ts +1 -1
  114. package/dist/types/features/CognitiveCompare/CognitiveCompareConstants.d.ts.map +1 -1
  115. package/dist/types/features/CognitiveCompare/CognitiveCompareTypes.d.ts +3 -12
  116. package/dist/types/features/CognitiveCompare/CognitiveCompareTypes.d.ts.map +1 -1
  117. package/dist/types/features/CognitiveCompare/CognitiveComparehelpers.d.ts +0 -12
  118. package/dist/types/features/CognitiveCompare/CognitiveComparehelpers.d.ts.map +1 -1
  119. package/dist/types/features/CognitiveCompare/CognitivePopup.d.ts.map +1 -1
  120. package/dist/types/features/CognitiveCompare/CompareContext.d.ts +2 -9
  121. package/dist/types/features/CognitiveCompare/CompareContext.d.ts.map +1 -1
  122. package/dist/types/features/CognitiveCompare/Guidelines/components/GuidelinePanel.d.ts.map +1 -1
  123. package/dist/types/features/CognitiveCompare/Guidelines/components/WebGptPanel.d.ts.map +1 -1
  124. package/dist/types/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.d.ts +1 -14
  125. package/dist/types/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.d.ts.map +1 -1
  126. package/dist/types/features/CognitiveCompare/components/LHSSectionRow.d.ts.map +1 -1
  127. package/dist/types/features/CognitiveCompare/components/RHSSectionRow.d.ts.map +1 -1
  128. package/dist/types/features/CognitiveCompare/components/SectionAccordion.d.ts.map +1 -1
  129. package/dist/types/features/CognitiveCompare/components/SubSectionAccordion.d.ts.map +1 -1
  130. package/dist/types/features/CognitiveCompare/components/SvgConnectors.d.ts +3 -2
  131. package/dist/types/features/CognitiveCompare/components/SvgConnectors.d.ts.map +1 -1
  132. package/dist/types/features/CognitiveCompare/hooks/memoizedMarkdown.d.ts +1 -2
  133. package/dist/types/features/CognitiveCompare/hooks/memoizedMarkdown.d.ts.map +1 -1
  134. package/dist/types/features/CognitiveCompare/hooks/useCompareData.d.ts +1 -1
  135. package/dist/types/features/CognitiveCompare/hooks/useCompareData.d.ts.map +1 -1
  136. package/dist/types/features/CognitiveCompare/hooks/useLinesCalculator.d.ts.map +1 -1
  137. package/dist/types/features/CognitiveCompare/hooks/useSideBySide.d.ts.map +1 -1
  138. package/dist/types/features/PdfViewer/PdfToolbar.d.ts.map +1 -1
  139. package/dist/types/features/PdfViewer/PdfViewer.d.ts.map +1 -1
  140. package/dist/types/features/PdfViewer/rotationManager.d.ts.map +1 -1
  141. package/dist/types/features/PdfViewer/usePdfHighlight.d.ts +1 -2
  142. package/dist/types/features/PdfViewer/usePdfHighlight.d.ts.map +1 -1
  143. package/dist/types/features/PdfViewer/zoomStateManager.d.ts +21 -0
  144. package/dist/types/features/PdfViewer/zoomStateManager.d.ts.map +1 -0
  145. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"useCompareData.js","sources":["../../../../src/features/CognitiveCompare/hooks/useCompareData.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { getSideData, getRationale, hasValue, safeStringify, isMissingStr, DEVIATION_BADGE_SEPARATOR, resolveComparisonInputItems } from \"../CognitiveComparehelpers\";\nimport { ComparisonRow, SectionBlock, ProposedRuleData, RuleData, ComparisonConfig } from \"../CognitiveCompareTypes\";\nimport { buildComparisonRows } from \"../utils/buildComparisonRows\";\n\nconst DEFAULT_RULE_FALLBACK: RuleData = { id: \"\", title: \"\", similarity: 0, sections: [] };\n\nexport const useCognitiveTreeData = (\n treeData: Record<string, any> | undefined,\n maintainRelativeOrder: boolean,\n deviationData: Record<string, any> | null,\n resolvedComparisonConfig: ComparisonConfig,\n enableDeviationSchemaBackwardCompatibility: boolean = true,\n guidelinesData?: string | Record<string, any> | null,\n isGuidelineModeFromParent?: boolean,\n) => {\n // AdaptTreeData function \n // memoized to increase performance\n // Stabilize the deviationData reference by stringifying it.\n // This prevents React from triggering re-renders purely due to memory reference changes.\n // We keep accepting it as a string so the memo dep stays content-based.\n const deviationDataStr = typeof deviationData === \"string\" ? deviationData : JSON.stringify(deviationData || {});\n\n // ── NEW: Check for either the new learnings_data or the old artifactData ──\n const isGuidelineMode = isGuidelineModeFromParent ?? Boolean(\n typeof guidelinesData === \"string\"\n ? guidelinesData.trim()\n : guidelinesData &&\n (guidelinesData.learnings_data ||\n guidelinesData.data?.artifactData?.userStorySnapshot),\n );\n\n const { activeProposed, activeVariants, comparisonRows, parseError } = useMemo(() => {\n if (!treeData || Object.keys(treeData).length === 0) {\n return {\n activeProposed: {} as ProposedRuleData,\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: \"Tree data is required\",\n };\n }\n const stableDeviationData = JSON.parse(deviationDataStr);\n\n try {\n const nodes = treeData.nodes || treeData;\n let baseSections: any[] = []; \n let refSections: any[] = []; \n let comparisonRows: ComparisonRow[] = [];\n\n const rootId = treeData.base_root_id;\n const indexMap = treeData.input_index_map || { \"0\": \"left\", \"1\": \"right\" };\n const rootNode = treeData[rootId] || nodes[rootId];\n\n if (!rootNode || rootNode.display_node === false) {\n return {\n activeProposed: { title: \"No Data\", sections: [] },\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: null,\n };\n }\n \n const contentMapping = treeData.content_mapping || {};\n const getNode = (nodeId: string) => treeData[nodeId] || nodes[nodeId];\n \n\n const normalizeEvaluationResult = (rawEvaluationResult: any, nodeLeftId: string, nodeRightId: string) => {\n if (!rawEvaluationResult || typeof rawEvaluationResult !== \"object\") {\n return rawEvaluationResult || null;\n }\n\n // Old format already supported by UI.\n if (rawEvaluationResult.deviations) {\n return rawEvaluationResult;\n }\n\n if (enableDeviationSchemaBackwardCompatibility) {\n return rawEvaluationResult;\n }\n\n const numericDeviationKeys = Object.keys(rawEvaluationResult).filter(\n (k) => /^\\d+$/.test(k),\n );\n\n if (!numericDeviationKeys.length) {\n return rawEvaluationResult;\n }\n\n const sortedDeviationKeys = numericDeviationKeys.sort(\n (a, b) => Number(a) - Number(b),\n );\n const normalizedDeviations: Record<string, any> = {};\n const deviationEntries: Record<string, any> = {};\n let firstEntry: any = null;\n\n sortedDeviationKeys.forEach((devKey) => {\n const entry = rawEvaluationResult[devKey];\n if (!entry || typeof entry !== \"object\") return;\n if (!firstEntry) firstEntry = entry;\n\n const isSameEvaluation =\n safeStringify(entry?.evaluation_outputs?.output_value)\n .trim()\n .toLowerCase() === \"same\";\n const shouldShowHighlights =\n (!entry?.status || entry.status === \"pending\") && !isSameEvaluation;\n const deviationHighlight =\n entry?.deviation_highlight ||\n entry?.web_search_answer?.deviation_highlight;\n\n const citationHighlights = (docId: string): string[] => {\n const citations = entry?.cognitive_decisioning?.citations || entry?.citations || {};\n return Object.values(citations)\n .map((citation: any) => citation?.[docId]?.highlighted_text)\n .filter((text: any) => typeof text === \"string\" && text.trim().length > 0);\n };\n\n const firstNonEmpty = (...values: any[]): string[] => {\n for (const value of values) {\n if (Array.isArray(value) && value.some((text) => !isMissingStr(text))) {\n return value;\n }\n }\n return [];\n };\n\n const leftHighlights: string[] = shouldShowHighlights\n ? firstNonEmpty(\n entry?.deviation_highlights?.[nodeLeftId] ||\n entry?.deviation_highlights?.[indexMap[\"0\"] as string],\n typeof deviationHighlight === \"string\"\n ? [deviationHighlight]\n : [],\n citationHighlights(nodeLeftId),\n citationHighlights(indexMap[\"0\"] as string),\n )\n : [];\n\n const rightHighlights: string[] = shouldShowHighlights\n ? firstNonEmpty(\n entry?.deviation_highlights?.[nodeRightId] ||\n entry?.deviation_highlights?.[indexMap[\"1\"] as string],\n citationHighlights(nodeRightId),\n citationHighlights(indexMap[\"1\"] as string),\n )\n : [];\n\n normalizedDeviations[devKey] = {\n [indexMap[\"0\"] as string]: leftHighlights[0] || \"\", \n [indexMap[\"1\"] as string]: rightHighlights[0] || \"\",\n deviation_summary: entry?.deviation_summary || \"\",\n deviation_title: entry?.deviation_title,\n deviation_impact: entry?.deviation_impact,\n deviation_explanation: entry?.deviation_explanation,\n evaluation_outputs: entry?.evaluation_outputs,\n cognitive_decisioning: entry?.cognitive_decisioning,\n deviation_highlights: entry?.deviation_highlights,\n };\n\n deviationEntries[devKey] = entry;\n });\n\n return {\n ...rawEvaluationResult,\n deviation_title: firstEntry?.deviation_title || rawEvaluationResult?.deviation_title,\n deviation_impact: firstEntry?.deviation_impact || rawEvaluationResult?.deviation_impact,\n deviation_summary: firstEntry?.deviation_summary || rawEvaluationResult?.deviation_summary,\n deviation_explanation:\n firstEntry?.deviation_explanation || rawEvaluationResult?.deviation_explanation,\n evaluation_outputs:\n firstEntry?.evaluation_outputs || rawEvaluationResult?.evaluation_outputs,\n cognitive_decisioning:\n firstEntry?.cognitive_decisioning || rawEvaluationResult?.cognitive_decisioning,\n deviations: normalizedDeviations,\n deviation_entries: deviationEntries,\n };\n };\n\n // UNIVERSAL RE-ROUTING ENGINE (WITH SORTING FIX)\n const reRouteRHSTree = (sections: any[]) => {\n const allNodesMap = new Map<string, any>();\n \n const indexNodes = (nodes: any[]) => {\n nodes.forEach(node => {\n if (node.id) allNodesMap.set(node.id, node);\n if (node.subsections?.length) indexNodes(node.subsections);\n });\n };\n indexNodes(sections);\n \n const moveNodes = (nodes: any[], parentNode?: any): any[] => {\n let filteredNodes: any[] = [];\n \n for (const node of nodes) {\n const targetParentId = node.ref_parent_section_node_id;\n \n if (targetParentId && allNodesMap.has(targetParentId) && targetParentId !== parentNode?.id) {\n const targetParent = allNodesMap.get(targetParentId)!;\n if (!targetParent.subsections) targetParent.subsections = [];\n \n if (!targetParent.subsections.some((s: any) => s.id === node.id)) {\n targetParent.subsections.push(node);\n }\n } else {\n if (node.subsections?.length) {\n node.subsections = moveNodes(node.subsections, node);\n }\n filteredNodes.push(node);\n }\n }\n return filteredNodes;\n };\n \n const finalSections = moveNodes(sections);\n\n // Sort step added to ensure display_index is respected after re-routing\n const sortSubsections = (nodes: any[]) => {\n nodes.forEach(node => {\n if (node.subsections && node.subsections.length > 0) {\n node.subsections.sort((a: any, b: any) => {\n if (a.selfIndex < 0 && b.selfIndex >= 0) return 1;\n if (a.selfIndex >= 0 && b.selfIndex < 0) return -1;\n return (a.selfIndex || 0) - (b.selfIndex || 0);\n });\n sortSubsections(node.subsections);\n }\n });\n };\n\n sortSubsections(finalSections);\n return finalSections;\n };\n\n const getNodeInputIds = (node: any) => {\n const nodeInputKeys = node.comparison_inputs ? Object.keys(node.comparison_inputs) : [];\n let nodeLeftId = indexMap[\"0\"];\n let nodeRightId = indexMap[\"1\"];\n\n if (nodeInputKeys.length > 0) {\n nodeLeftId = nodeInputKeys.includes(indexMap[\"0\"]) ? indexMap[\"0\"] : nodeInputKeys[0];\n nodeRightId = nodeInputKeys.includes(indexMap[\"1\"]) ? indexMap[\"1\"] : (nodeInputKeys.length > 1 ? nodeInputKeys[1] : nodeInputKeys[0]);\n }\n\n return { nodeLeftId, nodeRightId };\n };\n\n const getParentContentId = (attrs: any) =>\n attrs?.entity_id ||\n attrs?.ref_parent_section_node_id ||\n attrs?.parent_entity_id ||\n null;\n\n const makeSectionBlock = (\n nodeId: string,\n item: any,\n evaluationResult: any,\n rationale: any,\n ): SectionBlock => {\n const attrs = item.attributes || {};\n const data = item.data || {};\n const displayTitle = attrs.display_title !== false;\n const displayContent = attrs.display_content !== false;\n const title = displayTitle ? safeStringify(data.title || \"\") : \"\";\n const content = displayContent ? safeStringify(data.content || \"\") : \"\";\n const changeHistory = displayContent ? safeStringify(data.change_history || \"\") : \"\";\n const selfIndex =\n attrs.display_index !== undefined && attrs.display_index !== null\n ? Number(attrs.display_index)\n : -1;\n const parentContentId = getParentContentId(attrs);\n const hasData = !!(title.trim() || content.trim());\n\n return {\n id: `${nodeId}::${item.contentId}`,\n nodeId,\n contentId: item.contentId,\n parentContentId,\n title,\n content,\n change_history: changeHistory,\n displayTitle,\n displayContent,\n subsections: [],\n ...(hasData ? rationale : { score: undefined, relation: \"not_defined\" }),\n evaluationResult,\n evaluationResults: evaluationResult ? [evaluationResult] : [],\n selfIndex,\n refIndexes: [],\n refContentIds: [],\n ref_parent_section_node_id: parentContentId,\n } as SectionBlock;\n };\n\n const mergeBlock = (target: any, incoming: any) => {\n target.refIndexes = Array.from(new Set([...(target.refIndexes || []), ...(incoming.refIndexes || [])]));\n target.refContentIds = Array.from(new Set([...(target.refContentIds || []), ...(incoming.refContentIds || [])]));\n\n const existingChildKeys = new Set(\n (target.subsections || []).map((child: any) =>\n child.id || child.contentId || child.nodeId,\n ),\n );\n (incoming.subsections || []).forEach((child: any) => {\n const childKey = child.id || child.contentId || child.nodeId;\n if (!existingChildKeys.has(childKey)) {\n target.subsections = [...(target.subsections || []), child];\n existingChildKeys.add(childKey);\n }\n });\n\n const mergedEvaluationResults = [\n ...(target.evaluationResults || (target.evaluationResult ? [target.evaluationResult] : [])),\n ...(incoming.evaluationResults || (incoming.evaluationResult ? [incoming.evaluationResult] : [])),\n ].filter(Boolean);\n const seenEvaluationResults = new Set<string>();\n target.evaluationResults = mergedEvaluationResults.filter((result: any) => {\n const key = result?.nodeId || JSON.stringify(Object.keys(result?.deviations || result || {}));\n if (seenEvaluationResults.has(key)) return false;\n seenEvaluationResults.add(key);\n return true;\n });\n\n if (!target.evaluationResult && incoming.evaluationResult) target.evaluationResult = incoming.evaluationResult;\n if (!target.cognitiveData && incoming.cognitiveData) target.cognitiveData = incoming.cognitiveData;\n\n return target;\n };\n\n const sortFn = (a: any, b: any) => {\n if (a.selfIndex! < 0 && b.selfIndex! >= 0) return 1;\n if (a.selfIndex! >= 0 && b.selfIndex! < 0) return -1;\n return a.selfIndex! - b.selfIndex!;\n };\n\n const buildSideSections = (nodeId: string, sideIndex: \"0\" | \"1\"): SectionBlock[] => {\n const node = getNode(nodeId);\n if (!node || node.display_node === false) return [];\n \n if (isGuidelineMode && sideIndex === \"1\") return [];\n\n const { nodeLeftId, nodeRightId } = getNodeInputIds(node);\n const rationale = getRationale(node);\n const rawEvaluationResult =\n stableDeviationData?.[nodeId]?.evaluation_result || node.evaluation_result || null;\n const normalizedEvaluationResult = normalizeEvaluationResult(rawEvaluationResult, nodeLeftId, nodeRightId);\n const evaluationResult = normalizedEvaluationResult && typeof normalizedEvaluationResult === \"object\"\n ? { ...normalizedEvaluationResult, nodeId }\n : normalizedEvaluationResult;\n const items = resolveComparisonInputItems(node, sideIndex, indexMap, contentMapping);\n\n const sections = items.map((item) =>\n makeSectionBlock(nodeId, item, evaluationResult, rationale),\n );\n\n if (node.next) {\n const childSections = (Object.values(node.next) as string[]).flatMap((childId) =>\n buildSideSections(childId, sideIndex),\n );\n sections.forEach((section) => {\n const matchedChildren = childSections.filter((child: any) =>\n !child.parentContentId ||\n child.parentContentId === section.contentId ||\n child.parentContentId === section.parentContentId,\n );\n section.subsections = matchedChildren.length ? matchedChildren : childSections;\n });\n }\n\n return sections;\n };\n\n if (!maintainRelativeOrder) {\n if (rootNode.next) {\n (Object.values(rootNode.next) as string[]).forEach((nodeId) => {\n const node = getNode(nodeId);\n if (!node || node.display_node === false) return;\n\n const leftBlocks = buildSideSections(nodeId, \"0\");\n\n if (isGuidelineMode) {\n baseSections.push(...leftBlocks);\n return;\n }\n\n const rightBlocks = reRouteRHSTree(buildSideSections(nodeId, \"1\"));\n comparisonRows.push(\n ...buildComparisonRows(nodeId, leftBlocks, rightBlocks),\n );\n });\n }\n\n if (!isGuidelineMode) {\n baseSections = comparisonRows.map((row) => row.left);\n refSections = comparisonRows.map((row) => row.right);\n }\n\n } else {\n const buildRelativeOrderMapping = (nodeMap?: Record<string, string> | null, depth = 0) => {\n let refSections: SectionBlock[] = [];\n let baseSections: SectionBlock[] = [];\n if (!nodeMap) return { refSections, baseSections };\n \n const rightNodesHash: Record<string, SectionBlock> = {};\n const leftNodesHash: Record<string, SectionBlock> = {};\n let rightNodeOrphanIdx = -1;\n let leftNodeOrphanIdx = -1;\n\n for (const nodeIdx in nodeMap) {\n const nodeId = nodeMap[nodeIdx];\n const node = getNode(nodeId);\n if (!node || node.display_node === false) continue;\n\n const { nodeLeftId, nodeRightId } = getNodeInputIds(node);\n const rationale = getRationale(node);\n const rawEvaluationResult = stableDeviationData?.[nodeId]?.evaluation_result || node.evaluation_result || null;\n const normalizedEvaluationResult = normalizeEvaluationResult(rawEvaluationResult, nodeLeftId, nodeRightId);\n const evaluationResult = normalizedEvaluationResult && typeof normalizedEvaluationResult === \"object\"\n ? { ...normalizedEvaluationResult, nodeId }\n : normalizedEvaluationResult;\n\n const { refSections: refSubSections, baseSections: baseSubSections } = buildRelativeOrderMapping(node.next, depth + 1);\n\n const leftItems = resolveComparisonInputItems(node, \"0\", indexMap, contentMapping);\n const leftBlocks = leftItems.map((item) => {\n const block = makeSectionBlock(nodeId, item, evaluationResult, rationale);\n if (block.selfIndex === -1) block.selfIndex = leftNodeOrphanIdx--;\n return block;\n });\n\n let rightBlocks: any[] = [];\n if (!isGuidelineMode) {\n const rightItems = resolveComparisonInputItems(node, \"1\", indexMap, contentMapping);\n rightBlocks = rightItems.map((item) => {\n const block = makeSectionBlock(nodeId, item, evaluationResult, rationale);\n if (block.selfIndex === -1) block.selfIndex = rightNodeOrphanIdx--;\n return block;\n });\n }\n\n leftBlocks.forEach((leftBlock: any) => {\n rightBlocks.forEach((rightBlock: any) => {\n if (Number(rightBlock.selfIndex) >= 0 && Number(leftBlock.selfIndex) >= 0) {\n if (!rightBlock.refIndexes?.includes(Number(leftBlock.selfIndex))) rightBlock.refIndexes?.push(Number(leftBlock.selfIndex));\n if (!leftBlock.refIndexes?.includes(Number(rightBlock.selfIndex))) leftBlock.refIndexes?.push(Number(rightBlock.selfIndex));\n }\n if (leftBlock.contentId && !rightBlock.refContentIds?.includes(leftBlock.contentId)) rightBlock.refContentIds?.push(leftBlock.contentId);\n if (rightBlock.contentId && !leftBlock.refContentIds?.includes(rightBlock.contentId)) leftBlock.refContentIds?.push(rightBlock.contentId);\n });\n });\n\n rightBlocks.forEach((rightBlock: any) => {\n const matchedSubSections = refSubSections.filter((sub: any) =>\n !sub.parentContentId ||\n sub.parentContentId === rightBlock.contentId ||\n sub.parentContentId === rightBlock.parentContentId ||\n rightBlock.refContentIds?.includes(sub.parentContentId),\n );\n if (matchedSubSections.length > 0) rightBlock.subsections = matchedSubSections;\n\n const rightHashKey = depth === 0\n ? String(rightBlock.selfIndex)\n : `${rightBlock.selfIndex}_${rightBlock.contentId || nodeId}`;\n rightNodesHash[rightHashKey] = rightNodesHash[rightHashKey]\n ? mergeBlock(rightNodesHash[rightHashKey], rightBlock)\n : rightBlock;\n });\n\n leftBlocks.forEach((leftBlock: any) => {\n const matchedSubSections = baseSubSections.filter((sub: any) =>\n !sub.parentContentId ||\n sub.parentContentId === leftBlock.contentId ||\n sub.parentContentId === leftBlock.parentContentId ||\n leftBlock.refContentIds?.includes(sub.parentContentId),\n );\n if (matchedSubSections.length > 0) leftBlock.subsections = matchedSubSections;\n\n const leftHashKey = depth === 0\n ? String(leftBlock.selfIndex)\n : `${leftBlock.selfIndex}_${leftBlock.contentId || nodeId}`;\n leftNodesHash[leftHashKey] = leftNodesHash[leftHashKey]\n ? mergeBlock(leftNodesHash[leftHashKey], leftBlock)\n : leftBlock;\n });\n }\n\n refSections = Object.values(rightNodesHash);\n baseSections = Object.values(leftNodesHash);\n\n refSections.sort(sortFn);\n baseSections.sort(sortFn);\n\n return { refSections, baseSections };\n };\n\n const { refSections: righSections, baseSections: leftSections } = buildRelativeOrderMapping(rootNode.next);\n \n if (!isGuidelineMode) {\n refSections = reRouteRHSTree(righSections);\n }\n baseSections = leftSections;\n }\n\n const rootLeftData = getSideData(rootNode, \"0\", indexMap, contentMapping);\n const rootRightData = getSideData(rootNode, \"1\", indexMap, contentMapping);\n\n const activeProposed: ProposedRuleData = {\n title: rootLeftData.title || \"Uploaded Contract\",\n description: rootNode.decision_scope_description || \"\",\n sections: baseSections,\n };\n\n // ── NEW: Extract the title dynamically based on the new learnings_data structure ──\n const getGuidelineTitle = () => {\n if (\n typeof guidelinesData !== \"string\" &&\n guidelinesData?.learnings_data &&\n Object.keys(guidelinesData.learnings_data).length > 0\n ) {\n const firstKey = Object.keys(guidelinesData.learnings_data)[0];\n return guidelinesData.learnings_data[firstKey]?.title || \"Rulebook Guidelines\";\n }\n return (\n (typeof guidelinesData !== \"string\" &&\n guidelinesData?.data?.artifactTitle) ||\n \"Rulebook Guidelines\"\n );\n };\n\n const activeVariant: RuleData = {\n id: \"tree-variant-1\",\n title: isGuidelineMode ? getGuidelineTitle() : (rootRightData.title || \"Reference Template\"),\n similarity: 0,\n sections: refSections,\n analysis: { rule_difference_comparison: { summary: { overall_score: 0, overall_summary: rootNode.decision_scope_description || \"\" }, fields: {} } },\n };\n\n return {\n activeProposed,\n activeVariants: [activeVariant],\n comparisonRows,\n parseError: null,\n };\n } catch (err: unknown) {\n console.error(\"Data Transformation Error: \", err);\n return {\n activeProposed: {} as ProposedRuleData,\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: err instanceof Error ? err.message : \"Unknown Parsing Error\",\n };\n }\n }, [\n treeData,\n maintainRelativeOrder,\n deviationDataStr,\n enableDeviationSchemaBackwardCompatibility,\n guidelinesData,\n isGuidelineMode,\n ]);\n\n // 2. Extracted section references\n const existingRule = activeVariants?.[0] || DEFAULT_RULE_FALLBACK;\n \n const proposedSections = useMemo(\n () => (activeProposed?.sections || []) as SectionBlock[],\n [activeProposed?.sections]\n );\n \n const existingSections = useMemo(\n () => (existingRule.sections || []) as SectionBlock[],\n [existingRule.sections]\n );\n\n const hasSectionAccordions =\n proposedSections.length > 0 || existingSections.length > 0;\n\n const visibleFields = useMemo(() => {\n return resolvedComparisonConfig.fields.filter(({ key }) => {\n if (hasSectionAccordions && key === \"description\") return false;\n return hasValue(activeProposed?.[key as keyof ProposedRuleData]) || hasValue(existingRule[key as keyof RuleData]);\n });\n }, [activeProposed, existingRule, hasSectionAccordions, resolvedComparisonConfig.fields]);\n\n // @ts-ignore\n const { parentDeviationRecord, registry: deviationNumberRegistry, deviationParentRegistry } = useMemo(() => {\n const parentDeviationRecord: Record<string, SectionBlock[]> = {};\n const registry: Record<string, { index: number; rootKey: string; parentNum: number }> = {};\n const counters: Record<string, number> = {};\n // Add a fallback id counter to ensure no deviations are left without ID even when backend does not provide any id.\n let fallbackIdCounter = 0;\n const leftDocId = treeData?.input_index_map?.[\"0\"];\n const rightDocId = treeData?.input_index_map?.[\"1\"];\n\n const resolveRootKeyAndParentNum = (\n rootSec: SectionBlock,\n side: \"left\" | \"right\",\n ): { rootKey: string; parentNum: number } => {\n if (!maintainRelativeOrder) {\n const idx = side === \"left\"\n ? proposedSections.indexOf(rootSec)\n : existingSections.indexOf(rootSec);\n return { rootKey: `${side}:${idx}`, parentNum: idx + 1 };\n }\n\n if (side === \"left\") {\n const selfIdx = (rootSec as any).selfIndex;\n const parentNum = selfIdx !== undefined && selfIdx >= 0 \n ? selfIdx + 1 \n : proposedSections.indexOf(rootSec) + 1;\n return { rootKey: `left-root:${rootSec.id}`, parentNum };\n }\n\n const rhsSelfIndex = (rootSec as any).selfIndex;\n const mappedLhs = proposedSections.find(\n (l: any) => l.refIndexes?.includes(rhsSelfIndex),\n );\n\n if (mappedLhs) {\n const lhsSelfIdx = (mappedLhs as any).selfIndex;\n const parentNum = lhsSelfIdx !== undefined && lhsSelfIdx >= 0 \n ? lhsSelfIdx + 1 \n : proposedSections.indexOf(mappedLhs) + 1;\n return { rootKey: `left-root:${mappedLhs.id}`, parentNum };\n }\n\n // True RHS orphan\n const parentNum = rhsSelfIndex !== undefined && rhsSelfIndex >= 0 \n ? rhsSelfIndex + 1 \n : existingSections.indexOf(rootSec) + 1;\n return { rootKey: `right-orphan-root:${rootSec.id}`, parentNum };\n };\n\n const processDeviations = (evalNode: any, rootKey: string, parentNum: number) => {\n const evaluationResults = evalNode?.evaluationResults?.length\n ? evalNode.evaluationResults\n : (evalNode?.evaluationResult ? [evalNode.evaluationResult] : []);\n\n evaluationResults.forEach((evaluationResult: any) => {\n const deviations = evaluationResult?.deviations || {};\n\n Object.keys(deviations).sort().forEach(devKey => {\n const devMap = deviations[devKey];\n if (!devMap) return;\n\n // changed the code because this logic was too strict and missed\n // cases where highlights were present in normalized/citation-backed data.\n const hasLeftHighlight = !isMissingStr(devMap[leftDocId as string]);\n const hasRightHighlight = !isMissingStr(devMap[rightDocId as string]);\n if (hasLeftHighlight || hasRightHighlight) {\n const registryNodeId = evaluationResult?.nodeId || evalNode.nodeId || evalNode.id;\n const refId = `${registryNodeId}${DEVIATION_BADGE_SEPARATOR}${devKey}`;\n if (registry[refId] === undefined) {\n if (counters[rootKey] === undefined) counters[rootKey] = 1;\n registry[refId] = { index: counters[rootKey]++, rootKey, parentNum };\n }\n }\n });\n });\n };\n\n // Resolve the correct child node at each level using id/refIndexes matching\n // rather than blind array-position (`subsections[i]`), so cross-routed\n // subsections are attributed to their actual structural parent.\n const findMatchingChild = (\n children: SectionBlock[] | undefined,\n target: SectionBlock | undefined,\n ): SectionBlock | undefined => {\n if (!children || !target) return undefined;\n return children.find((c: any) =>\n c.id === target.id ||\n (c.nodeId && c.nodeId === (target as any).nodeId) ||\n (c.contentId && c.contentId === (target as any).contentId)\n ) || undefined;\n };\n\n const traverse = (\n leftNode: SectionBlock | undefined | null,\n evalNode: SectionBlock | undefined | null,\n rightNode: SectionBlock | undefined | null,\n rootKey: string,\n parentNum: number,\n isRoot: boolean,\n parentNode: SectionBlock,\n ) => {\n if (evalNode) {\n processDeviations(evalNode, rootKey, parentNum);\n }\n\n if (evalNode && !isRoot) {\n const safeParentId = parentNode?.id || `fallback_parent_${fallbackIdCounter++}`;\n if (!parentDeviationRecord[safeParentId]) {\n parentDeviationRecord[safeParentId] = [];\n }\n parentDeviationRecord[safeParentId].push(evalNode);\n }\n\n const subs = evalNode?.subsections || leftNode?.subsections || rightNode?.subsections || [];\n subs.forEach((childEvalNode: any) => {\n const matchedLeft = findMatchingChild(leftNode?.subsections, childEvalNode);\n const matchedRight = findMatchingChild(rightNode?.subsections, childEvalNode);\n traverse(\n childEvalNode,\n matchedLeft,\n matchedRight,\n rootKey,\n parentNum,\n false,\n evalNode || parentNode,\n );\n });\n };\n\n proposedSections.forEach((rootSec) => {\n const { rootKey, parentNum } = resolveRootKeyAndParentNum(rootSec, \"left\");\n let rightSec = null;\n if (maintainRelativeOrder) {\n const rhsSelfIndex = (rootSec as any).refIndexes?.[0];\n rightSec = existingSections.find(s => (s as any).selfIndex === rhsSelfIndex);\n } else {\n rightSec = existingSections[proposedSections.indexOf(rootSec)];\n }\n traverse(rootSec, rootSec, rightSec, rootKey, parentNum, true, rootSec);\n });\n\n if (!isGuidelineMode) {\n existingSections.forEach((rootSec) => {\n const { rootKey, parentNum } = resolveRootKeyAndParentNum(rootSec, \"right\");\n const isOrphan = rootKey.startsWith(\"right-orphan-root:\");\n\n if (isOrphan) {\n traverse(rootSec, null, rootSec, rootKey, parentNum, true, rootSec);\n }\n });\n }\n\n const deviationNumberRegistry = Object.fromEntries(\n Object.entries(registry).map(([k, v]) => [k, v.index])\n );\n const deviationParentRegistry = Object.fromEntries(\n Object.entries(registry).map(([k, v]) => [k, v.parentNum])\n );\n\n return { parentDeviationRecord, registry: deviationNumberRegistry, deviationParentRegistry };\n\n }, [proposedSections, existingSections, maintainRelativeOrder, treeData, isGuidelineMode]);\n\n return {\n isGuidelineMode, // ── NEW ──\n activeProposed,\n activeVariants,\n comparisonRows,\n existingRule,\n proposedSections,\n existingSections,\n visibleFields,\n parentDeviationRecord,\n deviationNumberRegistry,\n deviationParentRegistry,\n parseError\n };\n};\n"],"names":["DEFAULT_RULE_FALLBACK","id","title","similarity","sections","useCognitiveTreeData","treeData","maintainRelativeOrder","deviationData","resolvedComparisonConfig","enableDeviationSchemaBackwardCompatibility","guidelinesData","isGuidelineModeFromParent","deviationDataStr","JSON","stringify","isGuidelineMode","Boolean","trim","learnings_data","data","artifactData","userStorySnapshot","activeProposed","activeVariants","comparisonRows","parseError","useMemo","Object","keys","length","stableDeviationData","parse","nodes","baseSections","refSections","rootId","base_root_id","indexMap","input_index_map","rootNode","display_node","contentMapping","content_mapping","getNode","nodeId","normalizeEvaluationResult","rawEvaluationResult","nodeLeftId","nodeRightId","deviations","numericDeviationKeys","filter","k","test","sortedDeviationKeys","sort","a","b","Number","normalizedDeviations","deviationEntries","firstEntry","forEach","devKey","entry","isSameEvaluation","safeStringify","evaluation_outputs","output_value","toLowerCase","shouldShowHighlights","status","deviationHighlight","deviation_highlight","web_search_answer","citationHighlights","docId","citations","cognitive_decisioning","values","map","citation","highlighted_text","text","firstNonEmpty","value","Array","isArray","some","isMissingStr","leftHighlights","deviation_highlights","rightHighlights","deviation_summary","deviation_title","deviation_impact","deviation_explanation","deviation_entries","reRouteRHSTree","allNodesMap","Map","indexNodes","node","set","subsections","moveNodes","parentNode","filteredNodes","targetParentId","ref_parent_section_node_id","has","targetParent","get","s","push","finalSections","sortSubsections","selfIndex","getNodeInputIds","nodeInputKeys","comparison_inputs","includes","getParentContentId","attrs","entity_id","parent_entity_id","makeSectionBlock","item","evaluationResult","rationale","attributes","displayTitle","display_title","displayContent","display_content","content","changeHistory","change_history","display_index","parentContentId","hasData","contentId","score","relation","evaluationResults","refIndexes","refContentIds","mergeBlock","target","incoming","from","Set","existingChildKeys","child","childKey","add","mergedEvaluationResults","seenEvaluationResults","result","key","cognitiveData","sortFn","buildSideSections","sideIndex","getRationale","evaluation_result","normalizedEvaluationResult","resolveComparisonInputItems","next","childSections","flatMap","childId","section","matchedChildren","buildRelativeOrderMapping","nodeMap","depth","rightNodesHash","leftNodesHash","rightNodeOrphanIdx","leftNodeOrphanIdx","nodeIdx","refSubSections","baseSubSections","leftBlocks","block","rightBlocks","rightItems","leftBlock","rightBlock","matchedSubSections","sub","rightHashKey","String","leftHashKey","righSections","leftSections","buildComparisonRows","row","left","right","rootLeftData","getSideData","rootRightData","description","decision_scope_description","firstKey","artifactTitle","getGuidelineTitle","analysis","rule_difference_comparison","summary","overall_score","overall_summary","fields","err","console","error","Error","message","existingRule","proposedSections","existingSections","hasSectionAccordions","visibleFields","hasValue","parentDeviationRecord","registry","deviationNumberRegistry","deviationParentRegistry","counters","fallbackIdCounter","leftDocId","rightDocId","resolveRootKeyAndParentNum","rootSec","side","idx","indexOf","rootKey","parentNum","selfIdx","rhsSelfIndex","mappedLhs","find","l","lhsSelfIdx","findMatchingChild","children","c","traverse","leftNode","evalNode","rightNode","isRoot","devMap","hasLeftHighlight","hasRightHighlight","refId","DEVIATION_BADGE_SEPARATOR","index","processDeviations","safeParentId","childEvalNode","matchedLeft","matchedRight","rightSec","startsWith","fromEntries","entries","v"],"mappings":"uSAKA,MAAMA,EAAkC,CAAEC,GAAI,GAAIC,MAAO,GAAIC,WAAY,EAAGC,SAAU,IAEzEC,EAAuB,CAClCC,EACAC,EACAC,EACAC,EACAC,GAAsD,EACtDC,EACAC,KAOM,MAAAC,EAA4C,iBAAlBL,EAA6BA,EAAgBM,KAAKC,UAAUP,GAAiB,CAAA,GAGvGQ,EAAkBJ,GAA6BK,QACzB,iBAAnBN,EACHA,EAAeO,OACfP,IACCA,EAAeQ,gBACdR,EAAeS,MAAMC,cAAcC,qBAGrCC,eAAEA,EAAgBC,eAAAA,EAAAC,eAAgBA,aAAgBC,GAAeC,EAAQ,KAC7E,IAAKrB,GAA6C,IAAjCsB,OAAOC,KAAKvB,GAAUwB,OAC9B,MAAA,CACLP,eAAgB,CAAC,EACjBC,eAAgB,GAChBC,eAAgB,GAChBC,WAAY,yBAGV,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,MAAMC,EAAcjB,EAAkBI,GAAUnJ,YAAa+J,GACvDE,EAAelB,EAAkBM,GAAWrJ,YAAa+J,GAC/Db,EACEa,EACAC,EACAC,EACA1B,EACAC,GACA,EACAY,GAAYlJ,MAKDmH,EAAA/J,QAAS6K,IACxB,MAAMI,QAAEA,EAASC,UAAAA,GAAcN,EAA2BC,EAAS,QACnE,IAAI+B,EAAW,KACf,GAAIpQ,EAAuB,CACnB,MAAA4O,EAAgBP,EAAgB1F,aAAa,GACnDyH,EAAW5C,EAAiBsB,KAAWnI,GAAAA,EAAUI,YAAc6H,EAAY,MAE3EwB,EAAW5C,EAAiBD,EAAiBiB,QAAQH,IAEvDe,EAASf,EAASA,EAAS+B,EAAU3B,EAASC,GAAW,EAAML,KAG5D5N,GACc+M,EAAAhK,QAAS6K,IACxB,MAAMI,QAAEA,EAASC,UAAAA,GAAcN,EAA2BC,EAAS,SAClDI,EAAQ4B,WAAW,uBAGlCjB,EAASf,EAAS,KAAMA,EAASI,EAASC,GAAW,EAAML,KAKjE,MAAMP,EAA0BzM,OAAOiP,YACrCjP,OAAOkP,QAAQ1C,GAAUnJ,IAAI,EAAE5B,EAAG0N,KAAO,CAAC1N,EAAG0N,EAAEV,SAE3C/B,EAA0B1M,OAAOiP,YACrCjP,OAAOkP,QAAQ1C,GAAUnJ,IAAI,EAAE5B,EAAG0N,KAAO,CAAC1N,EAAG0N,EAAE9B,aAGjD,MAAO,CAAEd,sBAAAA,EAAuBC,SAAUC,EAAyBC,wBAAAA,IAElE,CAACR,EAAkBC,EAAkBxN,EAAuBD,EAAUU,IAElE,MAAA,CACLA,kBACAO,iBACAC,iBACAC,iBACAoM,eACAC,mBACAC,mBACAE,gBACAE,wBACAE,0BACAC,0BACA5M"}
1
+ {"version":3,"file":"useCompareData.js","sources":["../../../../src/features/CognitiveCompare/hooks/useCompareData.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { getSideData, getRationale, hasValue, safeStringify, isMissingStr, DEVIATION_BADGE_SEPARATOR, resolveComparisonInputItems } from \"../CognitiveComparehelpers\";\nimport { ComparisonRow, SectionBlock, ProposedRuleData, RuleData, ComparisonConfig } from \"../CognitiveCompareTypes\";\nimport { buildComparisonRows } from \"../utils/buildComparisonRows\";\n\nconst DEFAULT_RULE_FALLBACK: RuleData = { id: \"\", title: \"\", similarity: 0, sections: [] };\n\nexport const useCognitiveTreeData = (\n treeData: Record<string, any> | undefined,\n maintainRelativeOrder: boolean,\n deviationData: Record<string, any> | null,\n resolvedComparisonConfig: ComparisonConfig,\n enableDeviationSchemaBackwardCompatibility: boolean = true,\n guidelinesData?: Record<string, any> | null\n) => {\n // AdaptTreeData function \n // memoized to increase performance\n // Stabilize the deviationData reference by stringifying it.\n // This prevents React from triggering re-renders purely due to memory reference changes.\n // We keep accepting it as a string so the memo dep stays content-based.\n const deviationDataStr = typeof deviationData === \"string\" ? deviationData : JSON.stringify(deviationData || {});\n\n // ── NEW: Check for either the new learnings_data or the old artifactData ──\n const isGuidelineMode = Boolean(\n guidelinesData && \n (guidelinesData.learnings_data || guidelinesData.data?.artifactData?.userStorySnapshot)\n );\n\n const { activeProposed, activeVariants, comparisonRows, parseError } = useMemo(() => {\n if (!treeData || Object.keys(treeData).length === 0) {\n return {\n activeProposed: {} as ProposedRuleData,\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: \"Tree data is required\",\n };\n }\n const stableDeviationData = JSON.parse(deviationDataStr);\n\n try {\n const nodes = treeData.nodes || treeData;\n let baseSections: any[] = []; \n let refSections: any[] = []; \n let comparisonRows: ComparisonRow[] = [];\n\n const rootId = treeData.base_root_id;\n const indexMap = treeData.input_index_map || { \"0\": \"left\", \"1\": \"right\" };\n const rootNode = treeData[rootId] || nodes[rootId];\n\n if (!rootNode || rootNode.display_node === false) {\n return {\n activeProposed: { title: \"No Data\", sections: [] },\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: null,\n };\n }\n \n const contentMapping = treeData.content_mapping || {};\n const getNode = (nodeId: string) => treeData[nodeId] || nodes[nodeId];\n \n\n const normalizeEvaluationResult = (rawEvaluationResult: any, nodeLeftId: string, nodeRightId: string) => {\n if (!rawEvaluationResult || typeof rawEvaluationResult !== \"object\") {\n return rawEvaluationResult || null;\n }\n\n // Old format already supported by UI.\n if (rawEvaluationResult.deviations) {\n return rawEvaluationResult;\n }\n\n if (enableDeviationSchemaBackwardCompatibility) {\n return rawEvaluationResult;\n }\n\n const numericDeviationKeys = Object.keys(rawEvaluationResult).filter(\n (k) => /^\\d+$/.test(k),\n );\n\n if (!numericDeviationKeys.length) {\n return rawEvaluationResult;\n }\n\n const sortedDeviationKeys = numericDeviationKeys.sort(\n (a, b) => Number(a) - Number(b),\n );\n const normalizedDeviations: Record<string, any> = {};\n const deviationEntries: Record<string, any> = {};\n let firstEntry: any = null;\n\n sortedDeviationKeys.forEach((devKey) => {\n const entry = rawEvaluationResult[devKey];\n if (!entry || typeof entry !== \"object\") return;\n if (!firstEntry) firstEntry = entry;\n\n const shouldShowHighlights =\n !entry?.status || entry.status === \"pending\";\n const deviationHighlight =\n entry?.deviation_highlight ||\n entry?.web_search_answer?.deviation_highlight;\n\n const citationHighlights = (docId: string): string[] => {\n const citations = entry?.cognitive_decisioning?.citations || entry?.citations || {};\n return Object.values(citations)\n .map((citation: any) => citation?.[docId]?.highlighted_text)\n .filter((text: any) => typeof text === \"string\" && text.trim().length > 0);\n };\n\n const firstNonEmpty = (...values: any[]): string[] => {\n for (const value of values) {\n if (Array.isArray(value) && value.some((text) => !isMissingStr(text))) {\n return value;\n }\n }\n return [];\n };\n\n const leftHighlights: string[] = shouldShowHighlights\n ? firstNonEmpty(\n entry?.deviation_highlights?.[nodeLeftId] ||\n entry?.deviation_highlights?.[indexMap[\"0\"] as string],\n typeof deviationHighlight === \"string\"\n ? [deviationHighlight]\n : [],\n citationHighlights(nodeLeftId),\n citationHighlights(indexMap[\"0\"] as string),\n )\n : [];\n\n const rightHighlights: string[] = shouldShowHighlights\n ? firstNonEmpty(\n entry?.deviation_highlights?.[nodeRightId] ||\n entry?.deviation_highlights?.[indexMap[\"1\"] as string],\n citationHighlights(nodeRightId),\n citationHighlights(indexMap[\"1\"] as string),\n )\n : [];\n\n normalizedDeviations[devKey] = {\n [indexMap[\"0\"] as string]: leftHighlights[0] || \"\", \n [indexMap[\"1\"] as string]: rightHighlights[0] || \"\",\n deviation_summary: entry?.deviation_summary || \"\",\n deviation_title: entry?.deviation_title,\n deviation_impact: entry?.deviation_impact,\n deviation_explanation: entry?.deviation_explanation,\n evaluation_outputs: entry?.evaluation_outputs,\n cognitive_decisioning: entry?.cognitive_decisioning,\n deviation_highlights: entry?.deviation_highlights,\n };\n\n deviationEntries[devKey] = entry;\n });\n\n return {\n ...rawEvaluationResult,\n deviation_title: firstEntry?.deviation_title || rawEvaluationResult?.deviation_title,\n deviation_impact: firstEntry?.deviation_impact || rawEvaluationResult?.deviation_impact,\n deviation_summary: firstEntry?.deviation_summary || rawEvaluationResult?.deviation_summary,\n deviation_explanation:\n firstEntry?.deviation_explanation || rawEvaluationResult?.deviation_explanation,\n evaluation_outputs:\n firstEntry?.evaluation_outputs || rawEvaluationResult?.evaluation_outputs,\n cognitive_decisioning:\n firstEntry?.cognitive_decisioning || rawEvaluationResult?.cognitive_decisioning,\n deviations: normalizedDeviations,\n deviation_entries: deviationEntries,\n };\n };\n\n // UNIVERSAL RE-ROUTING ENGINE (WITH SORTING FIX)\n const reRouteRHSTree = (sections: any[]) => {\n const allNodesMap = new Map<string, any>();\n \n const indexNodes = (nodes: any[]) => {\n nodes.forEach(node => {\n if (node.id) allNodesMap.set(node.id, node);\n if (node.subsections?.length) indexNodes(node.subsections);\n });\n };\n indexNodes(sections);\n \n const moveNodes = (nodes: any[], parentNode?: any): any[] => {\n let filteredNodes: any[] = [];\n \n for (const node of nodes) {\n const targetParentId = node.ref_parent_section_node_id;\n \n if (targetParentId && allNodesMap.has(targetParentId) && targetParentId !== parentNode?.id) {\n const targetParent = allNodesMap.get(targetParentId)!;\n if (!targetParent.subsections) targetParent.subsections = [];\n \n if (!targetParent.subsections.some((s: any) => s.id === node.id)) {\n targetParent.subsections.push(node);\n }\n } else {\n if (node.subsections?.length) {\n node.subsections = moveNodes(node.subsections, node);\n }\n filteredNodes.push(node);\n }\n }\n return filteredNodes;\n };\n \n const finalSections = moveNodes(sections);\n\n // Sort step added to ensure display_index is respected after re-routing\n const sortSubsections = (nodes: any[]) => {\n nodes.forEach(node => {\n if (node.subsections && node.subsections.length > 0) {\n node.subsections.sort((a: any, b: any) => {\n if (a.selfIndex < 0 && b.selfIndex >= 0) return 1;\n if (a.selfIndex >= 0 && b.selfIndex < 0) return -1;\n return (a.selfIndex || 0) - (b.selfIndex || 0);\n });\n sortSubsections(node.subsections);\n }\n });\n };\n\n sortSubsections(finalSections);\n return finalSections;\n };\n\n const getNodeInputIds = (node: any) => {\n const nodeInputKeys = node.comparison_inputs ? Object.keys(node.comparison_inputs) : [];\n let nodeLeftId = indexMap[\"0\"];\n let nodeRightId = indexMap[\"1\"];\n\n if (nodeInputKeys.length > 0) {\n nodeLeftId = nodeInputKeys.includes(indexMap[\"0\"]) ? indexMap[\"0\"] : nodeInputKeys[0];\n nodeRightId = nodeInputKeys.includes(indexMap[\"1\"]) ? indexMap[\"1\"] : (nodeInputKeys.length > 1 ? nodeInputKeys[1] : nodeInputKeys[0]);\n }\n\n return { nodeLeftId, nodeRightId };\n };\n\n const getParentContentId = (attrs: any) =>\n attrs?.entity_id ||\n attrs?.ref_parent_section_node_id ||\n attrs?.parent_entity_id ||\n null;\n\n const makeSectionBlock = (\n nodeId: string,\n item: any,\n evaluationResult: any,\n rationale: any,\n ): SectionBlock => {\n const attrs = item.attributes || {};\n const data = item.data || {};\n const displayTitle = attrs.display_title !== false;\n const displayContent = attrs.display_content !== false;\n const title = displayTitle ? safeStringify(data.title || \"\") : \"\";\n const content = displayContent ? safeStringify(data.content || \"\") : \"\";\n const changeHistory = displayContent ? safeStringify(data.change_history || \"\") : \"\";\n const selfIndex =\n attrs.display_index !== undefined && attrs.display_index !== null\n ? Number(attrs.display_index)\n : -1;\n const parentContentId = getParentContentId(attrs);\n const hasData = !!(title.trim() || content.trim());\n\n return {\n id: `${nodeId}::${item.contentId}`,\n nodeId,\n contentId: item.contentId,\n parentContentId,\n title,\n content,\n change_history: changeHistory,\n displayTitle,\n displayContent,\n subsections: [],\n ...(hasData ? rationale : { score: undefined, relation: \"not_defined\" }),\n evaluationResult,\n evaluationResults: evaluationResult ? [evaluationResult] : [],\n selfIndex,\n refIndexes: [],\n refContentIds: [],\n ref_parent_section_node_id: parentContentId,\n } as SectionBlock;\n };\n\n const mergeBlock = (target: any, incoming: any) => {\n target.refIndexes = Array.from(new Set([...(target.refIndexes || []), ...(incoming.refIndexes || [])]));\n target.refContentIds = Array.from(new Set([...(target.refContentIds || []), ...(incoming.refContentIds || [])]));\n\n const existingChildKeys = new Set(\n (target.subsections || []).map((child: any) =>\n child.id || child.contentId || child.nodeId,\n ),\n );\n (incoming.subsections || []).forEach((child: any) => {\n const childKey = child.id || child.contentId || child.nodeId;\n if (!existingChildKeys.has(childKey)) {\n target.subsections = [...(target.subsections || []), child];\n existingChildKeys.add(childKey);\n }\n });\n\n const mergedEvaluationResults = [\n ...(target.evaluationResults || (target.evaluationResult ? [target.evaluationResult] : [])),\n ...(incoming.evaluationResults || (incoming.evaluationResult ? [incoming.evaluationResult] : [])),\n ].filter(Boolean);\n const seenEvaluationResults = new Set<string>();\n target.evaluationResults = mergedEvaluationResults.filter((result: any) => {\n const key = result?.nodeId || JSON.stringify(Object.keys(result?.deviations || result || {}));\n if (seenEvaluationResults.has(key)) return false;\n seenEvaluationResults.add(key);\n return true;\n });\n\n if (!target.evaluationResult && incoming.evaluationResult) target.evaluationResult = incoming.evaluationResult;\n if (!target.cognitiveData && incoming.cognitiveData) target.cognitiveData = incoming.cognitiveData;\n\n return target;\n };\n\n const sortFn = (a: any, b: any) => {\n if (a.selfIndex! < 0 && b.selfIndex! >= 0) return 1;\n if (a.selfIndex! >= 0 && b.selfIndex! < 0) return -1;\n return a.selfIndex! - b.selfIndex!;\n };\n\n const buildSideSections = (nodeId: string, sideIndex: \"0\" | \"1\"): SectionBlock[] => {\n const node = getNode(nodeId);\n if (!node || node.display_node === false) return [];\n \n if (isGuidelineMode && sideIndex === \"1\") return [];\n\n const { nodeLeftId, nodeRightId } = getNodeInputIds(node);\n const rationale = getRationale(node);\n const rawEvaluationResult =\n stableDeviationData?.[nodeId]?.evaluation_result || node.evaluation_result || null;\n const normalizedEvaluationResult = normalizeEvaluationResult(rawEvaluationResult, nodeLeftId, nodeRightId);\n const evaluationResult = normalizedEvaluationResult && typeof normalizedEvaluationResult === \"object\"\n ? { ...normalizedEvaluationResult, nodeId }\n : normalizedEvaluationResult;\n const items = resolveComparisonInputItems(node, sideIndex, indexMap, contentMapping);\n\n const sections = items.map((item) =>\n makeSectionBlock(nodeId, item, evaluationResult, rationale),\n );\n\n if (node.next) {\n const childSections = (Object.values(node.next) as string[]).flatMap((childId) =>\n buildSideSections(childId, sideIndex),\n );\n sections.forEach((section) => {\n const matchedChildren = childSections.filter((child: any) =>\n !child.parentContentId ||\n child.parentContentId === section.contentId ||\n child.parentContentId === section.parentContentId,\n );\n section.subsections = matchedChildren.length ? matchedChildren : childSections;\n });\n }\n\n return sections;\n };\n\n if (!maintainRelativeOrder) {\n if (rootNode.next) {\n (Object.values(rootNode.next) as string[]).forEach((nodeId) => {\n const node = getNode(nodeId);\n if (!node || node.display_node === false) return;\n\n const leftBlocks = buildSideSections(nodeId, \"0\");\n\n if (isGuidelineMode) {\n baseSections.push(...leftBlocks);\n return;\n }\n\n const rightBlocks = reRouteRHSTree(buildSideSections(nodeId, \"1\"));\n comparisonRows.push(\n ...buildComparisonRows(nodeId, leftBlocks, rightBlocks),\n );\n });\n }\n\n if (!isGuidelineMode) {\n baseSections = comparisonRows.map((row) => row.left);\n refSections = comparisonRows.map((row) => row.right);\n }\n\n } else {\n const buildRelativeOrderMapping = (nodeMap?: Record<string, string> | null, depth = 0) => {\n let refSections: SectionBlock[] = [];\n let baseSections: SectionBlock[] = [];\n if (!nodeMap) return { refSections, baseSections };\n \n const rightNodesHash: Record<string, SectionBlock> = {};\n const leftNodesHash: Record<string, SectionBlock> = {};\n let rightNodeOrphanIdx = -1;\n let leftNodeOrphanIdx = -1;\n\n for (const nodeIdx in nodeMap) {\n const nodeId = nodeMap[nodeIdx];\n const node = getNode(nodeId);\n if (!node || node.display_node === false) continue;\n\n const { nodeLeftId, nodeRightId } = getNodeInputIds(node);\n const rationale = getRationale(node);\n const rawEvaluationResult = stableDeviationData?.[nodeId]?.evaluation_result || node.evaluation_result || null;\n const normalizedEvaluationResult = normalizeEvaluationResult(rawEvaluationResult, nodeLeftId, nodeRightId);\n const evaluationResult = normalizedEvaluationResult && typeof normalizedEvaluationResult === \"object\"\n ? { ...normalizedEvaluationResult, nodeId }\n : normalizedEvaluationResult;\n\n const { refSections: refSubSections, baseSections: baseSubSections } = buildRelativeOrderMapping(node.next, depth + 1);\n\n const leftItems = resolveComparisonInputItems(node, \"0\", indexMap, contentMapping);\n const leftBlocks = leftItems.map((item) => {\n const block = makeSectionBlock(nodeId, item, evaluationResult, rationale);\n if (block.selfIndex === -1) block.selfIndex = leftNodeOrphanIdx--;\n return block;\n });\n\n let rightBlocks: any[] = [];\n if (!isGuidelineMode) {\n const rightItems = resolveComparisonInputItems(node, \"1\", indexMap, contentMapping);\n rightBlocks = rightItems.map((item) => {\n const block = makeSectionBlock(nodeId, item, evaluationResult, rationale);\n if (block.selfIndex === -1) block.selfIndex = rightNodeOrphanIdx--;\n return block;\n });\n }\n\n leftBlocks.forEach((leftBlock: any) => {\n rightBlocks.forEach((rightBlock: any) => {\n if (Number(rightBlock.selfIndex) >= 0 && Number(leftBlock.selfIndex) >= 0) {\n if (!rightBlock.refIndexes?.includes(Number(leftBlock.selfIndex))) rightBlock.refIndexes?.push(Number(leftBlock.selfIndex));\n if (!leftBlock.refIndexes?.includes(Number(rightBlock.selfIndex))) leftBlock.refIndexes?.push(Number(rightBlock.selfIndex));\n }\n if (leftBlock.contentId && !rightBlock.refContentIds?.includes(leftBlock.contentId)) rightBlock.refContentIds?.push(leftBlock.contentId);\n if (rightBlock.contentId && !leftBlock.refContentIds?.includes(rightBlock.contentId)) leftBlock.refContentIds?.push(rightBlock.contentId);\n });\n });\n\n rightBlocks.forEach((rightBlock: any) => {\n const matchedSubSections = refSubSections.filter((sub: any) =>\n !sub.parentContentId ||\n sub.parentContentId === rightBlock.contentId ||\n sub.parentContentId === rightBlock.parentContentId ||\n rightBlock.refContentIds?.includes(sub.parentContentId),\n );\n if (matchedSubSections.length > 0) rightBlock.subsections = matchedSubSections;\n\n const rightHashKey = depth === 0\n ? String(rightBlock.selfIndex)\n : `${rightBlock.selfIndex}_${rightBlock.contentId || nodeId}`;\n rightNodesHash[rightHashKey] = rightNodesHash[rightHashKey]\n ? mergeBlock(rightNodesHash[rightHashKey], rightBlock)\n : rightBlock;\n });\n\n leftBlocks.forEach((leftBlock: any) => {\n const matchedSubSections = baseSubSections.filter((sub: any) =>\n !sub.parentContentId ||\n sub.parentContentId === leftBlock.contentId ||\n sub.parentContentId === leftBlock.parentContentId ||\n leftBlock.refContentIds?.includes(sub.parentContentId),\n );\n if (matchedSubSections.length > 0) leftBlock.subsections = matchedSubSections;\n\n const leftHashKey = depth === 0\n ? String(leftBlock.selfIndex)\n : `${leftBlock.selfIndex}_${leftBlock.contentId || nodeId}`;\n leftNodesHash[leftHashKey] = leftNodesHash[leftHashKey]\n ? mergeBlock(leftNodesHash[leftHashKey], leftBlock)\n : leftBlock;\n });\n }\n\n refSections = Object.values(rightNodesHash);\n baseSections = Object.values(leftNodesHash);\n\n refSections.sort(sortFn);\n baseSections.sort(sortFn);\n\n return { refSections, baseSections };\n };\n\n const { refSections: righSections, baseSections: leftSections } = buildRelativeOrderMapping(rootNode.next);\n \n if (!isGuidelineMode) {\n refSections = reRouteRHSTree(righSections);\n }\n baseSections = leftSections;\n }\n\n const rootLeftData = getSideData(rootNode, \"0\", indexMap, contentMapping);\n const rootRightData = getSideData(rootNode, \"1\", indexMap, contentMapping);\n\n const activeProposed: ProposedRuleData = {\n title: rootLeftData.title || \"Uploaded Contract\",\n description: rootNode.decision_scope_description || \"\",\n sections: baseSections,\n };\n\n // ── NEW: Extract the title dynamically based on the new learnings_data structure ──\n const getGuidelineTitle = () => {\n if (guidelinesData?.learnings_data && Object.keys(guidelinesData.learnings_data).length > 0) {\n const firstKey = Object.keys(guidelinesData.learnings_data)[0];\n return guidelinesData.learnings_data[firstKey]?.title || \"Rulebook Guidelines\";\n }\n return guidelinesData?.data?.artifactTitle || \"Rulebook Guidelines\";\n };\n\n const activeVariant: RuleData = {\n id: \"tree-variant-1\",\n title: isGuidelineMode ? getGuidelineTitle() : (rootRightData.title || \"Reference Template\"),\n similarity: 0,\n sections: refSections,\n analysis: { rule_difference_comparison: { summary: { overall_score: 0, overall_summary: rootNode.decision_scope_description || \"\" }, fields: {} } },\n };\n\n return {\n activeProposed,\n activeVariants: [activeVariant],\n comparisonRows,\n parseError: null,\n };\n } catch (err: unknown) {\n console.error(\"Data Transformation Error: \", err);\n return {\n activeProposed: {} as ProposedRuleData,\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: err instanceof Error ? err.message : \"Unknown Parsing Error\",\n };\n }\n }, [treeData, maintainRelativeOrder, deviationDataStr, enableDeviationSchemaBackwardCompatibility, guidelinesData]);\n\n // 2. Extracted section references\n const existingRule = activeVariants?.[0] || DEFAULT_RULE_FALLBACK;\n \n const proposedSections = useMemo(\n () => (activeProposed?.sections || []) as SectionBlock[],\n [activeProposed?.sections]\n );\n \n const existingSections = useMemo(\n () => (existingRule.sections || []) as SectionBlock[],\n [existingRule.sections]\n );\n\n const hasSectionAccordions =\n proposedSections.length > 0 || existingSections.length > 0;\n\n const visibleFields = useMemo(() => {\n return resolvedComparisonConfig.fields.filter(({ key }) => {\n if (hasSectionAccordions && key === \"description\") return false;\n return hasValue(activeProposed?.[key as keyof ProposedRuleData]) || hasValue(existingRule[key as keyof RuleData]);\n });\n }, [activeProposed, existingRule, hasSectionAccordions, resolvedComparisonConfig.fields]);\n\n // @ts-ignore\n const { parentDeviationRecord, registry: deviationNumberRegistry, deviationParentRegistry } = useMemo(() => {\n const parentDeviationRecord: Record<string, SectionBlock[]> = {};\n const registry: Record<string, { index: number; rootKey: string; parentNum: number }> = {};\n const counters: Record<string, number> = {};\n // Add a fallback id counter to ensure no deviations are left without ID even when backend does not provide any id.\n let fallbackIdCounter = 0;\n const leftDocId = treeData?.input_index_map?.[\"0\"];\n const rightDocId = treeData?.input_index_map?.[\"1\"];\n\n const resolveRootKeyAndParentNum = (\n rootSec: SectionBlock,\n side: \"left\" | \"right\",\n ): { rootKey: string; parentNum: number } => {\n if (!maintainRelativeOrder) {\n const idx = side === \"left\"\n ? proposedSections.indexOf(rootSec)\n : existingSections.indexOf(rootSec);\n return { rootKey: `${side}:${idx}`, parentNum: idx + 1 };\n }\n\n if (side === \"left\") {\n const selfIdx = (rootSec as any).selfIndex;\n const parentNum = selfIdx !== undefined && selfIdx >= 0 \n ? selfIdx + 1 \n : proposedSections.indexOf(rootSec) + 1;\n return { rootKey: `left-root:${rootSec.id}`, parentNum };\n }\n\n const rhsSelfIndex = (rootSec as any).selfIndex;\n const mappedLhs = proposedSections.find(\n (l: any) => l.refIndexes?.includes(rhsSelfIndex),\n );\n\n if (mappedLhs) {\n const lhsSelfIdx = (mappedLhs as any).selfIndex;\n const parentNum = lhsSelfIdx !== undefined && lhsSelfIdx >= 0 \n ? lhsSelfIdx + 1 \n : proposedSections.indexOf(mappedLhs) + 1;\n return { rootKey: `left-root:${mappedLhs.id}`, parentNum };\n }\n\n // True RHS orphan\n const parentNum = rhsSelfIndex !== undefined && rhsSelfIndex >= 0 \n ? rhsSelfIndex + 1 \n : existingSections.indexOf(rootSec) + 1;\n return { rootKey: `right-orphan-root:${rootSec.id}`, parentNum };\n };\n\n const processDeviations = (evalNode: any, rootKey: string, parentNum: number) => {\n const evaluationResults = evalNode?.evaluationResults?.length\n ? evalNode.evaluationResults\n : (evalNode?.evaluationResult ? [evalNode.evaluationResult] : []);\n\n evaluationResults.forEach((evaluationResult: any) => {\n const deviations = evaluationResult?.deviations || {};\n\n Object.keys(deviations).sort().forEach(devKey => {\n const devMap = deviations[devKey];\n if (!devMap) return;\n\n // changed the code because this logic was too strict and missed\n // cases where highlights were present in normalized/citation-backed data.\n const hasLeftHighlight = !isMissingStr(devMap[leftDocId as string]);\n const hasRightHighlight = !isMissingStr(devMap[rightDocId as string]);\n if (hasLeftHighlight || hasRightHighlight) {\n const registryNodeId = evaluationResult?.nodeId || evalNode.nodeId || evalNode.id;\n const refId = `${registryNodeId}${DEVIATION_BADGE_SEPARATOR}${devKey}`;\n if (registry[refId] === undefined) {\n if (counters[rootKey] === undefined) counters[rootKey] = 1;\n registry[refId] = { index: counters[rootKey]++, rootKey, parentNum };\n }\n }\n });\n });\n };\n\n // Resolve the correct child node at each level using id/refIndexes matching\n // rather than blind array-position (`subsections[i]`), so cross-routed\n // subsections are attributed to their actual structural parent.\n const findMatchingChild = (\n children: SectionBlock[] | undefined,\n target: SectionBlock | undefined,\n ): SectionBlock | undefined => {\n if (!children || !target) return undefined;\n return children.find((c: any) =>\n c.id === target.id ||\n (c.nodeId && c.nodeId === (target as any).nodeId) ||\n (c.contentId && c.contentId === (target as any).contentId)\n ) || undefined;\n };\n\n const traverse = (\n leftNode: SectionBlock | undefined | null,\n evalNode: SectionBlock | undefined | null,\n rightNode: SectionBlock | undefined | null,\n rootKey: string,\n parentNum: number,\n isRoot: boolean,\n parentNode: SectionBlock,\n ) => {\n if (evalNode) {\n processDeviations(evalNode, rootKey, parentNum);\n }\n\n if (evalNode && !isRoot) {\n const safeParentId = parentNode?.id || `fallback_parent_${fallbackIdCounter++}`;\n if (!parentDeviationRecord[safeParentId]) {\n parentDeviationRecord[safeParentId] = [];\n }\n parentDeviationRecord[safeParentId].push(evalNode);\n }\n\n const subs = evalNode?.subsections || leftNode?.subsections || rightNode?.subsections || [];\n subs.forEach((childEvalNode: any) => {\n const matchedLeft = findMatchingChild(leftNode?.subsections, childEvalNode);\n const matchedRight = findMatchingChild(rightNode?.subsections, childEvalNode);\n traverse(\n childEvalNode,\n matchedLeft,\n matchedRight,\n rootKey,\n parentNum,\n false,\n evalNode || parentNode,\n );\n });\n };\n\n proposedSections.forEach((rootSec) => {\n const { rootKey, parentNum } = resolveRootKeyAndParentNum(rootSec, \"left\");\n let rightSec = null;\n if (maintainRelativeOrder) {\n const rhsSelfIndex = (rootSec as any).refIndexes?.[0];\n rightSec = existingSections.find(s => (s as any).selfIndex === rhsSelfIndex);\n } else {\n rightSec = existingSections[proposedSections.indexOf(rootSec)];\n }\n traverse(rootSec, rootSec, rightSec, rootKey, parentNum, true, rootSec);\n });\n\n if (!isGuidelineMode) {\n existingSections.forEach((rootSec) => {\n const { rootKey, parentNum } = resolveRootKeyAndParentNum(rootSec, \"right\");\n const isOrphan = rootKey.startsWith(\"right-orphan-root:\");\n\n if (isOrphan) {\n traverse(rootSec, null, rootSec, rootKey, parentNum, true, rootSec);\n }\n });\n }\n\n const deviationNumberRegistry = Object.fromEntries(\n Object.entries(registry).map(([k, v]) => [k, v.index])\n );\n const deviationParentRegistry = Object.fromEntries(\n Object.entries(registry).map(([k, v]) => [k, v.parentNum])\n );\n\n return { parentDeviationRecord, registry: deviationNumberRegistry, deviationParentRegistry };\n\n }, [proposedSections, existingSections, maintainRelativeOrder, treeData, isGuidelineMode]);\n\n return {\n isGuidelineMode, // ── NEW ──\n activeProposed,\n activeVariants,\n comparisonRows,\n existingRule,\n proposedSections,\n existingSections,\n visibleFields,\n parentDeviationRecord,\n deviationNumberRegistry,\n deviationParentRegistry,\n parseError\n };\n};\n"],"names":["DEFAULT_RULE_FALLBACK","id","title","similarity","sections","useCognitiveTreeData","treeData","maintainRelativeOrder","deviationData","resolvedComparisonConfig","enableDeviationSchemaBackwardCompatibility","guidelinesData","deviationDataStr","JSON","stringify","isGuidelineMode","Boolean","learnings_data","data","artifactData","userStorySnapshot","activeProposed","activeVariants","comparisonRows","parseError","useMemo","Object","keys","length","stableDeviationData","parse","nodes","baseSections","refSections","rootId","base_root_id","indexMap","input_index_map","rootNode","display_node","contentMapping","content_mapping","getNode","nodeId","normalizeEvaluationResult","rawEvaluationResult","nodeLeftId","nodeRightId","deviations","numericDeviationKeys","filter","k","test","sortedDeviationKeys","sort","a","b","Number","normalizedDeviations","deviationEntries","firstEntry","forEach","devKey","entry","shouldShowHighlights","status","deviationHighlight","deviation_highlight","web_search_answer","citationHighlights","docId","citations","cognitive_decisioning","values","map","citation","highlighted_text","text","trim","firstNonEmpty","value","Array","isArray","some","isMissingStr","leftHighlights","deviation_highlights","rightHighlights","deviation_summary","deviation_title","deviation_impact","deviation_explanation","evaluation_outputs","deviation_entries","reRouteRHSTree","allNodesMap","Map","indexNodes","node","set","subsections","moveNodes","parentNode","filteredNodes","targetParentId","ref_parent_section_node_id","has","targetParent","get","s","push","finalSections","sortSubsections","selfIndex","getNodeInputIds","nodeInputKeys","comparison_inputs","includes","getParentContentId","attrs","entity_id","parent_entity_id","makeSectionBlock","item","evaluationResult","rationale","attributes","displayTitle","display_title","displayContent","display_content","safeStringify","content","changeHistory","change_history","display_index","parentContentId","hasData","contentId","score","relation","evaluationResults","refIndexes","refContentIds","mergeBlock","target","incoming","from","Set","existingChildKeys","child","childKey","add","mergedEvaluationResults","seenEvaluationResults","result","key","cognitiveData","sortFn","buildSideSections","sideIndex","getRationale","evaluation_result","normalizedEvaluationResult","resolveComparisonInputItems","next","childSections","flatMap","childId","section","matchedChildren","buildRelativeOrderMapping","nodeMap","depth","rightNodesHash","leftNodesHash","rightNodeOrphanIdx","leftNodeOrphanIdx","nodeIdx","refSubSections","baseSubSections","leftBlocks","block","rightBlocks","rightItems","leftBlock","rightBlock","matchedSubSections","sub","rightHashKey","String","leftHashKey","righSections","leftSections","buildComparisonRows","row","left","right","rootLeftData","getSideData","rootRightData","description","decision_scope_description","firstKey","artifactTitle","getGuidelineTitle","analysis","rule_difference_comparison","summary","overall_score","overall_summary","fields","err","console","error","Error","message","existingRule","proposedSections","existingSections","hasSectionAccordions","visibleFields","hasValue","parentDeviationRecord","registry","deviationNumberRegistry","deviationParentRegistry","counters","fallbackIdCounter","leftDocId","rightDocId","resolveRootKeyAndParentNum","rootSec","side","idx","indexOf","rootKey","parentNum","selfIdx","rhsSelfIndex","mappedLhs","find","l","lhsSelfIdx","findMatchingChild","children","c","traverse","leftNode","evalNode","rightNode","isRoot","devMap","hasLeftHighlight","hasRightHighlight","refId","DEVIATION_BADGE_SEPARATOR","index","processDeviations","safeParentId","childEvalNode","matchedLeft","matchedRight","rightSec","startsWith","fromEntries","entries","v"],"mappings":"uSAKA,MAAMA,EAAkC,CAAEC,GAAI,GAAIC,MAAO,GAAIC,WAAY,EAAGC,SAAU,IAEzEC,EAAuB,CAClCC,EACAC,EACAC,EACAC,EACAC,GAAsD,EACtDC,KAOM,MAAAC,EAA4C,iBAAlBJ,EAA6BA,EAAgBK,KAAKC,UAAUN,GAAiB,CAAA,GAGvGO,EAAkBC,QACtBL,IACCA,EAAeM,gBAAkBN,EAAeO,MAAMC,cAAcC,qBAGjEC,eAAEA,EAAgBC,eAAAA,EAAAC,eAAgBA,aAAgBC,GAAeC,EAAQ,KAC7E,IAAKnB,GAA6C,IAAjCoB,OAAOC,KAAKrB,GAAUsB,OAC9B,MAAA,CACLP,eAAgB,CAAC,EACjBC,eAAgB,GAChBC,eAAgB,GAChBC,WAAY,yBAGV,MAAAK,EAAsBhB,KAAKiB,MAAMlB,GAEnC,IACI,MAAAmB,EAAQzB,EAASyB,OAASzB,EAChC,IAAI0B,EAAsB,GACtBC,EAAqB,GACrBV,EAAkC,GAEtC,MAAMW,EAAS5B,EAAS6B,aAClBC,EAAW9B,EAAS+B,iBAAmB,CAAE,EAAK,OAAQ,EAAK,SAC3DC,EAAWhC,EAAS4B,IAAWH,EAAMG,GA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I,YAAc8H,EAAY,MAE3EwB,EAAW5C,EAAiBD,EAAiBiB,QAAQH,IAEvDe,EAASf,EAASA,EAAS+B,EAAU3B,EAASC,GAAW,EAAML,KAG5DzN,GACc4M,EAAA9J,QAAS2K,IACxB,MAAMI,QAAEA,EAASC,UAAAA,GAAcN,EAA2BC,EAAS,SAClDI,EAAQ4B,WAAW,uBAGlCjB,EAASf,EAAS,KAAMA,EAASI,EAASC,GAAW,EAAML,KAKjE,MAAMP,EAA0BvM,OAAO+O,YACrC/O,OAAOgP,QAAQ1C,GAAUtJ,IAAI,EAAEvB,EAAGwN,KAAO,CAACxN,EAAGwN,EAAEV,SAE3C/B,EAA0BxM,OAAO+O,YACrC/O,OAAOgP,QAAQ1C,GAAUtJ,IAAI,EAAEvB,EAAGwN,KAAO,CAACxN,EAAGwN,EAAE9B,aAGjD,MAAO,CAAEd,sBAAAA,EAAuBC,SAAUC,EAAyBC,wBAAAA,IAElE,CAACR,EAAkBC,EAAkBpN,EAAuBD,EAAUS,IAElE,MAAA,CACLA,kBACAM,iBACAC,iBACAC,iBACAkM,eACAC,mBACAC,mBACAE,gBACAE,wBACAE,0BACAC,0BACA1M"}
@@ -1,2 +1,2 @@
1
- import{useState as t,useRef as e,useCallback as n,useEffect as r}from"react";import{DEVIATION_BADGE_SEPARATOR as i}from"../CognitiveComparehelpers.js";import{getVisibleGuidelineTargets as c}from"../Guidelines/utils/guidelineTargets.js";const l=({containerRef:l,leftContainerRef:o,rightContainerRef:u,svgContainerRef:s,pathRefs:h,leftHeaderRef:g,rightHeaderRef:d,proposedSections:a,existingSections:f,visibleFields:p,leftRefs:b,rightRefs:$,sectionLeftRefs:y,sectionRightRefs:x,subSectionLeftRefs:m,subSectionRightRefs:R,lhsBadgeRefs:C,rhsBadgeRefs:B,sectionRowRefs:A,expandedSections:S,expandedSubSections:M,connectedSections:v,isSideBySide:T,activeSideBySideSection:I,maintainRelativeOrder:L,isGuidelineMode:F,cognitiveMap:H,getSectionCompareStyle:w,getSubSectionCompareStyle:k,getDeviationStyleByKey:E,isArrowVisible:N,isAnimatingRef:Y,isSideBySideRef:D,sideBySideCacheRef:j,sideBySideLineRef:O,activeSideBySideSectionRef:z,activeSideBySideRightSectionRef:P,connectedLines:Q,setConnectedLines:X,cachedConnectedPositions:G,calculateLinesRef:q,resizeTimerRef:K,scrollLock:V,scrollSyncLocked:J,handleResizeRef:U,activeProposed:W,existingRule:Z,analysisData:_,pendingScrollTargetRef:tt,pendingScrollCallbackRef:et,resolvedComparisonConfig:nt,getFieldData:rt})=>{const[it,ct]=t([]),[lt,ot]=t(null),[ut,st]=t([]),ht=Q??ut,gt=X??st,[dt,at]=t({width:0,height:0}),ft=e(!1),pt=e(!1),bt=e(!1),$t=e(null),yt=e([]),xt=G??yt,mt=(t,e,n,r,i,c,l)=>{if(Math.abs(r-e)<=1)return c&&l?`M ${t},${e} L ${n},${r}`:c&&!l?`M ${t},${e} L ${i},${e}`:!c&&l?`M ${i},${e} L ${n},${r}`:`M ${i},${e} L ${i},${r}`;const o=Math.min(15,Math.abs(i-t),Math.abs(r-e)/2),u=Math.min(15,Math.abs(n-i),Math.abs(r-e)/2),s=r>e?o:-o,h=r>e?u:-u,g=n>i?u:-u;return c&&l?`M ${t},${e} L ${i-o},${e} Q ${i},${e} ${i},${e+s} L ${i},${r-h} Q ${i},${r} ${i+g},${r} L ${n},${r}`:c&&!l?`M ${t},${e} L ${i-o},${e} Q ${i},${e} ${i},${e+s} L ${i},${r}`:!c&&l?`M ${i},${e} L ${i},${r-h} Q ${i},${r} ${i+g},${r} L ${n},${r}`:`M ${i},${e} L ${i},${r}`},Rt=n(()=>{if(!ft.current&&!Y.current){ft.current=!0;try{if(!l.current)return;const t=t=>{const e=t.split("-"),n=e[0];if(!S[n]&&!1===L)return!1;if(L&&!S[`left-${n}`]&&!S[`right-${n}`]&&!S[n])return!1;let r=n;for(let t=1;t<e.length-1;t++)if(r+=`-${e[t]}`,!M[r])return!1;return!0},e=l.current.getBoundingClientRect();at({width:e.width,height:e.height});const n=[];if(p.forEach(({key:t})=>{const e=b.current[t]?.current,n=$.current[t]?.current;e&&n&&(e.style.height="auto",n.style.height="auto",e.style.minHeight="0px",n.style.minHeight="0px")}),!Y.current){for(let t=0;t<Math.max(a.length,f.length);t++){const e=y.current[t]?.current,n=x.current[t]?.current;e&&(e.style.height="auto",e.style.minHeight="0px"),n&&(n.style.height="auto",n.style.minHeight="0px")}L||Object.keys(m.current).forEach(e=>{if(!t(e))return;const n=m.current[e]?.current,r=R.current[e]?.current;n&&r&&(n.style.height="auto",r.style.height="auto",n.style.minHeight="0px",r.style.minHeight="0px")})}const r={};p.forEach(({key:t})=>{const e=b.current[t]?.current,n=$.current[t]?.current;if(e&&n){const i=e.getBoundingClientRect(),c=n.getBoundingClientRect();r[t]=Math.max(i.height,c.height)}});const s={left:{},right:{}},h={};if(!Y.current)if(L){if(T&&null!==I)if("number"==typeof I){const t=I,e=a[t],n=y.current[t]?.current;n&&e&&(e.refIndexes||[]).forEach(e=>{const r=f.findIndex(t=>t.selfIndex===e),i=x.current[r]?.current;if(i&&(S[`left-${t}`]||S[`right-${r}`])){const e=Math.max(n.getBoundingClientRect().height,i.getBoundingClientRect().height);s.left[t]=Math.max(s.left[t]||0,e),s.right[r]=Math.max(s.right[r]||0,e)}})}else{const t=I.split(i)[2];if(t){const e=m.current[t]?.current,n=R.current[t]?.current;if(e&&n){const r=Math.max(e.getBoundingClientRect().height,n.getBoundingClientRect().height);h[t]=Math.max(h[t]||0,r)}}}}else{Object.keys(m.current).forEach(e=>{if(!t(e))return;const n=m.current[e]?.current,r=R.current[e]?.current;if(n&&r&&null!==n.offsetParent&&null!==r.offsetParent){const t=n.getBoundingClientRect(),i=r.getBoundingClientRect(),c=Math.max(t.height,i.height);h[e]=c,n.style.minHeight=`${c}px`,r.style.minHeight=`${c}px`}});for(let t=0;t<Math.min(a.length,f.length);t++){const e=y.current[t]?.current,n=x.current[t]?.current;if(e&&n){const r=Math.max(e.getBoundingClientRect().height,n.getBoundingClientRect().height);s.left[t]=r,s.right[t]=r}}}if(p.forEach(({key:t})=>{const e=b.current[t]?.current,n=$.current[t]?.current;if(e&&n){const i=r[t];e.style.minHeight=`${i}px`,n.style.minHeight=`${i}px`}}),Y.current||(Object.entries(s.left).forEach(([t,e])=>{const n=y.current[Number(t)]?.current;n&&(n.style.minHeight=`${e}px`)}),Object.entries(s.right).forEach(([t,e])=>{const n=x.current[Number(t)]?.current;n&&(n.style.minHeight=`${e}px`)}),L||Object.keys(h).forEach(t=>{const e=m.current[t]?.current,n=R.current[t]?.current;if(e&&n&&h[t]){const r=h[t];e.style.minHeight=`${r}px`,n.style.minHeight=`${r}px`}})),!F){const t=(t,e)=>{if(!L)return f[e]?[e]:[];const n=(t.refIndexes||[]).map(t=>f.findIndex(e=>e.selfIndex===t)).filter(t=>-1!==t);return!n.length&&f[e]?[e]:Array.from(new Set(n))};a.forEach((r,i)=>{const c=r.continuationSourceRowId?a.findIndex(t=>t.comparisonRowId===r.continuationSourceRowId):-1,l=c>=0?c:i,s=y.current[l]?.current;if(!s)return;t(r,i).forEach(t=>{const r=x.current[t]?.current;if(!r)return;const h=s.getBoundingClientRect(),g=r.getBoundingClientRect(),d=h.right-e.left,p=g.left-e.left;let b=h.top+18-e.top,$=g.top+18-e.top;if(L&&T&&I===i){const t=o.current?.getBoundingClientRect().top??0,n=u.current?.getBoundingClientRect().top??0,r=t+(o.current?.clientHeight??1/0),i=n+(u.current?.clientHeight??1/0),c=(t,e,n)=>Math.max(e,Math.min(n,t));b=c(h.top+18,t,r)-e.top,$=c(g.top+18,n,i)-e.top}const y=w(l);y&&n.push({id:`line-${l}-${t}`,x1:d,y1:b,x2:p,y2:$,style:y,sectionIdx:l,targetRightIdx:t,isSubSection:!1,isMappingContinuation:c>=0,hasCognitive:!!(a[l]?.cognitiveData||f[t]?.cognitiveData||a[l]?.nodeId&&H[a[l].nodeId])})})})}if(!F&&T&&"string"==typeof I&&I.includes(i)){const[t,r,c,l]=I.split(i),s=`${t}${i}${r}`,h=C.current[s]?.current,g=B.current[s]?.current;if(h&&g){const i=h.getBoundingClientRect(),l=g.getBoundingClientRect(),d=i.right-e.left,a=l.left-e.left;let f=i.top+i.height/2-e.top,p=l.top+l.height/2-e.top;if(L){const t=o.current?.getBoundingClientRect().top??0,n=u.current?.getBoundingClientRect().top??0,r=t+(o.current?.clientHeight??1/0),c=n+(u.current?.clientHeight??1/0),s=(t,e,n)=>Math.max(e,Math.min(n,t));f=s(i.top+i.height/2,t,r)-e.top,p=s(l.top+l.height/2,n,c)-e.top}const b=E(t,r)??k(c);b&&n.push({id:`line-subsec-${s}`,x1:d,y1:f,x2:a,y2:p,style:b,sectionIdx:Number(c.split("-")[0]),isSubSection:!0,subSectionKeyPath:I})}}if(ct(n),g.current&&d.current){const t=g.current.getBoundingClientRect(),n=d.current.getBoundingClientRect(),r=(t.top+t.height/2-e.top+n.top+n.height/2-e.top)/2;ot({x1:t.right-e.left,x2:n.left-e.left,y:r})}else ot(null);if(v.size>0){const t=[],n=o.current,r=u.current;if(n&&r){const l=[],o=n.getBoundingClientRect().top,u=r.getBoundingClientRect().top,s=o+n.clientHeight,h=u+r.clientHeight,g=n.scrollTop,d=r.scrollTop,p=e.top,b=(t,e,n)=>Math.max(e,Math.min(n,t));v.forEach(n=>{if(F){let a=null,f=null,$=null;if("string"==typeof n&&n.includes(i)){const[t,e,r]=n.split(i),c=`${t}${i}${e}`;a=C.current[c]?.current,$=E(t,e)??k(r),f=Number(r?.split("-")[0]||0)}else f=Number(n),a=C.current[f]?.current,$=w(f);if(!a)return;const y=c(r);y.forEach((r,c)=>{const f=a.getBoundingClientRect(),x=r.getBoundingClientRect(),m=f.right-e.left,R=x.left-e.left-0,C=m+75,B=f.top+f.height/2,A=x.top+x.height/2,S=B-o+g,M=A-u+d,v=`conn-guide-${n}-${c}`;let T="";if("string"==typeof n&&n.includes(i)){T=(n.split(i)[2]||"").split("-").map(t=>Number(t)+1).join(".")}else T=String(Number(n)+1);const I=String.fromCharCode(97+c),L=1===y.length?null:`${T}(${I})`;l.push({lhsScrollY:S,rhsScrollY:M,x1:m,x2:R,containerTop:p,leftIdx:n,rhsArrayIdx:c,styleColor:$?.badgeBorder||"#6366F1",styleBg:$?.badgeBg||"#FFFFFF",styleText:$?.badgeText||"#A16207",styleId:v,centerX:C});const F=b(B,o,s),H=b(A,u,h),w=F-p,k=H-p,E=mt(m,w,R,k,C,B>=o-4&&B<=s+4,A>=u-4&&A<=h+4);t.push({id:v,pathD:E,style:$,leftIdx:n,rhsArrayIdx:c,x1:m,x2:R,y1:w,y2:k,centerX:C,matchLabel:L,isGuideline:!0})})}else if("string"==typeof n&&n.includes(i)){const[r,c,a,f]=n.split(i),$=`${r}${i}${c}`,y=C.current[$]?.current,x=B.current[$]?.current;if(!y||!x)return;const m=y.getBoundingClientRect(),R=x.getBoundingClientRect(),A=E(r,c)??k(a),S=m.right-e.left,M=R.left-e.left-0,v=S+75,T=m.top+m.height/2,I=R.top+R.height/2,L=T-o+g,F=I-u+d,H=`conn-subsec-${$}`,w=((a||"").split("-").map(t=>Number(t)+1).join("."),null);l.push({lhsScrollY:L,rhsScrollY:F,x1:S,x2:M,containerTop:p,leftIdx:n,rhsArrayIdx:n,styleColor:A?.badgeBorder||"#6366F1",styleBg:A?.badgeBg||"#FFFFFF",styleText:A?.badgeText||"#A16207",styleId:H,centerX:v});const N=b(T,o,s),Y=b(I,u,h),D=N-p,j=Y-p,O=mt(S,D,M,j,v,T>=o-4&&T<=s+4,I>=u-4&&I<=h+4);t.push({id:H,pathD:O,style:A,leftIdx:n,rhsArrayIdx:n,x1:S,x2:M,y1:D,y2:j,matchLabel:w})}else if(L){const r=n,i=a[r];if(!i?.refIndexes?.length)return;i.refIndexes.forEach((c,a)=>{const $=f.findIndex(t=>t.selfIndex===c);if(-1===$)return;const y=C.current[r]?.current,x=B.current[$]?.current;if(!y||!x)return;const m=y.getBoundingClientRect(),R=x.getBoundingClientRect(),A=w(r),S=m.right-e.left,M=R.left-e.left-0,v=S+75,T=m.top+m.height/2,I=R.top+R.height/2,L=T-o+g,F=I-u+d,H=`conn-${r}-${$}`,k=String(Number(n)+1),E=String.fromCharCode(97+a),N=1===i.refIndexes.length?null:`${k}(${E})`;l.push({lhsScrollY:L,rhsScrollY:F,x1:S,x2:M,containerTop:p,leftIdx:r,rhsArrayIdx:$,styleColor:A?.badgeBorder||"#6366F1",styleBg:A?.badgeBg||"#FFFFFF",styleText:A?.badgeText||"#A16207",styleId:H,centerX:v});const Y=b(T,o,s),D=b(I,u,h),j=Y-p,O=D-p,z=mt(S,j,M,O,v,T>=o-4&&T<=s+4,I>=u-4&&I<=h+4);t.push({id:H,pathD:z,style:A,leftIdx:r,rhsArrayIdx:$,x1:S,x2:M,y1:j,y2:O,matchLabel:N})})}else{const r=n,i=r,c=C.current[r]?.current,a=B.current[i]?.current;if(!c||!a)return;const f=c.getBoundingClientRect(),$=a.getBoundingClientRect(),y=w(r),x=f.right-e.left,m=$.left-e.left-0,R=x+75,A=f.top+f.height/2,S=$.top+$.height/2,M=A-o+g,v=S-u+d,T=`conn-${r}-${i}`,I=(String(Number(n)+1),null);l.push({lhsScrollY:M,rhsScrollY:v,x1:x,x2:m,containerTop:p,leftIdx:r,rhsArrayIdx:i,styleColor:y?.badgeBorder||"#6366F1",styleBg:y?.badgeBg||"#FFFFFF",styleText:y?.badgeText||"#A16207",styleId:T,centerX:R});const L=b(A,o,s),F=b(S,u,h),H=L-p,k=F-p,E=mt(x,H,m,k,R,A>=o-4&&A<=s+4,S>=u-4&&S<=h+4);t.push({id:T,pathD:E,style:y,leftIdx:r,rhsArrayIdx:i,x1:x,x2:m,y1:H,y2:k,matchLabel:I})}}),xt.current=l}gt(t),setTimeout(()=>Ct(),10)}else gt([]),xt.current=[],setTimeout(()=>Ct(),10)}catch(t){console.error("Line render safe fail: ",t)}finally{ft.current=!1}}},[p,a,f,H,nt,rt,w,E,L,T,I,v,S,M,F]),Ct=n(()=>{const t=xt.current;if(!t.length)return h.current["guideline-up-stroke"]?.setAttribute("visibility","hidden"),h.current["guideline-up-badge"]?.setAttribute("visibility","hidden"),h.current["guideline-down-stroke"]?.setAttribute("visibility","hidden"),void h.current["guideline-down-badge"]?.setAttribute("visibility","hidden");if(Y.current)return;const e=o.current?.scrollTop??0,n=u.current?.scrollTop??0,r=o.current?.clientHeight??1/0,i=u.current?.clientHeight??1/0,c=o.current?.getBoundingClientRect().top??0,s=u.current?.getBoundingClientRect().top??0,g=c+r,d=s+i,a=l.current?.getBoundingClientRect(),f=a?.top??0,p=a?.height??1/0,b=(t,e,n)=>Math.max(e,Math.min(n,t));let $=0,y=0,x=0,m=0,R="#6366F1",C="#A16207",B=!1,A=0;if(t.forEach(t=>{const r=t.lhsScrollY-e+c,i=t.rhsScrollY-n+s,l=h.current[t.styleId+"-stroke"],o=h.current[t.styleId+"-bg"],u=h.current[t.styleId+"-btn"],a=h.current[t.styleId+"-number"];if(!l&&!o)return;const p=b(r,c,g),S=b(i,s,d),M=p-f,v=S-f,T=r>=c-4&&r<=g+4,I=i>=s-4&&i<=d+4;let L=!0;B=!0;const F=t.centerX||t.x1+75;0===x&&(x=t.x1,m=M,A=F,R=t.styleColor,t.styleBg,C=t.styleText||"#A16207"),i<s-4?($++,L=!1):i>d+4&&(y++,L=!1);const H=mt(t.x1,M,t.x2,v,A,T,I);l&&(L&&H?(l.setAttribute("visibility","visible"),l.setAttribute("d",H)):l.setAttribute("visibility","hidden")),o&&(L&&H?(o.setAttribute("visibility","visible"),o.setAttribute("d",H)):o.setAttribute("visibility","hidden")),u&&(T&&L?(u.setAttribute("visibility","visible"),u.setAttribute("y",String(M-12))):u.setAttribute("visibility","hidden")),a&&(T&&L?(a.setAttribute("visibility","visible"),a.setAttribute("transform",`translate(${t.x2-42}, ${v})`)):a.setAttribute("visibility","hidden"))}),B&&A>0){const t=h.current["guideline-up-stroke"],e=h.current["guideline-up-badge"],n=h.current["guideline-up-arrow"],r=h.current["guideline-up-text"],i=h.current["guideline-up-badge-rect"];if($>0){const c=Math.max(15,s-f+15),l=Math.min(15,Math.abs(A-x),Math.max(0,m-c)),o=`M ${x},${m} L ${A-l},${m} Q ${A},${m} ${A},${m-l} L ${A},${c}`;t?.setAttribute("visibility","visible"),t?.setAttribute("d",o),t?.setAttribute("stroke",R),e?.setAttribute("visibility","visible"),e?.setAttribute("transform",`translate(${A}, ${c})`),n&&n.setAttribute("fill",R),r&&(r.textContent=`+${$}`,r.setAttribute("fill",C)),i&&i.setAttribute("stroke",R)}else t?.setAttribute("visibility","hidden"),e?.setAttribute("visibility","hidden");const c=h.current["guideline-down-stroke"],l=h.current["guideline-down-badge"],o=h.current["guideline-down-arrow"],u=h.current["guideline-down-text"],g=h.current["guideline-down-badge-rect"];if(y>0){const t=Math.min(p-15,d-f-15),e=Math.min(15,Math.abs(A-x),Math.max(0,t-m)),n=`M ${x},${m} L ${A-e},${m} Q ${A},${m} ${A},${m+e} L ${A},${t}`;c?.setAttribute("visibility","visible"),c?.setAttribute("d",n),c?.setAttribute("stroke",R),l?.setAttribute("visibility","visible"),l?.setAttribute("transform",`translate(${A}, ${t})`),o&&o.setAttribute("fill",R),u&&(u.textContent=`+${y}`,u.setAttribute("fill",C)),g&&g.setAttribute("stroke",R)}else c?.setAttribute("visibility","hidden"),l?.setAttribute("visibility","hidden")}},[]),Bt=n(()=>{xt.current.length>0&&!Y.current||(null!==$t.current&&clearTimeout($t.current),$t.current=setTimeout(()=>{q.current(),$t.current=null},50))},[]),At=n(t=>{if(null!==tt.current&&et.current&&Math.abs(t.currentTarget.scrollTop-tt.current)<=2){const t=et.current;tt.current=null,et.current=null,t()}if(!bt.current&&!V.current){if(L&&J&&(D.current||v.size>0)){const e=t.currentTarget,n=o.current,r=u.current,c=e===n?r:e===r?n:null;if(e&&c){const t=()=>{const t=z.current,e=P.current;if(null===t)return{leftAnchor:null,rightAnchor:null};if("string"==typeof t&&t.includes(i)){const e=t.split(i),n=`${e[0]}${i}${e[1]}`;return{leftAnchor:C.current[n]?.current||m.current[e[2]]?.current||y.current[Number(e[2])]?.current||null,rightAnchor:B.current[n]?.current||R.current[e[3]]?.current||x.current[Number(e[3])]?.current||null}}const n=Number(t),r=null!==e?Number(e):n;return{leftAnchor:C.current[n]?.current||A.current[n]?.current||y.current[n]?.current||null,rightAnchor:B.current[r]?.current||x.current[r]?.current||null}},{leftAnchor:r,rightAnchor:l}=t(),o=e===n?r:l,u=e===n?l:r;let s=null;if(o&&u){const t=o.getBoundingClientRect(),e=u.getBoundingClientRect(),n=c.getBoundingClientRect(),r=t.top+t.height/2;s=e.top-n.top+c.scrollTop+e.height/2-(r-n.top)}else{const t=Math.max(0,e.scrollHeight-e.clientHeight),n=Math.max(0,c.scrollHeight-c.clientHeight);s=t>0?e.scrollTop/t*n:e.scrollTop}const h=Math.max(0,c.scrollHeight-c.clientHeight);s=Math.max(0,Math.min(s,h)),Math.abs(c.scrollTop-s)>1&&(bt.current=!0,c.scrollTop=s,requestAnimationFrame(()=>{bt.current=!1}))}}L||Bt(),pt.current||(pt.current=!0,requestAnimationFrame(()=>{if(D.current){const t=o.current,e=u.current;if(t&&e&&O.current){if(!j.current){const e=z.current;let n;if("string"==typeof e&&e.includes(i)){const t=e.split(i),r=`${t[0]}${i}${t[1]}`;n=C.current[r]?.current}else n=C.current[e]?.current;if(n){const e=n.getBoundingClientRect();j.current={badgeScreenY:e.top+e.height/2,initialScrollTop:t.scrollTop,leftTop:t.getBoundingClientRect().top,leftBottom:t.getBoundingClientRect().top+t.clientHeight,cTop:l.current?.getBoundingClientRect().top??0}}}if(j.current){const e=j.current,n=t.scrollTop-e.initialScrollTop,r=e.badgeScreenY-n,i=(((t,e,n)=>Math.max(e,Math.min(n,t)))(r,e.leftTop,e.leftBottom)-e.cTop).toString(),c=r>=e.leftTop-4&&r<=e.leftBottom+4;O.current.setAttribute("y1",i),O.current.setAttribute("y2",i),O.current.setAttribute("visibility",c?"visible":"hidden")}}}Ct(),pt.current=!1}))}},[Ct,L,J,v,Bt]);return r(()=>{q.current=Rt},[Rt]),r(()=>{const t=setTimeout(Bt,250),e=()=>U.current();return window.addEventListener("resize",e),()=>{clearTimeout(t),null!==$t.current&&clearTimeout($t.current),null!==K.current&&clearTimeout(K.current),window.removeEventListener("resize",e)}},[W,Z,_,p,S,M,a,f,nt,Bt,T,I,N,v]),{lines:it,setLines:ct,overallConnector:lt,setOverallConnector:ot,connectedLines:ht,setConnectedLines:gt,svgDimensions:dt,cachedConnectedPositions:xt,calculateLines:Rt,calculateLinesRef:q,calculateLinesDebounced:Bt,handleColumnScroll:At}};export{l as useLinesCalculator};
1
+ import{useState as t,useRef as e,useCallback as n,useEffect as r}from"react";import{DEVIATION_BADGE_SEPARATOR as i}from"../CognitiveComparehelpers.js";const c=({containerRef:c,leftContainerRef:l,rightContainerRef:o,svgContainerRef:u,pathRefs:s,leftHeaderRef:h,rightHeaderRef:g,proposedSections:d,existingSections:a,visibleFields:f,leftRefs:p,rightRefs:b,sectionLeftRefs:y,sectionRightRefs:$,subSectionLeftRefs:x,subSectionRightRefs:m,lhsBadgeRefs:R,rhsBadgeRefs:C,sectionRowRefs:A,expandedSections:B,expandedSubSections:S,connectedSections:M,isSideBySide:v,activeSideBySideSection:I,maintainRelativeOrder:T,isGuidelineMode:L,cognitiveMap:F,getSectionCompareStyle:H,getSubSectionCompareStyle:w,getDeviationStyleByKey:k,isArrowVisible:E,isAnimatingRef:N,isSideBySideRef:Y,sideBySideCacheRef:D,sideBySideLineRef:j,activeSideBySideSectionRef:O,activeSideBySideRightSectionRef:z,connectedLines:P,setConnectedLines:Q,cachedConnectedPositions:X,calculateLinesRef:q,resizeTimerRef:G,scrollLock:K,scrollSyncLocked:V,handleResizeRef:J,activeProposed:U,existingRule:W,analysisData:Z,pendingScrollTargetRef:_,pendingScrollCallbackRef:tt,resolvedComparisonConfig:et,getFieldData:nt})=>{const[rt,it]=t([]),[ct,lt]=t(null),[ot,ut]=t([]),st=P??ot,ht=Q??ut,[gt,dt]=t({width:0,height:0}),at=e(!1),ft=e(!1),pt=e(!1),bt=e(null),yt=e([]),$t=X??yt,xt=(t,e,n,r,i,c,l)=>{if(Math.abs(r-e)<=1)return c&&l?`M ${t},${e} L ${n},${r}`:c&&!l?`M ${t},${e} L ${i},${e}`:!c&&l?`M ${i},${e} L ${n},${r}`:`M ${i},${e} L ${i},${r}`;const o=Math.min(15,Math.abs(i-t),Math.abs(r-e)/2),u=Math.min(15,Math.abs(n-i),Math.abs(r-e)/2),s=r>e?o:-o,h=r>e?u:-u,g=n>i?u:-u;return c&&l?`M ${t},${e} L ${i-o},${e} Q ${i},${e} ${i},${e+s} L ${i},${r-h} Q ${i},${r} ${i+g},${r} L ${n},${r}`:c&&!l?`M ${t},${e} L ${i-o},${e} Q ${i},${e} ${i},${e+s} L ${i},${r}`:!c&&l?`M ${i},${e} L ${i},${r-h} Q ${i},${r} ${i+g},${r} L ${n},${r}`:`M ${i},${e} L ${i},${r}`},mt=n(()=>{if(!at.current&&!N.current){at.current=!0;try{if(!c.current)return;const t=t=>{const e=t.split("-"),n=e[0];if(!B[n]&&!1===T)return!1;if(T&&!B[`left-${n}`]&&!B[`right-${n}`]&&!B[n])return!1;let r=n;for(let t=1;t<e.length-1;t++)if(r+=`-${e[t]}`,!S[r])return!1;return!0},e=c.current.getBoundingClientRect();dt({width:e.width,height:e.height});const n=[];if(f.forEach(({key:t})=>{const e=p.current[t]?.current,n=b.current[t]?.current;e&&n&&(e.style.height="auto",n.style.height="auto",e.style.minHeight="0px",n.style.minHeight="0px")}),!N.current){for(let t=0;t<Math.max(d.length,a.length);t++){const e=y.current[t]?.current,n=$.current[t]?.current;e&&(e.style.height="auto",e.style.minHeight="0px"),n&&(n.style.height="auto",n.style.minHeight="0px")}T||Object.keys(x.current).forEach(e=>{if(!t(e))return;const n=x.current[e]?.current,r=m.current[e]?.current;n&&r&&(n.style.height="auto",r.style.height="auto",n.style.minHeight="0px",r.style.minHeight="0px")})}const r={};f.forEach(({key:t})=>{const e=p.current[t]?.current,n=b.current[t]?.current;if(e&&n){const i=e.getBoundingClientRect(),c=n.getBoundingClientRect();r[t]=Math.max(i.height,c.height)}});const u={left:{},right:{}},s={};if(!N.current)if(T){if(v&&null!==I)if("number"==typeof I){const t=I,e=d[t],n=y.current[t]?.current;n&&e&&(e.refIndexes||[]).forEach(e=>{const r=a.findIndex(t=>t.selfIndex===e),i=$.current[r]?.current;if(i&&(B[`left-${t}`]||B[`right-${r}`])){const e=Math.max(n.getBoundingClientRect().height,i.getBoundingClientRect().height);u.left[t]=Math.max(u.left[t]||0,e),u.right[r]=Math.max(u.right[r]||0,e)}})}else{const t=I.split(i)[2];if(t){const e=x.current[t]?.current,n=m.current[t]?.current;if(e&&n){const r=Math.max(e.getBoundingClientRect().height,n.getBoundingClientRect().height);s[t]=Math.max(s[t]||0,r)}}}}else{Object.keys(x.current).forEach(e=>{if(!t(e))return;const n=x.current[e]?.current,r=m.current[e]?.current;if(n&&r&&null!==n.offsetParent&&null!==r.offsetParent){const t=n.getBoundingClientRect(),i=r.getBoundingClientRect(),c=Math.max(t.height,i.height);s[e]=c,n.style.minHeight=`${c}px`,r.style.minHeight=`${c}px`}});for(let t=0;t<Math.min(d.length,a.length);t++){const e=y.current[t]?.current,n=$.current[t]?.current;if(e&&n){const r=Math.max(e.getBoundingClientRect().height,n.getBoundingClientRect().height);u.left[t]=r,u.right[t]=r}}}if(f.forEach(({key:t})=>{const e=p.current[t]?.current,n=b.current[t]?.current;if(e&&n){const i=r[t];e.style.minHeight=`${i}px`,n.style.minHeight=`${i}px`}}),N.current||(Object.entries(u.left).forEach(([t,e])=>{const n=y.current[Number(t)]?.current;n&&(n.style.minHeight=`${e}px`)}),Object.entries(u.right).forEach(([t,e])=>{const n=$.current[Number(t)]?.current;n&&(n.style.minHeight=`${e}px`)}),T||Object.keys(s).forEach(t=>{const e=x.current[t]?.current,n=m.current[t]?.current;if(e&&n&&s[t]){const r=s[t];e.style.minHeight=`${r}px`,n.style.minHeight=`${r}px`}})),!L){const t=(t,e)=>{if(!T)return a[e]?[e]:[];const n=(t.refIndexes||[]).map(t=>a.findIndex(e=>e.selfIndex===t)).filter(t=>-1!==t);return!n.length&&a[e]?[e]:Array.from(new Set(n))};d.forEach((r,i)=>{const c=r.continuationSourceRowId?d.findIndex(t=>t.comparisonRowId===r.continuationSourceRowId):-1,u=c>=0?c:i,s=y.current[u]?.current;if(!s)return;t(r,i).forEach(t=>{const r=$.current[t]?.current;if(!r)return;const h=s.getBoundingClientRect(),g=r.getBoundingClientRect(),f=h.right-e.left,p=g.left-e.left;let b=h.top+18-e.top,y=g.top+18-e.top;if(T&&v&&I===i){const t=l.current?.getBoundingClientRect().top??0,n=o.current?.getBoundingClientRect().top??0,r=t+(l.current?.clientHeight??1/0),i=n+(o.current?.clientHeight??1/0),c=(t,e,n)=>Math.max(e,Math.min(n,t));b=c(h.top+18,t,r)-e.top,y=c(g.top+18,n,i)-e.top}const x=H(u);x&&n.push({id:`line-${u}-${t}`,x1:f,y1:b,x2:p,y2:y,style:x,sectionIdx:u,targetRightIdx:t,isSubSection:!1,isMappingContinuation:c>=0,hasCognitive:!!(d[u]?.cognitiveData||a[t]?.cognitiveData||d[u]?.nodeId&&F[d[u].nodeId])})})})}if(!L&&v&&"string"==typeof I&&I.includes(i)){const[t,r,c,u]=I.split(i),s=`${t}${i}${r}`,h=R.current[s]?.current,g=C.current[s]?.current;if(h&&g){const i=h.getBoundingClientRect(),u=g.getBoundingClientRect(),d=i.right-e.left,a=u.left-e.left;let f=i.top+i.height/2-e.top,p=u.top+u.height/2-e.top;if(T){const t=l.current?.getBoundingClientRect().top??0,n=o.current?.getBoundingClientRect().top??0,r=t+(l.current?.clientHeight??1/0),c=n+(o.current?.clientHeight??1/0),s=(t,e,n)=>Math.max(e,Math.min(n,t));f=s(i.top+i.height/2,t,r)-e.top,p=s(u.top+u.height/2,n,c)-e.top}const b=k(t,r)??w(c);b&&n.push({id:`line-subsec-${s}`,x1:d,y1:f,x2:a,y2:p,style:b,sectionIdx:Number(c.split("-")[0]),isSubSection:!0,subSectionKeyPath:I})}}if(it(n),h.current&&g.current){const t=h.current.getBoundingClientRect(),n=g.current.getBoundingClientRect(),r=(t.top+t.height/2-e.top+n.top+n.height/2-e.top)/2;lt({x1:t.right-e.left,x2:n.left-e.left,y:r})}else lt(null);if(M.size>0){const t=[],n=l.current,r=o.current;if(n&&r){const c=[],l=n.getBoundingClientRect().top,o=r.getBoundingClientRect().top,u=l+n.clientHeight,s=o+r.clientHeight,h=n.scrollTop,g=r.scrollTop,f=e.top,p=(t,e,n)=>Math.max(e,Math.min(n,t));M.forEach(n=>{if(L){let r=null,d=null,a=null;if("string"==typeof n&&n.includes(i)){const[t,e,c]=n.split(i),l=`${t}${i}${e}`;r=R.current[l]?.current,a=k(t,e)??w(c),d=Number(c?.split("-")[0]||0)}else d=Number(n),r=R.current[d]?.current,a=H(d);if(!r)return;const b=document.querySelectorAll('[id^="guideline-target-"]');b.forEach((d,y)=>{const $=r.getBoundingClientRect(),x=d.getBoundingClientRect(),m=$.right-e.left,R=x.left-e.left-0,C=m+75,A=$.top+$.height/2,B=x.top+x.height/2,S=A-l+h,M=B-o+g,v=`conn-guide-${n}-${y}`;let I="";if("string"==typeof n&&n.includes(i)){I=(n.split(i)[2]||"").split("-").map(t=>Number(t)+1).join(".")}else I=String(Number(n)+1);const T=String.fromCharCode(97+y),L=1===b.length?null:`${I}(${T})`;c.push({lhsScrollY:S,rhsScrollY:M,x1:m,x2:R,containerTop:f,leftIdx:n,rhsArrayIdx:y,styleColor:a?.badgeBorder||"#6366F1",styleBg:a?.badgeBg||"#FFFFFF",styleText:a?.badgeText||"#A16207",styleId:v,centerX:C});const F=p(A,l,u),H=p(B,o,s),w=F-f,k=H-f,E=xt(m,w,R,k,C,A>=l-4&&A<=u+4,B>=o-4&&B<=s+4);t.push({id:v,pathD:E,style:a,leftIdx:n,rhsArrayIdx:y,x1:m,x2:R,y1:w,y2:k,centerX:C,matchLabel:L,isGuideline:!0})})}else if("string"==typeof n&&n.includes(i)){const[r,d,a,b]=n.split(i),y=`${r}${i}${d}`,$=R.current[y]?.current,x=C.current[y]?.current;if(!$||!x)return;const m=$.getBoundingClientRect(),A=x.getBoundingClientRect(),B=k(r,d)??w(a),S=m.right-e.left,M=A.left-e.left-0,v=S+75,I=m.top+m.height/2,T=A.top+A.height/2,L=I-l+h,F=T-o+g,H=`conn-subsec-${y}`,E=((a||"").split("-").map(t=>Number(t)+1).join("."),null);c.push({lhsScrollY:L,rhsScrollY:F,x1:S,x2:M,containerTop:f,leftIdx:n,rhsArrayIdx:n,styleColor:B?.badgeBorder||"#6366F1",styleBg:B?.badgeBg||"#FFFFFF",styleText:B?.badgeText||"#A16207",styleId:H,centerX:v});const N=p(I,l,u),Y=p(T,o,s),D=N-f,j=Y-f,O=xt(S,D,M,j,v,I>=l-4&&I<=u+4,T>=o-4&&T<=s+4);t.push({id:H,pathD:O,style:B,leftIdx:n,rhsArrayIdx:n,x1:S,x2:M,y1:D,y2:j,matchLabel:E})}else if(T){const r=n,i=d[r];if(!i?.refIndexes?.length)return;i.refIndexes.forEach((d,b)=>{const y=a.findIndex(t=>t.selfIndex===d);if(-1===y)return;const $=R.current[r]?.current,x=C.current[y]?.current;if(!$||!x)return;const m=$.getBoundingClientRect(),A=x.getBoundingClientRect(),B=H(r),S=m.right-e.left,M=A.left-e.left-0,v=S+75,I=m.top+m.height/2,T=A.top+A.height/2,L=I-l+h,F=T-o+g,w=`conn-${r}-${y}`,k=String(Number(n)+1),E=String.fromCharCode(97+b),N=1===i.refIndexes.length?null:`${k}(${E})`;c.push({lhsScrollY:L,rhsScrollY:F,x1:S,x2:M,containerTop:f,leftIdx:r,rhsArrayIdx:y,styleColor:B?.badgeBorder||"#6366F1",styleBg:B?.badgeBg||"#FFFFFF",styleText:B?.badgeText||"#A16207",styleId:w,centerX:v});const Y=p(I,l,u),D=p(T,o,s),j=Y-f,O=D-f,z=xt(S,j,M,O,v,I>=l-4&&I<=u+4,T>=o-4&&T<=s+4);t.push({id:w,pathD:z,style:B,leftIdx:r,rhsArrayIdx:y,x1:S,x2:M,y1:j,y2:O,matchLabel:N})})}else{const r=n,i=r,d=R.current[r]?.current,a=C.current[i]?.current;if(!d||!a)return;const b=d.getBoundingClientRect(),y=a.getBoundingClientRect(),$=H(r),x=b.right-e.left,m=y.left-e.left-0,A=x+75,B=b.top+b.height/2,S=y.top+y.height/2,M=B-l+h,v=S-o+g,I=`conn-${r}-${i}`,T=(String(Number(n)+1),null);c.push({lhsScrollY:M,rhsScrollY:v,x1:x,x2:m,containerTop:f,leftIdx:r,rhsArrayIdx:i,styleColor:$?.badgeBorder||"#6366F1",styleBg:$?.badgeBg||"#FFFFFF",styleText:$?.badgeText||"#A16207",styleId:I,centerX:A});const L=p(B,l,u),F=p(S,o,s),w=L-f,k=F-f,E=xt(x,w,m,k,A,B>=l-4&&B<=u+4,S>=o-4&&S<=s+4);t.push({id:I,pathD:E,style:$,leftIdx:r,rhsArrayIdx:i,x1:x,x2:m,y1:w,y2:k,matchLabel:T})}}),$t.current=c}ht(t),setTimeout(()=>Rt(),10)}else ht([]),$t.current=[],setTimeout(()=>Rt(),10)}catch(t){console.error("Line render safe fail: ",t)}finally{at.current=!1}}},[f,d,a,F,et,nt,H,k,T,v,I,M,B,S,L]),Rt=n(()=>{const t=$t.current;if(!t.length)return s.current["guideline-up-stroke"]?.setAttribute("visibility","hidden"),s.current["guideline-up-badge"]?.setAttribute("visibility","hidden"),s.current["guideline-down-stroke"]?.setAttribute("visibility","hidden"),void s.current["guideline-down-badge"]?.setAttribute("visibility","hidden");if(N.current)return;const e=l.current?.scrollTop??0,n=o.current?.scrollTop??0,r=l.current?.clientHeight??1/0,i=o.current?.clientHeight??1/0,u=l.current?.getBoundingClientRect().top??0,h=o.current?.getBoundingClientRect().top??0,g=u+r,d=h+i,a=c.current?.getBoundingClientRect(),f=a?.top??0,p=a?.height??1/0,b=(t,e,n)=>Math.max(e,Math.min(n,t));let y=0,$=0,x=0,m=0,R="#6366F1",C="#A16207",A=!1,B=0;if(t.forEach(t=>{const r=t.lhsScrollY-e+u,i=t.rhsScrollY-n+h,c=s.current[t.styleId+"-stroke"],l=s.current[t.styleId+"-bg"],o=s.current[t.styleId+"-btn"],a=s.current[t.styleId+"-number"];if(!c&&!l)return;const p=b(r,u,g),S=b(i,h,d),M=p-f,v=S-f,I=r>=u-4&&r<=g+4,T=i>=h-4&&i<=d+4;let L=!0;A=!0;const F=t.centerX||t.x1+75;0===x&&(x=t.x1,m=M,B=F,R=t.styleColor,t.styleBg,C=t.styleText||"#A16207"),i<h-4?(y++,L=!1):i>d+4&&($++,L=!1);const H=xt(t.x1,M,t.x2,v,B,I,T);c&&(L&&H?(c.setAttribute("visibility","visible"),c.setAttribute("d",H)):c.setAttribute("visibility","hidden")),l&&(L&&H?(l.setAttribute("visibility","visible"),l.setAttribute("d",H)):l.setAttribute("visibility","hidden")),o&&(I&&L?(o.setAttribute("visibility","visible"),o.setAttribute("y",String(M-12))):o.setAttribute("visibility","hidden")),a&&(I&&L?(a.setAttribute("visibility","visible"),a.setAttribute("transform",`translate(${t.x2-42}, ${v})`)):a.setAttribute("visibility","hidden"))}),A&&B>0){const t=s.current["guideline-up-stroke"],e=s.current["guideline-up-badge"],n=s.current["guideline-up-arrow"],r=s.current["guideline-up-text"],i=s.current["guideline-up-badge-rect"];if(y>0){const c=Math.max(15,h-f+15),l=Math.min(15,Math.abs(B-x),Math.max(0,m-c)),o=`M ${x},${m} L ${B-l},${m} Q ${B},${m} ${B},${m-l} L ${B},${c}`;t?.setAttribute("visibility","visible"),t?.setAttribute("d",o),t?.setAttribute("stroke",R),e?.setAttribute("visibility","visible"),e?.setAttribute("transform",`translate(${B}, ${c})`),n&&n.setAttribute("fill",R),r&&(r.textContent=`+${y}`,r.setAttribute("fill",C)),i&&i.setAttribute("stroke",R)}else t?.setAttribute("visibility","hidden"),e?.setAttribute("visibility","hidden");const c=s.current["guideline-down-stroke"],l=s.current["guideline-down-badge"],o=s.current["guideline-down-arrow"],u=s.current["guideline-down-text"],g=s.current["guideline-down-badge-rect"];if($>0){const t=Math.min(p-15,d-f-15),e=Math.min(15,Math.abs(B-x),Math.max(0,t-m)),n=`M ${x},${m} L ${B-e},${m} Q ${B},${m} ${B},${m+e} L ${B},${t}`;c?.setAttribute("visibility","visible"),c?.setAttribute("d",n),c?.setAttribute("stroke",R),l?.setAttribute("visibility","visible"),l?.setAttribute("transform",`translate(${B}, ${t})`),o&&o.setAttribute("fill",R),u&&(u.textContent=`+${$}`,u.setAttribute("fill",C)),g&&g.setAttribute("stroke",R)}else c?.setAttribute("visibility","hidden"),l?.setAttribute("visibility","hidden")}},[]),Ct=n(()=>{$t.current.length>0&&!N.current||(null!==bt.current&&clearTimeout(bt.current),bt.current=setTimeout(()=>{q.current(),bt.current=null},50))},[]),At=n(t=>{if(null!==_.current&&tt.current&&Math.abs(t.currentTarget.scrollTop-_.current)<=2){const t=tt.current;_.current=null,tt.current=null,t()}if(!pt.current&&!K.current){if(T&&V&&(Y.current||M.size>0)){const e=t.currentTarget,n=l.current,r=o.current,c=e===n?r:e===r?n:null;if(e&&c){const t=()=>{const t=O.current,e=z.current;if(null===t)return{leftAnchor:null,rightAnchor:null};if("string"==typeof t&&t.includes(i)){const e=t.split(i),n=`${e[0]}${i}${e[1]}`;return{leftAnchor:R.current[n]?.current||x.current[e[2]]?.current||y.current[Number(e[2])]?.current||null,rightAnchor:C.current[n]?.current||m.current[e[3]]?.current||$.current[Number(e[3])]?.current||null}}const n=Number(t),r=null!==e?Number(e):n;return{leftAnchor:R.current[n]?.current||A.current[n]?.current||y.current[n]?.current||null,rightAnchor:C.current[r]?.current||$.current[r]?.current||null}},{leftAnchor:r,rightAnchor:l}=t(),o=e===n?r:l,u=e===n?l:r;let s=null;if(o&&u){const t=o.getBoundingClientRect(),e=u.getBoundingClientRect(),n=c.getBoundingClientRect(),r=t.top+t.height/2;s=e.top-n.top+c.scrollTop+e.height/2-(r-n.top)}else{const t=Math.max(0,e.scrollHeight-e.clientHeight),n=Math.max(0,c.scrollHeight-c.clientHeight);s=t>0?e.scrollTop/t*n:e.scrollTop}const h=Math.max(0,c.scrollHeight-c.clientHeight);s=Math.max(0,Math.min(s,h)),Math.abs(c.scrollTop-s)>1&&(pt.current=!0,c.scrollTop=s,requestAnimationFrame(()=>{pt.current=!1}))}}T||Ct(),ft.current||(ft.current=!0,requestAnimationFrame(()=>{if(Y.current){const t=l.current,e=o.current;if(t&&e&&j.current){if(!D.current){const e=O.current;let n;if("string"==typeof e&&e.includes(i)){const t=e.split(i),r=`${t[0]}${i}${t[1]}`;n=R.current[r]?.current}else n=R.current[e]?.current;if(n){const e=n.getBoundingClientRect();D.current={badgeScreenY:e.top+e.height/2,initialScrollTop:t.scrollTop,leftTop:t.getBoundingClientRect().top,leftBottom:t.getBoundingClientRect().top+t.clientHeight,cTop:c.current?.getBoundingClientRect().top??0}}}if(D.current){const e=D.current,n=t.scrollTop-e.initialScrollTop,r=e.badgeScreenY-n,i=(((t,e,n)=>Math.max(e,Math.min(n,t)))(r,e.leftTop,e.leftBottom)-e.cTop).toString(),c=r>=e.leftTop-4&&r<=e.leftBottom+4;j.current.setAttribute("y1",i),j.current.setAttribute("y2",i),j.current.setAttribute("visibility",c?"visible":"hidden")}}}Rt(),ft.current=!1}))}},[Rt,T,V,M,Ct]);return r(()=>{q.current=mt},[mt]),r(()=>{const t=setTimeout(Ct,250),e=()=>J.current();return window.addEventListener("resize",e),()=>{clearTimeout(t),null!==bt.current&&clearTimeout(bt.current),null!==G.current&&clearTimeout(G.current),window.removeEventListener("resize",e)}},[U,W,Z,f,B,S,d,a,et,Ct,v,I,E,M]),{lines:rt,setLines:it,overallConnector:ct,setOverallConnector:lt,connectedLines:st,setConnectedLines:ht,svgDimensions:gt,cachedConnectedPositions:$t,calculateLines:mt,calculateLinesRef:q,calculateLinesDebounced:Ct,handleColumnScroll:At}};export{c as useLinesCalculator};
2
2
  //# sourceMappingURL=useLinesCalculator.js.map