Skip to content

Format-specific source viewers ​

Use Source to choose the viewer automatically. The components below provide format-specific controls and require Sea context. They accept the same step bindings.

Source viewers display original documents and highlight the locations behind extracted values.

At a glance
TypeBuilding block
Elementssea-pdf-viewer, sea-image-viewer, sea-xlsx-viewer
ReactSeaPdfViewer from @sea-dev/widget-lit/react/pdf-viewer; SeaImageViewer from @sea-dev/widget-lit/react
Without React@sea-dev/widget-lit/pdf-viewer, @sea-dev/widget-lit/image-viewer, @sea-dev/widget-lit/xlsx-viewer
ConnectionRequired Sea context. A PDF viewer can use an explicit document URL
ConfigureThe attributes under each viewer below

Usage ​

SourceElementInput
PDFsea-pdf-viewerpdfUrl or a bound source
Imagesea-image-viewerdocumentExtractionId
Excel or CSVsea-xlsx-viewerdocumentExtractionId

Import the registration modules through your host's bundler:

ts
import "@sea-dev/widget-lit/context";
import type { SeaContext } from "@sea-dev/widget-lit/context";
import { SeaPdfViewer } from "@sea-dev/widget-lit/pdf-viewer";
import { SeaImageViewer } from "@sea-dev/widget-lit/image-viewer";
import { SeaXlsxViewer } from "@sea-dev/widget-lit/xlsx-viewer";

PDF ​

Web components ​

ts
export function showPdf(provider: SeaContext, url: string) {
  const viewer = new SeaPdfViewer();
  viewer.pdfUrl = url;
  viewer.style.cssText = "display:block;height:640px";
  provider.append(viewer);
  return viewer;
}

React ​

The React wrapper is SeaPdfViewer from @sea-dev/widget-lit/react/pdf-viewer.

It requires Context provider, including when pdfUrl supplies the document. It reads documents and active citations from the provider. An explicit pdfUrl takes precedence. activePage selects a page when a citation is unset.

PDF attributes and properties ​

PropertyAttributeTypeDefaultDescription
pdfUrlpdf-urlstring""Loads this PDF URL instead of the document selected by context.
documentExtractionIddocument-extraction-idstring""Selects one source document from the provider's loaded extractions.
contentTypecontent-typestring""Identifies the document format when the URL lacks an extension.
workerUrlworker-urlstring""Sets the shared PDF.js worker URL.
documentUrl—DocumentUrlResolver or undefined—Rewrites the source document URL before retrieval.
documentProxydocument-proxystring""Fetches the source document through a host proxy endpoint.
annotations—SourceAnnotation[][]Supplies source highlight regions for an explicit document.
activeAnnotationKeyactive-annotation-keystring or undefined—Selects a highlighted region by annotation key.
activeCitationIdactive-citation-idstring or undefined—Selects the active citation.
activePageactive-pagenumber or undefined—Selects a page, starting at 1, when no active citation or annotation is set.
tabs—PdfTab[] or undefined—Groups PDF pages into named tabs using each tab's pageNumbers list.
citationPopoverPlacementcitation-popover-placementstring""Places citation details at gutter, rail, below, above, beside or edge, inheriting the context when unset.
stepLabelstep-labelstring or undefined—Selects one step by its unique pipeline label within the enclosing process.
stepRolestep-rolePipelineStepRoleWire or undefined—Constrains the selected step to this execution role.
stepIdstep-idstring or undefined—Selects a pipeline step definition within the enclosing process.
runStepIdrun-step-idstring or undefined—Selects one executable step instance within the enclosing process.
outputFormIdoutput-form-idstring or undefined—Narrows the selected step's outputs to this form.
outputSubmissionIdoutput-submission-idstring or undefined—Selects an exact output submission from the enclosing process.
workerSrc—string or nullnullSets the shared PDF.js worker URL before the first viewer mounts.

PDF events ​

EventTypeDescription
pdf-loadedCustomEvent{ numPages } after a PDF loads.
pdf-load-errorCustomEvent{ error } when PDF loading fails.
citation-clickedCustomEvent{ annotationKey, citationId, citationIds } when a highlighted source is selected.

PDF styling parts ​

PartDescription
rootThe source viewer container.
toolbarThe page, zoom and source controls.
contentThe scrollable document area.
statusLoading, empty and error messages.

Images ​

Web components ​

Pass an already configured <sea-context> element to showImage.

ts
export function showImage(provider: SeaContext, documentExtractionId: string) {
  const viewer = new SeaImageViewer();
  viewer.documentExtractionId = documentExtractionId;
  viewer.style.cssText = "display:block;height:640px";
  provider.append(viewer);
  return viewer;
}

React ​

The React wrapper is SeaImageViewer from @sea-dev/widget-lit/react and accepts the same extraction identity.

Mount the image viewer inside Context provider for a known submission. Set documentExtractionId to a document in the submission or its referenced upstream sources. Read results describes the returned document identities.

Without an explicit identity, the viewer follows the provider's selected document or opens its only loaded source. Several unselected sources show a selection prompt. An unavailable extraction shows Retry. A loaded source retries its owning submission. If an explicit or provider-selected extraction is missing in the current round, Retry reloads the current submission and its referenced sources, plus the loaded current document request. The viewer opens only an exact extraction match. An explicit or provider-selected extraction can keep showing the current document request's source while another submission is inspected. Historic rounds use their own sources.

The viewer reads file metadata and citations from Sea. Configure documentUrl or document-proxy on the provider.

Image attributes and properties ​

PropertyAttributeTypeDefaultDescription
documentExtractionIddocument-extraction-idstring""Selects an image extraction from the provider's loaded document sources.
stepLabelstep-labelstring or undefined—Selects one step by its unique pipeline label within the enclosing process.
stepRolestep-rolePipelineStepRoleWire or undefined—Constrains the selected step to this execution role.
stepIdstep-idstring or undefined—Selects a pipeline step definition within the enclosing process.
runStepIdrun-step-idstring or undefined—Selects one executable step instance within the enclosing process.
outputFormIdoutput-form-idstring or undefined—Narrows the selected step's outputs to this form.
outputSubmissionIdoutput-submission-idstring or undefined—Selects an exact output submission from the enclosing process.

Image events ​

EventTypeDescription
citation-selectedCustomEvent{ citationId, documentExtractionId } selects the bound document before its highlight is activated.
citation-clickedCustomEvent{ annotationKey, citationId, citationIds } when a highlighted source is selected.

Image styling parts ​

PartDescription
rootThe source viewer container.
toolbarThe zoom or sheet controls.
contentThe scrollable source document.
statusLoading, empty and error messages.

Spreadsheets ​

Web components ​

ts
export function showSpreadsheet(
  provider: SeaContext,
  documentExtractionId: string,
) {
  const viewer = new SeaXlsxViewer();
  viewer.documentExtractionId = documentExtractionId;
  viewer.style.cssText = "display:block;height:640px";
  provider.append(viewer);
  return viewer;
}

React ​

The React wrapper is SeaXlsxViewer from @sea-dev/widget-lit/react and accepts the same extraction identity.

Mount the spreadsheet viewer inside Context provider and select a backend extraction with documentExtractionId. It follows the same selection and Retry rules as images. Filename, MIME type, URL and citations come from the provider. Configure source URL handling on the provider.

The preview displays up to 1,000 rows and 100 columns, moving to the selected backend citation. Stored sheet IDs and cell coordinates select the matching worksheet and cells.

Spreadsheet attributes and properties ​

PropertyAttributeTypeDefaultDescription
documentExtractionIddocument-extraction-idstring""Selects a spreadsheet extraction from the provider's loaded document sources.
stepLabelstep-labelstring or undefined—Selects one step by its unique pipeline label within the enclosing process.
stepRolestep-rolePipelineStepRoleWire or undefined—Constrains the selected step to this execution role.
stepIdstep-idstring or undefined—Selects a pipeline step definition within the enclosing process.
runStepIdrun-step-idstring or undefined—Selects one executable step instance within the enclosing process.
outputFormIdoutput-form-idstring or undefined—Narrows the selected step's outputs to this form.
outputSubmissionIdoutput-submission-idstring or undefined—Selects an exact output submission from the enclosing process.

Spreadsheet events ​

EventTypeDescription

Spreadsheet styling parts ​

PartDescription
rootThe source viewer container.
toolbarThe zoom or sheet controls.
contentThe scrollable source document.
statusLoading, empty and error messages.

Document collection ​

The document list selects a source for sibling viewers.

What they need from the API ​

Read a signed URL from documents[].url in submission results, then let the browser load the file. The PDF viewer can obtain its document through Context provider. Image and spreadsheet viewers read their URL and citations from the bound extraction.

Set documentProxy to a host endpoint to fetch through your application, or supply a documentUrl function to rewrite the URL. A proxy receives ?url=<encoded-original-url> and returns document bytes. Configure these settings on Context provider for image and spreadsheet viewers. PDF viewers and Document intake also accept them directly.

Worker and highlights ​

Deploy the generated assets with the application. For a custom PDF worker URL, set SeaPdfViewer.workerSrc before mounting or workerUrl on a viewer. Use the same worker version for all PDF viewers.

Set --sea-highlight to change source highlight colour. The PDF viewer accepts annotations, activeAnnotationKey and activeCitationId as properties. Image and spreadsheet viewers read highlighting from Context provider.

This PDF highlight uses page 1 and normalised coordinates from 0 to 1:

ts
import "@sea-dev/widget-lit/pdf-viewer";
import type { SeaPdfViewer } from "@sea-dev/widget-lit/pdf-viewer";

export function highlightTotal(viewer: SeaPdfViewer) {
  viewer.annotations = [
    {
      key: "total-assets",
      boundingRegions: [
        {
          pageNumber: 1,
          polygon: [0.1, 0.2, 0.6, 0.2, 0.6, 0.25, 0.1, 0.25],
        },
      ],
      linkedCitations: [
        {
          id: "citation-1",
          sourceRef: "document-1",
          path: "TotalAssets",
          value: 1250000,
        },
      ],
    },
  ];
  viewer.activeAnnotationKey = "total-assets";
  viewer.activeCitationId = "citation-1";
}

PDF tabs accepts { id, label, pageNumbers? } entries. Page numbers start at 1; omitting them shows all pages.

PDF methodUse
scrollToPage(pageNumber)Scroll to a page numbered from 1
scrollToAnnotation(key)Scroll to the named source highlight

Common problems ​

SymptomAction
PDF fails to openCheck the document request and worker errors; see asset and CSP settings
Browser blocks a documentAllow the host origin in storage CORS or configure a document proxy
Signed URL expiredRead submission data again and assign the refreshed URL
Spreadsheet requests a fresh linkSelect Refresh document to reload the bound source owner
Highlight is missingCheck the annotation identifiers and active selection