UNPKG

18x

Version:

util js for build web site

1 lines 941 B
var o,r,s,e,t,a;import{set as i}from"x/lang.js";import{hook as n,send as p}from"x/BC.js";import{onSet as f}from"x/lang.js";import{hook as m,send as c}from"x/share.js";import x from"x/LANG_CODE.js";import{get as d,set as v}from"x/cookie.js";o=new Set;export const onUser=s=>(o.add(s),void 0!==r&&s(r),()=>{o.delete(s)});export const User=()=>r;({V:s}=d(document.cookie)),s=s?parseInt(s,36):0,a=()=>{var o;o=[s],r?o.push(...r):o.push(r),localStorage.U=JSON.stringify(o)},t=o=>o?r&&r.every((r,s)=>o[s]===r):!1===r,e=s=>{var e,t;s?void 0!==(t=s[2])&&(t=x[t])!==e&&i(e=t):s=!1,r=s,o.forEach(o=>{o(s)})};export const setUser=o=>{var r;if(!t(o))for(r of(v("V",(++s).toString(36)),e(o),a(),[p,c]))r(0,o)};export const initUser=async(o,e)=>{var t,a,i;if(f(o=>{t!==o&&(r&&void 0!==t&&e(),t=o)}),!s){r=!1;return}if({U:a}=localStorage,a&&(a=JSON.parse(a))[0]===s){r=i=a[1]&&a.slice(1),c(0,i);return}setUser(await o())};n(0,o=>{t(o)||e(o)}),m(0,setUser);