Skip to content

Commit

Permalink
fix: πŸ› svg animation and ssr support
Browse files Browse the repository at this point in the history
enable svg animation and ssr support

BREAKING CHANGE: 🧨 all

βœ… Closes: none
  • Loading branch information
JonathonRP committed Dec 8, 2024
1 parent f8fea46 commit 5ae3550
Show file tree
Hide file tree
Showing 59 changed files with 232 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { backInOut } from '../../easing/back';
import { circInOut } from '../../easing/circ';
import type { EasingDefinition } from '../../easing/types';
import { DOMKeyframesResolver } from '../../render/dom/DOMKeyframesResolver';
import type { ResolvedKeyframes } from '../../render/utils/KeyframesResolver';
import type { ResolvedKeyframes } from '../../render/utils/KeyframesResolver.svelte';
import { noop } from '../../utils/noop';
import { millisecondsToSeconds, secondsToMilliseconds } from '../../utils/time-conversion';
import type { MotionValue } from '../../value';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/motion-start/animation/animators/BaseAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type KeyframeResolver,
type ResolvedKeyframes,
flushKeyframeResolvers,
} from '../../render/utils/KeyframesResolver';
} from '../../render/utils/KeyframesResolver.svelte';
import { instantAnimationState } from '../../utils/use-instant-transition-state';
import type {
AnimationPlaybackControls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright (c) 2018 Framer B.V.
import {
KeyframeResolver as DefaultKeyframeResolver,
type ResolvedKeyframes,
} from '../../render/utils/KeyframesResolver';
} from '../../render/utils/KeyframesResolver.svelte';
import { spring } from '../generators/spring/index';
import { inertia } from '../generators/inertia';
import { keyframes as keyframesGeneratorFactory } from '../generators/keyframes';
Expand Down Expand Up @@ -184,6 +184,7 @@ export class MainThreadAnimation<T extends string | number> extends BaseAnimatio
}

onPostResolved() {
console.log('post resolve');
const { autoplay = true } = this.options;

this.play();
Expand Down Expand Up @@ -378,6 +379,7 @@ export class MainThreadAnimation<T extends string | number> extends BaseAnimatio
}

play() {
console.log('play', this.isStopped);
if (!this.resolver.isScheduled) {
this.resolver.resume();
}
Expand Down Expand Up @@ -437,6 +439,7 @@ export class MainThreadAnimation<T extends string | number> extends BaseAnimatio
* animation.stop is returned as a reference from a useEffect.
*/
stop = () => {
console.log(new Error().stack?.toString());
this.resolver.cancel();
this.isStopped = true;
if (this.state === 'idle') return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ based on [email protected],
Copyright (c) 2018 Framer B.V.
*/

import type { ResolvedKeyframes } from '../../../render/utils/KeyframesResolver';
import type { ResolvedKeyframes } from '../../../render/utils/KeyframesResolver.svelte';
import { warning } from '../../../utils/errors';
import { isGenerator } from '../../generators/utils/is-generator';
import type { AnimationGeneratorType } from '../../types';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/motion-start/animation/hooks/animation-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Copyright (c) 2018 Framer B.V.

import { invariant } from '../../utils/errors';
import { setTarget } from '../../render/utils/setters';
import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import type { AnimationControls, AnimationDefinition } from '../types';
import { animateVisualElement } from '../interfaces/visual-element';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { TargetAndTransition } from '../../types';
import type { ResolvedValues } from '../../render/types';
import { makeUseVisualState } from '../../motion/utils/use-visual-state';
import { createBox } from '../../projection/geometry/models';
import { VisualElement } from '../../render/VisualElement';
import { VisualElement } from '../../render/VisualElement.svelte';
import { animateVisualElement } from '../interfaces/visual-element';

interface AnimatedStateOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/motion-start/animation/interfaces/motion-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type { MotionValue, StartAnimation } from '../../value';
import { getDefaultTransition } from '../utils/default-transitions';
import { getValueTransition } from '../utils/get-value-transition';
import type { AnimationPlaybackControls, ValueAnimationOptions } from '../types';
import type { UnresolvedKeyframes } from '../../render/utils/KeyframesResolver';
import type { UnresolvedKeyframes } from '../../render/utils/KeyframesResolver.svelte';
import { MotionGlobalConfig } from '../../utils/GlobalConfig';
import { instantAnimationState } from '../../utils/use-instant-transition-state';
import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import { getFinalKeyframe } from '../animators/waapi/utils/get-final-keyframe';
import { frame } from '../../frameloop/frame';
import { AcceleratedAnimation } from '../animators/AcceleratedAnimation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Copyright (c) 2018 Framer B.V.

import { transformProps } from '../../render/html/utils/transform';
import type { AnimationTypeState } from '../../render/utils/animation-state';
import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import type { TargetAndTransition } from '../../types';
import type { VisualElementAnimationOptions } from './types';
import { animateMotionValue } from './motion-value';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright (c) 2018 Framer B.V.
*/

import { resolveVariant } from '../../render/utils/resolve-dynamic-variants';
import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import type { VisualElementAnimationOptions } from './types';
import { animateTarget } from './visual-element-target';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright (c) 2018 Framer B.V.
*/

import { resolveVariant } from '../../render/utils/resolve-dynamic-variants';
import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import type { AnimationDefinition } from '../types';
import type { VisualElementAnimationOptions } from './types';
import { animateTarget } from './visual-element-target';
Expand Down
4 changes: 2 additions & 2 deletions src/lib/motion-start/animation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Copyright (c) 2018 Framer B.V.
*/

import type { TargetAndTransition, TargetResolver } from '../types';
import type { VisualElement } from '../render/VisualElement';
import type { VisualElement } from '../render/VisualElement.svelte';
import type { Easing } from '../easing/types';
import type { Driver } from './animators/drivers/types';
import type { SVGPathProperties, VariantLabels } from '../motion/types';
import type { SVGAttributes } from '../render/svg/types-attributes';
import type { ProgressTimeline } from '../render/dom/scroll/observe';
import type { MotionValue } from '../value';
import type { KeyframeResolver, OnKeyframesResolved } from '../render/utils/KeyframesResolver';
import type { KeyframeResolver, OnKeyframesResolved } from '../render/utils/KeyframesResolver.svelte';
import type { KeyframeGenerator } from './generators/types';

export interface AnimationPlaybackLifecycles<V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Copyright (c) 2018 Framer B.V. -->
import PresenceChild from "./PresenceChild/PresenceChild.svelte";
import { fromStore } from "svelte/store";
import { SvelteMap, SvelteSet } from "svelte/reactivity";
import { onMount, untrack, type Snippet } from "svelte";
import { untrack, type Snippet } from "svelte";
type Props = AnimatePresenceProps<ConditionalGeneric<T>> & {
isCustom?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Copyright (c) 2018 Framer B.V. -->
</script>

<script lang="ts">
import { onMount, type Snippet } from "svelte";
import { type Snippet } from "svelte";
import { useContext } from "../../context/utils/context.svelte";
import { LazyContext } from "../../context/LazyContext";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/motion-start/context/MotionContext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ based on [email protected],
Copyright (c) 2018 Framer B.V.
*/

import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import { createContext } from '../utils/context.svelte';

export interface MotionContextProps<Instance = unknown> {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/motion-start/context/utils/context.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class Context<T> extends CallableContext<T> {
) {
super((c?: any) => {
let context = null;
$effect(() => {
$effect.pre(() => {
context = getDomContext(this.key, this.c || c);
});
return getContext<T>(this) || context || this._default;
});
}

set Provider(value: UnwrapWritable<T>) {
$effect(() => {
$effect.pre(() => {
setDomContext(this.key, this.c, writable(value));
});
setContext(this, writable(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
defaultElastic,
calcOrigin,
} from './utils/constraints';
import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import type { MotionProps } from '../../motion/types';
import type { Axis, Point } from '../../projection/geometry/types';
import { createBox } from '../../projection/geometry/models';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/motion-start/gestures/drag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright (c) 2018 Framer B.V.
*/

import { Feature } from '../../motion/features/Feature';
import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import { noop } from '../../utils/noop';
import { VisualElementDragControls } from './VisualElementDragControls';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/motion-start/gestures/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { addPointerEvent } from '../events/add-pointer-event';
import { pipe } from '../utils/pipe';
import { isDragActive } from './drag/utils/lock';
import type { EventInfo } from '../events/types';
import type { VisualElement } from '../render/VisualElement';
import type { VisualElement } from '../render/VisualElement.svelte';
import { Feature } from '../motion/features/Feature';
import { frame } from '../frameloop';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/motion-start/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export { useDomEvent } from './events/use-dom-event.svelte';
export { createRendererMotionComponent } from './motion/index.svelte';
export { isMotionComponent } from './motion/utils/is-motion-component';
export { unwrapMotionComponent } from './motion/utils/unwrap-motion-component';
export { VisualElement } from './render/VisualElement';
export { VisualElement } from './render/VisualElement.svelte';
export { addScaleCorrector } from './projection/styles/scale-correction';
export {
useInstantTransition,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/motion-start/motion/features/Feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ based on [email protected],
Copyright (c) 2018 Framer B.V.
*/

import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';

export abstract class Feature<I> {
isMounted = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Copyright (c) 2018 Framer B.V.

import { isAnimationControls } from '../../../animation/utils/is-animation-controls';
import { createAnimationState } from '../../../render/utils/animation-state';
import type { VisualElement } from '../../../render/VisualElement';
import type { VisualElement } from '../../../render/VisualElement.svelte';
import { Feature } from '../Feature';

export class AnimationFeature extends Feature<unknown> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useContext } from '../../../context/utils/context.svelte';
import { LayoutGroupContext } from '../../../context/LayoutGroupContext';
import { SwitchLayoutGroupContext } from '../../../context/SwitchLayoutGroupContext';
import type { MotionProps } from '../../types';
import type { VisualElement } from '../../../render/VisualElement';
import type { VisualElement } from '../../../render/VisualElement.svelte';
import { default as MeasureLayoutWithContext } from './MeasureLayoutWithContext.svelte';
import type { Component } from 'svelte';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Copyright (c) 2018 Framer B.V. -->

<script lang="ts">
import { frame } from "../../../frameloop";
import { onDestroy, onMount } from "svelte";
import { onMount } from "svelte";
import { addScaleCorrector } from "../../../projection/styles/scale-correction";
import { globalProjectionState } from "../../../projection/node/state";
import { microtask } from "../../../frameloop/microtask";
Expand Down
23 changes: 13 additions & 10 deletions src/lib/motion-start/motion/features/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Copyright (c) 2018 Framer B.V.

import type { MotionProps } from '../types';
import type { VisualState } from '../utils/use-visual-state';
import type { VisualElement } from '../../render/VisualElement';
import type { VisualElement } from '../../render/VisualElement.svelte';
import type { CreateVisualElement } from '../../render/types';
import type { Feature } from './Feature';
import type { MeasureLayout } from './layout/MeasureLayout';
import type { Ref, RefCallBack } from '../../utils/safe-react-types';
import type { Component, Snippet } from 'svelte';
import type { SvelteHTMLElements } from 'svelte/elements';

export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;

Expand Down Expand Up @@ -57,12 +58,14 @@ export interface FeatureBundle extends FeaturePackages {

export type LazyFeatureBundle = () => Promise<FeatureBundle>;

export type RenderComponent<Instance, RenderState> = Component<{
Component: string;
props: MotionProps;
ref: RefCallBack<Instance>;
visualState: VisualState<Instance, RenderState>;
isStatic: boolean;
visualElement?: VisualElement<Instance>;
children?: Snippet;
}>;
export type RenderComponent<Instance, RenderState> = Component<
{
Component: string;
props: MotionProps;
ref: RefCallBack<Instance>;
visualState: VisualState<Instance, RenderState>;
isStatic: boolean;
visualElement?: VisualElement<Instance>;
children?: Snippet;
} & { el: SvelteHTMLElements[Parameters<RenderComponent<Instance, RenderState>>[1]['Component']]['this'] }
>;
Loading

0 comments on commit 5ae3550

Please sign in to comment.