@hanzogui/react-native-media-driver 2.0.0-rc.41-hanzoai.5

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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/createMedia.cjs +33 -0
  3. package/dist/cjs/createMedia.native.js +36 -0
  4. package/dist/cjs/createMedia.native.js.map +1 -0
  5. package/dist/cjs/index.cjs +21 -0
  6. package/dist/cjs/index.native.js +24 -0
  7. package/dist/cjs/index.native.js.map +1 -0
  8. package/dist/cjs/matchMedia.cjs +28 -0
  9. package/dist/cjs/matchMedia.native.js +34 -0
  10. package/dist/cjs/matchMedia.native.js.map +1 -0
  11. package/dist/cjs/matchQuery.cjs +158 -0
  12. package/dist/cjs/matchQuery.native.js +163 -0
  13. package/dist/cjs/matchQuery.native.js.map +1 -0
  14. package/dist/cjs/mediaQueryList.cjs +78 -0
  15. package/dist/cjs/mediaQueryList.native.js +134 -0
  16. package/dist/cjs/mediaQueryList.native.js.map +1 -0
  17. package/dist/esm/createMedia.mjs +8 -0
  18. package/dist/esm/createMedia.mjs.map +1 -0
  19. package/dist/esm/createMedia.native.js +8 -0
  20. package/dist/esm/createMedia.native.js.map +1 -0
  21. package/dist/esm/index.js +3 -0
  22. package/dist/esm/index.js.map +1 -0
  23. package/dist/esm/index.mjs +3 -0
  24. package/dist/esm/index.mjs.map +1 -0
  25. package/dist/esm/index.native.js +3 -0
  26. package/dist/esm/index.native.js.map +1 -0
  27. package/dist/esm/matchMedia.mjs +3 -0
  28. package/dist/esm/matchMedia.mjs.map +1 -0
  29. package/dist/esm/matchMedia.native.js +6 -0
  30. package/dist/esm/matchMedia.native.js.map +1 -0
  31. package/dist/esm/matchQuery.mjs +132 -0
  32. package/dist/esm/matchQuery.mjs.map +1 -0
  33. package/dist/esm/matchQuery.native.js +134 -0
  34. package/dist/esm/matchQuery.native.js.map +1 -0
  35. package/dist/esm/mediaQueryList.mjs +53 -0
  36. package/dist/esm/mediaQueryList.mjs.map +1 -0
  37. package/dist/esm/mediaQueryList.native.js +106 -0
  38. package/dist/esm/mediaQueryList.native.js.map +1 -0
  39. package/package.json +47 -0
  40. package/src/createMedia.ts +19 -0
  41. package/src/index.ts +2 -0
  42. package/src/matchMedia.native.ts +7 -0
  43. package/src/matchMedia.ts +5 -0
  44. package/src/matchQuery.ts +176 -0
  45. package/src/mediaQueryList.ts +60 -0
  46. package/types/createMedia.d.ts +10 -0
  47. package/types/createMedia.d.ts.map +11 -0
  48. package/types/index.d.ts +4 -0
  49. package/types/index.d.ts.map +11 -0
  50. package/types/matchMedia.d.ts +4 -0
  51. package/types/matchMedia.d.ts.map +11 -0
  52. package/types/matchMedia.native.d.ts +4 -0
  53. package/types/matchMedia.native.d.ts.map +11 -0
  54. package/types/matchQuery.d.ts +12 -0
  55. package/types/matchQuery.d.ts.map +11 -0
  56. package/types/mediaQueryList.d.ts +20 -0
  57. 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,33 @@
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: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
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
+ var import_matchMedia = require("./matchMedia.cjs");
30
+ function createMedia(media) {
31
+ (0, import_web.setupMatchMedia)(import_matchMedia.matchMedia);
32
+ return media;
33
+ }
@@ -0,0 +1,36 @@
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: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var createMedia_exports = {};
26
+ __export(createMedia_exports, {
27
+ createMedia: () => createMedia
28
+ });
29
+ module.exports = __toCommonJS(createMedia_exports);
30
+ var import_web = require("@hanzogui/web");
31
+ var import_matchMedia = require("./matchMedia.native.js");
32
+ function createMedia(media) {
33
+ (0, import_web.setupMatchMedia)(import_matchMedia.matchMedia);
34
+ return media;
35
+ }
36
+ //# 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,mBAAA;AAEhC,IAAAK,UAAA,GAAAC,OAA2B;AAMpB,IAAAC,iBAIL,GAAAD,OAAa;AAGb,SAAAJ,YAAAM,KAAA;EACA,IAAAH,UAAO,CAAAI,eAAA,EAAAF,iBAAA,CAAAG,UAAA;EACT,OAAAF,KAAA","ignoreList":[]}
@@ -0,0 +1,21 @@
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") {
7
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
+ get: () => from[key],
9
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
+ });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
16
+ value: true
17
+ }), mod);
18
+ var index_exports = {};
19
+ module.exports = __toCommonJS(index_exports);
20
+ __reExport(index_exports, require("./createMedia.cjs"), module.exports);
21
+ __reExport(index_exports, require("./matchMedia.cjs"), module.exports);
@@ -0,0 +1,24 @@
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") {
9
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
+ get: () => from[key],
11
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
+ });
13
+ }
14
+ return to;
15
+ };
16
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
18
+ value: true
19
+ }), mod);
20
+ var index_exports = {};
21
+ module.exports = __toCommonJS(index_exports);
22
+ __reExport(index_exports, require("./createMedia.native.js"), module.exports);
23
+ __reExport(index_exports, require("./matchMedia.native.js"), module.exports);
24
+ //# 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,28 @@
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: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var matchMedia_exports = {};
24
+ __export(matchMedia_exports, {
25
+ matchMedia: () => matchMedia
26
+ });
27
+ module.exports = __toCommonJS(matchMedia_exports);
28
+ const matchMedia = globalThis["matchMedia"];
@@ -0,0 +1,34 @@
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: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var matchMedia_native_exports = {};
26
+ __export(matchMedia_native_exports, {
27
+ matchMedia: () => matchMedia
28
+ });
29
+ module.exports = __toCommonJS(matchMedia_native_exports);
30
+ var import_mediaQueryList = require("./mediaQueryList.native.js");
31
+ var matchMedia = function (query) {
32
+ return new import_mediaQueryList.NativeMediaQueryList(query);
33
+ };
34
+ //# 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;AAC9B,IAAIL,UAAA,GAAa,SAAAA,CAASM,KAAA,EAAO;EACpC,OAAO,IAAIF,qBAAA,CAAAG,oBAAA,CAAqBD,KAAK;AACzC","ignoreList":[]}
@@ -0,0 +1,158 @@
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: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var matchQuery_exports = {};
24
+ __export(matchQuery_exports, {
25
+ matchQuery: () => matchQuery,
26
+ parseQuery: () => parseQuery
27
+ });
28
+ module.exports = __toCommonJS(matchQuery_exports);
29
+ const RE_MEDIA_QUERY = /(?:(only|not)?\s*([^\s()]+)(?:\s*and)?\s*)?(.+)?/i;
30
+ const RE_MQ_EXPRESSION = /\(\s*([^\s:)]+)\s*(?::\s*([^\s)]+))?\s*\)/;
31
+ const RE_MQ_FEATURE = /^(?:(min|max)-)?(.+)/;
32
+ const RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?$/;
33
+ const RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?$/;
34
+ function matchQuery(mediaQuery, values) {
35
+ return parseQuery(mediaQuery).some(query => {
36
+ if (!query) return;
37
+ const inverse = query.inverse;
38
+ const typeMatch = query.type === "all" || values.type === query.type;
39
+ if (typeMatch && inverse || !(typeMatch || inverse)) {
40
+ return false;
41
+ }
42
+ const expressionsMatch = query.expressions.every(expression => {
43
+ const feature = expression.feature;
44
+ const modifier = expression.modifier;
45
+ let expValue = expression.value;
46
+ let value = values[feature];
47
+ if (!value) {
48
+ return false;
49
+ }
50
+ switch (feature) {
51
+ case "orientation":
52
+ case "scan":
53
+ return value.toLowerCase() === expValue.toLowerCase();
54
+ case "width":
55
+ case "height":
56
+ case "device-width":
57
+ case "device-height":
58
+ expValue = toPx(expValue);
59
+ value = toPx(value);
60
+ break;
61
+ case "resolution":
62
+ expValue = toDpi(expValue);
63
+ value = toDpi(value);
64
+ break;
65
+ case "aspect-ratio":
66
+ case "device-aspect-ratio":
67
+ case /* Deprecated */
68
+ "device-pixel-ratio":
69
+ expValue = toDecimal(expValue);
70
+ value = toDecimal(value);
71
+ break;
72
+ case "grid":
73
+ case "color":
74
+ case "color-index":
75
+ case "monochrome":
76
+ expValue = Number.parseInt(expValue, 10) || 1;
77
+ value = Number.parseInt(value, 10) || 0;
78
+ break;
79
+ }
80
+ switch (modifier) {
81
+ case "min":
82
+ return value >= expValue;
83
+ case "max":
84
+ return value <= expValue;
85
+ default:
86
+ return value === expValue;
87
+ }
88
+ });
89
+ return expressionsMatch && !inverse || !expressionsMatch && inverse;
90
+ });
91
+ }
92
+ function parseQuery(mediaQuery) {
93
+ return mediaQuery.split(",").map(query => {
94
+ query = query.trim();
95
+ const captures = query.match(RE_MEDIA_QUERY);
96
+ if (!captures) return null;
97
+ const modifier = captures[1];
98
+ const type = captures[2];
99
+ const expressionsCapture = captures[3] || "";
100
+ const expressions = expressionsCapture.match(/\([^)]+\)/g) || [];
101
+ return {
102
+ inverse: !!modifier && modifier.toLowerCase() === "not",
103
+ type: type ? type.toLowerCase() : "all",
104
+ expressions: expressions.map(expression => {
105
+ const captures2 = expression.match(RE_MQ_EXPRESSION);
106
+ const feature = captures2[1].toLowerCase().match(RE_MQ_FEATURE);
107
+ return {
108
+ modifier: feature[1],
109
+ feature: feature[2],
110
+ value: captures2[2]
111
+ };
112
+ })
113
+ };
114
+ });
115
+ }
116
+ function toDecimal(ratio) {
117
+ let decimal = Number(ratio);
118
+ let numbers;
119
+ if (!decimal) {
120
+ numbers = ratio.match(/^(\d+)\s*\/\s*(\d+)$/);
121
+ decimal = numbers[1] / numbers[2];
122
+ }
123
+ return decimal;
124
+ }
125
+ function toDpi(resolution) {
126
+ const value = Number.parseFloat(resolution);
127
+ const units = String(resolution).match(RE_RESOLUTION_UNIT)?.[1];
128
+ switch (units) {
129
+ case "dpcm":
130
+ return value / 2.54;
131
+ case "dppx":
132
+ return value * 96;
133
+ default:
134
+ return value;
135
+ }
136
+ }
137
+ function toPx(length) {
138
+ const value = Number.parseFloat(length);
139
+ const units = String(length).match(RE_LENGTH_UNIT)?.[1];
140
+ switch (units) {
141
+ case "em":
142
+ return value * 16;
143
+ case "rem":
144
+ return value * 16;
145
+ case "cm":
146
+ return value * 96 / 2.54;
147
+ case "mm":
148
+ return value * 96 / 2.54 / 10;
149
+ case "in":
150
+ return value * 96;
151
+ case "pt":
152
+ return value * 72;
153
+ case "pc":
154
+ return value * 72 / 12;
155
+ default:
156
+ return value;
157
+ }
158
+ }
@@ -0,0 +1,163 @@
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: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var matchQuery_exports = {};
26
+ __export(matchQuery_exports, {
27
+ matchQuery: () => matchQuery,
28
+ parseQuery: () => parseQuery
29
+ });
30
+ module.exports = __toCommonJS(matchQuery_exports);
31
+ var RE_MEDIA_QUERY = /(?:(only|not)?\s*([^\s()]+)(?:\s*and)?\s*)?(.+)?/i;
32
+ var RE_MQ_EXPRESSION = /\(\s*([^\s:)]+)\s*(?::\s*([^\s)]+))?\s*\)/;
33
+ var RE_MQ_FEATURE = /^(?:(min|max)-)?(.+)/;
34
+ var RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?$/;
35
+ var RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?$/;
36
+ function matchQuery(mediaQuery, values) {
37
+ return parseQuery(mediaQuery).some(function (query) {
38
+ if (!query) return;
39
+ var inverse = query.inverse;
40
+ var typeMatch = query.type === "all" || values.type === query.type;
41
+ if (typeMatch && inverse || !(typeMatch || inverse)) {
42
+ return false;
43
+ }
44
+ var expressionsMatch = query.expressions.every(function (expression) {
45
+ var feature = expression.feature;
46
+ var modifier = expression.modifier;
47
+ var expValue = expression.value;
48
+ var value = values[feature];
49
+ if (!value) {
50
+ return false;
51
+ }
52
+ switch (feature) {
53
+ case "orientation":
54
+ case "scan":
55
+ return value.toLowerCase() === expValue.toLowerCase();
56
+ case "width":
57
+ case "height":
58
+ case "device-width":
59
+ case "device-height":
60
+ expValue = toPx(expValue);
61
+ value = toPx(value);
62
+ break;
63
+ case "resolution":
64
+ expValue = toDpi(expValue);
65
+ value = toDpi(value);
66
+ break;
67
+ case "aspect-ratio":
68
+ case "device-aspect-ratio":
69
+ case /* Deprecated */
70
+ "device-pixel-ratio":
71
+ expValue = toDecimal(expValue);
72
+ value = toDecimal(value);
73
+ break;
74
+ case "grid":
75
+ case "color":
76
+ case "color-index":
77
+ case "monochrome":
78
+ expValue = Number.parseInt(expValue, 10) || 1;
79
+ value = Number.parseInt(value, 10) || 0;
80
+ break;
81
+ }
82
+ switch (modifier) {
83
+ case "min":
84
+ return value >= expValue;
85
+ case "max":
86
+ return value <= expValue;
87
+ default:
88
+ return value === expValue;
89
+ }
90
+ });
91
+ return expressionsMatch && !inverse || !expressionsMatch && inverse;
92
+ });
93
+ }
94
+ function parseQuery(mediaQuery) {
95
+ return mediaQuery.split(",").map(function (query) {
96
+ query = query.trim();
97
+ var captures = query.match(RE_MEDIA_QUERY);
98
+ if (!captures) return null;
99
+ var modifier = captures[1];
100
+ var type = captures[2];
101
+ var expressionsCapture = captures[3] || "";
102
+ var expressions = expressionsCapture.match(/\([^)]+\)/g) || [];
103
+ return {
104
+ inverse: !!modifier && modifier.toLowerCase() === "not",
105
+ type: type ? type.toLowerCase() : "all",
106
+ expressions: expressions.map(function (expression) {
107
+ var captures2 = expression.match(RE_MQ_EXPRESSION);
108
+ var feature = captures2[1].toLowerCase().match(RE_MQ_FEATURE);
109
+ return {
110
+ modifier: feature[1],
111
+ feature: feature[2],
112
+ value: captures2[2]
113
+ };
114
+ })
115
+ };
116
+ });
117
+ }
118
+ function toDecimal(ratio) {
119
+ var decimal = Number(ratio);
120
+ var numbers;
121
+ if (!decimal) {
122
+ numbers = ratio.match(/^(\d+)\s*\/\s*(\d+)$/);
123
+ decimal = numbers[1] / numbers[2];
124
+ }
125
+ return decimal;
126
+ }
127
+ function toDpi(resolution) {
128
+ var _String_match;
129
+ var value = Number.parseFloat(resolution);
130
+ var units = (_String_match = String(resolution).match(RE_RESOLUTION_UNIT)) === null || _String_match === void 0 ? void 0 : _String_match[1];
131
+ switch (units) {
132
+ case "dpcm":
133
+ return value / 2.54;
134
+ case "dppx":
135
+ return value * 96;
136
+ default:
137
+ return value;
138
+ }
139
+ }
140
+ function toPx(length) {
141
+ var _String_match;
142
+ var value = Number.parseFloat(length);
143
+ var units = (_String_match = String(length).match(RE_LENGTH_UNIT)) === null || _String_match === void 0 ? void 0 : _String_match[1];
144
+ switch (units) {
145
+ case "em":
146
+ return value * 16;
147
+ case "rem":
148
+ return value * 16;
149
+ case "cm":
150
+ return value * 96 / 2.54;
151
+ case "mm":
152
+ return value * 96 / 2.54 / 10;
153
+ case "in":
154
+ return value * 96;
155
+ case "pt":
156
+ return value * 72;
157
+ case "pc":
158
+ return value * 72 / 12;
159
+ default:
160
+ return value;
161
+ }
162
+ }
163
+ //# 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;AACvB,IAAAM,cAAM,sDAAmB;AACzB,IAAAC,gBAAM,GAAgB;AACtB,IAAAC,aAAM,yBAAiB;AACvB,IAAAC,cAAM,iCAAqB;AAEpB,IAAAC,kBAAoB,sBAA0D;AACnF,SAAOR,WAAWS,UAAU,EAAEC,MAAM;EAClC,OAAKT,UAAO,CAAAQ,UAAA,EAAAE,IAAA,WAAAC,KAAA;IAEZ,KAAAA,KAAM;IAIN,IAAAC,OAAM,GAAAD,KAAY,CAAAC,OAAM;IAGxB,IAAKC,SAAA,GAAAF,KAAa,CAAAG,IAAA,KAAc,SAAAL,MAAa,CAAAK,IAAA,KAAUH,KAAA,CAAAG,IAAA;IACrD,IAAAD,SAAO,IAAAD,OAAA,MAAAC,SAAA,IAAAD,OAAA;MACT;IAEA;IACE,IAAAG,gBAAgB,GAAAJ,KAAA,CAAWK,WAAA,CAAAC,KAAA,WAAAC,UAAA;MAC3B,IA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AA;IACX;MACF,OAAAA,KAAA;EAEA;AACE;AACA,SAAM2B,KAAAoB,MAAQ;EACd,IAAAJ,aAAe;EAAA,IACb3C,KAAK,GAAA8B,MAAA,CAAAc,UAAA,CAAAG,MAAA;EACH,IAAAF,KAAA,GAAO,CAAAF,aAAQ,GAAAG,MAAA,CAAAC,MAAA,EAAAX,KAAA,CAAA1B,cAAA,eAAAiC,aAAA,uBAAAA,aAAA;EAAA,QACZE,KAAA;IACH,SAAO;MACT,OAAK7C,KAAA;IACH,UAAQ;MACV,OAAKA,KAAA;IACH,SAAQ;MACV,OAAKA,KAAA;IACH,SAAO;MACT,OAAKA,KAAA;IACH,SAAO;MACT,OAAKA,KAAA;IACH,SAAQ;MACV,OAAAA,KAAA;IACE,SAAO;MACX,OAAAA,KAAA;IACF","ignoreList":[]}
@@ -0,0 +1,78 @@
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: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var mediaQueryList_exports = {};
24
+ __export(mediaQueryList_exports, {
25
+ NativeMediaQueryList: () => NativeMediaQueryList
26
+ });
27
+ module.exports = __toCommonJS(mediaQueryList_exports);
28
+ var import_react_native = require("react-native-web");
29
+ var import_matchQuery = require("./matchQuery.cjs");
30
+ class NativeMediaQueryList {
31
+ constructor(query) {
32
+ this.query = query;
33
+ this.notify();
34
+ import_react_native.Dimensions.addEventListener("change", () => {
35
+ this.notify();
36
+ });
37
+ }
38
+ query;
39
+ listeners = [];
40
+ get orientation() {
41
+ const windowDimensions = import_react_native.Dimensions.get("window");
42
+ return windowDimensions.height > windowDimensions.width ? "portrait" : "landscape";
43
+ }
44
+ notify() {
45
+ this.listeners.forEach(listener => {
46
+ listener(this.orientation);
47
+ });
48
+ }
49
+ addListener(listener) {
50
+ this.listeners.push(listener);
51
+ }
52
+ removeListener(listener) {
53
+ const index = this.listeners.indexOf(listener);
54
+ if (index !== -1) this.listeners.splice(index, 1);
55
+ }
56
+ match(query, {
57
+ width,
58
+ height
59
+ }) {
60
+ return (0, import_matchQuery.matchQuery)(query, {
61
+ type: "screen",
62
+ orientation: height > width ? "portrait" : "landscape",
63
+ "device-width": width,
64
+ "device-height": height
65
+ });
66
+ }
67
+ get matches() {
68
+ const windowDimensions = import_react_native.Dimensions.get("window");
69
+ const matches = (0, import_matchQuery.matchQuery)(this.query, {
70
+ type: "screen",
71
+ orientation: this.orientation,
72
+ ...windowDimensions,
73
+ "device-width": windowDimensions.width,
74
+ "device-height": windowDimensions.height
75
+ });
76
+ return matches;
77
+ }
78
+ }