konva/konva.min.js

26 lines
149 KiB
JavaScript
Raw Normal View History

2018-02-05 16:03:26 +08:00
/*
2018-05-16 11:35:09 +08:00
* Konva JavaScript Framework v2.1.1
2018-02-05 16:03:26 +08:00
* http://konvajs.github.io/
* Licensed under the MIT
2018-05-16 10:42:39 +08:00
* Date: Wed May 16 2018
2018-02-05 16:03:26 +08:00
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
*
* @license
*/
2018-05-16 11:35:09 +08:00
!function(){"use strict";var e=Math.PI/180,r={version:"2.1.1",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:3,angleDeg:!0,showWarnings:!0,Filters:{},isDragging:function(){var t=r.DD;return!!t&&t.isDragging},isDragReady:function(){var t=r.DD;return!!t&&!!t.node},_addId:function(t,e){void 0!==e&&(this.ids[e]=t)},_removeId:function(t){void 0!==t&&delete this.ids[t]},_addName:function(t,e){e&&(this.names[e]||(this.names[e]=[]),this.names[e].push(t))},_removeName:function(t,e){if(t){var n=this.names[t];if(n){for(var i=0;i<n.length;i++){n[i]._id===e&&n.splice(i,1)}0===n.length&&delete this.names[t]}}},getAngle:function(t){return this.angleDeg?t*e:t},_detectIE:function(t){var e=t.indexOf("msie ");if(0<e)return parseInt(t.substring(e+5,t.indexOf(".",e)),10);if(0<t.indexOf("trident/")){var n=t.indexOf("rv:");return parseInt(t.substring(n+3,t.indexOf(".",n)),10)}var i=t.indexOf("edge/");return 0<i&&parseInt(t.substring(i+5,t.indexOf(".",i)),10)},_parseUA:function(t){var e=t.toLowerCase(),n=/(chrome)[ /]([\w.]+)/.exec(e)||/(webkit)[ /]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ /]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[],i=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),a=!!t.match(/IEMobile/i);return{browser:n[1]||"",version:n[2]||"0",isIE:r._detectIE(e),mobile:i,ieMobile:a}},UA:void 0},t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{};r.UA=r._parseUA(t.navigator&&t.navigator.userAgent||""),t.Konva&&console.error("Konva instance is already exist in current eviroment. Please use only one instance."),(t.Konva=r).global=t,r.window=t,r.document=t.document,"object"==typeof exports?module.exports=r:"function"==typeof define&&define.amd&&define(function(){return r})}(),function(){"use strict";Konva.Collection=function(){var t=[].slice.call(arguments),e=t.length,n=0;for(this.length=e;n<e;n++)this[n]=t[n];return this},Konva.Collection.prototype=[],Konva.Collection.prototype.each=function(t){for(var e=0;e<this.length;e++)t(this[e],e)},Konva.Collection.prototype.toArray=function(){var t,e=[],n=this.length;for(t=0;t<n;t++)e.push(this[t]);return e},Konva.Collection.toCollection=function(t){var e,n=new Konva.Collection,i=t.length;for(e=0;e<i;e++)n.push(t[e]);return n},Konva.Collection._mapMethod=function(i){Konva.Collection.prototype[i]=function(){var t,e=this.length,n=[].slice.call(arguments);for(t=0;t<e;t++)this[t][i].apply(this[t],n);return this}},Konva.Collection.mapMethods=function(t){var e=t.prototype;for(var n in e)Konva.Collection._mapMethod(n)},Konva.Transform=function(t){this.m=t&&t.slice()||[1,0,0,1,0,0]},Konva.Transform.prototype={copy:function(){return new Konva.Transform(this.m)},point:function(t){var e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}},translate:function(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this},scale:function(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this},rotate:function(t){var e=Math.cos(t),n=Math.sin(t),i=this.m[0]*e+this.m[2]*n,a=this.m[1]*e+this.m[3]*n,r=this.m[0]*-n+this.m[2]*e,o=this.m[1]*-n+this.m[3]*e;return this.m[0]=i,this.m[1]=a,this.m[2]=r,this.m[3]=o,this},getTranslation:function(){return{x:this.m[4],y:this.m[5]}},skew:function(t,e){var n=this.m[0]+this.m[2]*e,i=this.m[1]+this.m[3]*e,a=this.m[2]+this.m[0]*t,r=this.m[3]+this.m[1]*t;return this.m[0]=n,this.m[1]=i,this.m[2]=a,this.m[3]=r,this},multiply:function(t){var e=this.m[0]*t.m[0]+this.m[2]*t.m[1],n=this.m[1]*t.m[0]+this.m[3]*t.m[1],i=this.m[0]*t.m[2]+this.m[2]*t.m[3],a=this.m[1]*t.m[2]+this.m[3]*t.m[3],r=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],o=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=n,this.m[2]=i,this.m[3]=a,this.m[4]
2018-04-30 10:40:49 +08:00
/**
2015-04-07 16:03:08 +08:00
* Sepia Filter
* Based on: Pixastic Lib - Sepia filter - v0.1.0
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
* @function
* @name Sepia
* @memberof Konva.Filters
* @param {Object} imageData
* @author Jacob Seidelin <jseidelin@nihilogic.dk>
* @license MPL v1.1 [http://www.pixastic.com/lib/license.txt]
* @example
* node.cache();
* node.filters([Konva.Filters.Sepia]);
2018-05-16 11:35:09 +08:00
*/Konva.Filters.Sepia=function(t){var e,n,i,a,r,o,s,h,c,l=t.data,d=t.width,u=t.height,f=4*d;do{for(e=(u-1)*f,n=d;s=.393*(a=l[i=e+4*(n-1)])+.769*(r=l[i+1])+.189*(o=l[i+2]),h=.349*a+.686*r+.168*o,c=.272*a+.534*r+.131*o,l[i]=255<s?255:s,l[i+1]=255<h?255:h,l[i+2]=255<c?255:c,l[i+3]=l[i+3],--n;);}while(--u)}}(),function(){"use strict";Konva.Filters.Solarize=function(t){var e=t.data,n=t.width,i=4*n,a=t.height;do{var r=(a-1)*i,o=n;do{var s=r+4*(o-1),h=e[s],c=e[s+1],l=e[s+2];127<h&&(h=255-h),127<c&&(c=255-c),127<l&&(l=255-l),e[s]=h,e[s+1]=c,e[s+2]=l}while(--o)}while(--a)}}(),function(){"use strict";Konva.Filters.Kaleidoscope=function(t){var e,n,i,a,r,o,s,h,c,l=t.width,d=t.height,u=Math.round(this.kaleidoscopePower()),f=Math.round(this.kaleidoscopeAngle()),g=Math.floor(l*(f%360)/360);if(!(u<1)){var v=Konva.Util.createCanvasElement();v.width=l,v.height=d;var p=v.getContext("2d").getImageData(0,0,l,d);!function(t,e,n){var i,a,r,o,s=t.data,h=e.data,c=t.width,l=t.height,d=n.polarCenterX||c/2,u=n.polarCenterY||l/2,f=0,g=0,v=0,p=0,m=Math.sqrt(d*d+u*u);a=c-d,r=l-u,m=m<(o=Math.sqrt(a*a+r*r))?o:m;var _,y,S,K,x=l,C=c,b=360/C*Math.PI/180;for(y=0;y<C;y+=1)for(S=Math.sin(y*b),K=Math.cos(y*b),_=0;_<x;_+=1)a=Math.floor(d+m*_/x*K),f=s[0+(i=4*((r=Math.floor(u+m*_/x*S))*c+a))],g=s[i+1],v=s[i+2],p=s[i+3],h[0+(i=4*(y+_*c))]=f,h[i+1]=g,h[i+2]=v,h[i+3]=p}(t,p,{polarCenterX:l/2,polarCenterY:d/2});for(var m=l/Math.pow(2,u);m<=8;)m*=2,u-=1;var _=m=Math.ceil(m),y=0,S=_,K=1;for(l<g+m&&(y=_,S=0,K=-1),n=0;n<d;n+=1)for(e=y;e!==S;e+=K)h=4*(l*n+Math.round(e+g)%l),a=p.data[h+0],r=p.data[h+1],o=p.data[h+2],s=p.data[h+3],c=4*(l*n+e),p.data[c+0]=a,p.data[c+1]=r,p.data[c+2]=o,p.data[c+3]=s;for(n=0;n<d;n+=1)for(_=Math.floor(m),i=0;i<u;i+=1){for(e=0;e<_+1;e+=1)h=4*(l*n+e),a=p.data[h+0],r=p.data[h+1],o=p.data[h+2],s=p.data[h+3],c=4*(l*n+2*_-e-1),p.data[c+0]=a,p.data[c+1]=r,p.data[c+2]=o,p.data[c+3]=s;_*=2}!function(t,e,n){var i,a,r,o,s,h,c=t.data,l=e.data,d=t.width,u=t.height,f=n.polarCenterX||d/2,g=n.polarCenterY||u/2,v=0,p=0,m=0,_=0,y=Math.sqrt(f*f+g*g);a=d-f,r=u-g,y=y<(h=Math.sqrt(a*a+r*r))?h:y;var S,K,x,C=u,b=d,w=n.polarRotation||0;for(a=0;a<d;a+=1)for(r=0;r<u;r+=1)o=a-f,s=r-g,S=Math.sqrt(o*o+s*s)*C/y,K=(K=(180*Math.atan2(s,o)/Math.PI+360+w)%360)*b/360,x=Math.floor(K),v=c[0+(i=4*(Math.floor(S)*d+x))],p=c[i+1],m=c[i+2],_=c[i+3],l[0+(i=4*(r*d+a))]=v,l[i+1]=p,l[i+2]=m,l[i+3]=_}(p,t,{polarRotation:0})}},Konva.Factory.addGetterSetter(Konva.Node,"kaleidoscopePower",2,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"kaleidoscopeAngle",0,null,Konva.Factory.afterSetFilter)}(),function(t){"use strict";t.Filters.Contrast=function(t){var e,n=Math.pow((parseInt(this.contrast())+100)/100,2),i=t.data,a=i.length,r=150,o=150,s=150;for(e=0;e<a;e+=4)r=i[e],o=i[e+1],s=i[e+2],r/=255,r-=.5,r*=n,r+=.5,o/=255,o-=.5,o*=n,o+=.5,s/=255,s-=.5,s*=n,s+=.5,r=(r*=255)<0?0:255<r?255:r,o=(o*=255)<0?0:255<o?255:o,s=(s*=255)<0?0:255<s?255:s,i[e]=r,i[e+1]=o,i[e+2]=s},t.Factory.addGetterSetter(t.Node,"contrast",0,null,t.Factory.afterSetFilter)}(Konva),function(){"use strict";Konva.Container=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Container,{__init:function(t){this.children=new Konva.Collection,Konva.Node.call(this,t)},getChildren:function(e){if(!e)return this.children;var n=new Konva.Collection;return this.children.each(function(t){e(t)&&n.push(t)}),n},hasChildren:function(){return 0<this.getChildren().length},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n<e.length;n++)delete(t=e[n]).parent,t.index=0,t.remove();return e=null,this.children=new Konva.Collection,this},destroyChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n<e.length;n++)delete(t=e[n]).parent,t.index=0,t.destroy();return e=null,this.children=new Konva.Collection,this},add:function(t){if(1<arguments.length){for(var e=0;e<arguments.length;e++)this.add(arguments[e]);return this}if(t.getParent())return t.moveTo(this),this;var n=this.children;return this._validateAdd(t),t.index=n.length,t.parent=this,n.push(t),this._fire(