import{j as Z}from"./client-By3tlFYA.js";import{g as z,r as p,R as $}from"./index-TEHZzOO_.js";import{br as ee}from"./useSelectableClick-DFE6ksOx.js";import{u as te,c as ne}from"./short_number-C9zm8Jg6.js";var K=new Date().getTime();function oe(l){var r=new Date().getTime(),n=Math.max(0,16-(r-K)),e=setTimeout(l,n);return K=r,e}var re=["","webkit","moz","o","ms"],N="clearTimeout",I=oe,M=function(r,n){return r+(r?n[0].toUpperCase()+n.substr(1):n)+"AnimationFrame"};ee&&re.some(function(l){var r=M(l,"request");return r in window&&(N=M(l,"cancel"),I=function(e){return window[r](e)}),!!I});var C=function(r){typeof window[N]=="function"&&window[N](r)},y=I;function ie(l){return"nodeType"in l&&l.nodeType===document.DOCUMENT_NODE}function se(l){return"window"in l&&l.window===l?l:ie(l)&&l.defaultView||!1}function F(l){var r=l==="pageXOffset"?"scrollLeft":"scrollTop";function n(e,t){var s=se(e);if(t===void 0)return s?s[l]:e[r];s?s.scrollTo(s[l],t):e[r]=t}return n}const H=F("pageXOffset"),k=F("pageYOffset");var x,B;function le(){if(B)return x;B=1;var l=function(r,n,e,t,s,d,h,v){if(!r){var a;if(n===void 0)a=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var _=[e,t,s,d,h,v],S=0;a=new Error(n.replace(/%s/g,function(){return _[S++]})),a.name="Invariant Violation"}throw a.framesToPop=1,a}};return x=l,x}var ae=le();const V=z(ae);var W={exports:{}};/*!
 Copyright 2018 Google Inc. All Rights Reserved.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/var ce=W.exports,q;function ue(){return q||(q=1,function(l,r){/*! lifecycle.es5.js v0.1.1 */(function(n,e){l.exports=e()})(ce,function(){var n=void 0;try{new EventTarget,n=!1}catch(c){n=!1}var e=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(c){return typeof c}:function(c){return c&&typeof Symbol=="function"&&c.constructor===Symbol&&c!==Symbol.prototype?"symbol":typeof c},t=function(c,o){if(!(c instanceof o))throw new TypeError("Cannot call a class as a function")},s=function(){function c(o,i){for(var f=0;f<i.length;f++){var u=i[f];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(o,u.key,u)}}return function(o,i,f){return i&&c(o.prototype,i),f&&c(o,f),o}}(),d=function(c,o){if(typeof o!="function"&&o!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof o);c.prototype=Object.create(o&&o.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),o&&(Object.setPrototypeOf?Object.setPrototypeOf(c,o):c.__proto__=o)},h=function(c,o){if(!c)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!o||typeof o!="object"&&typeof o!="function"?c:o},v=function(){function c(){t(this,c),this._registry={}}return s(c,[{key:"addEventListener",value:function(o,i){this._getRegistry(o).push(i)}},{key:"removeEventListener",value:function(o,i){var f=this._getRegistry(o),u=f.indexOf(i);u>-1&&f.splice(u,1)}},{key:"dispatchEvent",value:function(o){return o.target=this,Object.freeze(o),this._getRegistry(o.type).forEach(function(i){return i(o)}),!0}},{key:"_getRegistry",value:function(o){return this._registry[o]=this._registry[o]||[]}}]),c}(),a=n?EventTarget:v,_=n?Event:function c(o){t(this,c),this.type=o},S=function(c){function o(i,f){t(this,o);var u=h(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,i));return u.newState=f.newState,u.oldState=f.oldState,u.originalEvent=f.originalEvent,u}return d(o,_),o}(),g="active",w="passive",m="hidden",E="frozen",R="terminated",U=(typeof safari>"u"?"undefined":e(safari))==="object"&&safari.pushNotification,X=["focus","blur","visibilitychange","freeze","resume","pageshow","onpageshow"in self?"pagehide":"unload"],j=function(c){return c.preventDefault(),c.returnValue="Are you sure?"},J=[[g,w,m,R],[g,w,m,E],[m,w,g],[E,m],[E,g],[E,w]].map(function(c){return c.reduce(function(o,i,f){return o[i]=f,o},{})}),P=function(){return document.visibilityState===m?m:document.hasFocus()?g:w};return new(function(c){function o(){t(this,o);var i=h(this,(o.__proto__||Object.getPrototypeOf(o)).call(this)),f=P();return i._state=f,i._unsavedChanges=[],i._handleEvents=i._handleEvents.bind(i),X.forEach(function(u){return addEventListener(u,i._handleEvents,!0)}),U&&addEventListener("beforeunload",function(u){i._safariBeforeUnloadTimeout=setTimeout(function(){u.defaultPrevented||u.returnValue.length>0||i._dispatchChangesIfNeeded(u,m)},0)}),i}return d(o,a),s(o,[{key:"addUnsavedChanges",value:function(i){!this._unsavedChanges.indexOf(i)>-1&&(this._unsavedChanges.length===0&&addEventListener("beforeunload",j),this._unsavedChanges.push(i))}},{key:"removeUnsavedChanges",value:function(i){var f=this._unsavedChanges.indexOf(i);f>-1&&(this._unsavedChanges.splice(f,1),this._unsavedChanges.length===0&&removeEventListener("beforeunload",j))}},{key:"_dispatchChangesIfNeeded",value:function(i,f){if(f!==this._state)for(var u=function(G,Q){for(var T,D=0;T=J[D];++D){var L=T[G],O=T[Q];if(L>=0&&O>=0&&O>L)return Object.keys(T).slice(L,O+1)}return[]}(this._state,f),b=0;b<u.length-1;++b){var Y=u[b],A=u[b+1];this._state=A,this.dispatchEvent(new S("statechange",{oldState:Y,newState:A,originalEvent:i}))}}},{key:"_handleEvents",value:function(i){switch(U&&clearTimeout(this._safariBeforeUnloadTimeout),i.type){case"pageshow":case"resume":this._dispatchChangesIfNeeded(i,P());break;case"focus":this._dispatchChangesIfNeeded(i,g);break;case"blur":this._state===g&&this._dispatchChangesIfNeeded(i,P());break;case"pagehide":case"unload":this._dispatchChangesIfNeeded(i,i.persisted?E:R);break;case"visibilitychange":this._state!==E&&this._state!==R&&this._dispatchChangesIfNeeded(i,P());break;case"freeze":this._dispatchChangesIfNeeded(i,E)}}},{key:"state",get:function(){return this._state}},{key:"pageWasDiscarded",get:function(){return document.wasDiscarded||!1}}]),o}())})}(W)),W.exports}var de=ue();const fe=z(de);function he(){return/iPad|iPhone|iPod/.test(window.navigator.platform)&&/^((?!CriOS).)*Safari/.test(window.navigator.userAgent)}var ve=2,_e=function(){function l(n){var e=this,t=n.addNavigationListener,s=n.stateStorage,d=n.getCurrentLocation,h=n.shouldUpdateScroll;this._setScrollRestoration=function(){if(!e._oldScrollRestoration&&"scrollRestoration"in window.history&&!he()){e._oldScrollRestoration=window.history.scrollRestoration;try{window.history.scrollRestoration="manual"}catch(a){e._oldScrollRestoration=null}}},this._restoreScrollRestoration=function(){if(e._oldScrollRestoration){try{window.history.scrollRestoration=e._oldScrollRestoration}catch(a){}e._oldScrollRestoration=null}},this._onWindowScroll=function(){if(!e._ignoreScrollEvents&&(e._saveWindowPositionHandle||(e._saveWindowPositionHandle=y(e._saveWindowPosition)),e._windowScrollTarget)){var a=e._windowScrollTarget,_=a[0],S=a[1],g=H(window),w=k(window);g===_&&w===S&&(e._windowScrollTarget=null,e._cancelCheckWindowScroll())}},this._saveWindowPosition=function(){e._saveWindowPositionHandle=null,e._savePosition(null,window)},this._checkWindowScrollPosition=function(){return e._checkWindowScrollHandle=null,e._windowScrollTarget?(e.scrollToTarget(window,e._windowScrollTarget),++e._numWindowScrollAttempts,e._numWindowScrollAttempts>=ve?(e._windowScrollTarget=null,Promise.resolve()):new Promise(function(a){e._checkWindowScrollHandle=y(function(){return a(e._checkWindowScrollPosition())})})):Promise.resolve()},this._stateStorage=s,this._getCurrentLocation=d,this._shouldUpdateScroll=h,this._oldScrollRestoration=null,this._setScrollRestoration(),this._saveWindowPositionHandle=null,this._checkWindowScrollHandle=null,this._windowScrollTarget=null,this._numWindowScrollAttempts=0,this._ignoreScrollEvents=!1,this._scrollElements={},window.addEventListener("scroll",this._onWindowScroll);var v=function(_){C(e._saveWindowPositionHandle),e._saveWindowPositionHandle=null,_&&!e._ignoreScrollEvents&&e._saveWindowPosition(),Object.keys(e._scrollElements).forEach(function(S){var g=e._scrollElements[S];C(g.savePositionHandle),g.savePositionHandle=null,e._ignoreScrollEvents||e._saveElementPosition(S)})};this._removeNavigationListener=t(function(a){var _=a.action;v(_!=="POP")}),fe.addEventListener("statechange",function(a){var _=a.newState;_==="terminated"||_==="frozen"||_==="discarded"?(v(!0),e._restoreScrollRestoration()):e._setScrollRestoration()})}var r=l.prototype;return r.registerElement=function(e,t,s,d){var h=this;this._scrollElements[e]&&V(!1);var v=function(){h._saveElementPosition(e)},a={element:t,shouldUpdateScroll:s,savePositionHandle:null,onScroll:function(){!a.savePositionHandle&&!h._ignoreScrollEvents&&(a.savePositionHandle=y(v))}};!a.savePositionHandle&&!this._ignoreScrollEvents&&(a.savePositionHandle=y(v)),this._scrollElements[e]=a,t.addEventListener("scroll",a.onScroll),this._updateElementScroll(e,null,d)},r.unregisterElement=function(e){this._scrollElements[e]||V(!1);var t=this._scrollElements[e],s=t.element,d=t.onScroll,h=t.savePositionHandle;s.removeEventListener("scroll",d),C(h),delete this._scrollElements[e]},r.updateScroll=function(e,t){var s=this;this._updateWindowScroll(e,t).then(function(){s._saveWindowPositionHandle||(s._saveWindowPositionHandle=y(s._saveWindowPosition))}),Object.keys(this._scrollElements).forEach(function(d){s._updateElementScroll(d,e,t)})},r.stop=function(){this._restoreScrollRestoration(),window.removeEventListener("scroll",this._onWindowScroll),this._cancelCheckWindowScroll(),this._removeNavigationListener()},r.startIgnoringScrollEvents=function(){this._ignoreScrollEvents=!0},r.stopIgnoringScrollEvents=function(){this._ignoreScrollEvents=!1},r._cancelCheckWindowScroll=function(){C(this._checkWindowScrollHandle),this._checkWindowScrollHandle=null},r._saveElementPosition=function(e){var t=this._scrollElements[e];t.savePositionHandle=null,this._savePosition(e,t.element)},r._savePosition=function(e,t){this._stateStorage.save(this._getCurrentLocation(),e,[H(t),k(t)])},r._updateWindowScroll=function(e,t){return this._cancelCheckWindowScroll(),this._windowScrollTarget=this._getScrollTarget(null,this._shouldUpdateScroll,e,t),this._numWindowScrollAttempts=0,this._checkWindowScrollPosition()},r._updateElementScroll=function(e,t,s){var d=this._scrollElements[e],h=d.element,v=d.shouldUpdateScroll,a=this._getScrollTarget(e,v,t,s);a&&this.scrollToTarget(h,a)},r._getDefaultScrollTarget=function(e){var t=e.hash;return t&&t!=="#"?t.charAt(0)==="#"?t.slice(1):t:[0,0]},r._getScrollTarget=function(e,t,s,d){var h=t?t.call(this,s,d):!0;if(!h||Array.isArray(h)||typeof h=="string")return h;var v=this._getCurrentLocation();return this._getSavedScrollTarget(e,v)||this._getDefaultScrollTarget(v)},r._getSavedScrollTarget=function(e,t){return t.action==="PUSH"?null:this._stateStorage.read(t,e)},r.scrollToTarget=function(e,t){if(typeof t=="string"){var s=document.getElementById(t)||document.getElementsByName(t)[0];if(s){s.scrollIntoView();return}t=[0,0]}var d=t,h=d[0],v=d[1];H(e,h),k(e,v)},l}();function ge(l){const r=p.useRef();return p.useEffect(()=>{r.current=l},[l]),r.current}const Se=(l,r)=>{var e,t;return!((e=r.state)!=null&&e.mastodonModalKey&&r.state.mastodonModalKey!==((t=l==null?void 0:l.state)==null?void 0:t.mastodonModalKey))},pe="@@scroll|";class we{read(r,n){const e=this.getStateKey(r,n);try{const t=sessionStorage.getItem(e);return t?JSON.parse(t):null}catch(t){return null}}save(r,n,e){const t=this.getStateKey(r,n),s=JSON.stringify(e);try{sessionStorage.setItem(t,s)}catch(d){}}getStateKey(r,n){const e=r.key,t="".concat(pe).concat(e);return n==null?t:"".concat(t,"|").concat(n)}}const me=$.createContext(null),Te=({children:l,shouldUpdateScroll:r=Se})=>{var v;const n=te(),e=ne(),t=p.useRef(n);p.useEffect(()=>{t.current=n},[n]);const[s]=p.useState(()=>new _e({addNavigationListener:e.listen.bind(e),stateStorage:new we,getCurrentLocation:()=>t.current,shouldUpdateScroll:(a,_)=>r.call(s,a,_)})),d=(v=ge(n))!=null?v:null;p.useEffect(()=>{s.updateScroll(d,n)},[n,d,s]),p.useEffect(()=>()=>{s.stop()},[s]);const h=p.useMemo(()=>({registerElement:(a,_,S)=>{s.registerElement(a,_,S,n)},unregisterElement:a=>{s.unregisterElement(a)},scrollBehavior:s}),[n,s]);return Z.jsx(me.Provider,{value:h,children:$.Children.only(l)})};export{Te as S,me as a,Se as d,ge as u};
//# sourceMappingURL=scroll_context-BtA-k5hE.js.map
