rn-css 1.9.1 → 1.9.3
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/dist/cssToRN/index.js +13 -1
- package/dist/features.d.ts +16 -1
- package/dist/features.js +45 -1
- package/dist/index.d.ts +2720 -3
- package/dist/index.js +56 -172
- package/dist/styleComponent.d.ts +9 -2
- package/dist/styleComponent.js +30 -6
- package/dist/types.d.ts +2 -0
- package/package.json +2 -2
- package/src/features.tsx +4 -4
- package/src/styleComponent.tsx +13 -13
- package/dist/app.json +0 -4
- package/dist/src/convertStyle.d.ts +0 -5
- package/dist/src/convertStyle.js +0 -56
- package/dist/src/convertUnits.d.ts +0 -5
- package/dist/src/convertUnits.js +0 -71
- package/dist/src/cssToRN/convert.d.ts +0 -55
- package/dist/src/cssToRN/convert.js +0 -418
- package/dist/src/cssToRN/index.d.ts +0 -8
- package/dist/src/cssToRN/index.js +0 -140
- package/dist/src/cssToRN/maths.d.ts +0 -4
- package/dist/src/cssToRN/maths.js +0 -86
- package/dist/src/cssToRN/mediaQueries.d.ts +0 -7
- package/dist/src/cssToRN/mediaQueries.js +0 -161
- package/dist/src/features.d.ts +0 -43
- package/dist/src/features.js +0 -130
- package/dist/src/generateHash.d.ts +0 -2
- package/dist/src/generateHash.js +0 -8
- package/dist/src/index.d.ts +0 -2720
- package/dist/src/index.js +0 -60
- package/dist/src/polyfill.d.ts +0 -3
- package/dist/src/polyfill.js +0 -23
- package/dist/src/rnToCss.d.ts +0 -3
- package/dist/src/rnToCss.js +0 -8
- package/dist/src/styleComponent.d.ts +0 -50
- package/dist/src/styleComponent.js +0 -181
- package/dist/src/types.d.ts +0 -86
- package/dist/src/types.js +0 -2
- package/dist/src/useTheme.d.ts +0 -18
- package/dist/src/useTheme.js +0 -33
package/dist/src/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.RemContext = exports.FontSizeContext = exports.SharedValue = exports.cssToRNStyle = void 0;
|
|
26
|
-
const RN = __importStar(require("react-native"));
|
|
27
|
-
require("./polyfill");
|
|
28
|
-
const styleComponent_1 = __importStar(require("./styleComponent"));
|
|
29
|
-
var cssToRN_1 = require("./cssToRN");
|
|
30
|
-
Object.defineProperty(exports, "cssToRNStyle", { enumerable: true, get: function () { return cssToRN_1.cssToRNStyle; } });
|
|
31
|
-
var styleComponent_2 = require("./styleComponent");
|
|
32
|
-
Object.defineProperty(exports, "SharedValue", { enumerable: true, get: function () { return styleComponent_2.SharedValue; } });
|
|
33
|
-
Object.defineProperty(exports, "FontSizeContext", { enumerable: true, get: function () { return styleComponent_2.FontSizeContext; } });
|
|
34
|
-
Object.defineProperty(exports, "RemContext", { enumerable: true, get: function () { return styleComponent_2.RemContext; } });
|
|
35
|
-
__exportStar(require("./useTheme"), exports);
|
|
36
|
-
const styled = (Component) => (0, styleComponent_1.default)(Component);
|
|
37
|
-
styled.ActivityIndicator = styled(RN.ActivityIndicator);
|
|
38
|
-
styled.DrawerLayoutAndroid = styled(RN.DrawerLayoutAndroid);
|
|
39
|
-
styled.Image = styled(RN.Image);
|
|
40
|
-
styled.ImageBackground = styled(RN.ImageBackground);
|
|
41
|
-
styled.KeyboardAvoidingView = styled(RN.KeyboardAvoidingView);
|
|
42
|
-
styled.Modal = styled(RN.Modal);
|
|
43
|
-
styled.NavigatorIOS = styled(RN.NavigatorIOS);
|
|
44
|
-
styled.ScrollView = styled(RN.ScrollView);
|
|
45
|
-
styled.SnapshotViewIOS = styled(RN.SnapshotViewIOS);
|
|
46
|
-
styled.Switch = styled(RN.Switch);
|
|
47
|
-
styled.RecyclerViewBackedScrollView = styled(RN.RecyclerViewBackedScrollView);
|
|
48
|
-
styled.RefreshControl = styled(RN.RefreshControl);
|
|
49
|
-
styled.SafeAreaView = styled(RN.SafeAreaView);
|
|
50
|
-
styled.Text = styled(RN.Text);
|
|
51
|
-
styled.TextInput = styled(RN.TextInput);
|
|
52
|
-
styled.TouchableHighlight = styled(RN.TouchableHighlight);
|
|
53
|
-
styled.TouchableNativeFeedback = styled(RN.TouchableNativeFeedback);
|
|
54
|
-
styled.TouchableOpacity = styled(RN.TouchableOpacity);
|
|
55
|
-
styled.TouchableWithoutFeedback = styled(RN.TouchableWithoutFeedback);
|
|
56
|
-
styled.View = styled(RN.View);
|
|
57
|
-
styled.FlatList = styleComponent_1.styledFlatList;
|
|
58
|
-
styled.SectionList = styleComponent_1.styledSectionList;
|
|
59
|
-
styled.VirtualizedList = styleComponent_1.styledVirtualizedList;
|
|
60
|
-
exports.default = styled;
|
package/dist/src/polyfill.d.ts
DELETED
package/dist/src/polyfill.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/** polyfill for Node < 12 */
|
|
3
|
-
// eslint-disable-next-line no-extend-native
|
|
4
|
-
if (!Array.prototype.flat)
|
|
5
|
-
Array.prototype.flat = function (depth) { return flat(this, depth); };
|
|
6
|
-
// eslint-disable-next-line no-extend-native
|
|
7
|
-
if (!String.prototype.matchAll)
|
|
8
|
-
String.prototype.matchAll = function (regex) { return matchAll(this, regex); };
|
|
9
|
-
/** polyfill for Node < 12 */
|
|
10
|
-
function flat(array, depth = 1) {
|
|
11
|
-
if (!depth || depth < 1 || !Array.isArray(array))
|
|
12
|
-
return array;
|
|
13
|
-
return array.reduce((result, current) => result.concat(flat(current, depth - 1)), []);
|
|
14
|
-
}
|
|
15
|
-
function matchAll(str, regex) {
|
|
16
|
-
const matches = [];
|
|
17
|
-
let groups;
|
|
18
|
-
// eslint-disable-next-line no-cond-assign
|
|
19
|
-
while (groups = regex.exec(str)) {
|
|
20
|
-
matches.push(groups);
|
|
21
|
-
}
|
|
22
|
-
return matches[Symbol.iterator]();
|
|
23
|
-
}
|
package/dist/src/rnToCss.d.ts
DELETED
package/dist/src/rnToCss.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const rnToCSS = (rn) => Object.entries(rn)
|
|
4
|
-
.map(([key, value]) => `${camelToKebab(key)}: ${convertValue(value)};`)
|
|
5
|
-
.join('\n');
|
|
6
|
-
const camelToKebab = (str) => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
7
|
-
const convertValue = (value) => isNaN(value) ? value : (value + 'px');
|
|
8
|
-
exports.default = rnToCSS;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import React, { MouseEvent } from 'react';
|
|
2
|
-
import { FlatListProps, GestureResponderEvent, LayoutChangeEvent, NativeSyntheticEvent, SectionListProps, StyleProp, TargetedEvent, VirtualizedListProps } from 'react-native';
|
|
3
|
-
import type { CompleteStyle, Units } from './types';
|
|
4
|
-
export declare const defaultUnits: Units;
|
|
5
|
-
export declare const RemContext: React.Context<number>;
|
|
6
|
-
export declare const FontSizeContext: React.Context<number>;
|
|
7
|
-
export declare const SharedValue: React.Context<unknown>;
|
|
8
|
-
export interface DefaultTheme {
|
|
9
|
-
}
|
|
10
|
-
declare type Primitive = number | string | null | undefined | boolean | CompleteStyle;
|
|
11
|
-
declare type Functs<T> = (arg: T & {
|
|
12
|
-
rnCSS?: string;
|
|
13
|
-
shared: unknown;
|
|
14
|
-
theme: DefaultTheme;
|
|
15
|
-
}) => Primitive;
|
|
16
|
-
declare type OptionalProps = {
|
|
17
|
-
rnCSS?: `${string};`;
|
|
18
|
-
onFocus?: (event: NativeSyntheticEvent<TargetedEvent>) => void;
|
|
19
|
-
onBlur?: (event: NativeSyntheticEvent<TargetedEvent>) => void;
|
|
20
|
-
onPressIn?: (event: GestureResponderEvent) => void;
|
|
21
|
-
onPressOut?: (event: GestureResponderEvent) => void;
|
|
22
|
-
onResponderStart?: (event: GestureResponderEvent) => void;
|
|
23
|
-
onResponderRelease?: (event: GestureResponderEvent) => void;
|
|
24
|
-
onResponderGrant?: (event: GestureResponderEvent) => boolean;
|
|
25
|
-
onMouseEnter?: (event: MouseEvent) => void;
|
|
26
|
-
onMouseLeave?: (event: MouseEvent) => void;
|
|
27
|
-
onLayout?: (event: LayoutChangeEvent) => void;
|
|
28
|
-
children?: React.ReactNode;
|
|
29
|
-
};
|
|
30
|
-
declare const styled: <StyleType, InitialProps extends {
|
|
31
|
-
style?: StyleProp<StyleType>;
|
|
32
|
-
}, Props extends InitialProps & OptionalProps = InitialProps & OptionalProps>(Component: React.ComponentType<InitialProps>) => {
|
|
33
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]): React.ForwardRefExoticComponent<Props & S & {
|
|
34
|
-
ref?: React.Ref<any> | undefined;
|
|
35
|
-
}>;
|
|
36
|
-
attrs<Part, Result extends Partial<Props & Part> = Partial<Props & Part>>(opts: Result | ((props: Props & Part) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<Props & Part>)[]) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Omit<Props, keyof Result> & Part & Partial<Pick<Props, Extract<keyof Props, keyof Result>>>> & React.RefAttributes<any>>;
|
|
37
|
-
};
|
|
38
|
-
export default styled;
|
|
39
|
-
export declare const styledFlatList: {
|
|
40
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & FlatListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & FlatListProps<Type>) => JSX.Element;
|
|
41
|
-
attrs<S_1, Result extends Partial<S_1 & FlatListProps<any> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & FlatListProps<any>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<FlatListProps<Props> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
42
|
-
};
|
|
43
|
-
export declare const styledSectionList: {
|
|
44
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps>)[]): <Type>(props: S & OptionalProps & SectionListProps<Type, import("react-native").DefaultSectionT>) => JSX.Element;
|
|
45
|
-
attrs<S_1, Result extends Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & SectionListProps<any, import("react-native").DefaultSectionT>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<SectionListProps<Props, import("react-native").DefaultSectionT> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
46
|
-
};
|
|
47
|
-
export declare const styledVirtualizedList: {
|
|
48
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & VirtualizedListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & VirtualizedListProps<Type>) => JSX.Element;
|
|
49
|
-
attrs<S_1, Result extends Partial<S_1 & VirtualizedListProps<any> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & VirtualizedListProps<any>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<VirtualizedListProps<Props> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
50
|
-
};
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.styledVirtualizedList = exports.styledSectionList = exports.styledFlatList = exports.SharedValue = exports.FontSizeContext = exports.RemContext = exports.defaultUnits = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
8
|
-
/* eslint-disable react/prop-types */
|
|
9
|
-
/* eslint-disable react/display-name */
|
|
10
|
-
const react_1 = __importDefault(require("react"));
|
|
11
|
-
const react_native_1 = require("react-native");
|
|
12
|
-
const convertStyle_1 = __importDefault(require("./convertStyle"));
|
|
13
|
-
const cssToRN_1 = __importDefault(require("./cssToRN"));
|
|
14
|
-
const features_1 = require("./features");
|
|
15
|
-
const generateHash_1 = __importDefault(require("./generateHash"));
|
|
16
|
-
const rnToCss_1 = __importDefault(require("./rnToCss"));
|
|
17
|
-
exports.defaultUnits = { em: 16, vw: 1, vh: 1, vmin: 1, vmax: 1, rem: 16, px: 1, pt: 72 / 96, in: 96, pc: 9, cm: 96 / 2.54, mm: 96 / 25.4 };
|
|
18
|
-
exports.RemContext = react_1.default.createContext(exports.defaultUnits.rem);
|
|
19
|
-
exports.FontSizeContext = react_1.default.createContext(exports.defaultUnits.em);
|
|
20
|
-
// We use this to share value within the component (Theme, Translation, whatever)
|
|
21
|
-
exports.SharedValue = react_1.default.createContext(undefined);
|
|
22
|
-
/** Converts the tagged template string into a css string */
|
|
23
|
-
function buildCSSString(chunks, functs, props, shared) {
|
|
24
|
-
let computedString = chunks
|
|
25
|
-
// Evaluate the chunks from the tagged template
|
|
26
|
-
.map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? functs[i]({ shared, theme: shared, ...props }) : functs[i]]))
|
|
27
|
-
.flat()
|
|
28
|
-
// Convert the objects to string if the result is not a primitive
|
|
29
|
-
.map(chunk => typeof chunk === 'object' ? (0, rnToCss_1.default)(chunk) : chunk)
|
|
30
|
-
.join('');
|
|
31
|
-
if (props.rnCSS)
|
|
32
|
-
computedString += props.rnCSS.replace(/=/gm, ':') + ';';
|
|
33
|
-
return computedString;
|
|
34
|
-
}
|
|
35
|
-
const styleMap = {};
|
|
36
|
-
function getStyle(hash, style) {
|
|
37
|
-
const styleInfo = styleMap[hash];
|
|
38
|
-
if (styleInfo) {
|
|
39
|
-
styleInfo.usage++;
|
|
40
|
-
return styleInfo.style;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const sheet = react_native_1.StyleSheet.create({ [hash]: style });
|
|
44
|
-
return (styleMap[hash] = { style: sheet[hash], usage: 1 }).style;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function removeStyle(hash) {
|
|
48
|
-
styleMap[hash].usage--;
|
|
49
|
-
if (styleMap[hash].usage <= 0)
|
|
50
|
-
delete styleMap[hash];
|
|
51
|
-
}
|
|
52
|
-
const styled = (Component) => {
|
|
53
|
-
const styledComponent = (chunks, ...functs) => {
|
|
54
|
-
const ForwardRefComponent = react_1.default.forwardRef((props, ref) => {
|
|
55
|
-
const rem = react_1.default.useContext(exports.RemContext);
|
|
56
|
-
const shared = react_1.default.useContext(exports.SharedValue);
|
|
57
|
-
// Build the css string with the context
|
|
58
|
-
const css = react_1.default.useMemo(() => buildCSSString(chunks, functs, props, shared), [props, shared]);
|
|
59
|
-
// Store the style in RN format
|
|
60
|
-
const rnStyle = react_1.default.useMemo(() => (0, cssToRN_1.default)(css), [css]);
|
|
61
|
-
const { needsLayout, needsHover, needsFocus, needsTouch } = react_1.default.useMemo(() => ({
|
|
62
|
-
// needsFontSize: !!css.match(/\b(\d+)(\.\d+)?em\b/)
|
|
63
|
-
// needsScreenSize: !!css.match(/\b(\d+)(\.\d*)?v([hw]|min|max)\b/) || !!rnStyle.media,
|
|
64
|
-
needsLayout: !!css.match(/\d%/),
|
|
65
|
-
needsHover: !!rnStyle.hover,
|
|
66
|
-
needsTouch: !!rnStyle.active,
|
|
67
|
-
needsFocus: !!rnStyle.focus
|
|
68
|
-
}), [css, rnStyle.active, rnStyle.focus, rnStyle.hover]);
|
|
69
|
-
// Handle hover
|
|
70
|
-
const { onMouseEnter, onMouseLeave, hover } = (0, features_1.useHover)(props.onMouseEnter, props.onMouseLeave, needsHover);
|
|
71
|
-
// Handle active
|
|
72
|
-
const { onPressIn, onPressOut, onResponderGrant, onResponderRelease, onResponderStart, active } = (0, features_1.useActive)(props.onPressIn, props.onPressOut, props.onResponderStart, props.onResponderRelease, props.onResponderGrant, needsTouch);
|
|
73
|
-
// Handle focus
|
|
74
|
-
const { onFocus, onBlur, focused } = (0, features_1.useFocus)(props.onFocus, props.onBlur, needsFocus);
|
|
75
|
-
const tempStyle = react_1.default.useMemo(() => {
|
|
76
|
-
const style = { ...rnStyle };
|
|
77
|
-
delete style.media;
|
|
78
|
-
delete style.hover;
|
|
79
|
-
delete style.active;
|
|
80
|
-
delete style.focus;
|
|
81
|
-
if (focused)
|
|
82
|
-
Object.assign(style, rnStyle.focus);
|
|
83
|
-
if (hover)
|
|
84
|
-
Object.assign(style, rnStyle.hover);
|
|
85
|
-
if (active)
|
|
86
|
-
Object.assign(style, rnStyle.active);
|
|
87
|
-
return style;
|
|
88
|
-
}, [active, focused, hover, rnStyle]);
|
|
89
|
-
// Calculate current em unit for media-queries
|
|
90
|
-
const parentEm = react_1.default.useContext(exports.FontSizeContext);
|
|
91
|
-
const { em: tempEm } = (0, features_1.useFontSize)(tempStyle.fontSize, rem, parentEm);
|
|
92
|
-
// Handle layout data needed for % units
|
|
93
|
-
const { width, height, onLayout } = (0, features_1.useLayout)(props.onLayout, needsLayout);
|
|
94
|
-
// Handle screen size needed for vw and wh units
|
|
95
|
-
const screenUnits = (0, features_1.useScreenSize)();
|
|
96
|
-
/** The units before re-updating the em */
|
|
97
|
-
const baseUnits = react_1.default.useMemo(() => ({
|
|
98
|
-
...exports.defaultUnits,
|
|
99
|
-
rem,
|
|
100
|
-
em: tempEm,
|
|
101
|
-
width,
|
|
102
|
-
height,
|
|
103
|
-
...screenUnits
|
|
104
|
-
}), [height, rem, screenUnits, tempEm, width]);
|
|
105
|
-
// apply media queries
|
|
106
|
-
const mediaQuery = (0, features_1.useMediaQuery)(rnStyle.media, baseUnits);
|
|
107
|
-
// Handle em units
|
|
108
|
-
const fontSize = (mediaQuery && mediaQuery.fontSize) || tempStyle.fontSize;
|
|
109
|
-
const { em } = (0, features_1.useFontSize)(fontSize, baseUnits.rem, parentEm);
|
|
110
|
-
const finalStyle = react_1.default.useMemo(() => {
|
|
111
|
-
const style = { ...tempStyle, ...mediaQuery };
|
|
112
|
-
if (style.fontSize)
|
|
113
|
-
style.fontSize = em + 'px';
|
|
114
|
-
if (style.zIndex === undefined && react_native_1.Platform.OS === 'web')
|
|
115
|
-
style.zIndex = 'auto';
|
|
116
|
-
return style;
|
|
117
|
-
}, [em, mediaQuery, tempStyle]);
|
|
118
|
-
const units = react_1.default.useMemo(() => ({ ...baseUnits, em }), [baseUnits, em]);
|
|
119
|
-
const { style: styleConvertedFromCSS, hash } = react_1.default.useMemo(() => {
|
|
120
|
-
const style = (0, convertStyle_1.default)(finalStyle, units);
|
|
121
|
-
delete style.textOverflow;
|
|
122
|
-
const hash = (0, generateHash_1.default)(JSON.stringify(style));
|
|
123
|
-
return { style: getStyle(hash, style), hash };
|
|
124
|
-
}, [finalStyle, units]);
|
|
125
|
-
const newProps = react_1.default.useMemo(() => {
|
|
126
|
-
const newProps = {
|
|
127
|
-
style: [styleConvertedFromCSS, props.style],
|
|
128
|
-
onMouseEnter,
|
|
129
|
-
onMouseLeave,
|
|
130
|
-
onLayout,
|
|
131
|
-
onFocus,
|
|
132
|
-
onBlur,
|
|
133
|
-
onPressIn,
|
|
134
|
-
onPressOut,
|
|
135
|
-
onResponderGrant,
|
|
136
|
-
onResponderStart,
|
|
137
|
-
onResponderRelease
|
|
138
|
-
};
|
|
139
|
-
if (finalStyle.textOverflow === 'ellipsis') {
|
|
140
|
-
Object.assign(newProps, { numberOfLines: 1 });
|
|
141
|
-
}
|
|
142
|
-
return newProps;
|
|
143
|
-
}, [finalStyle.textOverflow, onBlur, onFocus, onLayout, onMouseEnter, onMouseLeave, onPressIn, onPressOut, onResponderGrant, onResponderRelease, onResponderStart, props.style, styleConvertedFromCSS]);
|
|
144
|
-
react_1.default.useEffect(() => () => removeStyle(hash), [hash]);
|
|
145
|
-
// em !== parentEm alone is a bit dangerous as the component would rerender when the font size change
|
|
146
|
-
if (em !== parentEm || finalStyle.fontSize !== undefined) {
|
|
147
|
-
return react_1.default.createElement(exports.FontSizeContext.Provider, { value: em },
|
|
148
|
-
react_1.default.createElement(Component, { ref: ref, ...props, ...newProps }));
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
return react_1.default.createElement(Component, { ref: ref, ...props, ...newProps });
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return ForwardRefComponent;
|
|
155
|
-
};
|
|
156
|
-
// provide styled(Comp).attrs({} | () => {}) feature
|
|
157
|
-
styledComponent.attrs = (opts) => (chunks, ...functs) => {
|
|
158
|
-
const ComponentWithAttrs = styledComponent(chunks, ...functs);
|
|
159
|
-
// We need to limit the props control to only Result https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABBATgUwIZTQUQB7ZgAmaRAwnALYAOAPAAopzUDOAfABQU0BciH1Jqz6NmLAJSIAvG0QYwAT0kBvAFCJkCFlET5CJYt2rT+gsSKETpstRo3ooIFEiMDL49YgC+nvWmL+5FTUAHRYUCgsJrQASmgsIAA2OmgEgVH0GCiwGIkMlmyc4ZF8cQnJkjKItnYQWjqMaHVgwDAA5k5YpEYmbua6eBCJICT5YgA0iGVJUGyVNp52iA5OLsEcyiFbZqyTW2FQESxeHks+SyvOiI3NrR0oXUE0nufLaI5XfgGGwao+qqBILAEIgen1hNVENhtHxtCgYGA2pNtApEmhYREEW1vCpPJckDsWH9VM1tNd0Ld2j0pMh0F0viQntQuMFxAcjhsofEoHwAORwADWvJxqhuCDurmUiBRaL50KgwpOQA
|
|
160
|
-
const ForwardRefComponent = react_1.default.forwardRef((props, ref) => {
|
|
161
|
-
const attrs = (opts instanceof Function) ? opts(props) : opts;
|
|
162
|
-
return react_1.default.createElement(ComponentWithAttrs, { ref: ref, ...props, ...attrs });
|
|
163
|
-
});
|
|
164
|
-
// TODO : Find a way to remove from the Props the properties affected by opts
|
|
165
|
-
return ForwardRefComponent;
|
|
166
|
-
};
|
|
167
|
-
return styledComponent;
|
|
168
|
-
};
|
|
169
|
-
exports.default = styled;
|
|
170
|
-
const styledFlatList = (chunks, ...functs) => (props) => invoke(styled(react_native_1.FlatList)(chunks, ...functs), props);
|
|
171
|
-
exports.styledFlatList = styledFlatList;
|
|
172
|
-
exports.styledFlatList.attrs = (opts) => (chunks, ...functs) => (componentProps) => invoke(styled(react_native_1.FlatList).attrs(opts)(chunks, ...functs), componentProps);
|
|
173
|
-
const styledSectionList = (chunks, ...functs) => (props) => invoke(styled(react_native_1.SectionList)(chunks, ...functs), props);
|
|
174
|
-
exports.styledSectionList = styledSectionList;
|
|
175
|
-
exports.styledSectionList.attrs = (opts) => (chunks, ...functs) => (componentProps) => invoke(styled(react_native_1.SectionList).attrs(opts)(chunks, ...functs), componentProps);
|
|
176
|
-
const styledVirtualizedList = (chunks, ...functs) => (props) => invoke(styled(react_native_1.VirtualizedList)(chunks, ...functs), props);
|
|
177
|
-
exports.styledVirtualizedList = styledVirtualizedList;
|
|
178
|
-
exports.styledVirtualizedList.attrs = (opts) => (chunks, ...functs) => (componentProps) => invoke(styled(react_native_1.VirtualizedList).attrs(opts)(chunks, ...functs), componentProps);
|
|
179
|
-
function invoke(Component, props) {
|
|
180
|
-
return react_1.default.createElement(Component, { ...props });
|
|
181
|
-
}
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { ViewStyle, TextStyle, ImageStyle } from 'react-native';
|
|
2
|
-
export declare type Units = {
|
|
3
|
-
'%'?: number;
|
|
4
|
-
vw?: number;
|
|
5
|
-
vh?: number;
|
|
6
|
-
vmin?: number;
|
|
7
|
-
vmax?: number;
|
|
8
|
-
em: number;
|
|
9
|
-
rem: number;
|
|
10
|
-
px: number;
|
|
11
|
-
pt: number;
|
|
12
|
-
pc: number;
|
|
13
|
-
in: number;
|
|
14
|
-
cm: number;
|
|
15
|
-
mm: number;
|
|
16
|
-
width?: number;
|
|
17
|
-
height?: number;
|
|
18
|
-
};
|
|
19
|
-
export declare type Context = {
|
|
20
|
-
type: 'all' | 'sprint' | 'speech' | 'screen';
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
aspectRatio: number;
|
|
24
|
-
orientation: 'portrait' | 'landscape';
|
|
25
|
-
resolution: number;
|
|
26
|
-
scan: 'interlace' | 'progressive';
|
|
27
|
-
grid: 0 | 1;
|
|
28
|
-
update: 'none' | 'slow' | 'fast';
|
|
29
|
-
overflowBlock: 'none' | 'scroll' | 'paged';
|
|
30
|
-
overflowInline: 'none' | 'scroll';
|
|
31
|
-
environmentBlending: 'opaque' | 'additive' | 'subtractive';
|
|
32
|
-
color: number;
|
|
33
|
-
colorGamut: 'srgb' | 'p3' | 'rec2020';
|
|
34
|
-
colorIndex: number;
|
|
35
|
-
dynamicRange: 'standard' | 'high';
|
|
36
|
-
monochrome: number;
|
|
37
|
-
invertedColors: 'none' | 'inverted';
|
|
38
|
-
pointer: 'none' | 'coarse' | 'fine';
|
|
39
|
-
hover: 'none' | 'hover';
|
|
40
|
-
anyPointer: 'none' | 'coarse' | 'fine';
|
|
41
|
-
anyHover: 'none' | 'hover';
|
|
42
|
-
prefersReducedMotion: 'no-preference' | 'reduce';
|
|
43
|
-
prefersReducedTransparency: 'no-preference' | 'reduce';
|
|
44
|
-
prefersReducedData: 'no-preference' | 'reduce';
|
|
45
|
-
prefersContrast: 'no-preference' | 'high' | 'low' | 'forced';
|
|
46
|
-
prefersColorScheme: 'light' | 'dark';
|
|
47
|
-
forcedColor: 'none' | 'active';
|
|
48
|
-
scripting: 'none' | 'initial-only' | 'enabled';
|
|
49
|
-
deviceWidth: number;
|
|
50
|
-
deviceHeight: number;
|
|
51
|
-
deviceAspectRatio: number;
|
|
52
|
-
units: Units;
|
|
53
|
-
};
|
|
54
|
-
export declare type AnyStyle = ViewStyle | TextStyle | ImageStyle;
|
|
55
|
-
export declare type CompleteStyle = ViewStyle & TextStyle & ImageStyle;
|
|
56
|
-
export declare type PartialStyle = Partial<Record<keyof CompleteStyle, string>> & {
|
|
57
|
-
shadowOffset?: {
|
|
58
|
-
width: string;
|
|
59
|
-
height: string;
|
|
60
|
-
};
|
|
61
|
-
textShadowOffset?: {
|
|
62
|
-
width: string;
|
|
63
|
-
height: string;
|
|
64
|
-
};
|
|
65
|
-
textOverflow?: 'ellipsis';
|
|
66
|
-
transform?: Transform[];
|
|
67
|
-
};
|
|
68
|
-
export declare type Style = PartialStyle & {
|
|
69
|
-
hover?: PartialStyle;
|
|
70
|
-
active?: PartialStyle;
|
|
71
|
-
focus?: PartialStyle;
|
|
72
|
-
media?: MediaQuery[];
|
|
73
|
-
};
|
|
74
|
-
export declare type MediaQuery = (context: Context) => false | PartialStyle;
|
|
75
|
-
export declare type Transform = {
|
|
76
|
-
scaleX?: string;
|
|
77
|
-
scaleY?: string;
|
|
78
|
-
translateX?: string;
|
|
79
|
-
translateY?: string;
|
|
80
|
-
skewX?: string;
|
|
81
|
-
skewY?: string;
|
|
82
|
-
perspective?: string;
|
|
83
|
-
rotateX?: string;
|
|
84
|
-
rotateY?: string;
|
|
85
|
-
rotateZ?: string;
|
|
86
|
-
};
|
package/dist/src/types.js
DELETED
package/dist/src/useTheme.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { DefaultTheme } from './styleComponent';
|
|
3
|
-
/** Provider for the theme. */
|
|
4
|
-
export declare const ThemeProvider: ({ theme, children }: {
|
|
5
|
-
theme: DefaultTheme;
|
|
6
|
-
children: React.ReactNode;
|
|
7
|
-
}) => JSX.Element;
|
|
8
|
-
/**
|
|
9
|
-
* Returns the Theme
|
|
10
|
-
* @returns The Theme object
|
|
11
|
-
*/
|
|
12
|
-
export declare const useTheme: () => unknown;
|
|
13
|
-
/**
|
|
14
|
-
* Adds the theme prop to a non rn-css component
|
|
15
|
-
* @param Component A non rn-css component
|
|
16
|
-
* @returns A component with the theme prop
|
|
17
|
-
*/
|
|
18
|
-
export declare const withTheme: <T>(Component: React.ComponentType<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<T> & React.RefAttributes<React.Component<{}, {}, any>>>;
|
package/dist/src/useTheme.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.withTheme = exports.useTheme = exports.ThemeProvider = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const styleComponent_1 = require("./styleComponent");
|
|
9
|
-
/** Provider for the theme. */
|
|
10
|
-
const ThemeProvider = ({ theme, children }) => {
|
|
11
|
-
return react_1.default.createElement(styleComponent_1.SharedValue.Provider, { value: theme }, children);
|
|
12
|
-
};
|
|
13
|
-
exports.ThemeProvider = ThemeProvider;
|
|
14
|
-
/**
|
|
15
|
-
* Returns the Theme
|
|
16
|
-
* @returns The Theme object
|
|
17
|
-
*/
|
|
18
|
-
const useTheme = () => react_1.default.useContext(styleComponent_1.SharedValue);
|
|
19
|
-
exports.useTheme = useTheme;
|
|
20
|
-
/**
|
|
21
|
-
* Adds the theme prop to a non rn-css component
|
|
22
|
-
* @param Component A non rn-css component
|
|
23
|
-
* @returns A component with the theme prop
|
|
24
|
-
*/
|
|
25
|
-
const withTheme = (Component) => {
|
|
26
|
-
const ThemedComponent = react_1.default.forwardRef((props, ref) => {
|
|
27
|
-
const theme = (0, exports.useTheme)();
|
|
28
|
-
return react_1.default.createElement(Component, { ref: ref, theme: theme, ...props });
|
|
29
|
-
});
|
|
30
|
-
ThemedComponent.displayName = 'ThemedComponent';
|
|
31
|
-
return ThemedComponent;
|
|
32
|
-
};
|
|
33
|
-
exports.withTheme = withTheme;
|