@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
|
@@ -1,539 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = CssCalc;
|
|
7
|
-
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); }
|
|
8
|
-
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; }
|
|
9
|
-
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; }
|
|
10
|
-
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; }
|
|
11
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
12
|
-
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); }
|
|
13
|
-
var calcRe = /calc\(([^)]+)\)/g;
|
|
14
|
-
var colorRe1 = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+)\s*)?\)/g;
|
|
15
|
-
var colorRe2 = /rgba?\(\s*(\d+)\s+(\d+)\s+(\d+)\s*\/\s*([\d.]+)\s*\)/g;
|
|
16
|
-
var itohex = function itohex(component) {
|
|
17
|
-
var hex = Number(component).toString(16);
|
|
18
|
-
return hex.length === 1 ? "0".concat(hex) : hex;
|
|
19
|
-
};
|
|
20
|
-
function splitTopLevelCommas(str) {
|
|
21
|
-
var parts = [];
|
|
22
|
-
var current = "";
|
|
23
|
-
var depth = 0;
|
|
24
|
-
for (var i = 0; i < str.length; i++) {
|
|
25
|
-
var _char = str[i];
|
|
26
|
-
if (_char === "(") {
|
|
27
|
-
depth++;
|
|
28
|
-
current += _char;
|
|
29
|
-
} else if (_char === ")") {
|
|
30
|
-
depth--;
|
|
31
|
-
current += _char;
|
|
32
|
-
} else if (_char === "," && depth === 0) {
|
|
33
|
-
parts.push(current.trim());
|
|
34
|
-
current = "";
|
|
35
|
-
} else {
|
|
36
|
-
current += _char;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (current) {
|
|
40
|
-
parts.push(current.trim());
|
|
41
|
-
}
|
|
42
|
-
return parts;
|
|
43
|
-
}
|
|
44
|
-
function parseColorMixArg(arg) {
|
|
45
|
-
arg = arg.trim();
|
|
46
|
-
// Check if there is a percentage at the end
|
|
47
|
-
var percentEndMatch = arg.match(/\s+([\d.]+)%$/i);
|
|
48
|
-
if (percentEndMatch) {
|
|
49
|
-
var percentage = parseFloat(percentEndMatch[1]);
|
|
50
|
-
var colorStr = arg.substring(0, arg.length - percentEndMatch[0].length).trim();
|
|
51
|
-
return {
|
|
52
|
-
colorStr: colorStr,
|
|
53
|
-
percentage: percentage
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Check if there is a percentage at the beginning
|
|
58
|
-
var percentStartMatch = arg.match(/^([\d.]+)%\s+/i);
|
|
59
|
-
if (percentStartMatch) {
|
|
60
|
-
var _percentage = parseFloat(percentStartMatch[1]);
|
|
61
|
-
var _colorStr = arg.substring(percentStartMatch[0].length).trim();
|
|
62
|
-
return {
|
|
63
|
-
colorStr: _colorStr,
|
|
64
|
-
percentage: _percentage
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
colorStr: arg,
|
|
69
|
-
percentage: null
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function hslToRgb(h, s, l) {
|
|
73
|
-
h = h / 360;
|
|
74
|
-
s = s / 100;
|
|
75
|
-
l = l / 100;
|
|
76
|
-
var r, g, b;
|
|
77
|
-
if (s === 0) {
|
|
78
|
-
r = g = b = l; // achromatic
|
|
79
|
-
} else {
|
|
80
|
-
var hue2rgb = function hue2rgb(p, q, t) {
|
|
81
|
-
if (t < 0) t += 1;
|
|
82
|
-
if (t > 1) t -= 1;
|
|
83
|
-
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
84
|
-
if (t < 1 / 2) return q;
|
|
85
|
-
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
86
|
-
return p;
|
|
87
|
-
};
|
|
88
|
-
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
89
|
-
var p = 2 * l - q;
|
|
90
|
-
r = hue2rgb(p, q, h + 1 / 3);
|
|
91
|
-
g = hue2rgb(p, q, h);
|
|
92
|
-
b = hue2rgb(p, q, h - 1 / 3);
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
r: Math.round(r * 255),
|
|
96
|
-
g: Math.round(g * 255),
|
|
97
|
-
b: Math.round(b * 255)
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function parseColor(colorStr) {
|
|
101
|
-
if (!colorStr) return null;
|
|
102
|
-
colorStr = colorStr.trim().toLowerCase();
|
|
103
|
-
if (colorStr === "transparent") {
|
|
104
|
-
return {
|
|
105
|
-
r: 0,
|
|
106
|
-
g: 0,
|
|
107
|
-
b: 0,
|
|
108
|
-
a: 0
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Hex
|
|
113
|
-
if (colorStr.startsWith("#")) {
|
|
114
|
-
var hex = colorStr.substring(1);
|
|
115
|
-
if (hex.length === 3 || hex.length === 4) {
|
|
116
|
-
var r = parseInt(hex[0] + hex[0], 16);
|
|
117
|
-
var g = parseInt(hex[1] + hex[1], 16);
|
|
118
|
-
var b = parseInt(hex[2] + hex[2], 16);
|
|
119
|
-
var a = hex.length === 4 ? parseInt(hex[3] + hex[3], 16) / 255 : 1;
|
|
120
|
-
return {
|
|
121
|
-
r: r,
|
|
122
|
-
g: g,
|
|
123
|
-
b: b,
|
|
124
|
-
a: a
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
if (hex.length === 6 || hex.length === 8) {
|
|
128
|
-
var _r = parseInt(hex.substring(0, 2), 16);
|
|
129
|
-
var _g = parseInt(hex.substring(2, 4), 16);
|
|
130
|
-
var _b = parseInt(hex.substring(4, 6), 16);
|
|
131
|
-
var _a = hex.length === 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
|
|
132
|
-
return {
|
|
133
|
-
r: _r,
|
|
134
|
-
g: _g,
|
|
135
|
-
b: _b,
|
|
136
|
-
a: _a
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// rgb / rgba
|
|
143
|
-
var rgbMatch = colorStr.match(/rgba?\(\s*([\d.]+)(%?)\s*[\s,]\s*([\d.]+)(%?)\s*[\s,]\s*([\d.]+)(%?)(?:\s*[\s,/]\s*([\d.]+)(%?))?\s*\)/);
|
|
144
|
-
if (rgbMatch) {
|
|
145
|
-
var _r2 = parseFloat(rgbMatch[1]);
|
|
146
|
-
if (rgbMatch[2] === "%") _r2 = _r2 / 100 * 255;
|
|
147
|
-
var _g2 = parseFloat(rgbMatch[3]);
|
|
148
|
-
if (rgbMatch[4] === "%") _g2 = _g2 / 100 * 255;
|
|
149
|
-
var _b2 = parseFloat(rgbMatch[5]);
|
|
150
|
-
if (rgbMatch[6] === "%") _b2 = _b2 / 100 * 255;
|
|
151
|
-
var _a2 = 1;
|
|
152
|
-
if (rgbMatch[7] !== undefined) {
|
|
153
|
-
_a2 = parseFloat(rgbMatch[7]);
|
|
154
|
-
if (rgbMatch[8] === "%") _a2 = _a2 / 100;
|
|
155
|
-
}
|
|
156
|
-
return {
|
|
157
|
-
r: Math.round(_r2),
|
|
158
|
-
g: Math.round(_g2),
|
|
159
|
-
b: Math.round(_b2),
|
|
160
|
-
a: _a2
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// hsl / hsla
|
|
165
|
-
var hslMatch = colorStr.match(/hsla?\(\s*([\d.]+)(?:deg)?\s*[\s,]\s*([\d.]+)%\s*[\s,]\s*([\d.]+)%\s*(?:\s*[\s,/]\s*([\d.]+)(%?))?\s*\)/);
|
|
166
|
-
if (hslMatch) {
|
|
167
|
-
var h = parseFloat(hslMatch[1]);
|
|
168
|
-
var s = parseFloat(hslMatch[2]);
|
|
169
|
-
var l = parseFloat(hslMatch[3]);
|
|
170
|
-
var _a3 = 1;
|
|
171
|
-
if (hslMatch[4] !== undefined) {
|
|
172
|
-
_a3 = parseFloat(hslMatch[4]);
|
|
173
|
-
if (hslMatch[5] === "%") _a3 = _a3 / 100;
|
|
174
|
-
}
|
|
175
|
-
var rgb = hslToRgb(h, s, l);
|
|
176
|
-
return _objectSpread(_objectSpread({}, rgb), {}, {
|
|
177
|
-
a: _a3
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// oklch(L C H [/ A])
|
|
182
|
-
var oklchMatch = colorStr.match(/oklch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(?:deg)?(?:\s*\/\s*([\d.]+)(%?))?\s*\)/);
|
|
183
|
-
if (oklchMatch) {
|
|
184
|
-
var L = parseFloat(oklchMatch[1]);
|
|
185
|
-
if (oklchMatch[2] === "%" || L > 1) L = L / 100;
|
|
186
|
-
var C = parseFloat(oklchMatch[3]);
|
|
187
|
-
var H = parseFloat(oklchMatch[4]);
|
|
188
|
-
var _a4 = 1;
|
|
189
|
-
if (oklchMatch[5] !== undefined) {
|
|
190
|
-
_a4 = parseFloat(oklchMatch[5]);
|
|
191
|
-
if (oklchMatch[6] === "%") _a4 = _a4 / 100;
|
|
192
|
-
}
|
|
193
|
-
var hRad = H * Math.PI / 180;
|
|
194
|
-
var okA = C * Math.cos(hRad);
|
|
195
|
-
var okB = C * Math.sin(hRad);
|
|
196
|
-
var l_ = L + 0.3963377774 * okA + 0.2158037573 * okB;
|
|
197
|
-
var m_ = L - 0.1055613458 * okA - 0.0638541728 * okB;
|
|
198
|
-
var s_ = L - 0.0894841775 * okA - 1.291485548 * okB;
|
|
199
|
-
var _l = l_ * l_ * l_;
|
|
200
|
-
var m = m_ * m_ * m_;
|
|
201
|
-
var _s = s_ * s_ * s_;
|
|
202
|
-
var _r3 = +4.0767439362 * _l - 3.3077115913 * m + 0.2309699292 * _s;
|
|
203
|
-
var _g3 = -1.2684380046 * _l + 2.6097574011 * m - 0.3413193965 * _s;
|
|
204
|
-
var bl = -0.0041960863 * _l - 0.7034186147 * m + 1.707614701 * _s;
|
|
205
|
-
var gamma = function gamma(c) {
|
|
206
|
-
return c <= 0.0031308 ? 12.92 * c : 1.055 * Math.pow(Math.max(0, c), 1 / 2.4) - 0.055;
|
|
207
|
-
};
|
|
208
|
-
return {
|
|
209
|
-
r: Math.max(0, Math.min(255, Math.round(gamma(_r3) * 255))),
|
|
210
|
-
g: Math.max(0, Math.min(255, Math.round(gamma(_g3) * 255))),
|
|
211
|
-
b: Math.max(0, Math.min(255, Math.round(gamma(bl) * 255))),
|
|
212
|
-
a: _a4
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// lab(L a b [/ A])
|
|
217
|
-
var labMatch = colorStr.match(/lab\(\s*([\d.]+)(%?)\s+([+-]?[\d.]+)\s+([+-]?[\d.]+)(?:\s*\/\s*([\d.]+)(%?))?\s*\)/);
|
|
218
|
-
if (labMatch) {
|
|
219
|
-
var _L = parseFloat(labMatch[1]);
|
|
220
|
-
var labA = parseFloat(labMatch[3]);
|
|
221
|
-
var labB = parseFloat(labMatch[4]);
|
|
222
|
-
var _a5 = 1;
|
|
223
|
-
if (labMatch[5] !== undefined) {
|
|
224
|
-
_a5 = parseFloat(labMatch[5]);
|
|
225
|
-
if (labMatch[6] === "%") _a5 = _a5 / 100;
|
|
226
|
-
}
|
|
227
|
-
var y = (_L + 16) / 116;
|
|
228
|
-
var x = labA / 500 + y;
|
|
229
|
-
var z = y - labB / 200;
|
|
230
|
-
var fInv = function fInv(t) {
|
|
231
|
-
return t > 6 / 29 ? t * t * t : 3 * (6 / 29) * (6 / 29) * (t - 4 / 29);
|
|
232
|
-
};
|
|
233
|
-
x = 0.95047 * fInv(x);
|
|
234
|
-
y = 1.0 * fInv(y);
|
|
235
|
-
z = 1.08883 * fInv(z);
|
|
236
|
-
var _r4 = 3.2406 * x - 1.5372 * y - 0.4986 * z;
|
|
237
|
-
var _g4 = -0.9689 * x + 1.8758 * y + 0.0415 * z;
|
|
238
|
-
var _bl = 0.0557 * x - 0.204 * y + 1.057 * z;
|
|
239
|
-
var _gamma = function _gamma(c) {
|
|
240
|
-
return c <= 0.0031308 ? 12.92 * c : 1.055 * Math.pow(Math.max(0, c), 1 / 2.4) - 0.055;
|
|
241
|
-
};
|
|
242
|
-
return {
|
|
243
|
-
r: Math.max(0, Math.min(255, Math.round(_gamma(_r4) * 255))),
|
|
244
|
-
g: Math.max(0, Math.min(255, Math.round(_gamma(_g4) * 255))),
|
|
245
|
-
b: Math.max(0, Math.min(255, Math.round(_gamma(_bl) * 255))),
|
|
246
|
-
a: _a5
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Basic named colors fallback
|
|
251
|
-
var basicColors = {
|
|
252
|
-
white: {
|
|
253
|
-
r: 255,
|
|
254
|
-
g: 255,
|
|
255
|
-
b: 255,
|
|
256
|
-
a: 1
|
|
257
|
-
},
|
|
258
|
-
black: {
|
|
259
|
-
r: 0,
|
|
260
|
-
g: 0,
|
|
261
|
-
b: 0,
|
|
262
|
-
a: 1
|
|
263
|
-
},
|
|
264
|
-
red: {
|
|
265
|
-
r: 255,
|
|
266
|
-
g: 0,
|
|
267
|
-
b: 0,
|
|
268
|
-
a: 1
|
|
269
|
-
},
|
|
270
|
-
green: {
|
|
271
|
-
r: 0,
|
|
272
|
-
g: 128,
|
|
273
|
-
b: 0,
|
|
274
|
-
a: 1
|
|
275
|
-
},
|
|
276
|
-
blue: {
|
|
277
|
-
r: 0,
|
|
278
|
-
g: 0,
|
|
279
|
-
b: 255,
|
|
280
|
-
a: 1
|
|
281
|
-
},
|
|
282
|
-
yellow: {
|
|
283
|
-
r: 255,
|
|
284
|
-
g: 255,
|
|
285
|
-
b: 0,
|
|
286
|
-
a: 1
|
|
287
|
-
},
|
|
288
|
-
magenta: {
|
|
289
|
-
r: 255,
|
|
290
|
-
g: 0,
|
|
291
|
-
b: 255,
|
|
292
|
-
a: 1
|
|
293
|
-
},
|
|
294
|
-
cyan: {
|
|
295
|
-
r: 0,
|
|
296
|
-
g: 255,
|
|
297
|
-
b: 255,
|
|
298
|
-
a: 1
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
if (basicColors[colorStr]) {
|
|
302
|
-
return basicColors[colorStr];
|
|
303
|
-
}
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
function resolveColorMix(value) {
|
|
307
|
-
if (typeof value !== "string") return value;
|
|
308
|
-
var index;
|
|
309
|
-
while ((index = value.toLowerCase().indexOf("color-mix(")) !== -1) {
|
|
310
|
-
// Find matching closing parenthesis
|
|
311
|
-
var depth = 1;
|
|
312
|
-
var j = index + "color-mix(".length;
|
|
313
|
-
while (j < value.length && depth > 0) {
|
|
314
|
-
if (value[j] === "(") {
|
|
315
|
-
depth++;
|
|
316
|
-
} else if (value[j] === ")") {
|
|
317
|
-
depth--;
|
|
318
|
-
}
|
|
319
|
-
j++;
|
|
320
|
-
}
|
|
321
|
-
if (depth > 0) {
|
|
322
|
-
// Unmatched parenthesis, break to avoid infinite loop
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
var innerContent = value.substring(index + "color-mix(".length, j - 1);
|
|
326
|
-
|
|
327
|
-
// Parse innerContent: "in <color-space>, <args>"
|
|
328
|
-
var commaIndex = innerContent.indexOf(",");
|
|
329
|
-
if (commaIndex === -1) {
|
|
330
|
-
// Invalid syntax, skip this one by replacing "color-mix(" with a placeholder temporarily
|
|
331
|
-
value = value.substring(0, index) + "COLOR_MIX_TEMP(" + value.substring(index + "color-mix(".length);
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
var argsPart = innerContent.substring(commaIndex + 1).trim();
|
|
335
|
-
|
|
336
|
-
// Check if argsPart contains another color-mix. If so, resolve the inner one first.
|
|
337
|
-
if (argsPart.toLowerCase().includes("color-mix(")) {
|
|
338
|
-
var resolvedArgsPart = resolveColorMix(argsPart);
|
|
339
|
-
value = value.substring(0, index + "color-mix(".length + commaIndex + 1) + " " + resolvedArgsPart + value.substring(j - 1);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// Now we can resolve this color-mix
|
|
344
|
-
var args = splitTopLevelCommas(argsPart);
|
|
345
|
-
if (args.length !== 2) {
|
|
346
|
-
// Invalid syntax
|
|
347
|
-
value = value.substring(0, index) + "COLOR_MIX_TEMP(" + value.substring(index + "color-mix(".length);
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
var arg1 = parseColorMixArg(args[0]);
|
|
351
|
-
var arg2 = parseColorMixArg(args[1]);
|
|
352
|
-
var c1 = parseColor(arg1.colorStr);
|
|
353
|
-
var c2 = parseColor(arg2.colorStr);
|
|
354
|
-
if (!c1 || !c2) {
|
|
355
|
-
// Parsing failed, skip
|
|
356
|
-
value = value.substring(0, index) + "COLOR_MIX_TEMP(" + value.substring(index + "color-mix(".length);
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
var p1 = arg1.percentage;
|
|
360
|
-
var p2 = arg2.percentage;
|
|
361
|
-
var w1 = void 0,
|
|
362
|
-
w2 = void 0;
|
|
363
|
-
if (p1 !== null && p2 !== null) {
|
|
364
|
-
var sum = p1 + p2;
|
|
365
|
-
if (sum > 100) {
|
|
366
|
-
w1 = p1 / sum * 100;
|
|
367
|
-
w2 = p2 / sum * 100;
|
|
368
|
-
} else {
|
|
369
|
-
w1 = p1;
|
|
370
|
-
w2 = p2;
|
|
371
|
-
}
|
|
372
|
-
} else if (p1 !== null) {
|
|
373
|
-
w1 = p1;
|
|
374
|
-
w2 = 100 - p1;
|
|
375
|
-
} else if (p2 !== null) {
|
|
376
|
-
w2 = p2;
|
|
377
|
-
w1 = 100 - p2;
|
|
378
|
-
} else {
|
|
379
|
-
w1 = 50;
|
|
380
|
-
w2 = 50;
|
|
381
|
-
}
|
|
382
|
-
var a1 = c1.a;
|
|
383
|
-
var a2 = c2.a;
|
|
384
|
-
var totalWeight = w1 + w2;
|
|
385
|
-
var resolvedColor = void 0;
|
|
386
|
-
if (totalWeight === 0) {
|
|
387
|
-
resolvedColor = "transparent";
|
|
388
|
-
} else {
|
|
389
|
-
var f1 = w1 / totalWeight;
|
|
390
|
-
var f2 = w2 / totalWeight;
|
|
391
|
-
var mixedA = a1 * f1 + a2 * f2;
|
|
392
|
-
var mixedR = void 0,
|
|
393
|
-
mixedG = void 0,
|
|
394
|
-
mixedB = void 0;
|
|
395
|
-
if (mixedA === 0) {
|
|
396
|
-
mixedR = 0;
|
|
397
|
-
mixedG = 0;
|
|
398
|
-
mixedB = 0;
|
|
399
|
-
} else {
|
|
400
|
-
mixedR = Math.round((c1.r * a1 * f1 + c2.r * a2 * f2) / mixedA);
|
|
401
|
-
mixedG = Math.round((c1.g * a1 * f1 + c2.g * a2 * f2) / mixedA);
|
|
402
|
-
mixedB = Math.round((c1.b * a1 * f1 + c2.b * a2 * f2) / mixedA);
|
|
403
|
-
}
|
|
404
|
-
var finalA = totalWeight < 100 ? mixedA * (totalWeight / 100) : mixedA;
|
|
405
|
-
var roundedA = Math.round(finalA * 10000) / 10000;
|
|
406
|
-
resolvedColor = "rgba(".concat(mixedR, ", ").concat(mixedG, ", ").concat(mixedB, ", ").concat(roundedA, ")");
|
|
407
|
-
}
|
|
408
|
-
value = value.substring(0, index) + resolvedColor + value.substring(j);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Restore placeholders
|
|
412
|
-
value = value.replace(/COLOR_MIX_TEMP\(/gi, "color-mix(");
|
|
413
|
-
return value;
|
|
414
|
-
}
|
|
415
|
-
function safeEvalMath(expr) {
|
|
416
|
-
if (!expr || typeof expr !== "string") return 0;
|
|
417
|
-
|
|
418
|
-
// Clean rem and px units if present
|
|
419
|
-
var sanitized = expr.replace(/([\d.]+)rem/g, function (_, n) {
|
|
420
|
-
return "".concat(parseFloat(n) * 16);
|
|
421
|
-
}).replace(/([\d.]+)px/g, "$1");
|
|
422
|
-
var pos = 0;
|
|
423
|
-
var len = sanitized.length;
|
|
424
|
-
function peek() {
|
|
425
|
-
while (pos < len && sanitized.charCodeAt(pos) <= 32) pos++;
|
|
426
|
-
return pos < len ? sanitized[pos] : "";
|
|
427
|
-
}
|
|
428
|
-
function get() {
|
|
429
|
-
var ch = peek();
|
|
430
|
-
pos++;
|
|
431
|
-
return ch;
|
|
432
|
-
}
|
|
433
|
-
function parseFactor() {
|
|
434
|
-
var ch = peek();
|
|
435
|
-
if (ch === "+") {
|
|
436
|
-
get();
|
|
437
|
-
return parseFactor();
|
|
438
|
-
}
|
|
439
|
-
if (ch === "-") {
|
|
440
|
-
get();
|
|
441
|
-
return -parseFactor();
|
|
442
|
-
}
|
|
443
|
-
if (ch === "(") {
|
|
444
|
-
get();
|
|
445
|
-
var val = parseExpression();
|
|
446
|
-
if (peek() === ")") get();
|
|
447
|
-
return val;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// Parse number
|
|
451
|
-
var start = pos;
|
|
452
|
-
var hasDot = false;
|
|
453
|
-
while (pos < len) {
|
|
454
|
-
var c = sanitized[pos];
|
|
455
|
-
if (c >= "0" && c <= "9") {
|
|
456
|
-
pos++;
|
|
457
|
-
} else if (c === "." && !hasDot) {
|
|
458
|
-
hasDot = true;
|
|
459
|
-
pos++;
|
|
460
|
-
} else {
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
if (start === pos) return 0;
|
|
465
|
-
var numStr = sanitized.slice(start, pos);
|
|
466
|
-
var num = parseFloat(numStr);
|
|
467
|
-
return isNaN(num) ? 0 : num;
|
|
468
|
-
}
|
|
469
|
-
function parseTerm() {
|
|
470
|
-
var result = parseFactor();
|
|
471
|
-
while (true) {
|
|
472
|
-
var op = peek();
|
|
473
|
-
if (op === "*" || op === "/") {
|
|
474
|
-
get();
|
|
475
|
-
var factor = parseFactor();
|
|
476
|
-
result = op === "*" ? result * factor : factor !== 0 ? result / factor : 0;
|
|
477
|
-
} else {
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
return result;
|
|
482
|
-
}
|
|
483
|
-
function parseExpression() {
|
|
484
|
-
var result = parseTerm();
|
|
485
|
-
while (true) {
|
|
486
|
-
var op = peek();
|
|
487
|
-
if (op === "+" || op === "-") {
|
|
488
|
-
get();
|
|
489
|
-
var term = parseTerm();
|
|
490
|
-
result = op === "+" ? result + term : result - term;
|
|
491
|
-
} else {
|
|
492
|
-
break;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
return result;
|
|
496
|
-
}
|
|
497
|
-
try {
|
|
498
|
-
var val = parseExpression();
|
|
499
|
-
return isNaN(val) ? 0 : val;
|
|
500
|
-
} catch (_unused) {
|
|
501
|
-
return 0;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
function CssCalc() {
|
|
505
|
-
this.calc = function (value) {
|
|
506
|
-
if (value === undefined || typeof value !== "string") return value;
|
|
507
|
-
return value.replace(calcRe, function (_, calc) {
|
|
508
|
-
return safeEvalMath(calc);
|
|
509
|
-
});
|
|
510
|
-
};
|
|
511
|
-
this.calcColor = function (value) {
|
|
512
|
-
if (value === undefined || typeof value !== "string") return value;
|
|
513
|
-
value = resolveColorMix(value);
|
|
514
|
-
|
|
515
|
-
// If the entire value is a single color (hex, rgb, hsl, oklch, lab), normalize to hex/rgba
|
|
516
|
-
var parsed = parseColor(value);
|
|
517
|
-
if (parsed) {
|
|
518
|
-
if (parsed.a === 1) {
|
|
519
|
-
return "#".concat(itohex(parsed.r)).concat(itohex(parsed.g)).concat(itohex(parsed.b));
|
|
520
|
-
}
|
|
521
|
-
var a = Math.round(parsed.a * 255);
|
|
522
|
-
return "#".concat(itohex(parsed.r)).concat(itohex(parsed.g)).concat(itohex(parsed.b)).concat(itohex(a));
|
|
523
|
-
}
|
|
524
|
-
value = value.replace(colorRe1, function (_, r, g, b, a) {
|
|
525
|
-
a = parseFloat(a);
|
|
526
|
-
if (isNaN(a) || a >= 1) return "#".concat(itohex(r)).concat(itohex(g)).concat(itohex(b));
|
|
527
|
-
a = Math.round(a * 255);
|
|
528
|
-
return "#".concat(itohex(r)).concat(itohex(g)).concat(itohex(b)).concat(itohex(a));
|
|
529
|
-
});
|
|
530
|
-
value = value.replace(colorRe2, function (_, r, g, b, a) {
|
|
531
|
-
a = parseFloat(a);
|
|
532
|
-
if (isNaN(a) || a >= 1) return "#".concat(itohex(r)).concat(itohex(g)).concat(itohex(b));
|
|
533
|
-
a = Math.round(a * 255);
|
|
534
|
-
return "#".concat(itohex(r)).concat(itohex(g)).concat(itohex(b)).concat(itohex(a));
|
|
535
|
-
});
|
|
536
|
-
return value;
|
|
537
|
-
};
|
|
538
|
-
return this;
|
|
539
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = CssMedia;
|
|
7
|
-
var _helper = require("../utils/helper");
|
|
8
|
-
var _cssTransform = _interopRequireDefault(require("./css-transform"));
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
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
|
-
var SUPPORTED_MEDIA_TYPE = ["min-width", "min-height", "max-width", "max-height", "prefers-color-scheme"];
|
|
17
|
-
function CssMedia() {
|
|
18
|
-
var transform = new _cssTransform["default"]();
|
|
19
|
-
this.match = function (media) {
|
|
20
|
-
var _media$match;
|
|
21
|
-
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
22
|
-
width = _ref.width,
|
|
23
|
-
height = _ref.height,
|
|
24
|
-
colorScheme = _ref.colorScheme;
|
|
25
|
-
var isMedia = media.startsWith("@media");
|
|
26
|
-
if (!isMedia) return [false];
|
|
27
|
-
var isValidMedia = true;
|
|
28
|
-
var widthRange = [Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY];
|
|
29
|
-
var heightRange = [Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY];
|
|
30
|
-
var mediaGroupsRe = /\([^)]*\)/g;
|
|
31
|
-
var mediaGroups = (_media$match = media.match(mediaGroupsRe)) === null || _media$match === void 0 ? void 0 : _media$match.map(function (rawGroup) {
|
|
32
|
-
var mediaGroupRe = /\(\s*([^:)\s]+)\s*:\s*([^:)\s]+)\s*\)/g;
|
|
33
|
-
var _ref2 = mediaGroupRe.exec(rawGroup) || [],
|
|
34
|
-
_ref3 = _slicedToArray(_ref2, 3),
|
|
35
|
-
mediaType = _ref3[1],
|
|
36
|
-
mediaValue = _ref3[2];
|
|
37
|
-
if (!SUPPORTED_MEDIA_TYPE.includes(mediaType)) {
|
|
38
|
-
isValidMedia = false;
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
mediaType = (0, _helper.camelize)(mediaType);
|
|
42
|
-
mediaValue = transform.transformUnsupportedUnit(mediaValue);
|
|
43
|
-
mediaValue = transform.transformViewportUnit(mediaValue, {
|
|
44
|
-
width: width,
|
|
45
|
-
height: height
|
|
46
|
-
});
|
|
47
|
-
mediaValue = transform.removeUnit(mediaValue);
|
|
48
|
-
if (mediaType === "minWidth") {
|
|
49
|
-
widthRange[0] = mediaValue;
|
|
50
|
-
} else if (mediaType === "minHeight") {
|
|
51
|
-
heightRange[0] = mediaValue;
|
|
52
|
-
} else if (mediaType === "maxWidth") {
|
|
53
|
-
widthRange[1] = mediaValue;
|
|
54
|
-
} else if (mediaType === "maxHeight") {
|
|
55
|
-
heightRange[1] = mediaValue;
|
|
56
|
-
}
|
|
57
|
-
return [mediaType, mediaValue];
|
|
58
|
-
});
|
|
59
|
-
if (!Array.isArray(mediaGroups) || mediaGroups.length === 0) {
|
|
60
|
-
isValidMedia = false;
|
|
61
|
-
}
|
|
62
|
-
if (!isValidMedia) return [true, false];
|
|
63
|
-
if (mediaGroups[0][0] === "prefersColorScheme" && mediaGroups[0][1] === "dark") {
|
|
64
|
-
if (colorScheme === "dark") {
|
|
65
|
-
return [true, true];
|
|
66
|
-
} else {
|
|
67
|
-
return [true, false];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
var isValidRange = widthRange[0] <= widthRange[1] && heightRange[0] <= heightRange[1];
|
|
71
|
-
if (!isValidRange) return [true, false];
|
|
72
|
-
var isMatchedMedia = widthRange[0] <= width && width <= widthRange[1] && heightRange[0] <= height && height <= heightRange[1];
|
|
73
|
-
if (!isMatchedMedia) return [true, false];
|
|
74
|
-
return [true, true];
|
|
75
|
-
};
|
|
76
|
-
return this;
|
|
77
|
-
}
|