react-native-unistyles 1.2.0 → 2.0.0-alpha.10
Sign up to get free protection for your applications and to get access to all the features.
- 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 +11 -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/unistyles.js +6 -0
- package/lib/commonjs/types/unistyles.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 +44 -82
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/common.js +6 -1
- package/lib/commonjs/utils/common.js.map +1 -1
- package/lib/commonjs/utils/index.js +25 -30
- package/lib/commonjs/utils/index.js.map +1 -1
- 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/styles.js +6 -53
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/variants.js +20 -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 +1 -0
- 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/unistyles.js +2 -0
- package/lib/module/types/unistyles.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 +43 -82
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/common.js +5 -0
- package/lib/module/utils/common.js.map +1 -1
- package/lib/module/utils/index.js +5 -3
- package/lib/module/utils/index.js.map +1 -1
- 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/styles.js +7 -55
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/variants.js +13 -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 +34 -18
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +5 -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/unistyles.d.ts +37 -0
- package/lib/typescript/src/types/unistyles.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 +5 -0
- package/lib/typescript/src/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +5 -3
- 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/styles.d.ts +4 -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 +30 -19
- 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 +16 -19
- package/src/types/common.ts +2 -0
- package/src/types/core.ts +42 -24
- package/src/types/index.ts +5 -9
- package/src/types/mq.ts +3 -0
- package/src/types/unistyles.ts +45 -0
- package/src/useStyles.ts +56 -0
- package/src/utils/breakpoints.ts +57 -88
- package/src/utils/common.ts +6 -0
- package/src/utils/index.ts +5 -10
- package/src/utils/mq.ts +106 -0
- package/src/utils/mqParser.ts +99 -0
- package/src/utils/styles.ts +17 -64
- package/src/utils/variants.ts +17 -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 -34
- 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 -27
- 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/examples/expo/src/App.d.ts +0 -3
- package/lib/typescript/examples/expo/src/App.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +0 -7
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/index.d.ts +0 -9
- package/lib/typescript/examples/expo/src/examples/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/index.d.ts +0 -2
- package/lib/typescript/examples/expo/src/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +0 -8
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/index.d.ts +0 -46
- package/lib/typescript/examples/expo/src/styles/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/theme.d.ts +0 -24
- package/lib/typescript/examples/expo/src/styles/theme.d.ts.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 -34
- 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,OAAA,GAAAC,OAAA;AAKO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,QAA0B,EAAE;IAAA,KAAtED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,QAA0B,GAA1BA,QAA0B;EAAG;EAE3F,IAAWC,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,eAAe,CAACE,WAAW;EAC3C;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,eAAe,CAACG,iBAAiB;EACjD;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,QAAQ,CAACI,qBAAqB;EAC9C;EAEA,IAAWC,SAASA,CAAA,EAAG;IACnB,OAAO,IAAI,CAACN,eAAe,CAACM,SAAS;EACzC;EAEA,IAAWC,UAAUA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACP,eAAe,CAACO,UAAU;EAC1C;EAEA,IAAWC,MAAMA,CAAA,EAAG;IAChB,OAAO;MACHC,KAAK,EAAE,IAAI,CAACT,eAAe,CAACU,WAAW;MACvCC,MAAM,EAAE,IAAI,CAACX,eAAe,CAACY;IACjC,CAAC;EACL;EAEA,IAAWC,WAAWA,CAAA,EAAG;IACrB,MAAM;MAAEJ,KAAK;MAAEE;IAAO,CAAC,GAAG,IAAI,CAACH,MAAM;IAErC,IAAIC,KAAK,GAAGE,MAAM,EAAE;MAChB,OAAOG,yBAAiB,CAACC,SAAS;IACtC;IAEA,OAAOD,yBAAiB,CAACE,QAAQ;EACrC;EAEOC,QAAQ,GAAIC,IAA2B,IAAK;IAC/C,IAAI,IAAI,CAACC,QAAQ,CAACD,IAAI,CAAC,EAAE;MACrB,IAAI,CAAClB,eAAe,CAACoB,QAAQ,CAACF,IAAI,CAAC;MAEnC,OAAO,IAAI;IACf;IAEA,MAAM,IAAIG,KAAK,CAACC,sBAAc,CAACC,kBAAkB,CAAC;EACtD,CAAC;EAEMC,QAAQ,GAAIC,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"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAGA,MAAMI,eAAe,GAAG,IAAIC,+BAAkB,CAACC,0BAAa,CAACC,SAAS,CAAC;AAEhE,MAAMC,YAAY,GAAGA,CAAA,KAAM;EAC9B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACC,eAAS,CAACC,OAAO,CAACC,QAAQ,CAACF,eAAS,CAACC,OAAO,CAACE,SAAS,CAAC,CAAC;EAC3F,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAG,IAAAN,eAAQ,EAAC;IACjCO,UAAU,EAAEN,eAAS,CAACC,OAAO,CAACK,UAAU;IACxCC,WAAW,EAAEP,eAAS,CAACC,OAAO,CAACM,WAAW;IAC1CC,UAAU,EAAE;MACRC,KAAK,EAAET,eAAS,CAACC,OAAO,CAACS,MAAM,CAACD,KAAK;MACrCE,MAAM,EAAEX,eAAS,CAACC,OAAO,CAACS,MAAM,CAACC;IACrC;EACJ,CAAC,CAAC;EAEF,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGrB,eAAe,CAACsB,WAAW,CAC5C,UAAU,EACTC,KAAsB,IAAK;MACxB,QAAQA,KAAK,CAACC,IAAI;QACd,KAAKC,8BAAsB,CAACC,KAAK;UAAE;YAC/B,MAAMC,UAAU,GAAGJ,KAA4B;YAE/C,OAAOjB,QAAQ,CAACE,eAAS,CAACC,OAAO,CAACC,QAAQ,CAACiB,UAAU,CAACC,OAAO,CAACjB,SAAS,CAAC,CAAC;UAC7E;QACA,KAAKc,8BAAsB,CAACI,MAAM;UAAE;YAChC,MAAMC,WAAW,GAAGP,KAAmC;YAEvD,OAAOV,SAAS,CAAC;cACbC,UAAU,EAAEgB,WAAW,CAACF,OAAO,CAACd,UAAU;cAC1CC,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":""}
|
@@ -14,4 +14,15 @@ Object.keys(_normalizer).forEach(function (key) {
|
|
14
14
|
}
|
15
15
|
});
|
16
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
|
+
});
|
17
28
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_normalizer","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"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"}
|
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/unistyles.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,O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AEP,OAAO,CAAC,CAA8B;EAE/F,OAAO;IACHC,KAAK;IACLI,UAAU;IACVC,MAAM,EAAEG;EACZ,CAAC;AACL,CAAC;AAAAa,OAAA,CAAAxB,SAAA,GAAAA,SAAA"}
|
@@ -3,28 +3,12 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.sortAndValidateBreakpoints = exports.
|
6
|
+
exports.sortAndValidateBreakpoints = exports.getValueForNestedStyle = exports.getBreakpointFromScreenWidth = void 0;
|
7
|
+
var _core = require("../core");
|
7
8
|
var _common = require("./common");
|
8
|
-
var
|
9
|
-
|
10
|
-
|
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");
|
11
|
+
var _variants = require("./variants");
|
28
12
|
const sortAndValidateBreakpoints = breakpoints => {
|
29
13
|
const sortedPairs = Object.entries(breakpoints).sort((breakpoint1, breakpoint2) => {
|
30
14
|
const [, value1] = breakpoint1;
|
@@ -42,22 +26,6 @@ const sortAndValidateBreakpoints = breakpoints => {
|
|
42
26
|
}
|
43
27
|
return sortedBreakpoints;
|
44
28
|
};
|
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
29
|
exports.sortAndValidateBreakpoints = sortAndValidateBreakpoints;
|
62
30
|
const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
|
63
31
|
const [key] = breakpointEntries.find((_ref, index, otherBreakpoints) => {
|
@@ -72,64 +40,58 @@ const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
|
|
72
40
|
return key;
|
73
41
|
};
|
74
42
|
|
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
|
-
*/
|
43
|
+
// todo move it to different file
|
99
44
|
exports.getBreakpointFromScreenWidth = getBreakpointFromScreenWidth;
|
100
|
-
const
|
101
|
-
// the highest priority is for
|
102
|
-
const
|
103
|
-
|
104
|
-
return
|
105
|
-
}
|
106
|
-
|
107
|
-
|
45
|
+
const getValueForNestedStyle = (value, variant) => {
|
46
|
+
// the highest priority is for variants
|
47
|
+
const variantKey = (0, _variants.getKeyForVariant)(value, variant);
|
48
|
+
if (variantKey) {
|
49
|
+
return value.variants[variantKey];
|
50
|
+
}
|
51
|
+
|
52
|
+
// then custom media queries
|
53
|
+
const customMediaQueryKey = (0, _mqParser.getKeyForUnistylesMediaQuery)(Object.entries(value), _core.unistyles.runtime.screen);
|
54
|
+
if (customMediaQueryKey) {
|
108
55
|
return value[customMediaQueryKey];
|
109
56
|
}
|
110
57
|
|
111
|
-
//
|
112
|
-
|
113
|
-
const
|
58
|
+
// at this point user didn't use custom media queries (:w, :h)
|
59
|
+
// check if user defined any breakpoints
|
60
|
+
const hasBreakpoints = _core.unistyles.runtime.sortedBreakpoints.length > 0;
|
61
|
+
|
62
|
+
// if not then we can fall back to horizontal and portrait (mobile only)
|
63
|
+
if (!hasBreakpoints && _common.isMobile && (_common.Orientation.Landscape in value || _common.Orientation.Portrait in value)) {
|
64
|
+
return value[_core.unistyles.runtime.orientation === _common2.ScreenOrientation.Portrait ? _common.Orientation.Portrait : _common.Orientation.Landscape];
|
65
|
+
}
|
66
|
+
|
67
|
+
// let's get the current breakpoint
|
68
|
+
const breakpoint = _core.unistyles.runtime.breakpoint;
|
69
|
+
if (!breakpoint) {
|
70
|
+
return undefined;
|
71
|
+
}
|
72
|
+
|
73
|
+
// if user defined breakpoints, then we look for the valid one
|
74
|
+
const directBreakpoint = value[breakpoint];
|
114
75
|
|
115
76
|
// if there is a direct key like 'sm' or 'md', or value for this key exists but its undefined
|
116
|
-
if (directBreakpoint ||
|
77
|
+
if (directBreakpoint || breakpoint in value) {
|
117
78
|
return directBreakpoint;
|
118
79
|
}
|
119
80
|
|
120
|
-
// there is no direct hit for breakpoint nor media-query,
|
121
|
-
const
|
122
|
-
|
123
|
-
|
81
|
+
// there is no direct hit for breakpoint nor media-query, let's simulate CSS cascading
|
82
|
+
const breakpointPairs = _core.unistyles.runtime.sortedBreakpoints;
|
83
|
+
const currentBreakpoint = breakpointPairs.findIndex(_ref2 => {
|
84
|
+
let [key] = _ref2;
|
85
|
+
return key === breakpoint;
|
124
86
|
});
|
125
|
-
const availableBreakpoints = breakpointPairs.filter((
|
126
|
-
let [key] =
|
87
|
+
const availableBreakpoints = breakpointPairs.filter((_ref3, index) => {
|
88
|
+
let [key] = _ref3;
|
127
89
|
return index < currentBreakpoint && key && key in value;
|
128
|
-
}).map(
|
129
|
-
let [key] =
|
90
|
+
}).map(_ref4 => {
|
91
|
+
let [key] = _ref4;
|
130
92
|
return key;
|
131
93
|
});
|
132
94
|
return breakpointPairs.length > 0 ? value[availableBreakpoints[availableBreakpoints.length - 1]] : undefined;
|
133
95
|
};
|
134
|
-
exports.
|
96
|
+
exports.getValueForNestedStyle = getValueForNestedStyle;
|
135
97
|
//# sourceMappingURL=breakpoints.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_core","require","_common","_common2","_mqParser","_variants","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","getValueForNestedStyle","variant","variantKey","getKeyForVariant","variants","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,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAEO,MAAMK,0BAA0B,GAAIC,WAAiC,IAA2B;EACnG,MAAMC,WAAW,GAAGC,MAAM,CACrBC,OAAO,CAACH,WAAW,CAAC,CACpBI,IAAI,CAAC,CAACC,WAAW,EAAEC,WAAW,KAAK;IAChC,MAAM,GAAGC,MAAM,CAAC,GAAGF,WAAW;IAC9B,MAAM,GAAGG,MAAM,CAAC,GAAGF,WAAW;IAE9B,OAAQC,MAAM,GAAeC,MAAiB;EAClD,CAAC,CAAC;EAEN,MAAMC,iBAAiB,GAAIP,MAAM,CAACQ,MAAM,CAACR,MAAM,CAACS,WAAW,CAACV,WAAW,CAAC,CAAyB;EACjG,MAAMW,gBAAgB,GAAGV,MAAM,CAACW,MAAM,CAACJ,iBAAiB,CAAC;EACzD,MAAM,CAACK,eAAe,CAAC,GAAGF,gBAAgB;EAE1C,IAAIE,eAAe,KAAK,CAAC,EAAE;IACvB,IAAAC,kBAAU,EAAC,oCAAoC,CAAC;EACpD;EAEA,IAAIH,gBAAgB,CAACI,MAAM,KAAK,IAAIC,GAAG,CAACL,gBAAgB,CAAC,CAACM,IAAI,EAAE;IAC5D,IAAAH,kBAAU,EAAC,kCAAkC,CAAC;EAClD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BAAA,GAAAA,sBAAA"}
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.warn = exports.throwError = exports.isWeb = exports.isServer = exports.isIOS = exports.isAndroid = 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,8 +13,13 @@ const warn = message => {
|
|
13
13
|
console.warn(`🦄 [react-native-unistyles]: ${message}`);
|
14
14
|
};
|
15
15
|
exports.warn = warn;
|
16
|
+
const isMobile = exports.isMobile = _reactNative.Platform.OS === 'android' || _reactNative.Platform.OS === 'ios';
|
16
17
|
const isWeb = exports.isWeb = _reactNative.Platform.OS === 'web';
|
17
18
|
const isIOS = exports.isIOS = _reactNative.Platform.OS === 'ios';
|
18
19
|
const isAndroid = exports.isAndroid = _reactNative.Platform.OS === 'android';
|
19
20
|
const isServer = exports.isServer = typeof window === 'undefined';
|
21
|
+
const Orientation = exports.Orientation = {
|
22
|
+
Landscape: 'landscape',
|
23
|
+
Portrait: 'portrait'
|
24
|
+
};
|
20
25
|
//# sourceMappingURL=common.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_reactNative","require","throwError","message","Error","exports","warn","console","
|
1
|
+
{"version":3,"names":["_reactNative","require","throwError","message","Error","exports","warn","console","isMobile","Platform","OS","isWeb","isIOS","isAndroid","isServer","window","Orientation","Landscape","Portrait"],"sourceRoot":"../../../src","sources":["utils/common.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEO,MAAMC,UAAU,GAAIC,OAAe,IAAK;EAC3C,MAAM,IAAIC,KAAK,CAAE,gCAA+BD,OAAQ,EAAC,CAAC;AAC9D,CAAC;AAAAE,OAAA,CAAAH,UAAA,GAAAA,UAAA;AAEM,MAAMI,IAAI,GAAIH,OAAe,IAAK;EACrCI,OAAO,CAACD,IAAI,CAAE,gCAA+BH,OAAQ,EAAC,CAAC;AAC3D,CAAC;AAAAE,OAAA,CAAAC,IAAA,GAAAA,IAAA;AAEM,MAAME,QAAQ,GAAAH,OAAA,CAAAG,QAAA,GAAGC,qBAAQ,CAACC,EAAE,KAAK,SAAS,IAAID,qBAAQ,CAACC,EAAE,KAAK,KAAK;AACnE,MAAMC,KAAK,GAAAN,OAAA,CAAAM,KAAA,GAAGF,qBAAQ,CAACC,EAAE,KAAK,KAAK;AACnC,MAAME,KAAK,GAAAP,OAAA,CAAAO,KAAA,GAAGH,qBAAQ,CAACC,EAAE,KAAK,KAAK;AACnC,MAAMG,SAAS,GAAAR,OAAA,CAAAQ,SAAA,GAAGJ,qBAAQ,CAACC,EAAE,KAAK,SAAS;AAC3C,MAAMI,QAAQ,GAAAT,OAAA,CAAAS,QAAA,GAAG,OAAOC,MAAM,KAAK,WAAW;AAE9C,MAAMC,WAAW,GAAAX,OAAA,CAAAW,WAAA,GAAG;EACvBC,SAAS,EAAE,WAAW;EACtBC,QAAQ,EAAE;AACd,CAAU"}
|