Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@egjs/imready

Package Overview
Dependencies
Maintainers
8
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@egjs/imready - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0-beta.0

2

declaration/utils.d.ts

@@ -5,3 +5,3 @@ import { ArrayFormat } from "./types";

export declare function hasSizeAttribute(target: HTMLElement, prefix?: string): boolean;
export declare function hasLoadingAttribute(target: HTMLElement): target is HTMLImageElement;
export declare function hasLoadingAttribute(target: HTMLElement, prefix?: string): target is HTMLImageElement;
export declare function hasSkipAttribute(target: HTMLElement, prefix?: string): boolean;

@@ -8,0 +8,0 @@ export declare function addEvent(element: EventTarget, type: string, handler: (...args: any[]) => void): void;

@@ -7,3 +7,3 @@ /*

repository: https://github.com/naver/egjs-imready
version: 1.2.0
version: 1.3.0-beta.0
*/

@@ -100,4 +100,8 @@ 'use strict';

}
function hasLoadingAttribute(target) {
return "loading" in target && target.getAttribute("loading") === "lazy";
function hasLoadingAttribute(target, prefix) {
if (prefix === void 0) {
prefix = "data-";
}
return "loading" in target && target.getAttribute("loading") === "lazy" || !!target.getAttribute(prefix + "lazy");
}

@@ -242,3 +246,3 @@ function hasSkipAttribute(target, prefix) {

_this.isSkip = hasSkipAttribute(element, prefix);
_this.hasLoading = hasLoadingAttribute(element);
_this.hasLoading = hasLoadingAttribute(element, prefix);
return _this;

@@ -629,2 +633,3 @@ }

var loaders = this.options.loaders;
var prefix = options.prefix;
var tags = Object.keys(loaders);

@@ -639,3 +644,3 @@

loader.setHasLoading(children.some(function (el) {
return hasLoadingAttribute(el);
return hasLoadingAttribute(el, prefix);
}));

@@ -642,0 +647,0 @@ var withPreReady = false;

@@ -7,3 +7,3 @@ /*

repository: https://github.com/naver/egjs-imready
version: 1.2.0
version: 1.3.0-beta.0
*/

@@ -98,4 +98,8 @@ import Component from '@egjs/component';

}
function hasLoadingAttribute(target) {
return "loading" in target && target.getAttribute("loading") === "lazy";
function hasLoadingAttribute(target, prefix) {
if (prefix === void 0) {
prefix = "data-";
}
return "loading" in target && target.getAttribute("loading") === "lazy" || !!target.getAttribute(prefix + "lazy");
}

@@ -240,3 +244,3 @@ function hasSkipAttribute(target, prefix) {

_this.isSkip = hasSkipAttribute(element, prefix);
_this.hasLoading = hasLoadingAttribute(element);
_this.hasLoading = hasLoadingAttribute(element, prefix);
return _this;

@@ -627,2 +631,3 @@ }

var loaders = this.options.loaders;
var prefix = options.prefix;
var tags = Object.keys(loaders);

@@ -637,3 +642,3 @@

loader.setHasLoading(children.some(function (el) {
return hasLoadingAttribute(el);
return hasLoadingAttribute(el, prefix);
}));

@@ -640,0 +645,0 @@ var withPreReady = false;

@@ -7,3 +7,3 @@ /*

repository: https://github.com/naver/egjs-imready
version: 1.2.0
version: 1.3.0-beta.0
*/

@@ -561,4 +561,8 @@ (function (global, factory) {

}
function hasLoadingAttribute(target) {
return "loading" in target && target.getAttribute("loading") === "lazy";
function hasLoadingAttribute(target, prefix) {
if (prefix === void 0) {
prefix = "data-";
}
return "loading" in target && target.getAttribute("loading") === "lazy" || !!target.getAttribute(prefix + "lazy");
}

@@ -703,3 +707,3 @@ function hasSkipAttribute(target, prefix) {

_this.isSkip = hasSkipAttribute(element, prefix);
_this.hasLoading = hasLoadingAttribute(element);
_this.hasLoading = hasLoadingAttribute(element, prefix);
return _this;

@@ -1090,2 +1094,3 @@ }

var loaders = this.options.loaders;
var prefix = options.prefix;
var tags = Object.keys(loaders);

@@ -1100,3 +1105,3 @@

loader.setHasLoading(children.some(function (el) {
return hasLoadingAttribute(el);
return hasLoadingAttribute(el, prefix);
}));

@@ -1103,0 +1108,0 @@ var withPreReady = false;

@@ -7,5 +7,5 @@ /*

repository: https://github.com/naver/egjs-imready
version: 1.2.0
version: 1.3.0-beta.0
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t=t||self).eg=t.eg||{},t.eg.ImReady=e())}(this,function(){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var a=function(){return(a=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function d(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||0<e--)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}(arguments[e]));return t}function l(t){return void 0===t}var i=function(){function t(t,e){var n,r;if(this.eventType=t,this._canceled=!1,e)try{for(var i=d(Object.keys(e)),o=i.next();!o.done;o=i.next()){var a=o.value;this[a]=e[a]}}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}var e=t.prototype;return e.stop=function(){this._canceled=!0},e.isCanceled=function(){return this._canceled},t}(),t=function(){function t(){this._eventHandler={}}var e=t.prototype;return e.trigger=function(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];var r=e instanceof i?e.eventType:e,r=s(this._eventHandler[r]||[]);return r.length<=0||(e instanceof i?(e.currentTarget=this,r.forEach(function(t){t(e)})):r.forEach(function(t){t.apply(void 0,s(n))})),this},e.once=function(n,r){var i,o=this;if("object"==typeof n&&l(r)){var t,e=n;for(t in e)this.once(t,e[t]);return this}return"string"==typeof n&&"function"==typeof r&&(i=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];r.apply(void 0,s(t)),o.off(n,i)},this.on(n,i)),this},e.hasOn=function(t){return!!this._eventHandler[t]},e.on=function(t,e){if("object"==typeof t&&l(e)){var n,r=t;for(n in r)this.on(n,r[n]);return this}var i;return"string"==typeof t&&"function"==typeof e&&(i=this._eventHandler[t],l(i)&&(this._eventHandler[t]=[],i=this._eventHandler[t]),i.push(e)),this},e.off=function(t,e){var n,r;if(l(t))return this._eventHandler={},this;if(l(e)){if("string"==typeof t)return delete this._eventHandler[t],this;var i,o=t;for(i in o)this.off(i,o[i]);return this}var a=this._eventHandler[t];if(a){var s=0;try{for(var u=d(a),h=u.next();!h.done;h=u.next()){if(h.value===e){a.splice(s,1),a.length<=0&&delete this._eventHandler[t];break}s++}}catch(t){n={error:t}}finally{try{h&&!h.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}return this},t.VERSION="3.0.1",t}(),e="undefined"!=typeof window,n=e?window.navigator.userAgent:"",u=e&&!!("getComputedStyle"in window),h=/MSIE|Trident|Windows Phone|Edge/.test(n),f=e&&!!("addEventListener"in document),c="width",y="height";function p(t,e){return t.getAttribute(e)||""}function v(t){return[].slice.call(t)}function g(t){return"loading"in t&&"lazy"===t.getAttribute("loading")}function R(t,e,n){f?t.addEventListener(e,n,!1):t.attachEvent?t.attachEvent("on"+e,n):t["on"+e]=n}function m(t,e,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent?t.detachEvent("on"+e,n):t["on"+e]=null}function E(t,e){var n=t["client"+e]||t["offset"+e];return parseFloat(n||(t=t,((u?window.getComputedStyle(t):t.currentStyle)||{})[e.toLowerCase()]))||0}function C(t,e,n){var r=v(t.querySelectorAll(function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),i=0,e=0;e<n;e++)for(var o=arguments[e],a=0,s=o.length;a<s;a++,i++)r[i]=o[a];return r}(["["+n+"skip] ["+n+"width]"],e.map(function(t){return["["+n+"skip] "+t,t+"["+n+"skip]","["+n+"width] "+t].join(", ")})).join(", ")));return v(t.querySelectorAll("["+n+"width], "+e.join(", "))).filter(function(t){return-1===r.indexOf(t)})}var S=[];function P(t,e){S.length||R(window,"resize",_),t.__PREFIX__=e,S.push(t),k(t)}function k(t,e){void 0===e&&(e="data-");var n,r=t.__PREFIX__||e,i=parseInt(p(t,""+r+c),10)||0,e=parseInt(p(t,""+r+y),10)||0;p(t,r+"fixed")===y?(n=E(t,"Height")||e,t.style[c]=i/e*n+"px"):(n=E(t,"Width")||i,t.style[y]=e/i*n+"px")}function _(){S.forEach(function(t){k(t)})}var L,e=function(i){function t(t,e){void 0===e&&(e={});var n=i.call(this)||this;n.isReady=!1,n.isPreReady=!1,n.hasDataSize=!1,n.hasLoading=!1,n.isSkip=!1,n.onCheck=function(t){n.clear(),t&&"error"===t.type&&n.onError(n.element);t=!n.hasDataSize&&!n.hasLoading;n.onReady(t)},n.options=a({prefix:"data-"},e),n.element=t;var r=n.options.prefix;return n.hasDataSize=(void 0===(e=r)&&(e="data-"),!!t.getAttribute(e+"width")),n.isSkip=(void 0===(r=r)&&(r="data-"),!!t.getAttribute(r+"skip")),n.hasLoading=g(t),n}o(t,i);var e=t.prototype;return e.check=function(){return this.isSkip||!this.checkElement()?(this.onAlreadyReady(!0),!1):(this.hasDataSize&&P(this.element,this.options.prefix),(this.hasDataSize||this.hasLoading)&&this.onAlreadyPreReady(),!0)},e.addEvents=function(){var e=this,n=this.element;this.constructor.EVENTS.forEach(function(t){R(n,t,e.onCheck)})},e.clear=function(){var e=this,n=this.element;this.constructor.EVENTS.forEach(function(t){m(n,t,e.onCheck)}),this.removeAutoSizer()},e.destroy=function(){this.clear(),this.off()},e.removeAutoSizer=function(){var t,e,n;this.hasDataSize&&(n=this.options.prefix,t=this.element,e=n,(n=S.indexOf(t))<0||(e=p(t,e+"fixed"),delete t.__PREFIX__,t.style[e===y?c:y]="",S.splice(n,1),S.length||m(window,"resize",_)))},e.onError=function(t){this.trigger("error",{element:this.element,target:t})},e.onPreReady=function(){this.isPreReady||(this.isPreReady=!0,this.trigger("preReady",{element:this.element,hasLoading:this.hasLoading,isSkip:this.isSkip}))},e.onReady=function(t){this.isReady||((t=!this.isPreReady&&t)&&(this.isPreReady=!0),this.removeAutoSizer(),this.isReady=!0,this.trigger("ready",{element:this.element,withPreReady:t,hasLoading:this.hasLoading,isSkip:this.isSkip}))},e.onAlreadyError=function(t){var e=this;setTimeout(function(){e.onError(t)})},e.onAlreadyPreReady=function(){var t=this;setTimeout(function(){t.onPreReady()})},e.onAlreadyReady=function(t){var e=this;setTimeout(function(){e.onReady(t)})},t.EVENTS=[],t}(t),w=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}o(e,t);var n=e.prototype;return n.setHasLoading=function(t){this.hasLoading=t},n.check=function(){return this.isSkip?(this.onAlreadyReady(!0),!1):(this.hasDataSize?(P(this.element,this.options.prefix),this.onAlreadyPreReady()):this.trigger("requestChildren"),!0)},n.checkElement=function(){return!0},n.destroy=function(){this.clear(),this.trigger("requestDestroy"),this.off()},n.onAlreadyPreReady=function(){t.prototype.onAlreadyPreReady.call(this),this.trigger("reqeustReadyChildren")},e.EVENTS=[],e}(e),t=function(n){function t(t){void 0===t&&(t={});var e=n.call(this)||this;return e.readyCount=0,e.preReadyCount=0,e.totalCount=0,e.totalErrorCount=0,e.isPreReadyOver=!0,e.elementInfos=[],e.options=a({loaders:{},prefix:"data-"},t),e}o(t,n);var e=t.prototype;return e.check=function(t){var o=this,n=this.options.prefix;this.clear(),this.elementInfos=v(t).map(function(t,i){var e=o.getLoader(t,{prefix:n});return e.check(),e.on("error",function(t){o.onError(i,t.target)}).on("preReady",function(t){var e=o.elementInfos[i];e.hasLoading=t.hasLoading,e.isSkip=t.isSkip;t=o.checkPreReady(i);o.onPreReadyElement(i),t&&o.onPreReady()}).on("ready",function(t){var e=t.withPreReady,n=t.hasLoading,r=t.isSkip,t=o.elementInfos[i];t.hasLoading=n,t.isSkip=r;t=e&&o.checkPreReady(i),r=o.checkReady(i);e&&o.onPreReadyElement(i),o.onReadyElement(i),t&&o.onPreReady(),r&&o.onReady()}),{loader:e,element:t,hasLoading:!1,hasError:!1,isPreReady:!1,isReady:!1,isSkip:!1}});t=this.elementInfos.length;return(this.totalCount=t)||setTimeout(function(){o.onPreReady(),o.onReady()}),this},e.getTotalCount=function(){return this.totalCount},e.isPreReady=function(){return this.elementInfos.every(function(t){return t.isPreReady})},e.isReady=function(){return this.elementInfos.every(function(t){return t.isReady})},e.hasError=function(){return 0<this.totalErrorCount},e.clear=function(){this.isPreReadyOver=!1,this.totalCount=0,this.preReadyCount=0,this.readyCount=0,this.totalErrorCount=0,this.elementInfos.forEach(function(t){!t.isReady&&t.loader&&t.loader.destroy()}),this.elementInfos=[]},e.destroy=function(){this.clear(),this.off()},e.getLoader=function(e,t){var n=this,r=e.tagName.toLowerCase(),i=this.options.loaders,o=Object.keys(i);if(i[r])return new i[r](e,t);var a=new w(e,t),s=v(e.querySelectorAll(o.join(", ")));a.setHasLoading(s.some(g));var u=!1,h=this.clone().on("error",function(t){a.onError(t.target)}).on("ready",function(){a.onReady(u)});return a.on("requestChildren",function(){var t=C(e,o,n.options.prefix);h.check(t).on("preReady",function(t){(u=t.isReady)||a.onPreReady()})}).on("reqeustReadyChildren",function(){h.check(s)}).on("requestDestroy",function(){h.destroy()}),a},e.clone=function(){return new t(a({},this.options))},e.checkPreReady=function(t){return this.elementInfos[t].isPreReady=!0,++this.preReadyCount,!(this.preReadyCount<this.totalCount)},e.checkReady=function(t){return this.elementInfos[t].isReady=!0,++this.readyCount,!(this.readyCount<this.totalCount)},e.onError=function(t,e){var n=this.elementInfos[t];n.hasError=!0,this.trigger("error",{element:n.element,index:t,target:e,errorCount:this.getErrorCount(),totalErrorCount:++this.totalErrorCount})},e.onPreReadyElement=function(t){var e=this.elementInfos[t];this.trigger("preReadyElement",{element:e.element,index:t,preReadyCount:this.preReadyCount,readyCount:this.readyCount,totalCount:this.totalCount,isPreReady:this.isPreReady(),isReady:this.isReady(),hasLoading:e.hasLoading,isSkip:e.isSkip})},e.onPreReady=function(){this.isPreReadyOver=!0,this.trigger("preReady",{readyCount:this.readyCount,totalCount:this.totalCount,isReady:this.isReady(),hasLoading:this.hasLoading()})},e.onReadyElement=function(t){var e=this.elementInfos[t];this.trigger("readyElement",{index:t,element:e.element,hasError:e.hasError,errorCount:this.getErrorCount(),totalErrorCount:this.totalErrorCount,preReadyCount:this.preReadyCount,readyCount:this.readyCount,totalCount:this.totalCount,isPreReady:this.isPreReady(),isReady:this.isReady(),hasLoading:e.hasLoading,isPreReadyOver:this.isPreReadyOver,isSkip:e.isSkip})},e.onReady=function(){this.trigger("ready",{errorCount:this.getErrorCount(),totalErrorCount:this.totalErrorCount,totalCount:this.totalCount})},e.getErrorCount=function(){return this.elementInfos.filter(function(t){return t.hasError}).length},e.hasLoading=function(){return this.elementInfos.some(function(t){return t.hasLoading})},t}(t),x=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.checkElement=function(){var t=this.element,e=t.getAttribute("src");if(t.complete){if(e)return t.naturalWidth||this.onAlreadyError(t),!1;this.onAlreadyPreReady()}return this.addEvents(),h&&t.setAttribute("src",e),!0},e.EVENTS=["load","error"],e}(e),A=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.checkElement=function(){var t=this.element;return!(1<=t.readyState)&&(t.error?(this.onAlreadyError(t),!1):(this.addEvents(),!0))},e.EVENTS=["loadedmetadata","error"],e}(e),b=function(e){function t(t){return void 0===t&&(t={}),e.call(this,a({loaders:{img:x,video:A}},t))||this}return o(t,e),t}(t),I={__proto__:null,default:b,Manager:t,VideoLoader:A,ImageLoader:x,Loader:e,EVENTS:["preReadyElement","readyElement","error","preReady","ready"],PROPS:["prefix","loaders"]};for(L in I)b[L]=I[L];return b});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t=t||self).eg=t.eg||{},t.eg.ImReady=e())}(this,function(){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var a=function(){return(a=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function d(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||0<e--)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}(arguments[e]));return t}function l(t){return void 0===t}var i=function(){function t(t,e){var n,r;if(this.eventType=t,this._canceled=!1,e)try{for(var i=d(Object.keys(e)),o=i.next();!o.done;o=i.next()){var a=o.value;this[a]=e[a]}}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}var e=t.prototype;return e.stop=function(){this._canceled=!0},e.isCanceled=function(){return this._canceled},t}(),t=function(){function t(){this._eventHandler={}}var e=t.prototype;return e.trigger=function(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];var r=e instanceof i?e.eventType:e,r=s(this._eventHandler[r]||[]);return r.length<=0||(e instanceof i?(e.currentTarget=this,r.forEach(function(t){t(e)})):r.forEach(function(t){t.apply(void 0,s(n))})),this},e.once=function(n,r){var i,o=this;if("object"==typeof n&&l(r)){var t,e=n;for(t in e)this.once(t,e[t]);return this}return"string"==typeof n&&"function"==typeof r&&(i=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];r.apply(void 0,s(t)),o.off(n,i)},this.on(n,i)),this},e.hasOn=function(t){return!!this._eventHandler[t]},e.on=function(t,e){if("object"==typeof t&&l(e)){var n,r=t;for(n in r)this.on(n,r[n]);return this}var i;return"string"==typeof t&&"function"==typeof e&&(i=this._eventHandler[t],l(i)&&(this._eventHandler[t]=[],i=this._eventHandler[t]),i.push(e)),this},e.off=function(t,e){var n,r;if(l(t))return this._eventHandler={},this;if(l(e)){if("string"==typeof t)return delete this._eventHandler[t],this;var i,o=t;for(i in o)this.off(i,o[i]);return this}var a=this._eventHandler[t];if(a){var s=0;try{for(var u=d(a),h=u.next();!h.done;h=u.next()){if(h.value===e){a.splice(s,1),a.length<=0&&delete this._eventHandler[t];break}s++}}catch(t){n={error:t}}finally{try{h&&!h.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}return this},t.VERSION="3.0.1",t}(),e="undefined"!=typeof window,n=e?window.navigator.userAgent:"",u=e&&!!("getComputedStyle"in window),h=/MSIE|Trident|Windows Phone|Edge/.test(n),f=e&&!!("addEventListener"in document),c="width",y="height";function p(t,e){return t.getAttribute(e)||""}function v(t){return[].slice.call(t)}function g(t,e){return void 0===e&&(e="data-"),"loading"in t&&"lazy"===t.getAttribute("loading")||!!t.getAttribute(e+"lazy")}function R(t,e,n){f?t.addEventListener(e,n,!1):t.attachEvent?t.attachEvent("on"+e,n):t["on"+e]=n}function m(t,e,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent?t.detachEvent("on"+e,n):t["on"+e]=null}function E(t,e){var n=t["client"+e]||t["offset"+e];return parseFloat(n||(t=t,((u?window.getComputedStyle(t):t.currentStyle)||{})[e.toLowerCase()]))||0}function C(t,e,n){var r=v(t.querySelectorAll(function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),i=0,e=0;e<n;e++)for(var o=arguments[e],a=0,s=o.length;a<s;a++,i++)r[i]=o[a];return r}(["["+n+"skip] ["+n+"width]"],e.map(function(t){return["["+n+"skip] "+t,t+"["+n+"skip]","["+n+"width] "+t].join(", ")})).join(", ")));return v(t.querySelectorAll("["+n+"width], "+e.join(", "))).filter(function(t){return-1===r.indexOf(t)})}var S=[];function P(t,e){S.length||R(window,"resize",_),t.__PREFIX__=e,S.push(t),k(t)}function k(t,e){void 0===e&&(e="data-");var n,r=t.__PREFIX__||e,i=parseInt(p(t,""+r+c),10)||0,e=parseInt(p(t,""+r+y),10)||0;p(t,r+"fixed")===y?(n=E(t,"Height")||e,t.style[c]=i/e*n+"px"):(n=E(t,"Width")||i,t.style[y]=e/i*n+"px")}function _(){S.forEach(function(t){k(t)})}var L,e=function(i){function t(t,e){void 0===e&&(e={});var n=i.call(this)||this;n.isReady=!1,n.isPreReady=!1,n.hasDataSize=!1,n.hasLoading=!1,n.isSkip=!1,n.onCheck=function(t){n.clear(),t&&"error"===t.type&&n.onError(n.element);t=!n.hasDataSize&&!n.hasLoading;n.onReady(t)},n.options=a({prefix:"data-"},e),n.element=t;var r=n.options.prefix;return n.hasDataSize=(void 0===(e=r)&&(e="data-"),!!t.getAttribute(e+"width")),n.isSkip=(void 0===(e=r)&&(e="data-"),!!t.getAttribute(e+"skip")),n.hasLoading=g(t,r),n}o(t,i);var e=t.prototype;return e.check=function(){return this.isSkip||!this.checkElement()?(this.onAlreadyReady(!0),!1):(this.hasDataSize&&P(this.element,this.options.prefix),(this.hasDataSize||this.hasLoading)&&this.onAlreadyPreReady(),!0)},e.addEvents=function(){var e=this,n=this.element;this.constructor.EVENTS.forEach(function(t){R(n,t,e.onCheck)})},e.clear=function(){var e=this,n=this.element;this.constructor.EVENTS.forEach(function(t){m(n,t,e.onCheck)}),this.removeAutoSizer()},e.destroy=function(){this.clear(),this.off()},e.removeAutoSizer=function(){var t,e,n;this.hasDataSize&&(n=this.options.prefix,t=this.element,e=n,(n=S.indexOf(t))<0||(e=p(t,e+"fixed"),delete t.__PREFIX__,t.style[e===y?c:y]="",S.splice(n,1),S.length||m(window,"resize",_)))},e.onError=function(t){this.trigger("error",{element:this.element,target:t})},e.onPreReady=function(){this.isPreReady||(this.isPreReady=!0,this.trigger("preReady",{element:this.element,hasLoading:this.hasLoading,isSkip:this.isSkip}))},e.onReady=function(t){this.isReady||((t=!this.isPreReady&&t)&&(this.isPreReady=!0),this.removeAutoSizer(),this.isReady=!0,this.trigger("ready",{element:this.element,withPreReady:t,hasLoading:this.hasLoading,isSkip:this.isSkip}))},e.onAlreadyError=function(t){var e=this;setTimeout(function(){e.onError(t)})},e.onAlreadyPreReady=function(){var t=this;setTimeout(function(){t.onPreReady()})},e.onAlreadyReady=function(t){var e=this;setTimeout(function(){e.onReady(t)})},t.EVENTS=[],t}(t),w=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}o(e,t);var n=e.prototype;return n.setHasLoading=function(t){this.hasLoading=t},n.check=function(){return this.isSkip?(this.onAlreadyReady(!0),!1):(this.hasDataSize?(P(this.element,this.options.prefix),this.onAlreadyPreReady()):this.trigger("requestChildren"),!0)},n.checkElement=function(){return!0},n.destroy=function(){this.clear(),this.trigger("requestDestroy"),this.off()},n.onAlreadyPreReady=function(){t.prototype.onAlreadyPreReady.call(this),this.trigger("reqeustReadyChildren")},e.EVENTS=[],e}(e),t=function(n){function t(t){void 0===t&&(t={});var e=n.call(this)||this;return e.readyCount=0,e.preReadyCount=0,e.totalCount=0,e.totalErrorCount=0,e.isPreReadyOver=!0,e.elementInfos=[],e.options=a({loaders:{},prefix:"data-"},t),e}o(t,n);var e=t.prototype;return e.check=function(t){var o=this,n=this.options.prefix;this.clear(),this.elementInfos=v(t).map(function(t,i){var e=o.getLoader(t,{prefix:n});return e.check(),e.on("error",function(t){o.onError(i,t.target)}).on("preReady",function(t){var e=o.elementInfos[i];e.hasLoading=t.hasLoading,e.isSkip=t.isSkip;t=o.checkPreReady(i);o.onPreReadyElement(i),t&&o.onPreReady()}).on("ready",function(t){var e=t.withPreReady,n=t.hasLoading,r=t.isSkip,t=o.elementInfos[i];t.hasLoading=n,t.isSkip=r;t=e&&o.checkPreReady(i),r=o.checkReady(i);e&&o.onPreReadyElement(i),o.onReadyElement(i),t&&o.onPreReady(),r&&o.onReady()}),{loader:e,element:t,hasLoading:!1,hasError:!1,isPreReady:!1,isReady:!1,isSkip:!1}});t=this.elementInfos.length;return(this.totalCount=t)||setTimeout(function(){o.onPreReady(),o.onReady()}),this},e.getTotalCount=function(){return this.totalCount},e.isPreReady=function(){return this.elementInfos.every(function(t){return t.isPreReady})},e.isReady=function(){return this.elementInfos.every(function(t){return t.isReady})},e.hasError=function(){return 0<this.totalErrorCount},e.clear=function(){this.isPreReadyOver=!1,this.totalCount=0,this.preReadyCount=0,this.readyCount=0,this.totalErrorCount=0,this.elementInfos.forEach(function(t){!t.isReady&&t.loader&&t.loader.destroy()}),this.elementInfos=[]},e.destroy=function(){this.clear(),this.off()},e.getLoader=function(e,t){var n=this,r=e.tagName.toLowerCase(),i=this.options.loaders,o=t.prefix,a=Object.keys(i);if(i[r])return new i[r](e,t);var s=new w(e,t),u=v(e.querySelectorAll(a.join(", ")));s.setHasLoading(u.some(function(t){return g(t,o)}));var h=!1,d=this.clone().on("error",function(t){s.onError(t.target)}).on("ready",function(){s.onReady(h)});return s.on("requestChildren",function(){var t=C(e,a,n.options.prefix);d.check(t).on("preReady",function(t){(h=t.isReady)||s.onPreReady()})}).on("reqeustReadyChildren",function(){d.check(u)}).on("requestDestroy",function(){d.destroy()}),s},e.clone=function(){return new t(a({},this.options))},e.checkPreReady=function(t){return this.elementInfos[t].isPreReady=!0,++this.preReadyCount,!(this.preReadyCount<this.totalCount)},e.checkReady=function(t){return this.elementInfos[t].isReady=!0,++this.readyCount,!(this.readyCount<this.totalCount)},e.onError=function(t,e){var n=this.elementInfos[t];n.hasError=!0,this.trigger("error",{element:n.element,index:t,target:e,errorCount:this.getErrorCount(),totalErrorCount:++this.totalErrorCount})},e.onPreReadyElement=function(t){var e=this.elementInfos[t];this.trigger("preReadyElement",{element:e.element,index:t,preReadyCount:this.preReadyCount,readyCount:this.readyCount,totalCount:this.totalCount,isPreReady:this.isPreReady(),isReady:this.isReady(),hasLoading:e.hasLoading,isSkip:e.isSkip})},e.onPreReady=function(){this.isPreReadyOver=!0,this.trigger("preReady",{readyCount:this.readyCount,totalCount:this.totalCount,isReady:this.isReady(),hasLoading:this.hasLoading()})},e.onReadyElement=function(t){var e=this.elementInfos[t];this.trigger("readyElement",{index:t,element:e.element,hasError:e.hasError,errorCount:this.getErrorCount(),totalErrorCount:this.totalErrorCount,preReadyCount:this.preReadyCount,readyCount:this.readyCount,totalCount:this.totalCount,isPreReady:this.isPreReady(),isReady:this.isReady(),hasLoading:e.hasLoading,isPreReadyOver:this.isPreReadyOver,isSkip:e.isSkip})},e.onReady=function(){this.trigger("ready",{errorCount:this.getErrorCount(),totalErrorCount:this.totalErrorCount,totalCount:this.totalCount})},e.getErrorCount=function(){return this.elementInfos.filter(function(t){return t.hasError}).length},e.hasLoading=function(){return this.elementInfos.some(function(t){return t.hasLoading})},t}(t),x=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.checkElement=function(){var t=this.element,e=t.getAttribute("src");if(t.complete){if(e)return t.naturalWidth||this.onAlreadyError(t),!1;this.onAlreadyPreReady()}return this.addEvents(),h&&t.setAttribute("src",e),!0},e.EVENTS=["load","error"],e}(e),A=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.checkElement=function(){var t=this.element;return!(1<=t.readyState)&&(t.error?(this.onAlreadyError(t),!1):(this.addEvents(),!0))},e.EVENTS=["loadedmetadata","error"],e}(e),b=function(e){function t(t){return void 0===t&&(t={}),e.call(this,a({loaders:{img:x,video:A}},t))||this}return o(t,e),t}(t),I={__proto__:null,default:b,Manager:t,VideoLoader:A,ImageLoader:x,Loader:e,EVENTS:["preReadyElement","readyElement","error","preReady","ready"],PROPS:["prefix","loaders"]};for(L in I)b[L]=I[L];return b});
//# sourceMappingURL=imready.min.js.map
{
"name": "@egjs/imready",
"version": "1.2.0",
"version": "1.3.0-beta.0",
"description": "This module is used to wait for the image or video to be ready.",

@@ -77,3 +77,3 @@ "main": "dist/imready.cjs.js",

"print-sizes": "^0.1.0",
"pvu": "^0.6.0",
"pvu": "^0.6.1",
"rollup": "^1.7.3",

@@ -80,0 +80,0 @@ "rollup-plugin-node-resolve": "^4.0.1",

@@ -175,2 +175,3 @@ /*

const loaders = this.options.loaders;
const prefix = options.prefix;
const tags = Object.keys(loaders);

@@ -184,3 +185,3 @@

loader.setHasLoading(children.some(el => hasLoadingAttribute(el)));
loader.setHasLoading(children.some(el => hasLoadingAttribute(el, prefix)));
let withPreReady = false;

@@ -187,0 +188,0 @@

@@ -34,3 +34,3 @@ /*

this.isSkip = hasSkipAttribute(element, prefix);
this.hasLoading = hasLoadingAttribute(element);
this.hasLoading = hasLoadingAttribute(element, prefix);
}

@@ -37,0 +37,0 @@ public check() {

@@ -20,4 +20,5 @@ /*

}
export function hasLoadingAttribute(target: HTMLElement): target is HTMLImageElement {
return ("loading" in target) && (target as HTMLImageElement).getAttribute("loading") === "lazy";
export function hasLoadingAttribute(target: HTMLElement, prefix = "data-"): target is HTMLImageElement {
return (("loading" in target) && (target as HTMLImageElement).getAttribute("loading") === "lazy")
|| !!target.getAttribute(`${prefix}lazy`);
}

@@ -24,0 +25,0 @@ export function hasSkipAttribute(target: HTMLElement, prefix = "data-"): boolean {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc