JavaScript API

Corset's JavaScript API is how you initiate sheets and bind to the DOM, as well as control behaviors within sheets.

Usage

The JavaScript API is used by importing the main module. Installation goes through the various methods of using Corset.

Each of the below described exports are imported via the main module.

import sheet from 'https://cdn.corset.dev/v2';

sheet`
  body {
    class-toggle: js true;
  }
`.update(document);

Exports

These APIs are exported by the entrypoint module.

sheet
The default export of the main module, defines a sheet with values (JavaScript insertion) that is then used to update a root.
mount
Attach a sheet to a root element, binding it to that element. Provides a way to update when internal state changes.
registerBehavior
Register a behavior by name, that can be used in any sheet within your application.
registerCustomFunction
Register a custom function that can be used in any sheet within your application.