smooth-loader 1.1.4 → 1.2.0

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 ADDED
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ .vscode
3
+ .git
@@ -0,0 +1,19 @@
1
+ on:
2
+ push:
3
+ branches: master
4
+
5
+ jobs:
6
+ publish:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+
11
+ - name: Setup Node.js
12
+ uses: actions/setup-node@v2
13
+ with:
14
+ node-version: '20'
15
+ registry-url: 'https://registry.npmjs.org/'
16
+ - run: npm install
17
+ - run: npm publish
18
+ env:
19
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "trailingComma": "all",
3
+ "tabWidth": 4,
4
+ "semi": false,
5
+ "singleQuote": true,
6
+ "printWidth": 85,
7
+ "arrowParens": "avoid"
8
+ }
package/CHANGELOG.md CHANGED
@@ -1,51 +1,44 @@
1
1
  # Release Notes
2
2
 
3
- ## v1.1.4 (2024-04-08)
3
+ ## v1.2.0 (2025-06-29)
4
+ - Added Docker support to the project
4
5
 
6
+ ## v1.1.4 (2024-04-08)
5
7
  - Formatted the `CHANGELOG.md` file
6
- - Refactor the code to make it more readable
7
- - Improve error handling
8
+ - Refactored the code to make it more readable
9
+ - Improved error handling
8
10
 
9
11
  ## v1.1.3 (2023-11-19)
10
-
11
12
  - Changed the `README.MD` file
12
13
 
13
14
  ## v1.1.2 (2022-12-04)
14
-
15
15
  - Removed line from docs
16
16
 
17
17
  ## v1.1.1 (2022-12-04)
18
-
19
18
  - Code refactoring
20
19
  - Added ability to provide array of images instead of only NodeListOf
21
20
  - Improved documentation in `README.md`
22
21
 
23
22
  ## v1.1.0 (2022-12-01)
24
-
25
23
  - Moved from beta version
26
24
 
27
25
  ## v1.1.0-beta.2 (2022-11-30)
28
-
29
26
  - Code refactoring
30
27
  - Manual testing
31
28
 
32
29
  ## v1.1.0-beta.1 (2022-11-29)
33
-
34
30
  - Removed blur from small placeholder images if they are set with `src` attribute
35
31
  - Added more info to docs
36
32
 
37
33
  ## v1.1.0-beta.0 (2022-11-29)
38
-
39
34
  - Added missing information to the README.md file
40
35
  - Added ability to show small images as placeholder, so you don't look at empty screen but blurred mini version of the image
41
36
 
42
37
  ## v1.0.7 (2022-06-22)
43
-
44
38
  - Fixed appearing transition with background images. Now it works
45
39
  - Improved documentation `README.md` file
46
40
  - Added **configurations** for smooth loading images
47
41
 
48
42
  ## v1.0.6 (2022-01-02)
49
-
50
43
  - Changed default images selector to be more specific
51
44
  - Added `CHANGELOG.md` file
package/Dockerfile ADDED
@@ -0,0 +1,15 @@
1
+ FROM node:24-alpine
2
+
3
+ RUN apk add --no-cache git
4
+
5
+ WORKDIR /app
6
+
7
+ COPY package.json .
8
+
9
+ RUN npm install
10
+
11
+ COPY . .
12
+
13
+ EXPOSE 5173
14
+
15
+ ENTRYPOINT ["sh"]
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Serhii Cho
3
+ Copyright (c) 2021 Sergey Chornenkyi (Serhii Cho)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
@@ -0,0 +1,13 @@
1
+ name: smooth-loader
2
+
3
+ services:
4
+ app:
5
+ image: smooth-loader
6
+ container_name: smooth-loader
7
+ build:
8
+ context: .
9
+ volumes:
10
+ - .:/app
11
+ - /app/node_modules
12
+ ports:
13
+ - 3000:5173
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadImage = void 0;
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":";;;AAEA;;;GAGG;AACH,SAAgB,SAAS,CAAC,GAAiB;IACvC,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;IAEjC,IAAI,CAAC,QAAQ,EAAE;QACX,OAAO,CAAC,IAAI,CAAC,wDA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tE,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"}
@@ -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;oCAE/B,UAAU,WAAW,MAAM,KAAG,IAAI;AAA7D,wBAaC"}
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"}
@@ -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;IAC5D,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAE1C,IAAI,CAAC,MAAM,EAAE;QACT,OAAM;KACT;IAED,MAAM,cAAc,GAAG,MAAM,IAAI;QAC7B,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,CAAC;KACf,CAAA;IAED,OAAO,IAAA,yBAAe,EAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAClD,CAAC,CAAA;AAED,SAAS,iBAAiB,CAAC,QAAqB;IAC5C,IAAI,CAAC,QAAQ,EAAE;QACX,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAe,0BAA0B,CAAC,CAAA;QACpF,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;KAC9B;IAED,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAC9B,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAe,QAAQ,CAAC,CAAA;QAClE,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;KAC9B;IAED,IAAI,QAAQ,YAAY,QAAQ,EAAE;QAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;KAC9B;IAED,OAAO,QAAQ,CAAA;AACnB,CAAC"}
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":";;AACA,+CAAyC;AAEzC;;;;GAIG;AACH,mBAAyB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C,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
- "name": "smooth-loader",
3
- "version": "1.1.4",
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
- "directories": {
8
- "lib": "lib"
9
- },
10
- "scripts": {
11
- "build": "tsc -p .",
12
- "watch": "tsc --watch",
13
- "publish": "npm login && npm publish"
14
- },
15
- "keywords": [
16
- "lazy loader",
17
- "lazy",
18
- "image loader",
19
- "lazy loading",
20
- "background image"
21
- ],
22
- "author": "Serhii Cho",
23
- "license": "MIT",
24
- "homepage": "https://smooth-loader.github.io"
25
- }
2
+ "name": "smooth-loader",
3
+ "version": "1.2.0",
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
- const images = getImagesElements(selector)
5
+ const images = getImagesElements(selector)
6
6
 
7
- if (!images) {
8
- return
9
- }
7
+ if (!images) {
8
+ return
9
+ }
10
10
 
11
- const configurations = config || {
12
- root: null,
13
- threshold: 0,
14
- }
11
+ const configurations = config || {
12
+ root: null,
13
+ threshold: 0,
14
+ }
15
15
 
16
- return observerCreator(images, configurations)
16
+ return observerCreator(images, configurations)
17
17
  }
18
18
 
19
19
  function getImagesElements(selector?: InputTypes): ImageElement[] {
20
- if (!selector) {
21
- const elements = document.querySelectorAll<ImageElement>('.smooth-loader[data-src]')
22
- return Array.from(elements)
23
- }
24
-
25
- if (typeof selector === 'string') {
26
- const elements = document.querySelectorAll<ImageElement>(selector)
27
- return Array.from(elements)
28
- }
29
-
30
- if (selector instanceof NodeList) {
31
- return Array.from(selector)
32
- }
33
-
34
- return selector
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
  }