cube-vue-image-lazy
Version:
A super simple image lazy loader for Vue.
8 lines (7 loc) • 16.1 kB
JavaScript
/**
* @module cube-vue-image-lazy
* @version 0.4.1
* @license MIT
*/
var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t,e){return t(e={exports:{}},e.exports),e.exports}var r=function(t){return t&&t.Math==Math&&t},n=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof t&&t)||Function("return this")(),o=function(t){try{return!!t()}catch(t){return!0}},i=!o((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),c={}.propertyIsEnumerable,u=Object.getOwnPropertyDescriptor,a={f:u&&!c.call({1:2},1)?function(t){var e=u(this,t);return!!e&&e.enumerable}:c},f=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},s={}.toString,l=function(t){return s.call(t).slice(8,-1)},p="".split,d=o((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==l(t)?p.call(t,""):Object(t)}:Object,h=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},y=function(t){return d(h(t))},g=function(t){return"object"==typeof t?null!==t:"function"==typeof t},v=function(t,e){if(!g(t))return t;var r,n;if(e&&"function"==typeof(r=t.toString)&&!g(n=r.call(t)))return n;if("function"==typeof(r=t.valueOf)&&!g(n=r.call(t)))return n;if(!e&&"function"==typeof(r=t.toString)&&!g(n=r.call(t)))return n;throw TypeError("Can't convert object to primitive value")},m={}.hasOwnProperty,b=function(t,e){return m.call(t,e)},S=n.document,O=g(S)&&g(S.createElement),E=function(t){return O?S.createElement(t):{}},w=!i&&!o((function(){return 7!=Object.defineProperty(E("div"),"a",{get:function(){return 7}}).a})),_=Object.getOwnPropertyDescriptor,j={f:i?_:function(t,e){if(t=y(t),e=v(e,!0),w)try{return _(t,e)}catch(t){}if(b(t,e))return f(!a.f.call(t,e),t[e])}},C=function(t){if(!g(t))throw TypeError(String(t)+" is not an object");return t},T=Object.defineProperty,L={f:i?T:function(t,e,r){if(C(t),e=v(e,!0),C(r),w)try{return T(t,e,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported");return"value"in r&&(t[e]=r.value),t}},A=i?function(t,e,r){return L.f(t,e,f(1,r))}:function(t,e,r){return t[e]=r,t},I=function(t,e){try{A(n,t,e)}catch(r){n[t]=e}return e},N=n["__core-js_shared__"]||I("__core-js_shared__",{}),P=Function.toString;"function"!=typeof N.inspectSource&&(N.inspectSource=function(t){return P.call(t)});var x,M,R,F=N.inspectSource,$=n.WeakMap,k="function"==typeof $&&/native code/.test(F($)),V=e((function(t){(t.exports=function(t,e){return N[t]||(N[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.5",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),G=0,D=Math.random(),z=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++G+D).toString(36)},U=V("keys"),X=function(t){return U[t]||(U[t]=z(t))},q={},H=n.WeakMap;if(k){var W=new H,Y=W.get,B=W.has,K=W.set;x=function(t,e){return K.call(W,t,e),e},M=function(t){return Y.call(W,t)||{}},R=function(t){return B.call(W,t)}}else{var J=X("state");q[J]=!0,x=function(t,e){return A(t,J,e),e},M=function(t){return b(t,J)?t[J]:{}},R=function(t){return b(t,J)}}var Q,Z,tt={set:x,get:M,has:R,enforce:function(t){return R(t)?M(t):x(t,{})},getterFor:function(t){return function(e){var r;if(!g(e)||(r=M(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return r}}},et=e((function(t){var e=tt.get,r=tt.enforce,o=String(String).split("String");(t.exports=function(t,e,i,c){var u=!!c&&!!c.unsafe,a=!!c&&!!c.enumerable,f=!!c&&!!c.noTargetGet;"function"==typeof i&&("string"!=typeof e||b(i,"name")||A(i,"name",e),r(i).source=o.join("string"==typeof e?e:"")),t!==n?(u?!f&&t[e]&&(a=!0):delete t[e],a?t[e]=i:A(t,e,i)):a?t[e]=i:I(e,i)})(Function.prototype,"toString",(function(){return"function"==typeof this&&e(this).source||F(this)}))})),rt=n,nt=function(t){return"function"==typeof t?t:void 0},ot=function(t,e){return arguments.length<2?nt(rt[t])||nt(n[t]):rt[t]&&rt[t][e]||n[t]&&n[t][e]},it=Math.ceil,ct=Math.floor,ut=function(t){return isNaN(t=+t)?0:(t>0?ct:it)(t)},at=Math.min,ft=function(t){return t>0?at(ut(t),9007199254740991):0},st=Math.max,lt=Math.min,pt=function(t){return function(e,r,n){var o,i=y(e),c=ft(i.length),u=function(t,e){var r=ut(t);return r<0?st(r+e,0):lt(r,e)}(n,c);if(t&&r!=r){for(;c>u;)if((o=i[u++])!=o)return!0}else for(;c>u;u++)if((t||u in i)&&i[u]===r)return t||u||0;return!t&&-1}},dt={includes:pt(!0),indexOf:pt(!1)},ht=dt.indexOf,yt=function(t,e){var r,n=y(t),o=0,i=[];for(r in n)!b(q,r)&&b(n,r)&&i.push(r);for(;e.length>o;)b(n,r=e[o++])&&(~ht(i,r)||i.push(r));return i},gt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],vt=gt.concat("length","prototype"),mt={f:Object.getOwnPropertyNames||function(t){return yt(t,vt)}},bt={f:Object.getOwnPropertySymbols},St=ot("Reflect","ownKeys")||function(t){var e=mt.f(C(t)),r=bt.f;return r?e.concat(r(t)):e},Ot=function(t,e){for(var r=St(e),n=L.f,o=j.f,i=0;i<r.length;i++){var c=r[i];b(t,c)||n(t,c,o(e,c))}},Et=/#|\.prototype\./,wt=function(t,e){var r=jt[_t(t)];return r==Tt||r!=Ct&&("function"==typeof e?o(e):!!e)},_t=wt.normalize=function(t){return String(t).replace(Et,".").toLowerCase()},jt=wt.data={},Ct=wt.NATIVE="N",Tt=wt.POLYFILL="P",Lt=wt,At=j.f,It=function(t,e){var r,o,i,c,u,a=t.target,f=t.global,s=t.stat;if(r=f?n:s?n[a]||I(a,{}):(n[a]||{}).prototype)for(o in e){if(c=e[o],i=t.noTargetGet?(u=At(r,o))&&u.value:r[o],!Lt(f?o:a+(s?".":"#")+o,t.forced)&&void 0!==i){if(typeof c==typeof i)continue;Ot(c,i)}(t.sham||i&&i.sham)&&A(c,"sham",!0),et(r,o,c,t)}},Nt=function(t,e,r){if(function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function")}(t),void 0===e)return t;switch(r){case 0:return function(){return t.call(e)};case 1:return function(r){return t.call(e,r)};case 2:return function(r,n){return t.call(e,r,n)};case 3:return function(r,n,o){return t.call(e,r,n,o)}}return function(){return t.apply(e,arguments)}},Pt=function(t){return Object(h(t))},xt=Array.isArray||function(t){return"Array"==l(t)},Mt=!!Object.getOwnPropertySymbols&&!o((function(){return!String(Symbol())})),Rt=Mt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Ft=V("wks"),$t=n.Symbol,kt=Rt?$t:$t&&$t.withoutSetter||z,Vt=function(t){return b(Ft,t)||(Mt&&b($t,t)?Ft[t]=$t[t]:Ft[t]=kt("Symbol."+t)),Ft[t]},Gt=Vt("species"),Dt=function(t,e){var r;return xt(t)&&("function"!=typeof(r=t.constructor)||r!==Array&&!xt(r.prototype)?g(r)&&null===(r=r[Gt])&&(r=void 0):r=void 0),new(void 0===r?Array:r)(0===e?0:e)},zt=[].push,Ut=function(t){var e=1==t,r=2==t,n=3==t,o=4==t,i=6==t,c=5==t||i;return function(u,a,f,s){for(var l,p,h=Pt(u),y=d(h),g=Nt(a,f,3),v=ft(y.length),m=0,b=s||Dt,S=e?b(u,v):r?b(u,0):void 0;v>m;m++)if((c||m in y)&&(p=g(l=y[m],m,h),t))if(e)S[m]=p;else if(p)switch(t){case 3:return!0;case 5:return l;case 6:return m;case 2:zt.call(S,l)}else if(o)return!1;return i?-1:n||o?o:S}},Xt={forEach:Ut(0),map:Ut(1),filter:Ut(2),some:Ut(3),every:Ut(4),find:Ut(5),findIndex:Ut(6)},qt=Object.defineProperty,Ht={},Wt=function(t){throw t},Yt=function(t,e){if(b(Ht,t))return Ht[t];e||(e={});var r=[][t],n=!!b(e,"ACCESSORS")&&e.ACCESSORS,c=b(e,0)?e[0]:Wt,u=b(e,1)?e[1]:void 0;return Ht[t]=!!r&&!o((function(){if(n&&!i)return!0;var t={length:-1};n?qt(t,1,{enumerable:!0,get:Wt}):t[1]=1,r.call(t,c,u)}))},Bt=Xt.forEach,Kt=!!(Z=[]["forEach"])&&o((function(){Z.call(null,Q||function(){throw 1},1)})),Jt=Yt("forEach"),Qt=Kt&&Jt?[].forEach:function(t){return Bt(this,t,arguments.length>1?arguments[1]:void 0)};It({target:"Array",proto:!0,forced:[].forEach!=Qt},{forEach:Qt});var Zt,te=Object.keys||function(t){return yt(t,gt)},ee=i?Object.defineProperties:function(t,e){C(t);for(var r,n=te(e),o=n.length,i=0;o>i;)L.f(t,r=n[i++],e[r]);return t},re=ot("document","documentElement"),ne=X("IE_PROTO"),oe=function(){},ie=function(t){return"<script>"+t+"<\/script>"},ce=function(){try{Zt=document.domain&&new ActiveXObject("htmlfile")}catch(t){}var t,e;ce=Zt?function(t){t.write(ie("")),t.close();var e=t.parentWindow.Object;return t=null,e}(Zt):((e=E("iframe")).style.display="none",re.appendChild(e),e.src=String("javascript:"),(t=e.contentWindow.document).open(),t.write(ie("document.F=Object")),t.close(),t.F);for(var r=gt.length;r--;)delete ce.prototype[gt[r]];return ce()};q[ne]=!0;var ue=Object.create||function(t,e){var r;return null!==t?(oe.prototype=C(t),r=new oe,oe.prototype=null,r[ne]=t):r=ce(),void 0===e?r:ee(r,e)},ae=Vt("unscopables"),fe=Array.prototype;null==fe[ae]&&L.f(fe,ae,{configurable:!0,value:ue(null)});var se=dt.includes;It({target:"Array",proto:!0,forced:!Yt("indexOf",{ACCESSORS:!0,1:0})},{includes:function(t){return se(this,t,arguments.length>1?arguments[1]:void 0)}}),function(t){fe[ae][t]=!0}("includes");var le=L.f,pe=Function.prototype,de=pe.toString,he=/^\s*function ([^ (]*)/;i&&!("name"in pe)&&le(pe,"name",{configurable:!0,get:function(){try{return de.call(this).match(he)[1]}catch(t){return""}}});var ye=a.f,ge=function(t){return function(e){for(var r,n=y(e),o=te(n),c=o.length,u=0,a=[];c>u;)r=o[u++],i&&!ye.call(n,r)||a.push(t?[r,n[r]]:n[r]);return a}},ve={entries:ge(!0),values:ge(!1)}.entries;It({target:"Object",stat:!0},{entries:function(t){return ve(t)}}),It({target:"Object",stat:!0,forced:o((function(){te(1)}))},{keys:function(t){return te(Pt(t))}});var me=Vt("match"),be=function(t){if(function(t){var e;return g(t)&&(void 0!==(e=t[me])?!!e:"RegExp"==l(t))}(t))throw TypeError("The method doesn't accept regular expressions");return t},Se=Vt("match");It({target:"String",proto:!0,forced:!function(t){var e=/./;try{"/./"[t](e)}catch(r){try{return e[Se]=!1,"/./"[t](e)}catch(t){}}return!1}("includes")},{includes:function(t){return!!~String(h(this)).indexOf(be(t),arguments.length>1?arguments[1]:void 0)}});for(var Oe in{CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}){var Ee=n[Oe],we=Ee&&Ee.prototype;if(we&&we.forEach!==Qt)try{A(we,"forEach",Qt)}catch(t){we.forEach=Qt}}function _e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function je(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var r=[],n=!0,o=!1,i=void 0;try{for(var c,u=t[Symbol.iterator]();!(n=(c=u.next()).done)&&(r.push(c.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return r}}(t,e)||function(t,e){if(t){if("string"==typeof t)return _e(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_e(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var Ce=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,r={};try{(t=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set).call(r,[]),e=r instanceof Array}catch(t){}return function(r,n){return C(r),function(t){if(!g(t)&&null!==t)throw TypeError("Can't set "+String(t)+" as a prototype")}(n),e?t.call(r,n):r.__proto__=n,r}}():void 0),Te=function(t,e,r){var n,o;return Ce&&"function"==typeof(n=e.constructor)&&n!==r&&g(o=n.prototype)&&o!==r.prototype&&Ce(t,o),t},Le="[\t\n\v\f\r \u2028\u2029\ufeff]",Ae=RegExp("^"+Le+Le+"*"),Ie=RegExp(Le+Le+"*$"),Ne=function(t){return function(e){var r=String(h(e));return 1&t&&(r=r.replace(Ae,"")),2&t&&(r=r.replace(Ie,"")),r}},Pe={start:Ne(1),end:Ne(2),trim:Ne(3)},xe=mt.f,Me=j.f,Re=L.f,Fe=Pe.trim,$e=n.Number,ke=$e.prototype,Ve="Number"==l(ue(ke)),Ge=function(t){var e,r,n,o,i,c,u,a,f=v(t,!1);if("string"==typeof f&&f.length>2)if(43===(e=(f=Fe(f)).charCodeAt(0))||45===e){if(88===(r=f.charCodeAt(2))||120===r)return NaN}else if(48===e){switch(f.charCodeAt(1)){case 66:case 98:n=2,o=49;break;case 79:case 111:n=8,o=55;break;default:return+f}for(c=(i=f.slice(2)).length,u=0;u<c;u++)if((a=i.charCodeAt(u))<48||a>o)return NaN;return parseInt(i,n)}return+f};if(Lt("Number",!$e(" 0o1")||!$e("0b1")||$e("+0x1"))){for(var De,ze=function(t){var e=arguments.length<1?0:t,r=this;return r instanceof ze&&(Ve?o((function(){ke.valueOf.call(r)})):"Number"!=l(r))?Te(new $e(Ge(e)),r,ze):Ge(e)},Ue=i?xe($e):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger".split(","),Xe=0;Ue.length>Xe;Xe++)b($e,De=Ue[Xe])&&!b(ze,De)&&Re(ze,De,Me($e,De));ze.prototype=ke,ke.constructor=ze,et(n,"Number",ze)}var qe=0,He=1,We=2;function Ye(t,e,r,n,o,i,c,u,a,f){"boolean"!=typeof c&&(a=u,u=c,c=!1);const s="function"==typeof r?r.options:r;let l;if(t&&t.render&&(s.render=t.render,s.staticRenderFns=t.staticRenderFns,s._compiled=!0,o&&(s.functional=!0)),n&&(s._scopeId=n),i?(l=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,a(t)),t&&t._registeredComponents&&t._registeredComponents.add(i)},s._ssrRegister=l):e&&(l=c?function(t){e.call(this,f(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,u(t))}),l)if(s.functional){const t=s.render;s.render=function(e,r){return l.call(r),t(e,r)}}else{const t=s.beforeCreate;s.beforeCreate=t?[].concat(t,l):[l]}return r}var Be={name:"ImageLazy",props:{src:{type:String,required:!0},srcset:{type:String,default:""},eager:{type:Boolean,default:!1},delay:{type:Number,default:0},baseClass:{type:String,default:"image-lazy"},deferredClass:{type:String,default:"image-lazy-deferred"},loadingClass:{type:String,default:"image-lazy-loading"},loadedClass:{type:String,default:"image-lazy-loaded"}},data:function(){return{state:qe,delayExpired:!1}},computed:{imageClasses:function(){var t=[this.baseClass];switch(this.state){case qe:t.push(this.deferredClass);break;case He:t.push(this.loadingClass);break;case We:t.push(this.delayExpired?this.loadedClass:this.loadingClass)}return t}},methods:{observe:function(){var t=this;"IntersectionObserver"in window?(this.$observer=new IntersectionObserver((function(e){e.forEach((function(e){e.isIntersecting&&(t.load(),t.unobserve())}))})),this.$observer.observe(this.$refs.img)):this.load()},unobserve:function(){this.$observer&&this.$observer.unobserve(this.$refs.img)},load:function(){var t=this;window.requestAnimationFrame((function(){t.state=He,t.$emit("loading",t),setTimeout((function(){return t.delayExpired=!0}),t.delay),Object.assign(t.$refs.img,{src:t.src,srcset:t.srcset})}))},onLoad:function(){this.state=We,this.$emit("load",this)}},mounted:function(){this.eager?this.load():this.observe()},beforeDestroy:function(){this.unobserve()}},Ke=function(){var t=this.$createElement;return(this._self._c||t)("img",this._g(this._b({ref:"img",class:this.imageClasses,on:{load:this.onLoad}},"img",this.$attrs,!1),this.$listeners))};Ke._withStripped=!0;var Je=Ye({render:Ke,staticRenderFns:[]},void 0,Be,void 0,!1,void 0,!1,void 0,void 0,void 0);function Qe(t){var e=Object.keys(Je.props);Object.entries(t).forEach((function(t){var r=je(t,2),n=r[0],o=r[1];e.includes(n)&&(Je.props[n].default=o)}))}function Ze(t,e){var r=e.name,n=void 0===r?Je.name:r;t.component(n,Je)}Je.install=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Qe(e),Ze(t,e)};export default Je;
//# sourceMappingURL=cube-vue-image-lazy.esm.js.map