@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.
- package/dist/index.d.ts +5 -0
- package/dist/index.js +26 -0
- package/dist/lib/Cacher.d.ts +37 -0
- package/dist/lib/Cacher.js +104 -0
- package/dist/lib/StaleControl.d.ts +21 -0
- package/dist/lib/StaleControl.js +78 -0
- package/dist/lib/StyleCache.d.ts +20 -0
- package/dist/lib/StyleCache.js +52 -0
- package/dist/lib/StylePersistor.d.ts +13 -0
- package/dist/lib/StylePersistor.js +22 -0
- package/dist/lib/StyleRegistry.d.ts +46 -0
- package/dist/lib/StyleRegistry.js +499 -0
- package/dist/lib/borderCreator.d.ts +11 -0
- package/dist/lib/borderCreator.js +44 -0
- package/dist/lib/constants.d.ts +5 -0
- package/dist/lib/constants.js +8 -0
- package/dist/lib/createAppVariants.d.ts +6 -0
- package/dist/lib/createAppVariants.js +9 -0
- package/dist/lib/createStyles.d.ts +4 -0
- package/dist/lib/createStyles.js +27 -0
- package/dist/lib/createTheme.d.ts +7 -0
- package/dist/lib/createTheme.js +76 -0
- package/dist/lib/defaultVariants.d.ts +178 -0
- package/dist/lib/defaultVariants.js +179 -0
- package/dist/lib/dynamicVariants.d.ts +12 -0
- package/dist/lib/dynamicVariants.js +88 -0
- package/dist/lib/hashKey.d.ts +1 -0
- package/dist/lib/hashKey.js +14 -0
- package/dist/lib/hooks.d.ts +8 -0
- package/dist/lib/hooks.js +76 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.js +37 -0
- package/dist/lib/mediaQuery.d.ts +11 -0
- package/dist/lib/mediaQuery.js +65 -0
- package/dist/lib/minifier.d.ts +6 -0
- package/dist/lib/minifier.js +21 -0
- package/dist/lib/multiplierProperty.d.ts +3 -0
- package/dist/lib/multiplierProperty.js +13 -0
- package/dist/lib/spacing.d.ts +11 -0
- package/dist/lib/spacing.js +104 -0
- package/dist/lib/themeStore.d.ts +7 -0
- package/dist/lib/themeStore.js +9 -0
- package/dist/lib/utils.d.ts +8 -0
- package/dist/lib/utils.js +172 -0
- package/dist/lib/validateTheme.d.ts +2 -0
- package/dist/lib/validateTheme.js +68 -0
- package/dist/types/cache.d.ts +1 -0
- package/dist/types/cache.js +2 -0
- package/dist/types/component.d.ts +25 -0
- package/dist/types/component.js +2 -0
- package/dist/types/core.d.ts +20 -0
- package/dist/types/core.js +2 -0
- package/dist/types/icon.d.ts +4 -0
- package/dist/types/icon.js +3 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +21 -0
- package/dist/types/spacing.d.ts +6 -0
- package/dist/types/spacing.js +21 -0
- package/dist/types/style.d.ts +13 -0
- package/dist/types/style.js +2 -0
- package/dist/types/theme.d.ts +62 -0
- package/dist/types/theme.js +2 -0
- package/package.json +34 -0
- package/src/index.ts +7 -0
- package/src/lib/Cacher.ts +131 -0
- package/src/lib/StaleControl.ts +73 -0
- package/src/lib/StyleCache.ts +69 -0
- package/src/lib/StylePersistor.ts +28 -0
- package/src/lib/StyleRegistry.ts +549 -0
- package/src/lib/borderCreator.ts +42 -0
- package/src/lib/constants.ts +6 -0
- package/src/lib/createAppVariants.ts +12 -0
- package/src/lib/createStyles.ts +32 -0
- package/src/lib/createTheme.ts +89 -0
- package/src/lib/defaultVariants.ts +180 -0
- package/src/lib/dynamicVariants.ts +83 -0
- package/src/lib/hashKey.ts +12 -0
- package/src/lib/hooks.ts +52 -0
- package/src/lib/index.ts +11 -0
- package/src/lib/mediaQuery.ts +70 -0
- package/src/lib/minifier.ts +20 -0
- package/src/lib/multiplierProperty.ts +13 -0
- package/src/lib/spacing.ts +83 -0
- package/src/lib/themeStore.ts +14 -0
- package/src/lib/utils.ts +74 -0
- package/src/lib/validateTheme.ts +22 -0
- package/src/types/cache.ts +2 -0
- package/src/types/component.ts +40 -0
- package/src/types/core.ts +40 -0
- package/src/types/icon.ts +8 -0
- package/src/types/index.ts +5 -0
- package/src/types/spacing.ts +35 -0
- package/src/types/style.ts +41 -0
- 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,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,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
|
+
}
|