react-native-unistyles 3.0.0-alpha.33 → 3.0.0-alpha.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. package/cxx/common/Helpers.h +24 -2
  2. package/cxx/core/HostStyle.cpp +1 -1
  3. package/cxx/core/UnistyleWrapper.h +31 -1
  4. package/cxx/core/UnistylesMountHook.cpp +1 -1
  5. package/cxx/core/UnistylesMountHook.h +4 -2
  6. package/cxx/core/UnistylesRegistry.cpp +7 -1
  7. package/cxx/hybridObjects/HybridShadowRegistry.cpp +1 -2
  8. package/cxx/hybridObjects/HybridShadowRegistry.h +1 -3
  9. package/cxx/hybridObjects/HybridStyleSheet.cpp +4 -1
  10. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +12 -0
  11. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  12. package/cxx/parser/Parser.cpp +6 -6
  13. package/cxx/parser/Parser.h +1 -1
  14. package/cxx/shadowTree/ShadowTrafficController.h +2 -0
  15. package/lib/commonjs/components/Display.js +18 -0
  16. package/lib/commonjs/components/Display.js.map +1 -0
  17. package/lib/commonjs/components/Hide.js +18 -0
  18. package/lib/commonjs/components/Hide.js.map +1 -0
  19. package/lib/commonjs/components/index.js +20 -0
  20. package/lib/commonjs/components/index.js.map +1 -0
  21. package/lib/commonjs/components/useMedia.js +59 -0
  22. package/lib/commonjs/components/useMedia.js.map +1 -0
  23. package/lib/commonjs/core/createUnistylesComponent.js +2 -1
  24. package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
  25. package/lib/commonjs/core/createUnistylesComponent.native.js +40 -2
  26. package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -1
  27. package/lib/commonjs/core/index.js +0 -14
  28. package/lib/commonjs/core/index.js.map +1 -1
  29. package/lib/commonjs/global.js +0 -4
  30. package/lib/commonjs/global.js.map +1 -1
  31. package/lib/commonjs/index.js +12 -14
  32. package/lib/commonjs/index.js.map +1 -1
  33. package/lib/commonjs/mq.js +27 -11
  34. package/lib/commonjs/mq.js.map +1 -2
  35. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +0 -1
  36. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -2
  37. package/lib/commonjs/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -1
  38. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -2
  39. package/lib/commonjs/specs/ShadowRegistry/types.js +0 -4
  40. package/lib/commonjs/specs/ShadowRegistry/types.js.map +1 -1
  41. package/lib/commonjs/specs/StatusBar/index.js.map +1 -2
  42. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js +4 -2
  43. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -1
  44. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +3 -1
  45. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -2
  46. package/lib/commonjs/specs/TurboUnistyles/index.js.map +1 -1
  47. package/lib/commonjs/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +1 -1
  48. package/lib/commonjs/specs/index.web.js.map +1 -2
  49. package/lib/commonjs/specs/types.js +10 -10
  50. package/lib/commonjs/specs/types.js.map +1 -1
  51. package/lib/commonjs/types/accessibility.js +9 -9
  52. package/lib/commonjs/types/accessibility.js.map +1 -1
  53. package/lib/commonjs/types/breakpoints.js.map +1 -1
  54. package/lib/commonjs/types/common.js +0 -4
  55. package/lib/commonjs/types/common.js.map +1 -1
  56. package/lib/commonjs/types/core.js.map +1 -1
  57. package/lib/commonjs/types/index.js.map +1 -2
  58. package/lib/commonjs/types/stylesheet.js +2 -1
  59. package/lib/commonjs/types/stylesheet.js.map +1 -2
  60. package/lib/commonjs/web/convert/index.js +7 -1
  61. package/lib/commonjs/web/convert/index.js.map +1 -2
  62. package/lib/commonjs/web/convert/pseudo.js.map +1 -2
  63. package/lib/commonjs/web/convert/shadow.js +5 -1
  64. package/lib/commonjs/web/convert/shadow.js.map +1 -2
  65. package/lib/commonjs/web/convert/style.js.map +1 -2
  66. package/lib/commonjs/web/convert/textShadow.js.map +1 -2
  67. package/lib/commonjs/web/convert/transform.js.map +1 -2
  68. package/lib/commonjs/web/convert/types.js.map +1 -1
  69. package/lib/commonjs/web/convert/utils.js +2 -1
  70. package/lib/commonjs/web/convert/utils.js.map +1 -2
  71. package/lib/commonjs/web/index.js.map +1 -2
  72. package/lib/commonjs/web/listener.js.map +1 -2
  73. package/lib/commonjs/web/mock.js.map +1 -2
  74. package/lib/commonjs/web/runtime.js.map +1 -2
  75. package/lib/commonjs/web/shadowRegistry.js +9 -1
  76. package/lib/commonjs/web/shadowRegistry.js.map +1 -2
  77. package/lib/commonjs/web/state.js +5 -1
  78. package/lib/commonjs/web/utils/common.js +3 -1
  79. package/lib/commonjs/web/utils/common.js.map +1 -2
  80. package/lib/commonjs/web/utils/index.js.map +1 -1
  81. package/lib/commonjs/web/utils/unistyle.js +1 -1
  82. package/lib/commonjs/web/variants/index.js.map +1 -1
  83. package/lib/module/common.js.map +1 -1
  84. package/lib/module/components/Display.js +13 -0
  85. package/lib/module/components/Display.js.map +1 -0
  86. package/lib/module/components/Hide.js +13 -0
  87. package/lib/module/components/Hide.js.map +1 -0
  88. package/lib/module/components/index.js +5 -0
  89. package/lib/module/components/index.js.map +1 -0
  90. package/lib/module/components/useMedia.js +54 -0
  91. package/lib/module/components/useMedia.js.map +1 -0
  92. package/lib/module/core/createUnistylesComponent.js +2 -1
  93. package/lib/module/core/createUnistylesComponent.js.map +1 -1
  94. package/lib/module/core/createUnistylesComponent.native.js +41 -3
  95. package/lib/module/core/createUnistylesComponent.native.js.map +1 -1
  96. package/lib/module/core/index.js +0 -2
  97. package/lib/module/core/index.js.map +1 -1
  98. package/lib/module/global.js +1 -1
  99. package/lib/module/global.js.map +0 -1
  100. package/lib/module/index.js +2 -1
  101. package/lib/module/index.js.map +1 -1
  102. package/lib/module/mq.js +21 -11
  103. package/lib/module/mq.js.map +1 -1
  104. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +0 -1
  105. package/lib/module/specs/NativePlatform/index.js.map +1 -1
  106. package/lib/module/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +0 -1
  107. package/lib/module/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +0 -1
  108. package/lib/module/specs/ShadowRegistry/types.js +0 -2
  109. package/lib/module/specs/ShadowRegistry/types.js.map +1 -1
  110. package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -1
  111. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -1
  112. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +0 -1
  113. package/lib/module/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +0 -1
  114. package/lib/module/specs/index.web.js.map +1 -2
  115. package/lib/module/specs/types.js.map +0 -1
  116. package/lib/module/types/accessibility.js +1 -1
  117. package/lib/module/types/accessibility.js.map +0 -1
  118. package/lib/module/types/breakpoints.js.map +0 -1
  119. package/lib/module/types/common.js +1 -1
  120. package/lib/module/types/common.js.map +0 -1
  121. package/lib/module/types/core.js.map +0 -1
  122. package/lib/module/types/index.js.map +1 -2
  123. package/lib/module/types/stylesheet.js +2 -2
  124. package/lib/module/types/stylesheet.js.map +1 -2
  125. package/lib/module/types/variants.js.map +0 -1
  126. package/lib/module/web/convert/boxShadow.js +4 -1
  127. package/lib/module/web/convert/boxShadow.js.map +1 -2
  128. package/lib/module/web/convert/index.js +7 -1
  129. package/lib/module/web/convert/shadow.js +5 -1
  130. package/lib/module/web/convert/shadow.js.map +1 -2
  131. package/lib/module/web/convert/textShadow.js +4 -1
  132. package/lib/module/web/convert/utils.js +2 -1
  133. package/lib/module/web/convert/utils.js.map +1 -2
  134. package/lib/module/web/create.js +5 -1
  135. package/lib/module/web/create.js.map +1 -2
  136. package/lib/module/web/index.js +2 -1
  137. package/lib/module/web/index.js.map +1 -2
  138. package/lib/module/web/listener.js.map +1 -2
  139. package/lib/module/web/registry.js +3 -1
  140. package/lib/module/web/shadowRegistry.js +9 -1
  141. package/lib/module/web/shadowRegistry.js.map +1 -2
  142. package/lib/module/web/state.js +5 -1
  143. package/lib/module/web/state.js.map +1 -2
  144. package/lib/module/web/utils/common.js +3 -1
  145. package/lib/module/web/utils/common.js.map +1 -2
  146. package/lib/module/web/utils/unistyle.js +1 -1
  147. package/lib/module/web/utils/unistyle.js.map +1 -1
  148. package/lib/module/web/variants/getVariants.js.map +1 -2
  149. package/lib/module/web/variants/index.js.map +1 -1
  150. package/lib/typescript/src/components/Display.d.ts +7 -0
  151. package/lib/typescript/src/components/Display.d.ts.map +1 -0
  152. package/lib/typescript/src/components/Hide.d.ts +7 -0
  153. package/lib/typescript/src/components/Hide.d.ts.map +1 -0
  154. package/lib/typescript/src/components/index.d.ts +3 -0
  155. package/lib/typescript/src/components/index.d.ts.map +1 -0
  156. package/lib/typescript/src/components/useMedia.d.ts +6 -0
  157. package/lib/typescript/src/components/useMedia.d.ts.map +1 -0
  158. package/lib/typescript/src/core/createUnistylesComponent.d.ts +3 -2
  159. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
  160. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +3 -2
  161. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -1
  162. package/lib/typescript/src/core/index.d.ts +0 -2
  163. package/lib/typescript/src/core/index.d.ts.map +1 -1
  164. package/lib/typescript/src/index.d.ts +2 -1
  165. package/lib/typescript/src/index.d.ts.map +1 -1
  166. package/lib/typescript/src/mq.d.ts +8 -0
  167. package/lib/typescript/src/mq.d.ts.map +1 -1
  168. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +1 -0
  169. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  170. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -0
  171. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
  172. package/package.json +1 -1
  173. package/plugin/ref.js +4 -4
  174. package/plugin/style.js +15 -3
  175. package/src/components/Display.tsx +12 -0
  176. package/src/components/Hide.tsx +12 -0
  177. package/src/components/index.ts +2 -0
  178. package/src/components/useMedia.ts +64 -0
  179. package/src/core/createUnistylesComponent.native.tsx +48 -4
  180. package/src/core/createUnistylesComponent.tsx +4 -2
  181. package/src/core/index.ts +0 -2
  182. package/src/index.ts +2 -1
  183. package/src/mq.ts +27 -9
  184. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -0
  185. package/src/web/utils/unistyle.ts +1 -1
  186. package/lib/commonjs/core/useBreakpoint.js +0 -22
  187. package/lib/commonjs/core/useBreakpoint.js.map +0 -1
  188. package/lib/commonjs/core/useBreakpoint.native.js +0 -24
  189. package/lib/commonjs/core/useBreakpoint.native.js.map +0 -1
  190. package/lib/commonjs/core/useTheme.js +0 -22
  191. package/lib/commonjs/core/useTheme.js.map +0 -2
  192. package/lib/commonjs/core/useTheme.native.js +0 -24
  193. package/lib/commonjs/core/useTheme.native.js.map +0 -1
  194. package/lib/commonjs/web/mq.js +0 -23
  195. package/lib/commonjs/web/mq.js.map +0 -1
  196. package/lib/module/core/useBreakpoint.js +0 -17
  197. package/lib/module/core/useBreakpoint.js.map +0 -1
  198. package/lib/module/core/useBreakpoint.native.js +0 -19
  199. package/lib/module/core/useBreakpoint.native.js.map +0 -2
  200. package/lib/module/core/useTheme.js +0 -17
  201. package/lib/module/core/useTheme.js.map +0 -2
  202. package/lib/module/core/useTheme.native.js +0 -19
  203. package/lib/module/core/useTheme.native.js.map +0 -1
  204. package/lib/module/web/mq.js +0 -17
  205. package/lib/module/web/mq.js.map +0 -1
  206. package/lib/typescript/src/core/useBreakpoint.d.ts +0 -2
  207. package/lib/typescript/src/core/useBreakpoint.d.ts.map +0 -1
  208. package/lib/typescript/src/core/useBreakpoint.native.d.ts +0 -2
  209. package/lib/typescript/src/core/useBreakpoint.native.d.ts.map +0 -1
  210. package/lib/typescript/src/core/useTheme.d.ts +0 -3
  211. package/lib/typescript/src/core/useTheme.d.ts.map +0 -1
  212. package/lib/typescript/src/core/useTheme.native.d.ts +0 -3
  213. package/lib/typescript/src/core/useTheme.native.d.ts.map +0 -1
  214. package/lib/typescript/src/web/mq.d.ts +0 -8
  215. package/lib/typescript/src/web/mq.d.ts.map +0 -1
  216. package/src/common.js +0 -4
  217. package/src/core/createUnistylesComponent.js +0 -6
  218. package/src/core/createUnistylesComponent.native.js +0 -31
  219. package/src/core/index.js +0 -3
  220. package/src/core/useBreakpoint.js +0 -14
  221. package/src/core/useBreakpoint.native.js +0 -16
  222. package/src/core/useBreakpoint.native.ts +0 -21
  223. package/src/core/useBreakpoint.ts +0 -18
  224. package/src/core/useTheme.js +0 -14
  225. package/src/core/useTheme.native.js +0 -16
  226. package/src/core/useTheme.native.ts +0 -22
  227. package/src/core/useTheme.ts +0 -19
  228. package/src/global.js +0 -1
  229. package/src/index.js +0 -3
  230. package/src/mq.js +0 -38
  231. package/src/specs/NativePlatform/NativePlatform.nitro.js +0 -19
  232. package/src/specs/NativePlatform/index.js +0 -1
  233. package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.js +0 -1
  234. package/src/specs/NavigtionBar/index.js +0 -9
  235. package/src/specs/ShadowRegistry/ShadowRegistry.nitro.js +0 -1
  236. package/src/specs/ShadowRegistry/index.js +0 -26
  237. package/src/specs/ShadowRegistry/types.js +0 -1
  238. package/src/specs/StatusBar/UnistylesStatusBar.nitro.js +0 -1
  239. package/src/specs/StatusBar/index.js +0 -25
  240. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.js +0 -1
  241. package/src/specs/StyleSheet/index.js +0 -13
  242. package/src/specs/TurboUnistyles/NativeTurboUnistyles.js +0 -2
  243. package/src/specs/TurboUnistyles/index.js +0 -1
  244. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.js +0 -1
  245. package/src/specs/UnistylesRuntime/index.js +0 -20
  246. package/src/specs/index.js +0 -8
  247. package/src/specs/index.web.js +0 -2
  248. package/src/specs/types.js +0 -17
  249. package/src/types/accessibility.js +0 -30
  250. package/src/types/breakpoints.js +0 -1
  251. package/src/types/common.js +0 -1
  252. package/src/types/core.js +0 -1
  253. package/src/types/index.js +0 -1
  254. package/src/types/stylesheet.js +0 -2
  255. package/src/types/variants.js +0 -1
  256. package/src/web/convert/boxShadow.js +0 -59
  257. package/src/web/convert/index.js +0 -56
  258. package/src/web/convert/pseudo.js +0 -131
  259. package/src/web/convert/shadow.js +0 -50
  260. package/src/web/convert/style.js +0 -137
  261. package/src/web/convert/textShadow.js +0 -56
  262. package/src/web/convert/transform.js +0 -65
  263. package/src/web/convert/types.js +0 -2
  264. package/src/web/convert/utils.js +0 -39
  265. package/src/web/create.js +0 -36
  266. package/src/web/index.js +0 -22
  267. package/src/web/listener.js +0 -26
  268. package/src/web/mock.js +0 -21
  269. package/src/web/mq.js +0 -14
  270. package/src/web/mq.ts +0 -17
  271. package/src/web/registry.js +0 -165
  272. package/src/web/runtime.js +0 -160
  273. package/src/web/shadowRegistry.js +0 -96
  274. package/src/web/state.js +0 -68
  275. package/src/web/utils/common.js +0 -79
  276. package/src/web/utils/index.js +0 -2
  277. package/src/web/utils/unistyle.js +0 -72
  278. package/src/web/variants/getVariants.js +0 -26
  279. package/src/web/variants/index.js +0 -2
  280. package/src/web/variants/useVariants.js +0 -50
@@ -1,79 +0,0 @@
1
- export const reduceObject = (obj, reducer) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, reducer(value, key)]));
2
- export const keyInObject = (obj, key) => key in obj;
3
- export const isServer = () => typeof window === 'undefined';
4
- /**
5
- * Deeply merges properties of passed object
6
- */
7
- export const deepMergeObjects = (...sources) => {
8
- const target = {};
9
- sources.forEach(source => {
10
- Object.keys(source).forEach(key => {
11
- const sourceValue = source[key];
12
- const targetValue = target[key];
13
- if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
14
- // @ts-expect-error - can't assign to generic
15
- target[key] = deepMergeObjects(targetValue, sourceValue);
16
- return;
17
- }
18
- // @ts-expect-error - can't assign to generic
19
- target[key] = sourceValue;
20
- });
21
- });
22
- return target;
23
- };
24
- export const warn = (message) => console.warn(`🦄 [react-native-unistyles] ${message}`);
25
- export const equal = (a, b) => {
26
- if (Object.is(a, b)) {
27
- return true;
28
- }
29
- if (typeof a !== 'object'
30
- || a === null
31
- || typeof b !== 'object'
32
- || b === null) {
33
- return false;
34
- }
35
- const keysA = Object.keys(a);
36
- if (keysA.length !== Object.keys(b).length) {
37
- return false;
38
- }
39
- return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key));
40
- };
41
- export const generateHash = (value) => {
42
- const str = JSON.stringify(value);
43
- let hasher = 5381;
44
- let length = str.length;
45
- while (length--)
46
- hasher = (hasher * 33) ^ str.charCodeAt(length);
47
- return `unistyles-${(hasher >>> 0).toString(36)}`;
48
- };
49
- export const createDoubleMap = () => {
50
- const map = new Map();
51
- return {
52
- get: (key, secondKey) => {
53
- const mapForKey = map.get(key);
54
- if (!mapForKey) {
55
- return undefined;
56
- }
57
- return mapForKey.get(secondKey);
58
- },
59
- set: (key, secondKey, value) => {
60
- const mapForKey = map.get(key) ?? new Map();
61
- map.set(key, mapForKey);
62
- mapForKey.set(secondKey, value);
63
- },
64
- delete: (key, secondKey) => {
65
- const mapForKey = map.get(key);
66
- if (!mapForKey) {
67
- return;
68
- }
69
- mapForKey.delete(secondKey);
70
- },
71
- forEach: (callback) => {
72
- map.forEach((mapForKey, key) => {
73
- mapForKey.forEach((value, secondKey) => {
74
- callback(key, secondKey, value);
75
- });
76
- });
77
- }
78
- };
79
- };
@@ -1,2 +0,0 @@
1
- export * from './common';
2
- export * from './unistyle';
@@ -1,72 +0,0 @@
1
- import { ColorScheme, Orientation } from '../../specs/types';
2
- import { isUnistylesMq, parseMq } from '../mq';
3
- import { UnistylesState } from '../state';
4
- import { keyInObject, reduceObject } from './common';
5
- export const schemeToTheme = (scheme) => {
6
- switch (scheme) {
7
- case ColorScheme.Dark:
8
- return 'dark';
9
- case ColorScheme.Light:
10
- default:
11
- return 'light';
12
- }
13
- };
14
- export const hexToRGBA = (hex, opacity) => hex
15
- .replace('#', '')
16
- .split(/(?=(?:..)*$)/)
17
- .map(x => parseInt(x, 16))
18
- .filter(num => !isNaN(num))
19
- .reduce((acc, color) => `${acc}${color},`, 'rgba(')
20
- .concat(`${opacity})`);
21
- export const assignSecrets = (object, secrets) => {
22
- // @ts-expect-error - assign secrets to object
23
- object[`__uni__secrets__${Math.random().toString(16).slice(2)}`] = secrets;
24
- return object;
25
- };
26
- export const extractSecrets = (object) => {
27
- const secrets = Object.entries(object).reduce((acc, [key, value]) => {
28
- if (key.startsWith('__uni__secrets__')) {
29
- acc.push(value);
30
- }
31
- return acc;
32
- }, []);
33
- return secrets;
34
- };
35
- export const getStyles = (values) => {
36
- const returnValue = {};
37
- Object.defineProperties(returnValue, reduceObject(values, value => ({
38
- value,
39
- enumerable: false,
40
- configurable: true
41
- })));
42
- return returnValue;
43
- };
44
- export const isInDocument = (element) => document.body.contains(element);
45
- export const extractMediaQueryValue = (query) => {
46
- const [_, px] = query.match(/(\d+)px/) ?? [];
47
- if (!px) {
48
- return undefined;
49
- }
50
- const value = Number(px);
51
- return isNaN(value) ? undefined : value;
52
- };
53
- export const getMediaQuery = (query) => {
54
- if (Object.values(Orientation).includes(query)) {
55
- return `(orientation: ${query})`;
56
- }
57
- if (isUnistylesMq(query)) {
58
- const { minWidth, maxWidth, minHeight, maxHeight } = parseMq(query);
59
- return [
60
- minWidth ? `(min-width: ${minWidth}px)` : undefined,
61
- maxWidth ? `(max-width: ${maxWidth}px)` : undefined,
62
- minHeight ? `(min-height: ${minHeight}px)` : undefined,
63
- maxHeight ? `(max-height: ${maxHeight}px)` : undefined
64
- ].filter(Boolean).join(' and ');
65
- }
66
- const minWidth = UnistylesState.breakpoints && keyInObject(UnistylesState.breakpoints, query) ? UnistylesState.breakpoints[query] : undefined;
67
- return `(min-width: ${minWidth ?? 0}px)`;
68
- };
69
- export const extractUnistyleDependencies = (value) => {
70
- const dependencies = keyInObject(value, 'uni__dependencies') ? value.uni__dependencies : [];
71
- return dependencies;
72
- };
@@ -1,26 +0,0 @@
1
- import { deepMergeObjects } from '../utils';
2
- const hasVariants = (value) => 'variants' in value[1];
3
- export const getVariants = (styles, selectedVariants) => {
4
- return Object.entries(styles)
5
- .filter(hasVariants)
6
- .filter(([_key, { variants }]) => Object.keys(variants).some(variant => variant in variants))
7
- .map(([key, { variants, compoundVariants = [] }]) => {
8
- const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
9
- const selectedVariant = selectedVariants[variant];
10
- const selectedVariantStyles = styles[selectedVariant] ?? styles['default'];
11
- if (!selectedVariantStyles) {
12
- return [];
13
- }
14
- return selectedVariantStyles;
15
- });
16
- const compoundVariantStyles = compoundVariants.flatMap(compoundVariant => {
17
- const { styles, ...conditions } = compoundVariant;
18
- if (Object.entries(conditions).some(([variant, value]) => String(selectedVariants[variant]) !== String(value))) {
19
- return [];
20
- }
21
- return styles;
22
- });
23
- const mergedVariantStyles = deepMergeObjects(...variantStyles, ...compoundVariantStyles);
24
- return [key, mergedVariantStyles];
25
- });
26
- };
@@ -1,2 +0,0 @@
1
- export * from './useVariants';
2
- export * from './getVariants';
@@ -1,50 +0,0 @@
1
- import { useMemo, useRef, useState } from 'react';
2
- import { equal, keyInObject, reduceObject } from '../utils';
3
- import { getVariants } from './getVariants';
4
- export const createUseVariants = (styles, setSelectedVariants) => {
5
- const useVariants = (selectedVariants) => {
6
- const [selectedVariantStylesMap] = useState(() => new Map());
7
- const lastSelectedVariantsRef = useRef();
8
- // Variable that determines if variants have changed and we need to recalculate styles
9
- const variantsChanged = !equal(lastSelectedVariantsRef.current, selectedVariants);
10
- if (variantsChanged) {
11
- lastSelectedVariantsRef.current = selectedVariants;
12
- setSelectedVariants(selectedVariants);
13
- }
14
- const combinedVariantStyles = useMemo(() => {
15
- const result = getVariants(styles, selectedVariants);
16
- result.forEach(([key, value]) => {
17
- selectedVariantStylesMap.set(key, value);
18
- });
19
- return result;
20
- }, [lastSelectedVariantsRef.current]);
21
- combinedVariantStyles.forEach(([key]) => {
22
- const styleEntry = styles[key];
23
- if (!styleEntry) {
24
- return;
25
- }
26
- const selectedVariantStyles = selectedVariantStylesMap.get(key);
27
- Object.defineProperties(styleEntry, reduceObject(selectedVariantStyles ?? {}, value => ({
28
- value,
29
- enumerable: false,
30
- configurable: true
31
- })));
32
- // Add __uni__variants to static styles
33
- Object.keys(styleEntry).forEach(key => {
34
- if (!key.startsWith('__uni__secrets__')) {
35
- return;
36
- }
37
- const secret = keyInObject(styleEntry, key) ? styleEntry[key] : undefined;
38
- if (!secret) {
39
- return;
40
- }
41
- Object.defineProperty(secret, '__uni__variants', {
42
- value: selectedVariants
43
- });
44
- });
45
- });
46
- };
47
- Object.defineProperty(styles, 'useVariants', {
48
- value: useVariants
49
- });
50
- };