Build 574548stable
Module 57019
2,966 characters · in no known chunkDependencies
Source Raw
function(e,t,n){"use strict";n.d(t,{Fn:()=>h,Gt:()=>f,Ru:()=>m});var i=n(64700),r=n(717421),s=n(518009),a=n(626584),o=n(567249),l=n(287809),u=n(531685),c=n(365971),d=n(392164);let _=new a.A("NotificationLayoutManager");class h{resizeObserver;listeners=new Map;queuedCompute=!1;items=[];matchHeight=0;locked=!0;constructor(e){this.locked=e}updateState(e,t){this.items=e;let n=this.locked!==t;this.locked=t,this.computeLayout(n)}initialize(e){if(null==this.resizeObserver){for(let[,{element:t}]of(this.resizeObserver=new e.ResizeObserver(this.handleResize),this.listeners))this.resizeObserver.observe(t);this.queueCompute()}}cleanUp(){this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.listeners.clear()}queueCompute(){this.queuedCompute||(this.queuedCompute=!0,Promise.resolve().then(()=>this.computeLayout()))}handleResize=e=>{this.computeLayout()};computeLayout(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.queuedCompute=!1;let t=0,n=0;for(let i of this.items){let r=this.listeners.get(i.notification.id);if(null==r)continue;let{offsetHeight:s}=r.element;(r.top!==t||r.height!==s||r.index!==n)&&(e=!0),r.top=t,r.height=s,r.index=n,0===t&&(this.matchHeight!==s&&(e=!0),this.matchHeight=s),t+=s+8,n++}e&&this.broadcastLayoutUpdates()}broadcastLayoutUpdates(){for(let e of this.items){let t=this.listeners.get(e.notification.id);null!=t&&t.callback({locked:this.locked,matchHeight:this.matchHeight,height:t.height,top:t.top,index:t.index})}}subscribe(e,t,n){this.listeners.set(e,{notificationId:e,callback:n,element:t,height:0,top:0,index:0}),this.resizeObserver?.observe(t),this.queueCompute()}unsubscribe(e){let t=this.listeners.get(e);null!=t&&(this.resizeObserver?.unobserve(t.element),this.listeners.delete(e),this.queueCompute())}getLayoutSpecs(e){return this.listeners.get(e)}}let f=i.createContext(new h(!0));function E(e,t,n){return t&&0!==e?20*Math.max(e/5,0):n}let p={mass:.8,friction:25,tension:320};function m(e,t,n){let[a,h]=(0,r.z)(()=>({from:{opacity:0,scale:1,transform:0,height:0,contentOpacity:1}}),void 0,[]),m=i.useRef(h),g=i.useContext(f),A=i.useMemo(()=>{let t=!1;return n=>{null==n?g.unsubscribe(e):g.subscribe(e,n,n=>{let{locked:i,matchHeight:r,height:s,top:a,index:h}=n;if(l.default.getCurrentUser()?.isStaff()){let t=o.A.getWindow(d.f),n=null!=t?u.A.windowSize((0,c.Q2)(t)):void 0;_.info("Notification layout update",{id:e,locked:i,matchHeight:r,height:s,top:a,index:h},n)}let{current:f}=m,g={opacity:i&&h>4?0:i?Math.min(1-h/4,1):1,scale:i?Math.min(1-h/4,1):1,transform:E(h,i,a),contentOpacity:i&&h>0?0:1,height:i?r:s};f({from:t?void 0:{opacity:0,scale:1.1,transform:-((i?r:s)*1),contentOpacity:1,height:i?r:s},to:g,config:p}),t=!0})}},[e,g]);return i.useLayoutEffect(()=>{if(t===s.wL.YEETED){let t=g.getLayoutSpecs(e);if(null==t)return void n();m.current({to:{scale:.8,opacity:0,transform:E(t.index,g.locked,t.top)+(g.locked?0:t.height/2)},config:p}),setTimeout(n,300)}},[t,n,e,g]),{ref:A,springs:a}}}