@duckafire/lazy-loading-js 2.0.2-3 → 2.0.2-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/README.md +1 -1
- package/dist/LazyLoadingImage.min.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ tecnique to images, in order to optimize website pages.
|
|
|
25
25
|
Import the API in your HTML code:
|
|
26
26
|
|
|
27
27
|
``` html
|
|
28
|
-
<script src="https://cdn.jsdelivr.net/npm/@duckafire/lazy-loading-js@2.0.2-
|
|
28
|
+
<script src="https://cdn.jsdelivr.net/npm/@duckafire/lazy-loading-js@2.0.2-4/dist/LazyLoadingImage.min.js"></script>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
[source]: https://github.com/duckafire/lazy-loading-js/tree/main/src/ "Lazy loading API source code"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class LazyLoadingImage{#t;#e;#s=!1;#r=HTMLImageElement;#o="-1";#a="0";#i="1";constructor(t,e,s){if(this.#t=document.querySelectorAll(t),0==this.#t.length)throw new Error(`None was found. Query: "${t}"`);this.#t.forEach(t=>{if(!(t instanceof this.#r))throw new Error(`Invalid instance. Expected "${this.constructor.name}" instead "${t.constructor.name}".`);t instanceof HTMLImageElement&&(t.loading="lazy")}),s||this.start(e)}start(t){this.#s?t&&console.warn(this.hasSupport?"This instance already was started.":"This browser do not support the Intersection Observer API."):(this.#s=!0,this.#e="IntersectionObserver"in window,this.#e?this.#t.forEach(t=>{this.#n(t),this.#h(t)}):(this.#c(),t&&console.error("This browser do not suppor the Intersection Observer API - from JavaScript. So the resources that depend of it it will be loaded without optimizations of loading.")))}#c(){this.#t.forEach(t=>{this.#d(t)})}#u(t,e,s){const r=window["inner"+(s?"Width":"Height")];return t>=0&&t<=r||e>=0&&e<=r}#n(t){this.#l(t),t.onload=()=>{let e=new Image;e.src=t.dataset.src,e.onload=()=>{e=null,t.dataset.awaiting="no";const s=t.getBoundingClientRect();(this.#u(s.top,s.bottom)||this.#u(s.left,s.right,!0))&&this.#d(t,this.#i)}}}#l(t){t.src=t.dataset.placeholder,t.dataset.currentSrc=t.dataset.placeholder,t.dataset.state=this.#a,t.dataset.awaiting="yes"}#h(t){const e=new IntersectionObserver(t=>{t.forEach(t=>{"yes"!=t.target.dataset.awaiting&&(t.isIntersecting?this.#d(t.target,this.#i):this.#w(t.target,this.#o))})});e.observe(t),null==this.disconnectFromObserver&&(this.disconnectFromObserver=()=>{this.#s=!1,this.#t.forEach(t=>{e.unobserve(t),entity.target.dataset.state=this.#a})})}#I(t,e,s){if(null==t.dataset[s])throw new Error(`Data property "data-${s}" not found.`);t.dataset.state==e&&t.dataset.state!=this.#a||t.dataset.currentSrc==t.dataset[s]||(t.dataset.state=e,t.src=t.dataset[s],t.dataset.currentSrc=t.dataset[s])}#d(t,e){this.#I(t,e,"src")}#w(t,e){this.#I(t,e,"placeholder")}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duckafire/lazy-loading-js",
|
|
3
3
|
"author": "duckafire",
|
|
4
|
-
"version": "2.0.2-
|
|
4
|
+
"version": "2.0.2-4",
|
|
5
5
|
"license": "Zlib",
|
|
6
6
|
"description": "Simple lazy loading algorithm for websites front-end.",
|
|
7
7
|
"keywords": ["client", "html", "images", "web", "front-end", "optimization", "lazy", "loading", "lazy-loading"],
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"LICENSE",
|
|
20
20
|
"README.md",
|
|
21
|
-
"
|
|
21
|
+
"dist",
|
|
22
22
|
"src"
|
|
23
23
|
],
|
|
24
24
|
"custom-fields": {
|