{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "docx-editor-compare-documents",
  "framework": "javascript",
  "type": "registry:component",
  "component": "DocxEditor",
  "variant": "compare-documents",
  "dependencies": [
    "@syncfusion/ej2-documenteditor",
    "@syncfusion/ej2-buttons"
  ],
  "description": "Word editor compares uploaded original and revised documents and displays the revision results.",
  "meta": {
    "essentialStudioRelease": "2026 Volume 3 (v35.1.37)",
    "license": "commercial-or-community",
    "licenseNote": "The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md",
    "requiresLicenseKey": true,
    "requiresServerEndpoint": true,
    "platformIndex": "https://ai.syncfusion.com/javascript/llms.txt",
    "skillPack": "syncfusion/javascript-ui-components-skills",
    "docs": "https://ai.syncfusion.com/gallery/javascript/docx-editor-compare-documents.md"
  },
  "files": [
    {
      "target": "src/components/docx-editor-compare-documents/docx-editor.html",
      "content": "<div class=\"control-section\">\n    <!-- Controls container -->\n    <div class=\"controls-container\" style=\"width: 760px; margin: 10px auto\">\n      <!-- Files row -->\n      <div class=\"files-row\" style=\"display: flex; gap: 6px\">\n        <!-- Origial-->\n        <div style=\"width: 360px; border-radius: 6px; padding: 14px; border: 1px dashed #ccc\">\n          <div style=\"display: flex; align-items: center; gap: 10px;\">\n            <span>Original document</span>\n            <label style=\" padding: 4px 10px;\n              border: 1px solid #ccc;\n              border-radius: 4px;\n              cursor: pointer;\">\n            Choose file\n            <input type=\"file\" style=\"display: none;\" id=\"originalFileInput\" accept=\".docx,.sfdt\" />\n            </label>\n          </div>\n          <!-- Filename + Delete icon -->\n          <div style=\"display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; color: #666;\">\n            <span id=\"originalFileName\">Supported formats: SFDT, DOCX</span>\n            <span id=\"removeOriginalFile\" class=\"e-icons e-trash\" style=\"cursor: pointer;\" title=\"Remove file\"></span>\n          </div>\n        </div>\n        <!-- Revised file section-->\n        <div style=\"width: 360px; border-radius: 6px; padding: 14px; border: 1px dashed #ccc;\">\n          <!-- Top row -->\n          <div style=\"display: flex; align-items: center; gap: 10px;\">\n            <span>Revised document</span>\n            <label style=\"\n              padding: 4px 10px;\n              border: 1px solid #ccc;\n              border-radius: 4px;\n              cursor: pointer;\">\n              Choose file\n              <input type=\"file\" style=\"display: none;\" id=\"revisedFileInput\" accept=\".docx,.sfdt\" />\n            </label>\n          </div>\n          <!-- Filename + Delete icon -->\n          <div style=\"display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; color: #666;\">\n            <span id=\"revisedFileName\">Supported formats: SFDT, DOCX</span>\n            <span id=\"removeRevisedFile\" class=\"e-icons e-trash\" style=\"cursor: pointer;\" title=\"Remove file\"></span>\n          </div>\n        </div>\n      </div>\n      <!-- Checkbox, Compare & Download buttons  -->\n      <div style=\"display: flex; justify-content: space-between; align-items: center; margin-top: 12px;\">  \n        <!-- Checkbox -->\n        <div class=\"actions-row\">\n          <label>\n              <input type=\"checkbox\" id=\"showResultCheckbox\" checked=\"true\" />\n              Show comparison results with tracked changes\n          </label>\n        </div>\n        <div style=\"display: flex; gap: 10px; margin-right: 32px;\">\n          <button class=\"e-primary\" id=\"compareButton\">Compare</button>\n          <button class=\"e-outline e-flat e-primary\" id=\"downloadButton\">Download Result Document</button>\n        </div>\n      </div>\n    </div>\n\n    <!-- Editors Area -->\n    <div style=\"display: flex; gap: 6px; height: calc(100vh - 330px); padding: 0px 10px;\">\n      <!-- Left Container -->\n      <div style=\"width: 50%; display: flex; flex-direction: column; border: 1px solid #ddd; overflow: hidden;\">\n        <div style=\"padding: 8px; font-weight: 600;\" class=\"e-de-ctn-title\">Original Document</div>\n        <div style=\"flex: 1; height: 100%;\">\n          <div id=\"editorContainer1\"></div>\n        </div>\n      </div>\n      <!-- Right Editor -->\n      <div style=\"width: 50%; display: flex; flex-direction: column; border: 1px solid #ddd; overflow: hidden;\">\n        <div class=\"e-de-ctn-title\" style=\"display: flex; justify-content: space-between; align-items: center\">\n          <div style=\"float: left; padding: 8px; font-weight: 600; flex: 1px;\" id=\"rightEditorTitle\" >\n            Result Document (with tracked changes)\n          </div>\n          <button id=\"showRevisionsButton\"\n              class=\"e-de-ctn-title\"\n              iconCss=\"e-icons e-eye\"\n              style=\"float: right; font-weight: 400; background: transparent; box-shadow: none; border-color: transparent; border-radius: 0px;\n                    color: inherit; font-size: 12px;\"\n              title=\"Show/Hide Revisions Pane\">\n              Show Review Pane\n          </button>\n        </div>\n        <div style=\"flex: 1; height: 100%;\">\n          <div id=\"editorContainer2\"></div>  \n        </div>\n      </div>\n    </div>\n\n    <!-- Waiting Popup Overlay -->\n    <div class=\"overlay\" id=\"popup-overlay\"></div>\n    <div id='waiting-popup' style=\"display: none;\">\n      <svg class=\"circular\" height=\"40\" width=\"40\">\n        <circle class=\"circle-path\" cx=\"25\" cy=\"25\" r=\"20\" fill=\"none\" stroke-width=\"6\" stroke-miterlimit=\"10\" />\n      </svg>\n    </div>\n  </div>\n  <style>\n\n    .overlay {\n      position: fixed;\n      top: 0;\n      left: 0;\n      width: 100vw;\n      height: 100vh;\n      background-color: rgba(56, 56, 56, 0.5);\n      z-index: 9999;\n      display: none;\n      cursor: not-allowed;\n    }\n\n    #waiting-popup {\n      width: 56px;\n      height: 56px;\n      position: fixed;\n      top: 50%;\n      left: 50%;\n      transform: translate(-50%, -50%);\n      border-radius: 50%;\n      padding: 3px;\n      background: white;\n      box-shadow: 0px 3px 6px rgba(0,0,0,.3);\n      z-index: 10000;\n      display: none;\n    }\n\n\n    .circular {\n        animation: rotate 2s linear infinite;\n        height: 50px;\n        width: 50px;\n        border-radius: 50%;\n    }\n\n    .circle-path {\n        stroke-dasharray: 1, 200;\n        stroke-dashoffset: 0;\n        animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;\n        stroke-linecap: round;\n        stroke: #ff4081;\n    }\n\n    @keyframes rotate {\n        100% {\n            transform: rotate(360deg);\n        }\n    }\n\n    @keyframes dash {\n        0% {\n            stroke-dasharray: 1, 200;\n            stroke-dashoffset: 0;\n        }\n\n        50% {\n            stroke-dasharray: 89, 200;\n            stroke-dashoffset: -35;\n        }\n\n        100% {\n            stroke-dasharray: 89, 200;\n            stroke-dashoffset: -124;\n        }\n    }\n  </style>"
    },
    {
      "target": "src/components/docx-editor-compare-documents/docx-editor.ts",
      "content": "import { DocumentEditorContainer, Toolbar, DocumentEditor } from '@syncfusion/ej2-documenteditor';\nimport { Button } from '@syncfusion/ej2-buttons';\nimport * as data from '../datasource/docx-editor-data';\n/**\n * Document Comparison sample\n */\nexport function initDocxEditorCompareDocuments(): void {\n    let serviceUrl: string = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';\n    // Load necessary modules\n    DocumentEditorContainer.Inject(Toolbar);\n    \n    // Document editor container references\n    let editorContainer1: DocumentEditorContainer;\n    let editorContainer2: DocumentEditorContainer;\n\n    // Track files and state\n    let originalFile: File | null = null;\n    let revisedFile: File | null = null;\n    let showResult: boolean = true;\n    let compareClicked: boolean = false;\n    let showRevisions: boolean = false;\n\n    // Initialize the UI components after the DOM is fully loaded\n    createDocumentEditors();\n    attachEventListeners();\n\n    function createDocumentEditors(): void {\n        // Create the first document editor\n        editorContainer1 = new DocumentEditorContainer({\n            serviceUrl: serviceUrl,\n            enableToolbar: false,\n            showPropertiesPane: false,\n            height: '100%',\n            width: '100%'\n        });\n        editorContainer1.appendTo('#editorContainer1');\n\n        // Create the second document editor\n        editorContainer2 = new DocumentEditorContainer({\n            serviceUrl: serviceUrl,\n            enableToolbar: false,\n            showPropertiesPane: false,\n            height: '100%',\n            width: '100%'\n        });\n        editorContainer2.appendTo('#editorContainer2');\n\n        editorContainer1.documentEditor.open(JSON.stringify((<any>data).originalDocument));\n        editorContainer2.documentEditor.showRevisions = false;\n        editorContainer2.documentEditor.open(JSON.stringify((<any>data).revisedDocument));\n\n        // Sync scroll between editors\n        editorContainer1.documentEditor.viewChange = () => {\n            const pos = editorContainer1.documentEditor.selection.getScrollPosition();\n            editorContainer2.documentEditor.selection.setScrollPosition(pos);\n        };\n\n        editorContainer2.documentEditor.viewChange = () => {\n            const pos = editorContainer2.documentEditor.selection.getScrollPosition();\n            editorContainer1.documentEditor.selection.setScrollPosition(pos);\n        };\n    }\n\n    function attachEventListeners(): void {\n        // Get file input elements\n        const originalFileInput = document.getElementById('originalFileInput') as HTMLInputElement;\n        const revisedFileInput = document.getElementById('revisedFileInput') as HTMLInputElement;\n        const showResultCheckbox = document.getElementById('showResultCheckbox') as HTMLInputElement;\n        const removeOriginalFileSpan = document.getElementById('removeOriginalFile') as HTMLElement;\n        const removeRevisedFileSpan = document.getElementById('removeRevisedFile') as HTMLElement;\n\n        // Add event listners for clicking the remove icon for file names.\n        removeOriginalFileSpan.addEventListener('click', (e: Event) =>{\n            originalFile = null;\n            compareClicked = false;\n            updateButtonStates();\n            setOringialFileName();\n        });\n\n        removeRevisedFileSpan.addEventListener('click', (e: Event) =>{\n            revisedFile = null;\n            compareClicked = false;\n            updateButtonStates();\n            setRevisedFileName();\n        });\n        \n        // Add event listeners for file inputs\n        originalFileInput.addEventListener('change', (e: Event) => {\n            const input = e.target as HTMLInputElement;\n            originalFile = input.files ? input.files[0] : null;\n            compareClicked = false;\n            updateButtonStates();\n            setOringialFileName();\n        });\n        \n        revisedFileInput.addEventListener('change', (e: Event) => {\n            const input = e.target as HTMLInputElement;\n            revisedFile = input.files ? input.files[0] : null;\n            compareClicked = false;\n            updateButtonStates();\n            setRevisedFileName();\n        });\n        \n        // Show result checkbox listener\n        showResultCheckbox.addEventListener('change', (e: Event) => {\n            const input = e.target as HTMLInputElement;\n            showResult = input.checked;\n            updateRightEditorTitle();\n        });\n\n        // Compare button\n        const compareButton = new Button({\n            cssClass: 'e-primary',\n            disabled: true\n        });\n        compareButton.appendTo('#compareButton');\n\n        // Download button\n        const downloadButton = new Button({\n            cssClass: 'e-outline e-flat e-primary',\n            iconCss: 'e-icons e-download',\n            disabled: true\n        });\n        downloadButton.appendTo('#downloadButton');\n\n        const showRevisionsButton = new Button({\n            iconCss: 'e-icons e-eye'\n        });\n        showRevisionsButton.appendTo('#showRevisionsButton');\n\n        // Compare button click handler\n        document.getElementById('compareButton')?.addEventListener('click', async () => {\n            if (!originalFile || !revisedFile) return;\n\n            var orginalFileFormatType = originalFile.name.slice(originalFile.name.lastIndexOf('.')).toLowerCase();\n            var revisedFileFormatType = revisedFile.name.slice(revisedFile.name.lastIndexOf('.')).toLowerCase();\n            if(isSupportedFormatType(orginalFileFormatType) && isSupportedFormatType(revisedFileFormatType)){\n\n                compareClicked = true;\n                showRevisions = false;\n                showRevisionsButton.content = 'Show Review Pane';\n                downloadButton.disabled = false;\n                showHideWaitingIndicator(true);\n\n                if (showResult) {\n                    await openFileInEditor(originalFile, editorContainer1.documentEditor);\n                    await loadComparedDocumentAndOpen(editorContainer2.documentEditor, originalFile, revisedFile);\n                } else {\n                    await openFileInEditor(originalFile, editorContainer1.documentEditor);\n                    await openFileInEditor(revisedFile, editorContainer2.documentEditor);\n                }\n\n                updateRightEditorTitle();\n                showHideWaitingIndicator(false);\n            }\n            else{\n                alert('Unsupported file type is selected. Please use either .docx or .sfdt file.');\n                compareButton.disabled = true;\n                downloadButton.disabled = true;\n            }\n        });\n\n        // Download button click handler\n        document.getElementById('downloadButton')?.addEventListener('click', () => {\n            if (editorContainer2.documentEditor) {\n                editorContainer2.documentEditor.save('Result', 'Docx');\n            }\n        });\n\n        document.getElementById('showRevisionsButton')?.addEventListener('click', () => {\n            const editor2 = editorContainer2.documentEditor;\n            if (editor2) {\n                showRevisions = !showRevisions;\n                editor2.showRevisions = showRevisions;\n                showRevisionsButton.content = showRevisions ? 'Hide Review Pane' : 'Show Review Pane';\n            }\n        });\n    }\n\n    function updateButtonStates(): void {\n        const compareButtonObj = (document.getElementById('compareButton') as any).ej2_instances[0];\n        if (compareButtonObj) {\n            compareButtonObj.disabled = !(originalFile && revisedFile);\n        }\n\n        const downloadButtonObj = (document.getElementById('downloadButton') as any).ej2_instances[0];\n        if (downloadButtonObj) {\n            downloadButtonObj.disabled = !compareClicked;\n        }\n    }\n\n    function isSupportedFormatType(formatType: string): boolean {\n        switch (formatType) {\n            case '.docx':\n            case '.sfdt':\n                return true;\n            default:\n                return false;\n        }\n    }\n\n    async function openFileInEditor(file: File, editor: DocumentEditor): Promise<void> {\n        const formatType = file.name.slice(file.name.lastIndexOf('.')).toLowerCase();\n        if (formatType === '.sfdt') {\n            const content = await readFileAsText(file);\n            editor.showRevisions = false;\n            editor.open(content);\n        }\n        else if (isSupportedFormatType(formatType)) {\n            try {\n                const formData = new FormData();\n                formData.append('file', file);\n                const response = await fetch(serviceUrl + 'Import', {\n                    method: 'POST',\n                    body: formData\n                });\n\n                const sfdtString = await response.text();\n                let sfdtObject: any = null;\n                try {\n                    sfdtObject = JSON.parse(sfdtString);\n                } catch (e) {\n                    alert(\"Failed to process the compared document due to no valid JSON. Please try again.\");\n                }\n                if (sfdtObject) {\n                    editor.showRevisions = false;\n                    editor.open(JSON.stringify(sfdtObject));\n                } else {\n                    alert(\"Unable to display the compared document. Please try again.\");\n                }\n            } catch (e) {\n                alert('This Compare Documents demo supports only DOCX and SFDT file formats. Please select a valid DOCX or SFDT document and try again.');\n            }\n        } else {\n            alert('Unsupported file type. Please use .docx, or .sfdt file.');\n        }\n    }\n\n    async function loadComparedDocumentAndOpen(editor: DocumentEditor, originalFile: File, revisedFile: File): Promise<void> {\n        const formData = new FormData();\n        formData.append(\"originalFile\", originalFile);\n        formData.append(\"revisedFile\", revisedFile);\n        formData.append(\"author\", \"Author\");\n        formData.append(\"dateTime\", new Date().toISOString());\n        try {\n            const response = await fetch(serviceUrl + 'CompareDocuments', {\n                method: 'POST',\n                body: formData\n            });\n\n            if (!response.ok) {\n                alert(\"Failed to compare the selected documents. Please try again.\"); \n                return;\n            }\n\n            const sfdtString = await response.text();\n            try {\n                const sfdtObject = JSON.parse(sfdtString);\n                editor.showRevisions = false;\n                editor.open(sfdtObject);\n            } catch (e) {\n                alert(\"The comparison could not be completed due to no valid JSON. Please try again.\");\n            }\n        } catch (e) {\n            alert('Error during document comparison.');\n        }\n    }\n\n    function readFileAsText(file: File): Promise<string> {\n        return new Promise((resolve, reject) => {\n            const reader = new FileReader();\n            reader.onload = event => {\n                resolve(event.target?.result as string);\n            };\n            reader.onerror = error => reject(error);\n            reader.readAsText(file);\n        });\n    }\n\n    function showHideWaitingIndicator(show: boolean): void {\n        let waitingPopUp: HTMLElement | null = document.getElementById('waiting-popup');\n        let inActiveDiv: HTMLElement | null = document.getElementById('popup-overlay');\n        if (waitingPopUp && inActiveDiv){\n            inActiveDiv.style.display = show ? 'block' : 'none';\n            waitingPopUp.style.display = show ? 'block' : 'none';\n        }\n    }\n\n    function updateRightEditorTitle(): void {\n        const titleElement = document.getElementById('rightEditorTitle');\n        if (titleElement) {\n            titleElement.textContent = showResult ?\n                'Result Document (with tracked changes)' :\n                'Revised Document';\n        }\n        const showRevisionsElement = document.getElementById('showRevisionsButton');\n        if(showRevisionsElement){\n            showRevisionsElement.style.display = showResult ? 'block' : 'none';\n        }\n    }\n\n    function setOringialFileName(): void {\n        const originalFileNameElement = document.getElementById('originalFileName');\n        if(originalFileNameElement)\n        {\n            if (originalFile) {\n                const size = Math.round(originalFile.size / 1024);\n                const originalFileName = `${originalFile.name} (${size} KB)`;\n                originalFileNameElement.textContent = originalFileName;                \n            }\n            else {\n                originalFileNameElement.textContent = \"Supported formats: SFDT, DOCX\";\n            }\n        }\n    }\n\n   function setRevisedFileName(): void {\n        const revisedFileNameElement = document.getElementById('revisedFileName');\n        if(revisedFileNameElement)\n        {\n            if (revisedFile) {\n                const size = Math.round(revisedFile.size / 1024);\n                const revisedFileName = `${revisedFile.name} (${size} KB)`;\n                revisedFileNameElement.textContent = revisedFileName;            \n            }\n            else {\n                revisedFileNameElement.textContent = \"Supported formats: SFDT, DOCX\";\n            }\n        }\n    }\n}"
    }
  ]
}