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.
Files changed (122) hide show
  1. package/cxx/UnistylesRuntime.h +6 -6
  2. package/lib/commonjs/common.js +15 -15
  3. package/lib/commonjs/common.js.map +1 -1
  4. package/lib/commonjs/core/UnistyleRegistry.js +3 -2
  5. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
  6. package/lib/commonjs/core/UnistylesRuntime.js +1 -1
  7. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
  8. package/lib/commonjs/createStyleSheet.js +1 -6
  9. package/lib/commonjs/createStyleSheet.js.map +1 -1
  10. package/lib/commonjs/hooks/index.js +7 -0
  11. package/lib/commonjs/hooks/index.js.map +1 -1
  12. package/lib/commonjs/hooks/useUnistyles.js +4 -7
  13. package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
  14. package/lib/commonjs/hooks/useVariants.js +24 -0
  15. package/lib/commonjs/hooks/useVariants.js.map +1 -0
  16. package/lib/commonjs/plugins/normalizer/normalizer.js +1 -1
  17. package/lib/commonjs/plugins/normalizer/normalizer.js.map +1 -1
  18. package/lib/commonjs/plugins/withPlugins.js +2 -6
  19. package/lib/commonjs/plugins/withPlugins.js.map +1 -1
  20. package/lib/commonjs/types/stylesheet.js +6 -0
  21. package/lib/commonjs/types/stylesheet.js.map +1 -0
  22. package/lib/commonjs/useStyles.js +8 -11
  23. package/lib/commonjs/useStyles.js.map +1 -1
  24. package/lib/commonjs/utils/index.js +22 -5
  25. package/lib/commonjs/utils/index.js.map +1 -1
  26. package/lib/commonjs/utils/mq.js +42 -28
  27. package/lib/commonjs/utils/mq.js.map +1 -1
  28. package/lib/commonjs/utils/styles.js +19 -23
  29. package/lib/commonjs/utils/styles.js.map +1 -1
  30. package/lib/commonjs/utils/variants.js +43 -8
  31. package/lib/commonjs/utils/variants.js.map +1 -1
  32. package/lib/module/common.js +14 -14
  33. package/lib/module/common.js.map +1 -1
  34. package/lib/module/core/UnistyleRegistry.js +4 -3
  35. package/lib/module/core/UnistyleRegistry.js.map +1 -1
  36. package/lib/module/core/UnistylesRuntime.js +1 -1
  37. package/lib/module/core/UnistylesRuntime.js.map +1 -1
  38. package/lib/module/createStyleSheet.js +1 -6
  39. package/lib/module/createStyleSheet.js.map +1 -1
  40. package/lib/module/hooks/index.js +1 -0
  41. package/lib/module/hooks/index.js.map +1 -1
  42. package/lib/module/hooks/useUnistyles.js +5 -8
  43. package/lib/module/hooks/useUnistyles.js.map +1 -1
  44. package/lib/module/hooks/useVariants.js +17 -0
  45. package/lib/module/hooks/useVariants.js.map +1 -0
  46. package/lib/module/plugins/normalizer/normalizer.js +1 -1
  47. package/lib/module/plugins/normalizer/normalizer.js.map +1 -1
  48. package/lib/module/plugins/withPlugins.js +2 -6
  49. package/lib/module/plugins/withPlugins.js.map +1 -1
  50. package/lib/module/types/stylesheet.js +2 -0
  51. package/lib/module/types/stylesheet.js.map +1 -0
  52. package/lib/module/useStyles.js +9 -12
  53. package/lib/module/useStyles.js.map +1 -1
  54. package/lib/module/utils/index.js +1 -2
  55. package/lib/module/utils/index.js.map +1 -1
  56. package/lib/module/utils/mq.js +41 -27
  57. package/lib/module/utils/mq.js.map +1 -1
  58. package/lib/module/utils/styles.js +20 -24
  59. package/lib/module/utils/styles.js.map +1 -1
  60. package/lib/module/utils/variants.js +41 -6
  61. package/lib/module/utils/variants.js.map +1 -1
  62. package/lib/typescript/src/common.d.ts +10 -10
  63. package/lib/typescript/src/common.d.ts.map +1 -1
  64. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
  65. package/lib/typescript/src/createStyleSheet.d.ts +2 -2
  66. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
  67. package/lib/typescript/src/global.d.ts.map +1 -1
  68. package/lib/typescript/src/hooks/index.d.ts +1 -0
  69. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  70. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
  71. package/lib/typescript/src/hooks/useVariants.d.ts +3 -0
  72. package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -0
  73. package/lib/typescript/src/plugins/normalizer/normalizer.d.ts.map +1 -1
  74. package/lib/typescript/src/plugins/withPlugins.d.ts +3 -2
  75. package/lib/typescript/src/plugins/withPlugins.d.ts.map +1 -1
  76. package/lib/typescript/src/types/breakpoints.d.ts +20 -14
  77. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  78. package/lib/typescript/src/types/core.d.ts +3 -26
  79. package/lib/typescript/src/types/core.d.ts.map +1 -1
  80. package/lib/typescript/src/types/index.d.ts +2 -1
  81. package/lib/typescript/src/types/index.d.ts.map +1 -1
  82. package/lib/typescript/src/types/mq.d.ts +2 -2
  83. package/lib/typescript/src/types/mq.d.ts.map +1 -1
  84. package/lib/typescript/src/types/stylesheet.d.ts +47 -0
  85. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -0
  86. package/lib/typescript/src/types/unistyles.d.ts +5 -6
  87. package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
  88. package/lib/typescript/src/types/variants.d.ts +13 -7
  89. package/lib/typescript/src/types/variants.d.ts.map +1 -1
  90. package/lib/typescript/src/useStyles.d.ts +3 -3
  91. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  92. package/lib/typescript/src/utils/index.d.ts +1 -2
  93. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  94. package/lib/typescript/src/utils/mq.d.ts +19 -13
  95. package/lib/typescript/src/utils/mq.d.ts.map +1 -1
  96. package/lib/typescript/src/utils/styles.d.ts +4 -4
  97. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  98. package/lib/typescript/src/utils/variants.d.ts +2 -2
  99. package/lib/typescript/src/utils/variants.d.ts.map +1 -1
  100. package/package.json +14 -14
  101. package/src/common.ts +10 -10
  102. package/src/core/UnistyleRegistry.ts +6 -3
  103. package/src/core/UnistylesRuntime.ts +1 -1
  104. package/src/createStyleSheet.ts +2 -8
  105. package/src/global.ts +1 -0
  106. package/src/hooks/index.ts +1 -0
  107. package/src/hooks/useUnistyles.ts +5 -8
  108. package/src/hooks/useVariants.ts +23 -0
  109. package/src/plugins/normalizer/normalizer.ts +3 -3
  110. package/src/plugins/withPlugins.ts +13 -15
  111. package/src/types/breakpoints.ts +47 -26
  112. package/src/types/core.ts +6 -42
  113. package/src/types/index.ts +1 -1
  114. package/src/types/mq.ts +2 -2
  115. package/src/types/stylesheet.ts +56 -0
  116. package/src/types/unistyles.ts +5 -6
  117. package/src/types/variants.ts +17 -9
  118. package/src/useStyles.ts +22 -16
  119. package/src/utils/index.ts +1 -2
  120. package/src/utils/mq.ts +56 -41
  121. package/src/utils/styles.ts +28 -45
  122. package/src/utils/variants.ts +55 -7
@@ -1,9 +1,8 @@
1
- import { CxxUnistylesEventTypes, ScreenOrientation } from '../common';
1
+ import { UnistylesEventType, ScreenOrientation } from '../common';
2
2
  import type { UnistylesThemes, UnistylesBreakpoints } from '../global';
3
3
  import type { ScreenSize } from './core';
4
- import type { Optional } from './common';
5
4
  import type { UnistylesPlugin } from './plugin';
6
- export type ColorSchemeName = Optional<'light' | 'dark'>;
5
+ export type ColorSchemeName = 'light' | 'dark' | 'unspecified';
7
6
  export type UnistylesConfig = {
8
7
  adaptiveThemes?: boolean;
9
8
  experimentalPlugins?: Array<UnistylesPlugin>;
@@ -26,13 +25,13 @@ export type UnistylesBridge = {
26
25
  removePlugin(pluginName: string): void;
27
26
  };
28
27
  export type UnistylesThemeEvent = {
29
- type: CxxUnistylesEventTypes.Theme;
28
+ type: UnistylesEventType.Theme;
30
29
  payload: {
31
30
  themeName: keyof UnistylesThemes;
32
31
  };
33
32
  };
34
33
  export type UnistylesMobileLayoutEvent = {
35
- type: CxxUnistylesEventTypes.Layout;
34
+ type: UnistylesEventType.Layout;
36
35
  payload: {
37
36
  screen: ScreenSize;
38
37
  breakpoint: keyof UnistylesBreakpoints;
@@ -40,7 +39,7 @@ export type UnistylesMobileLayoutEvent = {
40
39
  };
41
40
  };
42
41
  export type UnistylesPluginEvent = {
43
- type: CxxUnistylesEventTypes.Plugin;
42
+ type: UnistylesEventType.Plugin;
44
43
  };
45
44
  export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent | UnistylesPluginEvent;
46
45
  //# sourceMappingURL=unistyles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unistyles.d.ts","sourceRoot":"","sources":["../../../../src/types/unistyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,CAAA;AAExD,MAAM,MAAM,eAAe,GAAG;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,eAAe,CAAA;CACvC,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAE1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,MAAM,eAAe,CAAC;IACjC,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,WAAW,EAAE,eAAe,CAAC;IAC7B,qBAAqB,EAAE,KAAK,CAAC,CAAC,MAAM,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAG7G,MAA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C,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC;IAChC,OAAO,EAAE;QACL,MAAM,EAAE,UAAU,CAAC;QACnB,UAAU,EAAE,MAAM,oBAAoB,CAAC;QACvC,WAAW,EAAE,OAAO,iBAAiB,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAA;KACxE,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAC/B,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,0BAA0B,GAAG,oBAAoB,CAAA"}
@@ -1,8 +1,14 @@
1
- export type ExtractVariantNames<T> = T extends object ? {
2
- [K in keyof T]: T[K] extends {
3
- variants: infer V;
4
- } ? V extends object ? {
5
- [VK in keyof V]: VK extends 'default' ? never : VK;
6
- }[keyof V] | ExtractVariantNames<V> : never : ExtractVariantNames<T[K]>;
7
- }[keyof T] : never;
1
+ export type ExtractVariantNames<T> = T extends (...args: any) => infer R ? ExtractVariantKeys<R> : ExtractVariantKeys<T>;
2
+ type ExtractVariantKeys<T> = T extends object ? ExtractVariant<T[keyof T]> : never;
3
+ type ExtractSubVariantKeys<T> = T extends object ? keyof Omit<T, 'default'> | undefined : never;
4
+ type ExtractVariant<T> = T extends (...args: any) => infer R ? R extends {
5
+ variants: infer V;
6
+ } ? {
7
+ [key in keyof V]?: ExtractSubVariantKeys<V[key]>;
8
+ } : never : T extends {
9
+ variants: infer V;
10
+ } ? {
11
+ [key in keyof V]?: ExtractSubVariantKeys<V[key]>;
12
+ } : never;
13
+ export {};
8
14
  //# sourceMappingURL=variants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/types/variants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAC/C;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAA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C,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAAE,GACpD,KAAK,CAAA"}
@@ -1,10 +1,10 @@
1
- import type { CreateStylesFactory, CustomNamedStyles, ExtractVariantNames, ReactNativeStyleSheet, UnistylesTheme } from './types';
2
1
  import type { UnistylesBreakpoints } from './global';
3
- type ParsedStylesheet<ST extends CustomNamedStyles<ST>> = {
2
+ import type { ExtractVariantNames, ReactNativeStyleSheet, StyleSheetWithSuperPowers, UnistylesTheme } from './types';
3
+ type ParsedStylesheet<ST extends StyleSheetWithSuperPowers> = {
4
4
  theme: UnistylesTheme;
5
5
  breakpoint: keyof UnistylesBreakpoints;
6
6
  styles: ReactNativeStyleSheet<ST>;
7
7
  };
8
- export declare const useStyles: <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, never> | undefined, variant?: (ExtractVariantNames<ST> & string) | undefined) => ParsedStylesheet<ST>;
8
+ export declare const useStyles: <ST extends StyleSheetWithSuperPowers>(stylesheet?: ST | undefined, variantsMap?: ExtractVariantNames<ST> | undefined) => ParsedStylesheet<ST>;
9
9
  export {};
10
10
  //# sourceMappingURL=useStyles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStyles.d.ts","sourceRoot":"","sources":["../../../src/useStyles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACjB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD,KAAK,gBAAgB,CAAC,EAAE,SAAS,iBAAiB,CAAC,EAAE,CAAC,IAAI;IACtD,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,MAAM,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,SAAS,oLA0CrB,CAAA"}
1
+ {"version":3,"file":"useStyles.d.ts","sourceRoot":"","sources":["../../../src/useStyles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD,OAAO,KAAK,EACR,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,cAAc,EACjB,MAAM,SAAS,CAAA;AAEhB,KAAK,gBAAgB,CAAC,EAAE,SAAS,yBAAyB,IAAI;IAC1D,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,MAAM,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,SAAS,gJAgDrB,CAAA"}
@@ -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,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACxG,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAA;AAC1F,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACxG,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA"}
@@ -1,21 +1,27 @@
1
- import type { MediaQuery, Nullable } from '../types';
1
+ import type { Nullable } from '../types';
2
2
  import type { UnistylesBreakpoints } from '../global';
3
3
  export declare const MQSymbol: unique symbol;
4
+ export declare const MQWidth: unique symbol;
5
+ export declare const MQHeight: unique symbol;
6
+ export declare const MQWidthAndHeight: unique symbol;
7
+ export declare const MQHeightAndWidth: unique symbol;
4
8
  type MQValue = keyof UnistylesBreakpoints | number;
5
9
  type MQHandler = {
6
- w(wMin?: Nullable<MQValue>, wMax?: MQValue): WidthHandler;
7
- width(wMin?: Nullable<MQValue>, wMax?: MQValue): WidthHandler;
8
- h(hMin?: Nullable<MQValue>, hMax?: MQValue): HeightHandler;
9
- height(hMin?: Nullable<MQValue>, hMax?: MQValue): HeightHandler;
10
+ only: {
11
+ width(wMin?: Nullable<MQValue>, wMax?: MQValue): typeof MQWidth;
12
+ height(hMin?: Nullable<MQValue>, hMax?: MQValue): typeof MQHeight;
13
+ };
14
+ width(wMin?: Nullable<MQValue>, wMax?: MQValue): {
15
+ and: {
16
+ height(hMin?: Nullable<MQValue>, hMax?: MQValue): typeof MQWidthAndHeight;
17
+ };
18
+ };
19
+ height(hMin?: Nullable<MQValue>, hMax?: MQValue): {
20
+ and: {
21
+ width(wMin?: Nullable<MQValue>, wMax?: MQValue): typeof MQHeightAndWidth;
22
+ };
23
+ };
10
24
  };
11
- type HeightHandler = {
12
- w(wMin?: Nullable<MQValue>, wMax?: MQValue): MediaQuery;
13
- width(wMin?: Nullable<MQValue>, wMax?: MQValue): MediaQuery;
14
- } & MediaQuery;
15
- type WidthHandler = {
16
- h(hMin?: Nullable<MQValue>, hMax?: MQValue): MediaQuery;
17
- height(hMin?: Nullable<MQValue>, hMax?: MQValue): MediaQuery;
18
- } & MediaQuery;
19
25
  export declare const mq: MQHandler;
20
26
  export {};
21
27
  //# sourceMappingURL=mq.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../../../src/utils/mq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGrD,eAAO,MAAM,QAAQ,eAAyB,CAAA;AAE9C,KAAK,OAAO,GAAG,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAElD,KAAK,SAAS,GAAG;IACb,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAC1D,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAC9D,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;CAClE,CAAA;AAED,KAAK,aAAa,GAAG;IACjB,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IACxD,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,O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AAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,gBAAgB,CAAA;SAC5E,CAAA;KACJ,CAAC;IACF,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG;QAC9C,GAAG,EAAE;YACD,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,gBAAgB,CAAA;SAC3E,CAAA;KACJ,CAAA;CACJ,CAAA;AA0ED,eAAO,MAAM,EAAE,WAmBb,CAAA"}
@@ -1,6 +1,6 @@
1
- import type { CustomNamedStyles, ScreenSize, RNStyle } from '../types';
2
- import type { UnistylesBreakpoints } from '../global';
3
- export declare const proxifyFunction: (key: string, fn: Function, breakpoint: keyof UnistylesBreakpoints & string, screenSize: ScreenSize, variant?: string) => Function;
1
+ import type { UnistylesPlugin, StyleSheet, Optional } from '../types';
2
+ import type { UnistylesRuntime } from '../core';
3
+ export declare const proxifyFunction: (key: string, fn: Function, plugins: Array<UnistylesPlugin>, runtime: UnistylesRuntime, variant?: Record<string, Optional<string>>) => Function;
4
4
  export declare const isPlatformColor: <T extends {}>(value: T) => boolean;
5
- export declare const parseStyle: <T extends RNStyle>(key: string, style: CustomNamedStyles<T>, breakpoint: keyof UnistylesBreakpoints & string, screenSize: ScreenSize, variant?: string) => T;
5
+ export declare const parseStyle: <T extends StyleSheet>(key: string, style: T, plugins: Array<UnistylesPlugin>, runtime: UnistylesRuntime, variant?: Record<string, Optional<string>>) => T;
6
6
  //# sourceMappingURL=styles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAe,OAAO,EAAE,MAAM,UAAU,CAAA;AAEnF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAKrD,eAAO,MAAM,eAAe,QACnB,MAAM,MACP,QAAQ,cAAc,MAAM,oBAAoB,GAAG,MAAM,cACjD,UAAU,YACZ,MAAM,KACjB,QAGD,CAAA;AAEF,eAAO,MAAM,eAAe,8BAA6B,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,2BACd,MAAM,2CAEC,MAAM,oBAAoB,GAAG,MAAM,cACnC,UAAU,YACZ,MAAM,MA4DnB,CAAA"}
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,eAAe,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAElF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAK/C,eAAO,MAAM,eAAe,QACnB,MAAM,MACP,QAAQ,WACH,MAAM,eAAe,CAAC,WACtB,gBAAgB,YACf,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,KAC3C,QAGD,CAAA;AAEF,eAAO,MAAM,eAAe,8BAA6B,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,8BACd,MAAM,qBAEF,MAAM,eAAe,CAAC,WACtB,gBAAgB,YACf,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,MA0C7C,CAAA"}
@@ -1,3 +1,3 @@
1
- import type { Optional, NestedStyle } from '../types';
2
- export declare const getKeyForVariant: (value: NestedStyle, variant?: string) => Optional<string>;
1
+ import type { Optional, StyleSheet } from '../types';
2
+ export declare const getStyleWithVariants: (style: StyleSheet, variantValues?: Record<string, Optional<string>>) => StyleSheet;
3
3
  //# sourceMappingURL=variants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/utils/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAErD,eAAO,MAAM,gBAAgB,UAAW,WAAW,YAAY,MAAM,KAAG,SAAS,MAAM,CAUtF,CAAA"}
1
+ {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/utils/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAe,MAAM,UAAU,CAAA;AAqCjE,eAAO,MAAM,oBAAoB,UACtB,UAAU,kBACD,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,eAqBnD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.0.0-alpha.13",
3
+ "version": "2.0.0-alpha.15",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -50,23 +50,23 @@
50
50
  "registry": "https://registry.npmjs.org/"
51
51
  },
52
52
  "devDependencies": {
53
- "@commitlint/config-conventional": "18.1.0",
53
+ "@commitlint/config-conventional": "18.4.3",
54
54
  "@react-native/eslint-config": "0.74.0",
55
55
  "@react-native/normalize-colors": "0.74.1",
56
- "@release-it/conventional-changelog": "7.0.2",
56
+ "@release-it/conventional-changelog": "8.0.1",
57
57
  "@testing-library/react-hooks": "8.0.1",
58
- "@types/jest": "29.5.7",
59
- "@types/react": "18.2.34",
60
- "@typescript-eslint/eslint-plugin": "6.9.1",
61
- "@typescript-eslint/eslint-plugin-tslint": "6.9.1",
62
- "@typescript-eslint/parser": "6.9.1",
63
- "commitlint": "18.2.0",
58
+ "@types/jest": "29.5.10",
59
+ "@types/react": "18.2.38",
60
+ "@typescript-eslint/eslint-plugin": "6.12.0",
61
+ "@typescript-eslint/eslint-plugin-tslint": "6.12.0",
62
+ "@typescript-eslint/parser": "6.12.0",
63
+ "commitlint": "18.4.3",
64
64
  "concurrently": "8.2.2",
65
- "eslint": "8.53.0",
65
+ "eslint": "8.54.0",
66
66
  "eslint-config-codemask": "1.1.7",
67
67
  "eslint-plugin-functional": "6.0.0",
68
68
  "eslint-plugin-import": "2.29.0",
69
- "eslint-plugin-jsdoc": "46.8.2",
69
+ "eslint-plugin-jsdoc": "46.9.0",
70
70
  "eslint-plugin-jsx-a11y": "6.8.0",
71
71
  "eslint-plugin-nested-if": "1.0.0",
72
72
  "eslint-plugin-no-else": "0.2.2",
@@ -77,11 +77,11 @@
77
77
  "husky": "8.0.3",
78
78
  "jest": "29.7.0",
79
79
  "react": "18.2.0",
80
- "react-native": "0.72.6",
81
- "react-native-builder-bob": "0.23.1",
80
+ "react-native": "0.72.7",
81
+ "react-native-builder-bob": "0.23.2",
82
82
  "react-native-web": "0.19.9",
83
83
  "react-test-renderer": "18.2.0",
84
- "release-it": "16.2.1",
84
+ "release-it": "17.0.0",
85
85
  "typescript": "5.2.2"
86
86
  },
87
87
  "peerDependencies": {
package/src/common.ts CHANGED
@@ -15,20 +15,20 @@ export const ScreenOrientation = {
15
15
  Portrait: 'portrait'
16
16
  } as const
17
17
 
18
- export enum CxxUnistylesEventTypes {
18
+ export enum UnistylesEventType {
19
19
  Theme = 'theme',
20
20
  Layout = 'layout',
21
21
  Plugin = 'plugin'
22
22
  }
23
23
 
24
24
  export enum UnistylesError {
25
- RuntimeUnavailable = 'UNISTYLES_ERROR_RUNTIME_UNAVAILABLE',
26
- ThemeNotFound = 'UNISTYLES_ERROR_THEME_NOT_FOUND',
27
- ThemeNotRegistered = 'UNISTYLES_ERROR_THEME_NOT_REGISTERED',
28
- ThemesCannotBeEmpty = 'UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY',
29
- BreakpointsCannotBeEmpty = 'UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY',
30
- BreakpointsMustStartFromZero = 'UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZERO',
31
- InvalidPluginName = 'UNISTYLES_ERROR_INVALID_PLUGIN_NAME',
32
- DuplicatePluginName = 'UNISTYLES_ERROR_DUPLICATE_PLUGIN_NAME',
33
- CantRemoveInternalPlugin = 'UNISTYLES_ERROR_CANT_REMOVE_INTERNAL_PLUGIN'
25
+ RuntimeUnavailable = 'Unistyles runtime is not available. Make sure you followed the installation instructions.',
26
+ ThemeNotFound = 'You are trying to get a theme that is not registered.',
27
+ ThemeNotRegistered = 'You are trying to set a theme that is not registered.',
28
+ ThemesCannotBeEmpty = 'You are trying to register an empty themes object.',
29
+ BreakpointsCannotBeEmpty = 'You are trying to register an empty breakpoints object.',
30
+ BreakpointsMustStartFromZero = 'One breakpoint must start from 0.',
31
+ InvalidPluginName = 'Plugin name can\'t start from reserved prefix. Use another name.',
32
+ DuplicatePluginName = 'You are trying to register a plugin with a name that is already registered.',
33
+ CantRemoveInternalPlugin = 'You are trying to remove an internal unistyles plugin.'
34
34
  }
@@ -1,10 +1,13 @@
1
1
  import type { UnistylesBridge, UnistylesConfig, UnistylesPlugin } from '../types'
2
2
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
3
- import { UnistylesError } from '../common'
3
+ import { isWeb, UnistylesError } from '../common'
4
+ import { normalizeWebStylesPlugin } from '../plugins'
4
5
 
5
6
  export class UnistyleRegistry {
6
7
  public config: UnistylesConfig = {}
7
- public plugins: Array<UnistylesPlugin> = []
8
+ public plugins: Array<UnistylesPlugin> = isWeb
9
+ ? [normalizeWebStylesPlugin]
10
+ : []
8
11
  public themeNames: Array<keyof UnistylesThemes> = []
9
12
  public themes: UnistylesThemes = {} as UnistylesThemes
10
13
  public breakpoints: UnistylesBreakpoints = {} as UnistylesBreakpoints
@@ -68,7 +71,7 @@ export class UnistyleRegistry {
68
71
  throw new Error(UnistylesError.DuplicatePluginName)
69
72
  }
70
73
 
71
- this.plugins = this.plugins.concat([plugin])
74
+ this.plugins = [plugin].concat(this.plugins)
72
75
  this.unistylesBridge.addPlugin(plugin.name, notify)
73
76
  }
74
77
 
@@ -44,7 +44,7 @@ export class UnistylesRuntime {
44
44
  }
45
45
 
46
46
  public setTheme = (name: keyof UnistylesThemes) => {
47
- if (this.unistylesRegistry.hasTheme(name)) {
47
+ if (name !== this.themeName && this.unistylesRegistry.hasTheme(name)) {
48
48
  this.unistylesBridge.useTheme(name)
49
49
 
50
50
  return true
@@ -1,9 +1,3 @@
1
- import type { CustomNamedStyles, UnistylesTheme } from './types'
1
+ import type { StyleSheetWithSuperPowers } from './types'
2
2
 
3
- export const createStyleSheet = <S, X>(styles: S | CustomNamedStyles<S> | X | ((theme: UnistylesTheme) => X | CustomNamedStyles<X>)): S | X => {
4
- if (typeof styles === 'function') {
5
- return styles as X
6
- }
7
-
8
- return styles as S
9
- }
3
+ export const createStyleSheet = <S extends StyleSheetWithSuperPowers>(stylesheet: S): S => stylesheet
package/src/global.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export interface UnistylesThemes {}
2
2
  export interface UnistylesBreakpoints {
3
+ // these breakpoints are only available on mobile, when you didn't specify any breakpoints
3
4
  landscape?: number,
4
5
  portrait?: number,
5
6
  }
@@ -1,2 +1,3 @@
1
1
  export { useInitialTheme } from './useInitialTheme'
2
2
  export { useUnistyles } from './useUnistyles'
3
+ export { useVariants } from './useVariants'
@@ -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 { CxxUnistylesEventTypes } from '../common'
4
+ import { UnistylesEventType } from '../common'
5
5
  import type { UnistylesEvents, UnistylesMobileLayoutEvent, UnistylesThemeEvent } from '../types'
6
6
 
7
7
  const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
@@ -23,24 +23,21 @@ export const useUnistyles = () => {
23
23
  'onChange',
24
24
  (event: UnistylesEvents) => {
25
25
  switch (event.type) {
26
- case CxxUnistylesEventTypes.Theme: {
26
+ case UnistylesEventType.Theme: {
27
27
  const themeEvent = event as UnistylesThemeEvent
28
28
 
29
29
  return setTheme(unistyles.registry.getTheme(themeEvent.payload.themeName))
30
30
  }
31
- case CxxUnistylesEventTypes.Layout: {
31
+ case UnistylesEventType.Layout: {
32
32
  const layoutEvent = event as UnistylesMobileLayoutEvent
33
33
 
34
34
  return setLayout({
35
35
  breakpoint: layoutEvent.payload.breakpoint,
36
36
  orientation: layoutEvent.payload.orientation,
37
- screenSize: {
38
- width: layoutEvent.payload.screen.width,
39
- height: layoutEvent.payload.screen.height
40
- }
37
+ screenSize: layoutEvent.payload.screen
41
38
  })
42
39
  }
43
- case CxxUnistylesEventTypes.Plugin: {
40
+ case UnistylesEventType.Plugin: {
44
41
  return setPlugins(unistyles.runtime.enabledPlugins)
45
42
  }
46
43
  default:
@@ -0,0 +1,23 @@
1
+ import { useRef } from 'react'
2
+ import type { Optional } from '../types'
3
+
4
+ const compareVariants = (prevVariants?: Record<string, Optional<string>>, nextVariants?: Record<string, Optional<string>>) => {
5
+ const keysA = Object.keys(prevVariants ?? {})
6
+ const keysB = Object.keys(nextVariants ?? {})
7
+
8
+ if (keysA.length !== keysB.length) {
9
+ return false
10
+ }
11
+
12
+ return keysA.every(key => prevVariants![key] === (nextVariants ?? {})[key])
13
+ }
14
+
15
+ export const useVariants = (variantsMap?: Record<string, Optional<string>>) => {
16
+ const variantsRef = useRef<Optional<Record<string, Optional<string>>>>(variantsMap)
17
+
18
+ if (!compareVariants(variantsRef.current, variantsMap)) {
19
+ variantsRef.current = variantsMap
20
+ }
21
+
22
+ return variantsRef.current
23
+ }
@@ -1,7 +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
- import type { TextShadow, Transforms, BoxShadow } from '../../types'
4
+ import type { TextShadow, Transforms, BoxShadow, Nullable } from '../../types'
5
5
 
6
6
  type Preprocessor = {
7
7
  createTextShadowValue(style: TextShadow): string,
@@ -15,9 +15,9 @@ export const normalizeColor = (color: string, opacity: number = 1) => {
15
15
  return color
16
16
  }
17
17
 
18
- const integer = normalizeColors(color) as number | null
18
+ const integer = normalizeColors(color) as Nullable<number>
19
19
 
20
- // If the colour is an unknown format, the return value is null
20
+ // If the color is an unknown format, the return value is null
21
21
  if (integer === null) {
22
22
  return color
23
23
  }
@@ -1,17 +1,15 @@
1
- import type { RNStyle } from '../types'
2
- import { normalizeWebStylesPlugin } from './normalizeWebStylesPlugin'
3
- import { isWeb } from '../common'
4
- import { unistyles } from '../core'
1
+ import type { RNStyle, UnistylesPlugin } from '../types'
2
+ import type { UnistylesRuntime } from '../core'
5
3
 
6
- const UNISTYLES_PLUGINS = isWeb
7
- ? [normalizeWebStylesPlugin]
8
- : []
4
+ export const withPlugins = (
5
+ key: string,
6
+ style: RNStyle,
7
+ plugins: Array<UnistylesPlugin>,
8
+ runtime: UnistylesRuntime
9
+ ) => plugins.reduce((acc, plugin) => {
10
+ if (plugin.onParsedStyle) {
11
+ return plugin.onParsedStyle(key, acc, runtime)
12
+ }
9
13
 
10
- export const withPlugins = (key: string, style: RNStyle) => unistyles.registry.plugins.concat(UNISTYLES_PLUGINS)
11
- .reduce((acc, plugin) => {
12
- if (plugin.onParsedStyle) {
13
- return plugin.onParsedStyle(key, acc, unistyles.runtime)
14
- }
15
-
16
- return acc
17
- }, style)
14
+ return acc
15
+ }, style)
@@ -1,34 +1,55 @@
1
- import type { OpaqueColorValue } from 'react-native'
2
- import type { UnistylesBreakpoints } from '../global'
3
- import type { MediaQuery } from './mq'
1
+ import type { ColorValue, OpaqueColorValue } from 'react-native'
2
+ import type { UnistylesTheme } from '../types'
3
+ import type { AllAvailableKeys, BreakpointsOrMediaQueries } from './stylesheet'
4
4
 
5
5
  type WithEmptyObject<V> = keyof V extends never ? {} : V
6
6
 
7
- type ExtractBreakpoints<T> = T extends Partial<Record<keyof UnistylesBreakpoints & string, infer V>>
8
- ? WithEmptyObject<V>
9
- : T extends (...args: infer A) => infer R
10
- ? (...args: A) => ExtractBreakpoints<R>
11
- : {
12
- [K in keyof T]: T[K] extends (...args: infer A) => infer R
13
- ? (...args: A) => ExtractBreakpoints<R>
14
- : T[K] extends object
15
- ? ExtractBreakpoints<T[K]>
7
+ type ExtractBreakpoints<T> = T extends Partial<Record<BreakpointsOrMediaQueries, infer R>>
8
+ ? WithEmptyObject<R>
9
+ : {
10
+ [K in keyof T]: T[K] extends object
11
+ ? T[K] extends OpaqueColorValue
12
+ ? ColorValue
13
+ : ExtractBreakpoints<T[K]>
14
+ : T[K]
15
+ }
16
+
17
+ type ParseNestedObject<T> = T extends (...args: infer A) => infer R
18
+ ? (...args: A) => ParseNestedObject<R>
19
+ : keyof T extends AllAvailableKeys
20
+ ? ExtractBreakpoints<T>
21
+ : T extends { variants: infer R }
22
+ ? ParseVariants<FlattenVariants<R>> & ParseNestedObject<Omit<T, 'variants'>>
23
+ : {
24
+ [K in keyof T]: T[K] extends object
25
+ ? T[K] extends OpaqueColorValue
26
+ ? ColorValue
27
+ : ExtractBreakpoints<T[K]>
16
28
  : T[K]
17
- }
29
+ }
18
30
 
19
- type UnionToIntersection<U> =
20
- (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
31
+ type FlattenVariants<T> = T extends object
32
+ ? {
33
+ [K in keyof T]: T[K] extends object
34
+ ? {
35
+ [key in keyof T[K]]: T[K][key] extends object
36
+ ? ParseNestedObject<T[K][key]>
37
+ : never
38
+ }
39
+ : never
40
+ }
41
+ : never
21
42
 
22
- type RemoveKeysWithPrefix<T> = T extends (...args: Array<any>) => infer R
23
- ? (...args: Parameters<T>) => RemoveKeysWithPrefix<R>
24
- : T extends object
25
- ? T extends OpaqueColorValue
26
- ? string
27
- : T extends Record<string, infer _V>
28
- ? T extends { variants: infer _V }
29
- ? Omit<T, 'variants'> & UnionToIntersection<_V[keyof _V]>
30
- : { [K in keyof T as K extends MediaQuery ? keyof UnistylesBreakpoints & string : K]: RemoveKeysWithPrefix<T[K]> }
31
- : { [K in keyof T]: RemoveKeysWithPrefix<T[K]> }
43
+ type ParseVariants<T> = T extends object
44
+ ? T[keyof T] extends object
45
+ ? ParseVariants<T[keyof T]>
32
46
  : T
47
+ : T
48
+
49
+ type ParseStyleKeys<T> = T extends object
50
+ ? { [K in keyof T]: ParseNestedObject<T[K]> }
51
+ : never
33
52
 
34
- export type ReactNativeStyleSheet<T> = ExtractBreakpoints<RemoveKeysWithPrefix<T>>
53
+ export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme) => infer R
54
+ ? ParseStyleKeys<R>
55
+ : ParseStyleKeys<T>
package/src/types/core.ts CHANGED
@@ -17,17 +17,12 @@ import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
17
17
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
18
18
  import type { MediaQuery } from './mq'
19
19
 
20
- type ShadowOffset = {
20
+ export type ShadowOffset = {
21
21
  width: number,
22
22
  height: number
23
23
  }
24
24
 
25
- export type ScreenSize = {
26
- width: number,
27
- height: number
28
- }
29
-
30
- type TransformStyles =
25
+ export type TransformStyles =
31
26
  & PerpectiveTransform
32
27
  & RotateTransform
33
28
  & RotateXTransform
@@ -42,40 +37,9 @@ type TransformStyles =
42
37
  & SkewYTransform
43
38
  & MatrixTransform
44
39
 
45
- type UnistyleNested = {
46
- shadowOffset?: DeepUniStyle<ShadowOffset>,
47
- textShadowOffset?: DeepUniStyle<ShadowOffset>,
48
- transform?: Array<DeepUniStyle<TransformStyles>>,
49
- variants?: Record<string, UnistyleView | UnistyleText | UnistyleImage & Omit<UnistyleNested, 'variants'>>
50
- }
51
-
52
- type UniStyle<V> = {
53
- [innerKey in keyof UnistylesBreakpoints]?: V
54
- } | {
55
- [innerKey in MediaQuery]: V
56
- }
57
-
58
- type DeepUniStyle<T> = {
59
- [K in keyof T]?: UniStyle<T[K]> | T[K]
60
- }
61
-
62
- // these props are treated differently to nest breakpoints and media queries
63
- type NestedTypes = 'shadowOffset' | 'transform' | 'textShadowOffset'
64
-
65
- type UnistyleView = DeepUniStyle<Omit<ViewStyle, NestedTypes>>
66
- type UnistyleText = DeepUniStyle<Omit<TextStyle, NestedTypes>>
67
- type UnistyleImage = DeepUniStyle<Omit<ImageStyle, NestedTypes>>
68
-
69
- export type StaticStyles =
70
- | UnistyleView
71
- | UnistyleText
72
- | UnistyleImage
73
- & UnistyleNested
74
-
75
- export type CustomNamedStyles<T> = {
76
- [K in keyof T]: T[K] extends (...args: infer A) => StaticStyles
77
- ? (...args: A) => StaticStyles
78
- : StaticStyles
40
+ export type ScreenSize = {
41
+ width: number,
42
+ height: number
79
43
  }
80
44
 
81
45
  export type RNStyle = ViewStyle | TextStyle | ImageStyle
@@ -83,4 +47,4 @@ export type RNValue = number | string | undefined
83
47
  export type NestedStyle = Record<keyof UnistylesBreakpoints | MediaQuery, RNValue>
84
48
  export type NestedStylePairs = Array<[keyof UnistylesBreakpoints | MediaQuery, RNValue]>
85
49
  export type UnistylesTheme = UnistylesThemes[keyof UnistylesThemes]
86
- export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST
50
+ export type CreateStylesFactory<ST> = (theme: UnistylesTheme) => ST