Skip to content

Commit

Permalink
feat(animations): migrate to motion-one@11
Browse files Browse the repository at this point in the history
  • Loading branch information
SethBurkart123 committed Nov 29, 2024
1 parent 34306e7 commit dc1ae9c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 385 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"localforage": "^1.10.0",
"lodash": "^4.17.21",
"million": "^3.1.11",
"motion": "^10.18.0",
"motion": "^11.12.0",
"postcss": "^8.4.45",
"publish-browser-extension": "^2.2.1",
"react": "17",
Expand Down
68 changes: 41 additions & 27 deletions src/SEQTA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Color from 'color'
import Sortable from 'sortablejs'
import browser from 'webextension-polyfill'
import { animate, spring, stagger } from 'motion'
import { animate, stagger } from 'motion'

// Internal utilities and functions
import { delay } from '@/seqta/utils/delay'
Expand Down Expand Up @@ -329,16 +329,20 @@ export function OpenWhatsNewPopup() {
animate(
[popup, bkelement as HTMLElement],
{ scale: [0, 1], opacity: [0, 1] },
{ easing: spring({ stiffness: 220, damping: 18 }) }
{
type: 'spring',
stiffness: 220,
damping: 18
}
)

animate(
'.whatsnewTextContainer *',
{ opacity: [0, 1], y: [10, 0] },
{
delay: stagger(0.05, { start: 0.1 }),
delay: stagger(0.05, { startDelay: 0.1 }),
duration: 0.5,
easing: [.22, .03, .26, 1]
ease: [.22, .03, .26, 1]
}
)
}
Expand Down Expand Up @@ -425,16 +429,20 @@ export function OpenAboutPage() {
animate(
[popup, bkelement as HTMLElement],
{ scale: [0, 1], opacity: [0, 1] },
{ easing: spring({ stiffness: 220, damping: 18 }) }
{
type: 'spring',
stiffness: 220,
damping: 18
}
)

animate(
'.whatsnewTextContainer *',
{ opacity: [0, 1], y: [10, 0] },
{
delay: stagger(0.05, { start: 0.1 }),
delay: stagger(0.05, { startDelay: 0.1 }),
duration: 0.5,
easing: [.22, .03, .26, 1]
ease: [.22, .03, .26, 1]
}
)
}
Expand Down Expand Up @@ -486,8 +494,8 @@ async function DeleteWhatsNew() {
animate(
[popup, bkelement!],
{ opacity: [1, 0], scale: [1, 0] },
{ easing: [.22, .03, .26, 1] }
).finished.then(() => {
{ ease: [.22, .03, .26, 1] }
).then(() => {
bkelement?.remove()
});
}
Expand Down Expand Up @@ -802,7 +810,7 @@ async function handleMessages(node: Element): Promise<void> {
{
delay: stagger(0.05),
duration: 0.5,
easing: [.22, .03, .26, 1]
ease: [.22, .03, .26, 1]
}
);

Expand All @@ -825,7 +833,7 @@ async function handleDashboard(node: Element): Promise<void> {
{
delay: stagger(0.1),
duration: 0.5,
easing: [.22, .03, .26, 1]
ease: [.22, .03, .26, 1]
}
);

Expand All @@ -843,7 +851,7 @@ async function handleDocuments(node: Element): Promise<void> {
{
delay: stagger(0.05),
duration: 0.5,
easing: [.22, .03, .26, 1]
ease: [.22, .03, .26, 1]
}
);
}
Expand All @@ -857,9 +865,9 @@ async function handleReports(node: Element): Promise<void> {
'.reports .item',
{ opacity: [0, 1], y: [10, 0] },
{
delay: stagger(0.05, { start: 0.2 }),
delay: stagger(0.05, { startDelay: 0.2 }),
duration: 0.5,
easing: [.22, .03, .26, 1]
ease: [.22, .03, .26, 1]
}
);
}
Expand Down Expand Up @@ -1052,10 +1060,15 @@ export const closeExtensionPopup = (extensionPopup?: HTMLElement) => {

extensionPopup.classList.add('hide')
if (settingsState.animations) {
animate((progress) => {
extensionPopup.style.opacity = Math.max(0, 1 - progress).toString()
extensionPopup.style.transform = `scale(${Math.max(0, 1 - progress)})`
}, { easing: spring({ stiffness: 520, damping: 20 }) })
animate(1, 0, {
onUpdate: (progress) => {
extensionPopup.style.opacity = Math.max(0, progress).toString()
extensionPopup.style.transform = `scale(${Math.max(0, progress)})`
},
type: 'spring',
stiffness: 520,
damping: 20
});
} else {
extensionPopup.style.opacity = '0'
extensionPopup.style.transform = 'scale(0)'
Expand Down Expand Up @@ -1329,10 +1342,15 @@ export function setupSettingsButton() {
closeExtensionPopup(extensionPopup as HTMLElement);
} else {
if (settingsState.animations) {
animate((progress) => {
extensionPopup!.style.opacity = progress.toString()
extensionPopup!.style.transform = `scale(${progress})`
}, { easing: spring({ stiffness: 280, damping: 20 }) });
animate(0, 1, {
onUpdate: (progress) => {
extensionPopup!.style.opacity = progress.toString()
extensionPopup!.style.transform = `scale(${progress})`
},
type: 'spring',
stiffness: 280,
damping: 20
});

} else {
extensionPopup!.style.opacity = '1'
Expand Down Expand Up @@ -2280,11 +2298,7 @@ export async function loadHomePage() {
animate(
'.home-container > div',
{ opacity: [0, 1], y: [10, 0] },
{
delay: stagger(0.2, { start: 0 }),
duration: 0.6,
easing: [.22, .03, .26, 1]
}
{ delay: stagger(0.2), startTime: 0 }
)
}

Expand Down
18 changes: 13 additions & 5 deletions src/interface/components/ColourPicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { onMount } from 'svelte'
import ColourPicker from './ColourPicker.tsx';
import ReactAdapter from './utils/ReactAdapter.svelte';
import { animate, spring } from 'motion';
import { animate } from 'motion';
import { delay } from '@/seqta/utils/delay.ts'
const { hidePicker, standalone = false, savePresets = true, customOnChange = null, customState = null } = $props<{
Expand All @@ -23,13 +23,17 @@
animate(
content,
{ scale: [1, 0.4], opacity: [1, 0] },
{ easing: spring({ stiffness: 400, damping: 30 }) }
{
type: 'spring',
stiffness: 400,
damping: 30
}
);
animate(
background,
{ opacity: [1, 0] },
{ easing: [0.4, 0, 0.2, 1] }
{ ease: [0.4, 0, 0.2, 1] }
);
await delay(400);
Expand All @@ -43,13 +47,17 @@
animate(
background,
{ opacity: [0, 1] },
{ duration: 0.3, easing: [0.4, 0, 0.2, 1] }
{ duration: 0.3, ease: [0.4, 0, 0.2, 1] }
);
animate(
content,
{ scale: [0.4, 1], opacity: [0, 1] },
{ easing: spring({ stiffness: 400, damping: 30 }) }
{
type: 'spring',
stiffness: 400,
damping: 30
}
);
const handleEscapeKey = (e: KeyboardEvent) => {
Expand Down
30 changes: 13 additions & 17 deletions src/interface/components/MotionDiv.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { animate as motionAnimate, spring } from 'motion';
import { onMount, onDestroy } from 'svelte';
import { animate as motionAnimate } from 'motion';
let { initial, animate, exit, transition, children, class: className } = $props<{
initial?: any,
Expand All @@ -12,11 +12,9 @@
}>();
let divElement: HTMLElement;
const dispatch = createEventDispatcher();
const playAnimation = (keyframe: any) => {
if (divElement && keyframe) {
let animationOptions = transition;
let finalKeyframe = { ...keyframe };
if (finalKeyframe.height === 'auto') {
Expand All @@ -36,16 +34,18 @@
finalKeyframe.height = `${autoHeight}px`;
}
if (!transition || transition.type === 'spring') {
const springConfig = transition?.config || { stiffness: 250, damping: 25 };
animationOptions = {
...transition,
easing: spring(springConfig)
};
}
const defaultSpringConfig = { stiffness: 250, damping: 25 };
const animation = motionAnimate(divElement, finalKeyframe, animationOptions);
return animation.finished;
const animation = motionAnimate(
[divElement],
finalKeyframe,
{
type: 'spring',
stiffness: transition?.stiffness || defaultSpringConfig.stiffness,
damping: transition?.damping || defaultSpringConfig.damping
}
);
return animation;
}
return Promise.resolve();
};
Expand All @@ -57,16 +57,12 @@
} else if (animate) {
await playAnimation(animate);
}
dispatch('animationend');
});
$effect(() => {
if (animate) {
playAnimation(animate);
}
dispatch('animationend');
});
onDestroy(async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/interface/components/Switch.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { animate, spring } from 'motion';
import { animate } from 'motion';
import { standalone } from '../utils/standalone.svelte'
let { state, onChange } = $props<{ state: boolean, onChange: (newState: boolean) => void }>();
Expand All @@ -18,7 +18,9 @@
x: enabled ? (standalone.standalone ? 24 : 20) : 0,
},
{
easing: spring(springParams),
type: 'spring',
stiffness: springParams.stiffness,
damping: springParams.damping,
}
);
};
Expand Down
14 changes: 11 additions & 3 deletions src/interface/components/store/ThemeModal.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { Theme } from '@/interface/types/Theme'
import { fade } from 'svelte/transition';
import { animate, spring } from 'motion';
import { animate } from 'motion';
let { theme, currentThemes, setDisplayTheme, onInstall, onRemove, allThemes, displayTheme } = $props<{
theme: Theme | null;
Expand All @@ -28,7 +28,11 @@
animate(
modalElement,
{ y: [500, 0], opacity: [0, 1] },
{ easing: spring({ stiffness: 150, damping: 20 }) }
{
type: 'spring',
stiffness: 150,
damping: 20
}
);
}
});
Expand All @@ -37,7 +41,11 @@
animate(
modalElement,
{ y: [10, 500], opacity: [1, 0] },
{ easing: spring({ stiffness: 150, damping: 20 }) }
{
type: 'spring',
stiffness: 150,
damping: 20
}
);
setTimeout(() => {
setDisplayTheme(relatedTheme ?? null);
Expand Down
Loading

0 comments on commit dc1ae9c

Please sign in to comment.