├── .editorconfig
├── .eslintrc.json
├── .gitignore
├── CHANGELOG.md
├── README.md
├── package.json
├── rollup.config.js
└── src
├── ImageCompare.svelte
└── index.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | end_of_line = lf
5 | insert_final_newline = true
6 |
7 | [*.{js,css,html,svelte}]
8 | charset = utf-8
9 | indent_style = tab
10 | indent_size = 4
11 | trim_trailing_whitespace = true
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint:recommended",
3 | "parserOptions": {
4 | "ecmaVersion": 2019,
5 | "sourceType": "module"
6 | },
7 | "plugins": ["svelte3"],
8 | "overrides": [{
9 | "files": ["**/*.svelte"],
10 | "processor": "svelte3/svelte3"
11 | }],
12 | "env": {
13 | "es6": true,
14 | "browser": true
15 | }
16 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | Thumbs.db
3 | node_modules
4 | yarn.lock
5 | package-lock.json
6 | *.log
7 | .idea/
8 | index.js
9 | index.mjs
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # svelte-image-compare changelog
2 |
3 | ## 1.1.1
4 | * fix initial resizing
5 | * update gitignore
6 |
7 | ## 1.1.0
8 | * Update to latest Svelte 3.
9 | * Few re-writes.
10 | * README & CHANGELOG added.
11 | * eslint, editorconfig added.
12 |
13 | ## 1.0.0
14 |
15 | * First release
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Image comparison slider for Svelte 3
2 |
3 | [](https://www.npmjs.com/package/svelte-image-compare) [](https://www.npmjs.com/package/svelte-image-compare)
4 |
5 | Simple Svelte component to compare two images using slider.
6 |
7 | 
8 |
9 | ## Features
10 |
11 | - Simple
12 | - Responsive (fit to the parent width)
13 | - Size difference between two images handled correctly. Element size determined by following two factors:
14 | - width of the parent
15 | - right image's aspect ratio
16 |
17 | ## Install
18 |
19 | ```bash
20 | npm i svelte-image-compare --save
21 | ```
22 |
23 | ```bash
24 | yarn add svelte-image-compare
25 | ```
26 |
27 | CDN: [UNPKG](https://unpkg.com/svelte-image-compare/) | [jsDelivr](https://cdn.jsdelivr.net/npm/svelte-image-compare/) (available as `window.ImageCompare`)
28 |
29 | ## Usage
30 |
31 | ```html
32 |
37 | BEFORE
38 | AFTER
39 |
40 |
41 |
44 | ```
45 |
46 | If you are **not** using using es6, instead of importing add
47 |
48 | ```html
49 |
50 | ```
51 |
52 | just before closing body tag.
53 |
54 | ## API
55 |
56 | ## Props
57 |
58 | | Name | Type | Description | Required | Default |
59 | | --- | --- | --- | --- | --- |
60 | | `before` | `String` | Path to the image image *before* change | Yes | `empty string` |
61 | | `after` | `String` | Path to the image image *after* change | Yes | `empty string` |
62 | | `offset` | `Number` | How far from the left the slider should be on load (between 0 and 1) | No | `0.5` |
63 | | `contain` | `Boolean` | Determines if images are stretched to fill parent element. Can be used with help of CSS `object-fit: cover` to create full page image comparison | No | `false` |
64 | | `overlay` | `Boolean` | Show overlay upon images | No | `true` |
65 | | `hideOnSlide` | `Boolean` | Hide overlay & labels on sliding | No | `true` |
66 |
67 | ## Slots
68 |
69 | - `before` - element to be placed on top of before image (basically a label)
70 | - `after` - element to be placed on top of after image (basically a label)
71 |
72 | ## License
73 |
74 | MIT © [PaulMaly](https://github.com/PaulMaly)
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "svelte-image-compare",
3 | "version": "1.1.1",
4 | "description": "Image comparison slider for Svelte 3",
5 | "svelte": "src/index.js",
6 | "main": "index.js",
7 | "module": "index.mjs",
8 | "scripts": {
9 | "build": "rollup -c",
10 | "prepublishOnly": "npm run lint & npm run build",
11 | "lint": "eslint src/*.svelte"
12 | },
13 | "files": [
14 | "src",
15 | "index.mjs",
16 | "index.js"
17 | ],
18 | "repository": {
19 | "type": "git",
20 | "url": "git+https://github.com/PaulMaly/svelte-image-compare.git"
21 | },
22 | "keywords": [
23 | "svelte"
24 | ],
25 | "author": "PaulMaly",
26 | "license": "MIT",
27 | "bugs": {
28 | "url": "https://github.com/PaulMaly/svelte-image-compare/issues"
29 | },
30 | "homepage": "https://github.com/PaulMaly/svelte-image-compare#readme",
31 | "devDependencies": {
32 | "eslint": "latest",
33 | "eslint-plugin-svelte3": "latest",
34 | "rollup": "latest",
35 | "rollup-plugin-node-resolve": "latest",
36 | "rollup-plugin-svelte": "latest",
37 | "svelte": "latest"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte';
2 | import resolve from 'rollup-plugin-node-resolve';
3 | import pkg from './package.json';
4 |
5 | const name = pkg.name
6 | .replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3')
7 | .replace(/^\w/, m => m.toUpperCase())
8 | .replace(/-\w/g, m => m[1].toUpperCase());
9 |
10 | export default {
11 | input: 'src/index.js',
12 | output: [
13 | { file: pkg.module, 'format': 'es' },
14 | { file: pkg.main, 'format': 'umd', name }
15 | ],
16 | plugins: [
17 | svelte(),
18 | resolve()
19 | ]
20 | };
--------------------------------------------------------------------------------
/src/ImageCompare.svelte:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |

18 |

24 | {#if overlay}
25 |
26 | {/if}
27 |
28 |
29 |
30 |
31 |
32 |
33 |
37 |
38 |
39 |
79 |
80 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | export { default } from './ImageCompare.svelte';
--------------------------------------------------------------------------------