react-native-unistyles 3.0.0-alpha.29 → 3.0.0-alpha.30
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/common/Helpers.h +11 -0
- package/cxx/core/HostStyle.cpp +1 -1
- package/cxx/core/UnistyleWrapper.h +9 -8
- package/cxx/core/UnistylesCommitHook.cpp +3 -14
- package/cxx/core/UnistylesCommitHook.h +5 -11
- package/cxx/core/UnistylesMountHook.cpp +0 -1
- package/cxx/core/UnistylesMountHook.h +0 -2
- package/cxx/core/UnistylesRegistry.cpp +1 -1
- package/cxx/core/UnistylesRegistry.h +1 -1
- package/cxx/hybridObjects/HybridStyleSheet.cpp +17 -11
- package/cxx/hybridObjects/HybridStyleSheet.h +1 -1
- package/cxx/parser/Parser.cpp +20 -14
- package/cxx/parser/Parser.h +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +4 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +3 -4
- package/cxx/shadowTree/ShadowTreeManager.h +1 -1
- package/ios/UnistylesModuleOnLoad.mm +4 -4
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/createUnistylesComponent.js +18 -0
- package/lib/commonjs/core/createUnistylesComponent.js.map +1 -0
- package/lib/commonjs/core/createUnistylesComponent.native.js +45 -0
- package/lib/commonjs/core/createUnistylesComponent.native.js.map +2 -0
- package/lib/commonjs/core/index.js +7 -0
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/useBreakpoint.js.map +1 -1
- package/lib/commonjs/core/useBreakpoint.native.js.map +2 -1
- package/lib/commonjs/core/useTheme.js.map +2 -1
- package/lib/commonjs/core/useTheme.native.js.map +2 -1
- package/lib/commonjs/global.js +3 -0
- package/lib/commonjs/index.js +8 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mq.js +1 -4
- package/lib/commonjs/mq.js.map +2 -1
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +5 -4
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
- package/lib/commonjs/specs/NativePlatform/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/types.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +2 -1
- package/lib/commonjs/specs/TurboUnistyles/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -2
- package/lib/commonjs/specs/index.web.js.map +1 -2
- package/lib/commonjs/specs/types.js +10 -10
- package/lib/commonjs/specs/types.js.map +2 -1
- package/lib/commonjs/types/accessibility.js +9 -9
- package/lib/commonjs/types/accessibility.js.map +1 -1
- package/lib/commonjs/types/common.js +3 -0
- package/lib/commonjs/types/core.js.map +1 -1
- package/lib/commonjs/types/index.js.map +2 -1
- package/lib/commonjs/types/stylesheet.js +1 -2
- package/lib/commonjs/web/convert/index.js +1 -7
- package/lib/commonjs/web/convert/index.js.map +2 -1
- package/lib/commonjs/web/convert/pseudo.js.map +2 -1
- package/lib/commonjs/web/convert/shadow.js.map +2 -1
- package/lib/commonjs/web/convert/style.js.map +2 -1
- package/lib/commonjs/web/convert/textShadow.js +1 -4
- package/lib/commonjs/web/convert/textShadow.js.map +2 -1
- package/lib/commonjs/web/convert/transform.js.map +2 -1
- package/lib/commonjs/web/convert/utils.js +1 -2
- package/lib/commonjs/web/convert/utils.js.map +2 -1
- package/lib/commonjs/web/index.js.map +2 -1
- package/lib/commonjs/web/listener.js.map +2 -1
- package/lib/commonjs/web/mock.js.map +2 -1
- package/lib/commonjs/web/mq.js.map +1 -1
- package/lib/commonjs/web/registry.js +1 -3
- package/lib/commonjs/web/registry.js.map +2 -1
- package/lib/commonjs/web/runtime.js.map +2 -1
- package/lib/commonjs/web/shadowRegistry.js +1 -9
- package/lib/commonjs/web/shadowRegistry.js.map +2 -1
- package/lib/commonjs/web/state.js +1 -5
- package/lib/commonjs/web/state.js.map +2 -1
- package/lib/commonjs/web/utils/common.js +1 -3
- package/lib/commonjs/web/utils/common.js.map +2 -1
- package/lib/commonjs/web/utils/index.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js.map +2 -1
- package/lib/commonjs/web/variants/index.js.map +1 -1
- package/lib/commonjs/web/variants/useVariants.js +1 -2
- package/lib/commonjs/web/variants/useVariants.js.map +2 -1
- package/lib/module/core/createUnistylesComponent.js +11 -0
- package/lib/module/core/createUnistylesComponent.js.map +2 -0
- package/lib/module/core/createUnistylesComponent.native.js +39 -0
- package/lib/module/core/createUnistylesComponent.native.js.map +1 -0
- package/lib/module/core/index.js +1 -0
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/useBreakpoint.js.map +1 -1
- package/lib/module/core/useBreakpoint.native.js.map +2 -1
- package/lib/module/core/useTheme.js.map +2 -1
- package/lib/module/core/useTheme.native.js.map +2 -1
- package/lib/module/global.js +1 -1
- package/lib/module/global.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/mq.js +1 -4
- package/lib/module/mq.js.map +2 -1
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
- package/lib/module/specs/NativePlatform/index.js.map +1 -1
- package/lib/module/specs/NavigtionBar/index.js.map +2 -1
- package/lib/module/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +2 -1
- package/lib/module/specs/ShadowRegistry/types.js.map +2 -1
- package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -2
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -1
- package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +0 -1
- package/lib/module/specs/StyleSheet/index.js.map +2 -1
- package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js +3 -2
- package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +2 -1
- package/lib/module/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +2 -1
- package/lib/module/specs/index.js.map +1 -2
- package/lib/module/specs/types.js.map +1 -2
- package/lib/module/types/accessibility.js +1 -1
- package/lib/module/types/accessibility.js.map +1 -0
- package/lib/module/types/breakpoints.js.map +1 -0
- package/lib/module/types/common.js +1 -1
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/types/core.js.map +1 -1
- package/lib/module/types/index.js.map +2 -1
- package/lib/module/types/variants.js.map +1 -0
- package/lib/module/web/convert/index.js.map +2 -1
- package/lib/module/web/convert/pseudo.js.map +2 -1
- package/lib/module/web/convert/shadow.js +1 -5
- package/lib/module/web/convert/utils.js +1 -2
- package/lib/module/web/index.js +1 -2
- package/lib/module/web/index.js.map +2 -1
- package/lib/module/web/listener.js.map +2 -1
- package/lib/module/web/mock.js.map +2 -1
- package/lib/module/web/state.js +1 -5
- package/lib/module/web/state.js.map +2 -1
- package/lib/module/web/variants/getVariants.js.map +2 -1
- package/lib/module/web/variants/index.js.map +1 -1
- package/lib/module/web/variants/useVariants.js +1 -2
- package/lib/module/web/variants/useVariants.js.map +2 -1
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +6 -0
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +6 -0
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +1 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +3 -3
- package/nitrogen/generated/android/unistyles+autolinking.cmake +13 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +4 -10
- package/package.json +3 -3
- package/src/common.js +4 -0
- package/src/core/createUnistylesComponent.js +6 -0
- package/src/core/createUnistylesComponent.native.js +31 -0
- package/src/core/createUnistylesComponent.native.tsx +44 -0
- package/src/core/createUnistylesComponent.tsx +10 -0
- package/src/core/index.js +3 -0
- package/src/core/index.ts +1 -0
- package/src/core/useBreakpoint.js +14 -0
- package/src/core/useBreakpoint.native.js +16 -0
- package/src/core/useTheme.js +14 -0
- package/src/core/useTheme.native.js +16 -0
- package/src/global.js +1 -0
- package/src/index.js +3 -0
- package/src/index.ts +1 -1
- package/src/mq.js +38 -0
- package/src/specs/NativePlatform/NativePlatform.nitro.js +1 -0
- package/src/types/accessibility.js +30 -0
- package/src/types/breakpoints.js +1 -0
- package/src/types/common.js +1 -0
- package/src/types/core.js +1 -0
- package/src/types/index.js +1 -0
- package/src/types/stylesheet.js +2 -0
- package/src/types/variants.js +1 -0
- package/src/web/convert/boxShadow.js +59 -0
- package/src/web/convert/index.js +56 -0
- package/src/web/convert/pseudo.js +131 -0
- package/src/web/convert/shadow.js +50 -0
- package/src/web/convert/style.js +137 -0
- package/src/web/convert/textShadow.js +56 -0
- package/src/web/convert/transform.js +65 -0
- package/src/web/convert/types.js +2 -0
- package/src/web/convert/utils.js +39 -0
- package/src/web/create.js +36 -0
- package/src/web/index.js +22 -0
- package/src/web/listener.js +26 -0
- package/src/web/mock.js +21 -0
- package/src/web/mq.js +14 -0
- package/src/web/registry.js +165 -0
- package/src/web/runtime.js +160 -0
- package/src/web/shadowRegistry.js +96 -0
- package/src/web/state.js +68 -0
- package/src/web/utils/common.js +79 -0
- package/src/web/utils/index.js +2 -0
- package/src/web/utils/unistyle.js +72 -0
- package/src/web/variants/getVariants.js +26 -0
- package/src/web/variants/index.js +2 -0
- package/src/web/variants/useVariants.js +50 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
import React, { type ComponentProps, type ComponentType } from 'react'
|
2
|
+
import type { UnistylesTheme } from '../types'
|
3
|
+
|
4
|
+
type Mappings<T extends ComponentType<any>> = (theme: UnistylesTheme) => Partial<ComponentProps<T>>
|
5
|
+
|
6
|
+
export const createUnistylesComponent = <T extends ComponentType<any>>(Component: T, _: Mappings<T>) => {
|
7
|
+
return (props: ComponentProps<T>) => {
|
8
|
+
return <Component {...props} />
|
9
|
+
}
|
10
|
+
}
|
package/src/core/index.ts
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
import { UnistylesRuntime } from '../web';
|
3
|
+
import { UnistylesListener } from '../web/listener';
|
4
|
+
import { UnistyleDependency } from '../specs/NativePlatform';
|
5
|
+
export const useBreakpoint = () => {
|
6
|
+
const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
|
7
|
+
useEffect(() => {
|
8
|
+
const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Breakpoints], () => setBreakpoint(UnistylesRuntime.breakpoint));
|
9
|
+
return () => {
|
10
|
+
removeChangeListener();
|
11
|
+
};
|
12
|
+
}, []);
|
13
|
+
return breakpoint;
|
14
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
|
3
|
+
export const useBreakpoint = () => {
|
4
|
+
const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
|
5
|
+
useEffect(() => {
|
6
|
+
const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
|
7
|
+
if (dependencies.includes(UnistyleDependency.Breakpoints)) {
|
8
|
+
setBreakpoint(UnistylesRuntime.breakpoint);
|
9
|
+
}
|
10
|
+
});
|
11
|
+
return () => {
|
12
|
+
removeChangeListener();
|
13
|
+
};
|
14
|
+
}, []);
|
15
|
+
return breakpoint;
|
16
|
+
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
import { UnistylesRuntime } from '../web';
|
3
|
+
import { UnistylesListener } from '../web/listener';
|
4
|
+
import { UnistyleDependency } from '../specs/NativePlatform';
|
5
|
+
export const useTheme = () => {
|
6
|
+
const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
|
7
|
+
useEffect(() => {
|
8
|
+
const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Theme], () => setTheme(UnistylesRuntime.getTheme()));
|
9
|
+
return () => {
|
10
|
+
removeChangeListener();
|
11
|
+
};
|
12
|
+
}, []);
|
13
|
+
return theme;
|
14
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
|
3
|
+
export const useTheme = () => {
|
4
|
+
const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
|
5
|
+
useEffect(() => {
|
6
|
+
const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
|
7
|
+
if (dependencies.includes(UnistyleDependency.Theme)) {
|
8
|
+
setTheme(UnistylesRuntime.getTheme());
|
9
|
+
}
|
10
|
+
});
|
11
|
+
return () => {
|
12
|
+
removeChangeListener();
|
13
|
+
};
|
14
|
+
}, []);
|
15
|
+
return theme;
|
16
|
+
};
|
package/src/global.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/src/index.js
ADDED
package/src/index.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export * from './specs'
|
2
2
|
export { mq } from './mq'
|
3
3
|
export type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
4
|
-
export { useTheme, useBreakpoint } from './core'
|
4
|
+
export { useTheme, useBreakpoint, createUnistylesComponent } from './core'
|
5
5
|
export type { UnistylesVariants } from './types'
|
package/src/mq.js
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
const getMQValue = (value) => {
|
2
|
+
if (typeof value === 'number') {
|
3
|
+
return value;
|
4
|
+
}
|
5
|
+
if (value === null) {
|
6
|
+
return 0;
|
7
|
+
}
|
8
|
+
// todo take it from js
|
9
|
+
const breakpoints = {
|
10
|
+
xs: 0,
|
11
|
+
sm: 300,
|
12
|
+
md: 500,
|
13
|
+
lg: 800,
|
14
|
+
xl: 1200
|
15
|
+
};
|
16
|
+
// @ts-ignore
|
17
|
+
return breakpoints[value] ?? 0;
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* Utility to create cross-platform media queries
|
21
|
+
* @returns - JavaScript symbol to be used in your stylesheet
|
22
|
+
*/
|
23
|
+
export const mq = {
|
24
|
+
only: {
|
25
|
+
width: (wMin = 0, wMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]`,
|
26
|
+
height: (hMin = 0, hMax = Infinity) => `:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
|
27
|
+
},
|
28
|
+
width: (wMin = 0, wMax = Infinity) => ({
|
29
|
+
and: {
|
30
|
+
height: (hMin = 0, hMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
|
31
|
+
}
|
32
|
+
}),
|
33
|
+
height: (hMin = 0, hMax = Infinity) => ({
|
34
|
+
and: {
|
35
|
+
width: (wMin = 0, wMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
|
36
|
+
}
|
37
|
+
})
|
38
|
+
};
|
@@ -15,4 +15,5 @@ export var UnistyleDependency;
|
|
15
15
|
UnistyleDependency[UnistyleDependency["FontScale"] = 11] = "FontScale";
|
16
16
|
UnistyleDependency[UnistyleDependency["StatusBar"] = 12] = "StatusBar";
|
17
17
|
UnistyleDependency[UnistyleDependency["NavigationBar"] = 13] = "NavigationBar";
|
18
|
+
UnistyleDependency[UnistyleDependency["Ime"] = 14] = "Ime";
|
18
19
|
})(UnistyleDependency || (UnistyleDependency = {}));
|
@@ -0,0 +1,30 @@
|
|
1
|
+
export var IOSContentSizeCategory;
|
2
|
+
(function (IOSContentSizeCategory) {
|
3
|
+
IOSContentSizeCategory["AccessibilityExtraExtraExtraLarge"] = "accessibilityExtraExtraExtraLarge";
|
4
|
+
IOSContentSizeCategory["AccessibilityExtraExtraLarge"] = "accessibilityExtraExtraLarge";
|
5
|
+
IOSContentSizeCategory["AccessibilityExtraLarge"] = "accessibilityExtraLarge";
|
6
|
+
IOSContentSizeCategory["AccessibilityLarge"] = "accessibilityLarge";
|
7
|
+
IOSContentSizeCategory["AccessibilityMedium"] = "accessibilityMedium";
|
8
|
+
IOSContentSizeCategory["ExtraExtraExtraLarge"] = "xxxLarge";
|
9
|
+
IOSContentSizeCategory["ExtraExtraLarge"] = "xxLarge";
|
10
|
+
IOSContentSizeCategory["ExtraLarge"] = "xLarge";
|
11
|
+
IOSContentSizeCategory["Large"] = "Large";
|
12
|
+
IOSContentSizeCategory["Medium"] = "Medium";
|
13
|
+
IOSContentSizeCategory["Small"] = "Small";
|
14
|
+
IOSContentSizeCategory["ExtraSmall"] = "xSmall";
|
15
|
+
IOSContentSizeCategory["Unspecified"] = "unspecified";
|
16
|
+
})(IOSContentSizeCategory || (IOSContentSizeCategory = {}));
|
17
|
+
export var AndroidContentSizeCategory;
|
18
|
+
(function (AndroidContentSizeCategory) {
|
19
|
+
AndroidContentSizeCategory["Small"] = "Small";
|
20
|
+
AndroidContentSizeCategory["Default"] = "Default";
|
21
|
+
AndroidContentSizeCategory["Large"] = "Large";
|
22
|
+
AndroidContentSizeCategory["ExtraLarge"] = "ExtraLarge";
|
23
|
+
AndroidContentSizeCategory["Huge"] = "Huge";
|
24
|
+
AndroidContentSizeCategory["ExtraHuge"] = "ExtraHuge";
|
25
|
+
AndroidContentSizeCategory["ExtraExtraHuge"] = "ExtraExtraHuge";
|
26
|
+
})(AndroidContentSizeCategory || (AndroidContentSizeCategory = {}));
|
27
|
+
export var WebContentSizeCategory;
|
28
|
+
(function (WebContentSizeCategory) {
|
29
|
+
WebContentSizeCategory["Unspecified"] = "web-unspecified";
|
30
|
+
})(WebContentSizeCategory || (WebContentSizeCategory = {}));
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { AndroidContentSizeCategory, IOSContentSizeCategory, WebContentSizeCategory } from './accessibility';
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { deepMergeObjects, warn } from '../utils';
|
2
|
+
import { validateShadow } from './shadow';
|
3
|
+
import { BOX_SHADOW_STYLES } from './types';
|
4
|
+
import { extractShadowValue, normalizeColor, normalizeNumericValue } from './utils';
|
5
|
+
const createBoxShadowValue = (style) => {
|
6
|
+
// at this point every prop is present
|
7
|
+
const { shadowColor, shadowOffset, shadowOpacity, shadowRadius } = style;
|
8
|
+
const offsetX = normalizeNumericValue(shadowOffset.width);
|
9
|
+
const offsetY = normalizeNumericValue(shadowOffset.height);
|
10
|
+
const radius = normalizeNumericValue(shadowRadius);
|
11
|
+
const color = normalizeColor(shadowColor, shadowOpacity);
|
12
|
+
return `${offsetX} ${offsetY} ${radius} ${color}`;
|
13
|
+
};
|
14
|
+
export const getBoxShadowStyle = (styles) => {
|
15
|
+
const missingStyles = BOX_SHADOW_STYLES.filter(key => !(key in styles));
|
16
|
+
if (missingStyles.length) {
|
17
|
+
warn(`can't apply box shadow as you miss these properties: ${missingStyles.join(', ')}`);
|
18
|
+
return {};
|
19
|
+
}
|
20
|
+
const breakpointsSet = new Set();
|
21
|
+
try {
|
22
|
+
validateShadow(BOX_SHADOW_STYLES, styles, breakpointsSet);
|
23
|
+
}
|
24
|
+
catch (error) {
|
25
|
+
if (typeof error === 'string') {
|
26
|
+
warn(error);
|
27
|
+
}
|
28
|
+
return {};
|
29
|
+
}
|
30
|
+
const breakpoints = Array.from(breakpointsSet);
|
31
|
+
// If no breakpoints were used return styles without media queries
|
32
|
+
if (breakpoints.length === 0) {
|
33
|
+
return {
|
34
|
+
boxShadow: createBoxShadowValue(styles)
|
35
|
+
};
|
36
|
+
}
|
37
|
+
// Create boxShadow for each breakpoint
|
38
|
+
const breakpointStyles = breakpoints.map(breakpoint => {
|
39
|
+
const color = extractShadowValue('shadowColor', breakpoint, styles);
|
40
|
+
const { width, height } = extractShadowValue('shadowOffset', breakpoint, styles);
|
41
|
+
const radius = extractShadowValue('shadowRadius', breakpoint, styles);
|
42
|
+
const opacity = extractShadowValue('shadowOpacity', breakpoint, styles);
|
43
|
+
return {
|
44
|
+
[breakpoint]: {
|
45
|
+
boxShadow: createBoxShadowValue({
|
46
|
+
shadowColor: color,
|
47
|
+
shadowOffset: {
|
48
|
+
width,
|
49
|
+
height
|
50
|
+
},
|
51
|
+
shadowRadius: radius,
|
52
|
+
shadowOpacity: opacity
|
53
|
+
})
|
54
|
+
}
|
55
|
+
};
|
56
|
+
});
|
57
|
+
// Merge all breakpoints styles into one
|
58
|
+
return deepMergeObjects(...breakpointStyles);
|
59
|
+
};
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import { isPseudo } from './pseudo';
|
2
|
+
import { getStyle } from './style';
|
3
|
+
import { deepMergeObjects } from '../utils';
|
4
|
+
import { getTransformStyle } from './transform';
|
5
|
+
import { isBoxShadow, isTextShadow, isTransform } from './utils';
|
6
|
+
import { getTextShadowStyle } from './textShadow';
|
7
|
+
import { getBoxShadowStyle } from './boxShadow';
|
8
|
+
export const convertUnistyles = (value) => {
|
9
|
+
// Flag to mark if textShadow is already created
|
10
|
+
let hasTextShadow = false;
|
11
|
+
// Flag to mark if boxShadow is already created
|
12
|
+
let hasBoxShadow = false;
|
13
|
+
const stylesArray = Object.entries({
|
14
|
+
...value,
|
15
|
+
...value._web
|
16
|
+
}).flatMap(([unistylesKey, unistylesValue]) => {
|
17
|
+
// Keys to omit
|
18
|
+
if (['_classNames', '_web', 'variants', 'compoundVariants', 'uni__dependencies', '__unistyles-secrets__'].includes(unistylesKey) || unistylesKey.startsWith('variant-')) {
|
19
|
+
return [];
|
20
|
+
}
|
21
|
+
// Pseudo classes :hover, :before etc.
|
22
|
+
if (isPseudo(unistylesKey)) {
|
23
|
+
const flattenValues = convertUnistyles(unistylesValue);
|
24
|
+
return { [unistylesKey]: flattenValues };
|
25
|
+
}
|
26
|
+
// Text shadow
|
27
|
+
if (isTextShadow(unistylesKey)) {
|
28
|
+
if (hasTextShadow) {
|
29
|
+
return [];
|
30
|
+
}
|
31
|
+
hasTextShadow = true;
|
32
|
+
return getTextShadowStyle(value);
|
33
|
+
}
|
34
|
+
// Box shadow
|
35
|
+
if (isBoxShadow(unistylesKey)) {
|
36
|
+
if (hasBoxShadow) {
|
37
|
+
return [];
|
38
|
+
}
|
39
|
+
hasBoxShadow = true;
|
40
|
+
return getBoxShadowStyle(value);
|
41
|
+
}
|
42
|
+
// Transforms
|
43
|
+
if (isTransform(unistylesKey, unistylesValue)) {
|
44
|
+
return getTransformStyle(unistylesValue);
|
45
|
+
}
|
46
|
+
// Breakpoints
|
47
|
+
if (typeof unistylesValue === 'object' && unistylesValue !== null) {
|
48
|
+
return Object.entries(unistylesValue).map(([breakpointKey, breakpointValue]) => {
|
49
|
+
return { [breakpointKey]: getStyle(unistylesKey, breakpointValue) };
|
50
|
+
});
|
51
|
+
}
|
52
|
+
// Regular styles
|
53
|
+
return getStyle(unistylesKey, unistylesValue);
|
54
|
+
});
|
55
|
+
return deepMergeObjects(...stylesArray);
|
56
|
+
};
|
@@ -0,0 +1,131 @@
|
|
1
|
+
export const pseudos = [
|
2
|
+
'_-moz-broken',
|
3
|
+
'_-moz-drag-over',
|
4
|
+
'_-moz-first-node',
|
5
|
+
'_-moz-handler-blocked',
|
6
|
+
'_-moz-handler-crashed',
|
7
|
+
'_-moz-handler-disabled',
|
8
|
+
'_-moz-last-node',
|
9
|
+
'_-moz-loading',
|
10
|
+
'_-moz-locale-dir(ltr)',
|
11
|
+
'_-moz-locale-dir(rtl)',
|
12
|
+
'_-moz-only-whitespace',
|
13
|
+
'_-moz-submit-invalid',
|
14
|
+
'_-moz-suppressed',
|
15
|
+
'_-moz-user-disabled',
|
16
|
+
'_-moz-window-inactive',
|
17
|
+
'_active',
|
18
|
+
'_any-link',
|
19
|
+
'_autofill',
|
20
|
+
'_blank',
|
21
|
+
'_buffering',
|
22
|
+
'_checked',
|
23
|
+
'_current',
|
24
|
+
'_default',
|
25
|
+
'_defined',
|
26
|
+
'_dir(',
|
27
|
+
'_disabled',
|
28
|
+
'_empty',
|
29
|
+
'_enabled',
|
30
|
+
'_first',
|
31
|
+
'_first-child',
|
32
|
+
'_first-of-type',
|
33
|
+
'_focus',
|
34
|
+
'_focus-visible',
|
35
|
+
'_focus-within',
|
36
|
+
'_fullscreen',
|
37
|
+
'_future',
|
38
|
+
'_has(',
|
39
|
+
'_host',
|
40
|
+
'_host-context(',
|
41
|
+
'_host(',
|
42
|
+
'_hover',
|
43
|
+
'_in-range',
|
44
|
+
'_indeterminate',
|
45
|
+
'_invalid',
|
46
|
+
'_is(',
|
47
|
+
'_lang(',
|
48
|
+
'_last-child',
|
49
|
+
'_last-of-type',
|
50
|
+
'_left',
|
51
|
+
'_link',
|
52
|
+
'_local-link',
|
53
|
+
'_modal',
|
54
|
+
'_muted',
|
55
|
+
'_not(',
|
56
|
+
'_nth-child(',
|
57
|
+
'_nth-last-child(',
|
58
|
+
'_nth-last-of-type(',
|
59
|
+
'_nth-of-type(',
|
60
|
+
'_only-child',
|
61
|
+
'_only-of-type',
|
62
|
+
'_optional',
|
63
|
+
'_out-of-range',
|
64
|
+
'_past',
|
65
|
+
'_paused',
|
66
|
+
'_picture-in-picture',
|
67
|
+
'_placeholder-shown',
|
68
|
+
'_playing',
|
69
|
+
'_popover-open',
|
70
|
+
'_read-only',
|
71
|
+
'_read-write',
|
72
|
+
'_required',
|
73
|
+
'_right',
|
74
|
+
'_scope',
|
75
|
+
'_seeking',
|
76
|
+
'_stalled',
|
77
|
+
'_state(',
|
78
|
+
'_target',
|
79
|
+
'_target-within',
|
80
|
+
'_user-invalid',
|
81
|
+
'_user-valid',
|
82
|
+
'_valid',
|
83
|
+
'_visited',
|
84
|
+
'_volume-locked',
|
85
|
+
'_where(',
|
86
|
+
'_-moz-color-swatch',
|
87
|
+
'_-moz-focus-inner',
|
88
|
+
'_-moz-list-bullet',
|
89
|
+
'_-moz-list-number',
|
90
|
+
'_-moz-meter-bar',
|
91
|
+
'_-moz-progress-bar',
|
92
|
+
'_-moz-range-progress',
|
93
|
+
'_-moz-range-thumb',
|
94
|
+
'_-moz-range-track',
|
95
|
+
'_-webkit-inner-spin-button',
|
96
|
+
'_-webkit-meter-barDeprecated',
|
97
|
+
'_-webkit-meter-even-less-good-value',
|
98
|
+
'_-webkit-meter-inner-element',
|
99
|
+
'_-webkit-meter-optimum-value',
|
100
|
+
'_-webkit-meter-suboptimum-value',
|
101
|
+
'_-webkit-progress-bar',
|
102
|
+
'_-webkit-progress-inner-element',
|
103
|
+
'_-webkit-progress-value',
|
104
|
+
'_-webkit-scrollbar',
|
105
|
+
'_-webkit-search-cancel-button',
|
106
|
+
'_-webkit-search-results-button',
|
107
|
+
'_-webkit-slider-runnable-track',
|
108
|
+
'_-webkit-slider-thumb',
|
109
|
+
'_after',
|
110
|
+
'_backdrop',
|
111
|
+
'_before',
|
112
|
+
'_cue',
|
113
|
+
'_file-selector-button',
|
114
|
+
'_first-letter',
|
115
|
+
'_first-line',
|
116
|
+
'_grammar-error',
|
117
|
+
'_highlight(',
|
118
|
+
'_marker',
|
119
|
+
'_part(',
|
120
|
+
'_placeholder',
|
121
|
+
'_selection',
|
122
|
+
'_slotted(',
|
123
|
+
'_spelling-error',
|
124
|
+
'_target-text',
|
125
|
+
'_view-transition',
|
126
|
+
'_view-transition-group',
|
127
|
+
'_view-transition-image-pair',
|
128
|
+
'_view-transition-new',
|
129
|
+
'_view-transition-old',
|
130
|
+
];
|
131
|
+
export const isPseudo = (selector) => pseudos.some(pseudo => selector.startsWith(pseudo));
|
@@ -0,0 +1,50 @@
|
|
1
|
+
export const validateShadow = (shadowProperties, styles, breakpoints) => {
|
2
|
+
// Collect breakpoints
|
3
|
+
shadowProperties.forEach(key => {
|
4
|
+
const value = styles[key];
|
5
|
+
if (typeof value !== 'object') {
|
6
|
+
return;
|
7
|
+
}
|
8
|
+
if (key === 'shadowOffset' || key === 'textShadowOffset') {
|
9
|
+
const { width, height } = value;
|
10
|
+
// If shadowOffset.width has breakpoints
|
11
|
+
if (typeof width === 'object') {
|
12
|
+
Object.keys(width).forEach(breakpoint => breakpoints.add(breakpoint));
|
13
|
+
}
|
14
|
+
// If shadowOffset.height has breakpoints
|
15
|
+
if (typeof height === 'object') {
|
16
|
+
Object.keys(height).forEach(breakpoint => breakpoints.add(breakpoint));
|
17
|
+
}
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
// Collect regular breakpoints
|
21
|
+
Object.keys(value).forEach(breakpoint => breakpoints.add(breakpoint));
|
22
|
+
});
|
23
|
+
// Validate if all breakpoints are present
|
24
|
+
shadowProperties.forEach(key => {
|
25
|
+
const value = styles[key];
|
26
|
+
if (typeof value !== 'object') {
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
if (key === 'shadowOffset' || key === 'textShadowOffset') {
|
30
|
+
const { width, height } = value;
|
31
|
+
if (typeof width === 'object') {
|
32
|
+
const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in width));
|
33
|
+
if (missingBreakpoints.length) {
|
34
|
+
throw `missing breakpoints in ${key}.width: ${missingBreakpoints.join(', ')}`;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
if (typeof height === 'object') {
|
38
|
+
const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in height));
|
39
|
+
if (missingBreakpoints.length) {
|
40
|
+
throw `missing breakpoints in ${key}.height: ${missingBreakpoints.join(', ')}`;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in value));
|
46
|
+
if (missingBreakpoints.length) {
|
47
|
+
throw `missing breakpoints in ${key}: ${missingBreakpoints.join(', ')}`;
|
48
|
+
}
|
49
|
+
});
|
50
|
+
};
|
@@ -0,0 +1,137 @@
|
|
1
|
+
import { keyInObject } from '../utils';
|
2
|
+
const SKIP_STYLES = [
|
3
|
+
'borderCurve',
|
4
|
+
'elevation',
|
5
|
+
'textAlignVertical',
|
6
|
+
'includeFontPadding',
|
7
|
+
'overlayColor',
|
8
|
+
'tintColor'
|
9
|
+
];
|
10
|
+
const CSS_NUMBER_KEYS = [
|
11
|
+
'animationIterationCount',
|
12
|
+
'borderImageOutset',
|
13
|
+
'borderImageSlice',
|
14
|
+
'borderImageWidth',
|
15
|
+
'boxFlex',
|
16
|
+
'boxFlexGroup',
|
17
|
+
'boxOrdinalGroup',
|
18
|
+
'columnCount',
|
19
|
+
'columns',
|
20
|
+
'counterIncrement',
|
21
|
+
'counterReset',
|
22
|
+
'flex',
|
23
|
+
'flexGrow',
|
24
|
+
'flexPositive',
|
25
|
+
'flexShrink',
|
26
|
+
'flexNegative',
|
27
|
+
'flexOrder',
|
28
|
+
'fontWeight',
|
29
|
+
'gridArea',
|
30
|
+
'gridColumn',
|
31
|
+
'gridColumnEnd',
|
32
|
+
'gridColumnSpan',
|
33
|
+
'gridColumnStart',
|
34
|
+
'gridRow',
|
35
|
+
'gridRowEnd',
|
36
|
+
'gridRowSpan',
|
37
|
+
'gridRowStart',
|
38
|
+
'line-clamp',
|
39
|
+
'line-height',
|
40
|
+
'opacity',
|
41
|
+
'order',
|
42
|
+
'orphans',
|
43
|
+
'tabSize',
|
44
|
+
'widows',
|
45
|
+
'zIndex',
|
46
|
+
'zoom',
|
47
|
+
'fillOpacity',
|
48
|
+
'floodOpacity',
|
49
|
+
'stopOpacity',
|
50
|
+
'strokeDasharray',
|
51
|
+
'strokeDashoffset',
|
52
|
+
'strokeMiterlimit',
|
53
|
+
'strokeOpacity',
|
54
|
+
'strokeWidth'
|
55
|
+
];
|
56
|
+
const convertMap = {
|
57
|
+
marginHorizontal: (value) => ({
|
58
|
+
marginInline: value
|
59
|
+
}),
|
60
|
+
marginVertical: (value) => ({
|
61
|
+
marginBlock: value
|
62
|
+
}),
|
63
|
+
paddingHorizontal: (value) => ({
|
64
|
+
paddingInline: value
|
65
|
+
}),
|
66
|
+
paddingVertical: (value) => ({
|
67
|
+
paddingBlock: value
|
68
|
+
}),
|
69
|
+
writingDirection: (value) => ({
|
70
|
+
direction: value
|
71
|
+
}),
|
72
|
+
borderBottomEndRadius: (value) => ({
|
73
|
+
borderBottomRightRadius: value
|
74
|
+
}),
|
75
|
+
borderBottomStartRadius: (value) => ({
|
76
|
+
borderBottomLeftRadius: value
|
77
|
+
}),
|
78
|
+
borderEndColor: (value) => ({
|
79
|
+
borderInlineEndColor: value
|
80
|
+
}),
|
81
|
+
borderStartColor: (value) => ({
|
82
|
+
borderInlineStartColor: value
|
83
|
+
}),
|
84
|
+
borderTopEndRadius: (value) => ({
|
85
|
+
borderTopRightRadius: value
|
86
|
+
}),
|
87
|
+
borderTopStartRadius: (value) => ({
|
88
|
+
borderTopLeftRadius: value
|
89
|
+
}),
|
90
|
+
borderEndWidth: (value) => ({
|
91
|
+
borderInlineEndWidth: value
|
92
|
+
}),
|
93
|
+
borderStartWidth: (value) => ({
|
94
|
+
borderInlineStartWidth: value
|
95
|
+
}),
|
96
|
+
end: (value) => ({
|
97
|
+
right: value
|
98
|
+
}),
|
99
|
+
start: (value) => ({
|
100
|
+
left: value
|
101
|
+
}),
|
102
|
+
marginEnd: (value) => ({
|
103
|
+
marginRight: value
|
104
|
+
}),
|
105
|
+
marginStart: (value) => ({
|
106
|
+
marginLeft: value
|
107
|
+
}),
|
108
|
+
paddingEnd: (value) => ({
|
109
|
+
paddingRight: value
|
110
|
+
}),
|
111
|
+
paddingStart: (value) => ({
|
112
|
+
paddingLeft: value
|
113
|
+
}),
|
114
|
+
transformMatrix: (value) => ({
|
115
|
+
transform: `matrix(${value.join(', ')})`
|
116
|
+
}),
|
117
|
+
resizeMode: (value) => ({
|
118
|
+
backgroundSize: value
|
119
|
+
})
|
120
|
+
};
|
121
|
+
const convertNumber = (key, value) => {
|
122
|
+
if (typeof value === 'number') {
|
123
|
+
return CSS_NUMBER_KEYS.includes(key, value) ? value : `${value}px`;
|
124
|
+
}
|
125
|
+
return value;
|
126
|
+
};
|
127
|
+
export const getStyle = (key, value) => {
|
128
|
+
if (SKIP_STYLES.includes(key)) {
|
129
|
+
return {};
|
130
|
+
}
|
131
|
+
if (keyInObject(convertMap, key)) {
|
132
|
+
return convertMap[key]?.(convertNumber(key, value)) ?? {};
|
133
|
+
}
|
134
|
+
return {
|
135
|
+
[key]: convertNumber(key, value)
|
136
|
+
};
|
137
|
+
};
|