API / @aihu/primitives

@aihu/primitives

Runtime core

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

version
0.2.3
exports
94
values
70
types
24
01

attachHiddenInput

function
function attachHiddenInput(host: HTMLElement, opts: HiddenInputOptions): () => void

Attach a visually-hidden native input to `host`, kept in sync with the provided signals by a single effect.

02

createCollection

function
function createCollection(): CollectionContextValue

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

03

createDomContext

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

Create a context token.

04

createFocusTrap

function
function createFocusTrap(container: Element, options: FocusTrapOptions = {}): FocusTrap
05

defineButton

function
function defineButton(tag: string): typeof AihuButton

Register a concrete button tag backed by `AihuButton` (idempotent).

06

defineCheckbox

function
function defineCheckbox(): void

Register all checkbox custom elements (idempotent; a no-op without a DOM).

07

defineCollection

function
function defineCollection(tag = 'aihu-collection'): void

Register `<aihu-collection>` (idempotent; a no-op without a DOM).

08

defineConfigProvider

function
function defineConfigProvider(tag = 'aihu-config-provider'): void

Register `<aihu-config-provider>` (idempotent; a no-op without a DOM).

09

defineDialog

function
function defineDialog(prefix = 'aihu'): void

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

10

defineFormControl

function
function defineFormControl(tag = 'aihu-form-control'): void

Register `<aihu-form-control>` (idempotent; a no-op without a DOM).

11

defineInput

function
function defineInput(tag = 'aihu-input'): void

Register `<aihu-input>` (idempotent; a no-op without a DOM).

12

defineLabel

function
function defineLabel(tag = 'aihu-label'): void

Register `<aihu-label>` (idempotent; a no-op without a DOM).

13

definePopover

function
function definePopover(prefix = 'aihu'): void

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

14

definePresenceGate

function
function definePresenceGate(tag = 'aihu-presence-gate'): void

Register `<aihu-presence-gate>` (idempotent — safe to call repeatedly; a no-op without a DOM).

15

defineRadioGroup

function
function defineRadioGroup(): void

Register all radio-group custom elements (idempotent; a no-op without a DOM).

16

defineRovingFocus

function
function defineRovingFocus(tag = 'aihu-roving-focus'): void

Register `<aihu-roving-focus>` (idempotent; a no-op without a DOM).

17

defineSeparator

function
function defineSeparator(tag = 'aihu-separator'): void

Register `<aihu-separator>` (idempotent; a no-op without a DOM).

18

defineSlider

function
function defineSlider(): void

Register all slider custom elements (idempotent; a no-op without a DOM).

19

defineSwitch

function
function defineSwitch(): void

Register all switch custom elements (idempotent; a no-op without a DOM).

20

defineTextarea

function
function defineTextarea(tag = 'aihu-textarea'): void

Register `<aihu-textarea>` (idempotent; a no-op without a DOM).

21

defineTooltip

function
function defineTooltip(prefix = 'aihu'): void

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

22

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.

23

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.

24

provideContext

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

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

25

checkboxContext

const
const checkboxContext
26

collectionContext

const
const collectionContext
27

configContext

const
const configContext
28

dialogContext

const
const dialogContext
29

formControlContext

const
const formControlContext
30

HTMLElementBase

const
const HTMLElementBase: typeof HTMLElement

`HTMLElement` in a DOM; an inert, throw-on-construct placeholder elsewhere.

31

popoverContext

const
const popoverContext
32

presenceContext

const
const presenceContext

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

33

radioGroupContext

const
const radioGroupContext
34

radioGroupItemContext

const
const radioGroupItemContext
35

sliderContext

const
const sliderContext
36

switchContext

const
const switchContext
37

tooltipContext

const
const tooltipContext
38

AihuButton

class
class AihuButton extends HTMLElementBase
39

AihuCheckboxIndicator

class
class AihuCheckboxIndicator extends HTMLElementBase

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

40

AihuCheckboxRoot

class
class AihuCheckboxRoot extends HTMLElementBase
41

AihuCollection

class
class AihuCollection extends HTMLElementBase
42

AihuConfigProvider

class
class AihuConfigProvider extends HTMLElementBase
43

AihuDialogBackdrop

class
class AihuDialogBackdrop extends DialogPiece
44

AihuDialogClose

class
class AihuDialogClose extends DialogPiece
45

AihuDialogContent

class
class AihuDialogContent extends DialogPiece
46

AihuDialogDescription

class
class AihuDialogDescription extends DialogPiece
47

AihuDialogRoot

class
class AihuDialogRoot extends HTMLElementBase
48

AihuDialogTitle

class
class AihuDialogTitle extends DialogPiece
49

AihuDialogTrigger

class
class AihuDialogTrigger extends DialogPiece
50

AihuFormControl

class
class AihuFormControl extends HTMLElementBase
51

AihuInput

class
class AihuInput extends AihuTextControlBase
52

AihuLabel

class
class AihuLabel extends HTMLElementBase
53

AihuPopoverContent

class
class AihuPopoverContent extends PopoverPiece
54

AihuPopoverRoot

class
class AihuPopoverRoot extends HTMLElementBase
55

AihuPopoverTrigger

class
class AihuPopoverTrigger extends PopoverPiece
56

AihuPresenceGate

class
class AihuPresenceGate extends HTMLElementBase
57

AihuRadioGroupIndicator

class
class AihuRadioGroupIndicator extends HTMLElementBase

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

58

AihuRadioGroupItem

class
class AihuRadioGroupItem extends HTMLElementBase
59

AihuRadioGroupRoot

class
class AihuRadioGroupRoot extends AihuRovingFocus
60

AihuRovingFocus

class
class AihuRovingFocus extends HTMLElementBase
61

AihuSeparator

class
class AihuSeparator extends HTMLElementBase
62

AihuSliderRoot

class
class AihuSliderRoot extends HTMLElementBase
63

AihuSwitchRoot

class
class AihuSwitchRoot extends HTMLElementBase
64

AihuSwitchThumb

class
class AihuSwitchThumb extends HTMLElementBase

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

65

AihuTextarea

class
class AihuTextarea extends AihuTextControlBase
66

AihuTextControlBase

class
abstract class AihuTextControlBase extends HTMLElementBase
67

AihuTooltipContent

class
class AihuTooltipContent extends HTMLElementBase
68

AihuTooltipRoot

class
class AihuTooltipRoot extends HTMLElementBase
69

AihuTooltipTrigger

class
class AihuTooltipTrigger extends HTMLElementBase
70

MissingContextError

class
class MissingContextError extends Error

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

71

CheckboxContextValue

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

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[]>
}
73

ConfigContextValue

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

DialogContextValue

interface
interface DialogContextValue {
  readonly open: Read<boolean>
  readonly modal: Read<boolean>
  readonly contentId: Read<string>
  readonly titleId: Read<string | null>
  readonly descriptionId: Read<string | null>
  setTitleId(id: string): void
  setDescriptionId(id: string): void
  setOpen(next: boolean): void
  close(): void
  toggle(): void
}
75

DomContext

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

Opaque token identifying a context slot.

76

FocusTrap

interface
interface FocusTrap {
  activate(): void
  deactivate(): void
}
77

FocusTrapOptions

interface
interface FocusTrapOptions {
  /**
   * CSS selector, resolved against the container's COMPOSED subtree (so it can
   * match into a nested open shadow root), naming the element to focus on
   * `activate()`. Falls back to the first tabbable — the default behavior —
   * when absent or when the selector matches nothing.
   */
  initialFocus?: string | null
  /**
   * Restore focus to whatever was focused before `activate()` when the trap is
   * deactivated. Defaults to `true`; pass `false` to opt out (the trap then
   * leaves focus wherever it currently is).
   */
  returnFocus?: boolean
}
78

FormControlContextValue

interface
interface FormControlContextValue {
  readonly disabled: Read<boolean>
  readonly required: Read<boolean>
  readonly invalid: Read<boolean>
  readonly controlId: Read<string>
  readonly describedById: Read<string | null>
  readonly labelId: Read<string | null>
}
79

HiddenInputOptions

interface
interface HiddenInputOptions {
  type: 'checkbox' | 'radio'
  name: Read<string | null>
  value: Read<string>
  checked: Read<boolean>
  required: Read<boolean>
  disabled: Read<boolean>
}
80

PopoverContextValue

interface
interface PopoverContextValue {
  readonly open: Read<boolean>
  readonly contentId: Read<string>
  readonly placement: Read<Placement>
  /** Resolved position written by the content after each `position()` call. */
  readonly coords: Read<PopoverCoords | null>
  setCoords(next: PopoverCoords): void
  /** Programmatic write — signal + reflected attribute, does NOT emit. */
  setOpen(next: boolean): void
  /** User-driven toggle (trigger click / Enter / Space) — emits. */
  toggle(): void
  /** User-driven close WITHOUT returning focus (outside pointerdown). */
  close(): void
  /** User-driven close that RETURNS focus to the trigger (Escape). */
  dismiss(): void
  registerTrigger(el: Element): void
  registerContent(el: Element): void
  triggerEl(): Element | null
}
81

PopoverCoords

interface
interface PopoverCoords {
  x: number
  y: number
  placement: Placement
}

The position the shim actually applied (post viewport-collision flip).

82

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
}
83

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).

84

SliderContextValue

interface
interface SliderContextValue {
  readonly value: Read<number>
  readonly min: Read<number>
  readonly max: Read<number>
  readonly step: Read<number>
  readonly disabled: Read<boolean>
}
85

SwitchContextValue

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

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
}
87

TooltipCoords

interface
interface TooltipCoords {
  x: number
  y: number
  placement: Placement
}
88

ButtonType

type
type ButtonType = 'button' | 'submit' | 'reset'
89

CheckboxState

type
type CheckboxState = 'checked' | 'unchecked' | 'indeterminate'
90

ColorScheme

type
type ColorScheme = 'light' | 'dark' | 'system'
91

Density

type
type Density = 'comfortable' | 'compact'
92

Direction

type
type Direction = 'ltr' | 'rtl'
93

Orientation

type
type Orientation = 'horizontal' | 'vertical' | 'both'
94

SeparatorOrientation

type
type SeparatorOrientation = 'horizontal' | 'vertical'