@duckafire/lazy-loading-js 2.0.2-1 → 2.0.2-2

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.
@@ -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-1",
4
+ "version": "2.0.2-2",
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,6 +18,7 @@
18
18
  "files": [
19
19
  "LICENSE",
20
20
  "README.md",
21
+ "lib",
21
22
  "src"
22
23
  ],
23
24
  "custom-fields": {