Skip to main content

API Reference

Complete reference for SmarterElements JavaScript API with component isolation, modal system, and automatic resizing.

CDN Version Management

unpkg.com Integration

SmarterElements is available via unpkg.com CDN with flexible versioning options:

Version Formats

Version Selection Strategy

SmarterElements Class

Constructor

Options

Example

Element Creation

elements.create(type, options)

Creates a new element instance.

Parameters

Options Object

onTokenRefresh

Long-lived embeds are backed by short-lived STS tokens; the SDK silently refreshes them before expiry. You opt in by supplying onTokenRefresh — the SDK owns the scheduling, forwards the rotated token to the element, and fires tokenRefreshed / tokenExpired, but the callback itself must fetch a fresh token set from your backend (the STS refresh endpoint requires your API credential, which never reaches the browser). If omitted, the token simply expires when its TTL runs out.
onTokenRefresh return shape
The callback must resolve with an StsTokenSet containing: Resolving with a valid set applies the new tokens and fires tokenRefreshed. Throwing or returning a rejected promise fires tokenExpired and ends the session. For the full flow, see Authentication & Tokens.

Example

Element Instance Methods

element.mount(selector)

Mounts element to DOM container. Parameters:
  • selector (string | HTMLElement) - Target container

element.openModal(options)

Opens element in modal overlay with automatic resizing and focus management. Parameters:
  • options (object) - Modal configuration options
Returns: Promise<void>

element.closeModal()

Closes the modal if element is displayed as modal.

element.updateConfig(newConfig)

Updates element configuration. Parameters:
  • newConfig (object) - New configuration data

element.updateConstraints(newConstraints)

Updates size constraints for mounted elements. Parameters:
  • newConstraints (object) - New constraint values

element.sendMessage(type, data)

Sends custom message to element. Parameters:
  • type (string) - Message type
  • data (any) - Message data

element.destroy()

Destroys element and cleans up resources.

React Integration

useSmarterElements(options)

React hook for managing SmarterElements. Parameters:
  • options (object) - Same as SmarterElements constructor options
Returns: SmarterElements instance

<SmarterElement> Component

React component for declarative element usage.

Size Constraints

Elements support flexible size constraints with CSS units:

Supported Units

  • Pixels: 300 or '300px'
  • Percentages: '80%' (of parent container)
  • Viewport units: '50vw', '30vh'
  • Relative units: '20rem', '15em'

Event System

Element Events

Standard Events

Utility Functions

debounce(func, wait, immediate?)

Delays function execution until after wait milliseconds have elapsed since the last time it was invoked. Parameters:
  • func (function) - The function to debounce
  • wait (number) - The number of milliseconds to delay
  • immediate (boolean, optional) - If true, trigger on leading edge
Returns: Debounced function with cancel() and flush() methods

throttle(func, wait, options?)

Limits function execution to at most once per wait milliseconds. Parameters:
  • func (function) - The function to throttle
  • wait (number) - The number of milliseconds to throttle to
  • options (object, optional) - { leading?: boolean, trailing?: boolean }
Returns: Throttled function with cancel() and flush() methods

CDN Usage

TypeScript Support

Full TypeScript definitions included:

For more examples and use cases, see the Examples section.