@vitus-labs/unistyle 2.6.1 → 2.6.2
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.js +40 -26
- package/lib/vitus-labs-unistyle.native.js +40 -26
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -23,19 +23,22 @@ const breakpoints = {
|
|
|
23
23
|
* Others are wrapped in `@media (min-width: <em>)` — em units
|
|
24
24
|
* ensure correct behaviour when users change browser font size.
|
|
25
25
|
*/
|
|
26
|
-
const createMediaQueries = ({ breakpoints, rootSize, css }) =>
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const createMediaQueries = ({ breakpoints, rootSize, css }) => {
|
|
27
|
+
const acc = {};
|
|
28
|
+
for (const key in breakpoints) {
|
|
29
|
+
const breakpointValue = breakpoints[key];
|
|
30
|
+
if (breakpointValue === 0) acc[key] = (...args) => css(...args);
|
|
31
|
+
else if (breakpointValue != null) {
|
|
32
|
+
const emSize = breakpointValue / rootSize;
|
|
33
|
+
acc[key] = (...args) => css`
|
|
32
34
|
@media only screen and (min-width: ${emSize}em) {
|
|
33
35
|
${css(...args)};
|
|
34
36
|
}
|
|
35
37
|
`;
|
|
38
|
+
}
|
|
36
39
|
}
|
|
37
40
|
return acc;
|
|
38
|
-
}
|
|
41
|
+
};
|
|
39
42
|
|
|
40
43
|
//#endregion
|
|
41
44
|
//#region src/responsive/normalizeTheme.ts
|
|
@@ -59,7 +62,13 @@ const handleObjectCb = (obj) => (bp, i, bps, res) => {
|
|
|
59
62
|
return previousValue;
|
|
60
63
|
};
|
|
61
64
|
const handleValueCb = (value) => () => value;
|
|
62
|
-
const shouldNormalize = (props) =>
|
|
65
|
+
const shouldNormalize = (props) => {
|
|
66
|
+
for (const key in props) {
|
|
67
|
+
const item = props[key];
|
|
68
|
+
if (typeof item === "object" || Array.isArray(item)) return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
};
|
|
63
72
|
/**
|
|
64
73
|
* Expands each theme property into a full breakpoint map so every
|
|
65
74
|
* breakpoint has a value. Arrays fill by index (last value carries forward),
|
|
@@ -70,12 +79,13 @@ const normalizeTheme = ({ theme, breakpoints }) => {
|
|
|
70
79
|
if (!shouldNormalize(theme)) return theme;
|
|
71
80
|
const getBpValues = assignToBreakpointKey(breakpoints);
|
|
72
81
|
const result = {};
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
for (const key in theme) {
|
|
83
|
+
const value = theme[key];
|
|
84
|
+
if (value == null) continue;
|
|
75
85
|
if (Array.isArray(value)) result[key] = getBpValues(handleArrayCb(value));
|
|
76
86
|
else if (typeof value === "object") result[key] = getBpValues(handleObjectCb(value));
|
|
77
87
|
else result[key] = getBpValues(handleValueCb(value));
|
|
78
|
-
}
|
|
88
|
+
}
|
|
79
89
|
return result;
|
|
80
90
|
};
|
|
81
91
|
|
|
@@ -205,11 +215,14 @@ const optimizeBreakpointDeltas = (cssStrings) => {
|
|
|
205
215
|
const shallowEqual = (a, b) => {
|
|
206
216
|
if (a === b) return true;
|
|
207
217
|
if (!a || !b) return false;
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
218
|
+
let aCount = 0;
|
|
219
|
+
for (const key in a) {
|
|
220
|
+
aCount++;
|
|
221
|
+
if (a[key] !== b[key]) return false;
|
|
222
|
+
}
|
|
223
|
+
let bCount = 0;
|
|
224
|
+
for (const _ in b) bCount++;
|
|
225
|
+
return aCount === bCount;
|
|
213
226
|
};
|
|
214
227
|
/**
|
|
215
228
|
* Removes breakpoints whose styles are identical to the previous one.
|
|
@@ -247,19 +260,20 @@ const removeUnexpectedKeys = (obj, keys) => {
|
|
|
247
260
|
const transformTheme = ({ theme, breakpoints }) => {
|
|
248
261
|
const result = {};
|
|
249
262
|
if (isEmpty(theme) || isEmpty(breakpoints)) return result;
|
|
250
|
-
|
|
251
|
-
|
|
263
|
+
for (const key in theme) {
|
|
264
|
+
const value = theme[key];
|
|
265
|
+
if (Array.isArray(value) && value.length > 0) for (let i = 0; i < value.length; i++) {
|
|
252
266
|
const indexBreakpoint = breakpoints[i];
|
|
253
|
-
set(result, [indexBreakpoint, key],
|
|
254
|
-
}
|
|
255
|
-
else if (typeof value === "object" && value !== null)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
else if (value != null) {
|
|
267
|
+
set(result, [indexBreakpoint, key], value[i]);
|
|
268
|
+
}
|
|
269
|
+
else if (typeof value === "object" && value !== null) {
|
|
270
|
+
const obj = value;
|
|
271
|
+
for (const childKey in obj) set(result, [childKey, key], obj[childKey]);
|
|
272
|
+
} else if (value != null) {
|
|
259
273
|
const firstBreakpoint = breakpoints[0];
|
|
260
274
|
set(result, [firstBreakpoint, key], value);
|
|
261
275
|
}
|
|
262
|
-
}
|
|
276
|
+
}
|
|
263
277
|
return removeUnexpectedKeys(result, breakpoints);
|
|
264
278
|
};
|
|
265
279
|
|
|
@@ -424,7 +438,7 @@ const ALIGN_CONTENT_DIRECTION = {
|
|
|
424
438
|
const alignContent = (attrs) => {
|
|
425
439
|
const { direction, alignX, alignY } = attrs;
|
|
426
440
|
if (isEmpty(attrs) || !direction || !alignX || !alignY) return null;
|
|
427
|
-
const isReverted =
|
|
441
|
+
const isReverted = direction === "inline" || direction === "reverseInline";
|
|
428
442
|
const dir = ALIGN_CONTENT_DIRECTION[direction];
|
|
429
443
|
const x = ALIGN_CONTENT_MAP_X[alignX];
|
|
430
444
|
const y = ALIGN_CONTENT_MAP_Y[alignY];
|
|
@@ -23,19 +23,22 @@ const breakpoints = {
|
|
|
23
23
|
* Others are wrapped in `@media (min-width: <em>)` — em units
|
|
24
24
|
* ensure correct behaviour when users change browser font size.
|
|
25
25
|
*/
|
|
26
|
-
const createMediaQueries = ({ breakpoints, rootSize, css }) =>
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const createMediaQueries = ({ breakpoints, rootSize, css }) => {
|
|
27
|
+
const acc = {};
|
|
28
|
+
for (const key in breakpoints) {
|
|
29
|
+
const breakpointValue = breakpoints[key];
|
|
30
|
+
if (breakpointValue === 0) acc[key] = (...args) => css(...args);
|
|
31
|
+
else if (breakpointValue != null) {
|
|
32
|
+
const emSize = breakpointValue / rootSize;
|
|
33
|
+
acc[key] = (...args) => css`
|
|
32
34
|
@media only screen and (min-width: ${emSize}em) {
|
|
33
35
|
${css(...args)};
|
|
34
36
|
}
|
|
35
37
|
`;
|
|
38
|
+
}
|
|
36
39
|
}
|
|
37
40
|
return acc;
|
|
38
|
-
}
|
|
41
|
+
};
|
|
39
42
|
|
|
40
43
|
//#endregion
|
|
41
44
|
//#region src/responsive/normalizeTheme.ts
|
|
@@ -59,7 +62,13 @@ const handleObjectCb = (obj) => (bp, i, bps, res) => {
|
|
|
59
62
|
return previousValue;
|
|
60
63
|
};
|
|
61
64
|
const handleValueCb = (value) => () => value;
|
|
62
|
-
const shouldNormalize = (props) =>
|
|
65
|
+
const shouldNormalize = (props) => {
|
|
66
|
+
for (const key in props) {
|
|
67
|
+
const item = props[key];
|
|
68
|
+
if (typeof item === "object" || Array.isArray(item)) return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
};
|
|
63
72
|
/**
|
|
64
73
|
* Expands each theme property into a full breakpoint map so every
|
|
65
74
|
* breakpoint has a value. Arrays fill by index (last value carries forward),
|
|
@@ -70,12 +79,13 @@ const normalizeTheme = ({ theme, breakpoints }) => {
|
|
|
70
79
|
if (!shouldNormalize(theme)) return theme;
|
|
71
80
|
const getBpValues = assignToBreakpointKey(breakpoints);
|
|
72
81
|
const result = {};
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
for (const key in theme) {
|
|
83
|
+
const value = theme[key];
|
|
84
|
+
if (value == null) continue;
|
|
75
85
|
if (Array.isArray(value)) result[key] = getBpValues(handleArrayCb(value));
|
|
76
86
|
else if (typeof value === "object") result[key] = getBpValues(handleObjectCb(value));
|
|
77
87
|
else result[key] = getBpValues(handleValueCb(value));
|
|
78
|
-
}
|
|
88
|
+
}
|
|
79
89
|
return result;
|
|
80
90
|
};
|
|
81
91
|
|
|
@@ -205,11 +215,14 @@ const optimizeBreakpointDeltas = (cssStrings) => {
|
|
|
205
215
|
const shallowEqual = (a, b) => {
|
|
206
216
|
if (a === b) return true;
|
|
207
217
|
if (!a || !b) return false;
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
218
|
+
let aCount = 0;
|
|
219
|
+
for (const key in a) {
|
|
220
|
+
aCount++;
|
|
221
|
+
if (a[key] !== b[key]) return false;
|
|
222
|
+
}
|
|
223
|
+
let bCount = 0;
|
|
224
|
+
for (const _ in b) bCount++;
|
|
225
|
+
return aCount === bCount;
|
|
213
226
|
};
|
|
214
227
|
/**
|
|
215
228
|
* Removes breakpoints whose styles are identical to the previous one.
|
|
@@ -247,19 +260,20 @@ const removeUnexpectedKeys = (obj, keys) => {
|
|
|
247
260
|
const transformTheme = ({ theme, breakpoints }) => {
|
|
248
261
|
const result = {};
|
|
249
262
|
if (isEmpty(theme) || isEmpty(breakpoints)) return result;
|
|
250
|
-
|
|
251
|
-
|
|
263
|
+
for (const key in theme) {
|
|
264
|
+
const value = theme[key];
|
|
265
|
+
if (Array.isArray(value) && value.length > 0) for (let i = 0; i < value.length; i++) {
|
|
252
266
|
const indexBreakpoint = breakpoints[i];
|
|
253
|
-
set(result, [indexBreakpoint, key],
|
|
254
|
-
}
|
|
255
|
-
else if (typeof value === "object" && value !== null)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
else if (value != null) {
|
|
267
|
+
set(result, [indexBreakpoint, key], value[i]);
|
|
268
|
+
}
|
|
269
|
+
else if (typeof value === "object" && value !== null) {
|
|
270
|
+
const obj = value;
|
|
271
|
+
for (const childKey in obj) set(result, [childKey, key], obj[childKey]);
|
|
272
|
+
} else if (value != null) {
|
|
259
273
|
const firstBreakpoint = breakpoints[0];
|
|
260
274
|
set(result, [firstBreakpoint, key], value);
|
|
261
275
|
}
|
|
262
|
-
}
|
|
276
|
+
}
|
|
263
277
|
return removeUnexpectedKeys(result, breakpoints);
|
|
264
278
|
};
|
|
265
279
|
|
|
@@ -424,7 +438,7 @@ const ALIGN_CONTENT_DIRECTION = {
|
|
|
424
438
|
const alignContent = (attrs) => {
|
|
425
439
|
const { direction, alignX, alignY } = attrs;
|
|
426
440
|
if (isEmpty(attrs) || !direction || !alignX || !alignY) return null;
|
|
427
|
-
const isReverted =
|
|
441
|
+
const isReverted = direction === "inline" || direction === "reverseInline";
|
|
428
442
|
const dir = ALIGN_CONTENT_DIRECTION[direction];
|
|
429
443
|
const x = ALIGN_CONTENT_MAP_X[alignX];
|
|
430
444
|
const y = ALIGN_CONTENT_MAP_Y[alignY];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/unistyle",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Vit Bokisch <vit@bokisch.cz>",
|
|
6
6
|
"maintainers": [
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"node": ">= 18"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@vitus-labs/core": "^2.6.
|
|
53
|
+
"@vitus-labs/core": "^2.6.2",
|
|
54
54
|
"react": ">= 19",
|
|
55
55
|
"react-native": ">= 0.76"
|
|
56
56
|
},
|