@cssxjs/runtime 0.2.3 → 0.2.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/CHANGELOG.md +24 -0
- package/package.json +2 -2
- package/platformHelpers/index.js +9 -0
- package/platformHelpers/react-native.js +4 -0
- package/platformHelpers/web.js +4 -0
- package/process.js +32 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
# v0.2.5 (Wed Nov 05 2025)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- fix: force 'px' unit for lineHegiht in pure React on web ([@cray0000](https://github.com/cray0000))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# v0.2.4 (Wed Nov 05 2025)
|
|
14
|
+
|
|
15
|
+
#### 🚀 Enhancement
|
|
16
|
+
|
|
17
|
+
- feat: add 'u' unit support to the 'style' prop: 1u = 8px ([@cray0000](https://github.com/cray0000))
|
|
18
|
+
|
|
19
|
+
#### Authors: 1
|
|
20
|
+
|
|
21
|
+
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
1
25
|
# v0.2.2 (Tue Nov 04 2025)
|
|
2
26
|
|
|
3
27
|
#### 🐛 Bug Fix
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssxjs/runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"optional": true
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "43c7c2f95105e88b07db9c12f3fffdb516a998ff"
|
|
56
56
|
}
|
package/platformHelpers/index.js
CHANGED
|
@@ -30,3 +30,12 @@ export function getPlatform (...args) {
|
|
|
30
30
|
throw err
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
export function isPureReact (...args) {
|
|
35
|
+
try {
|
|
36
|
+
return platformHelpers.isPureReact(...args)
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error('[cssxjs] platform helpers \'isPureReact\' is not specified. Babel is probably misconfigured')
|
|
39
|
+
throw err
|
|
40
|
+
}
|
|
41
|
+
}
|
package/platformHelpers/web.js
CHANGED
package/process.js
CHANGED
|
@@ -2,12 +2,14 @@ import { process as dynamicProcess } from './vendor/react-native-dynamic-style-p
|
|
|
2
2
|
import dimensions from './dimensions.js'
|
|
3
3
|
import singletonVariables, { defaultVariables } from './variables.js'
|
|
4
4
|
import matcher from './matcher.js'
|
|
5
|
+
import { isPureReact } from './platformHelpers/index.js'
|
|
5
6
|
|
|
6
7
|
// TODO: Improve css variables performance. Instead of rerunning finding variables each time
|
|
7
8
|
// it has to work as a pipeline and pass the variables from one step to the next.
|
|
8
9
|
|
|
9
10
|
const VARS_REGEX = /"var\(\s*(--[A-Za-z0-9_-]+)\s*,?\s*(.*?)\s*\)"/g
|
|
10
11
|
const HAS_VAR_REGEX = /"var\(/
|
|
12
|
+
const SUPPORT_UNIT = true
|
|
11
13
|
|
|
12
14
|
export function process (
|
|
13
15
|
styleName,
|
|
@@ -23,12 +25,41 @@ export function process (
|
|
|
23
25
|
const res = matcher(
|
|
24
26
|
styleName, fileStyles, globalStyles, localStyles, inlineStyleProps
|
|
25
27
|
)
|
|
26
|
-
// flatten styles into single objects
|
|
27
28
|
for (const propName in res) {
|
|
29
|
+
// flatten styles into single objects
|
|
28
30
|
if (Array.isArray(res[propName])) {
|
|
29
31
|
res[propName] = res[propName].flat(10)
|
|
30
32
|
res[propName] = Object.assign({}, ...res[propName])
|
|
31
33
|
}
|
|
34
|
+
// force transform to 'px' some units in pure React environment
|
|
35
|
+
if (isPureReact()) {
|
|
36
|
+
// atm it's only 'lineHeight' property
|
|
37
|
+
if (typeof res[propName].lineHeight === 'number') {
|
|
38
|
+
res[propName].lineHeight = `${res[propName].lineHeight}px`
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// add 'u' unit support (1u = 8px)
|
|
42
|
+
// replace in string values `{NUMBER}u` with the `{NUMBER*8}`
|
|
43
|
+
// (pure number without any units - which will be treated as 'px' by React Native and pure React)
|
|
44
|
+
if (SUPPORT_UNIT) {
|
|
45
|
+
for (const property in res[propName]) {
|
|
46
|
+
if (typeof res[propName][property] !== 'string') continue
|
|
47
|
+
if (!/\du/.test(res[propName][property])) continue // quick check for potential presence of 'u' unit
|
|
48
|
+
while (true) {
|
|
49
|
+
const match = res[propName][property].match(/(\(|,| |^)([+-]?(?:\d*\.)?\d+)u(\)|,| |$)/)
|
|
50
|
+
if (!match) break
|
|
51
|
+
const fullMatch = match[0]
|
|
52
|
+
const number = parseFloat(match[2])
|
|
53
|
+
const replacedValue = number * 8
|
|
54
|
+
// if left and right don't exist (pure value), then assign the pure number
|
|
55
|
+
if (!match[1] && !match[3]) {
|
|
56
|
+
res[propName][property] = replacedValue
|
|
57
|
+
break
|
|
58
|
+
}
|
|
59
|
+
res[propName][property] = res[propName][property].replace(fullMatch, `${match[1]}${replacedValue}${match[3]}`)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
32
63
|
}
|
|
33
64
|
return res
|
|
34
65
|
}
|