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

Add typescript declarations file #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jneuendorf
Copy link

@jneuendorf jneuendorf commented Sep 2, 2023

Closes #16.

Please double check, if the types are correct and complete 😅

@jneuendorf jneuendorf mentioned this pull request Sep 2, 2023
@megaheart
Copy link

Could you add more player's methods to the type declaration file. That make controlling player via script more comfortable.

@megaheart
Copy link

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;
    

}

@jneuendorf
Copy link
Author

jneuendorf commented Sep 17, 2023

@megaheart Thanks for the suggestion and input. 🙏 I pretty much used your code except for getLottie and setBackground 😉

@jakemckown
Copy link
Contributor

@jneuendorf I think your package.json should also have a types field:

// package.json
  {
    ...
+   "types": "index.d.ts"
    ...
  }

See Including declarations in your npm package.

@jneuendorf
Copy link
Author

@jneuendorf I think your package.json should also have a types field:

// package.json
  {
    ...
+   "types": "index.d.ts"
    ...
  }

See Including declarations in your npm package.

@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).

@jakemckown
Copy link
Contributor

@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"
  ]
  ...
}

Copy link

changeset-bot bot commented Jan 30, 2024

⚠️ No Changeset found

Latest commit: 45a4aec

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

@pjarnfelt
Copy link

Hey, what's the hold up on this pull request?

@a4vg
Copy link

a4vg commented Apr 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No typescript?
5 participants