-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartboard-1.2.0.min.js
6 lines (6 loc) · 6.6 KB
/
artboard-1.2.0.min.js
1
2
3
4
5
6
/*!
ArtboardJS v1.2.0
(c) 2017 Depth Development. http://depthdev.com
License: MIT
!*/
!function(e,t){"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};e.Artboard=function(){function i(e){e.preventDefault(),e.stopPropagation(),S=0,P=0;for(var t=m;t;)S+=t.offsetTop,P+=t.offsetLeft,t=t.offsetParent}function n(e){b=[],C=[];for(var t=0,i=e.length;t<i;t++)b.push(e[t].pageX-P),C.push(e[t].pageY-S)}function o(e){e.preventDefault(),e.stopPropagation(),O.isPlaying||(i(e),n(e.touches),O.createEntry(),A(),O.rewrite())}function l(e){e.preventDefault(),e.stopPropagation(),O.isPlaying||(n(e.touches),A())}function r(e){e.preventDefault(),e.stopPropagation(),O.isPlaying||(D=!0,i(e),b=[e.pageX-P],C=[e.pageY-S],O.createEntry(),A(),O.rewrite())}function a(e){e.preventDefault(),e.stopPropagation(),!O.isPlaying&&D&&(b=[e.pageX-P],C=[e.pageY-S],A())}function u(e){D&&(D=!1,e.preventDefault(),e.stopPropagation())}function h(e){if(O.isPlaying)return!1;var i=e||{};return m.width=i.width||t.documentElement.clientWidth,m.height=i.height||m.width*(9/16),_.clearRect(0,0,m.width,m.height),p=i.multiTouch!==!1,v=i.rainbow!==!1,_.fillStyle=i.color||"#000000",_.shadowColor=_.fillStyle,_.shadowBlur=i.glow>=0?i.glow:10,T=0,E=i.radius>=0?i.radius:10,B=i.done||function(){},O.timeline=[],!0}function s(e){if(O.isPlaying)return!1;var t={multiTouch:p,rainbow:v,color:_.fillStyle,glow:_.shadowBlur,degree:T,radius:E,done:B},i=e||{};return m.width=i.width||m.width,m.height=i.height||m.height,_.clearRect(0,0,m.width,m.height),O.timeline=[],p=t.multiTouch,v=t.rainbow,_.fillStyle=t.color,_.shadowColor=_.fillStyle,_.shadowBlur=t.glow,T=t.degree,E=t.radius,B=t.done,!0}function d(){return!O.isPlaying&&(_.clearRect(0,0,m.width,m.height),O.timeline=[],!0)}function g(e){if(O.isPlaying)return!1;var t=e||{};return p=void 0!==t.multiTouch?t.multiTouch:p,v=void 0!==t.rainbow?t.rainbow:v,_.fillStyle=t.color||_.fillStyle,_.shadowColor=_.fillStyle,_.shadowBlur=t.glow>=0?t.glow:_.shadowBlur,E=t.radius>=0?t.radius:E,B=t.done||B,!0}function c(e){this.a=t.createElement("a"),this.a.href=m.toDataURL("image/png"),this.a.download=e&&"string"==typeof e?e:"ArtboardJS",this.a.click(),delete this.a}function f(){O.timeline=[],m.removeEventListener("touchstart",o),m.removeEventListener("touchmove",l),m.removeEventListener("mousedown",r),m.removeEventListener("mousemove",a),t.removeEventListener("mouseup",u)}var m=arguments[0],w="object"===_typeof(arguments[1])&&arguments[1];if(!m.getContext){var y=arguments[arguments.length-1];return"function"==typeof y&&y(),!1}var p=!0,v=!0,S=0,P=0,b=[],C=[],E=10,L=2*Math.PI,T=0,B=null,_=m.getContext("2d");_.fillStyle="#000000",_.shadowColor="#000000",_.shadowOffsetX=0,_.shadowOffsetY=0,_.shadowBlur=10;var A=null,D=!1,O={timeline:[],createEntry:function(){O.timeline.push([])},stopPlaying:!1,isPlaying:!1,play:function(){function t(){return p=O.timeline[i][n].multiTouch,v=O.timeline[i][n].rainbow,_.fillStyle=O.timeline[i][n].color,b=O.timeline[i][n].x,C=O.timeline[i][n].y,E=O.timeline[i][n].radius,T=O.timeline[i][n].degree,_.shadowBlur=O.timeline[i][n].glow,_.shadowColor=_.fillStyle,A(!0),n++,O.stopPlaying?void(O.stopPlaying=!1):void(n===l?i+1!==o?(i++,n=0,l=O.timeline[i].length,e.requestAnimationFrame(t)):(O.stopPlaying=!1,O.isPlaying=!1,B()):e.requestAnimationFrame(t))}var i=0,n=0,o=O.timeline.length,l=O.timeline[i].length;return!(O.isPlaying||!O.timeline.length||(O.isPlaying=!0,_.clearRect(0,0,m.width,m.height),t(),0))},stop:function(){O.stopPlaying=!0,e.setTimeout(function(){O.isPlaying=!1,O.stopPlaying=!1,O.change()},100)},undoCount:0,save:function(){return!(O.isPlaying||!O.timeline.length||(e.localStorage.artboard=JSON.stringify({width:m.width,height:m.height,timeline:O.timeline}),0))},saveAs:function(t,i){return!O.isPlaying&&O.timeline.length&&/^[a-zA-Z0-9_$]+$/.test(t)?(e.localStorage["artboard_"+t]=JSON.stringify({width:m.width,height:m.height,timeline:O.timeline}),!i||i(!0)):!!i&&i(!1)},saved:function(){var t=[];for(var i in e.localStorage)/^artboard_/.test(i)&&t.push(i.replace(/^artboard_/,""));return t},backup:function(){return!(O.isPlaying||!O.timeline.length)&&{width:m.width,height:m.height,timeline:O.timeline}},restore:function(t,i){if(O.isPlaying)return!1;if(!t||t instanceof Event){if(e.localStorage.artboard){var n=JSON.parse(e.localStorage.artboard);return m.width=n.width,m.height=n.height,O.timeline=n.timeline,O.undoCount=0,O.change(),!i||i(!0)}return!!i&&i(!1)}if("string"==typeof t){if(e.localStorage["artboard_"+t]){var o=JSON.parse(e.localStorage["artboard_"+t]);return m.width=o.width,m.height=o.height,O.timeline=o.timeline,O.undoCount=0,O.change(),!i||i(!0)}return!!i&&i(!1)}try{return m.width=t.width,m.height=t.height,O.timeline=t.timeline,O.undoCount=0,O.change(),!i||i(!0)}catch(l){return!!i&&i(!1)}},deleteSaved:function(){delete e.localStorage.artboard;for(var t in e.localStorage)/^artboard_/.test(t)&&delete e.localStorage[t]},rewrite:function(){O.undoCount&&(O.timeline.splice(O.timeline.length-1-O.undoCount,O.undoCount),O.undoCount=0)},log:function(){O.timeline[O.timeline.length-1].push({multiTouch:p,rainbow:v,color:_.fillStyle,x:b,y:C,radius:E,degree:T,glow:_.shadowBlur})},settings:function(){return{multiTouch:p,rainbow:v,color:_.fillStyle,radius:E,degree:T,glow:_.shadowBlur}},change:function(){_.clearRect(0,0,m.width,m.height);for(var e=0,t=0,i=O.timeline.length-O.undoCount,n=O.timeline[e].length;e<i;e++)for(t=0,n=O.timeline[e].length;t<n;t++)p=O.timeline[e][t].multiTouch,v=O.timeline[e][t].rainbow,_.fillStyle=O.timeline[e][t].color,b=O.timeline[e][t].x,C=O.timeline[e][t].y,E=O.timeline[e][t].radius,T=O.timeline[e][t].degree,_.shadowBlur=O.timeline[e][t].glow,_.shadowColor=_.fillStyle,A(!0);B()},undo:function(){return!O.isPlaying&&O.undoCount!==O.timeline.length&&(O.undoCount++,O.change(),!0)},redo:function(){return!O.isPlaying&&O.undoCount>0&&(O.undoCount--,O.change(),!0)},size:function(){return JSON.stringify({width:m.width,height:m.height,timeline:O.timeline}).length}};return A=function(e){v&&(_.fillStyle="hsl("+T+",100%,50%)",_.shadowColor="hsl("+T+",100%,50%)",T++);for(var t=0,i=b.length;t<i&&(_.beginPath(),_.arc(b[t],C[t],E,0,L,!1),_.fill(),p);t++);e||O.log()},m.addEventListener("touchstart",o),m.addEventListener("touchmove",l),m.addEventListener("mousedown",r),m.addEventListener("mousemove",a),t.addEventListener("mouseup",u),h(w),{adjust:g,backup:O.backup,clear:d,deleteSaved:O.deleteSaved,destroy:f,hardReset:h,image:c,play:O.play,redo:O.redo,reset:s,restore:O.restore,save:O.save,saveAs:O.saveAs,saved:O.saved,settings:O.settings,size:O.size,stop:O.stop,undo:O.undo}}}(window,document);