react-native-unistyles 3.0.0-nightly-20250226 → 3.0.0-nightly-20250319

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +6 -7
  2. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +1 -1
  3. package/cxx/core/HostUnistyle.cpp +14 -4
  4. package/cxx/core/StyleSheet.h +1 -1
  5. package/cxx/core/UnistyleWrapper.h +1 -1
  6. package/cxx/hybridObjects/HybridStyleSheet.h +1 -1
  7. package/cxx/parser/Parser.cpp +26 -4
  8. package/cxx/parser/Parser.h +1 -1
  9. package/lib/commonjs/components/native/Pressable.native.js +1 -1
  10. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  11. package/lib/commonjs/core/getClassname.js +2 -2
  12. package/lib/commonjs/core/getClassname.js.map +1 -1
  13. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +12 -0
  14. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  15. package/lib/commonjs/core/withUnistyles/withUnistyles.js +13 -5
  16. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  17. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +1 -1
  18. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  19. package/lib/commonjs/web/registry.js +4 -3
  20. package/lib/commonjs/web/registry.js.map +1 -1
  21. package/lib/commonjs/web/runtime.js +5 -1
  22. package/lib/commonjs/web/runtime.js.map +1 -1
  23. package/lib/commonjs/web/shadowRegistry.js +4 -3
  24. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  25. package/lib/commonjs/web/state.js +8 -2
  26. package/lib/commonjs/web/state.js.map +1 -1
  27. package/lib/commonjs/web/utils/unistyle.js +1 -3
  28. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  29. package/lib/module/components/native/Pressable.native.js +1 -1
  30. package/lib/module/components/native/Pressable.native.js.map +1 -1
  31. package/lib/module/core/getClassname.js +2 -2
  32. package/lib/module/core/getClassname.js.map +1 -1
  33. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +12 -0
  34. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  35. package/lib/module/core/withUnistyles/withUnistyles.js +13 -5
  36. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  37. package/lib/module/core/withUnistyles/withUnistyles.native.js +1 -1
  38. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  39. package/lib/module/web/registry.js +4 -3
  40. package/lib/module/web/registry.js.map +1 -1
  41. package/lib/module/web/runtime.js +5 -1
  42. package/lib/module/web/runtime.js.map +1 -1
  43. package/lib/module/web/shadowRegistry.js +4 -3
  44. package/lib/module/web/shadowRegistry.js.map +1 -1
  45. package/lib/module/web/state.js +8 -2
  46. package/lib/module/web/state.js.map +1 -1
  47. package/lib/module/web/utils/unistyle.js +0 -1
  48. package/lib/module/web/utils/unistyle.js.map +1 -1
  49. package/lib/typescript/src/core/getClassname.d.ts +1 -1
  50. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  51. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  52. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +1 -1
  53. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  54. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +1 -3
  55. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  56. package/lib/typescript/src/types/common.d.ts +0 -1
  57. package/lib/typescript/src/types/common.d.ts.map +1 -1
  58. package/lib/typescript/src/web/registry.d.ts +1 -1
  59. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  60. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  61. package/lib/typescript/src/web/shadowRegistry.d.ts +1 -1
  62. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  63. package/lib/typescript/src/web/state.d.ts.map +1 -1
  64. package/lib/typescript/src/web/utils/unistyle.d.ts +0 -1
  65. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  66. package/package.json +1 -1
  67. package/plugin/index.js +3 -0
  68. package/src/components/native/Pressable.native.tsx +1 -1
  69. package/src/core/getClassname.ts +3 -2
  70. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +16 -0
  71. package/src/core/withUnistyles/withUnistyles.native.tsx +3 -4
  72. package/src/core/withUnistyles/withUnistyles.tsx +17 -6
  73. package/src/types/common.ts +0 -1
  74. package/src/web/registry.ts +6 -3
  75. package/src/web/runtime.ts +6 -2
  76. package/src/web/shadowRegistry.ts +7 -3
  77. package/src/web/state.ts +10 -2
  78. package/src/web/utils/unistyle.ts +0 -2
  79. /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
@@ -11,7 +11,7 @@ export declare class UnistylesShadowRegistry {
11
11
  private disposeMap;
12
12
  constructor(services: UnistylesServices);
13
13
  add: (ref: any, hash?: string) => void;
14
- addStyles: (unistyles: Array<UnistylesValues>) => {
14
+ addStyles: (unistyles: Array<UnistylesValues>, forChild?: boolean) => {
15
15
  injectedClassName: string;
16
16
  hash: string;
17
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"shadowRegistry.d.ts","sourceRoot":"","sources":["../../../../src/web/shadowRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIhD,qBAAa,uBAAuB;IAYpB,OAAO,CAAC,QAAQ;IAV5B,IAAI,SAA4B;IAChC,MAAM,SAAQ;IACd,MAAM,gBAAa;IACnB,QAAQ,eAAkC;IAC1C,OAAO,aAAW;IAGlB,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,UAAU,CAAkC;gBAEhC,QAAQ,EAAE,iBAAiB;IAE/C,GAAG,QAAS,GAAG,SAAS,MAAM,UAM7B;IAED,SAAS,cAAe,KAAK,CAAC,eAAe,CAAC;;;MAiD7C;IAED,cAAc,WAAY,cAAc,UAEvC;IAED,cAAc,kBAAyB;IAEvC,MAAM,QAAS,GAAG,SAAS,MAAM,UAWhC;CACJ"}
1
+ {"version":3,"file":"shadowRegistry.d.ts","sourceRoot":"","sources":["../../../../src/web/shadowRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIhD,qBAAa,uBAAuB;IAYpB,OAAO,CAAC,QAAQ;IAV5B,IAAI,SAA4B;IAChC,MAAM,SAAQ;IACd,MAAM,gBAAa;IACnB,QAAQ,eAAkC;IAC1C,OAAO,aAAW;IAGlB,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,UAAU,CAAkC;gBAEhC,QAAQ,EAAE,iBAAiB;IAE/C,GAAG,QAAS,GAAG,SAAS,MAAM,UAM7B;IAED,SAAS,cAAe,KAAK,CAAC,eAAe,CAAC,aAAa,OAAO;;;MAqDjE;IAED,cAAc,WAAY,cAAc,UAEvC;IAED,cAAc,kBAAyB;IAEvC,MAAM,QAAS,GAAG,SAAS,MAAM,UAWhC;CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../src/web/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAmB,MAAM,WAAW,CAAA;AAEtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAY,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAKhD,qBAAa,cAAc;IAqBX,OAAO,CAAC,QAAQ;IApB5B,aAAa,UAAQ;IACrB,MAAM,qBAAoC;IAC1C,SAAS,qBAAoC;IAC7C,SAAS,CAAC,EAAE,YAAY,CAAA;IACxB,OAAO,UAAO;IAEd,OAAO,CAAC,mBAAmB,CAA6B;IAExD,IAAI,UAAU,IAKkB,aAAa,GAAG,SAAS,CACxD;IAED,WAAW,CAAC,EAAE,oBAAoB,CAAA;IAElC,iBAAiB,UAAQ;gBAEL,QAAQ,EAAE,iBAAiB;IAE/C,IAAI,WAAY,eAAe,UAwB9B;IAED,OAAO,CAAC,UAAU,CA0BjB;IAED,OAAO,CAAC,YAAY,CA6BnB;IAED,OAAO,CAAC,eAAe,CA2BtB;CACJ"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../src/web/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAmB,MAAM,WAAW,CAAA;AAEtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAY,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAKhD,qBAAa,cAAc;IAqBX,OAAO,CAAC,QAAQ;IApB5B,aAAa,UAAQ;IACrB,MAAM,qBAAoC;IAC1C,SAAS,qBAAoC;IAC7C,SAAS,CAAC,EAAE,YAAY,CAAA;IACxB,OAAO,UAAO;IAEd,OAAO,CAAC,mBAAmB,CAA6B;IAExD,IAAI,UAAU,IAKkB,aAAa,GAAG,SAAS,CACxD;IAED,WAAW,CAAC,EAAE,oBAAoB,CAAA;IAElC,iBAAiB,UAAQ;gBAEL,QAAQ,EAAE,iBAAiB;IAE/C,IAAI,WAAY,eAAe,UAwB9B;IAED,OAAO,CAAC,UAAU,CA8BjB;IAED,OAAO,CAAC,YAAY,CA6BnB;IAED,OAAO,CAAC,eAAe,CA+BtB;CACJ"}
@@ -13,7 +13,6 @@ export declare const extractSecrets: (object: any) => {
13
13
  [x: string]: any;
14
14
  } | undefined;
15
15
  export declare const removeInlineStyles: (values: UnistylesValues) => {};
16
- export declare const isInDocument: (element: HTMLElement) => boolean;
17
16
  export declare const getMediaQuery: (query: string, allBreakpoints: Array<string>) => string;
18
17
  export declare const extractUnistyleDependencies: (value: any) => UnistyleDependency[];
19
18
  //# sourceMappingURL=unistyle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unistyle.d.ts","sourceRoot":"","sources":["../../../../../src/web/utils/unistyle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAIpG,eAAO,MAAM,aAAa,WAAY,WAAW,qBAQhD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,iBAAiB,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;CAC/D,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,UAAU,CAAC,WAAW,eAAe,MAanE,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG;;aAkBzC,CAAA;AAED,eAAO,MAAM,kBAAkB,WAAY,eAAe,OAUzD,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,WAAW,YAAoC,CAAA;AAErF,eAAO,MAAM,aAAa,UAAW,MAAM,kBAAkB,KAAK,CAAC,MAAM,CAAC,WA6BzE,CAAA;AAED,eAAO,MAAM,2BAA2B,UAAW,GAAG,yBAQrD,CAAA"}
1
+ {"version":3,"file":"unistyle.d.ts","sourceRoot":"","sources":["../../../../../src/web/utils/unistyle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAIpG,eAAO,MAAM,aAAa,WAAY,WAAW,qBAQhD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,iBAAiB,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;CAC/D,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,UAAU,CAAC,WAAW,eAAe,MAanE,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG;;aAkBzC,CAAA;AAED,eAAO,MAAM,kBAAkB,WAAY,eAAe,OAUzD,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,kBAAkB,KAAK,CAAC,MAAM,CAAC,WA6BzE,CAAA;AAED,eAAO,MAAM,2BAA2B,UAAW,GAAG,yBAQrD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-nightly-20250226",
3
+ "version": "3.0.0-nightly-20250319",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
package/plugin/index.js CHANGED
@@ -59,6 +59,9 @@ var REACT_NATIVE_COMPONENT_NAMES = [
59
59
  ];
60
60
  var REPLACE_WITH_UNISTYLES_PATHS = [
61
61
  "react-native-reanimated/src/component",
62
+ "react-native-reanimated/lib/module/component",
63
+ "react-native-gesture-handler/lib/module/components",
64
+ "react-native-gesture-handler/lib/commonjs/components",
62
65
  "react-native-gesture-handler/src/components"
63
66
  ];
64
67
  var REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = [];
@@ -51,7 +51,7 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
51
51
  }
52
52
 
53
53
  // @ts-expect-error - this is hidden from TS
54
- UnistylesShadowRegistry.add(storedRef.current, unistyles)
54
+ UnistylesShadowRegistry.add(ref, unistyles)
55
55
 
56
56
  return passForwardedRef(props, ref, forwardedRef)
57
57
  }}
@@ -1,13 +1,14 @@
1
1
  import type { UnistylesValues } from '../types'
2
2
  import { UnistylesWeb } from '../web'
3
3
 
4
- export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>) => {
4
+ export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>, forChild?: boolean) => {
5
5
  if (!unistyle) {
6
6
  return undefined
7
7
  }
8
8
 
9
9
  const { hash, injectedClassName } = UnistylesWeb.shadowRegistry.addStyles(
10
- Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle]
10
+ Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle],
11
+ forChild
11
12
  )
12
13
 
13
14
  return hash ? { $$css: true, hash, injectedClassName } : undefined
@@ -63,6 +63,22 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
63
63
  })
64
64
  const proxifiedRuntime = new Proxy(getMiniRuntime(), {
65
65
  get: (target, prop) => {
66
+ if (prop === 'insets') {
67
+ return new Proxy(target.insets, {
68
+ get: (target, prop) => {
69
+ if (prop === 'ime') {
70
+ dependencies.add(UnistyleDependency.Ime)
71
+
72
+ return target[prop as keyof typeof target]
73
+ }
74
+
75
+ dependencies.add(UnistyleDependency.Insets)
76
+
77
+ return target[prop as keyof typeof target]
78
+ }
79
+ })
80
+ }
81
+
66
82
  if (prop in RTDependencyMap) {
67
83
  dependencies.add(RTDependencyMap[prop as keyof typeof RTDependencyMap])
68
84
  }
@@ -1,11 +1,10 @@
1
1
  import React, { forwardRef, useEffect, type ComponentType, useRef } from 'react'
2
2
  import { type UnistyleDependency, UnistylesShadowRegistry } from '../../specs'
3
3
  import type { UnistylesTheme } from '../../types'
4
- import type { PartialBy } from '../../types/common'
5
4
  import { deepMergeObjects } from '../../utils'
6
5
  import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
7
6
  import { maybeWarnAboutMultipleUnistyles } from '../warn'
8
- import type { Mappings, SupportedStyleProps } from './types'
7
+ import type { Mappings } from './types'
9
8
 
10
9
  // @ts-expect-error
11
10
  type GenericComponentProps<P> = ComponentProps<P>
@@ -24,12 +23,12 @@ type MappedSecrets = {
24
23
 
25
24
  export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
26
25
  type TProps = GenericComponentProps<TComponent>
27
- type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
26
+ type PropsWithUnistyles = Partial<TProps> & {
28
27
  uniProps?: Mappings<TProps>
29
28
  }
30
29
  const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
31
30
  const styles = Array.isArray(styleProps)
32
- ? styleProps
31
+ ? styleProps.flat()
33
32
  : [styleProps]
34
33
 
35
34
  const secrets: Array<UnistylesSecrets> = styles
@@ -1,11 +1,10 @@
1
1
  import React, { type ComponentType, forwardRef, type ComponentProps, type ComponentRef } from 'react'
2
2
  import type { UnistylesValues } from '../../types'
3
- import type { PartialBy } from '../../types/common'
4
3
  import { deepMergeObjects } from '../../utils'
5
4
  import { getClassName } from '../getClassname'
6
5
  import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
7
6
  import { maybeWarnAboutMultipleUnistyles } from '../warn'
8
- import type { Mappings, SupportedStyleProps } from './types'
7
+ import type { Mappings } from './types'
9
8
 
10
9
  // @ts-expect-error
11
10
  type GenericComponentProps<T> = ComponentProps<T>
@@ -14,7 +13,7 @@ type GenericComponentRef<T> = ComponentRef<T>
14
13
 
15
14
  export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
16
15
  type TProps = GenericComponentProps<TComponent>
17
- type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
16
+ type PropsWithUnistyles = Partial<TProps> & {
18
17
  uniProps?: Mappings<TProps>
19
18
  }
20
19
  type UnistyleStyles = {
@@ -24,17 +23,22 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
24
23
 
25
24
  return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
26
25
  const narrowedProps = props as PropsWithUnistyles & UnistyleStyles
27
- const styleClassNames = getClassName(narrowedProps.style)
26
+ const styleClassNames = getClassName(narrowedProps.style, true)
28
27
  const contentContainerStyleClassNames = getClassName(narrowedProps.contentContainerStyle)
29
28
  const { proxifiedRuntime, proxifiedTheme } = useProxifiedUnistyles()
30
29
 
31
30
  const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
32
31
  const unistyleProps = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
33
32
 
33
+ const emptyStyles = Object.fromEntries(Object.entries(Object.getOwnPropertyDescriptors(narrowedProps.style))
34
+ .filter(([key]) => !key.startsWith('unistyles') && !key.startsWith('_'))
35
+ .map(([key]) => [key, undefined]))
36
+
34
37
  const combinedProps = {
35
38
  ...deepMergeObjects(mappingsProps, unistyleProps, props),
36
39
  ...narrowedProps.style ? {
37
- style: styleClassNames,
40
+ // Override default component styles with undefined values to reset them
41
+ style: emptyStyles
38
42
  } : {},
39
43
  ...narrowedProps.contentContainerStyle ? {
40
44
  contentContainerStyle: contentContainerStyleClassNames,
@@ -48,6 +52,13 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
48
52
 
49
53
  const NativeComponent = Component as ComponentType
50
54
 
51
- return <NativeComponent {...combinedProps} ref={ref} />
55
+ return (
56
+ <div
57
+ className={styleClassNames?.hash}
58
+ style={{ display: 'contents' }}
59
+ >
60
+ <NativeComponent {...combinedProps} ref={ref} />
61
+ </div>
62
+ )
52
63
  })
53
64
  }
@@ -1,5 +1,4 @@
1
1
  export type Optional<T> = T | undefined
2
2
  export type Nullable<T> = T | null
3
3
  export type SafeReturnType<T> = T extends (...args: any) => infer R ? R : T
4
- export type PartialBy<T, K> = Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>
5
4
  export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
@@ -21,7 +21,7 @@ export class UnistylesRegistry {
21
21
  }
22
22
 
23
23
  if (scopedThemeName) {
24
- const scopedTheme = this.services.runtime.getTheme(scopedThemeName, this.services.state.CSSVars)
24
+ const scopedTheme = this.services.runtime.getTheme(scopedThemeName)
25
25
 
26
26
  if (!scopedTheme) {
27
27
  throw error(`Unistyles: You're trying to use scoped theme '${scopedThemeName}' but it wasn't registered.`)
@@ -92,8 +92,11 @@ export class UnistylesRegistry {
92
92
  return false
93
93
  }
94
94
 
95
- add = (value: UnistylesValues) => {
96
- const hash = generateHash(value)
95
+ add = (value: UnistylesValues, forChild?: boolean) => {
96
+ const generatedHash = generateHash(value)
97
+ const hash = forChild
98
+ ? `${generatedHash} > *`
99
+ : generatedHash
97
100
 
98
101
  if (!this.stylesCache.has(hash)) {
99
102
  this.applyStyles(hash, value)
@@ -1,7 +1,7 @@
1
1
  import { UnistyleDependency } from '../specs/NativePlatform'
2
2
  import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
3
3
  import { type AppTheme, type AppThemeName, ColorScheme, Orientation } from '../specs/types'
4
- import { WebContentSizeCategory } from '../types'
4
+ import { type UnistylesTheme, WebContentSizeCategory } from '../types'
5
5
  import { NavigationBar, StatusBar } from './mock'
6
6
  import type { UnistylesServices } from './types'
7
7
  import { error, isServer, schemeToTheme } from './utils'
@@ -213,7 +213,11 @@ export class UnistylesRuntime {
213
213
  : this.services.state.themes.get(themeName ?? '')
214
214
 
215
215
  if (!themeName || !theme) {
216
- throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
216
+ return new Proxy({} as UnistylesTheme, {
217
+ get: () => {
218
+ throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
219
+ }
220
+ })
217
221
  }
218
222
 
219
223
  return theme
@@ -27,7 +27,7 @@ export class UnistylesShadowRegistry {
27
27
  this.services.registry.connect(ref, hash)
28
28
  }
29
29
 
30
- addStyles = (unistyles: Array<UnistylesValues>) => {
30
+ addStyles = (unistyles: Array<UnistylesValues>, forChild?: boolean) => {
31
31
  const getParsedStyles = () => {
32
32
  const allStyles = unistyles.map(unistyle => {
33
33
  const secrets = extractSecrets(unistyle)
@@ -61,7 +61,7 @@ export class UnistylesShadowRegistry {
61
61
  // Copy scoped theme to not use referenced value
62
62
  const scopedTheme = this.scopedTheme
63
63
  const parsedStyles = getParsedStyles()
64
- const { hash, existingHash } = this.services.registry.add(parsedStyles)
64
+ const { hash, existingHash } = this.services.registry.add(parsedStyles, forChild)
65
65
  const injectedClassNames = parsedStyles?._web?._classNames ?? []
66
66
  const injectedClassName = Array.isArray(injectedClassNames) ? injectedClassNames.join(' ') : injectedClassNames
67
67
  const dependencies = extractUnistyleDependencies(parsedStyles)
@@ -75,7 +75,11 @@ export class UnistylesShadowRegistry {
75
75
  }))
76
76
  }
77
77
 
78
- return { injectedClassName, hash }
78
+ const hashClassname = forChild
79
+ ? hash.replace(' > *', '')
80
+ : hash
81
+
82
+ return { injectedClassName, hash: hashClassname }
79
83
  }
80
84
 
81
85
  setScopedTheme = (theme?: UnistylesTheme) => {
package/src/web/state.ts CHANGED
@@ -58,7 +58,11 @@ export class UnistylesState {
58
58
  this.services.listener.initListeners()
59
59
  }
60
60
 
61
- private initThemes = (themes = {} as UnistylesThemes, CSSVars = true) => {
61
+ private initThemes = (themes?: UnistylesThemes, CSSVars = true) => {
62
+ if (!themes) {
63
+ return
64
+ }
65
+
62
66
  this.CSSVars = CSSVars
63
67
 
64
68
  Object.entries(themes).forEach(([themeName, theme]) => {
@@ -117,7 +121,11 @@ export class UnistylesState {
117
121
  }
118
122
  }
119
123
 
120
- private initBreakpoints = (breakpoints = {} as UnistylesBreakpoints) => {
124
+ private initBreakpoints = (breakpoints?: UnistylesBreakpoints) => {
125
+ if (!breakpoints) {
126
+ return
127
+ }
128
+
121
129
  this.breakpoints = breakpoints
122
130
  const breakpointsEntries = Object.entries(breakpoints)
123
131
 
@@ -70,8 +70,6 @@ export const removeInlineStyles = (values: UnistylesValues) => {
70
70
  return returnValue
71
71
  }
72
72
 
73
- export const isInDocument = (element: HTMLElement) => document.body.contains(element)
74
-
75
73
  export const getMediaQuery = (query: string, allBreakpoints: Array<string>) => {
76
74
  if (Object.values(Orientation).includes(query as Orientation)) {
77
75
  return `@media (orientation: ${query})`