API / @aihu/primitives

@aihu/primitives

Runtime core

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

version
0.2.1
exports
93
values
71
types
22
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, options = {})
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).

07

defineCollection

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

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

08

defineConfigProvider

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

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

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

11

defineInput

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

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

12

defineLabel

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

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

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

15

defineRadioGroup

function
function defineRadioGroup(): void

Register all radio-group custom elements (idempotent).

16

defineRovingFocus

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

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

17

defineSeparator

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

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

18

defineSlider

function
function defineSlider(): void

Register all slider custom elements (idempotent).

19

defineSwitch

function
function defineSwitch(): void

Register all switch custom elements (idempotent).

20

defineTextarea

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

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

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

FocusTrap

const
const FocusTrap
30

FocusTrapOptions

const
const FocusTrapOptions
31

formControlContext

const
const formControlContext
32

popoverContext

const
const popoverContext
33

presenceContext

const
const presenceContext

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

34

radioGroupContext

const
const radioGroupContext
35

radioGroupItemContext

const
const radioGroupItemContext
36

sliderContext

const
const sliderContext
37

switchContext

const
const switchContext
38

tooltipContext

const
const tooltipContext
39

AihuButton

class
class AihuButton extends HTMLElement
40

AihuCheckboxIndicator

class
class AihuCheckboxIndicator extends HTMLElement

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

41

AihuCheckboxRoot

class
class AihuCheckboxRoot extends HTMLElement
42

AihuCollection

class
class AihuCollection extends HTMLElement
43

AihuConfigProvider

class
class AihuConfigProvider extends HTMLElement
44

AihuDialogBackdrop

class
class AihuDialogBackdrop extends DialogPiece
45

AihuDialogClose

class
class AihuDialogClose extends DialogPiece
46

AihuDialogContent

class
class AihuDialogContent extends DialogPiece
47

AihuDialogDescription

class
class AihuDialogDescription extends DialogPiece
48

AihuDialogRoot

class
class AihuDialogRoot extends HTMLElement
49

AihuDialogTitle

class
class AihuDialogTitle extends DialogPiece
50

AihuDialogTrigger

class
class AihuDialogTrigger extends DialogPiece
51

AihuFormControl

class
class AihuFormControl extends HTMLElement
52

AihuInput

class
class AihuInput extends AihuTextControlBase
53

AihuLabel

class
class AihuLabel extends HTMLElement
54

AihuPopoverContent

class
class AihuPopoverContent extends PopoverPiece
55

AihuPopoverRoot

class
class AihuPopoverRoot extends HTMLElement
56

AihuPopoverTrigger

class
class AihuPopoverTrigger extends PopoverPiece
57

AihuPresenceGate

class
class AihuPresenceGate extends HTMLElement
58

AihuRadioGroupIndicator

class
class AihuRadioGroupIndicator extends HTMLElement

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

59

AihuRadioGroupItem

class
class AihuRadioGroupItem extends HTMLElement
60

AihuRadioGroupRoot

class
class AihuRadioGroupRoot extends AihuRovingFocus
61

AihuRovingFocus

class
class AihuRovingFocus extends HTMLElement
62

AihuSeparator

class
class AihuSeparator extends HTMLElement
63

AihuSliderRoot

class
class AihuSliderRoot extends HTMLElement
64

AihuSwitchRoot

class
class AihuSwitchRoot extends HTMLElement
65

AihuSwitchThumb

class
class AihuSwitchThumb extends HTMLElement

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

66

AihuTextarea

class
class AihuTextarea extends AihuTextControlBase
67

AihuTextControlBase

class
abstract class AihuTextControlBase extends HTMLElement
68

AihuTooltipContent

class
class AihuTooltipContent extends HTMLElement
69

AihuTooltipRoot

class
class AihuTooltipRoot extends HTMLElement
70

AihuTooltipTrigger

class
class AihuTooltipTrigger extends HTMLElement
71

MissingContextError

class
class MissingContextError extends Error

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

72

CheckboxContextValue

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

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

ConfigContextValue

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

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

DomContext

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

Opaque token identifying a context slot.

77

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

HiddenInputOptions

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

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

PopoverCoords

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

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

81

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

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

83

SliderContextValue

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

SwitchContextValue

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

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

TooltipCoords

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

ButtonType

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

CheckboxState

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

ColorScheme

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

Density

type
type Density = 'comfortable' | 'compact'
91

Direction

type
type Direction = 'ltr' | 'rtl'
92

Orientation

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

SeparatorOrientation

type
type SeparatorOrientation = 'horizontal' | 'vertical'