UNPKG

vuepress-theme-hope

Version:

A light vuepress theme with tons of features

3 lines (2 loc) 3.71 kB
import{defineComponent as f,ref as d,computed as m,h as s,nextTick as w,onMounted as E}from"vue";import{y as O,d as P}from"../PageTitle-Df4PhQKx.js";import{c as _}from"../LockIcon-6SjF5cQW.js";import{a as x,e as C}from"../PageInfo-CL1v9JCd.js";import{useStorage as b,useSessionStorage as g}from"@vueuse/core";import{compareSync as y}from"bcrypt-ts/browser";import{keys as G,isPlainObject as H,startsWith as K}from"@vuepress/helper/client";import{usePage as V}from"vuepress/client";import"@vuepress/helper/transition/fade-in-up.css";import"vuepress-shared/client";import"@vuepress/plugin-reading-time/client";import"@vuepress/helper/shared";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{frontmatter:i,themeLocale:u}=x(),l=d(""),o=d(!1),r=d(!1),e=m(()=>u.value.encryptLocales);let c=null;const v=()=>{c&&clearTimeout(c),o.value=!1,a("verify",l.value,r.value),w().then(()=>{o.value=!0,c=setTimeout(()=>{o.value=!1},1e3)})};return()=>s("div",{class:["vp-decrypt-layer",{expand:t.full||i.value.home}]},[t.showTitle?s(O):null,s("div",{class:"vp-decrypt-modal"},[s("div",{class:["vp-decrypt-hint",{tried:o.value}]},o.value?e.value.errorHint:s(_,{"aria-label":e.value.iconLabel})),t.hint?s("div",{class:"vp-decrypt-hint"},t.hint):null,s("div",{class:"vp-decrypt-input"},[s("input",{type:"password",value:l.value,placeholder:e.value.placeholder,onInput:({target:n})=>{l.value=n.value},onKeydown:({key:n})=>{n==="Enter"&&v()}})]),s("div",{class:"vp-remember-password"},[s("input",{id:"remember-password",type:"checkbox",value:r.value,onChange:()=>{r.value=!r.value}}),s("label",{for:"remember-password"},e.value.remember)]),s("button",{type:"button",class:"vp-decrypt-submit",onClick:()=>{v()}},"OK")])])}});const L=()=>{const t=C();return m(()=>t.value.encrypt)},T="VUEPRESS_HOPE_GLOBAL_TOKEN",j=()=>{const t=L(),a=b(T,""),i=g(T,"");return{status:m(()=>{const{global:u=!1,admin:l}=t.value,o=u&&!!l?.tokens.length,r=o?a.value?t.value.admin.tokens.every(e=>!y(a.value,e)):t.value.admin.tokens.every(e=>!y(i.value,e)):!1;return{isEncrypted:o,isLocked:r,hint:l?.hint??""}}),validate:(u,l=!1)=>{(l?a:i).value=u}}};var B=f({name:"GlobalEncrypt",slots:Object,setup(t,{slots:a}){const{status:i,validate:u}=j(),l=d(!1);return E(()=>{l.value=!0}),()=>{const{isEncrypted:o,isLocked:r,hint:e}=i.value;return s(P,()=>o?l.value?r?s(k,{full:!0,hint:e,onVerify:u}):a.default():null:a.default())}}});const h=(t="",a)=>!!t&&y(t,a),S="VUEPRESS_HOPE_PATH_TOKEN",M=()=>{const t=V(),a=L(),i=b(S,{}),u=g(S,{}),l=r=>H(a.value.config)?G(a.value.config).filter(e=>K(decodeURI(r),e)).sort((e,c)=>c.length-e.length):[],o=r=>{const{config:e={}}=a.value,c=l(r);if(c.length>0){const v=c.find(n=>e[n].hint);return{isEncrypted:!0,isLocked:c.some(n=>(i.value[n]?e[n].tokens.every(p=>!h(i.value[n],p)):!0)&&(u.value[n]?e[n].tokens.every(p=>!h(u.value[n],p)):!0)),hint:v?e[v].hint:""}}return{isEncrypted:!1,isLocked:!1,hint:""}};return{status:m(()=>o(t.value.path)),getStatus:o,validate:(r,e=!1)=>{const{config:c={}}=a.value,v=l(t.value.path);for(const n of v)if(c[n].tokens.some(p=>h(r,p))){(e?i:u).value[n]=r;break}}}};var R=f({name:"LocalEncrypt",slots:Object,setup(t,{slots:a}){const{status:i,validate:u}=M(),l=d(!1);return E(()=>{l.value=!0}),()=>{const{isEncrypted:o,isLocked:r,hint:e}=i.value;return o?l.value?r?s(k,{showTitle:!0,full:!0,hint:e,onVerify:u}):a.default():null:a.default()}}});export{B as GlobalEncrypt,R as LocalEncrypt}; //# sourceMappingURL=encrypt.js.map