Message API/docs/components/revision/align

Align

Start an interactive align workflow before comparing source files.

Overview

The align workflow posts an `align` message with two source file URLs and starts an interactive alignment flow in the viewer.

The viewer waits for the operator to pick reference points and then continues through the same completion and error lifecycle used by compare.

Quick Examples

Send the two file URLs to start interactive alignment.

Start interactive align

viewerWindow.postMessage({
  type: 'align',
  payload: {
    backgroundUrl: 'https://example.com/rev-a.pdf',
    overlayUrl: 'https://example.com/rev-b.pdf',
    dpi: 300
  }
}, '*');

Handle align result

window.addEventListener('message', (event) => {
  if (event.data?.type === 'comparisonComplete') {
    console.log('Aligned result:', event.data.payload.fileUrl);
  }

  if (event.data?.type === 'comparisonError') {
    console.error(event.data.payload.reason || event.data.payload.message);
  }
});

Control flow

Align follows the same result event pattern as compare, with the viewer driving the interactive point-picking step.

Host Sends

1. Host posts align

Send the two source URLs to begin the interactive align workflow.

javascript
viewerWindow.postMessage({
  type: 'align',
  payload: {
    backgroundUrl: bgUrl,
    overlayUrl: overlayUrl,
    dpi: 300
  }
}, '*');
Canvas Emits

2. Viewer runs interactive alignment

The viewer waits for the operator to pick the required reference points before completing the compare workflow.

javascript
// No extra host message is required during interactive align.
// Wait for completion or error from the viewer.
Host Sends

3. Host handles completion or failure

Use the same completion and error listeners as compare to move the workflow forward.

javascript
window.addEventListener('message', (event) => {
  if (event.data?.type === 'comparisonComplete') {
    openResult(event.data.payload.fileUrl);
  }
});

Complete Implementation

This example starts the interactive align flow and then waits for completion or failure from the viewer.

function alignFiles(backgroundUrl, overlayUrl) {
  viewerWindow.postMessage({
    type: 'align',
    payload: {
      backgroundUrl,
      overlayUrl,
      dpi: 300
    }
  }, '*');
}

window.addEventListener('message', (event) => {
  const data = event.data;
  if (!data) return;

  if (data.type === 'comparisonComplete') {
    console.log('Align result:', data.payload.fileUrl);
    return;
  }

  if (data.type === 'comparisonError') {
    console.error(data.payload.reason || data.payload.message);
  }
});
Complete Implementation

Additional Resources

Use compare for direct revision diffs when the source files are already aligned.