Skip to content

Motion

module Motion
AssemblyPartas.Nacara.Plugins.Motion
Attributes[<RequireQualifiedAccess>]

Hovers drawn in Figma, configured and compiled from F#.

compile applies every override and fails on a hover or a change the document does not have.

Functions and values

[<Literal>] CdnUrl: string = "https://cdn.jsdelivr.net/npm/animejs@4.5.0/dist/bundles/anime.esm.min.js"

The anime.js module url used by animeFromCdn.

[<Literal>] LayerName: string = "motion"

The name of the style layer the CSS hovers are offered to the theme in.

animeFromCdn (options: MotionOptions) : MotionOptions

Loads anime.js from the jsDelivr CDN instead of the bundled copy.

Defaults to the bundled copy.

Parameter
optionsThe options to change.
animeSource (source: AnimeSource) (options: MotionOptions) : MotionOptions

Sets where anime.js comes from.

Defaults to Bundled.

Parameter
sourceWhere anime.js comes from.
optionsThe options to change.
compile (options: MotionOptions) (document: MotionDocument) : Result<CompiledMotion,string>

Applies the options to a document and splits its hovers by engine.

Fails, naming the known ones, when the options name a hover or a change the document does not have. Fails, too, when a hover with a spring or spring preset easing is given a duration, when an easing override names a spring preset that is not one, and when two hovers of the document share a name.

Parameter
optionsThe options.
documentThe parsed document.
create () : IPlugin

The plugin, with the default options.

Loads the motion document at once and fails, naming the path, when it is missing.

createWith (configure: MotionOptions -> MotionOptions) : IPlugin

The plugin, with options changed by configure.

Loads the motion document at once, offers its CSS to the theme once, and fails when either cannot be done.

Parameter
configureChanges the default options.
defaults: MotionOptions

The options a site starts from.

disable (name: string) (options: MotionOptions) : MotionOptions

Leaves one hover out of the output.

Defaults to every hover being written.

Parameter
nameThe hover's name in the document.
optionsThe options to change.
document (path: string) (options: MotionOptions) : MotionOptions

Reads the motion document from a path.

Resolved against the working directory. Defaults to "design/tokens/motion.json".

Parameter
pathThe path of the exported document.
optionsThe options to change.
duration (name: string) (ms: int) (options: MotionOptions) : MotionOptions

Sets the duration of one hover in milliseconds.

Applies to a linear or cubic-bezier easing. A spring plays over its settling time and a spring preset over 1200ms, so compile fails when the hover's easing, after any easing override, is a spring or a preset. Defaults to the document's duration.

Parameter
nameThe hover's name in the document.
msThe duration in milliseconds.
optionsThe options to change.
easing (name: string) (easing: Easing) (options: MotionOptions) : MotionOptions

Sets the easing of one hover.

A SpringPreset is one of "GENTLE", "QUICK", "BOUNCY" and "SLOW"; compile fails on any other name. Defaults to the document's easing.

Parameter
nameThe hover's name in the document.
easingThe easing.
optionsThe options to change.
engine (engine: MotionEngine) (options: MotionOptions) : MotionOptions

Sets the engine that plays the hovers.

Defaults to Css.

Parameter
engineThe engine.
optionsThe options to change.
hoverEngine (name: string) (engine: MotionEngine) (options: MotionOptions) : MotionOptions

Sets the engine of one hover.

Defaults to the plugin's engine.

Parameter
nameThe hover's name in the document.
engineThe engine that plays this hover.
optionsThe options to change.
load (options: MotionOptions) : Result<CompiledMotion,string>

Reads the options' document, then compiles it.

A relative document path is taken from the project root. Fails, naming the resolved path and how to export the document, when the file is missing.

Parameter
optionsThe options.
projectRoot () : string

The project root Nacara builds this site from.

The value after --root on the command line when there is one, otherwise the directory of the site's project file, the same lookup Nacara makes.

reducedMotion (policy: ReducedMotion) (options: MotionOptions) : MotionOptions

Sets what the stylesheet does for visitors who ask for reduced motion.

Defaults to Instant.

Parameter
policyThe reduced-motion policy.
optionsThe options to change.
register (site: Site) : Site

Adds the plugin to a site, with the default options.

Parameter
siteThe site.
registerWith (configure: MotionOptions -> MotionOptions) (site: Site) : Site

Adds the plugin to a site, with options changed by configure.

Parameter
configureChanges the default options.
siteThe site.
resolve (root: string) (path: string) : string

The full path of a document, a relative one taken from the project root.

An absolute path is returned as it is.

Parameter
rootThe site's project root.
pathThe document's path, as the options name it.
value (name: string) (key: string) (css: string) (options: MotionOptions) : MotionOptions

Replaces the hovered value of one change with a CSS value.

Defaults to the document's value.

Parameter
nameThe hover's name in the document.
keyThe property for the root element, or Layer/property for a part.
cssThe CSS value.
optionsThe options to change.