@codeleap/styles 4.2.2 → 4.2.3

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.
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
13
24
  Object.defineProperty(exports, "__esModule", { value: true });
14
25
  exports.createTheme = void 0;
15
26
  var borderCreator_1 = require("./borderCreator");
@@ -19,57 +30,40 @@ var defaultVariants_1 = require("./defaultVariants");
19
30
  var spacing_1 = require("./spacing");
20
31
  var themeStore_1 = require("./themeStore");
21
32
  var createTheme = function (theme, colorSchemaPersistor) {
22
- var _a, _b, _c, _d, _e, _f;
23
- var themeObj = {
24
- get currentColorScheme() {
33
+ var _a;
34
+ var colors = theme.colors, breakpoints = theme.breakpoints, presets = theme.presets, borderRadius = theme.borderRadius, effects = theme.effects, typography = theme.typography, icons = theme.icons, values = theme.values, otherThemeValues = __rest(theme, ["colors", "breakpoints", "presets", "borderRadius", "effects", "typography", "icons", "values"]);
35
+ var themeObj = __assign(__assign({}, otherThemeValues), { get currentColorScheme() {
25
36
  return themeStore_1.themeStore.getState().colorScheme;
26
- },
27
- breakpoints: (_a = theme.breakpoints) !== null && _a !== void 0 ? _a : {},
28
- get colors() {
37
+ }, breakpoints: breakpoints !== null && breakpoints !== void 0 ? breakpoints : {}, get colors() {
29
38
  var _a;
30
39
  var colorScheme = themeStore_1.themeStore.getState().colorScheme;
31
40
  if (colorScheme === 'default')
32
- return theme.colors;
41
+ return colors;
33
42
  return (_a = theme.alternateColors) === null || _a === void 0 ? void 0 : _a[colorScheme];
34
- },
35
- setColorScheme: function (colorScheme) {
43
+ }, setColorScheme: function (colorScheme) {
36
44
  themeStore_1.themeStore.setState({ colorScheme: colorScheme });
37
45
  colorSchemaPersistor.set(colorScheme);
38
- },
39
- baseSpacing: theme.baseSpacing,
40
- value: function (n) {
46
+ }, baseSpacing: theme.baseSpacing, value: function (n) {
41
47
  if (n === void 0) { n = 1; }
42
48
  return theme.baseSpacing * n;
43
- },
44
- spacing: __assign(__assign(__assign(__assign({ value: function (n) {
49
+ }, spacing: __assign(__assign(__assign(__assign({ value: function (n) {
45
50
  if (n === void 0) { n = 1; }
46
51
  return theme.baseSpacing * n;
47
- }, gap: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'gap') }, (0, spacing_1.spacingFactory)(theme.baseSpacing, 'padding')), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'margin')), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'p', true)), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'm', true)),
48
- inset: {
52
+ }, gap: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'gap') }, (0, spacing_1.spacingFactory)(theme.baseSpacing, 'padding')), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'margin')), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'p', true)), (0, spacing_1.spacingFactory)(theme.baseSpacing, 'm', true)), inset: {
49
53
  top: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'top'),
50
54
  bottom: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'bottom'),
51
55
  left: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'left'),
52
- right: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'right')
53
- },
54
- presets: __assign(__assign({}, defaultVariants_1.defaultVariants), theme.presets),
55
- borderRadius: (_b = theme.borderRadius) !== null && _b !== void 0 ? _b : {},
56
- effects: (_c = theme.effects) !== null && _c !== void 0 ? _c : {},
57
- media: (0, mediaQuery_1.createMediaQueries)(theme.breakpoints),
58
- border: borderCreator_1.borderCreator,
59
- typography: (_d = theme.typography) !== null && _d !== void 0 ? _d : {},
60
- icons: theme.icons,
61
- values: (_e = theme.values) !== null && _e !== void 0 ? _e : {},
62
- sized: function (size) {
56
+ right: (0, multiplierProperty_1.multiplierProperty)(theme.baseSpacing, 'right'),
57
+ }, presets: __assign(__assign({}, defaultVariants_1.defaultVariants), presets), borderRadius: borderRadius !== null && borderRadius !== void 0 ? borderRadius : {}, effects: effects !== null && effects !== void 0 ? effects : {}, media: (0, mediaQuery_1.createMediaQueries)(breakpoints), border: borderCreator_1.borderCreator, typography: typography !== null && typography !== void 0 ? typography : {}, icons: icons, values: values !== null && values !== void 0 ? values : {}, sized: function (size) {
63
58
  var value = typeof size == 'number' ? size * theme.baseSpacing : size;
64
59
  return {
65
60
  width: value,
66
61
  height: value,
67
62
  };
68
- },
69
- };
63
+ } });
70
64
  themeStore_1.themeStore.setState({
71
65
  current: themeObj,
72
- colorScheme: (_f = colorSchemaPersistor.get()) !== null && _f !== void 0 ? _f : 'default'
66
+ colorScheme: (_a = colorSchemaPersistor.get()) !== null && _a !== void 0 ? _a : 'default',
73
67
  });
74
68
  return themeObj;
75
69
  };
@@ -6,7 +6,7 @@ type Inset = `top:${Multiplier}` | `bottom:${Multiplier}` | `left:${Multiplier}`
6
6
  export type CommonVariants = Spacing | Inset | DynamicVariants | keyof DefaultVariants | keyof IAppVariants | `effect:${keyof IEffects}`;
7
7
  type StyleAtom<Composition = AnyRecord, Variants = string, HasBreakpoints = string, HasComposition = string> = ICSS | Variants | CommonVariants | boolean | null | '' | (HasBreakpoints extends string ? {
8
8
  'breakpoints': Partial<Record<keyof IBreakpoints, StyleAtom<Composition, Variants, boolean, string> | StyleAtom<Composition, Variants, boolean, string>[]>>;
9
- } : null) | (HasComposition extends string ? Partial<Record<keyof Composition, StyleAtom<AnyRecord, Variants, boolean, boolean> | StyleAtom<AnyRecord, Variants, boolean, boolean>[]>> : null) | StyleAtom<Composition, Variants, string, string>[];
9
+ } : null) | (HasComposition extends string ? Partial<Record<keyof Composition, StyleAtom<AnyRecord, Variants, boolean, boolean> | StyleAtom<AnyRecord, Variants, boolean, boolean>[]>> : null) | Array<Variants | ICSS | Partial<Record<keyof Composition, StyleAtom<AnyRecord, Variants, boolean, boolean> | StyleAtom<AnyRecord, Variants, boolean, boolean>[]>>>;
10
10
  export type StyleProp<Composition = AnyRecord, Variants = string> = StyleAtom<Composition, Variants> | StyleAtom<Composition, Variants>[];
11
11
  export type VariantStyleSheet = Record<string, any>;
12
12
  export type StyledProp<T extends string> = StyleProp<Record<T, ICSS>>;
@@ -40,23 +40,28 @@ export type Theme = {
40
40
  };
41
41
  export type DefaultColorSchemeName = 'default';
42
42
  export type ColorScheme<T extends Theme = Theme> = DefaultColorSchemeName | keyof T['alternateColors'];
43
- export type AppTheme<T extends Theme> = {
43
+ type PredefinedThemeDerivedValues<T extends Theme> = {
44
44
  colors: T['colors'];
45
45
  breakpoints: T['breakpoints'];
46
- setColorScheme: (colorScheme: ColorScheme<T>) => void;
47
- currentColorScheme: ColorScheme<T>;
48
- spacing: SpacingMap;
49
46
  presets: DefaultVariants & T['presets'];
50
47
  borderRadius: T['borderRadius'];
51
- media: MediaQueries;
52
48
  effects: T['effects'];
53
- border: BorderCreator;
54
49
  typography: T['typography'];
55
50
  icons: T['icons'];
56
51
  values: T['values'];
52
+ };
53
+ type PredefinedAppTheme<T extends Theme> = PredefinedThemeDerivedValues<T> & {
54
+ setColorScheme: (colorScheme: ColorScheme<T>) => void;
55
+ currentColorScheme: ColorScheme<T>;
56
+ spacing: SpacingMap;
57
+ media: MediaQueries;
58
+ border: BorderCreator;
57
59
  inset: InsetMap;
58
60
  baseSpacing: number;
59
61
  value: (multiplier: number) => number;
60
62
  sized: (size: number | string) => ICSS;
61
63
  };
64
+ export type AppTheme<T extends Theme> = PredefinedAppTheme<T> & {
65
+ [P in Exclude<keyof T, keyof PredefinedThemeDerivedValues<T>>]: T[P];
66
+ };
62
67
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/styles",
3
- "version": "4.2.2",
3
+ "version": "4.2.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "UNLICENSED",
@@ -10,7 +10,7 @@
10
10
  "directory": "packages/styles"
11
11
  },
12
12
  "devDependencies": {
13
- "@codeleap/config": "4.2.2",
13
+ "@codeleap/config": "4.2.3",
14
14
  "ts-node-dev": "1.1.8"
15
15
  },
16
16
  "scripts": {
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/styles",
3
- "version": "4.2.2",
3
+ "version": "4.2.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "UNLICENSED",
@@ -12,18 +12,31 @@ type ColorSchemaPersistor = {
12
12
  }
13
13
 
14
14
  export const createTheme = <T extends Theme>(theme: T, colorSchemaPersistor: ColorSchemaPersistor): AppTheme<T> => {
15
+ const {
16
+ colors,
17
+ breakpoints,
18
+ presets,
19
+ borderRadius,
20
+ effects,
21
+ typography,
22
+ icons,
23
+ values,
24
+ ...otherThemeValues
25
+ } = theme
26
+
15
27
  const themeObj:AppTheme<T> = {
28
+ ...otherThemeValues,
16
29
  get currentColorScheme(): string {
17
30
  return themeStore.getState().colorScheme
18
31
  },
19
32
 
20
- breakpoints: theme.breakpoints ?? {},
33
+ breakpoints: breakpoints ?? {},
21
34
 
22
35
  get colors() {
23
36
  const colorScheme = themeStore.getState().colorScheme
24
37
 
25
- if (colorScheme === 'default') return theme.colors
26
-
38
+ if (colorScheme === 'default') return colors
39
+
27
40
  return theme.alternateColors?.[colorScheme]
28
41
  },
29
42
 
@@ -48,31 +61,31 @@ export const createTheme = <T extends Theme>(theme: T, colorSchemaPersistor: Col
48
61
  top: multiplierProperty(theme.baseSpacing, 'top'),
49
62
  bottom: multiplierProperty(theme.baseSpacing, 'bottom'),
50
63
  left: multiplierProperty(theme.baseSpacing, 'left'),
51
- right: multiplierProperty(theme.baseSpacing, 'right')
64
+ right: multiplierProperty(theme.baseSpacing, 'right'),
52
65
  },
53
66
 
54
67
  presets: {
55
68
  ...defaultVariants,
56
- ...theme.presets,
69
+ ...presets,
57
70
  },
58
71
 
59
- borderRadius: theme.borderRadius ?? {},
72
+ borderRadius: borderRadius ?? {},
60
73
 
61
- effects: theme.effects ?? {},
74
+ effects: effects ?? {},
62
75
 
63
- media: createMediaQueries(theme.breakpoints),
76
+ media: createMediaQueries(breakpoints),
64
77
 
65
78
  border: borderCreator,
66
79
 
67
- typography: theme.typography ?? {},
80
+ typography: typography ?? {},
68
81
 
69
- icons: theme.icons,
82
+ icons: icons,
70
83
 
71
- values: theme.values ?? {},
84
+ values: values ?? {},
72
85
 
73
86
  sized: (size) => {
74
87
  const value = typeof size == 'number' ? size * theme.baseSpacing : size
75
-
88
+
76
89
  return {
77
90
  width: value,
78
91
  height: value,
@@ -80,9 +93,9 @@ export const createTheme = <T extends Theme>(theme: T, colorSchemaPersistor: Col
80
93
  },
81
94
  }
82
95
 
83
- themeStore.setState({
84
- current: themeObj,
85
- colorScheme: colorSchemaPersistor.get() ?? 'default'
96
+ themeStore.setState({
97
+ current: themeObj,
98
+ colorScheme: colorSchemaPersistor.get() ?? 'default',
86
99
  })
87
100
 
88
101
  return themeObj
@@ -41,7 +41,13 @@ type StyleAtom<Composition = AnyRecord, Variants = string, HasBreakpoints = stri
41
41
  >>
42
42
  : null
43
43
  )
44
- | StyleAtom<Composition, Variants, string, string>[]
44
+ | Array<Variants | ICSS | Partial<
45
+ Record<
46
+ keyof Composition,
47
+ StyleAtom<AnyRecord, Variants, boolean, boolean> |
48
+ StyleAtom<AnyRecord, Variants, boolean, boolean>[]
49
+ >
50
+ >>
45
51
 
46
52
  export type StyleProp<
47
53
  Composition = AnyRecord,
@@ -20,8 +20,8 @@ type EffectsMap = {
20
20
  [key: string]: IEffect
21
21
  }
22
22
 
23
- export type SpacingMap =
24
- Spacings<'margin'> &
23
+ export type SpacingMap =
24
+ Spacings<'margin'> &
25
25
  Spacings<'padding'> &
26
26
  Spacings<'m', string> &
27
27
  Spacings<'p', string> &
@@ -29,7 +29,7 @@ export type SpacingMap =
29
29
  gap: MultiplierFunction
30
30
  }
31
31
 
32
- export type InsetMap =
32
+ export type InsetMap =
33
33
  {
34
34
  bottom: MultiplierFunction
35
35
  top: MultiplierFunction
@@ -56,22 +56,29 @@ export type DefaultColorSchemeName = 'default'
56
56
 
57
57
  export type ColorScheme<T extends Theme = Theme> = DefaultColorSchemeName | keyof T['alternateColors']
58
58
 
59
- export type AppTheme<T extends Theme> = {
59
+ type PredefinedThemeDerivedValues<T extends Theme> = {
60
60
  colors: T['colors']
61
61
  breakpoints: T['breakpoints']
62
- setColorScheme: (colorScheme: ColorScheme<T>) => void
63
- currentColorScheme: ColorScheme<T>
64
- spacing: SpacingMap
65
62
  presets: DefaultVariants & T['presets']
66
63
  borderRadius: T['borderRadius']
67
- media: MediaQueries
68
64
  effects: T['effects']
69
- border: BorderCreator
70
65
  typography: T['typography']
71
66
  icons: T['icons']
72
67
  values: T['values']
68
+ }
69
+
70
+ type PredefinedAppTheme<T extends Theme> = PredefinedThemeDerivedValues<T> & {
71
+ setColorScheme: (colorScheme: ColorScheme<T>) => void
72
+ currentColorScheme: ColorScheme<T>
73
+ spacing: SpacingMap
74
+ media: MediaQueries
75
+ border: BorderCreator
73
76
  inset: InsetMap
74
77
  baseSpacing: number
75
78
  value: (multiplier: number) => number
76
79
  sized: (size: number | string) => ICSS
77
80
  }
81
+
82
+ export type AppTheme<T extends Theme> = PredefinedAppTheme<T> & {
83
+ [P in Exclude<keyof T, keyof PredefinedThemeDerivedValues<T>>]: T[P]
84
+ }