Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-croppa

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-croppa - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

3

dist/vue-croppa.js
/*
* vue-croppa v0.1.1
* vue-croppa v0.1.3
* https://github.com/zhanziyang/vue-croppa

@@ -780,2 +780,3 @@ *

this.ctx.fillStyle = backgroundColor;
this.ctx.clearRect(0, 0, this.realWidth, this.realHeight);
this.ctx.fillRect(0, 0, this.realWidth, this.realHeight);

@@ -782,0 +783,0 @@ },

/*
* vue-croppa v0.1.1
* vue-croppa v0.1.3
* https://github.com/zhanziyang/vue-croppa

@@ -8,2 +8,2 @@ *

*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Croppa=e()}(this,function(){"use strict";function t(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var e={onePointCoord:function(t,e){var i=e.canvas,a=e.quality,n=i.getBoundingClientRect(),o=t.clientX,r=t.clientY;return{x:(o-n.left)*a,y:(r-n.top)*a}},getPointerCoords:function(t,e){var i=void 0;return i=t.touches&&t.touches[0]?t.touches[0]:t.changedTouches&&t.changedTouches[0]?t.changedTouches[0]:t,this.onePointCoord(i,e)},getPinchDistance:function(t,e){var i=t.touches[0],a=t.touches[1],n=this.onePointCoord(i,e),o=this.onePointCoord(a,e);return Math.sqrt(Math.pow(n.x-o.x,2)+Math.pow(n.y-o.y,2))},getPinchCenterCoord:function(t,e){var i=t.touches[0],a=t.touches[1],n=this.onePointCoord(i,e),o=this.onePointCoord(a,e);return{x:(n.x+o.x)/2,y:(n.y+o.y)/2}},imageLoaded:function(t){return t.complete&&0!==t.naturalWidth},rAFPolyfill:function(){if("undefined"!=typeof document&&"undefined"!=typeof window){for(var t=0,e=["webkit","moz"],i=0;i<e.length&&!window.requestAnimationFrame;++i)window.requestAnimationFrame=window[e[i]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e[i]+"CancelAnimationFrame"]||window[e[i]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(e){var i=(new Date).getTime(),a=Math.max(0,16.7-(i-t)),n=window.setTimeout(function(){e(i+a)},a);return t=i+a,n}),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,e,i;HTMLCanvasElement.prototype.toBlob||Object.defineProperty(HTMLCanvasElement.prototype,"toBlob",{value:function(a,n,o){t=atob(this.toDataURL(n,o).split(",")[1]),e=t.length,i=new Uint8Array(e);for(var r=0;r<e;r++)i[r]=t.charCodeAt(r);a(new Blob([i],{type:n||"image/png"}))}})}},eventHasFile:function(t){var e=t.dataTransfer||t.originalEvent.dataTransfer;if(e.types)for(var i=0,a=e.types.length;i<a;i++)if("Files"==e.types[i])return!0;return!1}};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"},a={render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("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(e){e.stopPropagation(),e.preventDefault(),t.handleDragEnter(e)},dragleave:function(e){e.stopPropagation(),e.preventDefault(),t.handleDragLeave(e)},dragover:function(e){e.stopPropagation(),e.preventDefault(),t.handleDragOver(e)},drop:function(e){e.stopPropagation(),e.preventDefault(),t.handleDrop(e)}}},[i("input",{ref:"fileInput",attrs:{type:"file",accept:t.accept,disabled:t.disabled,hidden:""},on:{change:t.handleInputChange}}),i("div",{staticClass:"initial",staticStyle:{width:"0",height:"0",visibility:"hidden"}},[t._t("initial")],2),i("canvas",{ref:"canvas",on:{click:function(e){e.stopPropagation(),e.preventDefault(),t.handleClick(e)},touchstart:function(e){e.stopPropagation(),t.handlePointerStart(e)},mousedown:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerStart(e)},pointerstart:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerStart(e)},touchend:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},touchcancel:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},mouseup:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},pointerend:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},pointercancel:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},touchmove:function(e){e.stopPropagation(),t.handlePointerMove(e)},mousemove:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerMove(e)},pointermove:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerMove(e)},DOMMouseScroll:function(e){e.stopPropagation(),t.handleWheel(e)},wheel:function(e){e.stopPropagation(),t.handleWheel(e)},mousewheel:function(e){e.stopPropagation(),t.handleWheel(e)}}}),t.showRemoveButton&&t.img?i("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}},[i("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:".jpg,.jpeg,.png,.gif,.bmp,.webp,.svg,.tiff"},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},initialImage:String},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(),e.rAFPolyfill(),e.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.img=null,this.setInitial(),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(e){t.move({x:0,y:-e})},moveDownwards:function(e){t.move({x:0,y:e})},moveLeftwards:function(e){t.move({x:-e,y:0})},moveRightwards:function(e){t.move({x:e,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 n=null!=this.img;this.img=null,this.$refs.fileInput.value="",this.imgData={},n&&this.$emit(i.IMAGE_REMOVE_EVENT)},setInitial:function(){var t=this,i=void 0;if(this.$slots.initial&&this.$slots.initial[0]){var a=this.$slots.initial[0],n=a.tag,o=a.elm;"img"==n&&o&&o.src&&(i=o.src)}if(!i&&this.initialImage&&(i=this.initialImage),i){var r=new Image;r.setAttribute("crossOrigin","anonymous"),r.src=i,e.imageLoaded(r)?(this.img=r,this.imgContentInit()):(r.onload=function(){t.img=r,t.imgContentInit()},r.onerror=function(){t.remove()})}else 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 e=t.files[0];this.onNewFileIn(e)}},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 n=new FileReader;n.onload=function(t){var i=t.target.result,a=new Image;a.src=i,a.crossOrigin="Anonymous",a.onload=function(){e.img=a,e.imgContentInit()}},n.readAsDataURL(t)}},fileSizeIsValid:function(t){return!!t&&(!this.fileSizeLimit||0==this.fileSizeLimit||t.size<this.fileSizeLimit)},fileTypeIsValid:function(t){for(var e=this.accept||"image/*",i=e.replace(/\/.*$/,""),a=e.split(","),n=0,o=a.length;n<o;n++){var r=a[n],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(/\/.*$/,"")===i)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,e=this.img.naturalHeight;if(e/t<this.realHeight/this.realWidth){var i=e/this.realHeight;this.imgData.width=t/i,this.imgData.startX=-(this.imgData.width-this.realWidth)/2,this.imgData.height=this.realHeight}else{var a=t/this.realWidth;this.imgData.height=e/a,this.imgData.startY=-(this.imgData.height-this.realHeight)/2,this.imgData.width=this.realWidth}this.draw()},handlePointerStart:function(t){this.supportTouch=!0,this.pointerMoved=!1;var i=e.getPointerCoords(t,this);if(this.pointerStartCoord=i,!this.disabled)if(this.img||this.disableClickToChoose){if(!(t.which&&t.which>1)){if(!t.touches||1===t.touches.length){this.dragging=!0,this.pinching=!1;var a=e.getPointerCoords(t,this);this.lastMovingCoord=a}t.touches&&2===t.touches.length&&!this.disablePinchToZoom&&(this.dragging=!1,this.pinching=!0,this.pinchDistance=e.getPinchDistance(t,this));for(var n=["mouseup","touchend","touchcancel","pointerend","pointercancel"],o=0,r=n.length;o<r;o++){var s=n[o];document.addEventListener(s,this.handlePointerEnd)}}}else this.tabStart=(new Date).valueOf()},handlePointerEnd:function(t){var i=0;if(this.pointerStartCoord){var a=e.getPointerCoords(t,this);i=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 n=(new Date).valueOf();return i<100&&n-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(t){if(this.pointerMoved=!0,!this.disabled&&!this.disableDragToMove&&this.img){if(t.preventDefault(),!t.touches||1===t.touches.length){if(!this.dragging)return;var i=e.getPointerCoords(t,this);this.lastMovingCoord&&this.move({x:i.x-this.lastMovingCoord.x,y:i.y-this.lastMovingCoord.y}),this.lastMovingCoord=i}if(t.touches&&2===t.touches.length&&!this.disablePinchToZoom){if(!this.pinching)return;var a=e.getPinchDistance(t,this),n=a-this.pinchDistance;this.zoom(n>0,null,2),this.pinchDistance=a}}},handleWheel:function(t){if(!this.disabled&&!this.disableScrollToZoom&&this.img){t.preventDefault();var i=e.getPointerCoords(t,this);t.wheelDelta<0||t.deltaY>0||t.detail>0?this.zoom(this.reverseZoomingGesture||this.reverseScrollToZoom,i):(t.wheelDelta>0||t.deltaY<0||t.detail<0)&&this.zoom(!this.reverseZoomingGesture&&!this.reverseScrollToZoom,i)}},handleDragEnter:function(t){this.disabled||this.disableDragAndDrop||this.img||!e.eventHasFile(t)||(this.fileDraggedOver=!0)},handleDragLeave:function(t){this.fileDraggedOver&&e.eventHasFile(t)&&(this.fileDraggedOver=!1)},handleDragOver:function(t){},handleDrop:function(t){if(this.fileDraggedOver&&e.eventHasFile(t)){this.fileDraggedOver=!1;var i=void 0,a=t.dataTransfer;if(a){if(a.items)for(var n=0,o=a.items.length;n<o;n++){var r=a.items[n];if("file"==r.kind){i=r.getAsFile();break}}else i=a.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 n=this.zoomSpeed*a,o=1e-5*this.realWidth*n,r=1;t?r=1+o:this.imgData.width>10&&(r=1-o);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 c=this.realHeight/this.imgData.height;this.imgData.height=this.realHeight,this.imgData.width=this.imgData.width*c}}if(s.toFixed(2)!==this.imgData.width.toFixed(2)||h.toFixed(2)!==this.imgData.height.toFixed(2)){var d=(r-1)*(e.x-this.imgData.startX),u=(r-1)*(e.y-this.imgData.startY);this.imgData.startX=this.imgData.startX-d,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,e=this.ctx;if(this.img){var i=this.imgData,a=i.startX,n=i.startY,o=i.width,r=i.height;window.requestAnimationFrame?requestAnimationFrame(function(){t.paintBackground(),e.drawImage(t.img,a,n,o,r)}):(this.paintBackground(),e.drawImage(this.img,a,n,o,r))}},generateDataUrl:function(t){return this.img?this.canvas.toDataURL(t):""},generateBlob:function(t,e,i){if(!this.img)return null;this.canvas.toBlob(t,e,i)},promisedBlob:function(){for(var t=this,e=arguments.length,i=Array(e),a=0;a<e;a++)i[a]=arguments[a];if("undefined"!=typeof Promise)return new Promise(function(e,a){try{t.generateBlob(function(t){e(t)},i)}catch(t){a(t)}});console.warn("No Promise support. Please add Promise polyfill if you want to use this method.")}}},n=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,s=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},i=0;i<10;i++)e["_"+String.fromCharCode(i)]=i;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var a={};return"abcdefghijklmnopqrst".split("").forEach(function(t){a[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},a)).join("")}catch(t){return!1}}()?Object.assign:function(e,i){for(var a,s,h=t(e),l=1;l<arguments.length;l++){a=Object(arguments[l]);for(var c in a)o.call(a,c)&&(h[c]=a[c]);if(n){s=n(a);for(var d=0;d<s.length;d++)r.call(a,s[d])&&(h[s[d]]=a[s[d]])}}return h},h={componentName:"croppa"};return{install:function(t,e){e=s({},h,e);var i=Number(t.version.split(".")[0]);if(i<2)throw new Error("vue-croppa supports vue version 2.0 and above. You are using Vue@"+i+". Please upgrade to the latest version of Vue.");var n=e.componentName||"croppa";t.component(n,a)},component:a}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Croppa=e()}(this,function(){"use strict";function t(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var e={onePointCoord:function(t,e){var i=e.canvas,a=e.quality,n=i.getBoundingClientRect(),o=t.clientX,r=t.clientY;return{x:(o-n.left)*a,y:(r-n.top)*a}},getPointerCoords:function(t,e){var i=void 0;return i=t.touches&&t.touches[0]?t.touches[0]:t.changedTouches&&t.changedTouches[0]?t.changedTouches[0]:t,this.onePointCoord(i,e)},getPinchDistance:function(t,e){var i=t.touches[0],a=t.touches[1],n=this.onePointCoord(i,e),o=this.onePointCoord(a,e);return Math.sqrt(Math.pow(n.x-o.x,2)+Math.pow(n.y-o.y,2))},getPinchCenterCoord:function(t,e){var i=t.touches[0],a=t.touches[1],n=this.onePointCoord(i,e),o=this.onePointCoord(a,e);return{x:(n.x+o.x)/2,y:(n.y+o.y)/2}},imageLoaded:function(t){return t.complete&&0!==t.naturalWidth},rAFPolyfill:function(){if("undefined"!=typeof document&&"undefined"!=typeof window){for(var t=0,e=["webkit","moz"],i=0;i<e.length&&!window.requestAnimationFrame;++i)window.requestAnimationFrame=window[e[i]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e[i]+"CancelAnimationFrame"]||window[e[i]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(e){var i=(new Date).getTime(),a=Math.max(0,16.7-(i-t)),n=window.setTimeout(function(){e(i+a)},a);return t=i+a,n}),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,e,i;HTMLCanvasElement.prototype.toBlob||Object.defineProperty(HTMLCanvasElement.prototype,"toBlob",{value:function(a,n,o){t=atob(this.toDataURL(n,o).split(",")[1]),e=t.length,i=new Uint8Array(e);for(var r=0;r<e;r++)i[r]=t.charCodeAt(r);a(new Blob([i],{type:n||"image/png"}))}})}},eventHasFile:function(t){var e=t.dataTransfer||t.originalEvent.dataTransfer;if(e.types)for(var i=0,a=e.types.length;i<a;i++)if("Files"==e.types[i])return!0;return!1}};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"},a={render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("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(e){e.stopPropagation(),e.preventDefault(),t.handleDragEnter(e)},dragleave:function(e){e.stopPropagation(),e.preventDefault(),t.handleDragLeave(e)},dragover:function(e){e.stopPropagation(),e.preventDefault(),t.handleDragOver(e)},drop:function(e){e.stopPropagation(),e.preventDefault(),t.handleDrop(e)}}},[i("input",{ref:"fileInput",attrs:{type:"file",accept:t.accept,disabled:t.disabled,hidden:""},on:{change:t.handleInputChange}}),i("div",{staticClass:"initial",staticStyle:{width:"0",height:"0",visibility:"hidden"}},[t._t("initial")],2),i("canvas",{ref:"canvas",on:{click:function(e){e.stopPropagation(),e.preventDefault(),t.handleClick(e)},touchstart:function(e){e.stopPropagation(),t.handlePointerStart(e)},mousedown:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerStart(e)},pointerstart:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerStart(e)},touchend:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},touchcancel:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},mouseup:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},pointerend:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},pointercancel:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerEnd(e)},touchmove:function(e){e.stopPropagation(),t.handlePointerMove(e)},mousemove:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerMove(e)},pointermove:function(e){e.stopPropagation(),e.preventDefault(),t.handlePointerMove(e)},DOMMouseScroll:function(e){e.stopPropagation(),t.handleWheel(e)},wheel:function(e){e.stopPropagation(),t.handleWheel(e)},mousewheel:function(e){e.stopPropagation(),t.handleWheel(e)}}}),t.showRemoveButton&&t.img?i("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}},[i("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:".jpg,.jpeg,.png,.gif,.bmp,.webp,.svg,.tiff"},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},initialImage:String},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(),e.rAFPolyfill(),e.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.img=null,this.setInitial(),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(e){t.move({x:0,y:-e})},moveDownwards:function(e){t.move({x:0,y:e})},moveLeftwards:function(e){t.move({x:-e,y:0})},moveRightwards:function(e){t.move({x:e,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 n=null!=this.img;this.img=null,this.$refs.fileInput.value="",this.imgData={},n&&this.$emit(i.IMAGE_REMOVE_EVENT)},setInitial:function(){var t=this,i=void 0;if(this.$slots.initial&&this.$slots.initial[0]){var a=this.$slots.initial[0],n=a.tag,o=a.elm;"img"==n&&o&&o.src&&(i=o.src)}if(!i&&this.initialImage&&(i=this.initialImage),i){var r=new Image;r.setAttribute("crossOrigin","anonymous"),r.src=i,e.imageLoaded(r)?(this.img=r,this.imgContentInit()):(r.onload=function(){t.img=r,t.imgContentInit()},r.onerror=function(){t.remove()})}else 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 e=t.files[0];this.onNewFileIn(e)}},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 n=new FileReader;n.onload=function(t){var i=t.target.result,a=new Image;a.src=i,a.crossOrigin="Anonymous",a.onload=function(){e.img=a,e.imgContentInit()}},n.readAsDataURL(t)}},fileSizeIsValid:function(t){return!!t&&(!this.fileSizeLimit||0==this.fileSizeLimit||t.size<this.fileSizeLimit)},fileTypeIsValid:function(t){for(var e=this.accept||"image/*",i=e.replace(/\/.*$/,""),a=e.split(","),n=0,o=a.length;n<o;n++){var r=a[n],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(/\/.*$/,"")===i)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,e=this.img.naturalHeight;if(e/t<this.realHeight/this.realWidth){var i=e/this.realHeight;this.imgData.width=t/i,this.imgData.startX=-(this.imgData.width-this.realWidth)/2,this.imgData.height=this.realHeight}else{var a=t/this.realWidth;this.imgData.height=e/a,this.imgData.startY=-(this.imgData.height-this.realHeight)/2,this.imgData.width=this.realWidth}this.draw()},handlePointerStart:function(t){this.supportTouch=!0,this.pointerMoved=!1;var i=e.getPointerCoords(t,this);if(this.pointerStartCoord=i,!this.disabled)if(this.img||this.disableClickToChoose){if(!(t.which&&t.which>1)){if(!t.touches||1===t.touches.length){this.dragging=!0,this.pinching=!1;var a=e.getPointerCoords(t,this);this.lastMovingCoord=a}t.touches&&2===t.touches.length&&!this.disablePinchToZoom&&(this.dragging=!1,this.pinching=!0,this.pinchDistance=e.getPinchDistance(t,this));for(var n=["mouseup","touchend","touchcancel","pointerend","pointercancel"],o=0,r=n.length;o<r;o++){var s=n[o];document.addEventListener(s,this.handlePointerEnd)}}}else this.tabStart=(new Date).valueOf()},handlePointerEnd:function(t){var i=0;if(this.pointerStartCoord){var a=e.getPointerCoords(t,this);i=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 n=(new Date).valueOf();return i<100&&n-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(t){if(this.pointerMoved=!0,!this.disabled&&!this.disableDragToMove&&this.img){if(t.preventDefault(),!t.touches||1===t.touches.length){if(!this.dragging)return;var i=e.getPointerCoords(t,this);this.lastMovingCoord&&this.move({x:i.x-this.lastMovingCoord.x,y:i.y-this.lastMovingCoord.y}),this.lastMovingCoord=i}if(t.touches&&2===t.touches.length&&!this.disablePinchToZoom){if(!this.pinching)return;var a=e.getPinchDistance(t,this),n=a-this.pinchDistance;this.zoom(n>0,null,2),this.pinchDistance=a}}},handleWheel:function(t){if(!this.disabled&&!this.disableScrollToZoom&&this.img){t.preventDefault();var i=e.getPointerCoords(t,this);t.wheelDelta<0||t.deltaY>0||t.detail>0?this.zoom(this.reverseZoomingGesture||this.reverseScrollToZoom,i):(t.wheelDelta>0||t.deltaY<0||t.detail<0)&&this.zoom(!this.reverseZoomingGesture&&!this.reverseScrollToZoom,i)}},handleDragEnter:function(t){this.disabled||this.disableDragAndDrop||this.img||!e.eventHasFile(t)||(this.fileDraggedOver=!0)},handleDragLeave:function(t){this.fileDraggedOver&&e.eventHasFile(t)&&(this.fileDraggedOver=!1)},handleDragOver:function(t){},handleDrop:function(t){if(this.fileDraggedOver&&e.eventHasFile(t)){this.fileDraggedOver=!1;var i=void 0,a=t.dataTransfer;if(a){if(a.items)for(var n=0,o=a.items.length;n<o;n++){var r=a.items[n];if("file"==r.kind){i=r.getAsFile();break}}else i=a.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 n=this.zoomSpeed*a,o=1e-5*this.realWidth*n,r=1;t?r=1+o:this.imgData.width>10&&(r=1-o);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 c=this.realHeight/this.imgData.height;this.imgData.height=this.realHeight,this.imgData.width=this.imgData.width*c}}if(s.toFixed(2)!==this.imgData.width.toFixed(2)||h.toFixed(2)!==this.imgData.height.toFixed(2)){var d=(r-1)*(e.x-this.imgData.startX),u=(r-1)*(e.y-this.imgData.startY);this.imgData.startX=this.imgData.startX-d,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.clearRect(0,0,this.realWidth,this.realHeight),this.ctx.fillRect(0,0,this.realWidth,this.realHeight)},draw:function(){var t=this,e=this.ctx;if(this.img){var i=this.imgData,a=i.startX,n=i.startY,o=i.width,r=i.height;window.requestAnimationFrame?requestAnimationFrame(function(){t.paintBackground(),e.drawImage(t.img,a,n,o,r)}):(this.paintBackground(),e.drawImage(this.img,a,n,o,r))}},generateDataUrl:function(t){return this.img?this.canvas.toDataURL(t):""},generateBlob:function(t,e,i){if(!this.img)return null;this.canvas.toBlob(t,e,i)},promisedBlob:function(){for(var t=this,e=arguments.length,i=Array(e),a=0;a<e;a++)i[a]=arguments[a];if("undefined"!=typeof Promise)return new Promise(function(e,a){try{t.generateBlob(function(t){e(t)},i)}catch(t){a(t)}});console.warn("No Promise support. Please add Promise polyfill if you want to use this method.")}}},n=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,s=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},i=0;i<10;i++)e["_"+String.fromCharCode(i)]=i;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var a={};return"abcdefghijklmnopqrst".split("").forEach(function(t){a[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},a)).join("")}catch(t){return!1}}()?Object.assign:function(e,i){for(var a,s,h=t(e),l=1;l<arguments.length;l++){a=Object(arguments[l]);for(var c in a)o.call(a,c)&&(h[c]=a[c]);if(n){s=n(a);for(var d=0;d<s.length;d++)r.call(a,s[d])&&(h[s[d]]=a[s[d]])}}return h},h={componentName:"croppa"};return{install:function(t,e){e=s({},h,e);var i=Number(t.version.split(".")[0]);if(i<2)throw new Error("vue-croppa supports vue version 2.0 and above. You are using Vue@"+i+". Please upgrade to the latest version of Vue.");var n=e.componentName||"croppa";t.component(n,a)},component:a}});
{
"name": "vue-croppa",
"version": "0.1.2",
"version": "0.1.3",
"description": "A simple straightforward customizable lightweight mobile-friendly image cropper for Vue 2.0.",

@@ -5,0 +5,0 @@ "main": "dist/vue-croppa.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc