@zag-js/color-utils 1.17.3 → 1.18.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/dist/index.js +6 -3
- package/dist/index.mjs +6 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -242,6 +242,9 @@ var Color = class {
|
|
|
242
242
|
return isSame && this.getChannelValue("alpha") === color.getChannelValue("alpha");
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
|
+
var HEX_COLOR_REGEX = /^#[\da-f]+$/i;
|
|
246
|
+
var RGB_COLOR_REGEX = /^rgba?\((.*)\)$/;
|
|
247
|
+
var HEX_STARTING_REGEX = /[^#]/gi;
|
|
245
248
|
var _RGBColor = class _RGBColor extends Color {
|
|
246
249
|
constructor(red, green, blue, alpha) {
|
|
247
250
|
super();
|
|
@@ -252,14 +255,14 @@ var _RGBColor = class _RGBColor extends Color {
|
|
|
252
255
|
}
|
|
253
256
|
static parse(value) {
|
|
254
257
|
let colors = [];
|
|
255
|
-
if (
|
|
256
|
-
const values = (value.length < 6 ? value.replace(
|
|
258
|
+
if (HEX_COLOR_REGEX.test(value) && [4, 5, 7, 9].includes(value.length)) {
|
|
259
|
+
const values = (value.length < 6 ? value.replace(HEX_STARTING_REGEX, "$&$&") : value).slice(1).split("");
|
|
257
260
|
while (values.length > 0) {
|
|
258
261
|
colors.push(parseInt(values.splice(0, 2).join(""), 16));
|
|
259
262
|
}
|
|
260
263
|
colors[3] = colors[3] !== void 0 ? colors[3] / 255 : void 0;
|
|
261
264
|
}
|
|
262
|
-
const match = value.match(
|
|
265
|
+
const match = value.match(RGB_COLOR_REGEX);
|
|
263
266
|
if (match?.[1]) {
|
|
264
267
|
colors = match[1].split(",").map((value2) => Number(value2.trim())).map((num, i) => utils.clampValue(num, 0, i < 3 ? 255 : 1));
|
|
265
268
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -240,6 +240,9 @@ var Color = class {
|
|
|
240
240
|
return isSame && this.getChannelValue("alpha") === color.getChannelValue("alpha");
|
|
241
241
|
}
|
|
242
242
|
};
|
|
243
|
+
var HEX_COLOR_REGEX = /^#[\da-f]+$/i;
|
|
244
|
+
var RGB_COLOR_REGEX = /^rgba?\((.*)\)$/;
|
|
245
|
+
var HEX_STARTING_REGEX = /[^#]/gi;
|
|
243
246
|
var _RGBColor = class _RGBColor extends Color {
|
|
244
247
|
constructor(red, green, blue, alpha) {
|
|
245
248
|
super();
|
|
@@ -250,14 +253,14 @@ var _RGBColor = class _RGBColor extends Color {
|
|
|
250
253
|
}
|
|
251
254
|
static parse(value) {
|
|
252
255
|
let colors = [];
|
|
253
|
-
if (
|
|
254
|
-
const values = (value.length < 6 ? value.replace(
|
|
256
|
+
if (HEX_COLOR_REGEX.test(value) && [4, 5, 7, 9].includes(value.length)) {
|
|
257
|
+
const values = (value.length < 6 ? value.replace(HEX_STARTING_REGEX, "$&$&") : value).slice(1).split("");
|
|
255
258
|
while (values.length > 0) {
|
|
256
259
|
colors.push(parseInt(values.splice(0, 2).join(""), 16));
|
|
257
260
|
}
|
|
258
261
|
colors[3] = colors[3] !== void 0 ? colors[3] / 255 : void 0;
|
|
259
262
|
}
|
|
260
|
-
const match = value.match(
|
|
263
|
+
const match = value.match(RGB_COLOR_REGEX);
|
|
261
264
|
if (match?.[1]) {
|
|
262
265
|
colors = match[1].split(",").map((value2) => Number(value2.trim())).map((num, i) => clampValue(num, 0, i < 3 ? 255 : 1));
|
|
263
266
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/color-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "Color utilities for zag.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"clean-package": "../../../clean-package.config.json",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@zag-js/utils": "1.
|
|
27
|
+
"@zag-js/utils": "1.18.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"clean-package": "2.2.0"
|