rn-css 1.5.2 → 1.5.5
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/convertUnits.js +4 -1
- package/dist/styleComponent.js +1 -1
- package/package.json +5 -5
- package/src/convertUnits.ts +3 -1
- package/src/styleComponent.tsx +1 -1
package/dist/convertUnits.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertValue = exports.parseValue = void 0;
|
|
4
4
|
const maths_1 = require("./cssToRN/maths");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
5
6
|
/** Take a css value like 12em and return [12, 'em'] */
|
|
6
7
|
function parseValue(value) {
|
|
7
8
|
// Match a single unit
|
|
8
|
-
const unit = value.match(/([+-]?\b\d+(\.\d+)?)([a-z]+\b|%)
|
|
9
|
+
const unit = value.match(/([+-]?\b\d+(\.\d+)?)([a-z]+\b|%)?/i);
|
|
9
10
|
return [parseFloat(unit[1]), unit[3]];
|
|
10
11
|
}
|
|
11
12
|
exports.parseValue = parseValue;
|
|
@@ -21,6 +22,8 @@ function convertValue(key, value, units) {
|
|
|
21
22
|
// Percentage values need to rely on an other unit as reference
|
|
22
23
|
const finalUnits = { ...units };
|
|
23
24
|
if (value.includes('%')) {
|
|
25
|
+
if (react_native_1.Platform.OS === 'web')
|
|
26
|
+
return value;
|
|
24
27
|
if (['marginTop', 'marginBottom', 'translateY'].includes(key))
|
|
25
28
|
finalUnits['%'] = units.height / 100;
|
|
26
29
|
else if (['marginLeft', 'marginRight', 'translateX'].includes(key))
|
package/dist/styleComponent.js
CHANGED
|
@@ -17,7 +17,7 @@ const styleMap = {};
|
|
|
17
17
|
// We use this to share value within the component (Theme, Translation, whatever)
|
|
18
18
|
exports.SharedValue = react_1.default.createContext(undefined);
|
|
19
19
|
function buildCSSString(chunks, functs, props, shared) {
|
|
20
|
-
let computedString = chunks.map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? functs[i]({
|
|
20
|
+
let computedString = chunks.map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? functs[i]({ shared, theme: shared, ...props }) : functs[i]])).flat().join('');
|
|
21
21
|
if (props.rnCSS)
|
|
22
22
|
computedString += props.rnCSS.replace(/=/gm, ':') + ';';
|
|
23
23
|
return computedString;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-css",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"test": "jest",
|
|
6
6
|
"prepare": "tsc",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"html-loader": "^3.0.1",
|
|
40
40
|
"html-webpack-plugin": "^5.5.0",
|
|
41
41
|
"husky": "^7.0.4",
|
|
42
|
-
"jest": "^27.
|
|
42
|
+
"jest": "^27.5.1",
|
|
43
43
|
"lint-staged": "^12.1.2",
|
|
44
|
-
"metro-react-native-babel-preset": "^0.
|
|
44
|
+
"metro-react-native-babel-preset": "^0.70.0",
|
|
45
45
|
"react": "^17.0.2",
|
|
46
46
|
"react-dom": "^17.0.2",
|
|
47
|
-
"react-native": "^0.
|
|
47
|
+
"react-native": "^0.68.0",
|
|
48
48
|
"react-native-typescript-transformer": "^1.2.13",
|
|
49
|
-
"react-native-web": "^0.17.
|
|
49
|
+
"react-native-web": "^0.17.7",
|
|
50
50
|
"react-test-renderer": "17.0.2",
|
|
51
51
|
"release-it": "^14.11.8",
|
|
52
52
|
"ts-jest": "^27.1.1",
|
package/src/convertUnits.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { PartialStyle, Transform, Units } from './types'
|
|
2
2
|
import { calculate, min, max } from './cssToRN/maths'
|
|
3
|
+
import { Platform } from 'react-native'
|
|
3
4
|
|
|
4
5
|
/** Take a css value like 12em and return [12, 'em'] */
|
|
5
6
|
export function parseValue (value: string): [number, string | undefined] {
|
|
6
7
|
// Match a single unit
|
|
7
|
-
const unit = value.match(/([+-]?\b\d+(\.\d+)?)([a-z]+\b|%)
|
|
8
|
+
const unit = value.match(/([+-]?\b\d+(\.\d+)?)([a-z]+\b|%)?/i)
|
|
8
9
|
return [parseFloat(unit![1]), unit![3] as (string | undefined)]
|
|
9
10
|
}
|
|
10
11
|
|
|
@@ -20,6 +21,7 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
|
|
|
20
21
|
// Percentage values need to rely on an other unit as reference
|
|
21
22
|
const finalUnits = { ...units }
|
|
22
23
|
if (value.includes('%')) {
|
|
24
|
+
if (Platform.OS === 'web') return value
|
|
23
25
|
if (['marginTop', 'marginBottom', 'translateY'].includes(key)) finalUnits['%'] = units.height! / 100
|
|
24
26
|
else if (['marginLeft', 'marginRight', 'translateX'].includes(key)) finalUnits['%'] = units.width! / 100
|
|
25
27
|
else if (key.startsWith('border') && key.endsWith('Radius')) finalUnits['%'] = (units.width! + units.height!) / 200
|
package/src/styleComponent.tsx
CHANGED
|
@@ -25,7 +25,7 @@ type OptionalProps = {
|
|
|
25
25
|
style?: StyleProp<any>;
|
|
26
26
|
}
|
|
27
27
|
function buildCSSString<T extends { rnCSS?: string }> (chunks: TemplateStringsArray, functs: (Primitive | Functs<T>)[], props: T, shared: unknown) {
|
|
28
|
-
let computedString = chunks.map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? (functs[i] as Functs<T>)({
|
|
28
|
+
let computedString = chunks.map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? (functs[i] as Functs<T>)({ shared, theme: shared, ...props }) : functs[i]])).flat().join('')
|
|
29
29
|
if (props.rnCSS) computedString += props.rnCSS.replace(/=/gm, ':') + ';'
|
|
30
30
|
return computedString
|
|
31
31
|
}
|