DEV Community

Cover image for A physics layer that draws nothing: reading interface forces back as CSS variables
Zach Shallbetter
Zach Shallbetter

Posted on Originally published at fundamentalengine.com

A physics layer that draws nothing: reading interface forces back as CSS variables

Most interface physics runs one way. Something moves, and the page watches.

I build Fundamental, a relational field runtime for interfaces. Elements bend a shared field, and the field bends them back. The second half is the part I care about. The field reports what it feels as live CSS variables, so the page can style itself from the result.

Bodies

A body is any element with a data-body attribute. Its value is one or more force tokens.

<field-root render="dots"></field-root>
<h1 data-body="attract" data-strength="1.2" data-feedback>Mass</h1>
<button data-body="repel" data-range="240">Keep clear</button>
Enter fullscreen mode Exit fullscreen mode

<field-root> goes on the page once. It finds every [data-body] element and wires it into the field. With data-feedback, an element gets the write-back. Its --d and --field-density variables change as the field moves around it. Those are ordinary CSS variables. Any rule can read them.

Nothing on screen by default

A field created without a render mode draws nothing. It still runs the simulation and reports through --field-* variables, events, queries and snapshots. The particle canvas is opt-in with render: 'dots', as above. The demo looks like particles, so this surprises people. The particles are one render surface, not the system.

Trying it needs no build step.

import { createField } from 'https://esm.sh/@fundamental-engine/vanilla';
createField(document.querySelector('canvas'), { render: 'dots' });
Enter fullscreen mode Exit fullscreen mode

Where it stands

It is a 0.x preview at 0.12.0, MIT licensed, with seven packages on npm. It ships in production apps and has no third-party adopters yet.

The core API is frozen and grows additively. The query, snapshot, diff and replay APIs are experimental. Swift and Kotlin ports exist at preview status, built from source only.

I haven't shown that this model fits every interface. It fits the ones where an element should behave according to what is near it.

Elements bend the field. The test is what a page does when the field bends back.

Related: https://fundamentalengine.com/

Top comments (1)

Collapse
 
alexshev profile image
Alex Shev •

Using the physics layer as an input to CSS variables is a good boundary: motion stays expressive without forcing every component to become a canvas. A worthwhile guardrail is a reduced-motion path that maps the same state variables to near-static values, so the interaction remains legible when animation is disabled.