> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# @reductoai/docx/browser

Layout, PDF and fonts in a page or a worker. See [Office.js in the browser](https://docs.reducto.ai/office/docx/js-api/browser.md). With a bundler other than Vite, webpack or Next.js, give the engine's URL: see [The layout engine](https://docs.reducto.ai/office/docx/js-api/browser.md#the-layout-engine).

## `layoutDocxInBrowser()`

```ts theme={null}
function layoutDocxInBrowser(
  bytes: ParseInput,
  opts: BrowserLayoutOptions,
): Promise<LayoutDocument>
```

Parse + lay out docx bytes in the browser, in the layout engine (`engine.wasm`), which fetches
the faces it lacks from `opts.fonts` as it lays out.

Import from `@reductoai/docx/browser`.

## `BrowserLayoutOptions`

Import from `@reductoai/docx/browser`.

| Name | Type | Description |
| - | - | - |
| `comments?` | `"hidden" \| "balloons"` | |
| `engine?` | `LayoutEngineSource` | The engine to lay out with: a URL of `@reductoai/docx/engine.wasm`, its bytes or module. Unset, `setLayoutEngine`'s or the package's. |
| `fonts` | `FaceProvider` | |
| `hiddenReviewers?` | `readonly string[]` | Authors whose revisions lay as accepted (Word's Reviewers filter). |
| `incremental?` | `IncrementalLayout` | Per-session layout memory; resumes and splices around the edited blocks. |
| `inks?` | `InkChoice` | Reviewer colours instead of Word's by-author order. |
| `markupGutter?` | `boolean` | `false`: the balloons view without the print gutter; an editor draws its own margin. |
| `maxPages?` | `number` | Keep only the first `maxPages` pages; layout stops after them unless a field shows the page count. |
| `name?` | `string` | |
| `onProgress?` | `LayoutProgress` | |
| `outline?` | `OutlineView` | Word's Outline view; see `OutlineView`. |
| `pageColor?` | `"print" \| "screen"` | Design > Page Color (w:background): painted by default (`screen`, as Word on screen and in PDF); `print` leaves it out. |
| `pageSink?` | `BrowserPageSink` | Receives pages as layout releases them; see `LayoutOptions.pageSink`. The result then carries `pages: []` and a `faceManifest` of the vector faces only. The first layout doubles as the font trace, so a fetch discards what it streamed and the reflow streams again. A layout that cannot stream (`incremental`, review balloons) never calls the sink; check `ir.pages.length`. |
| `trackedChanges?` | `"final" \| "inline" \| "balloons" \| "simple"` | |

## `BrowserPageSink`

A `PageSink` whose `begin` carries what a page consumer needs first.

Import from `@reductoai/docx/browser`.

| Name | Type | Description |
| - | - | - |
| `begin()` | `(header: LayoutHeader) => void` | |
| `discard()` | `() => void` | |
| `page()` | `(page: LayoutPage) => void` | |

## `browserLayoutHost()`

```ts theme={null}
function browserLayoutHost(
  options: BrowserHostOptions,
): SessionLayoutHost<DocxSession> & { release: any }
```

The browser LayoutHost: one cached SessionLayout per session, keyed on
`editVersion()`. Installs itself as the OfficeJS default, so a plain
`WordDocument.fromBytes` after this call can `readPage`. `release` frees a session's
engine copy.

Import from `@reductoai/docx/browser`.

## `BrowserHostOptions`

Per-host layout settings; `incremental` comes from the session and is not accepted.

Import from `@reductoai/docx/browser`.

```ts theme={null}
type BrowserHostOptions = Omit<BrowserLayoutOptions, "incremental"> & { engine?: LayoutEngineSource }
```

## `renderPdfInBrowser()`

```ts theme={null}
function renderPdfInBrowser(
  ir: LayoutDocument,
  fonts: Pick<FaceProvider, "fetch">,
  options?: RenderPdfOptions,
): Promise<RenderPdfResult>
```

PDF bytes for a laid IR. Layout fetched every face the runs use, with one
exception: the renderer embeds DEFAULT\_FAMILY as its fallback, and a document
whose every run resolves never traced it, so it is pulled here first.

Import from `@reductoai/docx/browser`.

## `createBrowserEditorHost()`

```ts theme={null}
function createBrowserEditorHost(
  bytes: Uint8Array,
  options: BrowserHostOptions,
): Promise<SessionEditorHost>
```

An editor host over fresh bytes; OfficeJS shares its pages through `host.pages`.

Import from `@reductoai/docx/browser`.

## `portableFaceProvider()`

```ts theme={null}
function portableFaceProvider(urlFor: (file: string) => string): TableFaceProvider
```

The portable profile served as static files from `urlFor(file)`. Lazy: the
first document pulls the faces it uses (a Calibri letter costs Carlito's four
files, about 1 MB), not the 16 MB profile.

Import from `@reductoai/docx/browser`.

## `tableFaceProvider()`

```ts theme={null}
function tableFaceProvider(
  source: FaceTable | (() => Promise<FaceTable>),
  urlFor: (file: string) => string,
): TableFaceProvider
```

Lazy, content-addressed faces served as plain files. `install` costs the
table alone; each face downloads once, the first time a document needs it,
and stays for the session. A face that fails to download is left absent, so
layout falls back exactly as it would on a machine missing that font.

Import from `@reductoai/docx/browser`.

## `FaceProvider`

How face bytes reach the browser. `FaceSource.bytes()` is synchronous, so a
layout cannot fetch mid-run; `layoutDocxInBrowser` lays out once to trace
the faces it needs, calls `fetch` with those ids, and lays out again when
bytes arrived. `bytes` serves canvas `FontFace` loading and PDF embedding.

Import from `@reductoai/docx/browser`.

| Name | Type | Description |
| - | - | - |
| `bytes()` | `(id: string) => Uint8Array<ArrayBufferLike> \| null` | Face bytes held here, or an embedded face the registry extracted. |
| `fetch()` | `(ids: string[], onProgress?: FetchProgress) => Promise<number>` | Pull the faces named by `ids` that are not held yet; returns the bytes pulled. |
| `heldIds()` | `() => string[]` | Ids whose bytes this thread holds; a worker skips these when it ships faces over. |
| `install()` | `() => Promise<void>` | Register every family on `defaultFontRegistry`; face bytes may still be absent. Memoized. |
| `seed()` | `(faces: Iterable<[string, Uint8Array<ArrayBufferLike>]>) => void` | Adopt face bytes another thread fetched, so `bytes` can serve them here. |

## `TableFaceProvider`

A FaceProvider over a FaceTable, plus the by-family verbs a host needs around it.

Import from `@reductoai/docx/browser`.

| Name | Type | Description |
| - | - | - |
| `bytes()` | `(id: string) => Uint8Array<ArrayBufferLike> \| null` | Face bytes held here, or an embedded face the registry extracted. |
| `familyFaceIds()` | `(family: string) => Promise<string[]>` | Ids of one family's faces, for a targeted prefetch. |
| `familyFaces()` | `(families: Iterable<string>) => Promise<[string, Uint8Array<ArrayBufferLike>][]>` | The faces of `families`, fetched when missing. For consumers that resolve fonts by name outside the layout trace: the metafile rasterizer, the PDF writer's fallback family. |
| `fetch()` | `(ids: string[], onProgress?: FetchProgress) => Promise<number>` | Pull the faces named by `ids` that are not held yet; returns the bytes pulled. |
| `heldIds()` | `() => string[]` | Ids whose bytes this thread holds; a worker skips these when it ships faces over. |
| `install()` | `() => Promise<void>` | Register every family on `defaultFontRegistry`; face bytes may still be absent. Memoized. |
| `seed()` | `(faces: Iterable<[string, Uint8Array<ArrayBufferLike>]>) => void` | Adopt face bytes another thread fetched, so `bytes` can serve them here. |
| `table()` | `() => Promise<FaceTable>` | The table, after `install`. |
