Utils
This is a big hodge-podge of helper functions. Several of these arguably do not belong in this library, but we have chosen author convenience over library slimness. You will probably only need animation, authoring, interactivity, misc, and mobile.
Utils.animation
#
animate()
#
replay()
#
Utils.authoring
#
during()
#
Returns a CSS block to show the element only when marker name begins with prefix
.
#
Examplefrom()
#
Returns a CSS block to show the element when marker is in [first, last).
showIf()
#
Utils.interactivity
#
dragHelper()
#
dragHelperReact()
#
Utils.media
#
awaitMediaCanPlay()
#
awaitMediaCanPlayThrough()
#
Utils.misc
#
A bunch of little functions that should be part of core Javascript, but aren't.
between()
#
Equivalent to (min <= val) && (val < max)
.
bind()
#
Bind methods of an object to the object, so that this
behaves as expected. This is mainly for code using class components rather than Hooks.
constrain()
#
Equivalent to Math.min(max, Math.max(min, val))
.
range()
#
Returns [0, ..., n-1]
wait()
#
Returns a Promise that resolves in time
milliseconds.
waitFor()
#
Returns a Promise that resolves once callback
returns true.
Utils.mobile
#
Utilities for ensuring compatibility with mobile devices.
anyHover
#
Whether any available input mechanism can hover over elements. This is often used as a standin for desktop/mobile.
onClick()
#
Drop-in replacement for onClick handlers which works better on mobile.
attachClickHandler()
#
Replacement for addEventListener("click") which works better on mobile.
Returns a function to remove the event listener.
Utils.react
#
useForceUpdate()
#
A forceUpdate() function.
recursiveMap()
#
Used internally by IdMap; you probably shouldn't use it.
Utils.replayData
#
concat()
#
length()
#
Utils.time
#
Utilities for manipulating time strings, e.g. 1:44.23
.
timeRegexp
#
The regular expression used internally by parseTime()
. Equal to /^(?:(?:(\d+):)?(\d+):)?(\d+)(?:\.(\d+))?$/
.
parseTime()
#
Parses a time in hh:mm:ss.ms
format to milliseconds. Hours, minutes, and milliseconds can be omitted if 0.
formatTime()
#
Format a time (given in milliseconds) as hh:mm:ss
.
formatTimeMs()
#
Format a time (given in milliseconds) as hh:mm:ss.ms
.