(function(g){"use strict";var _=Object.defineProperty,$=Object.defineProperties,C=Object.getOwnPropertyDescriptors,p=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,y=(t,e,n)=>e in t?_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,d=(t,e)=>{for(var n in e||(e={}))P.call(e,n)&&y(t,n,e[n]);if(p)for(var n of p(e))G.call(e,n)&&y(t,n,e[n]);return t},M=(t,e)=>$(t,C(e));const v=(t="always")=>({playMode:t,createContainers:!0,hideOverflow:!1,timing:t==="always"?{duration:2*1e3,iterations:1/0}:{duration:250,iterations:1},glitchTimeSpan:t==="always"?{start:.5,end:.7}:{start:0,end:1},shake:{velocity:15,amplitudeX:.2,amplitudeY:.2},slice:t==="click"?{count:15,velocity:20,minHeight:.02,maxHeight:.15,hueRotate:!0}:{count:6,velocity:15,minHeight:.02,maxHeight:.15,hueRotate:!0},pulse:!1}),w=(t,e)=>{if(!t.glitchTimeSpan)return 1;const n=t.glitchTimeSpan.start,r=t.glitchTimeSpan.end;if(er)return 0;const a=n+(r-n)/2;return e(Math.random()-.5)*2*w(t,e),O=({minHeight:t,maxHeight:e,minWidth:n,maxWidth:r})=>{const a=Math.floor(Math.random()*((e-t)*100+1))+t*100,s=Math.floor(Math.random()*((r-n)*100+1))+n*100,i=Math.floor(Math.random()*(100-a)),c=Math.floor(Math.random()*(100-s)),h=`${c+s}% ${i}%`,l=`${c+s}% ${i+a}%`,o=`${c}% ${i+a}%`,f=`${c}% ${i}%`;return`polygon(${h},${l},${o},${f})`},b=t=>{const e=Math.floor(t.slice.velocity*t.timing.duration/1e3)+1,n=[];for(let r=0;rt.pulse?{steps:[{transform:"scale(1)",opacity:"1"},{transform:`scale(${t.pulse.scale})`,opacity:"0"}],timing:M(d({},t.timing),{delay:(t.glitchTimeSpan?t.glitchTimeSpan.start:0)*t.timing.duration,easing:"ease-in-out"})}:null,L=t=>{if(!t.shake)return{steps:[],timing:{}};const e=Math.floor(t.shake.velocity*t.timing.duration/1e3)+1,n=[];for(let r=0;r[L(t),A(t),...Array.from({length:t.slice.count}).map(()=>b(t))].filter(e=>e!==null),m=(...t)=>{const e=n=>n&&typeof n=="object";return t.reduce((n,r)=>(Object.keys(r).forEach(a=>{e(n[a])&&e(r[a])?n[a]=m(n[a],r[a]):r[a]!==void 0&&(n[a]=r[a])}),n),{})},H=(t,e)=>{var n,r;if(!e.createContainers)return{container:t,layersContainer:t,glitched:t.firstElementChild};if(!t.dataset.glitched){const i=document.createElement("div"),c=document.createElement("div");return getComputedStyle(t).getPropertyValue("display").match(/^inline/)&&(c.style.display="inline-block"),c.appendChild(i),(n=t.parentElement)==null||n.insertBefore(c,t),i.prepend(t),{container:c,layersContainer:i,glitched:t}}const a=t.parentElement,s=(r=t.parentElement)==null?void 0:r.parentElement;for(;a.children.length>1;)a.removeChild(a.children[1]);return a.firstElementChild.getAnimations().forEach(i=>i.cancel()),{container:s,layersContainer:a,glitched:t}},R=(t,e,n)=>{const{glitched:r,container:a,layersContainer:s}=H(t,n);s.style.display="grid",n.hideOverflow&&(a.style.overflow="hidden"),n.html&&(r.innerHTML=n.html),r.style.gridArea="1/1/-1/-1";const i=r.cloneNode(!0);i.style.gridArea="1/1/-1/-1",i.style.userSelect="none",i.style.pointerEvents="none",i.style.opacity="0";for(let l=0;l{e.forEach((l,o)=>{s.children[o].animate(l.steps,l.timing)})},h=()=>{e.forEach((l,o)=>{s.children[o].getAnimations().forEach(f=>{f.cancel()})})};switch(a.onmouseenter=null,a.onmouseleave=null,a.onclick=null,n.playMode){case"always":c();break;case"hover":a.onmouseenter=c,a.onmouseleave=h;break;case"click":a.onclick=()=>{h(),c()};break}return t.dataset.glitched="1",{container:a,startGlitch:c,stopGlitch:h}},T={glitch:(t=".powerglitch",e={})=>{const n=m(v(e.playMode),e);let r=[];typeof t=="string"?r=Array.from(document.querySelectorAll(t)):t instanceof NodeList?r=Array.from(t):Array.isArray(t)?r=t:t instanceof HTMLElement&&(r=[t]);const a=E(n),s=r.map(i=>R(i,a,n));return{containers:s.map(i=>i.container),startGlitch:()=>s.forEach(i=>i.startGlitch()),stopGlitch:()=>s.forEach(i=>i.stopGlitch())}},generateLayers:E,getDefaultOptions:v};g.PowerGlitch=T,g.mergeOptions=m})(this.window=this.window||{});