# Functions

Import these from `@grafloria/engine`.

## Functions

### `debugLog`

Emit a diagnostic. No-op unless {@link setDebugLogging} turned it on.

```ts
function debugLog(...args: unknown[]): void
```

### `importDrawio`

Import a .drawio / mxGraph XML document.

Accepts plain `<mxGraphModel>` XML or a full `<mxfile>` (compressed or not). A multi-page file imports EVERY page: `diagram` is page 1 (back-compatible)
and `pages[]` — present only when the file has more than one `<diagram>` —
carries each page's own diagram, warnings, and (for a corrupt page) error. Never throws: unreadable input comes back as `{ error }`.

```ts
async function importDrawio(text: string): Promise<DrawioImportResult>
```

### `isComponentAdapter`

Type guard to check if an object implements ComponentAdapter

```ts
function isComponentAdapter(obj: any): obj is ComponentAdapter
```

**Parameters**

- `obj`: Object to check

**Returns** True if object implements ComponentAdapter interface

**Example**

```typescript
if (isComponentAdapter(obj)) {
  obj.registerComponent('test', TestComponent);
}
```

### `isDebugLogging`

Whether diagnostics are on — use this to guard an expensive call site.

```ts
function isDebugLogging(): boolean
```

### `layoutArchitecture`

Lay a diagram out as an architecture composition. Writes into the model.

```ts
function layoutArchitecture(diagram: DiagramModel, options: ArchitectureLayoutOptions = {}): ArchitectureLayoutResult
```

### `setDebugLogging`

Turn diagnostic logging on or off. Off by default, and off is the only state a
consumer ever sees unless they ask for otherwise.

```ts
function setDebugLogging(on: boolean): void
```

### `stripHtmlToText`

`value="<b>Start</b><br>here"` must become "Start here", not carry markup
into the label canon. Block/line-break boundaries turn into single spaces so
words do not fuse.

Entities are decoded a SECOND time here, after the tags are gone. The XML
reader already decoded one level — but with `html=1` (draw.io's default) the
value is an HTML FRAGMENT, so an author's literal `&` was double-encoded on
save (`&amp;amp;`) and one decode still leaves `&amp;` in the label.

```ts
function stripHtmlToText(value: string): string
```
