@codeleap/styles 4.0.1

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.
Files changed (94) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index.js +26 -0
  3. package/dist/lib/Cacher.d.ts +37 -0
  4. package/dist/lib/Cacher.js +104 -0
  5. package/dist/lib/StaleControl.d.ts +21 -0
  6. package/dist/lib/StaleControl.js +78 -0
  7. package/dist/lib/StyleCache.d.ts +20 -0
  8. package/dist/lib/StyleCache.js +52 -0
  9. package/dist/lib/StylePersistor.d.ts +13 -0
  10. package/dist/lib/StylePersistor.js +22 -0
  11. package/dist/lib/StyleRegistry.d.ts +46 -0
  12. package/dist/lib/StyleRegistry.js +499 -0
  13. package/dist/lib/borderCreator.d.ts +11 -0
  14. package/dist/lib/borderCreator.js +44 -0
  15. package/dist/lib/constants.d.ts +5 -0
  16. package/dist/lib/constants.js +8 -0
  17. package/dist/lib/createAppVariants.d.ts +6 -0
  18. package/dist/lib/createAppVariants.js +9 -0
  19. package/dist/lib/createStyles.d.ts +4 -0
  20. package/dist/lib/createStyles.js +27 -0
  21. package/dist/lib/createTheme.d.ts +7 -0
  22. package/dist/lib/createTheme.js +76 -0
  23. package/dist/lib/defaultVariants.d.ts +178 -0
  24. package/dist/lib/defaultVariants.js +179 -0
  25. package/dist/lib/dynamicVariants.d.ts +12 -0
  26. package/dist/lib/dynamicVariants.js +88 -0
  27. package/dist/lib/hashKey.d.ts +1 -0
  28. package/dist/lib/hashKey.js +14 -0
  29. package/dist/lib/hooks.d.ts +8 -0
  30. package/dist/lib/hooks.js +76 -0
  31. package/dist/lib/index.d.ts +10 -0
  32. package/dist/lib/index.js +37 -0
  33. package/dist/lib/mediaQuery.d.ts +11 -0
  34. package/dist/lib/mediaQuery.js +65 -0
  35. package/dist/lib/minifier.d.ts +6 -0
  36. package/dist/lib/minifier.js +21 -0
  37. package/dist/lib/multiplierProperty.d.ts +3 -0
  38. package/dist/lib/multiplierProperty.js +13 -0
  39. package/dist/lib/spacing.d.ts +11 -0
  40. package/dist/lib/spacing.js +104 -0
  41. package/dist/lib/themeStore.d.ts +7 -0
  42. package/dist/lib/themeStore.js +9 -0
  43. package/dist/lib/utils.d.ts +8 -0
  44. package/dist/lib/utils.js +172 -0
  45. package/dist/lib/validateTheme.d.ts +2 -0
  46. package/dist/lib/validateTheme.js +68 -0
  47. package/dist/types/cache.d.ts +1 -0
  48. package/dist/types/cache.js +2 -0
  49. package/dist/types/component.d.ts +25 -0
  50. package/dist/types/component.js +2 -0
  51. package/dist/types/core.d.ts +20 -0
  52. package/dist/types/core.js +2 -0
  53. package/dist/types/icon.d.ts +4 -0
  54. package/dist/types/icon.js +3 -0
  55. package/dist/types/index.d.ts +5 -0
  56. package/dist/types/index.js +21 -0
  57. package/dist/types/spacing.d.ts +6 -0
  58. package/dist/types/spacing.js +21 -0
  59. package/dist/types/style.d.ts +13 -0
  60. package/dist/types/style.js +2 -0
  61. package/dist/types/theme.d.ts +62 -0
  62. package/dist/types/theme.js +2 -0
  63. package/package.json +34 -0
  64. package/src/index.ts +7 -0
  65. package/src/lib/Cacher.ts +131 -0
  66. package/src/lib/StaleControl.ts +73 -0
  67. package/src/lib/StyleCache.ts +69 -0
  68. package/src/lib/StylePersistor.ts +28 -0
  69. package/src/lib/StyleRegistry.ts +549 -0
  70. package/src/lib/borderCreator.ts +42 -0
  71. package/src/lib/constants.ts +6 -0
  72. package/src/lib/createAppVariants.ts +12 -0
  73. package/src/lib/createStyles.ts +32 -0
  74. package/src/lib/createTheme.ts +89 -0
  75. package/src/lib/defaultVariants.ts +180 -0
  76. package/src/lib/dynamicVariants.ts +83 -0
  77. package/src/lib/hashKey.ts +12 -0
  78. package/src/lib/hooks.ts +52 -0
  79. package/src/lib/index.ts +11 -0
  80. package/src/lib/mediaQuery.ts +70 -0
  81. package/src/lib/minifier.ts +20 -0
  82. package/src/lib/multiplierProperty.ts +13 -0
  83. package/src/lib/spacing.ts +83 -0
  84. package/src/lib/themeStore.ts +14 -0
  85. package/src/lib/utils.ts +74 -0
  86. package/src/lib/validateTheme.ts +22 -0
  87. package/src/types/cache.ts +2 -0
  88. package/src/types/component.ts +40 -0
  89. package/src/types/core.ts +40 -0
  90. package/src/types/icon.ts +8 -0
  91. package/src/types/index.ts +5 -0
  92. package/src/types/spacing.ts +35 -0
  93. package/src/types/style.ts +41 -0
  94. package/src/types/theme.ts +77 -0
@@ -0,0 +1,22 @@
1
+ import { Theme } from '../types/theme'
2
+
3
+ export function validateTheme<T extends Theme>(theme: T) {
4
+ const colors = theme.colors
5
+ const requiredColors = Object.keys(colors)
6
+
7
+ const alternateColors = theme.alternateColors
8
+
9
+ if (alternateColors) {
10
+ for (const [colorSchemeName, colorSchemeColors] of Object.entries(alternateColors)) {
11
+ const colorSchemeColorNames = Object.keys(colorSchemeColors)
12
+
13
+ for (const requiredColor of requiredColors) {
14
+ if (!colorSchemeColorNames.includes(requiredColor)) {
15
+ throw new Error(`Alternate color scheme ${colorSchemeName} is missing color ${requiredColor}`)
16
+ }
17
+ }
18
+ }
19
+ }
20
+
21
+ return theme
22
+ }
@@ -0,0 +1,2 @@
1
+
2
+ export type CacheType = 'variants' | 'common' | 'styles' | 'compositions' | 'responsive' | 'components'
@@ -0,0 +1,40 @@
1
+ import { AnyRecord, IJSX } from './core'
2
+ import { StyleProp, VariantStyleSheet } from './style'
3
+
4
+ export type PropsWithVariants<Props extends AnyRecord, VariantStyles extends AnyRecord> = Omit<Props, 'style'> & {
5
+ style?: StyleProp<
6
+ Extract<keyof Props, 'style'> extends never ? VariantStyles[keyof VariantStyles] : (
7
+ Props['style'] extends StyleProp<infer C> ? C : VariantStyles[keyof VariantStyles]
8
+ ),
9
+ keyof VariantStyles
10
+ >
11
+ }
12
+
13
+ export type AnyFunction = (...args: any[]) => any
14
+
15
+ export type StyledComponentProps<Props extends AnyRecord, VariantStyles> = PropsWithVariants<Props, VariantStyles>
16
+
17
+ export type StyledComponent<VariantStyles, Props extends AnyRecord = AnyRecord> = (
18
+ (props: StyledComponentProps<Props, VariantStyles>) => IJSX
19
+ ) & {
20
+ styleRegistryName?: string
21
+ elements?: string[]
22
+ rootElement?: string
23
+ }
24
+
25
+ export type GenericStyledComponentAttributes<Props> = {
26
+ styleRegistryName?: string
27
+ withVariantTypes?: <VariantStyles extends VariantStyleSheet>(variants: VariantStyles) => StyledComponent<VariantStyles, Props>
28
+ elements?: string[]
29
+ rootElement?: string
30
+ }
31
+
32
+ export type GenericStyledComponent<
33
+ Props extends AnyRecord
34
+ > = ((props: Props) => IJSX) & GenericStyledComponentAttributes<Props>
35
+
36
+ export type AnyStyledComponent = GenericStyledComponent<any>
37
+
38
+ export type ComponentWithDefaultProps<P> = ((props: P) => JSX.Element) & { defaultProps?: Partial<P> }
39
+
40
+ export type StyledComponentWithProps<Props> = ComponentWithDefaultProps<Props> & GenericStyledComponentAttributes<Props>
@@ -0,0 +1,40 @@
1
+
2
+ /* eslint-disable @typescript-eslint/no-empty-interface */
3
+ export interface ICSS {
4
+
5
+ }
6
+
7
+ export interface ITheme {
8
+
9
+ }
10
+
11
+ export interface IJSX {
12
+
13
+ }
14
+ export interface IBreakpoints {
15
+
16
+ }
17
+
18
+ export interface IColors {
19
+
20
+ }
21
+
22
+ export interface IBorderRadius {
23
+
24
+ }
25
+
26
+ export interface IAppVariants {
27
+
28
+ }
29
+
30
+ export interface IEffect {
31
+
32
+ }
33
+
34
+ export interface IEffects {
35
+
36
+ }
37
+
38
+ export type AnyRecord = Record<string, any>
39
+
40
+ export type Breakpoint = keyof IBreakpoints
@@ -0,0 +1,8 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-interface */
2
+
3
+ export interface AppIcons {
4
+
5
+ }
6
+ export type AppIcon = keyof AppIcons
7
+
8
+ export type IconProp = AppIcon | `url:${string}`
@@ -0,0 +1,5 @@
1
+ export * from './core'
2
+ export * from './style'
3
+ export * from './theme'
4
+ export * from './icon'
5
+ export * from './component'
@@ -0,0 +1,35 @@
1
+ export const spacingVariants = [
2
+ 'Vertical',
3
+ 'Horizontal',
4
+ 'Bottom',
5
+ 'Top',
6
+ 'Left',
7
+ 'Right',
8
+ '',
9
+ ] as const
10
+
11
+ export const spacingShortVariants = [
12
+ 'y',
13
+ 'x',
14
+ 'b',
15
+ 't',
16
+ 'l',
17
+ 'r',
18
+ '',
19
+ ] as const
20
+
21
+ export type SpacingVariants = typeof spacingVariants[number]
22
+
23
+ export type SpacingShortVariants = typeof spacingShortVariants[number]
24
+
25
+ export type Multiplier =
26
+ | 'auto'
27
+ | number
28
+ | ''
29
+
30
+ export type Spacing =
31
+ | `padding${SpacingVariants}:${Multiplier}`
32
+ | `margin${SpacingVariants}:${Multiplier}`
33
+ | `p${SpacingShortVariants}:${Multiplier}`
34
+ | `m${SpacingShortVariants}:${Multiplier}`
35
+ | `gap:${Multiplier}`
@@ -0,0 +1,41 @@
1
+ import { DynamicVariants } from '../lib/dynamicVariants'
2
+ import { Queries } from '../lib/mediaQuery'
3
+ import { DefaultVariants } from '../lib/defaultVariants'
4
+ import { AnyRecord, IAppVariants, IBreakpoints, ICSS, IEffects } from './core'
5
+ import { Multiplier, Spacing } from './spacing'
6
+
7
+ type Inset =
8
+ | `top:${Multiplier}`
9
+ | `bottom:${Multiplier}`
10
+ | `left:${Multiplier}`
11
+ | `right:${Multiplier}`
12
+
13
+ export type CommonVariants =
14
+ Spacing |
15
+ Inset |
16
+ DynamicVariants |
17
+ keyof DefaultVariants |
18
+ keyof IAppVariants |
19
+ `effect:${keyof IEffects}`
20
+
21
+ type StyleAtom<Composition = AnyRecord, Variants = string, HasBreakpoints = string, HasComposition = string> =
22
+ ICSS |
23
+ Variants |
24
+ CommonVariants |
25
+ boolean |
26
+ null |
27
+ '' |
28
+ // (HasBreakpoints extends string ? `${keyof IBreakpoints}:${CommonVariants}` : null) |
29
+ (HasBreakpoints extends string ? {
30
+ 'breakpoints': Partial<Record<keyof IBreakpoints, StyleAtom<Composition, Variants, boolean, string> | StyleAtom<Composition, Variants, boolean, string>[]>>
31
+ } : null) |
32
+ (HasComposition extends string ? Partial<Record<keyof Composition, StyleAtom<AnyRecord, Variants, boolean, boolean> | StyleAtom<AnyRecord, Variants, boolean, boolean>[]>> : null)
33
+
34
+ export type StyleProp<
35
+ Composition = AnyRecord,
36
+ Variants = string
37
+ > = StyleAtom<Composition, Variants> | StyleAtom<Composition, Variants>[]
38
+
39
+ export type VariantStyleSheet = Record<string, any>
40
+
41
+ export type StyledProp<T extends string> = StyleProp<Record<T, ICSS>>
@@ -0,0 +1,77 @@
1
+ import { BorderCreator } from '../lib/borderCreator'
2
+ import { MediaQueries } from '../lib/mediaQuery'
3
+ import type { DefaultVariants } from '../lib/defaultVariants'
4
+ import { MultiplierFunction, Spacings } from '../lib/spacing'
5
+ import { ICSS, IEffect } from './core'
6
+
7
+ type AnyMap = {
8
+ [key: string]: any
9
+ }
10
+
11
+ type ColorMap = {
12
+ [key: string]: string
13
+ }
14
+
15
+ type BreakpointMap = {
16
+ [key: string]: number
17
+ }
18
+
19
+ type EffectsMap = {
20
+ [key: string]: IEffect
21
+ }
22
+
23
+ export type SpacingMap =
24
+ Spacings<'margin'> &
25
+ Spacings<'padding'> &
26
+ Spacings<'m', string> &
27
+ Spacings<'p', string> &
28
+ {
29
+ gap: MultiplierFunction
30
+ }
31
+
32
+ export type InsetMap =
33
+ {
34
+ bottom: MultiplierFunction
35
+ top: MultiplierFunction
36
+ left: MultiplierFunction
37
+ right: MultiplierFunction
38
+ }
39
+
40
+ export type Theme = {
41
+ colors: ColorMap
42
+ alternateColors?: {
43
+ [key: string]: ColorMap
44
+ }
45
+ breakpoints?: BreakpointMap
46
+ baseSpacing?: number
47
+ presets?: AnyMap
48
+ borderRadius?: AnyMap
49
+ effects?: EffectsMap
50
+ typography: AnyMap
51
+ icons: AnyMap
52
+ values?: AnyMap
53
+ }
54
+
55
+ export type DefaultColorSchemeName = 'default'
56
+
57
+ export type ColorScheme<T extends Theme = Theme> = DefaultColorSchemeName | keyof T['alternateColors']
58
+
59
+ export type AppTheme<T extends Theme> = {
60
+ colors: T['colors']
61
+ breakpoints: T['breakpoints']
62
+ setColorScheme: (colorScheme: ColorScheme<T>) => void
63
+ currentColorScheme: ColorScheme<T>
64
+ spacing: SpacingMap
65
+ presets: DefaultVariants & T['presets']
66
+ borderRadius: T['borderRadius']
67
+ media: MediaQueries
68
+ effects: T['effects']
69
+ border: BorderCreator
70
+ typography: T['typography']
71
+ icons: T['icons']
72
+ values: T['values']
73
+ inset: InsetMap
74
+ baseSpacing: number
75
+ value: (multiplier: number) => number
76
+ sized: (size: number | string) => ICSS
77
+ }