Packages

A drop-in replacement for notification system in Phoenix.

Retired package: Deprecated - Please use shino

Current section

Files

Jump to
phoenix_notif priv static phoenix_notif.min.js
Raw

priv/static/phoenix_notif.min.js

var PhoenixNotif=(()=>{var ot=Object.defineProperty;var Lt=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames;var Ut=Object.prototype.hasOwnProperty;var Bt=(t,e)=>{for(var r in e)ot(t,r,{get:e[r],enumerable:!0})},jt=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _t(e))!Ut.call(t,i)&&i!==r&&ot(t,i,{get:()=>e[i],enumerable:!(o=Lt(e,i))||o.enumerable});return t};var Gt=t=>jt(ot({},"__esModule",{value:!0}),t);var it=(t,e,r)=>new Promise((o,i)=>{var s=f=>{try{a(r.next(f))}catch(l){i(l)}},n=f=>{try{a(r.throw(f))}catch(l){i(l)}},a=f=>f.done?o(f.value):Promise.resolve(f.value).then(s,n);a((r=r.apply(t,e)).next())});var de={};Bt(de,{default:()=>kt});function nt(t,e){t.indexOf(e)===-1&&t.push(e)}var z=(t,e,r)=>Math.min(Math.max(r,t),e);var p={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"};var E=t=>typeof t=="number";var v=t=>Array.isArray(t)&&!E(t[0]);var yt=(t,e,r)=>{let o=e-t;return((r-t)%o+o)%o+t};function vt(t,e){return v(t)?t[yt(0,t.length,e)]:t}var Z=(t,e,r)=>-r*t+r*e+t;var k=()=>{},d=t=>t;var I=(t,e,r)=>e-t===0?1:(r-t)/(e-t);function st(t,e){let r=t[t.length-1];for(let o=1;o<=e;o++){let i=I(0,e,o);t.push(Z(r,1,i))}}function bt(t){let e=[0];return st(e,t-1),e}function at(t,e=bt(t.length),r=d){let o=t.length,i=o-e.length;return i>0&&st(e,i),s=>{let n=0;for(;n<o-2&&!(s<e[n+1]);n++);let a=z(0,1,I(e[n],e[n+1],s));return a=vt(r,n)(a),Z(t[n],t[n+1],a)}}var q=t=>Array.isArray(t)&&E(t[0]);var N=t=>typeof t=="object"&&!!t.createAnimation;var g=t=>typeof t=="function";var ct=t=>typeof t=="string";var T={ms:t=>t*1e3,s:t=>t/1e3};var St=(t,e,r)=>(((1-3*r+3*e)*t+(3*r-6*e))*t+3*e)*t,Wt=1e-7,Ht=12;function Kt(t,e,r,o,i){let s,n,a=0;do n=e+(r-e)/2,s=St(n,o,i)-t,s>0?r=n:e=n;while(Math.abs(s)>Wt&&++a<Ht);return n}function R(t,e,r,o){if(t===e&&r===o)return d;let i=s=>Kt(s,0,1,t,r);return s=>s===0||s===1?s:St(i(s),e,o)}var ft=(t,e="end")=>r=>{r=e==="end"?Math.min(r,.999):Math.max(r,.001);let o=r*t,i=e==="end"?Math.floor(o):Math.ceil(o);return z(0,1,i/t)};var Et={ease:R(.25,.1,.25,1),"ease-in":R(.42,0,1,1),"ease-in-out":R(.42,0,.58,1),"ease-out":R(0,0,.58,1)},Yt=/\((.*?)\)/;function mt(t){if(g(t))return t;if(q(t))return R(...t);if(Et[t])return Et[t];if(t.startsWith("steps")){let e=Yt.exec(t);if(e){let r=e[1].split(",");return ft(parseFloat(r[0]),r[1].trim())}}return d}var P=class{constructor(e,r=[0,1],{easing:o,duration:i=p.duration,delay:s=p.delay,endDelay:n=p.endDelay,repeat:a=p.repeat,offset:f,direction:l="normal",autoplay:b=!0}={}){if(this.startTime=null,this.rate=1,this.t=0,this.cancelTimestamp=null,this.easing=d,this.duration=0,this.totalDuration=0,this.repeat=0,this.playState="idle",this.finished=new Promise((c,S)=>{this.resolve=c,this.reject=S}),o=o||p.easing,N(o)){let c=o.createAnimation(r);o=c.easing,r=c.keyframes||r,i=c.duration||i}this.repeat=a,this.easing=v(o)?d:mt(o),this.updateDuration(i);let y=at(r,f,v(o)?o.map(mt):d);this.tick=c=>{var S;s=s;let h=0;this.pauseTime!==void 0?h=this.pauseTime:h=(c-this.startTime)*this.rate,this.t=h,h/=1e3,h=Math.max(h-s,0),this.playState==="finished"&&this.pauseTime===void 0&&(h=this.totalDuration);let $=h/this.duration,H=Math.floor($),w=$%1;!w&&$>=1&&(w=1),w===1&&H--;let K=H%2;(l==="reverse"||l==="alternate"&&K||l==="alternate-reverse"&&!K)&&(w=1-w);let V=h>=this.totalDuration?1:Math.min(w,1),M=y(this.easing(V));e(M),this.pauseTime===void 0&&(this.playState==="finished"||h>=this.totalDuration+n)?(this.playState="finished",(S=this.resolve)===null||S===void 0||S.call(this,M)):this.playState!=="idle"&&(this.frameRequestId=requestAnimationFrame(this.tick))},b&&this.play()}play(){let e=performance.now();this.playState="running",this.pauseTime!==void 0?this.startTime=e-this.pauseTime:this.startTime||(this.startTime=e),this.cancelTimestamp=this.startTime,this.pauseTime=void 0,this.frameRequestId=requestAnimationFrame(this.tick)}pause(){this.playState="paused",this.pauseTime=this.t}finish(){this.playState="finished",this.tick(0)}stop(){var e;this.playState="idle",this.frameRequestId!==void 0&&cancelAnimationFrame(this.frameRequestId),(e=this.reject)===null||e===void 0||e.call(this,!1)}cancel(){this.stop(),this.tick(this.cancelTimestamp)}reverse(){this.rate*=-1}commitStyles(){}updateDuration(e){this.duration=e,this.totalDuration=e*(this.repeat+1)}get currentTime(){return this.t}set currentTime(e){this.pauseTime!==void 0||this.rate===0?this.pauseTime=e:this.startTime=performance.now()-e/this.rate}get playbackRate(){return this.rate}set playbackRate(e){this.rate=e}};var ut=function(){};var L=class{setAnimation(e){this.animation=e,e==null||e.finished.then(()=>this.clearAnimation()).catch(()=>{})}clearAnimation(){this.animation=this.generator=void 0}};var lt=new WeakMap;function J(t){return lt.has(t)||lt.set(t,{transforms:[],values:new Map}),lt.get(t)}function wt(t,e){return t.has(e)||t.set(e,new L),t.get(e)}var Xt=["","X","Y","Z"],Zt=["translate","scale","rotate","skew"],_={x:"translateX",y:"translateY",z:"translateZ"},At={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},Jt={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:At,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:d},skew:At},O=new Map,tt=t=>`--motion-${t}`,Q=["x","y","z"];Zt.forEach(t=>{Xt.forEach(e=>{Q.push(t+e),O.set(tt(t+e),Jt[t])})});var Qt=(t,e)=>Q.indexOf(t)-Q.indexOf(e),te=new Set(Q),et=t=>te.has(t),Tt=(t,e)=>{_[e]&&(e=_[e]);let{transforms:r}=J(t);nt(r,e),t.style.transform=ee(r)},ee=t=>t.sort(Qt).reduce(re,"").trim(),re=(t,e)=>`${t} ${e}(var(${tt(e)}))`;var U=t=>t.startsWith("--"),Ot=new Set;function Dt(t){if(!Ot.has(t)){Ot.add(t);try{let{syntax:e,initialValue:r}=O.has(t)?O.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:r})}catch(e){}}}var pt=(t,e)=>document.createElement("div").animate(t,e),Ft={cssRegisterProperty:()=>typeof CSS!="undefined"&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{pt({opacity:[1]})}catch(t){return!1}return!0},finished:()=>!!pt({opacity:[0,1]},{duration:.001}).finished,linearEasing:()=>{try{pt({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0}},dt={},D={};for(let t in Ft)D[t]=()=>(dt[t]===void 0&&(dt[t]=Ft[t]()),dt[t]);var oe=.015,ie=(t,e)=>{let r="",o=Math.round(e/oe);for(let i=0;i<o;i++)r+=t(I(0,o-1,i))+", ";return r.substring(0,r.length-2)},ht=(t,e)=>g(t)?D.linearEasing()?`linear(${ie(t,e)})`:p.easing:q(t)?ne(t):t,ne=([t,e,r,o])=>`cubic-bezier(${t}, ${e}, ${r}, ${o})`;function It(t,e){for(let r=0;r<t.length;r++)t[r]===null&&(t[r]=r?t[r-1]:e());return t}var Rt=t=>Array.isArray(t)?t:[t];function B(t){return _[t]&&(t=_[t]),et(t)?tt(t):t}var j={get:(t,e)=>{e=B(e);let r=U(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!r&&r!==0){let o=O.get(e);o&&(r=o.initialValue)}return r},set:(t,e,r)=>{e=B(e),U(e)?t.style.setProperty(e,r):t.style[e]=r}};function rt(t,e=!0){if(!(!t||t.playState==="finished"))try{t.stop?t.stop():(e&&t.commitStyles(),t.cancel())}catch(r){}}function Pt(t,e){var r;let o=(e==null?void 0:e.toDefaultUnit)||d,i=t[t.length-1];if(ct(i)){let s=((r=i.match(/(-?[\d.]+)([a-z%]*)/))===null||r===void 0?void 0:r[2])||"";s&&(o=n=>n+s)}return o}function se(){return window.__MOTION_DEV_TOOLS_RECORD}function $t(t,e,r,o={},i){let s=se(),n=o.record!==!1&&s,a,{duration:f=p.duration,delay:l=p.delay,endDelay:b=p.endDelay,repeat:y=p.repeat,easing:c=p.easing,persist:S=!1,direction:h,offset:$,allowWebkitAcceleration:H=!1,autoplay:w=!0}=o,K=J(t),V=et(e),M=D.waapi();V&&Tt(t,e);let x=B(e),Y=wt(K.values,x),A=O.get(x);return rt(Y.animation,!(N(c)&&Y.generator)&&o.record!==!1),()=>{let X=()=>{var m,C;return(C=(m=j.get(t,x))!==null&&m!==void 0?m:A==null?void 0:A.initialValue)!==null&&C!==void 0?C:0},u=It(Rt(r),X),xt=Pt(u,A);if(N(c)){let m=c.createAnimation(u,e!=="opacity",X,x,Y);c=m.easing,u=m.keyframes||u,f=m.duration||f}if(U(x)&&(D.cssRegisterProperty()?Dt(x):M=!1),V&&!D.linearEasing()&&(g(c)||v(c)&&c.some(g))&&(M=!1),M){A&&(u=u.map(F=>E(F)?A.toDefaultUnit(F):F)),u.length===1&&(!D.partialKeyframes()||n)&&u.unshift(X());let m={delay:T.ms(l),duration:T.ms(f),endDelay:T.ms(b),easing:v(c)?void 0:ht(c,f),direction:h,iterations:y+1,fill:"both"};a=t.animate({[x]:u,offset:$,easing:v(c)?c.map(F=>ht(F,f)):void 0},m),a.finished||(a.finished=new Promise((F,qt)=>{a.onfinish=F,a.oncancel=qt}));let C=u[u.length-1];a.finished.then(()=>{S||(j.set(t,x,C),a.cancel())}).catch(k),H||(a.playbackRate=1.000001)}else if(i&&V)u=u.map(m=>typeof m=="string"?parseFloat(m):m),u.length===1&&u.unshift(parseFloat(X())),a=new i(m=>{j.set(t,x,xt?xt(m):m)},u,Object.assign(Object.assign({},o),{duration:f,easing:c}));else{let m=u[u.length-1];j.set(t,x,A&&E(m)?A.toDefaultUnit(m):m)}return n&&s(t,e,u,{duration:f,delay:l,easing:c,repeat:y,offset:$},"motion-one"),Y.setAnimation(a),a&&!w&&a.pause(),a}}var Mt=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):Object.assign({},t);function Nt(t,e){var r;return typeof t=="string"?e?((r=e[t])!==null&&r!==void 0||(e[t]=document.querySelectorAll(t)),t=e[t]):t=document.querySelectorAll(t):t instanceof Element&&(t=[t]),Array.from(t||[])}var ae=t=>t(),G=(t,e,r=p.duration)=>new Proxy({animations:t.map(ae).filter(Boolean),duration:r,options:e},fe),ce=t=>t.animations[0],fe={get:(t,e)=>{let r=ce(t);switch(e){case"duration":return t.duration;case"currentTime":return T.s((r==null?void 0:r[e])||0);case"playbackRate":case"playState":return r==null?void 0:r[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(me)).catch(k)),t.finished;case"stop":return()=>{t.animations.forEach(o=>rt(o))};case"forEachNative":return o=>{t.animations.forEach(i=>o(i,t))};default:return typeof(r==null?void 0:r[e])=="undefined"?void 0:()=>t.animations.forEach(o=>o[e]())}},set:(t,e,r)=>{switch(e){case"currentTime":r=T.ms(r);case"playbackRate":for(let o=0;o<t.animations.length;o++)t.animations[o][e]=r;return!0}return!1}},me=t=>t.finished;function Vt(t,e,r){return g(t)?t(e,r):t}function Ct(t){return function(r,o,i={}){r=Nt(r);let s=r.length;ut(!!s,"No valid element provided."),ut(!!o,"No keyframes defined.");let n=[];for(let a=0;a<s;a++){let f=r[a];for(let l in o){let b=Mt(i,l);b.delay=Vt(b.delay,a,s);let y=$t(f,l,o[l],b,t);n.push(y)}}return G(n,i,i.duration)}}var gt=Ct(P);function ue(t,e={}){return G([()=>{let r=new P(t,[0,1],e);return r.finished.catch(()=>{}),r}],e,e.duration)}function W(t,e,r){return(g(t)?ue:gt)(t,e,r)}function le(t){return t===null?!0:t.offsetParent===null}function zt(t,e,{gapBetweenNotifications:r=15,maxShownNotifications:o=3}={}){let i=document.querySelector(`#${t}`),s=Array.from(i.querySelectorAll('[phx-hook="PhoenixNotif"]')).filter(n=>!le(n)).filter(n=>n!==e).reverse().map((n,a)=>(n.new=n.order==null,n.order=a,n));for(let n of s){n.order>=o?n.classList.remove("pointer-events-auto"):n.classList.add("pointer-events-auto"),n.style.zIndex=`${49-n.order}`;let a=i.dataset.position.startsWith("bottom_")?"-":"",f=0;for(let c=0;c<n.order;c++)f+=s[c].offsetHeight+r;let l=`${a}${f}`;n.targetY=l;let b=n.order>=o?0:1,y={y:[`${l}px`],opacity:[b]};if(n.new){let c=n.offsetHeight+r,S=a==="-"?"":"-";y.y.unshift(`${S}${c}px`),y.opacity.unshift(0)}W(n,y,{duration:.55,easing:[.22,1,.36,1]})}}function pe(t,e){return it(this,null,function*(){let o=document.querySelector(`#${t}`).dataset.position.startsWith("bottom_")?"-":"",i=e.order>0?Math.abs(Math.abs(e.targetY)-e.offsetHeight):0;console.log(i),yield W(e,{y:`${o}${i}px`,opacity:0},{y:{duration:.3,easing:"ease-out"},opacity:{duration:.2,easing:"ease-out"}}).finished})}function kt(t){return{mounted(){let e=this.type(),r=this.groupId(),o=this.duration();this.el.addEventListener("notification-dismiss",i=>it(this,null,function*(){switch(i.stopPropagation(),zt(r,this.el,t),yield pe(r,this.el),e){case"flash":this.el.remove();break;case"lv-flash":this.el.remove();let s=this.kind();this.pushEvent("lv:clear-flash",{key:s});break;case"lv-toast":this.el.remove(),this.pushEventTo(`#${this.groupId()}`,"clear-toast",{id:this.el.id});break;default:throw`unknown notification type - ${e}`}})),zt(r,null,t),o>0&&window.setTimeout(()=>{let i=new Event("notification-dismiss");this.el.dispatchEvent(i)},o)},updated(){let e={y:[`${this.el.targetY}px`]};W(this.el,e,{duration:0})},type(){return this.el.dataset.type},kind(){return this.el.dataset.kind},groupId(){return this.el.dataset.groupId},duration(){return Number.parseInt(this.el.dataset.duration)}}}return Gt(de);})();