t-fighting-design
Version:
Fighting design can quickly build interactive interfaces in vue3 applications, which looks good.
2 lines (1 loc) • 1.35 kB
JavaScript
"use strict";var n=Object.defineProperty;var l=(s,e,r)=>e in s?n(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var o=(s,e,r)=>(l(s,typeof e!="symbol"?e+"":e,r),r);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("./index3.js");class i{constructor(e,r,t){o(this,"node");o(this,"props");o(this,"callback");o(this,"loadCreateImg",e=>{const r=new Image;e?r.src=e:r.src=this.props.src,r.addEventListener("error",t=>{this.onerror(t)}),r.addEventListener("load",t=>{this.onload(t,r.src)})});o(this,"onerror",e=>{if(this.props.errSrc){this.loadCreateImg(this.props.errSrc),this.props.errSrc="";return}this.props.error&&this.props.error(e),this.callback&&this.callback(!1)});o(this,"onload",(e,r)=>{this.node.src=r,this.props.load&&this.props.load(e),this.callback&&this.callback(!0)});this.node=e,this.props=r,this.callback=t}}class d extends i{constructor(r,t,a){super(r,t,a);o(this,"observer",()=>{const r=new IntersectionObserver(t=>{t[0].isIntersecting&&(this.loadCreateImg(),r.unobserve(this.node))},{rootMargin:c.isString(this.props.rootMargin)?this.props.rootMargin:this.props.rootMargin+"px"});return r});o(this,"lazyCreateImg",()=>{this.observer().observe(this.node)})}}const h=(s,e,r)=>e.lazy?new d(s,e,r).lazyCreateImg():new i(s,e,r).loadCreateImg();exports.loadImage=h;