@codeleap/styles 5.5.3 → 5.6.2

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": "@codeleap/styles",
3
- "version": "5.5.3",
3
+ "version": "5.6.2",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  "directory": "packages/styles"
10
10
  },
11
11
  "devDependencies": {
12
- "@codeleap/config": "5.5.3",
12
+ "@codeleap/config": "5.6.2",
13
13
  "ts-node-dev": "^1.1.8"
14
14
  },
15
15
  "scripts": {
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/styles",
3
- "version": "5.5.3",
3
+ "version": "5.6.2",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
package/src/lib/Cacher.ts CHANGED
@@ -67,7 +67,7 @@ export class Cache<T extends any = any> {
67
67
  // utils
68
68
 
69
69
  setCache(cache: Record<string, T>) {
70
- this.cache = cache
70
+ this.cache = cache ?? {}
71
71
  }
72
72
 
73
73
  clear() {
@@ -34,16 +34,20 @@ export const createTheme = <T extends Theme>(theme: T, themePersistor: ThemePers
34
34
 
35
35
  const persistedAlternateColors = themePersistor.get(alternateColorsKey)
36
36
 
37
- const currentAlternateColors = {
37
+ const alternateColors = {
38
38
  ...(persistedAlternateColors ?? {}),
39
39
  ...otherThemeValues?.alternateColors,
40
40
  }
41
41
 
42
- themeStore.setAlternateColorsScheme(currentAlternateColors)
42
+ themeStore.setAlternateColorsScheme(alternateColors)
43
43
 
44
44
  const themeObj: AppTheme<T> = {
45
45
  ...otherThemeValues,
46
46
 
47
+ get alternateColors() {
48
+ return themeStore.alternateColorsScheme
49
+ },
50
+
47
51
  baseColors,
48
52
 
49
53
  currentColorScheme() {
@@ -1,18 +1,19 @@
1
1
  import { AppTheme, ColorMap, IAppVariants, ITheme, Theme } from '../types'
2
- import { map, computed } from 'nanostores'
2
+ import { map, computed, atom } from 'nanostores'
3
3
 
4
4
  export type ThemeState = {
5
5
  theme: AppTheme<Theme> | null
6
+ colorScheme: string | null
6
7
  }
7
8
 
8
9
  class ThemeStore {
9
- private alternateColorsSchemeStore: { [key: string]: ColorMap } = {}
10
+ private readonly alternateColorsSchemeStore = map<{ [key: string]: ColorMap }>({})
10
11
 
11
- public colorSchemeStore: string = null
12
+ public readonly colorSchemeStore = atom<string | null>(null)
12
13
 
13
- public themeStore = map<ITheme | null>(null)
14
+ public readonly themeStore = map<ITheme | null>(null)
14
15
 
15
- public variantsStore: IAppVariants = {} as IAppVariants
16
+ public readonly variantsStore = map<IAppVariants>({})
16
17
 
17
18
  get theme() {
18
19
  return this.themeStore.get()
@@ -23,23 +24,23 @@ class ThemeStore {
23
24
  }
24
25
 
25
26
  get colorScheme() {
26
- return this.colorSchemeStore
27
+ return this.colorSchemeStore.get()
27
28
  }
28
29
 
29
30
  get variants() {
30
- return this.variantsStore
31
+ return this.variantsStore.get()
31
32
  }
32
33
 
33
34
  get alternateColorsScheme() {
34
- return this.alternateColorsSchemeStore ?? {}
35
+ return this.alternateColorsSchemeStore.get() ?? {}
35
36
  }
36
37
 
37
38
  setVariants<T>(variants: T) {
38
- this.variantsStore = variants as unknown as IAppVariants
39
+ this.variantsStore.set(variants as unknown as IAppVariants)
39
40
  }
40
41
 
41
42
  setColorScheme(colorScheme: string) {
42
- this.colorSchemeStore = colorScheme
43
+ this.colorSchemeStore.set(colorScheme)
43
44
  }
44
45
 
45
46
  setTheme(theme: ITheme) {
@@ -47,7 +48,7 @@ class ThemeStore {
47
48
  }
48
49
 
49
50
  setAlternateColorsScheme(colors: { [key: string]: ColorMap }) {
50
- this.alternateColorsSchemeStore = colors
51
+ this.alternateColorsSchemeStore.set(colors)
51
52
  }
52
53
 
53
54
  // utils
@@ -86,6 +87,8 @@ export const themeStore = new ThemeStore()
86
87
 
87
88
  export const themeStoreComputed = computed([
88
89
  themeStore['themeStore'],
89
- ], (theme) => ({
90
+ themeStore['colorSchemeStore'],
91
+ ], (theme, colorScheme) => ({
90
92
  theme: theme as unknown as AppTheme<Theme>,
93
+ colorScheme,
91
94
  }))