UNPKG

konami-emoji-blast

Version:

Hooks up konami-code-js to trigger emoji-blast. ๐ŸŽ‡

2 lines โ€ข 9.66 kB
/*! For license information please see global.js.LICENSE.txt */ (()=>{var e={635:function(e,t,n){var o,i,s,r,c;i=this||globalThis,s=function e(t){var n=this,o={},i=e;i.getNumberOfInstance=function(){return i._numberOfInstance},n.enable=function(){return o.listenCodeCharSequence(),o.listenCodeGestureSequence(),o.debug&&o.debug("Listener enabled for all."),n},n.enableKeyboardKeys=function(){return o.listenCodeCharSequence(),o.debug&&o.debug("Listener enabled for Keyboard Keys."),n},n.enableTouchGesture=function(){return o.listenCodeGestureSequence(),o.debug&&o.debug("Listener enabled for Touch Gesture."),n},n.disable=function(){return o.stopCodeCharSequence(),o.stopCodeGestureSequence(),o.debug&&o.debug("Listener disabled for all."),n},n.disableKeyboardKeys=function(){return o.stopCodeCharSequence(),o.debug&&o.debug("Listener disabled for Keyboard Keys."),n},n.disableTouchGesture=function(){return o.stopCodeGestureSequence(),o.debug&&o.debug("Listener disabled for Touch Gesture."),n},n.setListener=function(e){return o.stopCodeCharSequence(),o.stopCodeGestureSequence(),o.listener=e||document,o.listenCodeCharSequence(),o.listenCodeGestureSequence(),o.debug&&o.debug("Listener changed.",e),n},n.setCallback=function(e){return o.afterCodeSequenceCallback="function"==typeof e&&e||o.defaultCallback,o.debug&&o.debug("Callback changed.",e),n},n.setOptions=function(e){return o.initOptions(e),n},o.keptLastCodeChar=function(){o.input.length>o.konamiCodeChar.length&&(o.input=o.input.substr(o.input.length-o.konamiCodeChar.length))},o.defaultCallback=function(){o.debug&&o.debug("Konami Code Sequence Entered. There is no action defined.")},o.checkIfCodeCharIsValid=function(){o.input===o.konamiCodeChar&&o.afterCodeSequenceCallback(n)},o.codeSequenceEventKeyDown=function(e){o.input+=e.keyCode,o.keptLastCodeChar(),o.checkIfCodeCharIsValid()},o.codeSequenceEventTouchMove=function(e){var t;1===e.touches.length&&!0===o.capture&&(t=e.touches[0],o.stopX=t.pageX,o.stopY=t.pageY,o.tap=!1,o.capture=!1,o.checkIfCodeGestureIsValid())},o.codeSequenceEventTouchEnd=function(){!0===o.tap&&o.checkIfCodeGestureIsValid()},o.codeSequenceEventTouchStart=function(e){o.startX=e.changedTouches[0].pageX,o.startY=e.changedTouches[0].pageY,o.tap=!0,o.capture=!0},o.stopCodeCharSequence=function(){o.listener.removeEventListener("keydown",o.codeSequenceEventKeyDown)},o.stopCodeGestureSequence=function(){o.listener.removeEventListener("touchstart",o.codeSequenceEventTouchStart),o.listener.removeEventListener("touchmove",o.codeSequenceEventTouchMove),o.listener.removeEventListener("touchend",o.codeSequenceEventTouchEnd)},o.listenCodeCharSequence=function(){o.stopCodeCharSequence(),o.listener.addEventListener("keydown",o.codeSequenceEventKeyDown)},o.listenCodeGestureSequence=function(){o.originalCodeGesture=o.konamiCodeGesture,o.stopCodeGestureSequence(),o.listener.addEventListener("touchstart",o.codeSequenceEventTouchStart),o.listener.addEventListener("touchmove",o.codeSequenceEventTouchMove),o.listener.addEventListener("touchend",o.codeSequenceEventTouchEnd,!1)},o.checkIfCodeGestureIsValid=function(){var e=Math.abs(o.startX-o.stopX),t=Math.abs(o.startY-o.stopY),i=o.startX-o.stopX<0?"rt":"lt",s=o.startY-o.stopY<0?"dn":"up",r=e>t?i:s;(r=!0===o.tap?"tp":r)===o.konamiCodeGesture.substr(0,2)?o.konamiCodeGesture=o.konamiCodeGesture.substr(2,o.konamiCodeGesture.length-2):o.konamiCodeGesture=o.originalCodeGesture,0===o.konamiCodeGesture.length&&(o.konamiCodeGesture=o.originalCodeGesture,o.afterCodeSequenceCallback(n))},o.checkDebugMode=function(e){e&&!0===e.debug?(o.debug=function(e,t){void 0!==t?console.log(e,t):console.log(e)},o.debug&&o.debug("Debug Mode On.")):o.debug=!1},o.initOptions=function(e){o.checkDebugMode(e),o.listener=e&&e.listener||document,o.afterCodeSequenceCallback="function"==typeof e&&e||e&&"function"==typeof e.callback&&e.callback||o.defaultCallback},o.init=function(){o.input="",o.konamiCodeChar="38384040373937396665",o.konamiCodeGesture="upupdndnltrtltrttptp",o.startX=0,o.startY=0,o.stopX=0,o.stopY=0,o.tap=!1,o.capture=!1,i._numberOfInstance=i._numberOfInstance?i._numberOfInstance+1:1,o.initOptions(t),o.listenCodeCharSequence(),o.listenCodeGestureSequence()},o.init()},r=i.KonamiCode,(c=i.KonamiCode=s).noConflict=function(){return i.KonamiCode=r,c},void 0===(o=function(){return s}.call(t,n,t,e))||(e.exports=o),e.exports&&(e.exports=s)}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=e=>"number"==typeof e?e:Math.floor(Math.random()*(e.max-e.min+1))+e.min,t=e=>"function"==typeof e?e():e,o=e=>{const t=e.slice();for(let e=t.length-1;e>0;e-=1){const n=Math.floor(Math.random()*(e+1)),o=t[e];t[e]=t[n],t[n]=o}return t};class i{#e=1;#t;#n;#o;element;constructor(t){var n;this.element=document.createElement("button"),this.element.className=t.className,this.element.textContent=(n=t.emojis)[Math.floor(Math.random()*n.length)],this.element.setAttribute("role","img"),this.element.style.fontSize=`${e(t.physics.fontSize)}px`,this.element.style.transition="16ms opacity, 16ms transform",this.#t=t.physics,this.#n={rotation:e(t.physics.rotation),x:t.position.x,y:t.position.y},this.#o={rotation:e(t.physics.initialVelocities.rotation),x:e(t.physics.initialVelocities.x),y:e(t.physics.initialVelocities.y)},this.updateElement(),t.process?.(this.element),t.container.appendChild(this.element)}updateElement(){this.element.style.opacity=`${this.#e}`,this.element.style.transform=`translate(${this.#n.x}px, ${this.#n.y}px) rotate(${Math.round(this.#n.rotation)}deg)`}act(e){if(this.#t.opacityDecay&&(this.#e-=e/(this.#t.opacityDecay*this.#t.framerate),this.#e<=0))return!0;this.#o.rotation*=this.#t.rotationDeceleration,this.#o.y+=this.#t.gravity,this.#n.rotation+=this.#o.rotation,this.#n.x+=this.#o.x*e/this.#t.framerate,this.#n.y+=this.#o.y*e/this.#t.framerate;const t=window.outerHeight||document.documentElement.clientHeight,n=window.outerWidth||document.documentElement.clientWidth;if(!this.#t.preserveOutOfBounds){if(this.#n.y-this.element.clientHeight>t+350)return!0;if(this.#n.y+this.element.clientHeight<-350)return!0;if(this.#n.x-this.element.clientWidth>n+350)return!0;if(this.#n.x+this.element.clientWidth<-350)return!0}return this.updateElement(),!1}dispose(){null!==this.element.parentElement&&this.element.parentElement.removeChild(this.element)}update(e){void 0!==e.opacity&&(this.#e=e.opacity),void 0!==e.velocity&&(void 0!==e.velocity.rotation&&(this.#o.rotation=e.velocity.rotation),void 0!==e.velocity.x&&(this.#o.x=e.velocity.x),void 0!==e.velocity.y&&(this.#o.y=e.velocity.y))}get opacity(){return this.#e}get position(){return this.#n}get velocity(){return this.#o}}const s=["๐Ÿ˜","๐Ÿ˜‚","๐Ÿคฃ","๐Ÿ˜ƒ","๐Ÿ˜†","๐Ÿ˜","๐Ÿคฉ","๐Ÿ˜Ž","๐Ÿค—","๐Ÿฅณ","๐Ÿค–","๐Ÿ˜ป","๐Ÿ˜น","๐Ÿฑ","๐Ÿถ","๐Ÿ™ˆ","๐Ÿ™‰","๐Ÿ™Š","๐Ÿ„","๐Ÿ’ช","๐Ÿ‘Œ","๐Ÿ‘‹","๐Ÿ™Œ","๐Ÿซถ","๐Ÿ’","๐Ÿ’–","๐Ÿ’—","๐Ÿงก","๐Ÿ’›","๐Ÿ’š","๐Ÿ’™","๐Ÿ’œ","โค๏ธโ€๐Ÿ”ฅ","๐Ÿ”ฅ","๐Ÿš€","โ›„","๐Ÿฆฉ","๐Ÿ","๐Ÿ’","๐Ÿฆพ","โœจ","๐ŸŽ‰","๐Ÿ’ฏ"],r="data-emoji-blast-events-initialized",c=new WeakMap,a=new Set,u="emoji-styles",l=(()=>{let e;return()=>(e?.parentNode===document.body||(e=document.createElement("div"),document.body.prepend(e)),e)})(),d=()=>Math.floor(14*Math.random())+14,h={onClick({actor:e}){e.update({opacity:1,velocity:{y:e.velocity.y/2-15}})}},p={fontSize:{max:28,min:14},framerate:60,gravity:.35,initialVelocities:{rotation:{max:7,min:-7},x:{max:7,min:-7},y:{max:-7,min:-21}},preserveOutOfBounds:!1,rotation:{max:45,min:-45},rotationDeceleration:.98},m=()=>({x:Math.random()*innerWidth,y:Math.random()*innerHeight}),y=()=>700+Math.floor(1401*Math.random());var f=n(635);const C=n.n(f)()??f;window.initializeKonamiEmojiBlast=e=>{let n;const f=new C((()=>{n?(n.cancel(),n=void 0):(n=((e={})=>{const{interval:n=y,scheduler:f=setTimeout}=e;let C=!1;const v=()=>{((e={})=>{const{className:n=u,container:y=l,emojiCount:f=d,emojis:C=s,events:v=h,position:b=m,process:g,tick:S,uniqueness:k=1/0}=e,q=t(y);(e=>{if(a.has(e))return;a.add(e);const t=document.createElement("style");t.setAttribute("type","text/css"),t.appendChild(document.createTextNode(`\n\t\t.${e} {\n\t\t\tbackground: none;\n\t\t\tborder: none;\n\t\t\tcursor: default;\n\t\t\theight: 2em;\n\t\t\tmargin-left: -1em;\n\t\t\tmargin-top: -1em;\n\t\t\tposition: fixed;\n\t\t\tuser-select: none;\n\t\t\twidth: 2em;\n\t\t\tz-index: 2147483647;\n\t\t}\n\t`)),document.head.appendChild(t)})(n);const x={...p,...e.physics,initialVelocities:{...p.initialVelocities,...void 0!==e.physics?e.physics.initialVelocities:{}}},E={className:n,container:q,emojis:o(t(C)).slice(0,t(k)),physics:x,position:t(b),process:g},G=t(f),M=[];for(let e=0;e<G;e+=1)M.push(new i(E));(function(e,t,n){for(const t of e)c.set(t.element,t);t.hasAttribute(r)||(t.setAttribute(r,"true"),t.addEventListener("click",(e=>{const t=e.target&&c.get(e.target);t&&n.onClick({actor:t,event:e})})))})(M,q,v),function(e,t){let n=performance.now(),o=!1;const i=()=>{o=!0};if(t?.(e),o)return{stop:i};const s=i=>{if(o)return;if(t?.(e),0===e.length)return;const r=i-n;for(let t=0;t<e.length;t+=1){const n=e[t];n.act(r)&&(n.dispose(),e.splice(t,1),t-=1)}0!==e.length&&(n=i,o||requestAnimationFrame(s))};requestAnimationFrame(s)}(M,S)})(e)},b=()=>{C||("visible"===document.visibilityState&&v(),f(b,t(n)))};return f(b,0),{blast:v,cancel(){C=!0}}})(),e?.())}));return()=>{n?.cancel(),f.disable()}}})()})();