smooth-loader 1.0.0 → 1.0.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Serhii Cho
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.
package/README.md CHANGED
@@ -1,13 +1,69 @@
1
- # Installation
1
+ # Description
2
2
 
3
- > IN DEVELOPMENT !!!
3
+ Smooth loader allows you smoothly lazy load images and background images. Lazy Loading defers the loading of an image that is not needed on the page immediately. An image, not visible to the user when the page loads, is loaded later when the user scrolls and the image actually becomes visible. If the user never scrolls, an image that is not visible to the user never gets loaded.
4
4
 
5
- Npm:
6
- ```bash
7
- npm i smooth-loader --save
8
- ```
5
+ - [NPM](https://www.npmjs.com/package/smooth-loader)
6
+ - [Usage on codesandbox](https://codesandbox.io/s/smooth-loader-example-usage-5xr6h)
7
+ - [Example usage in production](https://shobar.com.ua/category/photo-reports)
8
+
9
+ # Features
10
+
11
+ - Written in TypeScript
12
+ - Very small package
13
+ - Loads images with IMG tag and backgrounds
14
+ - Loads images with a smooth fade in animation
15
+
16
+ # Installation
9
17
 
10
- Yarn:
11
18
  ```bash
19
+ # npm
20
+ npm i smooth-loader
21
+
22
+ # yarn
12
23
  yarn add smooth-loader
24
+ ```
25
+
26
+ Import `smooth-loader` and the core CSS. This assumes you're using a module bundler like webpack.
27
+
28
+ ```js
29
+ import smoothLoader from 'smooth-loader'
30
+ import 'smooth-loader/lib/css/index.css'
31
+ ```
32
+
33
+ # Usage
34
+
35
+ To make image or element Lazy loaded, replace `src` attribute with `data-src`
36
+ on image element, and add `data-src` attribute to elements that have background
37
+ image that you want to lazy load.
38
+
39
+ - Add **smooth-loader** css class to each image or element that you want to lazy load.
40
+ Unless you want to specify your own selector for images instead of **smooth-loader**.
41
+ - Call `smoothLoader()` function when you want to lazy load images.
42
+
43
+ ```js
44
+ // with .smooth-loader selector
45
+ smoothLoader()
46
+
47
+ // with custom string selector
48
+ smoothLoader('.lazy-image')
49
+
50
+ // with custom elements
51
+ const myImages = document.querySelectorAll<HTMLImageElement>('img')
52
+ smoothLoader(myImages)
53
+ ```
54
+
55
+ > Note, that lazy loading works only when your elements are already in the DOM. Meaning, if images are loaded after the `smoothLoader` was executed, lazy loading will not work.
56
+
57
+ ```html
58
+ <!-- Regular image -->
59
+ <img data-src="./images/me.png" class="smooth-loader">
60
+
61
+ <!-- Background image -->
62
+ <div data-src="./images/we.png" class="smooth-loader my-bg-image"></div>
63
+ ```
64
+
65
+ # Function types
66
+
67
+ ```js
68
+ function smoothLoader(selector?: NodeListOf<HTMLDivElement | HTMLImageElement> | string) => void
13
69
  ```
@@ -0,0 +1,8 @@
1
+ .smooth-loader {
2
+ opacity: 0;
3
+ transition: opacity 777ms;
4
+ }
5
+
6
+ .smooth-loaded {
7
+ opacity: 1 !important;
8
+ }
@@ -1,3 +1,4 @@
1
+ import { LazyImage } from './types';
1
2
  /**
2
3
  * Class that handles lazy loading images with
3
4
  * Intersection Observer
@@ -5,7 +6,7 @@
5
6
  export default class {
6
7
  private readonly images;
7
8
  private observerOptions;
8
- constructor(images: NodeListOf<HTMLDivElement | HTMLImageElement>);
9
+ constructor(images: NodeListOf<LazyImage>);
9
10
  /**
10
11
  * If image has tag IMG then set the src attribute to img url,
11
12
  * otherwise set the background of the element to given image url
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LazyLoader.d.ts","sourceRoot":"","sources":["../../src/LazyLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC;;;GAGG;AACH,MAAM,CAAC,OAAO;IACV,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,eAAe,CAGtB;gBAEkB,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC;IAIhD;;;OAGG;IACH,OAAO,CAAC,SAAS;IAcjB;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;;;OAIG;IACI,OAAO,IAAI,IAAI;CAKzB"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Class that handles lazy loading images with
5
+ * Intersection Observer
6
+ */
7
+ class default_1 {
8
+ constructor(images) {
9
+ this.observerOptions = {
10
+ root: null,
11
+ threshold: 0,
12
+ };
13
+ this.images = images;
14
+ }
15
+ /**
16
+ * If image has tag IMG then set the src attribute to img url,
17
+ * otherwise set the background of the element to given image url
18
+ */
19
+ loadImage(img) {
20
+ const imageUrl = img.getAttribute('data-src');
21
+ if (!imageUrl)
22
+ return;
23
+ if (img.tagName === 'IMG') {
24
+ img.setAttribute('src', imageUrl);
25
+ img.addEventListener('load', () => img.classList.add('smooth-loaded'));
26
+ }
27
+ else {
28
+ img.style.backgroundImage = `url(${img.getAttribute('data-src')})`;
29
+ setTimeout(() => img.classList.add('smooth-loaded'), 0);
30
+ }
31
+ }
32
+ /**
33
+ * Create observer object
34
+ */
35
+ createObserver(img) {
36
+ const observer = new IntersectionObserver((entries, observer) => {
37
+ entries.forEach(entry => {
38
+ if (entry.isIntersecting) {
39
+ this.loadImage(img);
40
+ observer.unobserve(img);
41
+ }
42
+ });
43
+ }, this.observerOptions);
44
+ observer.observe(img);
45
+ }
46
+ /**
47
+ * Creates image object, gets attributes from placeholder,
48
+ * sets them on image object, adds classes to image and
49
+ * when image is loaded, appends it to a placeholder
50
+ */
51
+ execute() {
52
+ this.images.forEach(img => {
53
+ !window['IntersectionObserver'] ? this.loadImage(img) : this.createObserver(img);
54
+ });
55
+ }
56
+ }
57
+ exports.default = default_1;
58
+ //# sourceMappingURL=LazyLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LazyLoader.js","sourceRoot":"","sources":["../../src/LazyLoader.ts"],"names":[],"mappings":";;AAEA;;;GAGG;AACH;IAOI,YAAmB,MAA6B;QALxC,oBAAe,GAAG;YACtB,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,CAAC;SACf,CAAA;QAGG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED;;;OAGG;IACK,SAAS,CAAC,GAAc;QAC5B,MAAM,QAAQ,GAAG,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;QAE7C,IAAI,CAAC,QAAQ;YAAE,OAAM;QAErB,IAAI,GAAG,CAAC,OAAO,KAAK,KAAK,EAAE;YACvB,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;YACjC,GAAG,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAA;SACzE;aAAM;YACH,GAAG,CAAC,KAAK,CAAC,eAAe,GAAG,OAAO,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAA;YAClE,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAA;SAC1D;IACL,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,GAAc;QACjC,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YAC5D,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACpB,IAAI,KAAK,CAAC,cAAc,EAAE;oBACtB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;oBACnB,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;iBAC1B;YACL,CAAC,CAAC,CAAA;QACN,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,CAAA;QAExB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;QACpF,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AAvDD,4BAuDC"}
@@ -0,0 +1,4 @@
1
+ import { LazyImage } from './types';
2
+ declare const _default: (selector?: string | NodeListOf<LazyImage> | undefined) => void;
3
+ export default _default;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;mFAEyB,IAAI;AAAhE,wBAOC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const LazyLoader_1 = __importDefault(require("./LazyLoader"));
7
+ exports.default = (selector) => {
8
+ const images = getImagesElements(selector);
9
+ if (!images)
10
+ return;
11
+ return new LazyLoader_1.default(images).execute();
12
+ };
13
+ function getImagesElements(selector) {
14
+ if (typeof selector === 'string' && selector !== '')
15
+ return document.querySelectorAll(selector);
16
+ if (selector instanceof NodeList)
17
+ return selector;
18
+ return document.querySelectorAll('.smooth-loader');
19
+ }
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AAGrC,kBAAe,CAAC,QAAyC,EAAQ,EAAE;IAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAE1C,IAAI,CAAC,MAAM;QACP,OAAM;IAEV,OAAO,IAAI,oBAAU,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAA;AAC3C,CAAC,CAAA;AAED,SAAS,iBAAiB,CAAC,QAAyC;IAChE,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,EAAE;QAC/C,OAAO,QAAQ,CAAC,gBAAgB,CAAY,QAAQ,CAAC,CAAA;IAEzD,IAAI,QAAQ,YAAY,QAAQ;QAC5B,OAAO,QAAQ,CAAA;IAEnB,OAAO,QAAQ,CAAC,gBAAgB,CAAY,gBAAgB,CAAC,CAAA;AACjE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare type LazyImage = HTMLDivElement | HTMLImageElement;
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS,GAAG,cAAc,GAAG,gBAAgB,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "smooth-loader",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
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/index.js",
6
- "types": "lib",
5
+ "main": "lib/js/index.js",
6
+ "types": "lib/js",
7
7
  "directories": {
8
8
  "lib": "lib"
9
9
  },
package/src/LazyLoader.ts CHANGED
@@ -1,15 +1,17 @@
1
+ import { LazyImage } from './types'
2
+
1
3
  /**
2
4
  * Class that handles lazy loading images with
3
5
  * Intersection Observer
4
6
  */
5
- export default class {
6
- private readonly images: NodeListOf<HTMLDivElement | HTMLImageElement>
7
+ export default class {
8
+ private readonly images: NodeListOf<LazyImage>
7
9
  private observerOptions = {
8
10
  root: null,
9
11
  threshold: 0,
10
12
  }
11
13
 
12
- public constructor(images: NodeListOf<HTMLDivElement | HTMLImageElement>) {
14
+ public constructor(images: NodeListOf<LazyImage>) {
13
15
  this.images = images
14
16
  }
15
17
 
@@ -17,22 +19,24 @@
17
19
  * If image has tag IMG then set the src attribute to img url,
18
20
  * otherwise set the background of the element to given image url
19
21
  */
20
- private loadImage(img: HTMLDivElement | HTMLImageElement): void {
21
- const dataAttr = img.getAttribute('data-src')
22
-
23
- if (!dataAttr) return
24
-
25
- img.tagName === 'IMG'
26
- ? img.setAttribute('src', dataAttr)
27
- : img.style.background = `url(${img.getAttribute('data-src')})`
28
-
29
- img.classList.add('sho-lazy-loaded')
22
+ private loadImage(img: LazyImage): void {
23
+ const imageUrl = img.getAttribute('data-src')
24
+
25
+ if (!imageUrl) return
26
+
27
+ if (img.tagName === 'IMG') {
28
+ img.setAttribute('src', imageUrl)
29
+ img.addEventListener('load', () => img.classList.add('smooth-loaded'))
30
+ } else {
31
+ img.style.backgroundImage = `url(${img.getAttribute('data-src')})`
32
+ setTimeout(() => img.classList.add('smooth-loaded'), 0)
33
+ }
30
34
  }
31
35
 
32
36
  /**
33
37
  * Create observer object
34
38
  */
35
- private createObserver(img: HTMLDivElement | HTMLImageElement): void {
39
+ private createObserver(img: LazyImage): void {
36
40
  const observer = new IntersectionObserver((entries, observer) => {
37
41
  entries.forEach(entry => {
38
42
  if (entry.isIntersecting) {
package/src/index.ts CHANGED
@@ -1,11 +1,21 @@
1
1
  import LazyLoader from "./LazyLoader"
2
+ import { LazyImage } from './types'
2
3
 
3
- export default () => {
4
- const images = document.querySelectorAll<HTMLImageElement|HTMLDivElement>('smooth-loader')
4
+ export default (selector?: NodeListOf<LazyImage> | string): void => {
5
+ const images = getImagesElements(selector)
5
6
 
6
- if (!images) {
7
+ if (!images)
7
8
  return
8
- }
9
9
 
10
10
  return new LazyLoader(images).execute()
11
11
  }
12
+
13
+ function getImagesElements(selector?: NodeListOf<LazyImage> | string): NodeListOf<LazyImage> {
14
+ if (typeof selector === 'string' && selector !== '')
15
+ return document.querySelectorAll<LazyImage>(selector)
16
+
17
+ if (selector instanceof NodeList)
18
+ return selector
19
+
20
+ return document.querySelectorAll<LazyImage>('.smooth-loader')
21
+ }
package/src/types.ts ADDED
@@ -0,0 +1 @@
1
+ export type LazyImage = HTMLDivElement | HTMLImageElement
package/tsconfig.json CHANGED
@@ -1,70 +1,16 @@
1
1
  {
2
2
  "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Basic Options */
6
- // "incremental": true, /* Enable incremental compilation */
7
- "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
- "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
- // "lib": [], /* Specify library files to be included in the compilation. */
10
- // "allowJs": true, /* Allow javascript files to be compiled. */
11
- // "checkJs": true, /* Report errors in .js files. */
12
- // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
- "declaration": true, /* Generates corresponding '.d.ts' file. */
14
- "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
- "sourceMap": true, /* Generates corresponding '.map' file. */
16
- // "outFile": "./", /* Concatenate and emit output to single file. */
17
- "outDir": "./lib", /* Redirect output structure to the directory. */
18
- // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19
- // "composite": true, /* Enable project compilation */
20
- // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21
- // "removeComments": true, /* Do not emit comments to output. */
22
- // "noEmit": true, /* Do not emit outputs. */
23
- // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24
- // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25
- // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26
-
27
- /* Strict Type-Checking Options */
28
- "strict": true, /* Enable all strict type-checking options. */
29
- // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30
- // "strictNullChecks": true, /* Enable strict null checks. */
31
- // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32
- // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33
- // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34
- // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35
- // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36
-
37
- /* Additional Checks */
38
- // "noUnusedLocals": true, /* Report errors on unused locals. */
39
- // "noUnusedParameters": true, /* Report errors on unused parameters. */
40
- // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41
- // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42
-
43
- /* Module Resolution Options */
44
- // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46
- // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48
- // "typeRoots": [], /* List of folders to include type definitions from. */
49
- // "types": [], /* Type declaration files to be included in compilation. */
50
- // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51
- "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54
-
55
- /* Source Map Options */
56
- // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
- // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59
- // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60
-
61
- /* Experimental Options */
62
- // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
63
- // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64
-
65
- /* Advanced Options */
66
- "skipLibCheck": true, /* Skip type checking of declaration files. */
67
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
3
+ "target": "es2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
4
+ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
5
+ "declaration": true, /* Generates corresponding '.d.ts' file. */
6
+ "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
7
+ "sourceMap": true, /* Generates corresponding '.map' file. */
8
+ "outDir": "./lib/js", /* Redirect output structure to the directory. */
9
+ "strict": true, /* Enable all strict type-checking options. */
10
+ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
11
+ "skipLibCheck": true, /* Skip type checking of declaration files. */
12
+ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68
13
  },
14
+ "exclude": ["node_modules"],
69
15
  "include": ["src"]
70
16
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"LazyLoader.d.ts","sourceRoot":"","sources":["../src/LazyLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACF,MAAM,CAAC,OAAO;IACX,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+C;IACtE,OAAO,CAAC,eAAe,CAGtB;gBAEkB,MAAM,EAAE,UAAU,CAAC,cAAc,GAAG,gBAAgB,CAAC;IAIxE;;;OAGG;IACH,OAAO,CAAC,SAAS;IAYjB;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;;;OAIG;IACI,OAAO,IAAI,IAAI;CAKzB"}
package/lib/LazyLoader.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Class that handles lazy loading images with
5
- * Intersection Observer
6
- */
7
- var default_1 = /** @class */ (function () {
8
- function default_1(images) {
9
- this.observerOptions = {
10
- root: null,
11
- threshold: 0,
12
- };
13
- this.images = images;
14
- }
15
- /**
16
- * If image has tag IMG then set the src attribute to img url,
17
- * otherwise set the background of the element to given image url
18
- */
19
- default_1.prototype.loadImage = function (img) {
20
- var dataAttr = img.getAttribute('data-src');
21
- if (!dataAttr)
22
- return;
23
- img.tagName === 'IMG'
24
- ? img.setAttribute('src', dataAttr)
25
- : img.style.background = "url(" + img.getAttribute('data-src') + ")";
26
- img.classList.add('sho-lazy-loaded');
27
- };
28
- /**
29
- * Create observer object
30
- */
31
- default_1.prototype.createObserver = function (img) {
32
- var _this = this;
33
- var observer = new IntersectionObserver(function (entries, observer) {
34
- entries.forEach(function (entry) {
35
- if (entry.isIntersecting) {
36
- _this.loadImage(img);
37
- observer.unobserve(img);
38
- }
39
- });
40
- }, this.observerOptions);
41
- observer.observe(img);
42
- };
43
- /**
44
- * Creates image object, gets attributes from placeholder,
45
- * sets them on image object, adds classes to image and
46
- * when image is loaded, appends it to a placeholder
47
- */
48
- default_1.prototype.execute = function () {
49
- var _this = this;
50
- this.images.forEach(function (img) {
51
- !window['IntersectionObserver'] ? _this.loadImage(img) : _this.createObserver(img);
52
- });
53
- };
54
- return default_1;
55
- }());
56
- exports.default = default_1;
57
- //# sourceMappingURL=LazyLoader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LazyLoader.js","sourceRoot":"","sources":["../src/LazyLoader.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACF;IAOG,mBAAmB,MAAqD;QALhE,oBAAe,GAAG;YACtB,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,CAAC;SACf,CAAA;QAGG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED;;;OAGG;IACK,6BAAS,GAAjB,UAAkB,GAAsC;QACpD,IAAM,QAAQ,GAAG,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;QAE7C,IAAI,CAAC,QAAQ;YAAE,OAAM;QAErB,GAAG,CAAC,OAAO,KAAK,KAAK;YACjB,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC;YACnC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,GAAG,SAAO,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,MAAG,CAAA;QAEnE,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IACxC,CAAC;IAED;;OAEG;IACK,kCAAc,GAAtB,UAAuB,GAAsC;QAA7D,iBAWC;QAVG,IAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,UAAC,OAAO,EAAE,QAAQ;YACxD,OAAO,CAAC,OAAO,CAAC,UAAA,KAAK;gBACjB,IAAI,KAAK,CAAC,cAAc,EAAE;oBACtB,KAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;oBACnB,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;iBAC1B;YACL,CAAC,CAAC,CAAA;QACN,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,CAAA;QAExB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACI,2BAAO,GAAd;QAAA,iBAIC;QAHG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,GAAG;YACnB,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,KAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;QACpF,CAAC,CAAC,CAAA;IACN,CAAC;IACL,gBAAC;AAAD,CAAC,AArDA,IAqDA"}
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,wBAQC"}
package/lib/index.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var LazyLoader_1 = __importDefault(require("./LazyLoader"));
7
- exports.default = (function () {
8
- var images = document.querySelectorAll('smooth-loader');
9
- if (!images) {
10
- return;
11
- }
12
- return new LazyLoader_1.default(images).execute();
13
- });
14
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,4DAAqC;AAErC,mBAAe;IACX,IAAM,MAAM,GAAG,QAAQ,CAAC,gBAAgB,CAAkC,eAAe,CAAC,CAAA;IAE1F,IAAI,CAAC,MAAM,EAAE;QACT,OAAM;KACT;IAED,OAAO,IAAI,oBAAU,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAA;AAC3C,CAAC,EAAA"}