@colorye/react-native-css 0.3.0 → 0.3.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/crates/transformer/index.js +1 -0
- package/crates/transformer/transformer.darwin-arm64.node +0 -0
- package/crates/transformer/transformer.darwin-x64.node +0 -0
- package/crates/transformer/transformer.linux-x64-gnu.node +0 -0
- package/crates/transformer/transformer.node +0 -0
- package/crates/transformer/transformer.win32-x64-msvc.node +0 -0
- package/dist/babel.js +68 -159
- package/dist/index.d.ts +22 -8
- package/dist/interop.js +17 -5
- package/dist/metro.js +55 -0
- package/dist/transformer-runtime.js +170 -18
- package/dist/transformer.js +73 -20
- package/package.json +10 -1
- package/src/babel.js +71 -224
- package/src/index.d.ts +22 -8
- package/src/interop.js +13 -1
- package/src/metro.js +42 -0
- package/src/transformer-runtime.js +169 -15
- package/src/transformer.js +75 -15
- package/dist/exported-stylesheet.json +0 -1
- package/dist/features/build-transform.js +0 -575
- package/dist/features/css-calc.js +0 -539
- package/dist/features/css-media.js +0 -77
- package/dist/features/css-transform.js +0 -426
- package/dist/features/css-vars.js +0 -153
- package/dist/features/stylesheet.js +0 -45
- package/dist/utils/babel.js +0 -363
- package/dist/utils/css.js +0 -263
- package/dist/utils/helper.js +0 -11
- package/src/exported-stylesheet.json +0 -1
- package/src/features/build-transform.js +0 -536
- package/src/features/css-calc.js +0 -490
- package/src/features/css-media.js +0 -78
- package/src/features/css-transform.js +0 -446
- package/src/features/css-vars.js +0 -138
- package/src/features/stylesheet.js +0 -29
- package/src/utils/babel.js +0 -425
- package/src/utils/css.js +0 -221
- package/src/utils/helper.js +0 -3
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/babel.js
CHANGED
|
@@ -6,105 +6,67 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports["default"] = _default;
|
|
7
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var
|
|
9
|
+
var _core = require("@babel/core");
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
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; } } }; }
|
|
12
|
+
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; } }
|
|
13
|
+
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; }
|
|
14
|
+
var _native = null;
|
|
15
|
+
try {
|
|
16
|
+
_native = require("./native");
|
|
17
|
+
} catch (_unused) {
|
|
18
|
+
try {
|
|
19
|
+
_native = require("../crates/transformer");
|
|
20
|
+
} catch (_unused2) {}
|
|
21
|
+
}
|
|
11
22
|
var libRoot = _path["default"].dirname(__filename);
|
|
12
|
-
|
|
13
|
-
// Cache for loaded stylesheets
|
|
14
23
|
var stylesheetCache = new Map();
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Load pre-computed stylesheet JSON (generated by Metro transformer)
|
|
18
|
-
*/
|
|
19
24
|
function loadStylesheet(cssPath, fileDir) {
|
|
25
|
+
if (!cssPath) return "{}";
|
|
20
26
|
if (stylesheetCache.has(cssPath)) {
|
|
21
27
|
return stylesheetCache.get(cssPath);
|
|
22
28
|
}
|
|
23
29
|
try {
|
|
24
30
|
var cwd = process.cwd();
|
|
25
31
|
var cleanPath = cssPath.replace(/^@\//, "");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (_fs["default"].existsSync(projectRootJson)) {
|
|
30
|
-
var content = _fs["default"].readFileSync(projectRootJson, "utf-8");
|
|
31
|
-
var stylesheet = JSON.parse(content);
|
|
32
|
-
stylesheetCache.set(cssPath, stylesheet);
|
|
33
|
-
return stylesheet;
|
|
34
|
-
}
|
|
35
|
-
var defaultIndexJson = _path["default"].resolve(cwd, "index.css.json");
|
|
36
|
-
if (_fs["default"].existsSync(defaultIndexJson)) {
|
|
37
|
-
var _content = _fs["default"].readFileSync(defaultIndexJson, "utf-8");
|
|
38
|
-
var _stylesheet = JSON.parse(_content);
|
|
39
|
-
stylesheetCache.set(cssPath, _stylesheet);
|
|
40
|
-
return _stylesheet;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 2. Try fileDir if provided
|
|
44
|
-
if (fileDir) {
|
|
45
|
-
var localJson = _path["default"].resolve(fileDir, cssPath);
|
|
46
|
-
if (_fs["default"].existsSync(localJson)) {
|
|
47
|
-
var _content2 = _fs["default"].readFileSync(localJson, "utf-8");
|
|
48
|
-
var _stylesheet2 = JSON.parse(_content2);
|
|
49
|
-
stylesheetCache.set(cssPath, _stylesheet2);
|
|
50
|
-
return _stylesheet2;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 3. Try resolving the module if it's a module specifier like @colorye/react-native-css/exported-stylesheet.json
|
|
32
|
+
var candidates = [_path["default"].resolve(cwd, cleanPath), _path["default"].resolve(cwd, cleanPath.endsWith(".json") ? cleanPath : "".concat(cleanPath, ".json")), fileDir ? _path["default"].resolve(fileDir, cssPath) : null, _path["default"].resolve(cwd, "index.css.json"), _path["default"].resolve(cwd, "index.css"), _path["default"].join(libRoot, "exported-stylesheet.json")].filter(Boolean);
|
|
33
|
+
var _iterator = _createForOfIteratorHelper(candidates),
|
|
34
|
+
_step;
|
|
55
35
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
36
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
37
|
+
var p = _step.value;
|
|
38
|
+
if (_fs["default"].existsSync(p)) {
|
|
39
|
+
var content = _fs["default"].readFileSync(p, "utf-8");
|
|
40
|
+
var sheetJson = content;
|
|
41
|
+
if (p.endsWith(".css") && _native && _native.compileCss) {
|
|
42
|
+
sheetJson = _native.compileCss(content);
|
|
43
|
+
}
|
|
44
|
+
stylesheetCache.set(cssPath, sheetJson);
|
|
45
|
+
return sheetJson;
|
|
46
|
+
}
|
|
64
47
|
}
|
|
65
|
-
} catch (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (_fs["default"].existsSync(exportedPath)) {
|
|
70
|
-
var _content4 = _fs["default"].readFileSync(exportedPath, "utf-8");
|
|
71
|
-
var _stylesheet4 = JSON.parse(_content4);
|
|
72
|
-
stylesheetCache.set(cssPath, _stylesheet4);
|
|
73
|
-
return _stylesheet4;
|
|
48
|
+
} catch (err) {
|
|
49
|
+
_iterator.e(err);
|
|
50
|
+
} finally {
|
|
51
|
+
_iterator.f();
|
|
74
52
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var cssJsonPath = "".concat(cssPath, ".json");
|
|
78
|
-
if (_fs["default"].existsSync(cssJsonPath)) {
|
|
79
|
-
var _content5 = _fs["default"].readFileSync(cssJsonPath, "utf-8");
|
|
80
|
-
var _stylesheet5 = JSON.parse(_content5);
|
|
81
|
-
stylesheetCache.set(cssPath, _stylesheet5);
|
|
82
|
-
return _stylesheet5;
|
|
83
|
-
}
|
|
84
|
-
return null;
|
|
85
|
-
} catch (_unused2) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
53
|
+
} catch (_unused3) {}
|
|
54
|
+
return "{}";
|
|
88
55
|
}
|
|
89
|
-
function _default(
|
|
90
|
-
var t = _ref.types;
|
|
56
|
+
function _default() {
|
|
91
57
|
return {
|
|
92
58
|
name: "@colorye/react-native-css",
|
|
93
59
|
visitor: {
|
|
94
60
|
Program: {
|
|
95
61
|
enter: function enter(path, state) {
|
|
96
|
-
|
|
97
|
-
console.warn("No css file provided");
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
62
|
+
var _this$opts, _this$opts2, _this$opts3;
|
|
100
63
|
var filename = state.file.opts.filename;
|
|
64
|
+
if (!filename || filename.includes("node_modules")) return;
|
|
101
65
|
var options = {
|
|
102
|
-
paths: this.opts.paths || [],
|
|
103
|
-
excludes: this.opts.excludes || [],
|
|
104
|
-
css: this.opts.css
|
|
66
|
+
paths: ((_this$opts = this.opts) === null || _this$opts === void 0 ? void 0 : _this$opts.paths) || [],
|
|
67
|
+
excludes: ((_this$opts2 = this.opts) === null || _this$opts2 === void 0 ? void 0 : _this$opts2.excludes) || [],
|
|
68
|
+
css: (_this$opts3 = this.opts) === null || _this$opts3 === void 0 ? void 0 : _this$opts3.css
|
|
105
69
|
};
|
|
106
|
-
|
|
107
|
-
// Normalize filename for cross-platform regex matching
|
|
108
70
|
var normalizedFilename = filename.replace(/\\/g, "/");
|
|
109
71
|
var regex = options.paths.map(function (p) {
|
|
110
72
|
return new RegExp(p);
|
|
@@ -112,94 +74,41 @@ function _default(_ref) {
|
|
|
112
74
|
var excludesRegex = options.excludes.map(function (p) {
|
|
113
75
|
return new RegExp(p);
|
|
114
76
|
});
|
|
115
|
-
if (!regex.some(function (re) {
|
|
116
|
-
return normalizedFilename.match(re) || filename.match(re);
|
|
117
|
-
}) || excludesRegex.some(function (re) {
|
|
77
|
+
if (options.paths.length > 0 && !regex.some(function (re) {
|
|
118
78
|
return normalizedFilename.match(re) || filename.match(re);
|
|
119
79
|
})) {
|
|
120
80
|
return;
|
|
121
81
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// Track which runtime helpers we need
|
|
128
|
-
state.needsGetStyle = false;
|
|
129
|
-
state.needsGetInheritStyle = false;
|
|
130
|
-
state.needsMergeStyles = false;
|
|
131
|
-
|
|
132
|
-
// Prepare runtime helper declarations
|
|
133
|
-
state.stylesheetId = path.scope.generateUidIdentifier();
|
|
134
|
-
state.stylesheet = t.variableDeclaration("var", [t.variableDeclarator(state.stylesheetId, t.callExpression(t.identifier("require"), [t.stringLiteral(options.css)]))]);
|
|
135
|
-
state.getStyleId = path.scope.generateUidIdentifier();
|
|
136
|
-
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")))]);
|
|
137
|
-
state.getInheritStyleId = path.scope.generateUidIdentifier();
|
|
138
|
-
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")))]);
|
|
139
|
-
state.mergeStylesId = path.scope.generateUidIdentifier();
|
|
140
|
-
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")))]);
|
|
141
|
-
},
|
|
142
|
-
exit: function exit(path, state) {
|
|
143
|
-
if (!state.enabled) return;
|
|
144
|
-
var helpers = [];
|
|
145
|
-
|
|
146
|
-
// Only inject helpers that are actually used
|
|
147
|
-
if (state.needsGetStyle) {
|
|
148
|
-
helpers.push(state.stylesheet);
|
|
149
|
-
helpers.push(state.getStyle);
|
|
150
|
-
}
|
|
151
|
-
if (state.needsGetInheritStyle) {
|
|
152
|
-
helpers.push(state.getInheritStyle);
|
|
153
|
-
}
|
|
154
|
-
if (state.needsMergeStyles) {
|
|
155
|
-
helpers.push(state.mergeStyles);
|
|
82
|
+
if (excludesRegex.some(function (re) {
|
|
83
|
+
return normalizedFilename.match(re) || filename.match(re);
|
|
84
|
+
})) {
|
|
85
|
+
return;
|
|
156
86
|
}
|
|
157
|
-
if (
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var styleExpressions;
|
|
180
|
-
|
|
181
|
-
// Try static inlining first (if stylesheet loaded and class is static)
|
|
182
|
-
if (state.stylesheetData) {
|
|
183
|
-
var staticInfo = (0, _babel.tryGetStaticStyleInfo)(path, state, t);
|
|
184
|
-
if (staticInfo) {
|
|
185
|
-
// Static class! Use lightweight mergeStyles
|
|
186
|
-
styleExpressions = (0, _babel.getStaticMergeExpression)(path, state, t, staticInfo);
|
|
187
|
-
state.needsMergeStyles = true;
|
|
87
|
+
if (!_native || !_native.transformJsx) return;
|
|
88
|
+
var stylesheetJson = loadStylesheet(options.css, filename ? _path["default"].dirname(filename) : null);
|
|
89
|
+
var rawCode = state.file.code;
|
|
90
|
+
try {
|
|
91
|
+
var res = _native.transformJsx(rawCode, {
|
|
92
|
+
filename: filename,
|
|
93
|
+
stylesheetJson: stylesheetJson,
|
|
94
|
+
sourceMaps: false
|
|
95
|
+
});
|
|
96
|
+
if (res && res.code && res.code !== rawCode) {
|
|
97
|
+
var newAst = (0, _core.parseSync)(res.code, {
|
|
98
|
+
filename: filename,
|
|
99
|
+
parserOpts: {
|
|
100
|
+
plugins: ["jsx", "typescript"]
|
|
101
|
+
},
|
|
102
|
+
configFile: false,
|
|
103
|
+
babelrc: false
|
|
104
|
+
});
|
|
105
|
+
if (newAst && newAst.program) {
|
|
106
|
+
path.replaceWith(newAst.program);
|
|
107
|
+
path.stop();
|
|
108
|
+
}
|
|
188
109
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Fall back to full runtime getStyle
|
|
192
|
-
state.needsGetStyle = true;
|
|
193
|
-
styleExpressions = (0, _babel.getStyleExpression)(path, state, t);
|
|
194
|
-
}
|
|
195
|
-
var style = openingElement.attributes.find(function (attr) {
|
|
196
|
-
var _attr$name2;
|
|
197
|
-
return ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.name) === "style";
|
|
198
|
-
});
|
|
199
|
-
if (style) {
|
|
200
|
-
style.value = t.jsxExpressionContainer(styleExpressions);
|
|
201
|
-
} else {
|
|
202
|
-
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(styleExpressions)));
|
|
110
|
+
} catch (_unused4) {
|
|
111
|
+
// Silently fall back if native transformation fails
|
|
203
112
|
}
|
|
204
113
|
}
|
|
205
114
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,8 +13,20 @@ export interface GroupState {
|
|
|
13
13
|
focus?: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export interface InheritedStyles {
|
|
17
|
+
color?: string;
|
|
18
|
+
fontSize?: number;
|
|
19
|
+
fontWeight?: string;
|
|
20
|
+
fontFamily?: string;
|
|
21
|
+
letterSpacing?: number;
|
|
22
|
+
lineHeight?: number;
|
|
23
|
+
textAlign?: string;
|
|
24
|
+
textTransform?: string;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}
|
|
27
|
+
|
|
16
28
|
export const GroupContext: React.Context<GroupState>;
|
|
17
|
-
export const InheritContext: React.Context<
|
|
29
|
+
export const InheritContext: React.Context<InheritedStyles | undefined>;
|
|
18
30
|
|
|
19
31
|
export function setGlobalStylesheet(sheet: Record<string, any>): void;
|
|
20
32
|
export function getGlobalStylesheet(): Record<string, any>;
|
|
@@ -33,7 +45,7 @@ export function getGlobalStylesheet(): Record<string, any>;
|
|
|
33
45
|
* });
|
|
34
46
|
* ```
|
|
35
47
|
*/
|
|
36
|
-
export function cssInterop<P extends object>(
|
|
48
|
+
export function cssInterop<T = any, P extends object = any>(
|
|
37
49
|
Component: React.ComponentType<P>,
|
|
38
50
|
mapping?: StyleMapping
|
|
39
51
|
): React.ForwardRefExoticComponent<
|
|
@@ -41,13 +53,13 @@ export function cssInterop<P extends object>(
|
|
|
41
53
|
className?: string;
|
|
42
54
|
contentContainerClassName?: string;
|
|
43
55
|
inheritStyle?: any;
|
|
44
|
-
} & React.RefAttributes<
|
|
56
|
+
} & React.RefAttributes<T>
|
|
45
57
|
>;
|
|
46
58
|
|
|
47
59
|
/**
|
|
48
60
|
* Alias for cssInterop.
|
|
49
61
|
*/
|
|
50
|
-
export function remapProps<P extends object>(
|
|
62
|
+
export function remapProps<T = any, P extends object = any>(
|
|
51
63
|
Component: React.ComponentType<P>,
|
|
52
64
|
mapping: StyleMapping
|
|
53
65
|
): React.ForwardRefExoticComponent<
|
|
@@ -55,7 +67,7 @@ export function remapProps<P extends object>(
|
|
|
55
67
|
className?: string;
|
|
56
68
|
contentContainerClassName?: string;
|
|
57
69
|
inheritStyle?: any;
|
|
58
|
-
} & React.RefAttributes<
|
|
70
|
+
} & React.RefAttributes<T>
|
|
59
71
|
>;
|
|
60
72
|
|
|
61
73
|
export namespace Runtime {
|
|
@@ -73,6 +85,11 @@ export function getStylesheet(css: string, filename?: string): string;
|
|
|
73
85
|
export function writeStylesheetJSON(content: string, filename?: string): void;
|
|
74
86
|
export function transform(args: { src: string; filename: string; options?: any }): any;
|
|
75
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Plug-and-play zero-configuration helper for Expo and React Native Metro bundler.
|
|
90
|
+
*/
|
|
91
|
+
export function withReactNativeCss<T = any>(metroConfig: T, options?: { input?: string }): T;
|
|
92
|
+
|
|
76
93
|
declare const _default: {
|
|
77
94
|
cssInterop: typeof cssInterop;
|
|
78
95
|
remapProps: typeof remapProps;
|
|
@@ -81,9 +98,6 @@ declare const _default: {
|
|
|
81
98
|
GroupContext: typeof GroupContext;
|
|
82
99
|
InheritContext: typeof InheritContext;
|
|
83
100
|
Runtime: typeof Runtime;
|
|
84
|
-
getStylesheet: typeof getStylesheet;
|
|
85
|
-
transform: typeof transform;
|
|
86
|
-
writeStylesheetJSON: typeof writeStylesheetJSON;
|
|
87
101
|
};
|
|
88
102
|
|
|
89
103
|
export default _default;
|
package/dist/interop.js
CHANGED
|
@@ -26,6 +26,18 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
26
26
|
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; } }
|
|
27
27
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
28
28
|
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); }
|
|
29
|
+
function shallowEqual(a, b) {
|
|
30
|
+
if (a === b) return true;
|
|
31
|
+
if (!a || !b || _typeof(a) !== "object" || _typeof(b) !== "object") return false;
|
|
32
|
+
var keysA = Object.keys(a);
|
|
33
|
+
var keysB = Object.keys(b);
|
|
34
|
+
if (keysA.length !== keysB.length) return false;
|
|
35
|
+
for (var _i = 0, _keysA = keysA; _i < _keysA.length; _i++) {
|
|
36
|
+
var k = _keysA[_i];
|
|
37
|
+
if (a[k] !== b[k]) return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
29
41
|
var InheritContext = exports.InheritContext = (0, _react.createContext)(undefined);
|
|
30
42
|
var GroupContext = exports.GroupContext = (0, _react.createContext)({
|
|
31
43
|
pressed: false,
|
|
@@ -96,8 +108,8 @@ function cssInterop(Component) {
|
|
|
96
108
|
var isGroupProvider = false;
|
|
97
109
|
|
|
98
110
|
// Check if this component acts as a group container
|
|
99
|
-
for (var
|
|
100
|
-
var classProp = _Object$keys[
|
|
111
|
+
for (var _i2 = 0, _Object$keys = Object.keys(mapping); _i2 < _Object$keys.length; _i2++) {
|
|
112
|
+
var classProp = _Object$keys[_i2];
|
|
101
113
|
var val = props[classProp];
|
|
102
114
|
if (typeof val === "string" && (val === "group" || val.split(/\s+/).includes("group"))) {
|
|
103
115
|
isGroupProvider = true;
|
|
@@ -117,7 +129,7 @@ function cssInterop(Component) {
|
|
|
117
129
|
};
|
|
118
130
|
}
|
|
119
131
|
var _loop = function _loop() {
|
|
120
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[
|
|
132
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2),
|
|
121
133
|
classProp = _Object$entries$_i[0],
|
|
122
134
|
styleProp = _Object$entries$_i[1];
|
|
123
135
|
var classValue = props[classProp];
|
|
@@ -231,7 +243,7 @@ function cssInterop(Component) {
|
|
|
231
243
|
}
|
|
232
244
|
}
|
|
233
245
|
};
|
|
234
|
-
for (var
|
|
246
|
+
for (var _i3 = 0, _Object$entries = Object.entries(mapping); _i3 < _Object$entries.length; _i3++) {
|
|
235
247
|
_loop();
|
|
236
248
|
}
|
|
237
249
|
delete nextProps.inheritStyle;
|
|
@@ -243,7 +255,7 @@ function cssInterop(Component) {
|
|
|
243
255
|
})
|
|
244
256
|
}, element);
|
|
245
257
|
}
|
|
246
|
-
if (currentInherit && currentInherit
|
|
258
|
+
if (currentInherit && !shallowEqual(currentInherit, parentInherit)) {
|
|
247
259
|
return _react["default"].createElement(InheritContext.Provider, {
|
|
248
260
|
value: currentInherit
|
|
249
261
|
}, element);
|
package/dist/metro.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
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; } }
|
|
7
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
8
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
9
|
+
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; }
|
|
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
|
+
var fs = require("fs");
|
|
16
|
+
var path = require("path");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* withReactNativeCss
|
|
20
|
+
*
|
|
21
|
+
* Plug-and-play zero-configuration helper for Expo and React Native Metro bundler.
|
|
22
|
+
*
|
|
23
|
+
* Automatically:
|
|
24
|
+
* 1. Configures Metro to handle .css files via @colorye/react-native-css/transformer.
|
|
25
|
+
* 2. Connects the high-performance Rust SWC native transformer for JSX/TSX.
|
|
26
|
+
* 3. Adds 'css' to sourceExts.
|
|
27
|
+
* 4. In-process caches and synchronizes stylesheet JSON without manual setup.
|
|
28
|
+
*
|
|
29
|
+
* @param {import('metro-config').MetroConfig} metroConfig
|
|
30
|
+
* @param {Object} [options]
|
|
31
|
+
* @param {string} [options.input] - Input CSS path relative to project root (default: 'src/assets/styles/index.css' or 'index.css')
|
|
32
|
+
* @returns {import('metro-config').MetroConfig}
|
|
33
|
+
*/
|
|
34
|
+
function withReactNativeCss(metroConfig) {
|
|
35
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
36
|
+
var config = _objectSpread({}, metroConfig);
|
|
37
|
+
|
|
38
|
+
// Ensure resolver & transformer objects exist
|
|
39
|
+
config.resolver = config.resolver || {};
|
|
40
|
+
config.transformer = config.transformer || {};
|
|
41
|
+
|
|
42
|
+
// 1. Add 'css' to sourceExts if missing
|
|
43
|
+
var currentSourceExts = config.resolver.sourceExts || [];
|
|
44
|
+
if (!currentSourceExts.includes("css")) {
|
|
45
|
+
config.resolver.sourceExts = [].concat(_toConsumableArray(currentSourceExts), ["css"]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 2. Wrap or assign babelTransformerPath
|
|
49
|
+
var defaultTransformerPath = config.transformer.babelTransformerPath || require.resolve("./transformer");
|
|
50
|
+
config.transformer.babelTransformerPath = defaultTransformerPath;
|
|
51
|
+
return config;
|
|
52
|
+
}
|
|
53
|
+
module.exports = {
|
|
54
|
+
withReactNativeCss: withReactNativeCss
|
|
55
|
+
};
|