{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "docx-editor-compare-documents",
  "framework": "angular",
  "type": "registry:component",
  "component": "DocxEditor",
  "variant": "compare-documents",
  "dependencies": [
    "@syncfusion/ej2-angular-documenteditor",
    "@syncfusion/ej2-angular-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/angular/llms.txt",
    "skillPack": "syncfusion/angular-ui-components-skills",
    "docs": "https://ai.syncfusion.com/gallery/angular/docx-editor-compare-documents.md"
  },
  "files": [
    {
      "target": "src/components/docx-editor-compare-documents/docx-editor.component.html",
      "content": "<div class=\"control-section\" style=\"width: 100%;\">\n  <!-- Shared container -->\n  <div style=\"width: 760px; margin: 10px auto\">\n    <!-- Upload row -->\n    <div style=\"display: flex; gap: 6px\">\n      <!-- Original 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>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\"\n              style=\"display: none;\"\n              accept=\".docx,.sfdt\"\n              (change)=\"onOriginalFileChange($event)\" />\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>{{ getOriginalFileName() }} </span>\n          <span *ngIf=\"originalFile\" class=\"e-icons e-trash\" (click)=\"removeOriginalFile()\" 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\"\n              style=\"display: none;\"\n              accept=\".docx,.sfdt\"\n              (change)=\"onRevisedFileChange($event)\" />\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>{{ getRevisedFileName() }} </span>\n          <span *ngIf=\"revisedFile\" class=\"e-icons e-trash\" (click)=\"removeRevisedFile()\" 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>\n        <label style=\"display: inline-flex; align-items: center; cursor: pointer;\">\n          <input\n            type=\"checkbox\"\n            [checked]=\"showResult\"\n            (change)=\"onShowResultChange($event)\"\n            aria-label=\"Show comparison results with tracked changes\"\n            style=\"margin-right: 6px;\" />\n          <span>Show comparison results with tracked changes</span>\n        </label>\n      </div>\n      <!-- Buttons -->\n      <div style=\"display: flex; gap: 10px; margin-right: 32px;\">\n        <button ejs-button\n          class=\"e-primary\"        \n          [disabled]=\"!originalFile || !revisedFile\"\n          (click)=\"onCompare()\">\n          Compare\n        </button>\n        <button ejs-button\n          class=\"e-outline e-flat e-primary\"\n          (click)=\"onDownload()\"\n          iconCss=\"e-icons e-download\"\n          [disabled]=\"!compareClicked\">\n          Download Result Document\n        </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: 1px; display:block; height: calc(100vh - 330px);\">\n        <ejs-documenteditorcontainer\n          #editor1\n          [serviceUrl]=\"serviceUrl\"\n          [height]=\"'100%'\"\n          [width]=\"'100%'\"\n          [enableToolbar]=\"false\"\n          [showPropertiesPane]=\"false\"\n        ></ejs-documenteditorcontainer>\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;\" >\n          {{\n            showResult\n              ? 'Result Document (with tracked changes)'\n              : 'Revised Document'\n          }}\n        </div>\n        <button ejs-button\n            *ngIf=\"showResult\"\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            (click)=\"OnToggleRevisionPane()\">\n            {{showRevisions ? ' Hide Review Pane' : ' Show Review Pane'}}\n        </button>\n      </div>      \n      <div style=\"flex: 1px; display:block; height: calc(100vh - 330px);\">\n        <ejs-documenteditorcontainer\n          #editor2\n          [serviceUrl]=\"serviceUrl\"\n          [height]=\"'100%'\"\n          [width]=\"'100%'\"\n          [enableToolbar]=\"false\"\n          [showPropertiesPane]=\"false\"\n        ></ejs-documenteditorcontainer>\n      </div>\n    </div>\n  </div>\n\n  <!-- Waiting Popup Overlay -->\n  <div class=\"overlay\" id=\"popup-overlay\" style=\"display: none;\"></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\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>  \n"
    },
    {
      "target": "src/components/docx-editor-compare-documents/docx-editor.component.ts",
      "content": "import { NgIf } from '@angular/common';\nimport { Component, ViewEncapsulation, ViewChild } from '@angular/core';\nimport { ToolbarService, SelectionService, DocumentEditorContainerComponent, DocumentEditorContainerModule } from '@syncfusion/ej2-angular-documenteditor';\nimport { ButtonModule} from '@syncfusion/ej2-angular-buttons';\nimport { originalDocument, revisedDocument } from '../datasource/docx-editor-data';\n\n\n@Component({\n    selector: 'app-root',\n    templateUrl: 'docx-editor.component.html',\n    encapsulation: ViewEncapsulation.None,\n    providers: [ToolbarService, SelectionService],\n    standalone: true,\n    imports: [NgIf, DocumentEditorContainerModule, ButtonModule]\n})\n\nexport class CompareDocumentsComponent {\n  @ViewChild('editor1', { static: false }) editorRef1?: DocumentEditorContainerComponent;\n  @ViewChild('editor2', { static: false }) editorRef2?: DocumentEditorContainerComponent;\n\n  serviceUrl: string = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';\n  originalFile: File | null = null;\n  revisedFile: File | null = null;\n  showResult: boolean = true;\n  compareClicked: boolean = false;\n  showRevisions: boolean = false;\n\n  ngAfterViewInit() {\n    setTimeout(() => {\n      const ed1 = this.editorRef1?.documentEditor;\n      const ed2 = this.editorRef2?.documentEditor;\n      if (ed1 && ed2) {\n        ed1.open(JSON.stringify(originalDocument));\n        ed2.showRevisions = false;\n        ed2.open(JSON.stringify(revisedDocument));\n        ed1.viewChange = () => {\n          const pos = ed1.selection.getScrollPosition();\n          ed2.selection.setScrollPosition(pos);\n        };\n        ed2.viewChange = () => {\n          const pos = ed2.selection.getScrollPosition();\n          ed1.selection.setScrollPosition(pos);\n        };\n      }\n    });\n  }\n\n  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 openFileInEditor(file: File, editorRef?: DocumentEditorContainerComponent): Promise<void> {\n    const formatType = file.name.slice(file.name.lastIndexOf('.')).toLowerCase();\n    if(editorRef){\n      if (formatType === '.sfdt') {\n        const docData = await file.text();\n        editorRef.documentEditor.showRevisions = false;\n        editorRef.documentEditor.open(docData);\n      } else if (this.isSupportedFormatType(formatType)) {\n        const formData = new FormData();\n        formData.append('file', file);\n        try {\n          const response = await fetch(this.serviceUrl + 'Import', {\n            method: 'POST',\n            body: formData,\n          });\n          const sfdtString = await response.text();\n          let sfdtObject: any = null;\n          try {\n            sfdtObject = JSON.parse(sfdtString);\n          } catch (e) {\n            alert(\"Unable to display the compared document. Please try again.\");\n          }\n          if (sfdtObject && editorRef?.documentEditor) {\n            editorRef.documentEditor.showRevisions = false;\n            editorRef.documentEditor.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 either .docx or .sfdt file.');\n        this.compareClicked = false;\n      }\n    }\n  }\n\n  async loadComparedDocumentAndOpen(editorRef2: DocumentEditorContainerComponent, 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(this.serviceUrl + 'CompareDocuments', {\n        method: 'POST',\n        body: formData,\n      });\n      if (!response.ok) {\n        alert(\"Failed to compare the selected documents. Please try again.\"); \n        return;\n      }\n      const sfdtString = await response.text();\n      let sfdtObject: any = null;\n      try {\n        sfdtObject = JSON.parse(sfdtString);\n      } catch {\n        alert(\"The comparison could not be completed due to no valid JSON. Please try again.\");\n        return;\n      }\n      if (sfdtObject && editorRef2?.documentEditor) {\n        editorRef2.documentEditor.showRevisions = false;\n        editorRef2.documentEditor.open(JSON.stringify(sfdtObject));\n      } else {\n        alert(\"Unable to display the comparison result. Please try again.\");\n      }\n    } catch (e) {\n      alert('Error on comparing documents: ' + e);\n    }\n  }\n\n  removeOriginalFile(): void {\n      this.originalFile = null;\n      this.compareClicked = false;\n  }\n\n  removeRevisedFile(): void {\n      this.revisedFile = null;\n      this.compareClicked = false;\n  }\n\n  getOriginalFileName(): string {\n    if (!this.originalFile) {\n      return 'Supported formats: SFDT, DOCX';\n    }\n\n    const size = Math.round(this.originalFile.size / 1024);\n    return `${this.originalFile.name} (${size} KB)`;\n }\n\n getRevisedFileName(): string {\n    if (!this.revisedFile) {\n      return 'Supported formats: SFDT, DOCX';\n    }\n\n    const size = Math.round(this.revisedFile.size / 1024);\n    return `${this.revisedFile.name} (${size} KB)`;\n }\n\n  onOriginalFileChange(event: any) {\n    this.originalFile = event.target.files && event.target.files[0] ? event.target.files[0] : null;\n    this.compareClicked = false;\n  }\n  onRevisedFileChange(event: any) {\n    this.revisedFile = event.target.files && event.target.files[0] ? event.target.files[0] : null;\n    this.compareClicked = false;\n  }\n  onShowResultChange(event: any) {\n    this.showResult = event.target.checked;\n  }\n\n  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  async onCompare(): Promise<void> {    \n    this.compareClicked = false;\n    this.showRevisions = false;\n    setTimeout(async () => {\n      if (this.originalFile && this.revisedFile){\n        var orginalFileFormatType = this.originalFile.name.slice(this.originalFile.name.lastIndexOf('.')).toLowerCase();\n        var revisedFileFormatType = this.revisedFile.name.slice(this.revisedFile.name.lastIndexOf('.')).toLowerCase();\n        if(this.isSupportedFormatType(orginalFileFormatType) && this.isSupportedFormatType(revisedFileFormatType)){\n          this.showHideWaitingIndicator(true);   \n          this.compareClicked = true;\n          if (this.showResult) {\n            if (this.editorRef1)\n                await this.openFileInEditor(this.originalFile, this.editorRef1);                       \n            if (this.editorRef2)\n                await this.loadComparedDocumentAndOpen(this.editorRef2, this.originalFile, this.revisedFile);           \n          } else {\n            if (this.editorRef1)\n              await this.openFileInEditor(this.originalFile, this.editorRef1);\n            if (this.editorRef2)\n              await this.openFileInEditor(this.revisedFile, this.editorRef2);\n          }\n          this.showHideWaitingIndicator(false);\n        }\n        else{          \n          alert('Unsupported file type is selected. Please use either .docx or .sfdt file.');\n        }\n      }\n    }, 0);\n  }\n\n  onDownload(): void {\n    if (this.editorRef2?.documentEditor)\n      this.editorRef2.documentEditor.save('Result', 'Docx');\n  }\n\n  OnToggleRevisionPane(): void {\n    this.showRevisions = !this.showRevisions;\n     const editor2 = this.editorRef2?.documentEditor;\n      if (editor2) {\n        editor2.showRevisions = this.showRevisions;\n      }\n  }\n\n}"
    }
  ]
}