react-native-unistyles 2.0.0-alpha.13 → 2.0.0-alpha.15
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/UnistylesRuntime.h +6 -6
- package/lib/commonjs/common.js +15 -15
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/UnistyleRegistry.js +3 -2
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
- package/lib/commonjs/core/UnistylesRuntime.js +1 -1
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
- package/lib/commonjs/createStyleSheet.js +1 -6
- package/lib/commonjs/createStyleSheet.js.map +1 -1
- package/lib/commonjs/hooks/index.js +7 -0
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useUnistyles.js +4 -7
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
- package/lib/commonjs/hooks/useVariants.js +24 -0
- package/lib/commonjs/hooks/useVariants.js.map +1 -0
- package/lib/commonjs/plugins/normalizer/normalizer.js +1 -1
- package/lib/commonjs/plugins/normalizer/normalizer.js.map +1 -1
- package/lib/commonjs/plugins/withPlugins.js +2 -6
- package/lib/commonjs/plugins/withPlugins.js.map +1 -1
- package/lib/commonjs/types/stylesheet.js +6 -0
- package/lib/commonjs/types/stylesheet.js.map +1 -0
- package/lib/commonjs/useStyles.js +8 -11
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/index.js +22 -5
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mq.js +42 -28
- package/lib/commonjs/utils/mq.js.map +1 -1
- package/lib/commonjs/utils/styles.js +19 -23
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/variants.js +43 -8
- package/lib/commonjs/utils/variants.js.map +1 -1
- package/lib/module/common.js +14 -14
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/UnistyleRegistry.js +4 -3
- package/lib/module/core/UnistyleRegistry.js.map +1 -1
- package/lib/module/core/UnistylesRuntime.js +1 -1
- package/lib/module/core/UnistylesRuntime.js.map +1 -1
- package/lib/module/createStyleSheet.js +1 -6
- package/lib/module/createStyleSheet.js.map +1 -1
- package/lib/module/hooks/index.js +1 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useUnistyles.js +5 -8
- package/lib/module/hooks/useUnistyles.js.map +1 -1
- package/lib/module/hooks/useVariants.js +17 -0
- package/lib/module/hooks/useVariants.js.map +1 -0
- package/lib/module/plugins/normalizer/normalizer.js +1 -1
- package/lib/module/plugins/normalizer/normalizer.js.map +1 -1
- package/lib/module/plugins/withPlugins.js +2 -6
- package/lib/module/plugins/withPlugins.js.map +1 -1
- package/lib/module/types/stylesheet.js +2 -0
- package/lib/module/types/stylesheet.js.map +1 -0
- package/lib/module/useStyles.js +9 -12
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/index.js +1 -2
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mq.js +41 -27
- package/lib/module/utils/mq.js.map +1 -1
- package/lib/module/utils/styles.js +20 -24
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/variants.js +41 -6
- package/lib/module/utils/variants.js.map +1 -1
- package/lib/typescript/src/common.d.ts +10 -10
- package/lib/typescript/src/common.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
- package/lib/typescript/src/createStyleSheet.d.ts +2 -2
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
- package/lib/typescript/src/global.d.ts.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +1 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useVariants.d.ts +3 -0
- package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -0
- package/lib/typescript/src/plugins/normalizer/normalizer.d.ts.map +1 -1
- package/lib/typescript/src/plugins/withPlugins.d.ts +3 -2
- package/lib/typescript/src/plugins/withPlugins.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +20 -14
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +3 -26
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +2 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/mq.d.ts +2 -2
- package/lib/typescript/src/types/mq.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +47 -0
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -0
- package/lib/typescript/src/types/unistyles.d.ts +5 -6
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
- package/lib/typescript/src/types/variants.d.ts +13 -7
- package/lib/typescript/src/types/variants.d.ts.map +1 -1
- package/lib/typescript/src/useStyles.d.ts +3 -3
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -2
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +19 -13
- package/lib/typescript/src/utils/mq.d.ts.map +1 -1
- package/lib/typescript/src/utils/styles.d.ts +4 -4
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/variants.d.ts +2 -2
- package/lib/typescript/src/utils/variants.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/common.ts +10 -10
- package/src/core/UnistyleRegistry.ts +6 -3
- package/src/core/UnistylesRuntime.ts +1 -1
- package/src/createStyleSheet.ts +2 -8
- package/src/global.ts +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useUnistyles.ts +5 -8
- package/src/hooks/useVariants.ts +23 -0
- package/src/plugins/normalizer/normalizer.ts +3 -3
- package/src/plugins/withPlugins.ts +13 -15
- package/src/types/breakpoints.ts +47 -26
- package/src/types/core.ts +6 -42
- package/src/types/index.ts +1 -1
- package/src/types/mq.ts +2 -2
- package/src/types/stylesheet.ts +56 -0
- package/src/types/unistyles.ts +5 -6
- package/src/types/variants.ts +17 -9
- package/src/useStyles.ts +22 -16
- package/src/utils/index.ts +1 -2
- package/src/utils/mq.ts +56 -41
- package/src/utils/styles.ts +28 -45
- package/src/utils/variants.ts +55 -7
@@ -8,8 +8,8 @@ var _breakpoints = require("./breakpoints");
|
|
8
8
|
var _common = require("../common");
|
9
9
|
var _variants = require("./variants");
|
10
10
|
var _plugins = require("../plugins");
|
11
|
-
const proxifyFunction = (key, fn,
|
12
|
-
apply: (target, thisArg, argumentsList) => parseStyle(key, target.apply(thisArg, argumentsList),
|
11
|
+
const proxifyFunction = (key, fn, plugins, runtime, variant) => new Proxy(fn, {
|
12
|
+
apply: (target, thisArg, argumentsList) => parseStyle(key, target.apply(thisArg, argumentsList), plugins, runtime, variant)
|
13
13
|
});
|
14
14
|
exports.proxifyFunction = proxifyFunction;
|
15
15
|
const isPlatformColor = value => {
|
@@ -19,36 +19,32 @@ const isPlatformColor = value => {
|
|
19
19
|
return _common.isAndroid && 'resource_paths' in value && typeof value.resource_paths === 'object';
|
20
20
|
};
|
21
21
|
exports.isPlatformColor = isPlatformColor;
|
22
|
-
const parseStyle = (key, style,
|
23
|
-
const entries = Object.entries(style || {})
|
22
|
+
const parseStyle = (key, style, plugins, runtime, variant) => {
|
23
|
+
const entries = Object.entries((0, _variants.getStyleWithVariants)(style || {}, variant));
|
24
|
+
const parsedStyles = Object.fromEntries(entries.map(_ref => {
|
24
25
|
let [key, value] = _ref;
|
25
|
-
|
26
|
+
// dynamic functions
|
27
|
+
if (typeof value === 'function') {
|
26
28
|
return [key, value];
|
27
29
|
}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
return Object.entries(value[variantKey]).flat();
|
33
|
-
}).filter(Boolean);
|
34
|
-
const parsedStyles = Object.fromEntries(entries.map(_ref2 => {
|
35
|
-
let [key, value] = _ref2;
|
36
|
-
const hasNestedProperties = key === 'shadowOffset' || key === 'textShadowOffset';
|
37
|
-
if (hasNestedProperties) {
|
38
|
-
return [key, parseStyle(key, value, breakpoint, screenSize, variant)];
|
30
|
+
|
31
|
+
// nested objects
|
32
|
+
if (key === 'shadowOffset' || key === 'textShadowOffset') {
|
33
|
+
return [key, parseStyle(key, value, plugins, runtime, variant)];
|
39
34
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
|
36
|
+
// transforms
|
37
|
+
if (key === 'transform' && Array.isArray(value)) {
|
38
|
+
return [key, value.map(value => parseStyle(key, value, plugins, runtime, variant))];
|
43
39
|
}
|
44
|
-
|
45
|
-
|
46
|
-
if (
|
40
|
+
|
41
|
+
// values or platform colors
|
42
|
+
if (typeof value !== 'object' || isPlatformColor(value)) {
|
47
43
|
return [key, value];
|
48
44
|
}
|
49
45
|
return [key, (0, _breakpoints.getValueForBreakpoint)(value)];
|
50
46
|
}));
|
51
|
-
return (0, _plugins.withPlugins)(key, parsedStyles);
|
47
|
+
return (0, _plugins.withPlugins)(key, parsedStyles, plugins, runtime);
|
52
48
|
};
|
53
49
|
exports.parseStyle = parseStyle;
|
54
50
|
//# sourceMappingURL=styles.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_breakpoints","require","_common","_variants","_plugins","proxifyFunction","key","fn","
|
1
|
+
{"version":3,"names":["_breakpoints","require","_common","_variants","_plugins","proxifyFunction","key","fn","plugins","runtime","variant","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","isPlatformColor","value","isIOS","semantic","isAndroid","resource_paths","style","entries","Object","getStyleWithVariants","parsedStyles","fromEntries","map","_ref","Array","isArray","getValueForBreakpoint","withPlugins"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEO,MAAMI,eAAe,GAAGA,CAC3BC,GAAW,EACXC,EAAY,EACZC,OAA+B,EAC/BC,OAAy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OAAO,CAAC,CACpD;IACL;;IAEA;IACA,IAAIJ,GAAG,KAAK,WAAW,IAAI0B,KAAK,CAACC,OAAO,CAACd,KAAK,CAAC,EAAE;MAC7C,OAAO,CACHb,GAAG,EACHa,KAAK,CAACW,GAAG,CAACX,KAAK,IAAIH,UAAU,CAACV,GAAG,EAAEa,KAAK,EAAEX,OAAO,EAAEC,OAAO,EAAEC,OAAO,CAAC,CAAC,CACxE;IACL;;IAEA;IACA,IAAI,OAAOS,KAAK,KAAK,QAAQ,IAAID,eAAe,CAACC,KAAK,CAAC,EAAE;MACrD,OAAO,CAACb,GAAG,EAAEa,KAAK,CAAC;IACvB;IAEA,OAAO,CACHb,GAAG,EACH,IAAA4B,kCAAqB,EAACf,KAAoB,CAAC,CAC9C;EACL,CAAC,CACL,CAAM;EAEV,OAAO,IAAAgB,oBAAW,EAAC7B,GAAG,EAAEsB,YAAY,EAAEpB,OAAO,EAAEC,OAAO,CAAC;AAC3D,CAAC;AAAAQ,OAAA,CAAAD,UAAA,GAAAA,UAAA"}
|
@@ -3,15 +3,50 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
7
|
-
const
|
8
|
-
|
9
|
-
|
6
|
+
exports.getStyleWithVariants = void 0;
|
7
|
+
const getKeysForVariants = (value, variants) => {
|
8
|
+
// case for no specified variants by user, we should fallback to 'default'
|
9
|
+
if (!variants.length) {
|
10
|
+
return Object.entries(value).map(_ref => {
|
11
|
+
let [key, value] = _ref;
|
12
|
+
if ('default' in value) {
|
13
|
+
return [key, 'default'];
|
14
|
+
}
|
15
|
+
return undefined;
|
16
|
+
}).filter(Boolean);
|
10
17
|
}
|
11
|
-
|
12
|
-
|
18
|
+
return variants.map(_ref2 => {
|
19
|
+
let [variantKey, variantValue] = _ref2;
|
20
|
+
const variantStyle = value[variantKey];
|
21
|
+
if (variantStyle && variantValue && variantValue in variantStyle) {
|
22
|
+
return [variantKey, variantValue];
|
23
|
+
}
|
24
|
+
if (variantStyle && 'default' in variantStyle) {
|
25
|
+
return [variantKey, 'default'];
|
26
|
+
}
|
27
|
+
return undefined;
|
28
|
+
}).filter(Boolean);
|
29
|
+
};
|
30
|
+
const getStyleWithVariants = (style, variantValues) => {
|
31
|
+
if (!('variants' in style)) {
|
32
|
+
return style;
|
13
33
|
}
|
14
|
-
|
34
|
+
const keys = getKeysForVariants(style.variants, Object.entries(variantValues || {}));
|
35
|
+
const variantsValues = keys.map(_ref3 => {
|
36
|
+
let [key, nestedKey] = _ref3;
|
37
|
+
return style.variants[key][nestedKey];
|
38
|
+
}).reduce((acc, styles) => ({
|
39
|
+
...acc,
|
40
|
+
...styles
|
41
|
+
}), {});
|
42
|
+
const {
|
43
|
+
variants,
|
44
|
+
...otherStyles
|
45
|
+
} = style;
|
46
|
+
return {
|
47
|
+
...otherStyles,
|
48
|
+
...variantsValues
|
49
|
+
};
|
15
50
|
};
|
16
|
-
exports.
|
51
|
+
exports.getStyleWithVariants = getStyleWithVariants;
|
17
52
|
//# sourceMappingURL=variants.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["getKeysForVariants","value","variants","length","Object","entries","map","_ref","key","undefined","filter","Boolean","_ref2","variantKey","variantValue","variantStyle","getStyleWithVariants","style","variantValues","keys","variantsValues","_ref3","nestedKey","reduce","acc","styles","otherStyles","exports"],"sourceRoot":"../../../src","sources":["utils/variants.ts"],"mappings":";;;;;;AAEA,MAAMA,kBAAkB,GAAGA,CACvBC,KAAkC,EAClCC,QAA2C,KACjB;EAC1B;EACA,IAAI,CAACA,QAAQ,CAACC,MAAM,EAAE;IAClB,OAAOC,MAAM,CACRC,OAAO,CAACJ,KAAK,CAAC,CACdK,GAAG,CAACC,IAAA,IAAkB;MAAA,IAAjB,CAACC,GAAG,EAAEP,KAAK,CAAC,GAAAM,IAAA;MACd,IAAI,SAAS,IAAIN,KAAK,EAAE;QACpB,OAAO,CAACO,GAA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IACH,GAAGS,WAAW;IACd,GAAGN;EACP,CAAC;AACL,CAAC;AAAAO,OAAA,CAAAX,oBAAA,GAAAA,oBAAA"}
|
package/lib/module/common.js
CHANGED
@@ -11,22 +11,22 @@ export const ScreenOrientation = {
|
|
11
11
|
Landscape: 'landscape',
|
12
12
|
Portrait: 'portrait'
|
13
13
|
};
|
14
|
-
export let
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
return
|
14
|
+
export let UnistylesEventType = /*#__PURE__*/function (UnistylesEventType) {
|
15
|
+
UnistylesEventType["Theme"] = "theme";
|
16
|
+
UnistylesEventType["Layout"] = "layout";
|
17
|
+
UnistylesEventType["Plugin"] = "plugin";
|
18
|
+
return UnistylesEventType;
|
19
19
|
}({});
|
20
20
|
export let UnistylesError = /*#__PURE__*/function (UnistylesError) {
|
21
|
-
UnistylesError["RuntimeUnavailable"] = "
|
22
|
-
UnistylesError["ThemeNotFound"] = "
|
23
|
-
UnistylesError["ThemeNotRegistered"] = "
|
24
|
-
UnistylesError["ThemesCannotBeEmpty"] = "
|
25
|
-
UnistylesError["BreakpointsCannotBeEmpty"] = "
|
26
|
-
UnistylesError["BreakpointsMustStartFromZero"] = "
|
27
|
-
UnistylesError["InvalidPluginName"] = "
|
28
|
-
UnistylesError["DuplicatePluginName"] = "
|
29
|
-
UnistylesError["CantRemoveInternalPlugin"] = "
|
21
|
+
UnistylesError["RuntimeUnavailable"] = "Unistyles runtime is not available. Make sure you followed the installation instructions.";
|
22
|
+
UnistylesError["ThemeNotFound"] = "You are trying to get a theme that is not registered.";
|
23
|
+
UnistylesError["ThemeNotRegistered"] = "You are trying to set a theme that is not registered.";
|
24
|
+
UnistylesError["ThemesCannotBeEmpty"] = "You are trying to register an empty themes object.";
|
25
|
+
UnistylesError["BreakpointsCannotBeEmpty"] = "You are trying to register an empty breakpoints object.";
|
26
|
+
UnistylesError["BreakpointsMustStartFromZero"] = "One breakpoint must start from 0.";
|
27
|
+
UnistylesError["InvalidPluginName"] = "Plugin name can't start from reserved prefix. Use another name.";
|
28
|
+
UnistylesError["DuplicatePluginName"] = "You are trying to register a plugin with a name that is already registered.";
|
29
|
+
UnistylesError["CantRemoveInternalPlugin"] = "You are trying to remove an internal unistyles plugin.";
|
30
30
|
return UnistylesError;
|
31
31
|
}({});
|
32
32
|
//# sourceMappingURL=common.js.map
|
package/lib/module/common.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Platform","warn","message","console","isMobile","OS","isWeb","isIOS","isAndroid","isServer","window","ScreenOrientation","Landscape","Portrait","
|
1
|
+
{"version":3,"names":["Platform","warn","message","console","isMobile","OS","isWeb","isIOS","isAndroid","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,QAAQ,GAAGJ,QAAQ,CAACK,EAAE,KAAK,SAAS,IAAIL,QAAQ,CAACK,EAAE,KAAK,KAAK;AAC1E,OAAO,MAAMC,KAAK,GAAGN,QAAQ,CAACK,EAAE,KAAK,KAAK;AAC1C,OAAO,MAAME,KAAK,GAAGP,QAAQ,CAACK,EAAE,KAAK,KAAK;AAC1C,OAAO,MAAMG,SAAS,GAAGR,QAAQ,CAACK,EAAE,KAAK,SAAS;AAClD,OAAO,MAAMI,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;AAM9B,WAAYC,cAAc,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA"}
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import { UnistylesError } from '../common';
|
1
|
+
import { isWeb, UnistylesError } from '../common';
|
2
|
+
import { normalizeWebStylesPlugin } from '../plugins';
|
2
3
|
export class UnistyleRegistry {
|
3
4
|
config = {};
|
4
|
-
plugins = [];
|
5
|
+
plugins = isWeb ? [normalizeWebStylesPlugin] : [];
|
5
6
|
themeNames = [];
|
6
7
|
themes = {};
|
7
8
|
breakpoints = {};
|
@@ -58,7 +59,7 @@ export class UnistyleRegistry {
|
|
58
59
|
})) {
|
59
60
|
throw new Error(UnistylesError.DuplicatePluginName);
|
60
61
|
}
|
61
|
-
_this.plugins = _this.plugins
|
62
|
+
_this.plugins = [plugin].concat(_this.plugins);
|
62
63
|
_this.unistylesBridge.addPlugin(plugin.name, notify);
|
63
64
|
};
|
64
65
|
})();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["UnistylesError","UnistyleRegistry","config","plugins","themeNames","themes","breakpoints","sortedBreakpointPairs","constructor","unistylesBridge","addThemes","keys","Object","addBreakpoints","useBreakpoints","addConfig","adaptiveThemes","useAdaptiveThemes","experimentalPlugins","forEach","plugin","addPlugin","initialTheme","useTheme","getTheme","forName","length","hasTheme","Error","ThemeNotFound","_this","notify","arguments","undefined","name","startsWith","InvalidPluginName","some","_ref","DuplicatePluginName","concat","removePlugin","CantRemoveInternalPlugin","filter","_ref2"],"sourceRoot":"../../../src","sources":["core/UnistyleRegistry.ts"],"mappings":"AAEA,SAASA,cAAc,QAAQ,WAAW;
|
1
|
+
{"version":3,"names":["isWeb","UnistylesError","normalizeWebStylesPlugin","UnistyleRegistry","config","plugins","themeNames","themes","breakpoints","sortedBreakpointPairs","constructor","unistylesBridge","addThemes","keys","Object","addBreakpoints","useBreakpoints","addConfig","adaptiveThemes","useAdaptiveThemes","experimentalPlugins","forEach","plugin","addPlugin","initialTheme","useTheme","getTheme","forName","length","hasTheme","Error","ThemeNotFound","_this","notify","arguments","undefined","name","startsWith","InvalidPluginName","some","_ref","DuplicatePluginName","concat","removePlugin","CantRemoveInternalPlugin","filter","_ref2"],"sourceRoot":"../../../src","sources":["core/UnistyleRegistry.ts"],"mappings":"AAEA,SAASA,KAAK,EAAEC,cAAc,QAAQ,WAAW;AACjD,SAASC,wBAAwB,QAAQ,YAAY;AAErD,OAAO,MAAMC,gBAAgB,CAAC;EACnBC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,OAAO,GAA2BL,KAAK,GACxC,CAACE,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,IAAI;EACf,CAAC;EAEME,cAAc,GAAIP,WAAiC,IAAK;IAC3D,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACG,eAAe,CAACK,cAAc,CAACR,WAAW,CAAC;IAChD,IAAI,CAACC,qBAAqB,GAAG,IAAI,CAACE,eAAe,CAACF,qBAAqB;IAEvE,OAAO,IAAI;EACf,CAAC;EAEMQ,SAAS,GAAIb,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,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cAAc,CAACwC,mBAAmB,CAAC;MACvD;MAEAT,KAAI,CAAC3B,OAAO,GAAG,CAACiB,MAAM,CAAC,CAACoB,MAAM,CAACV,KAAI,CAAC3B,OAAO,CAAC;MAC5C2B,KAAI,CAACrB,eAAe,CAACY,SAAS,CAACD,MAAM,CAACc,IAAI,EAAEH,MAAM,CAAC;IACvD,CAAC;EAAA;EAEMU,YAAY,GAAIrB,MAAuB,IAAK;IAC/C,IAAIA,MAAM,CAACc,IAAI,CAACC,UAAU,CAAC,aAAa,CAAC,EAAE;MACvC,MAAM,IAAIP,KAAK,CAAC7B,cAAc,CAAC2C,wBAAwB,CAAC;IAC5D;IAEA,IAAI,CAACvC,OAAO,GAAG,IAAI,CAACA,OAAO,CAACwC,MAAM,CAACC,KAAA;MAAA,IAAC;QAAEV;MAAK,CAAC,GAAAU,KAAA;MAAA,OAAKV,IAAI,KAAKd,MAAM,CAACc,IAAI;IAAA,EAAC;IACtE,IAAI,CAACzB,eAAe,CAACgC,YAAY,CAACrB,MAAM,CAACc,IAAI,CAAC;EAClD,CAAC;EAEMP,QAAQ,GAAIO,IAA2B,IAAKA,IAAI,IAAI,IAAI,CAAC7B,MAAM;AAC1E"}
|
@@ -36,7 +36,7 @@ export class UnistylesRuntime {
|
|
36
36
|
return ScreenOrientation.Portrait;
|
37
37
|
}
|
38
38
|
setTheme = name => {
|
39
|
-
if (this.unistylesRegistry.hasTheme(name)) {
|
39
|
+
if (name !== this.themeName && this.unistylesRegistry.hasTheme(name)) {
|
40
40
|
this.unistylesBridge.useTheme(name);
|
41
41
|
return true;
|
42
42
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ScreenOrientation","UnistylesError","UnistylesRuntime","constructor","unistylesBridge","unistylesRegistry","colorScheme","hasAdaptiveThemes","themeName","breakpoint","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,OAAO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,iBAAmC,EAAE;IAAA,KAA/ED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,iBAAmC,GAAnCA,iBAAmC;EAAG;EAEpG,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,SAASA,CAAA,EAAG;IACnB,OAAO,IAAI,CAACJ,eAAe,CAACI,SAAS;EACzC;EAEA,IAAWC,UAAUA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACL,eAAe,CAACK,UAAU;EAC1C;EAEA,IAAWC,cAAcA,CAAA,EAAG;IACxB,OAAO,IAAI,CAACN,eAAe,CAACM,cAAc;EAC9C;EAEA,IAAWC,MAAMA,CAAA,EAAG;IAChB,OAAO;MACHC,KAAK,EAAE,IAAI,CAACR,eAAe,CAACS,WAAW;MACvCC,MAAM,EAAE,IAAI,CAACV,eAAe,CAACW;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,OAAOd,iBAAiB,CAACiB,SAAS;IACtC;IAEA,OAAOjB,iBAAiB,CAACkB,QAAQ;EACrC;EAEOC,QAAQ,GAAIC,IAA2B,IAAK;IAC/C,IAAI,IAAI,
|
1
|
+
{"version":3,"names":["ScreenOrientation","UnistylesError","UnistylesRuntime","constructor","unistylesBridge","unistylesRegistry","colorScheme","hasAdaptiveThemes","themeName","breakpoint","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,OAAO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,iBAAmC,EAAE;IAAA,KAA/ED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,iBAAmC,GAAnCA,iBAAmC;EAAG;EAEpG,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,SAASA,CAAA,EAAG;IACnB,OAAO,IAAI,CAACJ,eAAe,CAACI,SAAS;EACzC;EAEA,IAAWC,UAAUA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACL,eAAe,CAACK,UAAU;EAC1C;EAEA,IAAWC,cAAcA,CAAA,EAAG;IACxB,OAAO,IAAI,CAACN,eAAe,CAACM,cAAc;EAC9C;EAEA,IAAWC,MAAMA,CAAA,EAAG;IAChB,OAAO;MACHC,KAAK,EAAE,IAAI,CAACR,eAAe,CAACS,WAAW;MACvCC,MAAM,EAAE,IAAI,CAACV,eAAe,CAACW;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,OAAOd,iBAAiB,CAACiB,SAAS;IACtC;IAEA,OAAOjB,iBAAiB,CAACkB,QAAQ;EACrC;EAEOC,QAAQ,GAAIC,IAA2B,IAAK;IAC/C,IAAIA,IAAI,KAAK,IAAI,CAACZ,SAAS,IAAI,IAAI,CAACH,iBAAiB,CAACgB,QAAQ,CAACD,IAAI,CAAC,EAAE;MAClE,IAAI,CAAChB,eAAe,CAACkB,QAAQ,CAACF,IAAI,CAAC;MAEnC,OAAO,IAAI;IACf;IAEA,MAAM,IAAIG,KAAK,CAACtB,cAAc,CAACuB,kBAAkB,CAAC;EACtD,CAAC;EAEMC,iBAAiB,GAAIC,MAAe,IAAK;IAC5C,IAAI,CAACtB,eAAe,CAACuB,iBAAiB,CAACD,MAAM,CAAC;EAClD,CAAC;EAEME,SAAS,GAAIC,MAAuB,IAAK;IAC5C,IAAI,CAACxB,iBAAiB,CAACuB,SAAS,CAACC,MAAM,CAAC;EAC5C,CAAC;EAEMC,YAAY,GAAID,MAAuB,IAAK;IAC/C,IAAI,CAACxB,iBAAiB,CAACyB,YAAY,CAACD,MAAM,CAAC;EAC/C,CAAC;AACL"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createStyleSheet","
|
1
|
+
{"version":3,"names":["createStyleSheet","stylesheet"],"sourceRoot":"../../src","sources":["createStyleSheet.ts"],"mappings":"AAEA,OAAO,MAAMA,gBAAgB,GAAyCC,UAAa,IAAQA,UAAU"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useInitialTheme","useUnistyles"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,SAASC,YAAY,QAAQ,gBAAgB"}
|
1
|
+
{"version":3,"names":["useInitialTheme","useUnistyles","useVariants"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,WAAW,QAAQ,eAAe"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { NativeEventEmitter, NativeModules } from 'react-native';
|
2
2
|
import { useEffect, useState } from 'react';
|
3
3
|
import { unistyles } from '../core';
|
4
|
-
import {
|
4
|
+
import { UnistylesEventType } from '../common';
|
5
5
|
const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles);
|
6
6
|
export const useUnistyles = () => {
|
7
7
|
const [plugins, setPlugins] = useState(unistyles.runtime.enabledPlugins);
|
@@ -17,24 +17,21 @@ export const useUnistyles = () => {
|
|
17
17
|
useEffect(() => {
|
18
18
|
const subscription = unistylesEvents.addListener('onChange', event => {
|
19
19
|
switch (event.type) {
|
20
|
-
case
|
20
|
+
case UnistylesEventType.Theme:
|
21
21
|
{
|
22
22
|
const themeEvent = event;
|
23
23
|
return setTheme(unistyles.registry.getTheme(themeEvent.payload.themeName));
|
24
24
|
}
|
25
|
-
case
|
25
|
+
case UnistylesEventType.Layout:
|
26
26
|
{
|
27
27
|
const layoutEvent = event;
|
28
28
|
return setLayout({
|
29
29
|
breakpoint: layoutEvent.payload.breakpoint,
|
30
30
|
orientation: layoutEvent.payload.orientation,
|
31
|
-
screenSize:
|
32
|
-
width: layoutEvent.payload.screen.width,
|
33
|
-
height: layoutEvent.payload.screen.height
|
34
|
-
}
|
31
|
+
screenSize: layoutEvent.payload.screen
|
35
32
|
});
|
36
33
|
}
|
37
|
-
case
|
34
|
+
case UnistylesEventType.Plugin:
|
38
35
|
{
|
39
36
|
return setPlugins(unistyles.runtime.enabledPlugins);
|
40
37
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","NativeModules","useEffect","useState","unistyles","
|
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"],"mapp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E;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,KAAKnB,kBAAkB,CAAC8B,MAAM;UAAE;YAC5B,OAAOzB,UAAU,CAACN,SAAS,CAACO,OAAO,CAACC,cAAc,CAAC;UACvD;QACA;UACI;MACR;IACJ,CACJ,CAAC;IAED,OAAOc,YAAY,CAACU,MAAM;EAC9B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACH3B,OAAO;IACPI,KAAK;IACLK;EACJ,CAAC;AACL,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { useRef } from 'react';
|
2
|
+
const compareVariants = (prevVariants, nextVariants) => {
|
3
|
+
const keysA = Object.keys(prevVariants ?? {});
|
4
|
+
const keysB = Object.keys(nextVariants ?? {});
|
5
|
+
if (keysA.length !== keysB.length) {
|
6
|
+
return false;
|
7
|
+
}
|
8
|
+
return keysA.every(key => prevVariants[key] === (nextVariants ?? {})[key]);
|
9
|
+
};
|
10
|
+
export const useVariants = variantsMap => {
|
11
|
+
const variantsRef = useRef(variantsMap);
|
12
|
+
if (!compareVariants(variantsRef.current, variantsMap)) {
|
13
|
+
variantsRef.current = variantsMap;
|
14
|
+
}
|
15
|
+
return variantsRef.current;
|
16
|
+
};
|
17
|
+
//# sourceMappingURL=useVariants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["useRef","compareVariants","prevVariants","nextVariants","keysA","Object","keys","keysB","length","every","key","useVariants","variantsMap","variantsRef","current"],"sourceRoot":"../../../src","sources":["hooks/useVariants.ts"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;AAG9B,MAAMC,eAAe,GAAGA,CAACC,YAA+C,EAAEC,YAA+C,KAAK;EAC1H,MAAMC,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACJ,YAAY,IAAI,CAAC,CAAC,CAAC;EAC7C,MAAMK,KAAK,GAAGF,MAAM,CAACC,IAAI,CAACH,YAAY,IAAI,CAAC,CAAC,CAAC;EAE7C,IAAIC,KAAK,CAACI,MAAM,KAAKD,KAAK,CAACC,MAAM,EAAE;IAC/B,OAAO,KAAK;EAChB;EAEA,OAAOJ,KAAK,CAACK,KAAK,CAACC,GAAG,IAAIR,YAAY,CAAEQ,GAAG,CAAC,KAAK,CAACP,YAAY,IAAI,CAAC,CAAC,EAAEO,GAAG,CAAC,CAAC;AAC/E,CAAC;AAED,OAAO,MAAMC,WAAW,GAAIC,WAA8C,IAAK;EAC3E,MAAMC,WAAW,GAAGb,MAAM,CAA6CY,WAAW,CAAC;EAEnF,IAAI,CAACX,eAAe,CAACY,WAAW,CAACC,OAAO,EAAEF,WAAW,CAAC,EAAE;IACpDC,WAAW,CAACC,OAAO,GAAGF,WAAW;EACrC;EAEA,OAAOC,WAAW,CAACC,OAAO;AAC9B,CAAC"}
|
@@ -9,7 +9,7 @@ export const normalizeColor = function (color) {
|
|
9
9
|
}
|
10
10
|
const integer = normalizeColors(color);
|
11
11
|
|
12
|
-
// If the
|
12
|
+
// If the color is an unknown format, the return value is null
|
13
13
|
if (integer === null) {
|
14
14
|
return color;
|
15
15
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["normalizeColors","normalizeColor","color","opacity","arguments","length","undefined","integer","hex","toString","padStart","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","join","Boolean","preprocessor"],"sourceRoot":"../../../../src","sources":["plugins/normalizer/normalizer.ts"],"mappings":"AAAA;AACA;AACA,OAAOA,eAAe,MAAM,gCAAgC;AAS5D,OAAO,MAAMC,cAAc,GAAG,SAAAA,CAACC,KAAa,EAA0B;EAAA,IAAxBC,OAAe,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAC7D;EACA,IAAID,OAAO,KAAK,CAAC,EAAE;IACf,OAAOD,KAAK;EAChB;EAEA,MAAMK,OAAO,GAAGP,eAAe,CAACE,KAAK,
|
1
|
+
{"version":3,"names":["normalizeColors","normalizeColor","color","opacity","arguments","length","undefined","integer","hex","toString","padStart","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","join","Boolean","preprocessor"],"sourceRoot":"../../../../src","sources":["plugins/normalizer/normalizer.ts"],"mappings":"AAAA;AACA;AACA,OAAOA,eAAe,MAAM,gCAAgC;AAS5D,OAAO,MAAMC,cAAc,GAAG,SAAAA,CAACC,KAAa,EAA0B;EAAA,IAAxBC,OAAe,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAC7D;EACA,IAAID,OAAO,KAAK,CAAC,EAAE;IACf,OAAOD,KAAK;EAChB;EAEA,MAAMK,OAAO,GAAGP,eAAe,CAACE,KAAK,CAAqB;;EAE1D;EACA,IAAIK,OAAO,KAAK,IAAI,EAAE;IAClB,OAAOL,KAAK;EAChB;EAEA,MAAMM,GAAG,GAAGD,OAAO,CAACE,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EAEjD,IAAIF,GAAG,CAACH,MAAM,KAAK,CAAC,EAAE;IAClB,MAAM,CAACM,CAAC,GAAG,CAAC,EAAE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ISTYLES_PLUGINS = isWeb ? [normalizeWebStylesPlugin] : [];
|
5
|
-
export const withPlugins = (key, style) => unistyles.registry.plugins.concat(UNISTYLES_PLUGINS).reduce((acc, plugin) => {
|
1
|
+
export const withPlugins = (key, style, plugins, runtime) => plugins.reduce((acc, plugin) => {
|
6
2
|
if (plugin.onParsedStyle) {
|
7
|
-
return plugin.onParsedStyle(key, acc,
|
3
|
+
return plugin.onParsedStyle(key, acc, runtime);
|
8
4
|
}
|
9
5
|
return acc;
|
10
6
|
}, style);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["withPlugins","key","style","plugins","runtime","reduce","acc","plugin","onParsedStyle"],"sourceRoot":"../../../src","sources":["plugins/withPlugins.ts"],"mappings":"AAGA,OAAO,MAAMA,WAAW,GAAGA,CACvBC,GAAW,EACXC,KAAc,EACdC,OAA+B,EAC/BC,OAAyB,KACxBD,OAAO,CAACE,MAAM,CAAC,CAACC,GAAG,EAAEC,MAAM,KAAK;EACjC,IAAIA,MAAM,CAACC,aAAa,EAAE;IACtB,OAAOD,MAAM,CAACC,aAAa,CAACP,GAAG,EAAEK,GAAG,EAAEF,OAAO,CAAC;EAClD;EAEA,OAAOE,GAAG;AACd,CAAC,EAAEJ,KAAK,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/stylesheet.ts"],"mappings":""}
|
package/lib/module/useStyles.js
CHANGED
@@ -1,42 +1,39 @@
|
|
1
1
|
import { useMemo } from 'react';
|
2
2
|
import { StyleSheet } from 'react-native';
|
3
3
|
import { parseStyle, proxifyFunction } from './utils';
|
4
|
-
import { useUnistyles } from './hooks';
|
5
|
-
|
4
|
+
import { useUnistyles, useVariants } from './hooks';
|
5
|
+
import { unistyles } from './core';
|
6
|
+
export const useStyles = (stylesheet, variantsMap) => {
|
6
7
|
const {
|
7
8
|
theme,
|
8
9
|
layout,
|
9
10
|
plugins
|
10
11
|
} = useUnistyles();
|
11
|
-
const {
|
12
|
-
screenSize,
|
13
|
-
breakpoint
|
14
|
-
} = layout;
|
15
12
|
if (!stylesheet) {
|
16
13
|
return {
|
17
14
|
theme,
|
18
|
-
breakpoint,
|
15
|
+
breakpoint: layout.breakpoint,
|
19
16
|
styles: {}
|
20
17
|
};
|
21
18
|
}
|
19
|
+
const variants = useVariants(variantsMap);
|
22
20
|
const parsedStyles = useMemo(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet, layout]);
|
23
21
|
const dynamicStyleSheet = useMemo(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
|
24
22
|
let [key, value] = _ref;
|
25
|
-
const style = value;
|
26
23
|
if (typeof value === 'function') {
|
27
24
|
return {
|
28
25
|
...acc,
|
29
|
-
[key]: proxifyFunction(key, value,
|
26
|
+
[key]: proxifyFunction(key, value, unistyles.registry.plugins, unistyles.runtime, variants)
|
30
27
|
};
|
31
28
|
}
|
32
29
|
return StyleSheet.create({
|
33
30
|
...acc,
|
34
|
-
[key]: parseStyle(key,
|
31
|
+
[key]: parseStyle(key, value, unistyles.registry.plugins, unistyles.runtime, variants)
|
35
32
|
});
|
36
|
-
}, {}), [
|
33
|
+
}, {}), [layout, parsedStyles, variants, plugins]);
|
37
34
|
return {
|
38
35
|
theme,
|
39
|
-
breakpoint,
|
36
|
+
breakpoint: layout.breakpoint,
|
40
37
|
styles: dynamicStyleSheet
|
41
38
|
};
|
42
39
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","useUnistyles","useStyles","stylesheet","
|
1
|
+
{"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","useUnistyles","useVariants","unistyles","useStyles","stylesheet","variantsMap","theme","layout","plugins","breakpoint","styles","variants","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","registry","runtime","create"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":"AAAA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AAK,EACLlB,SAAS,CAACmB,QAAQ,CAACb,OAAO,EAC1BN,SAAS,CAACoB,OAAO,EACjBX,QACJ;IACJ,CAAC,CAAC;EACN,CAAC,EAAE,CAAC,CAAC,CAAC,EACV,CAACJ,MAAM,EAAEK,YAAY,EAAED,QAAQ,EAAEH,OAAO,CACxC,CAA8B;EAE9B,OAAO;IACHF,KAAK;IACLG,UAAU,EAAEF,MAAM,CAACE,UAAU;IAC7BC,MAAM,EAAEG;EACZ,CAAC;AACL,CAAC"}
|
@@ -1,5 +1,4 @@
|
|
1
|
-
export { mq, MQSymbol } from './mq';
|
2
|
-
export { getKeyForVariant } from './variants';
|
1
|
+
export { mq, MQSymbol, MQHeight, MQWidth, MQHeightAndWidth, MQWidthAndHeight } from './mq';
|
3
2
|
export { getKeyForUnistylesMediaQuery, isWithinTheWidthAndHeight, isValidMq, parseMq } from './mqParser';
|
4
3
|
export { getValueForBreakpoint } from './breakpoints';
|
5
4
|
export { proxifyFunction, parseStyle } from './styles';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["mq","MQSymbol","
|
1
|
+
{"version":3,"names":["mq","MQSymbol","MQHeight","MQWidth","MQHeightAndWidth","MQWidthAndHeight","getKeyForUnistylesMediaQuery","isWithinTheWidthAndHeight","isValidMq","parseMq","getValueForBreakpoint","proxifyFunction","parseStyle"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":"AAAA,SAASA,EAAE,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,gBAAgB,QAAQ,MAAM;AAC1F,SAASC,4BAA4B,EAAEC,yBAAyB,EAAEC,SAAS,EAAEC,OAAO,QAAQ,YAAY;AACxG,SAASC,qBAAqB,QAAQ,eAAe;AACrD,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU"}
|