@codeandmoney/soelma 0.0.0-dev.0 → 0.0.0-dev.10

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 (76) hide show
  1. package/.eslintrc.js +1 -5
  2. package/biome.jsonc +73 -0
  3. package/example/AppStyleX/app.json +4 -16
  4. package/example/AppStyleX/babel.config.js +1 -1
  5. package/example/AppStyleX/index.js +3 -3
  6. package/example/AppStyleX/metro.config.js +1 -4
  7. package/example/AppStyleX/src/App.tsx +7 -10
  8. package/example/AppStyleX/src/BottomNav/index.tsx +9 -15
  9. package/example/AppStyleX/src/Circle/index.tsx +6 -6
  10. package/example/AppStyleX/src/Circle/styles.ts +4 -4
  11. package/example/AppStyleX/src/Root/index.tsx +12 -18
  12. package/example/AppStyleX/src/Root/styles.ts +5 -5
  13. package/example/AppStyleX/src/ToggleButton/index.tsx +10 -24
  14. package/example/AppStyleX/src/ToggleButton/styles.ts +13 -15
  15. package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +2 -2
  16. package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +2 -2
  17. package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +2 -2
  18. package/example/AppStyleX/src/style-system/palette.ts +6 -6
  19. package/example/AppStyleX/src/style-system/theme.ts +2 -2
  20. package/example/AppStyleX/src/style-system/utils.ts +4 -7
  21. package/example/AppStyleX/src/stylex.d.ts +3 -3
  22. package/package.json +15 -11
  23. package/src/appearance/index.ts +5 -12
  24. package/src/appearance/init.ts +2 -2
  25. package/src/context.ts +2 -5
  26. package/src/dark-mode/index.ts +2 -5
  27. package/src/dark-mode/init.ts +2 -2
  28. package/src/{dependencyUsage.ts → dependency-usage.ts} +0 -10
  29. package/src/dimensions/index.ts +1 -1
  30. package/src/dimensions/init.ts +5 -10
  31. package/src/dimensions/utils.ts +1 -3
  32. package/src/i18n.ts +1 -4
  33. package/src/index.ts +6 -6
  34. package/src/{makeUseStyles/createUseStylesTheme.js → make-use-styles/create-use-styles-theme.js} +23 -6
  35. package/src/{makeUseStyles/createUseStylesTheme.test.js → make-use-styles/create-use-styles-theme.test.js} +1 -1
  36. package/src/{makeUseStyles/createUseStylesWithoutTheme.js → make-use-styles/create-use-styles-without-theme.js} +20 -4
  37. package/src/make-use-styles/index.d.ts +20 -0
  38. package/src/make-use-styles/index.js +12 -0
  39. package/src/make-use-styles/types.ts +43 -0
  40. package/src/{makeUseStyles → make-use-styles}/utils.js +7 -12
  41. package/src/media-query/base.ts +19 -30
  42. package/src/media-query/breakpoints.ts +12 -37
  43. package/src/orientation.ts +3 -7
  44. package/src/safe-area/{eventEmitter.ts → event-emitter.ts} +1 -1
  45. package/src/safe-area/index.tsx +3 -3
  46. package/src/safe-area/init.tsx +2 -2
  47. package/src/safe-area/safe-area-provider.tsx +18 -0
  48. package/src/safe-area/{StylexSaveAreaConsumer.ts → stylex-save-area-consumer.ts} +4 -5
  49. package/src/safe-area/types.ts +2 -2
  50. package/src/{__tests__ → tests}/createEventEmitter.test.ts +1 -1
  51. package/src/{__tests__ → tests}/dependencyRegistry.test.ts +1 -1
  52. package/src/{__tests__ → tests}/dependencyUsage.test.ts +1 -1
  53. package/src/{__tests__ → tests}/dimensions.test.ts +4 -7
  54. package/src/{__tests__ → tests}/makeUseStyles.types-test.ts +1 -1
  55. package/src/{__tests__ → tests}/media-query.test.ts +1 -9
  56. package/src/{__tests__ → tests}/useTheme.test.ts +1 -1
  57. package/src/{__tests__ → tests}/withStyles.types-test.tsx +7 -8
  58. package/src/{useColorTransition.ts → use-color-transition.ts} +3 -3
  59. package/src/{useTheme.ts → use-theme.ts} +2 -4
  60. package/src/with-styles.tsx +22 -0
  61. package/tsconfig.build.json +31 -0
  62. package/src/makeUseStyles/index.d.ts +0 -7
  63. package/src/makeUseStyles/index.js +0 -12
  64. package/src/safe-area/SafeAreaProvider.tsx +0 -17
  65. package/src/withStyles.tsx +0 -35
  66. /package/src/{createEventEmitter.ts → create-event-emitter.ts} +0 -0
  67. /package/src/{DefaultTheme.ts → default-theme.ts} +0 -0
  68. /package/src/{dependencyRegistry.ts → dependency-registry.ts} +0 -0
  69. /package/src/{makeUseStyles/createUseStylesWithoutTheme.test.js → make-use-styles/create-use-styles-without-theme.test.js} +0 -0
  70. /package/src/{makeUseStyles → make-use-styles}/index.test.js +0 -0
  71. /package/src/{makeUseStyles → make-use-styles}/test-type.js +0 -0
  72. /package/src/{__tests__ → tests}/createBreakpoints.test.ts +0 -0
  73. /package/src/{__tests__ → tests}/createBreakpointsMatcher.test.ts +0 -0
  74. /package/src/{__tests__ → tests}/createBreakpointsMatcher.types-test.ts +0 -0
  75. /package/src/{__tests__ → tests}/dark-mode.test.ts +0 -0
  76. /package/src/{__tests__ → tests}/orientation.test.ts +0 -0
@@ -1,16 +1,13 @@
1
1
  import "./init";
2
2
 
3
- import { onUse } from "../dependencyUsage";
3
+ import { onUse } from "../dependency-usage";
4
4
 
5
5
  import { UI_MODE_DEPENDENCY_KEY } from "./consts";
6
6
  import { state } from "./state";
7
7
 
8
8
  export type UiType = "dark" | "light";
9
9
 
10
- export function uiMode<T>({
11
- dark,
12
- light,
13
- }: { [mode in UiType]?: T }): T | undefined {
10
+ export function uiMode<T>({ dark, light }: { [mode in UiType]?: T }): T | undefined {
14
11
  onUse(UI_MODE_DEPENDENCY_KEY);
15
12
 
16
13
  if (state.mode === "dark") {
@@ -1,7 +1,7 @@
1
1
  import { eventEmitter, Mode } from "react-native-dark-mode";
2
2
 
3
- import { addDependency } from "../dependencyRegistry";
4
- import { createEventEmitter } from "../createEventEmitter";
3
+ import { addDependency } from "../dependency-registry";
4
+ import { createEventEmitter } from "../create-event-emitter";
5
5
 
6
6
  import { UI_MODE_DEPENDENCY_KEY } from "./consts";
7
7
  import { state } from "./state";
@@ -19,13 +19,3 @@ export function getUsing(): UsingSpec {
19
19
  export function onUse(name: string): void {
20
20
  ref.current[name] = true;
21
21
  }
22
-
23
- interface Button {
24
- variant: "primary" | "danger"
25
- onAction: () => void
26
- }
27
-
28
- // onAction -> onClick
29
- // onAction -> onPress
30
-
31
-
@@ -2,7 +2,7 @@ import "./init";
2
2
 
3
3
  import { Dimensions, ScaledSize } from "react-native";
4
4
 
5
- import { onUse } from "../dependencyUsage";
5
+ import { onUse } from "../dependency-usage";
6
6
  import { WINDOW_DEPENDENCY_KEY, SCREEN_DEPENDENCY_KEY } from "./consts";
7
7
 
8
8
  const get = (dim: "window" | "screen") => Dimensions.get(dim);
@@ -1,7 +1,7 @@
1
1
  import { Dimensions, ScaledSize } from "react-native";
2
2
 
3
- import { createEventEmitter } from "../createEventEmitter";
4
- import { addDependency } from "../dependencyRegistry";
3
+ import { createEventEmitter } from "../create-event-emitter";
4
+ import { addDependency } from "../dependency-registry";
5
5
  import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
6
6
 
7
7
  const { get, addEventListener } = Dimensions;
@@ -11,16 +11,11 @@ const state = { window: get("window"), screen: get("screen") };
11
11
  const windowEventEmitter = createEventEmitter(WINDOW_DEPENDENCY_KEY);
12
12
  const screenEventEmitter = createEventEmitter(SCREEN_DEPENDENCY_KEY);
13
13
 
14
- const isNotEqual = (a: ScaledSize, b: ScaledSize) =>
15
- a.width !== b.width || a.height !== b.height;
14
+ const isNotEqual = (a: ScaledSize, b: ScaledSize) => a.width !== b.width || a.height !== b.height;
16
15
 
17
- addDependency(WINDOW_DEPENDENCY_KEY, (handler: () => void) =>
18
- windowEventEmitter.on(handler)
19
- );
16
+ addDependency(WINDOW_DEPENDENCY_KEY, (handler: () => void) => windowEventEmitter.on(handler));
20
17
 
21
- addDependency(SCREEN_DEPENDENCY_KEY, (handler: () => void) =>
22
- screenEventEmitter.on(handler)
23
- );
18
+ addDependency(SCREEN_DEPENDENCY_KEY, (handler: () => void) => screenEventEmitter.on(handler));
24
19
 
25
20
  addEventListener("change", ({ window, screen }) => {
26
21
  if (isNotEqual(screen, state.screen)) {
@@ -1,8 +1,6 @@
1
1
  import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
2
2
 
3
- export const optimizeDependencies = (
4
- keys: Record<string, boolean>
5
- ): Record<string, boolean> => {
3
+ export const optimizeDependencies = (keys: Record<string, boolean>): Record<string, boolean> => {
6
4
  if (keys[WINDOW_DEPENDENCY_KEY] && keys[SCREEN_DEPENDENCY_KEY]) {
7
5
  delete keys[SCREEN_DEPENDENCY_KEY];
8
6
  }
package/src/i18n.ts CHANGED
@@ -2,10 +2,7 @@ import { I18nManager } from "react-native";
2
2
 
3
3
  type LayoutDirectionType = "rtl" | "ltr";
4
4
 
5
- export function i18n<T>({
6
- rtl,
7
- ltr,
8
- }: { [direction in LayoutDirectionType]?: T }): T | undefined {
5
+ export function i18n<T>({ rtl, ltr }: { [direction in LayoutDirectionType]?: T }): T | undefined {
9
6
  if (I18nManager.isRTL) {
10
7
  return rtl;
11
8
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { useTheme } from "./useTheme";
2
- export { withStyles } from "./withStyles";
1
+ export { useTheme } from "./use-theme";
2
+ export { withStyles } from "./with-styles";
3
3
  export { ThemeProvider, ThemeConsumer } from "./context";
4
- export { useColorTransition } from "./useColorTransition";
5
- export { makeUseStyles } from "./makeUseStyles";
6
- export type { DefaultTheme } from "./DefaultTheme";
7
- export type { InferInjectedStyledProps } from "./withStyles";
4
+ export { useColorTransition } from "./use-color-transition";
5
+ export { makeUseStyles } from "./make-use-styles";
6
+ export type { DefaultTheme } from "./default-theme";
7
+ export type { InferInjectedStyledProps } from "./with-styles";
@@ -1,9 +1,9 @@
1
1
  import { StyleSheet } from "react-native";
2
- import { useTheme } from "../useTheme";
3
- import { resetUsing } from "../dependencyUsage";
2
+ import { useTheme } from "../use-theme";
3
+ import { resetUsing } from "../dependency-usage";
4
4
  import { getDependenciesKeys, useForceUpdate, subscribe } from "./utils";
5
5
 
6
- export function createUseStylesTheme(getStyles) {
6
+ export function createUseStylesTheme(getStyles, getVariants) {
7
7
  const scope = {
8
8
  styles: new WeakMap(),
9
9
  forceUpdate: [],
@@ -20,7 +20,7 @@ export function createUseStylesTheme(getStyles) {
20
20
  scope.unsubscribe();
21
21
  resetUsing();
22
22
 
23
- const style = StyleSheet.create(getStyles(theme));
23
+ const style = StyleSheet.create(getStyles?.(theme) ?? {});
24
24
  const keys = getDependenciesKeys();
25
25
 
26
26
  scope.unsubscribe = subscribe(keys, onUpdate);
@@ -28,7 +28,7 @@ export function createUseStylesTheme(getStyles) {
28
28
  return style;
29
29
  }
30
30
 
31
- return function useStyles() {
31
+ function useStyles(variants) {
32
32
  const theme = useTheme();
33
33
 
34
34
  useForceUpdate(scope);
@@ -37,6 +37,23 @@ export function createUseStylesTheme(getStyles) {
37
37
  scope.styles.set(theme, initStyle(theme));
38
38
  }
39
39
 
40
+ if (getVariants) {
41
+ const configVariants = getVariants(theme);
42
+ const requestedVarians = {};
43
+
44
+ for (const key in variants) {
45
+ const value = configVariants[key][variants[key]];
46
+ Object.assign(requestedVarians, value);
47
+ }
48
+
49
+ return {
50
+ ...scope.styles.get(theme),
51
+ ...StyleSheet.create({ variants: requestedVarians }),
52
+ };
53
+ }
54
+
40
55
  return scope.styles.get(theme);
41
- };
56
+ }
57
+
58
+ return useStyles;
42
59
  }
@@ -38,7 +38,7 @@ it("should create styles once", () => {
38
38
  {
39
39
  wrapper: ThemeProvider,
40
40
  initialProps: { value: theme },
41
- }
41
+ },
42
42
  );
43
43
 
44
44
  expect(mockGetStyles).toHaveBeenCalledTimes(1);
@@ -1,10 +1,11 @@
1
1
  import { StyleSheet } from "react-native";
2
- import { resetUsing } from "../dependencyUsage";
2
+ import { resetUsing } from "../dependency-usage";
3
3
  import { getDependenciesKeys, subscribe, useForceUpdate } from "./utils";
4
4
 
5
- export function createUseStylesWithoutTheme(getStyles) {
5
+ export function createUseStylesWithoutTheme(getStyles, getVariants) {
6
6
  const scope = {
7
7
  style: null,
8
+ variants: null,
8
9
  forceUpdate: [],
9
10
  unsubscribe: () => {},
10
11
  };
@@ -19,7 +20,7 @@ export function createUseStylesWithoutTheme(getStyles) {
19
20
  scope.unsubscribe();
20
21
  resetUsing();
21
22
 
22
- scope.style = StyleSheet.create(getStyles());
23
+ scope.style = StyleSheet.create(getStyles?.() ?? {});
23
24
 
24
25
  const keys = getDependenciesKeys();
25
26
 
@@ -28,9 +29,24 @@ export function createUseStylesWithoutTheme(getStyles) {
28
29
 
29
30
  initStyle();
30
31
 
31
- function useStyles() {
32
+ function useStyles(variants) {
32
33
  useForceUpdate(scope);
33
34
 
35
+ if (getVariants) {
36
+ const configVariants = getVariants();
37
+ const requestedVarians = {};
38
+
39
+ for (const key in variants) {
40
+ const value = configVariants[key][variants[key]];
41
+ Object.assign(requestedVarians, value);
42
+ }
43
+
44
+ return {
45
+ ...scope.style,
46
+ ...StyleSheet.create({ variants: requestedVarians }),
47
+ };
48
+ }
49
+
34
50
  return scope.style;
35
51
  }
36
52
 
@@ -0,0 +1,20 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { DefaultTheme } from "../default-theme";
3
+
4
+ export function makeUseStyles<
5
+ Theme extends DefaultTheme,
6
+ T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>,
7
+ VariantsConfig extends Record<string, StyleSheet.NamedStyles<any>> | undefined = undefined,
8
+ >(config: {
9
+ styles?: (theme: Theme) => T | StyleSheet.NamedStyles<T>;
10
+ variants?: ((theme: Theme) => VariantsConfig) | undefined;
11
+ }): <Variants extends { [Key in keyof VariantsConfig]: keyof VariantsConfig[Key] }>(
12
+ variants?: Partial<Variants>,
13
+ ) => T &
14
+ (VariantsConfig extends undefined
15
+ ? {}
16
+ : {
17
+ variants: {
18
+ [VKey in keyof Variants]: VKey extends keyof VariantsConfig ? VariantsConfig[VKey][Variants[VKey]] : never;
19
+ }[keyof Variants];
20
+ });
@@ -0,0 +1,12 @@
1
+ import { createUseStylesWithoutTheme } from "./create-use-styles-without-theme";
2
+ import { createUseStylesTheme } from "./create-use-styles-theme";
3
+
4
+ export function makeUseStyles({ styles, variants }) {
5
+ const hasThemeDependency = styles?.length === 1;
6
+
7
+ if (!hasThemeDependency) {
8
+ return createUseStylesWithoutTheme(styles, variants);
9
+ }
10
+
11
+ return createUseStylesTheme(styles);
12
+ }
@@ -0,0 +1,43 @@
1
+ // import { StyleSheet } from "react-native";
2
+ // import { DefaultTheme } from "../DefaultTheme";
3
+
4
+ // // // Source - https://stackoverflow.com/a/50375286
5
+ // // // Posted by jcalz, modified by community. See post 'Timeline' for change history
6
+ // // // Retrieved 2026-01-07, License - CC BY-SA 4.0
7
+
8
+ // // type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
9
+ // // x: infer I,
10
+ // // ) => void
11
+ // // ? I
12
+ // // : never;
13
+
14
+ // export function makeUseStyles<
15
+ // Theme extends DefaultTheme,
16
+ // T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>,
17
+ // V extends Record<string, StyleSheet.NamedStyles<any>>,
18
+ // >(
19
+ // getStyles: (theme: Theme) => T | StyleSheet.NamedStyles<T>,
20
+ // variants: V,
21
+ // ): <Variants extends { [Key in keyof V]: keyof V[Key] }>(
22
+ // variants?: Partial<Variants>,
23
+ // ) => T & {
24
+ // variants: {
25
+ // [VKey in keyof Variants]: VKey extends keyof V
26
+ // ? V[VKey][Variants[VKey]]
27
+ // : never;
28
+ // }[keyof Variants];
29
+ // } {
30
+ // return ((variants: any) => {}) as any;
31
+ // }
32
+
33
+ // const useStyles = makeUseStyles(() => ({ some: { alignContent: "center" } }), {
34
+ // other: {
35
+ // one: { alignContent: "flex-end", fontStyle: "italic", fontFamily: "Inter" },
36
+ // two: { alignContent: "flex-end" },
37
+ // },
38
+ // more: {
39
+ // lol: { color: "red", width: 123 },
40
+ // },
41
+ // });
42
+
43
+ // const res = useStyles({ more: "lol"});
@@ -1,6 +1,6 @@
1
1
  import { optimizeDependencies } from "../dimensions/utils";
2
- import { getUsing } from "../dependencyUsage";
3
- import { getDependency } from "../dependencyRegistry";
2
+ import { getUsing } from "../dependency-usage";
3
+ import { getDependency } from "../dependency-registry";
4
4
 
5
5
  import { useEffect, useRef, useState } from "react";
6
6
 
@@ -17,9 +17,7 @@ export const useForceUpdate = (scope) => {
17
17
  scope.forceUpdate = scope.forceUpdate.concat(forceRerender);
18
18
 
19
19
  unsubscribeRef.current = () => {
20
- scope.forceUpdate = scope.forceUpdate.filter(
21
- (fn) => fn !== forceRerender
22
- );
20
+ scope.forceUpdate = scope.forceUpdate.filter((fn) => fn !== forceRerender);
23
21
  };
24
22
  }
25
23
 
@@ -28,12 +26,11 @@ export const useForceUpdate = (scope) => {
28
26
  unsubscribeRef.current();
29
27
  unsubscribeRef.current = noop;
30
28
  },
31
- []
29
+ [],
32
30
  );
33
31
  };
34
32
 
35
- export const getDependenciesKeys = () =>
36
- Object.keys(optimizeDependencies(getUsing())).sort();
33
+ export const getDependenciesKeys = () => Object.keys(optimizeDependencies(getUsing())).sort();
37
34
 
38
35
  export const subscribe = (dependenciesKeys, handler) => {
39
36
  if (dependenciesKeys.length === 0) {
@@ -50,14 +47,12 @@ export const subscribe = (dependenciesKeys, handler) => {
50
47
  const dependencyName = dependenciesKeys[index];
51
48
 
52
49
  if (!onChange) {
53
- console.warn(
54
- `[react-native-stylex] Could not find onChange handler for ${dependencyName}!`
55
- );
50
+ console.warn(`[react-native-stylex] Could not find onChange handler for ${dependencyName}!`);
56
51
  }
57
52
 
58
53
  return !!onChange;
59
54
  }
60
- : Boolean
55
+ : Boolean,
61
56
  )
62
57
  .map((onChange) => onChange(handler));
63
58
 
@@ -2,42 +2,31 @@ import { ScaledSize } from "react-native";
2
2
 
3
3
  import { getWindowDimensions } from "../dimensions";
4
4
 
5
- export const createDimensionQueryHelper = <Value>(
6
- queryFunction: (options: { value: Value; dimensions: ScaledSize }) => boolean
7
- ) => <T>(value: Value, styles: T): null | T => {
8
- const isMatched = queryFunction({ value, dimensions: getWindowDimensions() });
5
+ export const createDimensionQueryHelper =
6
+ <Value>(queryFunction: (options: { value: Value; dimensions: ScaledSize }) => boolean) =>
7
+ <T>(value: Value, styles: T): null | T => {
8
+ const isMatched = queryFunction({
9
+ value,
10
+ dimensions: getWindowDimensions(),
11
+ });
9
12
 
10
- if (isMatched) {
11
- return styles;
12
- }
13
+ if (isMatched) {
14
+ return styles;
15
+ }
13
16
 
14
- return null;
15
- };
17
+ return null;
18
+ };
16
19
 
17
- export const maxHeight = createDimensionQueryHelper<number>(
18
- ({ value, dimensions }) => value >= dimensions.height
19
- );
20
+ export const maxHeight = createDimensionQueryHelper<number>(({ value, dimensions }) => value >= dimensions.height);
20
21
 
21
- export const maxWidth = createDimensionQueryHelper<number>(
22
- ({ value, dimensions }) => value >= dimensions.width
23
- );
22
+ export const maxWidth = createDimensionQueryHelper<number>(({ value, dimensions }) => value >= dimensions.width);
24
23
 
25
- export const minHeight = createDimensionQueryHelper<number>(
26
- ({ value, dimensions }) => value <= dimensions.height
27
- );
24
+ export const minHeight = createDimensionQueryHelper<number>(({ value, dimensions }) => value <= dimensions.height);
28
25
 
29
- export const minWidth = createDimensionQueryHelper<number>(
30
- ({ value, dimensions }) => value <= dimensions.width
31
- );
26
+ export const minWidth = createDimensionQueryHelper<number>(({ value, dimensions }) => value <= dimensions.width);
32
27
 
33
- export const minAspectRatio = createDimensionQueryHelper<number>(
34
- ({ value, dimensions: { width, height } }) => value <= width / height
35
- );
28
+ export const minAspectRatio = createDimensionQueryHelper<number>(({ value, dimensions: { width, height } }) => value <= width / height);
36
29
 
37
- export const maxAspectRatio = createDimensionQueryHelper<number>(
38
- ({ value, dimensions: { width, height } }) => value >= width / height
39
- );
30
+ export const maxAspectRatio = createDimensionQueryHelper<number>(({ value, dimensions: { width, height } }) => value >= width / height);
40
31
 
41
- export const aspectRatio = createDimensionQueryHelper<number>(
42
- ({ value, dimensions: { width, height } }) => value === width / height
43
- );
32
+ export const aspectRatio = createDimensionQueryHelper<number>(({ value, dimensions: { width, height } }) => value === width / height);
@@ -10,7 +10,7 @@ const orderByMin = [minWidth, minAspectRatio, minHeight];
10
10
  const toOrderedBreakpointNames = <TBreakpoints extends Record<string, number>>(
11
11
  values: any,
12
12
  breakpoints: any,
13
- matchFunction: any
13
+ matchFunction: any,
14
14
  ): Array<keyof TBreakpoints> => {
15
15
  const result = Object.keys(values)
16
16
  .filter((e) => e !== "default")
@@ -26,15 +26,13 @@ const toOrderedBreakpointNames = <TBreakpoints extends Record<string, number>>(
26
26
  /*
27
27
  * To debug use analog on CSS: https://codepen.io/retyui/pen/dyOzKzV
28
28
  */
29
- export function createBreakpointsMatcher<
30
- TBreakpoints extends Record<string, number>
31
- >(
29
+ export function createBreakpointsMatcher<TBreakpoints extends Record<string, number>>(
32
30
  breakpoints: TBreakpoints,
33
- matchFunction = minWidth
31
+ matchFunction = minWidth,
34
32
  ): BreakpointsMatcher<TBreakpoints> {
35
33
  return function breakpointsMatcher(values: any) {
36
34
  /* istanbul ignore next */
37
- // @ts-expect-error: was removed
35
+ // @ts-expect-error
38
36
  if (process.env.NODE_ENV !== "production") {
39
37
  const invalidKeys = Object.keys(values).filter((key) => {
40
38
  return key !== "default" && breakpoints[key] === undefined;
@@ -46,47 +44,30 @@ export function createBreakpointsMatcher<
46
44
 
47
45
  allowed keys: ${Object.keys(breakpoints).join(", ")}
48
46
  unexpected keys: ${invalidKeys.join(", ")}
49
- `
47
+ `,
50
48
  );
51
49
  }
52
50
  }
53
51
 
54
- const orderedBreakpointNames = toOrderedBreakpointNames<TBreakpoints>(
55
- values,
56
- breakpoints,
57
- matchFunction
58
- );
52
+ const orderedBreakpointNames = toOrderedBreakpointNames<TBreakpoints>(values, breakpoints, matchFunction);
59
53
 
60
- const key =
61
- orderedBreakpointNames.find((breakpointName) =>
62
- matchFunction(
63
- breakpoints[breakpointName] as number,
64
- values[breakpointName]
65
- )
66
- ) || "default";
54
+ const key = orderedBreakpointNames.find((breakpointName) => matchFunction(breakpoints[breakpointName] as number, values[breakpointName])) || "default";
67
55
 
68
56
  return values[key] || null;
69
57
  };
70
58
  }
71
59
 
72
- function getNextByKey<TBreakpoints extends Record<string, number>>(
73
- breakpoints: TBreakpoints,
74
- key: keyof TBreakpoints
75
- ) {
60
+ function getNextByKey<TBreakpoints extends Record<string, number>>(breakpoints: TBreakpoints, key: keyof TBreakpoints) {
76
61
  type Keys = keyof TBreakpoints;
77
62
 
78
- const breakpointsKeys: Array<Keys> = Object.keys(breakpoints).sort(
79
- (a: Keys, b: Keys) => breakpoints[a]! - breakpoints[b]!
80
- );
63
+ const breakpointsKeys: Array<Keys> = Object.keys(breakpoints).sort((a: Keys, b: Keys) => breakpoints[a]! - breakpoints[b]!);
81
64
  const index = breakpointsKeys.indexOf(key);
82
65
  const nextKey: Keys | undefined = breakpointsKeys[index + 1];
83
66
 
84
67
  return nextKey;
85
68
  }
86
69
 
87
- export function createBreakpoints<TBreakpoints extends Record<string, number>>(
88
- breakpoints: TBreakpoints
89
- ) {
70
+ export function createBreakpoints<TBreakpoints extends Record<string, number>>(breakpoints: TBreakpoints) {
90
71
  type Keys = keyof TBreakpoints;
91
72
 
92
73
  function up<T>(key: Keys, value: T): T | null {
@@ -101,20 +82,14 @@ export function createBreakpoints<TBreakpoints extends Record<string, number>>(
101
82
  const nextKey = getNextByKey<TBreakpoints>(breakpoints, key);
102
83
 
103
84
  if (nextKey !== undefined) {
104
- return minWidth(
105
- breakpoints[key] as number,
106
- maxWidth(breakpoints[nextKey]! - 0.05, value)
107
- );
85
+ return minWidth(breakpoints[key] as number, maxWidth(breakpoints[nextKey]! - 0.05, value));
108
86
  }
109
87
 
110
88
  return minWidth(breakpoints[key] as number, value);
111
89
  }
112
90
 
113
91
  function between<T>(start: Keys, end: Keys, value: T): T | null {
114
- return minWidth(
115
- breakpoints[start] as number,
116
- maxWidth(breakpoints[end]! - 0.05, value)
117
- );
92
+ return minWidth(breakpoints[start] as number, maxWidth(breakpoints[end]! - 0.05, value));
118
93
  }
119
94
 
120
95
  return { up, down, only, between };
@@ -2,16 +2,12 @@ import { getScreenDimensions } from "./dimensions";
2
2
 
3
3
  type OrientationType = "portrait" | "landscape";
4
4
 
5
- export function orientation<T>(
6
- spec: { [orientation in OrientationType]?: T }
7
- ): T | undefined {
5
+ export function orientation<T>(spec: { [orientation in OrientationType]?: T }): T | undefined {
8
6
  const { height, width } = getScreenDimensions();
9
7
 
10
8
  return width <= height ? spec.portrait : spec.landscape;
11
9
  }
12
10
 
13
- export const portraitOrientation = <T>(portraitStyles: T): T | undefined =>
14
- orientation<T>({ portrait: portraitStyles });
11
+ export const portraitOrientation = <T>(portraitStyles: T): T | undefined => orientation<T>({ portrait: portraitStyles });
15
12
 
16
- export const landscapeOrientation = <T>(landscapeStyles: T): T | undefined =>
17
- orientation<T>({ landscape: landscapeStyles });
13
+ export const landscapeOrientation = <T>(landscapeStyles: T): T | undefined => orientation<T>({ landscape: landscapeStyles });
@@ -1,4 +1,4 @@
1
- import { createEventEmitter } from "../createEventEmitter";
1
+ import { createEventEmitter } from "../create-event-emitter";
2
2
  import { SAFE_AREA_DEPENDENCY_KEY } from "./consts";
3
3
 
4
4
  export const { emit, on } = createEventEmitter(SAFE_AREA_DEPENDENCY_KEY);
@@ -1,13 +1,13 @@
1
1
  import "./init";
2
2
 
3
- import { onUse } from "../dependencyUsage";
3
+ import { onUse } from "../dependency-usage";
4
4
 
5
5
  import { SAFE_AREA_DEPENDENCY_KEY } from "./consts";
6
6
  import { EdgeInsets } from "./types";
7
7
  import { state } from "./state";
8
8
 
9
- export { StylexSaveAreaConsumer } from "./StylexSaveAreaConsumer";
10
- export { SafeAreaProvider } from "./SafeAreaProvider";
9
+ export { StylexSaveAreaConsumer } from "./stylex-save-area-consumer";
10
+ export { SafeAreaProvider } from "./safe-area-provider";
11
11
 
12
12
  export function getSafeArea(): EdgeInsets {
13
13
  onUse(SAFE_AREA_DEPENDENCY_KEY);
@@ -1,6 +1,6 @@
1
- import { addDependency } from "../dependencyRegistry";
1
+ import { addDependency } from "../dependency-registry";
2
2
 
3
3
  import { SAFE_AREA_DEPENDENCY_KEY } from "./consts";
4
- import { on } from "./eventEmitter";
4
+ import { on } from "./event-emitter";
5
5
 
6
6
  addDependency(SAFE_AREA_DEPENDENCY_KEY, (handler: () => void) => on(handler));
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { SafeAreaProvider as CoreSafeAreaProvider, initialWindowMetrics, initialWindowSafeAreaInsets } from "react-native-safe-area-context";
3
+
4
+ import { StylexSaveAreaConsumer } from "./stylex-save-area-consumer";
5
+ import { SafeAreaViewProps } from "./types";
6
+
7
+ export function SafeAreaProvider(props: SafeAreaViewProps): React.JSX.Element | null {
8
+ return (
9
+ <CoreSafeAreaProvider
10
+ initialSafeAreaInsets={props.initialSafeAreaInsets || initialWindowSafeAreaInsets}
11
+ initialMetrics={props.initialMetrics || initialWindowMetrics}
12
+ {...props}
13
+ >
14
+ {props.children}
15
+ <StylexSaveAreaConsumer />
16
+ </CoreSafeAreaProvider>
17
+ );
18
+ }
@@ -1,17 +1,16 @@
1
1
  import { useSafeAreaInsets } from "react-native-safe-area-context";
2
2
  import { EdgeInsets } from "./types";
3
3
 
4
- import { emit } from "./eventEmitter";
4
+ import { emit } from "./event-emitter";
5
5
  import { state } from "./state";
6
6
  import { useLayoutEffect } from "react";
7
+ import type React from "react";
7
8
 
8
- export function StylexSaveAreaConsumer(): JSX.Element | null {
9
+ export function StylexSaveAreaConsumer(): React.JSX.Element | null {
9
10
  const insets: EdgeInsets = useSafeAreaInsets();
10
11
 
11
12
  useLayoutEffect(() => {
12
- const isChanged = Object.entries(insets).some(
13
- ([key, value]) => state.insets[key as keyof EdgeInsets] !== value
14
- );
13
+ const isChanged = Object.entries(insets).some(([key, value]) => state.insets[key as keyof EdgeInsets] !== value);
15
14
 
16
15
  if (isChanged) {
17
16
  state.insets = insets;
@@ -1,4 +1,4 @@
1
- import {SafeAreaProviderProps} from "react-native-safe-area-context";
1
+ import { SafeAreaProviderProps } from "react-native-safe-area-context";
2
2
 
3
3
  export interface EdgeInsets {
4
4
  top: number;
@@ -7,4 +7,4 @@ export interface EdgeInsets {
7
7
  left: number;
8
8
  }
9
9
 
10
- export interface SafeAreaViewProps extends SafeAreaProviderProps { }
10
+ export interface SafeAreaViewProps extends SafeAreaProviderProps {}
@@ -1,4 +1,4 @@
1
- import { createEventEmitter } from "../createEventEmitter";
1
+ import { createEventEmitter } from "../create-event-emitter";
2
2
 
3
3
  it("should call handler when invoke emit", () => {
4
4
  const a = createEventEmitter("event");