# Review a proposed liability cap in Word

The lawyer’s instruction is to cap liability at fees paid in the 12 months before the claim. Review the tracked revision to the limitation of liability clause in a firm-owned agreement. Decide whether the draft reflects the instruction, then download it as a DOCX. The public sample contains a prepared proposal.

## Run

Requires Node.js 22 or newer. `npm install` then `npm run dev`. Open the localhost URL Vite prints. To check and build the project, run `npm run check` and `npm run build`.

Browser editor: 2.36.0. Direct dependencies are pinned in package.json.

## Try it

The accepted copy limits the cap to the specified 12 months. The rejected copy retains the original cap based on amounts paid under the agreement.

The included DOCX is a public synthetic example. It is not your uploaded document or the current edited demo state. Export a separate DOCX and inspect the result in Microsoft Word.

## Files

- package.json
- examples/proof-agent-law-firms/main.ts
- examples/proof-agent-law-firms/index.html
- examples/shared/browser.ts
- examples/shared/style.css
- examples/shared/word-proof.ts
- examples/shared/word-proof.css
- vite.config.ts
- tsconfig.json
- public/samples/verticals/law-firms-agent-proposed.docx

## Continue

[Current documentation](https://docs.superdoc.dev/editor/custom-ui/tracked-changes/)
[Open the public example](https://www.superdoc.dev/examples/proof-agent-law-firms/index.html)
[SuperDoc licensing](https://docs.superdoc.dev/editor/license/)

The shared browser.ts file contains the export button, status messages and CSS imports. Document setup and task logic are in main.ts.

## Complete source

### package.json

```json
{
  "name": "superdoc-proof-agent-law-firms",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "engines": {
    "node": ">=22"
  },
  "scripts": {
    "dev": "vite --open /examples/proof-agent-law-firms/",
    "build": "vite build",
    "check": "tsc --noEmit"
  },
  "dependencies": {
    "superdoc": "2.36.0",
    "fflate": "0.8.3"
  },
  "devDependencies": {
    "vite": "6.4.1",
    "typescript": "5.8.3"
  }
}
```

### examples/proof-agent-law-firms/main.ts

```javascript
import { mountWordProof } from '../shared/word-proof';

mountWordProof('review', '/samples/verticals/law-firms-agent-proposed.docx', { filename: 'law-firms-review.docx' });
```

### examples/proof-agent-law-firms/index.html

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Review a proposed liability cap in Word | SuperDoc example</title>
<meta name="description" content="Review the tracked revision to the limitation of liability clause in a firm-owned agreement. Decide whether the draft reflects the instruction, then download it as a DOCX.">
<link rel="canonical" href="https://www.superdoc.dev/examples/proof-agent-law-firms/index.html">
<link rel="alternate" type="text/markdown" href="https://www.superdoc.dev/examples/proof-agent-law-firms.md">
</head>
<body data-proof="review" data-agent-review>
<header class="review-heading">
  <h1>Review a proposed liability cap in Word</h1>
  <p>The lawyer’s instruction is to cap liability at fees paid in the 12 months before the claim.</p>
  <p>Review the sample proposal, then download the Word file.</p>
</header>
<main class="solo review-workspace" aria-label="Review the sample proposal">
  <div class="review-chrome">
    <div id="proof-actions" class="actions review-actions" role="group" aria-label="Review actions">
      <div class="review-action-group" role="group" aria-label="Selected change">
        <button type="button" data-proof-action="previous" aria-label="Previous change" disabled>Previous</button>
        <button type="button" data-proof-action="next" aria-label="Next change" disabled>Next</button>
        <button type="button" data-proof-action="accept" disabled>Accept</button>
        <button type="button" data-proof-action="reject" disabled>Reject</button>
      </div>
      <div class="review-action-group" role="group" aria-label="All pending changes">
        <button type="button" data-proof-action="accept-all" disabled>Accept all</button>
        <button type="button" data-proof-action="reject-all" disabled>Reject all</button>
      </div>
      <div class="review-action-group review-handoff">
        <span id="review-count">Loading…</span>
        <button id="export" class="example-file-action" type="button" disabled><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 4v12m-4-4 4 4 4-4M4 16v4h16v-4"/></svg>Download Word file</button>
      </div>
    </div>
    <p id="review-selection" aria-live="polite"></p>
    <output id="status" role="status">Opening sample…</output>
  </div>
  <div id="editor" aria-label="Word document"></div>
</main>
<footer class="review-resources">
  <button id="proof-reset" type="button">Reset example</button>
  <a href="https://docs.superdoc.dev/editor/custom-ui/tracked-changes/">Build review controls</a>
  <a href="/examples/proof-agent-law-firms.md">Read the browser example</a>
  <a href="/examples/proof-agent-law-firms.zip">Download the browser project</a>
</footer>
<script type="module" src="./main.ts"></script>
</body>
</html>
```

### examples/shared/browser.ts

```javascript
import type { SuperDoc } from 'superdoc';
import 'superdoc/style.css';
import './style.css';

export function element<T extends HTMLElement>(id: string): T {
  const node = document.getElementById(id);
  if (!node) throw new Error(`Missing element: ${id}`);
  return node as T;
}

const status = element<HTMLOutputElement>('status');
const exportButton = element<HTMLButtonElement>('export');
export function report(message: string) { status.value = message; }
export function showError(error: unknown) {
  report(error instanceof Error ? error.message : String(error));
}

export function enableExport(superdoc: SuperDoc) {
  report('Ready. Edit the document, then export a copy.');
  exportButton.disabled = false;
  exportButton.addEventListener('click', async () => {
    exportButton.disabled = true;
    try {
      await superdoc.export({ exportType: ['docx'], exportedName: 'edited-example', triggerDownload: true });
      report('DOCX exported. Open the saved file to check your changes.');
    } catch (error) { showError(error); }
    finally { exportButton.disabled = false; }
  });
}
```

### examples/shared/style.css

```css
:root { font-family: system-ui, sans-serif; color: #242424; background: #f5f5f5; }
#editor { --sd-caret-color: #242424; }
input, textarea, [contenteditable="true"] { caret-color: #242424; }
* { box-sizing: border-box; }
body { margin: 0; }
header { padding: 1rem; border-bottom: 1px solid #ddd; background: white; }
h1 { font-size: 1.2rem; margin: 0 0 .5rem; }
p { line-height: 1.5; }
button, input { font: inherit; padding: .5rem .7rem; min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: wait; }
label { display: grid; gap: .3rem; margin-bottom: .7rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; }
main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
main.solo { display: block; }
#editor { height: 76vh; overflow: auto; min-width: 0; }
aside { padding: 1rem; background: white; overflow: auto; max-height: 76vh; }
ul { list-style: none; padding: 0; }
li { border-bottom: 1px solid #ddd; padding: .7rem 0; }
li button { margin: .2rem; }
input { width: 100%; }
@media (max-width: 760px) { main { grid-template-columns: minmax(0, 1fr); } aside { max-height: none; } }

/* Keep file actions consistent with the homepage editor. */
.example-file-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  min-height: 44px;
  padding: .45rem .7rem;
  border: 1px solid var(--example-file-border, #b9c9e0);
  border-radius: .5rem;
  background: var(--example-file-surface, #fff);
  color: var(--example-file-color, #1747b7);
  font-size: .875rem;
  font-weight: 600;
}
.example-file-action:hover:enabled { background: var(--example-file-hover, #edf3ff); }
.example-file-action svg { width: 1.05rem; height: 1.05rem; flex: none; }
.example-file-primary { background: #1355ff; border-color: #1355ff; color: #fff; }
.example-file-primary:hover:enabled { background: #0f44cc; border-color: #0f44cc; }
```

### examples/shared/word-proof.ts

```javascript
import { SuperDoc } from 'superdoc';
import { unzipSync } from 'fflate';
import { element, report, showError } from './browser';
import './word-proof.css';

type Proof = 'review' | 'report' | 'formatting' | 'precise';
const jumpTargets = new Map([
  ['findings', { paraId: '50500150', instruction: 'Find the findings table and edit a status cell.' }],
]);
const formattingFinding = 'Evidence 0003 supports the quarterly controls review.';
const formattingHeading = '50504501';
export function mountWordProof(mode: Proof, fixture: string, sampleReview?: { filename: string }) {
  const ns = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
  const revisionNames = new Set([
    'ins', 'del', 'moveFrom', 'moveTo', 'rPrChange', 'pPrChange', 'sectPrChange',
    'tblPrChange', 'tblGridChange', 'trPrChange', 'tcPrChange', 'cellIns', 'cellDel',
    'cellMerge', 'numberingChange',
  ]);
  const actionBar = element('proof-actions');
  const download = element<HTMLButtonElement>('export');
  const workspace = mode === 'review' || mode === 'formatting';
  const surface = element('editor');
  const compact = window.matchMedia('(max-width: 1099px), (pointer: coarse)');
  const review = mode === 'review' ? {
    count: element('review-count'),
    selection: element('review-selection'),
    buttons: Array.from(actionBar.querySelectorAll<HTMLButtonElement>('[data-proof-action]')),
  } : undefined;
  const proposal = 'Approval is due within 10 days.';
  type Caret = Parameters<SuperDoc['ui']['selection']['apply']>[0];
  let editor: SuperDoc;
  let prepared: Blob | undefined;
  type Change = Awaited<ReturnType<typeof getReview>>[number];
  const decisions = new Map<string, 'accept' | 'reject'>();
  let changes: Change[] = [];
  let selected = -1;
  let findingCaret: Caret | undefined;
  let reviewReady = false;
  let working = false;
  let reviewDecided = false;
  const observe = (action: string) => window.dispatchEvent(new CustomEvent('superdoc:word-proof', { detail: action }));

  function elementText(part: Document, tag: string): string[] {
    return Array.from(part.getElementsByTagNameNS(ns, tag), node => node.textContent ?? '');
  }

  function releaseDownload(blob: Blob, label: string) {
    const url = URL.createObjectURL(blob);
    const link = document.createElement('a');
    link.href = url;
    link.download = label;
    link.click();
    setTimeout(() => URL.revokeObjectURL(url), 1000);
  }

  function proofParts(blob: Blob): Promise<Document[]> {
    return blob.arrayBuffer().then(bytes => {
      const parts = unzipSync(new Uint8Array(bytes), {
        filter: part => /^word\/(document|header\d+|footer\d+|footnotes|endnotes|comments)\.xml$/.test(part.name),
      });
      if (!parts['word/document.xml']) throw new Error('The saved package is missing its document.');
      const decoder = new TextDecoder();
      return Object.values(parts).map(bytes => {
        const parsed = new DOMParser().parseFromString(decoder.decode(bytes), 'application/xml');
        if (parsed.querySelector('parsererror')) throw new Error('The saved Word file contains an unreadable part.');
        return parsed;
      });
    });
  }

  async function exportCopy() {
    return await editor.export({ exportType: ['docx'], triggerDownload: false, commentsType: 'external' });
  }

  async function getReview() {
    const list = await editor.activeEditor.doc.trackChanges.list({ in: 'all', limit: 300 });
    return list.items;
  }

  function changeTarget(change: Change) {
    return { id: change.id, story: change.address?.story };
  }

  async function revealChange(index: number) {
    const change = changes[index];
    if (!change) {
      selected = -1;
      editor.ui.trackChanges.setActive(null);
      return;
    }
    const target = changeTarget(change);
    const result = await editor.ui.trackChanges.scrollTo(target);
    editor.ui.trackChanges.setActive(target);
    selected = index;
    if (!result.success) report('This change is selected. Its location could not be shown in the preview.');
  }

  async function initializeReview() {
    changes = await getReview();
    const proposalIndex = sampleReview && changes.length ? 0 : changes.findIndex(item => item.insertedText?.trim() === proposal);
    if (proposalIndex < 0) throw new Error('The sample proposal could not be found.');
    report(sampleReview
      ? 'Review the highlighted change, or download the document with the proposal still pending.'
      : 'Accept or reject the highlighted change, then download the Word file.');
    await revealChange(proposalIndex);
    reviewReady = true;
    if (sampleReview) observe('ready');
  }

  async function decide(decision: 'accept' | 'reject', all: boolean) {
    const change = changes[selected];
    if (!all && !change) return;
    const before = all ? changes : [change];
    // Keep the agreement read-only between decisions. The Document API requires
    // a writable mode while it applies the explicit review action.
    surface.inert = true;
    editor.setDocumentMode('suggesting');
    try {
      const result = await editor.activeEditor.doc.trackChanges.decide({
        decision,
        target: all ? { kind: 'all', story: 'all' } : { kind: 'id', ...changeTarget(change) },
        commentRetention: 'point',
      });
      if (!result.success) throw new Error('The decision could not be applied. Please try again.');
    } finally {
      editor.setDocumentMode('viewing');
      surface.inert = false;
    }
    if (sampleReview) {
      changes = await getReview();
      reviewDecided = true;
    } else {
      for (const item of before) {
        if (item.insertedText?.trim()) decisions.set(item.insertedText.trim(), decision);
      }
      changes = all ? [] : changes.filter((_, index) => index !== selected);
    }
    prepared = undefined;
    const next = Math.min(selected, changes.length - 1);
    const outcome = decision === 'accept' ? 'Accepted' : 'Rejected';
    report(all ? `${outcome} all remaining changes.` : `${outcome} the selected change.`);
    await revealChange(next);
  }

  function revisionSignatures(items: Change[]) {
    return JSON.stringify(items.map(({ type, author, insertedText, deletedText, address }) =>
      JSON.stringify([type, author, insertedText, deletedText, address?.story?.kind]),
    ).sort());
  }

  async function verifyReview() {
    report('Checking the saved Word file…');
    const candidate = await exportCopy();
    const parts = await proofParts(candidate);
    if (!sampleReview) {
      const contents = parts.map(part => elementText(part, 't').join(''));
      for (const [text, decision] of decisions) {
        if (contents.some(part => part.includes(text)) !== (decision === 'accept')) {
          throw new Error('The saved copy did not preserve a review decision. Retry the download.');
        }
      }
      const originalComment = parts.some(part => elementText(part, 'comment').includes('Retain this comment for the reviewer.'));
      const anchored = parts.some(part => ['commentRangeStart', 'commentRangeEnd', 'commentReference']
        .every(tag => part.getElementsByTagNameNS(ns, tag).length));
      if (!originalComment || !anchored) throw new Error('The saved copy lost the original comment. Retry the download.');
    }
    if (!changes.length && parts.some(part => Array.from(part.getElementsByTagNameNS(ns, '*'))
      .some(node => revisionNames.has(node.localName)))) {
      throw new Error('The saved copy still contains revisions. Retry the download.');
    }
    if (revisionSignatures(await reopen(candidate)) !== revisionSignatures(changes)) {
      throw new Error('The reopened copy did not preserve the pending changes. Retry the download.');
    }
    prepared = candidate;
    if (!sampleReview || reviewDecided) observe('task_succeeded');
    return candidate;
  }

  function keepTargetVisible(paraId: string) {
    const paragraph = surface.querySelector(`[data-para-id="${paraId}"]`);
    if (!paragraph) return;
    const target = paragraph.getBoundingClientRect();
    const view = surface.getBoundingClientRect();
    if (target.top < view.top || target.bottom > view.bottom) {
      surface.scrollTop += target.top - view.top - 20;
    }
  }

  async function initializeFormatting() {
    await editor.activeEditor.pageMetrics.revealBodyTarget({ paraId: formattingHeading });
    const { items } = await editor.activeEditor.doc.find({
      select: { type: 'text', pattern: formattingFinding, caseSensitive: true },
    });
    const match = items[0];
    if (items.length === 1 && match && 'nodeId' in match.address) {
      const point = { kind: 'text' as const, blockId: match.address.nodeId, offset: formattingFinding.length };
      findingCaret = { kind: 'selection', start: point, end: point };
    }
    // The painted coordinates describe the fitted page on touch screens.
    keepTargetVisible(formattingHeading);
    report('Edit finding 0003. Try adding “Confirmed.”, then download the DOCX.');
  }

  function editFinding() {
    if (findingCaret && editor.ui.selection.apply(findingCaret).ok) editor.focus();
    else void editor.activeEditor.pageMetrics.revealBodyTarget({ paraId: formattingHeading })
      .then(() => keepTargetVisible(formattingHeading));
    report('Update the wording in finding 0003.');
  }

  async function proposeNumber() {
    const doc = editor.activeEditor.doc;
    const response = await doc.find({ select: { type: 'text', pattern: '30 days', caseSensitive: true } });
    const hit = response.items.at(0);
    const target = hit && (Reflect.get(hit, 'target') ?? Reflect.get(hit, 'address'));
    const blockId: unknown = target?.nodeId;
    if (response.items.length !== 1 || typeof blockId !== 'string') {
      throw new Error('The original target was not found.');
    }
    const result = await doc.replace({
      target: {
        kind: 'selection',
        start: { kind: 'text', blockId, offset: 0 },
        end: { kind: 'text', blockId, offset: 7 },
      },
      text: '60 days', expectedText: '30 days', replacementGranularity: 'word',
    }, { changeMode: 'tracked' });
    if (!result.success) throw new Error('The proposal could not be applied.');
    const parts = await proofParts(await exportCopy());
    const inserted = parts.flatMap(part => elementText(part, 'ins')).join('');
    const removed = parts.flatMap(part => elementText(part, 'del')).join('');
    if (!['6', '60'].includes(inserted.trim()) || !['3', '30'].includes(removed.trim())) {
      throw new Error('The saved redline changes more than the expected number.');
    }
    const originalComment = parts.some(part => elementText(part, 'comment').includes('Confirm this term with the account team.'));
    if (!originalComment || !parts.some(part => part.getElementsByTagNameNS(ns, 'commentReference').length)) {
      throw new Error('The saved copy lost the original comment.');
    }
    observe('task_succeeded');
    report('Only the number is marked. Use the review toolbar to accept or reject the proposal.');
  }

  function setControls(enabled: boolean) {
    if (!review) {
      actionBar.querySelectorAll<HTMLButtonElement>('button[data-proof-action]').forEach(button => {
        button.disabled = !enabled;
      });
      download.disabled = !enabled;
      return;
    }
    const active = changes[selected];
    review.count.textContent = reviewReady ? `${changes.length} pending` : 'Loading…';
    review.selection.textContent = active
      ? `Change ${selected + 1} of ${changes.length} · ${active.insertedText?.trim() || active.deletedText?.trim() || active.type}`
      : reviewReady ? 'No pending changes' : '';
    for (const button of review.buttons) {
      const action = button.dataset.proofAction;
      const available = action === 'previous' ? selected > 0
        : action === 'next' ? selected >= 0 && selected < changes.length - 1
        : action?.endsWith('-all') ? changes.length > 0 : Boolean(active);
      button.disabled = !enabled || !reviewReady || !available;
    }
    download.disabled = !enabled || (sampleReview ? !reviewReady : decisions.size === 0);
  }

  function setTracking(tracks: boolean) {
    editor.setDocumentMode(tracks ? 'suggesting' : 'editing');
    actionBar.querySelector('[data-proof-action="tracking"]')?.setAttribute('aria-pressed', String(tracks));
  }

  async function perform(action: string) {
    if (action === 'initialize') return await initializeReview();
    if (action === 'formatting') return await initializeFormatting();
    if (action === 'findings-edit') return editFinding();
    if (action === 'previous' || action === 'next') {
      report('Review the selected change.');
      return await revealChange(selected + (action === 'next' ? 1 : -1));
    }
    if (action === 'reject' || action === 'accept' || action === 'reject-all' || action === 'accept-all') {
      return await decide(action.startsWith('accept') ? 'accept' : 'reject', action.endsWith('-all'));
    }
    if (action === 'propose') return await proposeNumber();
    if (action === 'tracking') {
      const button = actionBar.querySelector<HTMLButtonElement>('[data-proof-action="tracking"]')!;
      const tracks = button.getAttribute('aria-pressed') !== 'true';
      setTracking(tracks);
      report(tracks ? 'Track Changes is on.' : 'Track Changes is off.');
      return;
    }
    const target = jumpTargets.get(action);
    if (!target) return;
    const result = await editor.activeEditor.pageMetrics.revealBodyTarget({ paraId: target.paraId });
    report(result.status === 'revealed' ? target.instruction : 'This page is still preparing. Try again when pagination settles.');
  }

  async function act(action: string) {
    if (working) return;
    if (action === 'reset') {
      window.location.reload();
      return;
    }
    working = true;
    setControls(false);
    try {
      if (action === 'download') {
        observe('export_requested');
        const candidate = prepared ?? await (review ? verifyReview() : exportCopy());
        if (mode === 'formatting') {
          const parts = await proofParts(candidate);
          const documentPart = parts.find(part => part.documentElement.localName === 'document')!;
          const row = Array.from(documentPart.getElementsByTagNameNS(ns, 'tr')).find(row =>
            row.getElementsByTagNameNS(ns, 'tc')[0]?.textContent === 'AUD-0003',
          );
          const editedFinding = row?.getElementsByTagNameNS(ns, 'tc')[1]?.textContent;
          if (editedFinding && editedFinding !== formattingFinding) observe('task_succeeded');
        }
        releaseDownload(candidate, sampleReview?.filename ?? `word-${mode}-sample.docx`);
        observe('export_completed');
        report(sampleReview
          ? changes.length
            ? 'Word file downloaded with pending changes.'
            : 'Word file downloaded with your review decisions.'
          : review
          ? `Word file downloaded. ${changes.length} pending changes remain for review in Word.`
          : 'Word file downloaded. Open it in Microsoft Word to inspect the result.');
      } else {
        await perform(action);
      }
    } catch (error) {
      if (action === 'download') {
        observe('export_failed');
        if (review) observe('task_failed');
      }
      else if (action === 'initialize' && sampleReview) observe('load_failed');
      else if (/^(accept|reject|propose)/.test(action)) observe('task_failed');
      showError(error);
    }
    finally {
      working = false;
      setControls(true);
    }
  }

  actionBar.addEventListener('click', event => {
    const button = (event.target as HTMLElement).closest<HTMLButtonElement>('button');
    if (!button || button.disabled) return;
    const action = button === download ? 'download' : button.dataset.proofAction;
    if (action) void act(action);
  });
  if (review) surface.addEventListener('click', event => {
    if (working || !reviewReady) return;
    const hit = editor.ui.trackChanges.getAt({ x: event.clientX, y: event.clientY });
    const index = hit ? changes.findIndex(change => change.id === hit.id) : -1;
    if (index < 0) return;
    editor.ui.trackChanges.setActive(hit!);
    selected = index;
    setControls(true);
  });
  if (workspace) {
    element<HTMLButtonElement>('proof-reset').addEventListener('click', () => void act('reset'));
    if (!review) compact.addEventListener('change', () => editor?.setCommentsLayout(compact.matches ? 'inline' : 'sidebar'));
    const viewport = window.visualViewport;
    viewport?.addEventListener('resize', () => {
      document.body.style.setProperty('--proof-visible-height', `${viewport.height}px`);
    });
  }
  window.addEventListener('pagehide', event => { if (!event.persisted) editor?.destroy(); });

  const config = {
    telemetry: { enabled: false },
    selector: '#editor',
    zoom: { mode: 'fit-width' as const, fitWidth: { padding: 16 } },
    viewing: { trackedChanges: review ? 'markup' as const : 'final' as const, comments: false },
    ...(review && { interaction: { trackedChanges: { allowDecisions: true } } }),
    user: { name: 'Example reviewer', email: 'reviewer@example.com' },
    ui: {
      ...(review ? {} : { toolbar: { container: '#toolbar', responsiveTo: 'container' as const } }),
      ...(review ? { comments: false as const } : workspace ? { comments: { layout: compact.matches ? 'inline' as const : 'sidebar' as const } } : {}),
    },
  };

  async function reopen(candidate: Blob) {
    const host = document.createElement('div');
    host.id = 'review-verification';
    host.inert = true;
    host.setAttribute('aria-hidden', 'true');
    host.style.width = `${element('editor').clientWidth}px`;
    document.body.append(host);
    let verifier: SuperDoc | undefined;
    let timer: number | undefined;
    try {
      const copy = new File([candidate], 'reviewed-agreement.docx', {
        type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
      });
      const opened = await new Promise<SuperDoc>((resolve, reject) => {
        timer = window.setTimeout(() => reject(new Error('The saved copy did not reopen. Try verifying again.')), 20000);
        verifier = new SuperDoc({
          ...config, selector: '#review-verification', ui: {}, document: copy, documentMode: 'viewing',
          onReady: ({ superdoc }) => resolve(superdoc),
          onContentError: ({ error }) => reject(error),
          onException: ({ error }) => reject(error),
        });
      });
      const reopened = await opened.activeEditor.doc.trackChanges.list({ in: 'all', limit: 300 });
      return reopened.items;
    } finally {
      window.clearTimeout(timer);
      verifier?.destroy();
      host.remove();
    }
  }

  observe('load_started');
  new SuperDoc({
    ...config,
    document: fixture,
    documentMode: review ? 'viewing' : mode === 'precise' ? 'suggesting' : 'editing',
    onReady: ({ superdoc }) => {
      editor = superdoc;
      if (!sampleReview) observe('ready');
      if (review) void act('initialize');
      else if (mode === 'formatting') void act('formatting');
      else {
        report('Ready to edit.');
        setControls(true);
      }
    },
    onContentError: ({ error }) => handleEditorError(error),
    onException: ({ error }) => handleEditorError(error),
  });

  function handleEditorError(error: unknown) {
    if (sampleReview && !reviewReady) observe('load_failed');
    showError(error);
  }
}
```

### examples/shared/word-proof.css

```css
[data-proof] > header {
  padding: clamp(1rem, 2.6vw, 2rem) clamp(1rem, 5vw, 4rem) 1rem;
  color: #17213a;
  border-bottom-color: #d4d9e5;
}

[data-proof] h1 {
  font-size: clamp(1.45rem, 3vw, 2.4rem);
  line-height: 1.14;
  letter-spacing: -.024em;
}

[data-proof] > header p {
  max-width: 72ch;
  margin: .7rem 0;
  color: #425171;
}

[data-proof] .actions {
  gap: .45rem;
  margin-top: .9rem;
}

[data-proof] .actions button {
  padding: .5rem .8rem;
  border: 1px solid #c2cadc;
  border-radius: .5rem;
  background: white;
  color: #17213a;
  font-size: .875rem;
  font-weight: 600;
}

[data-proof] .actions :is(#export:not(.example-file-action), [data-proof-action="show"], [data-proof-action="propose"], [aria-pressed="true"]):enabled {
  border-color: #203e73;
  background: #203e73;
  color: white;
}

[data-proof] .actions button:disabled {
  background: #f2f4f8;
  color: #5f6d89;
  cursor: default;
}

[data-proof] .actions output {
  flex: 1 0 100%;
  margin-top: .25rem;
  font-size: .9rem;
}

[data-proof] > header a {
  color: #234779;
  text-underline-offset: .18em;
}

[data-proof] > header :focus-visible {
  outline: 2px solid #234779;
  outline-offset: 3px;
}

:is([data-proof="review"], [data-proof="formatting"]) {
  --review-border: #d4d9e5;
  background: #f5f7fb;
  color: #17213a;
}

:is([data-proof="review"], [data-proof="formatting"]) > .review-heading { padding: .85rem 1rem; }
.review-heading h1 { margin: 0; font-size: 1.25rem; }
.review-workspace {
  max-width: 90rem;
  margin: .85rem auto 0;
  border: 1px solid var(--review-border);
  border-radius: .75rem;
  background: white;
}
.review-chrome { position: sticky; top: 0; z-index: 5; background: white; border-radius: inherit; }
:is([data-proof="review"], [data-proof="formatting"]) .review-actions { margin: 0; padding: .4rem .7rem 0; }
.review-actions #review-count { margin-right: auto; color: #425171; font-size: .875rem; font-variant-numeric: tabular-nums; }
:is([data-proof="review"], [data-proof="formatting"]) .review-actions [data-proof-action="accept"]:enabled { background: #203e73; color: white; border-color: #203e73; }
:is([data-proof="review"], [data-proof="formatting"]) #status { display: block; padding: .3rem .7rem; font-size: .8125rem; color: #425171; }
:is([data-proof="review"], [data-proof="formatting"]) #editor { height: clamp(10rem, calc(var(--proof-visible-height, 100dvh) - 10rem), 52rem); background: #edf0f6; }
.review-resources { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem 1.15rem; padding: .25rem 1rem .75rem; color: #425171; font-size: .875rem; }
.review-resources summary { cursor: pointer; }
.review-resources a { display: inline-block; margin: .6rem 1rem 0 0; color: #234779; }
.review-resources button { padding: .25rem 0; background: none; border: 0; color: #234779; text-decoration: underline; }
#review-verification { position: fixed; top: 0; left: 0; height: 22rem; visibility: hidden; overflow: hidden; pointer-events: none; }

@media (max-width: 1099px), (pointer: coarse) {
  .review-workspace { margin-top: 0; border-inline: 0; border-radius: 0; }
  :is([data-proof="review"], [data-proof="formatting"]) .review-actions button { padding-inline: .55rem; }
  .review-chrome #toolbar { display: none; }
}

.review-heading, .review-resources { max-width: 90rem; margin-inline: auto; }
.review-actions button { min-height: 44px; }
.review-resources summary, .review-resources button { align-content: center; min-height: 44px; }
.review-chrome :focus-visible, .review-resources :focus-visible { outline: 2px solid #234779; outline-offset: 2px; }

.review-action-group { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.review-action-group + .review-action-group { padding-inline-start: .45rem; border-inline-start: 1px solid var(--review-border); }
.review-action-group.review-handoff { margin-inline-start: auto; }
#review-selection { margin: .35rem .7rem 0; color: #17213a; font-size: .85rem; font-weight: 600; overflow-wrap: anywhere; }
[data-proof="review"] #editor { height: clamp(14rem, calc(var(--proof-visible-height, 100dvh) - 13rem), 52rem); }
@media (max-width: 680px) {
  .review-action-group + .review-action-group { padding-inline-start: 0; border-inline-start: 0; }
  .review-action-group.review-handoff { margin-inline-start: 0; }
  [data-proof="review"] #editor { height: clamp(14rem, calc(var(--proof-visible-height, 100dvh) - 17rem), 42rem); }
}

[data-proof="review"] .review-actions #export.example-file-action:enabled {
  background: #fff;
  border-color: #b9c9e0;
  color: #1747b7;
}
[data-proof="review"] .review-actions #export.example-file-action:hover:enabled { background: #edf3ff; }
.review-resources .review-own-docx { display: inline-flex; align-items: center; min-height: 44px; margin: 0; }
```

### vite.config.ts

```javascript
import { defineConfig } from 'vite';
import { resolve } from 'node:path';
export default defineConfig({
  optimizeDeps: { exclude: ['@superdoc/docx-engine'], include: ['vue'] },
  resolve: { dedupe: ['vue'] },
  build: { rollupOptions: { input: resolve('examples/proof-agent-law-firms/index.html') } },
});
```

### tsconfig.json

```json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "lib": [
      "ES2022",
      "DOM",
      "DOM.Iterable"
    ],
    "strict": true,
    "skipLibCheck": true,
    "noEmit": true,
    "types": []
  },
  "include": [
    "examples/**/*.ts"
  ]
}
```

[Download the project](https://www.superdoc.dev/examples/proof-agent-law-firms.zip)
[Download the public sample](https://www.superdoc.dev/samples/verticals/law-firms-agent-proposed.docx)
