@gospore/theme 1.0.151 → 1.0.152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/theme.cjs.js +1 -1
- package/dist/theme.es.js +1 -1
- package/dist/theme.umd.js +1 -1
- package/package.json +4 -4
package/dist/theme.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vue`);require(`what-input`);let t=require(`@gospore/dropdown-menu`);var n=[`auto`,`light`,`dark`],r=`gospore-theme-mode`,i=3600*24*365,a=`(prefers-color-scheme: dark)`;function o(){if(typeof document>`u`)return null;let e=l(r);return f(e)?e:null}function s(e){if(typeof document>`u`||!n.includes(e))return;let t=typeof window<`u`?window.location.hostname:``,a=typeof window<`u`?window.location.protocol:``,o=u(t),s=a===`https:`,c=[`path=/`,`max-age=${i}`,`SameSite=Lax`];o&&c.push(`domain=${o}`),s&&c.push(`Secure`),document.cookie=[`${encodeURIComponent(r)}=${encodeURIComponent(e)}`,...c].join(`; `)}function c(e){if(typeof document>`u`)return;let t=f(e)?e:o()??`auto`;console.log(`Applying theme mode:`,t);let n=d(t);document.documentElement.setAttribute(`dark-mode`,String(n))}function l(e){if(typeof document>`u`||!document.cookie)return null;let t=`${encodeURIComponent(e)}=`,n=document.cookie.split(`; `);for(let e of n)if(e.startsWith(t))return decodeURIComponent(e.slice(t.length));return null}function u(e){if(!e||e===`localhost`)return null;if(/^\d+(?:\.\d+){3}$/.test(e))return e;let t=e.split(`.`);return t.length<=1?null:t.length===2?e:t.slice(-2).join(`.`)}function d(e){if(e===`dark`)return!0;if(e===`light`||typeof window>`u`)return!1;try{let e=typeof window.matchMedia==`function`?window.matchMedia(a):null;return e?e.matches:!1}catch{return!1}}function f(e){return typeof e==`string`&&n.includes(e)}var p=Symbol.for(`gospore.theme.portalHost`);function m(){let t=(0,e.inject)(p,null);console.log(`Using theme portal host:`,t);let n=typeof document<`u`?document.body:`body`;return(0,e.computed)(()=>t?.value??n)}var h=[],g=new Set,_=`(prefers-color-scheme: dark)`,v=`(prefers-reduced-motion: reduce)`,y=200,b=3.8,x=1.8,S=1.15,C=1.08,w=2.5,T=3,E=`#ffffff`,D=`#1f2228`,O=(0,e.defineComponent)({name:`Theme`,__name:`Theme`,props:{mode:{type:String,default:void 0,validator:e=>[`auto`,`light`,`dark`].includes(e)},accentColor:{type:String,required:!1,default:void 0},exposeGlobalAccent:{type:Boolean,default:!1}},setup(t){let n=t;function r(){let e=document.documentElement;if(!e)return;g.forEach(t=>{e.style.removeProperty(t)}),g.clear();let t=[...h].reverse().find(e=>e.enabled&&e.vars&&Object.keys(e.vars).length>0);t&&Object.entries(t.vars).forEach(([t,n])=>{e.style.setProperty(t,n),g.add(t)})}let i=window.matchMedia(_),a=window.matchMedia(v),s=j();c(s);let l=(0,e.ref)(s),u=(0,e.ref)({darkMode:m(s)}),d=(0,e.ref)(null);i.addEventListener(`change`,O),(0,e.watch)(()=>n.mode,()=>{f()},{immediate:!0}),(0,e.watch)(()=>u.value.darkMode,(e,t)=>{if(t===void 0){k(e);return}A(()=>{k(e)})},{immediate:!0}),(0,e.onBeforeUnmount)(()=>{i.removeEventListener(`change`,O);let e=h.indexOf($);e!==-1&&h.splice(e,1),r()});function f(){let e=j();l.value=e,u.value.darkMode=m(e)}function m(e){return e===`dark`?!0:e===`light`?!1:i.matches}function O(e){!e||l.value!==`auto`||(u.value.darkMode=e.matches)}function k(e){document.documentElement.setAttribute(`dark-mode`,String(e))}function A(e){if(a.matches){e();return}let t=document.startViewTransition?.bind(document);if(t){t(()=>{e()});return}e();let n=document.documentElement;typeof n.animate==`function`&&window.requestAnimationFrame(()=>{n.animate([{opacity:.85},{opacity:1}],{duration:y,easing:`ease-in-out`})})}function j(){return n.mode??o()??`auto`}(0,e.provide)(`theme`,u),(0,e.provide)(p,d);function M(e){if(!e)return null;let t=e.trim().toLowerCase();if(!/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t))return null;if(t.length===4){let e=t[1],n=t[2],r=t[3];return`#${e}${e}${n}${n}${r}${r}`}return t}function N(e){let t=M(e);return t?{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}:null}function P({r:e,g:t,b:n}){let r=e=>e.toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function F(e){return Math.max(0,Math.min(1,e))}function I(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function L(e){let t=F(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function R({r:e,g:t,b:n}){let r=e/255,i=t/255,a=n/255,o=I(r),s=I(i),c=I(a),l=.4122214708*o+.5363325363*s+.0514459929*c,u=.2119034982*o+.6806995451*s+.1073969566*c,d=.0883024619*o+.2817188376*s+.6299787005*c,f=Math.cbrt(l),p=Math.cbrt(u),m=Math.cbrt(d),h=.2104542553*f+.793617785*p-.0040720468*m,g=1.9779984951*f-2.428592205*p+.4505937099*m,_=.0259040371*f+.7827717662*p-.808675766*m,v=Math.sqrt(g*g+_*_),y=180/Math.PI*Math.atan2(_,g);return y<0&&(y+=360),{l:h,c:v,h:y}}function z(e,t,n,r=!1){let i=n*Math.PI/180,a=t*Math.cos(i),o=t*Math.sin(i),s=e+.3963377774*a+.2158037573*o,c=e-.1055613458*a-.0638541728*o,l=e-.0894841775*a-1.291485548*o,u=r?F(s):s,d=r?F(c):c,f=r?F(l):l;if(!r&&(u<-1e-4||u>1.0001||d<-1e-4||d>1.0001||f<-1e-4||f>1.0001))return null;let p=u*u*u,m=d*d*d,h=f*f*f,g=4.0767416621*p-3.3077115913*m+.2309699292*h,_=-1.2684380046*p+2.6097574011*m-.3413193965*h,v=-.0041960863*p-.7034186147*m+1.707614701*h;if(r)g=F(g),_=F(_),v=F(v);else if(g<-1e-4||g>1.0001||_<-1e-4||_>1.0001||v<-1e-4||v>1.0001)return null;let y=F(L(g)),b=F(L(_)),x=F(L(v));return{r:Math.round(y*255),g:Math.round(b*255),b:Math.round(x*255)}}function B(e,t,n){let r=t;for(let t=0;t<8;t+=1){let t=z(e,r,n);if(t)return t;r*=.9}return z(e,F(r),n,!0)||{r:0,g:0,b:0}}function V(e){let t=N(e);if(!t)return 0;let n=I(t.r/255),r=I(t.g/255),i=I(t.b/255);return .2126*n+.7152*r+.0722*i}function H(e,t){let n=V(e),r=V(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function U(e,t,n={}){let r=n.minContrast??b,i=n.preferDark!==!1,a=Math.max(.01,Math.min(.06,(e.c||.12)*(n.chromaScale??.25))),o=n.initialLightness??(i?.24:.94),s=i?-1:1,c=n.step??.03,l=F(o),u=P(B(l,a,e.h)),d=H(t,u);for(let n=0;n<48;n+=1){let n=P(B(l,a,e.h)),i=H(t,n);if(i>d&&(d=i,u=n),i>=r)return n;if(l=F(l+s*c),l===0||l===1)break}let f=`#101214`,p=`#ffffff`,m=H(t,f),h=H(t,p);return m>=r||h>=r?m>=h?f:p:u}function W(e,t,n={}){let r=n.minContrast??b,i=n.darkCandidate??`#101214`,a=n.lightCandidate??`#ffffff`,o=n.preferredCandidate,s=n.preferredMinContrast??r,c=n.preferredSwitchDelta??0,l=H(t,i),u=H(t,a),d=l>=r,f=u>=r,p=u>=s,m=l>=s;if(d||f)return o===`light`&&p?a:o===`dark`&&m?i:o===`light`&&f?!d||l-u<=c?a:i:o===`dark`&&d?!f||u-l<=c?i:a:d&&f?l>=u?i:a:d?i:a;let h=l>=u;return U(e,t,{minContrast:r,preferDark:h,initialLightness:h?.2:.96,chromaScale:.1})}let G=[100,200,300,400,500,600,700,800,900,1e3],K=[.9,.84,.78,.72,.67,.62,.56,.5,.44,.38],q=[.28,.4,.54,.7,.86,1,1.08,1.14,1.2,1.24];function J(e,t,n,r){let i=t[t.length-1];for(let i of t){let t=e[i];if(t&&H(t,n)>=r)return i}return i}function Y(e){let t=e.l-K[5],n=e.c>.02?.02:0;return G.reduce((r,i,a)=>(r[i]=P(B(F(K[a]+t),Math.min(.4,Math.max(n,e.c*q[a])),e.h)),r),{})}function X(e,t){let n=[100,200,300,400,500,600,700],r=J(t,n,E,C),i=n.indexOf(r),a=n[Math.min(i+1,n.length-1)],o=n[Math.min(i+2,n.length-1)],s=[1e3,900,800,700,600,500],c=J(t,s,D,C),l=s.indexOf(c),u=s[Math.min(l+1,s.length-1)],d=s[Math.min(l+2,s.length-1)],f=J(t,[200,300,400,500,600,700,800],E,S),p=J(t,[900,800,700,600,500,400],D,S),m=[600,700,800,900,1e3],h=J(t,m,E,x),g=m.indexOf(h),_=m[Math.min(g+1,m.length-1)],v=m[Math.min(g+2,m.length-1)],y=[400,300,200,100],O=J(t,y,D,x),k=y.indexOf(O),A=y[Math.min(k+1,y.length-1)],j=y[Math.min(k+2,y.length-1)],M={"--color-brand-surface-soft-light":t[r],"--color-brand-surface-soft-hovered-light":t[a],"--color-brand-surface-soft-pressed-light":t[o],"--color-brand-surface-soft-dark":t[c],"--color-brand-surface-soft-hovered-dark":t[u],"--color-brand-surface-soft-pressed-dark":t[d],"--color-brand-surface-subtle-light":t[f],"--color-brand-surface-subtle-dark":t[p],"--color-brand-surface-strong-light":t[h],"--color-brand-surface-strong-hovered-light":t[_],"--color-brand-surface-strong-pressed-light":t[v],"--color-brand-surface-strong-dark":t[O],"--color-brand-surface-strong-hovered-dark":t[A],"--color-brand-surface-strong-pressed-dark":t[j]},N=t[600];return M[`--color-brand-on-soft-light`]=H(M[`--color-brand-surface-soft-light`],N)>=b?N:W(e,M[`--color-brand-surface-soft-light`],{minContrast:b}),M[`--color-brand-on-soft-dark`]=W(e,M[`--color-brand-surface-soft-dark`],{minContrast:b}),M[`--color-brand-on-subtle-light`]=W(e,M[`--color-brand-surface-subtle-light`],{minContrast:w,preferredCandidate:`light`,preferredMinContrast:w,preferredSwitchDelta:T}),M[`--color-brand-on-subtle-dark`]=W(e,M[`--color-brand-surface-subtle-dark`],{minContrast:b}),M[`--color-brand-on-strong-light`]=W(e,M[`--color-brand-surface-strong-light`],{minContrast:w,preferredCandidate:`light`,preferredMinContrast:w,preferredSwitchDelta:T}),M[`--color-brand-on-strong-dark`]=W(e,M[`--color-brand-surface-strong-dark`],{minContrast:b}),M[`--color-brand-text-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-text-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-icon-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-icon-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-border-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-border-dark`]=M[`--color-brand-surface-strong-dark`],M}function Z(e){let t=M(e);if(!t)return null;let n=N(t);if(!n)return null;let r=R(n),i=Y(r);return i[600]=t,{"--color-brand-seed":t,"--color-brand-100":i[100],"--color-brand-200":i[200],"--color-brand-300":i[300],"--color-brand-400":i[400],"--color-brand-500":i[500],"--color-brand-600":i[600],"--color-brand-700":i[700],"--color-brand-800":i[800],"--color-brand-900":i[900],"--color-brand-1000":i[1e3],...X(r,i)}}let Q=(0,e.computed)(()=>Z(n.accentColor)??{}),$={vars:{},enabled:!!n.exposeGlobalAccent};return h.push($),(0,e.watch)(()=>n.exposeGlobalAccent,e=>{$.enabled=!!e,r()},{immediate:!0}),(0,e.watch)(Q,e=>{e&&Object.keys(e).length>0?$.vars={...e}:$.vars={},r()},{immediate:!0}),(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:`theme`,style:(0,e.normalizeStyle)(Q.value)},[(0,e.renderSlot)(t.$slots,`default`),(0,e.createElementVNode)(`div`,{ref_key:`portalHost`,ref:d,class:`theme__portal-host`},null,512)],4))}}),k=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,e.defineComponent)({__name:`ThemeSwitcher`,props:{mode:{type:String,default:`auto`,validator:e=>[`auto`,`light`,`dark`].includes(e)}},emits:[`update:mode`],setup(r,{emit:i}){let a=[{value:`auto`,label:`System`},{value:`light`,label:`Light`},{value:`dark`,label:`Dark`}].reduce((e,t)=>(e[t.value]=t.label,e),{}),l=n,u=r,d=i;c();let f=(0,e.ref)(!1),p=o()??u.mode,m=(0,e.ref)(l.includes(p)?p:`auto`);return(0,e.watch)(()=>u.mode,e=>{l.includes(e)&&e!==m.value&&(m.value=e)}),(0,e.watch)(m,e=>{if(!l.includes(e)){m.value=`auto`;return}f.value=!1,d(`update:mode`,e),s(e),c(e)},{immediate:!0}),(n,r)=>((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(t.DropdownMenu),{open:f.value,"onUpdate:open":r[3]||=e=>f.value=e,text:`Theme`,"aria-label":`Select theme mode`},{default:(0,e.withCtx)(()=>[(0,e.createVNode)((0,e.unref)(t.DropdownItemGroup),{title:`Theme`,"item-role":`menuitemradio`},{default:(0,e.withCtx)(()=>[(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[0]||=e=>m.value=e,value:`auto`,label:(0,e.unref)(a).auto,"aria-label":`${(0,e.unref)(a).auto} mode`},null,8,[`checked`,`label`,`aria-label`]),r[4]||=(0,e.createElementVNode)(`hr`,{class:`theme-switcher-divider`},null,-1),(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[1]||=e=>m.value=e,value:`light`,label:(0,e.unref)(a).light,"aria-label":`${(0,e.unref)(a).light} mode`},null,8,[`checked`,`label`,`aria-label`]),(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[2]||=e=>m.value=e,value:`dark`,label:(0,e.unref)(a).dark,"aria-label":`${(0,e.unref)(a).dark} mode`},null,8,[`checked`,`label`,`aria-label`])]),_:1})]),_:1},8,[`open`]))}}),[[`__scopeId`,`data-v-be9d7090`]]);exports.Theme=O,exports.ThemeSwitcher=k,exports.themePortalHostKey=p,exports.useThemePortalTarget=m;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue");require("what-input");let t=require("@gospore/dropdown-menu");var n=[`auto`,`light`,`dark`],r=`gospore-theme-mode`,i=3600*24*365,a=`(prefers-color-scheme: dark)`;function o(){if(typeof document>`u`)return null;let e=l(r);return f(e)?e:null}function s(e){if(typeof document>`u`||!n.includes(e))return;let t=typeof window<`u`?window.location.hostname:``,a=typeof window<`u`?window.location.protocol:``,o=u(t),s=a===`https:`,c=[`path=/`,`max-age=${i}`,`SameSite=Lax`];o&&c.push(`domain=${o}`),s&&c.push(`Secure`),document.cookie=[`${encodeURIComponent(r)}=${encodeURIComponent(e)}`,...c].join(`; `)}function c(e){if(typeof document>`u`)return;let t=f(e)?e:o()??`auto`;console.log(`Applying theme mode:`,t);let n=d(t);document.documentElement.setAttribute(`dark-mode`,String(n))}function l(e){if(typeof document>`u`||!document.cookie)return null;let t=`${encodeURIComponent(e)}=`,n=document.cookie.split(`; `);for(let e of n)if(e.startsWith(t))return decodeURIComponent(e.slice(t.length));return null}function u(e){if(!e||e===`localhost`)return null;if(/^\d+(?:\.\d+){3}$/.test(e))return e;let t=e.split(`.`);return t.length<=1?null:t.length===2?e:t.slice(-2).join(`.`)}function d(e){if(e===`dark`)return!0;if(e===`light`||typeof window>`u`)return!1;try{let e=typeof window.matchMedia==`function`?window.matchMedia(a):null;return e?e.matches:!1}catch{return!1}}function f(e){return typeof e==`string`&&n.includes(e)}var p=Symbol.for(`gospore.theme.portalHost`);function m(){let t=(0,e.inject)(p,null);console.log(`Using theme portal host:`,t);let n=typeof document<`u`?document.body:`body`;return(0,e.computed)(()=>t?.value??n)}var h=[],g=new Set,_=`(prefers-color-scheme: dark)`,v=`(prefers-reduced-motion: reduce)`,y=200,b=3.8,x=1.8,S=1.15,C=1.08,w=2.5,T=3,E=`#ffffff`,D=`#1f2228`,O=(0,e.defineComponent)({name:`Theme`,__name:`Theme`,props:{mode:{type:String,default:void 0,validator:e=>[`auto`,`light`,`dark`].includes(e)},accentColor:{type:String,required:!1,default:void 0},exposeGlobalAccent:{type:Boolean,default:!1}},setup(t){let n=t;function r(){let e=document.documentElement;if(!e)return;g.forEach(t=>{e.style.removeProperty(t)}),g.clear();let t=[...h].reverse().find(e=>e.enabled&&e.vars&&Object.keys(e.vars).length>0);t&&Object.entries(t.vars).forEach(([t,n])=>{e.style.setProperty(t,n),g.add(t)})}let i=window.matchMedia(_),a=window.matchMedia(v),s=j();c(s);let l=(0,e.ref)(s),u=(0,e.ref)({darkMode:m(s)}),d=(0,e.ref)(null);i.addEventListener(`change`,O),(0,e.watch)(()=>n.mode,()=>{f()},{immediate:!0}),(0,e.watch)(()=>u.value.darkMode,(e,t)=>{if(t===void 0){k(e);return}A(()=>{k(e)})},{immediate:!0}),(0,e.onBeforeUnmount)(()=>{i.removeEventListener(`change`,O);let e=h.indexOf($);e!==-1&&h.splice(e,1),r()});function f(){let e=j();l.value=e,u.value.darkMode=m(e)}function m(e){return e===`dark`?!0:e===`light`?!1:i.matches}function O(e){!e||l.value!==`auto`||(u.value.darkMode=e.matches)}function k(e){document.documentElement.setAttribute(`dark-mode`,String(e))}function A(e){if(a.matches){e();return}let t=document.startViewTransition?.bind(document);if(t){t(()=>{e()});return}e();let n=document.documentElement;typeof n.animate==`function`&&window.requestAnimationFrame(()=>{n.animate([{opacity:.85},{opacity:1}],{duration:y,easing:`ease-in-out`})})}function j(){return n.mode??o()??`auto`}(0,e.provide)(`theme`,u),(0,e.provide)(p,d);function M(e){if(!e)return null;let t=e.trim().toLowerCase();if(!/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t))return null;if(t.length===4){let e=t[1],n=t[2],r=t[3];return`#${e}${e}${n}${n}${r}${r}`}return t}function N(e){let t=M(e);return t?{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}:null}function P({r:e,g:t,b:n}){let r=e=>e.toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function F(e){return Math.max(0,Math.min(1,e))}function I(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function L(e){let t=F(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function R({r:e,g:t,b:n}){let r=e/255,i=t/255,a=n/255,o=I(r),s=I(i),c=I(a),l=.4122214708*o+.5363325363*s+.0514459929*c,u=.2119034982*o+.6806995451*s+.1073969566*c,d=.0883024619*o+.2817188376*s+.6299787005*c,f=Math.cbrt(l),p=Math.cbrt(u),m=Math.cbrt(d),h=.2104542553*f+.793617785*p-.0040720468*m,g=1.9779984951*f-2.428592205*p+.4505937099*m,_=.0259040371*f+.7827717662*p-.808675766*m,v=Math.sqrt(g*g+_*_),y=180/Math.PI*Math.atan2(_,g);return y<0&&(y+=360),{l:h,c:v,h:y}}function z(e,t,n,r=!1){let i=n*Math.PI/180,a=t*Math.cos(i),o=t*Math.sin(i),s=e+.3963377774*a+.2158037573*o,c=e-.1055613458*a-.0638541728*o,l=e-.0894841775*a-1.291485548*o,u=r?F(s):s,d=r?F(c):c,f=r?F(l):l;if(!r&&(u<-1e-4||u>1.0001||d<-1e-4||d>1.0001||f<-1e-4||f>1.0001))return null;let p=u*u*u,m=d*d*d,h=f*f*f,g=4.0767416621*p-3.3077115913*m+.2309699292*h,_=-1.2684380046*p+2.6097574011*m-.3413193965*h,v=-.0041960863*p-.7034186147*m+1.707614701*h;if(r)g=F(g),_=F(_),v=F(v);else if(g<-1e-4||g>1.0001||_<-1e-4||_>1.0001||v<-1e-4||v>1.0001)return null;let y=F(L(g)),b=F(L(_)),x=F(L(v));return{r:Math.round(y*255),g:Math.round(b*255),b:Math.round(x*255)}}function B(e,t,n){let r=t;for(let t=0;t<8;t+=1){let t=z(e,r,n);if(t)return t;r*=.9}return z(e,F(r),n,!0)||{r:0,g:0,b:0}}function V(e){let t=N(e);if(!t)return 0;let n=I(t.r/255),r=I(t.g/255),i=I(t.b/255);return .2126*n+.7152*r+.0722*i}function H(e,t){let n=V(e),r=V(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function U(e,t,n={}){let r=n.minContrast??b,i=n.preferDark!==!1,a=Math.max(.01,Math.min(.06,(e.c||.12)*(n.chromaScale??.25))),o=n.initialLightness??(i?.24:.94),s=i?-1:1,c=n.step??.03,l=F(o),u=P(B(l,a,e.h)),d=H(t,u);for(let n=0;n<48;n+=1){let n=P(B(l,a,e.h)),i=H(t,n);if(i>d&&(d=i,u=n),i>=r)return n;if(l=F(l+s*c),l===0||l===1)break}let f=`#101214`,p=`#ffffff`,m=H(t,f),h=H(t,p);return m>=r||h>=r?m>=h?f:p:u}function W(e,t,n={}){let r=n.minContrast??b,i=n.darkCandidate??`#101214`,a=n.lightCandidate??`#ffffff`,o=n.preferredCandidate,s=n.preferredMinContrast??r,c=n.preferredSwitchDelta??0,l=H(t,i),u=H(t,a),d=l>=r,f=u>=r,p=u>=s,m=l>=s;if(d||f)return o===`light`&&p?a:o===`dark`&&m?i:o===`light`&&f?!d||l-u<=c?a:i:o===`dark`&&d?!f||u-l<=c?i:a:d&&f?l>=u?i:a:d?i:a;let h=l>=u;return U(e,t,{minContrast:r,preferDark:h,initialLightness:h?.2:.96,chromaScale:.1})}let G=[100,200,300,400,500,600,700,800,900,1e3],K=[.9,.84,.78,.72,.67,.62,.56,.5,.44,.38],q=[.28,.4,.54,.7,.86,1,1.08,1.14,1.2,1.24];function J(e,t,n,r){let i=t[t.length-1];for(let i of t){let t=e[i];if(t&&H(t,n)>=r)return i}return i}function Y(e){let t=e.l-K[5],n=e.c>.02?.02:0;return G.reduce((r,i,a)=>(r[i]=P(B(F(K[a]+t),Math.min(.4,Math.max(n,e.c*q[a])),e.h)),r),{})}function X(e,t){let n=[100,200,300,400,500,600,700],r=J(t,n,E,C),i=n.indexOf(r),a=n[Math.min(i+1,n.length-1)],o=n[Math.min(i+2,n.length-1)],s=[1e3,900,800,700,600,500],c=J(t,s,D,C),l=s.indexOf(c),u=s[Math.min(l+1,s.length-1)],d=s[Math.min(l+2,s.length-1)],f=J(t,[200,300,400,500,600,700,800],E,S),p=J(t,[900,800,700,600,500,400],D,S),m=[600,700,800,900,1e3],h=J(t,m,E,x),g=m.indexOf(h),_=m[Math.min(g+1,m.length-1)],v=m[Math.min(g+2,m.length-1)],y=[400,300,200,100],O=J(t,y,D,x),k=y.indexOf(O),A=y[Math.min(k+1,y.length-1)],j=y[Math.min(k+2,y.length-1)],M={"--color-brand-surface-soft-light":t[r],"--color-brand-surface-soft-hovered-light":t[a],"--color-brand-surface-soft-pressed-light":t[o],"--color-brand-surface-soft-dark":t[c],"--color-brand-surface-soft-hovered-dark":t[u],"--color-brand-surface-soft-pressed-dark":t[d],"--color-brand-surface-subtle-light":t[f],"--color-brand-surface-subtle-dark":t[p],"--color-brand-surface-strong-light":t[h],"--color-brand-surface-strong-hovered-light":t[_],"--color-brand-surface-strong-pressed-light":t[v],"--color-brand-surface-strong-dark":t[O],"--color-brand-surface-strong-hovered-dark":t[A],"--color-brand-surface-strong-pressed-dark":t[j]},N=t[600];return M[`--color-brand-on-soft-light`]=H(M[`--color-brand-surface-soft-light`],N)>=b?N:W(e,M[`--color-brand-surface-soft-light`],{minContrast:b}),M[`--color-brand-on-soft-dark`]=W(e,M[`--color-brand-surface-soft-dark`],{minContrast:b}),M[`--color-brand-on-subtle-light`]=W(e,M[`--color-brand-surface-subtle-light`],{minContrast:w,preferredCandidate:`light`,preferredMinContrast:w,preferredSwitchDelta:T}),M[`--color-brand-on-subtle-dark`]=W(e,M[`--color-brand-surface-subtle-dark`],{minContrast:b}),M[`--color-brand-on-strong-light`]=W(e,M[`--color-brand-surface-strong-light`],{minContrast:w,preferredCandidate:`light`,preferredMinContrast:w,preferredSwitchDelta:T}),M[`--color-brand-on-strong-dark`]=W(e,M[`--color-brand-surface-strong-dark`],{minContrast:b}),M[`--color-brand-text-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-text-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-icon-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-icon-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-border-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-border-dark`]=M[`--color-brand-surface-strong-dark`],M}function Z(e){let t=M(e);if(!t)return null;let n=N(t);if(!n)return null;let r=R(n),i=Y(r);return i[600]=t,{"--color-brand-seed":t,"--color-brand-100":i[100],"--color-brand-200":i[200],"--color-brand-300":i[300],"--color-brand-400":i[400],"--color-brand-500":i[500],"--color-brand-600":i[600],"--color-brand-700":i[700],"--color-brand-800":i[800],"--color-brand-900":i[900],"--color-brand-1000":i[1e3],...X(r,i)}}let Q=(0,e.computed)(()=>Z(n.accentColor)??{}),$={vars:{},enabled:!!n.exposeGlobalAccent};return h.push($),(0,e.watch)(()=>n.exposeGlobalAccent,e=>{$.enabled=!!e,r()},{immediate:!0}),(0,e.watch)(Q,e=>{e&&Object.keys(e).length>0?$.vars={...e}:$.vars={},r()},{immediate:!0}),(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:`theme`,style:(0,e.normalizeStyle)(Q.value)},[(0,e.renderSlot)(t.$slots,`default`),(0,e.createElementVNode)(`div`,{ref_key:`portalHost`,ref:d,class:`theme__portal-host`},null,512)],4))}}),k=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,e.defineComponent)({__name:`ThemeSwitcher`,props:{mode:{type:String,default:`auto`,validator:e=>[`auto`,`light`,`dark`].includes(e)}},emits:[`update:mode`],setup(r,{emit:i}){let a=[{value:`auto`,label:`System`},{value:`light`,label:`Light`},{value:`dark`,label:`Dark`}].reduce((e,t)=>(e[t.value]=t.label,e),{}),l=n,u=r,d=i;c();let f=(0,e.ref)(!1),p=o()??u.mode,m=(0,e.ref)(l.includes(p)?p:`auto`);return(0,e.watch)(()=>u.mode,e=>{l.includes(e)&&e!==m.value&&(m.value=e)}),(0,e.watch)(m,e=>{if(!l.includes(e)){m.value=`auto`;return}f.value=!1,d(`update:mode`,e),s(e),c(e)},{immediate:!0}),(n,r)=>((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(t.DropdownMenu),{open:f.value,"onUpdate:open":r[3]||=e=>f.value=e,text:`Theme`,"aria-label":`Select theme mode`},{default:(0,e.withCtx)(()=>[(0,e.createVNode)((0,e.unref)(t.DropdownItemGroup),{title:`Theme`,"item-role":`menuitemradio`},{default:(0,e.withCtx)(()=>[(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[0]||=e=>m.value=e,value:`auto`,label:(0,e.unref)(a).auto,"aria-label":`${(0,e.unref)(a).auto} mode`},null,8,[`checked`,`label`,`aria-label`]),r[4]||=(0,e.createElementVNode)(`hr`,{class:`theme-switcher-divider`},null,-1),(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[1]||=e=>m.value=e,value:`light`,label:(0,e.unref)(a).light,"aria-label":`${(0,e.unref)(a).light} mode`},null,8,[`checked`,`label`,`aria-label`]),(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[2]||=e=>m.value=e,value:`dark`,label:(0,e.unref)(a).dark,"aria-label":`${(0,e.unref)(a).dark} mode`},null,8,[`checked`,`label`,`aria-label`])]),_:1})]),_:1},8,[`open`]))}}),[[`__scopeId`,`data-v-be9d7090`]]);exports.Theme=O,exports.ThemeSwitcher=k,exports.themePortalHostKey=p,exports.useThemePortalTarget=m;
|
|
2
2
|
//# sourceMappingURL=theme.cjs.js.map
|
package/dist/theme.es.js
CHANGED
|
@@ -407,7 +407,7 @@ var M = [], N = /* @__PURE__ */ new Set(), ee = "(prefers-color-scheme: dark)",
|
|
|
407
407
|
class: "theme__portal-host"
|
|
408
408
|
}, null, 512)], 4));
|
|
409
409
|
}
|
|
410
|
-
}), U =
|
|
410
|
+
}), U = /*#__PURE__*/ ((e, t) => {
|
|
411
411
|
let n = e.__vccOpts || e;
|
|
412
412
|
for (let [e, r] of t) n[e] = r;
|
|
413
413
|
return n;
|
package/dist/theme.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`vue`),require(`what-input`),require(`@gospore/dropdown-menu`)):typeof define==`function`&&define.amd?define([`exports`,`vue`,`what-input`,`@gospore/dropdown-menu`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.theme={},e.Vue,e.whatInput,e.DropdownMenu))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=[`auto`,`light`,`dark`],a=`gospore-theme-mode`,o=3600*24*365,s=`(prefers-color-scheme: dark)`;function c(){if(typeof document>`u`)return null;let e=d(a);return m(e)?e:null}function l(e){if(typeof document>`u`||!i.includes(e))return;let t=typeof window<`u`?window.location.hostname:``,n=typeof window<`u`?window.location.protocol:``,r=f(t),s=n===`https:`,c=[`path=/`,`max-age=${o}`,`SameSite=Lax`];r&&c.push(`domain=${r}`),s&&c.push(`Secure`),document.cookie=[`${encodeURIComponent(a)}=${encodeURIComponent(e)}`,...c].join(`; `)}function u(e){if(typeof document>`u`)return;let t=m(e)?e:c()??`auto`;console.log(`Applying theme mode:`,t);let n=p(t);document.documentElement.setAttribute(`dark-mode`,String(n))}function d(e){if(typeof document>`u`||!document.cookie)return null;let t=`${encodeURIComponent(e)}=`,n=document.cookie.split(`; `);for(let e of n)if(e.startsWith(t))return decodeURIComponent(e.slice(t.length));return null}function f(e){if(!e||e===`localhost`)return null;if(/^\d+(?:\.\d+){3}$/.test(e))return e;let t=e.split(`.`);return t.length<=1?null:t.length===2?e:t.slice(-2).join(`.`)}function p(e){if(e===`dark`)return!0;if(e===`light`||typeof window>`u`)return!1;try{let e=typeof window.matchMedia==`function`?window.matchMedia(s):null;return e?e.matches:!1}catch{return!1}}function m(e){return typeof e==`string`&&i.includes(e)}var h=Symbol.for(`gospore.theme.portalHost`);function g(){let e=(0,t.inject)(h,null);console.log(`Using theme portal host:`,e);let n=typeof document<`u`?document.body:`body`;return(0,t.computed)(()=>e?.value??n)}var _=[],v=new Set,y=`(prefers-color-scheme: dark)`,b=`(prefers-reduced-motion: reduce)`,x=200,S=3.8,C=1.8,w=1.15,T=1.08,E=2.5,D=3,O=`#ffffff`,k=`#1f2228`,A=(0,t.defineComponent)({name:`Theme`,__name:`Theme`,props:{mode:{type:String,default:void 0,validator:e=>[`auto`,`light`,`dark`].includes(e)},accentColor:{type:String,required:!1,default:void 0},exposeGlobalAccent:{type:Boolean,default:!1}},setup(e){let n=e;function r(){let e=document.documentElement;if(!e)return;v.forEach(t=>{e.style.removeProperty(t)}),v.clear();let t=[..._].reverse().find(e=>e.enabled&&e.vars&&Object.keys(e.vars).length>0);t&&Object.entries(t.vars).forEach(([t,n])=>{e.style.setProperty(t,n),v.add(t)})}let i=window.matchMedia(y),a=window.matchMedia(b),o=j();u(o);let s=(0,t.ref)(o),l=(0,t.ref)({darkMode:p(o)}),d=(0,t.ref)(null);i.addEventListener(`change`,m),(0,t.watch)(()=>n.mode,()=>{f()},{immediate:!0}),(0,t.watch)(()=>l.value.darkMode,(e,t)=>{if(t===void 0){g(e);return}A(()=>{g(e)})},{immediate:!0}),(0,t.onBeforeUnmount)(()=>{i.removeEventListener(`change`,m);let e=_.indexOf($);e!==-1&&_.splice(e,1),r()});function f(){let e=j();s.value=e,l.value.darkMode=p(e)}function p(e){return e===`dark`?!0:e===`light`?!1:i.matches}function m(e){!e||s.value!==`auto`||(l.value.darkMode=e.matches)}function g(e){document.documentElement.setAttribute(`dark-mode`,String(e))}function A(e){if(a.matches){e();return}let t=document.startViewTransition?.bind(document);if(t){t(()=>{e()});return}e();let n=document.documentElement;typeof n.animate==`function`&&window.requestAnimationFrame(()=>{n.animate([{opacity:.85},{opacity:1}],{duration:x,easing:`ease-in-out`})})}function j(){return n.mode??c()??`auto`}(0,t.provide)(`theme`,l),(0,t.provide)(h,d);function M(e){if(!e)return null;let t=e.trim().toLowerCase();if(!/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t))return null;if(t.length===4){let e=t[1],n=t[2],r=t[3];return`#${e}${e}${n}${n}${r}${r}`}return t}function N(e){let t=M(e);return t?{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}:null}function P({r:e,g:t,b:n}){let r=e=>e.toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function F(e){return Math.max(0,Math.min(1,e))}function I(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function L(e){let t=F(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function R({r:e,g:t,b:n}){let r=e/255,i=t/255,a=n/255,o=I(r),s=I(i),c=I(a),l=.4122214708*o+.5363325363*s+.0514459929*c,u=.2119034982*o+.6806995451*s+.1073969566*c,d=.0883024619*o+.2817188376*s+.6299787005*c,f=Math.cbrt(l),p=Math.cbrt(u),m=Math.cbrt(d),h=.2104542553*f+.793617785*p-.0040720468*m,g=1.9779984951*f-2.428592205*p+.4505937099*m,_=.0259040371*f+.7827717662*p-.808675766*m,v=Math.sqrt(g*g+_*_),y=180/Math.PI*Math.atan2(_,g);return y<0&&(y+=360),{l:h,c:v,h:y}}function z(e,t,n,r=!1){let i=n*Math.PI/180,a=t*Math.cos(i),o=t*Math.sin(i),s=e+.3963377774*a+.2158037573*o,c=e-.1055613458*a-.0638541728*o,l=e-.0894841775*a-1.291485548*o,u=r?F(s):s,d=r?F(c):c,f=r?F(l):l;if(!r&&(u<-1e-4||u>1.0001||d<-1e-4||d>1.0001||f<-1e-4||f>1.0001))return null;let p=u*u*u,m=d*d*d,h=f*f*f,g=4.0767416621*p-3.3077115913*m+.2309699292*h,_=-1.2684380046*p+2.6097574011*m-.3413193965*h,v=-.0041960863*p-.7034186147*m+1.707614701*h;if(r)g=F(g),_=F(_),v=F(v);else if(g<-1e-4||g>1.0001||_<-1e-4||_>1.0001||v<-1e-4||v>1.0001)return null;let y=F(L(g)),b=F(L(_)),x=F(L(v));return{r:Math.round(y*255),g:Math.round(b*255),b:Math.round(x*255)}}function B(e,t,n){let r=t;for(let t=0;t<8;t+=1){let t=z(e,r,n);if(t)return t;r*=.9}return z(e,F(r),n,!0)||{r:0,g:0,b:0}}function V(e){let t=N(e);if(!t)return 0;let n=I(t.r/255),r=I(t.g/255),i=I(t.b/255);return .2126*n+.7152*r+.0722*i}function H(e,t){let n=V(e),r=V(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function U(e,t,n={}){let r=n.minContrast??S,i=n.preferDark!==!1,a=Math.max(.01,Math.min(.06,(e.c||.12)*(n.chromaScale??.25))),o=n.initialLightness??(i?.24:.94),s=i?-1:1,c=n.step??.03,l=F(o),u=P(B(l,a,e.h)),d=H(t,u);for(let n=0;n<48;n+=1){let n=P(B(l,a,e.h)),i=H(t,n);if(i>d&&(d=i,u=n),i>=r)return n;if(l=F(l+s*c),l===0||l===1)break}let f=`#101214`,p=`#ffffff`,m=H(t,f),h=H(t,p);return m>=r||h>=r?m>=h?f:p:u}function W(e,t,n={}){let r=n.minContrast??S,i=n.darkCandidate??`#101214`,a=n.lightCandidate??`#ffffff`,o=n.preferredCandidate,s=n.preferredMinContrast??r,c=n.preferredSwitchDelta??0,l=H(t,i),u=H(t,a),d=l>=r,f=u>=r,p=u>=s,m=l>=s;if(d||f)return o===`light`&&p?a:o===`dark`&&m?i:o===`light`&&f?!d||l-u<=c?a:i:o===`dark`&&d?!f||u-l<=c?i:a:d&&f?l>=u?i:a:d?i:a;let h=l>=u;return U(e,t,{minContrast:r,preferDark:h,initialLightness:h?.2:.96,chromaScale:.1})}let G=[100,200,300,400,500,600,700,800,900,1e3],K=[.9,.84,.78,.72,.67,.62,.56,.5,.44,.38],q=[.28,.4,.54,.7,.86,1,1.08,1.14,1.2,1.24];function J(e,t,n,r){let i=t[t.length-1];for(let i of t){let t=e[i];if(t&&H(t,n)>=r)return i}return i}function Y(e){let t=e.l-K[5],n=e.c>.02?.02:0;return G.reduce((r,i,a)=>(r[i]=P(B(F(K[a]+t),Math.min(.4,Math.max(n,e.c*q[a])),e.h)),r),{})}function X(e,t){let n=[100,200,300,400,500,600,700],r=J(t,n,O,T),i=n.indexOf(r),a=n[Math.min(i+1,n.length-1)],o=n[Math.min(i+2,n.length-1)],s=[1e3,900,800,700,600,500],c=J(t,s,k,T),l=s.indexOf(c),u=s[Math.min(l+1,s.length-1)],d=s[Math.min(l+2,s.length-1)],f=J(t,[200,300,400,500,600,700,800],O,w),p=J(t,[900,800,700,600,500,400],k,w),m=[600,700,800,900,1e3],h=J(t,m,O,C),g=m.indexOf(h),_=m[Math.min(g+1,m.length-1)],v=m[Math.min(g+2,m.length-1)],y=[400,300,200,100],b=J(t,y,k,C),x=y.indexOf(b),A=y[Math.min(x+1,y.length-1)],j=y[Math.min(x+2,y.length-1)],M={"--color-brand-surface-soft-light":t[r],"--color-brand-surface-soft-hovered-light":t[a],"--color-brand-surface-soft-pressed-light":t[o],"--color-brand-surface-soft-dark":t[c],"--color-brand-surface-soft-hovered-dark":t[u],"--color-brand-surface-soft-pressed-dark":t[d],"--color-brand-surface-subtle-light":t[f],"--color-brand-surface-subtle-dark":t[p],"--color-brand-surface-strong-light":t[h],"--color-brand-surface-strong-hovered-light":t[_],"--color-brand-surface-strong-pressed-light":t[v],"--color-brand-surface-strong-dark":t[b],"--color-brand-surface-strong-hovered-dark":t[A],"--color-brand-surface-strong-pressed-dark":t[j]},N=t[600];return M[`--color-brand-on-soft-light`]=H(M[`--color-brand-surface-soft-light`],N)>=S?N:W(e,M[`--color-brand-surface-soft-light`],{minContrast:S}),M[`--color-brand-on-soft-dark`]=W(e,M[`--color-brand-surface-soft-dark`],{minContrast:S}),M[`--color-brand-on-subtle-light`]=W(e,M[`--color-brand-surface-subtle-light`],{minContrast:E,preferredCandidate:`light`,preferredMinContrast:E,preferredSwitchDelta:D}),M[`--color-brand-on-subtle-dark`]=W(e,M[`--color-brand-surface-subtle-dark`],{minContrast:S}),M[`--color-brand-on-strong-light`]=W(e,M[`--color-brand-surface-strong-light`],{minContrast:E,preferredCandidate:`light`,preferredMinContrast:E,preferredSwitchDelta:D}),M[`--color-brand-on-strong-dark`]=W(e,M[`--color-brand-surface-strong-dark`],{minContrast:S}),M[`--color-brand-text-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-text-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-icon-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-icon-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-border-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-border-dark`]=M[`--color-brand-surface-strong-dark`],M}function Z(e){let t=M(e);if(!t)return null;let n=N(t);if(!n)return null;let r=R(n),i=Y(r);return i[600]=t,{"--color-brand-seed":t,"--color-brand-100":i[100],"--color-brand-200":i[200],"--color-brand-300":i[300],"--color-brand-400":i[400],"--color-brand-500":i[500],"--color-brand-600":i[600],"--color-brand-700":i[700],"--color-brand-800":i[800],"--color-brand-900":i[900],"--color-brand-1000":i[1e3],...X(r,i)}}let Q=(0,t.computed)(()=>Z(n.accentColor)??{}),$={vars:{},enabled:!!n.exposeGlobalAccent};return _.push($),(0,t.watch)(()=>n.exposeGlobalAccent,e=>{$.enabled=!!e,r()},{immediate:!0}),(0,t.watch)(Q,e=>{e&&Object.keys(e).length>0?$.vars={...e}:$.vars={},r()},{immediate:!0}),(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:`theme`,style:(0,t.normalizeStyle)(Q.value)},[(0,t.renderSlot)(e.$slots,`default`),(0,t.createElementVNode)(`div`,{ref_key:`portalHost`,ref:d,class:`theme__portal-host`},null,512)],4))}}),j=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,t.defineComponent)({__name:`ThemeSwitcher`,props:{mode:{type:String,default:`auto`,validator:e=>[`auto`,`light`,`dark`].includes(e)}},emits:[`update:mode`],setup(e,{emit:n}){let a=[{value:`auto`,label:`System`},{value:`light`,label:`Light`},{value:`dark`,label:`Dark`}].reduce((e,t)=>(e[t.value]=t.label,e),{}),o=i,s=e,d=n;u();let f=(0,t.ref)(!1),p=c()??s.mode,m=(0,t.ref)(o.includes(p)?p:`auto`);return(0,t.watch)(()=>s.mode,e=>{o.includes(e)&&e!==m.value&&(m.value=e)}),(0,t.watch)(m,e=>{if(!o.includes(e)){m.value=`auto`;return}f.value=!1,d(`update:mode`,e),l(e),u(e)},{immediate:!0}),(e,n)=>((0,t.openBlock)(),(0,t.createBlock)((0,t.unref)(r.DropdownMenu),{open:f.value,"onUpdate:open":n[3]||=e=>f.value=e,text:`Theme`,"aria-label":`Select theme mode`},{default:(0,t.withCtx)(()=>[(0,t.createVNode)((0,t.unref)(r.DropdownItemGroup),{title:`Theme`,"item-role":`menuitemradio`},{default:(0,t.withCtx)(()=>[(0,t.createVNode)((0,t.unref)(r.DropdownItemRadio),{checked:m.value,"onUpdate:checked":n[0]||=e=>m.value=e,value:`auto`,label:(0,t.unref)(a).auto,"aria-label":`${(0,t.unref)(a).auto} mode`},null,8,[`checked`,`label`,`aria-label`]),n[4]||=(0,t.createElementVNode)(`hr`,{class:`theme-switcher-divider`},null,-1),(0,t.createVNode)((0,t.unref)(r.DropdownItemRadio),{checked:m.value,"onUpdate:checked":n[1]||=e=>m.value=e,value:`light`,label:(0,t.unref)(a).light,"aria-label":`${(0,t.unref)(a).light} mode`},null,8,[`checked`,`label`,`aria-label`]),(0,t.createVNode)((0,t.unref)(r.DropdownItemRadio),{checked:m.value,"onUpdate:checked":n[2]||=e=>m.value=e,value:`dark`,label:(0,t.unref)(a).dark,"aria-label":`${(0,t.unref)(a).dark} mode`},null,8,[`checked`,`label`,`aria-label`])]),_:1})]),_:1},8,[`open`]))}}),[[`__scopeId`,`data-v-be9d7090`]]);e.Theme=A,e.ThemeSwitcher=j,e.themePortalHostKey=h,e.useThemePortalTarget=g});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue"),require("what-input"),require("@gospore/dropdown-menu")):typeof define==`function`&&define.amd?define([`exports`,`vue`,`what-input`,`@gospore/dropdown-menu`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.theme={},e.Vue,e.whatInput,e.DropdownMenu))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=[`auto`,`light`,`dark`],a=`gospore-theme-mode`,o=3600*24*365,s=`(prefers-color-scheme: dark)`;function c(){if(typeof document>`u`)return null;let e=d(a);return m(e)?e:null}function l(e){if(typeof document>`u`||!i.includes(e))return;let t=typeof window<`u`?window.location.hostname:``,n=typeof window<`u`?window.location.protocol:``,r=f(t),s=n===`https:`,c=[`path=/`,`max-age=${o}`,`SameSite=Lax`];r&&c.push(`domain=${r}`),s&&c.push(`Secure`),document.cookie=[`${encodeURIComponent(a)}=${encodeURIComponent(e)}`,...c].join(`; `)}function u(e){if(typeof document>`u`)return;let t=m(e)?e:c()??`auto`;console.log(`Applying theme mode:`,t);let n=p(t);document.documentElement.setAttribute(`dark-mode`,String(n))}function d(e){if(typeof document>`u`||!document.cookie)return null;let t=`${encodeURIComponent(e)}=`,n=document.cookie.split(`; `);for(let e of n)if(e.startsWith(t))return decodeURIComponent(e.slice(t.length));return null}function f(e){if(!e||e===`localhost`)return null;if(/^\d+(?:\.\d+){3}$/.test(e))return e;let t=e.split(`.`);return t.length<=1?null:t.length===2?e:t.slice(-2).join(`.`)}function p(e){if(e===`dark`)return!0;if(e===`light`||typeof window>`u`)return!1;try{let e=typeof window.matchMedia==`function`?window.matchMedia(s):null;return e?e.matches:!1}catch{return!1}}function m(e){return typeof e==`string`&&i.includes(e)}var h=Symbol.for(`gospore.theme.portalHost`);function g(){let e=(0,t.inject)(h,null);console.log(`Using theme portal host:`,e);let n=typeof document<`u`?document.body:`body`;return(0,t.computed)(()=>e?.value??n)}var _=[],v=new Set,y=`(prefers-color-scheme: dark)`,b=`(prefers-reduced-motion: reduce)`,x=200,S=3.8,C=1.8,w=1.15,T=1.08,E=2.5,D=3,O=`#ffffff`,k=`#1f2228`,A=(0,t.defineComponent)({name:`Theme`,__name:`Theme`,props:{mode:{type:String,default:void 0,validator:e=>[`auto`,`light`,`dark`].includes(e)},accentColor:{type:String,required:!1,default:void 0},exposeGlobalAccent:{type:Boolean,default:!1}},setup(e){let n=e;function r(){let e=document.documentElement;if(!e)return;v.forEach(t=>{e.style.removeProperty(t)}),v.clear();let t=[..._].reverse().find(e=>e.enabled&&e.vars&&Object.keys(e.vars).length>0);t&&Object.entries(t.vars).forEach(([t,n])=>{e.style.setProperty(t,n),v.add(t)})}let i=window.matchMedia(y),a=window.matchMedia(b),o=j();u(o);let s=(0,t.ref)(o),l=(0,t.ref)({darkMode:p(o)}),d=(0,t.ref)(null);i.addEventListener(`change`,m),(0,t.watch)(()=>n.mode,()=>{f()},{immediate:!0}),(0,t.watch)(()=>l.value.darkMode,(e,t)=>{if(t===void 0){g(e);return}A(()=>{g(e)})},{immediate:!0}),(0,t.onBeforeUnmount)(()=>{i.removeEventListener(`change`,m);let e=_.indexOf($);e!==-1&&_.splice(e,1),r()});function f(){let e=j();s.value=e,l.value.darkMode=p(e)}function p(e){return e===`dark`?!0:e===`light`?!1:i.matches}function m(e){!e||s.value!==`auto`||(l.value.darkMode=e.matches)}function g(e){document.documentElement.setAttribute(`dark-mode`,String(e))}function A(e){if(a.matches){e();return}let t=document.startViewTransition?.bind(document);if(t){t(()=>{e()});return}e();let n=document.documentElement;typeof n.animate==`function`&&window.requestAnimationFrame(()=>{n.animate([{opacity:.85},{opacity:1}],{duration:x,easing:`ease-in-out`})})}function j(){return n.mode??c()??`auto`}(0,t.provide)(`theme`,l),(0,t.provide)(h,d);function M(e){if(!e)return null;let t=e.trim().toLowerCase();if(!/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t))return null;if(t.length===4){let e=t[1],n=t[2],r=t[3];return`#${e}${e}${n}${n}${r}${r}`}return t}function N(e){let t=M(e);return t?{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}:null}function P({r:e,g:t,b:n}){let r=e=>e.toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function F(e){return Math.max(0,Math.min(1,e))}function I(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function L(e){let t=F(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function R({r:e,g:t,b:n}){let r=e/255,i=t/255,a=n/255,o=I(r),s=I(i),c=I(a),l=.4122214708*o+.5363325363*s+.0514459929*c,u=.2119034982*o+.6806995451*s+.1073969566*c,d=.0883024619*o+.2817188376*s+.6299787005*c,f=Math.cbrt(l),p=Math.cbrt(u),m=Math.cbrt(d),h=.2104542553*f+.793617785*p-.0040720468*m,g=1.9779984951*f-2.428592205*p+.4505937099*m,_=.0259040371*f+.7827717662*p-.808675766*m,v=Math.sqrt(g*g+_*_),y=180/Math.PI*Math.atan2(_,g);return y<0&&(y+=360),{l:h,c:v,h:y}}function z(e,t,n,r=!1){let i=n*Math.PI/180,a=t*Math.cos(i),o=t*Math.sin(i),s=e+.3963377774*a+.2158037573*o,c=e-.1055613458*a-.0638541728*o,l=e-.0894841775*a-1.291485548*o,u=r?F(s):s,d=r?F(c):c,f=r?F(l):l;if(!r&&(u<-1e-4||u>1.0001||d<-1e-4||d>1.0001||f<-1e-4||f>1.0001))return null;let p=u*u*u,m=d*d*d,h=f*f*f,g=4.0767416621*p-3.3077115913*m+.2309699292*h,_=-1.2684380046*p+2.6097574011*m-.3413193965*h,v=-.0041960863*p-.7034186147*m+1.707614701*h;if(r)g=F(g),_=F(_),v=F(v);else if(g<-1e-4||g>1.0001||_<-1e-4||_>1.0001||v<-1e-4||v>1.0001)return null;let y=F(L(g)),b=F(L(_)),x=F(L(v));return{r:Math.round(y*255),g:Math.round(b*255),b:Math.round(x*255)}}function B(e,t,n){let r=t;for(let t=0;t<8;t+=1){let t=z(e,r,n);if(t)return t;r*=.9}return z(e,F(r),n,!0)||{r:0,g:0,b:0}}function V(e){let t=N(e);if(!t)return 0;let n=I(t.r/255),r=I(t.g/255),i=I(t.b/255);return .2126*n+.7152*r+.0722*i}function H(e,t){let n=V(e),r=V(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function U(e,t,n={}){let r=n.minContrast??S,i=n.preferDark!==!1,a=Math.max(.01,Math.min(.06,(e.c||.12)*(n.chromaScale??.25))),o=n.initialLightness??(i?.24:.94),s=i?-1:1,c=n.step??.03,l=F(o),u=P(B(l,a,e.h)),d=H(t,u);for(let n=0;n<48;n+=1){let n=P(B(l,a,e.h)),i=H(t,n);if(i>d&&(d=i,u=n),i>=r)return n;if(l=F(l+s*c),l===0||l===1)break}let f=`#101214`,p=`#ffffff`,m=H(t,f),h=H(t,p);return m>=r||h>=r?m>=h?f:p:u}function W(e,t,n={}){let r=n.minContrast??S,i=n.darkCandidate??`#101214`,a=n.lightCandidate??`#ffffff`,o=n.preferredCandidate,s=n.preferredMinContrast??r,c=n.preferredSwitchDelta??0,l=H(t,i),u=H(t,a),d=l>=r,f=u>=r,p=u>=s,m=l>=s;if(d||f)return o===`light`&&p?a:o===`dark`&&m?i:o===`light`&&f?!d||l-u<=c?a:i:o===`dark`&&d?!f||u-l<=c?i:a:d&&f?l>=u?i:a:d?i:a;let h=l>=u;return U(e,t,{minContrast:r,preferDark:h,initialLightness:h?.2:.96,chromaScale:.1})}let G=[100,200,300,400,500,600,700,800,900,1e3],K=[.9,.84,.78,.72,.67,.62,.56,.5,.44,.38],q=[.28,.4,.54,.7,.86,1,1.08,1.14,1.2,1.24];function J(e,t,n,r){let i=t[t.length-1];for(let i of t){let t=e[i];if(t&&H(t,n)>=r)return i}return i}function Y(e){let t=e.l-K[5],n=e.c>.02?.02:0;return G.reduce((r,i,a)=>(r[i]=P(B(F(K[a]+t),Math.min(.4,Math.max(n,e.c*q[a])),e.h)),r),{})}function X(e,t){let n=[100,200,300,400,500,600,700],r=J(t,n,O,T),i=n.indexOf(r),a=n[Math.min(i+1,n.length-1)],o=n[Math.min(i+2,n.length-1)],s=[1e3,900,800,700,600,500],c=J(t,s,k,T),l=s.indexOf(c),u=s[Math.min(l+1,s.length-1)],d=s[Math.min(l+2,s.length-1)],f=J(t,[200,300,400,500,600,700,800],O,w),p=J(t,[900,800,700,600,500,400],k,w),m=[600,700,800,900,1e3],h=J(t,m,O,C),g=m.indexOf(h),_=m[Math.min(g+1,m.length-1)],v=m[Math.min(g+2,m.length-1)],y=[400,300,200,100],b=J(t,y,k,C),x=y.indexOf(b),A=y[Math.min(x+1,y.length-1)],j=y[Math.min(x+2,y.length-1)],M={"--color-brand-surface-soft-light":t[r],"--color-brand-surface-soft-hovered-light":t[a],"--color-brand-surface-soft-pressed-light":t[o],"--color-brand-surface-soft-dark":t[c],"--color-brand-surface-soft-hovered-dark":t[u],"--color-brand-surface-soft-pressed-dark":t[d],"--color-brand-surface-subtle-light":t[f],"--color-brand-surface-subtle-dark":t[p],"--color-brand-surface-strong-light":t[h],"--color-brand-surface-strong-hovered-light":t[_],"--color-brand-surface-strong-pressed-light":t[v],"--color-brand-surface-strong-dark":t[b],"--color-brand-surface-strong-hovered-dark":t[A],"--color-brand-surface-strong-pressed-dark":t[j]},N=t[600];return M[`--color-brand-on-soft-light`]=H(M[`--color-brand-surface-soft-light`],N)>=S?N:W(e,M[`--color-brand-surface-soft-light`],{minContrast:S}),M[`--color-brand-on-soft-dark`]=W(e,M[`--color-brand-surface-soft-dark`],{minContrast:S}),M[`--color-brand-on-subtle-light`]=W(e,M[`--color-brand-surface-subtle-light`],{minContrast:E,preferredCandidate:`light`,preferredMinContrast:E,preferredSwitchDelta:D}),M[`--color-brand-on-subtle-dark`]=W(e,M[`--color-brand-surface-subtle-dark`],{minContrast:S}),M[`--color-brand-on-strong-light`]=W(e,M[`--color-brand-surface-strong-light`],{minContrast:E,preferredCandidate:`light`,preferredMinContrast:E,preferredSwitchDelta:D}),M[`--color-brand-on-strong-dark`]=W(e,M[`--color-brand-surface-strong-dark`],{minContrast:S}),M[`--color-brand-text-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-text-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-icon-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-icon-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-border-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-border-dark`]=M[`--color-brand-surface-strong-dark`],M}function Z(e){let t=M(e);if(!t)return null;let n=N(t);if(!n)return null;let r=R(n),i=Y(r);return i[600]=t,{"--color-brand-seed":t,"--color-brand-100":i[100],"--color-brand-200":i[200],"--color-brand-300":i[300],"--color-brand-400":i[400],"--color-brand-500":i[500],"--color-brand-600":i[600],"--color-brand-700":i[700],"--color-brand-800":i[800],"--color-brand-900":i[900],"--color-brand-1000":i[1e3],...X(r,i)}}let Q=(0,t.computed)(()=>Z(n.accentColor)??{}),$={vars:{},enabled:!!n.exposeGlobalAccent};return _.push($),(0,t.watch)(()=>n.exposeGlobalAccent,e=>{$.enabled=!!e,r()},{immediate:!0}),(0,t.watch)(Q,e=>{e&&Object.keys(e).length>0?$.vars={...e}:$.vars={},r()},{immediate:!0}),(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:`theme`,style:(0,t.normalizeStyle)(Q.value)},[(0,t.renderSlot)(e.$slots,`default`),(0,t.createElementVNode)(`div`,{ref_key:`portalHost`,ref:d,class:`theme__portal-host`},null,512)],4))}}),j=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,t.defineComponent)({__name:`ThemeSwitcher`,props:{mode:{type:String,default:`auto`,validator:e=>[`auto`,`light`,`dark`].includes(e)}},emits:[`update:mode`],setup(e,{emit:n}){let a=[{value:`auto`,label:`System`},{value:`light`,label:`Light`},{value:`dark`,label:`Dark`}].reduce((e,t)=>(e[t.value]=t.label,e),{}),o=i,s=e,d=n;u();let f=(0,t.ref)(!1),p=c()??s.mode,m=(0,t.ref)(o.includes(p)?p:`auto`);return(0,t.watch)(()=>s.mode,e=>{o.includes(e)&&e!==m.value&&(m.value=e)}),(0,t.watch)(m,e=>{if(!o.includes(e)){m.value=`auto`;return}f.value=!1,d(`update:mode`,e),l(e),u(e)},{immediate:!0}),(e,n)=>((0,t.openBlock)(),(0,t.createBlock)((0,t.unref)(r.DropdownMenu),{open:f.value,"onUpdate:open":n[3]||=e=>f.value=e,text:`Theme`,"aria-label":`Select theme mode`},{default:(0,t.withCtx)(()=>[(0,t.createVNode)((0,t.unref)(r.DropdownItemGroup),{title:`Theme`,"item-role":`menuitemradio`},{default:(0,t.withCtx)(()=>[(0,t.createVNode)((0,t.unref)(r.DropdownItemRadio),{checked:m.value,"onUpdate:checked":n[0]||=e=>m.value=e,value:`auto`,label:(0,t.unref)(a).auto,"aria-label":`${(0,t.unref)(a).auto} mode`},null,8,[`checked`,`label`,`aria-label`]),n[4]||=(0,t.createElementVNode)(`hr`,{class:`theme-switcher-divider`},null,-1),(0,t.createVNode)((0,t.unref)(r.DropdownItemRadio),{checked:m.value,"onUpdate:checked":n[1]||=e=>m.value=e,value:`light`,label:(0,t.unref)(a).light,"aria-label":`${(0,t.unref)(a).light} mode`},null,8,[`checked`,`label`,`aria-label`]),(0,t.createVNode)((0,t.unref)(r.DropdownItemRadio),{checked:m.value,"onUpdate:checked":n[2]||=e=>m.value=e,value:`dark`,label:(0,t.unref)(a).dark,"aria-label":`${(0,t.unref)(a).dark} mode`},null,8,[`checked`,`label`,`aria-label`])]),_:1})]),_:1},8,[`open`]))}}),[[`__scopeId`,`data-v-be9d7090`]]);e.Theme=A,e.ThemeSwitcher=j,e.themePortalHostKey=h,e.useThemePortalTarget=g});
|
|
2
2
|
//# sourceMappingURL=theme.umd.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gospore/theme",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "1.0.152",
|
|
4
|
+
"gitHead": "39f4d1dbafa5c646cf5094209b6a5ac15e3ea161",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "Gospore",
|
|
7
7
|
"files": [
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"build": "vite build"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@gospore/dropdown-menu": "^1.0.
|
|
30
|
+
"@gospore/dropdown-menu": "^1.0.120",
|
|
31
31
|
"what-input": "^5.2.12"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
35
35
|
"unplugin-vue-macros": "^2.14.5",
|
|
36
|
-
"vite": "^8.0.
|
|
36
|
+
"vite": "^8.0.16"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"vue": "^3.4.20"
|