vue3-lazyload
Advanced tools
Comparing version 0.2.4-beta to 0.2.5-beta
/*! | ||
* Vue3-Lazyload.js v0.2.4-beta | ||
* Vue3-Lazyload.js v0.2.5-beta | ||
* A Vue3.x image lazyload plugin | ||
@@ -218,2 +218,3 @@ * (c) 2021 MuRong <admin@imuboy.cn> | ||
(_a = this._realObserver(el)) === null || _a === void 0 ? void 0 : _a.unobserve(el); | ||
this._images.delete(el); | ||
}; | ||
@@ -220,0 +221,0 @@ /** |
/*! | ||
* Vue3-Lazyload.js v0.2.4-beta | ||
* Vue3-Lazyload.js v0.2.5-beta | ||
* A Vue3.x image lazyload plugin | ||
@@ -224,2 +224,3 @@ * (c) 2021 MuRong <admin@imuboy.cn> | ||
(_a = this._realObserver(el)) === null || _a === void 0 ? void 0 : _a.unobserve(el); | ||
this._images.delete(el); | ||
}; | ||
@@ -226,0 +227,0 @@ /** |
/*! | ||
* Vue3-Lazyload.js v0.2.4-beta | ||
* Vue3-Lazyload.js v0.2.5-beta | ||
* A Vue3.x image lazyload plugin | ||
@@ -7,2 +7,2 @@ * (c) 2021 MuRong <admin@imuboy.cn> | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueLazyload=t()}(this,function(){"use strict";var i,e;(e=i=i||{}).LOADING="loading",e.LOADED="loaded",e.ERROR="error";var t="undefined"!=typeof window&&null!==window,s=function(){if(t&&"IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)return"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return 0<this.intersectionRatio}}),!0;return!1}(),c=Object.prototype.propertyIsEnumerable,u=Object.getOwnPropertySymbols;function f(e){return"function"==typeof e||"[object Object]"===toString.call(e)}function p(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];var r,n,i=0;for(e=(e=("object"==typeof(r=e)?null===r:"function"!=typeof r)?t[i++]:e)||{};i<t.length;i++)if(f(t[i])){for(var s=0,l=Object.keys(t[i]);s<l.length;s++){var a=l[s];"__proto__"!==(n=a)&&"constructor"!==n&&"prototype"!==n&&(f(e[a])&&f(t[i][a])?p(e[a],t[i][a]):e[a]=t[i][a])}!function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];if(!f(e))throw new TypeError("expected the first argument to be an object");if(0===t.length||"function"!=typeof Symbol||"function"!=typeof u)return;for(var r=0,n=t;r<n.length;r++)for(var i=n[r],s=0,l=u(i);s<l.length;s++){var a=l[s];c.call(i,a)&&(e[a]=i[a])}}(e,t[i])}return e}var o={rootMargin:"0px",threshold:0},l="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",r=(n.prototype.config=function(e){p(this.options,e=void 0===e?{}:e)},n.prototype.mount=function(e,t){var o=this._valueFormatter(t.value),r=o.src,n=o.loading,t=o.error,o=o.lifecycle;this._lifecycle(i.LOADING,o,e),e.setAttribute("src",n||l),s||(this.loadImages(e,r,t,o),this._log(function(){throw new Error("Not support IntersectionObserver!")})),this._initIntersectionObserver(e,r,t,o)},n.prototype.update=function(e,t){null!==(r=this._realObserver(e))&&void 0!==r&&r.unobserve(e);var o=this._valueFormatter(t.value),r=o.src,t=o.error,o=o.lifecycle;this._initIntersectionObserver(e,r,t,o)},n.prototype.unmount=function(e){var t;null!==(t=this._realObserver(e))&&void 0!==t&&t.unobserve(e)},n.prototype.loadImages=function(e,t,o,r){this._setImageSrc(e,t,o,r)},n.prototype._setImageSrc=function(t,e,o,r){var n=this;"img"===t.tagName.toLowerCase()?(e&&t.getAttribute("src")!==e&&t.setAttribute("src",e),this._listenImageStatus(t,function(){n._lifecycle(i.LOADED,r,t)},function(){var e;t.onload=null,n._lifecycle(i.ERROR,r,t),null!==(e=n._realObserver(t))&&void 0!==e&&e.disconnect(),o&&t.setAttribute("src",o),n._log(function(){throw new Error("Image failed to load!")})})):t.style.backgroundImage="url('"+e+"')"},n.prototype._initIntersectionObserver=function(o,r,n,i){var s=this,e=this.options.observerOptions;this._images.set(o,new IntersectionObserver(function(e){Array.prototype.forEach.call(e,function(e){var t;e.isIntersecting&&(null!==(t=s._realObserver(o))&&void 0!==t&&t.unobserve(e.target),s._setImageSrc(o,r,n,i))})},e)),null!==(e=this._realObserver(o))&&void 0!==e&&e.observe(o)},n.prototype._listenImageStatus=function(e,t,o){e.onload=t,e.onerror=o},n.prototype._valueFormatter=function(e){var t=e,o=this.options.loading,r=this.options.error,n=this.options.lifecycle;return f(e)&&(t=e.src,o=e.loading||this.options.loading,r=e.error||this.options.error,n=e.lifecycle||this.options.lifecycle),{src:t,loading:o,error:r,lifecycle:n}},n.prototype._log=function(e){this.options.log&&e()},n.prototype._lifecycle=function(e,t,o){switch(e){case i.LOADING:null!=o&&o.setAttribute("lazy",i.LOADING),null!=t&&t.loading&&t.loading(o);break;case i.LOADED:null!=o&&o.setAttribute("lazy",i.LOADED),null!=t&&t.loaded&&t.loaded(o);break;case i.ERROR:null!=o&&o.setAttribute("lazy",i.ERROR),null!=t&&t.error&&t.error(o)}},n.prototype._realObserver=function(e){return this._images.get(e)},n);function n(e){this.options={loading:l,error:"",observerOptions:o,log:!0,lifecycle:{}},this._images=new WeakMap,this.config(e)}return{install:function(e,t){t=new r(t);e.config.globalProperties.$Lazyload=t,e.provide("Lazyload",t),e.directive("lazy",{mounted:t.mount.bind(t),updated:t.update.bind(t),unmounted:t.unmount.bind(t)})}}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueLazyload=t()}(this,function(){"use strict";var i,e;(e=i=i||{}).LOADING="loading",e.LOADED="loaded",e.ERROR="error";var t="undefined"!=typeof window&&null!==window,s=function(){if(t&&"IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)return"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return 0<this.intersectionRatio}}),!0;return!1}(),c=Object.prototype.propertyIsEnumerable,u=Object.getOwnPropertySymbols;function f(e){return"function"==typeof e||"[object Object]"===toString.call(e)}function p(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];var r,n,i=0;for(e=(e=("object"==typeof(r=e)?null===r:"function"!=typeof r)?t[i++]:e)||{};i<t.length;i++)if(f(t[i])){for(var s=0,l=Object.keys(t[i]);s<l.length;s++){var a=l[s];"__proto__"!==(n=a)&&"constructor"!==n&&"prototype"!==n&&(f(e[a])&&f(t[i][a])?p(e[a],t[i][a]):e[a]=t[i][a])}!function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];if(!f(e))throw new TypeError("expected the first argument to be an object");if(0===t.length||"function"!=typeof Symbol||"function"!=typeof u)return;for(var r=0,n=t;r<n.length;r++)for(var i=n[r],s=0,l=u(i);s<l.length;s++){var a=l[s];c.call(i,a)&&(e[a]=i[a])}}(e,t[i])}return e}var o={rootMargin:"0px",threshold:0},l="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",r=(n.prototype.config=function(e){p(this.options,e=void 0===e?{}:e)},n.prototype.mount=function(e,t){var o=this._valueFormatter(t.value),r=o.src,n=o.loading,t=o.error,o=o.lifecycle;this._lifecycle(i.LOADING,o,e),e.setAttribute("src",n||l),s||(this.loadImages(e,r,t,o),this._log(function(){throw new Error("Not support IntersectionObserver!")})),this._initIntersectionObserver(e,r,t,o)},n.prototype.update=function(e,t){null!==(r=this._realObserver(e))&&void 0!==r&&r.unobserve(e);var o=this._valueFormatter(t.value),r=o.src,t=o.error,o=o.lifecycle;this._initIntersectionObserver(e,r,t,o)},n.prototype.unmount=function(e){var t;null!==(t=this._realObserver(e))&&void 0!==t&&t.unobserve(e),this._images.delete(e)},n.prototype.loadImages=function(e,t,o,r){this._setImageSrc(e,t,o,r)},n.prototype._setImageSrc=function(t,e,o,r){var n=this;"img"===t.tagName.toLowerCase()?(e&&t.getAttribute("src")!==e&&t.setAttribute("src",e),this._listenImageStatus(t,function(){n._lifecycle(i.LOADED,r,t)},function(){var e;t.onload=null,n._lifecycle(i.ERROR,r,t),null!==(e=n._realObserver(t))&&void 0!==e&&e.disconnect(),o&&t.setAttribute("src",o),n._log(function(){throw new Error("Image failed to load!")})})):t.style.backgroundImage="url('"+e+"')"},n.prototype._initIntersectionObserver=function(o,r,n,i){var s=this,e=this.options.observerOptions;this._images.set(o,new IntersectionObserver(function(e){Array.prototype.forEach.call(e,function(e){var t;e.isIntersecting&&(null!==(t=s._realObserver(o))&&void 0!==t&&t.unobserve(e.target),s._setImageSrc(o,r,n,i))})},e)),null!==(e=this._realObserver(o))&&void 0!==e&&e.observe(o)},n.prototype._listenImageStatus=function(e,t,o){e.onload=t,e.onerror=o},n.prototype._valueFormatter=function(e){var t=e,o=this.options.loading,r=this.options.error,n=this.options.lifecycle;return f(e)&&(t=e.src,o=e.loading||this.options.loading,r=e.error||this.options.error,n=e.lifecycle||this.options.lifecycle),{src:t,loading:o,error:r,lifecycle:n}},n.prototype._log=function(e){this.options.log&&e()},n.prototype._lifecycle=function(e,t,o){switch(e){case i.LOADING:null!=o&&o.setAttribute("lazy",i.LOADING),null!=t&&t.loading&&t.loading(o);break;case i.LOADED:null!=o&&o.setAttribute("lazy",i.LOADED),null!=t&&t.loaded&&t.loaded(o);break;case i.ERROR:null!=o&&o.setAttribute("lazy",i.ERROR),null!=t&&t.error&&t.error(o)}},n.prototype._realObserver=function(e){return this._images.get(e)},n);function n(e){this.options={loading:l,error:"",observerOptions:o,log:!0,lifecycle:{}},this._images=new WeakMap,this.config(e)}return{install:function(e,t){t=new r(t);e.config.globalProperties.$Lazyload=t,e.provide("Lazyload",t),e.directive("lazy",{mounted:t.mount.bind(t),updated:t.update.bind(t),unmounted:t.unmount.bind(t)})}}}); |
{ | ||
"name": "vue3-lazyload", | ||
"version": "0.2.4-beta", | ||
"version": "0.2.5-beta", | ||
"description": "A Vue3.x image lazyload plugin", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue3-lazyload.js", |
@@ -84,2 +84,3 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
this._realObserver(el)?.unobserve(el) | ||
this._images.delete(el) | ||
} | ||
@@ -86,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72122
1614