js-confetti
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -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.jsConfetti=e():t.jsConfetti=e()}(self,(function(){return(()=>{"use strict";var t={276:(t,e,i)=>{function n(t){return+t.replace(/px/,"")}function r(t,e){return Math.floor(Math.random()*(e-t+1))+t}i.r(e),i.d(e,{default:()=>h});var o=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc9003"];function s(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function a(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?s(Object(i),!0).forEach((function(e){c(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):s(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function c(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function u(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var l=function(){function t(e,i){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var n=.1*r(500,900)/100;this.speed={x:n,y:n},this.rotationSpeed=.01*r(3,10),this.radius={x:10,y:10},this.radiusYUpdateDirection="down",this.angle="left"===i?r(-140,0)*Math.PI/180:r(0,-140)*Math.PI/180,this.currentPosition=a({},e),this.initialPosition=a({},e),this.color=o[r(0,o.length-1)],this.createdAt=(new Date).getTime()}var e,i;return e=t,(i=[{key:"draw",value:function(t){var e=this.currentPosition,i=this.radius,n=this.color,r=window.devicePixelRatio;t.fillStyle=n,t.beginPath(),t.ellipse(e.x*r,e.y*r,i.x*r,i.y*r,0,0,2*Math.PI),t.fill()}},{key:"updatePosition",value:function(t,e){var i=this.speed,n=this.angle,r=this.radiusYUpdateDirection,o=this.rotationSpeed,s=e-this.createdAt;i.x>1e-4&&(this.speed.x-=25e-5*t),this.currentPosition.x+=i.x*Math.cos(n)*t,this.currentPosition.y=this.initialPosition.y+i.y*Math.sin(n)*s+6e-4*Math.pow(s,2)/2,"down"===r?(this.radius.y-=t*o,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=t*o,this.radius.y>=10&&(this.radius.y=10,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(t){return this.currentPosition.y<t+100}}])&&u(e.prototype,i),t}();function f(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}const h=function(){function t(){var e,i=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.canvas=((e=document.createElement("canvas")).style.position="fixed",e.style.width="100%",e.style.height="100%",e.style.top="0",e.style.left="0",e.style.zIndex="1000",e.style.pointerEvents="none",document.body.appendChild(e),e),this.canvasContext=this.canvas.getContext("2d"),this.shapes=[],this.lastUpdated=(new Date).getTime(),setTimeout((function(){return i.loop.call(i,0)}),0)}var e,i;return e=t,(i=[{key:"loop",value:function(t){var e,i,r,o,s,a=this;e=this.canvas,i=window.devicePixelRatio,o=n((r=getComputedStyle(e)).getPropertyValue("width")),s=n(r.getPropertyValue("height")),e.setAttribute("width",(o*i).toString()),e.setAttribute("height",(s*i).toString());var c=(new Date).getTime(),u=c-this.lastUpdated,l=this.canvas.offsetHeight;this.shapes.forEach((function(t){t.updatePosition(u,c),t.draw(a.canvasContext)})),t%100==0&&(this.shapes=this.shapes.filter((function(t){return t.getIsVisibleOnCanvas(l)}))),this.lastUpdated=c,setTimeout((function(){return a.loop.call(a,++t)}),0)}},{key:"addConfetti",value:function(){for(var t=5*window.innerHeight/7,e={x:0,y:t},i={x:window.innerWidth,y:t},n=0;n<100;n++)this.shapes.push(new l(e,"right")),this.shapes.push(new l(i,"left"))}}])&&f(e.prototype,i),t}()}},e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={exports:{}};return t[n](r,r.exports,i),r.exports}return i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i(276)})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jsConfetti=e():t.jsConfetti=e()}(self,(function(){return(()=>{"use strict";var t={525:(t,e,i)=>{function n(t){return+t.replace(/px/,"")}function o(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=Math.random()*(e-t)+t;return Math.floor(n*Math.pow(10,i))/Math.pow(10,i)}i.r(e),i.d(e,{default:()=>l});var r=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc9003"];function s(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function a(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?s(Object(i),!0).forEach((function(e){c(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):s(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function c(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function h(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var u=function(){function t(e,i){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var n=o(.9,1.7,3)*(Math.log(window.innerWidth)/Math.log(1920));this.confettiSpeed={x:n,y:n},this.rotationSpeed=o(.03,.1,3),this.radius={x:10,y:10},this.radiusYUpdateDirection="down";var s="left"===i?o(82,15)*Math.PI/180:o(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(s)),this.absSin=Math.abs(Math.sin(s));var c=o(-150,0),h={x:e.x+("left"===i?-c:c)*this.absCos,y:e.y-c*this.absSin};this.currentPosition=a({},h),this.initialPosition=a({},h),this.color=r[o(0,r.length)],this.createdAt=(new Date).getTime(),this.direction=i}var e,i;return e=t,(i=[{key:"draw",value:function(t){var e=this.currentPosition,i=this.radius,n=this.color,o=window.devicePixelRatio;t.fillStyle=n,t.beginPath(),t.ellipse(e.x*o,e.y*o,i.x*o,i.y*o,0,0,2*Math.PI),t.fill()}},{key:"updatePosition",value:function(t,e,i){var n=this.confettiSpeed,o=this.radiusYUpdateDirection,r=this.rotationSpeed,s=this.createdAt,a=this.direction,c=e-s;this.rotationSpeed-=1e-5*t,this.rotationSpeed<0&&(this.rotationSpeed=0);var h="left"===a?this.currentPosition.x>=0:this.currentPosition.x<=i;h&&n.x>1e-4&&(this.confettiSpeed.x-=8e-4*t),this.currentPosition.x+=n.x*("left"===a?-this.absCos:this.absCos)*t,this.currentPosition.y=this.initialPosition.y-n.y*this.absSin*c+(h?.00125*Math.pow(c,2)/2:0),"down"===o?(this.radius.y-=t*r,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=t*r,this.radius.y>=10&&(this.radius.y=10,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(t){return this.currentPosition.y<t+100}}])&&h(e.prototype,i),t}();function f(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}const l=function(){function t(){var e,i=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.canvas=((e=document.createElement("canvas")).style.position="fixed",e.style.width="100%",e.style.height="100%",e.style.top="0",e.style.left="0",e.style.zIndex="1000",e.style.pointerEvents="none",document.body.appendChild(e),e),this.canvasContext=this.canvas.getContext("2d"),this.shapes=[],this.lastUpdated=(new Date).getTime(),setTimeout((function(){return i.loop.call(i,0)}),0)}var e,i;return e=t,(i=[{key:"loop",value:function(t){var e,i,o,r,s,a=this;e=this.canvas,i=window.devicePixelRatio,r=n((o=getComputedStyle(e)).getPropertyValue("width")),s=n(o.getPropertyValue("height")),e.setAttribute("width",(r*i).toString()),e.setAttribute("height",(s*i).toString());var c=(new Date).getTime(),h=c-this.lastUpdated,u=this.canvas.offsetHeight,f=this.canvas.offsetWidth;this.shapes.forEach((function(t){t.updatePosition(h,c,f),t.draw(a.canvasContext)})),t%100==0&&(this.shapes=this.shapes.filter((function(t){return t.getIsVisibleOnCanvas(u)}))),this.lastUpdated=c,setTimeout((function(){return a.loop.call(a,++t)}),0)}},{key:"addConfetti",value:function(){for(var t=5*window.innerHeight/7,e={x:0,y:t},i={x:window.innerWidth,y:t},n=0;n<100;n++)this.shapes.push(new u(e,"right")),this.shapes.push(new u(i,"left"))}}])&&f(e.prototype,i),t}()}},e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}return i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i(525)})()})); |
{ | ||
"name": "js-confetti", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "js-confetti", |
@@ -10,4 +10,2 @@ # js-confetti | ||
NPM: https://www.npmjs.com/package/js-confetti | ||
## Usage | ||
@@ -14,0 +12,0 @@ |
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
7235
31