@cssxjs/loaders 0.2.30 → 0.2.32
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 +22 -0
- package/cssToReactNativeLoader.js +28 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.2.32](https://github.com/startupjs/cssx/compare/v0.2.31...v0.2.32) (2026-01-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **runtime:** support var() in shorthand values and in various complex cases ([4483f54](https://github.com/startupjs/cssx/commit/4483f54d9507ebb38eb5f056de3fcac39862cb30))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.2.31](https://github.com/startupjs/cssx/compare/v0.2.30...v0.2.31) (2026-01-23)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **runtime:** improve performance of substituting var() in css ([282cb46](https://github.com/startupjs/cssx/commit/282cb461369cdb951cc873973a2d0da97a682b9b))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [0.2.30](https://github.com/startupjs/cssx/compare/v0.2.29...v0.2.30) (2026-01-18)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
const css2rn = require('@startupjs/css-to-react-native-transform').default
|
|
3
3
|
|
|
4
4
|
const EXPORT_REGEX = /:export\s*\{/
|
|
5
|
+
// Match var() anywhere in a string value (not just at the start)
|
|
6
|
+
const VAR_NAMES_REGEX = /var\(\s*(--[A-Za-z0-9_-]+)/g
|
|
5
7
|
|
|
6
8
|
module.exports = function cssToReactNative (source) {
|
|
7
9
|
source = escapeExport(source)
|
|
@@ -13,8 +15,16 @@ module.exports = function cssToReactNative (source) {
|
|
|
13
15
|
for (const key in cssObject.__exportProps || {}) {
|
|
14
16
|
cssObject[key] = parseStylValue(cssObject.__exportProps[key])
|
|
15
17
|
}
|
|
18
|
+
const stringifiedCss = JSON.stringify(cssObject)
|
|
16
19
|
// save hash to use with the caching system of @startupjs/cache
|
|
17
|
-
cssObject.__hash__ = simpleNumericHash(
|
|
20
|
+
cssObject.__hash__ = simpleNumericHash(stringifiedCss)
|
|
21
|
+
// OPTIMIZATION: save vars used in the styles for later replacement in runtime
|
|
22
|
+
// and also to determine whether we need to listen for variable changes
|
|
23
|
+
const vars = getVariableNames(stringifiedCss)
|
|
24
|
+
if (vars) cssObject.__vars = vars
|
|
25
|
+
// OPTIMIZATION: indicate whether @media queries are used.
|
|
26
|
+
// This is later used in runtime to determine whether we need to listen for dimension changes
|
|
27
|
+
if (hasMedia(cssObject)) cssObject.__hasMedia = true
|
|
18
28
|
return 'module.exports = ' + JSON.stringify(cssObject)
|
|
19
29
|
}
|
|
20
30
|
|
|
@@ -85,6 +95,22 @@ function escapeExport (source) {
|
|
|
85
95
|
|
|
86
96
|
// ref: https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0?permalink_comment_id=2694461#gistcomment-2694461
|
|
87
97
|
function simpleNumericHash (s) {
|
|
88
|
-
|
|
98
|
+
let i, h
|
|
99
|
+
for (i = 0, h = 0; i < s.length; i++) h = Math.imul(31, h) + s.charCodeAt(i) | 0
|
|
89
100
|
return h
|
|
90
101
|
}
|
|
102
|
+
|
|
103
|
+
function getVariableNames (cssString) {
|
|
104
|
+
const matches = [...cssString.matchAll(VAR_NAMES_REGEX)]
|
|
105
|
+
if (!matches.length) return
|
|
106
|
+
const res = matches.map(m => m[1]) // extract capture group (variable name)
|
|
107
|
+
return [...new Set(res)].sort() // remove duplicates and sort
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function hasMedia (styles = {}) {
|
|
111
|
+
for (const selector in styles) {
|
|
112
|
+
if (/^@media/.test(selector)) {
|
|
113
|
+
return true
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssxjs/loaders",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32",
|
|
4
4
|
"description": "Webpack-compatible loaders for CSSX styles in React Native and Web bundlers",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./callLoader": "./callLoader.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@startupjs/css-to-react-native-transform": "2.1.0-
|
|
23
|
+
"@startupjs/css-to-react-native-transform": "2.1.0-3",
|
|
24
24
|
"stylus": "0.64.0"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "2d5f40fdc99ec3cbfb397741444993e2d09d7975"
|
|
27
27
|
}
|