@codeandmoney/soelma 0.0.0-dev.0 → 0.0.0-dev.1
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.
- package/DefaultTheme.d.ts +2 -0
- package/DefaultTheme.js +1 -0
- package/appearance/consts.d.ts +1 -0
- package/appearance/index.d.ts +8 -0
- package/appearance/index.js +18 -0
- package/appearance/init.d.ts +1 -0
- package/{src/appearance/init.ts → appearance/init.js} +1 -6
- package/context.d.ts +4 -0
- package/context.js +3 -0
- package/createEventEmitter.d.ts +8 -0
- package/createEventEmitter.js +11 -0
- package/dark-mode/consts.d.ts +1 -0
- package/dark-mode/index.d.ts +7 -0
- package/dark-mode/index.js +16 -0
- package/dark-mode/init.d.ts +1 -0
- package/dark-mode/init.js +13 -0
- package/dark-mode/state.d.ts +3 -0
- package/{src/dark-mode/state.ts → dark-mode/state.js} +1 -2
- package/dependencyRegistry.d.ts +5 -0
- package/dependencyRegistry.js +12 -0
- package/dependencyUsage.d.ts +7 -0
- package/dependencyUsage.js +10 -0
- package/dimensions/consts.d.ts +2 -0
- package/dimensions/index.d.ts +4 -0
- package/dimensions/index.js +13 -0
- package/dimensions/init.d.ts +1 -0
- package/dimensions/init.js +21 -0
- package/dimensions/utils.d.ts +1 -0
- package/dimensions/utils.js +7 -0
- package/i18n.d.ts +7 -0
- package/i18n.js +9 -0
- package/index.js +5 -0
- package/{src/makeUseStyles → makeUseStyles}/index.d.ts +1 -1
- package/{src/makeUseStyles → makeUseStyles}/utils.js +4 -4
- package/media-query/base.d.ts +12 -0
- package/media-query/base.js +18 -0
- package/media-query/breakpoints.d.ts +18 -0
- package/media-query/breakpoints.js +60 -0
- package/media-query/index.d.ts +2 -0
- package/media-query/index.js +2 -0
- package/orientation.d.ts +7 -0
- package/orientation.js +7 -0
- package/package.json +6 -37
- package/safe-area/SafeAreaProvider.d.ts +3 -0
- package/safe-area/SafeAreaProvider.js +9 -0
- package/safe-area/StylexSaveAreaConsumer.d.ts +2 -0
- package/safe-area/StylexSaveAreaConsumer.js +15 -0
- package/safe-area/consts.d.ts +1 -0
- package/safe-area/eventEmitter.d.ts +1 -0
- package/{src/safe-area/eventEmitter.ts → safe-area/eventEmitter.js} +0 -1
- package/safe-area/index.d.ts +5 -0
- package/{src/safe-area/index.tsx → safe-area/index.js} +3 -9
- package/safe-area/init.d.ts +1 -0
- package/{src/safe-area/init.tsx → safe-area/init.js} +1 -3
- package/safe-area/state.d.ts +8 -0
- package/{src/safe-area/state.ts → safe-area/state.js} +5 -7
- package/safe-area/types.d.ts +9 -0
- package/safe-area/types.js +1 -0
- package/useColorTransition.d.ts +5 -0
- package/useColorTransition.js +38 -0
- package/useTheme.d.ts +2 -0
- package/useTheme.js +9 -0
- package/withStyles.d.ts +7 -0
- package/withStyles.js +13 -0
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -31
- package/.github/workflows/nodejs.yml +0 -33
- package/.size-limit.json +0 -6
- package/babel.config.js +0 -3
- package/docs/api.md +0 -103
- package/docs/appearance.md +0 -54
- package/docs/dark-mode.md +0 -46
- package/docs/dimensions.md +0 -29
- package/docs/i18n.md +0 -67
- package/docs/logo.png +0 -0
- package/docs/media-query.md +0 -274
- package/docs/orientation.md +0 -44
- package/docs/safe-area.md +0 -62
- package/docs/testting.md +0 -51
- package/docs/ts.md +0 -127
- package/example/AppStyleX/.watchmanconfig +0 -1
- package/example/AppStyleX/android/build.gradle +0 -26
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.properties +0 -7
- package/example/AppStyleX/android/gradle.properties +0 -53
- package/example/AppStyleX/android/gradlew +0 -249
- package/example/AppStyleX/android/gradlew.bat +0 -92
- package/example/AppStyleX/android/settings.gradle +0 -12
- package/example/AppStyleX/app.json +0 -28
- package/example/AppStyleX/babel.config.js +0 -3
- package/example/AppStyleX/index.js +0 -9
- package/example/AppStyleX/ios/Podfile +0 -7
- package/example/AppStyleX/ios/Podfile.lock +0 -1252
- package/example/AppStyleX/metro.config.js +0 -54
- package/example/AppStyleX/package.json +0 -43
- package/example/AppStyleX/react-native.config.js +0 -23
- package/example/AppStyleX/src/App.tsx +0 -25
- package/example/AppStyleX/src/BottomNav/index.tsx +0 -32
- package/example/AppStyleX/src/BottomNav/styles.ts +0 -42
- package/example/AppStyleX/src/Circle/index.tsx +0 -53
- package/example/AppStyleX/src/Circle/styles.ts +0 -22
- package/example/AppStyleX/src/Root/index.tsx +0 -41
- package/example/AppStyleX/src/Root/styles.ts +0 -18
- package/example/AppStyleX/src/ToggleButton/index.tsx +0 -66
- package/example/AppStyleX/src/ToggleButton/styles.ts +0 -69
- package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +0 -5
- package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +0 -5
- package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +0 -8
- package/example/AppStyleX/src/style-system/palette.ts +0 -11
- package/example/AppStyleX/src/style-system/theme.ts +0 -14
- package/example/AppStyleX/src/style-system/utils.ts +0 -11
- package/example/AppStyleX/src/stylex.d.ts +0 -6
- package/example/AppStyleX/tsconfig.json +0 -3
- package/example/AppStyleX/yarn.lock +0 -6767
- package/jest.config.js +0 -19
- package/src/DefaultTheme.ts +0 -4
- package/src/__tests__/createBreakpoints.test.ts +0 -152
- package/src/__tests__/createBreakpointsMatcher.test.ts +0 -188
- package/src/__tests__/createBreakpointsMatcher.types-test.ts +0 -81
- package/src/__tests__/createEventEmitter.test.ts +0 -37
- package/src/__tests__/dark-mode.test.ts +0 -56
- package/src/__tests__/dependencyRegistry.test.ts +0 -16
- package/src/__tests__/dependencyUsage.test.ts +0 -13
- package/src/__tests__/dimensions.test.ts +0 -36
- package/src/__tests__/makeUseStyles.types-test.ts +0 -69
- package/src/__tests__/media-query.test.ts +0 -204
- package/src/__tests__/orientation.test.ts +0 -61
- package/src/__tests__/useTheme.test.ts +0 -26
- package/src/__tests__/withStyles.types-test.tsx +0 -173
- package/src/appearance/index.ts +0 -37
- package/src/context.ts +0 -9
- package/src/createEventEmitter.ts +0 -26
- package/src/dark-mode/index.ts +0 -29
- package/src/dark-mode/init.ts +0 -19
- package/src/dependencyRegistry.ts +0 -21
- package/src/dependencyUsage.ts +0 -31
- package/src/dimensions/index.ts +0 -20
- package/src/dimensions/init.ts +0 -37
- package/src/dimensions/utils.ts +0 -11
- package/src/i18n.ts +0 -18
- package/src/makeUseStyles/createUseStylesTheme.test.js +0 -137
- package/src/makeUseStyles/createUseStylesWithoutTheme.test.js +0 -63
- package/src/makeUseStyles/index.test.js +0 -28
- package/src/media-query/base.ts +0 -43
- package/src/media-query/breakpoints.ts +0 -121
- package/src/media-query/index.ts +0 -12
- package/src/orientation.ts +0 -17
- package/src/safe-area/SafeAreaProvider.tsx +0 -17
- package/src/safe-area/StylexSaveAreaConsumer.ts +0 -23
- package/src/safe-area/types.ts +0 -10
- package/src/useColorTransition.ts +0 -50
- package/src/useTheme.ts +0 -16
- package/src/withStyles.tsx +0 -35
- package/tsconfig.json +0 -30
- /package/{src/appearance/consts.ts → appearance/consts.js} +0 -0
- /package/{src/dark-mode/consts.ts → dark-mode/consts.js} +0 -0
- /package/{src/dimensions/consts.ts → dimensions/consts.js} +0 -0
- /package/{src/index.ts → index.d.ts} +0 -0
- /package/{src/makeUseStyles → makeUseStyles}/createUseStylesTheme.js +0 -0
- /package/{src/makeUseStyles → makeUseStyles}/createUseStylesWithoutTheme.js +0 -0
- /package/{src/makeUseStyles → makeUseStyles}/index.js +0 -0
- /package/{src/makeUseStyles → makeUseStyles}/test-type.js +0 -0
- /package/{src/safe-area/consts.ts → safe-area/consts.js} +0 -0
package/DefaultTheme.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UI_MODE_DEPENDENCY_KEY = "react-native-appearance";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "./init";
|
|
2
|
+
export type ColorSchemeName = "light" | "dark" | "default";
|
|
3
|
+
export declare function appearance<T>({ dark, light, default: defaultScheme, }: {
|
|
4
|
+
[mode in ColorSchemeName]?: T;
|
|
5
|
+
}): T | undefined;
|
|
6
|
+
export declare const darkAppearance: <T>(dark: T) => T | undefined;
|
|
7
|
+
export declare const lightAppearance: <T>(light: T) => T | undefined;
|
|
8
|
+
export declare const noPreferenceAppearance: <T>(defaultScheme: T) => T | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "./init";
|
|
2
|
+
import { Appearance } from "react-native";
|
|
3
|
+
import { onUse } from "../dependencyUsage";
|
|
4
|
+
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
5
|
+
export function appearance({ dark, light, default: defaultScheme, }) {
|
|
6
|
+
onUse(UI_MODE_DEPENDENCY_KEY);
|
|
7
|
+
// Note: getColorScheme() will always return light when debugging with Chrome.
|
|
8
|
+
if (Appearance.getColorScheme() === "light") {
|
|
9
|
+
return light;
|
|
10
|
+
}
|
|
11
|
+
if (Appearance.getColorScheme() === "dark") {
|
|
12
|
+
return dark;
|
|
13
|
+
}
|
|
14
|
+
return defaultScheme;
|
|
15
|
+
}
|
|
16
|
+
export const darkAppearance = (dark) => appearance({ dark });
|
|
17
|
+
export const lightAppearance = (light) => appearance({ light });
|
|
18
|
+
export const noPreferenceAppearance = (defaultScheme) => appearance({ default: defaultScheme });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { Appearance } from "react-native";
|
|
2
|
-
|
|
3
2
|
import { addDependency } from "../dependencyRegistry";
|
|
4
3
|
import { createEventEmitter } from "../createEventEmitter";
|
|
5
|
-
|
|
6
4
|
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
7
|
-
|
|
8
5
|
const { on, emit } = createEventEmitter(UI_MODE_DEPENDENCY_KEY);
|
|
9
|
-
|
|
10
|
-
addDependency(UI_MODE_DEPENDENCY_KEY, (handler: () => void) => on(handler));
|
|
11
|
-
|
|
6
|
+
addDependency(UI_MODE_DEPENDENCY_KEY, (handler) => on(handler));
|
|
12
7
|
Appearance.addChangeListener(emit);
|
package/context.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DefaultTheme } from "./DefaultTheme";
|
|
3
|
+
export declare const themeContext: import("react").Context<DefaultTheme | null>;
|
|
4
|
+
export declare const ThemeProvider: import("react").Provider<DefaultTheme | null>, ThemeConsumer: import("react").Consumer<DefaultTheme | null>;
|
package/context.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const events = {};
|
|
2
|
+
export function createEventEmitter(event) {
|
|
3
|
+
const emit = () => (events[event] || []).forEach((fn) => fn());
|
|
4
|
+
const on = (cb) => {
|
|
5
|
+
(events[event] = events[event] || []).push(cb);
|
|
6
|
+
return () => {
|
|
7
|
+
events[event] = events[event].filter((fn) => fn !== cb);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
return { on, emit };
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UI_MODE_DEPENDENCY_KEY = "react-native-dark-mode";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./init";
|
|
2
|
+
export type UiType = "dark" | "light";
|
|
3
|
+
export declare function uiMode<T>({ dark, light, }: {
|
|
4
|
+
[mode in UiType]?: T;
|
|
5
|
+
}): T | undefined;
|
|
6
|
+
export declare const darkUiMode: <T>(dark: T) => T | undefined;
|
|
7
|
+
export declare const lightUiMode: <T>(light: T) => T | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "./init";
|
|
2
|
+
import { onUse } from "../dependencyUsage";
|
|
3
|
+
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
4
|
+
import { state } from "./state";
|
|
5
|
+
export function uiMode({ dark, light, }) {
|
|
6
|
+
onUse(UI_MODE_DEPENDENCY_KEY);
|
|
7
|
+
if (state.mode === "dark") {
|
|
8
|
+
return dark;
|
|
9
|
+
}
|
|
10
|
+
if (state.mode === "light") {
|
|
11
|
+
return light;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
export const darkUiMode = (dark) => uiMode({ dark });
|
|
16
|
+
export const lightUiMode = (light) => uiMode({ light });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { eventEmitter } from "react-native-dark-mode";
|
|
2
|
+
import { addDependency } from "../dependencyRegistry";
|
|
3
|
+
import { createEventEmitter } from "../createEventEmitter";
|
|
4
|
+
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
5
|
+
import { state } from "./state";
|
|
6
|
+
const { on, emit } = createEventEmitter(UI_MODE_DEPENDENCY_KEY);
|
|
7
|
+
addDependency(UI_MODE_DEPENDENCY_KEY, (handler) => on(handler));
|
|
8
|
+
eventEmitter.on("currentModeChanged", (newMode) => {
|
|
9
|
+
if (state.mode !== newMode) {
|
|
10
|
+
state.mode = newMode;
|
|
11
|
+
emit();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const registry = {};
|
|
2
|
+
export function addDependency(name, onChange) {
|
|
3
|
+
if (!registry[name]) {
|
|
4
|
+
Object.defineProperty(registry, name, {
|
|
5
|
+
value: onChange,
|
|
6
|
+
writable: false,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function getDependency(name) {
|
|
11
|
+
return registry[name];
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "./init";
|
|
2
|
+
import { Dimensions } from "react-native";
|
|
3
|
+
import { onUse } from "../dependencyUsage";
|
|
4
|
+
import { WINDOW_DEPENDENCY_KEY, SCREEN_DEPENDENCY_KEY } from "./consts";
|
|
5
|
+
const get = (dim) => Dimensions.get(dim);
|
|
6
|
+
export function getWindowDimensions() {
|
|
7
|
+
onUse(WINDOW_DEPENDENCY_KEY);
|
|
8
|
+
return get("window");
|
|
9
|
+
}
|
|
10
|
+
export function getScreenDimensions() {
|
|
11
|
+
onUse(SCREEN_DEPENDENCY_KEY);
|
|
12
|
+
return get("screen");
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dimensions } from "react-native";
|
|
2
|
+
import { createEventEmitter } from "../createEventEmitter";
|
|
3
|
+
import { addDependency } from "../dependencyRegistry";
|
|
4
|
+
import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
|
|
5
|
+
const { get, addEventListener } = Dimensions;
|
|
6
|
+
const state = { window: get("window"), screen: get("screen") };
|
|
7
|
+
const windowEventEmitter = createEventEmitter(WINDOW_DEPENDENCY_KEY);
|
|
8
|
+
const screenEventEmitter = createEventEmitter(SCREEN_DEPENDENCY_KEY);
|
|
9
|
+
const isNotEqual = (a, b) => a.width !== b.width || a.height !== b.height;
|
|
10
|
+
addDependency(WINDOW_DEPENDENCY_KEY, (handler) => windowEventEmitter.on(handler));
|
|
11
|
+
addDependency(SCREEN_DEPENDENCY_KEY, (handler) => screenEventEmitter.on(handler));
|
|
12
|
+
addEventListener("change", ({ window, screen }) => {
|
|
13
|
+
if (isNotEqual(screen, state.screen)) {
|
|
14
|
+
state.screen = screen;
|
|
15
|
+
screenEventEmitter.emit();
|
|
16
|
+
}
|
|
17
|
+
if (isNotEqual(window, state.window)) {
|
|
18
|
+
state.window = window;
|
|
19
|
+
windowEventEmitter.emit();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const optimizeDependencies: (keys: Record<string, boolean>) => Record<string, boolean>;
|
package/i18n.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type LayoutDirectionType = "rtl" | "ltr";
|
|
2
|
+
export declare function i18n<T>({ rtl, ltr, }: {
|
|
3
|
+
[direction in LayoutDirectionType]?: T;
|
|
4
|
+
}): T | undefined;
|
|
5
|
+
export declare const rtl: <T>(styles: T) => T | undefined;
|
|
6
|
+
export declare const ltr: <T>(styles: T) => T | undefined;
|
|
7
|
+
export {};
|
package/i18n.js
ADDED
package/index.js
ADDED
|
@@ -3,5 +3,5 @@ import { DefaultTheme } from "../DefaultTheme";
|
|
|
3
3
|
|
|
4
4
|
export function makeUseStyles<
|
|
5
5
|
Theme extends DefaultTheme,
|
|
6
|
-
T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any
|
|
6
|
+
T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>,
|
|
7
7
|
>(getStyles: (theme: Theme) => T | StyleSheet.NamedStyles<T>): () => T;
|
|
@@ -18,7 +18,7 @@ export const useForceUpdate = (scope) => {
|
|
|
18
18
|
|
|
19
19
|
unsubscribeRef.current = () => {
|
|
20
20
|
scope.forceUpdate = scope.forceUpdate.filter(
|
|
21
|
-
(fn) => fn !== forceRerender
|
|
21
|
+
(fn) => fn !== forceRerender,
|
|
22
22
|
);
|
|
23
23
|
};
|
|
24
24
|
}
|
|
@@ -28,7 +28,7 @@ export const useForceUpdate = (scope) => {
|
|
|
28
28
|
unsubscribeRef.current();
|
|
29
29
|
unsubscribeRef.current = noop;
|
|
30
30
|
},
|
|
31
|
-
[]
|
|
31
|
+
[],
|
|
32
32
|
);
|
|
33
33
|
};
|
|
34
34
|
|
|
@@ -51,13 +51,13 @@ export const subscribe = (dependenciesKeys, handler) => {
|
|
|
51
51
|
|
|
52
52
|
if (!onChange) {
|
|
53
53
|
console.warn(
|
|
54
|
-
`[react-native-stylex] Could not find onChange handler for ${dependencyName}
|
|
54
|
+
`[react-native-stylex] Could not find onChange handler for ${dependencyName}!`,
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
return !!onChange;
|
|
59
59
|
}
|
|
60
|
-
: Boolean
|
|
60
|
+
: Boolean,
|
|
61
61
|
)
|
|
62
62
|
.map((onChange) => onChange(handler));
|
|
63
63
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ScaledSize } from "react-native";
|
|
2
|
+
export declare const createDimensionQueryHelper: <Value>(queryFunction: (options: {
|
|
3
|
+
value: Value;
|
|
4
|
+
dimensions: ScaledSize;
|
|
5
|
+
}) => boolean) => <T>(value: Value, styles: T) => T | null;
|
|
6
|
+
export declare const maxHeight: <T>(value: number, styles: T) => T | null;
|
|
7
|
+
export declare const maxWidth: <T>(value: number, styles: T) => T | null;
|
|
8
|
+
export declare const minHeight: <T>(value: number, styles: T) => T | null;
|
|
9
|
+
export declare const minWidth: <T>(value: number, styles: T) => T | null;
|
|
10
|
+
export declare const minAspectRatio: <T>(value: number, styles: T) => T | null;
|
|
11
|
+
export declare const maxAspectRatio: <T>(value: number, styles: T) => T | null;
|
|
12
|
+
export declare const aspectRatio: <T>(value: number, styles: T) => T | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getWindowDimensions } from "../dimensions";
|
|
2
|
+
export const createDimensionQueryHelper = (queryFunction) => (value, styles) => {
|
|
3
|
+
const isMatched = queryFunction({
|
|
4
|
+
value,
|
|
5
|
+
dimensions: getWindowDimensions(),
|
|
6
|
+
});
|
|
7
|
+
if (isMatched) {
|
|
8
|
+
return styles;
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
};
|
|
12
|
+
export const maxHeight = createDimensionQueryHelper(({ value, dimensions }) => value >= dimensions.height);
|
|
13
|
+
export const maxWidth = createDimensionQueryHelper(({ value, dimensions }) => value >= dimensions.width);
|
|
14
|
+
export const minHeight = createDimensionQueryHelper(({ value, dimensions }) => value <= dimensions.height);
|
|
15
|
+
export const minWidth = createDimensionQueryHelper(({ value, dimensions }) => value <= dimensions.width);
|
|
16
|
+
export const minAspectRatio = createDimensionQueryHelper(({ value, dimensions: { width, height } }) => value <= width / height);
|
|
17
|
+
export const maxAspectRatio = createDimensionQueryHelper(({ value, dimensions: { width, height } }) => value >= width / height);
|
|
18
|
+
export const aspectRatio = createDimensionQueryHelper(({ value, dimensions: { width, height } }) => value === width / height);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface BreakpointsMatcher<TBreakpoints> {
|
|
2
|
+
<T>(values: {
|
|
3
|
+
[mode in keyof TBreakpoints]?: T;
|
|
4
|
+
}): T | undefined;
|
|
5
|
+
<T>(values: {
|
|
6
|
+
[mode in keyof TBreakpoints]?: T;
|
|
7
|
+
} & {
|
|
8
|
+
default: T;
|
|
9
|
+
}): T;
|
|
10
|
+
}
|
|
11
|
+
export declare function createBreakpointsMatcher<TBreakpoints extends Record<string, number>>(breakpoints: TBreakpoints, matchFunction?: <T>(value: number, styles: T) => T | null): BreakpointsMatcher<TBreakpoints>;
|
|
12
|
+
export declare function createBreakpoints<TBreakpoints extends Record<string, number>>(breakpoints: TBreakpoints): {
|
|
13
|
+
up: <T>(key: keyof TBreakpoints, value: T) => T | null;
|
|
14
|
+
down: <T_1>(key: keyof TBreakpoints, value: T_1) => T_1 | null;
|
|
15
|
+
only: <T_2>(key: keyof TBreakpoints, value: T_2) => T_2 | null;
|
|
16
|
+
between: <T_3>(start: keyof TBreakpoints, end: keyof TBreakpoints, value: T_3) => T_3 | null;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { minAspectRatio, minWidth, minHeight, maxWidth } from "./base";
|
|
2
|
+
const orderByMin = [minWidth, minAspectRatio, minHeight];
|
|
3
|
+
const toOrderedBreakpointNames = (values, breakpoints, matchFunction) => {
|
|
4
|
+
const result = Object.keys(values)
|
|
5
|
+
.filter((e) => e !== "default")
|
|
6
|
+
.sort((a, b) => breakpoints[a] - breakpoints[b]);
|
|
7
|
+
if (orderByMin.includes(matchFunction)) {
|
|
8
|
+
return result.slice().reverse();
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
/*
|
|
13
|
+
* To debug use analog on CSS: https://codepen.io/retyui/pen/dyOzKzV
|
|
14
|
+
*/
|
|
15
|
+
export function createBreakpointsMatcher(breakpoints, matchFunction = minWidth) {
|
|
16
|
+
return function breakpointsMatcher(values) {
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
// @ts-expect-error: was removed
|
|
19
|
+
if (process.env.NODE_ENV !== "production") {
|
|
20
|
+
const invalidKeys = Object.keys(values).filter((key) => {
|
|
21
|
+
return key !== "default" && breakpoints[key] === undefined;
|
|
22
|
+
});
|
|
23
|
+
if (invalidKeys.length > 0) {
|
|
24
|
+
console.warn(`[react-native-stylex]: Invalid values was passed to 'breakpointsMatcher' function
|
|
25
|
+
|
|
26
|
+
allowed keys: ${Object.keys(breakpoints).join(", ")}
|
|
27
|
+
unexpected keys: ${invalidKeys.join(", ")}
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const orderedBreakpointNames = toOrderedBreakpointNames(values, breakpoints, matchFunction);
|
|
32
|
+
const key = orderedBreakpointNames.find((breakpointName) => matchFunction(breakpoints[breakpointName], values[breakpointName])) || "default";
|
|
33
|
+
return values[key] || null;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function getNextByKey(breakpoints, key) {
|
|
37
|
+
const breakpointsKeys = Object.keys(breakpoints).sort((a, b) => breakpoints[a] - breakpoints[b]);
|
|
38
|
+
const index = breakpointsKeys.indexOf(key);
|
|
39
|
+
const nextKey = breakpointsKeys[index + 1];
|
|
40
|
+
return nextKey;
|
|
41
|
+
}
|
|
42
|
+
export function createBreakpoints(breakpoints) {
|
|
43
|
+
function up(key, value) {
|
|
44
|
+
return minWidth(breakpoints[key], value);
|
|
45
|
+
}
|
|
46
|
+
function down(key, value) {
|
|
47
|
+
return maxWidth(breakpoints[key], value);
|
|
48
|
+
}
|
|
49
|
+
function only(key, value) {
|
|
50
|
+
const nextKey = getNextByKey(breakpoints, key);
|
|
51
|
+
if (nextKey !== undefined) {
|
|
52
|
+
return minWidth(breakpoints[key], maxWidth(breakpoints[nextKey] - 0.05, value));
|
|
53
|
+
}
|
|
54
|
+
return minWidth(breakpoints[key], value);
|
|
55
|
+
}
|
|
56
|
+
function between(start, end, value) {
|
|
57
|
+
return minWidth(breakpoints[start], maxWidth(breakpoints[end] - 0.05, value));
|
|
58
|
+
}
|
|
59
|
+
return { up, down, only, between };
|
|
60
|
+
}
|
package/orientation.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type OrientationType = "portrait" | "landscape";
|
|
2
|
+
export declare function orientation<T>(spec: {
|
|
3
|
+
[orientation in OrientationType]?: T;
|
|
4
|
+
}): T | undefined;
|
|
5
|
+
export declare const portraitOrientation: <T>(portraitStyles: T) => T | undefined;
|
|
6
|
+
export declare const landscapeOrientation: <T>(landscapeStyles: T) => T | undefined;
|
|
7
|
+
export {};
|
package/orientation.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getScreenDimensions } from "./dimensions";
|
|
2
|
+
export function orientation(spec) {
|
|
3
|
+
const { height, width } = getScreenDimensions();
|
|
4
|
+
return width <= height ? spec.portrait : spec.landscape;
|
|
5
|
+
}
|
|
6
|
+
export const portraitOrientation = (portraitStyles) => orientation({ portrait: portraitStyles });
|
|
7
|
+
export const landscapeOrientation = (landscapeStyles) => orientation({ landscape: landscapeStyles });
|
package/package.json
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeandmoney/soelma",
|
|
3
|
-
"publishConfig": {
|
|
4
|
-
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.0.0-dev.1",
|
|
5
7
|
"private": false,
|
|
6
8
|
"main": "index.js",
|
|
7
9
|
"types": "index.d.ts",
|
|
8
10
|
"author": "David <4661784+retyui@users.noreply.github.com>",
|
|
9
11
|
"description": "Fork of git@github.com:retyui/react-native-stylex.git",
|
|
10
12
|
"license": "MIT",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"prebuild": "rm -rf lib",
|
|
13
|
-
"build": "tsc",
|
|
14
|
-
"postbuild": "mkdir lib/makeUseStyles && cp src/makeUseStyles/* lib/makeUseStyles && rm -rf lib/**/*test.* && prettier --write lib/**/*.{js,ts}",
|
|
15
|
-
"clean-publish": "yarn test && yarn build && node ./node_modules/clean-publish/clear-package-json.js package.json > lib/package.json && cp CHANGELOG.md LICENSE README.md lib",
|
|
16
|
-
"publish-next": "yarn clean-publish && cd lib && npm publish --tag next",
|
|
17
|
-
"presize": "yarn build",
|
|
18
|
-
"postinstall": "rm -rf node_modules/@types/node node_modules/@types/yauzl node_modules/@types/graceful-fs",
|
|
19
|
-
"lint": "eslint './src/*.{js,ts,tsx}' --quiet",
|
|
20
|
-
"test": "jest --coverage",
|
|
21
|
-
"size": "size-limit",
|
|
22
|
-
"ci": "yarn lint && yarn test && yarn size"
|
|
23
|
-
},
|
|
24
13
|
"peerDependencies": {
|
|
25
14
|
"react": ">=16.4.0",
|
|
26
15
|
"react-native": ">=0.59.0"
|
|
@@ -33,27 +22,7 @@
|
|
|
33
22
|
"optional": true
|
|
34
23
|
}
|
|
35
24
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"@testing-library/react-hooks": "^8.0.1",
|
|
39
|
-
"@types/jest": "^29.5.11",
|
|
40
|
-
"@types/react": "^18.2.45",
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
42
|
-
"@typescript-eslint/parser": "^6.14.0",
|
|
43
|
-
"clean-publish": "^4.2.0",
|
|
44
|
-
"eslint": "^8.56.0",
|
|
45
|
-
"eslint-config-prettier": "^9.1.0",
|
|
46
|
-
"eslint-plugin-prettier": "^5.0.1",
|
|
47
|
-
"eslint-plugin-react": "^7.33.2",
|
|
48
|
-
"jest": "^29.7.0",
|
|
49
|
-
"prettier": "^3.1.1",
|
|
50
|
-
"react": "^18.2.0",
|
|
51
|
-
"react-native": "^0.73.0",
|
|
52
|
-
"react-native-dark-mode": "^0.2.2",
|
|
53
|
-
"react-native-safe-area-context": "^4.8.1",
|
|
54
|
-
"react-native-test-app": "^2.5.34",
|
|
55
|
-
"react-test-renderer": "^18.2.0",
|
|
56
|
-
"size-limit": "^11.0.1",
|
|
57
|
-
"typescript": "^5.3.3"
|
|
25
|
+
"scripts": {
|
|
26
|
+
"postinstall": "rm -rf node_modules/@types/node node_modules/@types/yauzl node_modules/@types/graceful-fs"
|
|
58
27
|
}
|
|
59
28
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SafeAreaProvider as CoreSafeAreaProvider, initialWindowMetrics, initialWindowSafeAreaInsets, } from "react-native-safe-area-context";
|
|
3
|
+
import { StylexSaveAreaConsumer } from "./StylexSaveAreaConsumer";
|
|
4
|
+
export function SafeAreaProvider(props) {
|
|
5
|
+
return (<CoreSafeAreaProvider initialSafeAreaInsets={props.initialSafeAreaInsets || initialWindowSafeAreaInsets} initialMetrics={props.initialMetrics || initialWindowMetrics} {...props}>
|
|
6
|
+
{props.children}
|
|
7
|
+
<StylexSaveAreaConsumer />
|
|
8
|
+
</CoreSafeAreaProvider>);
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
2
|
+
import { emit } from "./eventEmitter";
|
|
3
|
+
import { state } from "./state";
|
|
4
|
+
import { useLayoutEffect } from "react";
|
|
5
|
+
export function StylexSaveAreaConsumer() {
|
|
6
|
+
const insets = useSafeAreaInsets();
|
|
7
|
+
useLayoutEffect(() => {
|
|
8
|
+
const isChanged = Object.entries(insets).some(([key, value]) => state.insets[key] !== value);
|
|
9
|
+
if (isChanged) {
|
|
10
|
+
state.insets = insets;
|
|
11
|
+
emit();
|
|
12
|
+
}
|
|
13
|
+
}, [insets]);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SAFE_AREA_DEPENDENCY_KEY = "react-native-safe-area-context";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const emit: () => void, on: (callback: () => void) => () => void;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import "./init";
|
|
2
|
-
|
|
3
2
|
import { onUse } from "../dependencyUsage";
|
|
4
|
-
|
|
5
3
|
import { SAFE_AREA_DEPENDENCY_KEY } from "./consts";
|
|
6
|
-
import { EdgeInsets } from "./types";
|
|
7
4
|
import { state } from "./state";
|
|
8
|
-
|
|
9
5
|
export { StylexSaveAreaConsumer } from "./StylexSaveAreaConsumer";
|
|
10
6
|
export { SafeAreaProvider } from "./SafeAreaProvider";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return state.insets;
|
|
7
|
+
export function getSafeArea() {
|
|
8
|
+
onUse(SAFE_AREA_DEPENDENCY_KEY);
|
|
9
|
+
return state.insets;
|
|
16
10
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { addDependency } from "../dependencyRegistry";
|
|
2
|
-
|
|
3
2
|
import { SAFE_AREA_DEPENDENCY_KEY } from "./consts";
|
|
4
3
|
import { on } from "./eventEmitter";
|
|
5
|
-
|
|
6
|
-
addDependency(SAFE_AREA_DEPENDENCY_KEY, (handler: () => void) => on(handler));
|
|
4
|
+
addDependency(SAFE_AREA_DEPENDENCY_KEY, (handler) => on(handler));
|