@codeleap/styles 6.2.3 → 6.8.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.
Files changed (138) hide show
  1. package/dist/classes/Cacher.d.ts +87 -0
  2. package/dist/classes/Cacher.d.ts.map +1 -0
  3. package/dist/classes/StaleControl.d.ts +65 -0
  4. package/dist/classes/StaleControl.d.ts.map +1 -0
  5. package/dist/classes/StyleCache.d.ts +63 -0
  6. package/dist/classes/StyleCache.d.ts.map +1 -0
  7. package/dist/classes/StylePersistor.d.ts +52 -0
  8. package/dist/classes/StylePersistor.d.ts.map +1 -0
  9. package/dist/classes/StyleRegistry.d.ts +108 -0
  10. package/dist/classes/StyleRegistry.d.ts.map +1 -0
  11. package/dist/classes/index.d.ts +3 -0
  12. package/dist/classes/index.d.ts.map +1 -0
  13. package/dist/constants.d.ts +22 -0
  14. package/dist/constants.d.ts.map +1 -0
  15. package/dist/hooks/index.d.ts +5 -0
  16. package/dist/hooks/index.d.ts.map +1 -0
  17. package/dist/hooks/useCompositionStyles.d.ts +12 -0
  18. package/dist/hooks/useCompositionStyles.d.ts.map +1 -0
  19. package/dist/hooks/useNestedStylesByKey.d.ts +11 -0
  20. package/dist/hooks/useNestedStylesByKey.d.ts.map +1 -0
  21. package/dist/hooks/useStyleObserver.d.ts +9 -0
  22. package/dist/hooks/useStyleObserver.d.ts.map +1 -0
  23. package/dist/hooks/useTheme.d.ts +19 -0
  24. package/dist/hooks/useTheme.d.ts.map +1 -0
  25. package/dist/index.d.ts +12 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/lib/calc.d.ts +27 -0
  28. package/dist/lib/calc.d.ts.map +1 -0
  29. package/dist/lib/createStyles.d.ts +30 -0
  30. package/dist/lib/createStyles.d.ts.map +1 -0
  31. package/dist/lib/createTheme.d.ts +28 -0
  32. package/dist/lib/createTheme.d.ts.map +1 -0
  33. package/dist/lib/cssVariables.d.ts +35 -0
  34. package/dist/lib/cssVariables.d.ts.map +1 -0
  35. package/dist/lib/index.d.ts +5 -0
  36. package/dist/lib/index.d.ts.map +1 -0
  37. package/dist/theme/generateColorScheme.d.ts +22 -0
  38. package/dist/theme/generateColorScheme.d.ts.map +1 -0
  39. package/dist/theme/index.d.ts +4 -0
  40. package/dist/theme/index.d.ts.map +1 -0
  41. package/dist/theme/themeStore.d.ts +106 -0
  42. package/dist/theme/themeStore.d.ts.map +1 -0
  43. package/dist/theme/validateTheme.d.ts +19 -0
  44. package/dist/theme/validateTheme.d.ts.map +1 -0
  45. package/dist/tools/colors.d.ts +70 -0
  46. package/dist/tools/colors.d.ts.map +1 -0
  47. package/dist/tools/deepClone.d.ts +7 -0
  48. package/dist/tools/deepClone.d.ts.map +1 -0
  49. package/dist/tools/deepmerge.d.ts +13 -0
  50. package/dist/tools/deepmerge.d.ts.map +1 -0
  51. package/dist/tools/hashKey.d.ts +8 -0
  52. package/dist/tools/hashKey.d.ts.map +1 -0
  53. package/dist/tools/index.d.ts +7 -0
  54. package/dist/tools/index.d.ts.map +1 -0
  55. package/dist/tools/minifier.d.ts +24 -0
  56. package/dist/tools/minifier.d.ts.map +1 -0
  57. package/dist/tools/multiplierProperty.d.ts +4 -0
  58. package/dist/tools/multiplierProperty.d.ts.map +1 -0
  59. package/dist/types/cache.d.ts +12 -0
  60. package/dist/types/cache.d.ts.map +1 -0
  61. package/dist/types/component.d.ts +58 -0
  62. package/dist/types/component.d.ts.map +1 -0
  63. package/dist/types/core.d.ts +77 -0
  64. package/dist/types/core.d.ts.map +1 -0
  65. package/dist/types/icon.d.ts +15 -0
  66. package/dist/types/icon.d.ts.map +1 -0
  67. package/dist/types/index.d.ts +6 -0
  68. package/dist/types/index.d.ts.map +1 -0
  69. package/dist/types/spacing.d.ts +28 -0
  70. package/dist/types/spacing.d.ts.map +1 -0
  71. package/dist/types/store.d.ts +12 -0
  72. package/dist/types/store.d.ts.map +1 -0
  73. package/dist/types/style.d.ts +42 -0
  74. package/dist/types/style.d.ts.map +1 -0
  75. package/dist/types/theme.d.ts +109 -0
  76. package/dist/types/theme.d.ts.map +1 -0
  77. package/dist/utils.d.ts +40 -0
  78. package/dist/utils.d.ts.map +1 -0
  79. package/dist/variants/borderCreator.d.ts +22 -0
  80. package/dist/variants/borderCreator.d.ts.map +1 -0
  81. package/dist/variants/createAppVariants.d.ts +18 -0
  82. package/dist/variants/createAppVariants.d.ts.map +1 -0
  83. package/dist/variants/defaultVariants.d.ts +140 -0
  84. package/dist/variants/defaultVariants.d.ts.map +1 -0
  85. package/dist/variants/dynamicVariants.d.ts +43 -0
  86. package/dist/variants/dynamicVariants.d.ts.map +1 -0
  87. package/dist/variants/index.d.ts +7 -0
  88. package/dist/variants/index.d.ts.map +1 -0
  89. package/dist/variants/mediaQuery.d.ts +30 -0
  90. package/dist/variants/mediaQuery.d.ts.map +1 -0
  91. package/dist/variants/spacing.d.ts +26 -0
  92. package/dist/variants/spacing.d.ts.map +1 -0
  93. package/package.json +19 -5
  94. package/src/classes/Cacher.ts +9 -9
  95. package/src/classes/StaleControl.ts +1 -1
  96. package/src/classes/StyleCache.ts +9 -3
  97. package/src/classes/StylePersistor.ts +11 -0
  98. package/src/classes/StyleRegistry.ts +124 -43
  99. package/src/classes/tests/StyleRegistry.spec.ts +169 -0
  100. package/src/constants.ts +14 -0
  101. package/src/hooks/useCompositionStyles.ts +9 -7
  102. package/src/hooks/useNestedStylesByKey.ts +8 -0
  103. package/src/hooks/useStyleObserver.ts +6 -5
  104. package/src/hooks/useTheme.ts +14 -0
  105. package/src/lib/calc.ts +13 -0
  106. package/src/lib/createStyles.ts +35 -4
  107. package/src/lib/createTheme.ts +74 -25
  108. package/src/lib/cssVariables.ts +74 -0
  109. package/src/lib/index.ts +2 -1
  110. package/src/lib/tests/createStyles.spec.ts +80 -23
  111. package/src/lib/tests/createStylesWithContext.spec.ts +108 -0
  112. package/src/tests/theme.ts +6 -2
  113. package/src/theme/generateColorScheme.ts +13 -10
  114. package/src/theme/tests/themeStore.spec.ts +72 -71
  115. package/src/theme/themeStore.ts +10 -7
  116. package/src/theme/validateTheme.ts +1 -1
  117. package/src/tools/colors.ts +24 -36
  118. package/src/tools/deepClone.ts +3 -5
  119. package/src/tools/deepmerge.ts +8 -6
  120. package/src/tools/hashKey.ts +4 -5
  121. package/src/tools/minifier.ts +11 -12
  122. package/src/tools/tests/deepClone.spec.ts +2 -2
  123. package/src/types/cache.ts +10 -0
  124. package/src/types/component.ts +41 -5
  125. package/src/types/core.ts +66 -6
  126. package/src/types/icon.ts +11 -0
  127. package/src/types/spacing.ts +21 -0
  128. package/src/types/store.ts +6 -0
  129. package/src/types/style.ts +37 -10
  130. package/src/types/theme.ts +37 -1
  131. package/src/utils.ts +34 -4
  132. package/src/variants/borderCreator.ts +14 -5
  133. package/src/variants/createAppVariants.ts +11 -0
  134. package/src/variants/defaultVariants.ts +28 -8
  135. package/src/variants/dynamicVariants.ts +76 -18
  136. package/src/variants/mediaQuery.ts +18 -0
  137. package/src/variants/spacing.ts +15 -1
  138. package/package.json.bak +0 -30
@@ -1,8 +1,7 @@
1
1
  /**
2
- * Converts a hex color to HSL format.
3
- *
4
- * @param {string} hex - Hex color string (e.g., '#ff5733')
5
- * @returns {object} HSL object with h (0-360), s (0-100), l (0-100)
2
+ * Expects a 7-character hex string (`#rrggbb`). Shorter forms (3-char, no hash) are
3
+ * not handled and will produce NaN channels. Returns h in [0, 360], s and l in [0, 100],
4
+ * all rounded to integers via `Math.round`.
6
5
  */
7
6
  export function hexToHSL(hex: string) {
8
7
  const r = parseInt(hex.slice(1, 3), 16) / 255
@@ -31,12 +30,10 @@ export function hexToHSL(hex: string) {
31
30
  }
32
31
 
33
32
  /**
34
- * Converts HSL values to hex color format.
35
- *
36
- * @param {number} h - Hue (0-360)
37
- * @param {number} s - Saturation (0-100)
38
- * @param {number} l - Lightness (0-100)
39
- * @returns {string} Hex color string
33
+ * Uses the HSL-to-RGB CSS Color 4 formula (single-pass, no separate hue helper).
34
+ * Inputs h in [0, 360], s and l in [0, 100]; channels are clamped implicitly by
35
+ * `Math.min`/`Math.max`. Each channel is individually rounded before hex encoding,
36
+ * so the round-trip `hexToHSL → hslToHex` may differ by ±1 in the last hex digit.
40
37
  */
41
38
  export function hslToHex(h: number, s: number, l: number): string {
42
39
  s /= 100
@@ -50,10 +47,8 @@ export function hslToHex(h: number, s: number, l: number): string {
50
47
  }
51
48
 
52
49
  /**
53
- * Converts a hex color to RGB format.
54
- *
55
- * @param {string} hex - Hex color string (e.g., '#ff5733')
56
- * @returns {object} RGB object with r, g, b values (0-255)
50
+ * Parses only the 6-digit `#rrggbb` form via `parseInt(..., 16)`.
51
+ * No alpha channel is extracted. Channels are returned as integers in [0, 255].
57
52
  */
58
53
  export function hexToRGB(hex: string) {
59
54
  const r = parseInt(hex.slice(1, 3), 16)
@@ -63,12 +58,9 @@ export function hexToRGB(hex: string) {
63
58
  }
64
59
 
65
60
  /**
66
- * Converts HSL values to RGB format.
67
- *
68
- * @param {number} h - Hue (0-360)
69
- * @param {number} s - Saturation (0-100)
70
- * @param {number} l - Lightness (0-100)
71
- * @returns {object} RGB object with r, g, b values (0-255)
61
+ * Shares the same formula as `hslToHex` but returns separate integer r/g/b channels
62
+ * instead of a hex string. Useful when you need numeric channels for `rgba(...)` output.
63
+ * Input ranges: h [0, 360], s [0, 100], l [0, 100].
72
64
  */
73
65
  export function hslToRGB(h: number, s: number, l: number) {
74
66
  s /= 100
@@ -86,10 +78,9 @@ export function hslToRGB(h: number, s: number, l: number) {
86
78
  }
87
79
 
88
80
  /**
89
- * Converts RGB values to HSL format.
90
- *
91
- * @param {object} rgb - RGB object with r, g, b values (0-255)
92
- * @returns {object} HSL object with h (0-360), s (0-100), l (0-100)
81
+ * Inverse of `hslToRGB`. Normalises each channel from [0, 255] to [0, 1] before
82
+ * computing. When max === min (achromatic), hue is fixed at 0. All output values are
83
+ * rounded, so the round-trip `hslToRGB rgbToHSL` is not guaranteed to be lossless.
93
84
  */
94
85
  export function rgbToHSL(rgb: { r: number; g: number; b: number }): { h: number; s: number; l: number } {
95
86
  const r = rgb.r / 255
@@ -129,11 +120,11 @@ export function rgbToHSL(rgb: { r: number; g: number; b: number }): { h: number;
129
120
  }
130
121
 
131
122
  /**
132
- * Calculates the relative luminance of an RGB color.
133
- * Uses the WCAG formula for accessibility calculations.
134
- *
135
- * @param {object} rgb - RGB object with r, g, b values (0-255)
136
- * @returns {number} Luminance value (0-1)
123
+ * Implements WCAG 2.x relative luminance (https://www.w3.org/TR/WCAG20/#relativeluminancedef).
124
+ * Channels are linearised with the sRGB transfer function: values ≤ 0.03928 use
125
+ * the linear segment (C / 12.92); values above use the gamma curve ((C + 0.055) / 1.055)^2.4.
126
+ * The luminance coefficients are 0.2126 R + 0.7152 G + 0.0722 B, reflecting the
127
+ * eye's greater sensitivity to green. Returns a value in [0, 1].
137
128
  */
138
129
  export function getLuminance({ r, g, b }: { r: number; g: number; b: number }): number {
139
130
  const [R, G, B] = [r, g, b].map(c => {
@@ -147,13 +138,10 @@ export function getLuminance({ r, g, b }: { r: number; g: number; b: number }):
147
138
  }
148
139
 
149
140
  /**
150
- * Determines the best text color (dark or light) for a given background.
151
- * Uses luminance calculation for optimal contrast.
152
- *
153
- * @param {string} backgroundHex - Background hex color
154
- * @param {string} darkColor - Dark text color option
155
- * @param {string} lightColor - Light text color option
156
- * @returns {string} Recommended text color
141
+ * Uses a luminance threshold of **0.5** (not the WCAG 4.5:1 contrast ratio) to pick
142
+ * between two text colours. Backgrounds with luminance > 0.5 are treated as light and
143
+ * receive `darkColor`; all others receive `lightColor`. This is a perceptual shortcut —
144
+ * use explicit contrast-ratio checks for accessibility-critical situations.
157
145
  */
158
146
  export function getTextColor(backgroundHex: string, darkColor = 'black', lightColor = 'white'): string {
159
147
  const rgb = hexToRGB(backgroundHex)
@@ -1,10 +1,8 @@
1
1
  import rfdc from 'rfdc'
2
2
 
3
3
  /**
4
- * Creates a deep clone of any JavaScript object or value.
5
- * Uses rfdc (Really Fast Deep Clone) for optimal performance.
6
- *
7
- * @param {T} obj - The object or value to clone
8
- * @returns {T} A deep copy of the input
4
+ * rfdc clone function configured with default options (no circular-reference support,
5
+ * proto: false). Does not handle `Date`, `RegExp`, or `Buffer` fields — they are copied
6
+ * by reference. Use only on plain style/theme objects.
9
7
  */
10
8
  export const deepClone = rfdc()
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Deep merge constructor from Fastify's optimized implementation.
3
- * Returns a merge function that recursively merges objects with high performance.
4
- * By default, arrays are concatenated and objects are deeply merged.
5
- *
2
+ * Re-exports `@fastify/deepmerge`'s factory function. Call it once with options
3
+ * (e.g., `deepmerge({ all: true })`) to obtain a variadic merge function.
4
+ * Passing `{ all: true }` merges arrays by index rather than concatenating them
5
+ * this is the mode used throughout the style registry for variant merging.
6
+ * The returned merger is not idempotent: source properties always overwrite target.
7
+ *
6
8
  * @example
7
- * const merger = deepmerge()
8
- * const result = merger(target, source)
9
+ * const merge = deepmerge({ all: true })
10
+ * const result = merge(base, override1, override2)
9
11
  */
10
12
  export { default as deepmerge } from '@fastify/deepmerge'
@@ -4,11 +4,10 @@ const styleKey = '@styles-version'
4
4
  const version = require('../../package.json')?.version
5
5
 
6
6
  /**
7
- * Generates a SHA-256 hash from an array with automatic version injection.
8
- * Appends package version to the array for cache invalidation purposes.
9
- *
10
- * @param {Array<any>} value - Array to be hashed
11
- * @returns {string} SHA-256 hash string
7
+ * Mutates the input array by appending `{ '@styles-version': <pkg.version> }` before
8
+ * hashing meaning callers must not rely on the array being unchanged after the call.
9
+ * The version injection ensures any cache key computed against an older package version
10
+ * is automatically invalid after a library upgrade.
12
11
  */
13
12
  export const hashKey = (value: Array<any>): string => {
14
13
  value.push({ [styleKey]: version })
@@ -1,11 +1,11 @@
1
1
  import { compressToBase64, decompressFromBase64 } from 'lz-string'
2
2
 
3
3
  /**
4
- * Compresses any value to a Base64 string using LZ compression.
5
- * Returns the original value if falsy.
6
- *
7
- * @param {any} value - Value to compress
8
- * @returns {string|any} Compressed Base64 string or original falsy value
4
+ * Serialises `value` with `JSON.stringify` then LZ-compresses to a Base64 string.
5
+ * Returns the value unchanged (without throwing) when it is falsy, so callers
6
+ * do not need to guard against `null`/`undefined`/`''` inputs.
7
+ * Non-serialisable values (functions, `undefined` inside objects, circular refs)
8
+ * will be silently dropped by `JSON.stringify`.
9
9
  */
10
10
  export function compress(value: any): any {
11
11
  if (!value) return value
@@ -14,11 +14,10 @@ export function compress(value: any): any {
14
14
  }
15
15
 
16
16
  /**
17
- * Decompresses a Base64 string back to its original value.
18
- * Returns the original value if falsy.
19
- *
20
- * @param {any} value - Compressed Base64 string to decompress
21
- * @returns {any} Original decompressed value or original falsy value
17
+ * Reverses `compress`: LZ-decompresses the Base64 string then parses the JSON.
18
+ * Returns the value unchanged when falsy. Will throw if `value` is a non-empty
19
+ * string that is not valid LZ-Base64, or if the decompressed payload is not
20
+ * valid JSON callers should guard accordingly.
22
21
  */
23
22
  export function decompress(value: any): any {
24
23
  if (!value) return value
@@ -29,8 +28,8 @@ export function decompress(value: any): any {
29
28
  }
30
29
 
31
30
  /**
32
- * Utility object containing compress and decompress functions.
33
- * Useful for data compression/decompression operations.
31
+ * Convenience namespace so callsites can import a single symbol and call
32
+ * `minifier.compress` / `minifier.decompress` without named imports.
34
33
  */
35
34
  export const minifier = {
36
35
  compress,
@@ -44,8 +44,8 @@ describe('deepClone', () => {
44
44
  expect(cloned).not.toBe(original)
45
45
  expect(cloned[2]).not.toBe(original[2])
46
46
 
47
- cloned[2][0] = 5
48
- expect(original[2][0]).toBe(3)
47
+ ;(cloned[2] as any)[0] = 5
48
+ expect((original[2] as any)[0]).toBe(3)
49
49
  })
50
50
 
51
51
  test('should handle complex nested structures', () => {
@@ -1,2 +1,12 @@
1
1
 
2
+ /**
3
+ * Discriminant union identifying the six cache buckets managed by `StyleCache`.
4
+ * Each bucket stores a different stage of the style-resolution pipeline:
5
+ * - `variants` — per-component variant merge results (persisted)
6
+ * - `common` — shared/common variant lookups (persisted)
7
+ * - `components` — final merged component output (persisted)
8
+ * - `styles` — `createStyles` call results (in-memory)
9
+ * - `compositions` — composition style resolution (in-memory)
10
+ * - `responsive` — responsive breakpoint style resolution (in-memory)
11
+ */
2
12
  export type CacheType = 'variants' | 'common' | 'styles' | 'compositions' | 'responsive' | 'components'
@@ -1,7 +1,24 @@
1
- import { AnyRecord, IJSX } from './core'
1
+ import { AnyRecord, ICSS, IJSX } from './core'
2
2
  import { StyleProp, VariantStyleSheet } from './style'
3
3
  import React, { JSX } from 'react'
4
4
 
5
+ /**
6
+ * Injects a typed `style` prop onto a component based on the composition keys
7
+ * inferred from the variant stylesheet. Primarily used when a component's style
8
+ * prop shape must mirror its variant composition keys exactly.
9
+ */
10
+ export type StyledProps<VariantStyles extends AnyRecord> = {
11
+ style?: StyleProp<
12
+ VariantStyles[keyof VariantStyles] extends Partial<Record<infer K, any>> ? K extends string ? K : never : never,
13
+ keyof VariantStyles
14
+ >
15
+ }
16
+
17
+ /**
18
+ * Merges external `Props` with variant-aware `style`. If `Props` already declares a
19
+ * `style` prop whose inner composition type can be inferred, that composition is
20
+ * preserved; otherwise the composition is derived from `VariantStyles`.
21
+ */
5
22
  export type PropsWithVariants<Props extends AnyRecord, VariantStyles extends AnyRecord> = Omit<Props, 'style'> & {
6
23
  style?: StyleProp<
7
24
  Extract<keyof Props, 'style'> extends never ? VariantStyles[keyof VariantStyles] : (
@@ -11,11 +28,18 @@ export type PropsWithVariants<Props extends AnyRecord, VariantStyles extends Any
11
28
  >
12
29
  }
13
30
 
31
+ /** Unconstrained function type used for variant callbacks and other callbacks. */
14
32
  export type AnyFunction = (...args: any[]) => any
15
33
 
16
- export type StyledComponentProps<Props extends AnyRecord, VariantStyles> = PropsWithVariants<Props, VariantStyles>
34
+ /** Resolved props type for a component that has been bound to a variant stylesheet. */
35
+ export type StyledComponentProps<Props extends AnyRecord, VariantStyles extends AnyRecord> = PropsWithVariants<Props, VariantStyles>
17
36
 
18
- export type StyledComponent<VariantStyles, Props extends AnyRecord = AnyRecord> = (
37
+ /**
38
+ * A component function that accepts variant-aware style props, plus the registry
39
+ * metadata fields (`styleRegistryName`, `elements`, `rootElement`) used by the
40
+ * `CodeleapStyleRegistry` to resolve composition and responsive styles.
41
+ */
42
+ export type StyledComponent<VariantStyles extends AnyRecord, Props extends AnyRecord = AnyRecord> = (
19
43
  (props: StyledComponentProps<Props, VariantStyles>) => IJSX
20
44
  ) & {
21
45
  styleRegistryName?: string
@@ -23,19 +47,31 @@ export type StyledComponent<VariantStyles, Props extends AnyRecord = AnyRecord>
23
47
  rootElement?: string
24
48
  }
25
49
 
26
- export type GenericStyledComponentAttributes<Props> = {
50
+ /**
51
+ * Static attributes attached to every component created by the style system.
52
+ * `withVariantTypes` narrows the component's style prop to a specific variant stylesheet
53
+ * without changing the runtime behaviour — it is a TypeScript-only helper.
54
+ */
55
+ export type GenericStyledComponentAttributes<Props extends AnyRecord> = {
27
56
  styleRegistryName?: string
28
57
  withVariantTypes?: <VariantStyles extends VariantStyleSheet>(variants: VariantStyles) => StyledComponent<VariantStyles, Props>
29
58
  elements?: string[]
30
59
  rootElement?: string
31
60
  }
32
61
 
62
+ /**
63
+ * A component that hasn't been bound to a specific variant stylesheet yet but carries
64
+ * the registry metadata needed for the style system to work at runtime.
65
+ */
33
66
  export type GenericStyledComponent<
34
67
  Props extends AnyRecord
35
68
  > = ((props: Props) => IJSX) & GenericStyledComponentAttributes<Props>
36
69
 
70
+ /** Escape-hatch alias for `GenericStyledComponent<any>` used in registry maps. */
37
71
  export type AnyStyledComponent = GenericStyledComponent<any>
38
72
 
73
+ /** Component function type that optionally accepts `defaultProps` — mirrors React's pattern. */
39
74
  export type ComponentWithDefaultProps<P> = ((props: P) => JSX.Element) & { defaultProps?: Partial<P> }
40
75
 
41
- export type StyledComponentWithProps<Props> = ComponentWithDefaultProps<Props> & GenericStyledComponentAttributes<Props>
76
+ /** Combines `ComponentWithDefaultProps` with the style-registry metadata attributes. */
77
+ export type StyledComponentWithProps<Props extends AnyRecord> = ComponentWithDefaultProps<Props> & GenericStyledComponentAttributes<Props>
package/src/types/core.ts CHANGED
@@ -1,40 +1,100 @@
1
-
2
1
  /* eslint-disable @typescript-eslint/no-empty-interface */
2
+
3
+ /**
4
+ * Declaration-merging target for the app's CSS/style property bag.
5
+ * Platform packages (`@codeleap/web`, `@codeleap/mobile`) augment this interface
6
+ * with the actual CSS or React Native style properties they support.
7
+ */
3
8
  export interface ICSS {
4
9
 
5
10
  }
6
11
 
12
+ /**
13
+ * Declaration-merging target for the resolved `AppTheme` object available at runtime.
14
+ * Consumer apps augment this so that `useTheme()` returns a fully typed theme without
15
+ * explicit generics at every callsite.
16
+ */
7
17
  export interface ITheme {
8
18
 
9
19
  }
10
20
 
21
+ /**
22
+ * Declaration-merging target for the JSX element type used by the platform.
23
+ * Web augments this with `React.ReactElement`; mobile augments with React Native's
24
+ * equivalent. Allows cross-platform component return types to be typed correctly.
25
+ */
11
26
  export interface IJSX {
12
27
 
13
28
  }
29
+
30
+ /**
31
+ * Declaration-merging target for the app's named breakpoint map.
32
+ * Augment with `{ sm: unknown; md: unknown; lg: unknown }` (or your own breakpoints)
33
+ * so that `Breakpoint` and the responsive style API become fully typed.
34
+ */
14
35
  export interface IBreakpoints {
15
36
 
16
37
  }
17
38
 
39
+ /**
40
+ * Declaration-merging target for the app's color token map.
41
+ * Augment with the flattened color keys from your theme (e.g., `{ primary: string }`)
42
+ * so that `color:`, `bg:`, and `borderColor:` variants are narrowed to valid tokens.
43
+ */
18
44
  export interface IColors {
19
-
45
+
20
46
  }
21
47
 
48
+ /**
49
+ * Declaration-merging target for the app's border-radius token map.
50
+ * Augment with keys from `theme.radius` so that `borderRadius:` and `br:` variants
51
+ * accept only the defined radius tokens.
52
+ */
22
53
  export interface IBorderRadius {
23
-
54
+
24
55
  }
25
56
 
57
+ /**
58
+ * Declaration-merging target for app-defined style variants registered via
59
+ * `createAppVariants`. Augment so that custom variant names are accepted by `StyleProp`.
60
+ */
26
61
  export interface IAppVariants {
27
-
62
+
28
63
  }
29
64
 
65
+ /**
66
+ * Declaration-merging target for the app's named size tokens (from `theme.size`).
67
+ * Augment so that the `size:` dynamic variant is narrowed to valid size keys.
68
+ */
69
+ export interface ISizes {
70
+
71
+ }
72
+
73
+ /**
74
+ * Declaration-merging target for a single effect object (e.g., a shadow or filter
75
+ * definition). Shape is platform-specific; augmented by platform packages.
76
+ */
30
77
  export interface IEffect {
31
-
78
+
32
79
  }
33
80
 
81
+ /**
82
+ * Declaration-merging target for the named effects map (`theme.effects`).
83
+ * Augment with `{ shadow: IEffect; ... }` so that `effect:` variants are narrowed.
84
+ */
34
85
  export interface IEffects {
35
-
86
+
36
87
  }
37
88
 
89
+ /** Convenience alias for an unconstrained key-value record. */
38
90
  export type AnyRecord = Record<string, any>
39
91
 
92
+ /** Union of all breakpoint names defined via `IBreakpoints` augmentation. */
40
93
  export type Breakpoint = keyof IBreakpoints
94
+
95
+ /**
96
+ * Runtime context passed to context-aware style factories created with
97
+ * `createStylesWithContext`. Keys are feature flags or numeric state values
98
+ * (e.g., `{ isDisabled: true, tabIndex: 2 }`).
99
+ */
100
+ export type ComponentContext = Record<string, boolean|number>
package/src/types/icon.ts CHANGED
@@ -1,8 +1,19 @@
1
1
  /* eslint-disable @typescript-eslint/no-empty-interface */
2
2
 
3
+ /**
4
+ * Declaration-merging target for the app's named icon set.
5
+ * Augment with `{ arrowLeft: unknown; close: unknown; ... }` to produce a typed
6
+ * `AppIcon` union. Shapes are platform-defined; only the keys matter for typing.
7
+ */
3
8
  export interface AppIcons {
4
9
 
5
10
  }
11
+
12
+ /** Union of all named icon keys declared in `AppIcons`. Resolves to `never` if not augmented. */
6
13
  export type AppIcon = keyof AppIcons
7
14
 
15
+ /**
16
+ * Accepted value for any `icon` prop: either a named `AppIcon` key or an inline
17
+ * URL in the form `url:<href>` (e.g., `"url:https://example.com/icon.svg"`).
18
+ */
8
19
  export type IconProp = AppIcon | `url:${string}`
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Long-form spacing direction suffixes used with `margin` and `padding`.
3
+ * The empty string `''` represents the un-suffixed property (e.g., `padding`).
4
+ */
1
5
  export const spacingVariants = [
2
6
  'Vertical',
3
7
  'Horizontal',
@@ -8,6 +12,11 @@ export const spacingVariants = [
8
12
  '',
9
13
  ] as const
10
14
 
15
+ /**
16
+ * Short-form spacing direction suffixes used with `m` and `p`.
17
+ * Maps to the long-form via `shortPositionMap` inside `spacingFactory`.
18
+ * The empty string `''` represents the un-suffixed property (e.g., `p`).
19
+ */
11
20
  export const spacingShortVariants = [
12
21
  'y',
13
22
  'x',
@@ -18,15 +27,27 @@ export const spacingShortVariants = [
18
27
  '',
19
28
  ] as const
20
29
 
30
+ /** Union of all long-form direction suffixes (e.g., `'Vertical'`, `''`). */
21
31
  export type SpacingVariants = typeof spacingVariants[number]
22
32
 
33
+ /** Union of all short-form direction suffixes (e.g., `'x'`, `''`). */
23
34
  export type SpacingShortVariants = typeof spacingShortVariants[number]
24
35
 
36
+ /**
37
+ * Valid multiplier values for spacing and inset variant strings.
38
+ * `'auto'` maps to the CSS `auto` keyword; a number is scaled by `baseSpacing`;
39
+ * `''` is the empty-string terminator used in template literal unions.
40
+ */
25
41
  export type Multiplier =
26
42
  | 'auto'
27
43
  | number
28
44
  | ''
29
45
 
46
+ /**
47
+ * All valid spacing variant strings accepted by `StyleProp`.
48
+ * Examples: `"paddingVertical:2"`, `"mt:1"`, `"gap:auto"`.
49
+ * The numeric part is multiplied by `baseSpacing` at resolution time.
50
+ */
30
51
  export type Spacing =
31
52
  | `padding${SpacingVariants}:${Multiplier}`
32
53
  | `margin${SpacingVariants}:${Multiplier}`
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Minimal key-value storage contract used by `StylePersistor` and `Cache`.
3
+ * Designed to be implemented by any synchronous store (e.g., MMKV, AsyncStorage
4
+ * adapters, or `localStorage` wrappers). `getItem` must return `null` (not `undefined`)
5
+ * when the key is absent — callers use `?? null` guards based on that assumption.
6
+ */
1
7
  export interface StateStorage {
2
8
  getItem: (name: string) => any | null
3
9
  setItem: (name: string, value: any) => void
@@ -10,6 +10,12 @@ type Inset =
10
10
  | `left:${Multiplier}`
11
11
  | `right:${Multiplier}`
12
12
 
13
+ /**
14
+ * Union of all built-in variant string literals accepted anywhere a style variant
15
+ * name is valid: spacing shorthands, inset offsets, dynamic token variants (color,
16
+ * border, cursor, etc.), the static `defaultVariants` keys, app-defined variants,
17
+ * and named effect tokens.
18
+ */
13
19
  export type CommonVariants =
14
20
  Spacing |
15
21
  Inset |
@@ -18,12 +24,13 @@ export type CommonVariants =
18
24
  keyof IAppVariants |
19
25
  `effect:${keyof IEffects}`
20
26
 
21
- type StyleAtom<Composition = AnyRecord, Variants = string, HasBreakpoints = string, HasComposition = string> =
27
+ type StyleAtom<Composition extends string = string, Variants = string, HasBreakpoints = string, HasComposition = string> =
22
28
  ICSS |
23
29
  Variants |
24
30
  CommonVariants |
25
31
  boolean |
26
32
  null |
33
+ undefined |
27
34
  '' |
28
35
 
29
36
  (HasBreakpoints extends string ? {
@@ -35,29 +42,49 @@ type StyleAtom<Composition = AnyRecord, Variants = string, HasBreakpoints = stri
35
42
  } : null) |
36
43
  (HasComposition extends string ?
37
44
  Partial<Record<
38
- keyof Composition,
39
- StyleAtom<AnyRecord, Variants, boolean, boolean> |
40
- StyleAtom<AnyRecord, Variants, boolean, boolean>[]
45
+ Composition,
46
+ StyleAtom<Composition, Variants, boolean, boolean> |
47
+ StyleAtom<Composition, Variants, boolean, boolean>[]
41
48
  >>
42
49
  : null
43
50
  )
44
51
  | Array<Variants | ICSS | Partial<
45
52
  Record<
46
- keyof Composition,
47
- StyleAtom<AnyRecord, Variants, boolean, boolean> |
48
- StyleAtom<AnyRecord, Variants, boolean, boolean>[]
53
+ Composition,
54
+ StyleAtom<Composition, Variants, boolean, boolean> |
55
+ StyleAtom<Composition, Variants, boolean, boolean>[]
49
56
  >
50
57
  >>
51
58
 
59
+ /**
60
+ * The value accepted by any component's `style` prop. Supports:
61
+ * - A raw `ICSS` object applied to the root element.
62
+ * - A variant string (or array of strings) resolved through the registry.
63
+ * - A composition object mapping sub-element names to their own `StyleAtom`.
64
+ * - A `{ breakpoints: { [key]: StyleAtom } }` object for responsive overrides.
65
+ * - An array mixing any of the above — processed left-to-right, last write wins.
66
+ */
52
67
  export type StyleProp<
53
- Composition = AnyRecord,
68
+ Composition extends string = string,
54
69
  Variants = string
55
70
  > = StyleAtom<Composition, Variants> | StyleAtom<Composition, Variants>[]
56
71
 
72
+ /**
73
+ * Loosely typed variant stylesheet — a record mapping variant names to their style
74
+ * definitions. Used as the input to `createStyles` and `registerVariants`.
75
+ */
57
76
  export type VariantStyleSheet = Record<string, any>
58
77
 
59
- export type StyledProp<T extends string> = StyleProp<Record<T, ICSS>>
78
+ /** Alias for `StyleProp<T>` scoped to a specific set of composition keys. */
79
+ export type StyledProp<T extends string> = StyleProp<T>
60
80
 
81
+ /**
82
+ * Post-processing function that receives the merged theme and fully resolved variant
83
+ * styles and returns a (potentially transformed) style record. Useful for injecting
84
+ * cross-variant logic such as conditional overrides that depend on multiple variant
85
+ * states simultaneously.
86
+ */
61
87
  export type StyleAggregator<T extends string = any> = (theme: ITheme, style: Record< T, ICSS>) => Record< T, ICSS>
62
88
 
63
- export type StyleRecord<K extends string> = Record<K, ICSS>
89
+ /** Typed record mapping composition/element keys to their resolved `ICSS` values. */
90
+ export type StyleRecord<K extends string> = Record<K, ICSS>