Skip to content

Commit

Permalink
push changes and include new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathonRP committed Dec 27, 2024
1 parent 3106dfc commit cd5bae8
Show file tree
Hide file tree
Showing 227 changed files with 826 additions and 684 deletions.
82 changes: 43 additions & 39 deletions bun.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
"bits-ui": "^0.22.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-svelte": "^0.468.0",
"lucide-svelte": "^0.469.0",
"mode-watcher": "^0.5.0",
"nanoid": "^5.0.9",
"tailwind-merge": "^2.5.5",
"tailwind-merge": "^2.6.0",
"tailwind-variants": "^0.3.0"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@changesets/cli": "^2.27.11",
"@emotion/is-prop-valid": "^1.3.1",
"@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/kit": "^2.13.0",
"@sveltejs/kit": "^2.15.1",
"@sveltejs/package": "^2.3.7",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"@sveltejs/vite-plugin-svelte-inspector": "^4.0.1",
Expand All @@ -58,16 +58,16 @@
"@vitest/ui": "^2.1.8",
"csstype": "^3.1.3",
"publint": "^0.2.12",
"runed": "^0.20.0",
"sv": "^0.6.8",
"runed": "^0.22.0",
"sv": "^0.6.10",
"svelte-check": "^4.1.1",
"tailwindcss": "^4.0.0-beta.8",
"typescript": "^5.7.2",
"vite": "^6.0.4",
"vite": "^6.0.6",
"vitest": "^2.1.8"
},
"peerDependencies": {
"svelte": "^5.15.0"
"svelte": "^5.16.0"
},
"engines": {
"bun": ">=1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/motion/AnimateLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<button class="switch" data-active={active} onclick={toggleSwitch}>
<motion.div
active={1 * !active}
ut
layout
class="handle"
transition={spring}
/>
Expand Down
58 changes: 58 additions & 0 deletions src/lib/components/motion/AnimatePresenceMode.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!-- https://codesandbox.io/p/sandbox/t7qxhv?file=/src/styles.css -->
<svelte:options runes />

<script lang="ts">
import Box from "../Box.svelte";
import { motion, AnimatePresence } from "$lib/motion-start";
let count = $state(0);
let items = $state([0]);
let popLayout = $state(false);
let mode = $derived<"popLayout" | "sync">(popLayout ? "popLayout" : "sync");
</script>

<Box>
<div class="flex flex-col items-center">
<div class="flex flex-col p-0 pb-[50px] items-center">
<label class="flex flex-col items-center my-[20px] mx-0">
<code>popLayout</code>
<input
class="text-accent-500"
type="checkbox"
checked={popLayout}
onchange={(e) => (popLayout = e.currentTarget.checked)}
/>
</label>
<motion.button
class="bg-accent-500 text-background border-none py-[15px] px-[25px] rounded-[50px] text-[18px] font-bold cursor-pointer w-[150px]"
whileTap={{ scale: 0.95 }}
onclick={() => {
count++;
items = [...items, count];
}}
>
Add item
</motion.button>
</div>
<ul
class="flex w-[300px] h-[300px] flex-col gap-[20px] m-0 p-0 list-none"
>
<AnimatePresence {mode}>
{#each items as id, indx (id)}
<motion.li
class="block bg-accent-500 h-[80px] w-full shrink-0 grow-0 basis-[80px] rounded-[20px] m-0 p-0"
layout
animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.8, opacity: 0 }}
transition={{ type: "spring" }}
onclick={() => {
const newItems = [...items];
if (indx > -1) newItems.splice(indx, 1);
items = newItems;
}}
/>
{/each}
</AnimatePresence>
</ul>
</div>
</Box>
1 change: 1 addition & 0 deletions src/lib/components/motion/AnimatePresenceStack.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- https://codesandbox.io/p/sandbox/gm9n3c?file=/src/index.js -->
<script>
import Box from "../Box.svelte";
import { AnimatePresence } from "$lib/motion-start";
Expand Down
87 changes: 87 additions & 0 deletions src/lib/components/motion/ReorderList.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!-- https://codesandbox.io/p/sandbox/uonye -->
<svelte:options runes />

<script lang="ts" module>
const inactiveShadow = "0px 0px 0px rgba(0,0,0,0.8)";
function useRaisedShadow(value: MotionValue<number>) {
const boxShadow = useMotionValue(inactiveShadow);
$effect.pre(() => {
let isActive = false;
value.onChange((latest) => {
const wasActive = isActive;
if (latest !== 0) {
isActive = true;
if (isActive !== wasActive) {
animate(boxShadow, "5px 5px 10px rgba(0,0,0,0.3)");
}
} else {
isActive = false;
if (isActive !== wasActive) {
animate(boxShadow, inactiveShadow);
}
}
});
});
return boxShadow;
}
</script>

<script lang="ts">
import {
Reorder,
useMotionValue,
animate,
MotionValue,
} from "$lib/motion-start";
import Box from "../Box.svelte";
let initialItems = $state([
"🍅 Tomato",
"🥒 Cucumber",
"🧀 Cheese",
"🥬 Lettuce",
]);
const y = useMotionValue(0);
const boxShadow = useRaisedShadow(y);
</script>

<Box>
<Reorder.Group
class="list-none p-0 m-0 font-medium text-2xl relative w-[300px]"
axis="y"
onReorder={(newItems) => (initialItems = newItems)}
values={initialItems}
>
{#each initialItems as item (item)}
<Reorder.Item
class="p-0 m-0 font-medium text-2xl rounded-[5px] mb-[10px] w-full py-[15px] px-[18px] bg-white flex justify-between items-center shrink-0 cursor-grab"
value={item}
id={item}
style={{ boxShadow, y }}
>
<span>{item}</span>
</Reorder.Item>
{/each}
</Reorder.Group>
</Box>

<style>
:global(li svg) {
width: 18px;
height: 18px;
cursor: grab;
}
:global(.background) {
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 300px;
background: #fff;
}
</style>
2 changes: 2 additions & 0 deletions src/lib/components/motion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export { default as Tweened } from './Tweened.svelte';
export { default as WhileDragEffect } from './WhileDragEffect.svelte';
export { default as WhileHoverEffect } from './WhileHoverEffect.svelte';
export { default as WhileTapEffect } from './WhileTapEffect.svelte';
export { default as AnimatePresenceMode } from './AnimatePresenceMode.svelte';
export { default as ReorderList } from './ReorderList.svelte';
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 { ProgressTimeline } from '../render/dom/scroll/observe.svelte';
import type { ProgressTimeline } from '../render/dom/scroll/observe';
import { supportsScrollTimeline } from '../render/dom/scroll/supports';
import type { AnimationPlaybackControls } from './types';

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

import type { GenericKeyframesTarget } from '../../types';
import type { MotionValue } from '../../value/index.svelte';
import { GroupPlaybackControls } from '../GroupPlaybackControls.svelte';
import type { AnimationSequence, ObjectTarget, SequenceOptions } from '../sequence/types.svelte';
import type { MotionValue } from '../../value';
import { GroupPlaybackControls } from '../GroupPlaybackControls';
import type { AnimationSequence, ObjectTarget, SequenceOptions } from '../sequence/types';
import type {
AnimationPlaybackControls,
AnimationScope,
Expand All @@ -15,8 +15,8 @@ import type {
ElementOrSelector,
ValueAnimationTransition,
} from '../types';
import { animateSequence } from './sequence.svelte';
import { animateSubject } from './subject.svelte';
import { animateSequence } from './sequence';
import { animateSubject } from './subject';

function isSequence(value: unknown): value is AnimationSequence {
return Array.isArray(value) && Array.isArray(value[0]);
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 { resolveElements, type SelectorCache } from '../../render/dom/utils/resolve-element';
import type { ObjectTarget } from '../sequence/types.svelte';
import type { ObjectTarget } from '../sequence/types';
import type { AnimationScope, DOMKeyframesDefinition } from '../types';
import { isDOMKeyframes } from '../utils/is-dom-keyframes';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ based on [email protected],
Copyright (c) 2018 Framer B.V.
*/

import { spring } from '../generators/spring/index.svelte';
import { createAnimationsFromSequence } from '../sequence/create.svelte';
import type { AnimationSequence, SequenceOptions } from '../sequence/types.svelte';
import { spring } from '../generators/spring';
import { createAnimationsFromSequence } from '../sequence/create';
import type { AnimationSequence, SequenceOptions } from '../sequence/types';
import type { AnimationPlaybackControls, AnimationScope } from '../types';
import { animateSubject } from './subject.svelte';
import { animateSubject } from './subject';

export function animateSequence(sequence: AnimationSequence, options?: SequenceOptions, scope?: AnimationScope) {
const animations: AnimationPlaybackControls[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ based on [email protected],
Copyright (c) 2018 Framer B.V.
*/

import { animateMotionValue } from '../interfaces/motion-value.svelte';
import { motionValue as createMotionValue, type MotionValue } from '../../value/index.svelte';
import { animateMotionValue } from '../interfaces/motion-value';
import { motionValue as createMotionValue, type MotionValue } from '../../value';
import { isMotionValue } from '../../value/utils/is-motion-value';
import type { GenericKeyframesTarget } from '../../types';
import type { AnimationPlaybackControls, ValueAnimationTransition } from '../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Copyright (c) 2018 Framer B.V.
import { visualElementStore } from '../../render/store.svelte';
import type { GenericKeyframesTarget, TargetAndTransition } from '../../types';
import { invariant } from '../../utils/errors';
import type { MotionValue } from '../../value/index.svelte';
import type { MotionValue } from '../../value';
import { isMotionValue } from '../../value/utils/is-motion-value';
import { animateTarget } from '../interfaces/visual-element-target.svelte';
import type { ObjectTarget } from '../sequence/types.svelte';
import { animateTarget } from '../interfaces/visual-element-target';
import type { ObjectTarget } from '../sequence/types';
import type {
AnimationPlaybackControls,
AnimationScope,
Expand All @@ -18,10 +18,10 @@ import type {
ElementOrSelector,
ValueAnimationTransition,
} from '../types';
import { createDOMVisualElement, createObjectVisualElement } from '../utils/create-visual-element.svelte';
import { createDOMVisualElement, createObjectVisualElement } from '../utils/create-visual-element';
import { isDOMKeyframes } from '../utils/is-dom-keyframes';
import { resolveSubjects } from './resolve-subjects.svelte';
import { animateSingleValue } from './single-value.svelte';
import { resolveSubjects } from './resolve-subjects';
import { animateSingleValue } from './single-value';

export type AnimationSubject = Element | MotionValue<any> | any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import { anticipate } from '../../easing/anticipate';
import { backInOut } from '../../easing/back';
import { circInOut } from '../../easing/circ';
import type { EasingDefinition } from '../../easing/types';
import { DOMKeyframesResolver } from '../../render/dom/DOMKeyframesResolver.svelte';
import type { ResolvedKeyframes } from '../../render/utils/KeyframesResolver.svelte';
import { DOMKeyframesResolver } from '../../render/dom/DOMKeyframesResolver';
import type { ResolvedKeyframes } from '../../render/utils/KeyframesResolver';
import { noop } from '../../utils/noop';
import { millisecondsToSeconds, secondsToMilliseconds } from '../../utils/time-conversion';
import type { MotionValue } from '../../value/index.svelte';
import type { MotionValue } from '../../value';
import { isGenerator } from '../generators/utils/is-generator';
import type { ValueAnimationOptions, ValueAnimationOptionsWithRenderContext } from '../types';
import { BaseAnimation, type ValueAnimationOptionsWithDefaults } from './BaseAnimation.svelte';
import { BaseAnimation, type ValueAnimationOptionsWithDefaults } from './BaseAnimation';
import { MainThreadAnimation } from './MainThreadAnimation.svelte';
import { acceleratedValues } from './utils/accelerated-values.svelte';
import { startWaapiAnimation } from './waapi/index.svelte';
import { isWaapiSupportedEasing } from './waapi/easing.svelte';
import { attachTimeline } from './waapi/utils/attach-timeline.svelte';
import { getFinalKeyframe } from './waapi/utils/get-final-keyframe.svelte';
import { supportsLinearEasing } from './waapi/utils/supports-linear-easing.svelte';
import { supportsWaapi } from './waapi/utils/supports-waapi.svelte';
import { acceleratedValues } from './utils/accelerated-values';
import { startWaapiAnimation } from './waapi';
import { isWaapiSupportedEasing } from './waapi/easing';
import { attachTimeline } from './waapi/utils/attach-timeline';
import { getFinalKeyframe } from './waapi/utils/get-final-keyframe';
import { supportsLinearEasing } from './waapi/utils/supports-linear-easing';
import { supportsWaapi } from './waapi/utils/supports-waapi';

/**
* 10ms is chosen here as it strikes a balance between smooth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ based on [email protected],
Copyright (c) 2018 Framer B.V.
*/

import { time } from '../../frameloop/sync-time.svelte';
import { time } from '../../frameloop/sync-time';
import {
type KeyframeResolver,
type ResolvedKeyframes,
flushKeyframeResolvers,
} from '../../render/utils/KeyframesResolver.svelte';
} from '../../render/utils/KeyframesResolver';
import { instantAnimationState } from '../../utils/use-instant-transition-state';
import type {
AnimationPlaybackControls,
RepeatType,
ValueAnimationOptions,
ValueAnimationOptionsWithRenderContext,
} from '../types';
import { canAnimate } from './utils/can-animate.svelte';
import { getFinalKeyframe } from './waapi/utils/get-final-keyframe.svelte';
import { canAnimate } from './utils/can-animate';
import { getFinalKeyframe } from './waapi/utils/get-final-keyframe';

/**
* Maximum time allowed between an animation being created and it being
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ Copyright (c) 2018 Framer B.V.
import {
KeyframeResolver as DefaultKeyframeResolver,
type ResolvedKeyframes,
} from '../../render/utils/KeyframesResolver.svelte';
import { spring } from '../generators/spring/index.svelte';
import { inertia } from '../generators/inertia.svelte';
import { keyframes as keyframesGeneratorFactory } from '../generators/keyframes.svelte';
} from '../../render/utils/KeyframesResolver';
import { spring } from '../generators/spring';
import { inertia } from '../generators/inertia';
import { keyframes as keyframesGeneratorFactory } from '../generators/keyframes';
import type { ValueAnimationOptions, ValueAnimationOptionsWithRenderContext } from '../types';
import { BaseAnimation } from './BaseAnimation.svelte';
import type { AnimationState, KeyframeGenerator } from '../generators/types.svelte';
import { BaseAnimation } from './BaseAnimation';
import type { AnimationState, KeyframeGenerator } from '../generators/types';
import { pipe } from '../../utils/pipe';
import { mix } from '../../utils/mix';
import { calcGeneratorDuration } from '../generators/utils/calc-duration.svelte';
import { calcGeneratorDuration } from '../generators/utils/calc-duration';
import type { DriverControls } from './drivers/types';
import { millisecondsToSeconds, secondsToMilliseconds } from '../../utils/time-conversion';
import { clamp } from '../../utils/clamp';
import { invariant } from '../../utils/errors';
import { frameloopDriver } from './drivers/driver-frameloop.svelte';
import { getFinalKeyframe } from './waapi/utils/get-final-keyframe.svelte';
import { frameloopDriver } from './drivers/driver-frameloop';
import { getFinalKeyframe } from './waapi/utils/get-final-keyframe';
import { isGenerator } from '../generators/utils/is-generator';

type GeneratorFactory = (options: ValueAnimationOptions<any>) => KeyframeGenerator<any>;
Expand Down
Loading

0 comments on commit cd5bae8

Please sign in to comment.