@vitus-labs/rocketstyle 1.4.2 → 1.4.3-alpha.1
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/lib/index.d.ts +43 -23
- package/lib/index.js +20 -13
- package/package.json +6 -5
package/lib/index.d.ts
CHANGED
|
@@ -38,6 +38,25 @@ declare const DEFAULT_DIMENSIONS: {
|
|
|
38
38
|
};
|
|
39
39
|
type DefaultDimensions = typeof DEFAULT_DIMENSIONS;
|
|
40
40
|
//#endregion
|
|
41
|
+
//#region src/types/pseudo.d.ts
|
|
42
|
+
type PseudoActions = {
|
|
43
|
+
onMouseEnter: MouseEventHandler;
|
|
44
|
+
onMouseLeave: MouseEventHandler;
|
|
45
|
+
onMouseDown: MouseEventHandler;
|
|
46
|
+
onMouseUp: MouseEventHandler;
|
|
47
|
+
onFocus: FocusEventHandler;
|
|
48
|
+
onBlur: FocusEventHandler;
|
|
49
|
+
};
|
|
50
|
+
type PseudoState = {
|
|
51
|
+
active: boolean;
|
|
52
|
+
hover: boolean;
|
|
53
|
+
focus: boolean;
|
|
54
|
+
pressed: boolean;
|
|
55
|
+
disabled: boolean;
|
|
56
|
+
readOnly: boolean;
|
|
57
|
+
};
|
|
58
|
+
type PseudoProps = Partial<PseudoState & PseudoActions>;
|
|
59
|
+
//#endregion
|
|
41
60
|
//#region src/types/utils.d.ts
|
|
42
61
|
type TObj = Record<string, unknown>;
|
|
43
62
|
type TFn = (...args: any) => any;
|
|
@@ -65,7 +84,27 @@ type ExtractProps<TComponentOrTProps> = TComponentOrTProps extends ComponentType
|
|
|
65
84
|
interface StylesDefault {}
|
|
66
85
|
type Styles<S> = S extends unknown ? StylesDefault : MergeTypes<[StylesDefault, S]>;
|
|
67
86
|
type Css = typeof config.css;
|
|
68
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Props available inside `.styles()` interpolation functions.
|
|
89
|
+
*
|
|
90
|
+
* - `$rocketstyle` — computed theme (inferred from `.theme()` chain)
|
|
91
|
+
* - `$rocketstate` — active dimension values + pseudo state
|
|
92
|
+
*/
|
|
93
|
+
type RocketStyleInterpolationProps<CSS extends TObj = TObj> = {
|
|
94
|
+
$rocketstyle: CSS;
|
|
95
|
+
$rocketstate: Record<string, string | string[]> & {
|
|
96
|
+
pseudo: Partial<PseudoState>;
|
|
97
|
+
};
|
|
98
|
+
} & Record<string, any>;
|
|
99
|
+
/**
|
|
100
|
+
* A tagged-template css function whose interpolation functions
|
|
101
|
+
* receive typed props including `$rocketstyle` and `$rocketstate`.
|
|
102
|
+
*
|
|
103
|
+
* When used via `.styles()`, `CSS` is inferred from the chain's
|
|
104
|
+
* accumulated `.theme()` calls, so both props are typed automatically.
|
|
105
|
+
*/
|
|
106
|
+
type RocketCss<CSS extends TObj = TObj> = (strings: TemplateStringsArray, ...values: Array<string | number | boolean | null | undefined | ((props: RocketStyleInterpolationProps<CSS>) => any) | any[]>) => any;
|
|
107
|
+
type StylesCb<CSS extends TObj = TObj> = (css: RocketCss<CSS>) => ReturnType<Css>;
|
|
69
108
|
type StylesCbArray = StylesCb[];
|
|
70
109
|
//#endregion
|
|
71
110
|
//#region src/constants/index.d.ts
|
|
@@ -107,25 +146,6 @@ type DimensionBooleanAttrs<DKP extends TDKP> = Partial<Record<ValueOf<DimensionT
|
|
|
107
146
|
type ExtractDimensionProps<D extends Dimensions, DKP extends TDKP, UB extends boolean> = UB extends true ? Partial<ExtractNullableDimensionKeys<DimensionObjAttrs<D, DKP> & DimensionBooleanAttrs<DKP>>> : Partial<ExtractNullableDimensionKeys<DimensionObjAttrs<D, DKP>>>;
|
|
108
147
|
type ExtractDimensions<D extends Dimensions, DKP extends TDKP> = ExtractNullableDimensionKeys<DimensionObjAttrs<D, DKP>>;
|
|
109
148
|
//#endregion
|
|
110
|
-
//#region src/types/pseudo.d.ts
|
|
111
|
-
type PseudoActions = {
|
|
112
|
-
onMouseEnter: MouseEventHandler;
|
|
113
|
-
onMouseLeave: MouseEventHandler;
|
|
114
|
-
onMouseDown: MouseEventHandler;
|
|
115
|
-
onMouseUp: MouseEventHandler;
|
|
116
|
-
onFocus: FocusEventHandler;
|
|
117
|
-
onBlur: FocusEventHandler;
|
|
118
|
-
};
|
|
119
|
-
type PseudoState = {
|
|
120
|
-
active: boolean;
|
|
121
|
-
hover: boolean;
|
|
122
|
-
focus: boolean;
|
|
123
|
-
pressed: boolean;
|
|
124
|
-
disabled: boolean;
|
|
125
|
-
readOnly: boolean;
|
|
126
|
-
};
|
|
127
|
-
type PseudoProps = Partial<PseudoState & PseudoActions>;
|
|
128
|
-
//#endregion
|
|
129
149
|
//#region src/types/config.d.ts
|
|
130
150
|
type RocketComponentType = ElementType & {
|
|
131
151
|
IS_ROCKETSTYLE: true;
|
|
@@ -345,7 +365,7 @@ interface IRocketStyleComponent<OA extends TObj = {}, EA extends TObj = {}, T ex
|
|
|
345
365
|
* }))
|
|
346
366
|
* ```
|
|
347
367
|
*/
|
|
348
|
-
theme: <P extends TObj
|
|
368
|
+
theme: <P extends TObj = {}>(param: Partial<P> | ThemeCb<P, Theme<T>>) => RocketStyleComponent<OA, EA, T, MergeTypes<[CSS, P]>, S, HOC, D, UB, DKP>;
|
|
349
369
|
/**
|
|
350
370
|
* A chaining method to define default rendered styles
|
|
351
371
|
* @param param Callback of styled-components `css` function
|
|
@@ -358,7 +378,7 @@ interface IRocketStyleComponent<OA extends TObj = {}, EA extends TObj = {}, T ex
|
|
|
358
378
|
* const newElement = base.styles(css => css``)
|
|
359
379
|
* ```
|
|
360
380
|
*/
|
|
361
|
-
styles: (param: StylesCb) => RocketStyleComponent<OA, EA, T, CSS, S, HOC, D, UB, DKP>;
|
|
381
|
+
styles: (param: StylesCb<CSS>) => RocketStyleComponent<OA, EA, T, CSS, S, HOC, D, UB, DKP>;
|
|
362
382
|
/**
|
|
363
383
|
* A chaining method to define high-order components to wrap
|
|
364
384
|
* the defined component
|
|
@@ -553,5 +573,5 @@ declare const rocketstyle: Rocketstyle;
|
|
|
553
573
|
type IsRocketComponent = <T>(component: T) => boolean;
|
|
554
574
|
declare const isRocketComponent: IsRocketComponent;
|
|
555
575
|
//#endregion
|
|
556
|
-
export { type AttrsCb, type ComposeParam, type ConfigAttrs, type ConsumerCb, type ConsumerCtxCBValue, type ConsumerCtxCb, type DefaultProps, type DimensionCallbackParam, type DimensionProps, type DimensionValue, type Dimensions, type ElementType, type ExtractDimensionProps, type ExtractDimensions, type ExtractProps, type GenericHoc, type IRocketStyleComponent, type IsRocketComponent, type MergeTypes, Provider, type RocketComponentType, type RocketProviderState, type RocketStyleComponent, type Rocketstyle, type StylesCb, type StylesDefault, type TDKP, type TObj, type TProvider, type ThemeCb, type ThemeDefault, type ThemeMode, type ThemeModeCallback, type ThemeModeKeys, context, rocketstyle as default, rocketstyle, isRocketComponent };
|
|
576
|
+
export { type AttrsCb, type ComposeParam, type ConfigAttrs, type ConsumerCb, type ConsumerCtxCBValue, type ConsumerCtxCb, type DefaultProps, type DimensionCallbackParam, type DimensionProps, type DimensionValue, type Dimensions, type ElementType, type ExtractDimensionProps, type ExtractDimensions, type ExtractProps, type GenericHoc, type IRocketStyleComponent, type IsRocketComponent, type MergeTypes, Provider, type RocketComponentType, type RocketProviderState, type RocketStyleComponent, type RocketStyleInterpolationProps, type Rocketstyle, type StylesCb, type StylesDefault, type TDKP, type TObj, type TProvider, type ThemeCb, type ThemeDefault, type ThemeMode, type ThemeModeCallback, type ThemeModeKeys, context, rocketstyle as default, rocketstyle, isRocketComponent };
|
|
557
577
|
//# sourceMappingURL=index2.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -259,14 +259,11 @@ const RocketStyleProviderComponent = (WrappedComponent) => forwardRef(({ onMouse
|
|
|
259
259
|
|
|
260
260
|
//#endregion
|
|
261
261
|
//#region src/utils/attrs.ts
|
|
262
|
-
const removeUndefinedProps = (props) =>
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
};
|
|
268
|
-
return acc;
|
|
269
|
-
}, {});
|
|
262
|
+
const removeUndefinedProps = (props) => {
|
|
263
|
+
const result = {};
|
|
264
|
+
for (const key in props) if (props[key] !== void 0) result[key] = props[key];
|
|
265
|
+
return result;
|
|
266
|
+
};
|
|
270
267
|
const pickStyledAttrs = (props, keywords) => Object.keys(props).reduce((acc, key) => {
|
|
271
268
|
if (keywords[key] && props[key]) acc[key] = props[key];
|
|
272
269
|
return acc;
|
|
@@ -280,9 +277,9 @@ const calculateStylingAttrs = ({ useBooleans, multiKeys }) => ({ props, dimensio
|
|
|
280
277
|
const result = {};
|
|
281
278
|
Object.keys(dimensions).forEach((item) => {
|
|
282
279
|
const pickedProp = props[item];
|
|
283
|
-
const
|
|
280
|
+
const t = typeof pickedProp;
|
|
284
281
|
if (multiKeys?.[item] && Array.isArray(pickedProp)) result[item] = pickedProp;
|
|
285
|
-
else if (
|
|
282
|
+
else if (t === "string" || t === "number") result[item] = pickedProp;
|
|
286
283
|
else result[item] = void 0;
|
|
287
284
|
});
|
|
288
285
|
if (useBooleans) {
|
|
@@ -496,7 +493,7 @@ const rocketComponent = (options) => {
|
|
|
496
493
|
useBooleans: options.useBooleans
|
|
497
494
|
});
|
|
498
495
|
const componentName = options.name ?? options.component.displayName ?? options.component.name;
|
|
499
|
-
const STYLED_COMPONENT = component.IS_ROCKETSTYLE ?? options.styled !== true ? component : styled(component)`
|
|
496
|
+
const STYLED_COMPONENT = component.IS_ROCKETSTYLE ?? options.styled !== true ? component : styled(component, { boost: true })`
|
|
500
497
|
${calculateStyles(styles)};
|
|
501
498
|
`;
|
|
502
499
|
const RenderComponent = options.provider ? RocketStyleProviderComponent(STYLED_COMPONENT) : STYLED_COMPONENT;
|
|
@@ -550,11 +547,21 @@ const rocketComponent = (options) => {
|
|
|
550
547
|
...rocketstate,
|
|
551
548
|
pseudo: pseudoRocketstate
|
|
552
549
|
};
|
|
553
|
-
|
|
550
|
+
let rsKey = "";
|
|
551
|
+
for (const k in rocketstate) {
|
|
552
|
+
const v = rocketstate[k];
|
|
553
|
+
rsKey += k;
|
|
554
|
+
rsKey += Array.isArray(v) ? v.join(",") : v;
|
|
555
|
+
}
|
|
556
|
+
const rocketstyle = useMemo(() => getTheme({
|
|
554
557
|
rocketstate,
|
|
555
558
|
themes: currentModeThemes,
|
|
556
559
|
baseTheme: currentModeBaseTheme
|
|
557
|
-
})
|
|
560
|
+
}), [
|
|
561
|
+
rsKey,
|
|
562
|
+
currentModeThemes,
|
|
563
|
+
currentModeBaseTheme
|
|
564
|
+
]);
|
|
558
565
|
const finalProps = {
|
|
559
566
|
...omit(mergeProps, [
|
|
560
567
|
...RESERVED_STYLING_PROPS_KEYS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/rocketstyle",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3-alpha.1+cf4e0a6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Vit Bokisch <vit@bokisch.cz>",
|
|
6
6
|
"maintainers": [
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"sideEffects": false,
|
|
11
11
|
"exports": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
12
13
|
"import": "./lib/index.js",
|
|
13
14
|
"types": "./lib/index.d.ts"
|
|
14
15
|
},
|
|
@@ -66,12 +67,12 @@
|
|
|
66
67
|
"react": ">= 19"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@vitus-labs/core": "1.4.
|
|
70
|
-
"@vitus-labs/elements": "1.4.
|
|
70
|
+
"@vitus-labs/core": "1.4.3-alpha.1+cf4e0a6",
|
|
71
|
+
"@vitus-labs/elements": "1.4.3-alpha.1+cf4e0a6",
|
|
71
72
|
"@vitus-labs/tools-rolldown": "^1.6.0",
|
|
72
73
|
"@vitus-labs/tools-storybook": "^1.6.0",
|
|
73
74
|
"@vitus-labs/tools-typescript": "^1.6.0",
|
|
74
|
-
"@vitus-labs/unistyle": "1.4.
|
|
75
|
+
"@vitus-labs/unistyle": "1.4.3-alpha.1+cf4e0a6"
|
|
75
76
|
},
|
|
76
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "cf4e0a6230687c5c7acc2e07a3248bae4ae55f07"
|
|
77
78
|
}
|