@vitus-labs/unistyle 2.0.0-alpha.8 → 2.0.0-beta.0
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 +6 -1
- package/lib/index.d.ts +0 -10
- package/lib/index.js +22 -12
- package/lib/vitus-labs-unistyle.native.js +22 -12
- package/package.json +18 -9
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vitus-labs/unistyle
|
|
2
2
|
|
|
3
|
-
Responsive CSS engine for React
|
|
3
|
+
Responsive CSS engine for React.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@vitus-labs/unistyle)
|
|
6
6
|
[](https://github.com/vitus-labs/ui-system/blob/main/LICENSE)
|
|
@@ -186,12 +186,17 @@ Every property in the theme object supports three formats:
|
|
|
186
186
|
|
|
187
187
|
When using `normalize: true` (default), missing breakpoints inherit from the previous one.
|
|
188
188
|
|
|
189
|
+
## React Native
|
|
190
|
+
|
|
191
|
+
On React Native, CSS `@media` queries are not available. When initialized with `@vitus-labs/connector-native`, unistyle uses `Dimensions.get('window').width` to evaluate breakpoints at render time (mobile-first). This is handled automatically via `createMediaQueries` passed to `init()`.
|
|
192
|
+
|
|
189
193
|
## Peer Dependencies
|
|
190
194
|
|
|
191
195
|
| Package | Version |
|
|
192
196
|
| ------- | ------- |
|
|
193
197
|
| react | >= 19 |
|
|
194
198
|
| @vitus-labs/core | * |
|
|
199
|
+
| react-native | >= 0.76 (optional) |
|
|
195
200
|
|
|
196
201
|
## License
|
|
197
202
|
|
package/lib/index.d.ts
CHANGED
|
@@ -98,16 +98,6 @@ type MakeItResponsive = ({
|
|
|
98
98
|
theme?: Theme$1;
|
|
99
99
|
[key: string]: any;
|
|
100
100
|
}) => any;
|
|
101
|
-
/**
|
|
102
|
-
* Core responsive engine used by every styled component in the system.
|
|
103
|
-
*
|
|
104
|
-
* Returns a styled-components interpolation function that:
|
|
105
|
-
* 1. Reads the component's theme prop (via `key` or direct `theme`)
|
|
106
|
-
* 2. Without breakpoints → renders plain CSS
|
|
107
|
-
* 3. With breakpoints → normalizes, transforms (property-per-breakpoint →
|
|
108
|
-
* breakpoint-per-property), optimizes (deduplicates identical breakpoints),
|
|
109
|
-
* and wraps each breakpoint's styles in the appropriate `@media` query.
|
|
110
|
-
*/
|
|
111
101
|
declare const makeItResponsive: MakeItResponsive;
|
|
112
102
|
//#endregion
|
|
113
103
|
//#region src/responsive/normalizeTheme.d.ts
|
package/lib/index.js
CHANGED
|
@@ -154,6 +154,7 @@ const transformTheme = ({ theme, breakpoints }) => {
|
|
|
154
154
|
* breakpoint-per-property), optimizes (deduplicates identical breakpoints),
|
|
155
155
|
* and wraps each breakpoint's styles in the appropriate `@media` query.
|
|
156
156
|
*/
|
|
157
|
+
const themeCache = /* @__PURE__ */ new WeakMap();
|
|
157
158
|
const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize = true }) => ({ theme = {}, ...props }) => {
|
|
158
159
|
const internalTheme = customTheme || props[key];
|
|
159
160
|
if (isEmpty(internalTheme)) return "";
|
|
@@ -168,18 +169,27 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
|
|
|
168
169
|
${renderStyles(internalTheme)}
|
|
169
170
|
`;
|
|
170
171
|
const { media, sortedBreakpoints } = __VITUS_LABS__;
|
|
171
|
-
let
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
theme: helperTheme,
|
|
172
|
+
let optimizedTheme;
|
|
173
|
+
const cached = themeCache.get(internalTheme);
|
|
174
|
+
if (cached && cached.breakpoints === sortedBreakpoints) optimizedTheme = cached.optimized;
|
|
175
|
+
else {
|
|
176
|
+
let helperTheme = internalTheme;
|
|
177
|
+
if (normalize) helperTheme = normalizeTheme({
|
|
178
|
+
theme: internalTheme,
|
|
179
179
|
breakpoints: sortedBreakpoints
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
});
|
|
181
|
+
optimizedTheme = optimizeTheme({
|
|
182
|
+
theme: transformTheme({
|
|
183
|
+
theme: helperTheme,
|
|
184
|
+
breakpoints: sortedBreakpoints
|
|
185
|
+
}),
|
|
186
|
+
breakpoints: sortedBreakpoints
|
|
187
|
+
});
|
|
188
|
+
themeCache.set(internalTheme, {
|
|
189
|
+
breakpoints: sortedBreakpoints,
|
|
190
|
+
optimized: optimizedTheme
|
|
191
|
+
});
|
|
192
|
+
}
|
|
183
193
|
return sortedBreakpoints.map((item) => {
|
|
184
194
|
const breakpointTheme = optimizedTheme[item];
|
|
185
195
|
if (!breakpointTheme || !media) return "";
|
|
@@ -210,7 +220,7 @@ const Provider = ({ theme, children, ...props }) => {
|
|
|
210
220
|
if (breakpoints && !isEmpty(breakpoints)) return sortBreakpoints(breakpoints);
|
|
211
221
|
}, [breakpoints]);
|
|
212
222
|
const media = useMemo(() => {
|
|
213
|
-
if (breakpoints && !isEmpty(breakpoints)) return createMediaQueries({
|
|
223
|
+
if (breakpoints && !isEmpty(breakpoints)) return (config.createMediaQueries ?? createMediaQueries)({
|
|
214
224
|
breakpoints,
|
|
215
225
|
css: config.css,
|
|
216
226
|
rootSize
|
|
@@ -154,6 +154,7 @@ const transformTheme = ({ theme, breakpoints }) => {
|
|
|
154
154
|
* breakpoint-per-property), optimizes (deduplicates identical breakpoints),
|
|
155
155
|
* and wraps each breakpoint's styles in the appropriate `@media` query.
|
|
156
156
|
*/
|
|
157
|
+
const themeCache = /* @__PURE__ */ new WeakMap();
|
|
157
158
|
const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize = true }) => ({ theme = {}, ...props }) => {
|
|
158
159
|
const internalTheme = customTheme || props[key];
|
|
159
160
|
if (isEmpty(internalTheme)) return "";
|
|
@@ -168,18 +169,27 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
|
|
|
168
169
|
${renderStyles(internalTheme)}
|
|
169
170
|
`;
|
|
170
171
|
const { media, sortedBreakpoints } = __VITUS_LABS__;
|
|
171
|
-
let
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
theme: helperTheme,
|
|
172
|
+
let optimizedTheme;
|
|
173
|
+
const cached = themeCache.get(internalTheme);
|
|
174
|
+
if (cached && cached.breakpoints === sortedBreakpoints) optimizedTheme = cached.optimized;
|
|
175
|
+
else {
|
|
176
|
+
let helperTheme = internalTheme;
|
|
177
|
+
if (normalize) helperTheme = normalizeTheme({
|
|
178
|
+
theme: internalTheme,
|
|
179
179
|
breakpoints: sortedBreakpoints
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
});
|
|
181
|
+
optimizedTheme = optimizeTheme({
|
|
182
|
+
theme: transformTheme({
|
|
183
|
+
theme: helperTheme,
|
|
184
|
+
breakpoints: sortedBreakpoints
|
|
185
|
+
}),
|
|
186
|
+
breakpoints: sortedBreakpoints
|
|
187
|
+
});
|
|
188
|
+
themeCache.set(internalTheme, {
|
|
189
|
+
breakpoints: sortedBreakpoints,
|
|
190
|
+
optimized: optimizedTheme
|
|
191
|
+
});
|
|
192
|
+
}
|
|
183
193
|
return sortedBreakpoints.map((item) => {
|
|
184
194
|
const breakpointTheme = optimizedTheme[item];
|
|
185
195
|
if (!breakpointTheme || !media) return "";
|
|
@@ -210,7 +220,7 @@ const Provider = ({ theme, children, ...props }) => {
|
|
|
210
220
|
if (breakpoints && !isEmpty(breakpoints)) return sortBreakpoints(breakpoints);
|
|
211
221
|
}, [breakpoints]);
|
|
212
222
|
const media = useMemo(() => {
|
|
213
|
-
if (breakpoints && !isEmpty(breakpoints)) return createMediaQueries({
|
|
223
|
+
if (breakpoints && !isEmpty(breakpoints)) return (config.createMediaQueries ?? createMediaQueries)({
|
|
214
224
|
breakpoints,
|
|
215
225
|
css: config.css,
|
|
216
226
|
rootSize
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/unistyle",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Vit Bokisch <vit@bokisch.cz>",
|
|
6
6
|
"maintainers": [
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"sideEffects": false,
|
|
11
11
|
"exports": {
|
|
12
12
|
"source": "./src/index.ts",
|
|
13
|
+
"react-native": "./lib/vitus-labs-unistyle.native.js",
|
|
13
14
|
"import": "./lib/index.js",
|
|
14
15
|
"types": "./lib/index.d.ts"
|
|
15
16
|
},
|
|
16
17
|
"types": "./lib/index.d.ts",
|
|
17
|
-
"react-native": "lib/vitus-labs-unistyle.native.js",
|
|
18
|
+
"react-native": "./lib/vitus-labs-unistyle.native.js",
|
|
19
|
+
"main": "./lib/index.js",
|
|
18
20
|
"files": [
|
|
19
21
|
"lib",
|
|
20
22
|
"!lib/**/*.map",
|
|
@@ -31,7 +33,8 @@
|
|
|
31
33
|
"test:coverage": "vitest run --coverage",
|
|
32
34
|
"test:watch": "vitest",
|
|
33
35
|
"cover": "coveralls < .coverage/lcov.info",
|
|
34
|
-
"typecheck": "tsc --noEmit"
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"version": "node ../../scripts/sync-peer-deps.mjs"
|
|
35
38
|
},
|
|
36
39
|
"publishConfig": {
|
|
37
40
|
"access": "public"
|
|
@@ -48,13 +51,19 @@
|
|
|
48
51
|
"node": ">= 18"
|
|
49
52
|
},
|
|
50
53
|
"peerDependencies": {
|
|
51
|
-
"@vitus-labs/core": "
|
|
52
|
-
"react": ">= 19"
|
|
54
|
+
"@vitus-labs/core": "2.0.0-alpha.27",
|
|
55
|
+
"react": ">= 19",
|
|
56
|
+
"react-native": ">= 0.76"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"react-native": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
53
62
|
},
|
|
54
63
|
"devDependencies": {
|
|
55
|
-
"@vitus-labs/core": "2.0.0-
|
|
56
|
-
"@vitus-labs/tools-rolldown": "
|
|
57
|
-
"@vitus-labs/tools-typescript": "
|
|
64
|
+
"@vitus-labs/core": "2.0.0-beta.0",
|
|
65
|
+
"@vitus-labs/tools-rolldown": "1.10.0",
|
|
66
|
+
"@vitus-labs/tools-typescript": "1.10.0"
|
|
58
67
|
},
|
|
59
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "dd8b9f356086ecd8bfb69c87fcad1e8bfa9ab1f4"
|
|
60
69
|
}
|