Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
!function(t){function e(s){if(n[s])return n[s].exports;var i=n[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,s){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:s})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,n){"use strict";function s(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.Ease=e.EZCanvas=void 0;var i=n(1),a=s(i),r=n(3),o=n(2),c=s(o),u={inQuad:function(t){return t*t},outQuad:function(t){return t*(2-t)},inOutQuad:function(t){return t<.5?2*t*t:-1+(4-2*t)*t},inCubic:function(t){return t*t*t},outCubic:function(t){return--t*t*t+1},inOutCubic:function(t){return t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1},inQuart:function(t){return t*t*t*t},outQuart:function(t){return 1- --t*t*t*t},inOutQuart:function(t){return t<.5?8*t*t*t*t:1-8*--t*t*t*t},inQuint:function(t){return t*t*t*t*t},outQuint:function(t){return 1+--t*t*t*t*t},inOutQuint:function(t){return t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t}},h=function(){var t=[],e=!1,n=!1,s=function(t,e,n){for(var s=0;s<t.length;s++){n.ctx.globalCompositeOperation=t[s].GCO,n.ctx.beginPath();var i=t[s].currentPosition(e),a=t[s].currentRotation(e),o=t[s].currentScale(e);n.ctx.save(),(t[s]instanceof r.Rectangle||t[s]instanceof c.default)&&n.ctx.translate(t[s].pos.x+t[s].w/2,t[s].pos.y+t[s].h/2),n.ctx.rotate(a*Math.PI/180),t[s]instanceof c.default?n.ctx.drawImage(t[s].image,i[0],i[1],o[0],o[1]):(n.shapes[s].draw(i,o),n.ctx.fillStyle=t[s].fill,n.ctx.fill()),n.ctx.restore()}},i=function n(){for(var i=0;i<t.length;i++){var a=window.performance.now();t[i].startTime||(t[i].startTime=a);var r=(a-t[i].startTime)/t[i].duration;r>1&&(r=1),t[i].progress=r,t[i].ctx.clearRect(0,0,t[i].ctx.canvas.width,t[i].ctx.canvas.height),s(t[i].images,r,t[i]),s(t[i].shapes,r,t[i]),r>=1&&(t[i].startTime=null,r=0,t[i].ctx.globalCompositeOperation="source-over",e=t[i].loop)}e&&window.requestAnimationFrame(n)};return{addCanvas:function(e){t.push(new a.default(e)),n=!0},addShape:function(e){if("number"!=typeof e.canvas)throw new Error("Canvas ID is not defined.");if("string"!=typeof e.shape)throw new Error("Function incorrectly called. Object required with shape property (string).");switch(e.canvases=t,e.shape){case"circ":t[e.canvas].shapes.push(new r.Circle(e));break;case"rect":t[e.canvas].shapes.push(new r.Rectangle(e));break;default:throw new Error("Provided shape not valid.")}},addImage:function(e){if("number"!=typeof e.canvas)throw new Error("Canvas ID is not defined.");e.canvases=t,t[e.canvas].images.push(new c.default(e))},clearShapes:function(e){t[e].shapes=[]},clearImages:function(e){t[e].images=[]},clearCanvas:function(e){t[e].shapes=[],t[e].images=[]},run:function(){t.length>0&&n&&(window.requestAnimationFrame(i),e=!0)},stop:function(){e=!1},getWindowSize:function(e){if("undefined"!==t.ctx){if(e)return{width:t[e].ctx.canvas.width,height:t[e].ctx.canvas.height};for(var n=[],s=0;s<t.length;s++)n.push({width:t[s].ctx.canvas.width,height:t[s].ctx.canvas.height});return n}throw new Error("Canvas must be set up before this function is called.")},getCurrentProgress:function(e){return t[e].progress},canvases:t}}();e.EZCanvas=h,e.Ease=u},function(t,e,n){"use strict";function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=function(){function t(t,e){for(var n=0;n<e.length;n++){var s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(e,n,s){return n&&t(e.prototype,n),s&&t(e,s),e}}(),r=function(){function t(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{size:[window.innerWidth,window.innerHeight],duration:1e3,easing:function(t){return t},loop:!1,el:"canvas",resize:!1};s(this,t),this.duration="number"==typeof n.duration?n.duration:1e3,this.easing="function"==typeof n.easing?n.easing:function(t){return t},this.loop="boolean"==typeof n.loop&&n.loop,this.c="string"==typeof n.el?document.querySelector(n.el):document.querySelector("canvas"),this.ctx=this.c.getContext("2d"),this.progress=0,this.shapes=[],this.images=[],this.startTime=null,n.resize&&window.addEventListener("resize",function(){e.setSize(n.size)}),this.setSize(n.size)}return a(t,[{key:"setSize",value:function(t){this.ctx.canvas.width="object"===("undefined"==typeof t?"undefined":i(t))?t[0]*window.devicePixelRatio:window.innerWidth*window.devicePixelRatio,this.ctx.canvas.height="object"===("undefined"==typeof t?"undefined":i(t))?t[1]*window.devicePixelRatio:window.innerHeight*window.devicePixelRatio,this.ctx.scale(window.devicePixelRatio,window.devicePixelRatio)}}]),t}();e.default=r},function(t,e,n){"use strict";function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=function(){function t(t,e){for(var n=0;n<e.length;n++){var s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(e,n,s){return n&&t(e.prototype,n),s&&t(e,s),e}}(),r=function(){function t(e){var n=this;if(s(this,t),this.GCO="string"==typeof e.GCO?e.GCO:"source-over",this.image=new window.Image,this.w="number"==typeof e.w?e.w:this.image.width,this.h="number"==typeof e.h?e.h:this.image.height,this.loaded=!1,this.image.onLoad=function(){n.loaded=!0},this.image.src="string"==typeof e.src?e.src:"http://placehold.it/500x500?text=Image+Must+Be+A+String",this.canvases=e.canvases,this.canvas="number"==typeof e.canvas?e.canvas:0,("object"!==i(e.position.start)||"object"!==i(e.position.end))&&"undefined"!=typeof e.position.end)throw new Error("New shapes require a starting position (array: [startX, startY] )");this.pos={start:e.position.start,end:"object"===i(e.position.end)?e.position.end:e.position.start},this.fill="string"==typeof e.fill?e.fill:"#000000",this.rot={start:0,end:0},"object"===i(e.rotation)&&("number"==typeof e.rotation.start&&"number"==typeof e.rotation.end||"undefined"==typeof e.rotation.end)&&(this.rot={start:e.rotation.start,end:"number"==typeof e.rotation.end?e.rotation.end:e.rotation.start}),this.scale={start:1,end:1},"object"===i(e.scale)&&("number"==typeof e.scale.start&&"number"==typeof e.scale.end||"undefined"==typeof e.scale.end)&&(this.scale={start:e.scale.start,end:"number"==typeof e.scale.end?e.scale.end:e.scale.start})}return a(t,[{key:"currentPosition",value:function(t){var e=this.pos.start[0]+(this.pos.end[0]-this.pos.start[0])*this.canvases[this.canvas].easing(t),n=this.pos.start[1]+(this.pos.end[1]-this.pos.start[1])*this.canvases[this.canvas].easing(t);return[e,n]}},{key:"currentRotation",value:function(t){return this.rot.start+(this.rot.end-this.rot.start)*this.canvases[this.canvas].easing(t)}},{key:"currentScale",value:function(t){var e=this.w*this.scale.start,n=this.h*this.scale.start;return this.scale.start!==this.scale.end&&(e=this.w+this.w*((this.scale.start+(this.scale.end-this.scale.start))*this.canvases[this.canvas].easing(t)-this.canvases[this.canvas].easing(t)),n=this.h+this.h*((this.scale.start+(this.scale.end-this.scale.start))*this.canvases[this.canvas].easing(t)-this.canvases[this.canvas].easing(t))),[e,n]}}]),t}();e.default=r},function(t,e,n){"use strict";function s(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=function(){function t(t,e){for(var n=0;n<e.length;n++){var s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(e,n,s){return n&&t(e.prototype,n),s&&t(e,s),e}}(),c=function(){function t(e){if(a(this,t),this.type,this.canvases=e.canvases,this.GCO="string"==typeof e.GCO?e.GCO:"source-over",this.canvas="number"==typeof e.canvas?e.canvas:0,("object"!==r(e.position.start)||"object"!==r(e.position.end))&&"undefined"!=typeof e.position.end)throw new Error("New shapes require a starting position (array: [startX, startY] )");this.pos={start:e.position.start,end:"object"===r(e.position.end)?e.position.end:e.position.start},this.fill="string"==typeof e.fill?e.fill:"#000000",this.rot={start:0,end:0},"object"===r(e.rotation)&&("number"==typeof e.rotation.start&&"number"==typeof e.rotation.end||"undefined"==typeof e.rotation.end)&&(this.rot={start:e.rotation.start,end:"number"==typeof e.rotation.end?e.rotation.end:e.rotation.start}),this.scale={start:1,end:1},"object"===r(e.scale)&&("number"==typeof e.scale.start&&"number"==typeof e.scale.end||"undefined"==typeof e.scale.end)&&(this.scale={start:e.scale.start,end:"number"==typeof e.scale.end?e.scale.end:e.scale.start})}return o(t,[{key:"currentPosition",value:function(t){var e=this.pos.start[0]+(this.pos.end[0]-this.pos.start[0])*this.canvases[this.canvas].easing(t),n=this.pos.start[1]+(this.pos.end[1]-this.pos.start[1])*this.canvases[this.canvas].easing(t);return[e,n]}},{key:"currentRotation",value:function(t){return this.rot.start+(this.rot.end-this.rot.start)*this.canvases[this.canvas].easing(t)}}]),t}(),u=function(t){function e(t){a(this,e);var n=s(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return n.r="number"==typeof t.r?t.r:75,n}return i(e,t),o(e,[{key:"currentScale",value:function(t){return this.scale.start!==this.scale.end?this.r+this.r*((this.scale.start+(this.scale.end-this.scale.start))*this.canvases[this.canvas].easing(t)-this.canvases[this.canvas].easing(t)):this.r*this.scale.start}},{key:"draw",value:function(t,e){this.canvases[this.canvas].ctx.arc(t[0],t[1],e,0,2*Math.PI)}}]),e}(c),h=function(t){function e(t){a(this,e);var n=s(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return n.w="number"==typeof t.w?t.w:75,n.h="number"==typeof t.h?t.h:75,n}return i(e,t),o(e,[{key:"currentScale",value:function(t){var e=this.w*this.scale.start,n=this.h*this.scale.start;return this.scale.start!==this.scale.end&&(e=this.w+this.w*((this.scale.start+(this.scale.end-this.scale.start))*this.canvases[this.canvas].easing(t)-this.canvases[this.canvas].easing(t)),n=this.h+this.h*((this.scale.start+(this.scale.end-this.scale.start))*this.canvases[this.canvas].easing(t)-this.canvases[this.canvas].easing(t))),[e,n]}},{key:"draw",value:function(t,e){this.canvases[this.canvas].ctx.rect(t[0],t[1],e[0],e[1])}}]),e}(c);e.Circle=u,e.Rectangle=h},function(t,e,n){"use strict";n(0)}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.