Chapter 22

API quick reference

// Runtime
new FormUI(app, { theme?, themeOverrides?, host?, fitVisualViewport? })
  .theme  .setTheme(theme, overrides?)  .content  .overlay  .focus  .announcer  .isTouch
  .onInteraction(fn) → unsubscribe       events: themechange | focuschange | viewportchange

// Controls (all extend Control<V>)
new TextInput(ui, TextInputOptions)          → string
new TextArea(ui, TextAreaOptions)            → string
new PasswordInput(ui, PasswordInputOptions)  → Secret
new OtpInput(ui, OtpInputOptions)            → string (digits)
new DatePicker(ui, DatePickerOptions)        → 'YYYY-MM-DD' | 'YYYY-MM-DDTHH:mm' | null
new PhoneInput(ui, PhoneInputOptions)        → '+<E.164>' | ''
new Checkbox(ui, CheckboxOptions)            → boolean
new Switch(ui, SwitchOptions)                → boolean
new RadioGroup<T>(ui, RadioGroupOptions<T>)  → T | null
new Select<T>(ui, SelectOptions<T>)          → T | null
new Slider(ui, SliderOptions)                → number
new Button(ui, ButtonOptions)                → null

// Form
new Form(ui, FormOptions).add(...).bindSubmit(btn)
  .submit() .validate() .values() .get(name) .reset() .wipeSecrets() .destroy()
  events: submitting | success | failure | invalid | blocked | idle

// Layout and widgets
new Column(items, gap?, padding?)   new Row(items, gap?, breakpoint?)   new ScrollView(ui, content)
insets(v, h?, b?, l?)   new Label(ui, text, variant?)   new StrengthMeter(ui)   new Toast(ui)   new PrivacyScreen(ui, msg?)

// Theme
lightTheme  darkTheme  createTheme(base, overrides)  themeFromSeed(color, dark?)  mix(a, b, t)  cssFont(theme)
createFormTheme({ mode, theme, text, accent, status }, tokens?)  presetTheme(name, mode)  accentPalettes
contrastRatio(a, b)  readableOn(bg)  luminance(c)  checkContrast(theme)
// every control: { info: 'tooltip text' }   ui.tooltip.show(anchor, text) / hide()

// Rules
fromRule(rules, name)  ruleValidator(rule)                      // browser
validatePayload(rules, body)  validateValue(rule, v, all)  checkPassword(pw, policy, ctx)   // shared

// Security
Secret: length isEmpty equals(other) count(pred) toUtf8() use(fn)
SecureBuffer  sanitizeInput(text, opts)  Formatters.*  RateLimiter  BotGuard
secureSubmit(url, body, { csrfToken?, allowedOrigins?, timeoutMs? })  readCsrfToken()
sealSecret(secret, key, field)  sealBytes(bytes, key, field)                      // PFE1 browser
openEnvelope(envelope, keysByKid, context)  loadKey(pem)  loadKeyRing(opts)       // PFE1 Node