@colorye/react-native-css 0.2.1 → 0.2.2
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/babel.js +31 -13
- package/package.json +1 -1
- package/src/babel.js +20 -4
package/dist/babel.js
CHANGED
|
@@ -30,14 +30,23 @@ function loadStylesheet(cssPath) {
|
|
|
30
30
|
return stylesheet;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
// Try .json
|
|
34
|
-
var
|
|
35
|
-
if (_fs["default"].existsSync(
|
|
36
|
-
var _content = _fs["default"].readFileSync(
|
|
33
|
+
// Try project root index.css.json
|
|
34
|
+
var projectRootJson = _path["default"].resolve(process.cwd(), "index.css.json");
|
|
35
|
+
if (_fs["default"].existsSync(projectRootJson)) {
|
|
36
|
+
var _content = _fs["default"].readFileSync(projectRootJson, "utf-8");
|
|
37
37
|
var _stylesheet = JSON.parse(_content);
|
|
38
38
|
stylesheetCache.set(cssPath, _stylesheet);
|
|
39
39
|
return _stylesheet;
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
// Try .json next to the CSS file
|
|
43
|
+
var cssJsonPath = "".concat(cssPath, ".json");
|
|
44
|
+
if (_fs["default"].existsSync(cssJsonPath)) {
|
|
45
|
+
var _content2 = _fs["default"].readFileSync(cssJsonPath, "utf-8");
|
|
46
|
+
var _stylesheet2 = JSON.parse(_content2);
|
|
47
|
+
stylesheetCache.set(cssPath, _stylesheet2);
|
|
48
|
+
return _stylesheet2;
|
|
49
|
+
}
|
|
41
50
|
return null;
|
|
42
51
|
} catch (_unused) {
|
|
43
52
|
return null;
|
|
@@ -90,11 +99,11 @@ function _default(_ref) {
|
|
|
90
99
|
state.stylesheetId = path.scope.generateUidIdentifier();
|
|
91
100
|
state.stylesheet = t.variableDeclaration("var", [t.variableDeclarator(state.stylesheetId, t.callExpression(t.identifier("require"), [t.stringLiteral(options.css)]))]);
|
|
92
101
|
state.getStyleId = path.scope.generateUidIdentifier();
|
|
93
|
-
state.getStyle = t.variableDeclaration("var", [t.variableDeclarator(state.getStyleId, t.memberExpression(t.memberExpression(t.callExpression(t.identifier("require"), [t.stringLiteral(
|
|
102
|
+
state.getStyle = t.variableDeclaration("var", [t.variableDeclarator(state.getStyleId, t.memberExpression(t.memberExpression(t.callExpression(t.identifier("require"), [t.stringLiteral("@colorye/react-native-css/dist/transformer-runtime")]), t.identifier("default")), t.identifier("getStyle")))]);
|
|
94
103
|
state.getInheritStyleId = path.scope.generateUidIdentifier();
|
|
95
|
-
state.getInheritStyle = t.variableDeclaration("var", [t.variableDeclarator(state.getInheritStyleId, t.memberExpression(t.memberExpression(t.callExpression(t.identifier("require"), [t.stringLiteral(
|
|
104
|
+
state.getInheritStyle = t.variableDeclaration("var", [t.variableDeclarator(state.getInheritStyleId, t.memberExpression(t.memberExpression(t.callExpression(t.identifier("require"), [t.stringLiteral("@colorye/react-native-css/dist/transformer-runtime")]), t.identifier("default")), t.identifier("getInheritStyle")))]);
|
|
96
105
|
state.mergeStylesId = path.scope.generateUidIdentifier();
|
|
97
|
-
state.mergeStyles = t.variableDeclaration("var", [t.variableDeclarator(state.mergeStylesId, t.memberExpression(t.memberExpression(t.callExpression(t.identifier("require"), [t.stringLiteral(
|
|
106
|
+
state.mergeStyles = t.variableDeclaration("var", [t.variableDeclarator(state.mergeStylesId, t.memberExpression(t.memberExpression(t.callExpression(t.identifier("require"), [t.stringLiteral("@colorye/react-native-css/dist/transformer-runtime")]), t.identifier("default")), t.identifier("mergeStyles")))]);
|
|
98
107
|
},
|
|
99
108
|
exit: function exit(path, state) {
|
|
100
109
|
if (!state.enabled) return;
|
|
@@ -137,10 +146,19 @@ function _default(_ref) {
|
|
|
137
146
|
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier("inheritStyle"), t.jsxExpressionContainer(inheritStyleExpressions)));
|
|
138
147
|
}
|
|
139
148
|
}
|
|
140
|
-
var
|
|
149
|
+
var hasClassName = openingElement.attributes.some(function (attr) {
|
|
141
150
|
var _attr$name2;
|
|
142
|
-
return ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.name) === "
|
|
151
|
+
return ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.name) === "className";
|
|
152
|
+
});
|
|
153
|
+
var hasCombinedStyles = openingElement.attributes.some(function (attr) {
|
|
154
|
+
var _attr$name3;
|
|
155
|
+
return ((_attr$name3 = attr.name) === null || _attr$name3 === void 0 ? void 0 : _attr$name3.name) === "__combinedStyles";
|
|
156
|
+
});
|
|
157
|
+
var hasInheritStyle = openingElement.attributes.some(function (attr) {
|
|
158
|
+
var _attr$name4;
|
|
159
|
+
return ((_attr$name4 = attr.name) === null || _attr$name4 === void 0 ? void 0 : _attr$name4.name) === "inheritStyle";
|
|
143
160
|
});
|
|
161
|
+
var shouldCombineStyles = hasClassName || hasCombinedStyles || hasInheritStyle;
|
|
144
162
|
if (shouldCombineStyles) {
|
|
145
163
|
var styleExpressions;
|
|
146
164
|
|
|
@@ -159,8 +177,8 @@ function _default(_ref) {
|
|
|
159
177
|
styleExpressions = (0, _babel.getStyleExpression)(path, state, t);
|
|
160
178
|
}
|
|
161
179
|
var style = openingElement.attributes.find(function (attr) {
|
|
162
|
-
var _attr$
|
|
163
|
-
return ((_attr$
|
|
180
|
+
var _attr$name5;
|
|
181
|
+
return ((_attr$name5 = attr.name) === null || _attr$name5 === void 0 ? void 0 : _attr$name5.name) === "style";
|
|
164
182
|
});
|
|
165
183
|
if (style) {
|
|
166
184
|
style.value = t.jsxExpressionContainer(styleExpressions);
|
|
@@ -184,8 +202,8 @@ function _default(_ref) {
|
|
|
184
202
|
state.needsGetStyle = true;
|
|
185
203
|
var inheritStyleExpressions = (0, _babel.getInheritStyleExpression)(path, state, t);
|
|
186
204
|
var inheritStyle = childOpeningElement.attributes.find(function (attr) {
|
|
187
|
-
var _attr$
|
|
188
|
-
return ((_attr$
|
|
205
|
+
var _attr$name6;
|
|
206
|
+
return ((_attr$name6 = attr.name) === null || _attr$name6 === void 0 ? void 0 : _attr$name6.name) === "inheritStyle";
|
|
189
207
|
});
|
|
190
208
|
if (inheritStyle) {
|
|
191
209
|
inheritStyle.value = t.jsxExpressionContainer(inheritStyleExpressions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colorye/react-native-css",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"author": "Rye Nguyen <ryenguyen7411@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"packageManager": "yarn@4.18.0+sha512.fcb8716fe7cd0eece141ffc18b92193a9df9204c1ba83189c288835223fc0bbe64af473bab0d5e9927a7daeb5caf2bb07eb2787cc9338ca040ea125f2a1f2f7e",
|
package/src/babel.js
CHANGED
|
@@ -34,6 +34,15 @@ function loadStylesheet(cssPath) {
|
|
|
34
34
|
return stylesheet;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
// Try project root index.css.json
|
|
38
|
+
const projectRootJson = nodePath.resolve(process.cwd(), "index.css.json");
|
|
39
|
+
if (fs.existsSync(projectRootJson)) {
|
|
40
|
+
const content = fs.readFileSync(projectRootJson, "utf-8");
|
|
41
|
+
const stylesheet = JSON.parse(content);
|
|
42
|
+
stylesheetCache.set(cssPath, stylesheet);
|
|
43
|
+
return stylesheet;
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
// Try .json next to the CSS file
|
|
38
47
|
const cssJsonPath = `${cssPath}.json`;
|
|
39
48
|
if (fs.existsSync(cssJsonPath)) {
|
|
@@ -104,7 +113,7 @@ export default function ({ types: t }) {
|
|
|
104
113
|
t.memberExpression(
|
|
105
114
|
t.memberExpression(
|
|
106
115
|
t.callExpression(t.identifier("require"), [
|
|
107
|
-
t.stringLiteral(
|
|
116
|
+
t.stringLiteral("@colorye/react-native-css/dist/transformer-runtime"),
|
|
108
117
|
]),
|
|
109
118
|
t.identifier("default"),
|
|
110
119
|
),
|
|
@@ -120,7 +129,7 @@ export default function ({ types: t }) {
|
|
|
120
129
|
t.memberExpression(
|
|
121
130
|
t.memberExpression(
|
|
122
131
|
t.callExpression(t.identifier("require"), [
|
|
123
|
-
t.stringLiteral(
|
|
132
|
+
t.stringLiteral("@colorye/react-native-css/dist/transformer-runtime"),
|
|
124
133
|
]),
|
|
125
134
|
t.identifier("default"),
|
|
126
135
|
),
|
|
@@ -136,7 +145,7 @@ export default function ({ types: t }) {
|
|
|
136
145
|
t.memberExpression(
|
|
137
146
|
t.memberExpression(
|
|
138
147
|
t.callExpression(t.identifier("require"), [
|
|
139
|
-
t.stringLiteral(
|
|
148
|
+
t.stringLiteral("@colorye/react-native-css/dist/transformer-runtime"),
|
|
140
149
|
]),
|
|
141
150
|
t.identifier("default"),
|
|
142
151
|
),
|
|
@@ -200,9 +209,16 @@ export default function ({ types: t }) {
|
|
|
200
209
|
}
|
|
201
210
|
}
|
|
202
211
|
|
|
203
|
-
const
|
|
212
|
+
const hasClassName = openingElement.attributes.some(
|
|
213
|
+
(attr) => attr.name?.name === "className",
|
|
214
|
+
);
|
|
215
|
+
const hasCombinedStyles = openingElement.attributes.some(
|
|
204
216
|
(attr) => attr.name?.name === "__combinedStyles",
|
|
205
217
|
);
|
|
218
|
+
const hasInheritStyle = openingElement.attributes.some(
|
|
219
|
+
(attr) => attr.name?.name === "inheritStyle",
|
|
220
|
+
);
|
|
221
|
+
const shouldCombineStyles = hasClassName || hasCombinedStyles || hasInheritStyle;
|
|
206
222
|
|
|
207
223
|
if (shouldCombineStyles) {
|
|
208
224
|
let styleExpressions;
|