framer-motion
Version:
A simple and powerful JavaScript animation library
1 lines • 33.1 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../../../src/animation/timeline/index.ts"],"sourcesContent":["import {\n animateSingleValue,\n AnimationPlaybackControls,\n AnimationPlaybackControlsWithThen,\n AnimationScope,\n GroupAnimationWithThen,\n MotionValue,\n motionValue,\n TimelineWithFallback,\n} from \"motion-dom\"\nimport { removeItem } from \"motion-utils\"\nimport { animateSequence } from \"../animate/sequence\"\nimport { calcLabelTime } from \"../sequence/utils/calc-time\"\nimport {\n AnimationSequence,\n Segment,\n SequenceInfo,\n SequenceOptions,\n SequenceTime,\n} from \"../sequence/types\"\n\nexport type TimelineItem = Segment | Timeline\n\n/**\n * Called with the playback direction: 1 forwards, -1 backwards.\n */\nexport type TimelineCallback = (direction: 1 | -1) => void\n\nexport interface TimelineOptions extends SequenceOptions {\n /**\n * Start paused. Defaults to `true` (plays as soon as it's built).\n */\n autoplay?: boolean\n /**\n * Resolve selectors within this scope, and stop when it's torn\n * down. Pass the scope from useAnimate() in React.\n */\n scope?: AnimationScope\n /**\n * Called every frame while the playhead moves, with its time in\n * seconds within the current repeat.\n */\n onUpdate?: (time: number) => void\n /**\n * Called each time the timeline starts a repeat.\n */\n onRepeat?: () => void\n /**\n * Called instead of `onComplete` when the timeline finishes\n * playing backwards, at its start.\n */\n onReverseComplete?: () => void\n}\n\ninterface Marker {\n name: string\n time: number\n callback?: TimelineCallback\n pause?: boolean\n}\n\ninterface Entry {\n item: TimelineItem | TimelineCallback\n at?: SequenceTime\n marker?: Marker\n}\n\nlet markerId = 0\n\n/**\n * Copy a segment with a new `at`, adding a transition if it has none.\n */\nfunction withAt(segment: any[], at: SequenceTime) {\n const copy = [...segment]\n const i = typeof copy[0] === \"function\" ? Math.max(1, copy.length - 1) : 2\n copy[i] = { ...copy[i], at }\n return copy as Segment\n}\n\nconst label = (name: string, at?: SequenceTime): Segment =>\n at === undefined ? name : { name, at }\n\n/**\n * Rewind to the start and stop, so every value is back at the value it\n * started from and the next build reads those values as its origin.\n */\nfunction rewind(animation: AnimationPlaybackControls) {\n animation.pause()\n animation.time = 0\n animation.stop()\n}\n\n/**\n * A sequence that can be changed after it's created. Segments, labels,\n * callbacks, pauses and other timelines can be added, moved and removed\n * at any point, including while it plays.\n *\n * Changes are batched and applied once per microtask. Each change\n * rebuilds the underlying animations from the timeline's starting\n * values, then restores the playhead, speed and play state, so changes\n * made while playing take effect without a jump.\n */\nexport class Timeline implements AnimationPlaybackControlsWithThen {\n finished!: Promise<any>\n\n private entries: Entry[] = []\n\n private group?: GroupAnimationWithThen\n\n /**\n * Tracks the playhead in seconds. Used to fire callbacks, pauses and\n * playTo(). Only created when one of those needs it.\n */\n private clock?: MotionValue<number>\n\n private clockAnimation?: AnimationPlaybackControls\n\n /**\n * The repeat the playhead is in, to detect when it starts another.\n */\n private repeatIndex = 0\n\n private prevTime = 0\n\n private markers: Marker[] = []\n\n private labels = new Map<string, number>()\n\n private totalDuration = 0\n\n private isDirty = false\n\n private isPaused: boolean\n\n private isDone = false\n\n private isRebuilding = false\n\n private playbackSpeed = 1\n\n private stopAt?: number\n\n private parent?: Timeline\n\n private scrollTimeline?: TimelineWithFallback\n\n private detachScroll?: VoidFunction\n\n private resolveFinished!: VoidFunction\n\n /**\n * True while this plays the animations it was created with, before\n * any change compiles it as a sequence.\n */\n private isWrapped = false\n\n /**\n * `animations` are already running animations of `items`, as\n * animate() makes them. The timeline plays these until it's first\n * changed, so it costs nothing over the animations themselves until\n * then.\n */\n constructor(\n items: TimelineItem[] = [],\n private options: TimelineOptions = {},\n animations?: AnimationPlaybackControlsWithThen[]\n ) {\n this.isPaused = options.autoplay === false\n this.newFinished()\n items.forEach((item) => this.add(item))\n\n if (animations) {\n this.isDirty = false\n this.isWrapped = true\n this.group = new GroupAnimationWithThen(animations)\n this.watch()\n } else {\n /**\n * Build now, like animate(), so selectors resolve while a\n * scope is attached. Later changes are batched.\n */\n this.invalidate()\n this.flush()\n }\n\n /**\n * Register with the scope (for instance from useAnimate()) so it\n * stops when the scope is torn down.\n */\n const { scope } = options\n if (scope) {\n scope.animations.push(this)\n this.finished.then(() => removeItem(scope.animations, this))\n }\n }\n\n /**\n * Add a segment, label or timeline. `at` overrides any `at` already\n * on the segment. The item itself is the handle for `move()` and\n * `remove()`.\n */\n add(item: TimelineItem, at?: SequenceTime) {\n if (item instanceof Timeline) item.adopt(this)\n return this.push({ item, at })\n }\n\n /**\n * Fire a callback when the playhead crosses `at`, in either direction.\n * It receives the direction: 1 forwards, -1 backwards.\n */\n call(callback: TimelineCallback, at?: SequenceTime) {\n return this.push({\n item: callback,\n at,\n marker: { name: \"_m\" + markerId++, time: 0, callback },\n })\n }\n\n /**\n * Pause when the playhead reaches `at`.\n */\n addPause(at?: SequenceTime, callback?: TimelineCallback) {\n return this.push({\n item: callback || {},\n at,\n marker: { name: \"_m\" + markerId++, time: 0, callback, pause: true },\n } as Entry)\n }\n\n /**\n * Change where an item starts.\n */\n move(item: TimelineItem | TimelineCallback, at: SequenceTime) {\n this.entries.forEach((entry) => {\n if (entry.item === item) entry.at = at\n })\n return this.invalidate()\n }\n\n /**\n * Remove a segment, label, callback or timeline.\n */\n remove(item: TimelineItem | TimelineCallback) {\n if (item instanceof Timeline) item.parent = undefined\n this.entries = this.entries.filter((entry) => entry.item !== item)\n return this.invalidate()\n }\n\n clear() {\n this.entries = []\n return this.invalidate()\n }\n\n /**\n * The time of a label in seconds, or `undefined` if there's no label\n * with this name.\n */\n getLabelTime(name: string) {\n this.flush()\n return this.labels.get(name)\n }\n\n /**\n * Jump to a time in seconds or a label.\n */\n seek(position: SequenceTime) {\n this.time = this.resolve(position)\n return this\n }\n\n /**\n * Play forwards or backwards to a time or label, then pause there.\n */\n playTo(position: SequenceTime) {\n const target = this.resolve(position)\n const speed = Math.abs(this.speed)\n this.speed = target < this.time ? -speed : speed\n this.stopAt = target\n this.clock || this.invalidate()\n this.play()\n return this\n }\n\n reverse() {\n this.speed = -this.speed\n this.play()\n return this\n }\n\n get progress() {\n return this.duration ? this.time / this.duration : 0\n }\n\n set progress(progress: number) {\n this.time = progress * this.duration\n }\n\n get time() {\n return this.active()?.time ?? 0\n }\n\n set time(time: number) {\n this.flush()\n this.prevTime = time\n this.group && (this.group.time = time)\n this.repeatIndex = this.currentRepeat()\n }\n\n get speed() {\n return this.playbackSpeed\n }\n\n set speed(speed: number) {\n this.playbackSpeed = speed\n this.group && (this.group.speed = speed)\n }\n\n get duration() {\n this.flush()\n return this.isWrapped ? this.group!.duration : this.totalDuration\n }\n\n get iterationDuration() {\n this.flush()\n return this.isWrapped\n ? this.group!.iterationDuration\n : this.totalDuration\n }\n\n get state() {\n return this.active()?.state ?? \"idle\"\n }\n\n get startTime() {\n return this.active()?.startTime ?? null\n }\n\n play() {\n this.flush()\n this.isPaused = false\n this.group?.play()\n\n /**\n * Watch after playing, so it waits for the restarted animations\n * rather than the ones that already finished.\n */\n if (this.isDone) {\n this.newFinished()\n this.watch()\n }\n }\n\n pause() {\n this.flush()\n this.isPaused = true\n this.group?.pause()\n }\n\n stop = () => {\n this.flush()\n this.group?.stop()\n }\n\n cancel() {\n this.flush()\n this.group?.cancel()\n }\n\n complete() {\n this.flush()\n this.group?.complete()\n }\n\n attachTimeline(timeline: TimelineWithFallback) {\n this.flush()\n this.scrollTimeline = timeline\n this.detachScroll = this.group?.attachTimeline(timeline)\n\n return () => {\n this.scrollTimeline = undefined\n this.detachScroll?.()\n }\n }\n\n then(onResolve: VoidFunction, onReject?: VoidFunction) {\n return this.finished.then(onResolve, onReject)\n }\n\n /**\n * The current animations, if any are running. Skipped animations\n * (skipAnimations, reduced motion) can leave the group empty.\n */\n private active() {\n this.flush()\n return this.group?.animations.length ? this.group : undefined\n }\n\n private push(entry: Entry) {\n this.entries.push(entry)\n return this.invalidate()\n }\n\n /**\n * Schedule a rebuild. A nested timeline passes changes up, as it's\n * built as part of its parent.\n */\n private invalidate(): this {\n if (this.parent) {\n this.parent.invalidate()\n } else if (!this.isDirty) {\n this.isDirty = true\n queueMicrotask(() => this.flush())\n }\n return this\n }\n\n /**\n * Apply pending changes now, so reads straight after a change\n * reflect it.\n */\n private flush() {\n this.isDirty && !this.parent && this.build()\n }\n\n private adopt(parent: Timeline) {\n if (this.group) {\n rewind(this.group)\n this.group = undefined\n }\n this.isDirty = false\n this.parent = parent\n }\n\n private build() {\n this.isDirty = false\n this.isWrapped = false\n\n const prev = this.group\n let time = 0\n\n if (prev) {\n this.isRebuilding = true\n if (this.scrollTimeline) {\n /**\n * Scroll-linked animations can't be seeked in seconds.\n * Cancelling also returns them to their starting values,\n * and the new build is attached to scroll instead.\n */\n this.detachScroll?.()\n prev.cancel()\n } else {\n time = prev.animations.length ? prev.time : 0\n rewind(prev)\n }\n this.isRebuilding = false\n }\n\n const {\n defaultTransition,\n onComplete,\n onUpdate,\n onRepeat,\n onReverseComplete,\n autoplay,\n scope,\n ...options\n } = this.options\n\n /**\n * Inherit MotionConfig settings from a useAnimate() scope.\n */\n const playback: SequenceOptions = {}\n if (scope?.reduceMotion !== undefined) {\n playback.reduceMotion = scope.reduceMotion\n }\n if (scope?.skipAnimations !== undefined) {\n playback.skipAnimations = scope.skipAnimations\n }\n Object.assign(playback, options)\n const markers = new Map<string, Marker>()\n const info: SequenceInfo = {}\n const animations = animateSequence(\n this.toSequence(markers),\n { defaultTransition, ...playback },\n scope,\n info\n )\n\n const labels = info.labels!\n let duration = playback.duration ?? info.duration!\n\n /**\n * A `duration` option stretches every animation to fit, so scale\n * label and marker times to match.\n */\n const scale = info.duration ? duration / info.duration : 1\n labels.forEach((time, name) => labels.set(name, time * scale))\n\n /**\n * Markers are resolved as labels. Move them out of the label map\n * and extend the duration to reach any marker past the end.\n */\n this.markers = []\n markers.forEach((marker, name) => {\n marker.time = labels.get(name)!\n labels.delete(name)\n duration = Math.max(duration, marker.time)\n this.markers.push(marker)\n })\n this.markers.sort((a, b) => a.time - b.time)\n this.labels = labels\n this.totalDuration = duration\n\n /**\n * Callbacks, pauses and playTo() watch a linear clock. Without\n * them, the timeline is only its animations.\n */\n this.clock = this.clockAnimation = undefined\n if (\n this.markers.length ||\n this.stopAt !== undefined ||\n onUpdate ||\n onRepeat\n ) {\n const clock = (this.clock = motionValue(0))\n clock.on(\"change\", (t) => clock === this.clock && this.onClock(t))\n animations.unshift(\n (this.clockAnimation = animateSingleValue(\n clock,\n [0, duration],\n {\n ...playback,\n duration,\n ease: \"linear\",\n }\n ))\n )\n }\n\n const group = (this.group = new GroupAnimationWithThen(animations))\n\n time = Math.min(time, duration)\n if (this.isDone && time < duration) this.newFinished()\n\n if (this.scrollTimeline) {\n this.detachScroll = group.attachTimeline(this.scrollTimeline)\n } else {\n group.speed = this.playbackSpeed\n if (this.isPaused) group.pause()\n if (time) group.time = time\n }\n this.repeatIndex = this.currentRepeat()\n /**\n * Treat a start from 0 as coming from just before it, so markers\n * at 0 fire.\n */\n this.prevTime = time || -1\n\n this.watch()\n }\n\n private toSequence(markers: Map<string, Marker>): AnimationSequence {\n return this.entries.map(({ item, at, marker }) => {\n if (marker) {\n markers.set(marker.name, marker)\n return label(marker.name, at)\n }\n if (item instanceof Timeline) {\n return { sequence: item.toSequence(markers), at }\n }\n if (typeof item === \"string\") return label(item, at)\n if (at === undefined) return item as Segment\n return Array.isArray(item)\n ? withAt(item, at)\n : ({ ...item, at } as Segment)\n })\n }\n\n private resolve(position: SequenceTime) {\n this.flush()\n return typeof position === \"number\"\n ? position\n : calcLabelTime(position, this.labels) ?? this.time\n }\n\n /**\n * The repeat the clock is in, from its time across all repeats.\n */\n private currentRepeat() {\n const { repeat = 0, repeatDelay = 0, delay = 0 } = this.options\n const cycle = this.totalDuration + repeatDelay\n const time = (this.clockAnimation?.time ?? 0) - delay\n return cycle && time > 0\n ? Math.min(repeat, Math.floor(time / cycle))\n : 0\n }\n\n private onClock(time: number) {\n let prevTime = this.prevTime\n this.prevTime = time\n if (this.isRebuilding) return\n\n const { onUpdate, onRepeat, repeatType = \"loop\" } = this.options\n onUpdate?.(time)\n\n const repeatIndex = this.currentRepeat()\n if (repeatIndex !== this.repeatIndex) {\n this.repeatIndex = repeatIndex\n onRepeat?.()\n\n /**\n * A loop jumps the playhead back to the start, or to the\n * end when playing backwards. Finish crossing the repeat\n * that ended, then cross the new one from its edge.\n */\n if (repeatType === \"loop\") {\n const isForward = this.speed > 0\n if (this.cross(prevTime, isForward ? this.totalDuration : 0)) {\n return\n }\n prevTime = isForward ? -1 : Infinity\n }\n }\n\n this.cross(prevTime, time)\n }\n\n /**\n * Fire markers between two playhead times. Returns `true` if it\n * paused.\n */\n private cross(from: number, to: number) {\n if (from === to) return\n\n const isForward = to > from\n const crossed = (t: number) =>\n isForward ? t > from && t <= to : t < from && t >= to\n\n const markers = isForward ? this.markers : [...this.markers].reverse()\n for (const marker of markers) {\n if (!crossed(marker.time)) continue\n marker.callback?.(isForward ? 1 : -1)\n if (marker.pause) return this.pauseAt(marker.time)\n }\n\n if (this.stopAt !== undefined && crossed(this.stopAt)) {\n this.pauseAt(this.stopAt)\n this.stopAt = undefined\n return true\n }\n }\n\n private pauseAt(time: number) {\n this.pause()\n this.time = time\n return true\n }\n\n private watch() {\n const group = this.group!\n group.finished.then(() => {\n if (group !== this.group || this.isDone) return\n this.isDone = true\n const { onComplete, onReverseComplete } = this.options\n /**\n * Without onReverseComplete, onComplete fires in either\n * direction, as it does for a single animation.\n */\n const callback =\n (this.speed < 0 && onReverseComplete) || onComplete\n callback?.()\n this.resolveFinished()\n })\n }\n\n private newFinished() {\n this.isDone = false\n this.finished = new Promise<void>((resolve) => {\n this.resolveFinished = resolve\n })\n }\n}\n"],"names":[],"mappings":";;;;;AAmEA,IAAI,QAAQ,GAAG,CAAC;AAEhB;;AAEG;AACH,SAAS,MAAM,CAAC,OAAc,EAAE,EAAgB,EAAA;AAC5C,IAAA,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC;AACzB,IAAA,MAAM,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,UA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