@colorye/react-native-css 0.3.0
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/README.md +198 -0
- package/crates/transformer/index.js +105 -0
- package/crates/transformer/transformer.darwin-arm64.node +0 -0
- package/crates/transformer/transformer.node +0 -0
- package/dist/babel.js +208 -0
- package/dist/exported-stylesheet.json +1 -0
- package/dist/features/build-transform.js +575 -0
- package/dist/features/css-calc.js +539 -0
- package/dist/features/css-media.js +77 -0
- package/dist/features/css-transform.js +426 -0
- package/dist/features/css-vars.js +153 -0
- package/dist/features/stylesheet.js +45 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +60 -0
- package/dist/interop.js +260 -0
- package/dist/transformer-runtime.js +274 -0
- package/dist/transformer.js +100 -0
- package/dist/utils/babel.js +363 -0
- package/dist/utils/css.js +263 -0
- package/dist/utils/helper.js +11 -0
- package/package.json +51 -0
- package/src/babel.js +271 -0
- package/src/exported-stylesheet.json +1 -0
- package/src/features/build-transform.js +536 -0
- package/src/features/css-calc.js +490 -0
- package/src/features/css-media.js +78 -0
- package/src/features/css-transform.js +446 -0
- package/src/features/css-vars.js +138 -0
- package/src/features/stylesheet.js +29 -0
- package/src/index.d.ts +89 -0
- package/src/index.js +29 -0
- package/src/interop.js +269 -0
- package/src/transformer-runtime.js +241 -0
- package/src/transformer.js +87 -0
- package/src/utils/babel.js +425 -0
- package/src/utils/css.js +221 -0
- package/src/utils/helper.js +3 -0
- package/types.d.ts +47 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.areAllClassesStatic = areAllClassesStatic;
|
|
7
|
+
exports.computeStaticStyles = computeStaticStyles;
|
|
8
|
+
exports.getInheritStyleExpression = getInheritStyleExpression;
|
|
9
|
+
exports.getRootInheritStyleExpression = getRootInheritStyleExpression;
|
|
10
|
+
exports.getStaticClassNameValue = getStaticClassNameValue;
|
|
11
|
+
exports.getStaticMergeExpression = getStaticMergeExpression;
|
|
12
|
+
exports.getStyleExpression = getStyleExpression;
|
|
13
|
+
exports.inlineStaticAttributes = inlineStaticAttributes;
|
|
14
|
+
exports.isClassStatic = isClassStatic;
|
|
15
|
+
exports.isFragmentElement = isFragmentElement;
|
|
16
|
+
exports.isImportOrRequire = isImportOrRequire;
|
|
17
|
+
exports.isRootLevelJSXElement = isRootLevelJSXElement;
|
|
18
|
+
exports.isStaticClassName = isStaticClassName;
|
|
19
|
+
exports.objectToAST = objectToAST;
|
|
20
|
+
exports.tryGetStaticStyleInfo = tryGetStaticStyleInfo;
|
|
21
|
+
var _transformerRuntime = _interopRequireDefault(require("../transformer-runtime.js"));
|
|
22
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
23
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
24
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
25
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
26
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
27
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
28
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
29
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
30
|
+
function isImportOrRequire(statement) {
|
|
31
|
+
var _statement$node;
|
|
32
|
+
return statement.isImportDeclaration() || ((_statement$node = statement.node) === null || _statement$node === void 0 || (_statement$node = _statement$node.declarations) === null || _statement$node === void 0 || (_statement$node = _statement$node[0]) === null || _statement$node === void 0 || (_statement$node = _statement$node.init) === null || _statement$node === void 0 || (_statement$node = _statement$node.callee) === null || _statement$node === void 0 ? void 0 : _statement$node.name) === "require";
|
|
33
|
+
}
|
|
34
|
+
function isFragmentElement(t, elementName) {
|
|
35
|
+
return t.isJSXIdentifier(elementName) && (elementName.name === "Fragment" || elementName.name === "React.Fragment") || t.isJSXMemberExpression(elementName) && elementName.object.name === "React" && elementName.property.name === "Fragment" || t.isJSXIdentifier(elementName, {
|
|
36
|
+
name: ""
|
|
37
|
+
}) // JSX shorthand fragment
|
|
38
|
+
;
|
|
39
|
+
}
|
|
40
|
+
function isRootLevelJSXElement(path) {
|
|
41
|
+
var currentPath = path;
|
|
42
|
+
while (currentPath.parentPath) {
|
|
43
|
+
var parent = currentPath.parentPath;
|
|
44
|
+
if (parent.isReturnStatement()) return true;
|
|
45
|
+
if (parent.isArrowFunctionExpression() && parent.node.body === currentPath.node) return true;
|
|
46
|
+
if (parent.isJSXElement() && parent !== path) return false;
|
|
47
|
+
if (parent.isConditionalExpression() || parent.isLogicalExpression() || parent.isParenthesizedExpression()) {
|
|
48
|
+
currentPath = parent;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
currentPath = parent;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ============================================================================
|
|
57
|
+
// Static style detection helpers
|
|
58
|
+
// ============================================================================
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Check if className is a static string literal
|
|
62
|
+
*/
|
|
63
|
+
function isStaticClassName(t, classNameAttr) {
|
|
64
|
+
if (!classNameAttr) return false;
|
|
65
|
+
if (t.isStringLiteral(classNameAttr.value)) return true;
|
|
66
|
+
if (t.isJSXExpressionContainer(classNameAttr.value) && t.isStringLiteral(classNameAttr.value.expression)) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get static className string value
|
|
74
|
+
*/
|
|
75
|
+
function getStaticClassNameValue(t, classNameAttr) {
|
|
76
|
+
if (!classNameAttr) return null;
|
|
77
|
+
if (t.isStringLiteral(classNameAttr.value)) return classNameAttr.value.value;
|
|
78
|
+
if (t.isJSXExpressionContainer(classNameAttr.value) && t.isStringLiteral(classNameAttr.value.expression)) {
|
|
79
|
+
return classNameAttr.value.expression.value;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check if a class is fully static (no dynamic breakpoint / dark mode queries)
|
|
86
|
+
*/
|
|
87
|
+
function isClassStatic(stylesheet, className) {
|
|
88
|
+
if (!className) return true;
|
|
89
|
+
if (className === "group" || className.startsWith("group") || className.startsWith("peer") || className.startsWith("active:") || className.startsWith("pressed:") || className.startsWith("disabled:") || className.startsWith("dark:") || className.startsWith("light:") || className.startsWith("sm:") || className.startsWith("md:") || className.startsWith("lg:") || className.startsWith("xl:") || className.startsWith("2xl:") || className.startsWith("portrait:") || className.startsWith("landscape:")) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Check if all classes in className string are static
|
|
97
|
+
*/
|
|
98
|
+
function areAllClassesStatic(stylesheet, classNameValue) {
|
|
99
|
+
if (!classNameValue || !stylesheet) return false;
|
|
100
|
+
var classes = classNameValue.trim().split(/\s+/).filter(Boolean);
|
|
101
|
+
return classes.every(function (cls) {
|
|
102
|
+
return isClassStatic(stylesheet, cls);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Compute merged static styles from className string using Runtime compiler
|
|
108
|
+
*/
|
|
109
|
+
function computeStaticStyles(stylesheet, classNameValue) {
|
|
110
|
+
if (!classNameValue || !stylesheet) return {};
|
|
111
|
+
try {
|
|
112
|
+
var computed = _transformerRuntime["default"].getStyle(stylesheet, [undefined, classNameValue, undefined]);
|
|
113
|
+
return computed || {};
|
|
114
|
+
} catch (_unused) {
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Inlines static className and contentContainerClassName attributes directly into styles
|
|
121
|
+
*/
|
|
122
|
+
function inlineStaticAttributes(path, state, t) {
|
|
123
|
+
if (!state.stylesheetData) return;
|
|
124
|
+
var openingElement = path.node.openingElement;
|
|
125
|
+
var stylesheet = state.stylesheetData;
|
|
126
|
+
var classPropMappings = [{
|
|
127
|
+
classProp: "className",
|
|
128
|
+
styleProp: "style"
|
|
129
|
+
}, {
|
|
130
|
+
classProp: "contentContainerClassName",
|
|
131
|
+
styleProp: "contentContainerStyle"
|
|
132
|
+
}];
|
|
133
|
+
var _loop = function _loop() {
|
|
134
|
+
var _classPropMappings$_i = _classPropMappings[_i],
|
|
135
|
+
classProp = _classPropMappings$_i.classProp,
|
|
136
|
+
styleProp = _classPropMappings$_i.styleProp;
|
|
137
|
+
var classAttrIndex = openingElement.attributes.findIndex(function (attr) {
|
|
138
|
+
var _attr$name;
|
|
139
|
+
return t.isJSXAttribute(attr) && ((_attr$name = attr.name) === null || _attr$name === void 0 ? void 0 : _attr$name.name) === classProp;
|
|
140
|
+
});
|
|
141
|
+
if (classAttrIndex === -1) return 0; // continue
|
|
142
|
+
var classAttr = openingElement.attributes[classAttrIndex];
|
|
143
|
+
if (!isStaticClassName(t, classAttr)) return 0; // continue
|
|
144
|
+
var classValue = getStaticClassNameValue(t, classAttr);
|
|
145
|
+
if (!classValue || !areAllClassesStatic(stylesheet, classValue)) return 0; // continue
|
|
146
|
+
var staticStyles = computeStaticStyles(stylesheet, classValue);
|
|
147
|
+
if (!staticStyles || Object.keys(staticStyles).length === 0) return 0; // continue
|
|
148
|
+
var styleAST = objectToAST(t, staticStyles);
|
|
149
|
+
|
|
150
|
+
// Find existing style prop if present
|
|
151
|
+
var existingStyle = openingElement.attributes.find(function (attr) {
|
|
152
|
+
var _attr$name2;
|
|
153
|
+
return t.isJSXAttribute(attr) && ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.name) === styleProp;
|
|
154
|
+
});
|
|
155
|
+
if (existingStyle) {
|
|
156
|
+
var currentVal = t.isJSXExpressionContainer(existingStyle.value) ? existingStyle.value.expression : existingStyle.value;
|
|
157
|
+
existingStyle.value = t.jsxExpressionContainer(t.arrayExpression([styleAST, currentVal]));
|
|
158
|
+
} else {
|
|
159
|
+
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier(styleProp), t.jsxExpressionContainer(styleAST)));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Remove the static class attribute to achieve zero runtime parsing
|
|
163
|
+
openingElement.attributes.splice(classAttrIndex, 1);
|
|
164
|
+
},
|
|
165
|
+
_ret;
|
|
166
|
+
for (var _i = 0, _classPropMappings = classPropMappings; _i < _classPropMappings.length; _i++) {
|
|
167
|
+
_ret = _loop();
|
|
168
|
+
if (_ret === 0) continue;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Convert JavaScript object to Babel AST
|
|
174
|
+
*/
|
|
175
|
+
function objectToAST(t, obj) {
|
|
176
|
+
if (obj === null || obj === undefined) return t.nullLiteral();
|
|
177
|
+
if (Array.isArray(obj)) {
|
|
178
|
+
return t.arrayExpression(obj.map(function (item) {
|
|
179
|
+
return objectToAST(t, item);
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
if (_typeof(obj) === "object") {
|
|
183
|
+
return t.objectExpression(Object.entries(obj).map(function (_ref) {
|
|
184
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
185
|
+
key = _ref2[0],
|
|
186
|
+
value = _ref2[1];
|
|
187
|
+
return t.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? t.identifier(key) : t.stringLiteral(key), objectToAST(t, value));
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
if (typeof obj === "string") return t.stringLiteral(obj);
|
|
191
|
+
if (typeof obj === "number") return t.numericLiteral(obj);
|
|
192
|
+
if (typeof obj === "boolean") return t.booleanLiteral(obj);
|
|
193
|
+
return t.nullLiteral();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Try to get static style info for an element
|
|
198
|
+
* Returns { staticStyles, hasInheritStyle, inlineStyleExpr } or null if not static
|
|
199
|
+
*/
|
|
200
|
+
function tryGetStaticStyleInfo(path, state, t) {
|
|
201
|
+
var openingElement = path.node.openingElement;
|
|
202
|
+
var classNameAttr = openingElement.attributes.find(function (attr) {
|
|
203
|
+
var _attr$name3;
|
|
204
|
+
return t.isJSXAttribute(attr) && ((_attr$name3 = attr.name) === null || _attr$name3 === void 0 ? void 0 : _attr$name3.name) === "className";
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Check if className is static
|
|
208
|
+
if (!isStaticClassName(t, classNameAttr)) return null;
|
|
209
|
+
|
|
210
|
+
// Get stylesheet
|
|
211
|
+
var stylesheet = state.stylesheetData;
|
|
212
|
+
if (!stylesheet) return null;
|
|
213
|
+
var classNameValue = getStaticClassNameValue(t, classNameAttr);
|
|
214
|
+
if (!classNameValue) return null;
|
|
215
|
+
|
|
216
|
+
// Check if all classes are fully static
|
|
217
|
+
if (!areAllClassesStatic(stylesheet, classNameValue)) return null;
|
|
218
|
+
|
|
219
|
+
// Compute static styles from className
|
|
220
|
+
var staticStyles = computeStaticStyles(stylesheet, classNameValue);
|
|
221
|
+
|
|
222
|
+
// Get inheritStyle attribute (for mergeStyles call)
|
|
223
|
+
var inheritStyleAttr = openingElement.attributes.find(function (attr) {
|
|
224
|
+
var _attr$name4;
|
|
225
|
+
return t.isJSXAttribute(attr) && ((_attr$name4 = attr.name) === null || _attr$name4 === void 0 ? void 0 : _attr$name4.name) === "inheritStyle";
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Get style attribute
|
|
229
|
+
var styleAttr = openingElement.attributes.find(function (attr) {
|
|
230
|
+
var _attr$name5;
|
|
231
|
+
return t.isJSXAttribute(attr) && ((_attr$name5 = attr.name) === null || _attr$name5 === void 0 ? void 0 : _attr$name5.name) === "style";
|
|
232
|
+
});
|
|
233
|
+
return {
|
|
234
|
+
staticStyles: staticStyles,
|
|
235
|
+
inheritStyleAttr: inheritStyleAttr,
|
|
236
|
+
styleAttr: styleAttr
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Generate mergeStyles(inheritStyle, staticStyles, inlineStyle) expression
|
|
242
|
+
*/
|
|
243
|
+
function getStaticMergeExpression(path, state, t, staticInfo) {
|
|
244
|
+
var _inheritStyleAttr$val, _styleAttr$value;
|
|
245
|
+
var staticStyles = staticInfo.staticStyles,
|
|
246
|
+
inheritStyleAttr = staticInfo.inheritStyleAttr,
|
|
247
|
+
styleAttr = staticInfo.styleAttr;
|
|
248
|
+
|
|
249
|
+
// Get inheritStyle expression
|
|
250
|
+
var propInheritStyle = getMemoizedInheritStyleExpression(path, t);
|
|
251
|
+
var inheritStyleExpr = inheritStyleAttr === null || inheritStyleAttr === void 0 || (_inheritStyleAttr$val = inheritStyleAttr.value) === null || _inheritStyleAttr$val === void 0 ? void 0 : _inheritStyleAttr$val.expression;
|
|
252
|
+
|
|
253
|
+
// Build inheritStyle array: [props.inheritStyle, explicitInheritStyle]
|
|
254
|
+
var inheritArg;
|
|
255
|
+
if (propInheritStyle || inheritStyleExpr) {
|
|
256
|
+
inheritArg = t.arrayExpression([propInheritStyle || t.nullLiteral(), inheritStyleExpr || t.nullLiteral()]);
|
|
257
|
+
} else {
|
|
258
|
+
inheritArg = t.nullLiteral();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Static styles as inline object
|
|
262
|
+
var staticArg = Object.keys(staticStyles).length > 0 ? objectToAST(t, staticStyles) : t.nullLiteral();
|
|
263
|
+
|
|
264
|
+
// Inline style expression
|
|
265
|
+
var inlineArg = (styleAttr === null || styleAttr === void 0 || (_styleAttr$value = styleAttr.value) === null || _styleAttr$value === void 0 ? void 0 : _styleAttr$value.expression) || t.nullLiteral();
|
|
266
|
+
|
|
267
|
+
// mergeStyles(inheritStyle, staticStyles, inlineStyle)
|
|
268
|
+
return t.callExpression(state.mergeStylesId, [inheritArg, staticArg, inlineArg]);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ============================================================================
|
|
272
|
+
// InheritStyle helpers
|
|
273
|
+
// ============================================================================
|
|
274
|
+
|
|
275
|
+
var inheritStyleMemo = new WeakMap();
|
|
276
|
+
function getMemoizedInheritStyleExpression(path, t) {
|
|
277
|
+
var currentPath = path;
|
|
278
|
+
var funcPath = null;
|
|
279
|
+
while (currentPath && !funcPath) {
|
|
280
|
+
if (currentPath.isFunction()) {
|
|
281
|
+
funcPath = currentPath;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
currentPath = currentPath.parentPath;
|
|
285
|
+
}
|
|
286
|
+
if (!funcPath) return undefined;
|
|
287
|
+
if (inheritStyleMemo.has(funcPath.node)) {
|
|
288
|
+
return inheritStyleMemo.get(funcPath.node);
|
|
289
|
+
}
|
|
290
|
+
var result;
|
|
291
|
+
var params = funcPath.node.params;
|
|
292
|
+
var parentPath = funcPath.parentPath;
|
|
293
|
+
if (parentPath && parentPath.isCallExpression() && parentPath.node.callee && parentPath.node.callee.type === "Identifier" && ["useMemo", "useCallback"].includes(parentPath.node.callee.name)) {
|
|
294
|
+
result = undefined;
|
|
295
|
+
} else if (params.length === 0) {
|
|
296
|
+
funcPath.node.params = [t.identifier("props")];
|
|
297
|
+
result = t.memberExpression(t.identifier("props"), t.identifier("inheritStyle"), false, false);
|
|
298
|
+
} else if (params.length > 0) {
|
|
299
|
+
var firstParam = params[0];
|
|
300
|
+
if (t.isIdentifier(firstParam)) {
|
|
301
|
+
result = t.memberExpression(firstParam, t.identifier("inheritStyle"), false, false);
|
|
302
|
+
} else if (t.isObjectPattern(firstParam)) {
|
|
303
|
+
var restElement = firstParam.properties.find(function (p) {
|
|
304
|
+
return t.isRestElement(p);
|
|
305
|
+
});
|
|
306
|
+
if (restElement) {
|
|
307
|
+
result = t.memberExpression(restElement.argument, t.identifier("inheritStyle"), false, false);
|
|
308
|
+
} else {
|
|
309
|
+
var restProp = t.restElement(t.identifier("rest"));
|
|
310
|
+
firstParam.properties.push(restProp);
|
|
311
|
+
result = t.memberExpression(t.identifier("rest"), t.identifier("inheritStyle"), false, false);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
inheritStyleMemo.set(funcPath.node, result);
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ============================================================================
|
|
320
|
+
// Style expression generators (for dynamic/fallback cases)
|
|
321
|
+
// ============================================================================
|
|
322
|
+
|
|
323
|
+
function getStyleExpression(path, state, t) {
|
|
324
|
+
var openingElement = path.node.openingElement;
|
|
325
|
+
var elementName = openingElement.name;
|
|
326
|
+
var propInheritStyle = getMemoizedInheritStyleExpression(path, t);
|
|
327
|
+
var inheritStyle = openingElement.attributes.find(function (attr) {
|
|
328
|
+
var _attr$name6;
|
|
329
|
+
return ((_attr$name6 = attr.name) === null || _attr$name6 === void 0 ? void 0 : _attr$name6.name) === "inheritStyle";
|
|
330
|
+
});
|
|
331
|
+
var className = openingElement.attributes.find(function (attr) {
|
|
332
|
+
var _attr$name7;
|
|
333
|
+
return ((_attr$name7 = attr.name) === null || _attr$name7 === void 0 ? void 0 : _attr$name7.name) === "className";
|
|
334
|
+
});
|
|
335
|
+
var style = openingElement.attributes.find(function (attr) {
|
|
336
|
+
var _attr$name8;
|
|
337
|
+
return ((_attr$name8 = attr.name) === null || _attr$name8 === void 0 ? void 0 : _attr$name8.name) === "style";
|
|
338
|
+
});
|
|
339
|
+
return t.callExpression(state.getStyleId, [state.stylesheetId, t.arrayExpression([t.arrayExpression([propInheritStyle || t.nullLiteral(), inheritStyle && inheritStyle.value.expression || t.nullLiteral()]), className && (t.isStringLiteral(className.value) ? t.stringLiteral(className.value.value) : className.value.expression) || t.nullLiteral(), style && style.value.expression || t.nullLiteral(), t.isJSXIdentifier(elementName) ? t.stringLiteral(elementName.name) : t.isJSXMemberExpression(elementName) ? t.stringLiteral("".concat(elementName.object.name, ".").concat(elementName.property.name)) : t.stringLiteral("Unknown")])]);
|
|
340
|
+
}
|
|
341
|
+
function getInheritStyleExpression(path, state, t) {
|
|
342
|
+
var _inheritStyle$value, _styleAttr$value2;
|
|
343
|
+
var openingElement = path.node.openingElement;
|
|
344
|
+
var inheritStyle = openingElement.attributes.find(function (attr) {
|
|
345
|
+
var _attr$name9;
|
|
346
|
+
return ((_attr$name9 = attr.name) === null || _attr$name9 === void 0 ? void 0 : _attr$name9.name) === "inheritStyle";
|
|
347
|
+
});
|
|
348
|
+
var propInheritStyle = getMemoizedInheritStyleExpression(path, t);
|
|
349
|
+
var inheritStyleExpr = (inheritStyle === null || inheritStyle === void 0 || (_inheritStyle$value = inheritStyle.value) === null || _inheritStyle$value === void 0 ? void 0 : _inheritStyle$value.expression) || propInheritStyle;
|
|
350
|
+
var classNameAttr = openingElement.attributes.find(function (attr) {
|
|
351
|
+
var _attr$name0;
|
|
352
|
+
return ((_attr$name0 = attr.name) === null || _attr$name0 === void 0 ? void 0 : _attr$name0.name) === "className";
|
|
353
|
+
});
|
|
354
|
+
var styleAttr = openingElement.attributes.find(function (attr) {
|
|
355
|
+
var _attr$name1;
|
|
356
|
+
return ((_attr$name1 = attr.name) === null || _attr$name1 === void 0 ? void 0 : _attr$name1.name) === "style";
|
|
357
|
+
});
|
|
358
|
+
return t.callExpression(state.getInheritStyleId, [t.callExpression(state.getStyleId, [state.stylesheetId, t.arrayExpression([inheritStyleExpr || t.nullLiteral(), (classNameAttr === null || classNameAttr === void 0 ? void 0 : classNameAttr.value) && (t.isStringLiteral(classNameAttr.value) ? t.stringLiteral(classNameAttr.value.value) : classNameAttr.value.expression) || t.nullLiteral(), (styleAttr === null || styleAttr === void 0 || (_styleAttr$value2 = styleAttr.value) === null || _styleAttr$value2 === void 0 ? void 0 : _styleAttr$value2.expression) || t.nullLiteral(), t.isJSXIdentifier(openingElement.name) ? t.stringLiteral(openingElement.name.name) : t.isJSXMemberExpression(openingElement.name) ? t.stringLiteral("".concat(openingElement.name.object.name, ".").concat(openingElement.name.property.name)) : t.stringLiteral("Unknown")])])]);
|
|
359
|
+
}
|
|
360
|
+
function getRootInheritStyleExpression(path, t) {
|
|
361
|
+
var propInheritStyle = getMemoizedInheritStyleExpression(path, t);
|
|
362
|
+
return propInheritStyle || t.identifier("undefined");
|
|
363
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.parseStylesheetWithLightning = parseStylesheetWithLightning;
|
|
8
|
+
var _lightningcss = require("lightningcss");
|
|
9
|
+
var _helper = require("./helper");
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
16
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
|
+
/**
|
|
19
|
+
* Unwrap @layer and @supports blocks to expose standard CSS rules
|
|
20
|
+
*/
|
|
21
|
+
function flattenBlocks(cssStr) {
|
|
22
|
+
var result = "";
|
|
23
|
+
var i = 0;
|
|
24
|
+
var len = cssStr.length;
|
|
25
|
+
while (i < len) {
|
|
26
|
+
// Skip comments
|
|
27
|
+
if (cssStr[i] === "/" && cssStr[i + 1] === "*") {
|
|
28
|
+
var commentEnd = cssStr.indexOf("*/", i + 2);
|
|
29
|
+
if (commentEnd === -1) {
|
|
30
|
+
result += cssStr.substring(i);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
result += cssStr.substring(i, commentEnd + 2);
|
|
34
|
+
i = commentEnd + 2;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Skip strings
|
|
39
|
+
if (cssStr[i] === '"' || cssStr[i] === "'") {
|
|
40
|
+
var _char = cssStr[i];
|
|
41
|
+
var strEnd = i + 1;
|
|
42
|
+
while (strEnd < len) {
|
|
43
|
+
if (cssStr[strEnd] === "\\") {
|
|
44
|
+
strEnd += 2;
|
|
45
|
+
} else if (cssStr[strEnd] === _char) {
|
|
46
|
+
strEnd++;
|
|
47
|
+
break;
|
|
48
|
+
} else {
|
|
49
|
+
strEnd++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
result += cssStr.substring(i, strEnd);
|
|
53
|
+
i = strEnd;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check for at-rules
|
|
58
|
+
if (cssStr[i] === "@") {
|
|
59
|
+
var remaining = cssStr.substring(i);
|
|
60
|
+
var layerMatch = remaining.match(/^@(layer|supports|property)[^{]*\{/i);
|
|
61
|
+
if (layerMatch) {
|
|
62
|
+
var layerType = layerMatch[1].toLowerCase();
|
|
63
|
+
// Skip @layer base entirely because React Native views should not inherit browser base resets (* { border: 0 solid; margin: 0 })
|
|
64
|
+
var isLayerBase = /^@layer\s+base\s*\{/i.test(layerMatch[0]);
|
|
65
|
+
if (layerType === "property" || isLayerBase) {
|
|
66
|
+
var _braceCount = 1;
|
|
67
|
+
var _j = i + layerMatch[0].length;
|
|
68
|
+
while (_j < len && _braceCount > 0) {
|
|
69
|
+
if (cssStr[_j] === "{") _braceCount++;else if (cssStr[_j] === "}") _braceCount--;
|
|
70
|
+
_j++;
|
|
71
|
+
}
|
|
72
|
+
i = _j;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
var braceCount = 1;
|
|
76
|
+
var j = i + layerMatch[0].length;
|
|
77
|
+
var innerContent = "";
|
|
78
|
+
while (j < len && braceCount > 0) {
|
|
79
|
+
if (cssStr[j] === "{") braceCount++;else if (cssStr[j] === "}") braceCount--;
|
|
80
|
+
if (braceCount > 0) innerContent += cssStr[j];
|
|
81
|
+
j++;
|
|
82
|
+
}
|
|
83
|
+
result += flattenBlocks(innerContent);
|
|
84
|
+
i = j;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
result += cssStr[i];
|
|
89
|
+
i++;
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Parse and lower modern CSS using LightningCSS (Rust-based engine)
|
|
96
|
+
* Handles OKLCH, color-mix, CSS nesting, @layer, and @media range queries
|
|
97
|
+
*/
|
|
98
|
+
function parseStylesheetWithLightning(rawCss) {
|
|
99
|
+
var transformed = (0, _lightningcss.transform)({
|
|
100
|
+
filename: "input.css",
|
|
101
|
+
code: Buffer.from(rawCss),
|
|
102
|
+
targets: {
|
|
103
|
+
safari: 14 << 16
|
|
104
|
+
},
|
|
105
|
+
minify: false
|
|
106
|
+
});
|
|
107
|
+
var cssText = flattenBlocks(transformed.code.toString());
|
|
108
|
+
var rawStylesheet = {};
|
|
109
|
+
var cleanSelector = function cleanSelector(sel) {
|
|
110
|
+
if (sel.includes(":root")) return [":root"];
|
|
111
|
+
var s = sel.trim();
|
|
112
|
+
if (!s.startsWith(".")) return [];
|
|
113
|
+
|
|
114
|
+
// Strip leading dot
|
|
115
|
+
s = s.slice(1);
|
|
116
|
+
|
|
117
|
+
// Extract class name (handling escaped chars like active\:scale-95, w-\[48\%\], etc.)
|
|
118
|
+
var classPart = "";
|
|
119
|
+
var i = 0;
|
|
120
|
+
while (i < s.length) {
|
|
121
|
+
if (s[i] === "\\") {
|
|
122
|
+
if (i + 1 < s.length) {
|
|
123
|
+
classPart += s[i + 1];
|
|
124
|
+
i += 2;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (s[i] === ":" || s[i] === " " || s[i] === ">" || s[i] === "~" || s[i] === "+") {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
classPart += s[i];
|
|
132
|
+
i++;
|
|
133
|
+
}
|
|
134
|
+
if (!classPart) return [];
|
|
135
|
+
var names = [classPart];
|
|
136
|
+
|
|
137
|
+
// For variants like disabled:bg-navy-300 or active:opacity-80, also register the base class name
|
|
138
|
+
if (classPart.startsWith("disabled:") || classPart.startsWith("active:") || classPart.startsWith("pressed:")) {
|
|
139
|
+
var base = classPart.replace(/^(disabled|active|pressed):/, "");
|
|
140
|
+
if (base && !names.includes(base)) {
|
|
141
|
+
names.push(base);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return names;
|
|
145
|
+
};
|
|
146
|
+
var parseDeclarations = function parseDeclarations(bodyText) {
|
|
147
|
+
var decls = {};
|
|
148
|
+
var parts = bodyText.split(";");
|
|
149
|
+
var _iterator = _createForOfIteratorHelper(parts),
|
|
150
|
+
_step;
|
|
151
|
+
try {
|
|
152
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
153
|
+
var part = _step.value;
|
|
154
|
+
var trimmed = part.trim();
|
|
155
|
+
if (!trimmed) continue;
|
|
156
|
+
var colonIdx = trimmed.indexOf(":");
|
|
157
|
+
if (colonIdx === -1) continue;
|
|
158
|
+
var prop = trimmed.slice(0, colonIdx).trim();
|
|
159
|
+
var val = trimmed.slice(colonIdx + 1).trim();
|
|
160
|
+
if (!prop || !val) continue;
|
|
161
|
+
if (prop.startsWith("--")) {
|
|
162
|
+
decls[prop] = val;
|
|
163
|
+
} else {
|
|
164
|
+
decls[(0, _helper.camelize)(prop)] = val;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} catch (err) {
|
|
168
|
+
_iterator.e(err);
|
|
169
|
+
} finally {
|
|
170
|
+
_iterator.f();
|
|
171
|
+
}
|
|
172
|
+
return decls;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// 1. Separate media query blocks
|
|
176
|
+
var mediaBlocks = [];
|
|
177
|
+
var noMediaCss = cssText.replace(/@media\s*([^{]+)\{([\s\S]+?\}\s*)\}/g, function (_, query, inner) {
|
|
178
|
+
mediaBlocks.push({
|
|
179
|
+
query: query.trim(),
|
|
180
|
+
inner: inner
|
|
181
|
+
});
|
|
182
|
+
return "";
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// 2. Parse regular rules
|
|
186
|
+
var ruleRe = /([^{}]+)\{([^{}]+)\}/g;
|
|
187
|
+
var match;
|
|
188
|
+
while ((match = ruleRe.exec(noMediaCss)) !== null) {
|
|
189
|
+
var rawSelectors = match[1].trim();
|
|
190
|
+
var body = match[2].trim();
|
|
191
|
+
if (rawSelectors.startsWith("@")) continue;
|
|
192
|
+
var selectors = rawSelectors.split(",").map(function (s) {
|
|
193
|
+
return s.trim();
|
|
194
|
+
});
|
|
195
|
+
var decls = parseDeclarations(body);
|
|
196
|
+
var _iterator2 = _createForOfIteratorHelper(selectors),
|
|
197
|
+
_step2;
|
|
198
|
+
try {
|
|
199
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
200
|
+
var sel = _step2.value;
|
|
201
|
+
if (!sel.startsWith(".") && !sel.includes(":root")) continue;
|
|
202
|
+
var names = cleanSelector(sel);
|
|
203
|
+
var _iterator3 = _createForOfIteratorHelper(names),
|
|
204
|
+
_step3;
|
|
205
|
+
try {
|
|
206
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
207
|
+
var name = _step3.value;
|
|
208
|
+
rawStylesheet[name] = _objectSpread(_objectSpread({}, rawStylesheet[name]), decls);
|
|
209
|
+
}
|
|
210
|
+
} catch (err) {
|
|
211
|
+
_iterator3.e(err);
|
|
212
|
+
} finally {
|
|
213
|
+
_iterator3.f();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
} catch (err) {
|
|
217
|
+
_iterator2.e(err);
|
|
218
|
+
} finally {
|
|
219
|
+
_iterator2.f();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 3. Parse media query rules
|
|
224
|
+
for (var _i = 0, _mediaBlocks = mediaBlocks; _i < _mediaBlocks.length; _i++) {
|
|
225
|
+
var mb = _mediaBlocks[_i];
|
|
226
|
+
var mMatch = void 0;
|
|
227
|
+
var mRuleRe = /([^{}]+)\{([^{}]+)\}/g;
|
|
228
|
+
while ((mMatch = mRuleRe.exec(mb.inner)) !== null) {
|
|
229
|
+
var _rawSelectors = mMatch[1].trim();
|
|
230
|
+
var _body = mMatch[2].trim();
|
|
231
|
+
var _selectors = _rawSelectors.split(",").map(function (s) {
|
|
232
|
+
return s.trim();
|
|
233
|
+
});
|
|
234
|
+
var _decls = parseDeclarations(_body);
|
|
235
|
+
var _iterator4 = _createForOfIteratorHelper(_selectors),
|
|
236
|
+
_step4;
|
|
237
|
+
try {
|
|
238
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
239
|
+
var _sel = _step4.value;
|
|
240
|
+
if (!_sel.startsWith(".") && !_sel.includes(":root")) continue;
|
|
241
|
+
var _names = cleanSelector(_sel);
|
|
242
|
+
var _iterator5 = _createForOfIteratorHelper(_names),
|
|
243
|
+
_step5;
|
|
244
|
+
try {
|
|
245
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
246
|
+
var _name = _step5.value;
|
|
247
|
+
rawStylesheet[_name] = _objectSpread(_objectSpread({}, rawStylesheet[_name]), {}, _defineProperty({}, "@media ".concat(mb.query), _decls));
|
|
248
|
+
}
|
|
249
|
+
} catch (err) {
|
|
250
|
+
_iterator5.e(err);
|
|
251
|
+
} finally {
|
|
252
|
+
_iterator5.f();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} catch (err) {
|
|
256
|
+
_iterator4.e(err);
|
|
257
|
+
} finally {
|
|
258
|
+
_iterator4.f();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return rawStylesheet;
|
|
263
|
+
}
|