svelte-lottie-player
svelte-lottie-player copied to clipboard
Add typescript declarations file
Closes #16.
Please double check, if the types are correct and complete 😅
Could you add more player's methods to the type declaration file. That make controlling player via script more comfortable.
I have just researched LottiePlayer.svelte
file and add some methods here. However, I don't know whether my type declaration is correct or not.
import type { SvelteComponentTyped } from 'svelte'
export class LottiePlayer extends SvelteComponentTyped<{
autoplay?: boolean
background: string
controls: boolean
controlsLayout?: string[]
count?: number
defaultFrame?: number
direction?: number
height: number
hover?: boolean
loop?: boolean
mode?: 'normal' | 'bounce'
onToggleZoom?: (isZoomed: boolean) => void
renderer?: 'svg' | 'canvas'
speed?: number
src?: string
style?: string
width: number
}> {
/**
* Returns the lottie-web version and this player's version
*/
getVersions(): { lottieWebVersion: string, svelteLottiePlayerVersion: string };
/**
* Returns the lottie-web instance used in the component.
*/
getLottie(): any;
/**
* Pause animation play.
*/
pause(): void;
/**
* Start playing animation.
*/
play(): void;
/**
* Stops animation play.
*/
stop(): void;
/**
* Freeze animation play.
* This internal state pauses animation and is used to differentiate between
* user requested pauses and component instigated pauses.
*/
freeze(): void;
/**
* Resize animation.
*/
resize(): void;
/**
* Seek to a given frame.
* @param frame Frame number or Percent string to seek to.
*/
seek(frame: number|string): void;
/**
* Snapshot the current frame as SVG.
* @param download If 'download' argument is boolean true, then a download is triggered in browser.
*/
snapshot(download?: boolean): void;
/**
* Sets the looping of the animation.
* @param value Whether to enable looping. Boolean true enables looping.
*/
setLooping(value: boolean): void;
/**
* Sets the speed of the animation.
* @param value The speed of the animation. 1 is normal speed.
*/
setSpeed(value: number): void;
/**
* Animation play direction.
* @param value Direction values.
*/
setDirection(value: number): void;
/**
* Toggle playing state.
*/
togglePlay(): void;
/**
* Toggle zoom state.
*/
toggleZoom(): void;
/**
* Toggles animation looping.
*/
toggleLooping(): void;
/**
* Sets background color.
*/
setBackgroundColor(color: string): void;
}
@megaheart Thanks for the suggestion and input. 🙏 I pretty much used your code except for getLottie
and setBackground
😉
@jneuendorf I think your package.json
should also have a types
field:
// package.json
{
...
+ "types": "index.d.ts"
...
}
@jneuendorf I think your
package.json
should also have atypes
field:// package.json { ... + "types": "index.d.ts" ... }
@jakemckown Thanks for the hint. Do you have a preference regarding the location of the file? As it seems both the src
and the dist
folder are part of the NPM package. Should it be placed in the dist
folder rather than in the project root? I guess, this would require copying to dist
and I am not sure what the best way to do this would be (extend build
script or rollup config).
@jneuendorf I think where you have it in the root is the best option for adding a declarations file to a non-TypeScript project. It technically doesn't matter as long as the types
field points to it. But that does remind me that you also need to include it in the files
field so that it gets published with the package.
// package.json
{
...
"files": [
"src/components",
- "dist"
+ "dist",
+ "index.d.ts"
]
...
}
⚠️ No Changeset found
Latest commit: 45a4aec2bc0c36291e45ce1388d5ec36dd4da0c4
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Hey, what's the hold up on this pull request?
Can this be merge or is there anything missing I can help with?
For now, I've copy pasted the contents in index.d.ts
and added them to src/ambient.d.ts
.