1import{_ as de}from"./Bw0n4hiA.js";import{d as L,al as se,c as v,e as _,am as G,a0 as N,D as i,t as h,an as pe,ao as fe,ap as le,C as be,n as g,ad as me,w as V,G as ve,p as B,m as E,aq as he,F as re,i as n,r as ye,K as j,O as b,ar as ue,as as W,f as ge,P as _e,a8 as Q,at as we,au as ke,J as $,av as $e,aw as C,j as Se,Z as Ve,aa as xe,h as X,ax as z,ay as Z,M as Ne}from"./DREHXjTd.js";const Pe={"flex-1":"","ms-2":"","pointer-events-none":""},Ee=["value"],Ce=L({__name:"CommonRadio",props:le({label:{},value:{},hover:{type:Boolean}},{modelValue:{},modelModifiers:{}}),emits:["update:modelValue"],setup(t){const e=se(t,"modelValue");return(s,o)=>(v(),_("label",{class:N(["common-radio flex items-center cursor-pointer py-1 text-md w-full gap-y-1",t.hover?"hover:bg-active ms--2 px-4 py-2":null]),onClick:o[1]||(o[1]=G(c=>e.value=t.value,["prevent"]))},[i("span",Pe,h(t.label),1),i("span",{class:N(e.value===t.value?"i-ri:radio-button-line":"i-ri:checkbox-blank-circle-line"),"aria-hidden":"true"},null,2),pe(i("input",{"onUpdate:modelValue":o[0]||(o[0]=c=>e.value=c),type:"radio",value:t.value,"sr-only":""},null,8,Ee),[[fe,e.value]])],2))}}),Oe=Object.assign(Ce,{__name:"CommonRadio"}),Ae={key:0,role:"alert","aria-describedby":"notification-failed",flex:"~ col","gap-1":"","text-sm":"","pt-1":"","ps-2":"","pe-1":"","pb-2":"","text-red-600":"","dark:text-red-400":"",border:"~ base rounded red-600 dark:red-400"},Ue={id:"notification-failed",flex:"","justify-between":""},Te={flex:"","items-center":"","gap-x-2":"","font-bold":""},Re=["aria-label"],Be={"py-2":""},De={"py-2":""},Me=L({__name:"NotificationSubscribePushNotificationError",props:le({title:{},message:{}},{modelValue:{type:Boolean,required:!0},modelModifiers:{}}),emits:["update:modelValue"],setup(t){const e=se(t,"modelValue");return(s,o)=>{const c=me,d=ve,r=be("i18n-t");return e.value?(v(),_("div",Ae,[i("header",Ue,[i("div",Te,[o[1]||(o[1]=i("div",{"aria-hidden":"true","i-ri:error-warning-fill":""},null,-1)),i("p",null,h(t.title??s.$t("settings.notifications.push_notifications.subscription_error.title")),1)]),g(c,{placement:"bottom",content:s.$t("settings.notifications.push_notifications.subscription_error.clear_error")},{default:V(()=>[i("button",{flex:"","rounded-4":"",p1:"","hover:bg-active":"","cursor-pointer":"","transition-100":"","aria-label":s.$t("settings.notifications.push_notifications.subscription_error.clear_error"),onClick:o[0]||(o[0]=y=>e.value=!1)},[...o[2]||(o[2]=[i("span",{"aria-hidden":"true",w:"1.75em",h:"1.75em","i-ri:close-line":""},null,-1)])],8,Re)]),_:1},8,["content"])]),i("p",null,h(t.message),1),i("p",Be,[g(r,{keypath:"settings.notifications.push_notifications.subscription_error.error_hint"},{default:V(()=>[g(d,{"font-bold":"",href:"https://docs.elk.zone/pwa#faq",target:"_blank","inline-flex":"~ row","items-center":"","gap-x-2":""},{default:V(()=>[...o[3]||(o[3]=[B(" https://docs.elk.zone/pwa#faq ",-1),i("span",{"inline-block":"","aria-hidden":"true","i-ri:external-link-line":"",class:"rtl-flip"},null,-1)])]),_:1})]),_:1})]),i("p",De,[g(d,{"font-bold":"","text-primary":"",href:"https://github.com/elk-zone/elk",target:"_blank",flex:"~ row","items-center":"","gap-x-2":""},{default:V(()=>[B(h(s.$t("settings.notifications.push_notifications.subscription_error.repo_link"))+" ",1),o[4]||(o[4]=i("span",{"inline-block":"","aria-hidden":"true","i-ri:external-link-line":"",class:"rtl-flip"},null,-1))]),_:1})])])):E("",!0)}}}),Ie=Object.assign(Me,{__name:"NotificationSubscribePushNotificationError"}),Ke={flex:"","items-center":"","pb-2":""},He={id:"notifications-warning","text-md":"","font-bold":"","w-full":""},je=["title","disabled"],Le={"xl:hidden":""},qe={"xl:hidden":""},Fe={key:1},ze={key:2},Ge=["disabled"],We={key:0,"aria-hidden":"true",block:"","animate-spin":"","preserve-3d":""},Ye={key:1,"aria-hidden":"true",block:"","i-ri:check-line":""},Je=L({__name:"NotificationEnablePushNotification.client",props:{closeableHeader:{type:Boolean},busy:{type:Boolean},animate:{type:Boolean}},emits:["hide","subscribe"],setup(t){const e=he("(min-width: 1280px)"),s=j(()=>!b.value?.vapidKey);return(o,c)=>(v(),_("div",{flex:"~ col","gap-y-2":"",role:"alert","aria-labelledby":"notifications-warning",class:N(t.closeableHeader?"border-b border-base":"px6 px4")},[i("header",Ke,[i("h2",He,h(o.$t("settings.notifications.push_notifications.warning.enable_title")),1),t.closeableHeader?(v(),_("button",{key:0,flex:"","rounded-4":"",type:"button",title:o.$t("settings.notifications.push_notifications.warning.enable_close"),"hover:bg-active":"","cursor-pointer":"","transition-100":"",disabled:t.busy,onClick:c[0]||(c[0]=d=>o.$emit("hide"))},[...c[2]||(c[2]=[i("span",{"aria-hidden":"true","i-ri:close-line":""},null,-1)])],8,je)):E("",!0)]),t.closeableHeader?(v(),_(re,{key:0},[i("p",Le,h(o.$t("settings.notifications.push_notifications.warning.enable_description")),1),i("p",qe,h(o.$t("settings.notifications.push_notifications.warning.enable_description_mobile")),1),i("p",{class:N(n(e)?null:"hidden")},h(o.$t("settings.notifications.push_notifications.warning.enable_description_desktop")),3)],64)):(v(),_("p",Fe,h(o.$t("settings.notifications.push_notifications.warning.enable_description_settings")),1)),n(s)?(v(),_("p",ze,h(o.$t("settings.notifications.push_notifications.warning.re_auth")),1)):E("",!0),i("button",{"btn-outline":"","rounded-full":"","font-bold":"",py4:"",flex:"~ gap2 center",m5:"",type:"button",class:N(t.busy||n(s)?"border-transparent":null),disabled:t.busy||n(s),onClick:c[1]||(c[1]=d=>o.$emit("subscribe"))},[t.busy&&t.animate?(v(),_("span",We,[...c[3]||(c[3]=[i("span",{block:"","i-ri:loader-2-fill":"","aria-hidden":"true"},null,-1)])])):(v(),_("span",Ye)),i("span",null,h(o.$t("settings.notifications.push_notifications.warning.enable_desktop")),1)],10,Ge),ye(o.$slots,"error")
1],2))}}),Qe=Object.assign(Je,{__name:"NotificationEnablePushNotification"});class H extends Error{code;constructor(e,s){super(s),this.code=e}}const ee={DASH_TO_PLUS:/-/g,UNDERSCORE_TO_SLASH:/_/g};async function Xe(t,e,s="all",o=!1){const{server:c,vapidKey:d}=t;return await te().then(ne).then(({registration:r,subscription:y})=>{if(y){const x=new Uint8Array(y.options.applicationServerKey).toString();if(ce(d).toString()===x&&y.endpoint===c&&!o&&t.pushSubscription)return Promise.resolve(t.pushSubscription);if(t.pushSubscription)return ie(!1,!1).catch(Ze).then(()=>oe(r,d)).then(A=>ae(A,e,s))}return oe(r,d).then(x=>ae(x,e,s))}).catch(r=>{let y=r;return r.code===11&&r.name==="InvalidStateError"?y=new H("too_many_registrations","Too many registrations"):r.code===20&&r.name==="AbortError"?y=new H("vapid_not_supported","Your browser supports Web Push Notifications, but does not seem to implement the VAPID protocol."):r.code===5&&r.name==="InvalidCharacterError"&&(y=new H("invalid_vapid_key",`The VAPID public key seems to be invalid: ${d}`)),te().then(ne).then(()=>ie(!0)).then(()=>Promise.resolve(void 0)).catch(x=>Promise.resolve(void 0)).finally(()=>Promise.reject(y))})}function ce(t){const e="=".repeat((4-t.length%4)%4),s=`${t}${e}`.replace(ee.DASH_TO_PLUS,"+").replace(ee.UNDERSCORE_TO_SLASH,"/"),o=window.atob(s),c=new Uint8Array(o.length);for(let d=0;d<o.length;++d)c[d]=o.charCodeAt(d);return c}function te(){return navigator.serviceWorker.ready}async function ne(t){const e=await t.pushManager.getSubscription();return{registration:t,subscription:e}}async function oe(t,e){return await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:ce(e)})}async function ie(t,e=!0){const s=b.value;s&&(await ue(s),e&&await W(s,t))}async function Ze(t){const e=b.value;throw e&&await W(e,!0),t}async function ae(t,e,s){const{endpoint:o,keys:c}=t.toJSON();return await ge().v1.push.subscription.create({policy:s,subscription:{endpoint:o,keys:{p256dh:c.p256dh,auth:c.auth}},data:e})}const et=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"getKey"in PushSubscription.prototype;function tt(){const{client:t}=_e(),e=$(!1),s=$(Notification.permission==="denied"?"denied":Notification.permission==="granted"?"granted":Notification.permission==="default"?"prompt":void 0),o=j(()=>et),c=Q(we,{}),d=Q(ke,{}),r=$(K(b.value?.pushSubscription,d.value[b.value?.account?.acct??""])),y=$(K(b.value?.pushSubscription,d.value[b.value?.account?.acct??""])),x=j(()=>{const l=r.value,p=y.value;return l.favourite!==p.favourite||l.reblog!==p.reblog||l.mention!==p.mention||l.follow!==p.follow||l.poll!==p.poll||l.policy!==p.policy});$e(()=>b.value?.pushSubscription,l=>{e.value=!!l,r.value=K(l,d.value[b.value?.account?.acct??""]),y.value=K(l,d.value[b.value?.account?.acct??""])},{immediate:!0,flush:"post"});const O=async(l,p,S)=>{if(!o.value)return"not-supported";if(!b.value)return"no-user";const{pushSubscription:w,server:k,token:D,vapidKey:T,account:{acct:F}}=b.value;if(!D||!k||!T)return"invalid-vapid-key";const P=await Promise.resolve(Notification.requestPermission()).then(M=>M==="default"?"prompt":M);return P==="denied"?(s.value=P,"notification-denied"):(b.value.pushSubscription=await Xe({pushSubscription:w,server:k,vapidKey:T},l??{alerts:{follow:!0,favourite:!0,reblog:!0,mention:!0,poll:!0}},p??"all",S),await C(),s.value=P,c.value[F]=!0,"subscribed")},A=async()=>{if(!o.value||!e.value||!b.value)return!1;await ue(b.value),await W(b.value)},U=async l=>{l&&(r.value.policy=l);const p=r.value;y.value={favourite:p.favourite,reblog:p.reblog,mention:p.mention,follow:p.follow,poll:p.poll,policy:p.policy},l?d.value[b.value.account.acct??""]=l:d.value[b.value.account.acct??""]=r.value.policy,await C()};return{pushNotificationData:r,saveEnabled:x,undoChanges:()=>{const l=y.value;r.value={favourite:l.favourite,reblog:l.reblog,mention:l.mention,follow:l.follow,poll:l.poll,policy:l.policy},d.value[b.value.account.acct??""]=l.policy},hiddenNotification:c,isSupported:o,isSubscribed:e,notificationPermission:s,updateSubscription:async()=>{if(b.value){const l=y.value,p={alerts:{follow:r.value.follow,favourite:r.value.favourite,reblog:r.value.reblog,mention:r.value.mention,poll:r.value.poll}},S=r.value.policy,w=l.policy!==S;w?await O(p,S,!0):b.value.pushSubscription=await t.value.v1.push.subscription.update({data:p}),w&&await C(),await U(w?S:void 0)}},subscribe:O,unsubscribe:A}}function K(t,e){return{follow:t?.alerts.follow??!0,favourite:t?.alerts.favourite??!0,reblog:t?.alerts.reblog??!0,mention:t?.alerts.mention??!0,poll:t?.alerts.poll??!0,policy:e??"all"}}const nt=Ne(Qe),ot={key:0,"aria-labelledby":"pn-s"},it={key:0,flex:"~ col",border:"b base"},at={id:"pn-settings",px6:"",py4:"",mt2:"","font-bold":"","text-xl":"",flex:"~ gap-1","items-center":""},st={key:0,flex:"~ col"},lt={id:"pn-instructions","text-sm":"",pb2:"","aria-hidden":"true"},rt={flex:"~ col","gap-y-1":"","py-1":""},ut={flex:"~ col","gap-y-1":"","py-1":""},ct={flex:"~ col","gap-y-4":"","gap-x-2":"","py-1":"",sm:"~ justify-between flex-row"},dt=["disabled"],pt={key:0,"aria-hidden":"true",block:"","animate-spin":"","preserve-3d":""},ft={key:1,block:"","aria-hidden":"true","i-ri:save-2-fill":""},bt=["disabled"],mt=["disabled"],vt={key:0,"aria-hidden":"true",block:"","animate-spin":"","preserve-3d":""},ht={key:1,block:"","aria-hidden":"true","i-material-symbols:cancel-rounded":""},yt={key:1,px6:"",pb4:"",role:"alert","aria-labelledby":"n-unsupported"},gt={id:"n-unsupported"},_t=L({__name:"NotificationPreferences.client",props:{show:{type:Boolean}},setup(t){const{pushNotificationData:e,saveEnabled:s,undoChanges:o,hiddenNotification:c,isSubscribed:d,isSupported:r,notificationPermission:y,updateSubscription:x,subscribe:O,unsubscribe:A}=tt(),{t:U}=Se(),q=Ve().pwaEnabled,m=$(!1),l=$(!1),p=$(!1),S=$(!1),w=$(""),k=$(!1);function D(){const u=b.value?.account?.acct;u&&(c.value[u]=!0)}const T=j(()=>q?r&&(!d.value||!y.value||y.value==="prompt")&&!c.value[b.value?.account?.acct??""]:!1);async function F(){if(!m.value){m.value=!0,await C(),l.value=!0;try{await x()}catch{}finally{m.value=!1,l.value=!1}}}async function P(){if(!m.value){m.value=!0,await C(),p.value=!0;try{const u=await O();u!=="subscribed"&&(w.value=U(`settings.notifications.push_notifications.subscription_error.${u==="notification-denied"?"permission_denied":"request_error"}`),k.value=!0)}catch(u){u instanceof H?w.value=U(`settings.notifications.push_notifications.subscription_error.${u.code}`):w.value=U("settings.notifications.push_notifications.subscription_error.request_error"),k.value=!0}finally{m.value=!1,p.value=!1}}}async function M(){if(!m.value){m.value=!0,await C(),S.value=!0;try{await A()}catch{}finally{m.value=!1,S.value=!1}}}return xe(()=>m.value=!1),(u,a)=>{const R=de,I=Oe,Y=Ie,J=nt;return n(q)&&(n(T)||t.show)?(v(),_("section",ot,[g(z,{name:"slide-down"},{default:V(()=>[t.show?(v(),_("div",it,[i("h3",at,h(u.$t("settings.notifications.push_notifications.label")),1),n(r)?(v(),_(re,{key:0},[n(d)?(v(),_("div",st,[i("form",{flex:"~ col","gap-y-2":"",px6:"",pb4:"",onSubmit:G(F,["prevent"])},[i("p",lt,h(u.$t("settings.notifications.push_notifications.instructions")),1),i("fieldset",rt,[i("legend",null,h(u.$t("settings.notifications.push_notifications.alerts.title")),1),g(R,{modelValue:n(e).follow,"onUpdate:modelValue":a[0]||(a[0]=f=>n(e).follow=f),hover:"",label:u.$t("settings.notifications.push_notifications.alerts.follow")},null,8,["modelValue","label"]),g(R,{modelValue:n(e).favourite,"onUpdate:modelValue":a[1]||(a[1]=f=>n(e).favourite=f),hover:"",label:u.$t("settings.notifications.push_notifications.alerts.favourite")},null,8,["modelValue","label"]),g(R,{modelValue:n(e).reblog,"onUpdate:modelValue":a[2]||(a[2]=f=>n(e).reblog=f),hover:"",label:u.$t("settings.notifications.push_notifications.alerts.reblog")},null,8,["modelValue","label"]),g(R,{modelValue:n(e).mention,"onUpdate:modelValue":a[3]||(a[3]=f=>n(e).mention=f),hover:"",label:u.$t("settings.notifications.push_notifications.alerts.mention")},null,8,["modelValue","label"]),g(R,{modelValue:n(e).poll,"onUpdate:modelValue":a[4]||(a[4]=f=>n(e).poll=f),hover:"",label:u.$t("settings.notifications.push_notifications.alerts.poll")},null,8,["modelValue","label"])]),i("fieldset",ut,[i("legend",null,h(u.$t("settings.notifications.push_notifications.policy.title")),1),g(I,{modelValue:n(e).policy,"onUpdate:modelValue":a[5]||(a[5]=f=>n(e).policy=f),hover:"",value:"all",label:u.$t("settings.notifications.push_notifications.policy.all")},null,8,["modelValue","label"]),g(I,{modelValue:n(e).policy,"onUpdate:modelValue":a[6]||(a[6]=f=>n(e).policy=f),hover:"",value:"followed",label:u.$t("settings.notifications.push_notifications.policy.followed")},null,8,["modelValue","label"]),g(I,{modelValue:n(e).policy,"onUpdate:modelValue":a[7]||(a[7]=f=>n(e).policy=f),hover:"",value:"follower",label:u.$t("settings.notifications.push_notifications.policy.follower")},null,8,["modelValue","label"]),g(I,{modelValue:n(e).policy,"onUpdate:modelValue":a[8]||(a[8]=f=>n(e).policy=f),hover:"",value:"none",label:u.$t("settings.notifications.push_notifications.policy.none")},null,8,["modelValue","label"])]),i("div",ct,[i("button",{"btn-solid":"","font-bold":"",py2:"","full-w":"","sm-wa":"",flex:"~ gap2 center",class:N(n(m)||!n(s)?"border-transparent":null),disabled:n(m)||!n(s)},[n(m)&&n(l)?(v(),_("span",pt,[...a[12]||(a[12]=[i("span",{block:"","i-ri:loader-2-fill":"","aria-hidden":"true"},null,-1)])])):(v(),_("span",ft)),B(" "+h(u.$t("settings.notifications.push_notifications.save_settings")),1)],10,dt),i("button",{"btn-outline":"","font-bold":"",py2:"","full-w":"","sm-wa":"",flex:"~ gap2 center",type:"button",class:N(n(m)||!n(s)?"border-transparent":null),disabled:n(m)||!n(s),onClick:a[9]||(a[9]=(...f)=>n(o)&&n(o)(...f))},[a[13]||(a[13]=i("span",{"aria-hidden":"true",class:"block i-material-symbols:undo-rounded"},null,-1)),B(" "+h(u.$t("settings.notifications.push_notifications.undo_settings")),1)],10,bt)])],32),i("form",{flex:"~ col","mt-4":"",onSubmit:G(M,["prevent"])},[a[15]||(a[15]=i("span",{border:"b base 2px",class:"bg-$c-text-secondary"},null,-1)),i("button",{"btn-outline":"","rounded-full":"","font-bold":"","py-4":"",flex:"~ gap2 center",m5:"",class:N(n(m)?"border-transparent":null),disabled:n(m)},[n(m)&&n(S)?(v(),_("span",vt,[...a[14]||(a[14]=[i("span",{block:"","i-ri:loader-2-fill":"","aria-hidden":"true"},null,-1)])])):(v(),_("span",ht)),B(" "+h(u.$t("settings.notifications.push_notifications.unsubscribe")),1)],10,mt)],32)])):(v(),X(J,{key:1,animate:n(p),busy:n(m),onHide:D,onSubscribe:P},{error:V(()=>[g(z,{name:"slide-down"},{default:V(()=>[g(Y,{modelValue:n(k),"onUpdate:modelValue":a[10]||(a[10]=f=>Z(k)?k.value=f:null),message:n(w)},null,8,["modelValue","message"])]),_:1})]),_:1},8,["animate","busy"]))],64)):(v(),_("div",yt,[i("p",gt,h(u.$t("settings.notifications.push_notifications.unsupported")),1)]))])):E("",!0)]),_:1}),n(T)&&!t.show?(v(),X(J,{key:0,"closeable-header":"",px5:"",py4:"",animate:n(p),busy:n(m),onHide:D,onSubscribe:P},{error:V(()=>[g(z,{name:"slide-down"},{default:V(()=>[g(Y,{modelValue:n(k),"onUpdate:modelValue":a[11]||(a[11]=f=>Z(k)?k.value=f:null),message:n(w)},null,8,["modelValue","message"])]),_:1})]),_:1},8,["animate","busy"])):E("",!0)])):E("",!0)}}}),$t=Object.assign(_t,{__name:"NotificationPreferences"});export{$t as _};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.