vue-confetti
Advanced tools
Comparing version 1.1.3 to 1.2.0
@@ -6,2 +6,5 @@ module.exports = { | ||
}, | ||
rules: { | ||
'class-methods-use-this': 'off', | ||
}, | ||
}; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["vue-confetti"]=e():t["vue-confetti"]=e()}(window,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,n){"use strict";n.r(e);var i=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t+1,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=parseFloat(t),r=parseFloat(e),o=Math.random()*(r-i)+i;return n?Math.round(o):o};function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var o=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.color,i=void 0===n?"blue":n,r=e.size,o=void 0===r?10:r,a=e.dropRate,s=void 0===a?10:a;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.color=i,this.size=o,this.dropRate=s}var e,n,o;return e=t,(n=[{key:"setup",value:function(t){var e=t.canvas,n=t.wind,r=t.windPosCoef,o=t.windSpeedMax,a=t.count;return this.canvas=e,this.wind=n,this.windPosCoef=r,this.windSpeedMax=o,this.x=i(-35,this.canvas.width+35),this.y=i(-30,-35),this.d=i(150)+10,this.r=i(this.size,2*this.size),this.tilt=i(10),this.tiltAngleIncremental=(i(0,.08)+.04)*(i()<.5?-1:1),this.tiltAngle=0,this.angle=i(2*Math.PI),this.count=a+1,this.remove=!1,this}},{key:"update",value:function(){return this.tiltAngle+=this.tiltAngleIncremental*(.2*Math.cos(this.wind+(this.d+this.x+this.y)*this.windPosCoef)+1),this.y+=(Math.cos(this.angle+this.d)+parseInt(this.dropRate,10))/2,this.x+=Math.sin(this.angle),this.x+=Math.cos(this.wind+(this.d+this.x+this.y)*this.windPosCoef)*this.windSpeedMax,this.y+=Math.sin(this.wind+(this.d+this.x+this.y)*this.windPosCoef)*this.windSpeedMax,this.tilt=15*Math.sin(this.tiltAngle-this.count/3),this.y>this.canvas.height}},{key:"draw",value:function(){this.canvas.ctx.fillStyle=this.color,this.canvas.ctx.beginPath(),this.canvas.ctx.setTransform(Math.cos(this.tiltAngle),Math.sin(this.tiltAngle),0,1,this.x,this.y)}},{key:"kill",value:function(){this.remove=!0}}])&&r(e.prototype,n),o&&r(e,o),t}();function a(t){return(a="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})(t)}function s(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function c(t,e){return!e||"object"!==a(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function u(t,e,n){return(u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=l(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function l(t){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var h=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),c(this,l(e).apply(this,arguments))}var n,i,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}(e,o),n=e,(i=[{key:"draw",value:function(){u(l(e.prototype),"draw",this).call(this),this.canvas.ctx.arc(0,0,this.r/2,0,2*Math.PI,!1),this.canvas.ctx.fill()}}])&&s(n.prototype,i),r&&s(n,r),e}();function p(t){return(p="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})(t)}function d(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function y(t,e){return!e||"object"!==p(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function v(t,e,n){return(v="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=b(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function b(t){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function w(t,e){return(w=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var m=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),y(this,b(e).apply(this,arguments))}var n,i,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&w(t,e)}(e,o),n=e,(i=[{key:"draw",value:function(){v(b(e.prototype),"draw",this).call(this),this.canvas.ctx.fillRect(0,0,this.r,this.r/2)}}])&&d(n.prototype,i),r&&d(n,r),e}();function g(t){return(g="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})(t)}function O(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function P(t,e){return!e||"object"!==g(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function x(t,e,n){return(x="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=j(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function k(t,e){return(k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var S=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),P(this,j(e).apply(this,arguments))}var n,i,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&k(t,e)}(e,o),n=e,(i=[{key:"draw",value:function(){var t=this;x(j(e.prototype),"draw",this).call(this);var n=function(e,n,i,r,o,a){t.canvas.ctx.bezierCurveTo(e*(t.r/200),n*(t.r/200),i*(t.r/200),r*(t.r/200),o*(t.r/200),a*(t.r/200))};this.canvas.ctx.moveTo(37.5/this.r,20/this.r),n(75,37,70,25,50,25),n(20,25,20,62.5,20,62.5),n(20,80,40,102,75,120),n(110,102,130,80,130,62.5),n(130,62.5,130,25,100,25),n(85,25,75,37,75,40),this.canvas.ctx.fill()}}])&&O(n.prototype,i),r&&O(n,r),e}();function C(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var _=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.items=[],this.pool=[],this.particleOptions=e}var e,n,r;return e=t,(n=[{key:"update",value:function(){var t=this;this.items.filter(function(t){return t.update()}).forEach(function(e,n){var i=t.items.splice(n-1,1)[0];i.setup(t.particleOptions),i.kill||t.pool.push(i)})}},{key:"draw",value:function(){this.items.forEach(function(t){return t.draw()})}},{key:"add",value:function(){this.pool.length>0?this.items.push(this.pool.pop().setup(this.particleOptions)):this.items.push(function(t){var e=Object.assign({shape:"circle",size:10,dropRate:10,colors:["DodgerBlue","OliveDrab","Gold","pink","SlateBlue","lightblue","Violet","PaleGreen","SteelBlue","SandyBrown","Chocolate","Crimson"]},t),n=i(0,e.colors.length,!0);if(e.color=e.colors[n],"circle"===e.shape)return new h(e);if("rect"===e.shape)return new m(e);if("heart"===e.shape)return new S(e);throw Error('Unkown particle shape: "'.concat(e.shape,'"'))}(this.particleOptions).setup(this.particleOptions))}},{key:"refresh",value:function(){this.items.forEach(function(t){t.kill()}),this.pool=[]}}])&&C(e.prototype,n),r&&C(e,r),t}();function M(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var E=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.canvas=t.createDefaultCanvas(),this.ctx=this.canvas.getContext("2d")}var e,n,i;return e=t,i=[{key:"createDefaultCanvas",value:function(){var t=document.createElement("canvas");return t.style.display="block",t.style.position="fixed",t.style.pointerEvents="none",t.style.top=0,t.style.width="100vw",t.style.height="100vh",t.id="confetti-canvas",document.querySelector("body").appendChild(t),t}}],(n=[{key:"clear",value:function(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.width,this.height)}},{key:"updateDimensions",value:function(){this.width===window.innerWidth&&this.height===window.innerHeight||(this.canvas.width=window.innerWidth,this.canvas.height=window.innerHeight)}},{key:"destroy",value:function(){document.body.removeChild(this.canvas)}},{key:"width",get:function(){return this.canvas.width}},{key:"height",get:function(){return this.canvas.width}}])&&M(e.prototype,n),i&&M(e,i),t}();function R(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var T=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.setDefaults()}var e,n,i;return e=t,(n=[{key:"setDefaults",value:function(){this.canvas=null,this.W=0,this.H=0,this.particles=null,this.droppedCount=0,this.particlesPerFrame=1.5,this.wind=0,this.windSpeed=1,this.windSpeedMax=1,this.windChange=.01,this.windPosCoef=.002,this.maxParticlesPerFrame=2,this.animationId=null}},{key:"particleOptions",value:function(t){var e={canvas:this.canvas,W:this.W,H:this.H,wind:this.wind,windPosCoef:this.windPosCoef,windSpeedMax:this.windSpeedMax,count:0};return Object.assign(e,t),e}},{key:"createParticles",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=this.particleOptions(t);this.particles=new _(e)}},{key:"start",value:function(t){this.canvas||(this.canvas=new E),this.animationId&&cancelAnimationFrame(this.animationId),this.createParticles(t),this.canvas.updateDimensions(),this.particlesPerFrame=this.maxParticlesPerFrame,this.animationId=requestAnimationFrame(this.mainLoop.bind(this))}},{key:"stop",value:function(){this.particlesPerFrame=0}},{key:"update",value:function(t){this.particles&&(this.particles.particleOptions=this.particleOptions(t),this.particles.refresh())}},{key:"remove",value:function(){this.stop(),this.animationId&&cancelAnimationFrame(this.animationId),this.canvas.destroy(),this.setDefaults()}},{key:"mainLoop",value:function(t){for(this.canvas.updateDimensions(),this.canvas.clear(),this.windSpeed=Math.sin(t/8e3)*this.windSpeedMax,this.wind=this.particles.particleOptions.wind+=this.windChange;this.droppedCount<this.particlesPerFrame;)this.droppedCount+=1,this.particles.add();this.droppedCount-=this.particlesPerFrame,this.particles.update(),this.particles.draw(),this.particles.items.length&&(this.animationId=requestAnimationFrame(this.mainLoop.bind(this)))}}])&&R(e.prototype,n),i&&R(e,i),t}();n.d(e,"Confetti",function(){return T});e.default={install:function(t,e){this.installed||(this.installed=!0,t.prototype.$confetti=new T(e))}}},,,function(t,e,n){t.exports=n(0)}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["vue-confetti"]=e():t["vue-confetti"]=e()}(window,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,n){"use strict";n.r(e);var i=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t+1,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=parseFloat(t),r=parseFloat(e),o=Math.random()*(r-i)+i;return n?Math.round(o):o};function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var o=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.color,i=void 0===n?"blue":n,r=e.size,o=void 0===r?10:r,a=e.dropRate,c=void 0===a?10:a;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.color=i,this.size=o,this.dropRate=c}var e,n,o;return e=t,(n=[{key:"setup",value:function(t){var e=t.canvas,n=t.wind,r=t.windPosCoef,o=t.windSpeedMax,a=t.count;return this.canvas=e,this.wind=n,this.windPosCoef=r,this.windSpeedMax=o,this.x=i(-35,this.canvas.width+35),this.y=i(-30,-35),this.d=i(150)+10,this.particleSize=i(this.size,2*this.size),this.tilt=i(10),this.tiltAngleIncremental=(i(0,.08)+.04)*(i()<.5?-1:1),this.tiltAngle=0,this.angle=i(2*Math.PI),this.count=a+1,this.remove=!1,this}},{key:"update",value:function(){return this.tiltAngle+=this.tiltAngleIncremental*(.2*Math.cos(this.wind+(this.d+this.x+this.y)*this.windPosCoef)+1),this.y+=(Math.cos(this.angle+this.d)+parseInt(this.dropRate,10))/2,this.x+=Math.sin(this.angle),this.x+=Math.cos(this.wind+(this.d+this.x+this.y)*this.windPosCoef)*this.windSpeedMax,this.y+=Math.sin(this.wind+(this.d+this.x+this.y)*this.windPosCoef)*this.windSpeedMax,this.tilt=15*Math.sin(this.tiltAngle-this.count/3),this.y>this.canvas.height}},{key:"draw",value:function(){this.canvas.ctx.fillStyle=this.color,this.canvas.ctx.beginPath(),this.canvas.ctx.setTransform(Math.cos(this.tiltAngle),Math.sin(this.tiltAngle),0,1,this.x,this.y)}},{key:"kill",value:function(){this.remove=!0}}])&&r(e.prototype,n),o&&r(e,o),t}();function a(t){return(a="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})(t)}function c(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function s(t,e){return!e||"object"!==a(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function u(t,e,n){return(u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=l(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function l(t){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var h=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),s(this,l(e).apply(this,arguments))}var n,i,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}(e,o),n=e,(i=[{key:"draw",value:function(){u(l(e.prototype),"draw",this).call(this),this.canvas.ctx.arc(0,0,this.particleSize/2,0,2*Math.PI,!1),this.canvas.ctx.fill()}}])&&c(n.prototype,i),r&&c(n,r),e}();function p(t){return(p="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})(t)}function y(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function d(t,e){return!e||"object"!==p(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function v(t,e,n){return(v="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=b(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function b(t){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function m(t,e){return(m=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var w=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),d(this,b(e).apply(this,arguments))}var n,i,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&m(t,e)}(e,o),n=e,(i=[{key:"draw",value:function(){v(b(e.prototype),"draw",this).call(this),this.canvas.ctx.fillRect(0,0,this.particleSize,this.particleSize/2)}}])&&y(n.prototype,i),r&&y(n,r),e}();function g(t){return(g="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})(t)}function O(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function P(t,e){return!e||"object"!==g(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function S(t,e,n){return(S="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=j(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function x(t,e){return(x=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var k=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),P(this,j(e).apply(this,arguments))}var n,i,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&x(t,e)}(e,o),n=e,(i=[{key:"draw",value:function(){var t=this;S(j(e.prototype),"draw",this).call(this);var n=function(e,n,i,r,o,a){t.canvas.ctx.bezierCurveTo(e*(t.particleSize/200),n*(t.particleSize/200),i*(t.particleSize/200),r*(t.particleSize/200),o*(t.particleSize/200),a*(t.particleSize/200))};this.canvas.ctx.moveTo(37.5/this.particleSize,20/this.particleSize),n(75,37,70,25,50,25),n(20,25,20,62.5,20,62.5),n(20,80,40,102,75,120),n(110,102,130,80,130,62.5),n(130,62.5,130,25,100,25),n(85,25,75,37,75,40),this.canvas.ctx.fill()}}])&&O(n.prototype,i),r&&O(n,r),e}();function _(t){return(_="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})(t)}function C(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function E(t,e){return!e||"object"!==_(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function M(t,e,n){return(M="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=I(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function I(t){return(I=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function R(t,e){return(R=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var z=function(t){function e(t,n){var i;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(i=E(this,I(e).call(this,t))).imgEl=n,i}var n,i,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&R(t,e)}(e,o),n=e,(i=[{key:"draw",value:function(){M(I(e.prototype),"draw",this).call(this),this.canvas.ctx.drawImage(this.imgEl,0,0,this.particleSize,this.particleSize)}}])&&C(n.prototype,i),r&&C(n,r),e}();function T(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var F=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.cachedImage=null}var e,n,r;return e=t,(n=[{key:"createImageElement",value:function(t){var e=document.createElement("img");return e.setAttribute("src",t),e}},{key:"getImageElement",value:function(t){return this.cachedImage&&t===this.cachedImage.getAttribute("src")||(this.cachedImage=this.createImageElement(t)),this.cachedImage}},{key:"create",value:function(t){var e=Object.assign({shape:"circle",size:10,dropRate:10,colors:["DodgerBlue","OliveDrab","Gold","pink","SlateBlue","lightblue","Violet","PaleGreen","SteelBlue","SandyBrown","Chocolate","Crimson"],image:null},t),n=i(0,e.colors.length,!0);if(e.color=e.colors[n],"circle"===e.shape)return new h(e);if("rect"===e.shape)return new w(e);if("heart"===e.shape)return new k(e);if("image"===e.shape)return new z(e,this.getImageElement(e.image));throw Error('Unkown particle shape: "'.concat(e.shape,'"'))}}])&&T(e.prototype,n),r&&T(e,r),t}();function D(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var A=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.items=[],this.pool=[],this.particleOptions=e,this.particleFactory=new F}var e,n,i;return e=t,(n=[{key:"update",value:function(){var t=this;this.items.filter(function(t){return t.update()}).forEach(function(e,n){var i=t.items.splice(n-1,1)[0];i.setup(t.particleOptions),i.kill||t.pool.push(i)})}},{key:"draw",value:function(){this.items.forEach(function(t){return t.draw()})}},{key:"add",value:function(){this.pool.length>0?this.items.push(this.pool.pop().setup(this.particleOptions)):this.items.push(this.particleFactory.create(this.particleOptions).setup(this.particleOptions))}},{key:"refresh",value:function(){this.items.forEach(function(t){t.kill()}),this.pool=[]}}])&&D(e.prototype,n),i&&D(e,i),t}();function H(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var W=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.canvas=t.createDefaultCanvas(),this.ctx=this.canvas.getContext("2d")}var e,n,i;return e=t,i=[{key:"createDefaultCanvas",value:function(){var t=document.createElement("canvas");return t.style.display="block",t.style.position="fixed",t.style.pointerEvents="none",t.style.top=0,t.style.width="100vw",t.style.height="100vh",t.id="confetti-canvas",document.querySelector("body").appendChild(t),t}}],(n=[{key:"clear",value:function(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.width,this.height)}},{key:"updateDimensions",value:function(){this.width===window.innerWidth&&this.height===window.innerHeight||(this.canvas.width=window.innerWidth,this.canvas.height=window.innerHeight)}},{key:"destroy",value:function(){document.body.removeChild(this.canvas)}},{key:"width",get:function(){return this.canvas.width}},{key:"height",get:function(){return this.canvas.width}}])&&H(e.prototype,n),i&&H(e,i),t}();function B(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var q=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.setDefaults()}var e,n,i;return e=t,(n=[{key:"setDefaults",value:function(){this.canvas=null,this.W=0,this.H=0,this.particles=null,this.droppedCount=0,this.particlesPerFrame=1.5,this.wind=0,this.windSpeed=1,this.windSpeedMax=1,this.windChange=.01,this.windPosCoef=.002,this.maxParticlesPerFrame=2,this.animationId=null}},{key:"particleOptions",value:function(t){var e={canvas:this.canvas,W:this.W,H:this.H,wind:this.wind,windPosCoef:this.windPosCoef,windSpeedMax:this.windSpeedMax,count:0};return Object.assign(e,t),e}},{key:"createParticles",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=this.particleOptions(t);this.particles=new A(e)}},{key:"start",value:function(t){this.canvas||(this.canvas=new W),this.animationId&&cancelAnimationFrame(this.animationId),this.createParticles(t),this.canvas.updateDimensions(),this.particlesPerFrame=this.maxParticlesPerFrame,this.animationId=requestAnimationFrame(this.mainLoop.bind(this))}},{key:"stop",value:function(){this.particlesPerFrame=0}},{key:"update",value:function(t){this.particles&&(this.particles.particleOptions=this.particleOptions(t),this.particles.refresh())}},{key:"remove",value:function(){this.stop(),this.animationId&&cancelAnimationFrame(this.animationId),this.canvas.destroy(),this.setDefaults()}},{key:"mainLoop",value:function(t){for(this.canvas.updateDimensions(),this.canvas.clear(),this.windSpeed=Math.sin(t/8e3)*this.windSpeedMax,this.wind=this.particles.particleOptions.wind+=this.windChange;this.droppedCount<this.particlesPerFrame;)this.droppedCount+=1,this.particles.add();this.droppedCount-=this.particlesPerFrame,this.particles.update(),this.particles.draw(),this.particles.items.length&&(this.animationId=requestAnimationFrame(this.mainLoop.bind(this)))}}])&&B(e.prototype,n),i&&B(e,i),t}();n.d(e,"Confetti",function(){return q});e.default={install:function(t,e){this.installed||(this.installed=!0,t.prototype.$confetti=new q(e))}}},,,function(t,e,n){t.exports=n(0)}])}); |
{ | ||
"name": "vue-confetti", | ||
"description": "A Vue component for dropping confetti.", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"main": "dist/vue-confetti.js", | ||
@@ -14,3 +14,4 @@ "author": "Alex Mendes <alexanderhmendes@gmail.com>", | ||
"dev": "webpack --watch", | ||
"build": "cross-env NODE_ENV=production webpack" | ||
"build": "cross-env NODE_ENV=production webpack", | ||
"demo": "http-server ./dist -c-1" | ||
}, | ||
@@ -40,2 +41,3 @@ "repository": { | ||
"clean-webpack-plugin": "^1.0.1", | ||
"copy-webpack-plugin": "^5.0.3", | ||
"cross-env": "^5.2.0", | ||
@@ -47,2 +49,3 @@ "eslint": "^5.3.0", | ||
"html-webpack-template": "^6.2.0", | ||
"http-server": "^0.11.1", | ||
"husky": "^1.3.1", | ||
@@ -49,0 +52,0 @@ "jest": "^24.1.0", |
@@ -64,11 +64,14 @@ # vue-confetti | ||
| Property | Type | Description | Default | | ||
|----------|-------------------|-----------------------------------------------------------------|-----------| | ||
| shape | String | The shape of the confetti (`'circle'`, `'rect'`, or `'heart'`). | 'circle' | | ||
| size | Number | The size of the particles (should be a positive number). | 10 | | ||
| dropRate | Number | The speed at which the particles fall. | 10 | | ||
| colors | Array | The confetti colors. | ['DodgerBlue', 'OliveDrab', 'Gold', 'pink', 'SlateBlue', 'lightblue', 'Violet', 'PaleGreen', 'SteelBlue', 'SandyBrown', 'Chocolate', 'Crimson'] | | ||
| Property | Type | Description | Default | | ||
|----------|-------------------|---------------------------------------------------------------------------|-----------| | ||
| shape | String | The shape of the confetti (`'circle'`, `'rect'`, `'heart'` or `'image'`). | 'circle' | | ||
| size | Number | The size of the particles (should be a positive number). | 10 | | ||
| dropRate | Number | The speed at which the particles fall. | 10 | | ||
| colors | Array | The confetti colors. | ['DodgerBlue', 'OliveDrab', 'Gold', 'pink', 'SlateBlue', 'lightblue', 'Violet', 'PaleGreen', 'SteelBlue', 'SandyBrown', 'Chocolate', 'Crimson'] | | ||
| image | string | The path to a custom image or SVG to use as the particle. Note that `shape` must be set to `image`. | null | | ||
### Example | ||
### Examples | ||
#### Red and pink hearts: | ||
``` js | ||
@@ -85,2 +88,11 @@ $confetti.start({ | ||
#### Custom image: | ||
``` js | ||
$confetti.start({ | ||
shape: 'image', | ||
image: 'http://placekitten.com/50/50', | ||
}); | ||
``` | ||
## Development | ||
@@ -99,2 +111,5 @@ | ||
npm run build | ||
# serve the demo page (watch for changes from another terminal) | ||
npm run demo | ||
``` | ||
@@ -101,0 +116,0 @@ |
@@ -6,2 +6,3 @@ import getRandomNumber from '../utils/get-random-number'; | ||
HeartParticle, | ||
ImageParticle, | ||
} from '../particles'; | ||
@@ -16,39 +17,82 @@ | ||
*/ | ||
export default (options) => { | ||
const defaults = { | ||
shape: 'circle', | ||
size: 10, | ||
dropRate: 10, | ||
colors: [ | ||
'DodgerBlue', | ||
'OliveDrab', | ||
'Gold', | ||
'pink', | ||
'SlateBlue', | ||
'lightblue', | ||
'Violet', | ||
'PaleGreen', | ||
'SteelBlue', | ||
'SandyBrown', | ||
'Chocolate', | ||
'Crimson', | ||
], | ||
}; | ||
export default class ParticleFactory { | ||
constructor() { | ||
this.cachedImage = null; | ||
} | ||
const opts = Object.assign(defaults, options); | ||
/** | ||
* Create an image element from the given source. | ||
* @param {string} imgSource | ||
* The path to the image. | ||
*/ | ||
createImageElement(imgSource) { | ||
const imgEl = document.createElement('img'); | ||
imgEl.setAttribute('src', imgSource); | ||
return imgEl; | ||
} | ||
// Set a random color from the array | ||
const colorIndex = getRandomNumber(0, opts.colors.length, true); | ||
opts.color = opts.colors[colorIndex]; | ||
/** | ||
* Get an image element from a source string. | ||
* @param {string} imgSource | ||
* The path to the image. | ||
*/ | ||
getImageElement(imgSource) { | ||
if (!this.cachedImage || imgSource !== this.cachedImage.getAttribute('src')) { | ||
this.cachedImage = this.createImageElement(imgSource); | ||
} | ||
// Generate a particle of the given shape | ||
if (opts.shape === 'circle') { | ||
return new CircleParticle(opts); | ||
} if (opts.shape === 'rect') { | ||
return new RectParticle(opts); | ||
} if (opts.shape === 'heart') { | ||
return new HeartParticle(opts); | ||
return this.cachedImage; | ||
} | ||
throw Error(`Unkown particle shape: "${opts.shape}"`); | ||
}; | ||
/** | ||
* Create a particle. | ||
* @param {Object} options | ||
* The particle options. | ||
*/ | ||
create(options) { | ||
const defaults = { | ||
shape: 'circle', | ||
size: 10, | ||
dropRate: 10, | ||
colors: [ | ||
'DodgerBlue', | ||
'OliveDrab', | ||
'Gold', | ||
'pink', | ||
'SlateBlue', | ||
'lightblue', | ||
'Violet', | ||
'PaleGreen', | ||
'SteelBlue', | ||
'SandyBrown', | ||
'Chocolate', | ||
'Crimson', | ||
], | ||
image: null, | ||
}; | ||
const opts = Object.assign(defaults, options); | ||
// Set a random color from the array | ||
const colorIndex = getRandomNumber(0, opts.colors.length, true); | ||
opts.color = opts.colors[colorIndex]; | ||
if (opts.shape === 'circle') { | ||
return new CircleParticle(opts); | ||
} | ||
if (opts.shape === 'rect') { | ||
return new RectParticle(opts); | ||
} | ||
if (opts.shape === 'heart') { | ||
return new HeartParticle(opts); | ||
} | ||
if (opts.shape === 'image') { | ||
return new ImageParticle(opts, this.getImageElement(opts.image)); | ||
} | ||
throw Error(`Unkown particle shape: "${opts.shape}"`); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import particleFactory from './factories/particle'; | ||
import ParticleFactory from './factories/particle'; | ||
@@ -16,2 +16,3 @@ /** | ||
this.particleOptions = particleOptions; | ||
this.particleFactory = new ParticleFactory(); | ||
} | ||
@@ -46,3 +47,5 @@ | ||
} else { | ||
this.items.push(particleFactory(this.particleOptions).setup(this.particleOptions)); | ||
this.items.push( | ||
this.particleFactory.create(this.particleOptions).setup(this.particleOptions), | ||
); | ||
} | ||
@@ -49,0 +52,0 @@ } |
@@ -47,3 +47,3 @@ import getRandomNumber from '../utils/get-random-number'; | ||
this.d = getRandomNumber(150) + 10; // density | ||
this.r = getRandomNumber(this.size, this.size * 2); | ||
this.particleSize = getRandomNumber(this.size, this.size * 2); | ||
this.tilt = getRandomNumber(10); | ||
@@ -50,0 +50,0 @@ this.tiltAngleIncremental = ( |
@@ -12,5 +12,5 @@ import BaseParticle from './base'; | ||
super.draw(); | ||
this.canvas.ctx.arc(0, 0, (this.r / 2), 0, Math.PI * 2, false); | ||
this.canvas.ctx.arc(0, 0, (this.particleSize / 2), 0, Math.PI * 2, false); | ||
this.canvas.ctx.fill(); | ||
} | ||
} |
@@ -14,11 +14,11 @@ import BaseParticle from './base'; | ||
this.canvas.ctx.bezierCurveTo( | ||
cp1x * (this.r / 200), | ||
cp1y * (this.r / 200), | ||
cp2x * (this.r / 200), | ||
cp2y * (this.r / 200), | ||
x * (this.r / 200), | ||
y * (this.r / 200), | ||
cp1x * (this.particleSize / 200), | ||
cp1y * (this.particleSize / 200), | ||
cp2x * (this.particleSize / 200), | ||
cp2y * (this.particleSize / 200), | ||
x * (this.particleSize / 200), | ||
y * (this.particleSize / 200), | ||
); | ||
}; | ||
this.canvas.ctx.moveTo(37.5 / this.r, 20 / this.r); | ||
this.canvas.ctx.moveTo(37.5 / this.particleSize, 20 / this.particleSize); | ||
curveTo(75, 37, 70, 25, 50, 25); | ||
@@ -25,0 +25,0 @@ curveTo(20, 25, 20, 62.5, 20, 62.5); |
import CircleParticle from './circle'; | ||
import RectParticle from './rect'; | ||
import HeartParticle from './heart'; | ||
import ImageParticle from './image'; | ||
@@ -9,2 +10,3 @@ export { | ||
HeartParticle, | ||
ImageParticle, | ||
}; |
@@ -12,4 +12,4 @@ import BaseParticle from './base'; | ||
super.draw(); | ||
this.canvas.ctx.fillRect(0, 0, this.r, this.r / 2); | ||
this.canvas.ctx.fillRect(0, 0, this.particleSize, this.particleSize / 2); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39607
20
545
119
27