@colorye/react-native-css 0.2.1
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/.babelrc +3 -0
- package/.yarnrc.yml +8 -0
- package/dist/babel.js +201 -0
- package/dist/features/build-transform.js +562 -0
- package/dist/features/css-calc.js +378 -0
- package/dist/features/css-media.js +77 -0
- package/dist/features/css-transform.js +398 -0
- package/dist/features/css-vars.js +107 -0
- package/dist/features/stylesheet.js +94 -0
- package/dist/index.js +158 -0
- package/dist/transformer-runtime.js +310 -0
- package/dist/utils/babel.js +336 -0
- package/dist/utils/css.js +239 -0
- package/dist/utils/helper.js +11 -0
- package/package.json +26 -0
- package/src/babel.js +274 -0
- package/src/features/build-transform.js +524 -0
- package/src/features/css-calc.js +326 -0
- package/src/features/css-media.js +78 -0
- package/src/features/css-transform.js +419 -0
- package/src/features/css-vars.js +93 -0
- package/src/features/stylesheet.js +82 -0
- package/src/index.js +123 -0
- package/src/transformer-runtime.js +287 -0
- package/src/utils/babel.js +354 -0
- package/src/utils/css.js +254 -0
- package/src/utils/helper.js +3 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = CssTransform;
|
|
7
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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; } }
|
|
10
|
+
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; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
+
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); }
|
|
16
|
+
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); }
|
|
17
|
+
var UNSUPPORTED_PROPERTIES = ["outline"];
|
|
18
|
+
var remOrEmUnitRe = /([\d.]+)(?:rem|em)\b/g;
|
|
19
|
+
function CssTransform() {
|
|
20
|
+
var _this = this;
|
|
21
|
+
this.transformUnsafeValue = function (property, value) {
|
|
22
|
+
if (!_this.isPropertySupported(property, value)) {
|
|
23
|
+
console.info("UNSUPPORTED", property, value);
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "string") {
|
|
27
|
+
value = value.trim();
|
|
28
|
+
value = _this.transformImportant(property, value);
|
|
29
|
+
}
|
|
30
|
+
value = _this.transformPosition(property, value);
|
|
31
|
+
value = _this.transformBorderRadius(property, value);
|
|
32
|
+
value = _this.transformOpacity(property, value);
|
|
33
|
+
property = _this.getAliasedPropertyName(property);
|
|
34
|
+
return [property, value];
|
|
35
|
+
};
|
|
36
|
+
this.transformUnsupportedUnit = function (value) {
|
|
37
|
+
if (value === undefined || typeof value !== "string") return value;
|
|
38
|
+
remOrEmUnitRe.lastIndex = 0;
|
|
39
|
+
return value.replace(remOrEmUnitRe, function (_, rem) {
|
|
40
|
+
return rem * 16;
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
this.transformViewportUnit = function (value) {
|
|
44
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
45
|
+
width = _ref.width,
|
|
46
|
+
height = _ref.height;
|
|
47
|
+
if (value === undefined || typeof value !== "string") return value;
|
|
48
|
+
if (!width || !height) return value;
|
|
49
|
+
var viewportUnitRe = /([+-]?[0-9.]+)(vh|vw|vmin|vmax)\b/g;
|
|
50
|
+
var dimensionsMap = {
|
|
51
|
+
vw: width,
|
|
52
|
+
vh: height
|
|
53
|
+
};
|
|
54
|
+
return value.replace(viewportUnitRe, function (_, number, unit) {
|
|
55
|
+
return parseFloat(number) * dimensionsMap[unit] / 100;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
this.removeUnit = function (value) {
|
|
59
|
+
if (value === undefined || typeof value !== "string") return value;
|
|
60
|
+
return value.replace(/px/g, "");
|
|
61
|
+
};
|
|
62
|
+
this.isPropertySupported = function (property, value) {
|
|
63
|
+
if (UNSUPPORTED_PROPERTIES.includes(property)) return false;
|
|
64
|
+
if (value === undefined) return false;
|
|
65
|
+
if (!["number", "string"].includes(_typeof(value))) return false;
|
|
66
|
+
return true;
|
|
67
|
+
};
|
|
68
|
+
this.transformImportant = function (property, value) {
|
|
69
|
+
if (typeof value !== "string") return value;
|
|
70
|
+
return value.replace(/!important/g, "");
|
|
71
|
+
};
|
|
72
|
+
this.transformPosition = function (property, value) {
|
|
73
|
+
if (property === "position" && value === "fixed") {
|
|
74
|
+
return "absolute";
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
};
|
|
78
|
+
this.transformBorderRadius = function (property, value) {
|
|
79
|
+
if (property.toLowerCase().endsWith("radius") && typeof value === "string" && value.includes("%")) {
|
|
80
|
+
return 9999;
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
};
|
|
84
|
+
this.transformOpacity = function (property, value) {
|
|
85
|
+
if (property === "opacity" && typeof value === "string" && value.endsWith("%")) {
|
|
86
|
+
var num = parseFloat(value);
|
|
87
|
+
if (!isNaN(num)) {
|
|
88
|
+
return num / 100;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
};
|
|
93
|
+
this.transformBorder = function (property, value) {
|
|
94
|
+
if (value === "none") {
|
|
95
|
+
return _defineProperty({}, "".concat(property, "Width"), 0);
|
|
96
|
+
}
|
|
97
|
+
var borderRe = /(\S+)(?:\s+(solid|dashed|dotted)(?:\s+(\S+))?)?/g;
|
|
98
|
+
var _ref3 = borderRe.exec(String(value)) || [],
|
|
99
|
+
_ref4 = _slicedToArray(_ref3, 4),
|
|
100
|
+
width = _ref4[1],
|
|
101
|
+
style = _ref4[2],
|
|
102
|
+
color = _ref4[3];
|
|
103
|
+
var transformed = {};
|
|
104
|
+
if (width) {
|
|
105
|
+
transformed["".concat(property, "Width")] = isNaN(width) ? width : Number(width);
|
|
106
|
+
} else {
|
|
107
|
+
transformed["".concat(property, "Width")] = 0;
|
|
108
|
+
}
|
|
109
|
+
if (style) {
|
|
110
|
+
transformed["".concat(property, "Style")] = style;
|
|
111
|
+
}
|
|
112
|
+
if (color) {
|
|
113
|
+
transformed["".concat(property, "Color")] = color;
|
|
114
|
+
}
|
|
115
|
+
return transformed;
|
|
116
|
+
};
|
|
117
|
+
this.transformSpacing = function (property, value) {
|
|
118
|
+
var strValue = String(value).trim();
|
|
119
|
+
var parts = [];
|
|
120
|
+
var current = "";
|
|
121
|
+
var depth = 0;
|
|
122
|
+
for (var i = 0; i < strValue.length; i++) {
|
|
123
|
+
var _char = strValue[i];
|
|
124
|
+
if (_char === "(") {
|
|
125
|
+
depth++;
|
|
126
|
+
current += _char;
|
|
127
|
+
} else if (_char === ")") {
|
|
128
|
+
depth--;
|
|
129
|
+
current += _char;
|
|
130
|
+
} else if (_char === " " && depth === 0) {
|
|
131
|
+
if (current) {
|
|
132
|
+
parts.push(current);
|
|
133
|
+
current = "";
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
current += _char;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (current) {
|
|
140
|
+
parts.push(current);
|
|
141
|
+
}
|
|
142
|
+
var cleanedParts = parts.filter(Boolean);
|
|
143
|
+
var toNumberOrString = function toNumberOrString(val) {
|
|
144
|
+
return isNaN(val) ? val : Number(val);
|
|
145
|
+
};
|
|
146
|
+
var transformed = {};
|
|
147
|
+
if (cleanedParts.length === 0) {
|
|
148
|
+
transformed["".concat(property, "Top")] = 0;
|
|
149
|
+
transformed["".concat(property, "Right")] = 0;
|
|
150
|
+
transformed["".concat(property, "Bottom")] = 0;
|
|
151
|
+
transformed["".concat(property, "Left")] = 0;
|
|
152
|
+
} else if (cleanedParts.length === 1) {
|
|
153
|
+
var top = cleanedParts[0];
|
|
154
|
+
transformed["".concat(property, "Top")] = toNumberOrString(top);
|
|
155
|
+
transformed["".concat(property, "Right")] = toNumberOrString(top);
|
|
156
|
+
transformed["".concat(property, "Bottom")] = toNumberOrString(top);
|
|
157
|
+
transformed["".concat(property, "Left")] = toNumberOrString(top);
|
|
158
|
+
} else if (cleanedParts.length === 2) {
|
|
159
|
+
var _top = cleanedParts[0];
|
|
160
|
+
var right = cleanedParts[1];
|
|
161
|
+
transformed["".concat(property, "Top")] = toNumberOrString(_top);
|
|
162
|
+
transformed["".concat(property, "Right")] = toNumberOrString(right);
|
|
163
|
+
transformed["".concat(property, "Bottom")] = toNumberOrString(_top);
|
|
164
|
+
transformed["".concat(property, "Left")] = toNumberOrString(right);
|
|
165
|
+
} else if (cleanedParts.length === 3) {
|
|
166
|
+
var _top2 = cleanedParts[0];
|
|
167
|
+
var _right = cleanedParts[1];
|
|
168
|
+
var bottom = cleanedParts[2];
|
|
169
|
+
transformed["".concat(property, "Top")] = toNumberOrString(_top2);
|
|
170
|
+
transformed["".concat(property, "Right")] = toNumberOrString(_right);
|
|
171
|
+
transformed["".concat(property, "Bottom")] = toNumberOrString(bottom);
|
|
172
|
+
transformed["".concat(property, "Left")] = toNumberOrString(_right);
|
|
173
|
+
} else {
|
|
174
|
+
var _top3 = cleanedParts[0];
|
|
175
|
+
var _right2 = cleanedParts[1];
|
|
176
|
+
var _bottom = cleanedParts[2];
|
|
177
|
+
var left = cleanedParts[3];
|
|
178
|
+
transformed["".concat(property, "Top")] = toNumberOrString(_top3);
|
|
179
|
+
transformed["".concat(property, "Right")] = toNumberOrString(_right2);
|
|
180
|
+
transformed["".concat(property, "Bottom")] = toNumberOrString(_bottom);
|
|
181
|
+
transformed["".concat(property, "Left")] = toNumberOrString(left);
|
|
182
|
+
}
|
|
183
|
+
return transformed;
|
|
184
|
+
};
|
|
185
|
+
this.transformFontWeight = function (property, value) {
|
|
186
|
+
var fontWeightRe = /(normal|bold|100|200|300|400|500|600|700|800|900)/g;
|
|
187
|
+
if (!fontWeightRe.test(String(value))) return;
|
|
188
|
+
return _defineProperty({}, property, String(value));
|
|
189
|
+
};
|
|
190
|
+
this.transformTransform = function (property, value) {
|
|
191
|
+
var transformRe = /(perspective|rotate|rotateX|rotateY|scale|scaleX|scaleY|translate|translateX|translateY|skew|skewX|skewY)\s*\(\s*([^,)]+)[,\s]*([^)]+)?\)/g;
|
|
192
|
+
var transforms = [];
|
|
193
|
+
var match;
|
|
194
|
+
var strValue = String(value);
|
|
195
|
+
do {
|
|
196
|
+
match = transformRe.exec(strValue);
|
|
197
|
+
if (!match) break;
|
|
198
|
+
var _match = match,
|
|
199
|
+
_match2 = _slicedToArray(_match, 4),
|
|
200
|
+
token = _match2[1],
|
|
201
|
+
val1 = _match2[2],
|
|
202
|
+
val2 = _match2[3];
|
|
203
|
+
if (["translate", "skew"].includes(token)) {
|
|
204
|
+
transforms.push(_defineProperty({}, "".concat(token, "X"), isNaN(val1) ? val1 : Number(val1)));
|
|
205
|
+
transforms.push(_defineProperty({}, "".concat(token, "Y"), isNaN(val2) ? val2 : Number(val2)));
|
|
206
|
+
} else {
|
|
207
|
+
transforms.push(_defineProperty({}, token, isNaN(val1) ? val1 : Number(val1)));
|
|
208
|
+
}
|
|
209
|
+
} while (match);
|
|
210
|
+
return _defineProperty({}, property, transforms);
|
|
211
|
+
};
|
|
212
|
+
this.transformFontScaling = function (property, value, _ref7) {
|
|
213
|
+
var width = _ref7.width,
|
|
214
|
+
roundFn = _ref7.roundFn;
|
|
215
|
+
if (!["fontSize", "lineHeight"].includes(property)) return value;
|
|
216
|
+
|
|
217
|
+
// Base width for design (iPhone 6/7/8)
|
|
218
|
+
var baseWidth = 375;
|
|
219
|
+
|
|
220
|
+
// Calculate scaling factor based on device width
|
|
221
|
+
var scaleFactor = width ? width / baseWidth : 1;
|
|
222
|
+
if (!isNaN(value)) {
|
|
223
|
+
return roundFn(Number(value) * scaleFactor);
|
|
224
|
+
}
|
|
225
|
+
return value;
|
|
226
|
+
};
|
|
227
|
+
this.transformLogicalProperty = function (property, value) {
|
|
228
|
+
var strValue = String(value).trim();
|
|
229
|
+
var parts = [];
|
|
230
|
+
var current = "";
|
|
231
|
+
var depth = 0;
|
|
232
|
+
for (var i = 0; i < strValue.length; i++) {
|
|
233
|
+
var _char2 = strValue[i];
|
|
234
|
+
if (_char2 === "(") {
|
|
235
|
+
depth++;
|
|
236
|
+
current += _char2;
|
|
237
|
+
} else if (_char2 === ")") {
|
|
238
|
+
depth--;
|
|
239
|
+
current += _char2;
|
|
240
|
+
} else if (_char2 === " " && depth === 0) {
|
|
241
|
+
if (current) {
|
|
242
|
+
parts.push(current);
|
|
243
|
+
current = "";
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
current += _char2;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (current) {
|
|
250
|
+
parts.push(current);
|
|
251
|
+
}
|
|
252
|
+
var cleanedParts = parts.filter(Boolean);
|
|
253
|
+
var toNumberOrString = function toNumberOrString(val) {
|
|
254
|
+
return isNaN(val) ? val : Number(val);
|
|
255
|
+
};
|
|
256
|
+
if (property === "paddingInlineStart") return {
|
|
257
|
+
paddingStart: toNumberOrString(value)
|
|
258
|
+
};
|
|
259
|
+
if (property === "paddingInlineEnd") return {
|
|
260
|
+
paddingEnd: toNumberOrString(value)
|
|
261
|
+
};
|
|
262
|
+
if (property === "marginInlineStart") return {
|
|
263
|
+
marginStart: toNumberOrString(value)
|
|
264
|
+
};
|
|
265
|
+
if (property === "marginInlineEnd") return {
|
|
266
|
+
marginEnd: toNumberOrString(value)
|
|
267
|
+
};
|
|
268
|
+
if (property === "insetInlineStart") return {
|
|
269
|
+
start: toNumberOrString(value)
|
|
270
|
+
};
|
|
271
|
+
if (property === "insetInlineEnd") return {
|
|
272
|
+
end: toNumberOrString(value)
|
|
273
|
+
};
|
|
274
|
+
if (property === "insetBlockStart") return {
|
|
275
|
+
top: toNumberOrString(value)
|
|
276
|
+
};
|
|
277
|
+
if (property === "insetBlockEnd") return {
|
|
278
|
+
bottom: toNumberOrString(value)
|
|
279
|
+
};
|
|
280
|
+
if (property === "paddingInline") {
|
|
281
|
+
if (cleanedParts.length === 1) {
|
|
282
|
+
return {
|
|
283
|
+
paddingHorizontal: toNumberOrString(cleanedParts[0])
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
if (cleanedParts.length >= 2) {
|
|
287
|
+
return {
|
|
288
|
+
paddingStart: toNumberOrString(cleanedParts[0]),
|
|
289
|
+
paddingEnd: toNumberOrString(cleanedParts[1])
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (property === "marginInline") {
|
|
294
|
+
if (cleanedParts.length === 1) {
|
|
295
|
+
return {
|
|
296
|
+
marginHorizontal: toNumberOrString(cleanedParts[0])
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
if (cleanedParts.length >= 2) {
|
|
300
|
+
return {
|
|
301
|
+
marginStart: toNumberOrString(cleanedParts[0]),
|
|
302
|
+
marginEnd: toNumberOrString(cleanedParts[1])
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (property === "paddingBlock") {
|
|
307
|
+
if (cleanedParts.length === 1) {
|
|
308
|
+
return {
|
|
309
|
+
paddingVertical: toNumberOrString(cleanedParts[0])
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (cleanedParts.length >= 2) {
|
|
313
|
+
return {
|
|
314
|
+
paddingTop: toNumberOrString(cleanedParts[0]),
|
|
315
|
+
paddingBottom: toNumberOrString(cleanedParts[1])
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (property === "marginBlock") {
|
|
320
|
+
if (cleanedParts.length === 1) {
|
|
321
|
+
return {
|
|
322
|
+
marginVertical: toNumberOrString(cleanedParts[0])
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (cleanedParts.length >= 2) {
|
|
326
|
+
return {
|
|
327
|
+
marginTop: toNumberOrString(cleanedParts[0]),
|
|
328
|
+
marginBottom: toNumberOrString(cleanedParts[1])
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (property === "insetInline") {
|
|
333
|
+
if (cleanedParts.length === 1) {
|
|
334
|
+
return {
|
|
335
|
+
left: toNumberOrString(cleanedParts[0]),
|
|
336
|
+
right: toNumberOrString(cleanedParts[0])
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
if (cleanedParts.length >= 2) {
|
|
340
|
+
return {
|
|
341
|
+
start: toNumberOrString(cleanedParts[0]),
|
|
342
|
+
end: toNumberOrString(cleanedParts[1])
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (property === "insetBlock") {
|
|
347
|
+
if (cleanedParts.length === 1) {
|
|
348
|
+
return {
|
|
349
|
+
top: toNumberOrString(cleanedParts[0]),
|
|
350
|
+
bottom: toNumberOrString(cleanedParts[0])
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
if (cleanedParts.length >= 2) {
|
|
354
|
+
return {
|
|
355
|
+
top: toNumberOrString(cleanedParts[0]),
|
|
356
|
+
bottom: toNumberOrString(cleanedParts[1])
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return null;
|
|
361
|
+
};
|
|
362
|
+
this.transform = function (property, value, _ref8) {
|
|
363
|
+
var width = _ref8.width,
|
|
364
|
+
height = _ref8.height;
|
|
365
|
+
if (property.toLowerCase().endsWith("radius")) {
|
|
366
|
+
value = _this.transformBorderRadius(property, value);
|
|
367
|
+
}
|
|
368
|
+
if (property === "opacity") {
|
|
369
|
+
value = _this.transformOpacity(property, value);
|
|
370
|
+
}
|
|
371
|
+
if (["paddingInline", "marginInline", "paddingBlock", "marginBlock", "paddingInlineStart", "paddingInlineEnd", "marginInlineStart", "marginInlineEnd", "insetInline", "insetInlineStart", "insetInlineEnd", "insetBlock", "insetBlockStart", "insetBlockEnd"].includes(property)) {
|
|
372
|
+
return _this.transformLogicalProperty(property, value);
|
|
373
|
+
}
|
|
374
|
+
if (["border", "borderTop", "borderBottom", "borderLeft", "borderRight"].includes(property)) {
|
|
375
|
+
return _this.transformBorder(property, value);
|
|
376
|
+
}
|
|
377
|
+
if (["padding", "margin"].includes(property)) {
|
|
378
|
+
return _this.transformSpacing(property, value);
|
|
379
|
+
}
|
|
380
|
+
if (["flex"].includes(property)) {
|
|
381
|
+
return {
|
|
382
|
+
flex: parseInt(value)
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (["fontWeight"].includes(property)) {
|
|
386
|
+
return _this.transformFontWeight(property, value);
|
|
387
|
+
}
|
|
388
|
+
if (["transform"].includes(property)) {
|
|
389
|
+
return _this.transformTransform(property, value);
|
|
390
|
+
}
|
|
391
|
+
return _defineProperty({}, property, isNaN(value) ? value : Number(value));
|
|
392
|
+
};
|
|
393
|
+
this.getAliasedPropertyName = function (property) {
|
|
394
|
+
if (property === "background") property = "backgroundColor";
|
|
395
|
+
return property;
|
|
396
|
+
};
|
|
397
|
+
return this;
|
|
398
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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["default"] = CssVars;
|
|
8
|
+
var _cssMedia = _interopRequireDefault(require("./css-media"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
16
|
+
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."); }
|
|
17
|
+
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; } }
|
|
18
|
+
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; }
|
|
19
|
+
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; } }
|
|
20
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
21
|
+
var DEFAULT_VARIABLE_VALUE = 0;
|
|
22
|
+
function CssVars() {
|
|
23
|
+
var _this = this;
|
|
24
|
+
this.global = {};
|
|
25
|
+
this.data = {};
|
|
26
|
+
var media = new _cssMedia["default"]();
|
|
27
|
+
this.setGlobal = function (declarations) {
|
|
28
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
29
|
+
width = _ref.width,
|
|
30
|
+
height = _ref.height;
|
|
31
|
+
for (var property in declarations) {
|
|
32
|
+
var value = declarations[property];
|
|
33
|
+
var _media$match = media.match(property, {
|
|
34
|
+
width: width,
|
|
35
|
+
height: height
|
|
36
|
+
}),
|
|
37
|
+
_media$match2 = _slicedToArray(_media$match, 2),
|
|
38
|
+
isMedia = _media$match2[0],
|
|
39
|
+
matchedMedia = _media$match2[1];
|
|
40
|
+
if (isMedia) {
|
|
41
|
+
if (matchedMedia) {
|
|
42
|
+
_this.setGlobal(value);
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (_this.isVar(property)) {
|
|
47
|
+
_this.global[property] = value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
this.getGlobal = function () {
|
|
52
|
+
return _this.global;
|
|
53
|
+
};
|
|
54
|
+
this.set = function (selector, declarations) {
|
|
55
|
+
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
56
|
+
width = _ref2.width,
|
|
57
|
+
height = _ref2.height;
|
|
58
|
+
for (var property in declarations) {
|
|
59
|
+
var value = declarations[property];
|
|
60
|
+
var _media$match3 = media.match(property, {
|
|
61
|
+
width: width,
|
|
62
|
+
height: height
|
|
63
|
+
}),
|
|
64
|
+
_media$match4 = _slicedToArray(_media$match3, 2),
|
|
65
|
+
isMedia = _media$match4[0],
|
|
66
|
+
matchedMedia = _media$match4[1];
|
|
67
|
+
if (isMedia) {
|
|
68
|
+
if (matchedMedia) {
|
|
69
|
+
_this.set(selector, value);
|
|
70
|
+
}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (_this.isVar(property)) {
|
|
74
|
+
if (!_this.data[selector]) _this.data[selector] = {};
|
|
75
|
+
_this.data[selector][property] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
this.get = function (selector) {
|
|
80
|
+
return _objectSpread(_objectSpread({}, _this.global), _this.data[selector] || {});
|
|
81
|
+
};
|
|
82
|
+
this.isVar = function (property) {
|
|
83
|
+
return /^--[\w-]+/.test(property);
|
|
84
|
+
};
|
|
85
|
+
this.injectVar = function (selector, value) {
|
|
86
|
+
if (value === undefined) return value;
|
|
87
|
+
var variables = _this.get(selector);
|
|
88
|
+
var _resolve = function resolve(val) {
|
|
89
|
+
var seen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();
|
|
90
|
+
if (typeof val !== "string") return val;
|
|
91
|
+
return val.replace(/var\((--[^,)]+)(?:,\s*([^)]*))?\)/g, function (match, variableName, defaultValue) {
|
|
92
|
+
if (seen.has(variableName)) {
|
|
93
|
+
return defaultValue !== undefined ? defaultValue : DEFAULT_VARIABLE_VALUE;
|
|
94
|
+
}
|
|
95
|
+
seen.add(variableName);
|
|
96
|
+
var resolvedVal = variables[variableName];
|
|
97
|
+
if (resolvedVal === undefined || resolvedVal === "initial") {
|
|
98
|
+
return defaultValue !== undefined ? defaultValue : DEFAULT_VARIABLE_VALUE;
|
|
99
|
+
}
|
|
100
|
+
return _resolve(resolvedVal, seen);
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
var resolved = _resolve(value);
|
|
104
|
+
return resolved;
|
|
105
|
+
};
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = Stylesheet;
|
|
7
|
+
var _helper = require("../utils/helper");
|
|
8
|
+
var _buildTransform = require("./build-transform");
|
|
9
|
+
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); }
|
|
10
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11
|
+
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."); }
|
|
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
|
+
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; } }
|
|
15
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
20
|
+
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); }
|
|
21
|
+
var SUPPORTED_RULE_TYPES = ["rule", "media"];
|
|
22
|
+
|
|
23
|
+
// Regex for CSS variable detection
|
|
24
|
+
var cssVarRe = /^--[\w-]+/;
|
|
25
|
+
function Stylesheet() {
|
|
26
|
+
var _this = this;
|
|
27
|
+
// Store raw declarations (before pre-computation)
|
|
28
|
+
this.rawStylesheet = {};
|
|
29
|
+
// Store pre-computed declarations
|
|
30
|
+
this.stylesheet = {};
|
|
31
|
+
var _getSelectorName = function _getSelectorName(selector) {
|
|
32
|
+
if (selector === ":root") return selector;
|
|
33
|
+
return selector.replace(/^\./, "").replace(/\\/g, ""); // remove escape backslash
|
|
34
|
+
};
|
|
35
|
+
var isVar = function isVar(property) {
|
|
36
|
+
return cssVarRe.test(property);
|
|
37
|
+
};
|
|
38
|
+
this.isRuleTypeSupported = function (type) {
|
|
39
|
+
return SUPPORTED_RULE_TYPES.includes(type);
|
|
40
|
+
};
|
|
41
|
+
this.isSelectorSupported = function (selector) {
|
|
42
|
+
if (selector === ":root") return true;
|
|
43
|
+
if (selector.includes(" ")) return false;
|
|
44
|
+
if (!selector.startsWith(".")) return false;
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
this.simplifyDeclarations = function (declarations) {
|
|
48
|
+
return (declarations || []).reduce(function (res, declaration) {
|
|
49
|
+
if (declaration.type !== "declaration") return res;
|
|
50
|
+
var property = declaration.property,
|
|
51
|
+
value = declaration.value;
|
|
52
|
+
if (isVar(property)) {
|
|
53
|
+
res[property] = value;
|
|
54
|
+
} else {
|
|
55
|
+
res[(0, _helper.camelize)(property)] = value;
|
|
56
|
+
}
|
|
57
|
+
return res;
|
|
58
|
+
}, {});
|
|
59
|
+
};
|
|
60
|
+
this.upsert = function (selector, declarations) {
|
|
61
|
+
var selectorName = _getSelectorName(selector);
|
|
62
|
+
|
|
63
|
+
// Merge raw declarations
|
|
64
|
+
_this.rawStylesheet[selectorName] = _objectSpread(_objectSpread({}, _this.rawStylesheet[selectorName]), declarations);
|
|
65
|
+
};
|
|
66
|
+
this.finalize = function () {
|
|
67
|
+
// Pre-compute all declarations at the end
|
|
68
|
+
for (var _i = 0, _Object$entries = Object.entries(_this.rawStylesheet); _i < _Object$entries.length; _i++) {
|
|
69
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
70
|
+
selector = _Object$entries$_i[0],
|
|
71
|
+
rawDecl = _Object$entries$_i[1];
|
|
72
|
+
var _precomputeDeclaratio = (0, _buildTransform.precomputeDeclaration)(rawDecl),
|
|
73
|
+
_static = _precomputeDeclaratio._static,
|
|
74
|
+
_dynamic = _precomputeDeclaratio._dynamic,
|
|
75
|
+
_hasDynamic = _precomputeDeclaratio._hasDynamic;
|
|
76
|
+
if (_hasDynamic) {
|
|
77
|
+
// Has dynamic properties - store both static and dynamic
|
|
78
|
+
_this.stylesheet[selector] = {
|
|
79
|
+
_static: _static,
|
|
80
|
+
_dynamic: _dynamic
|
|
81
|
+
};
|
|
82
|
+
} else {
|
|
83
|
+
// Fully static - just store the static object directly
|
|
84
|
+
_this.stylesheet[selector] = _static;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
this.toJSON = function () {
|
|
89
|
+
// Finalize pre-computation before serializing
|
|
90
|
+
_this.finalize();
|
|
91
|
+
return JSON.stringify(_this.stylesheet);
|
|
92
|
+
};
|
|
93
|
+
return this;
|
|
94
|
+
}
|