# Types

Import these from `@grafloria/renderer`.

## Types

### `Artifact`

Anything a user might drop on the canvas: an SVG string, a data: URL, or raw bytes.

```ts
type Artifact = string | Uint8Array;
```

**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `length` | `number` |  | Returns the length of a String object. |

**Members**

- `toString(): string` — Returns a string representation of a string.
- `indexOf(searchString: string, position?: number): number` — Returns the position of the first occurrence of a substring.
- `lastIndexOf(searchString: string, position?: number): number` — Returns the last occurrence of a substring in the string.
- `slice(start?: number, end?: number): string` — Returns a section of a string.
- `valueOf(): string` — Returns the primitive value of the specified object.
- `includes(searchString: string, position?: number): boolean` — Returns true if searchString appears as a substring of the result of converting this
object to a String, at one or more positions that are
greater than or equal to position; otherwise, returns false.
- `[Symbol.iterator](): StringIterator<string>` — Iterator
- `toLocaleString(): string` — Returns a date converted to a string using the current locale.

### `AssetFetcher`

Fetch bytes for a URL. Injectable — so tests never touch the network.

```ts
type AssetFetcher = (url: string) => Promise<{ data: Uint8Array; mimeType: string }>;
```

### `BaseFont`

Also has every member of `String`, listed on its own entry.

```ts
type BaseFont =
  | 'Helvetica'
  | 'Helvetica-Bold'
  | 'Helvetica-Oblique'
  | 'Helvetica-BoldOblique'
  | 'Times-Roman'
  | 'Times-Bold'
  | 'Times-Italic'
  | 'Times-BoldItalic'
  | 'Courier'
  | 'Courier-Bold';
```

### `BatchDocument`

A document to export: the engine's envelope, or the flat serialized form.

```ts
type BatchDocument = SerializedDiagramData | DiagramDocumentEnvelope;
```

### `ClassStyleResolver`

Resolves an element's class list to the concrete presentation attributes the
renderer's stylesheet would have painted, for THIS theme.

```ts
type ClassStyleResolver = (classList: string[]) => Record<string, string>;
```

### `CustomNodeFidelity`

Also has every member of `String`, listed on its own entry.

How faithfully a host's content could be captured.

- `vector` the host's paint was transcribed to SVG primitives. Exact, and it
  survives every target including PDF.
- `html`   the host holds markup we could not transcribe. The SVG target can carry
  it in a `<foreignObject>` (browsers render it); PDF and most standalone
  rasterizers cannot. Always warned about.
- `empty`  nothing capturable. A marked box plus a warning — never a silent blank.

```ts
type CustomNodeFidelity = 'vector' | 'html' | 'empty';
```

### `ExportScope`

Also has every member of `String`, listed on its own entry.

WHAT rectangle of the world an export covers.

'content'   the whole diagram, tight around everything drawn (the default —
              a thumbnail of "whatever the user happened to be scrolled to" is
              almost never what anyone means)
  'viewport'  exactly what is on screen right now
  'selection' tight around the selected nodes/links alone

```ts
type ExportScope = 'content' | 'viewport' | 'selection';
```

### `FontFormat`

Also has every member of `String`, listed on its own entry.

```ts
type FontFormat = 'woff2' | 'woff' | 'truetype' | 'opentype';
```

### `ForeignObjectMode`

Also has every member of `String`, listed on its own entry.

What the serializer does with a `<foreignObject>` (HTML-in-SVG) subtree.

```ts
type ForeignObjectMode = 'serialize' | 'placeholder' | 'omit';
```

### `HtmlFallbackMode`

Also has every member of `String`, listed on its own entry.

What to do with a capture we could only get as HTML.

```ts
type HtmlFallbackMode = 'foreignObject' | 'placeholder' | 'omit';
```

### `Orientation`

Also has every member of `String`, listed on its own entry.

```ts
type Orientation = 'portrait' | 'landscape';
```

### `PageSize`

Also has every member of `String`, listed on its own entry.

```ts
type PageSize = keyof typeof PAGE_SIZES;
```

### `SerializeFidelity`

Also has every member of `String`, listed on its own entry.

WHO is going to read this string — the only axis on which the two callers differ.

'file' (default)  A standalone `.svg` a rasterizer / Inkscape / an email client
                    will read. It has no stylesheet, so the cascade is FLATTENED
                    into presentation attributes; live-pipeline attributes minted
                    from process-global counters are DROPPED (they mean nothing in
                    a file and would destroy determinism); CSS `filter: blur()` is
                    translated into a real `<filter>` def.

'dom'             An SSR snapshot the client's VNodePatcher will ADOPT. Here the
                    string must describe exactly the DOM the patcher would have
                    built from the same tree — otherwise hydration sees a different
                    attribute set, tears the node down and rebuilds it, and the
                    diagram flashes. So: `style` is kept verbatim, nothing is
                    dropped, no cascade flattening, and the patcher's `data-vnode-key`
                    mirror is reproduced.

ONE traversal serves both. Keeping two would have meant two copies of the
prop→attribute rules, and the moment one learned a new verbatim attribute and the
other did not, exported files and hydrated pages would quietly disagree about what
the diagram looks like.

```ts
type SerializeFidelity = 'file' | 'dom';
```

### `SharpModule`

The slice of `sharp` we use.

```ts
type SharpModule = (input: Uint8Array, options?: { density?: number }) => {
  resize(width: number, height: number): ReturnType<SharpModule>;
  png(): ReturnType<SharpModule>;
  jpeg(options?: { quality?: number }): ReturnType<SharpModule>;
  webp(options?: { quality?: number }): ReturnType<SharpModule>;
  flatten(options?: { background?: string }): ReturnType<SharpModule>;
  toBuffer(): Promise<Uint8Array>;
};
```
