konami-emoji-blast
Version:
Hooks up konami-code-js to trigger emoji-blast. ๐
2 lines โข 11.3 kB
JavaScript
/*! For license information please see global.js.LICENSE.txt */
(()=>{var e={635(e,t,n){var o,i,s,r,a;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,(a=i.KonamiCode=s).noConflict=function(){return i.KonamiCode=r,a},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;#i;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.#i=e(t.physics.gravity),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.#i,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)),void 0!==e.position&&(void 0!==e.position.rotation&&(this.#n.rotation=e.position.rotation),void 0!==e.position.x&&(this.#n.x=e.position.x),void 0!==e.position.y&&(this.#n.y=e.position.y)),void 0!==e.gravity&&(this.#i=e.gravity)}get opacity(){return this.#e}get position(){return this.#n}get gravity(){return this.#i}get velocity(){return this.#o}}const s=["๐","๐","๐คฃ","๐","๐","๐","๐คฉ","๐","๐ค","๐ฅณ","๐ค","๐ป","๐น","๐ฑ","๐ถ","๐","๐","๐","๐","๐ช","๐","๐","๐","๐ซถ","๐","๐","๐","๐งก","๐","๐","๐","๐","โค๏ธโ๐ฅ","๐ฅ","๐","โ","๐ฆฉ","๐","๐","๐ฆพ","โจ","๐","๐ฏ"],r="data-emoji-blast-events-initialized",a=new WeakMap,c=e=>t=>{const n=t.target&&a.get(t.target);n&&e?.({actor:n,event:t})},u=(e,t)=>e*.75**t,d=(e,[t,n])=>Math.max(Math.min(n,e),t),l=(()=>{let e,t;const n=({clientX:t,clientY:n})=>{if(!e)return;const{actor:o,lastPosition:i}=e,s=t-i.x,r=n-i.y;o.update({position:{x:o.position.x+s,y:o.position.y+r}}),e.lastPosition={x:t,y:n}},o=()=>{if(!e)return;clearInterval(t);const{samplePoints:i}=e,s=[...i].reverse().map(({x:e,y:t},n)=>({x:u(e,n),y:u(t,n)})).reduce((e,t)=>({x:e.x+t.x,y:e.y+t.y}),{x:0,y:0}),r=s.x/i.length*75,a=s.y/i.length*75;e.actor.update({gravity:e.gravity,velocity:{x:d(r,[-50,50]),y:d(a,[-50,50])}}),e.actor.element.style.cursor="grab",e=void 0,document.removeEventListener("pointermove",n),document.removeEventListener("pointerup",o)};return{onPointerdown({actor:i,event:s}){if(e)return;const{clientX:r,clientY:a}=s,c={x:r,y:a};e={actor:i,gravity:i.gravity,lastPosition:c,samplePoints:[]},i.update({gravity:0,velocity:{x:0,y:0}}),i.element.style.cursor="grabbing",document.addEventListener("pointermove",n),document.addEventListener("pointerup",o);let u=c;t=setInterval(()=>{if(!e)return;const t={...e.actor.position},n=Math.round(t.x-u.x),o=Math.round(t.y-u.y);e.samplePoints.push({x:n,y:o}),u=t},5)}}})(),h=(...e)=>(...t)=>{e.filter(Boolean).forEach(e=>{e(...t)})},p=new Set,m="emoji-styles",y=(()=>{let e;return()=>(e?.parentNode===document.body||(e=document.createElement("div"),document.body.prepend(e)),e)})(),v=()=>Math.floor(14*Math.random())+14,f={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},g=()=>({x:Math.random()*innerWidth,y:Math.random()*innerHeight}),C=()=>700+Math.floor(1401*Math.random());var b=n(635);const x=n.n(b)()??b;window.initializeKonamiEmojiBlast=e=>{const{emojiBlastSettings:n,onKonamiCodeActivated:u}="function"==typeof e?{emojiBlastSettings:void 0,onKonamiCodeActivated:e}:e??{};let d;const b=new x(()=>{d?(d.cancel(),d=void 0):(d=((e={})=>{const{interval:n=C,scheduler:u=setTimeout}=e;let d=!1;const b=()=>{((e={})=>{const{className:n=m,container:u=y,emojiCount:d=v,emojis:C=s,events:b={},position:x=g,process:S,tick:k,uniqueness:E=1/0}=e,q=t(u);(e=>{if(p.has(e))return;p.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: grab;\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 G={...f,...e.physics,initialVelocities:{...f.initialVelocities,...void 0!==e.physics?e.physics.initialVelocities:{}}},M={className:n,container:q,emojis:o(t(C)).slice(0,t(E)),physics:G,position:t(x),process:S},L=t(d),w=[];for(let e=0;e<L;e+=1)w.push(new i(M));var T,K;(function(e,t,n){for(const t of e)a.set(t.element,t);t.hasAttribute(r)||(t.setAttribute(r,"true"),t.addEventListener("click",c(n.onClick)),t.addEventListener("pointerdown",c(n.onPointerdown)))})(w,q,(T=b,K=l,Object.keys({...T,...K}).reduce((e,t)=>({...e,[t]:h(T[t],K[t])}),{}))),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)}(w,k)})(e)},x=()=>{d||("visible"===document.visibilityState&&b(),u(x,t(n)))};return u(x,0),{blast:b,cancel(){d=!0}}})(n),u?.())});return()=>{d?.cancel(),b.disable()}}})()})();