API / @aihu/primitives

@aihu/primitives

Runtime core

aihu headless behavior primitives — WAI-ARIA APG patterns as vanilla custom elements, zero CSS.

version
0.1.3
exports
81
values
66
types
15
01

createCollection

function
function createCollection()

The registration mechanism, usable standalone (roving-focus reuses it).

02

createDomContext

function
function createDomContext<T>(name: string, defaultValue?: T): DomContext<T>

Create a context token.

03

defineCheckbox

function
function defineCheckbox()

Register all checkbox custom elements (idempotent).

04

defineCollection

function
function defineCollection(tag = "aihu-collection")

Register `<aihu-collection>` (idempotent).

05

defineConfigProvider

function
function defineConfigProvider(tag = "aihu-config-provider")

Register `<aihu-config-provider>` (idempotent).

06

defineInput

function
function defineInput(tag = "aihu-input")

Register `<aihu-input>` (idempotent).

07

defineLabel

function
function defineLabel(tag = "aihu-label")

Register `<aihu-label>` (idempotent).

08

definePresenceGate

function
function definePresenceGate(tag = "aihu-presence-gate")

Register `<aihu-presence-gate>` (idempotent — safe to call repeatedly).

09

defineRadioGroup

function
function defineRadioGroup()

Register all radio-group custom elements (idempotent).

10

defineRovingFocus

function
function defineRovingFocus(tag = "aihu-roving-focus")

Register `<aihu-roving-focus>` (idempotent).

11

defineSeparator

function
function defineSeparator(tag = "aihu-separator")

Register `<aihu-separator>` (idempotent).

12

defineSwitch

function
function defineSwitch()

Register all switch custom elements (idempotent).

13

defineTextarea

function
function defineTextarea(tag = "aihu-textarea")

Register `<aihu-textarea>` (idempotent).

14

defineTooltip

function
function defineTooltip(prefix = "aihu")

Register all tooltip custom elements under `<prefix>-tooltip-*` (idempotent per prefix).

15

injectContext

function
function injectContext<T>(from: Element, ctx: DomContext<T>): T | Read<T>

Resolve `ctx` for `from` by walking UP the DOM from `from.parentNode`, crossing `ShadowRoot` boundaries (`ShadowRoot → .host`), nearest-wins.

16

injectValue

function
function injectValue<T>(from: Element, ctx: DomContext<T>): T

Like `injectContext`, but for the common case where a context carries a raw (non-signal) value — typically an object whose fields are themselves signals.

17

provideContext

function
function provideContext<T>(host: Element, ctx: DomContext<T>, value: T | Read<T>): void

Provide `value` for `ctx` on `host`.

18

AihuButton

const
const AihuButton
19

AihuCheckboxIndicator

const
const AihuCheckboxIndicator

Presentational styling hook: mirrors the root's state, hidden from AT.

20

AihuCheckboxRoot

const
const AihuCheckboxRoot
21

AihuCollection

const
const AihuCollection
22

AihuConfigProvider

const
const AihuConfigProvider
23

AihuDialogBackdrop

const
const AihuDialogBackdrop
24

AihuDialogClose

const
const AihuDialogClose
25

AihuDialogContent

const
const AihuDialogContent
26

AihuDialogDescription

const
const AihuDialogDescription
27

AihuDialogRoot

const
const AihuDialogRoot
28

AihuDialogTitle

const
const AihuDialogTitle
29

AihuDialogTrigger

const
const AihuDialogTrigger
30

AihuFormControl

const
const AihuFormControl
31

AihuInput

const
const AihuInput
32

AihuLabel

const
const AihuLabel
33

AihuPresenceGate

const
const AihuPresenceGate
34

AihuRadioGroupIndicator

const
const AihuRadioGroupIndicator

Presentational styling hook: mirrors its enclosing ITEM's state (nearest `radioGroupItemContext` provider), hidden from AT.

35

AihuRadioGroupItem

const
const AihuRadioGroupItem
36

AihuRadioGroupRoot

const
const AihuRadioGroupRoot
37

AihuRovingFocus

const
const AihuRovingFocus

`<aihu-roving-focus>` — WAI-ARIA roving-tabindex container.

38

AihuSeparator

const
const AihuSeparator

`<aihu-separator>` — headless separator (WAI-ARIA APG Separator, static variant).

39

AihuSwitchRoot

const
const AihuSwitchRoot
40

AihuSwitchThumb

const
const AihuSwitchThumb

Presentational styling hook: mirrors the root's state, hidden from AT.

41

AihuTextarea

const
const AihuTextarea
42

AihuTextControlBase

const
const AihuTextControlBase
43

AihuTooltipContent

const
const AihuTooltipContent
44

AihuTooltipRoot

const
const AihuTooltipRoot
45

AihuTooltipTrigger

const
const AihuTooltipTrigger
46

attachHiddenInput

const
const attachHiddenInput
47

ButtonType

const
const ButtonType
48

checkboxContext

const
const checkboxContext

Headless checkbox — `<aihu-checkbox-root>` (state owner) + presentational `<aihu-checkbox-indicator>`.

49

collectionContext

const
const collectionContext

`<aihu-collection>` — descendant-registration substrate (the Radix `Collection` pattern) implemented over the DOM-walk context.

50

configContext

const
const configContext

`<aihu-config-provider>` — app-level config propagated via reactive DOM context.

51

createFocusTrap

const
const createFocusTrap
52

defineButton

const
const defineButton
53

defineDialog

const
const defineDialog
54

defineFormControl

const
const defineFormControl
55

dialogContext

const
const dialogContext
56

DialogContextValue

const
const DialogContextValue
57

FocusTrap

const
const FocusTrap
58

formControlContext

const
const formControlContext
59

FormControlContextValue

const
const FormControlContextValue
60

HiddenInputOptions

const
const HiddenInputOptions
61

presenceContext

const
const presenceContext

Context carrying the gate's `present` signal to descendants.

62

radioGroupContext

const
const radioGroupContext

Headless radio group — `<aihu-radio-group-root>` (state owner, EXTENDS `AihuRovingFocus`) + `<aihu-radio-group-item>` (role="radio") + presentational `<aihu-radio-group-indicator>`.

63

radioGroupItemContext

const
const radioGroupItemContext
64

switchContext

const
const switchContext

Headless switch — `<aihu-switch-root>` (state owner) + presentational `<aihu-switch-thumb>`.

65

tooltipContext

const
const tooltipContext

Headless tooltip — `<aihu-tooltip-root>` + `<aihu-tooltip-trigger>` + `<aihu-tooltip-content>`.

66

MissingContextError

class
class MissingContextError extends Error

Thrown by `injectContext` when no provider is found and the token has no default.

67

CheckboxContextValue

interface
interface CheckboxContextValue {
  readonly state: Read<CheckboxState>;
  readonly disabled: Read<boolean>;
}
68

CollectionContextValue

interface
interface CollectionContextValue {
  /** Register `el`; returns a disposer that unregisters it. */
  register(el: Element): () => void;
  /** Registered descendants, kept in DOM order. */
  readonly items: Read<Element[]>;
}
69

ConfigContextValue

interface
interface ConfigContextValue {
  readonly colorScheme: Read<ColorScheme>;
  readonly density: Read<Density>;
  readonly dir: Read<Direction>;
}
70

DomContext

interface
interface DomContext<T> {
  readonly _key: symbol
  readonly _name: string
  readonly _default: T | undefined
}

Opaque token identifying a context slot.

71

RadioGroupContextValue

interface
interface RadioGroupContextValue {
  /** Currently selected item value; null when nothing is selected. */
  readonly value: Read<string | null>;
  /** Group-effective disabled (own attribute ∥ inherited form-control). */
  readonly disabled: Read<boolean>;
  readonly required: Read<boolean>;
  /** Programmatic write: signal + reflected `value` attribute. NO event. */
  setValue(next: string | null): void;
  /** USER-driven selection of `item` (click path): moves the tab stop to the
   * item WITHOUT stealing focus, selects its value, emits `value-change`. */
  selectItem(item: Element): void;
}
72

RadioGroupItemContextValue

interface
interface RadioGroupItemContextValue {
  readonly checked: Read<boolean>;
  readonly disabled: Read<boolean>;
}

Per-item context so `<aihu-radio-group-indicator>` mirrors its OWN item (nearest-provider-wins walk lands on the enclosing item, not the root).

73

SwitchContextValue

interface
interface SwitchContextValue {
  readonly checked: Read<boolean>;
  readonly disabled: Read<boolean>;
}
74

TooltipContextValue

interface
interface TooltipContextValue {
  readonly open: Read<boolean>;
  readonly contentId: Read<string>;
  readonly placement: Read<Placement>;
  readonly openDelay: Read<number>;
  readonly closeDelay: Read<number>;
  setOpen(next: boolean): void;
  /** Schedule open/close honoring the configured delays. */
  scheduleOpen(): void;
  scheduleClose(): void;
  /** Immediate dismiss (Escape). */
  dismiss(): void;
  registerTrigger(el: Element): void;
  triggerEl(): Element | null;
}
75

TooltipCoords

interface
interface TooltipCoords {
  x: number;
  y: number;
  placement: Placement;
}
76

CheckboxState

type
type CheckboxState = 'checked' | 'unchecked' | 'indeterminate';
77

ColorScheme

type
type ColorScheme = 'light' | 'dark' | 'system';
78

Density

type
type Density = 'comfortable' | 'compact';
79

Direction

type
type Direction = 'ltr' | 'rtl';
80

Orientation

type
type Orientation = 'horizontal' | 'vertical' | 'both';
81

SeparatorOrientation

type
type SeparatorOrientation = 'horizontal' | 'vertical';