Bindings
Map any number in your app onto a value or a material, with ranges and easing curves — in the design file, not in your code.
A binding turns one of your app's numbers (an input) into a value the visual draws (a target). Steps become a constellation's progress, a heart rate becomes glow, a mic level becomes the orb's breathing. The mapping lives in the FX Spec, so a designer can tune it without a code change.
{
"fxSpec": "1.15",
"name": "Daily activity",
"object": "signal",
"pattern": "constellation",
"params": {
"steps": 3
},
"bindings": {
"progress": {
"input": "steps",
"inputRange": [
0,
10000
],
"curve": "easeOut"
},
"level": {
"input": "activeMinutes",
"inputRange": [
0,
30
]
},
"glow.strength": {
"input": "heartRate",
"inputRange": [
60,
100,
160
],
"outputRange": [
0,
0.2,
0.8
],
"curve": [
"linear",
"easeIn"
]
}
}
}
Anatomy
Each entry in bindings is keyed by its target (above: progress, level and glow.strength) and says:
| Key | Meaning |
|---|---|
| target (the key) | What to drive. One of the bindable targets below. |
input | Your name for the number. Pass it at runtime in inputs. Any name works. |
inputRange | Input stops, ascending or descending, at least two. Default [0, 1]. |
outputRange | Output stops, same count as inputRange. Default: the target's natural range. |
curve | linear, ease, easeIn, easeOut or easeInOut (CSS timing curves), one for all segments or one per segment. In TypeScript, a function works too. Default linear. |
The output is always clamped to the target's range. Multi-stop ranges let one input do different things in different spans. Above, the heart rate does one thing from 60 to 100 and another from 100 to 160: a glow that rises slowly, then faster.
Bindable targets
Ten in all: the values progress (dune, constellation), level (every signal pattern but dune), quality (cohesion), audioLevel and muted, and the material masters glow.strength, noise.strength, gradient.strength, pulse.strength and color.mix. A target the pattern doesn't read is a warning. Materials that need a companion setting to be visible get a sensible one automatically.
Bindings and states
Bindings are part of a state's patch, like everything else. A state can add a binding, change one, or remove one with null. The goalReached state in the rules example below drops the progress binding and holds progress at 1 instead.
Rules: the file picks the state
A binding moves a value; a rule (FX Spec 1.9) picks which of the file's states shows, from the same inputs. The app just passes numbers, and the design decides that 10,000 steps means goalReached:
{
"fxSpec": "1.15",
"name": "Daily activity (with rules)",
"object": "signal",
"pattern": "constellation",
"params": {
"steps": 3
},
"bindings": {
"progress": {
"input": "steps",
"inputRange": [
0,
10000
],
"curve": "easeOut"
},
"level": {
"input": "activeMinutes",
"inputRange": [
0,
30
]
},
"glow.strength": {
"input": "heartRate",
"inputRange": [
60,
100,
160
],
"outputRange": [
0,
0.2,
0.8
],
"curve": [
"linear",
"easeIn"
]
}
},
"states": {
"goalReached": {
"params": {
"progress": 1
},
"bindings": {
"progress": null
}
},
"intense": {
"speed": 1.6,
"materials": {
"glow": {
"strength": 0.8
}
}
}
},
"rules": [
{
"when": {
"input": "steps",
"gte": 10000
},
"state": "goalReached"
},
{
"when": {
"input": "heartRate",
"gt": 150
},
"state": "intense",
"hysteresis": 5
}
]
}
- Rules are tried in order and the first one that holds wins. When none holds, the view shows its own
state, or the base design. - One comparison per rule:
gt,gte,lt,lte, orbetween: [low, high](inclusive). A rule whose input you don't pass doesn't hold. hysteresisstops flicker at the edge: already inintense, the rule above keeps holding until the heart rate drops below 145, though it entered above 150.- A state that isn't in
statesis a warning (the rule never applies); a malformed rule is an error. Up to 32 rules. - Voice apps: with a voice source bound, the conversation drives the state and rules stay off. Rules are for everything else: fitness, finance, devices.
rules: falseon the view turns them off (rules="false"on<sinua-view>).
import { SinuaView } from "@sinua/web/react";
import activity from "../spec/activity-rules.fxspec.json";
// The app passes numbers; the file's `rules` pick the state: goalReached at 10,000 steps,
// intense above 150 bpm (and back below 145). With no rule holding, the base design shows.
export function DailyActivity({ steps, heartRate }: { steps: number; heartRate: number }) {
return <SinuaView spec={activity} inputs={{ steps, heartRate }} style={{ width: 120, height: 120 }} />;
}
An input that isn't passed
A binding whose input you don't pass leaves its target at the design's static value, and the view reports it as inactive. That's how one file works for users who have a heart-rate sensor and for users who don't.
Binding in code
Without an FX Spec, bindReactiveInput applies the same mapping in TypeScript:
import { bindReactiveInput, frameWithOverrides } from "@sinua/core";
declare const steps: number; // your app's value
declare const t: number; // seconds since the view started
// 10,000 steps moves the dune's glow along, eased out so the last few thousand feel slower.
const overrides = bindReactiveInput({
value: steps,
target: "progress",
input: [0, 10_000],
curve: "easeOut",
});
const frame = frameWithOverrides("dune", 64, t, overrides);
On every platform, pass the spec and your values as inputs:
import { SinuaView } from "@sinua/web/react";
import activity from "../spec/activity-rings.fxspec.json";
// The mapping lives in the spec's `bindings`; the app passes only its raw numbers.
// An input you leave out keeps its target at the design's value (reported as inactive).
export function DailyActivity({ steps, activeMinutes, heartRate }: { steps: number; activeMinutes: number; heartRate: number }) {
return <SinuaView spec={activity} inputs={{ steps, activeMinutes, heartRate }} style={{ width: 120, height: 120 }} />;
}