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

refactor(svelte): migrate to svelte 5 #391

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
142 changes: 69 additions & 73 deletions packages/svelte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ npm install @lottiefiles/dotlottie-svelte

```svelte
<script lang="ts">
import { DotLottieSvelte } from '@lottiefiles/dotlottie-svelte';
import { DotLottieSvelte } from '@lottiefiles/dotlottie-svelte';
</script>

<DotLottieSvelte
src="path/to/animation.lottie"
loop
autoplay
/>
<DotLottieSvelte src="path/to/animation.lottie" loop autoplay />
```

## Live Examples
Expand Down Expand Up @@ -92,29 +88,29 @@ Here is an example:

```svelte
<script lang="ts">
import { DotLottieSvelte } from '@lottiefiles/dotlottie-svelte';
import type { DotLottie } from '@lottiefiles/dotlottie-svelte';
let dotLottie: DotLottie | null = null;

function play() {
dotLottie?.play();
}

function pause() {
dotLottie?.pause();
}

function stop() {
dotLottie?.stop();
}
import { DotLottieSvelte } from '@lottiefiles/dotlottie-svelte';
import type { DotLottie } from '@lottiefiles/dotlottie-svelte';

let dotLottie: DotLottie | null = null;

function play() {
dotLottie?.play();
}

function pause() {
dotLottie?.pause();
}

function stop() {
dotLottie?.stop();
}
</script>

<DotLottieSvelte
src="path/to/your/animation.lottie"
loop={true}
autoplay={true}
dotLottieRefCallback={(ref) => dotLottie = ref}
src="path/to/your/animation.lottie"
loop={true}
autoplay={true}
dotLottieRefCallback={(ref) => (dotLottie = ref)}
/>

<button on:click={play}>Play</button>
Expand All @@ -132,56 +128,56 @@ Here is an example:

```svelte
<script lang="ts">
import { DotLottieSvelte } from '@lottiefiles/dotlottie-svelte';
import type { DotLottie } from '@lottiefiles/dotlottie-svelte';

let dotLottie: DotLottie | null = null;

function onLoaded() {
console.log("Animation loaded");
}

function onPlay() {
console.log("Animation started");
}

function onPause() {
console.log("Animation paused");
}

function onComplete() {
console.log("Animation completed");
}
function setupListeners(dotLottieInstance) {
dotLottieInstance.addEventListener('load', onLoaded);
dotLottieInstance.addEventListener('play', onPlay);
dotLottieInstance.addEventListener('pause', onPause);
dotLottieInstance.addEventListener('complete', onComplete);
}

function removeListeners(dotLottieInstance) {
dotLottieInstance.removeEventListener('load', onLoaded);
dotLottieInstance.removeEventListener('play', onPlay);
dotLottieInstance.removeEventListener('pause', onPause);
dotLottieInstance.removeEventListener('complete', onComplete);
}

onDestroy(() => {
if (dotLottie) {
removeListeners(dotLottie);
}
});
import { DotLottieSvelte } from '@lottiefiles/dotlottie-svelte';
import type { DotLottie } from '@lottiefiles/dotlottie-svelte';

let dotLottie: DotLottie | null = null;

function onLoaded() {
console.log('Animation loaded');
}

function onPlay() {
console.log('Animation started');
}

function onPause() {
console.log('Animation paused');
}

function onComplete() {
console.log('Animation completed');
}

function setupListeners(dotLottieInstance) {
dotLottieInstance.addEventListener('load', onLoaded);
dotLottieInstance.addEventListener('play', onPlay);
dotLottieInstance.addEventListener('pause', onPause);
dotLottieInstance.addEventListener('complete', onComplete);
}

function removeListeners(dotLottieInstance) {
dotLottieInstance.removeEventListener('load', onLoaded);
dotLottieInstance.removeEventListener('play', onPlay);
dotLottieInstance.removeEventListener('pause', onPause);
dotLottieInstance.removeEventListener('complete', onComplete);
}

onDestroy(() => {
if (dotLottie) {
removeListeners(dotLottie);
}
});
</script>

<DotLottieSvelte
src="path/to/your/animation.lottie"
loop={true}
autoplay={true}
dotLottieRefCallback={(ref) => {
dotLottie = ref;
setupListeners(dotLottie);
}}
src="path/to/your/animation.lottie"
loop={true}
autoplay={true}
dotLottieRefCallback={(ref) => {
dotLottie = ref;
setupListeners(dotLottie);
}}
/>
```

Expand Down
18 changes: 9 additions & 9 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/kit": "^2.5.27",
"@sveltejs/package": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@types/eslint": "8.56.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0-next.4",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^3.1.2",
"eslint-plugin-svelte": "^2.45.1",
"prettier": "^3.1.0",
"prettier-plugin-svelte": "^3.2.6",
"publint": "^0.1.9",
"svelte": "^5.0.0-next.1",
"svelte-check": "^3.6.0",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"tslib": "^2.4.1",
"typescript": "^5.0.3",
"vite": "^5.0.13",
"typescript": "^5.5.0",
"vite": "^5.4.4",
"vitest": "^1.2.2"
},
"publishConfig": {
Expand Down
Loading
Loading