Overview

stylesheet() creates a feature-scoped sheet. Call it at module level, define class maps with css({ … }), then mount() so the sheet enters the document via adopted stylesheets.

mount() inside a component outer function ties ref-counted mount/unmount to that host. At module level it injects immediately (scripts / benches).

globalCSS shares one document sheet with microtask mount — good for tiny utilities. Theme tokens live on theme / rootCSS.

stylesheet vs globalCSS

API
Lifetime
Prefer when
stylesheet() Ref-counted mount Feature / page co-located styles
globalCSS() Document singleton Tiny shared utilities (sr-only, …)

mount() in outer function

Sheet lifetime follows the host component.

import { html, renderApp, stylesheet } from 'mates';

const { css, mount } = stylesheet();

const cl = css({
box: {
padding: '12px 16px',
borderRadius: 'var(--m-r)',
background: 'var(--m-surface)',
color: 'var(--m-fg)',
border: '1px solid var(--m-border)',
},
accent: { color: 'var(--m-primary)', margin: '0 0 6px' },
});

const App = () => {
mount(); // ties sheet lifetime to this component
return () => html`
<div class="${cl.box}">
<p class="${cl.accent}">mount() in outer fn</p>
<p class="muted m-b-10">Sheet unmounts when this host cleans up.</p>
</div>
`;
};
renderApp(App, document.getElementById('app'));

Instance keyframes()

Scoped @keyframes name used in a css() animation property.

import { html, atom, renderApp, stylesheet } from 'mates';

const { css, mount, keyframes } = stylesheet();
mount();

const pulse = keyframes('pulse', {
'0%': { transform: 'scale(1)' },
'50%': { transform: 'scale(1.04)' },
'100%': { transform: 'scale(1)' },
});

const cl = css({
btn: {
padding: '8px 14px',
borderRadius: 'var(--m-r)',
border: '1px solid var(--m-border)',
background: 'var(--m-surface)',
color: 'var(--m-fg)',
cursor: 'pointer',
},
run: { animation: `${pulse} 0.6s ease` },
});

const App = () => {
const on = atom(false);
return () => html`
<div class="m-col m-gap">
<button
class="${cl.btn} ${on() ? cl.run : ''}"
@click=${() => { on.set(true); setTimeout(() => on.set(false), 600); }}
>Pulse</button>
</div>
`;
};
renderApp(App, document.getElementById('app'));