react-native-unistyles 1.1.1 → 2.0.0-alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- package/ios/UnistylesModule.h +10 -0
- package/ios/UnistylesModule.mm +108 -0
- package/ios/UnistylesRuntime.h +30 -0
- package/ios/UnistylesRuntime.mm +191 -0
- package/lib/commonjs/UnistyleRegistry.js +37 -0
- package/lib/commonjs/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/Unistyles.js +36 -0
- package/lib/commonjs/Unistyles.js.map +1 -0
- package/lib/commonjs/UnistylesEngine.js +22 -0
- package/lib/commonjs/UnistylesEngine.js.map +1 -0
- package/lib/commonjs/UnistylesModule.js +9 -0
- package/lib/commonjs/UnistylesModule.js.map +1 -0
- package/lib/commonjs/UnistylesRuntime.js +52 -0
- package/lib/commonjs/UnistylesRuntime.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/index.js +33 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/cxx.js +23 -0
- package/lib/commonjs/types/cxx.js.map +1 -0
- package/lib/commonjs/types/index.js +11 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/useInitialTheme.js +13 -0
- package/lib/commonjs/useInitialTheme.js.map +1 -0
- package/lib/commonjs/useStyles.js +48 -0
- package/lib/commonjs/useStyles.js.map +1 -0
- package/lib/commonjs/useUnistyles.js +59 -0
- package/lib/commonjs/useUnistyles.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.js +4 -2
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/styles.js +6 -6
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/UnistyleRegistry.js +30 -0
- package/lib/module/UnistyleRegistry.js.map +1 -0
- package/lib/module/Unistyles.js +30 -0
- package/lib/module/Unistyles.js.map +1 -0
- package/lib/module/UnistylesEngine.js +15 -0
- package/lib/module/UnistylesEngine.js.map +1 -0
- package/lib/module/UnistylesModule.js +3 -0
- package/lib/module/UnistylesModule.js.map +1 -0
- package/lib/module/UnistylesRuntime.js +45 -0
- package/lib/module/UnistylesRuntime.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/index.js +18 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/cxx.js +17 -0
- package/lib/module/types/cxx.js.map +1 -0
- package/lib/module/types/index.js +1 -0
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/useInitialTheme.js +6 -0
- package/lib/module/useInitialTheme.js.map +1 -0
- package/lib/module/useStyles.js +42 -0
- package/lib/module/useStyles.js.map +1 -0
- package/lib/module/useUnistyles.js +52 -0
- package/lib/module/useUnistyles.js.map +1 -0
- package/lib/module/utils/breakpoints.js +4 -3
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/styles.js +6 -7
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/examples/expo/src/App.d.ts.map +1 -1
- package/lib/typescript/examples/expo/src/examples/Cxx.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/Cxx.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/index.d.ts +1 -7
- package/lib/typescript/examples/expo/src/examples/index.d.ts.map +1 -1
- package/lib/typescript/examples/expo/src/styles/index.d.ts +15 -45
- package/lib/typescript/examples/expo/src/styles/index.d.ts.map +1 -1
- package/lib/typescript/examples/expo/src/styles/theme.d.ts +17 -1
- package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +1 -1
- package/lib/typescript/src/UnistyleRegistry.d.ts +15 -0
- package/lib/typescript/src/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/Unistyles.d.ts +16 -0
- package/lib/typescript/src/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/UnistylesEngine.d.ts +8 -0
- package/lib/typescript/src/UnistylesEngine.d.ts.map +1 -0
- package/lib/typescript/src/UnistylesModule.d.ts +6 -0
- package/lib/typescript/src/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/UnistylesRuntime.d.ts +56 -0
- package/lib/typescript/src/UnistylesRuntime.d.ts.map +1 -0
- package/lib/typescript/src/createStyleSheet.d.ts +6 -0
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
- package/lib/typescript/src/global.d.ts +5 -0
- package/lib/typescript/src/global.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 +6 -7
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +4 -4
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/cxx.d.ts +50 -0
- package/lib/typescript/src/types/cxx.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +3 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/useInitialTheme.d.ts +3 -0
- package/lib/typescript/src/useInitialTheme.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +46 -0
- package/lib/typescript/src/useStyles.d.ts.map +1 -0
- package/lib/typescript/src/useUnistyles.d.ts +45 -0
- package/lib/typescript/src/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +5 -4
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/styles.d.ts +4 -3
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/package.json +11 -8
- package/react-native-unistyles.podspec +21 -0
- package/src/UnistyleRegistry.ts +39 -0
- package/src/Unistyles.ts +41 -0
- package/src/UnistylesEngine.ts +15 -0
- package/src/UnistylesModule.ts +7 -0
- package/src/UnistylesRuntime.ts +58 -0
- package/src/createStyleSheet.ts +12 -0
- package/src/global.ts +2 -0
- package/src/index.ts +30 -2
- package/src/types/breakpoints.ts +9 -11
- package/src/types/core.ts +6 -6
- package/src/types/cxx.ts +61 -0
- package/src/types/index.ts +3 -3
- package/src/useInitialTheme.ts +7 -0
- package/src/useStyles.ts +49 -0
- package/src/useUnistyles.ts +67 -0
- package/src/utils/breakpoints.ts +16 -14
- package/src/utils/styles.ts +16 -18
- 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/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/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/Theme.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/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/src/UnistylesTheme.tsx +0 -17
- package/src/__tests__/createUnistyles.spec.tsx +0 -192
- package/src/createUnistyles.ts +0 -70
@@ -0,0 +1,13 @@
|
|
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 _Unistyles = require("./Unistyles");
|
9
|
+
const useInitialTheme = forName => {
|
10
|
+
(0, _react.useRef)(_Unistyles.unistyles.runtime.setTheme(forName));
|
11
|
+
};
|
12
|
+
exports.useInitialTheme = useInitialTheme;
|
13
|
+
//# sourceMappingURL=useInitialTheme.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","require","_Unistyles","useInitialTheme","forName","useRef","unistyles","runtime","setTheme","exports"],"sourceRoot":"../../src","sources":["useInitialTheme.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAGO,MAAME,eAAe,GAAIC,OAA8B,IAAK;EAC/D,IAAAC,aAAM,EAACC,oBAAS,CAACC,OAAO,CAACC,QAAQ,CAACJ,OAAO,CAAC,CAAC;AAC/C,CAAC;AAAAK,OAAA,CAAAN,eAAA,GAAAA,eAAA"}
|
@@ -0,0 +1,48 @@
|
|
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 _useUnistyles = require("./useUnistyles");
|
11
|
+
// todo types
|
12
|
+
|
13
|
+
const useStyles = stylesheet => {
|
14
|
+
const {
|
15
|
+
theme,
|
16
|
+
breakpoint,
|
17
|
+
screenSize
|
18
|
+
} = (0, _useUnistyles.useUnistyles)();
|
19
|
+
if (!stylesheet) {
|
20
|
+
return {
|
21
|
+
theme,
|
22
|
+
breakpoint,
|
23
|
+
styles: {}
|
24
|
+
};
|
25
|
+
}
|
26
|
+
const parsedStyles = (0, _react.useMemo)(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet]);
|
27
|
+
const dynamicStyleSheet = (0, _react.useMemo)(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
|
28
|
+
let [key, value] = _ref;
|
29
|
+
const style = value;
|
30
|
+
if (typeof value === 'function') {
|
31
|
+
return {
|
32
|
+
...acc,
|
33
|
+
[key]: (0, _utils.proxifyFunction)(value, breakpoint, screenSize)
|
34
|
+
};
|
35
|
+
}
|
36
|
+
return _reactNative.StyleSheet.create({
|
37
|
+
...acc,
|
38
|
+
[key]: (0, _utils.parseStyle)(style, breakpoint, screenSize)
|
39
|
+
});
|
40
|
+
}, {}), [breakpoint, screenSize, parsedStyles]);
|
41
|
+
return {
|
42
|
+
theme,
|
43
|
+
breakpoint,
|
44
|
+
styles: dynamicStyleSheet
|
45
|
+
};
|
46
|
+
};
|
47
|
+
exports.useStyles = useStyles;
|
48
|
+
//# sourceMappingURL=useStyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_utils","_useUnistyles","useStyles","stylesheet","theme","breakpoint","screenSize","useUnistyles","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;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAGA;;AAGO,MAAMI,SAAS,GAAsCC,UAA4C,IAAK;EACzG,MAAM;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAW,CAAC,GAAG,IAAAC,0BAAY,EAAC,CAAC;EAExD,IAAI,CAACJ,UAAU,EAAE;IACb,OAAO;MACHC,KAAK;MACLC,UAAU;MACVG,MAAM,EAAE,CAAC;IACb,CAAC;EACL;EAEA,MAAMC,YAAY,GAAG,IAAAC,cAAO,EAAC,MAAM,OAAOP,UAAU,KAAK,UAAU,GAC7DA,UAAU,CAACC,KAAM,CAAC,GAClBD,UAAU,EAAE,CAACC,KAAK,EAAED,UAAU,CAAC,CAAC;EAEtC,MAAMQ,iBAAiB,GAAG,IAAAD,cAAO,EAAC,MAAME,MAAM,CACzCC,OAAO,CAACJ,YAAY,CAAC,CACrBK,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACtB,MAAMG,KAAK,GAAGD,KAA8B;IAE5C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MAC7B,OAAO;QACH,GAAGH,GAAG;QACN,CAACE,GAAG,GAAG,IAAAG,sBAAe,EAACF,KAAK,EAAEb,UAAU,EAAGC,UAAU;MACzD,CAAC;IACL;IAEA,OAAOe,uBAAU,CAACC,MAAM,CAAC;MACrB,GAAGP,GAAG;MACN,CAACE,GAAG,GAAG,IAAAM,iBAAU,EAAKJ,KAAK,EAAEd,UAAU,EAAGC,UAAU;IACxD,CAAC,CAAC;EACN,CAAC,EAAE,CAAC,CAAO,CAAC,EAAE,CAACD,UAAU,EAAEC,UAAU,EAAEG,YAAY,CAAC,CAAC;EAEzD,OAAO;IACHL,KAAK;IACLC,UAAU;IACVG,MAAM,EAAEG;EACZ,CAAC;AACL,CAAC;AAAAa,OAAA,CAAAtB,SAAA,GAAAA,SAAA"}
|
@@ -0,0 +1,59 @@
|
|
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 _types = require("./types");
|
10
|
+
var _Unistyles = require("./Unistyles");
|
11
|
+
const unistylesEvents = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.Unistyles);
|
12
|
+
const useUnistyles = () => {
|
13
|
+
const [theme, setTheme] = (0, _react.useState)(_Unistyles.unistyles.runtime.getTheme(_Unistyles.unistyles.runtime.theme));
|
14
|
+
const [breakpoint, setBreakpoint] = (0, _react.useState)(_Unistyles.unistyles.runtime.currentBreakpoint);
|
15
|
+
const [screenSize, setScreenSize] = (0, _react.useState)({
|
16
|
+
width: 0,
|
17
|
+
height: 0
|
18
|
+
});
|
19
|
+
(0, _react.useEffect)(() => {
|
20
|
+
const subscription = unistylesEvents.addListener('onChange', event => {
|
21
|
+
switch (event.type) {
|
22
|
+
case _types.CxxUnistylesEventTypes.Theme:
|
23
|
+
{
|
24
|
+
const themeEvent = event;
|
25
|
+
setTheme(_Unistyles.unistyles.runtime.getTheme(themeEvent.payload.currentTheme));
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
case _types.CxxUnistylesEventTypes.Size:
|
29
|
+
{
|
30
|
+
const sizeEvent = event;
|
31
|
+
setScreenSize({
|
32
|
+
width: sizeEvent.payload.width,
|
33
|
+
height: sizeEvent.payload.height
|
34
|
+
});
|
35
|
+
// todo
|
36
|
+
// setBreakpoint(unistyles.runtime.currentBreakpoint)
|
37
|
+
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
case _types.CxxUnistylesEventTypes.Breakpoint:
|
41
|
+
{
|
42
|
+
const breakpointEvent = event;
|
43
|
+
setBreakpoint(breakpointEvent.payload.currentBreakpoint);
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
default:
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
});
|
50
|
+
return subscription.remove;
|
51
|
+
}, []);
|
52
|
+
return {
|
53
|
+
theme,
|
54
|
+
breakpoint,
|
55
|
+
screenSize
|
56
|
+
};
|
57
|
+
};
|
58
|
+
exports.useUnistyles = useUnistyles;
|
59
|
+
//# sourceMappingURL=useUnistyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_react","_types","_Unistyles","unistylesEvents","NativeEventEmitter","NativeModules","Unistyles","useUnistyles","theme","setTheme","useState","unistyles","runtime","getTheme","breakpoint","setBreakpoint","currentBreakpoint","screenSize","setScreenSize","width","height","useEffect","subscription","addListener","event","type","CxxUnistylesEventTypes","Theme","themeEvent","payload","currentTheme","Size","sizeEvent","Breakpoint","breakpointEvent","remove","exports"],"sourceRoot":"../../src","sources":["useUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAOA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA,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,oBAAS,CAACC,OAAO,CAACC,QAAQ,CAACF,oBAAS,CAACC,OAAO,CAACJ,KAAK,CAAC,CAAC;EACvF,MAAM,CAACM,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAL,eAAQ,EAACC,oBAAS,CAACC,OAAO,CAACI,iBAAiB,CAAC;EACjF,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAR,eAAQ,EAAC;IACzCS,KAAK,EAAE,CAAC;IACRC,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGnB,eAAe,CAACoB,WAAW,CAC5C,UAAU,EACTC,KAAsB,IAAK;MACxB,QAAQA,KAAK,CAACC,IAAI;QACd,KAAKC,6BAAsB,CAACC,KAAK;UAAE;YAC/B,MAAMC,UAAU,GAAGJ,KAA+B;YAElDf,QAAQ,CAACE,oBAAS,CAACC,OAAO,CAACC,QAAQ,CAACe,UAAU,CAACC,OAAO,CAACC,YAAY,CAAC,CAAC;YAErE;UACJ;QACA,KAAKJ,6BAAsB,CAACK,IAAI;UAAE;YAC9B,MAAMC,SAAS,GAAGR,KAA8B;YAEhDN,aAAa,CAAC;cACVC,KAAK,EAAEa,SAAS,CAACH,OAAO,CAACV,KAAK;cAC9BC,MAAM,EAAEY,SAAS,CAACH,OAAO,CAACT;YAC9B,CAAC,CAAC;YACF;YACA;;YAEA;UACJ;QACA,KAAKM,6BAAsB,CAACO,UAAU;UAAE;YACpC,MAAMC,eAAe,GAAGV,KAAoC;YAE5DT,aAAa,CAACmB,eAAe,CAACL,OAAO,CAACb,iBAAiB,CAAC;YAExD;UACJ;QACA;UACI;MACR;IACJ,CACJ,CAAC;IAED,OAAOM,YAAY,CAACa,MAAM;EAC9B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACH3B,KAAK;IACLM,UAAU;IACVG;EACJ,CAAC;AACL,CAAC;AAAAmB,OAAA,CAAA7B,YAAA,GAAAA,YAAA"}
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.sortAndValidateBreakpoints = exports.getValueForBreakpoint = exports.getBreakpointFromScreenWidth = void 0;
|
7
|
+
var _Unistyles = require("../Unistyles");
|
7
8
|
var _common = require("./common");
|
8
9
|
var _mediaQueries = require("./mediaQueries");
|
9
10
|
/**
|
@@ -97,7 +98,7 @@ const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
|
|
97
98
|
* getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
|
98
99
|
*/
|
99
100
|
exports.getBreakpointFromScreenWidth = getBreakpointFromScreenWidth;
|
100
|
-
const getValueForBreakpoint = (value, breakpoint, screenSize
|
101
|
+
const getValueForBreakpoint = (value, breakpoint, screenSize) => {
|
101
102
|
// the highest priority is for custom media queries
|
102
103
|
const customMediaQueries = Object.entries(value).filter(_ref2 => {
|
103
104
|
let [key] = _ref2;
|
@@ -109,7 +110,7 @@ const getValueForBreakpoint = (value, breakpoint, screenSize, breakpointPairs) =
|
|
109
110
|
}
|
110
111
|
|
111
112
|
// if no custom media query, or didn't match, proceed with defined breakpoints
|
112
|
-
const unifiedKey = breakpoint
|
113
|
+
const unifiedKey = breakpoint?.toLowerCase();
|
113
114
|
const directBreakpoint = value[unifiedKey];
|
114
115
|
|
115
116
|
// if there is a direct key like 'sm' or 'md', or value for this key exists but its undefined
|
@@ -118,6 +119,7 @@ const getValueForBreakpoint = (value, breakpoint, screenSize, breakpointPairs) =
|
|
118
119
|
}
|
119
120
|
|
120
121
|
// there is no direct hit for breakpoint nor media-query, so let's simulate CSS cascading
|
122
|
+
const breakpointPairs = _Unistyles.unistyles.runtime.sortedBreakpoints;
|
121
123
|
const currentBreakpoint = breakpointPairs.findIndex(_ref3 => {
|
122
124
|
let [key] = _ref3;
|
123
125
|
return key === unifiedKey;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_Unistyles","require","_common","_mediaQueries","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","breakpoint","screenSize","customMediaQueries","filter","_ref2","isMediaQuery","customMediaQueryKey","getKeyForCustomMediaQuery","unifiedKey","toLowerCase","directBreakpoint","breakpointPairs","unistyles","runtime","currentBreakpoint","findIndex","_ref3","availableBreakpoints","_ref4","map","_ref5","undefined"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAF,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,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;EAEA,OAAON,iBAAiB;AAC5B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAdAU,OAAA,CAAApB,0BAAA,GAAAA,0BAAA;AAeO,MAAMqB,4BAA4B,GAAGA,CAACC,KAAa,EAAEC,iBAAwG,KAA0C;EAC1M,MAAM,CAACC,GAAG,CAAC,GAAGD,iBAAiB,CAC1BE,IAAI,CAAC,CAAAC,IAAA,EAAYC,KAAK,EAAEC,gBAAgB,KAAK;IAAA,IAAvC,GAAGC,KAAK,CAAC,GAAAH,IAAA;IACZ,MAAMI,MAAM,GAAGD,KAAK;IACpB,MAAME,MAAM,GAAGH,gBAAgB,CAACD,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAE/C,IAAI,CAACI,MAAM,EAAE;MACT,OAAO,IAAI;IACf;IAEA,OAAOT,KAAK,IAAIQ,MAAM,IAAIR,KAAK,GAAGS,MAAM;EAC5C,CAAC,CAAkD;EAEvD,OAAOP,GAAG;AACd,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAvBAJ,OAAA,CAAAC,4BAAA,GAAAA,4BAAA;AAwBO,MAAMW,qBAAqB,GAAGA,CACjCH,KAAqF,EACrFI,UAAsC,EACtCC,UAAsB,KACQ;EAC9B;EACA,MAAMC,kBAAkB,GAAGhC,MAAM,CAC5BC,OAAO,CAACyB,KAAK,CAAC,CACdO,MAAM,CAACC,KAAA;IAAA,IAAC,CAACb,GAAG,CAAC,GAAAa,KAAA;IAAA,OAAK,IAAAC,0BAAY,EAACd,GAAG,CAAC;EAAA,EAAC;EACzC,MAAMe,mBAAmB,GAAG,IAAAC,uCAAyB,EAACL,kBAAkB,EAAED,UAAU,CAAuB;EAE3G,IAAIK,mBAAmB,IAAIA,mBAAmB,IAAIV,KAAK,EAAE;IACrD,OAAOA,KAAK,CAACU,mBAAmB,CAAC;EACrC;;EAEA;EACA,MAAME,UAAU,GAAGR,UAAU,EAAES,WAAW,CAAC,CAAuB;EAClE,MAAMC,gBAAgB,GAAGd,KAAK,CAACY,UAAU,CAAC;;EAE1C;EACA,IAAIE,gBAAgB,IAAKF,UAAU,IAAIZ,KAAM,EAAE;IAC3C,OAAOc,gBAAgB;EAC3B;;EAEA;EACA,MAAMC,eAAe,GAAGC,oBAAS,CAACC,OAAO,CAACpC,iBAAiB;EAC3D,MAAMqC,iBAAiB,GAAGH,eAAe,CACpCI,SAAS,CAACC,KAAA;IAAA,IAAC,CAACzB,GAAG,CAAC,GAAAyB,KAAA;IAAA,OAAKzB,GAAG,KAAKiB,UAAU;EAAA,EAAC;EAE7C,MAAMS,oBAAoB,GAAGN,eAAe,CACvCR,MAAM,CAAC,CAAAe,KAAA,EAAQxB,KAAK;IAAA,IAAZ,CAACH,GAAG,CAAC,GAAA2B,KAAA;IAAA,OAAYxB,KAAK,GAAGoB,iBAAiB,IAAIvB,GAAG,IAAIA,GAAG,IAAIK,KAAK;EAAA,EAAC,CAC1EuB,GAAG,CAACC,KAAA;IAAA,IAAC,CAAC7B,GAAG,CAAC,GAAA6B,KAAA;IAAA,OAAK7B,GAAG;EAAA,EAAC;EAExB,OAAOoB,eAAe,CAAC3B,MAAM,GAAG,CAAC,GAC3BY,KAAK,CAACqB,oBAAoB,CAACA,oBAAoB,CAACjC,MAAM,GAAG,CAAC,CAAC,CAAwC,GACnGqC,SAAS;AACnB,CAAC;AAAAlC,OAAA,CAAAY,qBAAA,GAAAA,qBAAA"}
|
@@ -28,8 +28,8 @@ var _common = require("./common");
|
|
28
28
|
* const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
|
29
29
|
* proxifiedFunction() // parsed style based on screenSize and breakpoints
|
30
30
|
*/
|
31
|
-
const proxifyFunction = (fn, breakpoint, screenSize
|
32
|
-
apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize
|
31
|
+
const proxifyFunction = (fn, breakpoint, screenSize) => new Proxy(fn, {
|
32
|
+
apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize)
|
33
33
|
});
|
34
34
|
|
35
35
|
/**
|
@@ -58,24 +58,24 @@ const proxifyFunction = (fn, breakpoint, screenSize, breakpointPairs) => new Pro
|
|
58
58
|
* // { fontSize: '12px' }
|
59
59
|
*/
|
60
60
|
exports.proxifyFunction = proxifyFunction;
|
61
|
-
const parseStyle = (style, breakpoint, screenSize
|
61
|
+
const parseStyle = (style, breakpoint, screenSize) => {
|
62
62
|
const entries = Object.entries(style);
|
63
63
|
const parsedStyles = Object.fromEntries(entries.map(_ref => {
|
64
64
|
let [key, value] = _ref;
|
65
65
|
const hasNestedProperties = key === 'shadowOffset' || key === 'textShadowOffset';
|
66
66
|
if (hasNestedProperties) {
|
67
|
-
return [key, parseStyle(value, breakpoint, screenSize
|
67
|
+
return [key, parseStyle(value, breakpoint, screenSize)];
|
68
68
|
}
|
69
69
|
const isTransform = key === 'transform';
|
70
70
|
if (isTransform && Array.isArray(value)) {
|
71
|
-
return [key, value.map(value => parseStyle(value, breakpoint, screenSize
|
71
|
+
return [key, value.map(value => parseStyle(value, breakpoint, screenSize))];
|
72
72
|
}
|
73
73
|
const isDynamicFunction = typeof value === 'function';
|
74
74
|
const isValidStyle = typeof value !== 'object';
|
75
75
|
if (isDynamicFunction || isValidStyle) {
|
76
76
|
return [key, value];
|
77
77
|
}
|
78
|
-
return [key, (0, _breakpoints.getValueForBreakpoint)(value, breakpoint, screenSize
|
78
|
+
return [key, (0, _breakpoints.getValueForBreakpoint)(value, breakpoint, screenSize)];
|
79
79
|
}));
|
80
80
|
return _common.isWeb ? (0, _normalizeStyles.normalizeStyles)(parsedStyles) : parsedStyles;
|
81
81
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_breakpoints","require","_normalizeStyles","_common","proxifyFunction","fn","breakpoint","screenSize","
|
1
|
+
{"version":3,"names":["_breakpoints","require","_normalizeStyles","_common","proxifyFunction","fn","breakpoint","screenSize","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","entries","Object","parsedStyles","fromEntries","map","_ref","key","value","hasNestedProperties","isTransform","Array","isArray","isDynamicFunction","isValidStyle","getValueForBreakpoint","isWeb","normalizeStyles"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA+C,EAC7DC,UAAsB,KACX,IAAIC,KAAK,CAACH,EAAE,EAAE;EACzBI,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAAa,CAAC,EAAEN,UAAU,EAAEC,UAAU;AAC/E,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAxBAO,OAAA,CAAAV,eAAA,GAAAA,eAAA;AAyBO,MAAMS,UAAU,GAAGA,CACtBE,KAA2B,EAC3BT,UAA+C,EAC/CC,UAAsB,KAClB;EACJ,MAAMS,OAAO,GAAGC,MAAM,CAACD,OAAO,CAACD,KAAK,CAGnC;EAED,MAAMG,YAAY,GAAGD,MAAM,CACtBE,WAAW,CAACH,OAAO,CACfI,GAAG,CAACC,IAAA,IAAkB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACd,MAAMG,mBAAmB,GAAGF,GAAG,KAAK,cAAc,IAAIA,GAAG,KAAK,kBAAkB;IAEhF,IAAIE,mBAAmB,EAAE;MACrB,OAAO,CACHF,GAAG,EACHT,UAAU,CAACU,KAAK,EAA0BjB,UAAU,EAAEC,UAAU,CAAC,CACpE;IACL;IAEA,MAAMkB,WAAW,GAAGH,GAAG,KAAK,WAAW;IAEvC,IAAIG,WAAW,IAAIC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE;MACrC,OAAO,CACHD,GAAG,EACHC,KAAK,CAACH,GAAG,CAACG,KAAK,IAAIV,UAAU,CAACU,KAAK,EAAEjB,UAAU,EAAEC,UAAU,CAAC,CAAC,CAChE;IACL;IAEA,MAAMqB,iBAAiB,GAAG,OAAOL,KAAK,KAAK,UAAU;IACrD,MAAMM,YAAY,GAAG,OAAON,KAAK,KAAK,QAAQ;IAE9C,IAAIK,iBAAiB,IAAIC,YAAY,EAAE;MACnC,OAAO,CAACP,GAAG,EAAEC,KAAK,CAAC;IACvB;IAEA,OAAO,CACHD,GAAG,EACH,IAAAQ,kCAAqB,EACjBP,KAAK,EACLjB,UAAU,EACVC,UACJ,CAAC,CACJ;EACL,CAAC,CACL,CAAC;EAEL,OAAOwB,aAAK,GACN,IAAAC,gCAAe,EAACd,YAAY,CAAC,GAC7BA,YAAY;AACtB,CAAC;AAAAJ,OAAA,CAAAD,UAAA,GAAAA,UAAA"}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
export class UnistyleRegistry {
|
2
|
+
isClosed = false;
|
3
|
+
themes = {};
|
4
|
+
breakpoints = {};
|
5
|
+
sortedBreakpointPairs = [];
|
6
|
+
config = {};
|
7
|
+
constructor(unistylesBridge) {
|
8
|
+
this.unistylesBridge = unistylesBridge;
|
9
|
+
}
|
10
|
+
addThemes = themes => {
|
11
|
+
this.themes = themes;
|
12
|
+
return this;
|
13
|
+
};
|
14
|
+
addBreakpoints = breakpoints => {
|
15
|
+
this.unistylesBridge.useBreakpoints(breakpoints);
|
16
|
+
this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs;
|
17
|
+
return this;
|
18
|
+
};
|
19
|
+
addConfig = config => {
|
20
|
+
this.config = config;
|
21
|
+
if (config.featureFlags && config.featureFlags.length > 0) {
|
22
|
+
this.unistylesBridge.useFeatureFlags(config.featureFlags);
|
23
|
+
}
|
24
|
+
if (config.colorScheme) {
|
25
|
+
this.unistylesBridge.useColorScheme(config.colorScheme);
|
26
|
+
}
|
27
|
+
return this;
|
28
|
+
};
|
29
|
+
}
|
30
|
+
//# sourceMappingURL=UnistyleRegistry.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistyleRegistry","isClosed","themes","breakpoints","sortedBreakpointPairs","config","constructor","unistylesBridge","addThemes","addBreakpoints","useBreakpoints","addConfig","featureFlags","length","useFeatureFlags","colorScheme","useColorScheme"],"sourceRoot":"../../src","sources":["UnistyleRegistry.ts"],"mappings":"AAGA,OAAO,MAAMA,gBAAgB,CAAC;EACnBC,QAAQ,GAAG,KAAK;EAChBC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,WAAW,GAAyB,CAAC,CAAC;EACtCC,qBAAqB,GAA0F,EAAE;EACjHC,MAAM,GAAoB,CAAC,CAAC;EAEnCC,WAAWA,CAASC,eAAgC,EAAE;IAAA,KAAlCA,eAAgC,GAAhCA,eAAgC;EAAG;EAEhDC,SAAS,GAAIN,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,OAAO,IAAI;EACf,CAAC;EAEMO,cAAc,GAAIN,WAAiC,IAAK;IAC3D,IAAI,CAACI,eAAe,CAACG,cAAc,CAACP,WAAW,CAAC;IAChD,IAAI,CAACC,qBAAqB,GAAG,IAAI,CAACG,eAAe,CAACH,qBAAqB;IAEvE,OAAO,IAAI;EACf,CAAC;EAEMO,SAAS,GAAIN,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,IAAIA,MAAM,CAACO,YAAY,IAAIP,MAAM,CAACO,YAAY,CAACC,MAAM,GAAG,CAAC,EAAE;MACvD,IAAI,CAACN,eAAe,CAACO,eAAe,CAACT,MAAM,CAACO,YAAY,CAAC;IAC7D;IAEA,IAAIP,MAAM,CAACU,WAAW,EAAE;MACpB,IAAI,CAACR,eAAe,CAACS,cAAc,CAACX,MAAM,CAACU,WAAW,CAAC;IAC3D;IAEA,OAAO,IAAI;EACf,CAAC;AACL"}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { UnistylesModule } from './UnistylesModule';
|
2
|
+
import { UnistylesRuntime } from './UnistylesRuntime';
|
3
|
+
import { UnistylesEngine } from './UnistylesEngine';
|
4
|
+
import { UnistyleRegistry } from './UnistyleRegistry';
|
5
|
+
import { UnistylesError } from './types';
|
6
|
+
class Unistyles {
|
7
|
+
constructor() {
|
8
|
+
const isInstalled = UnistylesModule?.install() ?? false;
|
9
|
+
if (!isInstalled) {
|
10
|
+
throw new Error(UnistylesError.RuntimeUnavailable);
|
11
|
+
}
|
12
|
+
|
13
|
+
// @ts-ignore
|
14
|
+
this._bridge = global.__UNISTYLES__;
|
15
|
+
this._registry = new UnistyleRegistry(this._bridge);
|
16
|
+
this._runtime = new UnistylesRuntime(this._bridge, this._registry);
|
17
|
+
this._engine = new UnistylesEngine(this._registry, this._runtime);
|
18
|
+
}
|
19
|
+
get registry() {
|
20
|
+
return this._registry;
|
21
|
+
}
|
22
|
+
get runtime() {
|
23
|
+
return this._runtime;
|
24
|
+
}
|
25
|
+
get engine() {
|
26
|
+
return this._engine;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
export const unistyles = new Unistyles();
|
30
|
+
//# sourceMappingURL=Unistyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistylesModule","UnistylesRuntime","UnistylesEngine","UnistyleRegistry","UnistylesError","Unistyles","constructor","isInstalled","install","Error","RuntimeUnavailable","_bridge","global","__UNISTYLES__","_registry","_runtime","_engine","registry","runtime","engine","unistyles"],"sourceRoot":"../../src","sources":["Unistyles.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,SAAS,CAAC;EAMZC,WAAWA,CAAA,EAAG;IACV,MAAMC,WAAW,GAAGP,eAAe,EAAEQ,OAAO,CAAC,CAAC,IAAI,KAAK;IAEvD,IAAI,CAACD,WAAW,EAAE;MACd,MAAM,IAAIE,KAAK,CAACL,cAAc,CAACM,kBAAkB,CAAC;IACtD;;IAEA;IACA,IAAI,CAACC,OAAO,GAAGC,MAAM,CAACC,aAAgC;IACtD,IAAI,CAACC,SAAS,GAAG,IAAIX,gBAAgB,CAAC,IAAI,CAACQ,OAAO,CAAC;IACnD,IAAI,CAACI,QAAQ,GAAG,IAAId,gBAAgB,CAAC,IAAI,CAACU,OAAO,EAAE,IAAI,CAACG,SAAS,CAAC;IAClE,IAAI,CAACE,OAAO,GAAG,IAAId,eAAe,CAAC,IAAI,CAACY,SAAS,EAAE,IAAI,CAACC,QAAQ,CAAC;EACrE;EAEA,IAAWE,QAAQA,CAAA,EAAG;IAClB,OAAO,IAAI,CAACH,SAAS;EACzB;EAEA,IAAWI,OAAOA,CAAA,EAAG;IACjB,OAAO,IAAI,CAACH,QAAQ;EACxB;EAEA,IAAWI,MAAMA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACH,OAAO;EACvB;AACJ;AAEA,OAAO,MAAMI,SAAS,GAAG,IAAIf,SAAS,CAAC,CAAC"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// todo implement engine
|
2
|
+
export class UnistylesEngine {
|
3
|
+
// @ts-ignore
|
4
|
+
constructor(registry, runtime) {
|
5
|
+
this.registry = registry;
|
6
|
+
this.runtime = runtime;
|
7
|
+
this.registry = registry;
|
8
|
+
this.runtime = runtime;
|
9
|
+
}
|
10
|
+
|
11
|
+
// UnistylesEngine.parseStyleSheet
|
12
|
+
// UnistylesEngine.parseStyle
|
13
|
+
// UnistylesEngine.proxify
|
14
|
+
}
|
15
|
+
//# sourceMappingURL=UnistylesEngine.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistylesEngine","constructor","registry","runtime"],"sourceRoot":"../../src","sources":["UnistylesEngine.ts"],"mappings":"AAGA;AACA,OAAO,MAAMA,eAAe,CAAC;EACzB;EACAC,WAAWA,CAASC,QAA0B,EAAUC,OAAyB,EAAE;IAAA,KAA/DD,QAA0B,GAA1BA,QAA0B;IAAA,KAAUC,OAAyB,GAAzBA,OAAyB;IAC7E,IAAI,CAACD,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;;EAEA;EACA;EACA;AACJ"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["NativeModules","UnistylesModule","Unistyles"],"sourceRoot":"../../src","sources":["UnistylesModule.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAM5C,OAAO,MAAMC,eAAe,GAAGD,aAAa,EAAEE,SAAkC"}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { UnistylesError } from './types';
|
2
|
+
export class UnistylesRuntime {
|
3
|
+
constructor(unistylesBridge, registry) {
|
4
|
+
this.unistylesBridge = unistylesBridge;
|
5
|
+
this.registry = registry;
|
6
|
+
}
|
7
|
+
get colorScheme() {
|
8
|
+
return this.unistylesBridge.colorScheme;
|
9
|
+
}
|
10
|
+
get breakpoints() {
|
11
|
+
return this.registry.breakpoints;
|
12
|
+
}
|
13
|
+
get sortedBreakpoints() {
|
14
|
+
return this.registry.sortedBreakpointPairs;
|
15
|
+
}
|
16
|
+
get config() {
|
17
|
+
return this.registry.config;
|
18
|
+
}
|
19
|
+
get theme() {
|
20
|
+
return this.unistylesBridge.theme;
|
21
|
+
}
|
22
|
+
get currentBreakpoint() {
|
23
|
+
return this.unistylesBridge.breakpoint;
|
24
|
+
}
|
25
|
+
setColorScheme = scheme => {
|
26
|
+
if (scheme !== this.colorScheme) {
|
27
|
+
this.unistylesBridge.useColorScheme(scheme);
|
28
|
+
}
|
29
|
+
};
|
30
|
+
setTheme = name => {
|
31
|
+
if (name !== this.theme && this.hasTheme(name)) {
|
32
|
+
this.unistylesBridge.useTheme(name);
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
return false;
|
36
|
+
};
|
37
|
+
hasTheme = name => name in this.registry.themes;
|
38
|
+
getTheme = forName => {
|
39
|
+
if (!this.hasTheme(forName)) {
|
40
|
+
throw new Error(UnistylesError.ThemeNotFound);
|
41
|
+
}
|
42
|
+
return this.registry.themes[forName];
|
43
|
+
};
|
44
|
+
}
|
45
|
+
//# sourceMappingURL=UnistylesRuntime.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistylesError","UnistylesRuntime","constructor","unistylesBridge","registry","colorScheme","breakpoints","sortedBreakpoints","sortedBreakpointPairs","config","theme","currentBreakpoint","breakpoint","setColorScheme","scheme","useColorScheme","setTheme","name","hasTheme","useTheme","themes","getTheme","forName","Error","ThemeNotFound"],"sourceRoot":"../../src","sources":["UnistylesRuntime.ts"],"mappings":"AAEA,SAA+BA,cAAc,QAAQ,SAAS;AAG9D,OAAO,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,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,QAAQ,CAACE,WAAW;EACpC;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,QAAQ,CAACI,qBAAqB;EAC9C;EAEA,IAAWC,MAAMA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACL,QAAQ,CAACK,MAAM;EAC/B;EAEA,IAAWC,KAAKA,CAAA,EAAG;IACf,OAAO,IAAI,CAACP,eAAe,CAACO,KAAK;EACrC;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACR,eAAe,CAACS,UAAU;EAC1C;EAEOC,cAAc,GAAIC,MAA4B,IAAK;IACtD,IAAIA,MAAM,KAAK,IAAI,CAACT,WAAW,EAAE;MAC7B,IAAI,CAACF,eAAe,CAACY,cAAc,CAACD,MAAM,CAAC;IAC/C;EACJ,CAAC;EAEME,QAAQ,GAAIC,IAA2B,IAAK;IAC/C,IAAIA,IAAI,KAAK,IAAI,CAACP,KAAK,IAAI,IAAI,CAACQ,QAAQ,CAACD,IAAI,CAAC,EAAE;MAC5C,IAAI,CAACd,eAAe,CAACgB,QAAQ,CAACF,IAAI,CAAC;MAEnC,OAAO,IAAI;IACf;IAEA,OAAO,KAAK;EAChB,CAAC;EAEMC,QAAQ,GAAID,IAA2B,IAAKA,IAAI,IAAI,IAAI,CAACb,QAAQ,CAACgB,MAAM;EAExEC,QAAQ,GAAIC,OAA8B,IAAK;IAClD,IAAI,CAAC,IAAI,CAACJ,QAAQ,CAACI,OAAO,CAAC,EAAE;MACzB,MAAM,IAAIC,KAAK,CAACvB,cAAc,CAACwB,aAAa,CAAC;IACjD;IAEA,OAAO,IAAI,CAACpB,QAAQ,CAACgB,MAAM,CAACE,OAAO,CAAC;EACxC,CAAC;AACL"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["createStyleSheet","styles"],"sourceRoot":"../../src","sources":["createStyleSheet.ts"],"mappings":"AAKA,OAAO,MAAMA,gBAAgB,GAAuCC,MAA+E,IAAY;EAC3J,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;IAC9B,OAAOA,MAAM;EACjB;EAEA,OAAOA,MAAM;AACjB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["global.ts"],"mappings":""}
|
package/lib/module/index.js
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { unistyles } from './Unistyles';
|
2
|
+
import { UnistylesColorScheme } from './types';
|
3
|
+
export { useInitialTheme } from './useInitialTheme';
|
4
|
+
export { useStyles } from './useStyles';
|
5
|
+
export { createStyleSheet } from './createStyleSheet';
|
6
|
+
const {
|
7
|
+
addThemes,
|
8
|
+
addBreakpoints,
|
9
|
+
addConfig
|
10
|
+
} = unistyles.registry;
|
11
|
+
const UnistylesRuntime = unistyles.runtime;
|
12
|
+
const UnistylesRegistry = {
|
13
|
+
addThemes,
|
14
|
+
addBreakpoints,
|
15
|
+
addConfig
|
16
|
+
};
|
17
|
+
export { UnistylesRuntime, UnistylesRegistry };
|
18
|
+
export { UnistylesColorScheme };
|
3
19
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["unistyles","UnistylesColorScheme","useInitialTheme","useStyles","createStyleSheet","addThemes","addBreakpoints","addConfig","registry","UnistylesRuntime","runtime","UnistylesRegistry"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,SAAS,QAAQ,aAAa;AAEvC,SAASC,oBAAoB,QAAQ,SAAS;AAE9C,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAM;EAAEC,SAAS;EAAEC,cAAc;EAAEC;AAAW,CAAC,GAAGP,SAAS,CAACQ,QAAQ;AACpE,MAAMC,gBAAgB,GAAGT,SAAS,CAACU,OAAO;AAC1C,MAAMC,iBAAiB,GAAG;EACtBN,SAAS;EACTC,cAAc;EACdC;AACJ,CAAC;AAED,SACIE,gBAAgB,EAChBE,iBAAiB;AAGrB,SACIV,oBAAoB"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export let UnistylesColorScheme = /*#__PURE__*/function (UnistylesColorScheme) {
|
2
|
+
UnistylesColorScheme["System"] = "system";
|
3
|
+
UnistylesColorScheme["Manual"] = "manual";
|
4
|
+
return UnistylesColorScheme;
|
5
|
+
}({});
|
6
|
+
export let CxxUnistylesEventTypes = /*#__PURE__*/function (CxxUnistylesEventTypes) {
|
7
|
+
CxxUnistylesEventTypes["Theme"] = "theme";
|
8
|
+
CxxUnistylesEventTypes["Size"] = "size";
|
9
|
+
CxxUnistylesEventTypes["Breakpoint"] = "breakpoint";
|
10
|
+
return CxxUnistylesEventTypes;
|
11
|
+
}({});
|
12
|
+
export let UnistylesError = /*#__PURE__*/function (UnistylesError) {
|
13
|
+
UnistylesError["RuntimeUnavailable"] = "UNISTYLES_ERROR_RUNTIME_UNAVAILABLE";
|
14
|
+
UnistylesError["ThemeNotFound"] = "UNISTYLES_ERROR_THEME_NOT_FOUND";
|
15
|
+
return UnistylesError;
|
16
|
+
}({});
|
17
|
+
//# sourceMappingURL=cxx.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistylesColorScheme","CxxUnistylesEventTypes","UnistylesError"],"sourceRoot":"../../../src","sources":["types/cxx.ts"],"mappings":"AAGA,WAAYA,oBAAoB,0BAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAAA,OAApBA,oBAAoB;AAAA;AAwBhC,WAAYC,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AA8BlC,WAAYC,cAAc,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"AAAA,cAAc,cAAc"}
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"AAAA,cAAc,cAAc;AAC5B,cAAc,OAAO"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["useRef","unistyles","useInitialTheme","forName","runtime","setTheme"],"sourceRoot":"../../src","sources":["useInitialTheme.ts"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;AAC9B,SAASC,SAAS,QAAQ,aAAa;AAGvC,OAAO,MAAMC,eAAe,GAAIC,OAA8B,IAAK;EAC/DH,MAAM,CAACC,SAAS,CAACG,OAAO,CAACC,QAAQ,CAACF,OAAO,CAAC,CAAC;AAC/C,CAAC"}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { useMemo } from 'react';
|
2
|
+
import { StyleSheet } from 'react-native';
|
3
|
+
import { parseStyle, proxifyFunction } from './utils';
|
4
|
+
import { useUnistyles } from './useUnistyles';
|
5
|
+
|
6
|
+
// todo types
|
7
|
+
|
8
|
+
export const useStyles = stylesheet => {
|
9
|
+
const {
|
10
|
+
theme,
|
11
|
+
breakpoint,
|
12
|
+
screenSize
|
13
|
+
} = useUnistyles();
|
14
|
+
if (!stylesheet) {
|
15
|
+
return {
|
16
|
+
theme,
|
17
|
+
breakpoint,
|
18
|
+
styles: {}
|
19
|
+
};
|
20
|
+
}
|
21
|
+
const parsedStyles = useMemo(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet]);
|
22
|
+
const dynamicStyleSheet = useMemo(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
|
23
|
+
let [key, value] = _ref;
|
24
|
+
const style = value;
|
25
|
+
if (typeof value === 'function') {
|
26
|
+
return {
|
27
|
+
...acc,
|
28
|
+
[key]: proxifyFunction(value, breakpoint, screenSize)
|
29
|
+
};
|
30
|
+
}
|
31
|
+
return StyleSheet.create({
|
32
|
+
...acc,
|
33
|
+
[key]: parseStyle(style, breakpoint, screenSize)
|
34
|
+
});
|
35
|
+
}, {}), [breakpoint, screenSize, parsedStyles]);
|
36
|
+
return {
|
37
|
+
theme,
|
38
|
+
breakpoint,
|
39
|
+
styles: dynamicStyleSheet
|
40
|
+
};
|
41
|
+
};
|
42
|
+
//# sourceMappingURL=useStyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","useUnistyles","useStyles","stylesheet","theme","breakpoint","screenSize","styles","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","create"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,EAAEC,eAAe,QAAQ,SAAS;AAErD,SAASC,YAAY,QAAQ,gBAAgB;;AAG7C;;AAGA,OAAO,MAAMC,SAAS,GAAsCC,UAA4C,IAAK;EACzG,MAAM;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAW,CAAC,GAAGL,YAAY,CAAC,CAAC;EAExD,IAAI,CAACE,UAAU,EAAE;IACb,OAAO;MACHC,KAAK;MACLC,UAAU;MACVE,MAAM,EAAE,CAAC;IACb,CAAC;EACL;EAEA,MAAMC,YAAY,GAAGX,OAAO,CAAC,MAAM,OAAOM,UAAU,KAAK,UAAU,GAC7DA,UAAU,CAACC,KAAM,CAAC,GAClBD,UAAU,EAAE,CAACC,KAAK,EAAED,UAAU,CAAC,CAAC;EAEtC,MAAMM,iBAAiB,GAAGZ,OAAO,CAAC,MAAMa,MAAM,CACzCC,OAAO,CAACH,YAAY,CAAC,CACrBI,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACtB,MAAMG,KAAK,GAAGD,KAA8B;IAE5C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MAC7B,OAAO;QACH,GAAGH,GAAG;QACN,CAACE,GAAG,GAAGf,eAAe,CAACgB,KAAK,EAAEX,UAAU,EAAGC,UAAU;MACzD,CAAC;IACL;IAEA,OAAOR,UAAU,CAACoB,MAAM,CAAC;MACrB,GAAGL,GAAG;MACN,CAACE,GAAG,GAAGhB,UAAU,CAAKkB,KAAK,EAAEZ,UAAU,EAAGC,UAAU;IACxD,CAAC,CAAC;EACN,CAAC,EAAE,CAAC,CAAO,CAAC,EAAE,CAACD,UAAU,EAAEC,UAAU,EAAEE,YAAY,CAAC,CAAC;EAEzD,OAAO;IACHJ,KAAK;IACLC,UAAU;IACVE,MAAM,EAAEE;EACZ,CAAC;AACL,CAAC"}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { NativeEventEmitter, NativeModules } from 'react-native';
|
2
|
+
import { useEffect, useState } from 'react';
|
3
|
+
import { CxxUnistylesEventTypes } from './types';
|
4
|
+
import { unistyles } from './Unistyles';
|
5
|
+
const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles);
|
6
|
+
export const useUnistyles = () => {
|
7
|
+
const [theme, setTheme] = useState(unistyles.runtime.getTheme(unistyles.runtime.theme));
|
8
|
+
const [breakpoint, setBreakpoint] = useState(unistyles.runtime.currentBreakpoint);
|
9
|
+
const [screenSize, setScreenSize] = useState({
|
10
|
+
width: 0,
|
11
|
+
height: 0
|
12
|
+
});
|
13
|
+
useEffect(() => {
|
14
|
+
const subscription = unistylesEvents.addListener('onChange', event => {
|
15
|
+
switch (event.type) {
|
16
|
+
case CxxUnistylesEventTypes.Theme:
|
17
|
+
{
|
18
|
+
const themeEvent = event;
|
19
|
+
setTheme(unistyles.runtime.getTheme(themeEvent.payload.currentTheme));
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
case CxxUnistylesEventTypes.Size:
|
23
|
+
{
|
24
|
+
const sizeEvent = event;
|
25
|
+
setScreenSize({
|
26
|
+
width: sizeEvent.payload.width,
|
27
|
+
height: sizeEvent.payload.height
|
28
|
+
});
|
29
|
+
// todo
|
30
|
+
// setBreakpoint(unistyles.runtime.currentBreakpoint)
|
31
|
+
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
case CxxUnistylesEventTypes.Breakpoint:
|
35
|
+
{
|
36
|
+
const breakpointEvent = event;
|
37
|
+
setBreakpoint(breakpointEvent.payload.currentBreakpoint);
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
default:
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
});
|
44
|
+
return subscription.remove;
|
45
|
+
}, []);
|
46
|
+
return {
|
47
|
+
theme,
|
48
|
+
breakpoint,
|
49
|
+
screenSize
|
50
|
+
};
|
51
|
+
};
|
52
|
+
//# sourceMappingURL=useUnistyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NativeModules","useEffect","useState","CxxUnistylesEventTypes","unistyles","unistylesEvents","Unistyles","useUnistyles","theme","setTheme","runtime","getTheme","breakpoint","setBreakpoint","currentBreakpoint","screenSize","setScreenSize","width","height","subscription","addListener","event","type","Theme","themeEvent","payload","currentTheme","Size","sizeEvent","Breakpoint","breakpointEvent","remove"],"sourceRoot":"../../src","sources":["useUnistyles.ts"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAChE,SAASC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAO3C,SAASC,sBAAsB,QAAQ,SAAS;AAChD,SAASC,SAAS,QAAQ,aAAa;AAEvC,MAAMC,eAAe,GAAG,IAAIN,kBAAkB,CAACC,aAAa,CAACM,SAAS,CAAC;AAEvE,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAM;EAC9B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGP,QAAQ,CAACE,SAAS,CAACM,OAAO,CAACC,QAAQ,CAACP,SAAS,CAACM,OAAO,CAACF,KAAK,CAAC,CAAC;EACvF,MAAM,CAACI,UAAU,EAAEC,aAAa,CAAC,GAAGX,QAAQ,CAACE,SAAS,CAACM,OAAO,CAACI,iBAAiB,CAAC;EACjF,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGd,QAAQ,CAAC;IACzCe,KAAK,EAAE,CAAC;IACRC,MAAM,EAAE;EACZ,CAAC,CAAC;EAEFjB,SAAS,CAAC,MAAM;IACZ,MAAMkB,YAAY,GAAGd,eAAe,CAACe,WAAW,CAC5C,UAAU,EACTC,KAAsB,IAAK;MACxB,QAAQA,KAAK,CAACC,IAAI;QACd,KAAKnB,sBAAsB,CAACoB,KAAK;UAAE;YAC/B,MAAMC,UAAU,GAAGH,KAA+B;YAElDZ,QAAQ,CAACL,SAAS,CAACM,OAAO,CAACC,QAAQ,CAACa,UAAU,CAACC,OAAO,CAACC,YAAY,CAAC,CAAC;YAErE;UACJ;QACA,KAAKvB,sBAAsB,CAACwB,IAAI;UAAE;YAC9B,MAAMC,SAAS,GAAGP,KAA8B;YAEhDL,aAAa,CAAC;cACVC,KAAK,EAAEW,SAAS,CAACH,OAAO,CAACR,KAAK;cAC9BC,MAAM,EAAEU,SAAS,CAACH,OAAO,CAACP;YAC9B,CAAC,CAAC;YACF;YACA;;YAEA;UACJ;QACA,KAAKf,sBAAsB,CAAC0B,UAAU;UAAE;YACpC,MAAMC,eAAe,GAAGT,KAAoC;YAE5DR,aAAa,CAACiB,eAAe,CAACL,OAAO,CAACX,iBAAiB,CAAC;YAExD;UACJ;QACA;UACI;MACR;IACJ,CACJ,CAAC;IAED,OAAOK,YAAY,CAACY,MAAM;EAC9B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACHvB,KAAK;IACLI,UAAU;IACVG;EACJ,CAAC;AACL,CAAC"}
|