# Debug

`<ui-debug>`: a development-time audit of every style utility and attribute on the page.

Source: https://www.zazz.sh/api/primitives/debug/

## Installation

```bash
pnpm dlx zazz-ui add debug
```

Run `zazz-ui init` first if the project has no `zazz/` folder yet.

## Example

Add it once, at the end of `<body>`, in the pages you develop on. It audits the whole page and logs its findings to the console. On a hostname it doesn't list, it removes itself and logs one warning saying so (`data-debug-warnings="false"` silences that), so the tag can stay in a shared template.

```html
<ui-debug data-debug-domains="localhost, staging.example.com"></ui-debug>
```

When you upgrade, the audit also reports `data-ui` tokens the kit has retired and names each replacement. A leftover `data-ui="sr-only"` matches no rule, so without it the hidden text just appears on the page.

## Behavior

`primitives/debug/audit-core.js`

The DOM-free audit behind `<ui-debug>` and the html lint rules.
Works on `AuditNode`, a five-method view of an element, so
the browser (a live `Element`) and the linter (an html-eslint `Tag`) run the
same checks and raise the same messages. Each finding names its rule and,
where it can, the span of the declaration it is about (offsets into the
`style` attribute) and a suggested rewrite.

`primitives/debug/debug.js`

`<ui-debug>`: audits utilities in `style` attributes.
Development only. On a listed domain the element walks every
element once, and again on mutation, and warns about the mistakes the
generated gates cannot report: an unknown utility, a wrong mode, a tier without
a base, a modifier the family lacks, a base utility that flattens a state a
primitive's hook covers, a raw property shadowing a utility, a
whitespace form the gates cannot match, and a `data-<name>-*` attribute
outside its identity. On an unlisted domain it removes itself and logs
`DEBUG_WARNING` once. Identities and hooks are read from the page's
stylesheets, so the audit needs no manifest. The checks live in
`audit-core.ts`, which the html lint rules (`@zazz-ui/eslint-plugin`) share.

## Attributes

| Attribute | Kind | Values |
| --- | --- | --- |
| `data-debug-domains` | config | free value |
| `data-debug-warnings` | config | `false` |
