@tamagui/react-native-media-driver 1.88.13 → 1.89.0-1706308641099

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 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,6 @@
1
+ import { setupMatchMedia } from "@tamagui/web";
2
+ import { matchMedia } from "./matchMedia.mjs";
3
+ function createMedia(media) {
4
+ return setupMatchMedia(matchMedia), media;
5
+ }
6
+ export { createMedia };
@@ -0,0 +1,2 @@
1
+ export * from "./createMedia.mjs";
2
+ export * from "./matchMedia.mjs";
@@ -0,0 +1,2 @@
1
+ const matchMedia = globalThis.matchMedia;
2
+ export { matchMedia };
@@ -0,0 +1,116 @@
1
+ const RE_MEDIA_QUERY = /(?:(only|not)?\s*([^\s\(\)]+)(?:\s*and)?\s*)?(.+)?/i,
2
+ RE_MQ_EXPRESSION = /\(\s*([^\s\:\)]+)\s*(?:\:\s*([^\s\)]+))?\s*\)/,
3
+ RE_MQ_FEATURE = /^(?:(min|max)-)?(.+)/,
4
+ RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?$/,
5
+ RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?$/;
6
+ function matchQuery(mediaQuery, values) {
7
+ return parseQuery(mediaQuery).some(query => {
8
+ if (!query) return;
9
+ const inverse = query.inverse,
10
+ typeMatch = query.type === "all" || values.type === query.type;
11
+ if (typeMatch && inverse || !(typeMatch || inverse)) return !1;
12
+ const expressionsMatch = query.expressions.every(expression => {
13
+ const feature = expression.feature,
14
+ modifier = expression.modifier;
15
+ let expValue = expression.value,
16
+ value = values[feature];
17
+ if (!value) return !1;
18
+ switch (feature) {
19
+ case "orientation":
20
+ case "scan":
21
+ return value.toLowerCase() === expValue.toLowerCase();
22
+ case "width":
23
+ case "height":
24
+ case "device-width":
25
+ case "device-height":
26
+ expValue = toPx(expValue), value = toPx(value);
27
+ break;
28
+ case "resolution":
29
+ expValue = toDpi(expValue), value = toDpi(value);
30
+ break;
31
+ case "aspect-ratio":
32
+ case "device-aspect-ratio":
33
+ case /* Deprecated */
34
+ "device-pixel-ratio":
35
+ expValue = toDecimal(expValue), value = toDecimal(value);
36
+ break;
37
+ case "grid":
38
+ case "color":
39
+ case "color-index":
40
+ case "monochrome":
41
+ expValue = parseInt(expValue, 10) || 1, value = parseInt(value, 10) || 0;
42
+ break;
43
+ }
44
+ switch (modifier) {
45
+ case "min":
46
+ return value >= expValue;
47
+ case "max":
48
+ return value <= expValue;
49
+ default:
50
+ return value === expValue;
51
+ }
52
+ });
53
+ return expressionsMatch && !inverse || !expressionsMatch && inverse;
54
+ });
55
+ }
56
+ function parseQuery(mediaQuery) {
57
+ return mediaQuery.split(",").map(function (query) {
58
+ query = query.trim();
59
+ const captures = query.match(RE_MEDIA_QUERY);
60
+ if (!captures) return null;
61
+ const modifier = captures[1],
62
+ type = captures[2],
63
+ expressions = (captures[3] || "").match(/\([^\)]+\)/g) || [];
64
+ return {
65
+ inverse: !!modifier && modifier.toLowerCase() === "not",
66
+ type: type ? type.toLowerCase() : "all",
67
+ expressions: expressions.map(function (expression) {
68
+ var captures2 = expression.match(RE_MQ_EXPRESSION),
69
+ feature = captures2[1].toLowerCase().match(RE_MQ_FEATURE);
70
+ return {
71
+ modifier: feature[1],
72
+ feature: feature[2],
73
+ value: captures2[2]
74
+ };
75
+ })
76
+ };
77
+ });
78
+ }
79
+ function toDecimal(ratio) {
80
+ var decimal = Number(ratio),
81
+ numbers;
82
+ return decimal || (numbers = ratio.match(/^(\d+)\s*\/\s*(\d+)$/), decimal = numbers[1] / numbers[2]), decimal;
83
+ }
84
+ function toDpi(resolution) {
85
+ const value = parseFloat(resolution);
86
+ switch (String(resolution).match(RE_RESOLUTION_UNIT)?.[1]) {
87
+ case "dpcm":
88
+ return value / 2.54;
89
+ case "dppx":
90
+ return value * 96;
91
+ default:
92
+ return value;
93
+ }
94
+ }
95
+ function toPx(length) {
96
+ const value = parseFloat(length);
97
+ switch (String(length).match(RE_LENGTH_UNIT)?.[1]) {
98
+ case "em":
99
+ return value * 16;
100
+ case "rem":
101
+ return value * 16;
102
+ case "cm":
103
+ return value * 96 / 2.54;
104
+ case "mm":
105
+ return value * 96 / 2.54 / 10;
106
+ case "in":
107
+ return value * 96;
108
+ case "pt":
109
+ return value * 72;
110
+ case "pc":
111
+ return value * 72 / 12;
112
+ default:
113
+ return value;
114
+ }
115
+ }
116
+ export { matchQuery, parseQuery };
@@ -0,0 +1,49 @@
1
+ import { Dimensions } from "react-native-web";
2
+ import { matchQuery } from "./matchQuery.mjs";
3
+ class NativeMediaQueryList {
4
+ constructor(query) {
5
+ this.query = query;
6
+ this.notify(), Dimensions.addEventListener("change", () => {
7
+ this.notify();
8
+ });
9
+ }
10
+ listeners = [];
11
+ get orientation() {
12
+ const windowDimensions = Dimensions.get("window");
13
+ return windowDimensions.height > windowDimensions.width ? "portrait" : "landscape";
14
+ }
15
+ notify() {
16
+ this.listeners.forEach(listener => {
17
+ listener(this.orientation);
18
+ });
19
+ }
20
+ addListener(listener) {
21
+ this.listeners.push(listener);
22
+ }
23
+ removeListener(listener) {
24
+ const index = this.listeners.indexOf(listener);
25
+ index !== -1 && this.listeners.splice(index, 1);
26
+ }
27
+ match(query, {
28
+ width,
29
+ height
30
+ }) {
31
+ return matchQuery(query, {
32
+ type: "screen",
33
+ orientation: height > width ? "portrait" : "landscape",
34
+ "device-width": width,
35
+ "device-height": height
36
+ });
37
+ }
38
+ get matches() {
39
+ const windowDimensions = Dimensions.get("window");
40
+ return matchQuery(this.query, {
41
+ type: "screen",
42
+ orientation: this.orientation,
43
+ ...windowDimensions,
44
+ "device-width": windowDimensions.width,
45
+ "device-height": windowDimensions.height
46
+ });
47
+ }
48
+ }
49
+ export { NativeMediaQueryList };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/react-native-media-driver",
3
- "version": "1.88.13",
3
+ "version": "1.89.0-1706308641099",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -13,10 +13,10 @@
13
13
  ],
14
14
  "sideEffects": true,
15
15
  "dependencies": {
16
- "@tamagui/web": "1.88.13"
16
+ "@tamagui/web": "1.89.0-1706308641099"
17
17
  },
18
18
  "devDependencies": {
19
- "@tamagui/build": "1.88.13",
19
+ "@tamagui/build": "1.89.0-1706308641099",
20
20
  "react-native": "^0.72.6"
21
21
  },
22
22
  "peerDependencies": {