zhgdyun/public/js/customiseControls.min.js

1 line
7.0 KiB
JavaScript
Raw Normal View History

"use strict";(function(t){var e=t.fabric||(t.fabric={}),r="1.6.0",o=function(){return"undefined"!=typeof G_vmlCanvasManager},i=e.util.degreesToRadians,s={mt:0,tr:1,mr:2,br:3,mb:4,bl:5,ml:6,tl:7};r.localeCompare(t.fabric.version)>-1&&console.warn("this extension might not be fully compatible with your version of fabric.js ("+t.fabric.version+").Consider using the latest compatible build of fabric.js (> "+r+")"),e.util.object.extend(e.Object.prototype,{useCustomIcons:!1,cornerBackgroundColor:"transparent",cornerShape:"",cornerPadding:0,customiseCornerIcons:function(t,e){var r,o;for(r in t)t.hasOwnProperty(r)&&(o={},void 0!==t[r].cornerShape&&(this.cornerShape=t[r].cornerShape),void 0!==t[r].cornerBackgroundColor&&(this.cornerBackgroundColor=t[r].cornerBackgroundColor),void 0!==t[r].borderColor&&(this.borderColor=t[r].borderColor),void 0!==t[r].cornerSize&&(this.cornerSize=t[r].cornerSize),void 0!==t[r].cornerPadding&&(this.cornerPadding=t[r].cornerPadding),void 0===t[r].icon&&"settings"!==Object.keys(t)[0]||(this.useCustomIcons=!0,void 0!==t[r].settings&&(o.settings=t[r].settings),void 0!==t[r].icon&&(o.icon=t[r].icon,this.loadIcon(r,o,function(){e&&"function"==typeof e&&e()}))))},loadIcon:function(t,r,o){var i=this,s=new Image;s.onload=function(){i[t+"Icon"]=this,r.settings&&(i[t+"Settings"]=r.settings),o&&"function"==typeof o&&o()},s.onerror=function(){e.warn(this.src+" icon is not an image")},(r.icon.match(/^http[s]?:\/\//)||"//"===r.icon.substring(0,2))&&(s.crossOrigin="Anonymous"),s.src=r.icon},customizeCornerIcons:function(t){this.customiseCornerIcons(t)},drawControls:function(t){if(!this.hasControls)return this;var e,r=this._calculateCurrentDimensions(),o=r.x,i=r.y,s=this.cornerSize,n=-(o+s)/2,c=-(i+s)/2;return this.useCustomIcons?e="drawImage":(t.lineWidth=1,t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,t.strokeStyle=t.fillStyle=this.cornerColor,this.transparentCorners||(t.strokeStyle=this.cornerStrokeColor),e=this.transparentCorners?"stroke":"fill"),t.save(),this._setLineDash(t,this.cornerDashArray,null),this._drawControl("tl",t,e,n,c,this.tlIcon,this.tlSettings),this._drawControl("tr",t,e,n+o,c,this.trIcon,this.trSettings),this._drawControl("bl",t,e,n,c+i,this.blIcon,this.blSettings),this._drawControl("br",t,e,n+o,c+i,this.brIcon,this.brSettings),this.get("lockUniScaling")||(this._drawControl("mt",t,e,n+o/2,c,this.mtIcon,this.mtSettings),this._drawControl("mb",t,e,n+o/2,c+i,this.mbIcon,this.mbSettings),this._drawControl("mr",t,e,n+o,c+i/2,this.mrIcon,this.mrSettings),this._drawControl("ml",t,e,n,c+i/2,this.mlIcon,this.mlSettings)),this.hasRotatingPoint&&this._drawControl("mtr",t,e,n+o/2,c-this.rotatingPointOffset,this.mtrIcon,this.mtrSettings),t.restore(),this},_drawControl:function(t,e,r,i,s,n,c){if(this.isControlVisible(t)){var a=this.cornerSize,h=this.cornerStrokeColor||"transparent",u=this.cornerBackgroundColor||"black",l=this.cornerShape||"rect",d="number"==typeof this.cornerPadding?this.cornerPadding:10;if(c&&(c.cornerSize&&(i=i+a/2-c.cornerSize/2,s=s+a/2-c.cornerSize/2,a=c.cornerSize),l=c.cornerShape||l,u=c.cornerBackgroundColor||u,d="number"==typeof c.cornerPadding?c.cornerPadding:d,h=c.cornerStrokeColor||h),this.useCustomIcons)if(l){switch(e.globalAlpha=1,e.fillStyle=u,e.lineWidth=1,e.strokeStyle=h,l){case"rect":break;case"circle":}void 0!==n&&e[r](n,i+d/2,s+d/2,a-d,a-d)}else void 0!==n&&e[r](n,i,s,a,a);else o()||this.transparentCorners||e.clearRect(i,s,a,a),e[r+"Rect"](i,s,a,a),!this.transparentCorners&&h&&e.strokeRect(i,s,a,a)}}}),e.util.object.extend(e.Canvas.prototype,{overwriteActions:!1,fixedCursors:!1,customiseControls:function(t){var e;for(e in t)t.hasOwnProperty(e)&&(void 0!==t[e].action&&(this.overwriteActions=!0,this.setCustomAction(e,t[e].action)),void 0!==t[e].cursor&&(this.fixedCursors=!0,this.setCustomCursor(e,t[e].cursor)))},setCustomAction:function(t,e){this[t+"Action"]=e},setCustomCursor:function(t,e){this[t+"cursorIcon"]=e},customizeControls:function(t){this.customiseControls(t)},_getActionFromCorner:function(t,e,r){if(!e)return"drag";if(e)if(this[e+"Action"]&&this.overwr