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

fix: use modern Spring and MediaQuery implementation #361

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tiny-colts-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/create': patch
---

fix: use modern `Spring` implementation
4 changes: 2 additions & 2 deletions packages/create/templates/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"devDependencies": {
"@fontsource/fira-mono": "^5.0.0",
"@neoconfetti/svelte": "^2.0.0",
"@sveltejs/adapter-auto": "workspace:*",
"@sveltejs/kit": "workspace:*",
"@sveltejs/adapter-auto": "^3",
"@sveltejs/kit": "^2",
"@sveltejs/vite-plugin-svelte": "^5.0.0",
"svelte": "^5.0.0",
"typescript": "^5.3.3",
Expand Down
21 changes: 7 additions & 14 deletions packages/create/templates/demo/src/routes/Counter.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
<script lang="ts">
import { spring } from 'svelte/motion';
import { Spring } from 'svelte/motion';

let count = $state(0);

// svelte-ignore state_referenced_locally
const displayedCount = spring(count);

$effect(() => {
displayedCount.set(count);
});
let offset = $derived(modulo($displayedCount, 1));
const count = new Spring(0);
const offset = $derived(modulo(count.current, 1));

/**
* @param {number} n
Expand All @@ -22,20 +15,20 @@
</script>

<div class="counter">
<button onclick={() => (count -= 1)} aria-label="Decrease the counter by one">
<button onclick={() => (count.target -= 1)} aria-label="Decrease the counter by one">
<svg aria-hidden="true" viewBox="0 0 1 1">
<path d="M0,0.5 L1,0.5" />
</svg>
</button>

<div class="counter-viewport">
<div class="counter-digits" style="transform: translate(0, {100 * offset}%)">
<strong class="hidden" aria-hidden="true">{Math.floor($displayedCount + 1)}</strong>
<strong>{Math.floor($displayedCount)}</strong>
<strong class="hidden" aria-hidden="true">{Math.floor(count.current + 1)}</strong>
<strong>{Math.floor(count.current)}</strong>
</div>
</div>

<button onclick={() => (count += 1)} aria-label="Increase the counter by one">
<button onclick={() => (count.target += 1)} aria-label="Increase the counter by one">
<svg aria-hidden="true" viewBox="0 0 1 1">
<path d="M0,0.5 L1,0.5 M0.5,0 L0.5,1" />
</svg>
Expand Down
Loading