UNPKG

vitepress-theme-tui

Version:
2 lines (1 loc) 5.42 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue");function H(e){return o.getCurrentScope()?(o.onScopeDispose(e),!0):!1}const U=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const q=Object.prototype.toString,K=e=>q.call(e)==="[object Object]",B=()=>{};function Q(...e){if(e.length!==1)return o.toRef(...e);const t=e[0];return typeof t=="function"?o.readonly(o.customRef(()=>({get:t,set:B}))):o.ref(t)}function X(e,t){function r(...u){return new Promise((c,d)=>{Promise.resolve(e(()=>t.apply(this,u),{fn:t,thisArg:this,args:u})).then(c).catch(d)})}return r}const z=e=>e();function Y(e=z,t={}){const{initialState:r="active"}=t,u=Q(r==="active");function c(){u.value=!1}function d(){u.value=!0}const h=(...i)=>{u.value&&e(...i)};return{isActive:o.readonly(u),pause:c,resume:d,eventFilter:h}}function F(e){return Array.isArray(e)?e:[e]}function Z(e){return o.getCurrentInstance()}function ee(e,t,r={}){const{eventFilter:u=z,...c}=r;return o.watch(e,X(u,t),c)}function te(e,t,r={}){const{eventFilter:u,initialState:c="active",...d}=r,{eventFilter:h,pause:i,resume:a,isActive:s}=Y(u,{initialState:c});return{stop:ee(e,t,{...d,eventFilter:h}),pause:i,resume:a,isActive:s}}function ne(e,t=!0,r){Z()?o.onMounted(e,r):t?e():o.nextTick(e)}function re(e,t,r){return o.watch(e,t,{...r,immediate:!0})}const j=U?window:void 0;function oe(e){var t;const r=o.toValue(e);return(t=r?.$el)!=null?t:r}function D(...e){const t=[],r=()=>{t.forEach(i=>i()),t.length=0},u=(i,a,s,p)=>(i.addEventListener(a,s,p),()=>i.removeEventListener(a,s,p)),c=o.computed(()=>{const i=F(o.toValue(e[0])).filter(a=>a!=null);return i.every(a=>typeof a!="string")?i:void 0}),d=re(()=>{var i,a;return[(a=(i=c.value)==null?void 0:i.map(s=>oe(s)))!=null?a:[j].filter(s=>s!=null),F(o.toValue(c.value?e[1]:e[0])),F(o.unref(c.value?e[2]:e[1])),o.toValue(c.value?e[3]:e[2])]},([i,a,s,p])=>{if(r(),!i?.length||!a?.length||!s?.length)return;const y=K(p)?{...p}:p;t.push(...i.flatMap(A=>a.flatMap(S=>s.map(b=>u(A,S,b,y)))))},{flush:"post"}),h=()=>{d(),r()};return H(r),h}const E=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},O="__vueuse_ssr_handlers__",ie=ue();function ue(){return O in E||(E[O]=E[O]||{}),E[O]}function ae(e,t){return ie[e]||t}function le(e){return e==null?"any":e instanceof Set?"set":e instanceof Map?"map":e instanceof Date?"date":typeof e=="boolean"?"boolean":typeof e=="string"?"string":typeof e=="object"?"object":Number.isNaN(e)?"any":"number"}const se={boolean:{read:e=>e==="true",write:e=>String(e)},object:{read:e=>JSON.parse(e),write:e=>JSON.stringify(e)},number:{read:e=>Number.parseFloat(e),write:e=>String(e)},any:{read:e=>e,write:e=>String(e)},string:{read:e=>e,write:e=>String(e)},map:{read:e=>new Map(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e.entries()))},set:{read:e=>new Set(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e))},date:{read:e=>new Date(e),write:e=>e.toISOString()}},N="vueuse-storage";function ce(e,t,r,u={}){var c;const{flush:d="pre",deep:h=!0,listenToStorageChanges:i=!0,writeDefaults:a=!0,mergeDefaults:s=!1,shallow:p,window:y=j,eventFilter:A,onError:S=n=>{console.error(n)},initOnMounted:b}=u,g=(p?o.shallowRef:o.ref)(t),m=o.computed(()=>o.toValue(e));if(!r)try{r=ae("getDefaultStorage",()=>{var n;return(n=j)==null?void 0:n.localStorage})()}catch(n){S(n)}if(!r)return g;const v=o.toValue(t),M=le(v),w=(c=u.serializer)!=null?c:se[M],{pause:R,resume:V}=te(g,n=>$(n),{flush:d,deep:h,eventFilter:A});o.watch(m,()=>T(),{flush:d});let C=!1;const I=n=>{b&&!C||T(n)},_=n=>{b&&!C||G(n)};y&&i&&(r instanceof Storage?D(y,"storage",I,{passive:!0}):D(y,N,_)),b?ne(()=>{C=!0,T()}):T();function W(n,l){if(y){const f={key:m.value,oldValue:n,newValue:l,storageArea:r};y.dispatchEvent(r instanceof Storage?new StorageEvent("storage",f):new CustomEvent(N,{detail:f}))}}function $(n){try{const l=r.getItem(m.value);if(n==null)W(l,null),r.removeItem(m.value);else{const f=w.write(n);l!==f&&(r.setItem(m.value,f),W(l,f))}}catch(l){S(l)}}function x(n){const l=n?n.newValue:r.getItem(m.value);if(l==null)return a&&v!=null&&r.setItem(m.value,w.write(v)),v;if(!n&&s){const f=w.read(l);return typeof s=="function"?s(f,v):M==="object"&&!Array.isArray(f)?{...v,...f}:f}else return typeof l!="string"?l:w.read(l)}function T(n){if(!(n&&n.storageArea!==r)){if(n&&n.key==null){g.value=v;return}if(!(n&&n.key!==m.value)){R();try{const l=w.write(g.value);(n===void 0||n?.newValue!==l)&&(g.value=x(n))}catch(l){S(l)}finally{n?o.nextTick(V):V()}}}}function G(n){T(n.detail)}return g}const k=[{name:"plain",label:"Plain"},{name:"default",label:"Default"},{name:"monokai",label:"Monokai"}],L=k.map(e=>e.name),J=ce("vp-tui-theme","default");function fe(){if(typeof document>"u")return"default";const e=document.documentElement;for(const t of k)if(e.classList.contains(t.className))return t.name;return"default"}function P(e){if(typeof document>"u")return!1;L.includes(e)||console.warn(`Theme "${e}" not found. Available themes: ${L.join(", ")}`);const t=document.documentElement;return t.classList.remove(...Array.from(t.classList).filter(r=>r.startsWith("tui-theme-"))),t.classList.add(`tui-theme-${e}`),J.value=e,!0}function de({theme:e}={}){P(e||"default")}exports.currentTheme=J;exports.getCurrentTheme=fe;exports.setTheme=P;exports.themes=k;exports.useTUI=de;