MCPcopy Index your code
hub / github.com/argyleink/prop-for-that

github.com/argyleink/prop-for-that @v0.7.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.7.8 ↗ · + Follow
237 symbols 589 edges 76 files 18 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

prop-for-that

Expose what JavaScript knows but CSS can't see — as live CSS custom properties.

npm version minzipped size zero dependencies license MIT

Docs · Demos · Changelog · llms.txt


Sliders, pointer position, element visibility, viewport size, battery, network, sensors — JavaScript can read all of it; CSS can't. prop-for-that writes that runtime state into --live-* and --const-* custom properties — batched and diffed down to one setProperty per frame — so your CSS can compose and react to it with plain calc() and var().

Zero dependencies. TypeScript. ESM + CJS. SSR-safe.

npm i prop-for-that

Quick start

<script type="module">import 'prop-for-that/auto'</script>

<input type="range" data-props-for="range" />
/* the slider paints itself from its own value — no event listeners, no render loop */
input {
  background: hsl(calc(var(--live-value-pct) * 120) 80% 50%);
}

Bind any element with data-props-for="key …" and read its --live-* properties in CSS. That's the whole idea.

Why

  • CSS does the work. No per-element event handlers or render loops — bind once, compose in stylesheets.
  • Fast by design. One requestAnimationFrame flush per frame — idle when nothing changes, frozen while the tab is hidden — plus write-on-change diffing and a single shared ResizeObserver / IntersectionObserver for the whole page. Continuously-sampling element sources pause while their element is off screen; event-driven ones (form fields, ranges, selects) run ungated.
  • Ship only what you use. Four lightweight core sources are built in; everything else is an opt-in, tree-shakeable plugin — and under auto each plugin loads on demand, the moment a data-props-for attribute asks for it.
  • Plays with the platform. Opt into typed @property values for interpolation, or FOUC-safe constants written before first paint.
  • Tiny and dependency-free, in every bundle format.

What it can read

Core (built in): viewport, element size, visibility, and <input type="range"> values.

Plugins (opt-in): pointer position, battery, network, online status, page focus & visibility, navigation type, page meta tags, low-entropy user-agent (OS / browser / engine / version / mobile), FPS, clock, scroll velocity, device orientation / motion, geolocation, CPU pressure, soft-keyboard geometry, media playback, form & field state, select & color-picker values, text-truncation (ellipsis) detection, and dominant + accent colors extracted from images and video — 20+ in all.

→ Every source, every property, and live demos are in the docs.

Entry points

Import What it does
prop-for-that/auto Zero-config & declarative: binds every data-props-for element — globals included, via <html data-props-for="…"> — loading plugin sources on demand, kept in sync with the DOM. Use as <script type="module">.
prop-for-that Imperative API — propsFor(), register(), configure() — for explicit control and teardown.
prop-for-that/head Synchronous, FOUC-safe constants (scrollbar width & overlay preference, DPR, core count, device memory, low-entropy user-agent) before first paint.
prop-for-that/plugins The opt-in plugin catalog.

auto sees the light DOM only (not shadow roots — bind those with propsFor(el, …)), and lazy-loads plugin chunks, so from a CDN use one that serves the dist files verbatim (unpkg / jsDelivr), not a rewriting CDN.

Full API and concepts: prop-for-that.netlify.app/docsite.

For LLMs / AI tools

A condensed, single-file reference — entry points, the full variable catalog, recipes, and gotchas — lives at llms.txt, hosted at prop-for-that.netlify.app/llms.txt and shipped in the npm package (node_modules/prop-for-that/llms.txt).

License

MIT © Adam Argyle

Extension points exported contracts — how you extend this code

BucketSum (Interface)
A running colour bucket: summed channels + member count.
src/plugins/_color.ts
Entry (Interface)
(no doc)
src/index.ts
UAInfo (Interface)
(no doc)
src/core/ua.ts
VirtualKeyboardLike (Interface)
* The soft (on-screen) keyboard's geometry, written to `:root`: * * - `--live-keyboard-open` — `1` while the keybo
src/plugins/keyboard.ts
UADataBrand (Interface)
(no doc)
src/core/ua.ts
PressureObserverInstance (Interface)
(no doc) [1 implementers]
src/plugins/cpu-pressure.ts
UAData (Interface)
(no doc)
src/core/ua.ts
PressureRecord (Interface)
(no doc)
src/plugins/cpu-pressure.ts

Core symbols most depended-on inside this repo

write
called by 115
src/core/types.ts
propsFor
called by 52
src/index.ts
start
called by 46
src/core/types.ts
round4
called by 37
src/core/num.ts
addEventListener
called by 37
src/plugins/keyboard.ts
set
called by 33
src/core/writer.ts
removeEventListener
called by 29
src/plugins/keyboard.ts
register
called by 27
src/index.ts

Shape

Function 178
Method 27
Class 16
Interface 16

Languages

TypeScript100%

Modules by API surface

test/plugins.test.ts30 symbols
src/index.ts18 symbols
src/plugins/_color.ts11 symbols
test/api.test.ts10 symbols
test/observers.test.ts9 symbols
demos/src/main.ts9 symbols
src/plugins/field-state.ts8 symbols
src/core/ua.ts8 symbols
src/core/frame.ts8 symbols
src/auto.ts8 symbols
src/plugins/keyboard.ts7 symbols
test/visibility.test.ts6 symbols

For agents

$ claude mcp add prop-for-that \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page