API / @aihu/css-engine

@aihu/css-engine

Runtime core

aihu CSS engine — Tailwind v4 hard fork with WC-native scoped output.

version
0.4.6
exports
18
values
12
types
6
01

anchorFallback

function
function anchorFallback( anchor: Element, floating: HTMLElement, opts: PositionOptions = {}, ): () => void

Fallback for the `anchor:` feature: position `floating` against `anchor` with JS when native CSS anchor positioning is unsupported.

02

cn

function
function cn(...inputs: ClassValue[]): string

Merge class values, resolving last-wins conflicts per property group.

03

compile

function
function compile(classes: string[]): string
04

compileSfc

function
function compileSfc(source: string, id?: string): string

Compile a `.aihu` SFC source string to scoped, shadow-DOM-embedded CSS.

05

defineStylePack

function
function defineStylePack(input: StylePackInput): StylePack

Define a style pack from a token map.

06

isUsableExecutable

function
function isUsableExecutable(candidate: string): boolean

Whether `candidate` is a usable `aihu-css-compile` executable — NOT merely a present file.

07

popoverFallback

function
function popoverFallback( anchor: Element, panel: HTMLElement, opts: PositionOptions = {}, ): () => void

Fallback for the `popover:` feature: emulate the Popover API's top layer by portaling `panel` out of the normal flow and positioning it against `anchor` with the SHARED positioning shim (`position`, also used by `anchorFallback`).

08

portal

function
function portal(el: HTMLElement): () => void

Portal `el` to a top-layer-emulating container appended to `<body>` with a high z-index.

09

position

function
function position( anchor: Element, floating: HTMLElement, opts: PositionOptions = {}, ): Placement

Position `floating` against `anchor` and apply `position: fixed; left/top`.

10

aihuDefault

const
const aihuDefault: StylePack

`aihu-default` — the aihu brand palette (warm paper + ink, accent `#c8543a`), derived from `aihu-logo.html` / `aihu-wordmark.svg`.

11

aihuGraphite

const
const aihuGraphite: StylePack

`aihu-graphite` — a neutral monochrome ramp expressed in `oklch()` (chroma ≈ 0).

12

builtinPacks

const
const builtinPacks: Record<string, StylePack>

All built-in packs, keyed by name — handy for registry/iteration.

13

PositionOptions

interface
interface PositionOptions {
  /** Preferred side. Default `'bottom'`. */
  placement?: Placement
  /** Gap between anchor and floating element, in px. Default `4`. */
  offset?: number
  /** Flip to the opposite side if it would overflow the viewport. Default `true`. */
  flip?: boolean
}
14

StylePack

interface
interface StylePack {
  readonly name: string
  readonly tokens: TokenMap
  readonly dark: TokenMap
  /**
   * Serialize the pack to a `:root { … }` (+ `.dark { … }`) CSS string — the
   * same shape as the shipped `styles/*.css` bundles.
   */
  toCss(): string
}

A registered, validated style-pack descriptor.

15

StylePackInput

interface
interface StylePackInput {
  /** Pack name, e.g. `'acme'` (used for registration / debugging). */
  name: string
  /** Light-theme tokens (the `:root` block). Names without the `--` prefix. */
  tokens: TokenMap
  /** Optional dark-theme overrides (the `.dark` block). */
  dark?: TokenMap
}
16

ClassValue

type
type ClassValue = string | number | null | undefined | false | ClassValue[]

A class value: string, falsy (dropped), or a nested array of the same.

17

Placement

type
type Placement = 'top' | 'bottom' | 'left' | 'right'

Where to place the floating element relative to its anchor.

18

TokenMap

type
type TokenMap = Record<string, string>

A design-token map: `name` → CSS value.