Current section

Files

Jump to
shino priv static notification.cjs
Raw

priv/static/notification.cjs

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