Skip to content

Commit e811067

Browse files
committed
Initial commit 🚀
0 parents  commit e811067

File tree

17 files changed

+2692
-0
lines changed

17 files changed

+2692
-0
lines changed

‎.eslintrc.cjs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
5+
plugins: ['svelte3', '@typescript-eslint'],
6+
ignorePatterns: ['*.cjs'],
7+
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
8+
settings: {
9+
'svelte3/typescript': () => require('typescript')
10+
},
11+
parserOptions: {
12+
sourceType: 'module',
13+
ecmaVersion: 2019
14+
},
15+
env: {
16+
browser: true,
17+
es2017: true,
18+
node: true
19+
}
20+
};

‎.github/demo.jpg‎

169 KB
Loading

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package

‎.prettierrc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"useTabs": true,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"printWidth": 100
6+
}

‎README.md‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# svelte-magnifier
2+
3+
**Svelte image magnifier component**
4+
5+
- Simple and customizable
6+
- Supports touch screens
7+
- Allows different files for large image and magnifying glass (e.g. thumbnail and high-resolution image)
8+
9+
**[Demo](https://supercoww.github.io/svelte-magnifier)**
10+
11+
<p align="center">
12+
<img src=".github/demo.jpg" width=600 alt="Demo">
13+
</p>
14+
15+
## Usage
16+
17+
Install the package using NPM:
18+
19+
```sh
20+
npm i -D svelte-magnifier
21+
```
22+
23+
Add the component to your Svelte application:
24+
25+
```svelte
26+
<script>
27+
import { Magnifier } from 'svelte-magnifier';
28+
</script>
29+
30+
<Magnifier src="path/to/image.jpg" width="500px" />
31+
```
32+
33+
## Configuration
34+
35+
| Prop | Type | Default | Description |
36+
| ---------------- | ------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37+
| `src` (required) | String | – | URL/path of the large image |
38+
| `alt` (required) | String | – | alt attribute of image |
39+
| `height` | String | `'auto'` | Image height (absolute or relative values possible) |
40+
| `width` | String | `'100%'` | Image width (absolute or relative values possible) |
41+
| `className` | String | `''` | Class which will be applied to the image wrapper |
42+
| `zoomImgSrc` | String | – | URL/path of the image inside the magnifying glass (if not specified, the large image will be used) |
43+
| `zoomFactor` | Number | `1.5` | Factor by which the zoom image will be scaled (based on the size of the large image) |
44+
| `mgWidth` | Number | `150` | Width of the magnifying glass in px |
45+
| `mgHeight` | Number | `150` | Height of the magnifying glass in px |
46+
| `mgBorderWidth` | Number | `2` | Border width of the magnifying glass in px |
47+
| `mgShape` | String | `'circle'` | Shape of the magnifying glass (possible values: `'circle'`, `'square'`) |
48+
| `mgShowOverflow` | Boolean | `true` | Set this to `false` to cut off the magnifying glass at the image borders. When disabling `mgShowOverflow`, it's recommended that you also set all offsets to `0` |
49+
| `mgMouseOffsetX` | Number | `0` | Horizontal offset of the magnifying glass in px when hovering with a mouse |
50+
| `mgMouseOffsetY` | Number | `0` | Vertical offset of the magnifying glass in px when hovering with a mouse |
51+
| `mgTouchOffsetX` | Number | `-50` | Horizontal offset of the magnifying glass in px when dragging on a touch screen |
52+
| `mgTouchOffsetY` | Number | `-50` | Vertical offset of the magnifying glass in px when dragging on a touch screen |
53+
54+
Any other props will be passed down to the `<img>` element.
55+
56+
## Custom styling
57+
58+
```svelte
59+
<style>
60+
:global(.magnifier) {
61+
/* Styles for <div> around image and magnifying glass */
62+
}
63+
:global(.magnifier-image) {
64+
/* Styles for large image */
65+
}
66+
:global(.magnifying-glass) {
67+
/* Styles for magnifying glass */
68+
}
69+
</style>
70+
```
71+
72+
## Developing
73+
74+
Once you've created a project and installed dependencies with `pnpm install`, start a development server:
75+
76+
```bash
77+
npm run dev
78+
79+
# or start the server and open the app in a new browser tab
80+
npm run dev -- --open
81+
```

‎package.json‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "svelte-magnifier",
3+
"version": "0.0.1",
4+
"description": "Svelte image magnifier component",
5+
"keywords": [
6+
"svelte",
7+
"component",
8+
"image",
9+
"zoom",
10+
"magnify",
11+
"magnifier",
12+
"magnifying glass"
13+
],
14+
"author": "Ambar Mutha",
15+
"license": "MIT",
16+
"homepage": "https://github.com/supercoww/svelte-magnifier#readme",
17+
"bugs": "https://github.com/supercoww/svelte-magnifier/issues",
18+
"repository": {
19+
"type": "git",
20+
"url": "git+https://github.com/supercoww/svelte-magnifier.git"
21+
},
22+
"scripts": {
23+
"dev": "svelte-kit dev",
24+
"build": "svelte-kit build",
25+
"preview": "svelte-kit preview",
26+
"package": "svelte-kit package",
27+
"check": "svelte-check --tsconfig ./tsconfig.json",
28+
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
29+
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
30+
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
31+
},
32+
"devDependencies": {
33+
"@sveltejs/kit": "next",
34+
"@typescript-eslint/eslint-plugin": "^4.31.1",
35+
"@typescript-eslint/parser": "^4.31.1",
36+
"eslint": "^7.32.0",
37+
"eslint-config-prettier": "^8.3.0",
38+
"eslint-plugin-svelte3": "^3.2.1",
39+
"postcss-nesting": "^8.0.1",
40+
"prettier": "^2.4.1",
41+
"prettier-plugin-svelte": "^2.4.0",
42+
"svelte": "^3.42.6",
43+
"svelte-check": "^2.2.6",
44+
"svelte-preprocess": "^4.9.4",
45+
"svelte2tsx": "^0.4.7",
46+
"tslib": "^2.3.1",
47+
"typescript": "^4.4.3"
48+
},
49+
"type": "module"
50+
}

0 commit comments

Comments
 (0)