react-native-unistyles 1.0.0-beta.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/LICENSE +20 -0
- package/README.md +243 -0
- package/lib/commonjs/UnistylesTheme.js +21 -0
- package/lib/commonjs/UnistylesTheme.js.map +1 -0
- package/lib/commonjs/createUnistyles.js +52 -0
- package/lib/commonjs/createUnistyles.js.map +1 -0
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.js +139 -0
- package/lib/commonjs/utils/breakpoints.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.spec.js +149 -0
- package/lib/commonjs/utils/breakpoints.spec.js.map +1 -0
- package/lib/commonjs/utils/common.js +11 -0
- package/lib/commonjs/utils/common.js.map +1 -0
- package/lib/commonjs/utils/index.js +32 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/mediaQueries.js +189 -0
- package/lib/commonjs/utils/mediaQueries.js.map +1 -0
- package/lib/commonjs/utils/mediaQueries.spec.js +220 -0
- package/lib/commonjs/utils/mediaQueries.spec.js.map +1 -0
- package/lib/commonjs/utils/styles.js +82 -0
- package/lib/commonjs/utils/styles.js.map +1 -0
- package/lib/commonjs/utils/styles.spec.js +98 -0
- package/lib/commonjs/utils/styles.spec.js.map +1 -0
- package/lib/module/UnistylesTheme.js +12 -0
- package/lib/module/UnistylesTheme.js.map +1 -0
- package/lib/module/createUnistyles.js +45 -0
- package/lib/module/createUnistyles.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/breakpoints.js +131 -0
- package/lib/module/utils/breakpoints.js.map +1 -0
- package/lib/module/utils/breakpoints.spec.js +147 -0
- package/lib/module/utils/breakpoints.spec.js.map +1 -0
- package/lib/module/utils/common.js +4 -0
- package/lib/module/utils/common.js.map +1 -0
- package/lib/module/utils/index.js +3 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/mediaQueries.js +176 -0
- package/lib/module/utils/mediaQueries.js.map +1 -0
- package/lib/module/utils/mediaQueries.spec.js +218 -0
- package/lib/module/utils/mediaQueries.spec.js.map +1 -0
- package/lib/module/utils/styles.js +75 -0
- package/lib/module/utils/styles.js.map +1 -0
- package/lib/module/utils/styles.spec.js +96 -0
- package/lib/module/utils/styles.spec.js.map +1 -0
- package/lib/typescript/src/UnistylesTheme.d.ts +9 -0
- package/lib/typescript/src/UnistylesTheme.d.ts.map +1 -0
- package/lib/typescript/src/createUnistyles.d.ts +9 -0
- package/lib/typescript/src/createUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +27 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +63 -0
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.spec.d.ts +2 -0
- package/lib/typescript/src/utils/breakpoints.spec.d.ts.map +1 -0
- package/lib/typescript/src/utils/common.d.ts +2 -0
- package/lib/typescript/src/utils/common.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +3 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/mediaQueries.d.ts +130 -0
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +1 -0
- package/lib/typescript/src/utils/mediaQueries.spec.d.ts +2 -0
- package/lib/typescript/src/utils/mediaQueries.spec.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +56 -0
- package/lib/typescript/src/utils/styles.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.spec.d.ts +2 -0
- package/lib/typescript/src/utils/styles.spec.d.ts.map +1 -0
- package/package.json +132 -0
- package/src/UnistylesTheme.tsx +17 -0
- package/src/createUnistyles.ts +56 -0
- package/src/index.ts +2 -0
- package/src/types.ts +52 -0
- package/src/utils/breakpoints.ts +140 -0
- package/src/utils/common.ts +3 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/mediaQueries.ts +201 -0
- package/src/utils/styles.ts +95 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _breakpoints = require("./breakpoints");
|
4
|
+
describe('breakpoints', () => {
|
5
|
+
describe('sortAndValidateBreakpoints', () => {
|
6
|
+
it('should throw error for empty breakpoints', () => {
|
7
|
+
const breakpoints = {};
|
8
|
+
expect(() => (0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toThrow();
|
9
|
+
});
|
10
|
+
it('should throw error for breakpoints that don\'t start with 0', () => {
|
11
|
+
const breakpoints = {
|
12
|
+
sm: -1
|
13
|
+
};
|
14
|
+
expect(() => (0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toThrow();
|
15
|
+
});
|
16
|
+
it('should return same order for sorted elements', () => {
|
17
|
+
const breakpoints = {
|
18
|
+
sm: 0,
|
19
|
+
md: 200,
|
20
|
+
lg: 300,
|
21
|
+
xl: 500
|
22
|
+
};
|
23
|
+
expect((0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toEqual(breakpoints);
|
24
|
+
});
|
25
|
+
it('should sort the order of breakpoints', () => {
|
26
|
+
const breakpoints = {
|
27
|
+
md: 200,
|
28
|
+
sm: 0,
|
29
|
+
lg: 300,
|
30
|
+
xl: 500
|
31
|
+
};
|
32
|
+
expect((0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toEqual({
|
33
|
+
sm: 0,
|
34
|
+
md: 200,
|
35
|
+
lg: 300,
|
36
|
+
xl: 500
|
37
|
+
});
|
38
|
+
});
|
39
|
+
it('should throw errors for duplicated values', () => {
|
40
|
+
const breakpoints = {
|
41
|
+
md: 200,
|
42
|
+
sm: 0,
|
43
|
+
lg: 300,
|
44
|
+
xl: 300
|
45
|
+
};
|
46
|
+
expect(() => (0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toThrow();
|
47
|
+
});
|
48
|
+
});
|
49
|
+
describe('getBreakpointFromScreenWidth', () => {
|
50
|
+
it('should return correct breakpoints based on screen width', () => {
|
51
|
+
const breakpoints = {
|
52
|
+
xs: 0,
|
53
|
+
sm: 300,
|
54
|
+
md: 500,
|
55
|
+
xl: 1200
|
56
|
+
};
|
57
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(0, breakpoints)).toEqual('xs');
|
58
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(20, breakpoints)).toEqual('xs');
|
59
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(100, breakpoints)).toEqual('xs');
|
60
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(101, breakpoints)).toEqual('xs');
|
61
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(250, breakpoints)).toEqual('xs');
|
62
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(300, breakpoints)).toEqual('sm');
|
63
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(499, breakpoints)).toEqual('sm');
|
64
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(500, breakpoints)).toEqual('md');
|
65
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(799, breakpoints)).toEqual('md');
|
66
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(1200, breakpoints)).toEqual('xl');
|
67
|
+
expect((0, _breakpoints.getBreakpointFromScreenWidth)(2000, breakpoints)).toEqual('xl');
|
68
|
+
});
|
69
|
+
});
|
70
|
+
describe('getValueForBreakpoint', () => {
|
71
|
+
it('should prioritize custom media query', () => {
|
72
|
+
const breakpoint = 'sm';
|
73
|
+
const breakpoints = {
|
74
|
+
xs: 0,
|
75
|
+
sm: 200,
|
76
|
+
md: 500
|
77
|
+
};
|
78
|
+
const style = {
|
79
|
+
':w[, 200]': 'green',
|
80
|
+
':w[201]': 'orange',
|
81
|
+
sm: 'pink'
|
82
|
+
};
|
83
|
+
const screenSize = {
|
84
|
+
width: 200,
|
85
|
+
height: 800
|
86
|
+
};
|
87
|
+
expect((0, _breakpoints.getValueForBreakpoint)(style, breakpoint, screenSize, breakpoints)).toEqual('green');
|
88
|
+
});
|
89
|
+
});
|
90
|
+
it('should match breakpoint if media query doesnt exist', () => {
|
91
|
+
const breakpoint = 'md';
|
92
|
+
const breakpoints = {
|
93
|
+
xs: 0,
|
94
|
+
sm: 200,
|
95
|
+
md: 500
|
96
|
+
};
|
97
|
+
const style = {
|
98
|
+
':w[, 200]': 'green',
|
99
|
+
':w[201, 499]': 'orange',
|
100
|
+
sm: 'pink',
|
101
|
+
md: 'red'
|
102
|
+
};
|
103
|
+
const screenSize = {
|
104
|
+
width: 500,
|
105
|
+
height: 1200
|
106
|
+
};
|
107
|
+
expect((0, _breakpoints.getValueForBreakpoint)(style, breakpoint, screenSize, breakpoints)).toEqual('red');
|
108
|
+
});
|
109
|
+
it('should match breakpoint even if value is undefined', () => {
|
110
|
+
const breakpoint = 'md';
|
111
|
+
const breakpoints = {
|
112
|
+
xs: 0,
|
113
|
+
sm: 200,
|
114
|
+
md: 500
|
115
|
+
};
|
116
|
+
const style = {
|
117
|
+
':w[, 200]': 'green',
|
118
|
+
':w[201, 499]': 'orange',
|
119
|
+
sm: 'pink',
|
120
|
+
md: undefined
|
121
|
+
};
|
122
|
+
const screenSize = {
|
123
|
+
width: 500,
|
124
|
+
height: 1200
|
125
|
+
};
|
126
|
+
expect((0, _breakpoints.getValueForBreakpoint)(style, breakpoint, screenSize, breakpoints)).toEqual(undefined);
|
127
|
+
});
|
128
|
+
it('should match lower breakpoint to match css cascading', () => {
|
129
|
+
const breakpoint = 'xl';
|
130
|
+
const breakpoints = {
|
131
|
+
xs: 0,
|
132
|
+
sm: 200,
|
133
|
+
md: 500,
|
134
|
+
xl: 600
|
135
|
+
};
|
136
|
+
const style = {
|
137
|
+
':w[, 200]': 'green',
|
138
|
+
':w[201, 499]': 'orange',
|
139
|
+
sm: 'pink',
|
140
|
+
md: 'red'
|
141
|
+
};
|
142
|
+
const screenSize = {
|
143
|
+
width: 500,
|
144
|
+
height: 1200
|
145
|
+
};
|
146
|
+
expect((0, _breakpoints.getValueForBreakpoint)(style, breakpoint, screenSize, breakpoints)).toEqual('red');
|
147
|
+
});
|
148
|
+
});
|
149
|
+
//# sourceMappingURL=breakpoints.spec.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_breakpoints","require","describe","it","breakpoints","expect","sortAndValidateBreakpoints","toThrow","sm","md","lg","xl","toEqual","xs","getBreakpointFromScreenWidth","breakpoint","style","screenSize","width","height","getValueForBreakpoint","undefined"],"sourceRoot":"../../../src","sources":["utils/breakpoints.spec.ts"],"mappings":";;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGAC,QAAQ,CAAC,aAAa,EAAE,MAAM;EAC1BA,QAAQ,CAAC,4BAA4B,EAAE,MAAM;IACzCC,EAAE,CAAC,0CAA0C,EAAE,MAAM;MACjD,MAAMC,WAAW,GAAG,CAAC,CAAC;MAEtBC,MAAM,CAAC,MAAM,IAAAC,uCAA0B,EAACF,WAAW,CAAC,CAAC,CAACG,OAAO,CAAC,CAAC;IACnE,CAAC,CAAC;IAEFJ,EAAE,CAAC,6DAA6D,EAAE,MAAM;MACpE,MAAMC,WAAW,GAAG;QAChBI,EAAE,EAAE,CAAC;MACT,CAAC;MAEDH,MAAM,CAAC,MAAM,IAAAC,uCAA0B,EAACF,WAAW,CAAC,CAAC,CAACG,OAAO,CAAC,CAAC;IACnE,CAAC,CAAC;IAEFJ,EAAE,CAAC,8CAA8C,EAAE,MAAM;MACrD,MAAMC,WAAW,GAAG;QAChBI,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MAEDN,MAAM,CAAC,I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,UAAU,EAAEb,WAAW,CAAC,CAAC,CAACQ,OAAO,CAACS,SAAS,CAAC;EAChG,CAAC,CAAC;EAEFlB,EAAE,CAAC,sDAAsD,EAAE,MAAM;IAC7D,MAAMY,UAAU,GAAG,IAAI;IACvB,MAAMX,WAAW,GAAG;MAChBS,EAAE,EAAE,CAAC;MACLL,EAAE,EAAE,GAAG;MACPC,EAAE,EAAE,GAAG;MACPE,EAAE,EAAE;IACR,CAAC;IACD,MAAMK,KAAyC,GAAG;MAC9C,WAAW,EAAE,OAAO;MACpB,cAAc,EAAE,QAAQ;MACxBR,EAAE,EAAE,MAAM;MACVC,EAAE,EAAE;IACR,CAAC;IACD,MAAMQ,UAAsB,GAAG;MAC3BC,KAAK,EAAE,GAAG;MACVC,MAAM,EAAE;IACZ,CAAC;IAEDd,MAAM,CAAC,IAAAe,kCAAqB,EAACJ,KAAK,EAAED,UAAU,EAAEE,UAAU,EAAEb,WAAW,CAAC,CAAC,CAACQ,OAAO,CAAC,KAAK,CAAC;EAC5F,CAAC,CAAC;AACN,CAAC,CAAC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.throwError = void 0;
|
7
|
+
const throwError = message => {
|
8
|
+
throw new Error(`🦄 [react-native-unistyles]: ${message}`);
|
9
|
+
};
|
10
|
+
exports.throwError = throwError;
|
11
|
+
//# sourceMappingURL=common.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["throwError","message","Error","exports"],"sourceRoot":"../../../src","sources":["utils/common.ts"],"mappings":";;;;;;AAAO,MAAMA,UAAU,GAAIC,OAAe,IAAK;EAC3C,MAAM,IAAIC,KAAK,CAAE,gCAA+BD,OAAQ,EAAC,CAAC;AAC9D,CAAC;AAAAE,OAAA,CAAAH,UAAA,GAAAA,UAAA"}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "getBreakpointFromScreenWidth", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _breakpoints.getBreakpointFromScreenWidth;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
Object.defineProperty(exports, "parseStyle", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _styles.parseStyle;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
Object.defineProperty(exports, "proxifyFunction", {
|
19
|
+
enumerable: true,
|
20
|
+
get: function () {
|
21
|
+
return _styles.proxifyFunction;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
Object.defineProperty(exports, "sortAndValidateBreakpoints", {
|
25
|
+
enumerable: true,
|
26
|
+
get: function () {
|
27
|
+
return _breakpoints.sortAndValidateBreakpoints;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
var _breakpoints = require("./breakpoints");
|
31
|
+
var _styles = require("./styles");
|
32
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_breakpoints","require","_styles"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA"}
|
@@ -0,0 +1,189 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.isWithinTheWidthAndHeight = exports.isWithinTheWidth = exports.isWithinTheHeight = exports.isWithinBreakpoint = exports.isMediaQuery = exports.getKeyForCustomMediaQuery = exports.extractValues = void 0;
|
7
|
+
/**
|
8
|
+
* Extracts numeric values from a coded string.
|
9
|
+
*
|
10
|
+
* The function is designed to process strings that have a format like "w[100,200]" or "h[300]".
|
11
|
+
* It removes characters 'w', 'h', '[', and ']' from the input string and then extracts the numbers.
|
12
|
+
*
|
13
|
+
* @param {string} codedValue - The input string to extract values from.
|
14
|
+
* @returns {Array<number>} An array of extracted numbers. Can contain one or two numbers based on the input format.
|
15
|
+
*
|
16
|
+
* @example
|
17
|
+
* extractValues("w[100,200]") // returns [100, 200]
|
18
|
+
* extractValues("h[300]") // returns [300]
|
19
|
+
* extractValues("h[,300]") // returns [0,300]
|
20
|
+
* extractValues("h[100,]") // returns [100]
|
21
|
+
*/
|
22
|
+
const extractValues = codedValue => {
|
23
|
+
const [lh, rh] = codedValue.replace(/[wh[\]]/g, '').split(',');
|
24
|
+
return rh ? [Number(lh), Number(rh)] : [Number(lh)];
|
25
|
+
};
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Determines if the given screen size matches the specified breakpoint query.
|
29
|
+
*
|
30
|
+
* The function checks if the screen size (width and/or height) falls within the range
|
31
|
+
* specified by the breakpoint query. The query can specify width (using 'w'), height (using 'h'),
|
32
|
+
* or both.
|
33
|
+
*
|
34
|
+
* @param {string} query - The breakpoint query string. Examples: 'w[100,200]', 'h[300]', 'w[100,200]h[300,400]'.
|
35
|
+
* @param {ScreenSize} screenSize - The screen size to check against the breakpoint query.
|
36
|
+
* @returns {boolean} True if the screen size matches the breakpoint query, false otherwise.
|
37
|
+
*
|
38
|
+
* @example
|
39
|
+
* const screenSize = { width: 150, height: 350 }
|
40
|
+
* isWithinBreakpoint('w[100,200]', screenSize) // returns true
|
41
|
+
* isWithinBreakpoint('h[400]', screenSize) // returns false
|
42
|
+
*/
|
43
|
+
exports.extractValues = extractValues;
|
44
|
+
const isWithinBreakpoint = (query, screenSize) => {
|
45
|
+
if (query.includes('w') && query.includes('h')) {
|
46
|
+
return isWithinTheWidthAndHeight(query, screenSize);
|
47
|
+
}
|
48
|
+
if (query.charAt(0) === 'w') {
|
49
|
+
return isWithinTheWidth(query, screenSize.width);
|
50
|
+
}
|
51
|
+
if (query.charAt(0) === 'h') {
|
52
|
+
return isWithinTheHeight(query, screenSize.height);
|
53
|
+
}
|
54
|
+
return false;
|
55
|
+
};
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Determines if the given width matches the specified width range in the query.
|
59
|
+
*
|
60
|
+
* The function checks if the provided width falls within the range specified by the query.
|
61
|
+
* The query specifies a width range using a format like 'w[100,200]'. If only one value is provided,
|
62
|
+
* it's treated as a minimum width.
|
63
|
+
*
|
64
|
+
* @param {string} query - The width query string. Examples: 'w[100,200]' or 'w[100]'.
|
65
|
+
* @param {number} width - The width to check against the query.
|
66
|
+
* @returns {boolean} True if the width matches the query range, false otherwise.
|
67
|
+
*
|
68
|
+
* @example
|
69
|
+
* isWithinTheWidth('w[100,200]', 150) // returns true
|
70
|
+
* isWithinTheWidth('w[100]', 50) // returns false
|
71
|
+
* isWithinTheWidth('w[100]', 150) // returns true
|
72
|
+
*/
|
73
|
+
exports.isWithinBreakpoint = isWithinBreakpoint;
|
74
|
+
const isWithinTheWidth = (query, width) => {
|
75
|
+
const [minWidth, maxWidth] = extractValues(query);
|
76
|
+
if (maxWidth && width >= minWidth && width <= maxWidth) {
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
return !maxWidth && width >= minWidth;
|
80
|
+
};
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Determines if the given height matches the specified height range in the query.
|
84
|
+
*
|
85
|
+
* The function checks if the provided height falls within the range specified by the query.
|
86
|
+
* The query specifies a height range using a format like 'h[100,200]'. If only one value is provided,
|
87
|
+
* it's treated as a minimum height.
|
88
|
+
*
|
89
|
+
* @param {string} query - The height query string. Examples: 'h[100,200]' or 'h[100]'.
|
90
|
+
* @param {number} height - The height to check against the query.
|
91
|
+
* @returns {boolean} True if the height matches the query range, false otherwise.
|
92
|
+
*
|
93
|
+
* @example
|
94
|
+
* isWithinTheHeight('h[100,200]', 150) // returns true
|
95
|
+
* isWithinTheHeight('h[100]', 50) // returns false
|
96
|
+
* isWithinTheHeight('h[100]', 150) // returns true
|
97
|
+
*/
|
98
|
+
exports.isWithinTheWidth = isWithinTheWidth;
|
99
|
+
const isWithinTheHeight = (query, height) => {
|
100
|
+
const [minHeight, maxHeight] = extractValues(query);
|
101
|
+
if (maxHeight && height >= minHeight && height <= maxHeight) {
|
102
|
+
return true;
|
103
|
+
}
|
104
|
+
return !maxHeight && height >= minHeight;
|
105
|
+
};
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Determines if the given screen size matches both the specified width and height ranges in the query.
|
109
|
+
*
|
110
|
+
* The function checks if the provided screen size (both width and height) falls within the ranges
|
111
|
+
* specified by the query. The query can specify both width and height using a format like 'w[100,200]:h[300,400]'.
|
112
|
+
*
|
113
|
+
* @param {string} query - The combined width and height query string. Example: 'w[100,200]:h[300,400]'.
|
114
|
+
* @param {ScreenSize} screenSize - The screen size to check against the query.
|
115
|
+
* @returns {boolean} True if the screen size matches both the width and height ranges in the query, false otherwise.
|
116
|
+
*
|
117
|
+
* @example
|
118
|
+
* const screenSize = { width: 150, height: 350 }
|
119
|
+
* isWithinTheWidthAndHeight('w[100,200]:h[300,400]', screenSize) // returns true
|
120
|
+
* isWithinTheWidthAndHeight('w[100,200]:h[400,500]', screenSize) // returns false
|
121
|
+
*/
|
122
|
+
exports.isWithinTheHeight = isWithinTheHeight;
|
123
|
+
const isWithinTheWidthAndHeight = (query, screenSize) => {
|
124
|
+
const result = query.split(':').filter(Boolean).map(q => isWithinBreakpoint(q, screenSize)).filter(Boolean);
|
125
|
+
return result.length === 2;
|
126
|
+
};
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Checks if the given query string is a valid custom media query.
|
130
|
+
*
|
131
|
+
* The valid custom media query formats include:
|
132
|
+
* - :w[200]
|
133
|
+
* - :w[0, 200]
|
134
|
+
* - :w[, 300]
|
135
|
+
* - :h[200]
|
136
|
+
* - :h[0, 500]
|
137
|
+
* - :h[,200]
|
138
|
+
* - :w[100, 300]:h[200,500]
|
139
|
+
* - :h[200,500]:w[100, 300]
|
140
|
+
*
|
141
|
+
* @param {string} query - The query string to be checked.
|
142
|
+
* @returns {boolean} Returns `true` if the query is a valid custom media query, otherwise `false`.
|
143
|
+
* @example
|
144
|
+
*
|
145
|
+
* isMediaQuery(':w[200]') // true
|
146
|
+
* isMediaQuery(':w100]') // false
|
147
|
+
*/
|
148
|
+
exports.isWithinTheWidthAndHeight = isWithinTheWidthAndHeight;
|
149
|
+
const isMediaQuery = query => {
|
150
|
+
const regex = /^(?:(:w\[\d*(?:,\s?\d+)?])?(:h\[\d*(?:,\s?\d+)?])?|(:h\[\d*(?:,\s?\d+)?])?(:w\[\d*(?:,\s?\d+)?])?)$/;
|
151
|
+
return query.length > 0 && regex.test(query);
|
152
|
+
};
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Retrieves the first matching custom media query key based on the provided screen size.
|
156
|
+
*
|
157
|
+
* The function processes an array of media queries and returns the first query that matches
|
158
|
+
* the given screen size. The media queries can be in formats like:
|
159
|
+
* - w[200]
|
160
|
+
* - w[0, 200]
|
161
|
+
* - w[, 300]
|
162
|
+
* - h[200]
|
163
|
+
* - h[0, 500]
|
164
|
+
* - h[,200]
|
165
|
+
* - w[100, 300]:h[200,500]
|
166
|
+
* - h[200,500]:w[100, 300]
|
167
|
+
*
|
168
|
+
* @param {Array<[string, string | number]>} mediaQueries - An array of tuples containing media query keys and associated values.
|
169
|
+
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
170
|
+
* @returns {string | undefined} Returns the first matching media query key or `undefined` if no match is found.
|
171
|
+
* @example
|
172
|
+
*
|
173
|
+
* const queries = [[':w[200]', 'value1'], [':h[300,500]', 'value2']]
|
174
|
+
* const size = { width: 250, height: 400 }
|
175
|
+
* getKeyForCustomMediaQuery(queries, size) // ':w[200]
|
176
|
+
*/
|
177
|
+
exports.isMediaQuery = isMediaQuery;
|
178
|
+
const getKeyForCustomMediaQuery = (mediaQueries, screenSize) => {
|
179
|
+
const [matchedQuery] = mediaQueries.flatMap(_ref => {
|
180
|
+
let [key] = _ref;
|
181
|
+
if (key.includes('w') && key.includes('h')) {
|
182
|
+
return isWithinBreakpoint(key, screenSize) ? key : undefined;
|
183
|
+
}
|
184
|
+
return key.split(':').filter(Boolean).map(query => isWithinBreakpoint(query, screenSize) ? key : undefined);
|
185
|
+
}).filter(Boolean);
|
186
|
+
return matchedQuery;
|
187
|
+
};
|
188
|
+
exports.getKeyForCustomMediaQuery = getKeyForCustomMediaQuery;
|
189
|
+
//# sourceMappingURL=mediaQueries.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["extractValues","codedValue","lh","rh","replace","split","Number","exports","isWithinBreakpoint","query","screenSize","includes","isWithinTheWidthAndHeight","charAt","isWithinTheWidth","width","isWithinTheHeight","height","minWidth","maxWidth","minHeight","maxHeight","result","filter","Boolean","map","q","length","isMediaQuery","regex","test","getKeyForCustomMediaQuery","mediaQueries","matchedQuery","flatMap","_ref","key","undefined"],"sourceRoot":"../../../src","sources":["utils/mediaQueries.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,aAAa,GAAIC,UAAkB,IAAoB;EAChE,MAAM,CAACC,EAAE,EAAEC,EAAE,CAAC,GAAGF,UAAU,CACtBG,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CACvBC,KAAK,CAAC,GAAG,CAAC;EAEf,OAAOF,EAAE,GACH,CAACG,MAAM,CAACJ,EAAE,CAAC,EAAEI,MAAM,CAACH,EAAE,CAAC,CAAC,GACxB,CAACG,MAAM,CAACJ,EAAE,CAAC,CAAC;AACtB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAfAK,OAAA,CAAAP,aAAA,GAAAA,aAAA;AAgBO,MAAMQ,kBAAkB,GAAGA,CAACC,KAAa,EAAEC,UAAsB,KAAc;EAClF,IAAID,KAAK,CAACE,QAAQ,CAAC,GAAG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AQ,CAAC,GAAG,CAAC,EAAE;MACxC,OAAOH,kBAAkB,CAAC4B,GAAG,EAAE1B,UAAU,CAAC,GAAG0B,GAAG,GAAGC,SAAS;IAChE;IAEA,OAAOD,GAAG,CACL/B,KAAK,CAAC,GAAG,CAAC,CACVkB,MAAM,CAACC,OAAO,CAAC,CACfC,GAAG,CAAChB,KAAK,IAAID,kBAAkB,CAACC,KAAK,EAAEC,UAAU,CAAC,GAAG0B,GAAG,GAAGC,SAAS,CAAC;EAC9E,CAAC,CAAC,CACDd,MAAM,CAACC,OAAO,CAAC;EAEpB,OAAOS,YAAY;AACvB,CAAC;AAAA1B,OAAA,CAAAwB,yBAAA,GAAAA,yBAAA"}
|
@@ -0,0 +1,220 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _mediaQueries = require("./mediaQueries");
|
4
|
+
describe('utils', () => {
|
5
|
+
describe('extractValues', () => {
|
6
|
+
it('should correctly extract a width with both bounds', () => {
|
7
|
+
const mediaQuery = 'w[100, 600]';
|
8
|
+
expect((0, _mediaQueries.extractValues)(mediaQuery)).toEqual([100, 600]);
|
9
|
+
});
|
10
|
+
it('should correctly extract a width with lower bound equal to 0', () => {
|
11
|
+
const mediaQuery = 'w[0, 400]';
|
12
|
+
expect((0, _mediaQueries.extractValues)(mediaQuery)).toEqual([0, 400]);
|
13
|
+
});
|
14
|
+
it('should correctly extract a height with single value', () => {
|
15
|
+
const mediaQuery = 'h[700]';
|
16
|
+
expect((0, _mediaQueries.extractValues)(mediaQuery)).toEqual([700]);
|
17
|
+
});
|
18
|
+
it('should correctly extract a height with lower bound equal to 0', () => {
|
19
|
+
const mediaQuery = 'h[0,]';
|
20
|
+
expect((0, _mediaQueries.extractValues)(mediaQuery)).toEqual([0]);
|
21
|
+
});
|
22
|
+
it('should correctly extract a width with no lower bound', () => {
|
23
|
+
const mediaQuery = 'w[,100]';
|
24
|
+
expect((0, _mediaQueries.extractValues)(mediaQuery)).toEqual([0, 100]);
|
25
|
+
});
|
26
|
+
});
|
27
|
+
describe('isWithinTheWidth', () => {
|
28
|
+
it('should return true if the screen width is within the media query', () => {
|
29
|
+
const pairs = [{
|
30
|
+
width: 200,
|
31
|
+
query: 'w[120]'
|
32
|
+
}, {
|
33
|
+
width: 100,
|
34
|
+
query: 'w[,500]'
|
35
|
+
}, {
|
36
|
+
width: 0,
|
37
|
+
query: 'w[,500]'
|
38
|
+
}, {
|
39
|
+
width: 300,
|
40
|
+
query: 'w[300,500]'
|
41
|
+
}];
|
42
|
+
pairs.forEach(_ref => {
|
43
|
+
let {
|
44
|
+
width,
|
45
|
+
query
|
46
|
+
} = _ref;
|
47
|
+
expect((0, _mediaQueries.isWithinTheWidth)(query, width)).toEqual(true);
|
48
|
+
});
|
49
|
+
});
|
50
|
+
it('should return false if the screen width is outside the media query', () => {
|
51
|
+
const pairs = [{
|
52
|
+
width: 120,
|
53
|
+
query: 'w[200]'
|
54
|
+
}, {
|
55
|
+
width: 501,
|
56
|
+
query: 'w[,500]'
|
57
|
+
}, {
|
58
|
+
width: 700,
|
59
|
+
query: 'w[200,500]'
|
60
|
+
}];
|
61
|
+
pairs.forEach(_ref2 => {
|
62
|
+
let {
|
63
|
+
width,
|
64
|
+
query
|
65
|
+
} = _ref2;
|
66
|
+
expect((0, _mediaQueries.isWithinTheWidth)(query, width)).toEqual(false);
|
67
|
+
});
|
68
|
+
});
|
69
|
+
});
|
70
|
+
describe('isWithinTheHeight', () => {
|
71
|
+
it('should return true if the screen height is within the media query', () => {
|
72
|
+
const pairs = [{
|
73
|
+
height: 200,
|
74
|
+
query: 'h[120]'
|
75
|
+
}, {
|
76
|
+
height: 100,
|
77
|
+
query: 'h[,500]'
|
78
|
+
}, {
|
79
|
+
height: 0,
|
80
|
+
query: 'h[,500]'
|
81
|
+
}, {
|
82
|
+
height: 300,
|
83
|
+
query: 'h[300,500]'
|
84
|
+
}];
|
85
|
+
pairs.forEach(_ref3 => {
|
86
|
+
let {
|
87
|
+
height,
|
88
|
+
query
|
89
|
+
} = _ref3;
|
90
|
+
expect((0, _mediaQueries.isWithinTheHeight)(query, height)).toEqual(true);
|
91
|
+
});
|
92
|
+
});
|
93
|
+
it('should return false if the screen height is outside the media query', () => {
|
94
|
+
const pairs = [{
|
95
|
+
height: 120,
|
96
|
+
query: 'h[200]'
|
97
|
+
}, {
|
98
|
+
height: 501,
|
99
|
+
query: 'h[,500]'
|
100
|
+
}, {
|
101
|
+
height: 700,
|
102
|
+
query: 'h[200,500]'
|
103
|
+
}];
|
104
|
+
pairs.forEach(_ref4 => {
|
105
|
+
let {
|
106
|
+
height,
|
107
|
+
query
|
108
|
+
} = _ref4;
|
109
|
+
expect((0, _mediaQueries.isWithinTheHeight)(query, height)).toEqual(false);
|
110
|
+
});
|
111
|
+
});
|
112
|
+
});
|
113
|
+
describe('isWithinTheWidthAndHeight', () => {
|
114
|
+
it('should return true if the screen width and height are within the media query', () => {
|
115
|
+
const pairs = [{
|
116
|
+
screenSize: {
|
117
|
+
width: 200,
|
118
|
+
height: 600
|
119
|
+
},
|
120
|
+
query: 'w[, 200]:h[600]'
|
121
|
+
}, {
|
122
|
+
screenSize: {
|
123
|
+
width: 200,
|
124
|
+
height: 600
|
125
|
+
},
|
126
|
+
query: 'w[110]:h[400]'
|
127
|
+
}, {
|
128
|
+
screenSize: {
|
129
|
+
width: 400,
|
130
|
+
height: 800
|
131
|
+
},
|
132
|
+
query: 'w[400, 800]:h[400, 800]'
|
133
|
+
}];
|
134
|
+
pairs.forEach(_ref5 => {
|
135
|
+
let {
|
136
|
+
screenSize,
|
137
|
+
query
|
138
|
+
} = _ref5;
|
139
|
+
expect((0, _mediaQueries.isWithinTheWidthAndHeight)(query, screenSize)).toEqual(true);
|
140
|
+
});
|
141
|
+
});
|
142
|
+
it('should return false if the screen width and height are outside the media query', () => {
|
143
|
+
const pairs = [{
|
144
|
+
screenSize: {
|
145
|
+
width: 200,
|
146
|
+
height: 600
|
147
|
+
},
|
148
|
+
query: 'w[, 220]:h[620]'
|
149
|
+
}, {
|
150
|
+
screenSize: {
|
151
|
+
width: 200,
|
152
|
+
height: 600
|
153
|
+
},
|
154
|
+
query: 'w[290]:h[400]'
|
155
|
+
}, {
|
156
|
+
screenSize: {
|
157
|
+
width: 400,
|
158
|
+
height: 800
|
159
|
+
},
|
160
|
+
query: 'w[, 800]:h[, 700]'
|
161
|
+
}];
|
162
|
+
pairs.forEach(_ref6 => {
|
163
|
+
let {
|
164
|
+
screenSize,
|
165
|
+
query
|
166
|
+
} = _ref6;
|
167
|
+
expect((0, _mediaQueries.isWithinTheWidthAndHeight)(query, screenSize)).toEqual(false);
|
168
|
+
});
|
169
|
+
});
|
170
|
+
});
|
171
|
+
describe('isMediaQuery', () => {
|
172
|
+
it('should detect correct media queries', () => {
|
173
|
+
const correctMediaQueries = [':w[100]', ':w[100, 200]', ':w[, 300]', ':h[200]', ':h[0, 500]', ':h[, 750]', ':w[100]:h[200]', ':h[100]:w[200]', ':h[100, 200]:w[,400]', ':w[200]:h[200, 400]'];
|
174
|
+
correctMediaQueries.forEach(query => {
|
175
|
+
expect((0, _mediaQueries.isMediaQuery)(query)).toEqual(true);
|
176
|
+
});
|
177
|
+
});
|
178
|
+
it('should detect incorrect media queries', () => {
|
179
|
+
const incorrectMediaQueries = [':w100]', ':w[100, 200', ':p[, 300]', ':&[200]', ':h[0 500]', ':h[p, 750]', ':w[0]:l[200]', ':[100]:w[200]', ':h(100, 200):w[400]', ':w[2OO]:h[200, 400]', '', 'x', '>300', ']]w200[['];
|
180
|
+
incorrectMediaQueries.forEach(query => {
|
181
|
+
expect((0, _mediaQueries.isMediaQuery)(query)).toEqual(false);
|
182
|
+
});
|
183
|
+
});
|
184
|
+
});
|
185
|
+
describe('getKeyForCustomMediaQuery', () => {
|
186
|
+
it('should return a key for string value based on media query', () => {
|
187
|
+
const mediaQueries = [['w[,200]', 'orange'], ['w[300, 400]', 'pink'], ['w[500, 600]', 'red']];
|
188
|
+
const screenSize = {
|
189
|
+
width: 300,
|
190
|
+
height: 700
|
191
|
+
};
|
192
|
+
expect((0, _mediaQueries.getKeyForCustomMediaQuery)(mediaQueries, screenSize)).toEqual('w[300, 400]');
|
193
|
+
});
|
194
|
+
it('should return a key for number value based on media query', () => {
|
195
|
+
const mediaQueries = [['w[,200]', 200], ['w[250]', 300]];
|
196
|
+
const screenSize = {
|
197
|
+
width: 300,
|
198
|
+
height: 700
|
199
|
+
};
|
200
|
+
expect((0, _mediaQueries.getKeyForCustomMediaQuery)(mediaQueries, screenSize)).toEqual('w[250]');
|
201
|
+
});
|
202
|
+
it('should return undefined for no match', () => {
|
203
|
+
const mediaQueries = [['w[,400]', 'green'], ['w[500, 999]', 'olive'], ['w[1000]', 'red']];
|
204
|
+
const screenSize = {
|
205
|
+
width: 450,
|
206
|
+
height: 1000
|
207
|
+
};
|
208
|
+
expect((0, _mediaQueries.getKeyForCustomMediaQuery)(mediaQueries, screenSize)).toEqual(undefined);
|
209
|
+
});
|
210
|
+
it('should handle correctly complex media queries', () => {
|
211
|
+
const mediaQueries = [['w[,300]:h[200,700]', 200], ['w[250]:h[701]', 300], ['w[200]', 500]];
|
212
|
+
const screenSize = {
|
213
|
+
width: 300,
|
214
|
+
height: 700
|
215
|
+
};
|
216
|
+
expect((0, _mediaQueries.getKeyForCustomMediaQuery)(mediaQueries, screenSize)).toEqual('w[,300]:h[200,700]');
|
217
|
+
});
|
218
|
+
});
|
219
|
+
});
|
220
|
+
//# sourceMappingURL=mediaQueries.spec.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_mediaQueries","require","describe","it","mediaQuery","expect","extractValues","toEqual","pairs","width","query","forEach","_ref","isWithinTheWidth","_ref2","height","_ref3","isWithinTheHeight","_ref4","screenSize","_ref5","isWithinTheWidthAndHeight","_ref6","correctMediaQueries","isMediaQuery","incorrectMediaQueries","mediaQueries","getKeyForCustomMediaQuery","undefined"],"sourceRoot":"../../../src","sources":["utils/mediaQueries.spec.ts"],"mappings":";;AAAA,IAAAA,aAAA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