@data-fair/lib-vue 1.14.0 → 1.15.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-vue",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "Composables and other utilities for Vue applications in the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "files": [
package/session.d.ts CHANGED
@@ -51,6 +51,8 @@ interface FullSiteInfo {
51
51
  darkColors?: Colors;
52
52
  hc: boolean;
53
53
  hcColors?: Colors;
54
+ hcDark: boolean;
55
+ hcDarkColors?: Colors;
54
56
  };
55
57
  }
56
58
  export interface SiteInfo {
@@ -59,7 +61,7 @@ export interface SiteInfo {
59
61
  dark?: boolean;
60
62
  colors: Colors;
61
63
  }
62
- type Theme = 'default' | 'dark' | 'hc';
64
+ type Theme = 'default' | 'dark' | 'hc' | 'hc-dark';
63
65
  export interface Session {
64
66
  state: SessionState;
65
67
  user: ComputedRef<SessionState['user']>;
package/session.js CHANGED
@@ -11,12 +11,11 @@ const debug = Debug('session')
11
11
  debug.log = console.log.bind(console)
12
12
  function getDefaultTheme (site) {
13
13
  // see https://www.scottohara.me/blog/2021/10/01/detect-high-contrast-and-dark-modes.html
14
- if (site.theme.hc) {
15
- if (window.matchMedia && window.matchMedia('(forced-colors: active)').matches) { return 'hc' }
16
- }
17
- if (site.theme.dark) {
18
- if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { return 'dark' }
19
- }
14
+ const preferDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
15
+ const preferHC = window.matchMedia && window.matchMedia('(forced-colors: active)').matches
16
+ if (site.theme.hcDark && preferDark && preferHC) { return 'hc-dark' }
17
+ if (site.theme.hc && preferHC) { return 'hc' }
18
+ if (site.theme.dark && preferDark) { return 'dark' }
20
19
  return 'default'
21
20
  }
22
21
  function jwtDecodeAlive (jwt) {
@@ -73,7 +72,7 @@ export async function getSession (initOptions) {
73
72
  // cookies are the source of truth and this information is transformed into the state reactive object
74
73
  const cookies = initOptions?.cookies ?? new Cookies(options.req?.headers.cookie)
75
74
  const readState = () => {
76
- theme.value = cookies.get('theme') ?? 'default'
75
+ theme.value = cookies.get('theme') ?? null
77
76
  const langCookie = cookies.get('i18n_lang')
78
77
  state.lang = langCookie ?? options.defaultLang
79
78
  const idToken = cookies.get('id_token')
@@ -250,6 +249,10 @@ export async function getSession (initOptions) {
250
249
  partialSite.colors = siteInfo.theme.darkColors
251
250
  partialSite.dark = true
252
251
  }
252
+ if (theme.value === 'hc-dark') {
253
+ partialSite.colors = siteInfo.theme.hcDarkColors
254
+ partialSite.dark = true
255
+ }
253
256
  site.value = partialSite
254
257
  } else {
255
258
  site.value = siteInfo