# theme-tokens.ts

**[Source](https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/theme-tokens.ts)**

> 6 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

<div class="ox-api-stats" aria-label="API reference summary">
<span class="ox-api-stat">
  <strong>6</strong>
  <span>symbols</span>
</span>
<span class="ox-api-stat">
  <strong>3</strong>
  <span>functions</span>
</span>
<span class="ox-api-stat">
  <strong>2</strong>
  <span>interfaces</span>
</span>
<span class="ox-api-stat">
  <strong>1</strong>
  <span>types</span>
</span>
<span class="ox-api-stat">
  <strong>5</strong>
  <span>parameters</span>
</span>
<span class="ox-api-stat">
  <strong>4</strong>
  <span>members</span>
</span>
<span class="ox-api-stat">
  <strong>3</strong>
  <span>returns</span>
</span>
</div>

## Reference

<div class="ox-api-controls" data-ox-api-target=".ox-api-entry" role="toolbar" aria-label="Reference display controls">
<button type="button" class="ox-api-controls__button" data-ox-api-toggle="expand">Open all</button>
<button type="button" class="ox-api-controls__button" data-ox-api-toggle="collapse">Close all</button>
</div>

<details id="expandextendschain" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">expandExtendsChain(theme: ThemeTokenSource): ThemeTokenSource[]</code><span class="ox-api-entry__description">Flattens one layer&#39;s extends chain into base-first order, mirroring the SSG&#39;s o…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">1 param</span><span class="ox-api-badge">returns ThemeTokenSource[]</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Flattens one layer&#39;s <code>extends</code> chain into base-first order, mirroring the SSG&#39;s own resolution. The <code>seen</code> guard keeps a theme that extends itself (or forms a cycle across two packages) from hanging the caller.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">function expandExtendsChain(theme: ThemeTokenSource): ThemeTokenSource[]</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/theme-tokens.ts#L148-L160" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">theme</code>
    <code class="ox-api-entry__param-type"><a href="#themetokensource">ThemeTokenSource</a></code>
  </div>
</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type"><a href="#themetokensource">ThemeTokenSource</a>[]</code>
</div>
</div>
  </div>
</details>

<details id="renderthemetokencss" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">renderThemeTokenCss(theme: ThemeTokenSource | ThemeTokenSource[], options: RenderThemeTokenCssOptions = {}): string</code><span class="ox-api-entry__description">Renders a theme&#39;s --octc-* tokens as a standalone stylesheet. The built-in SSG…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">2 params</span><span class="ox-api-badge">returns string</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Renders a theme&#39;s <code>--octc-*</code> tokens as a standalone stylesheet.</p>
<p>The built-in SSG emits these declarations itself, but <code>ssg.bare: true</code> and custom hosts render their own document — this is how they get the same tokens. The built-in highlighter emits <code>var(--octc-syntax-*)</code> references, so a bare host that wants only the highlighter palette can ask for it:</p>
<pre><code class="language-ts">import { renderThemeTokenCss } from &quot;@ox-content/vite-plugin/theme-tokens&quot;;
import { kanagawa } from &quot;@ox-content/theme-color-kanagawa&quot;;&#10;
const css = renderThemeTokenCss(kanagawa, {
  include: (name) =&gt; name.startsWith(&quot;syntax-&quot;),
});</code></pre>
<p>Layers compose left to right and each layer&#39;s <code>extends</code> chain is flattened base-first, matching how <code>resolveTheme()</code> stacks a skin and a color scheme.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">export function renderThemeTokenCss(theme: ThemeTokenSource | ThemeTokenSource[], options: RenderThemeTokenCssOptions = {}): string</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/theme-tokens.ts#L68-L77" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">theme</code>
    <code class="ox-api-entry__param-type"><a href="#themetokensource">ThemeTokenSource</a> | <a href="#themetokensource">ThemeTokenSource</a>[]</code>
  </div>
</li>
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">options</code>
    <code class="ox-api-entry__param-type"><a href="#renderthemetokencssoptions">RenderThemeTokenCssOptions</a></code>
  </div>
  <p class="ox-api-entry__param-description">optional · default: {}</p>
</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type">string</code>
</div>
</div>
  </div>
</details>

<details id="renderthemetokencssoptions" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">interface</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">RenderThemeTokenCssOptions</code><span class="ox-api-entry__description">Options for renderThemeTokenCss.</span><span class="ox-api-entry__meta"><span class="ox-api-badge">1 member</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Options for <a href="#renderthemetokencss">renderThemeTokenCss</a>.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">export interface RenderThemeTokenCssOptions</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/theme-tokens.ts#L35-L46" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--members">
<h4>Members</h4>
<div class="ox-api-entry__member-group">
<h5>Properties</h5>
<table class="ox-api-entry__members-table">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr id="renderthemetokencssoptions-include">
  <td><code>include</code><span class="ox-api-badge">optional</span></td>
  <td><code class="ox-api-entry__member-type language-typescript">(name: string) =&gt; boolean</code></td>
  <td><div class="ox-api-entry__member-description">Keeps only the tokens whose name passes the predicate. Names arrive without<br>the <code>--octc-</code> prefix, so <code>(name) =&gt; name.startsWith(&quot;syntax-&quot;)</code> reuses a<br>color scheme&#39;s highlighter palette without adopting its page colors,<br>typography, or layout policy.<br><br>Filtering runs per layer, before merging, so a token a later layer would<br>have overridden is dropped along with the override.</div><ul class="ox-api-entry__member-params"><li><code>name</code></li></ul></td>
</tr>
</tbody>
</table>
</div>
</div>
  </div>
</details>

<details id="themetokens" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">type</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">ThemeTokens = Record&lt;string, string&gt;</code><span class="ox-api-entry__description">Free-form --octc-* custom properties for themes that need more than the typed c…</span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Free-form <code>--octc-*</code> custom properties for themes that need more than the typed <code>colors</code> / <code>fonts</code> / <code>layout</code> fields.</p>
<p>Keys are written <strong>without</strong> the <code>--octc-</code> prefix, so <code>&quot;surface-glass&quot;</code> becomes <code>--octc-surface-glass</code>. This is the seam that keeps the two theme axes independent: a color package can restyle code-block line markers, brand accents, and surface textures purely through tokens, while a skin package lays out geometry against those same tokens without knowing any color.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">export type ThemeTokens = Record&lt;string, string&gt;</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/theme-tokens.ts#L11" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
  </div>
</details>

<details id="themetokensource" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">interface</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">ThemeTokenSource</code><span class="ox-api-entry__description">The token-bearing shape of a theme. Declared structurally instead of importing…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">3 members</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>The token-bearing shape of a theme.</p>
<p>Declared structurally instead of importing <code>ThemeConfig</code> so this module keeps an empty import graph: <code>@ox-content/vite-plugin/theme-tokens</code> has to be loadable by a bare (<code>ssg.bare: true</code>) or custom host that never pulls in the Vite plugin, the SSG, the native binding, or a filesystem API. Every <code>ThemeConfig</code> — including the published <code>@ox-content/theme-color-*</code> and <code>@ox-content/theme-*</code> packages — satisfies it.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">export interface ThemeTokenSource</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/theme-tokens.ts#L26-L30" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--members">
<h4>Members</h4>
<div class="ox-api-entry__member-group">
<h5>Properties</h5>
<table class="ox-api-entry__members-table">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr id="themetokensource-darktokens">
  <td><code>darkTokens</code><span class="ox-api-badge">optional</span></td>
  <td><code class="ox-api-entry__member-type language-typescript"><a href="#themetokens">ThemeTokens</a></code></td>
  <td></td>
</tr>
<tr id="themetokensource-extends">
  <td><code>extends</code><span class="ox-api-badge">optional</span></td>
  <td><code class="ox-api-entry__member-type language-typescript"><a href="#themetokensource">ThemeTokenSource</a></code></td>
  <td></td>
</tr>
<tr id="themetokensource-tokens">
  <td><code>tokens</code><span class="ox-api-badge">optional</span></td>
  <td><code class="ox-api-entry__member-type language-typescript"><a href="#themetokens">ThemeTokens</a></code></td>
  <td></td>
</tr>
</tbody>
</table>
</div>
</div>
  </div>
</details>

<details id="tokenstocss" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">tokensToCss(light: ThemeTokens, dark: ThemeTokens): string</code><span class="ox-api-entry__description">Renders light and dark token records as the three selectors the SSG runtime swi…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">2 params</span><span class="ox-api-badge">returns string</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Renders light and dark token records as the three selectors the SSG runtime switches between: an explicit <code>[data-theme=&quot;dark&quot;]</code> opt-in, the OS <code>prefers-color-scheme</code> fallback, and the <code>:root</code> base.</p>
<p>Emitted after the typed color variables and before the theme&#39;s own <code>css</code>, so a token can override a typed color and raw <code>css</code> can override a token.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">export function tokensToCss(light: ThemeTokens, dark: ThemeTokens): string</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/theme-tokens.ts#L87-L103" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">light</code>
    <code class="ox-api-entry__param-type"><a href="#themetokens">ThemeTokens</a></code>
  </div>
</li>
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">dark</code>
    <code class="ox-api-entry__param-type"><a href="#themetokens">ThemeTokens</a></code>
  </div>
</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type">string</code>
</div>
</div>
  </div>
</details>
