motion-dom 13.1.1 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3062,7 +3062,7 @@ declare namespace spring {
3062
3062
  * to prevent infinite loops
3063
3063
  */
3064
3064
  declare const maxGeneratorDuration = 20000;
3065
- declare function calcGeneratorDuration(generator: KeyframeGenerator<unknown>): number;
3065
+ declare function calcGeneratorDuration<T>(generator: KeyframeGenerator<T>, timeStep?: number, maxDuration?: number, keyframes?: T[]): number;
3066
3066
 
3067
3067
  /**
3068
3068
  * Create a progress => progress easing function from a generator.
@@ -3131,22 +3131,87 @@ declare function applyGeneratorOptions({ type, ...options }: ValueTransition): V
3131
3131
  declare const generateLinearEasing: (easing: EasingFunction, duration: number, resolution?: number) => string;
3132
3132
 
3133
3133
  declare class MotionValueState {
3134
+ private step;
3134
3135
  latest: {
3135
3136
  [name: string]: AnyResolvedKeyframe;
3136
3137
  };
3137
3138
  private values;
3138
- set(name: string, value: MotionValue, render?: VoidFunction, computed?: MotionValue, useDefaultValueType?: boolean): () => void;
3139
+ /**
3140
+ * @param step - The frameloop step renders are scheduled in. Defaults
3141
+ * to `frame.render`. Effects that feed a render loop running in
3142
+ * `frame.render` (GPU scenes) should write in `frame.preRender`.
3143
+ */
3144
+ constructor(step?: Schedule);
3145
+ set(name: string, value: MotionValue, render?: VoidFunction, computed?: MotionValue, useDefaultValueType?: boolean): VoidFunction;
3139
3146
  get(name: string): MotionValue | undefined;
3140
3147
  }
3141
3148
 
3142
- declare const addAttrValue: (element: HTMLElement | SVGElement, state: MotionValueState, key: string, value: MotionValue) => () => void;
3149
+ /**
3150
+ * Returns true if the effect knows how to write to `subject`.
3151
+ */
3152
+ type EffectTest<Subject extends object> = (subject: unknown) => subject is Subject;
3153
+ /**
3154
+ * Reads the current value of `key` from `subject`, used as the initial
3155
+ * keyframe when `animate()` creates a motion value for the subject.
3156
+ * Returns `undefined` when the value can't be read.
3157
+ *
3158
+ * `keyframes` is the target being animated to, so effects can match
3159
+ * the format of the initial value (for instance color vs numeric).
3160
+ */
3161
+ type EffectRead<Subject extends object> = (subject: Subject, key: string, keyframes?: UnresolvedValueKeyframe | UnresolvedValueKeyframe[]) => AnyResolvedKeyframe | undefined;
3162
+ interface EffectOptions<Subject extends object> {
3163
+ test?: EffectTest<Subject>;
3164
+ read?: EffectRead<Subject>;
3165
+ /**
3166
+ * Frameloop step writes are scheduled in. Defaults to `frame.render`.
3167
+ */
3168
+ step?: Schedule;
3169
+ }
3170
+ interface Effect<Subject extends object = object> extends EffectOptions<Subject> {
3171
+ (subject: Subject, values: Record<string, MotionValue>): VoidFunction;
3172
+ /**
3173
+ * Returns the motion value currently bound to `key` on `subject`, if any.
3174
+ */
3175
+ get(subject: Subject, key: string): MotionValue | undefined;
3176
+ }
3177
+ /**
3178
+ * An effect that can be registered with `animate.addEffect()`.
3179
+ */
3180
+ interface AnimateEffect<Subject extends object = object> extends Effect<Subject> {
3181
+ test: EffectTest<Subject>;
3182
+ read: EffectRead<Subject>;
3183
+ }
3184
+ type AddEffectValue<Subject extends object> = (subject: Subject, state: MotionValueState, key: string, value: MotionValue) => VoidFunction;
3185
+ declare function createEffect<Subject extends object>(addValue: AddEffectValue<Subject>, options: EffectOptions<Subject> & {
3186
+ test: EffectTest<Subject>;
3187
+ read: EffectRead<Subject>;
3188
+ }): AnimateEffect<Subject>;
3189
+ declare function createEffect<Subject extends object>(addValue: AddEffectValue<Subject>, options?: EffectOptions<Subject>): Effect<Subject>;
3190
+
3191
+ declare function addEffect(effect: AnimateEffect<any>): void;
3192
+ declare function removeEffect(effect: AnimateEffect<any>): void;
3193
+ declare function findEffect(subject: unknown): AnimateEffect | undefined;
3194
+ type EffectKeyframes = Record<string, UnresolvedValueKeyframe | UnresolvedValueKeyframe[]>;
3195
+ /**
3196
+ * Effect subjects can expose any key, so per-key transition overrides
3197
+ * are keyed by arbitrary strings.
3198
+ */
3199
+ type EffectTransition = ValueAnimationTransition & Record<string, unknown>;
3200
+ /**
3201
+ * Animate the keys of `subject` via `effect`. Motion values are created on
3202
+ * first animation, seeded from `effect.read()` or the first keyframe, and
3203
+ * then bound to the subject via the effect for the rest of its life.
3204
+ */
3205
+ declare function animateEffectSubject<Subject extends object>(effect: AnimateEffect<Subject>, subject: Subject, keyframes: EffectKeyframes, transition?: EffectTransition): AnimationPlaybackControlsWithThen[];
3206
+
3207
+ declare const addAttrValue: (element: HTMLElement | SVGElement, state: MotionValueState, key: string, value: MotionValue) => VoidFunction;
3143
3208
  declare const attrEffect: (subject: ElementOrSelector, values: Record<string, MotionValue<any>>) => () => void;
3144
3209
 
3145
- declare const propEffect: (subject: {
3210
+ declare const propEffect: Effect<{
3146
3211
  [key: string]: any;
3147
- }, values: Record<string, MotionValue<any>>) => VoidFunction;
3212
+ }>;
3148
3213
 
3149
- declare const addStyleValue: (element: HTMLElement | SVGElement, state: MotionValueState, key: string, value: MotionValue) => () => void;
3214
+ declare const addStyleValue: (element: HTMLElement | SVGElement, state: MotionValueState, key: string, value: MotionValue) => VoidFunction;
3150
3215
  declare const styleEffect: (subject: ElementOrSelector, values: Record<string, MotionValue<any>>) => () => void;
3151
3216
 
3152
3217
  declare const svgEffect: (subject: ElementOrSelector, values: Record<string, MotionValue<any>>) => () => void;
@@ -5290,4 +5355,4 @@ declare const sync: Batcher;
5290
5355
  */
5291
5356
  declare const cancelSync: Record<string, (process: Process) => void>;
5292
5357
 
5293
- export { type AccelerateConfig, type AcceptedAnimations, type ActiveStatsBuffer, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationList, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState$1 as AnimationState, type AnimationType, type AnimationTypeState, type AnyResolvedKeyframe, type ArcOptions, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, DOMVisualElement, type DOMVisualElementOptions, type DecayOptions, type DelayedFunction, DocumentProjectionNode, type DragElastic, type DragHandler, type DraggableProps, type DurationSpringOptions, type DynamicOption, type ElementOrSelector, type EventInfo, type EventOptions, Feature, type FeatureClass, FlatTree, type FollowValueOptions, type FrameData, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, HTMLProjectionNode, type HTMLRenderState, HTMLVisualElement, type HandoffFunction, type IProjectionNode, type InactiveStatsBuffer, type InertiaOptions, type InitialPromotionConfig, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, LayoutAnimationBuilder, type LayoutEvents, type LayoutLifecycles, type LayoutProjectionMetrics, type LayoutProjectionStats, type LayoutUpdateData, type LayoutUpdateHandler, type LegacyAnimationControls, type MapInputRange, type Measurements, type Mixer, type MixerFactory, type MotionConfigContextProps, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, type MotionPath, type MotionStyle, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NodeGroup, NodeStack, type NumberMap, ObjectVisualElement, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, type PassiveEffect, type PathInterpolator, type PathState, type Phase, type Point2D, type PointerEventOptions, type PresenceContextProps, type PressGestureInfo, type Process, type ProgressTimeline, type ProjectionEventName, type ProjectionNodeConfig, type ProjectionNodeOptions, type PropagateOptions, type RGBA, type ReducedMotionConfig, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues$1 as ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGRenderState, type SVGTransitions, SVGVisualElement, type ScaleCorrectionNode, type ScaleCorrector, type ScaleCorrectorDefinition, type ScaleCorrectorMap, type Schedule, type ScrapeMotionValuesFromProps, type ScrollMeasurements, type SelectorCache, type SingleTransformer, type Spring, type SpringOptions, type StaggerOptions, type StaggerOrigin, type StartAnimation, type StatsRecording, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type TapHandlers, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformOrigin, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type TransitionWithValueOverrides, type Tween, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type UseRenderState, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueAnimationWithDynamicDelay, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewTransitionTargetDefinition, type ViewportEventHandler, type ViewportOptions, VisualElement, type VisualElementAnimationOptions, type VisualElementEventCallbacks, type VisualElementOptions, type VisualState, type WillChange, type WithAppearProps, type WithDepth, type WithQuerySelectorAll, acceleratedValues, addAttrValue, addDomEvent, addScaleCorrector, addStyleValue, addValueToWillChange, alpha, analyseComplexValue, animateMotionValue, animateSingleValue, animateTarget, animateValue, animateVariant, animateView, animateVisualElement, animationMapKey, applyAxisDelta, applyBoxDelta, applyGeneratorOptions, applyPointDelta, applyPxDefaults, applyTreeDeltas, arc, aspectRatio, attachFollow, attachSpring, attrEffect, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, buildHTMLStyles, buildProjectionTransform, buildSVGAttrs, buildSVGPath, buildTransform, calcAxisDelta, calcBoxDelta, calcChildStagger, calcGeneratorDuration, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, camelCaseAttributes, camelToDash, cancelFrame, cancelMicrotask, cancelSync, checkVariantsDidChange, cleanDirtyNodes, collectMotionValues, color, compareByDepth, complex, containsCSSVariable, convertBoundingBoxToBox, convertBoxToBoundingBox, convertOffsetToTimes, copyAxisDeltaInto, copyAxisInto, copyBoxInto, correctBorderRadius, correctBoxShadow, createAnimationState, createAxis, createAxisDelta, createBox, createDelta, createGeneratorEasing, createProjectionNode, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, delay, delayInSeconds, dimensionValueTypes, eachAxis, fillOffset, fillWildcards, findDimensionValueType, findValueType, flushKeyframeResolvers, followValue, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultTransition, getDefaultValueType, getFeatureDefinitions, getFinalKeyframe, getMixer, getOptimisedAppearId, getOriginIndex, getValueAsType, getValueTransition, getVariableValue, getVariantContext, getViewAnimationLayerInfo, getViewAnimations, globalProjectionState, has2DTranslate, hasReducedMotionListener, hasScale, hasTransform, hex, hover, hsla, hslaToRgba, inertia, initPrefersReducedMotion, interpolate, invisibleValues, isAnimationControls, isCSSVariableName, isCSSVariableToken, isControllingVariants, isDeltaZero, isDragActive, isDragging, isElementKeyboardAccessible, isElementTextInput, isForcedMotionValue, isGenerator, isHTMLElement, isKeyframesTarget, isMotionValue, isNear, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isSVGTag, isTransitionDefined, isVariantLabel, isVariantNode, isWaapiSupportedEasing, isWillChangeMotionValue, keyframes, makeAnimationInstant, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, measurePageBox, measureViewportBox, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixValues, mixVisibility, motionValue, nodeGroup, number, numberValueTypes, observeTimeline, optimizedAppearDataAttribute, optimizedAppearDataId, parseAnimateLayoutArgs, parseCSSVariable, parseValueFromTransform, percent, pixelsToPercent, positionalKeys, prefersReducedMotion, press, progressPercentage, propEffect, propagateDirtyNodes, px, readTransformValue, recordStats, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removePointDelta, renderHTML, renderSVG, resize, resolveElements, resolveMotionValue, resolveTransition, resolveVariant, resolveVariantFromProps, rgbUnit, rgba, rootProjectionNode, scale, scaleCorrectors, scalePoint, scrapeMotionValuesFromProps$1 as scrapeHTMLMotionValuesFromProps, scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps, setDragLock, setFeatureDefinitions, setStyle, setTarget, spring, springValue, stagger, startWaapiAnimation, statsBuffer, styleEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, supportsViewTimeline, svgEffect, sync, testValueType, time, transform, transformAxis, transformBox, transformBoxPoints, transformPropOrder, transformProps, transformValue, transformValueTypes, translateAxis, updateMotionValuesFromProps, variantPriorityOrder, variantProps, vh, visualElementStore, vw };
5358
+ export { type AccelerateConfig, type AcceptedAnimations, type ActiveStatsBuffer, type AddEffectValue, type AnimateEffect, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationList, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState$1 as AnimationState, type AnimationType, type AnimationTypeState, type AnyResolvedKeyframe, type ArcOptions, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, DOMVisualElement, type DOMVisualElementOptions, type DecayOptions, type DelayedFunction, DocumentProjectionNode, type DragElastic, type DragHandler, type DraggableProps, type DurationSpringOptions, type DynamicOption, type Effect, type EffectKeyframes, type EffectOptions, type EffectRead, type EffectTest, type EffectTransition, type ElementOrSelector, type EventInfo, type EventOptions, Feature, type FeatureClass, FlatTree, type FollowValueOptions, type FrameData, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, HTMLProjectionNode, type HTMLRenderState, HTMLVisualElement, type HandoffFunction, type IProjectionNode, type InactiveStatsBuffer, type InertiaOptions, type InitialPromotionConfig, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, LayoutAnimationBuilder, type LayoutEvents, type LayoutLifecycles, type LayoutProjectionMetrics, type LayoutProjectionStats, type LayoutUpdateData, type LayoutUpdateHandler, type LegacyAnimationControls, type MapInputRange, type Measurements, type Mixer, type MixerFactory, type MotionConfigContextProps, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, type MotionPath, type MotionStyle, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, MotionValueState, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NodeGroup, NodeStack, type NumberMap, ObjectVisualElement, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, type PassiveEffect, type PathInterpolator, type PathState, type Phase, type Point2D, type PointerEventOptions, type PresenceContextProps, type PressGestureInfo, type Process, type ProgressTimeline, type ProjectionEventName, type ProjectionNodeConfig, type ProjectionNodeOptions, type PropagateOptions, type RGBA, type ReducedMotionConfig, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues$1 as ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGRenderState, type SVGTransitions, SVGVisualElement, type ScaleCorrectionNode, type ScaleCorrector, type ScaleCorrectorDefinition, type ScaleCorrectorMap, type Schedule, type ScrapeMotionValuesFromProps, type ScrollMeasurements, type SelectorCache, type SingleTransformer, type Spring, type SpringOptions, type StaggerOptions, type StaggerOrigin, type StartAnimation, type StatsRecording, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type TapHandlers, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformOrigin, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type TransitionWithValueOverrides, type Tween, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type UseRenderState, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueAnimationWithDynamicDelay, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewTransitionTargetDefinition, type ViewportEventHandler, type ViewportOptions, VisualElement, type VisualElementAnimationOptions, type VisualElementEventCallbacks, type VisualElementOptions, type VisualState, type WillChange, type WithAppearProps, type WithDepth, type WithQuerySelectorAll, acceleratedValues, addAttrValue, addDomEvent, addEffect, addScaleCorrector, addStyleValue, addValueToWillChange, alpha, analyseComplexValue, animateEffectSubject, animateMotionValue, animateSingleValue, animateTarget, animateValue, animateVariant, animateView, animateVisualElement, animationMapKey, applyAxisDelta, applyBoxDelta, applyGeneratorOptions, applyPointDelta, applyPxDefaults, applyTreeDeltas, arc, aspectRatio, attachFollow, attachSpring, attrEffect, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, buildHTMLStyles, buildProjectionTransform, buildSVGAttrs, buildSVGPath, buildTransform, calcAxisDelta, calcBoxDelta, calcChildStagger, calcGeneratorDuration, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, camelCaseAttributes, camelToDash, cancelFrame, cancelMicrotask, cancelSync, checkVariantsDidChange, cleanDirtyNodes, collectMotionValues, color, compareByDepth, complex, containsCSSVariable, convertBoundingBoxToBox, convertBoxToBoundingBox, convertOffsetToTimes, copyAxisDeltaInto, copyAxisInto, copyBoxInto, correctBorderRadius, correctBoxShadow, createAnimationState, createAxis, createAxisDelta, createBox, createDelta, createEffect, createGeneratorEasing, createProjectionNode, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, delay, delayInSeconds, dimensionValueTypes, eachAxis, fillOffset, fillWildcards, findDimensionValueType, findEffect, findValueType, flushKeyframeResolvers, followValue, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultTransition, getDefaultValueType, getFeatureDefinitions, getFinalKeyframe, getMixer, getOptimisedAppearId, getOriginIndex, getValueAsType, getValueTransition, getVariableValue, getVariantContext, getViewAnimationLayerInfo, getViewAnimations, globalProjectionState, has2DTranslate, hasReducedMotionListener, hasScale, hasTransform, hex, hover, hsla, hslaToRgba, inertia, initPrefersReducedMotion, interpolate, invisibleValues, isAnimationControls, isCSSVariableName, isCSSVariableToken, isControllingVariants, isDeltaZero, isDragActive, isDragging, isElementKeyboardAccessible, isElementTextInput, isForcedMotionValue, isGenerator, isHTMLElement, isKeyframesTarget, isMotionValue, isNear, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isSVGTag, isTransitionDefined, isVariantLabel, isVariantNode, isWaapiSupportedEasing, isWillChangeMotionValue, keyframes, makeAnimationInstant, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, measurePageBox, measureViewportBox, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixValues, mixVisibility, motionValue, nodeGroup, number, numberValueTypes, observeTimeline, optimizedAppearDataAttribute, optimizedAppearDataId, parseAnimateLayoutArgs, parseCSSVariable, parseValueFromTransform, percent, pixelsToPercent, positionalKeys, prefersReducedMotion, press, progressPercentage, propEffect, propagateDirtyNodes, px, readTransformValue, recordStats, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removeEffect, removePointDelta, renderHTML, renderSVG, resize, resolveElements, resolveMotionValue, resolveTransition, resolveVariant, resolveVariantFromProps, rgbUnit, rgba, rootProjectionNode, scale, scaleCorrectors, scalePoint, scrapeMotionValuesFromProps$1 as scrapeHTMLMotionValuesFromProps, scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps, setDragLock, setFeatureDefinitions, setStyle, setTarget, spring, springValue, stagger, startWaapiAnimation, statsBuffer, styleEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, supportsViewTimeline, svgEffect, sync, testValueType, time, transform, transformAxis, transformBox, transformBoxPoints, transformPropOrder, transformProps, transformValue, transformValueTypes, translateAxis, updateMotionValuesFromProps, variantPriorityOrder, variantProps, vh, visualElementStore, vw };
@@ -736,15 +736,16 @@
736
736
  * to prevent infinite loops
737
737
  */
738
738
  const maxGeneratorDuration = 20000;
739
- function calcGeneratorDuration(generator) {
739
+ function calcGeneratorDuration(generator, timeStep = 50, maxDuration = maxGeneratorDuration, keyframes) {
740
740
  let duration = 0;
741
- const timeStep = 50;
742
741
  let state = generator.next(duration);
743
- while (!state.done && duration < maxGeneratorDuration) {
742
+ keyframes?.push(state.value);
743
+ while (!state.done && duration < maxDuration) {
744
744
  duration += timeStep;
745
745
  state = generator.next(duration);
746
+ keyframes?.push(state.value);
746
747
  }
747
- return duration >= maxGeneratorDuration ? Infinity : duration;
748
+ return duration >= maxDuration ? Infinity : duration;
748
749
  }
749
750
 
750
751
  /**
@@ -828,9 +829,13 @@
828
829
  const exponentialDecay = undampedFreq * dampingRatio;
829
830
  const delta = exponentialDecay * duration;
830
831
  const d = delta * velocity + velocity;
831
- const e = Math.pow(dampingRatio, 2) * Math.pow(undampedFreq, 2) * duration;
832
+ const e = dampingRatio *
833
+ dampingRatio *
834
+ undampedFreq *
835
+ undampedFreq *
836
+ duration;
832
837
  const f = Math.exp(-delta);
833
- const g = calcAngularFreq(Math.pow(undampedFreq, 2), dampingRatio);
838
+ const g = calcAngularFreq(undampedFreq * undampedFreq, dampingRatio);
834
839
  const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1;
835
840
  return (factor * ((d - e) * f)) / g;
836
841
  };
@@ -861,7 +866,7 @@
861
866
  };
862
867
  }
863
868
  else {
864
- const stiffness = Math.pow(undampedFreq, 2) * mass;
869
+ const stiffness = undampedFreq * undampedFreq * mass;
865
870
  return {
866
871
  stiffness,
867
872
  damping: dampingRatio * 2 * Math.sqrt(mass * stiffness),
@@ -941,6 +946,7 @@
941
946
  const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
942
947
  const initialDelta = target - origin;
943
948
  const undampedAngularFreq = motionUtils.millisecondsToSeconds(Math.sqrt(stiffness / mass));
949
+ const decay = dampingRatio * undampedAngularFreq;
944
950
  /**
945
951
  * If we're working on a granular scale, use smaller defaults for determining
946
952
  * when the spring is finished.
@@ -957,35 +963,38 @@
957
963
  : springDefaults.restDelta.default);
958
964
  let resolveSpring;
959
965
  let resolveVelocity;
960
- // Underdamped coefficients, hoisted for use in the inlined next() hot path
961
- let angularFreq;
962
- let A;
963
- let sinCoeff;
964
- let cosCoeff;
965
966
  if (dampingRatio < 1) {
966
- angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
967
- A =
968
- (initialVelocity +
969
- dampingRatio * undampedAngularFreq * initialDelta) /
970
- angularFreq;
967
+ const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
968
+ const A = (initialVelocity + decay * initialDelta) / angularFreq;
969
+ // Coefficients for the analytical derivative (px/ms)
970
+ const sinCoeff = decay * A + initialDelta * angularFreq;
971
+ const cosCoeff = decay * initialDelta - A * angularFreq;
972
+ /**
973
+ * The underdamped hot path needs both position and velocity every
974
+ * frame and they share the same exp/sin/cos terms, so sample both
975
+ * at once, memoized by t, to only calculate them once per frame.
976
+ */
977
+ let sampledT = -1;
978
+ let position = 0;
979
+ let velocityAtT = 0;
980
+ const sample = (t) => {
981
+ if (t !== sampledT) {
982
+ sampledT = t;
983
+ const envelope = Math.exp(-decay * t);
984
+ const sin = Math.sin(angularFreq * t);
985
+ const cos = Math.cos(angularFreq * t);
986
+ position = target - envelope * (A * sin + initialDelta * cos);
987
+ velocityAtT = envelope * (sinCoeff * sin + cosCoeff * cos);
988
+ }
989
+ };
971
990
  // Underdamped spring
972
991
  resolveSpring = (t) => {
973
- const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
974
- return (target -
975
- envelope *
976
- (A * Math.sin(angularFreq * t) +
977
- initialDelta * Math.cos(angularFreq * t)));
992
+ sample(t);
993
+ return position;
978
994
  };
979
- // Analytical derivative of underdamped spring (px/ms)
980
- sinCoeff =
981
- dampingRatio * undampedAngularFreq * A + initialDelta * angularFreq;
982
- cosCoeff =
983
- dampingRatio * undampedAngularFreq * initialDelta - A * angularFreq;
984
995
  resolveVelocity = (t) => {
985
- const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
986
- return envelope *
987
- (sinCoeff * Math.sin(angularFreq * t) +
988
- cosCoeff * Math.cos(angularFreq * t));
996
+ sample(t);
997
+ return velocityAtT;
989
998
  };
990
999
  }
991
1000
  else if (dampingRatio === 1) {
@@ -1003,13 +1012,12 @@
1003
1012
  // Overdamped spring
1004
1013
  const dampedAngularFreq = undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1);
1005
1014
  resolveSpring = (t) => {
1006
- const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
1015
+ const envelope = Math.exp(-decay * t);
1007
1016
  // When performing sinh or cosh values can hit Infinity so we cap them here
1008
1017
  const freqForT = Math.min(dampedAngularFreq * t, 300);
1009
1018
  return (target -
1010
1019
  (envelope *
1011
- ((initialVelocity +
1012
- dampingRatio * undampedAngularFreq * initialDelta) *
1020
+ ((initialVelocity + decay * initialDelta) *
1013
1021
  Math.sinh(freqForT) +
1014
1022
  dampedAngularFreq *
1015
1023
  initialDelta *
@@ -1017,43 +1025,21 @@
1017
1025
  dampedAngularFreq);
1018
1026
  };
1019
1027
  // Analytical derivative of overdamped spring (px/ms)
1020
- const P = (initialVelocity +
1021
- dampingRatio * undampedAngularFreq * initialDelta) /
1022
- dampedAngularFreq;
1023
- const sinhCoeff = dampingRatio * undampedAngularFreq * P - initialDelta * dampedAngularFreq;
1024
- const coshCoeff = dampingRatio * undampedAngularFreq * initialDelta - P * dampedAngularFreq;
1028
+ const P = (initialVelocity + decay * initialDelta) / dampedAngularFreq;
1029
+ const sinhCoeff = decay * P - initialDelta * dampedAngularFreq;
1030
+ const coshCoeff = decay * initialDelta - P * dampedAngularFreq;
1025
1031
  resolveVelocity = (t) => {
1026
- const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
1032
+ const envelope = Math.exp(-decay * t);
1027
1033
  const freqForT = Math.min(dampedAngularFreq * t, 300);
1028
- return envelope *
1034
+ return (envelope *
1029
1035
  (sinhCoeff * Math.sinh(freqForT) +
1030
- coshCoeff * Math.cosh(freqForT));
1036
+ coshCoeff * Math.cosh(freqForT)));
1031
1037
  };
1032
1038
  }
1033
1039
  const generator = {
1034
1040
  calculatedDuration: isResolvedFromDuration ? duration || null : null,
1035
1041
  velocity: (t) => motionUtils.secondsToMilliseconds(resolveVelocity(t)),
1036
1042
  next: (t) => {
1037
- /**
1038
- * For underdamped physics springs we need both position and
1039
- * velocity each tick. Compute shared trig values once to avoid
1040
- * duplicate Math.exp/sin/cos calls on the hot path.
1041
- */
1042
- if (!isResolvedFromDuration && dampingRatio < 1) {
1043
- const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
1044
- const sin = Math.sin(angularFreq * t);
1045
- const cos = Math.cos(angularFreq * t);
1046
- const current = target -
1047
- envelope *
1048
- (A * sin + initialDelta * cos);
1049
- const currentVelocity = motionUtils.secondsToMilliseconds(envelope *
1050
- (sinCoeff * sin + cosCoeff * cos));
1051
- state.done =
1052
- Math.abs(currentVelocity) <= restSpeed &&
1053
- Math.abs(target - current) <= restDelta;
1054
- state.value = state.done ? target : current;
1055
- return state;
1056
- }
1057
1043
  const current = resolveSpring(t);
1058
1044
  if (!isResolvedFromDuration) {
1059
1045
  const currentVelocity = motionUtils.secondsToMilliseconds(resolveVelocity(t));
@@ -1084,19 +1070,13 @@
1084
1070
  return options;
1085
1071
  };
1086
1072
 
1087
- const velocitySampleDuration = 5; // ms
1088
- function getGeneratorVelocity(resolveValue, t, current) {
1089
- const prevT = Math.max(t - velocitySampleDuration, 0);
1090
- return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
1091
- }
1092
-
1093
1073
  function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, bounceDamping = 10, bounceStiffness = 500, modifyTarget, min, max, restDelta = 0.5, restSpeed, }) {
1094
1074
  const origin = keyframes[0];
1095
1075
  const state = {
1096
1076
  done: false,
1097
1077
  value: origin,
1098
1078
  };
1099
- const isOutOfBounds = (v) => (min !== undefined && v < min) || (max !== undefined && v > max);
1079
+ const isOutOfBounds = (v) => v < min || v > max;
1100
1080
  const nearestBoundary = (v) => {
1101
1081
  if (min === undefined)
1102
1082
  return max;
@@ -1114,12 +1094,10 @@
1114
1094
  if (target !== ideal)
1115
1095
  amplitude = target - origin;
1116
1096
  const calcDelta = (t) => -amplitude * Math.exp(-t / timeConstant);
1117
- const calcLatest = (t) => target + calcDelta(t);
1118
1097
  const applyFriction = (t) => {
1119
1098
  const delta = calcDelta(t);
1120
- const latest = calcLatest(t);
1121
1099
  state.done = Math.abs(delta) <= restDelta;
1122
- state.value = state.done ? target : latest;
1100
+ state.value = state.done ? target : target + delta;
1123
1101
  };
1124
1102
  /**
1125
1103
  * Ideally this would resolve for t in a stateless way, we could
@@ -1135,7 +1113,12 @@
1135
1113
  timeReachedBoundary = t;
1136
1114
  spring$1 = spring({
1137
1115
  keyframes: [state.value, nearestBoundary(state.value)],
1138
- velocity: getGeneratorVelocity(calcLatest, t, state.value), // TODO: This should be passing * 1000
1116
+ /**
1117
+ * The friction curve is target + calcDelta(t), so its exact
1118
+ * derivative is -calcDelta(t) / timeConstant in units/ms,
1119
+ * converted here to the units/second expected by spring.
1120
+ */
1121
+ velocity: (-calcDelta(t) / timeConstant) * 1000,
1139
1122
  damping: bounceDamping,
1140
1123
  stiffness: bounceStiffness,
1141
1124
  restDelta,
@@ -1304,6 +1287,12 @@
1304
1287
  };
1305
1288
  }
1306
1289
 
1290
+ const velocitySampleDuration = 5; // ms
1291
+ function getGeneratorVelocity(resolveValue, t, current) {
1292
+ const prevT = Math.max(t - velocitySampleDuration, 0);
1293
+ return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
1294
+ }
1295
+
1307
1296
  const isNotNull = (value) => value !== null;
1308
1297
  function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
1309
1298
  const resolvedKeyframes = keyframes.filter(isNotNull);
@@ -4309,6 +4298,47 @@
4309
4298
  return true;
4310
4299
  });
4311
4300
 
4301
+ /**
4302
+ * Effects registered via `animate.addEffect()`, most recent first.
4303
+ */
4304
+ const effects = [];
4305
+ function addEffect(effect) {
4306
+ motionUtils.invariant(typeof effect.test === "function" && typeof effect.read === "function", "Effects passed to animate.addEffect() need test() and read().", "effect-missing-test");
4307
+ removeEffect(effect);
4308
+ effects.unshift(effect);
4309
+ }
4310
+ function removeEffect(effect) {
4311
+ motionUtils.removeItem(effects, effect);
4312
+ }
4313
+ function findEffect(subject) {
4314
+ return effects.find((effect) => effect.test(subject));
4315
+ }
4316
+ /**
4317
+ * Animate the keys of `subject` via `effect`. Motion values are created on
4318
+ * first animation, seeded from `effect.read()` or the first keyframe, and
4319
+ * then bound to the subject via the effect for the rest of its life.
4320
+ */
4321
+ function animateEffectSubject(effect, subject, keyframes, transition = {}) {
4322
+ const animations = [];
4323
+ for (const key in keyframes) {
4324
+ const target = keyframes[key];
4325
+ let value = effect.get(subject, key);
4326
+ if (!value) {
4327
+ const initial = effect.read(subject, key, target) ?? firstKeyframe(target);
4328
+ motionUtils.invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
4329
+ value = motionValue(initial);
4330
+ effect(subject, { [key]: value });
4331
+ }
4332
+ value.start(animateMotionValue(key, value, target, getValueTransition(transition, key)));
4333
+ value.animation && animations.push(value.animation);
4334
+ }
4335
+ return animations;
4336
+ }
4337
+ function firstKeyframe(target) {
4338
+ const first = Array.isArray(target) ? target[0] : undefined;
4339
+ return first === null ? undefined : first;
4340
+ }
4341
+
4312
4342
  function resolveElements(elementOrSelector, scope, selectorCache) {
4313
4343
  if (elementOrSelector == null) {
4314
4344
  return [];
@@ -4353,7 +4383,13 @@
4353
4383
  };
4354
4384
 
4355
4385
  class MotionValueState {
4356
- constructor() {
4386
+ /**
4387
+ * @param step - The frameloop step renders are scheduled in. Defaults
4388
+ * to `frame.render`. Effects that feed a render loop running in
4389
+ * `frame.render` (GPU scenes) should write in `frame.preRender`.
4390
+ */
4391
+ constructor(step = frame.render) {
4392
+ this.step = step;
4357
4393
  this.latest = {};
4358
4394
  this.values = new Map();
4359
4395
  }
@@ -4370,7 +4406,7 @@
4370
4406
  else {
4371
4407
  this.latest[name] = v;
4372
4408
  }
4373
- render && frame.render(render);
4409
+ render && this.step(render);
4374
4410
  };
4375
4411
  onChange();
4376
4412
  const cancelOnChange = value.on("change", onChange);
@@ -4389,10 +4425,10 @@
4389
4425
  }
4390
4426
  }
4391
4427
 
4392
- function createEffect(addValue) {
4428
+ function createEffect(addValue, { step, ...options } = {}) {
4393
4429
  const stateCache = new WeakMap();
4394
- return (subject, values) => {
4395
- const state = stateCache.get(subject) ?? new MotionValueState();
4430
+ const effect = (subject, values) => {
4431
+ const state = stateCache.get(subject) ?? new MotionValueState(step);
4396
4432
  stateCache.set(subject, state);
4397
4433
  const subscriptions = [];
4398
4434
  for (const key in values) {
@@ -4405,6 +4441,9 @@
4405
4441
  cancel();
4406
4442
  };
4407
4443
  };
4444
+ return Object.assign(effect, options, {
4445
+ get: (subject, key) => stateCache.get(subject)?.get(key),
4446
+ });
4408
4447
  }
4409
4448
 
4410
4449
  function canSetAsProperty(element, name) {
@@ -10782,6 +10821,7 @@
10782
10821
  exports.KeyframeResolver = KeyframeResolver;
10783
10822
  exports.LayoutAnimationBuilder = LayoutAnimationBuilder;
10784
10823
  exports.MotionValue = MotionValue;
10824
+ exports.MotionValueState = MotionValueState;
10785
10825
  exports.NativeAnimation = NativeAnimation;
10786
10826
  exports.NativeAnimationExtended = NativeAnimationExtended;
10787
10827
  exports.NativeAnimationWrapper = NativeAnimationWrapper;
@@ -10793,11 +10833,13 @@
10793
10833
  exports.acceleratedValues = acceleratedValues;
10794
10834
  exports.addAttrValue = addAttrValue;
10795
10835
  exports.addDomEvent = addDomEvent;
10836
+ exports.addEffect = addEffect;
10796
10837
  exports.addScaleCorrector = addScaleCorrector;
10797
10838
  exports.addStyleValue = addStyleValue;
10798
10839
  exports.addValueToWillChange = addValueToWillChange;
10799
10840
  exports.alpha = alpha;
10800
10841
  exports.analyseComplexValue = analyseComplexValue;
10842
+ exports.animateEffectSubject = animateEffectSubject;
10801
10843
  exports.animateMotionValue = animateMotionValue;
10802
10844
  exports.animateSingleValue = animateSingleValue;
10803
10845
  exports.animateTarget = animateTarget;
@@ -10861,6 +10903,7 @@
10861
10903
  exports.createAxisDelta = createAxisDelta;
10862
10904
  exports.createBox = createBox;
10863
10905
  exports.createDelta = createDelta;
10906
+ exports.createEffect = createEffect;
10864
10907
  exports.createGeneratorEasing = createGeneratorEasing;
10865
10908
  exports.createProjectionNode = createProjectionNode;
10866
10909
  exports.createRenderBatcher = createRenderBatcher;
@@ -10877,6 +10920,7 @@
10877
10920
  exports.fillOffset = fillOffset;
10878
10921
  exports.fillWildcards = fillWildcards;
10879
10922
  exports.findDimensionValueType = findDimensionValueType;
10923
+ exports.findEffect = findEffect;
10880
10924
  exports.findValueType = findValueType;
10881
10925
  exports.flushKeyframeResolvers = flushKeyframeResolvers;
10882
10926
  exports.followValue = followValue;
@@ -10980,6 +11024,7 @@
10980
11024
  exports.removeAxisDelta = removeAxisDelta;
10981
11025
  exports.removeAxisTransforms = removeAxisTransforms;
10982
11026
  exports.removeBoxTransforms = removeBoxTransforms;
11027
+ exports.removeEffect = removeEffect;
10983
11028
  exports.removePointDelta = removePointDelta;
10984
11029
  exports.renderHTML = renderHTML;
10985
11030
  exports.renderSVG = renderSVG;