react-native-unistyles 2.0.0-rc.1 → 2.0.0-rc.3
Sign up to get free protection for your applications and to get access to all the features.
- package/android/src/main/cxx/cpp-adapter.cpp +26 -2
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +29 -3
- package/cxx/UnistylesRuntime.cpp +10 -0
- package/cxx/UnistylesRuntime.h +10 -2
- package/ios/UnistylesHelpers.h +1 -0
- package/ios/UnistylesHelpers.mm +32 -0
- package/ios/UnistylesModule.mm +39 -2
- package/lib/commonjs/common.js +21 -1
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/UnistyleRegistry.js +15 -25
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
- package/lib/commonjs/core/UnistylesModule.js +190 -2
- package/lib/commonjs/core/UnistylesModule.js.map +1 -1
- package/lib/commonjs/core/UnistylesModule.native.js +9 -0
- package/lib/commonjs/core/UnistylesModule.native.js.map +1 -0
- package/lib/commonjs/core/UnistylesRuntime.js +8 -0
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
- package/lib/commonjs/hooks/useCSS.js +36 -1
- package/lib/commonjs/hooks/useCSS.js.map +1 -1
- package/lib/commonjs/hooks/useCSS.native.js +9 -0
- package/lib/commonjs/hooks/useCSS.native.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +8 -1
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/normalizer/normalizer.js +1 -2
- package/lib/commonjs/normalizer/normalizer.js.map +1 -1
- package/lib/commonjs/useStyles.js +2 -3
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/breakpoints.js +2 -11
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/cssMediaQuery.js +3 -9
- package/lib/commonjs/utils/cssMediaQuery.js.map +1 -1
- package/lib/commonjs/utils/mq.js +12 -36
- package/lib/commonjs/utils/mq.js.map +1 -1
- package/lib/commonjs/utils/mqParser.js +1 -2
- package/lib/commonjs/utils/mqParser.js.map +1 -1
- package/lib/commonjs/utils/styles.js +34 -39
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/common.js +20 -0
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/UnistyleRegistry.js +15 -25
- package/lib/module/core/UnistyleRegistry.js.map +1 -1
- package/lib/module/core/UnistylesModule.js +189 -2
- package/lib/module/core/UnistylesModule.js.map +1 -1
- package/lib/module/core/UnistylesModule.native.js +3 -0
- package/lib/module/core/UnistylesModule.native.js.map +1 -0
- package/lib/module/core/UnistylesRuntime.js +8 -0
- package/lib/module/core/UnistylesRuntime.js.map +1 -1
- package/lib/module/hooks/useCSS.js +36 -1
- package/lib/module/hooks/useCSS.js.map +1 -1
- package/lib/module/hooks/useCSS.native.js +2 -0
- package/lib/module/hooks/useCSS.native.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +8 -1
- package/lib/module/hooks/useUnistyles.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/normalizer/normalizer.js +1 -2
- package/lib/module/normalizer/normalizer.js.map +1 -1
- package/lib/module/useStyles.js +2 -3
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/breakpoints.js +2 -11
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/cssMediaQuery.js +3 -9
- package/lib/module/utils/cssMediaQuery.js.map +1 -1
- package/lib/module/utils/mq.js +12 -36
- package/lib/module/utils/mq.js.map +1 -1
- package/lib/module/utils/mqParser.js +1 -2
- package/lib/module/utils/mqParser.js.map +1 -1
- package/lib/module/utils/styles.js +34 -39
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/src/common.d.ts +19 -1
- package/lib/typescript/src/common.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistylesModule.d.ts +17 -4
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistylesModule.native.d.ts +6 -0
- package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +5 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCSS.d.ts +1 -1
- package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCSS.native.d.ts +3 -0
- package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/unistyles.d.ts +9 -2
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
- package/package.json +6 -8
- package/src/common.ts +21 -1
- package/src/core/UnistylesModule.native.ts +7 -0
- package/src/core/UnistylesModule.ts +227 -4
- package/src/core/UnistylesRuntime.ts +8 -0
- package/src/hooks/useCSS.native.ts +3 -0
- package/src/hooks/useCSS.ts +49 -1
- package/src/hooks/useUnistyles.ts +9 -2
- package/src/index.ts +3 -1
- package/src/types/unistyles.ts +10 -2
- package/src/useStyles.ts +1 -1
- package/lib/commonjs/core/UnistylesModule.web.js +0 -199
- package/lib/commonjs/core/UnistylesModule.web.js.map +0 -1
- package/lib/commonjs/hooks/useCSS.web.js +0 -46
- package/lib/commonjs/hooks/useCSS.web.js.map +0 -1
- package/lib/module/core/UnistylesModule.web.js +0 -192
- package/lib/module/core/UnistylesModule.web.js.map +0 -1
- package/lib/module/hooks/useCSS.web.js +0 -39
- package/lib/module/hooks/useCSS.web.js.map +0 -1
- package/lib/typescript/src/core/UnistylesModule.web.d.ts +0 -19
- package/lib/typescript/src/core/UnistylesModule.web.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useCSS.web.d.ts +0 -3
- package/lib/typescript/src/hooks/useCSS.web.d.ts.map +0 -1
- package/src/core/UnistylesModule.web.ts +0 -227
- package/src/hooks/useCSS.web.ts +0 -51
package/lib/module/common.js
CHANGED
@@ -11,10 +11,30 @@ export const ScreenOrientation = {
|
|
11
11
|
Landscape: 'landscape',
|
12
12
|
Portrait: 'portrait'
|
13
13
|
};
|
14
|
+
export let IOSContentSizeCategory = /*#__PURE__*/function (IOSContentSizeCategory) {
|
15
|
+
IOSContentSizeCategory["ExtraExtraExtraLarge"] = "xxxLarge";
|
16
|
+
IOSContentSizeCategory["ExtraExtraLarge"] = "xxLarge";
|
17
|
+
IOSContentSizeCategory["ExtraLarge"] = "xLarge";
|
18
|
+
IOSContentSizeCategory["Large"] = "Large";
|
19
|
+
IOSContentSizeCategory["Medium"] = "Medium";
|
20
|
+
IOSContentSizeCategory["Small"] = "Small";
|
21
|
+
IOSContentSizeCategory["ExtraSmall"] = "xSmall";
|
22
|
+
IOSContentSizeCategory["Unspecified"] = "unspecified";
|
23
|
+
return IOSContentSizeCategory;
|
24
|
+
}({});
|
25
|
+
export let AndroidContentSizeCategory = /*#__PURE__*/function (AndroidContentSizeCategory) {
|
26
|
+
AndroidContentSizeCategory["Small"] = "Small";
|
27
|
+
AndroidContentSizeCategory["Default"] = "Default";
|
28
|
+
AndroidContentSizeCategory["Large"] = "Large";
|
29
|
+
AndroidContentSizeCategory["ExtraLarge"] = "ExtraLarge";
|
30
|
+
AndroidContentSizeCategory["Huge"] = "Huge";
|
31
|
+
return AndroidContentSizeCategory;
|
32
|
+
}({});
|
14
33
|
export let UnistylesEventType = /*#__PURE__*/function (UnistylesEventType) {
|
15
34
|
UnistylesEventType["Theme"] = "theme";
|
16
35
|
UnistylesEventType["Layout"] = "layout";
|
17
36
|
UnistylesEventType["Plugin"] = "plugin";
|
37
|
+
UnistylesEventType["DynamicTypeSize"] = "dynamicTypeSize";
|
18
38
|
return UnistylesEventType;
|
19
39
|
}({});
|
20
40
|
export let UnistylesError = /*#__PURE__*/function (UnistylesError) {
|
package/lib/module/common.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Platform","warn","message","console","isWeb","OS","isIOS","isAndroid","isMobile","isServer","window","ScreenOrientation","Landscape","Portrait","UnistylesEventType","UnistylesError"],"sourceRoot":"../../src","sources":["common.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,IAAI,GAAIC,OAAe,IAAK;EACrCC,OAAO,CAACF,IAAI,CAAE,gCAA+BC,OAAQ,EAAC,CAAC;AAC3D,CAAC;AAED,OAAO,MAAME,KAAK,GAAGJ,QAAQ,CAACK,EAAE,KAAK,KAAK;AAC1C,OAAO,MAAMC,KAAK,GAAGN,QAAQ,CAACK,EAAE,KAAK,KAAK;AAC1C,OAAO,MAAME,SAAS,GAAGP,QAAQ,CAACK,EAAE,KAAK,SAAS;AAClD,OAAO,MAAMG,QAAQ,GAAGF,KAAK,IAAIC,SAAS;AAC1C,OAAO,MAAME,QAAQ,GAAG,OAAOC,MAAM,KAAK,WAAW;AAErD,OAAO,MAAMC,iBAAiB,GAAG;EAC7BC,SAAS,EAAE,WAAW;EACtBC,QAAQ,EAAE;AACd,CAAU;AAEV,WAAYC,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;
|
1
|
+
{"version":3,"names":["Platform","warn","message","console","isWeb","OS","isIOS","isAndroid","isMobile","isServer","window","ScreenOrientation","Landscape","Portrait","IOSContentSizeCategory","AndroidContentSizeCategory","UnistylesEventType","UnistylesError"],"sourceRoot":"../../src","sources":["common.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,IAAI,GAAIC,OAAe,IAAK;EACrCC,OAAO,CAACF,IAAI,CAAE,gCAA+BC,OAAQ,EAAC,CAAC;AAC3D,CAAC;AAED,OAAO,MAAME,KAAK,GAAGJ,QAAQ,CAACK,EAAE,KAAK,KAAK;AAC1C,OAA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|
-
|
76
|
-
})) {
|
77
|
-
throw new Error(UnistylesError.DuplicatePluginName);
|
78
|
-
}
|
79
|
-
_this.plugins = [plugin].concat(_this.plugins);
|
80
|
-
_this.unistylesBridge.addPlugin(plugin.name, notify);
|
81
|
-
};
|
82
|
-
})();
|
64
|
+
addPlugin = (plugin, notify = true) => {
|
65
|
+
if (plugin.name.startsWith('__unistyles')) {
|
66
|
+
throw new Error(UnistylesError.InvalidPluginName);
|
67
|
+
}
|
68
|
+
if (this.plugins.some(({
|
69
|
+
name
|
70
|
+
}) => name === plugin.name)) {
|
71
|
+
throw new Error(UnistylesError.DuplicatePluginName);
|
72
|
+
}
|
73
|
+
this.plugins = [plugin].concat(this.plugins);
|
74
|
+
this.unistylesBridge.addPlugin(plugin.name, notify);
|
75
|
+
};
|
83
76
|
removePlugin = plugin => {
|
84
77
|
if (plugin.name.startsWith('__unistyles')) {
|
85
78
|
throw new Error(UnistylesError.CantRemoveInternalPlugin);
|
86
79
|
}
|
87
|
-
this.plugins = this.plugins.filter(
|
88
|
-
|
89
|
-
|
90
|
-
} = _ref2;
|
91
|
-
return name !== plugin.name;
|
92
|
-
});
|
80
|
+
this.plugins = this.plugins.filter(({
|
81
|
+
name
|
82
|
+
}) => name !== plugin.name);
|
93
83
|
this.unistylesBridge.removePlugin(plugin.name);
|
94
84
|
};
|
95
85
|
hasTheme = name => name in this.themes;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["isWeb","UnistylesError","cssMediaQueriesPlugin","normalizeWebStylesPlugin","UnistyleRegistry","config","plugins","themeNames","themes","breakpoints","sortedBreakpointPairs","constructor","unistylesBridge","addThemes","keys","Object","addBreakpoints","addConfig","useBreakpoints","adaptiveThemes","useAdaptiveThemes","forEach","plugin","addPlugin","initialTheme","useTheme","experimentalCSSMediaQueries","concat","name","getTheme","forName","length","hasTheme","themeName","Error","ThemeNotFound","ThemeNotSelected","
|
1
|
+
{"version":3,"names":["isWeb","UnistylesError","cssMediaQueriesPlugin","normalizeWebStylesPlugin","UnistyleRegistry","config","plugins","themeNames","themes","breakpoints","sortedBreakpointPairs","constructor","unistylesBridge","addThemes","keys","Object","addBreakpoints","addConfig","useBreakpoints","adaptiveThemes","useAdaptiveThemes","forEach","plugin","addPlugin","initialTheme","useTheme","experimentalCSSMediaQueries","concat","name","getTheme","forName","length","hasTheme","themeName","Error","ThemeNotFound","ThemeNotSelected","notify","startsWith","InvalidPluginName","some","DuplicatePluginName","removePlugin","CantRemoveInternalPlugin","filter"],"sourceRoot":"../../../src","sources":["core/UnistyleRegistry.ts"],"mappings":"AAEA,SAASA,KAAK,EAAEC,cAAc,QAAQ,WAAW;AACjD,SAASC,qBAAqB,EAAEC,wBAAwB,QAAQ,YAAY;AAE5E,OAAO,MAAMC,gBAAgB,CAAC;EACnBC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,OAAO,GAA2BN,KAAK,GACxC,CAACG,wBAAwB,CAAC,GAC1B,EAAE;EACDI,UAAU,GAAiC,EAAE;EAC7CC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,WAAW,GAAyB,CAAC,CAAC;EACtCC,qBAAqB,GAA0F,EAAE;EAExHC,WAAWA,CAASC,eAAgC,EAAE;IAAA,KAAlCA,eAAgC,GAAhCA,eAAgC;EAAG;EAEhDC,SAAS,GAAIL,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,MAAMM,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACN,MAAM,CAAiC;IAEhE,IAAI,CAACI,eAAe,CAACJ,MAAM,GAAGM,IAAI;IAClC,IAAI,CAACP,UAAU,GAAGO,IAAI;IAEtB,OAAO;MACHE,cAAc,EAAE,IAAI,CAACA,cAAc;MACnCC,SAAS,EAAE,IAAI,CAACA;IACpB,CAAC;EACL,CAAC;EAEMD,cAAc,GAAIP,WAAiC,IAAK;IAC3D,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACG,eAAe,CAACM,cAAc,CAACT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1,190 @@
|
|
1
|
-
import { NativeModules } from 'react-native';
|
2
|
-
|
1
|
+
import { NativeEventEmitter, NativeModules } from 'react-native';
|
2
|
+
import { normalizeWebStylesPlugin } from '../plugins';
|
3
|
+
import { isServer } from '../common';
|
4
|
+
export class UnistylesBridgeWeb {
|
5
|
+
#timerRef = undefined;
|
6
|
+
#hasAdaptiveThemes = false;
|
7
|
+
#supportsAutomaticColorScheme = false;
|
8
|
+
#screenWidth = isServer ? undefined : window.innerWidth;
|
9
|
+
#screenHeight = isServer ? undefined : window.innerHeight;
|
10
|
+
#themes = [];
|
11
|
+
#breakpoints = {};
|
12
|
+
#colorScheme = this.getPreferredColorScheme();
|
13
|
+
#themeName = '';
|
14
|
+
#enabledPlugins = [normalizeWebStylesPlugin.name];
|
15
|
+
#unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles);
|
16
|
+
#sortedBreakpointPairs = [];
|
17
|
+
#breakpoint = '';
|
18
|
+
#contentSizeCategory = 'unspecified';
|
19
|
+
constructor() {
|
20
|
+
if (!isServer) {
|
21
|
+
this.setupListeners();
|
22
|
+
this.#screenWidth = window.innerWidth;
|
23
|
+
this.#screenHeight = window.innerHeight;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
install() {
|
27
|
+
// @ts-ignore
|
28
|
+
// eslint-disable-next-line no-undef
|
29
|
+
globalThis.__UNISTYLES__ = new Proxy({}, {
|
30
|
+
get: (_target, prop) => {
|
31
|
+
switch (prop) {
|
32
|
+
case 'themeName':
|
33
|
+
return this.getTheme();
|
34
|
+
case 'screenWidth':
|
35
|
+
return this.#screenWidth;
|
36
|
+
case 'screenHeight':
|
37
|
+
return this.#screenHeight;
|
38
|
+
case 'contentSizeCategory':
|
39
|
+
return this.#contentSizeCategory;
|
40
|
+
case 'breakpoint':
|
41
|
+
return this.#breakpoint || undefined;
|
42
|
+
case 'breakpoints':
|
43
|
+
return this.#breakpoints;
|
44
|
+
case 'hasAdaptiveThemes':
|
45
|
+
return this.#hasAdaptiveThemes;
|
46
|
+
case 'sortedBreakpointPairs':
|
47
|
+
return this.#sortedBreakpointPairs;
|
48
|
+
case 'enabledPlugins':
|
49
|
+
return this.#enabledPlugins;
|
50
|
+
case 'colorScheme':
|
51
|
+
return this.#colorScheme;
|
52
|
+
case 'useTheme':
|
53
|
+
return themeName => this.useTheme(themeName);
|
54
|
+
case 'useBreakpoints':
|
55
|
+
return breakpoints => this.useBreakpoints(breakpoints);
|
56
|
+
case 'useAdaptiveThemes':
|
57
|
+
return enable => this.useAdaptiveThemes(enable);
|
58
|
+
case 'addPlugin':
|
59
|
+
return (pluginName, notify) => this.addPlugin(pluginName, notify);
|
60
|
+
case 'removePlugin':
|
61
|
+
return pluginName => this.removePlugin(pluginName);
|
62
|
+
default:
|
63
|
+
return Reflect.get(this, prop);
|
64
|
+
}
|
65
|
+
},
|
66
|
+
set: (target, prop, newValue, receiver) => {
|
67
|
+
switch (prop) {
|
68
|
+
case 'themes':
|
69
|
+
{
|
70
|
+
this.#themes = newValue;
|
71
|
+
this.#supportsAutomaticColorScheme = newValue.includes('light') && newValue.includes('dark');
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
case 'themeName':
|
75
|
+
{
|
76
|
+
this.#themeName = newValue;
|
77
|
+
this.emitThemeChange();
|
78
|
+
return true;
|
79
|
+
}
|
80
|
+
default:
|
81
|
+
return Reflect.set(target, prop, newValue, receiver);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
});
|
85
|
+
return true;
|
86
|
+
}
|
87
|
+
useTheme(themeName) {
|
88
|
+
this.#themeName = themeName;
|
89
|
+
this.emitThemeChange();
|
90
|
+
}
|
91
|
+
useBreakpoints(breakpoints) {
|
92
|
+
this.#breakpoints = breakpoints;
|
93
|
+
this.#sortedBreakpointPairs = Object.entries(breakpoints).sort(([, a], [, b]) => (a ?? 0) - (b ?? 0));
|
94
|
+
if (!isServer) {
|
95
|
+
this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
useAdaptiveThemes(enable) {
|
99
|
+
this.#hasAdaptiveThemes = enable;
|
100
|
+
if (!this.#hasAdaptiveThemes || !this.#supportsAutomaticColorScheme) {
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
if (this.#themeName !== this.#colorScheme) {
|
104
|
+
this.#themeName = this.#colorScheme;
|
105
|
+
this.emitThemeChange();
|
106
|
+
}
|
107
|
+
}
|
108
|
+
addPlugin(pluginName, notify) {
|
109
|
+
this.#enabledPlugins = [pluginName].concat(this.#enabledPlugins);
|
110
|
+
if (notify) {
|
111
|
+
this.emitPluginChange();
|
112
|
+
}
|
113
|
+
}
|
114
|
+
removePlugin(pluginName) {
|
115
|
+
this.#enabledPlugins = this.#enabledPlugins.filter(name => name !== pluginName);
|
116
|
+
this.emitPluginChange();
|
117
|
+
}
|
118
|
+
getTheme() {
|
119
|
+
if (this.#themes.length === 1) {
|
120
|
+
return this.#themes.at(0);
|
121
|
+
}
|
122
|
+
return this.#themeName;
|
123
|
+
}
|
124
|
+
setupListeners() {
|
125
|
+
window.addEventListener('resize', () => {
|
126
|
+
clearTimeout(this.#timerRef);
|
127
|
+
this.#timerRef = setTimeout(() => {
|
128
|
+
this.#screenWidth = window.innerWidth;
|
129
|
+
this.#screenHeight = window.innerHeight;
|
130
|
+
this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth);
|
131
|
+
this.emitLayoutChange();
|
132
|
+
}, 100);
|
133
|
+
});
|
134
|
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
|
135
|
+
this.#colorScheme = event.matches ? 'dark' : 'light';
|
136
|
+
if (!this.#supportsAutomaticColorScheme || !this.#hasAdaptiveThemes) {
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
if (this.#colorScheme !== this.#themeName) {
|
140
|
+
this.#themeName = this.#colorScheme;
|
141
|
+
this.emitThemeChange();
|
142
|
+
}
|
143
|
+
});
|
144
|
+
}
|
145
|
+
getBreakpointFromScreenWidth(width) {
|
146
|
+
const breakpoint = this.#sortedBreakpointPairs.find(([, value], index, otherBreakpoints) => {
|
147
|
+
const minVal = value;
|
148
|
+
const maxVal = otherBreakpoints[index + 1]?.[1];
|
149
|
+
if (!maxVal) {
|
150
|
+
return true;
|
151
|
+
}
|
152
|
+
return width >= minVal && width < maxVal;
|
153
|
+
});
|
154
|
+
return breakpoint?.at(0);
|
155
|
+
}
|
156
|
+
getPreferredColorScheme() {
|
157
|
+
if (!isServer && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
158
|
+
return 'dark';
|
159
|
+
}
|
160
|
+
return 'light';
|
161
|
+
}
|
162
|
+
emitPluginChange() {
|
163
|
+
this.#unistylesEvents.emit('__unistylesOnChange', {
|
164
|
+
type: 'plugin'
|
165
|
+
});
|
166
|
+
}
|
167
|
+
emitThemeChange() {
|
168
|
+
this.#unistylesEvents.emit('__unistylesOnChange', {
|
169
|
+
type: 'theme',
|
170
|
+
payload: {
|
171
|
+
themeName: this.#themeName
|
172
|
+
}
|
173
|
+
});
|
174
|
+
}
|
175
|
+
emitLayoutChange() {
|
176
|
+
this.#unistylesEvents.emit('__unistylesOnChange', {
|
177
|
+
type: 'layout',
|
178
|
+
payload: {
|
179
|
+
breakpoint: this.#breakpoint,
|
180
|
+
orientation: this.#screenWidth > this.#screenHeight ? 'landscape' : 'portrait',
|
181
|
+
screen: {
|
182
|
+
width: this.#screenWidth,
|
183
|
+
height: this.#screenHeight
|
184
|
+
}
|
185
|
+
}
|
186
|
+
});
|
187
|
+
}
|
188
|
+
}
|
189
|
+
export const UnistylesModule = new UnistylesBridgeWeb();
|
3
190
|
//# sourceMappingURL=UnistylesModule.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["NativeModules","
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NativeModules","normalizeWebStylesPlugin","isServer","UnistylesBridgeWeb","timerRef","undefined","hasAdaptiveThemes","supportsAutomaticColorScheme","screenWidth","window","innerWidth","screenHeight","innerHeight","themes","breakpoints","colorScheme","getPreferredColorScheme","themeName","enabledPlugins","name","unistylesEvents","Unistyles","sortedBreakpointPairs","breakpoint","contentSizeCategory","constructor","setupListeners","install","globalThis","__UNISTYLES__","Proxy","get","_target","prop","getTheme","useTheme","useBreakpoints","enable","useAdaptiveThemes","pluginName","notify","addPlugin","removePlugin","Reflect","set","target","newValue","receiver","includes","emitThemeChange","Object","entries","sort","a","b","getBreakpointFromScreenWidth","concat","emitPluginChange","filter","length","at","addEventListener","clearTimeout","setTimeout","emitLayoutChange","matchMedia","event","matches","width","find","value","index","otherBreakpoints","minVal","maxVal","emit","type","payload","orientation","screen","height","UnistylesModule"],"sourceRoot":"../../../src","sources":["core/UnistylesModule.ts"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAGhE,SAASC,wBAAwB,QAAQ,YAAY;AACrD,SAASC,QAAQ,QAAQ,WAAW;AAEpC,OAAO,MAAMC,kBAAkB,CAAC;EAC5B,CAACC,QAAQ,GAAmCC,SAAS;EACrD,CAACC,iBAAiB,GAAY,KAAK;EACnC,CAACC,4BAA4B,GAAG,KAAK;EACrC,CAACC,WAAW,GAAGN,QAAQ,GAAGG,SAAS,GAAGI,MAAM,CAACC,UAAU;EACvD,CAACC,YAAY,GAAGT,QAAQ,GAAGG,SAAS,GAAGI,MAAM,CAACG,WAAW;EACzD,CAACC,MAAM,GAAiC,EAAE;EAC1C,CAACC,WAAW,GAAyB,CAAC,CAAC;EACvC,CAACC,WAAW,GAAoB,IAAI,CAACC,uBAAuB,CAAC,CAAC;EAC9D,CAACC,SAAS,GAA0B,EAAE;EACtC,CAACC,cAAc,GAAkB,CAACjB,wBAAwB,CAACkB,IAAI,CAAC;EAChE,CAACC,eAAe,GAAG,IAAIrB,kBAAkB,CAACC,aAAa,CAACqB,SAAS,CAAC;EAClE,CAACC,qBAAqB,GAAgD,EAAE;EACxE,CAACC,UAAU,GAA+B,EAAE;EAC5C,CAACC,mBAAmB,GA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A,OAAO,MAAMsE,eAAe,GAAG,IAAI9E,kBAAkB,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["NativeModules","UnistylesModule","Unistyles"],"sourceRoot":"../../../src","sources":["core/UnistylesModule.native.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAM5C,OAAO,MAAMC,eAAe,GAAGD,aAAa,EAAEE,SAAkC"}
|
@@ -32,6 +32,14 @@ export class UnistylesRuntime {
|
|
32
32
|
return this.unistylesBridge.themeName;
|
33
33
|
}
|
34
34
|
|
35
|
+
/**
|
36
|
+
* Get the current content size category
|
37
|
+
* @returns - The current content size category
|
38
|
+
*/
|
39
|
+
get contentSizeCategory() {
|
40
|
+
return this.unistylesBridge.contentSizeCategory;
|
41
|
+
}
|
42
|
+
|
35
43
|
/**
|
36
44
|
* Get the current breakpoint based on device size
|
37
45
|
* @returns - The current breakpoint
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ScreenOrientation","UnistylesError","UnistylesRuntime","constructor","unistylesBridge","unistylesRegistry","colorScheme","hasAdaptiveThemes","themeName","breakpoint","breakpoints","enabledPlugins","screen","width","screenWidth","height","screenHeight","orientation","Landscape","Portrait","setTheme","name","hasTheme","useTheme","Error","ThemeNotRegistered","setAdaptiveThemes","enable","useAdaptiveThemes","addPlugin","plugin","removePlugin"],"sourceRoot":"../../../src","sources":["core/UnistylesRuntime.ts"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,cAAc,QAAQ,WAAW;AAK7D;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,iBAAmC,EAAE;IAAA,KAA/ED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,iBAAmC,GAAnCA,iBAAmC;EAAG;;EAEpG;AACJ;AACA;AACA;EACI,IAAWC,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,eAAe,CAACE,WAAW;EAC3C;;EAEA;AACJ;AACA;AACA;EACI,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,eAAe,CAACG,iBAAiB;EACjD;;EAEA;AACJ;AACA;AACA;EACI,IAAWC,SAASA,CAAA,EAAG;IACnB,OAAO,IAAI,CAACJ,eAAe,CAACI,SAAS;EACzC;;EAEA;AACJ;AACA;AACA;EACI,IAAWC,
|
1
|
+
{"version":3,"names":["ScreenOrientation","UnistylesError","UnistylesRuntime","constructor","unistylesBridge","unistylesRegistry","colorScheme","hasAdaptiveThemes","themeName","contentSizeCategory","breakpoint","breakpoints","enabledPlugins","screen","width","screenWidth","height","screenHeight","orientation","Landscape","Portrait","setTheme","name","hasTheme","useTheme","Error","ThemeNotRegistered","setAdaptiveThemes","enable","useAdaptiveThemes","addPlugin","plugin","removePlugin"],"sourceRoot":"../../../src","sources":["core/UnistylesRuntime.ts"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,cAAc,QAAQ,WAAW;AAK7D;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,iBAAmC,EAAE;IAAA,KAA/ED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,iBAAmC,GAAnCA,iBAAmC;EAAG;;EAEpG;AACJ;AACA;AACA;EACI,IAAWC,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,eAAe,CAACE,WAAW;EAC3C;;EAEA;AACJ;AACA;AACA;EACI,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,eAAe,CAACG,iBAAiB;EACjD;;EAEA;AACJ;AACA;AACA;EACI,IAAWC,SAASA,CAAA,EAAG;IACnB,OAAO,IAAI,CAACJ,eAAe,CAACI,SAAS;EACzC;;EAEA;AACJ;AACA;AACA;EACI,IAAWC,mBAAmBA,CAAA,EAAG;IAC7B,OAAO,IAAI,CAACL,eAAe,CAACK,mBAAmB;EACnD;;EAEA;AACJ;AACA;A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IC,MAAuB,IAAK;IAC5C,IAAI,CAAC1B,iBAAiB,CAACyB,SAAS,CAACC,MAAM,CAAC;EAC5C,CAAC;;EAED;AACJ;AACA;AACA;EACWC,YAAY,GAAID,MAAuB,IAAK;IAC/C,IAAI,CAAC1B,iBAAiB,CAAC2B,YAAY,CAACD,MAAM,CAAC;EAC/C,CAAC;AACL"}
|
@@ -1,2 +1,37 @@
|
|
1
|
-
|
1
|
+
import { useInsertionEffect, useRef } from 'react';
|
2
|
+
import { unistyles } from '../core';
|
3
|
+
import { generateReactNativeWebId } from '../utils';
|
4
|
+
export const useCSS = stylesheet => {
|
5
|
+
const insertedIds = useRef([]);
|
6
|
+
useInsertionEffect(() => {
|
7
|
+
if (!unistyles.registry.config.experimentalCSSMediaQueries) {
|
8
|
+
return;
|
9
|
+
}
|
10
|
+
Object.entries(stylesheet).forEach(([_key, value]) => {
|
11
|
+
Object.entries(value).forEach(([prop, val]) => {
|
12
|
+
if (!val.toString().includes('@media')) {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
const id = generateReactNativeWebId(prop, '""');
|
16
|
+
if (insertedIds.current.includes(id)) {
|
17
|
+
return;
|
18
|
+
}
|
19
|
+
const style = document.createElement('style');
|
20
|
+
style.id = id;
|
21
|
+
style.innerHTML = val;
|
22
|
+
document.head.appendChild(style);
|
23
|
+
insertedIds.current = [...insertedIds.current, id];
|
24
|
+
});
|
25
|
+
});
|
26
|
+
return () => {
|
27
|
+
insertedIds.current.forEach(id => {
|
28
|
+
const style = document.getElementById(id);
|
29
|
+
if (style) {
|
30
|
+
style.remove();
|
31
|
+
}
|
32
|
+
});
|
33
|
+
insertedIds.current = [];
|
34
|
+
};
|
35
|
+
}, [stylesheet]);
|
36
|
+
};
|
2
37
|
//# sourceMappingURL=useCSS.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useCSS","
|
1
|
+
{"version":3,"names":["useInsertionEffect","useRef","unistyles","generateReactNativeWebId","useCSS","stylesheet","insertedIds","registry","config","experimentalCSSMediaQueries","Object","entries","forEach","_key","value","prop","val","toString","includes","id","current","style","document","createElement","innerHTML","head","appendChild","getElementById","remove"],"sourceRoot":"../../../src","sources":["hooks/useCSS.ts"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,MAAM,QAAQ,OAAO;AAClD,SAASC,SAAS,QAAQ,SAAS;AAEnC,SAASC,wBAAwB,QAAQ,UAAU;AAEnD,OAAO,MAAMC,MAAM,GAAOC,UAAoC,IAAK;EAC/D,MAAMC,WAAW,GAAGL,MAAM,CAAgB,EAAE,CAAC;EAE7CD,kBAAkB,CAAC,MAAM;IACrB,IAAI,CAACE,SAAS,CAACK,QAAQ,CAACC,MAAM,CAACC,2BAA2B,EAAE;MACxD;IACJ;IAEAC,MAAM,CACDC,OAAO,CAACN,UAAU,CAAC,CACnBO,OAAO,CAAC,CAAC,CAACC,IAAI,EAAEC,KAAK,CAAC,KAAK;MACxBJ,MAAM,CAACC,OAAO,CAACG,KAAM,CAAC,CACjBF,OAAO,CAAC,CAAC,CAACG,IAAI,EAAEC,GAAG,CAAC,KAAK;QACtB,IAAI,CAACA,GAAG,CAACC,QAAQ,CAAC,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC,EAAE;UACpC;QACJ;QAEA,MAAMC,EAAE,GAAGhB,wBAAwB,CAACY,IAAI,EAAE,IAAI,CAAC;QAE/C,IAAIT,WAAW,CAACc,OAAO,CAACF,QAAQ,CAACC,EAAE,CAAC,EAAE;UAClC;QACJ;QAEA,MAAME,KAAK,GAAGC,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC;QAE7CF,KAAK,CAACF,EAAE,GAAGA,EAAE;QACbE,KAAK,CAACG,SAAS,GAAGR,GAAG;QAErBM,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACL,KAAK,CAAC;QAChCf,WAAW,CAACc,OAAO,GAAG,CAAC,GAAGd,WAAW,CAACc,OAAO,EAAED,EAAE,CAAC;MACtD,CAAC,CAAC;IACV,CAAC,CAAC;IAEN,OAAO,MAAM;MACTb,WAAW,CAACc,OAAO,CAACR,OAAO,CAACO,EAAE,IAAI;QAC9B,MAAME,KAAK,GAAGC,QAAQ,CAACK,cAAc,CAACR,EAAE,CAAC;QAEzC,IAAIE,KAAK,EAAE;UACPA,KAAK,CAACO,MAAM,CAAC,CAAC;QAClB;MACJ,CAAC,CAAC;MAEFtB,WAAW,CAACc,OAAO,GAAG,EAAE;IAC5B,CAAC;EACL,CAAC,EAAE,CAACf,UAAU,CAAC,CAAC;AACpB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["useCSS","_stylesheet"],"sourceRoot":"../../../src","sources":["hooks/useCSS.native.ts"],"mappings":"AAEA,OAAO,MAAMA,MAAM,GAAOC,WAAqC,IAAW,CAAC,CAAC"}
|
@@ -6,6 +6,7 @@ const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles);
|
|
6
6
|
export const useUnistyles = () => {
|
7
7
|
const [plugins, setPlugins] = useState(unistyles.runtime.enabledPlugins);
|
8
8
|
const [theme, setTheme] = useState(unistyles.registry.getTheme(unistyles.runtime.themeName));
|
9
|
+
const [contentSizeCategory, setContentSizeCategory] = useState(unistyles.runtime.contentSizeCategory);
|
9
10
|
const [layout, setLayout] = useState({
|
10
11
|
breakpoint: unistyles.runtime.breakpoint,
|
11
12
|
orientation: unistyles.runtime.orientation,
|
@@ -35,6 +36,11 @@ export const useUnistyles = () => {
|
|
35
36
|
{
|
36
37
|
return setPlugins(unistyles.runtime.enabledPlugins);
|
37
38
|
}
|
39
|
+
case UnistylesEventType.DynamicTypeSize:
|
40
|
+
{
|
41
|
+
const dynamicTypeSizeEvent = event;
|
42
|
+
return setContentSizeCategory(dynamicTypeSizeEvent.payload.contentSizeCategory);
|
43
|
+
}
|
38
44
|
default:
|
39
45
|
return;
|
40
46
|
}
|
@@ -44,7 +50,8 @@ export const useUnistyles = () => {
|
|
44
50
|
return {
|
45
51
|
plugins,
|
46
52
|
theme,
|
47
|
-
layout
|
53
|
+
layout,
|
54
|
+
contentSizeCategory
|
48
55
|
};
|
49
56
|
};
|
50
57
|
//# sourceMappingURL=useUnistyles.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","NativeModules","useEffect","useState","unistyles","UnistylesEventType","unistylesEvents","Unistyles","useUnistyles","plugins","setPlugins","runtime","enabledPlugins","theme","setTheme","registry","getTheme","themeName","layout","setLayout","breakpoint","orientation","screenSize","width","screen","height","subscription","addListener","event","type","Theme","themeEvent","payload","Layout","layoutEvent","Plugin","remove"],"sourceRoot":"../../../src","sources":["hooks/useUnistyles.ts"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAChE,SAASC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,SAAS,QAAQ,SAAS;AACnC,SAASC,kBAAkB,QAAQ,WAAW;AAG9C,MAAMC,eAAe,GAAG,IAAIN,kBAAkB,CAACC,aAAa,CAACM,SAAS,CAAC;AAEvE,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAM;EAC9B,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGP,QAAQ,CAACC,SAAS,CAACO,OAAO,CAACC,cAAc,CAAC;EACxE,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGX,QAAQ,CAACC,SAAS,CAACW,QAAQ,CAACC,QAAQ,CAACZ,SAAS,CAACO,OAAO,CAACM,SAAS,CAAC,CAAC;EAC5F,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NativeModules","useEffect","useState","unistyles","UnistylesEventType","unistylesEvents","Unistyles","useUnistyles","plugins","setPlugins","runtime","enabledPlugins","theme","setTheme","registry","getTheme","themeName","contentSizeCategory","setContentSizeCategory","layout","setLayout","breakpoint","orientation","screenSize","width","screen","height","subscription","addListener","event","type","Theme","themeEvent","payload","Layout","layoutEvent","Plugin","DynamicType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AMC,UAAU,GAAGH,KAA4B;YAE/C,OAAOhB,QAAQ,CAACV,SAAS,CAACW,QAAQ,CAACC,QAAQ,CAACiB,UAAU,CAACC,OAAO,CAACjB,SAAS,CAAC,CAAC;UAC9E;QACA,KAAKZ,kBAAkB,CAAC8B,MAAM;UAAE;YAC5B,MAAMC,WAAW,GAAGN,KAAmC;YAEvD,OAAOT,SAAS,CAAC;cACbC,UAAU,EAAEc,WAAW,CAACF,OAAO,CAACZ,UAAU;cAC1CC,WAAW,EAAEa,WAAW,CAACF,OAAO,CAACX,WAAW;cAC5CC,UAAU,EAAEY,WAAW,CAACF,OAAO,CAACR;YACpC,CAAC,CAAC;UACN;QACA,KAAKrB,kBAAkB,CAACgC,MAAM;UAAE;YAC5B,OAAO3B,UAAU,CAACN,SAAS,CAACO,OAAO,CAACC,cAAc,CAAC;UACvD;QACA,KAAKP,kBAAkB,CAACiC,eAAe;UAAE;YACrC,MAAMC,oBAAoB,GAAGT,KAAsC;YAEnE,OAAOX,sBAAsB,CAACoB,oBAAoB,CAACL,OAAO,CAAChB,mBAAmB,CAAC;UACnF;QACA;UACI;MACR;IACJ,CACJ,CAAC;IAED,OAAOU,YAAY,CAACY,MAAM;EAC9B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACH/B,OAAO;IACPI,KAAK;IACLO,MAAM;IACNF;EACJ,CAAC;AACL,CAAC"}
|
package/lib/module/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { unistyles } from './core';
|
2
2
|
import { mq } from './utils';
|
3
3
|
import { useInitialTheme } from './hooks';
|
4
|
-
import { ScreenOrientation } from './common';
|
4
|
+
import { ScreenOrientation, AndroidContentSizeCategory, IOSContentSizeCategory } from './common';
|
5
5
|
import { useStyles } from './useStyles';
|
6
6
|
import { createStyleSheet } from './createStyleSheet';
|
7
7
|
|
@@ -27,5 +27,5 @@ const UnistylesRegistry = {
|
|
27
27
|
addConfig: unistyles.registry.addConfig
|
28
28
|
};
|
29
29
|
const UnistylesRuntime = unistyles.runtime;
|
30
|
-
export { mq, useStyles, useInitialTheme, createStyleSheet, ScreenOrientation, UnistylesRegistry, UnistylesRuntime };
|
30
|
+
export { mq, useStyles, useInitialTheme, createStyleSheet, ScreenOrientation, AndroidContentSizeCategory, IOSContentSizeCategory, UnistylesRegistry, UnistylesRuntime };
|
31
31
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["unistyles","mq","useInitialTheme","ScreenOrientation","useStyles","createStyleSheet","UnistylesRegistry","addThemes","registry","addBreakpoints","addConfig","UnistylesRuntime","runtime"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,SAAS,QAAQ,QAAQ;AAClC,SAASC,EAAE,QAAQ,SAAS;AAC5B,SAASC,eAAe,QAAQ,SAAS;AAGzC,SAASC,iBAAiB,QAAQ,UAAU;
|
1
|
+
{"version":3,"names":["unistyles","mq","useInitialTheme","ScreenOrientation","AndroidContentSizeCategory","IOSContentSizeCategory","useStyles","createStyleSheet","UnistylesRegistry","addThemes","registry","addBreakpoints","addConfig","UnistylesRuntime","runtime"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,SAAS,QAAQ,QAAQ;AAClC,SAASC,EAAE,QAAQ,SAAS;AAC5B,SAASC,eAAe,QAAQ,SAAS;AAGzC,SAASC,iBAAiB,EAAEC,0BAA0B,EAAEC,sBAAsB,QAAQ,UAAU;AAChG,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,gBAAgB,QAAQ,oBAAoB;;AAErD;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAG;EACtB;AACJ;AACA;AACA;EACIC,SAAS,EAAET,SAAS,CAACU,QAAQ,CAACD,SAAS;EACvC;AACJ;AACA;AACA;EACIE,cAAc,EAAEX,SAAS,CAACU,QAAQ,CAACC,cAAc;EACjD;AACJ;AACA;AACA;EACIC,SAAS,EAAEZ,SAAS,CAACU,QAAQ,CAACE;AAClC,CAAC;AAED,MAAMC,gBAAgB,GAAGb,SAAS,CAACc,OAAO;AAE1C,SACIb,EAAE,EACFK,SAAS,EACTJ,eAAe,EACfK,gBAAgB,EAChBJ,iBAAiB,EACjBC,0BAA0B,EAC1BC,sBAAsB,EACtBG,iBAAiB,EACjBK,gBAAgB"}
|
@@ -1,8 +1,7 @@
|
|
1
1
|
// based on react-native-web normalizer
|
2
2
|
// https://github.com/necolas/react-native-web
|
3
3
|
import normalizeColors from '@react-native/normalize-colors';
|
4
|
-
export const normalizeColor =
|
5
|
-
let opacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
4
|
+
export const normalizeColor = (color, opacity = 1) => {
|
6
5
|
// If the opacity is 1 there's no need to normalize the color
|
7
6
|
if (opacity === 1) {
|
8
7
|
return color;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["normalizeColors","normalizeColor","color","opacity","
|
1
|
+
{"version":3,"names":["normalizeColors","normalizeColor","color","opacity","integer","hex","toString","padStart","length","r","g","b","a","split","map","x","parseInt","filter","num","isNaN","normalizeNumericValue","value","normalizeTransform","key","includes","createTextShadowValue","style","textShadowColor","textShadowOffset","textShadowRadius","offsetX","width","offsetY","height","radius","createBoxShadowValue","shadowColor","shadowOffset","shadowOpacity","shadowRadius","createTransformValue","transforms","transform","Object","keys","undefined","join","Boolean","preprocessor"],"sourceRoot":"../../../src","sources":["normalizer/normalizer.ts"],"mappings":"AAAA;AACA;AACA,OAAOA,eAAe,MAAM,gCAAgC;AAS5D,OAAO,MAAMC,cAAc,GAAGA,CAACC,KAAa,EAAEC,OAAe,GAAG,CAAC,KAAK;EAClE;EACA,IAAIA,OAAO,KAAK,CAAC,EAAE;IACf,OAAOD,KAAK;EAChB;EAEA,MAAME,OAAO,GAAGJ,eAAe,CAACE,KAAK,CAAqB;;EAE1D;EACA,IAAIE,OAAO,KAAK,IAAI,EAAE;IAClB,OAAOF,KAAK;EAChB;EAEA,MAAMG,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AC;AAEd,OAAO,MAAME,YAA0B,GAAG;EACtCvB,qBAAqB;EACrBU,oBAAoB;EACpBK;AACJ,CAAC"}
|
package/lib/module/useStyles.js
CHANGED
@@ -18,12 +18,11 @@ export const useStyles = (stylesheet, variantsMap) => {
|
|
18
18
|
} = useUnistyles();
|
19
19
|
const variants = useVariants(variantsMap);
|
20
20
|
const parsedStyles = useMemo(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet, layout]);
|
21
|
-
const dynamicStyleSheet = useMemo(() => Object.entries(parsedStyles || {}).reduce((acc,
|
22
|
-
let [key, value] = _ref;
|
21
|
+
const dynamicStyleSheet = useMemo(() => Object.entries(parsedStyles || {}).reduce((acc, [key, value]) => {
|
23
22
|
if (typeof value === 'function') {
|
24
23
|
return {
|
25
24
|
...acc,
|
26
|
-
[key]: proxifyFunction(key, value)
|
25
|
+
[key]: proxifyFunction(key, value, variants)
|
27
26
|
};
|
28
27
|
}
|
29
28
|
return StyleSheet.create({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","withPlugins","useCSS","useUnistyles","useVariants","unistyles","isWeb","useStyles","stylesheet","variantsMap","theme","layout","plugins","variants","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","
|
1
|
+
{"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","withPlugins","useCSS","useUnistyles","useVariants","unistyles","isWeb","useStyles","stylesheet","variantsMap","theme","layout","plugins","variants","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","key","value","create","registry","config","experimentalCSSMediaQueries","breakpoint","styles"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,EAAEC,eAAe,EAAEC,WAAW,QAAQ,SAAS;AAClE,SAASC,MAAM,EAAEC,YAAY,EAAEC,WAAW,QAAQ,SAAS;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,MAAM,CAACe,UAAU;IAC7BC,MAAM,EAAEZ;EACZ,CAAC;AACL,CAAC"}
|
@@ -19,17 +19,8 @@ export const getValueForBreakpoint = value => {
|
|
19
19
|
return directBreakpoint;
|
20
20
|
}
|
21
21
|
const breakpointPairs = unistyles.registry.sortedBreakpointPairs;
|
22
|
-
const currentBreakpointIndex = breakpointPairs.findIndex(
|
23
|
-
|
24
|
-
return key === breakpoint;
|
25
|
-
});
|
26
|
-
const availableBreakpoints = breakpointPairs.filter((_ref2, index) => {
|
27
|
-
let [key] = _ref2;
|
28
|
-
return index < currentBreakpointIndex && key in value;
|
29
|
-
}).map(_ref3 => {
|
30
|
-
let [key] = _ref3;
|
31
|
-
return key;
|
32
|
-
});
|
22
|
+
const currentBreakpointIndex = breakpointPairs.findIndex(([key]) => key === breakpoint);
|
23
|
+
const availableBreakpoints = breakpointPairs.filter(([key], index) => index < currentBreakpointIndex && key in value).map(([key]) => key);
|
33
24
|
return value[availableBreakpoints[availableBreakpoints.length - 1]];
|
34
25
|
};
|
35
26
|
//# sourceMappingURL=breakpoints.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["unistyles","ScreenOrientation","isMobile","getKeyForUnistylesMediaQuery","getValueForBreakpoint","value","customMediaQueryKey","Object","entries","runtime","screen","hasBreakpoints","registry","sortedBreakpointPairs","length","Landscape","Portrait","orientation","breakpoint","undefined","directBreakpoint","breakpointPairs","currentBreakpointIndex","findIndex","
|
1
|
+
{"version":3,"names":["unistyles","ScreenOrientation","isMobile","getKeyForUnistylesMediaQuery","getValueForBreakpoint","value","customMediaQueryKey","Object","entries","runtime","screen","hasBreakpoints","registry","sortedBreakpointPairs","length","Landscape","Portrait","orientation","breakpoint","undefined","directBreakpoint","breakpointPairs","currentBreakpointIndex","findIndex","key","availableBreakpoints","filter","index","map"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":"AAAA,SAASA,SAAS,QAAQ,SAAS;AAGnC,SAASC,iBAAiB,EAAE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AAG,CAAC;EAExB,OAAOnB,KAAK,CAACoB,oBAAoB,CAACA,oBAAoB,CAACX,MAAM,GAAG,CAAC,CAAC,CAAwC;AAC9G,CAAC"}
|
@@ -2,11 +2,7 @@ import { normalizeColor } from '../normalizer';
|
|
2
2
|
import { isUnistylesMq, isValidMq, parseMq } from './mqParser';
|
3
3
|
import { generateReactNativeWebId } from './generateId';
|
4
4
|
export const createMediaQueryForStyles = (styles, runtime) => {
|
5
|
-
const withMediaQueries = Object.entries(styles).filter(
|
6
|
-
let [, value] = _ref;
|
7
|
-
return typeof value === 'object';
|
8
|
-
}).reduce((acc, _ref2) => {
|
9
|
-
let [prop, value] = _ref2;
|
5
|
+
const withMediaQueries = Object.entries(styles).filter(([, value]) => typeof value === 'object').reduce((acc, [prop, value]) => {
|
10
6
|
const objectKeys = Object.keys(value);
|
11
7
|
const mediaQueries = objectKeys.filter(key => isUnistylesMq(key));
|
12
8
|
const breakpoints = objectKeys.filter(key => runtime.breakpoints[key]);
|
@@ -47,8 +43,7 @@ const getMaxHeightMediaQuery = height => {
|
|
47
43
|
}
|
48
44
|
return `and (max-height: ${height.to}px)`;
|
49
45
|
};
|
50
|
-
const getMediaQueriesFromMQ = (prop, value, className) => Object.entries(value).reduce((acc,
|
51
|
-
let [key, value] = _ref3;
|
46
|
+
const getMediaQueriesFromMQ = (prop, value, className) => Object.entries(value).reduce((acc, [key, value]) => {
|
52
47
|
const result = parseMq(key);
|
53
48
|
if (!isValidMq(result)) {
|
54
49
|
return acc;
|
@@ -85,8 +80,7 @@ const getMediaQueriesFromMQ = (prop, value, className) => Object.entries(value).
|
|
85
80
|
}
|
86
81
|
return acc;
|
87
82
|
}, '');
|
88
|
-
const getBreakpointsStyles = (prop, value, runtime, className) => Object.entries(value).reduce((acc,
|
89
|
-
let [key, value] = _ref4;
|
83
|
+
const getBreakpointsStyles = (prop, value, runtime, className) => Object.entries(value).reduce((acc, [key, value]) => {
|
90
84
|
const breakpoint = runtime.breakpoints[key];
|
91
85
|
if (breakpoint === undefined) {
|
92
86
|
return acc;
|