@cssxjs/loaders 0.2.30 → 0.2.31

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 CHANGED
@@ -3,6 +3,17 @@
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.31](https://github.com/startupjs/cssx/compare/v0.2.30...v0.2.31) (2026-01-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **runtime:** improve performance of substituting var() in css ([282cb46](https://github.com/startupjs/cssx/commit/282cb461369cdb951cc873973a2d0da97a682b9b))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [0.2.30](https://github.com/startupjs/cssx/compare/v0.2.29...v0.2.30) (2026-01-18)
7
18
 
8
19
 
@@ -2,6 +2,7 @@
2
2
  const css2rn = require('@startupjs/css-to-react-native-transform').default
3
3
 
4
4
  const EXPORT_REGEX = /:export\s*\{/
5
+ const VAR_NAMES_REGEX = /"var\(\s*--[A-Za-z0-9_-]+/g
5
6
 
6
7
  module.exports = function cssToReactNative (source) {
7
8
  source = escapeExport(source)
@@ -13,8 +14,16 @@ module.exports = function cssToReactNative (source) {
13
14
  for (const key in cssObject.__exportProps || {}) {
14
15
  cssObject[key] = parseStylValue(cssObject.__exportProps[key])
15
16
  }
17
+ const stringifiedCss = JSON.stringify(cssObject)
16
18
  // save hash to use with the caching system of @startupjs/cache
17
- cssObject.__hash__ = simpleNumericHash(JSON.stringify(cssObject))
19
+ cssObject.__hash__ = simpleNumericHash(stringifiedCss)
20
+ // OPTIMIZATION: save vars used in the styles for later replacement in runtime
21
+ // and also to determine whether we need to listen for variable changes
22
+ const vars = getVariableNames(stringifiedCss)
23
+ if (vars) cssObject.__vars = vars
24
+ // OPTIMIZATION: indicate whether @media queries are used.
25
+ // This is later used in runtime to determine whether we need to listen for dimension changes
26
+ if (hasMedia(cssObject)) cssObject.__hasMedia = true
18
27
  return 'module.exports = ' + JSON.stringify(cssObject)
19
28
  }
20
29
 
@@ -85,6 +94,23 @@ function escapeExport (source) {
85
94
 
86
95
  // ref: https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0?permalink_comment_id=2694461#gistcomment-2694461
87
96
  function simpleNumericHash (s) {
88
- for (var i = 0, h = 0; i < s.length; i++) h = Math.imul(31, h) + s.charCodeAt(i) | 0
97
+ let i, h
98
+ for (i = 0, h = 0; i < s.length; i++) h = Math.imul(31, h) + s.charCodeAt(i) | 0
89
99
  return h
90
100
  }
101
+
102
+ function getVariableNames (cssString) {
103
+ let res = cssString.match(VAR_NAMES_REGEX)
104
+ if (!res) return
105
+ res = res.map(i => i.replace(/"var\(\s*/, ''))
106
+ res = [...new Set(res)].sort() // remove duplicates and sort
107
+ return res
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.30",
3
+ "version": "0.2.31",
4
4
  "description": "Webpack-compatible loaders for CSSX styles in React Native and Web bundlers",
5
5
  "exports": {
6
6
  "./callLoader": "./callLoader.js",
@@ -23,5 +23,5 @@
23
23
  "@startupjs/css-to-react-native-transform": "2.1.0-2",
24
24
  "stylus": "0.64.0"
25
25
  },
26
- "gitHead": "2fd171f6da726008a2386471bd5be4b5291e49ab"
26
+ "gitHead": "989ab68dbc3ed81262ccc51946ddaa01b90416a5"
27
27
  }