smooth-loader 1.1.4 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +3 -0
- package/.github/workflows/npm-publish.yml +23 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +8 -12
- package/Dockerfile +11 -0
- package/LICENSE +1 -1
- package/README.md +35 -1
- package/docker-compose.yml +11 -0
- package/lib/js/imageLoader.js +1 -2
- package/lib/js/imageLoader.js.map +1 -1
- package/lib/js/index.d.ts.map +1 -1
- package/lib/js/index.js.map +1 -1
- package/lib/js/observerCreator.js +1 -1
- package/lib/js/observerCreator.js.map +1 -1
- package/package.json +23 -24
- package/src/index.ts +26 -24
package/.dockerignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Publish package to NPM
|
|
2
|
+
|
|
3
|
+
# Good article: https://medium.com/@codewithwaheed/publish-your-first-package-using-npm-and-github-actions-e453ca9f9fd2
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
branches: master
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v2
|
|
14
|
+
|
|
15
|
+
- name: Setup Node.js
|
|
16
|
+
uses: actions/setup-node@v2
|
|
17
|
+
with:
|
|
18
|
+
node-version: '20'
|
|
19
|
+
registry-url: 'https://registry.npmjs.org/'
|
|
20
|
+
- run: npm install
|
|
21
|
+
- run: npm publish
|
|
22
|
+
env:
|
|
23
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.prettierrc
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,51 +1,47 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
-
## v1.1
|
|
3
|
+
## v1.2.1 (2025-06-29)
|
|
4
|
+
- Removed not needed lines from Dockerfile and docker-compose.yml
|
|
5
|
+
|
|
6
|
+
## v1.2.0 (2025-06-29)
|
|
7
|
+
- Added Docker support to the project
|
|
4
8
|
|
|
9
|
+
## v1.1.4 (2024-04-08)
|
|
5
10
|
- Formatted the `CHANGELOG.md` file
|
|
6
|
-
-
|
|
7
|
-
-
|
|
11
|
+
- Refactored the code to make it more readable
|
|
12
|
+
- Improved error handling
|
|
8
13
|
|
|
9
14
|
## v1.1.3 (2023-11-19)
|
|
10
|
-
|
|
11
15
|
- Changed the `README.MD` file
|
|
12
16
|
|
|
13
17
|
## v1.1.2 (2022-12-04)
|
|
14
|
-
|
|
15
18
|
- Removed line from docs
|
|
16
19
|
|
|
17
20
|
## v1.1.1 (2022-12-04)
|
|
18
|
-
|
|
19
21
|
- Code refactoring
|
|
20
22
|
- Added ability to provide array of images instead of only NodeListOf
|
|
21
23
|
- Improved documentation in `README.md`
|
|
22
24
|
|
|
23
25
|
## v1.1.0 (2022-12-01)
|
|
24
|
-
|
|
25
26
|
- Moved from beta version
|
|
26
27
|
|
|
27
28
|
## v1.1.0-beta.2 (2022-11-30)
|
|
28
|
-
|
|
29
29
|
- Code refactoring
|
|
30
30
|
- Manual testing
|
|
31
31
|
|
|
32
32
|
## v1.1.0-beta.1 (2022-11-29)
|
|
33
|
-
|
|
34
33
|
- Removed blur from small placeholder images if they are set with `src` attribute
|
|
35
34
|
- Added more info to docs
|
|
36
35
|
|
|
37
36
|
## v1.1.0-beta.0 (2022-11-29)
|
|
38
|
-
|
|
39
37
|
- Added missing information to the README.md file
|
|
40
38
|
- Added ability to show small images as placeholder, so you don't look at empty screen but blurred mini version of the image
|
|
41
39
|
|
|
42
40
|
## v1.0.7 (2022-06-22)
|
|
43
|
-
|
|
44
41
|
- Fixed appearing transition with background images. Now it works
|
|
45
42
|
- Improved documentation `README.md` file
|
|
46
43
|
- Added **configurations** for smooth loading images
|
|
47
44
|
|
|
48
45
|
## v1.0.6 (2022-01-02)
|
|
49
|
-
|
|
50
46
|
- Changed default images selector to be more specific
|
|
51
47
|
- Added `CHANGELOG.md` file
|
package/Dockerfile
ADDED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -4,4 +4,38 @@ Smooth loader allows you smoothly lazy load images and background images. Lazy L
|
|
|
4
4
|
|
|
5
5
|
This package is a MUST-HAVE for every website containing multiple images on the page. It's surely the best lazy loading package on NPM that you can configure to your own needs.
|
|
6
6
|
|
|
7
|
-
## Follow the [official documentation](https://smooth-loader.github.io) for all the details
|
|
7
|
+
## Follow the [official documentation](https://smooth-loader.github.io) for all the details
|
|
8
|
+
|
|
9
|
+
## Development
|
|
10
|
+
### Without Docker
|
|
11
|
+
You'll need to have [Node JS and NPM](https://nodejs.org/en/download) installed on your machine to run it locally.
|
|
12
|
+
|
|
13
|
+
#### Install Dependencies
|
|
14
|
+
```bash
|
|
15
|
+
npm i
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
#### Watch File Changes
|
|
19
|
+
This command will watch for your changes and compile TypeScript to JavaScript files into `lib/js`
|
|
20
|
+
```bash
|
|
21
|
+
npm run watch
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### With [Docker](https://www.docker.com/)
|
|
25
|
+
#### Build the Image
|
|
26
|
+
To build an image, navigate to the root of the project that contains `Dockerfile` and run this command:
|
|
27
|
+
```bash
|
|
28
|
+
docker compose build
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Now, you'll have an image `smooth-loader` that you can use to create a container.
|
|
32
|
+
|
|
33
|
+
#### Create and Enter the Container
|
|
34
|
+
To create and enter inside the container, run this command:
|
|
35
|
+
```bash
|
|
36
|
+
docker compose run --rm app
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
You'll be able to run NPM commands inside of the container and commands:
|
|
40
|
+
- `npm run watch` to make TypeScript watch for your changes and auto-compile everything to plain JavaScript
|
|
41
|
+
- `npm run build` compile all of your TypeScript files to JavaScript
|
package/lib/js/imageLoader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadImage =
|
|
3
|
+
exports.loadImage = loadImage;
|
|
4
4
|
/**
|
|
5
5
|
* If image has tag IMG then set the src attribute to img url,
|
|
6
6
|
* otherwise set the background of the element to given image url
|
|
@@ -21,7 +21,6 @@ function loadImage(img) {
|
|
|
21
21
|
}
|
|
22
22
|
img.style.backgroundImage = `url(${imageUrl})`;
|
|
23
23
|
}
|
|
24
|
-
exports.loadImage = loadImage;
|
|
25
24
|
function preloadAndFadeInImage(img, imageUrl) {
|
|
26
25
|
const preloadedImage = new Image();
|
|
27
26
|
preloadedImage.addEventListener('load', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageLoader.js","sourceRoot":"","sources":["../../src/imageLoader.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"imageLoader.js","sourceRoot":"","sources":["../../src/imageLoader.ts"],"names":[],"mappings":";;AAMA,8BAoBC;AAxBD;;;GAGG;AACH,SAAgB,SAAS,CAAC,GAAiB;IACvC,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;IAEjC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAA;QACtE,OAAM;IACV,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAA;IAC3B,CAAC;IAED,qBAAqB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IAEpC,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QACjC,OAAM;IACV,CAAC;IAED,GAAG,CAAC,KAAK,CAAC,eAAe,GAAG,OAAO,QAAQ,GAAG,CAAA;AAClD,CAAC;AAED,SAAS,qBAAqB,CAAC,GAAiB,EAAE,QAAgB;IAC9D,MAAM,cAAc,GAAG,IAAI,KAAK,EAAE,CAAA;IAElC,cAAc,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;QACzC,GAAG,CAAC,KAAK,CAAC,UAAU,GAAG,eAAe,CAAA;QACtC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAA;IAC3B,CAAC,CAAC,CAAA;IAEF,cAAc,CAAC,GAAG,GAAG,QAAQ,CAAA;AACjC,CAAC;AAED,MAAM,cAAc,GAAG,CAAC,GAAiB,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,KAAK,KAAK,CAAA;AACnE,MAAM,WAAW,GAAG,CAAC,GAAiB,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA"}
|
package/lib/js/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAgB,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAgB,UAAU,EAAE,MAAM,SAAS,CAAA;yBAE1C,WAAW,UAAU,EAAE,SAAS,MAAM,KAAG,IAAI;AAA7D,wBAaC"}
|
package/lib/js/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,wEAA+C;AAG/C,kBAAe,CAAC,QAAqB,EAAE,MAAe,EAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,wEAA+C;AAG/C,kBAAe,CAAC,QAAqB,EAAE,MAAe,EAAQ,EAAE;IAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAE1C,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAM;IACP,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,IAAI;QAChC,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,CAAC;KACZ,CAAA;IAED,OAAO,IAAA,yBAAe,EAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAC/C,CAAC,CAAA;AAED,SAAS,iBAAiB,CAAC,QAAqB;IAC/C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CACzC,0BAA0B,CAC1B,CAAA;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5B,CAAC;IAED,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAe,QAAQ,CAAC,CAAA;QAClE,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5B,CAAC;IAED,IAAI,QAAQ,YAAY,QAAQ,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5B,CAAC;IAED,OAAO,QAAQ,CAAA;AAChB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
3
4
|
const imageLoader_1 = require("./imageLoader");
|
|
4
5
|
/**
|
|
5
6
|
* Creates image object, gets attributes from placeholder,
|
|
@@ -15,7 +16,6 @@ function default_1(images, config) {
|
|
|
15
16
|
(0, imageLoader_1.loadImage)(img);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
|
-
exports.default = default_1;
|
|
19
19
|
function browserSupportsIntersectionObserver() {
|
|
20
20
|
return 'IntersectionObserver' in window;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observerCreator.js","sourceRoot":"","sources":["../../src/observerCreator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"observerCreator.js","sourceRoot":"","sources":["../../src/observerCreator.ts"],"names":[],"mappings":";;AAQA,4BASC;AAhBD,+CAAyC;AAEzC;;;;GAIG;AACH,mBAAyB,MAAsB,EAAE,MAAc;IAC3D,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,mCAAmC,EAAE,EAAE,CAAC;YACxC,2BAA2B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;YACxC,SAAQ;QACZ,CAAC;QAED,IAAA,uBAAS,EAAC,GAAG,CAAC,CAAA;IAClB,CAAC;AACL,CAAC;AAED,SAAS,mCAAmC;IACxC,OAAO,sBAAsB,IAAI,MAAM,CAAA;AAC3C,CAAC;AAED;;;GAGG;AACH,SAAS,2BAA2B,CAAC,GAAiB,EAAE,MAAc;IAClE,6EAA6E;IAC7E,MAAM,cAAc,GAAG,CAAC,OAAoC,EAAE,QAA8B,EAAE,EAAE;QAC5F,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC1B,oDAAoD;YACpD,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;gBACxB,SAAQ;YACZ,CAAC;YAED,IAAA,uBAAS,EAAC,GAAG,CAAC,CAAA;YAEd,yCAAyC;YACzC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC;IACL,CAAC,CAAA;IAED,IAAI,oBAAoB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
2
|
+
"name": "smooth-loader",
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "This package allows you to lazy load your images using IntersectionObserver technology. It supports loading background images as well as the regular images with img tag.",
|
|
5
|
+
"main": "lib/js/index.js",
|
|
6
|
+
"types": "lib/js",
|
|
7
|
+
"author": "Serhii Cho",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"homepage": "https://smooth-loader.github.io",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"typescript": "^5.8.3"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -p .",
|
|
15
|
+
"watch": "tsc --watch"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"lazy loader",
|
|
19
|
+
"lazy",
|
|
20
|
+
"image loader",
|
|
21
|
+
"lazy loading",
|
|
22
|
+
"background image"
|
|
23
|
+
]
|
|
24
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,34 +2,36 @@ import observerCreator from './observerCreator'
|
|
|
2
2
|
import { Config, ImageElement, InputTypes } from './types'
|
|
3
3
|
|
|
4
4
|
export default (selector?: InputTypes, config?: Config): void => {
|
|
5
|
-
|
|
5
|
+
const images = getImagesElements(selector)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
if (!images) {
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const configurations = config || {
|
|
12
|
+
root: null,
|
|
13
|
+
threshold: 0,
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
return observerCreator(images, configurations)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function getImagesElements(selector?: InputTypes): ImageElement[] {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
if (!selector) {
|
|
21
|
+
const elements = document.querySelectorAll<ImageElement>(
|
|
22
|
+
'.smooth-loader[data-src]',
|
|
23
|
+
)
|
|
24
|
+
return Array.from(elements)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof selector === 'string') {
|
|
28
|
+
const elements = document.querySelectorAll<ImageElement>(selector)
|
|
29
|
+
return Array.from(elements)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (selector instanceof NodeList) {
|
|
33
|
+
return Array.from(selector)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return selector
|
|
35
37
|
}
|