vue-croppa
Advanced tools
Comparing version 0.0.25 to 0.0.26
/* | ||
* vue-croppa v0.0.25 | ||
* vue-croppa v0.0.26 | ||
* https://github.com/zhanziyang/vue-croppa | ||
@@ -63,2 +63,3 @@ * | ||
// rAF polyfill | ||
if (typeof document == 'undefined' || typeof window == 'undefined') return; | ||
var lastTime = 0; | ||
@@ -93,2 +94,21 @@ var vendors = ['webkit', 'moz']; | ||
}; | ||
}, | ||
toBlobPolyfill: function toBlobPolyfill() { | ||
if (typeof document == 'undefined' || typeof window == 'undefined' || !HTMLCanvasElement) return; | ||
var binStr, len, arr; | ||
if (!HTMLCanvasElement.prototype.toBlob) { | ||
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', { | ||
value: function value(callback, type, quality) { | ||
binStr = atob(this.toDataURL(type, quality).split(',')[1]); | ||
len = binStr.length; | ||
arr = new Uint8Array(len); | ||
for (var i = 0; i < len; i++) { | ||
arr[i] = binStr.charCodeAt(i); | ||
} | ||
callback(new Blob([arr], { type: type || 'image/png' })); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -283,2 +303,3 @@ }; | ||
u.rAFPolyfill(); | ||
u.toBlobPolyfill(); | ||
@@ -364,3 +385,6 @@ if (this.$options._parentListeners['initial-image-load'] || this.$options._parentListeners['initial-image-error']) { | ||
}, | ||
reset: this.remove, // soon to be deprecated due to misnamed | ||
reset: function reset() { | ||
console.warn('"reset()" method will be deprecated in the near future due to misnaming. Please use "remove()" instead. They have the same effect.'); | ||
_this.remove(); | ||
}, // soon to be deprecated due to misnamed | ||
remove: this.remove, | ||
@@ -460,13 +484,15 @@ chooseFile: this.chooseFile, | ||
} | ||
var fr = new FileReader(); | ||
fr.onload = function (e) { | ||
var fileData = e.target.result; | ||
var img = new Image(); | ||
img.src = fileData; | ||
img.onload = function () { | ||
_this3.img = img; | ||
_this3.imgContentInit(); | ||
if (typeof window.FileReader !== 'undefined') { | ||
var fr = new FileReader(); | ||
fr.onload = function (e) { | ||
var fileData = e.target.result; | ||
var img = new Image(); | ||
img.src = fileData; | ||
img.onload = function () { | ||
_this3.img = img; | ||
_this3.imgContentInit(); | ||
}; | ||
}; | ||
}; | ||
fr.readAsDataURL(file); | ||
fr.readAsDataURL(file); | ||
} | ||
}, | ||
@@ -483,35 +509,15 @@ fileSizeIsValid: function fileSizeIsValid(file) { | ||
var types = accept.split(','); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = types[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var type = _step.value; | ||
var t = type.trim(); | ||
if (t.charAt(0) == '.') { | ||
if (file.name.toLowerCase().split('.').pop() === t.toLowerCase().slice(1)) return true; | ||
} else if (/\/\*$/.test(t)) { | ||
var fileBaseType = file.type.replace(/\/.*$/, ''); | ||
if (fileBaseType === baseMimetype) { | ||
return true; | ||
} | ||
} else if (file.type === type) { | ||
for (var i = 0, len = types.length; i < len; i++) { | ||
var type = types[i]; | ||
var t = type.trim(); | ||
if (t.charAt(0) == '.') { | ||
if (file.name.toLowerCase().split('.').pop() === t.toLowerCase().slice(1)) return true; | ||
} else if (/\/\*$/.test(t)) { | ||
var fileBaseType = file.type.replace(/\/.*$/, ''); | ||
if (fileBaseType === baseMimetype) { | ||
return true; | ||
} | ||
} else if (file.type === type) { | ||
return true; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -576,25 +582,5 @@ | ||
var cancelEvents = ['mouseup', 'touchend', 'touchcancel', 'pointerend', 'pointercancel']; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = cancelEvents[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var e = _step2.value; | ||
document.addEventListener(e, this.handlePointerEnd); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
for (var i = 0, len = cancelEvents.length; i < len; i++) { | ||
var e = cancelEvents[i]; | ||
document.addEventListener(e, this.handlePointerEnd); | ||
} | ||
@@ -816,2 +802,6 @@ }, | ||
if (typeof Promise == 'undefined') { | ||
console.warn('No Promise support. Please add Promise polyfill if you want to use this method.'); | ||
return; | ||
} | ||
return new Promise(function (resolve, reject) { | ||
@@ -832,2 +822,3 @@ try { | ||
install: function install(Vue, options) { | ||
options = options || {}; | ||
var version = Number(Vue.version.split('.')[0]); | ||
@@ -837,3 +828,4 @@ if (version < 2) { | ||
} | ||
Vue.component('croppa', cropper); | ||
var componentName = options.componentName || 'croppa'; | ||
Vue.component(componentName, cropper); | ||
} | ||
@@ -840,0 +832,0 @@ }; |
/* | ||
* vue-croppa v0.0.25 | ||
* vue-croppa v0.0.26 | ||
* https://github.com/zhanziyang/vue-croppa | ||
@@ -8,2 +8,2 @@ * | ||
*/ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.Croppa=i()}(this,function(){"use strict";var t={onePointCoord:function(t,i){var e=i.canvas,a=i.quality,o=e.getBoundingClientRect(),n=t.clientX,r=t.clientY;return{x:(n-o.left)*a,y:(r-o.top)*a}},getPointerCoords:function(t,i){var e=void 0;return e=t.touches&&t.touches[0]?t.touches[0]:t.changedTouches&&t.changedTouches[0]?t.changedTouches[0]:t,this.onePointCoord(e,i)},getPinchDistance:function(t,i){var e=t.touches[0],a=t.touches[1],o=this.onePointCoord(e,i),n=this.onePointCoord(a,i);return Math.sqrt(Math.pow(o.x-n.x,2)+Math.pow(o.y-n.y,2))},getPinchCenterCoord:function(t,i){var e=t.touches[0],a=t.touches[1],o=this.onePointCoord(e,i),n=this.onePointCoord(a,i);return{x:(o.x+n.x)/2,y:(o.y+n.y)/2}},imageLoaded:function(t){return t.complete&&0!==t.naturalWidth},rAFPolyfill:function(){for(var t=0,i=["webkit","moz"],e=0;e<i.length&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[i[e]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[i[e]+"CancelAnimationFrame"]||window[i[e]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(i){var e=(new Date).getTime(),a=Math.max(0,16.7-(e-t)),o=window.setTimeout(function(){i(e+a)},a);return t=e+a,o}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)}),Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}}};Number.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};var i={INIT_EVENT:"init",FILE_CHOOSE_EVENT:"file-choose",FILE_SIZE_EXCEED_EVENT:"file-size-exceed",FILE_TYPE_MISMATCH_EVENT:"file-type-mismatch",IMAGE_REMOVE_EVENT:"image-remove",MOVE_EVENT:"move",ZOOM_EVENT:"zoom"},e={render:function(){var t=this,i=t.$createElement,e=t._self._c||i;return e("div",{class:"croppa-container "+(t.img?"croppa--has-target":"")+" "+(t.disabled?"croppa--disabled":"")+" "+(t.disableClickToChoose?"croppa--disabled-cc":"")+" "+(t.disableDragToMove&&t.disableScrollToZoom?"croppa--disabled-mz":"")+" "+(t.fileDraggedOver?"croppa--dropzone":""),on:{dragenter:function(i){i.stopPropagation(),i.preventDefault(),t.handleDragEnter(i)},dragleave:function(i){i.stopPropagation(),i.preventDefault(),t.handleDragLeave(i)},dragover:function(i){i.stopPropagation(),i.preventDefault(),t.handleDragOver(i)},drop:function(i){i.stopPropagation(),i.preventDefault(),t.handleDrop(i)}}},[e("input",{ref:"fileInput",attrs:{type:"file",accept:t.accept,disabled:t.disabled,hidden:""},on:{change:t.handleInputChange}}),e("div",{staticClass:"initial",staticStyle:{width:"0",height:"0",visibility:"hidden"}},[t._t("initial")],2),e("canvas",{ref:"canvas",on:{click:function(i){i.stopPropagation(),i.preventDefault(),t.handleClick(i)},touchstart:function(i){i.stopPropagation(),t.handlePointerStart(i)},mousedown:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerStart(i)},pointerstart:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerStart(i)},touchend:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},touchcancel:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},mouseup:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},pointerend:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},pointercancel:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},touchmove:function(i){i.stopPropagation(),t.handlePointerMove(i)},mousemove:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerMove(i)},pointermove:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerMove(i)},DOMMouseScroll:function(i){i.stopPropagation(),t.handleWheel(i)},wheel:function(i){i.stopPropagation(),t.handleWheel(i)},mousewheel:function(i){i.stopPropagation(),t.handleWheel(i)}}}),t.showRemoveButton&&t.img?e("svg",{staticClass:"icon icon-remove",style:"top: -"+t.height/40+"px; right: -"+t.width/40+"px",attrs:{viewBox:"0 0 1024 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",width:t.removeButtonSize||t.width/10,height:t.removeButtonSize||t.width/10},on:{click:t.remove}},[e("path",{attrs:{d:"M511.921231 0C229.179077 0 0 229.257846 0 512 0 794.702769 229.179077 1024 511.921231 1024 794.781538 1024 1024 794.702769 1024 512 1024 229.257846 794.781538 0 511.921231 0ZM732.041846 650.633846 650.515692 732.081231C650.515692 732.081231 521.491692 593.683692 511.881846 593.683692 502.429538 593.683692 373.366154 732.081231 373.366154 732.081231L291.761231 650.633846C291.761231 650.633846 430.316308 523.500308 430.316308 512.196923 430.316308 500.696615 291.761231 373.523692 291.761231 373.523692L373.366154 291.918769C373.366154 291.918769 503.453538 430.395077 511.881846 430.395077 520.349538 430.395077 650.515692 291.918769 650.515692 291.918769L732.041846 373.523692C732.041846 373.523692 593.447385 502.547692 593.447385 512.196923 593.447385 521.412923 732.041846 650.633846 732.041846 650.633846Z",fill:t.removeButtonColor}})]):t._e()])},staticRenderFns:[],model:{prop:"value",event:"init"},props:{value:Object,width:{type:Number,default:200,validator:function(t){return t>0}},height:{type:Number,default:200,validator:function(t){return t>0}},placeholder:{type:String,default:"Choose an image"},placeholderColor:{default:"#606060"},placeholderFontSize:{type:Number,default:0,validator:function(t){return t>=0}},canvasColor:{default:"#e6e6e6"},quality:{type:Number,default:2,validator:function(t){return Number.isInteger(t)&&t>0}},zoomSpeed:{default:3,type:Number,validator:function(t){return t>0}},accept:{type:String,default:"image/*"},fileSizeLimit:{type:Number,default:0,validator:function(t){return t>=0}},disabled:Boolean,disableDragAndDrop:Boolean,disableClickToChoose:Boolean,disableDragToMove:Boolean,disableScrollToZoom:Boolean,disablePinchToZoom:Boolean,reverseZoomingGesture:Boolean,reverseScrollToZoom:Boolean,preventWhiteSpace:Boolean,showRemoveButton:{type:Boolean,default:!0},removeButtonColor:{type:String,default:"red"},removeButtonSize:{type:Number}},data:function(){return{instance:null,canvas:null,ctx:null,img:null,dragging:!1,lastMovingCoord:null,imgData:{},dataUrl:"",fileDraggedOver:!1,tabStart:0,pinching:!1,pinchDistance:0,supportTouch:!1,pointerMoved:!1,pointerStartCoord:null}},computed:{realWidth:function(){return this.width*this.quality},realHeight:function(){return this.height*this.quality},realPlaceholderFontSize:function(){return this.placeholderFontSize*this.quality}},mounted:function(){this.init(),t.rAFPolyfill(),(this.$options._parentListeners["initial-image-load"]||this.$options._parentListeners["initial-image-error"])&&console.warn("initial-image-load and initial-image-error events are already deprecated. Please bind them directly on the <img> tag (the slot)."),this.supportDetection().basic||console.warn("Your browser does not support vue-croppa functionality.")},watch:{value:function(t){this.instance=t},realWidth:"init",realHeight:"init",canvasColor:"init",placeholder:"init",placeholderColor:"init",realPlaceholderFontSize:"init",preventWhiteSpace:"imgContentInit"},methods:{init:function(){var t=this;this.canvas=this.$refs.canvas,this.canvas.width=this.realWidth,this.canvas.height=this.realHeight,this.canvas.style.width=this.width+"px",this.canvas.style.height=this.height+"px",this.canvas.style.backgroundColor=this.canvasColor&&"default"!=this.canvasColor?"string"==typeof this.canvasColor?this.canvasColor:"":"#e6e6e6",this.ctx=this.canvas.getContext("2d"),this.$slots.initial&&this.$slots.initial[0]?this.setInitial():this.remove(),this.$emit(i.INIT_EVENT,{getCanvas:function(){return t.canvas},getContext:function(){return t.ctx},getChosenFile:function(){return t.$refs.fileInput.files[0]},getActualImageSize:function(){return{width:t.realWidth,height:t.realHeight}},moveUpwards:function(i){t.move({x:0,y:-i})},moveDownwards:function(i){t.move({x:0,y:i})},moveLeftwards:function(i){t.move({x:-i,y:0})},moveRightwards:function(i){t.move({x:i,y:0})},zoomIn:function(){t.zoom(!0)},zoomOut:function(){t.zoom(!1)},refresh:function(){t.$nextTick(t.init)},hasImage:function(){return!!t.img},reset:this.remove,remove:this.remove,chooseFile:this.chooseFile,generateDataUrl:this.generateDataUrl,generateBlob:this.generateBlob,promisedBlob:this.promisedBlob,supportDetection:this.supportDetection})},supportDetection:function(){var t=document.createElement("div");return{basic:window.requestAnimationFrame&&window.File&&window.FileReader&&window.FileList&&window.Blob,dnd:"ondragstart"in t&&"ondrop"in t}},remove:function(){var t=this.ctx;this.paintBackground(),t.textBaseline="middle",t.textAlign="center";var e=this.realWidth*(2/3)/this.placeholder.length,a=this.realPlaceholderFontSize&&0!=this.realPlaceholderFontSize?this.realPlaceholderFontSize:e;t.font=a+"px sans-serif",t.fillStyle=this.placeholderColor&&"default"!=this.placeholderColor?this.placeholderColor:"#606060",t.fillText(this.placeholder,this.realWidth/2,this.realHeight/2);var o=null!=this.img;this.img=null,this.$refs.fileInput.value="",this.imgData={},o&&this.$emit(i.IMAGE_REMOVE_EVENT)},setInitial:function(){var i=this,e=this.$slots.initial[0],a=e.tag,o=e.elm;"img"===a&&o&&o.src?t.imageLoaded(o)?(this.img=o,this.imgContentInit()):(o.onload=function(){i.img=o,i.imgContentInit()},o.onerror=function(){i.remove()}):this.remove()},chooseFile:function(){this.$refs.fileInput.click()},handleClick:function(){this.img||this.disableClickToChoose||this.disabled||this.supportTouch||this.chooseFile()},handleInputChange:function(){var t=this.$refs.fileInput;if(t.files.length){var i=t.files[0];this.onNewFileIn(i)}},onNewFileIn:function(t){var e=this;if(this.$emit(i.FILE_CHOOSE_EVENT,t),!this.fileSizeIsValid(t))throw this.$emit(i.FILE_SIZE_EXCEED_EVENT,t),new Error("File size exceeds limit which is "+this.fileSizeLimit+" bytes.");if(!this.fileTypeIsValid(t)){this.$emit(i.FILE_TYPE_MISMATCH_EVENT,t);var a=t.type||t.name.toLowerCase().split(".").pop();throw new Error("File type ("+a+") does not match what you specified ("+this.accept+").")}var o=new FileReader;o.onload=function(t){var i=t.target.result,a=new Image;a.src=i,a.onload=function(){e.img=a,e.imgContentInit()}},o.readAsDataURL(t)},fileSizeIsValid:function(t){return!!t&&(!this.fileSizeLimit||0==this.fileSizeLimit||t.size<this.fileSizeLimit)},fileTypeIsValid:function(t){var i=this.accept||"image/*",e=i.replace(/\/.*$/,""),a=i.split(","),o=!0,n=!1,r=void 0;try{for(var s,h=a[Symbol.iterator]();!(o=(s=h.next()).done);o=!0){var l=s.value,d=l.trim();if("."==d.charAt(0)){if(t.name.toLowerCase().split(".").pop()===d.toLowerCase().slice(1))return!0}else if(/\/\*$/.test(d)){if(t.type.replace(/\/.*$/,"")===e)return!0}else if(t.type===l)return!0}}catch(t){n=!0,r=t}finally{try{!o&&h.return&&h.return()}finally{if(n)throw r}}return!1},imgContentInit:function(){this.imgData.startX=0,this.imgData.startY=0;var t=this.img.naturalWidth,i=this.img.naturalHeight;if(i/t<this.realHeight/this.realWidth){var e=i/this.realHeight;this.imgData.width=t/e,this.imgData.startX=-(this.imgData.width-this.realWidth)/2,this.imgData.height=this.realHeight}else{var a=t/this.realWidth;this.imgData.height=i/a,this.imgData.startY=-(this.imgData.height-this.realHeight)/2,this.imgData.width=this.realWidth}this.draw()},handlePointerStart:function(i){this.supportTouch=!0,this.pointerMoved=!1;var e=t.getPointerCoords(i,this);if(this.pointerStartCoord=e,!this.disabled)if(this.img||this.disableClickToChoose){if(!(i.which&&i.which>1)){if(!i.touches||1===i.touches.length){this.dragging=!0,this.pinching=!1;var a=t.getPointerCoords(i,this);this.lastMovingCoord=a}i.touches&&2===i.touches.length&&!this.disablePinchToZoom&&(this.dragging=!1,this.pinching=!0,this.pinchDistance=t.getPinchDistance(i,this));var o=["mouseup","touchend","touchcancel","pointerend","pointercancel"],n=!0,r=!1,s=void 0;try{for(var h,l=o[Symbol.iterator]();!(n=(h=l.next()).done);n=!0){var d=h.value;document.addEventListener(d,this.handlePointerEnd)}}catch(t){r=!0,s=t}finally{try{!n&&l.return&&l.return()}finally{if(r)throw s}}}}else this.tabStart=(new Date).valueOf()},handlePointerEnd:function(i){var e=0;if(this.pointerStartCoord){var a=t.getPointerCoords(i,this);e=Math.sqrt(Math.pow(a.x-this.pointerStartCoord.x,2)+Math.pow(a.y-this.pointerStartCoord.y,2))||0}if(!this.disabled){if(!this.img&&!this.disableClickToChoose){var o=(new Date).valueOf();return e<100&&o-this.tabStart<500&&this.supportTouch&&this.chooseFile(),void(this.tabStart=0)}this.dragging=!1,this.pinching=!1,this.pinchDistance=0,this.lastMovingCoord=null,this.pointerMoved=!1,this.pointerStartCoord=null}},handlePointerMove:function(i){if(this.pointerMoved=!0,!this.disabled&&!this.disableDragToMove&&this.img){if(i.preventDefault(),!i.touches||1===i.touches.length){if(!this.dragging)return;var e=t.getPointerCoords(i,this);this.lastMovingCoord&&this.move({x:e.x-this.lastMovingCoord.x,y:e.y-this.lastMovingCoord.y}),this.lastMovingCoord=e}if(i.touches&&2===i.touches.length&&!this.disablePinchToZoom){if(!this.pinching)return;var a=t.getPinchDistance(i,this),o=a-this.pinchDistance;this.zoom(o>0,null,2),this.pinchDistance=a}}},handleWheel:function(i){if(!this.disabled&&!this.disableScrollToZoom&&this.img){i.preventDefault();var e=t.getPointerCoords(i,this);i.wheelDelta<0||i.deltaY>0||i.detail>0?this.zoom(this.reverseZoomingGesture||this.reverseScrollToZoom,e):(i.wheelDelta>0||i.deltaY<0||i.detail<0)&&this.zoom(!this.reverseZoomingGesture&&!this.reverseScrollToZoom,e)}},handleDragEnter:function(t){this.disabled||this.disableDragAndDrop||this.img||(this.fileDraggedOver=!0)},handleDragLeave:function(t){this.fileDraggedOver&&(this.fileDraggedOver=!1)},handleDragOver:function(t){},handleDrop:function(t){if(this.fileDraggedOver){this.fileDraggedOver=!1;var i=void 0,e=t.dataTransfer;if(e){if(e.items)for(var a=0,o=e.items.length;a<o;a++){var n=e.items[a];if("file"==n.kind){i=n.getAsFile();break}}else i=e.files[0];i&&this.onNewFileIn(i)}}},move:function(t){if(t){var e=this.imgData.startX,a=this.imgData.startY;this.imgData.startX+=t.x,this.imgData.startY+=t.y,this.preventWhiteSpace&&this.preventMovingToWhiteSpace(),this.imgData.startX===e&&this.imgData.startY===a||(this.$emit(i.MOVE_EVENT),this.draw())}},preventMovingToWhiteSpace:function(){this.imgData.startX>0&&(this.imgData.startX=0),this.imgData.startY>0&&(this.imgData.startY=0),this.realWidth-this.imgData.startX>this.imgData.width&&(this.imgData.startX=-(this.imgData.width-this.realWidth)),this.realHeight-this.imgData.startY>this.imgData.height&&(this.imgData.startY=-(this.imgData.height-this.realHeight))},zoom:function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;e=e||{x:this.imgData.startX+this.imgData.width/2,y:this.imgData.startY+this.imgData.height/2};var o=this.zoomSpeed*a,n=1e-5*this.realWidth*o,r=1;t?r=1+n:this.imgData.width>10&&(r=1-n);var s=this.imgData.width,h=this.imgData.height;if(this.imgData.width=this.imgData.width*r,this.imgData.height=this.imgData.height*r,this.preventWhiteSpace){if(this.imgData.width<this.realWidth){var l=this.realWidth/this.imgData.width;this.imgData.width=this.realWidth,this.imgData.height=this.imgData.height*l}if(this.imgData.height<this.realHeight){var d=this.realHeight/this.imgData.height;this.imgData.height=this.realHeight,this.imgData.width=this.imgData.width*d}}if(s.toFixed(2)!==this.imgData.width.toFixed(2)||h.toFixed(2)!==this.imgData.height.toFixed(2)){var c=(r-1)*(e.x-this.imgData.startX),u=(r-1)*(e.y-this.imgData.startY);this.imgData.startX=this.imgData.startX-c,this.imgData.startY=this.imgData.startY-u,this.preventWhiteSpace&&this.preventMovingToWhiteSpace(),this.$emit(i.ZOOM_EVENT),this.draw()}},paintBackground:function(){var t=this.canvasColor&&"default"!=this.canvasColor?this.canvasColor:"#e6e6e6";this.ctx.fillStyle=t,this.ctx.fillRect(0,0,this.realWidth,this.realHeight)},draw:function(){var t=this,i=this.ctx;if(this.img){var e=this.imgData,a=e.startX,o=e.startY,n=e.width,r=e.height;window.requestAnimationFrame?requestAnimationFrame(function(){t.paintBackground(),i.drawImage(t.img,a,o,n,r)}):(this.paintBackground(),i.drawImage(this.img,a,o,n,r))}},generateDataUrl:function(t){return this.img?this.canvas.toDataURL(t):""},generateBlob:function(t,i,e){if(!this.img)return null;this.canvas.toBlob(t,i,e)},promisedBlob:function(){for(var t=this,i=arguments.length,e=Array(i),a=0;a<i;a++)e[a]=arguments[a];return new Promise(function(i,a){try{t.generateBlob(function(t){i(t)},e)}catch(t){a(t)}})}}};return{install:function(t,i){var a=Number(t.version.split(".")[0]);if(a<2)throw new Error("vue-croppa supports vue version 2.0 and above. You are using Vue@"+a+". Please upgrade to the latest version of Vue.");t.component("croppa",e)}}}); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.Croppa=i()}(this,function(){"use strict";var t={onePointCoord:function(t,i){var e=i.canvas,a=i.quality,o=e.getBoundingClientRect(),n=t.clientX,r=t.clientY;return{x:(n-o.left)*a,y:(r-o.top)*a}},getPointerCoords:function(t,i){var e=void 0;return e=t.touches&&t.touches[0]?t.touches[0]:t.changedTouches&&t.changedTouches[0]?t.changedTouches[0]:t,this.onePointCoord(e,i)},getPinchDistance:function(t,i){var e=t.touches[0],a=t.touches[1],o=this.onePointCoord(e,i),n=this.onePointCoord(a,i);return Math.sqrt(Math.pow(o.x-n.x,2)+Math.pow(o.y-n.y,2))},getPinchCenterCoord:function(t,i){var e=t.touches[0],a=t.touches[1],o=this.onePointCoord(e,i),n=this.onePointCoord(a,i);return{x:(o.x+n.x)/2,y:(o.y+n.y)/2}},imageLoaded:function(t){return t.complete&&0!==t.naturalWidth},rAFPolyfill:function(){if("undefined"!=typeof document&&"undefined"!=typeof window){for(var t=0,i=["webkit","moz"],e=0;e<i.length&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[i[e]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[i[e]+"CancelAnimationFrame"]||window[i[e]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(i){var e=(new Date).getTime(),a=Math.max(0,16.7-(e-t)),o=window.setTimeout(function(){i(e+a)},a);return t=e+a,o}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)}),Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}}},toBlobPolyfill:function(){if("undefined"!=typeof document&&"undefined"!=typeof window&&HTMLCanvasElement){var t,i,e;HTMLCanvasElement.prototype.toBlob||Object.defineProperty(HTMLCanvasElement.prototype,"toBlob",{value:function(a,o,n){t=atob(this.toDataURL(o,n).split(",")[1]),i=t.length,e=new Uint8Array(i);for(var r=0;r<i;r++)e[r]=t.charCodeAt(r);a(new Blob([e],{type:o||"image/png"}))}})}}};Number.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};var i={INIT_EVENT:"init",FILE_CHOOSE_EVENT:"file-choose",FILE_SIZE_EXCEED_EVENT:"file-size-exceed",FILE_TYPE_MISMATCH_EVENT:"file-type-mismatch",IMAGE_REMOVE_EVENT:"image-remove",MOVE_EVENT:"move",ZOOM_EVENT:"zoom"},e={render:function(){var t=this,i=t.$createElement,e=t._self._c||i;return e("div",{class:"croppa-container "+(t.img?"croppa--has-target":"")+" "+(t.disabled?"croppa--disabled":"")+" "+(t.disableClickToChoose?"croppa--disabled-cc":"")+" "+(t.disableDragToMove&&t.disableScrollToZoom?"croppa--disabled-mz":"")+" "+(t.fileDraggedOver?"croppa--dropzone":""),on:{dragenter:function(i){i.stopPropagation(),i.preventDefault(),t.handleDragEnter(i)},dragleave:function(i){i.stopPropagation(),i.preventDefault(),t.handleDragLeave(i)},dragover:function(i){i.stopPropagation(),i.preventDefault(),t.handleDragOver(i)},drop:function(i){i.stopPropagation(),i.preventDefault(),t.handleDrop(i)}}},[e("input",{ref:"fileInput",attrs:{type:"file",accept:t.accept,disabled:t.disabled,hidden:""},on:{change:t.handleInputChange}}),e("div",{staticClass:"initial",staticStyle:{width:"0",height:"0",visibility:"hidden"}},[t._t("initial")],2),e("canvas",{ref:"canvas",on:{click:function(i){i.stopPropagation(),i.preventDefault(),t.handleClick(i)},touchstart:function(i){i.stopPropagation(),t.handlePointerStart(i)},mousedown:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerStart(i)},pointerstart:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerStart(i)},touchend:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},touchcancel:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},mouseup:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},pointerend:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},pointercancel:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerEnd(i)},touchmove:function(i){i.stopPropagation(),t.handlePointerMove(i)},mousemove:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerMove(i)},pointermove:function(i){i.stopPropagation(),i.preventDefault(),t.handlePointerMove(i)},DOMMouseScroll:function(i){i.stopPropagation(),t.handleWheel(i)},wheel:function(i){i.stopPropagation(),t.handleWheel(i)},mousewheel:function(i){i.stopPropagation(),t.handleWheel(i)}}}),t.showRemoveButton&&t.img?e("svg",{staticClass:"icon icon-remove",style:"top: -"+t.height/40+"px; right: -"+t.width/40+"px",attrs:{viewBox:"0 0 1024 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",width:t.removeButtonSize||t.width/10,height:t.removeButtonSize||t.width/10},on:{click:t.remove}},[e("path",{attrs:{d:"M511.921231 0C229.179077 0 0 229.257846 0 512 0 794.702769 229.179077 1024 511.921231 1024 794.781538 1024 1024 794.702769 1024 512 1024 229.257846 794.781538 0 511.921231 0ZM732.041846 650.633846 650.515692 732.081231C650.515692 732.081231 521.491692 593.683692 511.881846 593.683692 502.429538 593.683692 373.366154 732.081231 373.366154 732.081231L291.761231 650.633846C291.761231 650.633846 430.316308 523.500308 430.316308 512.196923 430.316308 500.696615 291.761231 373.523692 291.761231 373.523692L373.366154 291.918769C373.366154 291.918769 503.453538 430.395077 511.881846 430.395077 520.349538 430.395077 650.515692 291.918769 650.515692 291.918769L732.041846 373.523692C732.041846 373.523692 593.447385 502.547692 593.447385 512.196923 593.447385 521.412923 732.041846 650.633846 732.041846 650.633846Z",fill:t.removeButtonColor}})]):t._e()])},staticRenderFns:[],model:{prop:"value",event:"init"},props:{value:Object,width:{type:Number,default:200,validator:function(t){return t>0}},height:{type:Number,default:200,validator:function(t){return t>0}},placeholder:{type:String,default:"Choose an image"},placeholderColor:{default:"#606060"},placeholderFontSize:{type:Number,default:0,validator:function(t){return t>=0}},canvasColor:{default:"#e6e6e6"},quality:{type:Number,default:2,validator:function(t){return Number.isInteger(t)&&t>0}},zoomSpeed:{default:3,type:Number,validator:function(t){return t>0}},accept:{type:String,default:"image/*"},fileSizeLimit:{type:Number,default:0,validator:function(t){return t>=0}},disabled:Boolean,disableDragAndDrop:Boolean,disableClickToChoose:Boolean,disableDragToMove:Boolean,disableScrollToZoom:Boolean,disablePinchToZoom:Boolean,reverseZoomingGesture:Boolean,reverseScrollToZoom:Boolean,preventWhiteSpace:Boolean,showRemoveButton:{type:Boolean,default:!0},removeButtonColor:{type:String,default:"red"},removeButtonSize:{type:Number}},data:function(){return{instance:null,canvas:null,ctx:null,img:null,dragging:!1,lastMovingCoord:null,imgData:{},dataUrl:"",fileDraggedOver:!1,tabStart:0,pinching:!1,pinchDistance:0,supportTouch:!1,pointerMoved:!1,pointerStartCoord:null}},computed:{realWidth:function(){return this.width*this.quality},realHeight:function(){return this.height*this.quality},realPlaceholderFontSize:function(){return this.placeholderFontSize*this.quality}},mounted:function(){this.init(),t.rAFPolyfill(),t.toBlobPolyfill(),(this.$options._parentListeners["initial-image-load"]||this.$options._parentListeners["initial-image-error"])&&console.warn("initial-image-load and initial-image-error events are already deprecated. Please bind them directly on the <img> tag (the slot)."),this.supportDetection().basic||console.warn("Your browser does not support vue-croppa functionality.")},watch:{value:function(t){this.instance=t},realWidth:"init",realHeight:"init",canvasColor:"init",placeholder:"init",placeholderColor:"init",realPlaceholderFontSize:"init",preventWhiteSpace:"imgContentInit"},methods:{init:function(){var t=this;this.canvas=this.$refs.canvas,this.canvas.width=this.realWidth,this.canvas.height=this.realHeight,this.canvas.style.width=this.width+"px",this.canvas.style.height=this.height+"px",this.canvas.style.backgroundColor=this.canvasColor&&"default"!=this.canvasColor?"string"==typeof this.canvasColor?this.canvasColor:"":"#e6e6e6",this.ctx=this.canvas.getContext("2d"),this.$slots.initial&&this.$slots.initial[0]?this.setInitial():this.remove(),this.$emit(i.INIT_EVENT,{getCanvas:function(){return t.canvas},getContext:function(){return t.ctx},getChosenFile:function(){return t.$refs.fileInput.files[0]},getActualImageSize:function(){return{width:t.realWidth,height:t.realHeight}},moveUpwards:function(i){t.move({x:0,y:-i})},moveDownwards:function(i){t.move({x:0,y:i})},moveLeftwards:function(i){t.move({x:-i,y:0})},moveRightwards:function(i){t.move({x:i,y:0})},zoomIn:function(){t.zoom(!0)},zoomOut:function(){t.zoom(!1)},refresh:function(){t.$nextTick(t.init)},hasImage:function(){return!!t.img},reset:function(){console.warn('"reset()" method will be deprecated in the near future due to misnaming. Please use "remove()" instead. They have the same effect.'),t.remove()},remove:this.remove,chooseFile:this.chooseFile,generateDataUrl:this.generateDataUrl,generateBlob:this.generateBlob,promisedBlob:this.promisedBlob,supportDetection:this.supportDetection})},supportDetection:function(){var t=document.createElement("div");return{basic:window.requestAnimationFrame&&window.File&&window.FileReader&&window.FileList&&window.Blob,dnd:"ondragstart"in t&&"ondrop"in t}},remove:function(){var t=this.ctx;this.paintBackground(),t.textBaseline="middle",t.textAlign="center";var e=this.realWidth*(2/3)/this.placeholder.length,a=this.realPlaceholderFontSize&&0!=this.realPlaceholderFontSize?this.realPlaceholderFontSize:e;t.font=a+"px sans-serif",t.fillStyle=this.placeholderColor&&"default"!=this.placeholderColor?this.placeholderColor:"#606060",t.fillText(this.placeholder,this.realWidth/2,this.realHeight/2);var o=null!=this.img;this.img=null,this.$refs.fileInput.value="",this.imgData={},o&&this.$emit(i.IMAGE_REMOVE_EVENT)},setInitial:function(){var i=this,e=this.$slots.initial[0],a=e.tag,o=e.elm;"img"===a&&o&&o.src?t.imageLoaded(o)?(this.img=o,this.imgContentInit()):(o.onload=function(){i.img=o,i.imgContentInit()},o.onerror=function(){i.remove()}):this.remove()},chooseFile:function(){this.$refs.fileInput.click()},handleClick:function(){this.img||this.disableClickToChoose||this.disabled||this.supportTouch||this.chooseFile()},handleInputChange:function(){var t=this.$refs.fileInput;if(t.files.length){var i=t.files[0];this.onNewFileIn(i)}},onNewFileIn:function(t){var e=this;if(this.$emit(i.FILE_CHOOSE_EVENT,t),!this.fileSizeIsValid(t))throw this.$emit(i.FILE_SIZE_EXCEED_EVENT,t),new Error("File size exceeds limit which is "+this.fileSizeLimit+" bytes.");if(!this.fileTypeIsValid(t)){this.$emit(i.FILE_TYPE_MISMATCH_EVENT,t);var a=t.type||t.name.toLowerCase().split(".").pop();throw new Error("File type ("+a+") does not match what you specified ("+this.accept+").")}if(void 0!==window.FileReader){var o=new FileReader;o.onload=function(t){var i=t.target.result,a=new Image;a.src=i,a.onload=function(){e.img=a,e.imgContentInit()}},o.readAsDataURL(t)}},fileSizeIsValid:function(t){return!!t&&(!this.fileSizeLimit||0==this.fileSizeLimit||t.size<this.fileSizeLimit)},fileTypeIsValid:function(t){for(var i=this.accept||"image/*",e=i.replace(/\/.*$/,""),a=i.split(","),o=0,n=a.length;o<n;o++){var r=a[o],s=r.trim();if("."==s.charAt(0)){if(t.name.toLowerCase().split(".").pop()===s.toLowerCase().slice(1))return!0}else if(/\/\*$/.test(s)){if(t.type.replace(/\/.*$/,"")===e)return!0}else if(t.type===r)return!0}return!1},imgContentInit:function(){this.imgData.startX=0,this.imgData.startY=0;var t=this.img.naturalWidth,i=this.img.naturalHeight;if(i/t<this.realHeight/this.realWidth){var e=i/this.realHeight;this.imgData.width=t/e,this.imgData.startX=-(this.imgData.width-this.realWidth)/2,this.imgData.height=this.realHeight}else{var a=t/this.realWidth;this.imgData.height=i/a,this.imgData.startY=-(this.imgData.height-this.realHeight)/2,this.imgData.width=this.realWidth}this.draw()},handlePointerStart:function(i){this.supportTouch=!0,this.pointerMoved=!1;var e=t.getPointerCoords(i,this);if(this.pointerStartCoord=e,!this.disabled)if(this.img||this.disableClickToChoose){if(!(i.which&&i.which>1)){if(!i.touches||1===i.touches.length){this.dragging=!0,this.pinching=!1;var a=t.getPointerCoords(i,this);this.lastMovingCoord=a}i.touches&&2===i.touches.length&&!this.disablePinchToZoom&&(this.dragging=!1,this.pinching=!0,this.pinchDistance=t.getPinchDistance(i,this));for(var o=["mouseup","touchend","touchcancel","pointerend","pointercancel"],n=0,r=o.length;n<r;n++){var s=o[n];document.addEventListener(s,this.handlePointerEnd)}}}else this.tabStart=(new Date).valueOf()},handlePointerEnd:function(i){var e=0;if(this.pointerStartCoord){var a=t.getPointerCoords(i,this);e=Math.sqrt(Math.pow(a.x-this.pointerStartCoord.x,2)+Math.pow(a.y-this.pointerStartCoord.y,2))||0}if(!this.disabled){if(!this.img&&!this.disableClickToChoose){var o=(new Date).valueOf();return e<100&&o-this.tabStart<500&&this.supportTouch&&this.chooseFile(),void(this.tabStart=0)}this.dragging=!1,this.pinching=!1,this.pinchDistance=0,this.lastMovingCoord=null,this.pointerMoved=!1,this.pointerStartCoord=null}},handlePointerMove:function(i){if(this.pointerMoved=!0,!this.disabled&&!this.disableDragToMove&&this.img){if(i.preventDefault(),!i.touches||1===i.touches.length){if(!this.dragging)return;var e=t.getPointerCoords(i,this);this.lastMovingCoord&&this.move({x:e.x-this.lastMovingCoord.x,y:e.y-this.lastMovingCoord.y}),this.lastMovingCoord=e}if(i.touches&&2===i.touches.length&&!this.disablePinchToZoom){if(!this.pinching)return;var a=t.getPinchDistance(i,this),o=a-this.pinchDistance;this.zoom(o>0,null,2),this.pinchDistance=a}}},handleWheel:function(i){if(!this.disabled&&!this.disableScrollToZoom&&this.img){i.preventDefault();var e=t.getPointerCoords(i,this);i.wheelDelta<0||i.deltaY>0||i.detail>0?this.zoom(this.reverseZoomingGesture||this.reverseScrollToZoom,e):(i.wheelDelta>0||i.deltaY<0||i.detail<0)&&this.zoom(!this.reverseZoomingGesture&&!this.reverseScrollToZoom,e)}},handleDragEnter:function(t){this.disabled||this.disableDragAndDrop||this.img||(this.fileDraggedOver=!0)},handleDragLeave:function(t){this.fileDraggedOver&&(this.fileDraggedOver=!1)},handleDragOver:function(t){},handleDrop:function(t){if(this.fileDraggedOver){this.fileDraggedOver=!1;var i=void 0,e=t.dataTransfer;if(e){if(e.items)for(var a=0,o=e.items.length;a<o;a++){var n=e.items[a];if("file"==n.kind){i=n.getAsFile();break}}else i=e.files[0];i&&this.onNewFileIn(i)}}},move:function(t){if(t){var e=this.imgData.startX,a=this.imgData.startY;this.imgData.startX+=t.x,this.imgData.startY+=t.y,this.preventWhiteSpace&&this.preventMovingToWhiteSpace(),this.imgData.startX===e&&this.imgData.startY===a||(this.$emit(i.MOVE_EVENT),this.draw())}},preventMovingToWhiteSpace:function(){this.imgData.startX>0&&(this.imgData.startX=0),this.imgData.startY>0&&(this.imgData.startY=0),this.realWidth-this.imgData.startX>this.imgData.width&&(this.imgData.startX=-(this.imgData.width-this.realWidth)),this.realHeight-this.imgData.startY>this.imgData.height&&(this.imgData.startY=-(this.imgData.height-this.realHeight))},zoom:function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;e=e||{x:this.imgData.startX+this.imgData.width/2,y:this.imgData.startY+this.imgData.height/2};var o=this.zoomSpeed*a,n=1e-5*this.realWidth*o,r=1;t?r=1+n:this.imgData.width>10&&(r=1-n);var s=this.imgData.width,h=this.imgData.height;if(this.imgData.width=this.imgData.width*r,this.imgData.height=this.imgData.height*r,this.preventWhiteSpace){if(this.imgData.width<this.realWidth){var l=this.realWidth/this.imgData.width;this.imgData.width=this.realWidth,this.imgData.height=this.imgData.height*l}if(this.imgData.height<this.realHeight){var d=this.realHeight/this.imgData.height;this.imgData.height=this.realHeight,this.imgData.width=this.imgData.width*d}}if(s.toFixed(2)!==this.imgData.width.toFixed(2)||h.toFixed(2)!==this.imgData.height.toFixed(2)){var c=(r-1)*(e.x-this.imgData.startX),u=(r-1)*(e.y-this.imgData.startY);this.imgData.startX=this.imgData.startX-c,this.imgData.startY=this.imgData.startY-u,this.preventWhiteSpace&&this.preventMovingToWhiteSpace(),this.$emit(i.ZOOM_EVENT),this.draw()}},paintBackground:function(){var t=this.canvasColor&&"default"!=this.canvasColor?this.canvasColor:"#e6e6e6";this.ctx.fillStyle=t,this.ctx.fillRect(0,0,this.realWidth,this.realHeight)},draw:function(){var t=this,i=this.ctx;if(this.img){var e=this.imgData,a=e.startX,o=e.startY,n=e.width,r=e.height;window.requestAnimationFrame?requestAnimationFrame(function(){t.paintBackground(),i.drawImage(t.img,a,o,n,r)}):(this.paintBackground(),i.drawImage(this.img,a,o,n,r))}},generateDataUrl:function(t){return this.img?this.canvas.toDataURL(t):""},generateBlob:function(t,i,e){if(!this.img)return null;this.canvas.toBlob(t,i,e)},promisedBlob:function(){for(var t=this,i=arguments.length,e=Array(i),a=0;a<i;a++)e[a]=arguments[a];if("undefined"!=typeof Promise)return new Promise(function(i,a){try{t.generateBlob(function(t){i(t)},e)}catch(t){a(t)}});console.warn("No Promise support. Please add Promise polyfill if you want to use this method.")}}};return{install:function(t,i){i=i||{};var a=Number(t.version.split(".")[0]);if(a<2)throw new Error("vue-croppa supports vue version 2.0 and above. You are using Vue@"+a+". Please upgrade to the latest version of Vue.");var o=i.componentName||"croppa";t.component(o,e)}}}); |
{ | ||
"name": "vue-croppa", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"description": "A simple straightforward customizable lightweight mobile-friendly image cropper for Vue 2.0.", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-croppa.js", |
@@ -358,4 +358,8 @@ # vue-croppa | ||
- [x] Add a method `hasImage()` to represent whether currently there is a image. | ||
- [ ] SSR compatibility. | ||
- [x] SSR compatibility. | ||
- [ ] Make container optionally resizable. | ||
- [ ] Add a showcase with different customization use cases. | ||
- [ ] Make default position customizable. | ||
- [x] Deprecation warning of `reset()` method. | ||
- [ ] Ignore non-file dragging. | ||
- [ ] Change `accept` default value. | ||
- [x] Replace `for of` with tranditional `for` loop for better compatibility. |
@@ -5,2 +5,3 @@ import cropper from './cropper.vue' | ||
install: function (Vue, options) { | ||
options = options || {} | ||
let version = Number(Vue.version.split('.')[0]) | ||
@@ -10,3 +11,4 @@ if (version < 2) { | ||
} | ||
Vue.component('croppa', cropper) | ||
let componentName = options.componentName || 'croppa' | ||
Vue.component(componentName, cropper) | ||
} | ||
@@ -13,0 +15,0 @@ } |
@@ -52,2 +52,3 @@ export default { | ||
// rAF polyfill | ||
if (typeof document == 'undefined' || typeof window == 'undefined') return | ||
var lastTime = 0 | ||
@@ -82,3 +83,23 @@ var vendors = ['webkit', 'moz'] | ||
} | ||
}, | ||
toBlobPolyfill() { | ||
if (typeof document == 'undefined' || typeof window == 'undefined' || !HTMLCanvasElement) return | ||
var binStr, len, arr | ||
if (!HTMLCanvasElement.prototype.toBlob) { | ||
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', { | ||
value: function (callback, type, quality) { | ||
binStr = atob(this.toDataURL(type, quality).split(',')[1]) | ||
len = binStr.length | ||
arr = new Uint8Array(len) | ||
for (var i = 0; i < len; i++) { | ||
arr[i] = binStr.charCodeAt(i) | ||
} | ||
callback(new Blob([arr], { type: type || 'image/png' })) | ||
} | ||
}) | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
268601
5810
365