react-native-unistyles 3.0.0-alpha.20 → 3.0.0-alpha.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. package/cxx/common/Constants.h +1 -0
  2. package/cxx/core/UnistyleWrapper.h +21 -41
  3. package/cxx/hybridObjects/HybridStyleSheet.cpp +1 -1
  4. package/cxx/hybridObjects/HybridStyleSheet.h +1 -1
  5. package/lib/commonjs/web/convert/boxShadow.js +13 -13
  6. package/lib/commonjs/web/convert/boxShadow.js.map +1 -1
  7. package/lib/commonjs/web/convert/index.js +9 -11
  8. package/lib/commonjs/web/convert/index.js.map +1 -1
  9. package/lib/commonjs/web/convert/pseudo.js.map +1 -0
  10. package/lib/commonjs/web/convert/style.js +11 -7
  11. package/lib/commonjs/web/convert/style.js.map +1 -1
  12. package/lib/commonjs/web/convert/textShadow.js +12 -12
  13. package/lib/commonjs/web/convert/textShadow.js.map +1 -1
  14. package/lib/commonjs/web/convert/transform.js +5 -5
  15. package/lib/commonjs/web/convert/transform.js.map +1 -1
  16. package/lib/commonjs/web/{listener/listener.js → listener.js} +2 -2
  17. package/lib/commonjs/web/listener.js.map +1 -0
  18. package/lib/commonjs/web/mq.js.map +1 -1
  19. package/lib/commonjs/web/registry.js +159 -21
  20. package/lib/commonjs/web/registry.js.map +1 -1
  21. package/lib/commonjs/web/shadowRegistry.js +50 -48
  22. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  23. package/lib/commonjs/web/state.js +8 -16
  24. package/lib/commonjs/web/state.js.map +1 -1
  25. package/lib/commonjs/web/{utils.js → utils/common.js} +9 -47
  26. package/lib/commonjs/web/utils/common.js.map +1 -0
  27. package/lib/commonjs/web/utils/index.js +28 -0
  28. package/lib/commonjs/web/utils/index.js.map +1 -0
  29. package/lib/commonjs/web/utils/unistyle.js +82 -0
  30. package/lib/commonjs/web/utils/unistyle.js.map +1 -0
  31. package/lib/module/web/convert/boxShadow.js +13 -13
  32. package/lib/module/web/convert/boxShadow.js.map +1 -1
  33. package/lib/module/web/convert/index.js +7 -9
  34. package/lib/module/web/convert/index.js.map +1 -1
  35. package/lib/module/web/convert/pseudo.js.map +1 -0
  36. package/lib/module/web/convert/style.js +11 -7
  37. package/lib/module/web/convert/style.js.map +1 -1
  38. package/lib/module/web/convert/textShadow.js +12 -12
  39. package/lib/module/web/convert/textShadow.js.map +1 -1
  40. package/lib/module/web/convert/transform.js +5 -5
  41. package/lib/module/web/convert/transform.js.map +1 -1
  42. package/lib/module/web/{listener/listener.js → listener.js} +2 -2
  43. package/lib/module/web/listener.js.map +1 -0
  44. package/lib/module/web/mq.js.map +1 -1
  45. package/lib/module/web/registry.js +160 -22
  46. package/lib/module/web/registry.js.map +1 -1
  47. package/lib/module/web/shadowRegistry.js +51 -49
  48. package/lib/module/web/shadowRegistry.js.map +1 -1
  49. package/lib/module/web/state.js +8 -16
  50. package/lib/module/web/state.js.map +1 -1
  51. package/lib/module/web/{utils.js → utils/common.js} +7 -39
  52. package/lib/module/web/utils/common.js.map +1 -0
  53. package/lib/module/web/utils/index.js +5 -0
  54. package/lib/module/web/utils/index.js.map +1 -0
  55. package/lib/module/web/utils/unistyle.js +69 -0
  56. package/lib/module/web/utils/unistyle.js.map +1 -0
  57. package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts +3 -0
  58. package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts.map +1 -0
  59. package/lib/typescript/expo-example/app/(tabs)/explore.d.ts +3 -0
  60. package/lib/typescript/expo-example/app/(tabs)/explore.d.ts.map +1 -0
  61. package/lib/typescript/expo-example/app/(tabs)/index.d.ts +3 -0
  62. package/lib/typescript/expo-example/app/(tabs)/index.d.ts.map +1 -0
  63. package/lib/typescript/expo-example/app/+html.d.ts +4 -0
  64. package/lib/typescript/expo-example/app/+html.d.ts.map +1 -0
  65. package/lib/typescript/expo-example/app/+not-found.d.ts +3 -0
  66. package/lib/typescript/expo-example/app/+not-found.d.ts.map +1 -0
  67. package/lib/typescript/expo-example/app/_layout.d.ts +3 -0
  68. package/lib/typescript/expo-example/app/_layout.d.ts.map +1 -0
  69. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +1 -1
  70. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
  71. package/lib/typescript/src/types/stylesheet.d.ts +1 -1
  72. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  73. package/lib/typescript/src/web/convert/boxShadow.d.ts +7 -2
  74. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -1
  75. package/lib/typescript/src/web/convert/index.d.ts +1 -2
  76. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  77. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -0
  78. package/lib/typescript/src/web/convert/style.d.ts +1 -2
  79. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  80. package/lib/typescript/src/web/convert/textShadow.d.ts +7 -2
  81. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -1
  82. package/lib/typescript/src/web/convert/transform.d.ts +1 -2
  83. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -1
  84. package/lib/typescript/src/web/{listener/listener.d.ts → listener.d.ts} +1 -1
  85. package/lib/typescript/src/web/listener.d.ts.map +1 -0
  86. package/lib/typescript/src/web/mq.d.ts +6 -2
  87. package/lib/typescript/src/web/mq.d.ts.map +1 -1
  88. package/lib/typescript/src/web/registry.d.ts +21 -8
  89. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  90. package/lib/typescript/src/web/shadowRegistry.d.ts +3 -4
  91. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  92. package/lib/typescript/src/web/state.d.ts +2 -2
  93. package/lib/typescript/src/web/state.d.ts.map +1 -1
  94. package/lib/typescript/src/web/{utils.d.ts → utils/common.d.ts} +2 -20
  95. package/lib/typescript/src/web/utils/common.d.ts.map +1 -0
  96. package/lib/typescript/src/web/utils/index.d.ts +3 -0
  97. package/lib/typescript/src/web/utils/index.d.ts.map +1 -0
  98. package/lib/typescript/src/web/utils/unistyle.d.ts +20 -0
  99. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -0
  100. package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
  101. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency_.hpp +8 -8
  102. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +22 -22
  103. package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
  104. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +1 -1
  105. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +2 -2
  106. package/nitrogen/generated/android/{UnistylesOnLoad.cpp → unistylesOnLoad.cpp} +2 -2
  107. package/nitrogen/generated/android/{UnistylesOnLoad.hpp → unistylesOnLoad.hpp} +1 -1
  108. package/nitrogen/generated/ios/Unistyles+autolinking.rb +5 -3
  109. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +25 -0
  110. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +32 -32
  111. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -29
  112. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +0 -12
  113. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +134 -110
  114. package/nitrogen/generated/shared/c++/ColorScheme.hpp +2 -2
  115. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
  116. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
  117. package/nitrogen/generated/shared/c++/Orientation.hpp +2 -2
  118. package/package.json +4 -15
  119. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +1 -1
  120. package/src/types/stylesheet.ts +1 -1
  121. package/src/web/convert/boxShadow.ts +14 -15
  122. package/src/web/convert/index.ts +6 -13
  123. package/src/web/convert/style.ts +61 -10
  124. package/src/web/convert/textShadow.ts +13 -14
  125. package/src/web/convert/transform.ts +7 -8
  126. package/src/web/{listener/listener.ts → listener.ts} +2 -2
  127. package/src/web/mq.ts +1 -3
  128. package/src/web/registry.ts +202 -23
  129. package/src/web/shadowRegistry.ts +49 -49
  130. package/src/web/state.ts +13 -23
  131. package/src/web/{utils.ts → utils/common.ts} +6 -68
  132. package/src/web/utils/index.ts +2 -0
  133. package/src/web/utils/unistyle.ts +104 -0
  134. package/lib/commonjs/web/convert/breakpoint.js +0 -25
  135. package/lib/commonjs/web/convert/breakpoint.js.map +0 -1
  136. package/lib/commonjs/web/createUnistylesComponent.js +0 -61
  137. package/lib/commonjs/web/createUnistylesComponent.js.map +0 -1
  138. package/lib/commonjs/web/listener/index.js +0 -20
  139. package/lib/commonjs/web/listener/index.js.map +0 -1
  140. package/lib/commonjs/web/listener/listenToDependencies.js +0 -38
  141. package/lib/commonjs/web/listener/listenToDependencies.js.map +0 -1
  142. package/lib/commonjs/web/listener/listener.js.map +0 -1
  143. package/lib/commonjs/web/pseudo.js.map +0 -1
  144. package/lib/commonjs/web/utils.js.map +0 -1
  145. package/lib/module/web/convert/breakpoint.js +0 -20
  146. package/lib/module/web/convert/breakpoint.js.map +0 -1
  147. package/lib/module/web/createUnistylesComponent.js +0 -54
  148. package/lib/module/web/createUnistylesComponent.js.map +0 -1
  149. package/lib/module/web/listener/index.js +0 -5
  150. package/lib/module/web/listener/index.js.map +0 -1
  151. package/lib/module/web/listener/listenToDependencies.js +0 -33
  152. package/lib/module/web/listener/listenToDependencies.js.map +0 -1
  153. package/lib/module/web/listener/listener.js.map +0 -1
  154. package/lib/module/web/pseudo.js.map +0 -1
  155. package/lib/module/web/utils.js.map +0 -1
  156. package/lib/typescript/src/web/convert/breakpoint.d.ts +0 -3
  157. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +0 -1
  158. package/lib/typescript/src/web/createUnistylesComponent.d.ts +0 -3
  159. package/lib/typescript/src/web/createUnistylesComponent.d.ts.map +0 -1
  160. package/lib/typescript/src/web/listener/index.d.ts +0 -3
  161. package/lib/typescript/src/web/listener/index.d.ts.map +0 -1
  162. package/lib/typescript/src/web/listener/listenToDependencies.d.ts +0 -12
  163. package/lib/typescript/src/web/listener/listenToDependencies.d.ts.map +0 -1
  164. package/lib/typescript/src/web/listener/listener.d.ts.map +0 -1
  165. package/lib/typescript/src/web/pseudo.d.ts.map +0 -1
  166. package/lib/typescript/src/web/utils.d.ts.map +0 -1
  167. package/src/web/convert/breakpoint.ts +0 -21
  168. package/src/web/createUnistylesComponent.tsx +0 -54
  169. package/src/web/listener/index.ts +0 -2
  170. package/src/web/listener/listenToDependencies.ts +0 -45
  171. /package/lib/commonjs/web/{pseudo.js → convert/pseudo.js} +0 -0
  172. /package/lib/module/web/{pseudo.js → convert/pseudo.js} +0 -0
  173. /package/lib/typescript/src/web/{pseudo.d.ts → convert/pseudo.d.ts} +0 -0
  174. /package/nitrogen/generated/android/{UnistylesOnLoad.kt → unistylesOnLoad.kt} +0 -0
  175. /package/src/web/{pseudo.ts → convert/pseudo.ts} +0 -0
@@ -1,3 +0,0 @@
1
- import type { MediaQuery } from 'typestyle/lib/types';
2
- export declare const convertBreakpoint: (breakpoint: string) => MediaQuery;
3
- //# sourceMappingURL=breakpoint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"breakpoint.d.ts","sourceRoot":"","sources":["../../../../../src/web/convert/breakpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAMrD,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,UActD,CAAA"}
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- export declare const createUnistylesComponent: <TProps extends object>(Component: React.ComponentType<TProps>) => (props: TProps) => React.JSX.Element;
3
- //# sourceMappingURL=createUnistylesComponent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createUnistylesComponent.d.ts","sourceRoot":"","sources":["../../../../src/web/createUnistylesComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAiClD,eAAO,MAAM,wBAAwB,GAAI,MAAM,SAAS,MAAM,aAAa,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,aAAa,MAAM,sBAoBxH,CAAA"}
@@ -1,3 +0,0 @@
1
- export { UnistylesListener } from './listener';
2
- export { listenToDependencies } from './listenToDependencies';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/web/listener/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA"}
@@ -1,12 +0,0 @@
1
- import type { TypeStyle } from 'typestyle';
2
- import type { StyleSheet, StyleSheetWithSuperPowers } from '../../types/stylesheet';
3
- type ListenToDependenciesProps = {
4
- key: PropertyKey;
5
- unistyles: TypeStyle;
6
- className: string;
7
- stylesheet: StyleSheetWithSuperPowers<StyleSheet>;
8
- args?: Array<any>;
9
- };
10
- export declare const listenToDependencies: ({ key, className, unistyles, args, stylesheet }: ListenToDependenciesProps) => (() => void) | undefined;
11
- export {};
12
- //# sourceMappingURL=listenToDependencies.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listenToDependencies.d.ts","sourceRoot":"","sources":["../../../../../src/web/listener/listenToDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAMnF,KAAK,yBAAyB,GAAG;IAC7B,GAAG,EAAE,WAAW,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAAA;IACjD,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,oBAAoB,oDAA0D,yBAAyB,6BA6BnH,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../../../src/web/listener/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAG/D,cAAM,wBAAwB;IAC1B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,SAAS,CAAoG;IAErH,UAAU,eAAgB,kBAAkB,UAE3C;IAED,aAAa,aAUZ;IAED,YAAY,iBAAkB,KAAK,CAAC,kBAAkB,CAAC,YAAY,YAAY,gBAM9E;CACJ;AAED,eAAO,MAAM,iBAAiB,0BAAiC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"pseudo.d.ts","sourceRoot":"","sources":["../../../../src/web/pseudo.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,ssEAiIV,CAAA;AAEV,eAAO,MAAM,QAAQ,aAAc,MAAM,YAAwD,CAAA;AAEjG,KAAK,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,MAAM,GAAG,GAAG,CAAC,CAAA;AAE3F,MAAM,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/web/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAEjG,eAAO,MAAM,YAAY,GAAI,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,OAC9D,IAAI,WACA,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,IAAI,KAAK,QAAQ,KACmD,GAAG,CAAe,IAAV,MAAM,IAAI,GAAG,QAAQ,GAAE,CAAA;AAErJ,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,WAAW,KAAG,GAAG,IAAI,MAAM,CAAe,CAAA;AAElH,eAAO,MAAM,aAAa,WAAY,WAAW,KAAG,YAQnD,CAAA;AAED,eAAO,MAAM,SAAS,QAAS,MAAM,WAAW,MAAM,WAM5B,CAAA;AAE1B,eAAO,MAAM,QAAQ,eAAsC,CAAA;AAE3D;;EAEE;AACF,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,cAAc,KAAK,CAAC,CAAC,CAAC,MAqBxF,CAAA;AAED,eAAO,MAAM,IAAI,YAAa,MAAM,SAA2D,CAAA;AAE/F,eAAO,MAAM,KAAK,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,YAqBlC,CAAA;AAED,KAAK,eAAe,GAAG;IACnB,iBAAiB,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,GAAG,CAAC,WAAW,CAAC,CAAA;IAC7B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,UAAU,CAAC,WAAW,eAAe,MAKnE,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG,sBAUzC,CAAA;AAED,eAAO,MAAM,SAAS,WAAY,eAAe,OAUhD,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,IAAI,EAAE,UAAU,EAAE,MAAM;eAIrC,IAAI,aAAa,UAAU;eAS3B,IAAI,aAAa,UAAU,SAAS,MAAM;kBAMvC,IAAI,aAAa,UAAU;wBASrB,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI;CAQpF,CAAA;AAED,eAAO,MAAM,uBAAuB,WAAY,GAAG;;CAQlD,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,WAAW,YAAoC,CAAA"}
@@ -1,21 +0,0 @@
1
- import type { MediaQuery } from 'typestyle/lib/types'
2
- import { UnistylesState } from '../state'
3
- import { keyInObject } from '../utils'
4
- import { isUnistylesMq, parseMq } from '../mq'
5
- import { Orientation } from '../../specs/types'
6
-
7
- export const convertBreakpoint = (breakpoint: string): MediaQuery => {
8
- if (Object.values(Orientation).includes(breakpoint as Orientation)) {
9
- return {
10
- orientation: breakpoint as Orientation
11
- }
12
- }
13
-
14
- if (isUnistylesMq(breakpoint)) {
15
- return parseMq(breakpoint)
16
- }
17
-
18
- return {
19
- minWidth: UnistylesState.breakpoints && keyInObject(UnistylesState.breakpoints, breakpoint) ? UnistylesState.breakpoints[breakpoint] : undefined,
20
- }
21
- }
@@ -1,54 +0,0 @@
1
- import React, { useEffect, useState } from 'react'
2
- import { extractHiddenProperties, extractSecrets } from './utils'
3
- import { getVariants } from './variants'
4
- import { UnistylesListener } from './listener'
5
- import { UnistylesRegistry } from './registry'
6
-
7
- const getStyles = (value: Record<string, any>) => {
8
- const secrets = extractSecrets(value)
9
-
10
- if (secrets.length === 0) {
11
- return undefined
12
- }
13
-
14
- return secrets.reduce((acc, { __uni__stylesheet, __uni__key, __uni__args = [], __uni__variants }) => {
15
- const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
16
- const style = newComputedStylesheet[__uni__key]
17
- const resultHidden = typeof style === 'function'
18
- ? style(...__uni__args)
19
- : style
20
- const result = extractHiddenProperties(resultHidden)
21
- const { variants } = Object.fromEntries(getVariants({ variants: result }, __uni__variants ))
22
- const resultWithVariants = {
23
- ...result,
24
- ...variants
25
- }
26
-
27
- return {
28
- ...acc,
29
- ...resultWithVariants
30
- }
31
- }, {} as Record<string, any>)
32
- }
33
-
34
- export const createUnistylesComponent = <TProps extends object>(Component: React.ComponentType<TProps>) => (props: TProps) => {
35
- const passedStyles = (props as TProps & { style: Record<string, any> }).style ?? {}
36
- const [style, setStyle] = useState(getStyles(passedStyles))
37
-
38
- useEffect(() => {
39
- const newStyles = getStyles(passedStyles)
40
- const dependencies = newStyles?.['uni__dependencies'] ?? []
41
- const dispose = UnistylesListener.addListeners(dependencies, () => setStyle(getStyles(passedStyles)))
42
-
43
- setStyle(newStyles)
44
-
45
- return dispose
46
- }, [passedStyles])
47
-
48
- return (
49
- <Component
50
- {...props}
51
- style={style}
52
- />
53
- )
54
- }
@@ -1,2 +0,0 @@
1
- export { UnistylesListener } from './listener'
2
- export { listenToDependencies } from './listenToDependencies'
@@ -1,45 +0,0 @@
1
- import type { TypeStyle } from 'typestyle'
2
- import type { StyleSheet, StyleSheetWithSuperPowers } from '../../types/stylesheet'
3
- import type { UnistyleDependency } from '../../specs/NativePlatform'
4
- import { UnistylesListener } from './listener'
5
- import { keyInObject } from '../utils'
6
- import { UnistylesRegistry } from '../registry'
7
-
8
- type ListenToDependenciesProps = {
9
- key: PropertyKey,
10
- unistyles: TypeStyle,
11
- className: string,
12
- stylesheet: StyleSheetWithSuperPowers<StyleSheet>
13
- args?: Array<any>
14
- }
15
-
16
- export const listenToDependencies = ({ key, className, unistyles, args = [], stylesheet }: ListenToDependenciesProps) => {
17
- const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(stylesheet)
18
- const _value = keyInObject(newComputedStylesheet, key) ? newComputedStylesheet[key] : undefined
19
-
20
- if (!_value) {
21
- return
22
- }
23
-
24
- const value = typeof _value === 'function' ? _value(...args) : _value
25
- const dependencies = ('uni__dependencies' in value ? value['uni__dependencies'] : []) as Array<UnistyleDependency>
26
-
27
- if (dependencies.length === 0) {
28
- return
29
- }
30
-
31
- return UnistylesListener.addListeners(dependencies, () => {
32
- const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(stylesheet)
33
-
34
- if (!keyInObject(newComputedStylesheet, key)) {
35
- return
36
- }
37
-
38
- const value = newComputedStylesheet[key]!
39
- const result = typeof value === 'function'
40
- ? value(...args)
41
- : value
42
-
43
- UnistylesRegistry.updateStyles(unistyles, result, className)
44
- })
45
- }
File without changes
File without changes