@pyreon/rocketstyle 0.24.5 → 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.
Files changed (60) hide show
  1. package/package.json +8 -10
  2. package/src/__tests__/attrs-overloads.test.ts +0 -97
  3. package/src/__tests__/attrs.test.ts +0 -190
  4. package/src/__tests__/cache-key-boolean-collision.test.ts +0 -54
  5. package/src/__tests__/chaining.test.ts +0 -86
  6. package/src/__tests__/collection.test.ts +0 -35
  7. package/src/__tests__/compose.test.ts +0 -36
  8. package/src/__tests__/context.test.ts +0 -200
  9. package/src/__tests__/createLocalProvider.test.ts +0 -280
  10. package/src/__tests__/dimensions.test.ts +0 -183
  11. package/src/__tests__/e2e-styler.test.ts +0 -299
  12. package/src/__tests__/hooks.test.ts +0 -178
  13. package/src/__tests__/isRocketComponent.test.ts +0 -48
  14. package/src/__tests__/memo-cap.test.ts +0 -174
  15. package/src/__tests__/minimal-theme.test.ts +0 -62
  16. package/src/__tests__/misc.test.ts +0 -204
  17. package/src/__tests__/native-marker.test.ts +0 -9
  18. package/src/__tests__/providerConsumer.test.ts +0 -183
  19. package/src/__tests__/reactive-props-preservation.test.ts +0 -195
  20. package/src/__tests__/rocketstyle.browser.test.tsx +0 -481
  21. package/src/__tests__/rocketstyleIntegration.test.ts +0 -711
  22. package/src/__tests__/theme-integration.test.tsx +0 -254
  23. package/src/__tests__/themeUtils.test.ts +0 -463
  24. package/src/cache/LocalThemeManager.ts +0 -14
  25. package/src/cache/index.ts +0 -3
  26. package/src/constants/booleanTags.ts +0 -32
  27. package/src/constants/defaultDimensions.ts +0 -23
  28. package/src/constants/index.ts +0 -59
  29. package/src/context/context.ts +0 -70
  30. package/src/context/createLocalProvider.ts +0 -97
  31. package/src/context/localContext.ts +0 -37
  32. package/src/env.d.ts +0 -6
  33. package/src/hoc/index.ts +0 -3
  34. package/src/hoc/rocketstyleAttrsHoc.ts +0 -76
  35. package/src/hooks/index.ts +0 -4
  36. package/src/hooks/usePseudoState.ts +0 -79
  37. package/src/hooks/useTheme.ts +0 -48
  38. package/src/index.ts +0 -95
  39. package/src/init.ts +0 -93
  40. package/src/isRocketComponent.ts +0 -16
  41. package/src/rocketstyle.ts +0 -640
  42. package/src/types/attrs.ts +0 -23
  43. package/src/types/config.ts +0 -48
  44. package/src/types/configuration.ts +0 -69
  45. package/src/types/dimensions.ts +0 -109
  46. package/src/types/hoc.ts +0 -5
  47. package/src/types/pseudo.ts +0 -19
  48. package/src/types/rocketComponent.ts +0 -24
  49. package/src/types/rocketstyle.ts +0 -220
  50. package/src/types/styles.ts +0 -61
  51. package/src/types/theme.ts +0 -18
  52. package/src/types/utils.ts +0 -98
  53. package/src/utils/attrs.ts +0 -181
  54. package/src/utils/chaining.ts +0 -58
  55. package/src/utils/collection.ts +0 -9
  56. package/src/utils/compose.ts +0 -11
  57. package/src/utils/dimensions.ts +0 -126
  58. package/src/utils/statics.ts +0 -44
  59. package/src/utils/styles.ts +0 -18
  60. package/src/utils/theme.ts +0 -211
@@ -1,97 +0,0 @@
1
- import { provide } from '@pyreon/core'
2
- import { signal } from '@pyreon/reactivity'
3
- import type { PseudoProps } from '../types/pseudo'
4
- import type { ComponentFn } from '../types/utils'
5
- import { localContext } from './localContext'
6
-
7
- type Props = PseudoProps & Record<string, any>
8
-
9
- /**
10
- * Higher-order component that wraps a component with a LocalProvider,
11
- * detecting pseudo-states (hover, focus, pressed) via mouse/focus events
12
- * and broadcasting them through local context to child rocketstyle components.
13
- *
14
- * In Pyreon, context is provided via provide(), and state is managed
15
- * with signals instead of useState.
16
- */
17
- const createLocalProvider = (WrappedComponent: ComponentFn<any>) => {
18
- const HOCComponent: ComponentFn<Props> = ({
19
- onMouseEnter,
20
- onMouseLeave,
21
- onMouseUp,
22
- onMouseDown,
23
- onFocus,
24
- onBlur,
25
- $rocketstate,
26
- ...props
27
- }) => {
28
- const hover = signal(false)
29
- const focus = signal(false)
30
- const pressed = signal(false)
31
-
32
- const events = {
33
- onMouseEnter: (e: MouseEvent) => {
34
- hover.set(true)
35
- if (onMouseEnter) onMouseEnter(e)
36
- },
37
- onMouseLeave: (e: MouseEvent) => {
38
- hover.set(false)
39
- pressed.set(false)
40
- if (onMouseLeave) onMouseLeave(e)
41
- },
42
- onMouseDown: (e: MouseEvent) => {
43
- pressed.set(true)
44
- if (onMouseDown) onMouseDown(e)
45
- },
46
- onMouseUp: (e: MouseEvent) => {
47
- pressed.set(false)
48
- if (onMouseUp) onMouseUp(e)
49
- },
50
- onFocus: (e: FocusEvent) => {
51
- focus.set(true)
52
- if (onFocus) onFocus(e)
53
- },
54
- onBlur: (e: FocusEvent) => {
55
- focus.set(false)
56
- if (onBlur) onBlur(e)
57
- },
58
- }
59
-
60
- // Use getters so pseudo-state signals are read lazily by consumers
61
- // inside their own reactive scopes — NOT eagerly during parent setup.
62
- // Without getters, hover()/focus()/pressed() reads here would register
63
- // as dependencies of any parent effect, causing cascading re-renders
64
- // on every mouse event.
65
- // Resolve $rocketstate if it's a function accessor (from EnhancedComponent)
66
- const resolvedState =
67
- typeof $rocketstate === 'function' ? $rocketstate() : $rocketstate
68
- const updatedState = {
69
- ...resolvedState,
70
- pseudo: {
71
- ...resolvedState?.pseudo,
72
- get hover() {
73
- return hover()
74
- },
75
- get focus() {
76
- return focus()
77
- },
78
- get pressed() {
79
- return pressed()
80
- },
81
- },
82
- }
83
-
84
- // Provide local context for child rocketstyle components
85
- provide(localContext, updatedState)
86
-
87
- return WrappedComponent({
88
- ...props,
89
- ...events,
90
- $rocketstate: updatedState,
91
- })
92
- }
93
-
94
- return HOCComponent
95
- }
96
-
97
- export default createLocalProvider
@@ -1,37 +0,0 @@
1
- import { createContext, useContext } from '@pyreon/core'
2
- import type { PseudoState } from '../types/pseudo'
3
-
4
- type LocalContext = Partial<
5
- {
6
- pseudo: PseudoState
7
- } & Record<string, string>
8
- >
9
-
10
- /**
11
- * Local context for propagating pseudo-state (hover, focus, pressed)
12
- * and additional styling attributes from a parent provider component
13
- * to its rocketstyle children.
14
- */
15
- const localContext = createContext<LocalContext>({})
16
-
17
- const EMPTY_CTX = { pseudo: {} } as LocalContext
18
-
19
- /**
20
- * Retrieves the local pseudo-state context. When a consumer callback
21
- * is provided, it transforms the raw context; otherwise returns defaults.
22
- *
23
- * In Pyreon, components are plain functions that run once — no useMemo needed.
24
- */
25
- type UseLocalContext = (consumer: any) => LocalContext
26
- export const useLocalContext: UseLocalContext = (consumer) => {
27
- const ctx = useContext(localContext)
28
-
29
- if (!consumer) return EMPTY_CTX
30
-
31
- const result = consumer((callback: any) => callback(ctx))
32
- return { pseudo: {}, ...result }
33
- }
34
-
35
- export { localContext }
36
-
37
- export default localContext
package/src/env.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Minimal process type — just enough for `process.env.NODE_ENV` checks.
3
- * Avoids requiring @types/node in consumers that import pyreon source
4
- * via the `"bun"` export condition.
5
- */
6
- declare var process: { env: { NODE_ENV?: string } }
package/src/hoc/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import rocketstyleAttrsHoc from './rocketstyleAttrsHoc'
2
-
3
- export { rocketstyleAttrsHoc }
@@ -1,76 +0,0 @@
1
- import { render } from '@pyreon/ui-core'
2
- import { useTheme } from '../hooks'
3
- import type { Configuration } from '../types/configuration'
4
- import type { ComponentFn } from '../types/utils'
5
- import {
6
- calculateChainOptions,
7
- mergeDescriptors,
8
- removeUndefinedProps,
9
- } from '../utils/attrs'
10
-
11
- export type RocketStyleHOC = ({
12
- inversed,
13
- attrs,
14
- priorityAttrs,
15
- }: Pick<Configuration, 'inversed' | 'attrs' | 'priorityAttrs'>) => (
16
- WrappedComponent: ComponentFn<any>,
17
- ) => ComponentFn<any>
18
-
19
- /**
20
- * HOC that resolves the `.attrs()` chain before the inner component renders.
21
- * Evaluates both regular and priority attrs callbacks with the current theme
22
- * and mode, then merges the results with explicit props (priority attrs
23
- * are applied first, regular attrs can be overridden by direct props).
24
- *
25
- * In Pyreon, there is no forwardRef — ref flows as a normal prop.
26
- * Components are plain functions.
27
- */
28
- const rocketStyleHOC: RocketStyleHOC = ({ inversed, attrs, priorityAttrs }) => {
29
- const calculateAttrs = calculateChainOptions(attrs)
30
- const calculatePriorityAttrs = calculateChainOptions(priorityAttrs)
31
-
32
- const Enhanced = (WrappedComponent: ComponentFn<any>) => {
33
- const HOCComponent: ComponentFn<any> = (props) => {
34
- // IMPORTANT: Do NOT destructure — useTheme returns getter properties.
35
- // Destructuring calls getters once and captures static values.
36
- // Keep the object reference so properties re-evaluate lazily.
37
- const themeAttrs = useTheme({ inversed })
38
-
39
- // Remove undefined props not to override potential default props
40
- const filteredProps = removeUndefinedProps(props)
41
-
42
- // Read theme attrs eagerly — .attrs() callbacks run once at mount.
43
- // Mode-dependent styling is handled reactively by the $rocketstyle
44
- // accessor in EnhancedComponent, not by re-running attrs.
45
- const callbackParams = [
46
- themeAttrs.theme,
47
- { render, mode: themeAttrs.mode, isDark: themeAttrs.isDark, isLight: themeAttrs.isLight },
48
- ]
49
-
50
- const prioritizedAttrs = calculatePriorityAttrs([filteredProps, ...callbackParams])
51
-
52
- // Merge via descriptor-copy so reactive getter props on
53
- // filteredProps survive the chain. A `{...A, ...B}` spread
54
- // would fire every getter on A and B and store the resolved
55
- // value, breaking the reactive subscription downstream.
56
- // Attrs callbacks legitimately read prop VALUES (e.g.
57
- // `({ href }) => ({ tag: href ? 'a' : 'button' })`) — that's
58
- // a one-shot read at setup time by design. The pipeline only
59
- // needs to preserve reactivity for props the callbacks DON'T
60
- // consume, which the descriptor-merge does.
61
- const finalAttrs = calculateAttrs([
62
- mergeDescriptors(prioritizedAttrs, filteredProps),
63
- ...callbackParams,
64
- ])
65
-
66
- const finalProps = mergeDescriptors(prioritizedAttrs, finalAttrs, filteredProps)
67
-
68
- return WrappedComponent(finalProps)
69
- }
70
- return HOCComponent
71
- }
72
-
73
- return Enhanced
74
- }
75
-
76
- export default rocketStyleHOC
@@ -1,4 +0,0 @@
1
- import usePseudoState from './usePseudoState'
2
- import useTheme from './useTheme'
3
-
4
- export { usePseudoState, useTheme }
@@ -1,79 +0,0 @@
1
- import { signal } from '@pyreon/reactivity'
2
- import type { PseudoActions, PseudoState } from '../types/pseudo'
3
-
4
- type UsePseudoState = ({
5
- onMouseEnter,
6
- onMouseLeave,
7
- onMouseDown,
8
- onMouseUp,
9
- onFocus,
10
- onBlur,
11
- }: Partial<PseudoActions>) => {
12
- state: Pick<PseudoState, 'hover' | 'focus' | 'pressed'>
13
- events: PseudoActions
14
- }
15
-
16
- /**
17
- * Tracks hover, focus, and pressed pseudo-states via mouse and focus
18
- * event handlers. Returns the current state flags and wrapped event
19
- * callbacks that preserve any user-provided handlers.
20
- *
21
- * In Pyreon, uses signals instead of useState. Components are plain
22
- * functions that run once — no useCallback/useMemo needed.
23
- */
24
- const usePseudoState: UsePseudoState = ({
25
- onBlur,
26
- onFocus,
27
- onMouseDown,
28
- onMouseEnter,
29
- onMouseLeave,
30
- onMouseUp,
31
- }) => {
32
- const hover = signal(false)
33
- const focus = signal(false)
34
- const pressed = signal(false)
35
-
36
- const state = {
37
- get hover() {
38
- return hover()
39
- },
40
- get focus() {
41
- return focus()
42
- },
43
- get pressed() {
44
- return pressed()
45
- },
46
- }
47
-
48
- const events: PseudoActions = {
49
- onMouseEnter: (e) => {
50
- hover.set(true)
51
- if (onMouseEnter) onMouseEnter(e)
52
- },
53
- onMouseLeave: (e) => {
54
- hover.set(false)
55
- pressed.set(false)
56
- if (onMouseLeave) onMouseLeave(e)
57
- },
58
- onMouseDown: (e) => {
59
- pressed.set(true)
60
- if (onMouseDown) onMouseDown(e)
61
- },
62
- onMouseUp: (e) => {
63
- pressed.set(false)
64
- if (onMouseUp) onMouseUp(e)
65
- },
66
- onFocus: (e) => {
67
- focus.set(true)
68
- if (onFocus) onFocus(e)
69
- },
70
- onBlur: (e) => {
71
- focus.set(false)
72
- if (onBlur) onBlur(e)
73
- },
74
- }
75
-
76
- return { state, events }
77
- }
78
-
79
- export default usePseudoState
@@ -1,48 +0,0 @@
1
- import { useContext } from '@pyreon/core'
2
- import { THEME_MODES_INVERSED } from '../constants'
3
- import { context } from '../context/context'
4
- import type { ThemeModeKeys } from '../types/theme'
5
-
6
- type Context = {
7
- theme: Record<string, unknown>
8
- mode: ThemeModeKeys
9
- isDark: boolean
10
- isLight: boolean
11
- }
12
-
13
- type UseThemeAttrs = ({ inversed }: { inversed?: boolean | undefined }) => Context
14
-
15
- /**
16
- * Retrieves the current theme object and resolved mode from context.
17
- *
18
- * Returns an object with getter properties so that mode/isDark/isLight
19
- * are evaluated lazily on each access. The context is a ReactiveContext,
20
- * so useContext returns `() => CoreContextValue` — we call it inside
21
- * each getter to ensure reactive tracking.
22
- */
23
- const useThemeAttrs: UseThemeAttrs = ({ inversed }) => {
24
- // ReactiveContext: useContext returns () => CoreContextValue.
25
- // Call the getter inside each property getter for reactive tracking.
26
- const getCtx = useContext(context)
27
-
28
- return {
29
- get theme() {
30
- return getCtx().theme ?? ({} as Record<string, unknown>)
31
- },
32
- get mode() {
33
- const ctxMode = getCtx().mode ?? 'light'
34
- return inversed ? THEME_MODES_INVERSED[ctxMode] : ctxMode
35
- },
36
- get isDark() {
37
- const ctxDark = getCtx().isDark ?? false
38
- return inversed ? !ctxDark : ctxDark
39
- },
40
- get isLight() {
41
- const ctxDark = getCtx().isDark ?? false
42
- const isDark = inversed ? !ctxDark : ctxDark
43
- return !isDark
44
- },
45
- }
46
- }
47
-
48
- export default useThemeAttrs
package/src/index.ts DELETED
@@ -1,95 +0,0 @@
1
- import type { TProvider } from './context/context'
2
- import Provider, { context } from './context/context'
3
- import type { Rocketstyle } from './init'
4
- import rocketstyle from './init'
5
- import type { IsRocketComponent } from './isRocketComponent'
6
- import isRocketComponent from './isRocketComponent'
7
- import type { AttrsCb, AttrsHelpers } from './types/attrs'
8
- import type {
9
- ConfigAttrs,
10
- ConsumerCb,
11
- ConsumerCtxCBValue,
12
- ConsumerCtxCb,
13
- RocketComponentType,
14
- RocketProviderState,
15
- } from './types/config'
16
- import type { DefaultProps } from './types/configuration'
17
- import type {
18
- DimensionCallbackParam,
19
- DimensionProps,
20
- Dimensions,
21
- DimensionValue,
22
- ExtractDimensionProps,
23
- ExtractDimensions,
24
- TDKP,
25
- } from './types/dimensions'
26
- import type { ComposeParam, GenericHoc } from './types/hoc'
27
- import type { IRocketStyleComponent, RocketStyleComponent } from './types/rocketstyle'
28
- import type { RocketStyleInterpolationProps, StylesCb, StylesDefault } from './types/styles'
29
- import type {
30
- ThemeCb,
31
- ThemeDefault,
32
- ThemeMode,
33
- ThemeModeCallback,
34
- ThemeModeKeys,
35
- } from './types/theme'
36
- import type { ComponentFn, ElementType, ExtractProps, MergeTypes, TObj } from './types/utils'
37
-
38
- export type {
39
- AttrsCb,
40
- AttrsHelpers,
41
- ComponentFn,
42
- ComposeParam,
43
- ConfigAttrs,
44
- ConsumerCb,
45
- ConsumerCtxCBValue,
46
- ConsumerCtxCb,
47
- DefaultProps,
48
- DimensionCallbackParam,
49
- DimensionProps,
50
- Dimensions,
51
- DimensionValue,
52
- ElementType,
53
- ExtractDimensionProps,
54
- ExtractDimensions,
55
- ExtractProps,
56
- GenericHoc,
57
- IRocketStyleComponent,
58
- IsRocketComponent,
59
- MergeTypes,
60
- RocketComponentType,
61
- RocketProviderState,
62
- RocketStyleComponent,
63
- RocketStyleInterpolationProps,
64
- Rocketstyle,
65
- StylesCb,
66
- StylesDefault,
67
- TDKP,
68
- ThemeCb,
69
- ThemeDefault,
70
- ThemeMode,
71
- ThemeModeCallback,
72
- ThemeModeKeys,
73
- TObj,
74
- TProvider,
75
- }
76
-
77
- /**
78
- * Resolve a $rocketstyle value — handles both function accessor and plain object.
79
- * Use in styled() interpolation functions when $rocketstyle may be a reactive accessor.
80
- *
81
- * @example
82
- * ```ts
83
- * styled(Component)`
84
- * color: ${(props) => resolveTheme(props.$rocketstyle).color};
85
- * `
86
- * ```
87
- */
88
- export function resolveTheme<T = Record<string, unknown>>(
89
- value: (() => T) | T,
90
- ): T {
91
- return typeof value === 'function' ? (value as () => T)() : value
92
- }
93
-
94
- export { context, isRocketComponent, Provider, rocketstyle }
95
- export default rocketstyle
package/src/init.ts DELETED
@@ -1,93 +0,0 @@
1
- import { isEmpty } from '@pyreon/ui-core'
2
- import { ALL_RESERVED_KEYS, __DEV__ } from './constants'
3
- import defaultDimensions from './constants/defaultDimensions'
4
- import rocketComponent from './rocketstyle'
5
- import type { DefaultDimensions, Dimensions } from './types/dimensions'
6
- import type { RocketComponent } from './types/rocketComponent'
7
- import type { ElementType } from './types/utils'
8
- import {
9
- getDimensionsValues,
10
- getKeys,
11
- getMultipleDimensions,
12
- getTransformDimensions,
13
- } from './utils/dimensions'
14
-
15
- export type Rocketstyle = <
16
- const D extends Dimensions = DefaultDimensions,
17
- UB extends boolean = false,
18
- >({
19
- dimensions,
20
- useBooleans,
21
- }?: {
22
- dimensions?: D
23
- useBooleans?: UB
24
- }) => <C extends ElementType>({
25
- name,
26
- component,
27
- }: {
28
- name: string
29
- component: C
30
- }) => ReturnType<RocketComponent<C, {}, {}, D, UB>>
31
-
32
- /**
33
- * Factory initializer for rocketstyle components. Validates dimension
34
- * configurations against reserved keys, then delegates to the core
35
- * `rocketComponent` builder with pre-computed dimension metadata.
36
- */
37
- type InitErrors = Partial<{
38
- component: string
39
- name: string
40
- dimensions: string
41
- invalidDimensions: string
42
- }>
43
-
44
- const validateInit = (name: string, component: unknown, dimensions: Dimensions) => {
45
- const errors: InitErrors = {}
46
-
47
- if (!component) {
48
- errors.component = 'Parameter `component` is missing in params!'
49
- }
50
-
51
- if (!name) {
52
- errors.name = 'Parameter `name` is missing in params!'
53
- }
54
-
55
- if (isEmpty(dimensions)) {
56
- errors.dimensions = 'Parameter `dimensions` is missing in params!'
57
- } else {
58
- const definedDimensions = getKeys(dimensions)
59
- const invalidDimension = ALL_RESERVED_KEYS.some((item) =>
60
- definedDimensions.some((d) => d === item),
61
- )
62
-
63
- if (invalidDimension) {
64
- errors.invalidDimensions = `Some of your \`dimensions\` is invalid and uses reserved static keys which are
65
- ${defaultDimensions.toString()}`
66
- }
67
- }
68
-
69
- if (!isEmpty(errors)) {
70
- throw Error(JSON.stringify(errors))
71
- }
72
- }
73
-
74
- const rocketstyle = (({ dimensions = defaultDimensions, useBooleans = false } = {}) =>
75
- ({ name, component }: { name: string; component: any }) => {
76
- if (__DEV__) {
77
- validateInit(name, component, dimensions)
78
- }
79
-
80
- return (rocketComponent as any)({
81
- name,
82
- component,
83
- useBooleans,
84
- dimensions,
85
- dimensionKeys: getKeys(dimensions),
86
- dimensionValues: getDimensionsValues(dimensions),
87
- multiKeys: getMultipleDimensions(dimensions),
88
- transformKeys: getTransformDimensions(dimensions),
89
- styled: true,
90
- })
91
- }) as unknown as Rocketstyle
92
-
93
- export default rocketstyle
@@ -1,16 +0,0 @@
1
- export type IsRocketComponent = <T>(component: T) => boolean
2
-
3
- /** Runtime type guard — checks if a component was created by `rocketstyle()`. */
4
- const isRocketComponent: IsRocketComponent = (component) => {
5
- if (
6
- component &&
7
- (typeof component === 'object' || typeof component === 'function') &&
8
- Object.hasOwn(component as object, 'IS_ROCKETSTYLE')
9
- ) {
10
- return true
11
- }
12
-
13
- return false
14
- }
15
-
16
- export default isRocketComponent