# Templates

This directory stores reusable dynamic-ui generation materials.

Templates are not frontend components and do not belong to any particular rendering tool. They
are source examples and behavior contracts for a static HTML/SVG fragment that gets either (a)
dropped inline into a minimal-desktop chat reply as a ` ```svg ` fenced code block, or (b)
embedded into a document (docx/pptx/html report) that's already being written — see `../SKILL.md`
for Mermaid/SVG routing and `../svg-design.md`
for the host-routing rules and the two-tier root-element contract (Desktop tolerates an HTML
`<div>` fragment; document embedding needs a real `<svg>` root).

Templates are materials, not rigid constraints. The model may reference one material, mix CSS or
layout patterns from multiple materials, or generate a custom fragment when no material fits and
the scene contract allows it.

Every template folder must contain:

```text
templates/<template-id>/
  template.md
  widget-code.html
  fixture.json
```

Template folders sit directly under `templates/`. Do not add another family or category
directory. Only keep folders that contain an implemented template — no empty placeholders.

## `status` in `manifest.json`

- `ready` — `widget-code.html` is verified static markup (no `<canvas>`, no Chart.js, no
  `<script>`) and safe to use as-is.
- `needs-static-rewrite` — the folder's `widget-code.html` is still the old Chart.js/`<script>`
  hover-interaction implementation inherited from before this skill was adapted to this project;
  neither host can execute scripts, so it is **not usable today**. `template.md`'s design intent
  (data shape, use/avoid rules, visual rules) is still accurate — a future pass needs to redraw
  the chart as static SVG following that intent, the same way `line-trend`/`bar-chart-multiple`/
  `pie-donut-text` already were. Do not flip this to `ready` without actually rewriting the file.

## File Roles

`template.md`

- Explains when to use the template, and when to avoid it in favor of another template or a
  custom path.
- Defines the expected data shape (illustrative — there is no runtime data-binding layer; adapting
  a template means editing the SVG coordinates and the sample data together).
- Lists visual rules, limits, and edge cases (null values, empty data, long labels, dense data).
- Lists acceptance checks that can be verified before shipping.
- Points to related templates to use instead.

`widget-code.html`

- Contains the real static HTML/SVG/CSS fragment — **no `<script>`, no `onXxx` event attributes,
  no `<canvas>`/Chart.js**. Neither minimal-desktop's chat CSP (`script-src 'self'`) nor a static
  document can execute JavaScript, so nothing in this project's template library may depend on it.
- Starts with `<style>` (for diagram/chart templates the root is `<svg>` and the `<style>` sits
  inside it as SVG's own embedded stylesheet; for HTML card templates the `<style>` precedes the
  `.widget` markup).
- Does not include `<!DOCTYPE html>`, `<html>`, `<head>`, or `<body>`.
- Every color/font reference uses `var(--dui-<role>, <literal-fallback>)` — see
  `tokens/visual-tokens.md`. Never a bare `var(--x)` with no fallback, and never a hard-coded
  color with no variable at all.
- Every value that would have been shown on hover in the original (pre-adaptation) version of this
  skill must instead be drawn permanently on the chart/diagram.

`fixture.json`

- Provides sample data matching what `widget-code.html` actually draws.
- Should be small, realistic, and easy to replace.
- Must not contain private or production data.

## Template IDs

The folder name is the template ID used by `manifest.json`. See `manifest.json` for each one's
current `status`, `kind`, `scene`, and machine-readable `intent` — that file is the source of
truth for which templates are actually usable right now, not this list.

Use `../scenes/*.md` for scene-level routing and composition guidance. Do not encode the category
in the folder path. When adding a future template, create its folder and update the scene
reference plus the manifest in the same change.

## Cross-File Sync

When adding, renaming, removing, or changing the intent/status of a template, update the folder,
`manifest.json`, and the relevant `scenes/*.md` reference together. Do not leave a manifest entry
or scene reference without a matching implemented folder.

## Validation

After changing chart templates, fixtures, or color guidance, manually verify ordinary chart data
mappings do not use `--dui-accent` or semantic colors (`--dui-success`/`-warning`/`-danger`) as
peer-source colors — those are reserved for explicit status/risk encoding, not ordinary categories.
