nudg

v1.15.0
io.github.seukwoo/nudg Checked 9 hours ago Published 4 days ago

Write, check and compare UI interactions (springs, gestures, states) for web, iOS and Android.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

nudg_guide nudg format guide

The nudg format in one page: skeleton, vocabulary, motion forms, structure rules, and which field to change for requests like "bouncier" or "snappier". Read it before writing your first nudg file.

nudg_recipe Resolve a semantic UI recipe

Turn a common UI term such as toggle, FAB, sheet, voice call, video chat, or media player into a stable interaction contract: required and optional parts, states, events, continuous inputs, host responsibilities, motion, known format gaps, and a validated starter example. Omit name to list available recipes.

ParameterTypeDescription
namestringRecipe name or human alias, e.g. switch, toggle, video chat, sheet, or audio player.
sourcebooleanInclude the starter .nudg.json source. Default false.

nudg_validate Validate a nudg file

Check a nudg file. Each problem has a stable code, a JSON pointer path, and a hint that says how to fix it. Pass `file`, or `source` to check text before writing it.

ParameterTypeDescription
filestringPath to a .nudg.json file, relative to the working directory.
pathstringWith `source`: where the text would live, for resolving imports and labeling.
revstringWith `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included.
sourcestringThe file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory.

nudg_simulate Simulate a nudg file

Send events at given times without rendering anything, and get active states and property values over time, plus a per-property summary: min, max, final value, and when it came to rest.

ParameterTypeDescription
eventsarrayWhat happens, in time order. Each item is an event { "event": "track.tap", "t": 0.1 }, an input sample { "input": "track.drag.x", "value": 12, "t": 0.2 }, or a whole drag { "drag": "track", "t": 0.1,…
everynumber | stringSeconds between samples. Default 0.05.
filestringPath to a .nudg.json file, relative to the working directory.
layoutobjectWhat the host would measure (0.4), reported at time 0: { "tab2.x": 96, "tab2.width": 88, "underline.x": 8 }. Measured values without it fall back to their base; compare with url or html measures them…
pathstringWith `source`: where the text would live, for resolving imports and labeling.
propertiesarrayProperties to report, e.g. ["knob.x"]. Default: all.
reducedMotionbooleanPlay as a reduced-motion user would see it: short linear tweens, no kicks (0.3).
revstringWith `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included.
sourcestringThe file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory.
startarrayStart in these states instead of initial, e.g. ["on"].
untilnumber | stringLast time to look at. Default: when everything has come to rest.

nudg_plot Plot motion

Draw a motion graph image: each property over time with state bands, events, targets, overshoot (max/min) and settle times. Good for judging feel, e.g. comparing bounce before and after an edit.

ParameterTypeDescription
eventsarrayWhat happens, in time order. Each item is an event { "event": "track.tap", "t": 0.1 }, an input sample { "input": "track.drag.x", "value": 12, "t": 0.2 }, or a whole drag { "drag": "track", "t": 0.1,…
filestringPath to a .nudg.json file, relative to the working directory.
layoutobjectWhat the host would measure (0.4), reported at time 0: { "tab2.x": 96, "tab2.width": 88, "underline.x": 8 }. Measured values without it fall back to their base; compare with url or html measures them…
outstringAlso save the graph here (.svg or .png).
pathstringWith `source`: where the text would live, for resolving imports and labeling.
propertiesarrayProperties to report, e.g. ["knob.x"]. Default: all.
reducedMotionbooleanPlay as a reduced-motion user would see it: short linear tweens, no kicks (0.3).
revstringWith `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included.
sourcestringThe file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory.
startarrayStart in these states instead of initial, e.g. ["on"].
untilnumber | stringLast time to look at. Default: when everything has come to rest.

nudg_compare Compare two versions

Two versions of an interaction under the same events, for a person to judge. Says first whether anyone would notice the difference (imperceptible / subtle / clear, per property, with what changed: overshoot, settle time, position), then shows both: with `html`, real A/B filmstrips in two rows; otherwise both curves on one graph. If the change is below perception it proposes looking at an exaggerated version first.

ParameterTypeDescription
aobjectThe current version: { file }, { file, rev } (at a git revision) or { source, path? }. Not needed with `before`.
atarrayFrame times for the filmstrips.
bobjectThe changed version: { file }, { file, rev } or { source, path? }. Not needed with `before`.
beforestringShorthand with `file`: compare the file at this git revision (HEAD, HEAD~1, a branch) with the file on disk; a and b are then not needed. Labels default to the revision and "now".
bundlestringFor a SwiftUI or Compose app: write the comparison (both versions compiled, the events, the verdict) to this .compare.json, for NudgCompare to play side by side on the app's own views. Put it in the a…
eventsarrayWhat happens, in time order. Each item is an event { "event": "track.tap", "t": 0.1 }, an input sample { "input": "track.drag.x", "value": 12, "t": 0.2 }, or a whole drag { "drag": "track", "t": 0.1,…
filestringWith `before`: the file to compare across revisions.
framesintegerEvenly spaced frames when `at` is not given. Default 6.
htmlstringThe host page with the component's markup, when there is no running app. Gives real A/B filmstrips (needs Chrome) and writes a page the person should open: both versions playing side by side in a loop…
labelsarrayNames for the two versions, default ["A", "B"].
layoutobjectWhat the host would measure (0.4), reported at time 0: { "tab2.x": 96, "tab2.width": 88, "underline.x": 8 }. Measured values without it fall back to their base; compare with url or html measures them…
openbooleanOpen the side-by-side page in the person's browser. Default: once per session; later calls rewrite the same page and the open tab shows it after a reload. true forces a new tab, false never opens (NUD…
outstringAlso save the picture here (.png; .svg for the graph).
pagestringWhere to write that page. Default: next to `out` as .html, else in the temp folder.
propertiesarrayProperties to report, e.g. ["knob.x"]. Default: all.
reducedMotionbooleanPlay as a reduced-motion user would see it: short linear tweens, no kicks (0.3).
selectorstringWith url: which element to snapshot. Default: the smallest element holding every bound target (a toggle's track with its knob).
startarrayStart in these states instead of initial, e.g. ["on"].
untilnumber | stringLast time to look at. Default: when everything has come to rest.
urlstringThe running app's URL (or a local page). The component is snapshotted from it, styles and all, so no html file is needed: real A/B filmstrips, and the side-by-side page, on the real thing. Sizes the f…

nudg_render Render frames

Draw real frames of the component as one filmstrip image, using the host page's markup and styles (elements with data-nudg names). Needs a local Chrome.

ParameterTypeDescription
file *stringPath to a .nudg.json file, relative to the working directory.
html *stringPage with the component's markup and styles. Its scripts don't run.
atarrayFrame times. Default: evenly spaced until at rest.
eventsarrayWhat happens, in time order. Each item is an event { "event": "track.tap", "t": 0.1 }, an input sample { "input": "track.drag.x", "value": 12, "t": 0.2 }, or a whole drag { "drag": "track", "t": 0.1,…
framesintegerNumber of evenly spaced frames when `at` is not given. Default 6.
outstringAlso save the PNG here.
reducedMotionbooleanPlay as a reduced-motion user would see it: short linear tweens, no kicks (0.3).
startarrayStart in these states instead of initial, e.g. ["on"].
untilnumber | stringLast time to look at. Default: when everything has come to rest.

nudg_critique Critique the motion

Whether the motion is good, not only valid. Plays every transition from rest and checks it against the platforms' motion guidelines and accessibility rules: transitions that take too long, press feedback that arrives late, changes nobody can see, fades that bounce, exits slower than entrances, auto-dismiss too short to read, dialogs that can't be closed with Escape. Each finding has a JSON pointer, a fix and its source. Call it once after writing or changing a file, and fix the warnings before showing the person.

ParameterTypeDescription
filestringPath to a .nudg.json file, relative to the working directory.
pathstringWith `source`: where the text would live, for resolving imports and labeling.
revstringWith `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included.
sourcestringThe file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory.

nudg_audit Where motion lives outside nudg

Scans an app's source for motion that isn't on nudg: CSS keyframes and transitions of moving properties, Web Animations, other motion libraries, styles written by hand, frame loops, and timers or document listeners around players. Each finding names what in nudg does it, or is marked a gap when nudg can't yet (report those to the nudg project instead of working around them). Starts with the share of motion on nudg. Call it after wiring nudg into an app, and before adding motion of your own.

ParameterTypeDescription
dirstringThe directory to scan, default the working directory.

nudg_check Check the app's motion

One call over a project: every nudg file validated and checked against the platforms' guidelines, and the source audited for motion outside nudg. It returns two lists. forAi: fix these yourself without asking (validation errors, guideline warnings with one right answer, glue nudg replaces), then call nudg_check again. forPerson: what needs the person's taste or decision; ask them, one line each. Pass on only the headline and the person's list; when forPerson is empty you may say nothing about motion at all. When the person keeps a choice, add its code to that file's "keep" with a note, so it i…

ParameterTypeDescription
dirstringThe project directory, default the working directory.

nudg_from_css CSS keyframes to a nudg file

Turns one CSS @keyframes (in a .css file or a CSS-in-JS string) into a nudg file, with the duration, delay, timing, iterations and direction read from the animation line that plays it, and proves it moves the same: the largest difference per property over 60 samples. Past the limits (0.5 px, 0.5°, 0.01) it returns no file and names each reason; never approximate around them by hand. Use it for every @keyframes nudg_audit reports instead of rewriting them. When the result offers a spring (keyframes that overshoot), show the person both, with how far the spring strays from the CSS, and ask whic…

ParameterTypeDescription
name *stringThe @keyframes name.
animationstringThe animation line's timing, when the source has none or it holds values only the app knows, e.g. "0.6s ease-out".
cssstringThe source text instead of a path.
pathstringThe source file that holds the @keyframes block.
targetstringThe nudg target name, default content.
valuesobjectValues only the app knows, by the expression the source interpolates, e.g. { "V.accent": "#ff6a00", "GO_MS": "900" }. Read them from the app's code.

nudg_to_css A nudg file as plain CSS

For a page that runs no JavaScript (a static page that shares a component with the app): the file as plain CSS. A rule per state under a selector the page toggles (or :hover, :active and :focus when the file enters the state on hover, press or focus), transitions carrying each motion (springs as linear()), the way in on mount from @starting-style, colors in oklab(). Checked against nudg's runtime at 60 points and two sizes; differences and what the page loses without a script (drags, timers, kicks, loops, layout from another element) are listed. Don't add a script to a static page yourself: te…

ParameterTypeDescription
filestringPath to a .nudg.json file, relative to the working directory.
mountstringThe event the element is shown with as it mounts, e.g. host.show: its way in plays from @starting-style.
pathstringWith `source`: where the text would live, for resolving imports and labeling.
revstringWith `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included.
scriptbooleanAlso return a script (an ES module) that plays the file on nudg's runtime, exactly, where the page runs JavaScript; the CSS stays the fallback. Only when the person decided the page may load JavaScrip…
scriptSrcstringWith script: the URL of a copy of nudg's dist folder the site serves itself, instead of jsDelivr.
sourcestringThe file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory.
statesobjectA selector per state that matches while it is active, e.g. { "hidden": "[data-closing]" }. Default [data-nudg-state~="<name>"].
targetsobjectA selector per target, e.g. { "menu": ".lnb" }. Default [data-nudg="<name>"].

nudg_generate TypeScript contract for the host

The TypeScript module `nudg generate` writes beside a file (x.nudg.json -> x.nudg.ts): a types-only interface with the file's targets, handled events, continuous inputs and state paths, imports resolved. Hosts pass it to the adapters, e.g. useNudg<ToggleContract>(toggle), so misspelled names fail to compile. After changing a file's names, write the returned text to that path, or run `nudg generate <file>`.

ParameterTypeDescription
filestringPath to a .nudg.json file, relative to the working directory.
pathstringWith `source`: where the text would live, for resolving imports and labeling.
revstringWith `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included.
sourcestringThe file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory.

nudg_share Share usage with the nudg project

Prepares a counts-only summary of this machine's nudg log (rounds per change, verdicts, tool calls, versions; no file names, paths, URLs or code) and a link to a prefilled GitHub issue the person can read and submit. Sends nothing by itself. Call it only when the person agreed to share, typically after nudg_compare said a change took several rounds; pass their words as `note`.

ParameterTypeDescription
notestringWhat the person said made it hard, in their words. Optional.

nudg_observe Observe the real page

Host truth. Opens the real page (its scripts run) in headless Chrome, performs actions on the element as a finger or a key would, measures it every frame (translate, scale, rotation, opacity, size, and whether it is still there), and says what the page actually showed. With `file`, judges the page against the file under the same actions: played as the file says, differs, never shown (the element left the page), or nothing moved. Needs a local Chrome.

ParameterTypeDescription
actions *arrayWhat to do, in time order: { "action": "tap", "t": 0.1 }. Actions are down, up, tap (down, held 80 ms, up), hover, leave, or key:<name> (a letter, or escape, enter, space, tab, arrow keys, home, end,…
url *stringAn http(s) URL of the running app, or a local .html path (served from the working directory).
eventsarrayThe file's events to judge against. Default: the actions, as the file's events on `on`, at the times they actually happened.
filestringPath to a .nudg.json file, relative to the working directory.
onstringWhich of the file's targets the actions are for. Default: the first target that handles them (a toggle's track, not its knob).
reducedMotionbooleanPlay as a reduced-motion user would see it: short linear tweens, no kicks (0.3).
selectorstringCSS selector of the element to measure; shadow roots are searched. Default, with `file`: [data-nudg="<the file's first target>"].
settlenumber | stringSeconds to keep measuring after the last action. Default 1.5.
startarrayStart in these states instead of initial, e.g. ["on"].
viewportobjectWindow size, e.g. a phone's 390×844.
warmupnumber | stringSeconds to let the page's scripts start first. Default 0.5.