react-native-unistyles 3.0.0-alpha.27 → 3.0.0-alpha.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. package/cxx/core/UnistylesRegistry.cpp +4 -8
  2. package/cxx/core/UnistylesRegistry.h +1 -1
  3. package/cxx/core/UnistylesState.cpp +2 -10
  4. package/cxx/core/UnistylesState.h +1 -1
  5. package/cxx/hybridObjects/HybridStyleSheet.cpp +1 -2
  6. package/cxx/parser/Parser.cpp +73 -4
  7. package/cxx/parser/Parser.h +2 -0
  8. package/lib/commonjs/core/index.js.map +1 -1
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/mq.js +1 -4
  11. package/lib/commonjs/mq.js.map +2 -1
  12. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -0
  13. package/lib/commonjs/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +1 -1
  14. package/lib/commonjs/specs/NavigtionBar/index.js.map +2 -1
  15. package/lib/commonjs/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -1
  16. package/lib/commonjs/specs/ShadowRegistry/types.js +3 -0
  17. package/lib/commonjs/specs/ShadowRegistry/types.js.map +1 -1
  18. package/lib/commonjs/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -1
  19. package/lib/commonjs/specs/StatusBar/index.js.map +2 -1
  20. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js +2 -4
  21. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -1
  22. package/lib/commonjs/specs/index.js.map +1 -1
  23. package/lib/commonjs/specs/types.js +10 -10
  24. package/lib/commonjs/specs/types.js.map +1 -1
  25. package/lib/commonjs/types/stylesheet.js.map +1 -1
  26. package/lib/commonjs/web/convert/index.js +1 -7
  27. package/lib/commonjs/web/convert/shadow.js +1 -5
  28. package/lib/commonjs/web/convert/shadow.js.map +2 -1
  29. package/lib/commonjs/web/convert/textShadow.js +1 -4
  30. package/lib/commonjs/web/convert/textShadow.js.map +2 -1
  31. package/lib/commonjs/web/convert/transform.js.map +2 -1
  32. package/lib/commonjs/web/create.js +1 -5
  33. package/lib/commonjs/web/create.js.map +2 -1
  34. package/lib/commonjs/web/mock.js.map +2 -1
  35. package/lib/commonjs/web/runtime.js.map +2 -1
  36. package/lib/commonjs/web/state.js.map +1 -1
  37. package/lib/commonjs/web/utils/common.js +1 -3
  38. package/lib/commonjs/web/utils/common.js.map +2 -1
  39. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  40. package/lib/commonjs/web/variants/index.js.map +1 -1
  41. package/lib/module/common.js.map +1 -1
  42. package/lib/module/core/useBreakpoint.js.map +1 -1
  43. package/lib/module/core/useBreakpoint.native.js.map +2 -1
  44. package/lib/module/core/useTheme.js.map +2 -1
  45. package/lib/module/core/useTheme.native.js.map +2 -1
  46. package/lib/module/index.js.map +1 -1
  47. package/lib/module/mq.js +1 -4
  48. package/lib/module/mq.js.map +2 -1
  49. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +5 -6
  50. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  51. package/lib/module/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +1 -1
  52. package/lib/module/specs/NavigtionBar/index.js.map +2 -1
  53. package/lib/module/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -0
  54. package/lib/module/specs/ShadowRegistry/index.js.map +2 -1
  55. package/lib/module/specs/ShadowRegistry/types.js +2 -0
  56. package/lib/module/specs/ShadowRegistry/types.js.map +1 -1
  57. package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -1
  58. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -1
  59. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -0
  60. package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js +2 -3
  61. package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +2 -1
  62. package/lib/module/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +1 -1
  63. package/lib/module/specs/index.web.js.map +2 -1
  64. package/lib/module/specs/types.js.map +1 -1
  65. package/lib/module/types/stylesheet.js.map +1 -1
  66. package/lib/module/web/convert/boxShadow.js +1 -4
  67. package/lib/module/web/convert/boxShadow.js.map +2 -1
  68. package/lib/module/web/convert/pseudo.js.map +2 -1
  69. package/lib/module/web/convert/shadow.js +1 -5
  70. package/lib/module/web/convert/shadow.js.map +2 -1
  71. package/lib/module/web/convert/style.js.map +2 -1
  72. package/lib/module/web/convert/textShadow.js +1 -4
  73. package/lib/module/web/convert/textShadow.js.map +2 -1
  74. package/lib/module/web/convert/transform.js.map +2 -1
  75. package/lib/module/web/convert/utils.js.map +2 -1
  76. package/lib/module/web/index.js +1 -2
  77. package/lib/module/web/index.js.map +2 -1
  78. package/lib/module/web/listener.js.map +2 -1
  79. package/lib/module/web/mock.js.map +2 -1
  80. package/lib/module/web/registry.js +1 -3
  81. package/lib/module/web/registry.js.map +2 -1
  82. package/lib/module/web/runtime.js.map +2 -1
  83. package/lib/module/web/shadowRegistry.js +1 -9
  84. package/lib/module/web/shadowRegistry.js.map +2 -1
  85. package/lib/module/web/state.js.map +1 -1
  86. package/lib/module/web/utils/index.js.map +1 -1
  87. package/lib/module/web/utils/unistyle.js.map +2 -1
  88. package/lib/module/web/variants/index.js.map +1 -1
  89. package/lib/module/web/variants/useVariants.js +1 -2
  90. package/lib/module/web/variants/useVariants.js.map +2 -1
  91. package/lib/typescript/src/global.d.ts +0 -2
  92. package/lib/typescript/src/global.d.ts.map +1 -1
  93. package/lib/typescript/src/types/stylesheet.d.ts +4 -2
  94. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  95. package/lib/typescript/src/web/create.d.ts +204 -0
  96. package/lib/typescript/src/web/create.d.ts.map +1 -1
  97. package/lib/typescript/src/web/index.d.ts +204 -0
  98. package/lib/typescript/src/web/index.d.ts.map +1 -1
  99. package/lib/typescript/src/web/runtime.d.ts +3 -3
  100. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  101. package/lib/typescript/src/web/state.d.ts +1 -1
  102. package/lib/typescript/src/web/state.d.ts.map +1 -1
  103. package/lib/typescript/src/web/utils/unistyle.d.ts +2 -2
  104. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  105. package/package.json +13 -13
  106. package/src/common.js +4 -0
  107. package/src/core/index.js +2 -0
  108. package/src/core/useBreakpoint.js +14 -0
  109. package/src/core/useBreakpoint.native.js +16 -0
  110. package/src/core/useTheme.js +14 -0
  111. package/src/core/useTheme.native.js +16 -0
  112. package/src/global.ts +1 -4
  113. package/src/index.js +3 -0
  114. package/src/mq.js +38 -0
  115. package/src/specs/NativePlatform/NativePlatform.nitro.js +18 -0
  116. package/src/specs/NativePlatform/index.js +1 -0
  117. package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.js +1 -0
  118. package/src/specs/NavigtionBar/index.js +9 -0
  119. package/src/specs/ShadowRegistry/ShadowRegistry.nitro.js +1 -0
  120. package/src/specs/ShadowRegistry/index.js +26 -0
  121. package/src/specs/ShadowRegistry/types.js +1 -0
  122. package/src/specs/StatusBar/UnistylesStatusBar.nitro.js +1 -0
  123. package/src/specs/StatusBar/index.js +25 -0
  124. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -0
  125. package/src/specs/StyleSheet/index.js +13 -0
  126. package/src/specs/TurboUnistyles/NativeTurboUnistyles.js +2 -0
  127. package/src/specs/TurboUnistyles/index.js +1 -0
  128. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.js +1 -0
  129. package/src/specs/UnistylesRuntime/index.js +20 -0
  130. package/src/specs/index.js +8 -0
  131. package/src/specs/index.web.js +2 -0
  132. package/src/specs/types.js +17 -0
  133. package/src/types/stylesheet.ts +5 -3
  134. package/src/web/convert/boxShadow.js +59 -0
  135. package/src/web/convert/index.js +56 -0
  136. package/src/web/convert/pseudo.js +131 -0
  137. package/src/web/convert/shadow.js +50 -0
  138. package/src/web/convert/style.js +137 -0
  139. package/src/web/convert/textShadow.js +56 -0
  140. package/src/web/convert/transform.js +65 -0
  141. package/src/web/convert/types.js +2 -0
  142. package/src/web/convert/utils.js +39 -0
  143. package/src/web/create.js +39 -0
  144. package/src/web/index.js +22 -0
  145. package/src/web/listener.js +26 -0
  146. package/src/web/mock.js +21 -0
  147. package/src/web/mq.js +14 -0
  148. package/src/web/registry.js +168 -0
  149. package/src/web/runtime.js +160 -0
  150. package/src/web/runtime.ts +1 -1
  151. package/src/web/shadowRegistry.js +99 -0
  152. package/src/web/state.ts +3 -3
  153. package/src/web/utils/common.js +79 -0
  154. package/src/web/utils/index.js +2 -0
  155. package/src/web/utils/unistyle.js +72 -0
  156. package/src/web/utils/unistyle.ts +2 -2
  157. package/src/web/variants/getVariants.js +26 -0
  158. package/src/web/variants/index.js +2 -0
  159. package/src/web/variants/useVariants.js +50 -0
package/src/common.js ADDED
@@ -0,0 +1,4 @@
1
+ import { Platform } from 'react-native';
2
+ export const isWeb = Platform.OS === 'web';
3
+ export const isIOS = Platform.OS === 'ios';
4
+ export const isAndroid = Platform.OS === 'android';
@@ -0,0 +1,2 @@
1
+ export { useBreakpoint } from './useBreakpoint';
2
+ export { useTheme } from './useTheme';
@@ -0,0 +1,14 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { UnistylesRuntime } from '../web';
3
+ import { UnistylesListener } from '../web/listener';
4
+ import { UnistyleDependency } from '../specs/NativePlatform';
5
+ export const useBreakpoint = () => {
6
+ const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
7
+ useEffect(() => {
8
+ const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Breakpoints], () => setBreakpoint(UnistylesRuntime.breakpoint));
9
+ return () => {
10
+ removeChangeListener();
11
+ };
12
+ }, []);
13
+ return breakpoint;
14
+ };
@@ -0,0 +1,16 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
3
+ export const useBreakpoint = () => {
4
+ const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
5
+ useEffect(() => {
6
+ const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
7
+ if (dependencies.includes(UnistyleDependency.Breakpoints)) {
8
+ setBreakpoint(UnistylesRuntime.breakpoint);
9
+ }
10
+ });
11
+ return () => {
12
+ removeChangeListener();
13
+ };
14
+ }, []);
15
+ return breakpoint;
16
+ };
@@ -0,0 +1,14 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { UnistylesRuntime } from '../web';
3
+ import { UnistylesListener } from '../web/listener';
4
+ import { UnistyleDependency } from '../specs/NativePlatform';
5
+ export const useTheme = () => {
6
+ const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
7
+ useEffect(() => {
8
+ const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Theme], () => setTheme(UnistylesRuntime.getTheme()));
9
+ return () => {
10
+ removeChangeListener();
11
+ };
12
+ }, []);
13
+ return theme;
14
+ };
@@ -0,0 +1,16 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
3
+ export const useTheme = () => {
4
+ const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
5
+ useEffect(() => {
6
+ const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
7
+ if (dependencies.includes(UnistyleDependency.Theme)) {
8
+ setTheme(UnistylesRuntime.getTheme());
9
+ }
10
+ });
11
+ return () => {
12
+ removeChangeListener();
13
+ };
14
+ }, []);
15
+ return theme;
16
+ };
package/src/global.ts CHANGED
@@ -1,7 +1,4 @@
1
- export interface UnistylesThemes {
2
- light: {}
3
- dark: {}
4
- }
1
+ export interface UnistylesThemes {}
5
2
  export interface UnistylesBreakpoints {
6
3
  // these breakpoints are only available on mobile, when you didn't specify any breakpoints
7
4
  landscape?: number,
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './specs';
2
+ export { mq } from './mq';
3
+ export { useTheme, useBreakpoint } from './core';
package/src/mq.js ADDED
@@ -0,0 +1,38 @@
1
+ const getMQValue = (value) => {
2
+ if (typeof value === 'number') {
3
+ return value;
4
+ }
5
+ if (value === null) {
6
+ return 0;
7
+ }
8
+ // todo take it from js
9
+ const breakpoints = {
10
+ xs: 0,
11
+ sm: 300,
12
+ md: 500,
13
+ lg: 800,
14
+ xl: 1200
15
+ };
16
+ // @ts-ignore
17
+ return breakpoints[value] ?? 0;
18
+ };
19
+ /**
20
+ * Utility to create cross-platform media queries
21
+ * @returns - JavaScript symbol to be used in your stylesheet
22
+ */
23
+ export const mq = {
24
+ only: {
25
+ width: (wMin = 0, wMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]`,
26
+ height: (hMin = 0, hMax = Infinity) => `:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
27
+ },
28
+ width: (wMin = 0, wMax = Infinity) => ({
29
+ and: {
30
+ height: (hMin = 0, hMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
31
+ }
32
+ }),
33
+ height: (hMin = 0, hMax = Infinity) => ({
34
+ and: {
35
+ width: (wMin = 0, wMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
36
+ }
37
+ })
38
+ };
@@ -0,0 +1,18 @@
1
+ import {} from '../types';
2
+ export var UnistyleDependency;
3
+ (function (UnistyleDependency) {
4
+ UnistyleDependency[UnistyleDependency["Theme"] = 0] = "Theme";
5
+ UnistyleDependency[UnistyleDependency["ThemeName"] = 1] = "ThemeName";
6
+ UnistyleDependency[UnistyleDependency["AdaptiveThemes"] = 2] = "AdaptiveThemes";
7
+ UnistyleDependency[UnistyleDependency["Breakpoints"] = 3] = "Breakpoints";
8
+ UnistyleDependency[UnistyleDependency["Variants"] = 4] = "Variants";
9
+ UnistyleDependency[UnistyleDependency["ColorScheme"] = 5] = "ColorScheme";
10
+ UnistyleDependency[UnistyleDependency["Dimensions"] = 6] = "Dimensions";
11
+ UnistyleDependency[UnistyleDependency["Orientation"] = 7] = "Orientation";
12
+ UnistyleDependency[UnistyleDependency["ContentSizeCategory"] = 8] = "ContentSizeCategory";
13
+ UnistyleDependency[UnistyleDependency["Insets"] = 9] = "Insets";
14
+ UnistyleDependency[UnistyleDependency["PixelRatio"] = 10] = "PixelRatio";
15
+ UnistyleDependency[UnistyleDependency["FontScale"] = 11] = "FontScale";
16
+ UnistyleDependency[UnistyleDependency["StatusBar"] = 12] = "StatusBar";
17
+ UnistyleDependency[UnistyleDependency["NavigationBar"] = 13] = "NavigationBar";
18
+ })(UnistyleDependency || (UnistyleDependency = {}));
@@ -0,0 +1 @@
1
+ export { UnistyleDependency } from './NativePlatform.nitro';
@@ -0,0 +1,9 @@
1
+ import { processColor } from 'react-native';
2
+ export const attachNavigationBarJSMethods = (hybridObject) => {
3
+ const privateHybrid = hybridObject;
4
+ privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor;
5
+ hybridObject.setBackgroundColor = (color) => {
6
+ const parsedColor = processColor(color) ?? 0;
7
+ privateHybrid._setBackgroundColor(parsedColor);
8
+ };
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ const HybridShadowRegistry = NitroModules.createHybridObject('UnistylesShadowRegistry');
3
+ const findShadowNodeForHandle = (handle) => {
4
+ const node = handle?.__internalInstanceHandle?.stateNode?.node
5
+ ?? handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node
6
+ ?? handle?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node;
7
+ if (!node) {
8
+ // todo extend log with file name / component name
9
+ throw new Error('Could not find shadow node for one of your components');
10
+ }
11
+ return node;
12
+ };
13
+ HybridShadowRegistry.add = (handle, style, variants, args) => {
14
+ // virtualized nodes can be null
15
+ if (!handle || !style) {
16
+ return;
17
+ }
18
+ HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
19
+ };
20
+ HybridShadowRegistry.remove = handle => {
21
+ if (!handle) {
22
+ return;
23
+ }
24
+ HybridShadowRegistry.unlink(findShadowNodeForHandle(handle));
25
+ };
26
+ export const UnistylesShadowRegistry = HybridShadowRegistry;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import { processColor, StatusBar as NativeStatusBar } from 'react-native';
2
+ import { StatusBarStyle } from '../types';
3
+ export const attachStatusBarJSMethods = (hybridObject) => {
4
+ hybridObject.setStyle = (style, animated) => {
5
+ switch (style) {
6
+ case StatusBarStyle.Light:
7
+ return NativeStatusBar.setBarStyle('light-content', animated);
8
+ case StatusBarStyle.Dark:
9
+ return NativeStatusBar.setBarStyle('dark-content', animated);
10
+ case StatusBarStyle.Default:
11
+ return NativeStatusBar.setBarStyle('default', animated);
12
+ }
13
+ };
14
+ const privateHybrid = hybridObject;
15
+ privateHybrid._setHidden = hybridObject.setHidden;
16
+ hybridObject.setHidden = (isHidden, animation) => {
17
+ NativeStatusBar.setHidden(isHidden, animation);
18
+ privateHybrid._setHidden(isHidden);
19
+ };
20
+ privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor;
21
+ hybridObject.setBackgroundColor = (color) => {
22
+ const parsedColor = processColor(color) ?? 0;
23
+ privateHybrid._setBackgroundColor(parsedColor);
24
+ };
25
+ };
@@ -0,0 +1 @@
1
+ import { UnistyleDependency } from '../NativePlatform';
@@ -0,0 +1,13 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import { processColor, StyleSheet as NativeStyleSheet } from 'react-native';
3
+ const HybridUnistylesStyleSheet = NitroModules
4
+ .createHybridObject('UnistylesStyleSheet');
5
+ HybridUnistylesStyleSheet.absoluteFillObject = NativeStyleSheet.absoluteFillObject;
6
+ HybridUnistylesStyleSheet.absoluteFill = NativeStyleSheet.absoluteFill;
7
+ HybridUnistylesStyleSheet.flatten = NativeStyleSheet.flatten;
8
+ HybridUnistylesStyleSheet.compose = NativeStyleSheet.compose;
9
+ HybridUnistylesStyleSheet.jsMethods = {
10
+ processColor
11
+ };
12
+ HybridUnistylesStyleSheet.init();
13
+ export const StyleSheet = HybridUnistylesStyleSheet;
@@ -0,0 +1,2 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ TurboModuleRegistry.get('Unistyles');
@@ -0,0 +1 @@
1
+ import './NativeTurboUnistyles';
@@ -0,0 +1,20 @@
1
+ import { processColor } from 'react-native';
2
+ import { NitroModules } from 'react-native-nitro-modules';
3
+ import { attachStatusBarJSMethods } from '../StatusBar';
4
+ import { attachNavigationBarJSMethods } from '../NavigtionBar';
5
+ import { isIOS } from '../../common';
6
+ const HybridUnistylesRuntime = NitroModules
7
+ .createHybridObject('UnistylesRuntime');
8
+ HybridUnistylesRuntime.statusBar = HybridUnistylesRuntime.createHybridStatusBar();
9
+ HybridUnistylesRuntime.navigationBar = HybridUnistylesRuntime.createHybridNavigationBar();
10
+ HybridUnistylesRuntime._setRootViewBackgroundColor = HybridUnistylesRuntime.setRootViewBackgroundColor;
11
+ HybridUnistylesRuntime.setRootViewBackgroundColor = (color) => {
12
+ const parsedColor = processColor(color) ?? 0;
13
+ HybridUnistylesRuntime._setRootViewBackgroundColor(parsedColor);
14
+ };
15
+ if (isIOS) {
16
+ HybridUnistylesRuntime.setImmersiveMode = (isEnabled) => HybridUnistylesRuntime.statusBar.setHidden(isEnabled, 'fade');
17
+ }
18
+ attachStatusBarJSMethods(HybridUnistylesRuntime.statusBar);
19
+ attachNavigationBarJSMethods(HybridUnistylesRuntime.navigationBar);
20
+ export const Runtime = HybridUnistylesRuntime;
@@ -0,0 +1,8 @@
1
+ import './TurboUnistyles';
2
+ import { Runtime } from './UnistylesRuntime';
3
+ import { StyleSheet } from './StyleSheet';
4
+ import { UnistylesShadowRegistry } from './ShadowRegistry';
5
+ import { StatusBarStyle, ColorScheme, Orientation } from './types';
6
+ import { UnistyleDependency } from './NativePlatform';
7
+ export { StatusBarStyle, ColorScheme, Orientation, UnistyleDependency };
8
+ export { UnistylesShadowRegistry, Runtime as UnistylesRuntime, StyleSheet, };
@@ -0,0 +1,2 @@
1
+ export const getSSRUnistyles = () => [];
2
+ export * from '../web';
@@ -0,0 +1,17 @@
1
+ export var ColorScheme;
2
+ (function (ColorScheme) {
3
+ ColorScheme["Light"] = "light";
4
+ ColorScheme["Dark"] = "dark";
5
+ ColorScheme["Unspecified"] = "unspecified";
6
+ })(ColorScheme || (ColorScheme = {}));
7
+ export var Orientation;
8
+ (function (Orientation) {
9
+ Orientation["Portrait"] = "portrait";
10
+ Orientation["Landscape"] = "landscape";
11
+ })(Orientation || (Orientation = {}));
12
+ export var StatusBarStyle;
13
+ (function (StatusBarStyle) {
14
+ StatusBarStyle["Default"] = "default";
15
+ StatusBarStyle["Light"] = "light";
16
+ StatusBarStyle["Dark"] = "dark";
17
+ })(StatusBarStyle || (StatusBarStyle = {}));
@@ -1,4 +1,4 @@
1
- import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
1
+ import type { BoxShadowValue, ImageStyle, TextStyle, ViewStyle, FilterFunction } from 'react-native'
2
2
  import type { ShadowOffset, TransformStyles, UnistylesTheme } from './core'
3
3
  import type { UnistylesBreakpoints } from '../global'
4
4
  import type { UnistylesMiniRuntime } from '../specs'
@@ -8,7 +8,7 @@ import type { CSSProperties } from 'react'
8
8
  import type { Pseudo } from '../web/convert/pseudo'
9
9
 
10
10
  // these props are treated differently to nest breakpoints and media queries
11
- type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
11
+ type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset' | 'boxShadow' | 'filter'
12
12
 
13
13
  export type UnistyleView = Omit<ViewStyle, NestedKeys>
14
14
  export type UnistyleText = Omit<TextStyle, NestedKeys>
@@ -17,7 +17,9 @@ export type UnistyleImage = Omit<ImageStyle, NestedKeys>
17
17
  type UnistyleNestedStyles = {
18
18
  shadowOffset?: ToDeepUnistyles<ShadowOffset>,
19
19
  textShadowOffset?: ToDeepUnistyles<ShadowOffset>,
20
- transform?: Array<ToDeepUnistyles<TransformStyles>>
20
+ transform?: Array<ToDeepUnistyles<TransformStyles>>,
21
+ boxShadow?: Array<ToDeepUnistyles<BoxShadowValue>> | string,
22
+ filter?: Array<ToDeepUnistyles<FilterFunction>> | string
21
23
  }
22
24
 
23
25
  type VariantsObject = {
@@ -0,0 +1,59 @@
1
+ import { deepMergeObjects, warn } from '../utils';
2
+ import { validateShadow } from './shadow';
3
+ import { BOX_SHADOW_STYLES } from './types';
4
+ import { extractShadowValue, normalizeColor, normalizeNumericValue } from './utils';
5
+ const createBoxShadowValue = (style) => {
6
+ // at this point every prop is present
7
+ const { shadowColor, shadowOffset, shadowOpacity, shadowRadius } = style;
8
+ const offsetX = normalizeNumericValue(shadowOffset.width);
9
+ const offsetY = normalizeNumericValue(shadowOffset.height);
10
+ const radius = normalizeNumericValue(shadowRadius);
11
+ const color = normalizeColor(shadowColor, shadowOpacity);
12
+ return `${offsetX} ${offsetY} ${radius} ${color}`;
13
+ };
14
+ export const getBoxShadowStyle = (styles) => {
15
+ const missingStyles = BOX_SHADOW_STYLES.filter(key => !(key in styles));
16
+ if (missingStyles.length) {
17
+ warn(`can't apply box shadow as you miss these properties: ${missingStyles.join(', ')}`);
18
+ return {};
19
+ }
20
+ const breakpointsSet = new Set();
21
+ try {
22
+ validateShadow(BOX_SHADOW_STYLES, styles, breakpointsSet);
23
+ }
24
+ catch (error) {
25
+ if (typeof error === 'string') {
26
+ warn(error);
27
+ }
28
+ return {};
29
+ }
30
+ const breakpoints = Array.from(breakpointsSet);
31
+ // If no breakpoints were used return styles without media queries
32
+ if (breakpoints.length === 0) {
33
+ return {
34
+ boxShadow: createBoxShadowValue(styles)
35
+ };
36
+ }
37
+ // Create boxShadow for each breakpoint
38
+ const breakpointStyles = breakpoints.map(breakpoint => {
39
+ const color = extractShadowValue('shadowColor', breakpoint, styles);
40
+ const { width, height } = extractShadowValue('shadowOffset', breakpoint, styles);
41
+ const radius = extractShadowValue('shadowRadius', breakpoint, styles);
42
+ const opacity = extractShadowValue('shadowOpacity', breakpoint, styles);
43
+ return {
44
+ [breakpoint]: {
45
+ boxShadow: createBoxShadowValue({
46
+ shadowColor: color,
47
+ shadowOffset: {
48
+ width,
49
+ height
50
+ },
51
+ shadowRadius: radius,
52
+ shadowOpacity: opacity
53
+ })
54
+ }
55
+ };
56
+ });
57
+ // Merge all breakpoints styles into one
58
+ return deepMergeObjects(...breakpointStyles);
59
+ };
@@ -0,0 +1,56 @@
1
+ import { isPseudo } from './pseudo';
2
+ import { getStyle } from './style';
3
+ import { deepMergeObjects } from '../utils';
4
+ import { getTransformStyle } from './transform';
5
+ import { isBoxShadow, isTextShadow, isTransform } from './utils';
6
+ import { getTextShadowStyle } from './textShadow';
7
+ import { getBoxShadowStyle } from './boxShadow';
8
+ export const convertUnistyles = (value) => {
9
+ // Flag to mark if textShadow is already created
10
+ let hasTextShadow = false;
11
+ // Flag to mark if boxShadow is already created
12
+ let hasBoxShadow = false;
13
+ const stylesArray = Object.entries({
14
+ ...value,
15
+ ...value._web
16
+ }).flatMap(([unistylesKey, unistylesValue]) => {
17
+ // Keys to omit
18
+ if (['_classNames', '_web', 'variants', 'compoundVariants', 'uni__dependencies', '__unistyles-secrets__'].includes(unistylesKey) || unistylesKey.startsWith('variant-')) {
19
+ return [];
20
+ }
21
+ // Pseudo classes :hover, :before etc.
22
+ if (isPseudo(unistylesKey)) {
23
+ const flattenValues = convertUnistyles(unistylesValue);
24
+ return { [unistylesKey]: flattenValues };
25
+ }
26
+ // Text shadow
27
+ if (isTextShadow(unistylesKey)) {
28
+ if (hasTextShadow) {
29
+ return [];
30
+ }
31
+ hasTextShadow = true;
32
+ return getTextShadowStyle(value);
33
+ }
34
+ // Box shadow
35
+ if (isBoxShadow(unistylesKey)) {
36
+ if (hasBoxShadow) {
37
+ return [];
38
+ }
39
+ hasBoxShadow = true;
40
+ return getBoxShadowStyle(value);
41
+ }
42
+ // Transforms
43
+ if (isTransform(unistylesKey, unistylesValue)) {
44
+ return getTransformStyle(unistylesValue);
45
+ }
46
+ // Breakpoints
47
+ if (typeof unistylesValue === 'object' && unistylesValue !== null) {
48
+ return Object.entries(unistylesValue).map(([breakpointKey, breakpointValue]) => {
49
+ return { [breakpointKey]: getStyle(unistylesKey, breakpointValue) };
50
+ });
51
+ }
52
+ // Regular styles
53
+ return getStyle(unistylesKey, unistylesValue);
54
+ });
55
+ return deepMergeObjects(...stylesArray);
56
+ };
@@ -0,0 +1,131 @@
1
+ export const pseudos = [
2
+ '_-moz-broken',
3
+ '_-moz-drag-over',
4
+ '_-moz-first-node',
5
+ '_-moz-handler-blocked',
6
+ '_-moz-handler-crashed',
7
+ '_-moz-handler-disabled',
8
+ '_-moz-last-node',
9
+ '_-moz-loading',
10
+ '_-moz-locale-dir(ltr)',
11
+ '_-moz-locale-dir(rtl)',
12
+ '_-moz-only-whitespace',
13
+ '_-moz-submit-invalid',
14
+ '_-moz-suppressed',
15
+ '_-moz-user-disabled',
16
+ '_-moz-window-inactive',
17
+ '_active',
18
+ '_any-link',
19
+ '_autofill',
20
+ '_blank',
21
+ '_buffering',
22
+ '_checked',
23
+ '_current',
24
+ '_default',
25
+ '_defined',
26
+ '_dir(',
27
+ '_disabled',
28
+ '_empty',
29
+ '_enabled',
30
+ '_first',
31
+ '_first-child',
32
+ '_first-of-type',
33
+ '_focus',
34
+ '_focus-visible',
35
+ '_focus-within',
36
+ '_fullscreen',
37
+ '_future',
38
+ '_has(',
39
+ '_host',
40
+ '_host-context(',
41
+ '_host(',
42
+ '_hover',
43
+ '_in-range',
44
+ '_indeterminate',
45
+ '_invalid',
46
+ '_is(',
47
+ '_lang(',
48
+ '_last-child',
49
+ '_last-of-type',
50
+ '_left',
51
+ '_link',
52
+ '_local-link',
53
+ '_modal',
54
+ '_muted',
55
+ '_not(',
56
+ '_nth-child(',
57
+ '_nth-last-child(',
58
+ '_nth-last-of-type(',
59
+ '_nth-of-type(',
60
+ '_only-child',
61
+ '_only-of-type',
62
+ '_optional',
63
+ '_out-of-range',
64
+ '_past',
65
+ '_paused',
66
+ '_picture-in-picture',
67
+ '_placeholder-shown',
68
+ '_playing',
69
+ '_popover-open',
70
+ '_read-only',
71
+ '_read-write',
72
+ '_required',
73
+ '_right',
74
+ '_scope',
75
+ '_seeking',
76
+ '_stalled',
77
+ '_state(',
78
+ '_target',
79
+ '_target-within',
80
+ '_user-invalid',
81
+ '_user-valid',
82
+ '_valid',
83
+ '_visited',
84
+ '_volume-locked',
85
+ '_where(',
86
+ '_-moz-color-swatch',
87
+ '_-moz-focus-inner',
88
+ '_-moz-list-bullet',
89
+ '_-moz-list-number',
90
+ '_-moz-meter-bar',
91
+ '_-moz-progress-bar',
92
+ '_-moz-range-progress',
93
+ '_-moz-range-thumb',
94
+ '_-moz-range-track',
95
+ '_-webkit-inner-spin-button',
96
+ '_-webkit-meter-barDeprecated',
97
+ '_-webkit-meter-even-less-good-value',
98
+ '_-webkit-meter-inner-element',
99
+ '_-webkit-meter-optimum-value',
100
+ '_-webkit-meter-suboptimum-value',
101
+ '_-webkit-progress-bar',
102
+ '_-webkit-progress-inner-element',
103
+ '_-webkit-progress-value',
104
+ '_-webkit-scrollbar',
105
+ '_-webkit-search-cancel-button',
106
+ '_-webkit-search-results-button',
107
+ '_-webkit-slider-runnable-track',
108
+ '_-webkit-slider-thumb',
109
+ '_after',
110
+ '_backdrop',
111
+ '_before',
112
+ '_cue',
113
+ '_file-selector-button',
114
+ '_first-letter',
115
+ '_first-line',
116
+ '_grammar-error',
117
+ '_highlight(',
118
+ '_marker',
119
+ '_part(',
120
+ '_placeholder',
121
+ '_selection',
122
+ '_slotted(',
123
+ '_spelling-error',
124
+ '_target-text',
125
+ '_view-transition',
126
+ '_view-transition-group',
127
+ '_view-transition-image-pair',
128
+ '_view-transition-new',
129
+ '_view-transition-old',
130
+ ];
131
+ export const isPseudo = (selector) => pseudos.some(pseudo => selector.startsWith(pseudo));
@@ -0,0 +1,50 @@
1
+ export const validateShadow = (shadowProperties, styles, breakpoints) => {
2
+ // Collect breakpoints
3
+ shadowProperties.forEach(key => {
4
+ const value = styles[key];
5
+ if (typeof value !== 'object') {
6
+ return;
7
+ }
8
+ if (key === 'shadowOffset' || key === 'textShadowOffset') {
9
+ const { width, height } = value;
10
+ // If shadowOffset.width has breakpoints
11
+ if (typeof width === 'object') {
12
+ Object.keys(width).forEach(breakpoint => breakpoints.add(breakpoint));
13
+ }
14
+ // If shadowOffset.height has breakpoints
15
+ if (typeof height === 'object') {
16
+ Object.keys(height).forEach(breakpoint => breakpoints.add(breakpoint));
17
+ }
18
+ return;
19
+ }
20
+ // Collect regular breakpoints
21
+ Object.keys(value).forEach(breakpoint => breakpoints.add(breakpoint));
22
+ });
23
+ // Validate if all breakpoints are present
24
+ shadowProperties.forEach(key => {
25
+ const value = styles[key];
26
+ if (typeof value !== 'object') {
27
+ return;
28
+ }
29
+ if (key === 'shadowOffset' || key === 'textShadowOffset') {
30
+ const { width, height } = value;
31
+ if (typeof width === 'object') {
32
+ const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in width));
33
+ if (missingBreakpoints.length) {
34
+ throw `missing breakpoints in ${key}.width: ${missingBreakpoints.join(', ')}`;
35
+ }
36
+ }
37
+ if (typeof height === 'object') {
38
+ const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in height));
39
+ if (missingBreakpoints.length) {
40
+ throw `missing breakpoints in ${key}.height: ${missingBreakpoints.join(', ')}`;
41
+ }
42
+ }
43
+ return;
44
+ }
45
+ const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in value));
46
+ if (missingBreakpoints.length) {
47
+ throw `missing breakpoints in ${key}: ${missingBreakpoints.join(', ')}`;
48
+ }
49
+ });
50
+ };