JavaScript API Reference

The xfscss object exposed by runtime.js and esm.js

Overview

From v1.2.0 onward, the browser-facing API is served from two public entry points, runtime.js and esm.js. This is the entry-point structure going forward — future releases in the 1.2.x line and beyond keep using these same two files unless noted otherwise in that release's changelog. Use one or the other, never both. Every method below is identical on both builds — the only difference is when it runs automatically. All npm/CLI usage is unaffected.

runtime.js vs esm.js

runtime.js is for plain HTML pages. It auto-scans the document for [type*="fscss"] links and <style>/[style] content, processes them, and reveals the page once done — no setup required. xfscss.reboot() is still available on it for re-running after you inject markup dynamically.

esm.js is for module-based use: an FSCSS-to-CSS conversion tool, build-time processing, or any manipulation that shouldn't automatically run against the live page. It never auto-boots and never touches page loading — you call xfscss.reboot() (or the individual methods) yourself, optionally from DOMContentLoaded if you do want page-code behavior.

Loading the API

Pin whichever release you're on in the URL — the paths below (runtime.js / runtime.min.js / esm.js) stay the same from v1.2.0 onward, only the version number changes.

Browser, auto-run:

HTML
<link type="fscss" href="/style.fscss">
<script src="https://cdn.jsdelivr.net/npm/fscss@1.2.0/runtime.min.js" async></script>

Module, manual control:

JavaScript
import xfscss from "https://cdn.jsdelivr.net/npm/fscss@1.2.0/esm.js";

// call whichever method you need
xfscss.reboot();

Methods

xfscss.run()

Async. Finds every <style> element on the page and processes its FSCSS content in place, replacing each element's contents with compiled CSS. Logs a warning and exits early if no <style> elements are found. Errors during processing are caught and logged rather than thrown.

JavaScript
await xfscss.run();

xfscss.inline(css)

Strips selectors and braces from a block of CSS, returning just the declarations inside. Used internally to turn a processed rule block into a flat string suitable for a style attribute.

JavaScript
const flat = xfscss.inline(".btn{ color: red; }");
// " color: red; "

xfscss.process(css)

Async. The core FSCSS compiler. Takes a raw FSCSS string and runs it through the full pipeline — imports, variables, functions, @define blocks, arrays, events, random values, patterns, extensions, and transformations — then returns the compiled CSS string. This is the method to reach for when you want FSCSS-to-CSS conversion without touching the DOM (e.g. inside esm.js tooling).

Individual pipeline stages can be skipped per input by including a matching exec.obj.block(...) marker in the source (for example exec.obj.block(all) skips the entire pipeline). See the full marker list below. All markers are stripped from the output regardless.

JavaScript
const compiled = await xfscss.process(rawFscssString);

xfscss.assign()

Async. Bootstraps FSCSS on the current page: fetches and injects any [type*="fscss"] linked stylesheets, runs process()/run() across all <style> elements once, then processes any inline style attributes found in the document. This is what runtime.js calls automatically on load.

JavaScript
await xfscss.assign();

xfscss.reboot()

Alias for assign(). Use this name when you want to explicitly re-run FSCSS processing — for example after injecting new markup into the DOM, or as the manual entry point on esm.js, which never calls it for you.

JavaScript
document.addEventListener("DOMContentLoaded", () => {
  xfscss.reboot();
});

xfscss.exec(options)

Injects a new <style> element from either an FSCSS/CSS text string or an external URL, then re-runs the bootstrap so it gets processed immediately.

OptionTypeDescription
typestringDefaults to "text". Text-like values: text, auto, text/fscss, text/css, text/xfscss, fscss. URL-like values: fromUrl, URL, fromURL, link, external.
contentstringRequired. Either the raw FSCSS/CSS text, or a URL to fetch it from, depending on type.
onSuccessfunctionOptional. Called with the created <style> element once it's appended and processed.
onErrorfunctionOptional. Called with an error message string if content is missing, the type is unsupported, or a URL fetch fails.
JavaScript
xfscss.exec({
  type: "text",
  content: ".btn { background: $primary-color; }",
  onSuccess: (el) => console.log("injected", el),
  onError: (msg) => console.error(msg)
});

Selective pipeline control — exec.obj.block(...)

Skip individual stages of process()

Inside any FSCSS source, a matching exec.obj.block(...) marker tells process() to skip that stage of the pipeline — useful for debugging or when only a subset of features is needed. All markers are stripped from the compiled output regardless of whether they matched anything.

FSCSS
/* Skip the entire pipeline */
exec.obj.block(all);

/* Or skip individual stages */
exec.obj.block(f import);
exec.obj.block(f import pick);
exec.obj.block(f import from);
exec.obj.block(vfc);
exec.obj.block(pattern);
exec.obj.block(store);
exec.obj.block(store:before);
exec.obj.block(store:after);
exec.obj.block(ext);
exec.obj.block(ext:before);
exec.obj.block(ext:after);
exec.obj.block(f var);
exec.obj.block(fun);
exec.obj.block(obj);
exec.obj.block(length);
exec.obj.block(count);
exec.obj.block(define);
exec.obj.block(arr);
exec.obj.block(event);
exec.obj.block(random);
exec.obj.block(copy);
exec.obj.block(num);
exec.obj.block(t group);
exec.obj.block(debug);
MarkerSkips
allThe entire pipeline — the source passes through untouched (markers still stripped)
f import / f import pick / f import fromImport resolution (selector-pick and from forms, plus the general import pass)
vfcVFC pass
patternPattern matching
store / store:before / store:afterStyle-store substitution, either generally or at a specific pass
ext / ext:before / ext:afterExternal processing, either generally or at a specific pass
f varVariable substitution
fun / objFunction stores / function-object processing
length / countLength and count helpers
define@define block expansion
arrArrays and loops
eventEvent functions
randomRandom value generation
copyValue transformation/copying pass
numNumeric processing
t groupTransform group application
debugDebug output pass

Looking for the language reference?

The API above covers the JavaScript runtime. For FSCSS syntax — variables, @define, patterns, arrays — see the docs.