├── .browserslistrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitattributes ├── .github └── workflows │ └── storybook.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .storybook ├── main.js └── manager.js ├── LICENSE ├── README.md ├── assets └── screenshot1.png ├── babel.config.js ├── jest.config.js ├── package.json ├── prettier.config.js ├── rollup.config.js ├── src ├── components │ ├── ColorPicker.svelte │ ├── Controls.svelte │ ├── Info.svelte │ ├── LottiePlayer.svelte │ ├── Popover.svelte │ ├── index.js │ ├── store.js │ ├── utils.js │ └── versions.js └── stories │ ├── LottiePlayer.stories.js │ └── Wrapper.svelte └── yarn.lock /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 0.25% 2 | not dead 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | max_line_length = 120 11 | tab_width = 2 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # Third party 2 | **/node_modules 3 | 4 | # Build products 5 | docs/ 6 | dist/ 7 | 8 | # Testing 9 | coverage/ 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parserOptions: { 3 | ecmaVersion: 2019, 4 | sourceType: 'module', 5 | }, 6 | env: { 7 | es6: true, 8 | browser: true, 9 | node: true, 10 | }, 11 | extends: 'eslint:recommended', 12 | plugins: ['svelte3'], 13 | overrides: [ 14 | { 15 | files: ['**/*.svelte'], 16 | processor: 'svelte3/svelte3', 17 | }, 18 | ], 19 | rules: { 20 | // ... 21 | }, 22 | }; 23 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.svelte linguist-language=HTML 2 | -------------------------------------------------------------------------------- /.github/workflows/storybook.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | paths: ['src/stories/**', 'src/components/**'] 6 | 7 | name: Publish storybook 8 | 9 | jobs: 10 | build-and-deploy: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 🛎️ 14 | uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly. 15 | with: 16 | persist-credentials: false 17 | 18 | - name: Install and Build 🔧 19 | run: | 20 | yarn install 21 | yarn build-storybook 22 | 23 | - name: Deploy 🚀 24 | uses: JamesIves/github-pages-deploy-action@releases/v3 25 | with: 26 | ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 27 | BRANCH: gh-pages 28 | FOLDER: storybook-static # Deploy the storybook static build 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Package management 9 | node_modules 10 | package-lock.json 11 | 12 | # Optional npm cache directory 13 | .npm 14 | 15 | # Optional eslint cache 16 | .eslintcache 17 | 18 | # Yarn stuff 19 | .pnp.* 20 | .yarn-integrity 21 | 22 | # Storybook 23 | storybook-static 24 | 25 | # Build and dev artifacts 26 | dist/ 27 | public/bundle.* 28 | 29 | # IDE related 30 | **/.idea 31 | **/.vscode 32 | **/.history 33 | 34 | # Operating system 35 | .DS_Store 36 | .tmp 37 | *.bak 38 | *.swp 39 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Ignore examples and assets 2 | assets 3 | examples 4 | 5 | # Editor config 6 | .editorconfig 7 | 8 | # Eslint configs 9 | .eslintignore 10 | .eslintrc.js 11 | 12 | # Prettier configs 13 | .prettierignore 14 | .prettierrc.js 15 | 16 | # Babel configs 17 | babel.config.js 18 | 19 | # Testing configs 20 | jest.config.js 21 | 22 | # Rollup configs 23 | rollup.config.js 24 | 25 | # NPM 26 | yarn.lock 27 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # package.json is formatted by package managers, so we ignore it here 2 | package.json 3 | 4 | # Build artifacts 5 | dist/ 6 | -------------------------------------------------------------------------------- /.storybook/main.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | stories: ['../src/stories/**/*.stories.*'], 5 | addons: [ 6 | '@storybook/addon-storysource', 7 | '@storybook/addon-actions', 8 | '@storybook/addon-links', 9 | '@storybook/addon-knobs', 10 | '@storybook/addon-backgrounds', 11 | '@storybook/addon-viewport', 12 | '@storybook/addon-a11y', 13 | ], 14 | webpackFinal: async (config) => { 15 | config.module.rules.push({ 16 | test: [/\.stories\.js$/, /index\.js$/], 17 | loaders: [require.resolve('@storybook/source-loader')], 18 | include: [path.resolve(__dirname, '../src')], 19 | enforce: 'pre', 20 | }); 21 | return config; 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /.storybook/manager.js: -------------------------------------------------------------------------------- 1 | import { addons } from '@storybook/addons'; 2 | 3 | addons.setConfig({ 4 | showRoots: true, 5 | }); 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 LottieFiles.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Svelte Lottie Player 2 | 3 | ![npm (scoped)](https://img.shields.io/npm/v/@lottiefiles/svelte-lottie-player?style=flat-square) 4 | ![NPM](https://img.shields.io/npm/l/@lottiefiles/svelte-lottie-player?style=flat-square) 5 | ![David](https://img.shields.io/david/LottieFiles/svelte-lottie-player?style=flat-square) 6 | ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@lottiefiles/svelte-lottie-player?style=flat-square) 7 | 8 | > Lottie player component for use with Svelte. 9 | 10 | This provides a Lottie player using the lottie-web library, adding a control toolbar, render graph and other handy 11 | configs for viewing Lottie animations. 12 | 13 | ![Screenshot](assets/screenshot1.png?raw=true) 14 | 15 | ## Features 16 | 17 | - Configuration of lottie-web via props 18 | - Control toolbar with play, pause, stop, progress track with seeker, looping 19 | - Render graph for viewing frame render times 20 | 21 | ## Table of Contents 22 | 23 | - [Getting started](#getting-started) 24 | - [Installation](#installation) 25 | - [Usage](#usage) 26 | 27 | ## Demos 28 | 29 | - [Component Storybook](https://lottiefiles.github.io/svelte-lottie-player/) 30 | - [Basic usage on Svelte REPL](https://svelte.dev/repl/c7c774dba1464389af5d738a9e486658) 31 | 32 | ## Installation 33 | 34 | With `yarn`: 35 | 36 | ```bash 37 | yarn add @lottiefiles/svelte-lottie-player 38 | ``` 39 | 40 | With `npm`: 41 | 42 | ```bash 43 | npm install --save @lottiefiles/svelte-lottie-player 44 | ``` 45 | 46 | ## Usage 47 | 48 | Basic steps for use in a Svelte project: 49 | 50 | ```html 51 | 52 | 70 | 71 | 82 | ``` 83 | 84 | [examples-folder-url]: https://github.com/LottieFiles/svelte-lottie-player/tree/master/examples 85 | [examples-basic]: https://github.com/LottieFiles/svelte-lottie-player/tree/master/examples/basic 86 | -------------------------------------------------------------------------------- /assets/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LottieFiles/svelte-lottie-player/3a0886dbe1d24ca03f5ce2da73043a67e29b2aec/assets/screenshot1.png -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['@babel/preset-env'], 3 | ignore: ['node_modules/**'], 4 | }; 5 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | // For a detailed explanation regarding each configuration property, visit: 2 | // https://jestjs.io/docs/en/configuration.html 3 | 4 | module.exports = { 5 | transformIgnorePatterns: ['/node_modules/'], 6 | transform: { 7 | "^.+\\.js$": "babel-jest", 8 | "^.+\\.svelte$": "svelte-jester" 9 | }, 10 | moduleFileExtensions: [ 11 | 'js', 12 | 'svelte' 13 | ], 14 | setupFilesAfterEnv: [ 15 | '@testing-library/jest-dom/extend-expect' 16 | ] 17 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@lottiefiles/svelte-lottie-player", 3 | "version": "0.3.1", 4 | "svelte": "src/components/index.js", 5 | "exports": { 6 | ".": { 7 | "svelte": "./src/components/index.js" 8 | } 9 | }, 10 | "module": "dist/index.mjs", 11 | "main": "dist/index.js", 12 | "description": "Lottie animation player component for Svelte", 13 | "keywords": [ 14 | "lottie", 15 | "lottiefiles", 16 | "dotlottie", 17 | "svelte", 18 | "component", 19 | "svelte-component" 20 | ], 21 | "author": "Jawish Hameed ", 22 | "license": "MIT", 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/LottieFiles/svelte-lottie-player.git" 26 | }, 27 | "homepage": "https://github.com/LottieFiles/svelte-lottie-player", 28 | "bugs": { 29 | "url": "https://github.com/LottieFiles/svelte-lottie-player/issues" 30 | }, 31 | "scripts": { 32 | "predev": "node -p \"'export const SVELTE_LOTTIE_PLAYER_VERSION = ' + JSON.stringify(require('./package.json').version) + '; \\n' + 'export const LOTTIE_WEB_VERSION = ' + JSON.stringify(require('./package.json').dependencies['lottie-web']) + ';'\" > src/components/versions.js", 33 | "dev": "rollup -c -w", 34 | "prebuild": "node -p \"'export const SVELTE_LOTTIE_PLAYER_VERSION = ' + JSON.stringify(require('./package.json').version) + '; \\n' + 'export const LOTTIE_WEB_VERSION = ' + JSON.stringify(require('./package.json').dependencies['lottie-web']) + ';'\" > src/components/versions.js", 35 | "build": "rollup -c", 36 | "prepublishOnly": "yarn build", 37 | "lint": "eslint src/", 38 | "lint:fix": "eslint src/ --fix", 39 | "storybook": "start-storybook -p 6006", 40 | "build-storybook": "build-storybook" 41 | }, 42 | "devDependencies": { 43 | "@babel/core": "^7.9.6", 44 | "@rollup/plugin-commonjs": "11.1.0", 45 | "@rollup/plugin-node-resolve": "^7.1.3", 46 | "@rollup/plugin-strip": "^1.3.2", 47 | "@storybook/addon-a11y": "^5.3.18", 48 | "@storybook/addon-actions": "^5.3.18", 49 | "@storybook/addon-backgrounds": "^5.3.18", 50 | "@storybook/addon-knobs": "^5.3.18", 51 | "@storybook/addon-links": "^5.3.18", 52 | "@storybook/addon-storysource": "^5.3.18", 53 | "@storybook/addon-viewport": "^5.3.18", 54 | "@storybook/addons": "^5.3.18", 55 | "@storybook/source-loader": "^5.3.18", 56 | "@storybook/svelte": "^5.3.18", 57 | "babel-loader": "^8.1.0", 58 | "eslint": "^6.8.0", 59 | "eslint-plugin-svelte3": "^2.7.3", 60 | "husky": "^4.2.5", 61 | "lint-staged": "^10.2.2", 62 | "npm-run-all": "^4.1.5", 63 | "prettier": "^2.0.5", 64 | "prettier-plugin-svelte": "^0.7.0", 65 | "rollup": "^2.7.6", 66 | "rollup-plugin-svelte": "^6.1.1", 67 | "rollup-plugin-terser": "^5.3.0", 68 | "svelte": "^3.21.0", 69 | "svelte-loader": "^2.13.6" 70 | }, 71 | "dependencies": { 72 | "lottie-web": "^5.10.0" 73 | }, 74 | "files": [ 75 | "src/components", 76 | "dist" 77 | ], 78 | "husky": { 79 | "hooks": { 80 | "pre-commit": "lint-staged" 81 | } 82 | }, 83 | "lint-staged": { 84 | "*.{html, css, scss, stylus, js, ts, json, yml, md}": [ 85 | "prettier --write" 86 | ], 87 | "*.{js, svelte}": [ 88 | "eslint . --fix" 89 | ] 90 | }, 91 | "publishConfig": { 92 | "access": "public" 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSpacing: true, 4 | endOfLine: 'lf', 5 | insertPragma: false, 6 | jsxBracketSameLine: false, 7 | printWidth: 120, 8 | proseWrap: 'always', 9 | requirePragma: false, 10 | semi: true, 11 | singleQuote: true, 12 | tabWidth: 2, 13 | trailingComma: 'all', 14 | useTabs: false, 15 | overrides: [ 16 | { 17 | files: '*.json', 18 | options: { 19 | tabWidth: 2, 20 | singleQuote: false, 21 | }, 22 | }, 23 | ], 24 | 25 | // Svelte configs 26 | svelteSortOrder: 'styles-scripts-markup', 27 | svelteStrictMode: true, 28 | svelteBracketNewLine: true, 29 | svelteAllowShorthand: true, 30 | }; 31 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import commonjs from '@rollup/plugin-commonjs'; 2 | import resolve from '@rollup/plugin-node-resolve'; 3 | import strip from '@rollup/plugin-strip'; 4 | import svelte from 'rollup-plugin-svelte'; 5 | import { terser } from 'rollup-plugin-terser'; 6 | 7 | import pkg from './package.json'; 8 | 9 | const isProduction = !process.env.ROLLUP_WATCH; 10 | const name = pkg.name 11 | .replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3') 12 | .replace(/^\w/, m => m.toUpperCase()) 13 | .replace(/-\w/g, m => m[1].toUpperCase()); 14 | 15 | export default { 16 | input: 'src/components/index.js', 17 | output: [ 18 | { 19 | file: pkg.module, 20 | format: 'es', 21 | sourcemap: true, 22 | name, 23 | }, 24 | { 25 | file: pkg.main, 26 | format: 'umd', 27 | sourcemap: true, 28 | name, 29 | }, 30 | ], 31 | plugins: [ 32 | // Strip assert and console.log statements 33 | strip(), 34 | 35 | svelte({ 36 | // Enable run-time checks when not in production 37 | dev: !isProduction, 38 | }), 39 | 40 | // If you have external dependencies installed from 41 | // npm, you'll most likely need these plugins. In 42 | // some cases you'll need additional configuration — 43 | // consult the documentation for details: 44 | // https://github.com/rollup/plugins/tree/master/packages/commonjs 45 | resolve({ 46 | browser: true, 47 | dedupe: importee => { 48 | return importee === 'svelte' || importee.startsWith('svelte/'); 49 | }, 50 | }), 51 | commonjs(), 52 | 53 | // In production mode, minify 54 | isProduction && terser(), 55 | ], 56 | 57 | watch: { 58 | clearScreen: true, 59 | }, 60 | }; 61 | -------------------------------------------------------------------------------- /src/components/ColorPicker.svelte: -------------------------------------------------------------------------------- 1 | 59 | 60 | 116 | 117 |
118 |
119 |
120 | Red 121 | 122 | 123 |
124 |
125 | Green 126 | 127 | 128 |
129 |
130 | Blue 131 | 132 | 133 |
134 |
135 |
136 |
137 |
138 | parseColor(e.target.value)} /> 143 |
144 |
145 |
146 | -------------------------------------------------------------------------------- /src/components/Controls.svelte: -------------------------------------------------------------------------------- 1 | 152 | 153 | 227 | 228 |
229 | {#each layout as item} 230 | {#if item === 'playpause'} 231 |
232 | {#if isPlaying} 233 | 234 | 235 | 236 | 237 | {:else} 238 | 239 | 240 | 241 | {/if} 242 |
243 | {:else if item === 'stop'} 244 |
245 | 246 | 250 | 251 |
252 | {:else if item === 'progress'} 253 | 268 | {:else if item === 'loop'} 269 |
270 | 271 | 281 | 295 | 296 |
297 | {:else if item === 'background'} 298 |
299 | 300 |
301 | 302 | 309 | 310 |
311 |
312 | 313 |
314 |
315 |
316 | {:else if item === 'snapshot'} 317 |
322 | 323 |
324 | 325 | 332 | 333 | 334 | 340 | 341 |
342 |
343 |
Frame {formattedFrame}
344 | Download SVG 345 | Download PNG 346 | Scroll with mousewheel to find exact frame 347 |
348 |
349 |
350 | {:else if item === 'zoom'} 351 |
352 | {#if isZoomed} 353 | 354 | 360 | 361 | {:else} 362 | 363 | 369 | 370 | {/if} 371 |
372 | {:else if item === 'info'} 373 |
374 | 375 |
376 | 377 | 384 | 390 | 391 |
392 |
393 | 394 |
395 |
396 |
397 | {:else if item === 'frame'} 398 |
399 | 408 |
409 | {:else if item === 'nextFrame'} 410 |
411 | 412 | 416 | 417 | 418 |
419 | {:else if item === 'previousFrame'} 420 |
421 | 422 | 423 | 424 | 425 |
426 | {:else if item === 'spacer'} 427 |
428 | {/if} 429 | {/each} 430 |
431 | -------------------------------------------------------------------------------- /src/components/Info.svelte: -------------------------------------------------------------------------------- 1 | 35 | 36 | 61 | 62 |

Info

63 | 64 | {#if version} 65 |
66 | Lottie Version 67 | {version} 68 |
69 | {/if} 70 | 71 | {#if numFrames} 72 |
73 | Frames 74 | {numFrames} 75 |
76 | {/if} 77 | 78 | {#if frameRate} 79 |
80 | Frame Rate 81 | {frameRate} 82 |
83 | {/if} 84 | 85 | {#if numLayers} 86 |
87 | Layers 88 | {numLayers} 89 |
90 | {/if} 91 | 92 | {#if numAssets} 93 |
94 | Assets 95 | {numAssets} 96 |
97 | {/if} 98 | 99 | {#if numFonts} 100 |
101 | Fonts 102 | {numFonts} 103 |
104 | {/if} 105 | 106 | {#if hasMeta} 107 |
108 | 109 | {#if generator} 110 |
111 | Generator 112 | {generator} 113 |
114 | {/if} 115 | 116 | {#if author} 117 |
118 | Author 119 | {author} 120 |
121 | {/if} 122 | 123 | {#if keywords} 124 |
125 | Keywords 126 | {keywords} 127 |
128 | {/if} 129 | 130 | {#if themeColor} 131 |
132 | Theme Color 133 | {themeColor} 134 |
135 | {/if} 136 | {/if} 137 | -------------------------------------------------------------------------------- /src/components/LottiePlayer.svelte: -------------------------------------------------------------------------------- 1 | 525 | 526 | 556 | 557 |
562 |
567 |
571 | {#if currentState === PlayerState.Error} 572 |
⚠️
573 | {/if} 574 |
575 | {#if controls} 576 | setBackground(e.detail.color)} 578 | layout={controlsLayout} 579 | {animationData} 580 | {background} 581 | {controls} 582 | {currentState} 583 | {frame} 584 | {freeze} 585 | {instance} 586 | {loop} 587 | {lottie} 588 | {pause} 589 | {play} 590 | {progress} 591 | {seek} 592 | {setDirection} 593 | {setSpeed} 594 | {setLooping} 595 | {snapshot} 596 | {src} 597 | {stop} 598 | {toggleZoom} 599 | {toggleLooping} 600 | {togglePlay} 601 | {totalFrames} /> 602 | {/if} 603 |
604 |
605 | -------------------------------------------------------------------------------- /src/components/Popover.svelte: -------------------------------------------------------------------------------- 1 | 38 | 39 | 81 | 82 |
89 |
90 | 91 |
92 |
98 | 99 |
102 |
103 |
104 | -------------------------------------------------------------------------------- /src/components/index.js: -------------------------------------------------------------------------------- 1 | import LottiePlayer from './LottiePlayer.svelte'; 2 | import Controls from './Controls.svelte'; 3 | import { parseSrc, PlayMode, PlayerEvents, PlayerState } from './utils'; 4 | 5 | export { 6 | Controls, 7 | LottiePlayer, 8 | PlayerEvents, 9 | PlayerState, 10 | PlayMode, 11 | parseSrc, 12 | }; 13 | -------------------------------------------------------------------------------- /src/components/store.js: -------------------------------------------------------------------------------- 1 | import { writable } from 'svelte/store'; 2 | 3 | export const autoplay = writable(); 4 | export const background = writable(); 5 | export const controls = writable(); 6 | export const loopCount = writable(); 7 | export const defaultFrame = writable(); 8 | export const direction = writable(); 9 | export const hover = writable(); 10 | export const loop = writable(); 11 | export const mode = writable(); 12 | export const speed = writable(); 13 | export const state = writable(); 14 | 15 | export const instance = writable(); 16 | export const animationData = writable(); 17 | export const frame = writable(); 18 | export const progress = writable(); 19 | -------------------------------------------------------------------------------- /src/components/utils.js: -------------------------------------------------------------------------------- 1 | export const PlayerRender = { 2 | SVG: 'svg', 3 | Canvas: 'canvas' 4 | } 5 | 6 | // Define valid player states 7 | export const PlayerState = { 8 | Loading: 'loading', 9 | Playing: 'playing', 10 | Paused: 'paused', 11 | Stopped: 'stopped', 12 | Frozen: 'frozen', 13 | Error: 'error', 14 | }; 15 | 16 | // Define play modes 17 | export const PlayMode = { 18 | Normal: 'normal', 19 | Bounce: 'bounce', 20 | }; 21 | 22 | // Define player events 23 | export const PlayerEvents = { 24 | Load: 'load', 25 | Error: 'error', 26 | Ready: 'ready', 27 | Play: 'play', 28 | Pause: 'pause', 29 | Stop: 'stop', 30 | Freeze: 'freeze', 31 | Loop: 'loop', 32 | Complete: 'complete', 33 | Frame: 'frame', 34 | }; 35 | 36 | // Define controls layout options 37 | export const ControlsLayoutOptions = [ 38 | "previousFrame", 39 | "playpause", 40 | "stop", 41 | "nextFrame", 42 | "progress", 43 | "frame", 44 | "loop", 45 | "spacer", 46 | "background", 47 | "snapshot", 48 | "info", 49 | "zoom" 50 | ]; 51 | 52 | /** 53 | * Parse a resource into a JSON object or a URL string 54 | */ 55 | export const parseSrc = src => { 56 | if (typeof src === 'object') { 57 | return src; 58 | } 59 | 60 | try { 61 | return JSON.parse(src); 62 | } catch (e) { 63 | // Try construct an absolute URL from the src URL 64 | const srcUrl = new URL(src, window.location.href); 65 | 66 | return srcUrl.toString(); 67 | } 68 | }; 69 | 70 | /** 71 | * Trigger the download of the given data URI as a file 72 | * 73 | * @param {string} dataUri 74 | * @param {string} name 75 | */ 76 | export const triggerDownload = (dataUri, filename) => { 77 | const element = document.createElement('a'); 78 | element.href = dataUri; 79 | element.download = filename; 80 | document.body.appendChild(element); 81 | 82 | element.click(); 83 | 84 | document.body.removeChild(element); 85 | }; 86 | -------------------------------------------------------------------------------- /src/components/versions.js: -------------------------------------------------------------------------------- 1 | export const SVELTE_LOTTIE_PLAYER_VERSION = "0.3.0"; 2 | export const LOTTIE_WEB_VERSION = "^5.10.0"; 3 | -------------------------------------------------------------------------------- /src/stories/LottiePlayer.stories.js: -------------------------------------------------------------------------------- 1 | import { withKnobs, boolean, text, color, number, select } from '@storybook/addon-knobs'; 2 | 3 | import LottiePlayer from './Wrapper.svelte'; 4 | import { PlayMode, PlayerRender, ControlsLayoutOptions } from '../components/utils'; 5 | 6 | export default { 7 | title: 'LottiePlayer', 8 | decorators: [withKnobs], 9 | }; 10 | 11 | export const Basic = () => ({ 12 | Component: LottiePlayer, 13 | props: { 14 | src: text('Lottie URL/JSON', 'https://assets2.lottiefiles.com/packages/lf20_wxUJzo.json'), 15 | renderer: select('Renderer', PlayerRender), 16 | autoplay: boolean('Auto Play', false), 17 | loop: boolean('Loop', true), 18 | mode: select('Playback mode', PlayMode), 19 | hover: boolean('Play on hover', false), 20 | background: color('Background', '#ffffff'), 21 | defaultFrame: number('Default Frame', 100), 22 | speed: number('Speed', 1), 23 | height: number('Height', ''), 24 | width: number('Width', 500), 25 | controls: boolean('Show Controls', true), 26 | controlsLayout: text('Controls Layout', ControlsLayoutOptions.join(',')), 27 | style: text('Styles', ''), 28 | } 29 | }); 30 | -------------------------------------------------------------------------------- /src/stories/Wrapper.svelte: -------------------------------------------------------------------------------- 1 | 29 | 30 | 37 | 38 |

Lottie Player

39 |

Load and play lottie animations

40 | 41 | 57 | 58 |

59 | Lorem Ipsum is simply dummy text of the printing and typesetting industry. 60 | Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 61 | when an unknown printer took a galley of type and scrambled it to make a type 62 | specimen book. It has survived not only five centuries, but also the leap into 63 | electronic typesetting, remaining essentially unchanged. It was popularised in 64 | the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, 65 | and more recently with desktop publishing software like Aldus PageMaker 66 | including versions of Lorem Ipsum. 67 |

68 | --------------------------------------------------------------------------------