@pyreon/ui-core 0.24.4 → 0.24.6

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.
@@ -1,102 +0,0 @@
1
- import { afterEach, describe, expect, it } from 'vitest'
2
- import config, { init } from '../config'
3
-
4
- describe('Configuration', () => {
5
- it('has default component as div', () => {
6
- expect(config.component).toBe('div')
7
- })
8
-
9
- it('has default textComponent as span', () => {
10
- expect(config.textComponent).toBe('span')
11
- })
12
-
13
- it('has css function', () => {
14
- expect(config.css).toBeDefined()
15
- expect(typeof config.css).toBe('function')
16
- })
17
-
18
- it('has styled function', () => {
19
- expect(config.styled).toBeDefined()
20
- expect(typeof config.styled).toBe('function')
21
- })
22
-
23
- it('has keyframes function', () => {
24
- expect(config.keyframes).toBeDefined()
25
- expect(typeof config.keyframes).toBe('function')
26
- })
27
-
28
- describe('init', () => {
29
- const originalCss = config.css
30
- const originalStyled = config.styled
31
- const originalKeyframes = config.keyframes
32
- const originalComponent = config.component
33
- const originalTextComponent = config.textComponent
34
- const originalCreateMediaQueries = config.createMediaQueries
35
-
36
- afterEach(() => {
37
- // restore defaults
38
- config.css = originalCss
39
- config.styled = originalStyled
40
- config.keyframes = originalKeyframes
41
- config.component = originalComponent
42
- config.textComponent = originalTextComponent
43
- config.createMediaQueries = originalCreateMediaQueries
44
- })
45
-
46
- it('updates css engine', () => {
47
- const mockCss = (() => '') as any
48
- init({ css: mockCss })
49
- expect(config.css).toBe(mockCss)
50
- })
51
-
52
- it('updates styled engine', () => {
53
- const mockStyled = (() => '') as any
54
- init({ styled: mockStyled })
55
- expect(config.styled).toBe(mockStyled)
56
- })
57
-
58
- it('updates component', () => {
59
- init({ component: 'section' })
60
- expect(config.component).toBe('section')
61
- })
62
-
63
- it('updates textComponent', () => {
64
- init({ textComponent: 'p' })
65
- expect(config.textComponent).toBe('p')
66
- })
67
-
68
- it('updates keyframes', () => {
69
- const mockKeyframes = (() => 'anim') as any
70
- init({ keyframes: mockKeyframes })
71
- expect(config.keyframes).toBe(mockKeyframes)
72
- })
73
-
74
- it('updates createMediaQueries', () => {
75
- const mockCreateMQ = (() => ({})) as any
76
- init({ createMediaQueries: mockCreateMQ })
77
- expect(config.createMediaQueries).toBe(mockCreateMQ)
78
- })
79
-
80
- it('only updates provided fields', () => {
81
- init({ component: 'article' })
82
- expect(config.component).toBe('article')
83
- expect(config.textComponent).toBe('span')
84
- expect(config.css).toBe(originalCss)
85
- })
86
-
87
- it('does nothing with empty object', () => {
88
- init({})
89
- expect(config.component).toBe('div')
90
- expect(config.textComponent).toBe('span')
91
- })
92
-
93
- it('can be called multiple times to swap engine', () => {
94
- const first = (() => 'first') as any
95
- const second = (() => 'second') as any
96
- init({ css: first })
97
- expect(config.css).toBe(first)
98
- init({ css: second })
99
- expect(config.css).toBe(second)
100
- })
101
- })
102
- })
@@ -1,71 +0,0 @@
1
- import { popContext, useContext } from '@pyreon/core'
2
- import { afterEach, describe, expect, it } from 'vitest'
3
- import Provider, { context } from '../context'
4
-
5
- describe('Provider', () => {
6
- afterEach(() => {
7
- // Clean up any pushed context frames
8
- try {
9
- popContext()
10
- } catch {
11
- // Ignore if no context was pushed
12
- }
13
- })
14
-
15
- it('returns children when no theme is provided', () => {
16
- const children = 'Hello'
17
- const result = Provider({ children })
18
- expect(result).toBe('Hello')
19
- })
20
-
21
- it('returns children with empty theme', () => {
22
- const children = 'Hello'
23
- const result = Provider({ theme: {}, children })
24
- expect(result).toBe('Hello')
25
- })
26
-
27
- it('returns children with null theme', () => {
28
- const children = 'Hello'
29
- // @ts-expect-error testing null theme
30
- const result = Provider({ theme: null, children })
31
- expect(result).toBe('Hello')
32
- })
33
-
34
- it('returns children when theme is provided and pushes context', () => {
35
- const theme = { rootSize: 16, breakpoints: { xs: 0 } }
36
- const children = 'Styled'
37
- const result = Provider({ theme, children })
38
- expect(result).toBe('Styled')
39
- })
40
-
41
- it('pushes context with theme and extra props', () => {
42
- const theme = { rootSize: 16 }
43
- const children = 'Content'
44
- Provider({ theme, children, custom: 'value' })
45
- // After Provider runs, context should have been pushed
46
- // Context is ReactiveContext — useContext returns () => value
47
- const getCtx = useContext(context)
48
- const ctx = getCtx() as any
49
- expect(ctx.theme).toEqual({ rootSize: 16 })
50
- expect(ctx.custom).toBe('value')
51
- })
52
-
53
- it('returns null when no children and no theme', () => {
54
- const result = Provider({})
55
- expect(result).toBeNull()
56
- })
57
-
58
- it('returns null when theme is provided but no children', () => {
59
- const theme = { rootSize: 16 }
60
- const result = Provider({ theme })
61
- expect(result).toBeNull()
62
- })
63
- })
64
-
65
- describe('context', () => {
66
- it('exports context object with an id', () => {
67
- expect(context).toBeDefined()
68
- expect(context.id).toBeDefined()
69
- expect(typeof context.id).toBe('symbol')
70
- })
71
- })
@@ -1,166 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import hoistNonReactStatics from '../hoistNonReactStatics'
3
-
4
- describe('hoistNonReactStatics', () => {
5
- it('copies custom static properties from source to target', () => {
6
- const Source = () => null
7
- ;(Source as any).customStatic = 'hello'
8
- ;(Source as any).anotherStatic = 42
9
-
10
- const Target = () => null
11
-
12
- hoistNonReactStatics(Target, Source)
13
-
14
- expect((Target as any).customStatic).toBe('hello')
15
- expect((Target as any).anotherStatic).toBe(42)
16
- })
17
-
18
- it('does not copy component statics (displayName, defaultProps)', () => {
19
- const Source = () => null
20
- Source.displayName = 'SourceComponent'
21
- ;(Source as any).defaultProps = { bar: 1 }
22
- ;(Source as any).customProp = 'should copy'
23
-
24
- const Target = () => null
25
- Target.displayName = 'TargetComponent'
26
-
27
- hoistNonReactStatics(Target, Source)
28
-
29
- expect(Target.displayName).toBe('TargetComponent')
30
- expect((Target as any).defaultProps).toBeUndefined()
31
- expect((Target as any).customProp).toBe('should copy')
32
- })
33
-
34
- it('does not copy known JS statics (name, length, prototype)', () => {
35
- const Source = () => null
36
- ;(Source as any).customProp = 'value'
37
-
38
- const Target = () => null
39
- const originalName = Target.name
40
-
41
- hoistNonReactStatics(Target, Source)
42
-
43
- expect(Target.name).toBe(originalName)
44
- expect((Target as any).customProp).toBe('value')
45
- })
46
-
47
- it('respects the excludeList', () => {
48
- const Source = () => null
49
- ;(Source as any).foo = 'included'
50
- ;(Source as any).bar = 'excluded'
51
- ;(Source as any).baz = 'included'
52
-
53
- const Target = () => null
54
-
55
- hoistNonReactStatics(Target, Source, { bar: true })
56
-
57
- expect((Target as any).foo).toBe('included')
58
- expect((Target as any).bar).toBeUndefined()
59
- expect((Target as any).baz).toBe('included')
60
- })
61
-
62
- it('returns the target component', () => {
63
- const Source = () => null
64
- const Target = () => null
65
-
66
- const result = hoistNonReactStatics(Target, Source)
67
- expect(result).toBe(Target)
68
- })
69
-
70
- it('handles string source (HTML tag) gracefully', () => {
71
- const Target = () => null
72
-
73
- const result = hoistNonReactStatics(Target, 'div' as any)
74
- expect(result).toBe(Target)
75
- })
76
-
77
- it('copies symbol-keyed properties', () => {
78
- const sym = Symbol('custom')
79
- const Source = () => null
80
- ;(Source as any)[sym] = 'symbol value'
81
-
82
- const Target = () => null
83
-
84
- hoistNonReactStatics(Target, Source)
85
-
86
- expect((Target as any)[sym]).toBe('symbol value')
87
- })
88
-
89
- it('copies getters and setters via property descriptors', () => {
90
- const Source = () => null
91
- let value = 0
92
- Object.defineProperty(Source, 'counter', {
93
- get: () => value,
94
- set: (v) => {
95
- value = v
96
- },
97
- enumerable: true,
98
- configurable: true,
99
- })
100
-
101
- const Target = () => null
102
-
103
- hoistNonReactStatics(Target, Source)
104
-
105
- expect((Target as any).counter).toBe(0)
106
- ;(Target as any).counter = 5
107
- expect((Target as any).counter).toBe(5)
108
- // shares the same backing variable
109
- expect((Source as any).counter).toBe(5)
110
- })
111
-
112
- it('does not throw on non-configurable target properties', () => {
113
- const Source = () => null
114
- ;(Source as any).locked = 'source value'
115
-
116
- const Target = () => null
117
- Object.defineProperty(Target, 'locked', {
118
- value: 'target value',
119
- writable: false,
120
- configurable: false,
121
- })
122
-
123
- expect(() => hoistNonReactStatics(Target, Source)).not.toThrow()
124
- expect((Target as any).locked).toBe('target value')
125
- })
126
-
127
- it('hoists statics from prototype chain', () => {
128
- function Base() {
129
- // constructor stub
130
- }
131
- Base.prototype = Object.create(null)
132
- ;(Base as any).inheritedStatic = 'from base'
133
-
134
- function Source() {
135
- // constructor stub
136
- }
137
- Source.prototype = Object.create(null)
138
- Object.setPrototypeOf(Source, Base)
139
- ;(Source as any).ownStatic = 'from source'
140
-
141
- const Target = () => null
142
-
143
- hoistNonReactStatics(Target, Source as any)
144
-
145
- expect((Target as any).ownStatic).toBe('from source')
146
- expect((Target as any).inheritedStatic).toBe('from base')
147
- })
148
-
149
- it('works with components that have no custom statics', () => {
150
- const Source = () => null
151
- const Target = () => null
152
-
153
- expect(() => hoistNonReactStatics(Target, Source)).not.toThrow()
154
- })
155
-
156
- it('stops prototype recursion at Object.prototype', () => {
157
- const Source = () => null
158
- ;(Source as any).custom = 'value'
159
- // Source's prototype is Function.prototype which has proto Object.prototype
160
- // The recursion should walk up and stop at Object.prototype
161
-
162
- const Target = () => null
163
- expect(() => hoistNonReactStatics(Target, Source)).not.toThrow()
164
- expect((Target as any).custom).toBe('value')
165
- })
166
- })
@@ -1,53 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import isEmpty from '../isEmpty'
3
-
4
- describe('isEmpty', () => {
5
- it('should return true for null', () => {
6
- expect(isEmpty(null)).toBe(true)
7
- })
8
-
9
- it('should return true for undefined', () => {
10
- expect(isEmpty(undefined)).toBe(true)
11
- })
12
-
13
- it('should return true for empty object', () => {
14
- expect(isEmpty({})).toBe(true)
15
- })
16
-
17
- it('should return true for empty array', () => {
18
- expect(isEmpty([])).toBe(true)
19
- })
20
-
21
- it('should return false for non-empty object', () => {
22
- expect(isEmpty({ a: 1 })).toBe(false)
23
- })
24
-
25
- it('should return false for non-empty array', () => {
26
- expect(isEmpty([1])).toBe(false)
27
- })
28
-
29
- it('should return false for array with falsy values', () => {
30
- expect(isEmpty([0, null, undefined])).toBe(false)
31
- })
32
-
33
- it('should return false for object with falsy values', () => {
34
- expect(isEmpty({ a: 0, b: null })).toBe(false)
35
- })
36
-
37
- it('should return true for Object.create(null) with no properties', () => {
38
- expect(isEmpty(Object.create(null))).toBe(true)
39
- })
40
-
41
- it('should return false for Object.create(null) with properties', () => {
42
- const obj = Object.create(null)
43
- obj.a = 1
44
- expect(isEmpty(obj)).toBe(false)
45
- })
46
-
47
- it('should return true for non-object truthy primitives', () => {
48
- // Covers typeof param !== 'object' branch
49
- expect(isEmpty(42 as any)).toBe(true)
50
- expect(isEmpty('hello' as any)).toBe(true)
51
- expect(isEmpty(true as any)).toBe(true)
52
- })
53
- })
@@ -1,114 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import isEqual from '../isEqual'
3
-
4
- describe('isEqual', () => {
5
- // Primitives
6
- it('should return true for identical primitives', () => {
7
- expect(isEqual(1, 1)).toBe(true)
8
- expect(isEqual('a', 'a')).toBe(true)
9
- expect(isEqual(true, true)).toBe(true)
10
- })
11
-
12
- it('should return false for different primitives', () => {
13
- expect(isEqual(1, 2)).toBe(false)
14
- expect(isEqual('a', 'b')).toBe(false)
15
- expect(isEqual(true, false)).toBe(false)
16
- })
17
-
18
- it('should handle NaN', () => {
19
- expect(isEqual(NaN, NaN)).toBe(true)
20
- })
21
-
22
- it('should distinguish 0 and -0', () => {
23
- expect(isEqual(0, -0)).toBe(false)
24
- })
25
-
26
- // Null / undefined
27
- it('should return true for null === null and undefined === undefined', () => {
28
- expect(isEqual(null, null)).toBe(true)
29
- expect(isEqual(undefined, undefined)).toBe(true)
30
- })
31
-
32
- it('should return false for null vs undefined', () => {
33
- expect(isEqual(null, undefined)).toBe(false)
34
- })
35
-
36
- it('should return false for null vs object', () => {
37
- expect(isEqual(null, {})).toBe(false)
38
- expect(isEqual({}, null)).toBe(false)
39
- })
40
-
41
- // Objects
42
- it('should return true for deeply equal objects', () => {
43
- expect(isEqual({ a: 1, b: 2 }, { a: 1, b: 2 })).toBe(true)
44
- })
45
-
46
- it('should return true regardless of key order', () => {
47
- expect(isEqual({ a: 1, b: 2 }, { b: 2, a: 1 })).toBe(true)
48
- })
49
-
50
- it('should return false for objects with different values', () => {
51
- expect(isEqual({ a: 1 }, { a: 2 })).toBe(false)
52
- })
53
-
54
- it('should return false for objects with different keys', () => {
55
- expect(isEqual({ a: 1 }, { b: 1 })).toBe(false)
56
- })
57
-
58
- it('should return false for objects with different key counts', () => {
59
- expect(isEqual({ a: 1 }, { a: 1, b: 2 })).toBe(false)
60
- })
61
-
62
- // Nested objects
63
- it('should deeply compare nested objects', () => {
64
- const a = { a: { b: { c: 1 } } }
65
- expect(isEqual(a, { a: { b: { c: 1 } } })).toBe(true)
66
- expect(isEqual(a, { a: { b: { c: 2 } } })).toBe(false)
67
- })
68
-
69
- it('should handle nested key order differences', () => {
70
- expect(isEqual({ x: { b: 2, a: 1 }, y: 3 }, { y: 3, x: { a: 1, b: 2 } })).toBe(true)
71
- })
72
-
73
- // Arrays
74
- it('should return true for identical arrays', () => {
75
- expect(isEqual([1, 2, 3], [1, 2, 3])).toBe(true)
76
- })
77
-
78
- it('should return false for arrays with different values', () => {
79
- expect(isEqual([1, 2], [1, 3])).toBe(false)
80
- })
81
-
82
- it('should return false for arrays with different lengths', () => {
83
- expect(isEqual([1, 2], [1, 2, 3])).toBe(false)
84
- })
85
-
86
- it('should not treat array and object as equal', () => {
87
- expect(isEqual([1], { 0: 1 })).toBe(false)
88
- expect(isEqual({ 0: 1 }, [1])).toBe(false)
89
- })
90
-
91
- // Mixed nested
92
- it('should deeply compare arrays of objects', () => {
93
- expect(isEqual([{ a: 1 }, { b: 2 }], [{ a: 1 }, { b: 2 }])).toBe(true)
94
- expect(isEqual([{ a: 1 }], [{ a: 2 }])).toBe(false)
95
- })
96
-
97
- it('should deeply compare objects with array values', () => {
98
- expect(isEqual({ a: [1, 2] }, { a: [1, 2] })).toBe(true)
99
- expect(isEqual({ a: [1, 2] }, { a: [1, 3] })).toBe(false)
100
- })
101
-
102
- // Same reference
103
- it('should return true for the same reference', () => {
104
- const obj = { a: 1 }
105
- expect(isEqual(obj, obj)).toBe(true)
106
- })
107
-
108
- // Type mismatches
109
- it('should return false for different types', () => {
110
- expect(isEqual(1, '1')).toBe(false)
111
- expect(isEqual([], {})).toBe(false)
112
- expect(isEqual(0, false)).toBe(false)
113
- })
114
- })
@@ -1,27 +0,0 @@
1
- import {
2
- renderApiReferenceEntries,
3
- renderLlmsFullSection,
4
- renderLlmsTxtLine,
5
- } from '@pyreon/manifest'
6
- import manifest from '../manifest'
7
-
8
- describe('gen-docs — ui-core snapshot', () => {
9
- it('renders a llms.txt bullet starting with the package prefix', () => {
10
- const line = renderLlmsTxtLine(manifest)
11
- expect(line.startsWith('- @pyreon/ui-core —')).toBe(true)
12
- })
13
-
14
- it('renders a llms-full.txt section with the right header', () => {
15
- const section = renderLlmsFullSection(manifest)
16
- expect(section.startsWith('## @pyreon/ui-core —')).toBe(true)
17
- expect(section).toContain('```typescript')
18
- })
19
-
20
- it('renders MCP api-reference entries for every api[] item', () => {
21
- const record = renderApiReferenceEntries(manifest)
22
- expect(Object.keys(record).sort()).toEqual([
23
- 'ui-core/PyreonUI',
24
- 'ui-core/useMode',
25
- ])
26
- })
27
- })
@@ -1,13 +0,0 @@
1
- import { isNativeCompat } from '@pyreon/core'
2
- import { describe, expect, it } from 'vitest'
3
- import CoreProvider from '../context'
4
- import { PyreonUI } from '../PyreonUI'
5
-
6
- describe('native-compat markers — @pyreon/ui-core', () => {
7
- it('PyreonUI is marked native', () => {
8
- expect(isNativeCompat(PyreonUI)).toBe(true)
9
- })
10
- it('CoreProvider is marked native', () => {
11
- expect(isNativeCompat(CoreProvider)).toBe(true)
12
- })
13
- })
@@ -1,72 +0,0 @@
1
- import type { VNode } from '@pyreon/core'
2
- import { Fragment, h } from '@pyreon/core'
3
- import { describe, expect, it } from 'vitest'
4
- import renderFn from '../render'
5
-
6
- const TestComponent = (props: { label?: string }) => {
7
- return h('span', { 'data-testid': 'test' }, props.label ?? 'default')
8
- }
9
-
10
- describe('render', () => {
11
- it('should return null for falsy content', () => {
12
- expect(renderFn(null)).toBeNull()
13
- expect(renderFn(undefined)).toBeNull()
14
- expect(renderFn(false as any)).toBeNull()
15
- expect(renderFn('' as any)).toBeNull()
16
- })
17
-
18
- it('should render a component with props', () => {
19
- const result = renderFn(TestComponent, { label: 'hello' }) as VNode
20
- expect(result).toBeDefined()
21
- expect(result.type).toBe(TestComponent)
22
- expect(result.props.label).toBe('hello')
23
- })
24
-
25
- it('should render a component without props', () => {
26
- const result = renderFn(TestComponent) as VNode
27
- expect(result).toBeDefined()
28
- expect(result.type).toBe(TestComponent)
29
- })
30
-
31
- it('should return string content as-is (treated as text)', () => {
32
- expect(renderFn('div' as any)).toBe('div')
33
- expect(renderFn('hello' as any)).toBe('hello')
34
- })
35
-
36
- it('should return primitive values as-is', () => {
37
- expect(renderFn(42 as any)).toBe(42)
38
- expect(renderFn(true as any)).toBe(true)
39
- expect(renderFn('text' as any)).toBe('text')
40
- })
41
-
42
- it('should return arrays as-is', () => {
43
- const arr = [h('span', { key: '1' }, 'a'), h('span', { key: '2' }, 'b')]
44
- expect(renderFn(arr as any)).toBe(arr)
45
- })
46
-
47
- it('should return a VNode object without modification when no props', () => {
48
- const vnode = h(TestComponent, { label: 'original' })
49
- const result = renderFn(vnode as any)
50
- // VNode objects are returned as-is
51
- expect(result).toBe(vnode)
52
- })
53
-
54
- it('should return a VNode object as-is even with props (VNode path does not merge)', () => {
55
- const vnode = h(TestComponent, { label: 'original' })
56
- const result = renderFn(vnode as any, { label: 'cloned' })
57
- // In Pyreon's render, VNode objects hit the object branch and are returned as-is
58
- expect(result).toBe(vnode)
59
- })
60
-
61
- it('should return fragment as-is', () => {
62
- const frag = h(Fragment, null, h('span', null, 'a'), h('span', null, 'b'))
63
- const result = renderFn(frag as any)
64
- expect(result).toBe(frag)
65
- })
66
-
67
- it('should return plain object as-is (fallback branch)', () => {
68
- // Plain objects are not valid elements, not primitives, not arrays
69
- const obj = { foo: 'bar' }
70
- expect(renderFn(obj as any)).toBe(obj)
71
- })
72
- })