react-native-unistyles 2.0.0-alpha.1 → 2.0.0-alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -4
- package/cxx/UnistylesRuntime.cpp +255 -0
- package/cxx/UnistylesRuntime.h +60 -0
- package/ios/UnistylesHelpers.h +4 -0
- package/ios/UnistylesHelpers.mm +20 -0
- package/ios/UnistylesModule.h +10 -0
- package/ios/UnistylesModule.mm +158 -0
- package/lib/commonjs/common.js +26 -0
- package/lib/commonjs/common.js.map +1 -0
- package/lib/commonjs/core/UnistyleRegistry.js +38 -0
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/core/Unistyles.js +31 -0
- package/lib/commonjs/core/Unistyles.js.map +1 -0
- package/lib/commonjs/core/UnistylesModule.js +9 -0
- package/lib/commonjs/core/UnistylesModule.js.map +1 -0
- package/lib/commonjs/core/UnistylesRuntime.js +66 -0
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
- package/lib/commonjs/core/index.js +13 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/createStyleSheet.js +14 -0
- package/lib/commonjs/createStyleSheet.js.map +1 -0
- package/lib/commonjs/global.js +2 -0
- package/lib/commonjs/global.js.map +1 -0
- package/lib/commonjs/hooks/index.js +10 -3
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useInitialTheme.js +17 -0
- package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +54 -0
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
- package/lib/commonjs/index.js +35 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/common.js +2 -0
- package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
- package/lib/commonjs/types/index.js +26 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/mq.js +6 -0
- package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
- package/lib/commonjs/types/normalizer.js +6 -0
- package/lib/commonjs/types/normalizer.js.map +1 -0
- package/lib/commonjs/types/unistyles.js +6 -0
- package/lib/commonjs/types/unistyles.js.map +1 -0
- package/lib/commonjs/types/variants.js +2 -0
- package/lib/commonjs/types/variants.js.map +1 -0
- package/lib/commonjs/useStyles.js +49 -0
- package/lib/commonjs/useStyles.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.js +33 -80
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/common.js +10 -3
- package/lib/commonjs/utils/common.js.map +1 -1
- package/lib/commonjs/utils/index.js +46 -17
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/module.d.js +2 -0
- package/lib/commonjs/utils/module.d.js.map +1 -0
- package/lib/commonjs/utils/mq.js +89 -0
- package/lib/commonjs/utils/mq.js.map +1 -0
- package/lib/commonjs/utils/mqParser.js +86 -0
- package/lib/commonjs/utils/mqParser.js.map +1 -0
- package/lib/commonjs/utils/normalizeStyles.web.js +13 -13
- package/lib/commonjs/utils/normalizeStyles.web.js.map +1 -1
- package/lib/commonjs/utils/normalizer.js +89 -0
- package/lib/commonjs/utils/normalizer.js.map +1 -0
- package/lib/commonjs/utils/styles.js +29 -58
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/variants.js +17 -0
- package/lib/commonjs/utils/variants.js.map +1 -0
- package/lib/module/common.js +22 -0
- package/lib/module/common.js.map +1 -0
- package/lib/module/core/UnistyleRegistry.js +31 -0
- package/lib/module/core/UnistyleRegistry.js.map +1 -0
- package/lib/module/core/Unistyles.js +25 -0
- package/lib/module/core/Unistyles.js.map +1 -0
- package/lib/module/core/UnistylesModule.js +3 -0
- package/lib/module/core/UnistylesModule.js.map +1 -0
- package/lib/module/core/UnistylesRuntime.js +59 -0
- package/lib/module/core/UnistylesRuntime.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/createStyleSheet.js +7 -0
- package/lib/module/createStyleSheet.js.map +1 -0
- package/lib/module/global.js +2 -0
- package/lib/module/global.js.map +1 -0
- package/lib/module/hooks/index.js +2 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useInitialTheme.js +10 -0
- package/lib/module/hooks/useInitialTheme.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +47 -0
- package/lib/module/hooks/useUnistyles.js.map +1 -0
- package/lib/module/index.js +13 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/types/index.js +2 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/mq.js +2 -0
- package/lib/module/types/mq.js.map +1 -0
- package/lib/module/types/normalizer.js +2 -0
- package/lib/module/types/normalizer.js.map +1 -0
- package/lib/module/types/unistyles.js +2 -0
- package/lib/module/types/unistyles.js.map +1 -0
- package/lib/module/types/variants.js +2 -0
- package/lib/module/types/variants.js.map +1 -0
- package/lib/module/useStyles.js +42 -0
- package/lib/module/useStyles.js.map +1 -0
- package/lib/module/utils/breakpoints.js +34 -82
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/common.js +9 -1
- package/lib/module/utils/common.js.map +1 -1
- package/lib/module/utils/index.js +5 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/module.d.js +2 -0
- package/lib/module/utils/module.d.js.map +1 -0
- package/lib/module/utils/mq.js +83 -0
- package/lib/module/utils/mq.js.map +1 -0
- package/lib/module/utils/mqParser.js +79 -0
- package/lib/module/utils/mqParser.js.map +1 -0
- package/lib/module/utils/normalizeStyles.web.js +13 -13
- package/lib/module/utils/normalizeStyles.web.js.map +1 -1
- package/lib/module/utils/normalizer.js +79 -0
- package/lib/module/utils/normalizer.js.map +1 -0
- package/lib/module/utils/styles.js +28 -59
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/variants.js +10 -0
- package/lib/module/utils/variants.js.map +1 -0
- package/lib/typescript/src/common.d.ts +17 -0
- package/lib/typescript/src/common.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts +15 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/core/Unistyles.d.ts +13 -0
- package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts +6 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +24 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/createStyleSheet.d.ts +3 -0
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
- package/lib/typescript/src/global.d.ts +7 -0
- package/lib/typescript/src/global.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +2 -1
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
- package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +14 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +12 -13
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +3 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/lib/typescript/src/types/core.d.ts +28 -18
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +7 -2
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/mq.d.ts +3 -0
- package/lib/typescript/src/types/mq.d.ts.map +1 -0
- package/lib/typescript/src/types/normalizer.d.ts +20 -0
- package/lib/typescript/src/types/normalizer.d.ts.map +1 -0
- package/lib/typescript/src/types/unistyles.d.ts +37 -0
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
- package/lib/typescript/src/types/variants.d.ts +8 -0
- package/lib/typescript/src/types/variants.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +10 -0
- package/lib/typescript/src/useStyles.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +5 -62
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/common.d.ts +9 -1
- package/lib/typescript/src/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +5 -1
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +21 -0
- package/lib/typescript/src/utils/mq.d.ts.map +1 -0
- package/lib/typescript/src/utils/mqParser.d.ts +3 -0
- package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts +4 -1
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +1 -1
- package/lib/typescript/src/utils/normalizer.d.ts +11 -0
- package/lib/typescript/src/utils/normalizer.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +5 -49
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/variants.d.ts +3 -0
- package/lib/typescript/src/utils/variants.d.ts.map +1 -0
- package/package.json +33 -15
- package/react-native-unistyles.podspec +22 -0
- package/src/common.ts +19 -0
- package/src/core/UnistyleRegistry.ts +41 -0
- package/src/core/Unistyles.ts +34 -0
- package/src/core/UnistylesModule.ts +7 -0
- package/src/core/UnistylesRuntime.ts +73 -0
- package/src/core/index.ts +1 -0
- package/src/createStyleSheet.ts +9 -0
- package/src/global.ts +5 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useInitialTheme.ts +11 -0
- package/src/hooks/useUnistyles.ts +55 -0
- package/src/index.ts +30 -2
- package/src/types/breakpoints.ts +21 -20
- package/src/types/common.ts +2 -0
- package/src/types/core.ts +36 -24
- package/src/types/index.ts +7 -9
- package/src/types/mq.ts +3 -0
- package/src/types/normalizer.ts +29 -0
- package/src/types/unistyles.ts +45 -0
- package/src/types/variants.ts +11 -0
- package/src/useStyles.ts +62 -0
- package/src/utils/breakpoints.ts +46 -86
- package/src/utils/common.ts +10 -1
- package/src/utils/index.ts +5 -8
- package/src/utils/module.d.ts +3 -0
- package/src/utils/mq.ts +106 -0
- package/src/utils/mqParser.ts +99 -0
- package/src/utils/normalizeStyles.web.ts +21 -42
- package/src/utils/normalizer.ts +99 -0
- package/src/utils/styles.ts +46 -70
- package/src/utils/variants.ts +13 -0
- package/lib/commonjs/UnistylesTheme.js +0 -21
- package/lib/commonjs/UnistylesTheme.js.map +0 -1
- package/lib/commonjs/createUnistyles.js +0 -57
- package/lib/commonjs/createUnistyles.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.js +0 -10
- package/lib/commonjs/hooks/useDimensions.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.web.js +0 -31
- package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
- package/lib/commonjs/types/mediaQueries.js +0 -2
- package/lib/commonjs/utils/mediaQueries.js +0 -189
- package/lib/commonjs/utils/mediaQueries.js.map +0 -1
- package/lib/module/UnistylesTheme.js +0 -12
- package/lib/module/UnistylesTheme.js.map +0 -1
- package/lib/module/createUnistyles.js +0 -50
- package/lib/module/createUnistyles.js.map +0 -1
- package/lib/module/hooks/useDimensions.js +0 -3
- package/lib/module/hooks/useDimensions.js.map +0 -1
- package/lib/module/hooks/useDimensions.web.js +0 -24
- package/lib/module/hooks/useDimensions.web.js.map +0 -1
- package/lib/module/types/mediaQueries.js +0 -2
- package/lib/module/utils/mediaQueries.js +0 -176
- package/lib/module/utils/mediaQueries.js.map +0 -1
- package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
- package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
- package/lib/typescript/src/createUnistyles.d.ts +0 -10
- package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +0 -8
- package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +0 -130
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
- package/src/UnistylesTheme.tsx +0 -17
- package/src/__tests__/createUnistyles.spec.tsx +0 -192
- package/src/createUnistyles.ts +0 -70
- package/src/hooks/useDimensions.ts +0 -4
- package/src/hooks/useDimensions.web.ts +0 -30
- package/src/types/mediaQueries.ts +0 -10
- package/src/utils/mediaQueries.ts +0 -201
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.UnistylesRuntime = void 0;
|
7
|
+
var _common = require("../common");
|
8
|
+
class UnistylesRuntime {
|
9
|
+
constructor(unistylesBridge, registry) {
|
10
|
+
this.unistylesBridge = unistylesBridge;
|
11
|
+
this.registry = registry;
|
12
|
+
}
|
13
|
+
get colorScheme() {
|
14
|
+
return this.unistylesBridge.colorScheme;
|
15
|
+
}
|
16
|
+
get hasAdaptiveThemes() {
|
17
|
+
return this.unistylesBridge.hasAdaptiveThemes;
|
18
|
+
}
|
19
|
+
get sortedBreakpoints() {
|
20
|
+
return this.registry.sortedBreakpointPairs;
|
21
|
+
}
|
22
|
+
get themeName() {
|
23
|
+
return this.unistylesBridge.themeName;
|
24
|
+
}
|
25
|
+
get breakpoint() {
|
26
|
+
return this.unistylesBridge.breakpoint;
|
27
|
+
}
|
28
|
+
get screen() {
|
29
|
+
return {
|
30
|
+
width: this.unistylesBridge.screenWidth,
|
31
|
+
height: this.unistylesBridge.screenHeight
|
32
|
+
};
|
33
|
+
}
|
34
|
+
get orientation() {
|
35
|
+
const {
|
36
|
+
width,
|
37
|
+
height
|
38
|
+
} = this.screen;
|
39
|
+
if (width > height) {
|
40
|
+
return _common.ScreenOrientation.Landscape;
|
41
|
+
}
|
42
|
+
return _common.ScreenOrientation.Portrait;
|
43
|
+
}
|
44
|
+
setTheme = name => {
|
45
|
+
if (this.hasTheme(name)) {
|
46
|
+
this.unistylesBridge.useTheme(name);
|
47
|
+
return true;
|
48
|
+
}
|
49
|
+
throw new Error(_common.UnistylesError.ThemeNotRegistered);
|
50
|
+
};
|
51
|
+
getTheme = forName => {
|
52
|
+
if (this.registry.themeNames.length === 0) {
|
53
|
+
return {};
|
54
|
+
}
|
55
|
+
if (!this.hasTheme(forName)) {
|
56
|
+
throw new Error(_common.UnistylesError.ThemeNotFound);
|
57
|
+
}
|
58
|
+
return this.registry.themes[forName];
|
59
|
+
};
|
60
|
+
setAdaptiveThemes = enable => {
|
61
|
+
this.unistylesBridge.useAdaptiveThemes(enable);
|
62
|
+
};
|
63
|
+
hasTheme = name => name in this.registry.themes;
|
64
|
+
}
|
65
|
+
exports.UnistylesRuntime = UnistylesRuntime;
|
66
|
+
//# sourceMappingURL=UnistylesRuntime.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_common","require","UnistylesRuntime","constructor","unistylesBridge","registry","colorScheme","hasAdaptiveThemes","sortedBreakpoints","sortedBreakpointPairs","themeName","breakpoint","screen","width","screenWidth","height","screenHeight","orientation","ScreenOrientation","Landscape","Portrait","setTheme","name","hasTheme","useTheme","Error","UnistylesError","ThemeNotRegistered","getTheme","forName","themeNames","length","ThemeNotFound","themes","setAdaptiveThemes","enable","useAdaptiveThemes","exports"],"sourceRoot":"../../../src","sources":["core/UnistylesRuntime.ts"],"mappings":";;;;;;AAAA,IAAAA,OA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OAA8B,IAAK;IAClD,IAAI,IAAI,CAACxB,QAAQ,CAACyB,UAAU,CAACC,MAAM,KAAK,CAAC,EAAE;MACvC,OAAO,CAAC,CAAC;IACb;IAEA,IAAI,CAAC,IAAI,CAACR,QAAQ,CAACM,OAAO,CAAC,EAAE;MACzB,MAAM,IAAIJ,KAAK,CAACC,sBAAc,CAACM,aAAa,CAAC;IACjD;IAEA,OAAO,IAAI,CAAC3B,QAAQ,CAAC4B,MAAM,CAACJ,OAAO,CAAC;EACxC,CAAC;EAEMK,iBAAiB,GAAIC,MAAe,IAAK;IAC5C,IAAI,CAAC/B,eAAe,CAACgC,iBAAiB,CAACD,MAAM,CAAC;EAClD,CAAC;EAEOZ,QAAQ,GAAID,IAA2B,IAAKA,IAAI,IAAI,IAAI,CAACjB,QAAQ,CAAC4B,MAAM;AACpF;AAACI,OAAA,CAAAnC,gBAAA,GAAAA,gBAAA"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "unistyles", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _Unistyles.unistyles;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
var _Unistyles = require("./Unistyles");
|
13
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_Unistyles","require"],"sourceRoot":"../../../src","sources":["core/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createStyleSheet = void 0;
|
7
|
+
const createStyleSheet = styles => {
|
8
|
+
if (typeof styles === 'function') {
|
9
|
+
return styles;
|
10
|
+
}
|
11
|
+
return styles;
|
12
|
+
};
|
13
|
+
exports.createStyleSheet = createStyleSheet;
|
14
|
+
//# sourceMappingURL=createStyleSheet.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["createStyleSheet","styles","exports"],"sourceRoot":"../../src","sources":["createStyleSheet.ts"],"mappings":";;;;;;AAEO,MAAMA,gBAAgB,GAAUC,MAA4F,IAAY;EAC3I,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;IAC9B,OAAOA,MAAM;EACjB;EAEA,OAAOA,MAAM;AACjB,CAAC;AAAAC,OAAA,CAAAF,gBAAA,GAAAA,gBAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["global.ts"],"mappings":""}
|
@@ -3,11 +3,18 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
Object.defineProperty(exports, "
|
6
|
+
Object.defineProperty(exports, "useInitialTheme", {
|
7
7
|
enumerable: true,
|
8
8
|
get: function () {
|
9
|
-
return
|
9
|
+
return _useInitialTheme.useInitialTheme;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
|
12
|
+
Object.defineProperty(exports, "useUnistyles", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _useUnistyles.useUnistyles;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
var _useInitialTheme = require("./useInitialTheme");
|
19
|
+
var _useUnistyles = require("./useUnistyles");
|
13
20
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_useInitialTheme","require","_useUnistyles"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useInitialTheme = void 0;
|
7
|
+
var _react = require("react");
|
8
|
+
var _core = require("../core");
|
9
|
+
const useInitialTheme = forName => {
|
10
|
+
(0, _react.useMemo)(() => {
|
11
|
+
if (!_core.unistyles.runtime.themeName) {
|
12
|
+
_core.unistyles.runtime.setTheme(forName);
|
13
|
+
}
|
14
|
+
}, []);
|
15
|
+
};
|
16
|
+
exports.useInitialTheme = useInitialTheme;
|
17
|
+
//# sourceMappingURL=useInitialTheme.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","require","_core","useInitialTheme","forName","useMemo","unistyles","runtime","themeName","setTheme","exports"],"sourceRoot":"../../../src","sources":["hooks/useInitialTheme.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAGO,MAAME,eAAe,GAAIC,OAA8B,IAAK;EAC/D,IAAAC,cAAO,EAAC,MAAM;IACV,IAAI,CAACC,eAAS,CAACC,OAAO,CAACC,SAAS,EAAE;MAC9BF,eAAS,CAACC,OAAO,CAACE,QAAQ,CAACL,OAAO,CAAC;IACvC;EACJ,CAAC,EAAE,EAAE,CAAC;AACV,CAAC;AAAAM,OAAA,CAAAP,eAAA,GAAAA,eAAA"}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useUnistyles = void 0;
|
7
|
+
var _reactNative = require("react-native");
|
8
|
+
var _react = require("react");
|
9
|
+
var _core = require("../core");
|
10
|
+
var _common = require("../common");
|
11
|
+
const unistylesEvents = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.Unistyles);
|
12
|
+
const useUnistyles = () => {
|
13
|
+
const [theme, setTheme] = (0, _react.useState)(_core.unistyles.runtime.getTheme(_core.unistyles.runtime.themeName));
|
14
|
+
const [layout, setLayout] = (0, _react.useState)({
|
15
|
+
breakpoint: _core.unistyles.runtime.breakpoint,
|
16
|
+
orientation: _core.unistyles.runtime.orientation,
|
17
|
+
screenSize: {
|
18
|
+
width: _core.unistyles.runtime.screen.width,
|
19
|
+
height: _core.unistyles.runtime.screen.height
|
20
|
+
}
|
21
|
+
});
|
22
|
+
(0, _react.useEffect)(() => {
|
23
|
+
const subscription = unistylesEvents.addListener('onChange', event => {
|
24
|
+
switch (event.type) {
|
25
|
+
case _common.CxxUnistylesEventTypes.Theme:
|
26
|
+
{
|
27
|
+
const themeEvent = event;
|
28
|
+
return setTheme(_core.unistyles.runtime.getTheme(themeEvent.payload.themeName));
|
29
|
+
}
|
30
|
+
case _common.CxxUnistylesEventTypes.Layout:
|
31
|
+
{
|
32
|
+
const layoutEvent = event;
|
33
|
+
return setLayout({
|
34
|
+
breakpoint: layoutEvent.payload.breakpoint,
|
35
|
+
orientation: layoutEvent.payload.orientation,
|
36
|
+
screenSize: {
|
37
|
+
width: layoutEvent.payload.screen.width,
|
38
|
+
height: layoutEvent.payload.screen.height
|
39
|
+
}
|
40
|
+
});
|
41
|
+
}
|
42
|
+
default:
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
});
|
46
|
+
return subscription.remove;
|
47
|
+
}, []);
|
48
|
+
return {
|
49
|
+
theme,
|
50
|
+
layout
|
51
|
+
};
|
52
|
+
};
|
53
|
+
exports.useUnistyles = useUnistyles;
|
54
|
+
//# sourceMappingURL=useUnistyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_react","_core","_common","unistylesEvents","NativeEventEmitter","NativeModules","Unistyles","useUnistyles","theme","setTheme","useState","unistyles","runtime","getTheme","themeName","layout","setLayout","breakpoint","orientation","screenSize","width","screen","height","useEffect","subscription","addListener","event","type","CxxUnistylesEventTypes","Theme","themeEvent","payload","Layout","layoutEvent","remove","exports"],"sourceRoot":"../../../src","sources":["hooks/useUnistyles.ts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WAAW,EAAEe,WAAW,CAACF,OAAO,CAACb,WAAW;cAC5CC,UAAU,EAAE;gBACRC,KAAK,EAAEa,WAAW,CAACF,OAAO,CAACV,MAAM,CAACD,KAAK;gBACvCE,MAAM,EAAEW,WAAW,CAACF,OAAO,CAACV,MAAM,CAACC;cACvC;YACJ,CAAC,CAAC;UACN;QACA;UACI;MACR;IACJ,CACJ,CAAC;IAED,OAAOE,YAAY,CAACU,MAAM;EAC9B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACH1B,KAAK;IACLO;EACJ,CAAC;AACL,CAAC;AAAAoB,OAAA,CAAA5B,YAAA,GAAAA,YAAA"}
|
package/lib/commonjs/index.js
CHANGED
@@ -3,18 +3,47 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
Object.defineProperty(exports, "
|
6
|
+
Object.defineProperty(exports, "ScreenOrientation", {
|
7
7
|
enumerable: true,
|
8
8
|
get: function () {
|
9
|
-
return
|
9
|
+
return _common.ScreenOrientation;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
|
12
|
+
exports.UnistylesRuntime = exports.UnistylesRegistry = void 0;
|
13
|
+
Object.defineProperty(exports, "createStyleSheet", {
|
13
14
|
enumerable: true,
|
14
15
|
get: function () {
|
15
|
-
return
|
16
|
+
return _createStyleSheet.createStyleSheet;
|
16
17
|
}
|
17
18
|
});
|
18
|
-
|
19
|
-
|
19
|
+
Object.defineProperty(exports, "mq", {
|
20
|
+
enumerable: true,
|
21
|
+
get: function () {
|
22
|
+
return _utils.mq;
|
23
|
+
}
|
24
|
+
});
|
25
|
+
Object.defineProperty(exports, "useInitialTheme", {
|
26
|
+
enumerable: true,
|
27
|
+
get: function () {
|
28
|
+
return _hooks.useInitialTheme;
|
29
|
+
}
|
30
|
+
});
|
31
|
+
Object.defineProperty(exports, "useStyles", {
|
32
|
+
enumerable: true,
|
33
|
+
get: function () {
|
34
|
+
return _useStyles.useStyles;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
var _core = require("./core");
|
38
|
+
var _utils = require("./utils");
|
39
|
+
var _hooks = require("./hooks");
|
40
|
+
var _common = require("./common");
|
41
|
+
var _useStyles = require("./useStyles");
|
42
|
+
var _createStyleSheet = require("./createStyleSheet");
|
43
|
+
const UnistylesRegistry = exports.UnistylesRegistry = {
|
44
|
+
addThemes: _core.unistyles.registry.addThemes,
|
45
|
+
addBreakpoints: _core.unistyles.registry.addBreakpoints,
|
46
|
+
addConfig: _core.unistyles.registry.addConfig
|
47
|
+
};
|
48
|
+
const UnistylesRuntime = exports.UnistylesRuntime = _core.unistyles.runtime;
|
20
49
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_core","require","_utils","_hooks","_common","_useStyles","_createStyleSheet","UnistylesRegistry","exports","addThemes","unistyles","registry","addBreakpoints","addConfig","UnistylesRuntime","runtime"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AAEA,MAAMM,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG;EACtBE,SAAS,EAAEC,eAAS,CAACC,QAAQ,CAACF,SAAS;EACvCG,cAAc,EAAEF,eAAS,CAACC,QAAQ,CAACC,cAAc;EACjDC,SAAS,EAAEH,eAAS,CAACC,QAAQ,CAACE;AAClC,CAAC;AAED,MAAMC,gBAAgB,GAAAN,OAAA,CAAAM,gBAAA,GAAGJ,eAAS,CAACK,OAAO"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/common.ts"],"mappings":""}
|
@@ -1,2 +1,28 @@
|
|
1
1
|
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
var _normalizer = require("./normalizer");
|
7
|
+
Object.keys(_normalizer).forEach(function (key) {
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
9
|
+
if (key in exports && exports[key] === _normalizer[key]) return;
|
10
|
+
Object.defineProperty(exports, key, {
|
11
|
+
enumerable: true,
|
12
|
+
get: function () {
|
13
|
+
return _normalizer[key];
|
14
|
+
}
|
15
|
+
});
|
16
|
+
});
|
17
|
+
var _unistyles = require("./unistyles");
|
18
|
+
Object.keys(_unistyles).forEach(function (key) {
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
20
|
+
if (key in exports && exports[key] === _unistyles[key]) return;
|
21
|
+
Object.defineProperty(exports, key, {
|
22
|
+
enumerable: true,
|
23
|
+
get: function () {
|
24
|
+
return _unistyles[key];
|
25
|
+
}
|
26
|
+
});
|
27
|
+
});
|
2
28
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":""}
|
1
|
+
{"version":3,"names":["_normalizer","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_unistyles"],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,UAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,UAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,UAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAL,GAAA;IAAA;EAAA;AAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mq.ts"],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/normalizer.ts"],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/unistyles.ts"],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/variants.ts"],"mappings":""}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useStyles = void 0;
|
7
|
+
var _react = require("react");
|
8
|
+
var _reactNative = require("react-native");
|
9
|
+
var _utils = require("./utils");
|
10
|
+
var _hooks = require("./hooks");
|
11
|
+
const useStyles = (stylesheet, variant) => {
|
12
|
+
const {
|
13
|
+
theme,
|
14
|
+
layout
|
15
|
+
} = (0, _hooks.useUnistyles)();
|
16
|
+
const {
|
17
|
+
screenSize,
|
18
|
+
breakpoint
|
19
|
+
} = layout;
|
20
|
+
if (!stylesheet) {
|
21
|
+
return {
|
22
|
+
theme,
|
23
|
+
breakpoint,
|
24
|
+
styles: {}
|
25
|
+
};
|
26
|
+
}
|
27
|
+
const parsedStyles = (0, _react.useMemo)(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet]);
|
28
|
+
const dynamicStyleSheet = (0, _react.useMemo)(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
|
29
|
+
let [key, value] = _ref;
|
30
|
+
const style = value;
|
31
|
+
if (typeof value === 'function') {
|
32
|
+
return {
|
33
|
+
...acc,
|
34
|
+
[key]: (0, _utils.proxifyFunction)(value, breakpoint, screenSize, variant)
|
35
|
+
};
|
36
|
+
}
|
37
|
+
return _reactNative.StyleSheet.create({
|
38
|
+
...acc,
|
39
|
+
[key]: (0, _utils.parseStyle)(style, breakpoint, screenSize, variant)
|
40
|
+
});
|
41
|
+
}, {}), [breakpoint, screenSize, parsedStyles, variant]);
|
42
|
+
return {
|
43
|
+
theme,
|
44
|
+
breakpoint,
|
45
|
+
styles: dynamicStyleSheet
|
46
|
+
};
|
47
|
+
};
|
48
|
+
exports.useStyles = useStyles;
|
49
|
+
//# sourceMappingURL=useStyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_utils","_hooks","useStyles","stylesheet","variant","theme","layout","useUnistyles","screenSize","breakpoint","styles","parsedStyles","useMemo","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","proxifyFunction","StyleSheet","create","parseStyle","exports"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAQA,IAAAG,MAAA,GAAAH,OAAA;AASO,MAAMI,SAAS,GAAGA,CACrBC,UAAyD,EACzDC,OAAyD,KAClC;EACvB,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAG,IAAAC,mBAA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|
6
6
|
exports.sortAndValidateBreakpoints = exports.getValueForBreakpoint = exports.getBreakpointFromScreenWidth = void 0;
|
7
|
+
var _core = require("../core");
|
7
8
|
var _common = require("./common");
|
8
|
-
var
|
9
|
-
|
10
|
-
* Sorts the breakpoints object based on its numeric values in ascending order and validates them.
|
11
|
-
*
|
12
|
-
* This function takes an object where keys represent breakpoint names and values are numeric.
|
13
|
-
* It returns a new object with the same keys but sorted based on their corresponding numeric values.
|
14
|
-
* Additionally, it validates that:
|
15
|
-
* 1. The first breakpoint starts with a value of 0.
|
16
|
-
* 2. No duplicate breakpoint values exist.
|
17
|
-
*
|
18
|
-
* If the validation fails, appropriate error messages are logged to the console.
|
19
|
-
*
|
20
|
-
* @template B - An object type where keys are strings and values are numbers.
|
21
|
-
* @param {B} breakpoints - The breakpoints object to be sorted and validated.
|
22
|
-
* @returns {B} A new object with sorted and validated breakpoints.
|
23
|
-
*
|
24
|
-
* @example
|
25
|
-
* const input = { md: 768, lg: 1024, sm: 0 }
|
26
|
-
* sortAndValidateBreakpoints(input) // returns { sm: 0, md: 768, lg: 1024 }
|
27
|
-
*/
|
9
|
+
var _common2 = require("../common");
|
10
|
+
var _mqParser = require("./mqParser");
|
28
11
|
const sortAndValidateBreakpoints = breakpoints => {
|
29
12
|
const sortedPairs = Object.entries(breakpoints).sort((breakpoint1, breakpoint2) => {
|
30
13
|
const [, value1] = breakpoint1;
|
@@ -42,22 +25,6 @@ const sortAndValidateBreakpoints = breakpoints => {
|
|
42
25
|
}
|
43
26
|
return sortedBreakpoints;
|
44
27
|
};
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Determines the appropriate breakpoint key for a given screen width based on provided breakpoints.
|
48
|
-
*
|
49
|
-
* This function takes a screen width and an object of breakpoints. It returns the key of the breakpoint
|
50
|
-
* that the screen width falls into. The breakpoints are assumed to be sorted in ascending order.
|
51
|
-
*
|
52
|
-
* @template B - An object type where keys are strings and values are numbers representing screen widths.
|
53
|
-
* @param {number} width - The screen width to determine the breakpoint for.
|
54
|
-
* @param breakpointEntries - sorted pairs of breakpoints
|
55
|
-
* @returns {keyof B & string} The key of the breakpoint that the screen width falls into.
|
56
|
-
*
|
57
|
-
* @example
|
58
|
-
* const breakpoints = { sm: 0, md: 768, lg: 1024 }
|
59
|
-
* getBreakpointFromScreenWidth(800, breakpoints) // returns 'md'
|
60
|
-
*/
|
61
28
|
exports.sortAndValidateBreakpoints = sortAndValidateBreakpoints;
|
62
29
|
const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
|
63
30
|
const [key] = breakpointEntries.find((_ref, index, otherBreakpoints) => {
|
@@ -71,62 +38,48 @@ const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
|
|
71
38
|
});
|
72
39
|
return key;
|
73
40
|
};
|
74
|
-
|
75
|
-
/**
|
76
|
-
* Retrieves the value associated with a given breakpoint or custom media query based on the provided screen size.
|
77
|
-
*
|
78
|
-
* The function first checks for custom media queries. If a matching custom media query is found, its associated value is returned.
|
79
|
-
* If no custom media query matches, the function then checks for a direct breakpoint match.
|
80
|
-
* If there's no direct breakpoint match, the function simulates CSS cascading to find the closest matching breakpoint.
|
81
|
-
*
|
82
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
83
|
-
*
|
84
|
-
* @param {Record<keyof B & string, string | number>} value - An object containing values associated with breakpoints or custom media queries.
|
85
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
86
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
87
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
88
|
-
*
|
89
|
-
* @returns {string | number | undefined} Returns the value associated with the matching breakpoint or custom media query, or `undefined` if no match is found.
|
90
|
-
*
|
91
|
-
* @example
|
92
|
-
*
|
93
|
-
* const values = { ':w[200]': 'value1', sm: 'value2', md: 'value3' }
|
94
|
-
* const screenSize = { width: 250, height: 400 }
|
95
|
-
* const breakpoints = { sm: 300, md: 600, lg: 900 }
|
96
|
-
*
|
97
|
-
* getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
|
98
|
-
*/
|
99
41
|
exports.getBreakpointFromScreenWidth = getBreakpointFromScreenWidth;
|
100
|
-
const getValueForBreakpoint =
|
42
|
+
const getValueForBreakpoint = value => {
|
101
43
|
// the highest priority is for custom media queries
|
102
|
-
const
|
103
|
-
|
104
|
-
return (0, _mediaQueries.isMediaQuery)(key);
|
105
|
-
});
|
106
|
-
const customMediaQueryKey = (0, _mediaQueries.getKeyForCustomMediaQuery)(customMediaQueries, screenSize);
|
107
|
-
if (customMediaQueryKey && customMediaQueryKey in value) {
|
44
|
+
const customMediaQueryKey = (0, _mqParser.getKeyForUnistylesMediaQuery)(Object.entries(value), _core.unistyles.runtime.screen);
|
45
|
+
if (customMediaQueryKey) {
|
108
46
|
return value[customMediaQueryKey];
|
109
47
|
}
|
110
48
|
|
111
|
-
//
|
112
|
-
|
113
|
-
const
|
49
|
+
// at this point user didn't use custom media queries (:w, :h)
|
50
|
+
// check if user defined any breakpoints
|
51
|
+
const hasBreakpoints = _core.unistyles.runtime.sortedBreakpoints.length > 0;
|
52
|
+
|
53
|
+
// if not then we can fall back to horizontal and portrait (mobile only)
|
54
|
+
if (!hasBreakpoints && _common.isMobile && (_common.Orientation.Landscape in value || _common.Orientation.Portrait in value)) {
|
55
|
+
return value[_core.unistyles.runtime.orientation === _common2.ScreenOrientation.Portrait ? _common.Orientation.Portrait : _common.Orientation.Landscape];
|
56
|
+
}
|
57
|
+
|
58
|
+
// let's get the current breakpoint
|
59
|
+
const breakpoint = _core.unistyles.runtime.breakpoint;
|
60
|
+
if (!breakpoint) {
|
61
|
+
return undefined;
|
62
|
+
}
|
63
|
+
|
64
|
+
// if user defined breakpoints, then we look for the valid one
|
65
|
+
const directBreakpoint = value[breakpoint];
|
114
66
|
|
115
67
|
// if there is a direct key like 'sm' or 'md', or value for this key exists but its undefined
|
116
|
-
if (directBreakpoint ||
|
68
|
+
if (directBreakpoint || breakpoint in value) {
|
117
69
|
return directBreakpoint;
|
118
70
|
}
|
119
71
|
|
120
|
-
// there is no direct hit for breakpoint nor media-query,
|
121
|
-
const
|
122
|
-
|
123
|
-
|
72
|
+
// there is no direct hit for breakpoint nor media-query, let's simulate CSS cascading
|
73
|
+
const breakpointPairs = _core.unistyles.runtime.sortedBreakpoints;
|
74
|
+
const currentBreakpoint = breakpointPairs.findIndex(_ref2 => {
|
75
|
+
let [key] = _ref2;
|
76
|
+
return key === breakpoint;
|
124
77
|
});
|
125
|
-
const availableBreakpoints = breakpointPairs.filter((
|
126
|
-
let [key] =
|
78
|
+
const availableBreakpoints = breakpointPairs.filter((_ref3, index) => {
|
79
|
+
let [key] = _ref3;
|
127
80
|
return index < currentBreakpoint && key && key in value;
|
128
|
-
}).map(
|
129
|
-
let [key] =
|
81
|
+
}).map(_ref4 => {
|
82
|
+
let [key] = _ref4;
|
130
83
|
return key;
|
131
84
|
});
|
132
85
|
return breakpointPairs.length > 0 ? value[availableBreakpoints[availableBreakpoints.length - 1]] : undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_core","require","_common","_common2","_mqParser","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","throwError","length","Set","size","exports","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForBreakpoint","customMediaQueryKey","getKeyForUnistylesMediaQuery","unistyles","runtime","screen","hasBreakpoints","isMobile","Orientation","Landscape","Portrait","orientation","ScreenOrientation","breakpoint","undefined","directBreakpoint","breakpointPairs","currentBreakpoint","findIndex","_ref2","availableBreakpoints","filter","_ref3","map","_ref4"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAGA,IAA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;IAAA,IAAC,CAAC3B,GAAG,CAAC,GAAA2B,KAAA;IAAA,OAAK3B,GAAG,KAAKqB,UAAU;EAAA,EAAC;EAE7C,MAAMO,oBAAoB,GAAGJ,eAAe,CACvCK,MAAM,CAAC,CAAAC,KAAA,EAAQ3B,KAAK;IAAA,IAAZ,CAACH,GAAG,CAAC,GAAA8B,KAAA;IAAA,OAAY3B,KAAK,GAAGsB,iBAAiB,IAAIzB,GAAG,IAAIA,GAAG,IAAIK,KAAK;EAAA,EAAC,CAC1E0B,GAAG,CAACC,KAAA;IAAA,IAAC,CAAChC,GAAG,CAAC,GAAAgC,KAAA;IAAA,OAAKhC,GAAG;EAAA,EAAC;EAExB,OAAOwB,eAAe,CAAC/B,MAAM,GAAG,CAAC,GAC3BY,KAAK,CAACuB,oBAAoB,CAACA,oBAAoB,CAACnC,MAAM,GAAG,CAAC,CAAC,CAAwC,GACnG6B,SAAS;AACnB,CAAC;AAAA1B,OAAA,CAAAY,qBAAA,GAAAA,qBAAA"}
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.warn = exports.throwError = exports.isWeb = void 0;
|
6
|
+
exports.warn = exports.throwError = exports.isWeb = exports.isServer = exports.isMobile = exports.isIOS = exports.isAndroid = exports.Orientation = void 0;
|
7
7
|
var _reactNative = require("react-native");
|
8
8
|
const throwError = message => {
|
9
9
|
throw new Error(`🦄 [react-native-unistyles]: ${message}`);
|
@@ -13,6 +13,13 @@ const warn = message => {
|
|
13
13
|
console.warn(`🦄 [react-native-unistyles]: ${message}`);
|
14
14
|
};
|
15
15
|
exports.warn = warn;
|
16
|
-
const
|
17
|
-
exports.isWeb =
|
16
|
+
const isMobile = exports.isMobile = _reactNative.Platform.OS === 'android' || _reactNative.Platform.OS === 'ios';
|
17
|
+
const isWeb = exports.isWeb = _reactNative.Platform.OS === 'web';
|
18
|
+
const isIOS = exports.isIOS = _reactNative.Platform.OS === 'ios';
|
19
|
+
const isAndroid = exports.isAndroid = _reactNative.Platform.OS === 'android';
|
20
|
+
const isServer = exports.isServer = typeof window === 'undefined';
|
21
|
+
const Orientation = exports.Orientation = {
|
22
|
+
Landscape: 'landscape',
|
23
|
+
Portrait: 'portrait'
|
24
|
+
};
|
18
25
|
//# sourceMappingURL=common.js.map
|