@hanzogui/react-native-media-driver 2.0.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/LICENSE +21 -0
- package/dist/cjs/createMedia.cjs +30 -0
- package/dist/cjs/createMedia.native.js +33 -0
- package/dist/cjs/createMedia.native.js.map +1 -0
- package/dist/cjs/index.cjs +19 -0
- package/dist/cjs/index.native.js +22 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/matchMedia.cjs +26 -0
- package/dist/cjs/matchMedia.native.js +32 -0
- package/dist/cjs/matchMedia.native.js.map +1 -0
- package/dist/cjs/matchQuery.cjs +141 -0
- package/dist/cjs/matchQuery.native.js +150 -0
- package/dist/cjs/matchQuery.native.js.map +1 -0
- package/dist/cjs/mediaQueryList.cjs +73 -0
- package/dist/cjs/mediaQueryList.native.js +113 -0
- package/dist/cjs/mediaQueryList.native.js.map +1 -0
- package/dist/esm/createMedia.mjs +7 -0
- package/dist/esm/createMedia.mjs.map +1 -0
- package/dist/esm/createMedia.native.js +7 -0
- package/dist/esm/createMedia.native.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +3 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/matchMedia.mjs +3 -0
- package/dist/esm/matchMedia.mjs.map +1 -0
- package/dist/esm/matchMedia.native.js +6 -0
- package/dist/esm/matchMedia.native.js.map +1 -0
- package/dist/esm/matchQuery.mjs +117 -0
- package/dist/esm/matchQuery.mjs.map +1 -0
- package/dist/esm/matchQuery.native.js +123 -0
- package/dist/esm/matchQuery.native.js.map +1 -0
- package/dist/esm/mediaQueryList.mjs +50 -0
- package/dist/esm/mediaQueryList.mjs.map +1 -0
- package/dist/esm/mediaQueryList.native.js +87 -0
- package/dist/esm/mediaQueryList.native.js.map +1 -0
- package/package.json +47 -0
- package/src/createMedia.ts +19 -0
- package/src/index.ts +2 -0
- package/src/matchMedia.native.ts +7 -0
- package/src/matchMedia.ts +5 -0
- package/src/matchQuery.ts +176 -0
- package/src/mediaQueryList.ts +60 -0
- package/types/createMedia.d.ts +10 -0
- package/types/createMedia.d.ts.map +11 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +11 -0
- package/types/matchMedia.d.ts +4 -0
- package/types/matchMedia.d.ts.map +11 -0
- package/types/matchMedia.native.d.ts +4 -0
- package/types/matchMedia.native.d.ts.map +11 -0
- package/types/matchQuery.d.ts +12 -0
- package/types/matchQuery.d.ts.map +11 -0
- package/types/mediaQueryList.d.ts +20 -0
- package/types/mediaQueryList.d.ts.map +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var createMedia_exports = {};
|
|
22
|
+
__export(createMedia_exports, {
|
|
23
|
+
createMedia: () => createMedia
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(createMedia_exports);
|
|
26
|
+
var import_web = require("@hanzogui/web"),
|
|
27
|
+
import_matchMedia = require("./matchMedia.cjs");
|
|
28
|
+
function createMedia(media) {
|
|
29
|
+
return (0, import_web.setupMatchMedia)(import_matchMedia.matchMedia), media;
|
|
30
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var createMedia_exports = {};
|
|
24
|
+
__export(createMedia_exports, {
|
|
25
|
+
createMedia: () => createMedia
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(createMedia_exports);
|
|
28
|
+
var import_web = require("@hanzogui/web"),
|
|
29
|
+
import_matchMedia = require("./matchMedia.native.js");
|
|
30
|
+
function createMedia(media) {
|
|
31
|
+
return (0, import_web.setupMatchMedia)(import_matchMedia.matchMedia), media;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=createMedia.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","createMedia_exports","__export","createMedia","module","exports","import_web","require","import_matchMedia","media","setupMatchMedia","matchMedia"],"sources":["../../src/createMedia.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAgCT,YAAA,CAAAK,mBAEhC;AAMO,IAAAK,UAAS,GAAAC,OAId,gBAAa;EAAAC,iBAAA,GAAAD,OAAA;AAGb,SAAAJ,YAAAM,KAAA;EAEF,WAAAH,UAAA,CAAAI,eAAA,EAAAF,iBAAA,CAAAG,UAAA,GAAAF,KAAA","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./createMedia.cjs"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./matchMedia.cjs"), module.exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
9
|
+
get: () => from[key],
|
|
10
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
|
+
});
|
|
12
|
+
return to;
|
|
13
|
+
},
|
|
14
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
+
value: !0
|
|
17
|
+
}), mod);
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(index_exports);
|
|
20
|
+
__reExport(index_exports, require("./createMedia.native.js"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./matchMedia.native.js"), module.exports);
|
|
22
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA;AACdG,UAAA,CAAAH,aAAA,EAAcI,OAAA,6BADdH,MAAA,CAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var matchMedia_exports = {};
|
|
22
|
+
__export(matchMedia_exports, {
|
|
23
|
+
matchMedia: () => matchMedia
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(matchMedia_exports);
|
|
26
|
+
const matchMedia = globalThis.matchMedia;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var matchMedia_native_exports = {};
|
|
24
|
+
__export(matchMedia_native_exports, {
|
|
25
|
+
matchMedia: () => matchMedia
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(matchMedia_native_exports);
|
|
28
|
+
var import_mediaQueryList = require("./mediaQueryList.native.js"),
|
|
29
|
+
matchMedia = function (query) {
|
|
30
|
+
return new import_mediaQueryList.NativeMediaQueryList(query);
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=matchMedia.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["matchMedia_native_exports","__export","matchMedia","module","exports","__toCommonJS","import_mediaQueryList","require","query","NativeMediaQueryList"],"sources":["../../src/matchMedia.native.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,yBAAA;AAAAC,QAAA,CAAAD,yBAAA;EAAAE,UAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAC,YAAA,CAAAL,yBAAA;AAAA,IAAAM,qBAAA,GAAqCC,OAAA;EAC1BL,UAAA,GAAa,SAAAA,CAASM,KAAA,EAAO;IACpC,OAAO,IAAIF,qBAAA,CAAAG,oBAAA,CAAqBD,KAAK;EACzC","ignoreList":[]}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var matchQuery_exports = {};
|
|
22
|
+
__export(matchQuery_exports, {
|
|
23
|
+
matchQuery: () => matchQuery,
|
|
24
|
+
parseQuery: () => parseQuery
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(matchQuery_exports);
|
|
27
|
+
const RE_MEDIA_QUERY = /(?:(only|not)?\s*([^\s()]+)(?:\s*and)?\s*)?(.+)?/i,
|
|
28
|
+
RE_MQ_EXPRESSION = /\(\s*([^\s:)]+)\s*(?::\s*([^\s)]+))?\s*\)/,
|
|
29
|
+
RE_MQ_FEATURE = /^(?:(min|max)-)?(.+)/,
|
|
30
|
+
RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?$/,
|
|
31
|
+
RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?$/;
|
|
32
|
+
function matchQuery(mediaQuery, values) {
|
|
33
|
+
return parseQuery(mediaQuery).some(query => {
|
|
34
|
+
if (!query) return;
|
|
35
|
+
const inverse = query.inverse,
|
|
36
|
+
typeMatch = query.type === "all" || values.type === query.type;
|
|
37
|
+
if (typeMatch && inverse || !(typeMatch || inverse)) return !1;
|
|
38
|
+
const expressionsMatch = query.expressions.every(expression => {
|
|
39
|
+
const feature = expression.feature,
|
|
40
|
+
modifier = expression.modifier;
|
|
41
|
+
let expValue = expression.value,
|
|
42
|
+
value = values[feature];
|
|
43
|
+
if (!value) return !1;
|
|
44
|
+
switch (feature) {
|
|
45
|
+
case "orientation":
|
|
46
|
+
case "scan":
|
|
47
|
+
return value.toLowerCase() === expValue.toLowerCase();
|
|
48
|
+
case "width":
|
|
49
|
+
case "height":
|
|
50
|
+
case "device-width":
|
|
51
|
+
case "device-height":
|
|
52
|
+
expValue = toPx(expValue), value = toPx(value);
|
|
53
|
+
break;
|
|
54
|
+
case "resolution":
|
|
55
|
+
expValue = toDpi(expValue), value = toDpi(value);
|
|
56
|
+
break;
|
|
57
|
+
case "aspect-ratio":
|
|
58
|
+
case "device-aspect-ratio":
|
|
59
|
+
case /* Deprecated */
|
|
60
|
+
"device-pixel-ratio":
|
|
61
|
+
expValue = toDecimal(expValue), value = toDecimal(value);
|
|
62
|
+
break;
|
|
63
|
+
case "grid":
|
|
64
|
+
case "color":
|
|
65
|
+
case "color-index":
|
|
66
|
+
case "monochrome":
|
|
67
|
+
expValue = Number.parseInt(expValue, 10) || 1, value = Number.parseInt(value, 10) || 0;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
switch (modifier) {
|
|
71
|
+
case "min":
|
|
72
|
+
return value >= expValue;
|
|
73
|
+
case "max":
|
|
74
|
+
return value <= expValue;
|
|
75
|
+
default:
|
|
76
|
+
return value === expValue;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return expressionsMatch && !inverse || !expressionsMatch && inverse;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function parseQuery(mediaQuery) {
|
|
83
|
+
return mediaQuery.split(",").map(query => {
|
|
84
|
+
query = query.trim();
|
|
85
|
+
const captures = query.match(RE_MEDIA_QUERY);
|
|
86
|
+
if (!captures) return null;
|
|
87
|
+
const modifier = captures[1],
|
|
88
|
+
type = captures[2],
|
|
89
|
+
expressions = (captures[3] || "").match(/\([^)]+\)/g) || [];
|
|
90
|
+
return {
|
|
91
|
+
inverse: !!modifier && modifier.toLowerCase() === "not",
|
|
92
|
+
type: type ? type.toLowerCase() : "all",
|
|
93
|
+
expressions: expressions.map(expression => {
|
|
94
|
+
const captures2 = expression.match(RE_MQ_EXPRESSION),
|
|
95
|
+
feature = captures2[1].toLowerCase().match(RE_MQ_FEATURE);
|
|
96
|
+
return {
|
|
97
|
+
modifier: feature[1],
|
|
98
|
+
feature: feature[2],
|
|
99
|
+
value: captures2[2]
|
|
100
|
+
};
|
|
101
|
+
})
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function toDecimal(ratio) {
|
|
106
|
+
let decimal = Number(ratio),
|
|
107
|
+
numbers;
|
|
108
|
+
return decimal || (numbers = ratio.match(/^(\d+)\s*\/\s*(\d+)$/), decimal = numbers[1] / numbers[2]), decimal;
|
|
109
|
+
}
|
|
110
|
+
function toDpi(resolution) {
|
|
111
|
+
const value = Number.parseFloat(resolution);
|
|
112
|
+
switch (String(resolution).match(RE_RESOLUTION_UNIT)?.[1]) {
|
|
113
|
+
case "dpcm":
|
|
114
|
+
return value / 2.54;
|
|
115
|
+
case "dppx":
|
|
116
|
+
return value * 96;
|
|
117
|
+
default:
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function toPx(length) {
|
|
122
|
+
const value = Number.parseFloat(length);
|
|
123
|
+
switch (String(length).match(RE_LENGTH_UNIT)?.[1]) {
|
|
124
|
+
case "em":
|
|
125
|
+
return value * 16;
|
|
126
|
+
case "rem":
|
|
127
|
+
return value * 16;
|
|
128
|
+
case "cm":
|
|
129
|
+
return value * 96 / 2.54;
|
|
130
|
+
case "mm":
|
|
131
|
+
return value * 96 / 2.54 / 10;
|
|
132
|
+
case "in":
|
|
133
|
+
return value * 96;
|
|
134
|
+
case "pt":
|
|
135
|
+
return value * 72;
|
|
136
|
+
case "pc":
|
|
137
|
+
return value * 72 / 12;
|
|
138
|
+
default:
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var matchQuery_exports = {};
|
|
24
|
+
__export(matchQuery_exports, {
|
|
25
|
+
matchQuery: () => matchQuery,
|
|
26
|
+
parseQuery: () => parseQuery
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(matchQuery_exports);
|
|
29
|
+
var RE_MEDIA_QUERY = /(?:(only|not)?\s*([^\s()]+)(?:\s*and)?\s*)?(.+)?/i,
|
|
30
|
+
RE_MQ_EXPRESSION = /\(\s*([^\s:)]+)\s*(?::\s*([^\s)]+))?\s*\)/,
|
|
31
|
+
RE_MQ_FEATURE = /^(?:(min|max)-)?(.+)/,
|
|
32
|
+
RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?$/,
|
|
33
|
+
RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?$/;
|
|
34
|
+
function matchQuery(mediaQuery, values) {
|
|
35
|
+
return parseQuery(mediaQuery).some(function (query) {
|
|
36
|
+
if (query) {
|
|
37
|
+
var inverse = query.inverse,
|
|
38
|
+
typeMatch = query.type === "all" || values.type === query.type;
|
|
39
|
+
if (typeMatch && inverse || !(typeMatch || inverse)) return !1;
|
|
40
|
+
var expressionsMatch = query.expressions.every(function (expression) {
|
|
41
|
+
var feature = expression.feature,
|
|
42
|
+
modifier = expression.modifier,
|
|
43
|
+
expValue = expression.value,
|
|
44
|
+
value = values[feature];
|
|
45
|
+
if (!value) return !1;
|
|
46
|
+
switch (feature) {
|
|
47
|
+
case "orientation":
|
|
48
|
+
case "scan":
|
|
49
|
+
return value.toLowerCase() === expValue.toLowerCase();
|
|
50
|
+
case "width":
|
|
51
|
+
case "height":
|
|
52
|
+
case "device-width":
|
|
53
|
+
case "device-height":
|
|
54
|
+
expValue = toPx(expValue), value = toPx(value);
|
|
55
|
+
break;
|
|
56
|
+
case "resolution":
|
|
57
|
+
expValue = toDpi(expValue), value = toDpi(value);
|
|
58
|
+
break;
|
|
59
|
+
case "aspect-ratio":
|
|
60
|
+
case "device-aspect-ratio":
|
|
61
|
+
case /* Deprecated */
|
|
62
|
+
"device-pixel-ratio":
|
|
63
|
+
expValue = toDecimal(expValue), value = toDecimal(value);
|
|
64
|
+
break;
|
|
65
|
+
case "grid":
|
|
66
|
+
case "color":
|
|
67
|
+
case "color-index":
|
|
68
|
+
case "monochrome":
|
|
69
|
+
expValue = Number.parseInt(expValue, 10) || 1, value = Number.parseInt(value, 10) || 0;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
switch (modifier) {
|
|
73
|
+
case "min":
|
|
74
|
+
return value >= expValue;
|
|
75
|
+
case "max":
|
|
76
|
+
return value <= expValue;
|
|
77
|
+
default:
|
|
78
|
+
return value === expValue;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return expressionsMatch && !inverse || !expressionsMatch && inverse;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function parseQuery(mediaQuery) {
|
|
86
|
+
return mediaQuery.split(",").map(function (query) {
|
|
87
|
+
query = query.trim();
|
|
88
|
+
var captures = query.match(RE_MEDIA_QUERY);
|
|
89
|
+
if (!captures) return null;
|
|
90
|
+
var modifier = captures[1],
|
|
91
|
+
type = captures[2],
|
|
92
|
+
expressionsCapture = captures[3] || "",
|
|
93
|
+
expressions = expressionsCapture.match(/\([^)]+\)/g) || [];
|
|
94
|
+
return {
|
|
95
|
+
inverse: !!modifier && modifier.toLowerCase() === "not",
|
|
96
|
+
type: type ? type.toLowerCase() : "all",
|
|
97
|
+
expressions: expressions.map(function (expression) {
|
|
98
|
+
var captures2 = expression.match(RE_MQ_EXPRESSION),
|
|
99
|
+
feature = captures2[1].toLowerCase().match(RE_MQ_FEATURE);
|
|
100
|
+
return {
|
|
101
|
+
modifier: feature[1],
|
|
102
|
+
feature: feature[2],
|
|
103
|
+
value: captures2[2]
|
|
104
|
+
};
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function toDecimal(ratio) {
|
|
110
|
+
var decimal = Number(ratio),
|
|
111
|
+
numbers;
|
|
112
|
+
return decimal || (numbers = ratio.match(/^(\d+)\s*\/\s*(\d+)$/), decimal = numbers[1] / numbers[2]), decimal;
|
|
113
|
+
}
|
|
114
|
+
function toDpi(resolution) {
|
|
115
|
+
var _String_match,
|
|
116
|
+
value = Number.parseFloat(resolution),
|
|
117
|
+
units = (_String_match = String(resolution).match(RE_RESOLUTION_UNIT)) === null || _String_match === void 0 ? void 0 : _String_match[1];
|
|
118
|
+
switch (units) {
|
|
119
|
+
case "dpcm":
|
|
120
|
+
return value / 2.54;
|
|
121
|
+
case "dppx":
|
|
122
|
+
return value * 96;
|
|
123
|
+
default:
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function toPx(length) {
|
|
128
|
+
var _String_match,
|
|
129
|
+
value = Number.parseFloat(length),
|
|
130
|
+
units = (_String_match = String(length).match(RE_LENGTH_UNIT)) === null || _String_match === void 0 ? void 0 : _String_match[1];
|
|
131
|
+
switch (units) {
|
|
132
|
+
case "em":
|
|
133
|
+
return value * 16;
|
|
134
|
+
case "rem":
|
|
135
|
+
return value * 16;
|
|
136
|
+
case "cm":
|
|
137
|
+
return value * 96 / 2.54;
|
|
138
|
+
case "mm":
|
|
139
|
+
return value * 96 / 2.54 / 10;
|
|
140
|
+
case "in":
|
|
141
|
+
return value * 96;
|
|
142
|
+
case "pt":
|
|
143
|
+
return value * 72;
|
|
144
|
+
case "pc":
|
|
145
|
+
return value * 72 / 12;
|
|
146
|
+
default:
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=matchQuery.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","matchQuery_exports","__export","matchQuery","parseQuery","module","exports","RE_MEDIA_QUERY","RE_MQ_EXPRESSION","RE_MQ_FEATURE","RE_LENGTH_UNIT","RE_RESOLUTION_UNIT","mediaQuery","values","some","query","inverse","typeMatch","type","expressionsMatch","expressions","every","expression","feature","modifier","expValue","toLowerCase","toPx","toDpi","toDecimal","Number","parseInt","split","map","trim","captures","match","expressionsCapture","captures2","ratio","decimal","numbers","resolution","_String_match","parseFloat","units","String","length"],"sources":["../../src/matchQuery.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,kBAAA;AAAAC,QAAA,CAAAD,kBAAA;EAAAE,UAAA,EAAAA,CAAA,KAAAA,UAAA;EAAAC,UAAA,EAAAA,CAAA,KAAAA;AAAA;AAQAC,MAAM,CAAAC,OAAA,GAAAV,YAAiB,CAAAK,kBAAA;AAMhB,IAAAM,cAAS,GAAW,mDAA0D;EAAAC,gBAAA;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K,GAAAV,MACH,CAAAS,KAAA;IAAUE,OAAM;EAKpB,OAAAD,OAAA,KAAAC,OAAA,GAAAF,KAAA,CAAAH,KAAA,0BAAAI,OAAA,GAAAC,OAAA,MAAAA,OAAA,MAAAD,OAAA;AAEA;AACE,SAAMZ,MAAAc,UAAe;EAGrB,IAAAC,aAFqB;IAAA3C,KAAA,GAAY8B,MAAM,CAAAc,UAAA,CAAAF,UAAsB,CAAC;IAAAG,KAE/C,IAAAF,aAAA,GAAAG,MAAA,CAAAJ,UAAA,EAAAN,KAAA,CAAAzB,kBAAA,eAAAgC,aAAA,uBAAAA,aAAA;EAAA,QACRE,KAAA;IACH,WAAO;MACT,OAAK7C,KAAA;IACH,WAAO;MACT,OAAAA,KAAA;IACE;MACJ,OAAAA,KAAA;EACF;AAEA;AACE,SAAM2B,KAAAoB,MAAQ;EAEd,IAAAJ,aADqB;IAAA3C,KAAQ,GAAA8B,MAAM,CAAAc,UAAc,CAAAG,MAClC;IAAAF,KAAA,IAAAF,aAAA,GAAAG,MAAA,CAAAC,MAAA,EAAAX,KAAA,CAAA1B,cAAA,eAAAiC,aAAA,uBAAAA,aAAA;EAAA,QACRE,KAAA;IACH,SAAO;MACT,OAAK7C,KAAA;IACH,UAAO;MACT,OAAKA,KAAA;IACH,SAAQ;MACV,OAAKA,KAAA;IACH,SAAQ;MACV,OAAKA,KAAA;IACH,SAAO;MACT,OAAKA,KAAA;IACH,SAAO;MACT,OAAKA,KAAA;IACH,SAAQ;MACV,OAAAA,KAAA;IACE;MACJ,OAAAA,KAAA;EACF","ignoreList":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var mediaQueryList_exports = {};
|
|
22
|
+
__export(mediaQueryList_exports, {
|
|
23
|
+
NativeMediaQueryList: () => NativeMediaQueryList
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(mediaQueryList_exports);
|
|
26
|
+
var import_react_native = require("react-native-web"),
|
|
27
|
+
import_matchQuery = require("./matchQuery.cjs");
|
|
28
|
+
class NativeMediaQueryList {
|
|
29
|
+
constructor(query) {
|
|
30
|
+
this.query = query;
|
|
31
|
+
this.notify(), import_react_native.Dimensions.addEventListener("change", () => {
|
|
32
|
+
this.notify();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
listeners = [];
|
|
36
|
+
get orientation() {
|
|
37
|
+
const windowDimensions = import_react_native.Dimensions.get("window");
|
|
38
|
+
return windowDimensions.height > windowDimensions.width ? "portrait" : "landscape";
|
|
39
|
+
}
|
|
40
|
+
notify() {
|
|
41
|
+
this.listeners.forEach(listener => {
|
|
42
|
+
listener(this.orientation);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
addListener(listener) {
|
|
46
|
+
this.listeners.push(listener);
|
|
47
|
+
}
|
|
48
|
+
removeListener(listener) {
|
|
49
|
+
const index = this.listeners.indexOf(listener);
|
|
50
|
+
index !== -1 && this.listeners.splice(index, 1);
|
|
51
|
+
}
|
|
52
|
+
match(query, {
|
|
53
|
+
width,
|
|
54
|
+
height
|
|
55
|
+
}) {
|
|
56
|
+
return (0, import_matchQuery.matchQuery)(query, {
|
|
57
|
+
type: "screen",
|
|
58
|
+
orientation: height > width ? "portrait" : "landscape",
|
|
59
|
+
"device-width": width,
|
|
60
|
+
"device-height": height
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
get matches() {
|
|
64
|
+
const windowDimensions = import_react_native.Dimensions.get("window");
|
|
65
|
+
return (0, import_matchQuery.matchQuery)(this.query, {
|
|
66
|
+
type: "screen",
|
|
67
|
+
orientation: this.orientation,
|
|
68
|
+
...windowDimensions,
|
|
69
|
+
"device-width": windowDimensions.width,
|
|
70
|
+
"device-height": windowDimensions.height
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|