@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.
- package/README.md +32 -32
- package/lib/index.d.ts +25 -6
- package/lib/index.js +122 -97
- package/package.json +25 -24
- package/src/__tests__/attrs.test.ts +49 -49
- package/src/__tests__/chaining.test.ts +27 -27
- package/src/__tests__/collection.test.ts +12 -12
- package/src/__tests__/compose.test.ts +10 -10
- package/src/__tests__/context.test.ts +65 -65
- package/src/__tests__/createLocalProvider.test.ts +53 -53
- package/src/__tests__/dimensions.test.ts +54 -54
- package/src/__tests__/e2e-styler.test.ts +142 -136
- package/src/__tests__/hooks.test.ts +41 -70
- package/src/__tests__/isRocketComponent.test.ts +11 -11
- package/src/__tests__/misc.test.ts +91 -91
- package/src/__tests__/providerConsumer.test.ts +54 -126
- package/src/__tests__/rocketstyleIntegration.test.ts +182 -255
- package/src/__tests__/themeUtils.test.ts +173 -173
- package/src/cache/index.ts +1 -1
- package/src/constants/booleanTags.ts +25 -25
- package/src/constants/defaultDimensions.ts +5 -5
- package/src/constants/index.ts +16 -16
- package/src/context/context.ts +13 -10
- package/src/context/createLocalProvider.ts +26 -13
- package/src/context/localContext.ts +2 -2
- package/src/hoc/index.ts +1 -1
- package/src/hoc/rocketstyleAttrsHoc.ts +26 -29
- package/src/hooks/index.ts +2 -2
- package/src/hooks/usePseudoState.ts +3 -3
- package/src/hooks/useTheme.ts +14 -17
- package/src/index.ts +32 -15
- package/src/init.ts +12 -12
- package/src/isRocketComponent.ts +2 -2
- package/src/rocketstyle.ts +125 -112
- package/src/types/attrs.ts +2 -2
- package/src/types/config.ts +4 -4
- package/src/types/configuration.ts +5 -5
- package/src/types/dimensions.ts +5 -5
- package/src/types/hoc.ts +1 -1
- package/src/types/rocketComponent.ts +4 -4
- package/src/types/rocketstyle.ts +10 -10
- package/src/types/styles.ts +9 -4
- package/src/types/theme.ts +4 -4
- package/src/types/utils.ts +1 -1
- package/src/utils/attrs.ts +2 -2
- package/src/utils/chaining.ts +2 -2
- package/src/utils/compose.ts +1 -1
- package/src/utils/dimensions.ts +6 -6
- package/src/utils/statics.ts +2 -2
- package/src/utils/styles.ts +2 -2
- package/src/utils/theme.ts +10 -10
package/src/rocketstyle.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { compose, config, hoistNonReactStatics, omit, pick, render } from
|
|
2
|
-
import { LocalThemeManager } from
|
|
3
|
-
import { CONFIG_KEYS, PSEUDO_KEYS, PSEUDO_META_KEYS, STYLING_KEYS } from
|
|
4
|
-
import createLocalProvider from
|
|
5
|
-
import { useLocalContext } from
|
|
6
|
-
import { rocketstyleAttrsHoc } from
|
|
7
|
-
import { useTheme } from
|
|
8
|
-
import type { Configuration, ExtendedConfiguration } from
|
|
9
|
-
import type { RocketComponent } from
|
|
10
|
-
import type { InnerComponentProps, RocketStyleComponent } from
|
|
11
|
-
import type { ComponentFn } from
|
|
12
|
-
import { calculateChainOptions, calculateStylingAttrs, pickStyledAttrs } from
|
|
13
|
-
import { chainOptions, chainOrOptions, chainReservedKeyOptions } from
|
|
14
|
-
import { calculateHocsFuncs } from
|
|
15
|
-
import { getDimensionsMap } from
|
|
16
|
-
import { createStaticsChainingEnhancers, createStaticsEnhancers } from
|
|
17
|
-
import { calculateStyles } from
|
|
18
|
-
import { getDimensionThemes, getTheme, getThemeByMode, getThemeFromChain } from
|
|
1
|
+
import { compose, config, hoistNonReactStatics, omit, pick, render } from '@pyreon/ui-core'
|
|
2
|
+
import { LocalThemeManager } from './cache'
|
|
3
|
+
import { CONFIG_KEYS, PSEUDO_KEYS, PSEUDO_META_KEYS, STYLING_KEYS } from './constants'
|
|
4
|
+
import createLocalProvider from './context/createLocalProvider'
|
|
5
|
+
import { useLocalContext } from './context/localContext'
|
|
6
|
+
import { rocketstyleAttrsHoc } from './hoc'
|
|
7
|
+
import { useTheme } from './hooks'
|
|
8
|
+
import type { Configuration, ExtendedConfiguration } from './types/configuration'
|
|
9
|
+
import type { RocketComponent } from './types/rocketComponent'
|
|
10
|
+
import type { InnerComponentProps, RocketStyleComponent } from './types/rocketstyle'
|
|
11
|
+
import type { ComponentFn } from './types/utils'
|
|
12
|
+
import { calculateChainOptions, calculateStylingAttrs, pickStyledAttrs } from './utils/attrs'
|
|
13
|
+
import { chainOptions, chainOrOptions, chainReservedKeyOptions } from './utils/chaining'
|
|
14
|
+
import { calculateHocsFuncs } from './utils/compose'
|
|
15
|
+
import { getDimensionsMap } from './utils/dimensions'
|
|
16
|
+
import { createStaticsChainingEnhancers, createStaticsEnhancers } from './utils/statics'
|
|
17
|
+
import { calculateStyles } from './utils/styles'
|
|
18
|
+
import { getDimensionThemes, getTheme, getThemeByMode, getThemeFromChain } from './utils/theme'
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Core rocketstyle component factory. Creates a fully-featured Pyreon component
|
|
@@ -110,132 +110,145 @@ const rocketComponent: RocketComponent = (options) => {
|
|
|
110
110
|
const themeAttrs = useTheme(options)
|
|
111
111
|
|
|
112
112
|
// --------------------------------------------------
|
|
113
|
-
//
|
|
113
|
+
// Theme structure — cached by theme object identity.
|
|
114
|
+
// Theme object itself doesn't change (enrichTheme produces a stable ref),
|
|
115
|
+
// only mode switches change which mode-variant is resolved.
|
|
114
116
|
// --------------------------------------------------
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
const theme = themeAttrs.theme
|
|
118
|
+
|
|
119
|
+
const baseThemeHelper = ThemeManager.baseTheme
|
|
120
|
+
if (!baseThemeHelper.has(theme)) {
|
|
121
|
+
baseThemeHelper.set(theme, getThemeFromChain(options.theme, theme))
|
|
118
122
|
}
|
|
123
|
+
const baseTheme = baseThemeHelper.get(theme)
|
|
119
124
|
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
const dimHelper = ThemeManager.dimensionsThemes
|
|
126
|
+
if (!dimHelper.has(theme)) {
|
|
127
|
+
dimHelper.set(theme, getDimensionThemes(theme, options))
|
|
123
128
|
}
|
|
129
|
+
const themes = dimHelper.get(theme)
|
|
130
|
+
|
|
131
|
+
const { keysMap: dimensions, keywords: reservedPropNames } = getDimensionsMap({
|
|
132
|
+
themes,
|
|
133
|
+
useBooleans: options.useBooleans,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const RESERVED_STYLING_PROPS_KEYS = Object.keys(reservedPropNames)
|
|
124
137
|
|
|
125
138
|
// --------------------------------------------------
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
// re-render of the styled subtree is acceptable.
|
|
139
|
+
// $rocketstyle as a FUNCTION ACCESSOR — fully reactive.
|
|
140
|
+
// Re-evaluates when mode OR dimension props change.
|
|
141
|
+
// Props are resolved fresh each call so reactive prop accessors
|
|
142
|
+
// (signals, getters) produce updated dimension values.
|
|
131
143
|
// --------------------------------------------------
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// --------------------------------------------------
|
|
139
|
-
// calculate themes for all defined styling dimensions
|
|
140
|
-
// --------------------------------------------------
|
|
141
|
-
|
|
142
|
-
// BASE / DEFAULT THEME Object (cached by theme identity)
|
|
143
|
-
const baseThemeHelper = ThemeManager.baseTheme
|
|
144
|
-
if (!baseThemeHelper.has(theme)) {
|
|
145
|
-
baseThemeHelper.set(theme, getThemeFromChain(options.theme, theme))
|
|
144
|
+
const $rocketstyleAccessor = () => {
|
|
145
|
+
// Merge props fresh — if parent passes reactive accessors,
|
|
146
|
+
// spreading them here evaluates them in this reactive scope.
|
|
147
|
+
const { pseudo, ...mergeProps } = {
|
|
148
|
+
...localCtx,
|
|
149
|
+
...props,
|
|
146
150
|
}
|
|
147
|
-
const baseTheme = baseThemeHelper.get(theme)
|
|
148
151
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
const mode = themeAttrs.mode // reactive: tracks mode signal
|
|
153
|
+
|
|
154
|
+
// Resolve active dimensions from current prop values
|
|
155
|
+
const rocketstate = _calculateStylingAttrs({
|
|
156
|
+
props: pickStyledAttrs(mergeProps, reservedPropNames),
|
|
157
|
+
dimensions,
|
|
158
|
+
})
|
|
155
159
|
|
|
156
|
-
//
|
|
160
|
+
// Resolve mode-specific theme
|
|
157
161
|
const modeBaseHelper = ThemeManager.modeBaseTheme[mode]
|
|
158
162
|
if (!modeBaseHelper.has(baseTheme)) {
|
|
159
163
|
modeBaseHelper.set(baseTheme, getThemeByMode(baseTheme, mode))
|
|
160
164
|
}
|
|
161
165
|
const currentModeBaseTheme = modeBaseHelper.get(baseTheme)
|
|
162
166
|
|
|
163
|
-
// DIMENSION(S) MODE THEMES Object (cached by mode + themes)
|
|
164
167
|
const modeDimHelper = ThemeManager.modeDimensionTheme[mode]
|
|
165
168
|
if (!modeDimHelper.has(themes)) {
|
|
166
169
|
modeDimHelper.set(themes, getThemeByMode(themes, mode))
|
|
167
170
|
}
|
|
168
171
|
const currentModeThemes = modeDimHelper.get(themes)
|
|
169
172
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
return getTheme({
|
|
174
|
+
rocketstate,
|
|
175
|
+
themes: currentModeThemes,
|
|
176
|
+
baseTheme: currentModeBaseTheme,
|
|
177
|
+
transformKeys: options.transformKeys,
|
|
178
|
+
appTheme: theme,
|
|
176
179
|
})
|
|
180
|
+
}
|
|
177
181
|
|
|
178
|
-
|
|
182
|
+
// --------------------------------------------------
|
|
183
|
+
// $rocketstate as a FUNCTION ACCESSOR — reactive on prop changes.
|
|
184
|
+
// Re-evaluates active dimensions + pseudo state from current props.
|
|
185
|
+
// --------------------------------------------------
|
|
186
|
+
const $rocketstateAccessor = () => {
|
|
187
|
+
const { pseudo, ...mergeProps } = {
|
|
188
|
+
...localCtx,
|
|
189
|
+
...props,
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const pseudoRocketstate = {
|
|
193
|
+
...pseudo,
|
|
194
|
+
...pick(props, [...PSEUDO_KEYS, ...PSEUDO_META_KEYS]),
|
|
195
|
+
}
|
|
179
196
|
|
|
180
|
-
// --------------------------------------------------
|
|
181
|
-
// rocketstate — active dimension values
|
|
182
|
-
// --------------------------------------------------
|
|
183
197
|
const rocketstate = _calculateStylingAttrs({
|
|
184
198
|
props: pickStyledAttrs(mergeProps, reservedPropNames),
|
|
185
199
|
dimensions,
|
|
186
200
|
})
|
|
187
201
|
|
|
188
|
-
|
|
202
|
+
return { ...rocketstate, pseudo: pseudoRocketstate }
|
|
203
|
+
}
|
|
189
204
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
transformKeys: options.transformKeys,
|
|
198
|
-
appTheme: theme,
|
|
199
|
-
})
|
|
205
|
+
// --------------------------------------------------
|
|
206
|
+
// Static mergeProps for final prop filtering (non-dimension props)
|
|
207
|
+
// --------------------------------------------------
|
|
208
|
+
const { pseudo: _pseudo, ...mergeProps } = {
|
|
209
|
+
...localCtx,
|
|
210
|
+
...props,
|
|
211
|
+
}
|
|
200
212
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
// --------------------------------------------------
|
|
214
|
+
// final props passed to WrappedComponent
|
|
215
|
+
// --------------------------------------------------
|
|
216
|
+
const finalProps: Record<string, any> = {
|
|
217
|
+
...omit(mergeProps, [
|
|
218
|
+
...RESERVED_STYLING_PROPS_KEYS,
|
|
219
|
+
...PSEUDO_KEYS,
|
|
220
|
+
...options.filterAttrs,
|
|
221
|
+
]),
|
|
222
|
+
...(options.passProps ? pick(mergeProps, options.passProps) : {}),
|
|
223
|
+
ref: props.ref,
|
|
224
|
+
// FUNCTION accessors — styled component resolves them reactively
|
|
225
|
+
$rocketstyle: $rocketstyleAccessor,
|
|
226
|
+
$rocketstate: $rocketstateAccessor,
|
|
227
|
+
}
|
|
216
228
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// biome-ignore lint/suspicious/noConsole: debug logging controlled by DEBUG option
|
|
233
|
-
console.debug(`[rocketstyle] ${componentName} render:`, debugPayload)
|
|
229
|
+
// development debugging
|
|
230
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
231
|
+
finalProps['data-rocketstyle'] = componentName
|
|
232
|
+
|
|
233
|
+
if (options.DEBUG) {
|
|
234
|
+
const debugPayload = {
|
|
235
|
+
component: componentName,
|
|
236
|
+
rocketstate: $rocketstateAccessor(),
|
|
237
|
+
rocketstyle: $rocketstyleAccessor(),
|
|
238
|
+
dimensions,
|
|
239
|
+
mode: themeAttrs.mode,
|
|
240
|
+
reservedPropNames: RESERVED_STYLING_PROPS_KEYS,
|
|
241
|
+
filteredAttrs: options.filterAttrs,
|
|
234
242
|
}
|
|
243
|
+
|
|
244
|
+
// eslint-disable-next-line no-console
|
|
245
|
+
console.debug(`[rocketstyle] ${componentName} render:`, debugPayload)
|
|
235
246
|
}
|
|
247
|
+
}
|
|
236
248
|
|
|
237
|
-
|
|
238
|
-
|
|
249
|
+
// STATIC VNode — created once, never remounted on mode change.
|
|
250
|
+
// The styled component handles reactive class swaps internally.
|
|
251
|
+
return RenderComponent(finalProps)
|
|
239
252
|
}
|
|
240
253
|
|
|
241
254
|
// ------------------------------------------------------
|
|
@@ -285,12 +298,12 @@ const rocketComponent: RocketComponent = (options) => {
|
|
|
285
298
|
}
|
|
286
299
|
|
|
287
300
|
if (priority) {
|
|
288
|
-
result.priorityAttrs = attrs as ExtendedConfiguration[
|
|
301
|
+
result.priorityAttrs = attrs as ExtendedConfiguration['priorityAttrs']
|
|
289
302
|
|
|
290
303
|
return cloneAndEnhance(options, result)
|
|
291
304
|
}
|
|
292
305
|
|
|
293
|
-
result.attrs = attrs as ExtendedConfiguration[
|
|
306
|
+
result.attrs = attrs as ExtendedConfiguration['attrs']
|
|
294
307
|
|
|
295
308
|
return cloneAndEnhance(options, result)
|
|
296
309
|
},
|
|
@@ -326,8 +339,8 @@ const rocketComponent: RocketComponent = (options) => {
|
|
|
326
339
|
{
|
|
327
340
|
render,
|
|
328
341
|
mode,
|
|
329
|
-
isDark: mode ===
|
|
330
|
-
isLight: mode ===
|
|
342
|
+
isDark: mode === 'light',
|
|
343
|
+
isLight: mode === 'dark',
|
|
331
344
|
},
|
|
332
345
|
]),
|
|
333
346
|
})
|
package/src/types/attrs.ts
CHANGED
package/src/types/config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { DimensionBooleanAttrs, Dimensions, ExtractDimensions, TDKP } from
|
|
2
|
-
import type { PseudoState } from
|
|
3
|
-
import type { ElementType, TObj } from
|
|
1
|
+
import type { DimensionBooleanAttrs, Dimensions, ExtractDimensions, TDKP } from './dimensions'
|
|
2
|
+
import type { PseudoState } from './pseudo'
|
|
3
|
+
import type { ElementType, TObj } from './utils'
|
|
4
4
|
|
|
5
5
|
// --------------------------------------------------------
|
|
6
6
|
// CONFIG
|
|
@@ -11,7 +11,7 @@ export type RocketComponentType = ElementType & {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type RocketProviderState<T extends RocketComponentType | TObj | unknown = unknown> =
|
|
14
|
-
T extends RocketComponentType ? Partial<T[
|
|
14
|
+
T extends RocketComponentType ? Partial<T['$$rocketstyle']> & { pseudo: PseudoState } : T
|
|
15
15
|
|
|
16
16
|
export type ConsumerCtxCBValue<
|
|
17
17
|
T extends RocketComponentType,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ConsumerCb } from
|
|
2
|
-
import type { Dimensions, MultiKeys } from
|
|
3
|
-
import type { PseudoProps } from
|
|
4
|
-
import type { StylesCbArray } from
|
|
5
|
-
import type { ArrayOfKeys, ArrayOfValues, ElementType, TFn } from
|
|
1
|
+
import type { ConsumerCb } from './config'
|
|
2
|
+
import type { Dimensions, MultiKeys } from './dimensions'
|
|
3
|
+
import type { PseudoProps } from './pseudo'
|
|
4
|
+
import type { StylesCbArray } from './styles'
|
|
5
|
+
import type { ArrayOfKeys, ArrayOfValues, ElementType, TFn } from './utils'
|
|
6
6
|
|
|
7
7
|
export type __ROCKETSTYLE__ = {
|
|
8
8
|
dimensions: Record<string, string>
|
package/src/types/dimensions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { DefaultDimensions } from
|
|
2
|
-
import type { Css } from
|
|
3
|
-
import type { ThemeModeCallback } from
|
|
4
|
-
import type { CallBackParam, NullableKeys, ReturnCbParam, Spread, TObj, ValueOf } from
|
|
1
|
+
import type { DefaultDimensions } from '../constants/defaultDimensions'
|
|
2
|
+
import type { Css } from './styles'
|
|
3
|
+
import type { ThemeModeCallback } from './theme'
|
|
4
|
+
import type { CallBackParam, NullableKeys, ReturnCbParam, Spread, TObj, ValueOf } from './utils'
|
|
5
5
|
|
|
6
6
|
export type { DefaultDimensions }
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ export type ExtractNullableDimensionKeys<T> = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export type ExtractDimensionKey<T extends DimensionValue> = T extends DimensionValueObj
|
|
13
|
-
? T[
|
|
13
|
+
? T['propName']
|
|
14
14
|
: T
|
|
15
15
|
|
|
16
16
|
export type ExtractDimensionMulti<T extends DimensionValue> = T extends DimensionValueObj
|
package/src/types/hoc.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Configuration } from
|
|
2
|
-
import type { DefaultDimensions, Dimensions } from
|
|
3
|
-
import type { RocketStyleComponent } from
|
|
4
|
-
import type { ElementType, ExtractProps, TObj } from
|
|
1
|
+
import type { Configuration } from './configuration'
|
|
2
|
+
import type { DefaultDimensions, Dimensions } from './dimensions'
|
|
3
|
+
import type { RocketStyleComponent } from './rocketstyle'
|
|
4
|
+
import type { ElementType, ExtractProps, TObj } from './utils'
|
|
5
5
|
|
|
6
6
|
export type RocketComponent<
|
|
7
7
|
C extends ElementType = ElementType,
|
package/src/types/rocketstyle.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { VNodeChild } from
|
|
2
|
-
import type { AttrsCb } from
|
|
3
|
-
import type { ConfigAttrs } from
|
|
4
|
-
import type { DefaultProps } from
|
|
1
|
+
import type { VNodeChild } from '@pyreon/core'
|
|
2
|
+
import type { AttrsCb } from './attrs'
|
|
3
|
+
import type { ConfigAttrs } from './config'
|
|
4
|
+
import type { DefaultProps } from './configuration'
|
|
5
5
|
import type {
|
|
6
6
|
DimensionCallbackParam,
|
|
7
7
|
DimensionProps,
|
|
@@ -11,14 +11,14 @@ import type {
|
|
|
11
11
|
ExtractDimensions,
|
|
12
12
|
MultiKeys,
|
|
13
13
|
TDKP,
|
|
14
|
-
} from
|
|
15
|
-
import type { ComposeParam } from
|
|
16
|
-
import type { Styles, StylesCb } from
|
|
17
|
-
import type { Theme, ThemeCb, ThemeModeKeys } from
|
|
18
|
-
import type { ElementType, ExtractProps, MergeTypes, TObj } from
|
|
14
|
+
} from './dimensions'
|
|
15
|
+
import type { ComposeParam } from './hoc'
|
|
16
|
+
import type { Styles, StylesCb } from './styles'
|
|
17
|
+
import type { Theme, ThemeCb, ThemeModeKeys } from './theme'
|
|
18
|
+
import type { ElementType, ExtractProps, MergeTypes, TObj } from './utils'
|
|
19
19
|
|
|
20
20
|
export type InnerComponentProps = {
|
|
21
|
-
|
|
21
|
+
'data-rocketstyle'?: string | undefined
|
|
22
22
|
} & Record<string, any>
|
|
23
23
|
|
|
24
24
|
export type RocketStyleComponent<
|
package/src/types/styles.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { config } from
|
|
2
|
-
import type { PseudoState } from
|
|
3
|
-
import type { TObj } from
|
|
1
|
+
import type { config } from '@pyreon/ui-core'
|
|
2
|
+
import type { PseudoState } from './pseudo'
|
|
3
|
+
import type { TObj } from './utils'
|
|
4
4
|
|
|
5
5
|
// biome-ignore lint/suspicious/noEmptyInterface: this is an interface to be extended in consuming projects
|
|
6
6
|
export interface StylesDefault {}
|
|
@@ -15,8 +15,13 @@ export type OptionStyles = ((css: Css) => ReturnType<Css>)[]
|
|
|
15
15
|
/**
|
|
16
16
|
* Props available inside `.styles()` interpolation functions.
|
|
17
17
|
*
|
|
18
|
-
* - `$rocketstyle` —
|
|
18
|
+
* - `$rocketstyle` — resolved theme object (the styled() runtime resolves
|
|
19
|
+
* the reactive accessor before calling interpolation functions)
|
|
19
20
|
* - `$rocketstate` — active dimension values + pseudo state
|
|
21
|
+
*
|
|
22
|
+
* Note: internally, rocketstyle passes $rocketstyle as a `() => CSS` accessor
|
|
23
|
+
* to DynamicStyled for reactive class swapping. But by the time interpolation
|
|
24
|
+
* functions run, it's always been resolved to a plain CSS object.
|
|
20
25
|
*/
|
|
21
26
|
export type RocketStyleInterpolationProps<CSS extends TObj = TObj> = {
|
|
22
27
|
$rocketstyle: CSS
|
package/src/types/theme.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { THEME_MODES } from
|
|
2
|
-
import type { Css } from
|
|
3
|
-
import type { MergeTypes } from
|
|
1
|
+
import type { THEME_MODES } from '../constants'
|
|
2
|
+
import type { Css } from './styles'
|
|
3
|
+
import type { MergeTypes } from './utils'
|
|
4
4
|
|
|
5
5
|
// biome-ignore lint/suspicious/noEmptyInterface: this is an interface to be extended in consuming projects
|
|
6
6
|
export interface ThemeDefault {}
|
|
@@ -12,7 +12,7 @@ export type ThemeModeKeys = keyof typeof THEME_MODES
|
|
|
12
12
|
export type ThemeModeCallback = <A = any, B = any>(
|
|
13
13
|
light: A,
|
|
14
14
|
dark: B,
|
|
15
|
-
) => (mode:
|
|
15
|
+
) => (mode: 'light' | 'dark') => A | B
|
|
16
16
|
|
|
17
17
|
export type ThemeMode = <A = any, B = any>(light: A, dark: B) => A | B
|
|
18
18
|
|
package/src/types/utils.ts
CHANGED
package/src/utils/attrs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MultiKeys } from
|
|
1
|
+
import type { MultiKeys } from '../types/dimensions'
|
|
2
2
|
|
|
3
3
|
// --------------------------------------------------------
|
|
4
4
|
// remove undefined props
|
|
@@ -91,7 +91,7 @@ export const calculateStylingAttrs: CalculateStylingAttrs =
|
|
|
91
91
|
}
|
|
92
92
|
// assign when it's only a string or number otherwise it's considered
|
|
93
93
|
// as invalid param
|
|
94
|
-
else if (t ===
|
|
94
|
+
else if (t === 'string' || t === 'number') {
|
|
95
95
|
result[item] = pickedProp
|
|
96
96
|
} else {
|
|
97
97
|
result[item] = undefined
|
package/src/utils/chaining.ts
CHANGED
|
@@ -13,8 +13,8 @@ type ChainOptions = (opts: Obj | Func | undefined, defaultOpts: Func[]) => Func[
|
|
|
13
13
|
export const chainOptions: ChainOptions = (opts, defaultOpts = []) => {
|
|
14
14
|
const result = [...defaultOpts]
|
|
15
15
|
|
|
16
|
-
if (typeof opts ===
|
|
17
|
-
else if (typeof opts ===
|
|
16
|
+
if (typeof opts === 'function') result.push(opts)
|
|
17
|
+
else if (typeof opts === 'object') result.push(() => opts)
|
|
18
18
|
|
|
19
19
|
return result
|
|
20
20
|
}
|
package/src/utils/compose.ts
CHANGED
|
@@ -7,5 +7,5 @@ type CalculateHocsFuncs = (options: Record<string, any>) => ((arg: any) => any)[
|
|
|
7
7
|
|
|
8
8
|
export const calculateHocsFuncs: CalculateHocsFuncs = (options = {}) =>
|
|
9
9
|
Object.values(options)
|
|
10
|
-
.filter((item) => typeof item ===
|
|
10
|
+
.filter((item) => typeof item === 'function')
|
|
11
11
|
.reverse()
|
package/src/utils/dimensions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { get, isEmpty, set } from
|
|
2
|
-
import type { Dimensions, DimensionValue, MultiKeys } from
|
|
1
|
+
import { get, isEmpty, set } from '@pyreon/ui-core'
|
|
2
|
+
import type { Dimensions, DimensionValue, MultiKeys } from '../types/dimensions'
|
|
3
3
|
|
|
4
4
|
// --------------------------------------------------------
|
|
5
5
|
// Is value a valid key
|
|
@@ -15,7 +15,7 @@ export const isValidKey: IsValidKey = (value) =>
|
|
|
15
15
|
/** Determines if a dimension value is a multi-key config object, returning [isMulti, propName]. */
|
|
16
16
|
type IsMultiKey = (value: string | Record<string, unknown>) => [boolean, string]
|
|
17
17
|
export const isMultiKey: IsMultiKey = (value) => {
|
|
18
|
-
if (typeof value ===
|
|
18
|
+
if (typeof value === 'object' && value !== null) return [true, get(value, 'propName') as string]
|
|
19
19
|
return [false, value]
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -81,7 +81,7 @@ type GetDimensionsValues = <T extends Dimensions, K extends keyof T>(obj: T) =>
|
|
|
81
81
|
|
|
82
82
|
export const getDimensionsValues = (<T extends Dimensions>(obj: T) =>
|
|
83
83
|
getValues(obj).map((item: DimensionValue) => {
|
|
84
|
-
if (typeof item ===
|
|
84
|
+
if (typeof item === 'object') {
|
|
85
85
|
return item.propName as string
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -97,7 +97,7 @@ type GetMultipleDimensions = <T extends Dimensions>(obj: T) => MultiKeys<T>
|
|
|
97
97
|
export const getMultipleDimensions: GetMultipleDimensions = (obj) =>
|
|
98
98
|
getValues(obj).reduce(
|
|
99
99
|
(accumulator, value: DimensionValue) => {
|
|
100
|
-
if (typeof value ===
|
|
100
|
+
if (typeof value === 'object') {
|
|
101
101
|
if (value.multi === true) accumulator[value.propName] = true
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -116,7 +116,7 @@ type GetTransformDimensions = <T extends Dimensions>(obj: T) => TransformKeys
|
|
|
116
116
|
export const getTransformDimensions: GetTransformDimensions = (obj) =>
|
|
117
117
|
getValues(obj).reduce(
|
|
118
118
|
(accumulator, value: DimensionValue) => {
|
|
119
|
-
if (typeof value ===
|
|
119
|
+
if (typeof value === 'object') {
|
|
120
120
|
if (value.transform === true) accumulator[value.propName] = true
|
|
121
121
|
}
|
|
122
122
|
|
package/src/utils/statics.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isEmpty } from
|
|
2
|
-
import { STATIC_KEYS } from
|
|
1
|
+
import { isEmpty } from '@pyreon/ui-core'
|
|
2
|
+
import { STATIC_KEYS } from '../constants'
|
|
3
3
|
|
|
4
4
|
// --------------------------------------------------------
|
|
5
5
|
// helpers for create statics chaining methods on component
|
package/src/utils/styles.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { config } from
|
|
2
|
-
import type { StylesCbArray } from
|
|
1
|
+
import { config } from '@pyreon/ui-core'
|
|
2
|
+
import type { StylesCbArray } from '../types/styles'
|
|
3
3
|
|
|
4
4
|
// --------------------------------------------------------
|
|
5
5
|
// Calculate styles
|
package/src/utils/theme.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { config, isEmpty, merge } from
|
|
2
|
-
import type { ThemeModeCallback } from
|
|
3
|
-
import { removeNullableValues } from
|
|
4
|
-
import { isMultiKey } from
|
|
1
|
+
import { config, isEmpty, merge } from '@pyreon/ui-core'
|
|
2
|
+
import type { ThemeModeCallback } from '../types/theme'
|
|
3
|
+
import { removeNullableValues } from './collection'
|
|
4
|
+
import { isMultiKey } from './dimensions'
|
|
5
5
|
|
|
6
6
|
// --------------------------------------------------------
|
|
7
7
|
// Theme Mode Callback
|
|
8
8
|
// --------------------------------------------------------
|
|
9
|
-
const MODE_CALLBACK_BRAND = Symbol.for(
|
|
9
|
+
const MODE_CALLBACK_BRAND = Symbol.for('pyreon.themeModeCallback')
|
|
10
10
|
|
|
11
11
|
/** Creates a mode-switching function that returns the light or dark value based on the active mode. */
|
|
12
12
|
export const themeModeCallback: ThemeModeCallback = (light, dark) => {
|
|
13
13
|
const fn = (mode: string) => {
|
|
14
|
-
if (!mode || mode ===
|
|
14
|
+
if (!mode || mode === 'light') return light
|
|
15
15
|
return dark
|
|
16
16
|
}
|
|
17
17
|
;(fn as unknown as Record<string, unknown>).__brand = MODE_CALLBACK_BRAND
|
|
@@ -24,7 +24,7 @@ export const themeModeCallback: ThemeModeCallback = (light, dark) => {
|
|
|
24
24
|
/** Detects whether a value is a `themeModeCallback` function via Symbol brand. */
|
|
25
25
|
type IsModeCallback = (value: unknown) => boolean
|
|
26
26
|
const isModeCallback: IsModeCallback = (value: unknown) =>
|
|
27
|
-
typeof value ===
|
|
27
|
+
typeof value === 'function' &&
|
|
28
28
|
(value as unknown as Record<string, unknown>).__brand === MODE_CALLBACK_BRAND
|
|
29
29
|
|
|
30
30
|
// --------------------------------------------------------
|
|
@@ -136,7 +136,7 @@ export const getTheme: GetTheme = ({ rocketstate, themes, baseTheme, transformKe
|
|
|
136
136
|
|
|
137
137
|
const mergeValue = (item: string) => {
|
|
138
138
|
const val = keyTheme[item]
|
|
139
|
-
if (isTransform && typeof val ===
|
|
139
|
+
if (isTransform && typeof val === 'function') {
|
|
140
140
|
deferredTransforms.push(val)
|
|
141
141
|
} else {
|
|
142
142
|
finalTheme = merge({}, finalTheme, val)
|
|
@@ -171,7 +171,7 @@ export const getTheme: GetTheme = ({ rocketstate, themes, baseTheme, transformKe
|
|
|
171
171
|
*/
|
|
172
172
|
export type GetThemeByMode = (
|
|
173
173
|
object: Record<string, any>,
|
|
174
|
-
mode:
|
|
174
|
+
mode: 'light' | 'dark',
|
|
175
175
|
) => Partial<{
|
|
176
176
|
baseTheme: Record<string, unknown>
|
|
177
177
|
themes: Record<string, unknown>
|
|
@@ -182,7 +182,7 @@ export const getThemeByMode: GetThemeByMode = (object, mode) =>
|
|
|
182
182
|
(acc, key) => {
|
|
183
183
|
const value = object[key]
|
|
184
184
|
|
|
185
|
-
if (typeof value ===
|
|
185
|
+
if (typeof value === 'object' && value !== null) {
|
|
186
186
|
acc[key] = getThemeByMode(value, mode)
|
|
187
187
|
} else if (isModeCallback(value)) {
|
|
188
188
|
acc[key] = value(mode)
|