Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rewrite #7

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3b3bcda
update deps
JonathonRP Oct 23, 2024
49276d7
feat: 🎸 rewrite to gain features from 11.11.11 framer-motion
JonathonRP Nov 12, 2024
b8514ae
feat: 🎸 more rewrite work on hooks
JonathonRP Nov 13, 2024
c73d288
feat: 🎸 stablizing getting ready to rewrite components
JonathonRP Nov 20, 2024
26d6a5f
fix: 🐛 attempt to fix rewrite
JonathonRP Nov 24, 2024
9108d89
feat: 🎸 more progress getting back to functioning
JonathonRP Nov 26, 2024
4a01d4c
feat: 🎸 consistent context props and context api usage
JonathonRP Nov 29, 2024
027b26b
refactor: 💡 consistant component call/ mounting in motion
JonathonRP Nov 30, 2024
43056fc
fix: 🐛 few errors from incorrect derived usages
JonathonRP Nov 30, 2024
3f33056
refactor: 💡 set runes for comps using them
JonathonRP Nov 30, 2024
68e95c1
fix: 🐛 element mounting
JonathonRP Nov 30, 2024
b096c39
fix: 🐛 use hydrate instead of mount and codebase cleanup
JonathonRP Dec 1, 2024
df7d6af
refactor: 💡 onMount doesn't run with ssr
JonathonRP Dec 1, 2024
7ac0e1d
fix: 🐛 visualElement.current and context access errors
JonathonRP Dec 1, 2024
35da701
fix: 🐛 animations and update tests to reflect and cleanup
JonathonRP Dec 3, 2024
65093fe
update deps
JonathonRP Dec 3, 2024
2cbbc94
chore: 🤖 update svelte comps to runes
JonathonRP Dec 5, 2024
f8fea46
chore: 🤖 move hooks to use runes
JonathonRP Dec 6, 2024
5ae3550
fix: 🐛 svg animation and ssr support
JonathonRP Dec 8, 2024
44a4c33
docs: ✏️ add comment to note reason for svelte specifics
JonathonRP Dec 8, 2024
c0a55b5
refactor: 💡 more changes
JonathonRP Dec 10, 2024
ef38928
possible definition?
cliffordkleinsr Dec 10, 2024
1897412
push incremental changes for debugging
JonathonRP Dec 10, 2024
d5abf47
fix: 🐛 useCycle and exit feature now gets called
JonathonRP Dec 11, 2024
23f98fc
pushing incremental changes
JonathonRP Dec 12, 2024
d2b7633
codebase cleanup, consistent ui tests, update svelte version and more…
JonathonRP Dec 16, 2024
979edb2
push changes
JonathonRP Dec 17, 2024
6f8cdb6
fix some import paths
JonathonRP Dec 17, 2024
5714f68
Restore Legacy animatepresence stack with conditional ✅
cliffordkleinsr Dec 17, 2024
9dd5f66
gets rid of legacies within animatepresence and unifiess default expo…
cliffordkleinsr Dec 18, 2024
0aab524
Delete src/lib/motion-start/components/AnimatePresence/AnimatePresenc…
cliffordkleinsr Dec 18, 2024
bcb84a0
small fixes
JonathonRP Dec 18, 2024
ae3605a
pushing updates
JonathonRP Dec 18, 2024
3106dfc
push fixes for animate presence and useCycle
JonathonRP Dec 23, 2024
cd5bae8
push changes and include new tests
JonathonRP Dec 27, 2024
cbe947c
checking in bunch of improvements
JonathonRP Jan 7, 2025
74296c4
update to new understanding of derived update propegation
JonathonRP Jan 8, 2025
1830bdd
new understanding of update propegations
JonathonRP Jan 9, 2025
3e7d649
pushing changes
JonathonRP Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/polite-rockets-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"motion-start": minor
---

rewrite to include new and latest features of framer-motion
778 changes: 778 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

Binary file removed bun.lockb
Binary file not shown.
56 changes: 29 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"types": "./dist/index.d.ts",
"exports": "./dist/index.js",
"scripts": {
"sv": "bunx sv",
"dev": "vite dev",
"build": "vite build && bun --bun package",
"package": "svelte-kit sync && svelte-package --input ./src/lib/motion-start && publint --strict",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check": "svelte-kit sync && sv check --tsconfig ./tsconfig.json",
"lint": "biome check",
"test": "vitest",
"test:types": "vitest --typecheck.only",
Expand All @@ -32,46 +33,47 @@
"release": "bun --bun run build && bun --bun changeset publish"
},
"dependencies": {
"bits-ui": "^0.21.16",
"class-variance-authority": "^0.7.0",
"bits-ui": "^0.22.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"framesync": "^6.1.2",
"lucide-svelte": "^0.453.0",
"mode-watcher": "^0.4.1",
"popmotion": "^11.0.5",
"style-value-types": "5.1.2",
"tailwind-merge": "^2.5.4",
"tailwind-variants": "^0.2.1"
"lucide-svelte": "^0.471.0",
"mode-watcher": "^0.5.0",
"nanoid": "^5.0.9",
"tailwind-merge": "^2.6.0",
"tailwind-variants": "^0.3.0"
},
"devDependencies": {
"@changesets/cli": "^2.27.9",
"@biomejs/biome": "^1.9.4",
"@changesets/cli": "^2.27.11",
"@emotion/is-prop-valid": "^1.3.1",
"@sveltejs/package": "^2.3.5",
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.8",
"svelte-check": "^4.0.5",
"@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/kit": "^2.15.2",
"@sveltejs/package": "^2.3.7",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"@sveltejs/vite-plugin-svelte-inspector": "^4.0.1",
"@tailwindcss/typography": "^0.5.16",
"@tailwindcss/vite": "^4.0.0-beta.9",
"@tsconfig/svelte": "^5.0.4",
"@types/node": "^20.16.12",
"@vitest/ui": "latest",
"@types/node": "^20.17.12",
"@vitest/ui": "^2.1.8",
"csstype": "^3.1.3",
"publint": "^0.2.11",
"typescript": "^5.6.3",
"vite": "latest",
"vitest": "latest",
"@sveltejs/adapter-auto": "^3.2.5",
"@sveltejs/kit": "^2.7.1",
"@tailwindcss/typography": "^0.5.15",
"@tailwindcss/vite": "^4.0.0-alpha.28",
"tailwindcss": "^4.0.0-alpha.28"
"publint": "^0.3.2",
"runed": "^0.23.0",
"sv": "^0.6.11",
"svelte-check": "^4.1.4",
"tailwindcss": "^4.0.0-beta.9",
"typescript": "^5.7.3",
"vite": "^6.0.7",
"vitest": "^2.1.8"
},
"peerDependencies": {
"svelte": "^5.0.0-next.269"
"svelte": "^5.17.3"
},
"engines": {
"bun": ">=1.0.0",
"node": ">=20"
},
"sideEffects": false,
"keywords": ["svelte animation", "svelte", "animation", "gestures", "drag", "spring", "popmotion", "framer-motion"],
"trustedDependencies": ["@biomejs/biome", "@sveltejs/kit", "esbuild"]
"trustedDependencies": ["@biomejs/biome", "@sveltejs/kit", "esbuild", "svelte-preprocess"]
}
8 changes: 8 additions & 0 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const handle = async ({ event, resolve }) => {
const response = await resolve(event, {
preload: ({ type }) => {
return type === 'font' || type === 'asset' || type === 'js' || type === 'css';
},
});
return response;
};
10 changes: 8 additions & 2 deletions src/lib/components/Box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

<div
style="min-height: {minHeight}px; height:fit-content; touch-action: none;"
class="{cls} dark:bg-white/5 flex justify-center items-center border border-primary/40 rounded-xl my-2 p-4 md:p-6 w-full"
class="{cls} dark:bg-white/5 dark:text-black flex justify-center items-center border border-primary/40 rounded-xl my-2 p-4 md:p-6 w-full"
>
<slot></slot>
<svelte:boundary onerror={console.log}>
<slot></slot>
{#snippet failed()}
<p>whoops!</p>
<p>check console for error</p>
{/snippet}
</svelte:boundary>
</div>
8 changes: 4 additions & 4 deletions src/lib/components/Card.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Motion, useMotionValue, useTransform } from "$lib/motion-start";
import { motion, useMotionValue, useTransform } from "$lib/motion-start";
let exitX = 0;
const x = useMotionValue(0);
const scale = useTransform(x, [-150, 0, 150], [0.5, 1, 0.5]);
Expand All @@ -19,7 +19,7 @@
};
$: isFront = frontCard ? variantsFrontCard : variantsBackCard;

function handleDragEnd(_: any, info: { offset: { x: number } }) {
function handleDragEnd(_: PointerEvent, info: PanInfo) {
// console.log("info", info);
if (info.offset.x < -100) {
// setExitX(-250);
Expand All @@ -39,7 +39,7 @@

<!-- Animate Presence Stack -->

<Motion.div
<motion.div
style={{
x,
rotate,
Expand All @@ -58,4 +58,4 @@
class="w-32 h-32 top-10 bg-white rouned-xl absolute rounded-xl text-black flex justify-center items-center select-none"
>
{index}
</Motion.div>
</motion.div>
25 changes: 18 additions & 7 deletions src/lib/components/motion/AnimateLayout.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import Box from "../Box.svelte";
import { motion } from "$lib/motion-start";

const spring = {
Expand All @@ -14,13 +15,23 @@
}
</script>

<div
class="w-64 h-64 relative bg-gray-700/40 rounded-lg flex justify-center items-center"
>
<button class="switch" data-active={active} onclick={toggleSwitch}>
<motion.div layout class="handle" transition={spring} />
</button>
</div>
<Box>
<div
class="w-64 h-64 relative bg-gray-700/40 rounded-lg flex justify-center items-center"
>
<button class="switch" data-active={active} onclick={toggleSwitch}>
<motion.div
active={1 * !active}
layout
transition={spring}
onLayoutUpdate={(...args) => {
console.log("change", args);
}}
class="handle"
/>
</button>
</div>
</Box>

<style>
.switch {
Expand Down
60 changes: 60 additions & 0 deletions src/lib/components/motion/AnimatePresenceMode.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!-- 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}
list={items.map((id, indx) => ({ key: id, id, indx }))}
let:item
>
<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 (item.indx > -1) newItems.splice(item.indx, 1);
items = newItems;
}}
/>
</AnimatePresence>
</ul>
</div>
</Box>
22 changes: 13 additions & 9 deletions src/lib/components/motion/AnimatePresenceStack.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<!-- https://codesandbox.io/p/sandbox/gm9n3c?file=/src/index.js -->
<script>
import { Motion, AnimatePresence } from "$lib/motion-start";
import Box from "../Box.svelte";
import { AnimatePresence } from "$lib/motion-start";
import Card from "$lib/components/Card.svelte";
let index = 0;
$: mint = index + 1;
</script>

<div
class="w-64 h-64 relative bg-gray-700/40 rounded-lg flex justify-center items-center"
>
<AnimatePresence initial={false} let:item list={[{ key: index }]}>
<Card bind:index={mint} frontCard={false} />
<Card bind:index drag="x" frontCard={true} />
</AnimatePresence>
</div>
<Box>
<div
class="w-64 h-64 relative bg-gray-700/40 rounded-lg flex justify-center items-center"
>
<AnimatePresence initial={false} list={[{ key: index }]}>
<Card bind:index={mint} frontCard={false} />
<Card bind:index drag="x" frontCard={true} />
</AnimatePresence>
</div>
</Box>
6 changes: 3 additions & 3 deletions src/lib/components/motion/AnimationSequence.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import Box from "../Box.svelte";
import { Motion, useAnimation } from "$lib/motion-start";
import { motion, useAnimation } from "$lib/motion-start";
let controls = useAnimation();
let startCode = async () => {
let all = [
Expand All @@ -21,7 +21,7 @@
};
</script>

<Box cls="bg-slate-800 text-black">
<Motion.div animate={controls} onTap={startCode} class="box">Tap</Motion.div
<Box>
<motion.div animate={controls} onTap={startCode} class="box">Tap</motion.div
>
</Box>
35 changes: 19 additions & 16 deletions src/lib/components/motion/ColorInterpolation.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import { Motion, useMotionValue, useTransform } from "$lib/motion-start";
import Box from "../Box.svelte";
import { motion, useMotionValue, useTransform } from "$lib/motion-start";
let x = useMotionValue(0);
let background = useTransform(
x,
Expand All @@ -9,21 +10,23 @@
</script>

<!-- Color Interpolation -->
<Motion.div
style={{
background,
}}
class=" h-[350px] border border-dashed flex justify-center items-center rounded-3xl"
>
<Motion.div
<Box cls="grid cols-1 rows-1 justify-stretch">
<motion.div
style={{
x: x,
background,
}}
drag="x"
dragConstraints={{ right: 0, left: 0 }}
whileTap={{ cursor: "grabbing" }}
class="w-32 h-32 text-black rounded-full bg-white cursor-grab flex justify-center items-center select-none"
class="h-full w-full border border-dashed flex justify-center items-center rounded-3xl"
>
Drag me
</Motion.div>
</Motion.div>
<motion.div
style={{
x: x,
}}
drag="x"
dragConstraints={{ right: 0, left: 0 }}
whileTap={{ cursor: "grabbing" }}
class="w-32 h-32 text-black rounded-full bg-white cursor-grab flex justify-center items-center select-none"
>
Drag me
</motion.div>
</motion.div>
</Box>
21 changes: 12 additions & 9 deletions src/lib/components/motion/CyclingThroughStates.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Box from "../Box.svelte";

// Cycling through states
import { Motion, useCycle } from "$lib/motion-start";
import { motion, useCycle, useMotionValue } from "$lib/motion-start";
let stateText = "State 1";
// In React
// const [animate, cycle] = useCycle(
Expand All @@ -16,14 +16,17 @@
// }
// );
// In Svelte
let rotate = useCycle(0, 90);
let scale = useCycle(0.8, 1.2);
let [rotate, cycleRotate] = useCycle(0, 90);
let [scale, cycleScale] = useCycle(0.8, 1.2);
let x = useCycle(0, 140);
let backgroundColor = useCycle("#9EF4FF", "#0FBFFF");
let [backgroundColor, cycleBackgroundColor] = useCycle(
"#9EF4FF",
"#0FBFFF",
);
</script>

<Box cls="bg-slate-800 text-black">
<Motion.div
<Box>
<motion.div
animate={{
scale: $scale,
backgroundColor: $backgroundColor,
Expand All @@ -32,8 +35,8 @@
duration: 0.3,
}}
onTap={() => {
scale.next();
backgroundColor.next();
cycleScale();
cycleBackgroundColor();
if (stateText === "State 1") {
stateText = "State 2";
} else {
Expand All @@ -43,5 +46,5 @@
class="box"
>
{stateText}
</Motion.div>
</motion.div>
</Box>
Loading
Loading