vuepress-theme-hope
Version:
A light vuepress theme with tons of features
3 lines (2 loc) • 3.68 kB
JavaScript
import{defineComponent as f,ref as d,computed as m,h as o,nextTick as S,onMounted as E}from"vue";import{RenderDefault as w}from"vuepress-shared/client";import{usePageFrontmatter as O,usePageData as _}from"vuepress/client";import{y as V,F as x}from"../../PageTitle-DNGnO8bB.js";import{L as C}from"../../icons-BBxJRXot.js";import{u as D,c as G,d as H}from"../../PageInfo-Cb8wmvLH.js";import{useStorage as b,useSessionStorage as g}from"@vueuse/core";import{compareSync as y}from"bcrypt-ts/browser";import{keys as I,isPlainObject as K,startsWith as R}from"@vuepress/helper/client";import"@vuepress/plugin-reading-time/client";import"@vuepress/helper/noopComponent";import"@vuepress/plugin-comment/pageview";import"@vuepress/plugin-theme-data/client";import"../../styles/variables.module.scss";import"balloon-css/balloon.css";var k=f({name:"PasswordModal",props:{hint:String,full:Boolean,showTitle:Boolean},emits:["verify"],setup(t,{emit:a}){const c=O(),u=D(),r=d(""),n=d(!1),l=d(!1),e=m(()=>u.value.encryptLocales);let i=null;const v=()=>{i&&clearTimeout(i),n.value=!1,a("verify",r.value,l.value),S().then(()=>{n.value=!0,i=setTimeout(()=>{n.value=!1},1e3)})};return()=>o("div",{class:["vp-decrypt-layer",{expand:t.full||c.value.home}]},[t.showTitle?o(V):null,o("div",{class:"vp-decrypt-modal"},[o("div",{class:["vp-decrypt-hint",{tried:n.value}]},n.value?e.value.errorHint:o(C,{"aria-label":e.value.iconLabel})),t.hint?o("div",{class:"vp-decrypt-hint"},t.hint):null,o("div",{class:"vp-decrypt-input"},[o("input",{type:"password",value:r.value,placeholder:e.value.placeholder,onInput:({target:s})=>{r.value=s.value},onKeydown:({key:s})=>{s==="Enter"&&v()}})]),o("div",{class:"vp-remember-password"},[o("input",{id:"remember-password",type:"checkbox",value:l.value,onChange:()=>{l.value=!l.value}}),o("label",{for:"remember-password"},e.value.remember)]),o("button",{type:"button",class:"vp-decrypt-submit",onClick:()=>{v()}},"OK")])])}});const L=()=>{const t=G();return m(()=>t.value.encrypt)},T="VUEPRESS_HOPE_GLOBAL_TOKEN",U=()=>{const t=L(),a=b(T,""),c=g(T,"");return{status:m(()=>{const{global:u=!1,admin:r}=t.value,n=u&&!!r?.tokens.length,l=n?a.value?t.value.admin.tokens.every(e=>!y(a.value,e)):t.value.admin.tokens.every(e=>!y(c.value,e)):!1;return{isEncrypted:n,isLocked:l,hint:r?.hint??""}}),validate:(u,r=!1)=>{(r?a:c).value=u}}},h=(t="",a)=>!!t&&y(t,a),P="VUEPRESS_HOPE_PATH_TOKEN",j=()=>{const t=_(),a=L(),c=b(P,{}),u=g(P,{}),r=l=>K(a.value.config)?I(a.value.config).filter(e=>R(decodeURI(l),e)).sort((e,i)=>i.length-e.length):[],n=l=>{const{config:e={}}=a.value,i=r(l);if(i.length>0){const v=i.find(s=>e[s].hint);return{isEncrypted:!0,isLocked:i.some(s=>(c.value[s]?e[s].tokens.every(p=>!h(c.value[s],p)):!0)&&(u.value[s]?e[s].tokens.every(p=>!h(u.value[s],p)):!0)),hint:v?e[v].hint:""}}return{isEncrypted:!1,isLocked:!1,hint:""}};return{status:m(()=>n(t.value.path)),getStatus:n,validate:(l,e=!1)=>{const{config:i={}}=a.value,v=r(t.value.path);for(const s of v)if(i[s].tokens.some(p=>h(l,p))){(e?c:u).value[s]=l;break}}}};var B=f({name:"GlobalEncrypt",slots:Object,setup(t,{slots:a}){const{status:c,validate:u}=U(),r=H(),n=d(!1);return E(()=>{n.value=!0}),()=>{const{isEncrypted:l,isLocked:e,hint:i}=c.value;return o(r.value?w:x,()=>l?n.value?e?o(k,{full:!0,hint:i,onVerify:u}):a.default():null:a.default())}}}),F=f({name:"LocalEncrypt",slots:Object,setup(t,{slots:a}){const{status:c,validate:u}=j(),r=d(!1);return E(()=>{r.value=!0}),()=>{const{isEncrypted:n,isLocked:l,hint:e}=c.value;return n?r.value?l?o(k,{showTitle:!0,full:!0,hint:e,onVerify:u}):a.default():null:a.default()}}});export{B as GlobalEncrypt,F as LocalEncrypt};
//# sourceMappingURL=export.js.map