Skip to content

Commit

Permalink
feat: adds rotation property
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoliradev committed Oct 30, 2024
1 parent b3437e6 commit ac3c7bb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/svelte/src/animate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function flip(node, { from, to }, params = {}) {

var dx = (from.left + dsx * ox - (to.left + ox)) / zoom;
var dy = (from.top + dsy * oy - (to.top + oy)) / zoom;
var { delay = 0, duration = (d) => Math.sqrt(d) * 120, easing = cubicOut } = params;
var { delay = 0, duration = (d) => Math.sqrt(d) * 120, easing = cubicOut, rotation = 0 } = params;

return {
delay,
Expand All @@ -30,9 +30,10 @@ export function flip(node, { from, to }, params = {}) {
css: (t, u) => {
var x = u * dx;
var y = u * dy;
var r = u * rotation;
var sx = t + u * dsx;
var sy = t + u * dsy;
return `transform: ${transform} scale(${sx}, ${sy}) translate(${x}px, ${y}px);`;
return `transform: ${transform} scale(${sx}, ${sy}) translate(${x}px, ${y}px) rotate(${r}deg);`;
}
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/animate/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface FlipParams {
delay?: number;
duration?: number | ((len: number) => number);
easing?: (t: number) => number;
rotation?: number;
}

export * from './index.js';
1 change: 1 addition & 0 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ declare module 'svelte/animate' {
delay?: number;
duration?: number | ((len: number) => number);
easing?: (t: number) => number;
rotation?: number;
}
/**
* The flip function calculates the start and end position of an element and animates between them, translating the x and y values.
Expand Down

0 comments on commit ac3c7bb

Please sign in to comment.