@pyreon/rocketstyle 0.11.5 → 0.11.7

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 (51) hide show
  1. package/README.md +32 -32
  2. package/lib/index.d.ts +25 -6
  3. package/lib/index.js +122 -97
  4. package/package.json +25 -24
  5. package/src/__tests__/attrs.test.ts +49 -49
  6. package/src/__tests__/chaining.test.ts +27 -27
  7. package/src/__tests__/collection.test.ts +12 -12
  8. package/src/__tests__/compose.test.ts +10 -10
  9. package/src/__tests__/context.test.ts +65 -65
  10. package/src/__tests__/createLocalProvider.test.ts +53 -53
  11. package/src/__tests__/dimensions.test.ts +54 -54
  12. package/src/__tests__/e2e-styler.test.ts +142 -136
  13. package/src/__tests__/hooks.test.ts +41 -70
  14. package/src/__tests__/isRocketComponent.test.ts +11 -11
  15. package/src/__tests__/misc.test.ts +91 -91
  16. package/src/__tests__/providerConsumer.test.ts +54 -126
  17. package/src/__tests__/rocketstyleIntegration.test.ts +182 -255
  18. package/src/__tests__/themeUtils.test.ts +173 -173
  19. package/src/cache/index.ts +1 -1
  20. package/src/constants/booleanTags.ts +25 -25
  21. package/src/constants/defaultDimensions.ts +5 -5
  22. package/src/constants/index.ts +16 -16
  23. package/src/context/context.ts +13 -10
  24. package/src/context/createLocalProvider.ts +26 -13
  25. package/src/context/localContext.ts +2 -2
  26. package/src/hoc/index.ts +1 -1
  27. package/src/hoc/rocketstyleAttrsHoc.ts +26 -29
  28. package/src/hooks/index.ts +2 -2
  29. package/src/hooks/usePseudoState.ts +3 -3
  30. package/src/hooks/useTheme.ts +14 -17
  31. package/src/index.ts +32 -15
  32. package/src/init.ts +12 -12
  33. package/src/isRocketComponent.ts +2 -2
  34. package/src/rocketstyle.ts +125 -112
  35. package/src/types/attrs.ts +2 -2
  36. package/src/types/config.ts +4 -4
  37. package/src/types/configuration.ts +5 -5
  38. package/src/types/dimensions.ts +5 -5
  39. package/src/types/hoc.ts +1 -1
  40. package/src/types/rocketComponent.ts +4 -4
  41. package/src/types/rocketstyle.ts +10 -10
  42. package/src/types/styles.ts +9 -4
  43. package/src/types/theme.ts +4 -4
  44. package/src/types/utils.ts +1 -1
  45. package/src/utils/attrs.ts +2 -2
  46. package/src/utils/chaining.ts +2 -2
  47. package/src/utils/compose.ts +1 -1
  48. package/src/utils/dimensions.ts +6 -6
  49. package/src/utils/statics.ts +2 -2
  50. package/src/utils/styles.ts +2 -2
  51. package/src/utils/theme.ts +10 -10
@@ -3,102 +3,102 @@ import {
3
3
  calculateStylingAttrs,
4
4
  pickStyledAttrs,
5
5
  removeUndefinedProps,
6
- } from "../utils/attrs"
6
+ } from '../utils/attrs'
7
7
 
8
- describe("removeUndefinedProps", () => {
9
- it("removes keys with undefined values", () => {
10
- const result = removeUndefinedProps({ a: 1, b: undefined, c: "hello" })
11
- expect(result).toEqual({ a: 1, c: "hello" })
8
+ describe('removeUndefinedProps', () => {
9
+ it('removes keys with undefined values', () => {
10
+ const result = removeUndefinedProps({ a: 1, b: undefined, c: 'hello' })
11
+ expect(result).toEqual({ a: 1, c: 'hello' })
12
12
  })
13
13
 
14
- it("keeps null values", () => {
14
+ it('keeps null values', () => {
15
15
  const result = removeUndefinedProps({ a: null, b: 0 })
16
16
  expect(result).toEqual({ a: null, b: 0 })
17
17
  })
18
18
 
19
- it("keeps all falsy non-undefined values", () => {
20
- const result = removeUndefinedProps({ a: 0, b: "", c: false, d: null })
21
- expect(result).toEqual({ a: 0, b: "", c: false, d: null })
19
+ it('keeps all falsy non-undefined values', () => {
20
+ const result = removeUndefinedProps({ a: 0, b: '', c: false, d: null })
21
+ expect(result).toEqual({ a: 0, b: '', c: false, d: null })
22
22
  })
23
23
 
24
- it("returns empty for all undefined", () => {
24
+ it('returns empty for all undefined', () => {
25
25
  expect(removeUndefinedProps({ a: undefined, b: undefined })).toEqual({})
26
26
  })
27
27
 
28
- it("returns empty for empty input", () => {
28
+ it('returns empty for empty input', () => {
29
29
  expect(removeUndefinedProps({})).toEqual({})
30
30
  })
31
31
  })
32
32
 
33
- describe("pickStyledAttrs", () => {
34
- it("picks keys that exist in keywords with truthy values", () => {
33
+ describe('pickStyledAttrs', () => {
34
+ it('picks keys that exist in keywords with truthy values', () => {
35
35
  const result = pickStyledAttrs(
36
- { state: "primary", size: "large", label: "hello" },
36
+ { state: 'primary', size: 'large', label: 'hello' },
37
37
  { state: true, size: true },
38
38
  )
39
- expect(result).toEqual({ state: "primary", size: "large" })
39
+ expect(result).toEqual({ state: 'primary', size: 'large' })
40
40
  })
41
41
 
42
- it("ignores falsy prop values", () => {
43
- const result = pickStyledAttrs({ state: "", size: "large" }, { state: true, size: true })
44
- expect(result).toEqual({ size: "large" })
42
+ it('ignores falsy prop values', () => {
43
+ const result = pickStyledAttrs({ state: '', size: 'large' }, { state: true, size: true })
44
+ expect(result).toEqual({ size: 'large' })
45
45
  })
46
46
 
47
- it("returns empty when no keywords match", () => {
48
- const result = pickStyledAttrs({ label: "hello" } as any, { state: true })
47
+ it('returns empty when no keywords match', () => {
48
+ const result = pickStyledAttrs({ label: 'hello' } as any, { state: true })
49
49
  expect(result).toEqual({})
50
50
  })
51
51
 
52
- it("returns empty for empty props", () => {
52
+ it('returns empty for empty props', () => {
53
53
  const result = pickStyledAttrs({}, { state: true })
54
54
  expect(result).toEqual({})
55
55
  })
56
56
  })
57
57
 
58
- describe("calculateChainOptions", () => {
59
- it("returns empty object when options is empty array", () => {
58
+ describe('calculateChainOptions', () => {
59
+ it('returns empty object when options is empty array', () => {
60
60
  const calc = calculateChainOptions([])
61
61
  expect(calc([])).toEqual({})
62
62
  })
63
63
 
64
- it("returns empty object when options is undefined", () => {
64
+ it('returns empty object when options is undefined', () => {
65
65
  const calc = calculateChainOptions(undefined)
66
66
  expect(calc([])).toEqual({})
67
67
  })
68
68
 
69
- it("evaluates chain of functions and merges via Object.assign", () => {
69
+ it('evaluates chain of functions and merges via Object.assign', () => {
70
70
  const fn1 = (props: any) => ({ a: 1, ...props })
71
71
  const fn2 = (_props: any) => ({ b: 2 })
72
72
  const calc = calculateChainOptions([fn1, fn2])
73
73
  expect(calc([{ c: 3 }])).toEqual({ a: 1, b: 2, c: 3 })
74
74
  })
75
75
 
76
- it("later functions override earlier ones (shallow)", () => {
76
+ it('later functions override earlier ones (shallow)', () => {
77
77
  const fn1 = () => ({ a: 1 })
78
78
  const fn2 = () => ({ a: 2 })
79
79
  const calc = calculateChainOptions([fn1, fn2])
80
80
  expect(calc([])).toEqual({ a: 2 })
81
81
  })
82
82
 
83
- it("passes all args to each function", () => {
83
+ it('passes all args to each function', () => {
84
84
  const fn = vi.fn(() => ({}))
85
85
  const calc = calculateChainOptions([fn])
86
- calc(["arg1", "arg2"] as any)
87
- expect(fn).toHaveBeenCalledWith("arg1", "arg2")
86
+ calc(['arg1', 'arg2'] as any)
87
+ expect(fn).toHaveBeenCalledWith('arg1', 'arg2')
88
88
  })
89
89
  })
90
90
 
91
- describe("calculateStylingAttrs", () => {
92
- it("picks string values from props for dimensions", () => {
91
+ describe('calculateStylingAttrs', () => {
92
+ it('picks string values from props for dimensions', () => {
93
93
  const calc = calculateStylingAttrs({ useBooleans: false, multiKeys: {} })
94
94
  const result = calc({
95
- props: { state: "primary", size: "large" },
95
+ props: { state: 'primary', size: 'large' },
96
96
  dimensions: { state: {}, size: {} },
97
97
  })
98
- expect(result).toEqual({ state: "primary", size: "large" })
98
+ expect(result).toEqual({ state: 'primary', size: 'large' })
99
99
  })
100
100
 
101
- it("picks number values from props", () => {
101
+ it('picks number values from props', () => {
102
102
  const calc = calculateStylingAttrs({ useBooleans: false, multiKeys: {} })
103
103
  const result = calc({
104
104
  props: { state: 0 },
@@ -107,7 +107,7 @@ describe("calculateStylingAttrs", () => {
107
107
  expect(result).toEqual({ state: 0 })
108
108
  })
109
109
 
110
- it("sets undefined for non-string/non-number values when booleans disabled", () => {
110
+ it('sets undefined for non-string/non-number values when booleans disabled', () => {
111
111
  const calc = calculateStylingAttrs({ useBooleans: false, multiKeys: {} })
112
112
  const result = calc({
113
113
  props: { state: true },
@@ -116,19 +116,19 @@ describe("calculateStylingAttrs", () => {
116
116
  expect(result).toEqual({ state: undefined })
117
117
  })
118
118
 
119
- it("allows arrays for multi-key dimensions", () => {
119
+ it('allows arrays for multi-key dimensions', () => {
120
120
  const calc = calculateStylingAttrs({
121
121
  useBooleans: false,
122
122
  multiKeys: { multiple: true },
123
123
  })
124
124
  const result = calc({
125
- props: { multiple: ["a", "b"] },
125
+ props: { multiple: ['a', 'b'] },
126
126
  dimensions: { multiple: {} },
127
127
  })
128
- expect(result).toEqual({ multiple: ["a", "b"] })
128
+ expect(result).toEqual({ multiple: ['a', 'b'] })
129
129
  })
130
130
 
131
- it("resolves boolean props when useBooleans is true (single key)", () => {
131
+ it('resolves boolean props when useBooleans is true (single key)', () => {
132
132
  const calc = calculateStylingAttrs({
133
133
  useBooleans: true,
134
134
  multiKeys: {},
@@ -137,10 +137,10 @@ describe("calculateStylingAttrs", () => {
137
137
  props: { primary: true },
138
138
  dimensions: { state: { primary: true, secondary: true } },
139
139
  })
140
- expect(result).toEqual({ state: "primary" })
140
+ expect(result).toEqual({ state: 'primary' })
141
141
  })
142
142
 
143
- it("resolves multi-key boolean props as array", () => {
143
+ it('resolves multi-key boolean props as array', () => {
144
144
  const calc = calculateStylingAttrs({
145
145
  useBooleans: true,
146
146
  multiKeys: { multiple: true },
@@ -149,22 +149,22 @@ describe("calculateStylingAttrs", () => {
149
149
  props: { a: true, b: true },
150
150
  dimensions: { multiple: { a: true, b: true, c: true } },
151
151
  })
152
- expect(result.multiple).toEqual(expect.arrayContaining(["a", "b"]))
152
+ expect(result.multiple).toEqual(expect.arrayContaining(['a', 'b']))
153
153
  })
154
154
 
155
- it("prefers explicit string prop over boolean shorthand", () => {
155
+ it('prefers explicit string prop over boolean shorthand', () => {
156
156
  const calc = calculateStylingAttrs({
157
157
  useBooleans: true,
158
158
  multiKeys: {},
159
159
  })
160
160
  const result = calc({
161
- props: { state: "secondary", primary: true },
161
+ props: { state: 'secondary', primary: true },
162
162
  dimensions: { state: { primary: true, secondary: true } },
163
163
  })
164
- expect(result).toEqual({ state: "secondary" })
164
+ expect(result).toEqual({ state: 'secondary' })
165
165
  })
166
166
 
167
- it("skips boolean keyword when prop value is falsy", () => {
167
+ it('skips boolean keyword when prop value is falsy', () => {
168
168
  const calc = calculateStylingAttrs({
169
169
  useBooleans: true,
170
170
  multiKeys: {},
@@ -176,15 +176,15 @@ describe("calculateStylingAttrs", () => {
176
176
  expect(result.state).toBeUndefined()
177
177
  })
178
178
 
179
- it("skips boolean resolution when value is already set", () => {
179
+ it('skips boolean resolution when value is already set', () => {
180
180
  const calc = calculateStylingAttrs({
181
181
  useBooleans: true,
182
182
  multiKeys: {},
183
183
  })
184
184
  const result = calc({
185
- props: { state: "primary", secondary: true },
185
+ props: { state: 'primary', secondary: true },
186
186
  dimensions: { state: { primary: true, secondary: true } },
187
187
  })
188
- expect(result.state).toBe("primary")
188
+ expect(result.state).toBe('primary')
189
189
  })
190
190
  })
@@ -1,7 +1,7 @@
1
- import { chainOptions, chainOrOptions, chainReservedKeyOptions } from "../utils/chaining"
1
+ import { chainOptions, chainOrOptions, chainReservedKeyOptions } from '../utils/chaining'
2
2
 
3
- describe("chainOptions", () => {
4
- it("appends function to defaults", () => {
3
+ describe('chainOptions', () => {
4
+ it('appends function to defaults', () => {
5
5
  const fn1 = () => ({ a: 1 })
6
6
  const fn2 = () => ({ b: 2 })
7
7
  const result = chainOptions(fn2, [fn1])
@@ -10,26 +10,26 @@ describe("chainOptions", () => {
10
10
  expect(result[1]).toBe(fn2)
11
11
  })
12
12
 
13
- it("wraps object in function and appends", () => {
13
+ it('wraps object in function and appends', () => {
14
14
  const obj = { a: 1 }
15
15
  const result = chainOptions(obj, [])
16
16
  expect(result).toHaveLength(1)
17
17
  expect(result[0]?.()).toEqual({ a: 1 })
18
18
  })
19
19
 
20
- it("returns defaults when opts is undefined", () => {
20
+ it('returns defaults when opts is undefined', () => {
21
21
  const fn1 = () => ({ a: 1 })
22
22
  const result = chainOptions(undefined, [fn1])
23
23
  expect(result).toEqual([fn1])
24
24
  })
25
25
 
26
- it("handles empty defaults", () => {
26
+ it('handles empty defaults', () => {
27
27
  const fn = () => ({ a: 1 })
28
28
  const result = chainOptions(fn, [])
29
29
  expect(result).toHaveLength(1)
30
30
  })
31
31
 
32
- it("defaults to empty array when defaultOpts missing", () => {
32
+ it('defaults to empty array when defaultOpts missing', () => {
33
33
  const fn = () => ({ a: 1 })
34
34
  // @ts-expect-error testing with undefined defaults
35
35
  const result = chainOptions(fn, undefined)
@@ -37,33 +37,33 @@ describe("chainOptions", () => {
37
37
  })
38
38
  })
39
39
 
40
- describe("chainOrOptions", () => {
41
- it("merges opts with defaults using keys", () => {
42
- const keys = ["a", "b", "c"] as const
43
- const opts = { a: "new", c: "also" }
44
- const defaults = { a: "old", b: "default", c: "orig" }
40
+ describe('chainOrOptions', () => {
41
+ it('merges opts with defaults using keys', () => {
42
+ const keys = ['a', 'b', 'c'] as const
43
+ const opts = { a: 'new', c: 'also' }
44
+ const defaults = { a: 'old', b: 'default', c: 'orig' }
45
45
  const result = chainOrOptions(keys, opts, defaults)
46
- expect(result).toEqual({ a: "new", b: "default", c: "also" })
46
+ expect(result).toEqual({ a: 'new', b: 'default', c: 'also' })
47
47
  })
48
48
 
49
- it("uses default when opt is falsy", () => {
50
- const keys = ["a"] as const
51
- const opts = { a: "" }
52
- const defaults = { a: "default" }
49
+ it('uses default when opt is falsy', () => {
50
+ const keys = ['a'] as const
51
+ const opts = { a: '' }
52
+ const defaults = { a: 'default' }
53
53
  const result = chainOrOptions(keys, opts, defaults)
54
- expect(result).toEqual({ a: "default" })
54
+ expect(result).toEqual({ a: 'default' })
55
55
  })
56
56
 
57
- it("handles missing keys in both", () => {
58
- const keys = ["x"] as const
57
+ it('handles missing keys in both', () => {
58
+ const keys = ['x'] as const
59
59
  const result = chainOrOptions(keys, {}, {})
60
60
  expect(result).toEqual({ x: undefined })
61
61
  })
62
62
  })
63
63
 
64
- describe("chainReservedKeyOptions", () => {
65
- it("chains options for each reserved key", () => {
66
- const keys = ["theme", "styles"] as const
64
+ describe('chainReservedKeyOptions', () => {
65
+ it('chains options for each reserved key', () => {
66
+ const keys = ['theme', 'styles'] as const
67
67
  const fn1 = () => ({ a: 1 })
68
68
  const fn2 = () => ({ b: 2 })
69
69
  const opts = { theme: fn2 }
@@ -74,13 +74,13 @@ describe("chainReservedKeyOptions", () => {
74
74
  expect(result.styles).toHaveLength(0)
75
75
  })
76
76
 
77
- it("wraps object opts into functions", () => {
78
- const keys = ["theme"] as const
79
- const opts = { theme: { color: "red" } }
77
+ it('wraps object opts into functions', () => {
78
+ const keys = ['theme'] as const
79
+ const opts = { theme: { color: 'red' } }
80
80
  const defaults = { theme: [] }
81
81
 
82
82
  const result = chainReservedKeyOptions(keys, opts, defaults)
83
83
  expect(result.theme).toHaveLength(1)
84
- expect(result.theme?.[0]?.()).toEqual({ color: "red" })
84
+ expect(result.theme?.[0]?.()).toEqual({ color: 'red' })
85
85
  })
86
86
  })
@@ -1,35 +1,35 @@
1
- import { removeNullableValues } from "../utils/collection"
1
+ import { removeNullableValues } from '../utils/collection'
2
2
 
3
- describe("removeNullableValues", () => {
4
- it("removes null values", () => {
3
+ describe('removeNullableValues', () => {
4
+ it('removes null values', () => {
5
5
  expect(removeNullableValues({ a: 1, b: null })).toEqual({ a: 1 })
6
6
  })
7
7
 
8
- it("removes undefined values", () => {
8
+ it('removes undefined values', () => {
9
9
  expect(removeNullableValues({ a: 1, b: undefined })).toEqual({ a: 1 })
10
10
  })
11
11
 
12
- it("removes false values", () => {
12
+ it('removes false values', () => {
13
13
  expect(removeNullableValues({ a: 1, b: false })).toEqual({ a: 1 })
14
14
  })
15
15
 
16
- it("keeps truthy values", () => {
17
- expect(removeNullableValues({ a: 1, b: "hello", c: true })).toEqual({
16
+ it('keeps truthy values', () => {
17
+ expect(removeNullableValues({ a: 1, b: 'hello', c: true })).toEqual({
18
18
  a: 1,
19
- b: "hello",
19
+ b: 'hello',
20
20
  c: true,
21
21
  })
22
22
  })
23
23
 
24
- it("keeps zero and empty string", () => {
25
- expect(removeNullableValues({ a: 0, b: "" })).toEqual({ a: 0, b: "" })
24
+ it('keeps zero and empty string', () => {
25
+ expect(removeNullableValues({ a: 0, b: '' })).toEqual({ a: 0, b: '' })
26
26
  })
27
27
 
28
- it("returns empty object for all nullable", () => {
28
+ it('returns empty object for all nullable', () => {
29
29
  expect(removeNullableValues({ a: null, b: undefined, c: false })).toEqual({})
30
30
  })
31
31
 
32
- it("handles empty object", () => {
32
+ it('handles empty object', () => {
33
33
  expect(removeNullableValues({})).toEqual({})
34
34
  })
35
35
  })
@@ -1,7 +1,7 @@
1
- import { calculateHocsFuncs } from "../utils/compose"
1
+ import { calculateHocsFuncs } from '../utils/compose'
2
2
 
3
- describe("calculateHocsFuncs", () => {
4
- it("extracts functions from object values", () => {
3
+ describe('calculateHocsFuncs', () => {
4
+ it('extracts functions from object values', () => {
5
5
  const fn1 = (x: any) => x
6
6
  const fn2 = (x: any) => x
7
7
  const options = { a: fn1, b: fn2 }
@@ -9,28 +9,28 @@ describe("calculateHocsFuncs", () => {
9
9
  expect(result).toHaveLength(2)
10
10
  })
11
11
 
12
- it("filters out non-function values", () => {
12
+ it('filters out non-function values', () => {
13
13
  const fn = (x: any) => x
14
- const options = { a: fn, b: "string", c: 42, d: null }
14
+ const options = { a: fn, b: 'string', c: 42, d: null }
15
15
  const result = calculateHocsFuncs(options)
16
16
  expect(result).toHaveLength(1)
17
17
  expect(result[0]).toBe(fn)
18
18
  })
19
19
 
20
- it("reverses the order", () => {
21
- const fn1 = () => "first"
22
- const fn2 = () => "second"
20
+ it('reverses the order', () => {
21
+ const fn1 = () => 'first'
22
+ const fn2 = () => 'second'
23
23
  const options = { a: fn1, b: fn2 }
24
24
  const result = calculateHocsFuncs(options)
25
25
  expect(result[0]).toBe(fn2)
26
26
  expect(result[1]).toBe(fn1)
27
27
  })
28
28
 
29
- it("returns empty array for empty options", () => {
29
+ it('returns empty array for empty options', () => {
30
30
  expect(calculateHocsFuncs({})).toEqual([])
31
31
  })
32
32
 
33
- it("handles undefined options", () => {
33
+ it('handles undefined options', () => {
34
34
  expect(calculateHocsFuncs(undefined as any)).toEqual([])
35
35
  })
36
36
  })