vendor.js 10 KB

1
  1. (global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["pages_basics/common/vendor"],{a507:function(t,e,i){"use strict";i.r(e);var a=i("c74f"),r=i.n(a);for(var s in a)["default"].indexOf(s)<0&&function(t){i.d(e,t,(function(){return a[t]}))}(s);e["default"]=r.a},c74f:function(t,e,i){"use strict";(function(t){var a=i("47a9");Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=a(i("7eb4")),s=a(i("ee10")),h=Math.abs,o=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},n={props:{width:{type:[String,Number],default:"100%"},height:{type:[String,Number],default:"100%"},cutWidth:{type:[String,Number],default:"50%"},cutHeight:{type:[String,Number],default:0},minWidth:{type:Number,default:50},minHeight:{type:Number,default:50},center:{type:Boolean,default:!0},src:String,disableScale:Boolean,disableRotate:Boolean,disableTranslate:Boolean,disableCtrl:Boolean,boundDetect:Boolean,freeBoundDetect:Boolean,keepRatio:Boolean,disablePreview:Boolean,showCtrlBorder:Boolean,resetCut:Boolean,fit:{type:Boolean,default:!0},imageCenter:Boolean,maxZoom:{type:Number,default:10},minZoom:{type:Number,default:1},angle:{type:Number,default:0},zoom:{type:Number,default:1},offset:{type:Array,default:function(){return[0,0]}},background:{type:String,default:"#000"},canvasBackground:{type:String,default:"#fff"},canvasZoom:{type:Number,default:1},fileType:{type:String,default:"png",validator:function(t){return["png","jpg"].includes(t)}},quality:{type:Number,default:1},maskType:{type:String,default:"shadow"},circleView:Boolean},data:function(){return{transform:{angle:0,translate:{x:0,y:0},zoom:1},corner:{left:50,right:50,bottom:50,top:50},image:{originWidth:0,originHeight:0,width:0,height:0},ctrlWidth:0,ctrlHeight:0,view:!1,canvasId:""}},computed:{transformMeta:function(){var t=this.transform;return"translate3d(".concat(t.translate.x,"px, ").concat(t.translate.y,"px, 0) rotate(").concat(t.angle,"deg) scale(").concat(t.zoom,")")},ctrlStyle:function(){var t=this.corner,e="left: ".concat(t.left,"px;top: ").concat(t.top,"px;right: ").concat(t.right,"px;bottom: ").concat(t.bottom,"px;");return"outline"!==this.maskType?e+="box-shadow: 0 0 0 50000rpx rgba(0,0,0, ".concat(this.view?.8:.4,")"):e+="outline: rgba(0,0,0, ".concat(this.view?.8:.4,") solid 5000px"),e}},watch:{src:function(){this.resetCut&&this.resetCutReact(),this.initImage()}},created:function(){var e=this;this.canvasId=function(){var t,e="abcdefghijklmnopqrstuvwxyz",i=e.split("").concat(e.toUpperCase().split("")).concat("0123456789".split("")),a=i.length;while(a){t=Math.floor(Math.random()*a--);var r=i[a];i[a]=i[t],i[t]=r}return i.slice(0,16).join("")}(),t.getSystemInfo().then((function(t){t=t[1]||{windowWidth:375,windowHeight:736},e.ratio=t.windowWidth/750,e.windowHeight=t.windowHeight,e.init(),e.initCanvas()}))},methods:{toPx:function(t){return-1!==t.indexOf("%")?Math.floor(Number(t.replace("%",""))/100*this.containerWidth):-1!==t.indexOf("rpx")?Math.floor(Number(t.replace("rpx",""))*this.ratio):Math.floor(Number(t.replace("px","")))},initCanvas:function(){var e=this,i=t.createSelectorQuery().in(this);i.select(".nice-cropper").boundingClientRect(),i.exec((function(t){e.containerWidth=t[0].width,e.containerHeight=t[0].height,e.initCut()}))},resetCutReact:function(){this.ctrlWidth=Math.min(this.toPx(this.cutWidth),this.containerWidth),this.cutHeight?this.ctrlHeight=Math.min(this.toPx(this.cutHeight),this.containerHeight):this.ctrlHeight=Math.min(this.ctrlWidth,this.containerHeight);var t=this.center?Math.floor((this.containerWidth-this.ctrlWidth)/2):0,e=this.center?Math.floor((this.containerHeight-this.ctrlHeight)/2):0;this.cutRatio=this.ctrlHeight/this.ctrlWidth,this.corner={left:t,right:this.containerWidth-this.ctrlWidth-t,top:e,bottom:this.containerHeight-this.ctrlHeight-e}},initCut:function(){this.resetCutReact(),this.initImage()},initImage:function(){var e=this;return(0,s.default)(r.default.mark((function i(){var a,s;return r.default.wrap((function(i){while(1)switch(i.prev=i.next){case 0:if(e.src){i.next=2;break}return i.abrupt("return");case 2:return i.prev=2,i.next=5,t.getImageInfo({src:e.src});case 5:a=i.sent,e.$emit("load",a),e.image.originWidth=a.width,e.image.originHeight=a.height,e.image.width=e.fit?e.ctrlWidth:a.width,e.image.height=a.height/a.width*e.image.width,e.img=a.path,i.next=23;break;case 14:i.prev=14,i.t0=i["catch"](2),console.error("图片信息获取失败:",i.t0),e.$emit("error",i.t0),e.image.originWidth=e.ctrlWidth,e.image.originHeight=e.ctrlHeight,e.image.width=e.ctrlWidth,e.image.height=e.ctrlHeight,e.img=null;case 23:s=[0,0],e.imageCenter&&(s[0]=(e.ctrlWidth-e.image.width)/2,s[1]=(e.ctrlHeight-e.image.height)/2),Array.isArray(e.offset)&&(s[0]+=e.offset[0]||0,s[1]+=e.offset[1]||0),e.setTranslate(s),e.setZoom(e.zoom),e.transform.angle=e.freeBoundDetect||!e.disableRotate?e.angle:0,e.setBoundary(),e.preview(),e.draw();case 32:case"end":return i.stop()}}),i,null,[[2,14]])})))()},init:function(){this.pretouch={},this.handles={},this.preVector={x:0,y:0},this.distance=30,this.touch={},this.movetouch={},this.cutMode=!1,this.params={zoom:1,deltaX:0,deltaY:0,diffX:0,diffY:0,angle:0}},start:function(t){this.src||t.preventDefault();var e=t.touches?t.touches[0]:t,i=this.touch,a=Date.now();if(i.startX=e.pageX,i.startY=e.pageY,i.startTime=a,this.doubleTap=!1,this.view=!1,clearTimeout(this.previewTimer),t.touches.length>1){var r=t.touches[1];this.preVector={x:r.pageX-this.touch.startX,y:r.pageY-this.touch.startY},this.startDistance=o(this.preVector)}else{var s=this.pretouch;this.doubleTap=this.pretouch.time&&a-this.pretouch.time<300&&h(i.startX-s.startX)<30&&h(i.startY-s.startY)<30&&h(i.startTime-s.time)<300,s={startX:this.touch.startX,startY:this.touch.startY,time:this.touch.startTime}}},move:function(t){if(this.src){var e=t.touches?t.touches[0]:t;if(t.touches.length>1){var i=t.touches[1],a={x:i.pageX-e.pageX,y:i.pageY-e.pageY};if(null!==this.preVector.x){if(this.startDistance){var r=o(a);this.params.zoom=o(a)/this.startDistance,this.startDistance=r,this.cutMode&&!this.disableCtrl?this.setCut():!this.disableScale&&this.pinch()}this.params.angle=function(t,e){var i,a,r=o(t)*o(e);return r?(i=(t.x*e.x+t.y*e.y)/r,a=Math.acos(Math.min(i,1)),a=t.x*e.y-e.x*t.y>0?-a:a,180*a/Math.PI):0}(a,this.preVector),this.cutMode&&!this.disableCtrl?this.setCut():!this.disableRotate&&this.rotate()}this.preVector.x=a.x,this.preVector.y=a.y}else{var s=e.pageX-this.touch.startX,n=e.pageY-this.touch.startY;this.params.diffY=n,this.params.diffX=s,this.movetouch.x?(this.params.deltaX=e.pageX-this.movetouch.x,this.params.deltaY=e.pageY-this.movetouch.y):this.params.deltaX=this.params.deltaY=0,(h(s)>30||h(n)>30)&&(this.doubleTap=!1),this.cutMode&&!this.disableCtrl?this.setCut():!this.disableTranslate&&this.translate(),this.movetouch.x=e.pageX,this.movetouch.y=e.pageY}!this.cutMode&&this.setBoundary(),t.touches.length>1&&t.preventDefault()}},end:function(){this.doubleTap&&this.$emit("doubleTap"),this.cutMode&&this.setBoundary(),this.init(),!this.disablePreview&&this.preview(),this.draw()},translate:function(){var t=this.transform.translate,e=this.params;t.x+=e.deltaX,t.y+=e.deltaY},pinch:function(){this.transform.zoom*=this.params.zoom},rotate:function(){this.transform.angle+=this.params.angle},setZoom:function(t){t=Math.min(Math.max(Number(t)||1,this.minZoom),this.maxZoom),this.transform.zoom=t},setTranslate:function(t){if(Array.isArray(t)){var e=Number(t[0]),i=Number(t[1]);this.transform.translate.x=isNaN(e)?this.transform.translate.x:this.corner.left+e,this.transform.translate.y=isNaN(i)?this.transform.translate.y:this.corner.top+i}},setRotate:function(t){this.transform.angle=Number(t)||0},setTransform:function(t,e,i,a){this.setTranslate([t,e]),this.setZoom(a),this.setRotate(i)},setCutMode:function(t){this.src&&(this.cutMode=!0,this.cutDirection=t)},setCut:function(){var t=this.corner,e=this.params;switch(this.setMeta(this.cutDirection,e),this.keepRatio&&("lt"===this.cutDirection||"rb"===this.cutDirection?e.deltaY=e.deltaX*this.cutRatio:e.deltaX=e.deltaY/this.cutRatio),this.cutDirection){case"lt":t.top+=e.deltaY,t.left+=e.deltaX;break;case"rt":t.top+=e.deltaY,t.right-=this.keepRatio?-e.deltaX:e.deltaX;break;case"rb":t.right-=e.deltaX,t.bottom-=e.deltaY;break;case"lb":t.bottom-=e.deltaY,t.left+=this.keepRatio?-e.deltaX:e.deltaX;break}this.ctrlWidth=this.containerWidth-t.left-t.right,this.ctrlHeight=this.containerHeight-t.top-t.bottom},setMeta:function(t,e){var i=this.ctrlWidth,a=this.ctrlHeight,r=this.minWidth,s=this.minHeight;switch(t){case"lt":(e.deltaX>0||e.deltaY>0)&&(e.deltaX=Math.min(e.deltaX,i-r),e.deltaY=Math.min(e.deltaY,a-s));break;case"rt":(e.deltaX<0||e.deltaY>0)&&(e.deltaX=Math.max(e.deltaX,r-i),e.deltaY=Math.min(e.deltaY,a-s));break;case"rb":(e.deltaX<0||e.deltaY<0)&&(e.deltaX=Math.max(e.deltaX,r-i),e.deltaY=Math.max(e.deltaY,s-a));break;case"lb":(e.deltaX>0||e.deltaY<0)&&(e.deltaX=Math.min(e.deltaX,i-r),e.deltaY=Math.max(e.deltaY,s-a));break}},setBoundary:function(){var t=this.transform.zoom;if(t=t<this.minZoom?this.minZoom:t>this.maxZoom?this.maxZoom:t,this.transform.zoom=t,!this.boundDetect||!this.disableRotate&&!this.freeBoundDetect)return!0;var e=this.transform.translate,i=this.corner,a=i.left-this.image.width+this.ctrlWidth-this.image.width*(t-1)/2,r=i.left+this.image.width*(t-1)/2,s=i.top-this.image.height+this.ctrlHeight-this.image.height*(t-1)/2,h=i.top+this.image.height*(t-1)/2;e.x=Math.floor(e.x<a?a:e.x>r?r:e.x),e.y=Math.floor(e.y<s?s:e.y>h?h:e.y)},preview:function(){var t=this;clearTimeout(this.previewTimer),this.previewTimer=setTimeout((function(){t.view=!0}),500)},draw:function(){var e=this,i=t.createCanvasContext(this.canvasId,this),a=this.transform,r=this.corner,s=this.canvasZoom,h=this.image;i.save(),i.setFillStyle(this.canvasBackground),this.$emit("beforeDraw",i,a);var o=a.zoom;i.fillRect(0,0,this.ctrlWidth*s,this.ctrlHeight*s),i.translate((a.translate.x-r.left+h.width/2)*s,(a.translate.y-r.top+h.height/2)*s),i.rotate(a.angle*Math.PI/180),i.translate(-h.width*o*.5*s,-h.height*o*.5*s),i.drawImage(this.img,0,0,h.width*o*s,h.height*o*s),i.restore(),this.$emit("afterDraw",i,{width:this.ctrlWidth*s,height:this.ctrlHeight*s}),i.draw(!1,(function(){t.canvasToTempFilePath({canvasId:e.canvasId,quality:e.quality||1,fileType:e.fileType,success:function(t){e.$emit("cropped",t.tempFilePath,{originWidth:e.image.originWidth,originHeight:e.image.originHeight,width:e.ctrlWidth*s,height:e.ctrlHeight*s,scale:o,translate:{x:a.translate.x,y:a.translate.y},rotate:a.angle})}},e)}))}}};e.default=n}).call(this,i("df3c")["default"])}}]);