@tarojs/components
Version:
1 lines • 2.54 kB
JavaScript
import{r as registerInstance,c as createEvent,h,H as Host}from"./index-ab3c86da.js";import{c as classnames}from"./index-c3e4004b.js";var indexCss='img[src=""]{opacity:0}taro-image-core{width:auto;height:auto;font-size:0;display:inline-block;position:relative;overflow:hidden}.taro-img.taro-img__widthfix{height:100%}.taro-img__mode-scaletofill{width:100%;height:100%}.taro-img__mode-aspectfit{max-width:100%;max-height:100%}.taro-img__mode-aspectfill{position:absolute;top:50%;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%)}.taro-img__mode-aspectfill--width{min-width:100%;height:100%}.taro-img__mode-aspectfill--height{width:100%;min-height:100%}.taro-img__mode-widthfix{width:100%}.taro-img__mode-heightfix{height:100%}.taro-img__mode-top{width:100%}.taro-img__mode-bottom{width:100%;position:absolute;bottom:0}.taro-img__mode-left{height:100%}.taro-img__mode-right{height:100%;position:absolute;right:0}.taro-img__mode-topright{position:absolute;right:0}.taro-img__mode-bottomleft{position:absolute;bottom:0}.taro-img__mode-bottomright{position:absolute;bottom:0;right:0}';var Image=function(){function t(t){registerInstance(this,t);this.onLoad=createEvent(this,"load",7);this.onError=createEvent(this,"error",7);this.src=undefined;this.mode="scaleToFill";this.lazyLoad=false;this.nativeProps={};this.aspectFillMode="width";this.didLoad=false}t.prototype.componentDidLoad=function(){var t=this;if(!this.lazyLoad)return;var i=new IntersectionObserver((function(o){if(o[o.length-1].isIntersecting){i.unobserve(t.imgRef);t.didLoad=true}}),{rootMargin:"300px 0px"});i.observe(this.imgRef)};t.prototype.imageOnLoad=function(){var t=this.imgRef,i=t.width,o=t.height,e=t.naturalWidth,a=t.naturalHeight;this.onLoad.emit({width:i,height:o});this.aspectFillMode=e>a?"width":"height"};t.prototype.imageOnError=function(t){this.onError.emit(t)};t.prototype.render=function(){var t;var i=this;var o=this,e=o.src,a=o.lazyLoad,r=a===void 0?false:a,s=o.aspectFillMode,n=s===void 0?"width":s,d=o.imageOnLoad,m=o.imageOnError,g=o.nativeProps,l=o.didLoad;var c=this.mode||"scaleToFill";var f=classnames({"taro-img__widthfix":c==="widthFix"});var p=classnames("taro-img__mode-".concat(c.toLowerCase().replace(/\s/g,"")),(t={},t["taro-img__mode-aspectfill--".concat(n)]=c==="aspectFill",t));return h(Host,{class:f},e?h("img",Object.assign({ref:function(t){return i.imgRef=t},class:p,src:r&&!l?undefined:e,onLoad:d.bind(this),onError:m.bind(this)},g)):"")};return t}();Image.style=indexCss;export{Image as taro_image_core};