You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9 lines
18 KiB

3 years ago
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["uview-ui-components-u-avatar-cropper-u-avatar-cropper"],{7148:function(t,e,n){(function(e){n("99af"),n("cb29"),n("4160"),n("c975"),n("fb6a"),n("b64b"),n("d3b7"),n("acd8"),n("ac1f"),n("25f0"),n("466d"),n("5319"),n("159b"),
/**
* we-cropper v1.3.9
* (c) 2020 dlhandsome
* @license MIT
*/
function(e,n){t.exports=n()}(0,(function(){"use strict";var t=void 0,n=["touchstarted","touchmoved","touchended"];function o(t){return t.charAt(0).toUpperCase()+t.slice(1)}function r(t){var e=[],o=arguments.length-1;while(o-- >0)e[o]=arguments[o+1];n.forEach((function(n,o){void 0!==e[o]&&(t[n]=e[o])}))}function i(t,e){Object.defineProperties(t,e)}function a(){return t||(t=uni.getSystemInfoSync()),t}var c={},u=a(),s=u.pixelRatio,d={id:{default:"cropper",get:function(){return c.id},set:function(t){"string"!==typeof t&&console.error("id:"+t+" is invalid"),c.id=t}},width:{default:750,get:function(){return c.width},set:function(t){"number"!==typeof t&&console.error("width:"+t+" is invalid"),c.width=t}},height:{default:750,get:function(){return c.height},set:function(t){"number"!==typeof t&&console.error("height:"+t+" is invalid"),c.height=t}},pixelRatio:{default:s,get:function(){return c.pixelRatio},set:function(t){"number"!==typeof t&&console.error("pixelRatio:"+t+" is invalid"),c.pixelRatio=t}},scale:{default:2.5,get:function(){return c.scale},set:function(t){"number"!==typeof t&&console.error("scale:"+t+" is invalid"),c.scale=t}},zoom:{default:5,get:function(){return c.zoom},set:function(t){"number"!==typeof t?console.error("zoom:"+t+" is invalid"):(t<0||t>10)&&console.error("zoom should be ranged in 0 ~ 10"),c.zoom=t}},src:{default:"",get:function(){return c.src},set:function(t){"string"!==typeof t&&console.error("src:"+t+" is invalid"),c.src=t}},cut:{default:{},get:function(){return c.cut},set:function(t){"object"!==typeof t&&console.error("cut:"+t+" is invalid"),c.cut=t}},boundStyle:{default:{},get:function(){return c.boundStyle},set:function(t){"object"!==typeof t&&console.error("boundStyle:"+t+" is invalid"),c.boundStyle=t}},onReady:{default:null,get:function(){return c.ready},set:function(t){c.ready=t}},onBeforeImageLoad:{default:null,get:function(){return c.beforeImageLoad},set:function(t){c.beforeImageLoad=t}},onImageLoad:{default:null,get:function(){return c.imageLoad},set:function(t){c.imageLoad=t}},onBeforeDraw:{default:null,get:function(){return c.beforeDraw},set:function(t){c.beforeDraw=t}}},h=a(),p=h.windowWidth;function f(){var t=this;t.attachPage=function(){var e=getCurrentPages(),n=e[e.length-1];Object.defineProperty(n,"wecropper",{get:function(){return console.warn("Instance will not be automatically bound to the page after v1.4.0\n\nPlease use a custom instance name instead\n\nExample: \nthis.mycropper = new WeCropper(options)\n\n// ...\nthis.mycropper.getCropperImage()"),t},configurable:!0})},t.createCtx=function(){var e=t.id,n=t.targetId;e?(t.ctx=t.ctx||uni.createCanvasContext(e),t.targetCtx=t.targetCtx||uni.createCanvasContext(n)):console.error("constructor: create canvas context failed, 'id' must be valuable")},t.deviceRadio=p/750}var l="undefined"!==typeof window?window:"undefined"!==typeof e?e:"undefined"!==typeof self?self:{};function g(t,e){return e={exports:{}},t(e,e.exports),e.exports}var v=g((function(t,e){e.isStr=function(t){return"string"===typeof t},e.isNum=function(t){return"number"===typeof t},e.isArr=Array.isArray,e.isUndef=function(t){return void 0===t},e.isTrue=function(t){return!0===t},e.isFalse=function(t){return!1===t},e.isFunc=function(t){return"function"===typeof t},e.isObj=e.isObject=function(t){return null!==t&&"object"===typeof t};var n=Object.prototype.toString;e.isPlainObject=function(t){return"[object Object]"===n.call(t)};var o=Object.prototype.hasOwnProperty;e.hasOwn=function(t,e){return o.call(t,e)},e.noop=function(t,e,n){},e.isValidArrayIndex=function(t){var e=parseFloat(String(t));return e>=0&&Math.floor(e)===e&&isFinite(t)}})),b=v.isFunc,y=v.isPlainObject,m=["ready","beforeImageLoad","beforeDraw","imageLoad"];function w(){var t=this;t.on=function(e,n){return m.indexOf(e)>-1?b(n)&&("ready"===e?n(t):t["on"+o(e)]=n):console.error("event: "+e+" is invalid"),t}}function x(t){return function(e){var n=[],o=arguments.length-1;while(o-- >0)n[o]=arguments[o+1];return void 0===e&&(e={}),new Promise((function(o,r){e.success=function(t){o(t)},e.fail=function(t){r
/*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */
(function(n){var o=e,r=t&&t.exports==o&&t,i="object"==typeof l&&l;i.global!==i&&i.window!==i||(n=i);var a=function(t){this.message=t};a.prototype=new Error,a.prototype.name="InvalidCharacterError";var c=function(t){throw new a(t)},u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=/[\t\n\f\r ]/g,d=function(t){t=String(t).replace(s,"");var e=t.length;e%4==0&&(t=t.replace(/==?$/,""),e=t.length),(e%4==1||/[^+a-zA-Z0-9/]/.test(t))&&c("Invalid character: the string to be decoded is not correctly encoded.");var n,o,r=0,i="",a=-1;while(++a<e)o=u.indexOf(t.charAt(a)),n=r%4?64*n+o:o,r++%4&&(i+=String.fromCharCode(255&n>>(-2*r&6)));return i},h=function(t){t=String(t),/[^\0-\xFF]/.test(t)&&c("The string to be encoded contains characters outside of the Latin1 range.");var e,n,o,r,i=t.length%3,a="",s=-1,d=t.length-i;while(++s<d)e=t.charCodeAt(s)<<16,n=t.charCodeAt(++s)<<8,o=t.charCodeAt(++s),r=e+n+o,a+=u.charAt(r>>18&63)+u.charAt(r>>12&63)+u.charAt(r>>6&63)+u.charAt(63&r);return 2==i?(e=t.charCodeAt(s)<<8,n=t.charCodeAt(++s),r=e+n,a+=u.charAt(r>>10)+u.charAt(r>>4&63)+u.charAt(r<<2&63)+"="):1==i&&(r=t.charCodeAt(s),a+=u.charAt(r>>2)+u.charAt(r<<4&63)+"=="),a},p={encode:h,decode:d,version:"0.1.0"};if(o&&!o.nodeType)if(r)r.exports=p;else for(var f in p)p.hasOwnProperty(f)&&(o[f]=p[f]);else n.base64=p})(l)}));function T(t,e){return"data:"+e+";base64,"+t}function W(t){t=t.toLowerCase().replace(/jpg/i,"jpeg");var e=t.match(/png|jpeg|bmp|gif/)[0];return"image/"+e}function M(t){var e="";if("string"===typeof t)e=t;else for(var n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return O.encode(e)}function j(t,e,n,o,r,i){uni.canvasGetImageData({canvasId:t,x:e,y:n,width:o,height:r,success:function(t){i(t,null)},fail:function(t){i(null,t)}})}function _(t){var e=t.width,n=t.height,o=e*n*3,r=o+54,i=[66,77,255&r,r>>8&255,r>>16&255,r>>24&255,0,0,0,0,54,0,0,0],a=[40,0,0,0,255&e,e>>8&255,e>>16&255,e>>24&255,255&n,n>>8&255,n>>16&255,n>>24&255,1,0,24,0,0,0,0,0,255&o,o>>8&255,o>>16&255,o>>24&255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],c=(4-3*e%4)%4,u=t.data,s="",d=e<<2,h=n,p=String.fromCharCode;do{for(var f=d*(h-1),l="",g=0;g<e;g++){var v=g<<2;l+=p(u[f+v+2])+p(u[f+v+1])+p(u[f+v])}for(var b=0;b<c;b++)l+=String.fromCharCode(0);s+=l}while(--h);var y=M(i.concat(a))+M(s);return y}function A(t,e,n,o,r,i,a){void 0===a&&(a=function(){}),void 0===i&&(i="png"),i=W(i),/bmp/.test(i)?j(t,e,n,o,r,(function(t,e){var n=_(t);b(a)&&a(T(n,"image/"+i),e)})):console.error("暂不支持生成'"+i+"'类型的base64图片")}var L={convertToImage:A,convertToBMP:function(t,e){void 0===t&&(t={});var n=t.canvasId,o=t.x,r=t.y,i=t.width,a=t.height;return void 0===e&&(e=function(){}),A(n,o,r,i,a,"bmp",e)}};function P(){var t=this,e=t.width,n=t.height,o=t.id,r=t.targetId,i=t.pixelRatio,a=t.cut,c=a.x;void 0===c&&(c=0);var u=a.y;void 0===u&&(u=0);var s=a.width;void 0===s&&(s=e);var d=a.height;void 0===d&&(d=n),t.updateCanvas=function(e){return t.croperTarget&&t.ctx.drawImage(t.croperTarget,t.imgLeft,t.imgTop,t.scaleWidth,t.scaleHeight),b(t.onBeforeDraw)&&t.onBeforeDraw(t.ctx,t),t.setBoundStyle(t.boundStyle),t.ctx.draw(!1,e),t},t.pushOrigin=t.pushOrign=function(e){return t.src=e,b(t.onBeforeImageLoad)&&t.onBeforeImageLoad(t.ctx,t),S({src:e}).then((function(e){var n=e.width/e.height,o=s/d;return t.croperTarget=e.path,n<o?(t.rectX=c,t.baseWidth=s,t.baseHeight=s/n,t.rectY=u-Math.abs((d-t.baseHeight)/2)):(t.rectY=u,t.baseWidth=d*n,t.baseHeight=d,t.rectX=c-Math.abs((s-t.baseWidth)/2)),t.imgLeft=t.rectX,t.imgTop=t.rectY,t.scaleWidth=t.baseWidth,t.scaleHeight=t.baseHeight,t.update(),new Promise((function(e){t.updateCanvas(e)}))})).then((function(){b(t.onImageLoad)&&t.onImageLoad(t.ctx,t)}))},t.removeImage=function(){return t.src="",t.croperTarget="",C(t.ctx)},t.getCropperBase64=function(t){void 0===t&&(t=function(){}),L.convertToBMP({canvasId:o,x:c,y:u,width:s,height:d},t)},t.getCropperImage=function(e,n){var a=e,h={canvasId:o,x:c,y:u,width:s,height:d},p=function(){return Promise.resolve()};return y(a)&&a.original&&(p=function(){return t.targetCtx.drawImage(t.croperTarget,t.imgLeft*i,t