@tamagui/normalize-css-color 2.7.7 → 3.0.0-beta.1097.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/dist/cjs/index.cjs +108 -43
- package/dist/cjs/index.native.cjs +44 -0
- package/dist/cjs/index.native.js +27 -40
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/rgba.cjs +35 -0
- package/dist/cjs/rgba.native.cjs +37 -0
- package/dist/cjs/rgba.native.js +39 -0
- package/dist/cjs/rgba.native.js.map +1 -0
- package/dist/esm/index.js +94 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +94 -15
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +7 -13
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/rgba.mjs +15 -0
- package/dist/esm/rgba.mjs.map +1 -0
- package/dist/esm/rgba.native.js +15 -0
- package/dist/esm/rgba.native.js.map +1 -0
- package/package.json +3 -2
- package/src/index.native.ts +14 -0
- package/src/index.ts +190 -16
- package/src/rgba.ts +12 -0
- package/types/index.d.ts +9 -7
- package/types/index.d.ts.map +1 -1
- package/types/index.native.d.ts +5 -0
- package/types/index.native.d.ts.map +1 -0
- package/types/rgba.d.ts +7 -0
- package/types/rgba.d.ts.map +1 -0
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,56 +1,121 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
12
10
|
};
|
|
13
11
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
21
19
|
};
|
|
22
|
-
var
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
21
|
var index_exports = {};
|
|
35
22
|
__export(index_exports, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
default: () => index_default,
|
|
24
|
+
isKnownColorName: () => isKnownColorName,
|
|
25
|
+
normalizeCSSColor: () => normalizeCSSColor,
|
|
26
|
+
rgba: () => import_rgba.rgba
|
|
39
27
|
});
|
|
40
28
|
module.exports = __toCommonJS(index_exports);
|
|
41
|
-
var
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
var import_rgba = require("./rgba.cjs");
|
|
30
|
+
const colorNames = "transparent,aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,burntsienna,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkgrey,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkslategrey,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dimgrey,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,grey,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightslategrey,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,rebeccapurple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,slategrey,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow,yellowgreen";
|
|
31
|
+
const colorValues = "00000000f0f8fffffaebd7ff00ffffff7fffd4fff0fffffff5f5dcffffe4c4ff000000ffffebcdff0000ffff8a2be2ffa52a2affdeb887ffea7e5dff5f9ea0ff7fff00ffd2691effff7f50ff6495edfffff8dcffdc143cff00ffffff00008bff008b8bffb8860bffa9a9a9ff006400ffa9a9a9ffbdb76bff8b008bff556b2fffff8c00ff9932ccff8b0000ffe9967aff8fbc8fff483d8bff2f4f4fff2f4f4fff00ced1ff9400d3ffff1493ff00bfffff696969ff696969ff1e90ffffb22222fffffaf0ff228b22ffff00ffffdcdcdcfff8f8ffffffd700ffdaa520ff808080ff008000ffadff2fff808080fff0fff0ffff69b4ffcd5c5cff4b0082fffffff0fff0e68cffe6e6fafffff0f5ff7cfc00fffffacdffadd8e6fff08080ffe0fffffffafad2ffd3d3d3ff90ee90ffd3d3d3ffffb6c1ffffa07aff20b2aaff87cefaff778899ff778899ffb0c4deffffffe0ff00ff00ff32cd32fffaf0e6ffff00ffff800000ff66cdaaff0000cdffba55d3ff9370dbff3cb371ff7b68eeff00fa9aff48d1ccffc71585ff191970fff5fffaffffe4e1ffffe4b5ffffdeadff000080fffdf5e6ff808000ff6b8e23ffffa500ffff4500ffda70d6ffeee8aaff98fb98ffafeeeeffdb7093ffffefd5ffffdab9ffcd853fffffc0cbffdda0ddffb0e0e6ff800080ff663399ffff0000ffbc8f8fff4169e1ff8b4513fffa8072fff4a460ff2e8b57fffff5eeffa0522dffc0c0c0ff87ceebff6a5acdff708090ff708090fffffafaff00ff7fff4682b4ffd2b48cff008080ffd8bfd8ffff6347ff40e0d0ffee82eefff5deb3fffffffffff5f5f5ffffff00ff9acd32ff";
|
|
32
|
+
const number = "[-+]?\\d*\\.?\\d+";
|
|
33
|
+
const percentage = `${number}%`;
|
|
34
|
+
const call = (...args) => `\\(\\s*(${args.join(")\\s*,?\\s*(")})\\s*\\)`;
|
|
35
|
+
const callWithSlashSeparator = (...args) => `\\(\\s*(${args.slice(0, -1).join(")\\s*,?\\s*(")})\\s*\\/\\s*(${args[args.length - 1]})\\s*\\)`;
|
|
36
|
+
const commaSeparatedCall = (...args) => `\\(\\s*(${args.join(")\\s*,\\s*(")})\\s*\\)`;
|
|
37
|
+
const matchers = {
|
|
38
|
+
rgb: new RegExp(`rgb${call(number, number, number)}`),
|
|
39
|
+
rgba: new RegExp(`rgba(${commaSeparatedCall(number, number, number, number)}|${callWithSlashSeparator(number, number, number, number)})`),
|
|
40
|
+
hsl: new RegExp(`hsl${call(number, percentage, percentage)}`),
|
|
41
|
+
hsla: new RegExp(`hsla(${commaSeparatedCall(number, percentage, percentage, number)}|${callWithSlashSeparator(number, percentage, percentage, number)})`),
|
|
42
|
+
hwb: new RegExp(`hwb${call(number, percentage, percentage)}`),
|
|
43
|
+
hex3: /^#([\da-f])([\da-f])([\da-f])$/i,
|
|
44
|
+
hex4: /^#([\da-f])([\da-f])([\da-f])([\da-f])$/i,
|
|
45
|
+
hex6: /^#([\da-f]{6})$/i,
|
|
46
|
+
hex8: /^#([\da-f]{8})$/i
|
|
47
|
+
};
|
|
48
|
+
let colorNameMap;
|
|
49
|
+
const parse255 = (value) => Math.max(0, Math.min(255, Number.parseInt(value, 10)));
|
|
50
|
+
const parse360 = (value) => (Number.parseFloat(value) % 360 + 360) % 360 / 360;
|
|
51
|
+
const parse1 = (value) => Math.round(Math.max(0, Math.min(1, Number.parseFloat(value))) * 255);
|
|
52
|
+
const parsePercentage = (value) => Math.max(0, Math.min(100, Number.parseFloat(value))) / 100;
|
|
53
|
+
function hue2rgb(p, q, value) {
|
|
54
|
+
let t = value;
|
|
55
|
+
if (t < 0) t += 1;
|
|
56
|
+
if (t > 1) t -= 1;
|
|
57
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
58
|
+
if (t < 1 / 2) return q;
|
|
59
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
60
|
+
return p;
|
|
61
|
+
}
|
|
62
|
+
function hslToRgb(h, s, l) {
|
|
63
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
64
|
+
const p = 2 * l - q;
|
|
65
|
+
return Math.round(hue2rgb(p, q, h + 1 / 3) * 255) << 24 | Math.round(hue2rgb(p, q, h) * 255) << 16 | Math.round(hue2rgb(p, q, h - 1 / 3) * 255) << 8;
|
|
66
|
+
}
|
|
67
|
+
function hwbToRgb(h, w, b) {
|
|
68
|
+
if (w + b >= 1) {
|
|
69
|
+
const gray = Math.round(w * 255 / (w + b));
|
|
70
|
+
return gray << 24 | gray << 16 | gray << 8;
|
|
71
|
+
}
|
|
72
|
+
return Math.round((hue2rgb(0, 1, h + 1 / 3) * (1 - w - b) + w) * 255) << 24 | Math.round((hue2rgb(0, 1, h) * (1 - w - b) + w) * 255) << 16 | Math.round((hue2rgb(0, 1, h - 1 / 3) * (1 - w - b) + w) * 255) << 8;
|
|
73
|
+
}
|
|
74
|
+
function normalizeCSSColor(color) {
|
|
75
|
+
if (typeof color !== "string") return null;
|
|
76
|
+
let match = matchers.hex6.exec(color);
|
|
77
|
+
if (match) return Number.parseInt(`${match[1]}ff`, 16) >>> 0;
|
|
78
|
+
match = matchers.rgb.exec(color);
|
|
79
|
+
if (match) {
|
|
80
|
+
return (parse255(match[1]) << 24 | parse255(match[2]) << 16 | parse255(match[3]) << 8 | 255) >>> 0;
|
|
81
|
+
}
|
|
82
|
+
match = matchers.rgba.exec(color);
|
|
83
|
+
if (match) {
|
|
84
|
+
const offset = match[6] === void 0 ? 2 : 6;
|
|
85
|
+
return (parse255(match[offset]) << 24 | parse255(match[offset + 1]) << 16 | parse255(match[offset + 2]) << 8 | parse1(match[offset + 3])) >>> 0;
|
|
86
|
+
}
|
|
87
|
+
match = matchers.hex3.exec(color);
|
|
88
|
+
if (match) {
|
|
89
|
+
return Number.parseInt(`${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}ff`, 16) >>> 0;
|
|
90
|
+
}
|
|
91
|
+
match = matchers.hex8.exec(color);
|
|
92
|
+
if (match) return Number.parseInt(match[1], 16) >>> 0;
|
|
93
|
+
match = matchers.hex4.exec(color);
|
|
94
|
+
if (match) {
|
|
95
|
+
return Number.parseInt(`${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}${match[4]}${match[4]}`, 16) >>> 0;
|
|
96
|
+
}
|
|
97
|
+
match = matchers.hsl.exec(color);
|
|
98
|
+
if (match) {
|
|
99
|
+
return (hslToRgb(parse360(match[1]), parsePercentage(match[2]), parsePercentage(match[3])) | 255) >>> 0;
|
|
100
|
+
}
|
|
101
|
+
match = matchers.hsla.exec(color);
|
|
102
|
+
if (match) {
|
|
103
|
+
const offset = match[6] === void 0 ? 2 : 6;
|
|
104
|
+
return (hslToRgb(parse360(match[offset]), parsePercentage(match[offset + 1]), parsePercentage(match[offset + 2])) | parse1(match[offset + 3])) >>> 0;
|
|
105
|
+
}
|
|
106
|
+
match = matchers.hwb.exec(color);
|
|
107
|
+
if (match) {
|
|
108
|
+
return (hwbToRgb(parse360(match[1]), parsePercentage(match[2]), parsePercentage(match[3])) | 255) >>> 0;
|
|
109
|
+
}
|
|
110
|
+
const namedColor = getColorNameMap().get(color);
|
|
111
|
+
if (namedColor !== void 0) return namedColor;
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
function getColorNameMap() {
|
|
115
|
+
colorNameMap ||= new Map(colorNames.split(",").map((name, index) => [name, Number.parseInt(colorValues.slice(index * 8, index * 8 + 8), 16) >>> 0]));
|
|
116
|
+
return colorNameMap;
|
|
117
|
+
}
|
|
118
|
+
function isKnownColorName(color) {
|
|
119
|
+
return getColorNameMap().has(color);
|
|
55
120
|
}
|
|
56
|
-
var index_default = normalizeCSSColor;
|
|
121
|
+
var index_default = normalizeCSSColor;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var index_native_exports = {};
|
|
30
|
+
__export(index_native_exports, {
|
|
31
|
+
default: () => index_native_default,
|
|
32
|
+
isKnownColorName: () => isKnownColorName,
|
|
33
|
+
normalizeCSSColor: () => normalizeCSSColor,
|
|
34
|
+
rgba: () => import_rgba.rgba
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_native_exports);
|
|
37
|
+
var normalizeColor = __toESM(require("@react-native/normalize-color"), 1);
|
|
38
|
+
var import_rgba = require("./rgba.native.js");
|
|
39
|
+
var norm = normalizeColor.default || normalizeColor;
|
|
40
|
+
var normalizeCSSColor = norm;
|
|
41
|
+
function isKnownColorName(color) {
|
|
42
|
+
return /^[a-z]+$/i.test(color) && normalizeCSSColor(color) != null;
|
|
43
|
+
}
|
|
44
|
+
var index_native_default = normalizeCSSColor;
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -7,53 +7,40 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
14
|
};
|
|
15
15
|
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
23
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
32
27
|
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
rgba: () => rgba
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var index_native_exports = {};
|
|
30
|
+
__export(index_native_exports, {
|
|
31
|
+
default: () => index_native_default,
|
|
32
|
+
isKnownColorName: () => isKnownColorName,
|
|
33
|
+
normalizeCSSColor: () => normalizeCSSColor,
|
|
34
|
+
rgba: () => import_rgba.rgba
|
|
41
35
|
});
|
|
42
|
-
module.exports = __toCommonJS(
|
|
36
|
+
module.exports = __toCommonJS(index_native_exports);
|
|
43
37
|
var normalizeColor = __toESM(require("@react-native/normalize-color"), 1);
|
|
38
|
+
var import_rgba = require("./rgba.native.js");
|
|
44
39
|
var norm = normalizeColor.default || normalizeColor;
|
|
45
40
|
var normalizeCSSColor = norm;
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
var g = Math.round((colorInt & 16711680) >>> 16);
|
|
49
|
-
var b = Math.round((colorInt & 65280) >>> 8);
|
|
50
|
-
var a = ((colorInt & 255) >>> 0) / 255;
|
|
51
|
-
return {
|
|
52
|
-
r,
|
|
53
|
-
g,
|
|
54
|
-
b,
|
|
55
|
-
a
|
|
56
|
-
};
|
|
41
|
+
function isKnownColorName(color) {
|
|
42
|
+
return /^[a-z]+$/i.test(color) && normalizeCSSColor(color) != null;
|
|
57
43
|
}
|
|
58
|
-
var
|
|
44
|
+
var index_native_default = normalizeCSSColor;
|
|
45
|
+
|
|
59
46
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["cjs/index.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_native_exports = {};\n__export(index_native_exports, {\n default: () => index_native_default,\n isKnownColorName: () => isKnownColorName,\n normalizeCSSColor: () => normalizeCSSColor,\n rgba: () => import_rgba.rgba\n});\nmodule.exports = __toCommonJS(index_native_exports);\nvar normalizeColor = __toESM(require(\"@react-native/normalize-color\"), 1);\nvar import_rgba = require(\"./rgba\");\nvar norm = normalizeColor.default || normalizeColor;\nvar normalizeCSSColor = norm;\nfunction isKnownColorName(color) {\n return /^[a-z]+$/i.test(color) && normalizeCSSColor(color) != null;\n}\nvar index_native_default = normalizeCSSColor;\n//# sourceMappingURL=index.native.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ,WAAW;CAAE,OAAO;CAAK,YAAY;AAAK,CAAC,IAAI,QACzG,GACF;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,uBAAuB,CAAC;AAC5B,SAAS,sBAAsB;CAC7B,eAAe;CACf,wBAAwB;CACxB,yBAAyB;CACzB,YAAY,YAAY;AAC1B,CAAC;AACD,OAAO,UAAU,aAAa,oBAAoB;AAClD,IAAI,iBAAiB,QAAQ,QAAQ,+BAA+B,GAAG,CAAC;AACxE,IAAI,cAAc,QAAQ,kBAAQ;AAClC,IAAI,OAAO,eAAe,WAAW;AACrC,IAAI,oBAAoB;AACxB,SAAS,iBAAiB,OAAO;CAC/B,OAAO,YAAY,KAAK,KAAK,KAAK,kBAAkB,KAAK,KAAK;AAChE;AACA,IAAI,uBAAuB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var rgba_exports = {};
|
|
22
|
+
__export(rgba_exports, { rgba: () => rgba });
|
|
23
|
+
module.exports = __toCommonJS(rgba_exports);
|
|
24
|
+
function rgba(colorInt) {
|
|
25
|
+
const r = Math.round((colorInt & 4278190080) >>> 24);
|
|
26
|
+
const g = Math.round((colorInt & 16711680) >>> 16);
|
|
27
|
+
const b = Math.round((colorInt & 65280) >>> 8);
|
|
28
|
+
const a = ((colorInt & 255) >>> 0) / 255;
|
|
29
|
+
return {
|
|
30
|
+
r,
|
|
31
|
+
g,
|
|
32
|
+
b,
|
|
33
|
+
a
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var rgba_exports = {};
|
|
24
|
+
__export(rgba_exports, { rgba: () => rgba });
|
|
25
|
+
module.exports = __toCommonJS(rgba_exports);
|
|
26
|
+
function rgba(colorInt) {
|
|
27
|
+
var r = Math.round((colorInt & 4278190080) >>> 24);
|
|
28
|
+
var g = Math.round((colorInt & 16711680) >>> 16);
|
|
29
|
+
var b = Math.round((colorInt & 65280) >>> 8);
|
|
30
|
+
var a = ((colorInt & 255) >>> 0) / 255;
|
|
31
|
+
return {
|
|
32
|
+
r,
|
|
33
|
+
g,
|
|
34
|
+
b,
|
|
35
|
+
a
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var rgba_exports = {};
|
|
24
|
+
__export(rgba_exports, { rgba: () => rgba });
|
|
25
|
+
module.exports = __toCommonJS(rgba_exports);
|
|
26
|
+
function rgba(colorInt) {
|
|
27
|
+
var r = Math.round((colorInt & 4278190080) >>> 24);
|
|
28
|
+
var g = Math.round((colorInt & 16711680) >>> 16);
|
|
29
|
+
var b = Math.round((colorInt & 65280) >>> 8);
|
|
30
|
+
var a = ((colorInt & 255) >>> 0) / 255;
|
|
31
|
+
return {
|
|
32
|
+
r,
|
|
33
|
+
g,
|
|
34
|
+
b,
|
|
35
|
+
a
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=rgba.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgba.native.js","names":[],"sources":["cjs/rgba.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar rgba_exports = {};\n__export(rgba_exports, {\n rgba: () => rgba\n});\nmodule.exports = __toCommonJS(rgba_exports);\nfunction rgba(colorInt) {\n var r = Math.round((colorInt & 4278190080) >>> 24);\n var g = Math.round((colorInt & 16711680) >>> 16);\n var b = Math.round((colorInt & 65280) >>> 8);\n var a = ((colorInt & 255) >>> 0) / 255;\n return {\n r,\n g,\n b,\n a\n };\n}\n//# sourceMappingURL=rgba.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,eAAe,CAAC;AACpB,SAAS,cAAc,EACrB,YAAY,KACd,CAAC;AACD,OAAO,UAAU,aAAa,YAAY;AAC1C,SAAS,KAAK,UAAU;CACtB,IAAI,IAAI,KAAK,OAAO,WAAW,gBAAgB,EAAE;CACjD,IAAI,IAAI,KAAK,OAAO,WAAW,cAAc,EAAE;CAC/C,IAAI,IAAI,KAAK,OAAO,WAAW,WAAW,CAAC;CAC3C,IAAI,MAAM,WAAW,SAAS,KAAK;CACnC,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,18 +1,97 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { rgba } from "./rgba.mjs";
|
|
2
|
+
|
|
3
|
+
const colorNames = "transparent,aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,burntsienna,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkgrey,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkslategrey,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dimgrey,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,grey,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightslategrey,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,rebeccapurple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,slategrey,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow,yellowgreen";
|
|
4
|
+
const colorValues = "00000000f0f8fffffaebd7ff00ffffff7fffd4fff0fffffff5f5dcffffe4c4ff000000ffffebcdff0000ffff8a2be2ffa52a2affdeb887ffea7e5dff5f9ea0ff7fff00ffd2691effff7f50ff6495edfffff8dcffdc143cff00ffffff00008bff008b8bffb8860bffa9a9a9ff006400ffa9a9a9ffbdb76bff8b008bff556b2fffff8c00ff9932ccff8b0000ffe9967aff8fbc8fff483d8bff2f4f4fff2f4f4fff00ced1ff9400d3ffff1493ff00bfffff696969ff696969ff1e90ffffb22222fffffaf0ff228b22ffff00ffffdcdcdcfff8f8ffffffd700ffdaa520ff808080ff008000ffadff2fff808080fff0fff0ffff69b4ffcd5c5cff4b0082fffffff0fff0e68cffe6e6fafffff0f5ff7cfc00fffffacdffadd8e6fff08080ffe0fffffffafad2ffd3d3d3ff90ee90ffd3d3d3ffffb6c1ffffa07aff20b2aaff87cefaff778899ff778899ffb0c4deffffffe0ff00ff00ff32cd32fffaf0e6ffff00ffff800000ff66cdaaff0000cdffba55d3ff9370dbff3cb371ff7b68eeff00fa9aff48d1ccffc71585ff191970fff5fffaffffe4e1ffffe4b5ffffdeadff000080fffdf5e6ff808000ff6b8e23ffffa500ffff4500ffda70d6ffeee8aaff98fb98ffafeeeeffdb7093ffffefd5ffffdab9ffcd853fffffc0cbffdda0ddffb0e0e6ff800080ff663399ffff0000ffbc8f8fff4169e1ff8b4513fffa8072fff4a460ff2e8b57fffff5eeffa0522dffc0c0c0ff87ceebff6a5acdff708090ff708090fffffafaff00ff7fff4682b4ffd2b48cff008080ffd8bfd8ffff6347ff40e0d0ffee82eefff5deb3fffffffffff5f5f5ffffff00ff9acd32ff";
|
|
5
|
+
const number = "[-+]?\\d*\\.?\\d+";
|
|
6
|
+
const percentage = `${number}%`;
|
|
7
|
+
const call = (...args) => `\\(\\s*(${args.join(")\\s*,?\\s*(")})\\s*\\)`;
|
|
8
|
+
const callWithSlashSeparator = (...args) => `\\(\\s*(${args.slice(0, -1).join(")\\s*,?\\s*(")})\\s*\\/\\s*(${args[args.length - 1]})\\s*\\)`;
|
|
9
|
+
const commaSeparatedCall = (...args) => `\\(\\s*(${args.join(")\\s*,\\s*(")})\\s*\\)`;
|
|
10
|
+
const matchers = {
|
|
11
|
+
rgb: new RegExp(`rgb${call(number, number, number)}`),
|
|
12
|
+
rgba: new RegExp(`rgba(${commaSeparatedCall(number, number, number, number)}|${callWithSlashSeparator(number, number, number, number)})`),
|
|
13
|
+
hsl: new RegExp(`hsl${call(number, percentage, percentage)}`),
|
|
14
|
+
hsla: new RegExp(`hsla(${commaSeparatedCall(number, percentage, percentage, number)}|${callWithSlashSeparator(number, percentage, percentage, number)})`),
|
|
15
|
+
hwb: new RegExp(`hwb${call(number, percentage, percentage)}`),
|
|
16
|
+
hex3: /^#([\da-f])([\da-f])([\da-f])$/i,
|
|
17
|
+
hex4: /^#([\da-f])([\da-f])([\da-f])([\da-f])$/i,
|
|
18
|
+
hex6: /^#([\da-f]{6})$/i,
|
|
19
|
+
hex8: /^#([\da-f]{8})$/i
|
|
20
|
+
};
|
|
21
|
+
let colorNameMap;
|
|
22
|
+
const parse255 = (value) => Math.max(0, Math.min(255, Number.parseInt(value, 10)));
|
|
23
|
+
const parse360 = (value) => (Number.parseFloat(value) % 360 + 360) % 360 / 360;
|
|
24
|
+
const parse1 = (value) => Math.round(Math.max(0, Math.min(1, Number.parseFloat(value))) * 255);
|
|
25
|
+
const parsePercentage = (value) => Math.max(0, Math.min(100, Number.parseFloat(value))) / 100;
|
|
26
|
+
function hue2rgb(p, q, value) {
|
|
27
|
+
let t = value;
|
|
28
|
+
if (t < 0) t += 1;
|
|
29
|
+
if (t > 1) t -= 1;
|
|
30
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
31
|
+
if (t < 1 / 2) return q;
|
|
32
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
33
|
+
return p;
|
|
34
|
+
}
|
|
35
|
+
function hslToRgb(h, s, l) {
|
|
36
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
37
|
+
const p = 2 * l - q;
|
|
38
|
+
return Math.round(hue2rgb(p, q, h + 1 / 3) * 255) << 24 | Math.round(hue2rgb(p, q, h) * 255) << 16 | Math.round(hue2rgb(p, q, h - 1 / 3) * 255) << 8;
|
|
39
|
+
}
|
|
40
|
+
function hwbToRgb(h, w, b) {
|
|
41
|
+
if (w + b >= 1) {
|
|
42
|
+
const gray = Math.round(w * 255 / (w + b));
|
|
43
|
+
return gray << 24 | gray << 16 | gray << 8;
|
|
44
|
+
}
|
|
45
|
+
return Math.round((hue2rgb(0, 1, h + 1 / 3) * (1 - w - b) + w) * 255) << 24 | Math.round((hue2rgb(0, 1, h) * (1 - w - b) + w) * 255) << 16 | Math.round((hue2rgb(0, 1, h - 1 / 3) * (1 - w - b) + w) * 255) << 8;
|
|
46
|
+
}
|
|
47
|
+
function normalizeCSSColor(color) {
|
|
48
|
+
if (typeof color !== "string") return null;
|
|
49
|
+
let match = matchers.hex6.exec(color);
|
|
50
|
+
if (match) return Number.parseInt(`${match[1]}ff`, 16) >>> 0;
|
|
51
|
+
match = matchers.rgb.exec(color);
|
|
52
|
+
if (match) {
|
|
53
|
+
return (parse255(match[1]) << 24 | parse255(match[2]) << 16 | parse255(match[3]) << 8 | 255) >>> 0;
|
|
54
|
+
}
|
|
55
|
+
match = matchers.rgba.exec(color);
|
|
56
|
+
if (match) {
|
|
57
|
+
const offset = match[6] === void 0 ? 2 : 6;
|
|
58
|
+
return (parse255(match[offset]) << 24 | parse255(match[offset + 1]) << 16 | parse255(match[offset + 2]) << 8 | parse1(match[offset + 3])) >>> 0;
|
|
59
|
+
}
|
|
60
|
+
match = matchers.hex3.exec(color);
|
|
61
|
+
if (match) {
|
|
62
|
+
return Number.parseInt(`${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}ff`, 16) >>> 0;
|
|
63
|
+
}
|
|
64
|
+
match = matchers.hex8.exec(color);
|
|
65
|
+
if (match) return Number.parseInt(match[1], 16) >>> 0;
|
|
66
|
+
match = matchers.hex4.exec(color);
|
|
67
|
+
if (match) {
|
|
68
|
+
return Number.parseInt(`${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}${match[4]}${match[4]}`, 16) >>> 0;
|
|
69
|
+
}
|
|
70
|
+
match = matchers.hsl.exec(color);
|
|
71
|
+
if (match) {
|
|
72
|
+
return (hslToRgb(parse360(match[1]), parsePercentage(match[2]), parsePercentage(match[3])) | 255) >>> 0;
|
|
73
|
+
}
|
|
74
|
+
match = matchers.hsla.exec(color);
|
|
75
|
+
if (match) {
|
|
76
|
+
const offset = match[6] === void 0 ? 2 : 6;
|
|
77
|
+
return (hslToRgb(parse360(match[offset]), parsePercentage(match[offset + 1]), parsePercentage(match[offset + 2])) | parse1(match[offset + 3])) >>> 0;
|
|
78
|
+
}
|
|
79
|
+
match = matchers.hwb.exec(color);
|
|
80
|
+
if (match) {
|
|
81
|
+
return (hwbToRgb(parse360(match[1]), parsePercentage(match[2]), parsePercentage(match[3])) | 255) >>> 0;
|
|
82
|
+
}
|
|
83
|
+
const namedColor = getColorNameMap().get(color);
|
|
84
|
+
if (namedColor !== void 0) return namedColor;
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
function getColorNameMap() {
|
|
88
|
+
colorNameMap ||= new Map(colorNames.split(",").map((name, index) => [name, Number.parseInt(colorValues.slice(index * 8, index * 8 + 8), 16) >>> 0]));
|
|
89
|
+
return colorNameMap;
|
|
90
|
+
}
|
|
91
|
+
function isKnownColorName(color) {
|
|
92
|
+
return getColorNameMap().has(color);
|
|
15
93
|
}
|
|
16
94
|
var index_default = normalizeCSSColor;
|
|
17
|
-
|
|
95
|
+
|
|
96
|
+
export { index_default as default, isKnownColorName, normalizeCSSColor, rgba };
|
|
18
97
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["normalizeColor","norm","default","normalizeCSSColor","rgba","colorInt","r","Math","round","g","b","a","index_default"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,cAAA,MAAoB;AAGhC,MAAMC,IAAA,GAAOD,cAAA,CAAeE,OAAA,IAAWF,cAAA;AAChC,MAAMG,iBAAA,GAAoBF,IAAA;AAE1B,SAASG,KAAKC,QAAA,EAAkB;EACrC,MAAMC,CAAA,GAAIC,IAAA,CAAKC,KAAA,EAAOH,QAAA,GAAW,gBAAgB,EAAE;EACnD,MAAMI,CAAA,GAAIF,IAAA,CAAKC,KAAA,EAAOH,QAAA,GAAW,cAAgB,EAAE;EACnD,MAAMK,CAAA,GAAIH,IAAA,CAAKC,KAAA,EAAOH,QAAA,GAAW,WAAgB,CAAC;EAClD,MAAMM,CAAA,KAAMN,QAAA,GAAW,SAAgB,KAAK;EAC5C,OAAO;IACLC,CAAA;IACAG,CAAA;IACAC,CAAA;IACAC;EACF;AACF;AAEA,IAAOC,aAAA,GAAQT,iBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { rgba } from \"./rgba\";\nconst colorNames = \"transparent,aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,burntsienna,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkgrey,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkslategrey,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dimgrey,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,grey,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightslategrey,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,rebeccapurple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,slategrey,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow,yellowgreen\";\nconst colorValues = \"00000000f0f8fffffaebd7ff00ffffff7fffd4fff0fffffff5f5dcffffe4c4ff000000ffffebcdff0000ffff8a2be2ffa52a2affdeb887ffea7e5dff5f9ea0ff7fff00ffd2691effff7f50ff6495edfffff8dcffdc143cff00ffffff00008bff008b8bffb8860bffa9a9a9ff006400ffa9a9a9ffbdb76bff8b008bff556b2fffff8c00ff9932ccff8b0000ffe9967aff8fbc8fff483d8bff2f4f4fff2f4f4fff00ced1ff9400d3ffff1493ff00bfffff696969ff696969ff1e90ffffb22222fffffaf0ff228b22ffff00ffffdcdcdcfff8f8ffffffd700ffdaa520ff808080ff008000ffadff2fff808080fff0fff0ffff69b4ffcd5c5cff4b0082fffffff0fff0e68cffe6e6fafffff0f5ff7cfc00fffffacdffadd8e6fff08080ffe0fffffffafad2ffd3d3d3ff90ee90ffd3d3d3ffffb6c1ffffa07aff20b2aaff87cefaff778899ff778899ffb0c4deffffffe0ff00ff00ff32cd32fffaf0e6ffff00ffff800000ff66cdaaff0000cdffba55d3ff9370dbff3cb371ff7b68eeff00fa9aff48d1ccffc71585ff191970fff5fffaffffe4e1ffffe4b5ffffdeadff000080fffdf5e6ff808000ff6b8e23ffffa500ffff4500ffda70d6ffeee8aaff98fb98ffafeeeeffdb7093ffffefd5ffffdab9ffcd853fffffc0cbffdda0ddffb0e0e6ff800080ff663399ffff0000ffbc8f8fff4169e1ff8b4513fffa8072fff4a460ff2e8b57fffff5eeffa0522dffc0c0c0ff87ceebff6a5acdff708090ff708090fffffafaff00ff7fff4682b4ffd2b48cff008080ffd8bfd8ffff6347ff40e0d0ffee82eefff5deb3fffffffffff5f5f5ffffff00ff9acd32ff\";\nconst number = \"[-+]?\\\\d*\\\\.?\\\\d+\";\nconst percentage = `${number}%`;\nconst call = (...args) => `\\\\(\\\\s*(${args.join(\")\\\\s*,?\\\\s*(\")})\\\\s*\\\\)`;\nconst callWithSlashSeparator = (...args) => `\\\\(\\\\s*(${args.slice(0, -1).join(\")\\\\s*,?\\\\s*(\")})\\\\s*\\\\/\\\\s*(${args[args.length - 1]})\\\\s*\\\\)`;\nconst commaSeparatedCall = (...args) => `\\\\(\\\\s*(${args.join(\")\\\\s*,\\\\s*(\")})\\\\s*\\\\)`;\nconst matchers = {\n rgb: new RegExp(`rgb${call(number, number, number)}`),\n rgba: new RegExp(\n `rgba(${commaSeparatedCall(number, number, number, number)}|${callWithSlashSeparator(number, number, number, number)})`\n ),\n hsl: new RegExp(`hsl${call(number, percentage, percentage)}`),\n hsla: new RegExp(\n `hsla(${commaSeparatedCall(number, percentage, percentage, number)}|${callWithSlashSeparator(number, percentage, percentage, number)})`\n ),\n hwb: new RegExp(`hwb${call(number, percentage, percentage)}`),\n hex3: /^#([\\da-f])([\\da-f])([\\da-f])$/i,\n hex4: /^#([\\da-f])([\\da-f])([\\da-f])([\\da-f])$/i,\n hex6: /^#([\\da-f]{6})$/i,\n hex8: /^#([\\da-f]{8})$/i\n};\nlet colorNameMap;\nconst parse255 = (value) => Math.max(0, Math.min(255, Number.parseInt(value, 10)));\nconst parse360 = (value) => (Number.parseFloat(value) % 360 + 360) % 360 / 360;\nconst parse1 = (value) => Math.round(Math.max(0, Math.min(1, Number.parseFloat(value))) * 255);\nconst parsePercentage = (value) => Math.max(0, Math.min(100, Number.parseFloat(value))) / 100;\nfunction hue2rgb(p, q, value) {\n let t = value;\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n}\nfunction hslToRgb(h, s, l) {\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n return Math.round(hue2rgb(p, q, h + 1 / 3) * 255) << 24 | Math.round(hue2rgb(p, q, h) * 255) << 16 | Math.round(hue2rgb(p, q, h - 1 / 3) * 255) << 8;\n}\nfunction hwbToRgb(h, w, b) {\n if (w + b >= 1) {\n const gray = Math.round(w * 255 / (w + b));\n return gray << 24 | gray << 16 | gray << 8;\n }\n return Math.round((hue2rgb(0, 1, h + 1 / 3) * (1 - w - b) + w) * 255) << 24 | Math.round((hue2rgb(0, 1, h) * (1 - w - b) + w) * 255) << 16 | Math.round((hue2rgb(0, 1, h - 1 / 3) * (1 - w - b) + w) * 255) << 8;\n}\nfunction normalizeCSSColor(color) {\n if (typeof color !== \"string\") return null;\n let match = matchers.hex6.exec(color);\n if (match) return Number.parseInt(`${match[1]}ff`, 16) >>> 0;\n match = matchers.rgb.exec(color);\n if (match) {\n return (parse255(match[1]) << 24 | parse255(match[2]) << 16 | parse255(match[3]) << 8 | 255) >>> 0;\n }\n match = matchers.rgba.exec(color);\n if (match) {\n const offset = match[6] === void 0 ? 2 : 6;\n return (parse255(match[offset]) << 24 | parse255(match[offset + 1]) << 16 | parse255(match[offset + 2]) << 8 | parse1(match[offset + 3])) >>> 0;\n }\n match = matchers.hex3.exec(color);\n if (match) {\n return Number.parseInt(\n `${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}ff`,\n 16\n ) >>> 0;\n }\n match = matchers.hex8.exec(color);\n if (match) return Number.parseInt(match[1], 16) >>> 0;\n match = matchers.hex4.exec(color);\n if (match) {\n return Number.parseInt(\n `${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}${match[4]}${match[4]}`,\n 16\n ) >>> 0;\n }\n match = matchers.hsl.exec(color);\n if (match) {\n return (hslToRgb(\n parse360(match[1]),\n parsePercentage(match[2]),\n parsePercentage(match[3])\n ) | 255) >>> 0;\n }\n match = matchers.hsla.exec(color);\n if (match) {\n const offset = match[6] === void 0 ? 2 : 6;\n return (hslToRgb(\n parse360(match[offset]),\n parsePercentage(match[offset + 1]),\n parsePercentage(match[offset + 2])\n ) | parse1(match[offset + 3])) >>> 0;\n }\n match = matchers.hwb.exec(color);\n if (match) {\n return (hwbToRgb(\n parse360(match[1]),\n parsePercentage(match[2]),\n parsePercentage(match[3])\n ) | 255) >>> 0;\n }\n const namedColor = getColorNameMap().get(color);\n if (namedColor !== void 0) return namedColor;\n return null;\n}\nfunction getColorNameMap() {\n colorNameMap ||= new Map(\n colorNames.split(\",\").map((name, index) => [\n name,\n Number.parseInt(colorValues.slice(index * 8, index * 8 + 8), 16) >>> 0\n ])\n );\n return colorNameMap;\n}\nfunction isKnownColorName(color) {\n return getColorNameMap().has(color);\n}\nvar index_default = normalizeCSSColor;\nexport {\n index_default as default,\n isKnownColorName,\n normalizeCSSColor,\n rgba\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,MAAM,aAAa;AACnB,MAAM,cAAc;AACpB,MAAM,SAAS;AACf,MAAM,aAAa,GAAG,OAAO;AAC7B,MAAM,QAAQ,GAAG,SAAS,WAAW,KAAK,KAAK,cAAc,EAAE;AAC/D,MAAM,0BAA0B,GAAG,SAAS,WAAW,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,cAAc,EAAE,eAAe,KAAK,KAAK,SAAS,GAAG;AACnI,MAAM,sBAAsB,GAAG,SAAS,WAAW,KA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aAAa,gBAAgB,CAAC,CAAC,IAAI,KAAK;CAC9C,IAAI,eAAe,KAAK,GAAG,OAAO;CAClC,OAAO;AACT;AACA,SAAS,kBAAkB;CACzB,iBAAiB,IAAI,IACnB,WAAW,MAAM,GAAG,CAAC,CAAC,KAAK,MAAM,UAAU,CACzC,MACA,OAAO,SAAS,YAAY,MAAM,QAAQ,GAAG,QAAQ,IAAI,CAAC,GAAG,EAAE,MAAM,CACvE,CAAC,CACH;CACA,OAAO;AACT;AACA,SAAS,iBAAiB,OAAO;CAC/B,OAAO,gBAAgB,CAAC,CAAC,IAAI,KAAK;AACpC;AACA,IAAI,gBAAgB"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,18 +1,97 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { rgba } from "./rgba.mjs";
|
|
2
|
+
|
|
3
|
+
const colorNames = "transparent,aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,burntsienna,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkgrey,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkslategrey,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dimgrey,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,grey,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightslategrey,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,rebeccapurple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,slategrey,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow,yellowgreen";
|
|
4
|
+
const colorValues = "00000000f0f8fffffaebd7ff00ffffff7fffd4fff0fffffff5f5dcffffe4c4ff000000ffffebcdff0000ffff8a2be2ffa52a2affdeb887ffea7e5dff5f9ea0ff7fff00ffd2691effff7f50ff6495edfffff8dcffdc143cff00ffffff00008bff008b8bffb8860bffa9a9a9ff006400ffa9a9a9ffbdb76bff8b008bff556b2fffff8c00ff9932ccff8b0000ffe9967aff8fbc8fff483d8bff2f4f4fff2f4f4fff00ced1ff9400d3ffff1493ff00bfffff696969ff696969ff1e90ffffb22222fffffaf0ff228b22ffff00ffffdcdcdcfff8f8ffffffd700ffdaa520ff808080ff008000ffadff2fff808080fff0fff0ffff69b4ffcd5c5cff4b0082fffffff0fff0e68cffe6e6fafffff0f5ff7cfc00fffffacdffadd8e6fff08080ffe0fffffffafad2ffd3d3d3ff90ee90ffd3d3d3ffffb6c1ffffa07aff20b2aaff87cefaff778899ff778899ffb0c4deffffffe0ff00ff00ff32cd32fffaf0e6ffff00ffff800000ff66cdaaff0000cdffba55d3ff9370dbff3cb371ff7b68eeff00fa9aff48d1ccffc71585ff191970fff5fffaffffe4e1ffffe4b5ffffdeadff000080fffdf5e6ff808000ff6b8e23ffffa500ffff4500ffda70d6ffeee8aaff98fb98ffafeeeeffdb7093ffffefd5ffffdab9ffcd853fffffc0cbffdda0ddffb0e0e6ff800080ff663399ffff0000ffbc8f8fff4169e1ff8b4513fffa8072fff4a460ff2e8b57fffff5eeffa0522dffc0c0c0ff87ceebff6a5acdff708090ff708090fffffafaff00ff7fff4682b4ffd2b48cff008080ffd8bfd8ffff6347ff40e0d0ffee82eefff5deb3fffffffffff5f5f5ffffff00ff9acd32ff";
|
|
5
|
+
const number = "[-+]?\\d*\\.?\\d+";
|
|
6
|
+
const percentage = `${number}%`;
|
|
7
|
+
const call = (...args) => `\\(\\s*(${args.join(")\\s*,?\\s*(")})\\s*\\)`;
|
|
8
|
+
const callWithSlashSeparator = (...args) => `\\(\\s*(${args.slice(0, -1).join(")\\s*,?\\s*(")})\\s*\\/\\s*(${args[args.length - 1]})\\s*\\)`;
|
|
9
|
+
const commaSeparatedCall = (...args) => `\\(\\s*(${args.join(")\\s*,\\s*(")})\\s*\\)`;
|
|
10
|
+
const matchers = {
|
|
11
|
+
rgb: new RegExp(`rgb${call(number, number, number)}`),
|
|
12
|
+
rgba: new RegExp(`rgba(${commaSeparatedCall(number, number, number, number)}|${callWithSlashSeparator(number, number, number, number)})`),
|
|
13
|
+
hsl: new RegExp(`hsl${call(number, percentage, percentage)}`),
|
|
14
|
+
hsla: new RegExp(`hsla(${commaSeparatedCall(number, percentage, percentage, number)}|${callWithSlashSeparator(number, percentage, percentage, number)})`),
|
|
15
|
+
hwb: new RegExp(`hwb${call(number, percentage, percentage)}`),
|
|
16
|
+
hex3: /^#([\da-f])([\da-f])([\da-f])$/i,
|
|
17
|
+
hex4: /^#([\da-f])([\da-f])([\da-f])([\da-f])$/i,
|
|
18
|
+
hex6: /^#([\da-f]{6})$/i,
|
|
19
|
+
hex8: /^#([\da-f]{8})$/i
|
|
20
|
+
};
|
|
21
|
+
let colorNameMap;
|
|
22
|
+
const parse255 = (value) => Math.max(0, Math.min(255, Number.parseInt(value, 10)));
|
|
23
|
+
const parse360 = (value) => (Number.parseFloat(value) % 360 + 360) % 360 / 360;
|
|
24
|
+
const parse1 = (value) => Math.round(Math.max(0, Math.min(1, Number.parseFloat(value))) * 255);
|
|
25
|
+
const parsePercentage = (value) => Math.max(0, Math.min(100, Number.parseFloat(value))) / 100;
|
|
26
|
+
function hue2rgb(p, q, value) {
|
|
27
|
+
let t = value;
|
|
28
|
+
if (t < 0) t += 1;
|
|
29
|
+
if (t > 1) t -= 1;
|
|
30
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
31
|
+
if (t < 1 / 2) return q;
|
|
32
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
33
|
+
return p;
|
|
34
|
+
}
|
|
35
|
+
function hslToRgb(h, s, l) {
|
|
36
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
37
|
+
const p = 2 * l - q;
|
|
38
|
+
return Math.round(hue2rgb(p, q, h + 1 / 3) * 255) << 24 | Math.round(hue2rgb(p, q, h) * 255) << 16 | Math.round(hue2rgb(p, q, h - 1 / 3) * 255) << 8;
|
|
39
|
+
}
|
|
40
|
+
function hwbToRgb(h, w, b) {
|
|
41
|
+
if (w + b >= 1) {
|
|
42
|
+
const gray = Math.round(w * 255 / (w + b));
|
|
43
|
+
return gray << 24 | gray << 16 | gray << 8;
|
|
44
|
+
}
|
|
45
|
+
return Math.round((hue2rgb(0, 1, h + 1 / 3) * (1 - w - b) + w) * 255) << 24 | Math.round((hue2rgb(0, 1, h) * (1 - w - b) + w) * 255) << 16 | Math.round((hue2rgb(0, 1, h - 1 / 3) * (1 - w - b) + w) * 255) << 8;
|
|
46
|
+
}
|
|
47
|
+
function normalizeCSSColor(color) {
|
|
48
|
+
if (typeof color !== "string") return null;
|
|
49
|
+
let match = matchers.hex6.exec(color);
|
|
50
|
+
if (match) return Number.parseInt(`${match[1]}ff`, 16) >>> 0;
|
|
51
|
+
match = matchers.rgb.exec(color);
|
|
52
|
+
if (match) {
|
|
53
|
+
return (parse255(match[1]) << 24 | parse255(match[2]) << 16 | parse255(match[3]) << 8 | 255) >>> 0;
|
|
54
|
+
}
|
|
55
|
+
match = matchers.rgba.exec(color);
|
|
56
|
+
if (match) {
|
|
57
|
+
const offset = match[6] === void 0 ? 2 : 6;
|
|
58
|
+
return (parse255(match[offset]) << 24 | parse255(match[offset + 1]) << 16 | parse255(match[offset + 2]) << 8 | parse1(match[offset + 3])) >>> 0;
|
|
59
|
+
}
|
|
60
|
+
match = matchers.hex3.exec(color);
|
|
61
|
+
if (match) {
|
|
62
|
+
return Number.parseInt(`${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}ff`, 16) >>> 0;
|
|
63
|
+
}
|
|
64
|
+
match = matchers.hex8.exec(color);
|
|
65
|
+
if (match) return Number.parseInt(match[1], 16) >>> 0;
|
|
66
|
+
match = matchers.hex4.exec(color);
|
|
67
|
+
if (match) {
|
|
68
|
+
return Number.parseInt(`${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}${match[4]}${match[4]}`, 16) >>> 0;
|
|
69
|
+
}
|
|
70
|
+
match = matchers.hsl.exec(color);
|
|
71
|
+
if (match) {
|
|
72
|
+
return (hslToRgb(parse360(match[1]), parsePercentage(match[2]), parsePercentage(match[3])) | 255) >>> 0;
|
|
73
|
+
}
|
|
74
|
+
match = matchers.hsla.exec(color);
|
|
75
|
+
if (match) {
|
|
76
|
+
const offset = match[6] === void 0 ? 2 : 6;
|
|
77
|
+
return (hslToRgb(parse360(match[offset]), parsePercentage(match[offset + 1]), parsePercentage(match[offset + 2])) | parse1(match[offset + 3])) >>> 0;
|
|
78
|
+
}
|
|
79
|
+
match = matchers.hwb.exec(color);
|
|
80
|
+
if (match) {
|
|
81
|
+
return (hwbToRgb(parse360(match[1]), parsePercentage(match[2]), parsePercentage(match[3])) | 255) >>> 0;
|
|
82
|
+
}
|
|
83
|
+
const namedColor = getColorNameMap().get(color);
|
|
84
|
+
if (namedColor !== void 0) return namedColor;
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
function getColorNameMap() {
|
|
88
|
+
colorNameMap ||= new Map(colorNames.split(",").map((name, index) => [name, Number.parseInt(colorValues.slice(index * 8, index * 8 + 8), 16) >>> 0]));
|
|
89
|
+
return colorNameMap;
|
|
90
|
+
}
|
|
91
|
+
function isKnownColorName(color) {
|
|
92
|
+
return getColorNameMap().has(color);
|
|
15
93
|
}
|
|
16
94
|
var index_default = normalizeCSSColor;
|
|
17
|
-
|
|
95
|
+
|
|
96
|
+
export { index_default as default, isKnownColorName, normalizeCSSColor, rgba };
|
|
18
97
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["normalizeColor","norm","default","normalizeCSSColor","rgba","colorInt","r","Math","round","g","b","a","index_default"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,cAAA,MAAoB;AAGhC,MAAMC,IAAA,GAAOD,cAAA,CAAeE,OAAA,IAAWF,cAAA;AAChC,MAAMG,iBAAA,GAAoBF,IAAA;AAE1B,SAASG,KAAKC,QAAA,EAAkB;EACrC,MAAMC,CAAA,GAAIC,IAAA,CAAKC,KAAA,EAAOH,QAAA,GAAW,gBAAgB,EAAE;EACnD,MAAMI,CAAA,GAAIF,IAAA,CAAKC,KAAA,EAAOH,QAAA,GAAW,cAAgB,EAAE;EACnD,MAAMK,CAAA,GAAIH,IAAA,CAAKC,KAAA,EAAOH,QAAA,GAAW,WAAgB,CAAC;EAClD,MAAMM,CAAA,KAAMN,QAAA,GAAW,SAAgB,KAAK;EAC5C,OAAO;IACLC,CAAA;IACAG,CAAA;IACAC,CAAA;IACAC;EACF;AACF;AAEA,IAAOC,aAAA,GAAQT,iBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { rgba } from \"./rgba\";\nconst colorNames = \"transparent,aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,burntsienna,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkgrey,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkslategrey,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dimgrey,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,grey,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightslategrey,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,rebeccapurple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,slategrey,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow,yellowgreen\";\nconst colorValues = \"00000000f0f8fffffaebd7ff00ffffff7fffd4fff0fffffff5f5dcffffe4c4ff000000ffffebcdff0000ffff8a2be2ffa52a2affdeb887ffea7e5dff5f9ea0ff7fff00ffd2691effff7f50ff6495edfffff8dcffdc143cff00ffffff00008bff008b8bffb8860bffa9a9a9ff006400ffa9a9a9ffbdb76bff8b008bff556b2fffff8c00ff9932ccff8b0000ffe9967aff8fbc8fff483d8bff2f4f4fff2f4f4fff00ced1ff9400d3ffff1493ff00bfffff696969ff696969ff1e90ffffb22222fffffaf0ff228b22ffff00ffffdcdcdcfff8f8ffffffd700ffdaa520ff808080ff008000ffadff2fff808080fff0fff0ffff69b4ffcd5c5cff4b0082fffffff0fff0e68cffe6e6fafffff0f5ff7cfc00fffffacdffadd8e6fff08080ffe0fffffffafad2ffd3d3d3ff90ee90ffd3d3d3ffffb6c1ffffa07aff20b2aaff87cefaff778899ff778899ffb0c4deffffffe0ff00ff00ff32cd32fffaf0e6ffff00ffff800000ff66cdaaff0000cdffba55d3ff9370dbff3cb371ff7b68eeff00fa9aff48d1ccffc71585ff191970fff5fffaffffe4e1ffffe4b5ffffdeadff000080fffdf5e6ff808000ff6b8e23ffffa500ffff4500ffda70d6ffeee8aaff98fb98ffafeeeeffdb7093ffffefd5ffffdab9ffcd853fffffc0cbffdda0ddffb0e0e6ff800080ff663399ffff0000ffbc8f8fff4169e1ff8b4513fffa8072fff4a460ff2e8b57fffff5eeffa0522dffc0c0c0ff87ceebff6a5acdff708090ff708090fffffafaff00ff7fff4682b4ffd2b48cff008080ffd8bfd8ffff6347ff40e0d0ffee82eefff5deb3fffffffffff5f5f5ffffff00ff9acd32ff\";\nconst number = \"[-+]?\\\\d*\\\\.?\\\\d+\";\nconst percentage = `${number}%`;\nconst call = (...args) => `\\\\(\\\\s*(${args.join(\")\\\\s*,?\\\\s*(\")})\\\\s*\\\\)`;\nconst callWithSlashSeparator = (...args) => `\\\\(\\\\s*(${args.slice(0, -1).join(\")\\\\s*,?\\\\s*(\")})\\\\s*\\\\/\\\\s*(${args[args.length - 1]})\\\\s*\\\\)`;\nconst commaSeparatedCall = (...args) => `\\\\(\\\\s*(${args.join(\")\\\\s*,\\\\s*(\")})\\\\s*\\\\)`;\nconst matchers = {\n rgb: new RegExp(`rgb${call(number, number, number)}`),\n rgba: new RegExp(\n `rgba(${commaSeparatedCall(number, number, number, number)}|${callWithSlashSeparator(number, number, number, number)})`\n ),\n hsl: new RegExp(`hsl${call(number, percentage, percentage)}`),\n hsla: new RegExp(\n `hsla(${commaSeparatedCall(number, percentage, percentage, number)}|${callWithSlashSeparator(number, percentage, percentage, number)})`\n ),\n hwb: new RegExp(`hwb${call(number, percentage, percentage)}`),\n hex3: /^#([\\da-f])([\\da-f])([\\da-f])$/i,\n hex4: /^#([\\da-f])([\\da-f])([\\da-f])([\\da-f])$/i,\n hex6: /^#([\\da-f]{6})$/i,\n hex8: /^#([\\da-f]{8})$/i\n};\nlet colorNameMap;\nconst parse255 = (value) => Math.max(0, Math.min(255, Number.parseInt(value, 10)));\nconst parse360 = (value) => (Number.parseFloat(value) % 360 + 360) % 360 / 360;\nconst parse1 = (value) => Math.round(Math.max(0, Math.min(1, Number.parseFloat(value))) * 255);\nconst parsePercentage = (value) => Math.max(0, Math.min(100, Number.parseFloat(value))) / 100;\nfunction hue2rgb(p, q, value) {\n let t = value;\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n}\nfunction hslToRgb(h, s, l) {\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n return Math.round(hue2rgb(p, q, h + 1 / 3) * 255) << 24 | Math.round(hue2rgb(p, q, h) * 255) << 16 | Math.round(hue2rgb(p, q, h - 1 / 3) * 255) << 8;\n}\nfunction hwbToRgb(h, w, b) {\n if (w + b >= 1) {\n const gray = Math.round(w * 255 / (w + b));\n return gray << 24 | gray << 16 | gray << 8;\n }\n return Math.round((hue2rgb(0, 1, h + 1 / 3) * (1 - w - b) + w) * 255) << 24 | Math.round((hue2rgb(0, 1, h) * (1 - w - b) + w) * 255) << 16 | Math.round((hue2rgb(0, 1, h - 1 / 3) * (1 - w - b) + w) * 255) << 8;\n}\nfunction normalizeCSSColor(color) {\n if (typeof color !== \"string\") return null;\n let match = matchers.hex6.exec(color);\n if (match) return Number.parseInt(`${match[1]}ff`, 16) >>> 0;\n match = matchers.rgb.exec(color);\n if (match) {\n return (parse255(match[1]) << 24 | parse255(match[2]) << 16 | parse255(match[3]) << 8 | 255) >>> 0;\n }\n match = matchers.rgba.exec(color);\n if (match) {\n const offset = match[6] === void 0 ? 2 : 6;\n return (parse255(match[offset]) << 24 | parse255(match[offset + 1]) << 16 | parse255(match[offset + 2]) << 8 | parse1(match[offset + 3])) >>> 0;\n }\n match = matchers.hex3.exec(color);\n if (match) {\n return Number.parseInt(\n `${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}ff`,\n 16\n ) >>> 0;\n }\n match = matchers.hex8.exec(color);\n if (match) return Number.parseInt(match[1], 16) >>> 0;\n match = matchers.hex4.exec(color);\n if (match) {\n return Number.parseInt(\n `${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}${match[4]}${match[4]}`,\n 16\n ) >>> 0;\n }\n match = matchers.hsl.exec(color);\n if (match) {\n return (hslToRgb(\n parse360(match[1]),\n parsePercentage(match[2]),\n parsePercentage(match[3])\n ) | 255) >>> 0;\n }\n match = matchers.hsla.exec(color);\n if (match) {\n const offset = match[6] === void 0 ? 2 : 6;\n return (hslToRgb(\n parse360(match[offset]),\n parsePercentage(match[offset + 1]),\n parsePercentage(match[offset + 2])\n ) | parse1(match[offset + 3])) >>> 0;\n }\n match = matchers.hwb.exec(color);\n if (match) {\n return (hwbToRgb(\n parse360(match[1]),\n parsePercentage(match[2]),\n parsePercentage(match[3])\n ) | 255) >>> 0;\n }\n const namedColor = getColorNameMap().get(color);\n if (namedColor !== void 0) return namedColor;\n return null;\n}\nfunction getColorNameMap() {\n colorNameMap ||= new Map(\n colorNames.split(\",\").map((name, index) => [\n name,\n Number.parseInt(colorValues.slice(index * 8, index * 8 + 8), 16) >>> 0\n ])\n );\n return colorNameMap;\n}\nfunction isKnownColorName(color) {\n return getColorNameMap().has(color);\n}\nvar index_default = normalizeCSSColor;\nexport {\n index_default as default,\n isKnownColorName,\n normalizeCSSColor,\n rgba\n};\n//# sourceMappingURL=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I,IAAI;EACzC,QAAQ,SACN,SAAS,MAAM,OAAO,GACtB,gBAAgB,MAAM,SAAS,EAAE,GACjC,gBAAgB,MAAM,SAAS,EAAE,CACnC,IAAI,OAAO,MAAM,SAAS,EAAE,OAAO;CACrC;CACA,QAAQ,SAAS,IAAI,KAAK,KAAK;CAC/B,IAAI,OAAO;EACT,QAAQ,SACN,SAAS,MAAM,EAAE,GACjB,gBAAgB,MAAM,EAAE,GACxB,gBAAgB,MAAM,EAAE,CAC1B,IAAI,SAAS;CACf;CACA,MAAM,aAAa,gBAAgB,CAAC,CAAC,IAAI,KAAK;CAC9C,IAAI,eAAe,KAAK,GAAG,OAAO;CAClC,OAAO;AACT;AACA,SAAS,kBAAkB;CACzB,iBAAiB,IAAI,IACnB,WAAW,MAAM,GAAG,CAAC,CAAC,KAAK,MAAM,UAAU,CACzC,MACA,OAAO,SAAS,YAAY,MAAM,QAAQ,GAAG,QAAQ,IAAI,CAAC,GAAG,EAAE,MAAM,CACvE,CAAC,CACH;CACA,OAAO;AACT;AACA,SAAS,iBAAiB,OAAO;CAC/B,OAAO,gBAAgB,CAAC,CAAC,IAAI,KAAK;AACpC;AACA,IAAI,gBAAgB"}
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import * as normalizeColor from "@react-native/normalize-color";
|
|
2
|
+
import { rgba } from "./rgba.native.js";
|
|
3
|
+
|
|
2
4
|
var norm = normalizeColor.default || normalizeColor;
|
|
3
5
|
var normalizeCSSColor = norm;
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
var g = Math.round((colorInt & 16711680) >>> 16);
|
|
7
|
-
var b = Math.round((colorInt & 65280) >>> 8);
|
|
8
|
-
var a = ((colorInt & 255) >>> 0) / 255;
|
|
9
|
-
return {
|
|
10
|
-
r,
|
|
11
|
-
g,
|
|
12
|
-
b,
|
|
13
|
-
a
|
|
14
|
-
};
|
|
6
|
+
function isKnownColorName(color) {
|
|
7
|
+
return /^[a-z]+$/i.test(color) && normalizeCSSColor(color) != null;
|
|
15
8
|
}
|
|
16
|
-
var
|
|
17
|
-
|
|
9
|
+
var index_native_default = normalizeCSSColor;
|
|
10
|
+
|
|
11
|
+
export { index_native_default as default, isKnownColorName, normalizeCSSColor, rgba };
|
|
18
12
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["esm/index.native.js"],"sourcesContent":["import * as normalizeColor from \"@react-native/normalize-color\";\nimport { rgba } from \"./rgba\";\nvar norm = normalizeColor.default || normalizeColor;\nvar normalizeCSSColor = norm;\nfunction isKnownColorName(color) {\n return /^[a-z]+$/i.test(color) && normalizeCSSColor(color) != null;\n}\nvar index_native_default = normalizeCSSColor;\nexport {\n index_native_default as default,\n isKnownColorName,\n normalizeCSSColor,\n rgba\n};\n//# sourceMappingURL=index.native.js.map\n"],"mappings":";;;;AAEA,IAAI,OAAO,eAAe,WAAW;AACrC,IAAI,oBAAoB;AACxB,SAAS,iBAAiB,OAAO;CAC/B,OAAO,YAAY,KAAK,KAAK,KAAK,kBAAkB,KAAK,KAAK;AAChE;AACA,IAAI,uBAAuB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function rgba(colorInt) {
|
|
2
|
+
const r = Math.round((colorInt & 4278190080) >>> 24);
|
|
3
|
+
const g = Math.round((colorInt & 16711680) >>> 16);
|
|
4
|
+
const b = Math.round((colorInt & 65280) >>> 8);
|
|
5
|
+
const a = ((colorInt & 255) >>> 0) / 255;
|
|
6
|
+
return {
|
|
7
|
+
r,
|
|
8
|
+
g,
|
|
9
|
+
b,
|
|
10
|
+
a
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { rgba };
|
|
15
|
+
//# sourceMappingURL=rgba.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgba.js","names":[],"sources":["esm/rgba.js"],"sourcesContent":["function rgba(colorInt) {\n const r = Math.round((colorInt & 4278190080) >>> 24);\n const g = Math.round((colorInt & 16711680) >>> 16);\n const b = Math.round((colorInt & 65280) >>> 8);\n const a = ((colorInt & 255) >>> 0) / 255;\n return {\n r,\n g,\n b,\n a\n };\n}\nexport {\n rgba\n};\n//# sourceMappingURL=rgba.js.map\n"],"mappings":";AAAA,SAAS,KAAK,UAAU;CACtB,MAAM,IAAI,KAAK,OAAO,WAAW,gBAAgB,EAAE;CACnD,MAAM,IAAI,KAAK,OAAO,WAAW,cAAc,EAAE;CACjD,MAAM,IAAI,KAAK,OAAO,WAAW,WAAW,CAAC;CAC7C,MAAM,MAAM,WAAW,SAAS,KAAK;CACrC,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function rgba(colorInt) {
|
|
2
|
+
var r = Math.round((colorInt & 4278190080) >>> 24);
|
|
3
|
+
var g = Math.round((colorInt & 16711680) >>> 16);
|
|
4
|
+
var b = Math.round((colorInt & 65280) >>> 8);
|
|
5
|
+
var a = ((colorInt & 255) >>> 0) / 255;
|
|
6
|
+
return {
|
|
7
|
+
r,
|
|
8
|
+
g,
|
|
9
|
+
b,
|
|
10
|
+
a
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { rgba };
|
|
15
|
+
//# sourceMappingURL=rgba.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgba.native.js","names":[],"sources":["esm/rgba.native.js"],"sourcesContent":["function rgba(colorInt) {\n var r = Math.round((colorInt & 4278190080) >>> 24);\n var g = Math.round((colorInt & 16711680) >>> 16);\n var b = Math.round((colorInt & 65280) >>> 8);\n var a = ((colorInt & 255) >>> 0) / 255;\n return {\n r,\n g,\n b,\n a\n };\n}\nexport {\n rgba\n};\n//# sourceMappingURL=rgba.js.map\n"],"mappings":";AAAA,SAAS,KAAK,UAAU;CACtB,IAAI,IAAI,KAAK,OAAO,WAAW,gBAAgB,EAAE;CACjD,IAAI,IAAI,KAAK,OAAO,WAAW,cAAc,EAAE;CAC/C,IAAI,IAAI,KAAK,OAAO,WAAW,WAAW,CAAC;CAC3C,IAAI,MAAM,WAAW,SAAS,KAAK;CACnC,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/normalize-css-color",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.1097.1",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"source": "src/index.ts",
|
|
5
6
|
"files": [
|
|
6
7
|
"src",
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"@react-native/normalize-color": "^2.1.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@tamagui/build": "
|
|
41
|
+
"@tamagui/build": "3.0.0-beta.1097.1"
|
|
41
42
|
},
|
|
42
43
|
"repository": {
|
|
43
44
|
"type": "git",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as normalizeColor from '@react-native/normalize-color'
|
|
2
|
+
|
|
3
|
+
export { rgba } from './rgba'
|
|
4
|
+
|
|
5
|
+
// vite/webpack compat
|
|
6
|
+
const norm = normalizeColor.default || normalizeColor
|
|
7
|
+
export const normalizeCSSColor = norm as (color: string) => number | null
|
|
8
|
+
|
|
9
|
+
// alphabetic strings RN's normalize-color accepts are exactly the named colors
|
|
10
|
+
export function isKnownColorName(color: string): boolean {
|
|
11
|
+
return /^[a-z]+$/i.test(color) && normalizeCSSColor(color) != null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default normalizeCSSColor
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,194 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { rgba } from './rgba'
|
|
9
|
+
|
|
10
|
+
const colorNames =
|
|
11
|
+
'transparent,aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,burntsienna,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkgrey,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkslategrey,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dimgrey,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,grey,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightslategrey,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,rebeccapurple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,slategrey,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow,yellowgreen'
|
|
12
|
+
const colorValues =
|
|
13
|
+
'00000000f0f8fffffaebd7ff00ffffff7fffd4fff0fffffff5f5dcffffe4c4ff000000ffffebcdff0000ffff8a2be2ffa52a2affdeb887ffea7e5dff5f9ea0ff7fff00ffd2691effff7f50ff6495edfffff8dcffdc143cff00ffffff00008bff008b8bffb8860bffa9a9a9ff006400ffa9a9a9ffbdb76bff8b008bff556b2fffff8c00ff9932ccff8b0000ffe9967aff8fbc8fff483d8bff2f4f4fff2f4f4fff00ced1ff9400d3ffff1493ff00bfffff696969ff696969ff1e90ffffb22222fffffaf0ff228b22ffff00ffffdcdcdcfff8f8ffffffd700ffdaa520ff808080ff008000ffadff2fff808080fff0fff0ffff69b4ffcd5c5cff4b0082fffffff0fff0e68cffe6e6fafffff0f5ff7cfc00fffffacdffadd8e6fff08080ffe0fffffffafad2ffd3d3d3ff90ee90ffd3d3d3ffffb6c1ffffa07aff20b2aaff87cefaff778899ff778899ffb0c4deffffffe0ff00ff00ff32cd32fffaf0e6ffff00ffff800000ff66cdaaff0000cdffba55d3ff9370dbff3cb371ff7b68eeff00fa9aff48d1ccffc71585ff191970fff5fffaffffe4e1ffffe4b5ffffdeadff000080fffdf5e6ff808000ff6b8e23ffffa500ffff4500ffda70d6ffeee8aaff98fb98ffafeeeeffdb7093ffffefd5ffffdab9ffcd853fffffc0cbffdda0ddffb0e0e6ff800080ff663399ffff0000ffbc8f8fff4169e1ff8b4513fffa8072fff4a460ff2e8b57fffff5eeffa0522dffc0c0c0ff87ceebff6a5acdff708090ff708090fffffafaff00ff7fff4682b4ffd2b48cff008080ffd8bfd8ffff6347ff40e0d0ffee82eefff5deb3fffffffffff5f5f5ffffff00ff9acd32ff'
|
|
14
|
+
|
|
15
|
+
const number = '[-+]?\\d*\\.?\\d+'
|
|
16
|
+
const percentage = `${number}%`
|
|
17
|
+
const call = (...args: string[]) => `\\(\\s*(${args.join(')\\s*,?\\s*(')})\\s*\\)`
|
|
18
|
+
const callWithSlashSeparator = (...args: string[]) =>
|
|
19
|
+
`\\(\\s*(${args.slice(0, -1).join(')\\s*,?\\s*(')})\\s*\\/\\s*(${args[args.length - 1]})\\s*\\)`
|
|
20
|
+
const commaSeparatedCall = (...args: string[]) =>
|
|
21
|
+
`\\(\\s*(${args.join(')\\s*,\\s*(')})\\s*\\)`
|
|
22
|
+
|
|
23
|
+
const matchers = {
|
|
24
|
+
rgb: new RegExp(`rgb${call(number, number, number)}`),
|
|
25
|
+
rgba: new RegExp(
|
|
26
|
+
`rgba(${commaSeparatedCall(number, number, number, number)}|${callWithSlashSeparator(number, number, number, number)})`
|
|
27
|
+
),
|
|
28
|
+
hsl: new RegExp(`hsl${call(number, percentage, percentage)}`),
|
|
29
|
+
hsla: new RegExp(
|
|
30
|
+
`hsla(${commaSeparatedCall(number, percentage, percentage, number)}|${callWithSlashSeparator(number, percentage, percentage, number)})`
|
|
31
|
+
),
|
|
32
|
+
hwb: new RegExp(`hwb${call(number, percentage, percentage)}`),
|
|
33
|
+
hex3: /^#([\da-f])([\da-f])([\da-f])$/i,
|
|
34
|
+
hex4: /^#([\da-f])([\da-f])([\da-f])([\da-f])$/i,
|
|
35
|
+
hex6: /^#([\da-f]{6})$/i,
|
|
36
|
+
hex8: /^#([\da-f]{8})$/i,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let colorNameMap: Map<string, number> | undefined
|
|
40
|
+
|
|
41
|
+
const parse255 = (value: string) => Math.max(0, Math.min(255, Number.parseInt(value, 10)))
|
|
42
|
+
const parse360 = (value: string) => (((Number.parseFloat(value) % 360) + 360) % 360) / 360
|
|
43
|
+
const parse1 = (value: string) =>
|
|
44
|
+
Math.round(Math.max(0, Math.min(1, Number.parseFloat(value))) * 255)
|
|
45
|
+
const parsePercentage = (value: string) =>
|
|
46
|
+
Math.max(0, Math.min(100, Number.parseFloat(value))) / 100
|
|
47
|
+
|
|
48
|
+
function hue2rgb(p: number, q: number, value: number) {
|
|
49
|
+
let t = value
|
|
50
|
+
if (t < 0) t += 1
|
|
51
|
+
if (t > 1) t -= 1
|
|
52
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t
|
|
53
|
+
if (t < 1 / 2) return q
|
|
54
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
|
|
55
|
+
return p
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function hslToRgb(h: number, s: number, l: number) {
|
|
59
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s
|
|
60
|
+
const p = 2 * l - q
|
|
61
|
+
return (
|
|
62
|
+
(Math.round(hue2rgb(p, q, h + 1 / 3) * 255) << 24) |
|
|
63
|
+
(Math.round(hue2rgb(p, q, h) * 255) << 16) |
|
|
64
|
+
(Math.round(hue2rgb(p, q, h - 1 / 3) * 255) << 8)
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function hwbToRgb(h: number, w: number, b: number) {
|
|
69
|
+
if (w + b >= 1) {
|
|
70
|
+
const gray = Math.round((w * 255) / (w + b))
|
|
71
|
+
return (gray << 24) | (gray << 16) | (gray << 8)
|
|
72
|
+
}
|
|
73
|
+
return (
|
|
74
|
+
(Math.round((hue2rgb(0, 1, h + 1 / 3) * (1 - w - b) + w) * 255) << 24) |
|
|
75
|
+
(Math.round((hue2rgb(0, 1, h) * (1 - w - b) + w) * 255) << 16) |
|
|
76
|
+
(Math.round((hue2rgb(0, 1, h - 1 / 3) * (1 - w - b) + w) * 255) << 8)
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function normalizeCSSColor(color: string): number | null {
|
|
81
|
+
if (typeof color !== 'string') return null
|
|
82
|
+
|
|
83
|
+
let match = matchers.hex6.exec(color)
|
|
84
|
+
if (match) return Number.parseInt(`${match[1]}ff`, 16) >>> 0
|
|
85
|
+
|
|
86
|
+
match = matchers.rgb.exec(color)
|
|
87
|
+
if (match) {
|
|
88
|
+
return (
|
|
89
|
+
((parse255(match[1]) << 24) |
|
|
90
|
+
(parse255(match[2]) << 16) |
|
|
91
|
+
(parse255(match[3]) << 8) |
|
|
92
|
+
0xff) >>>
|
|
93
|
+
0
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
match = matchers.rgba.exec(color)
|
|
98
|
+
if (match) {
|
|
99
|
+
const offset = match[6] === undefined ? 2 : 6
|
|
100
|
+
return (
|
|
101
|
+
((parse255(match[offset]) << 24) |
|
|
102
|
+
(parse255(match[offset + 1]) << 16) |
|
|
103
|
+
(parse255(match[offset + 2]) << 8) |
|
|
104
|
+
parse1(match[offset + 3])) >>>
|
|
105
|
+
0
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
match = matchers.hex3.exec(color)
|
|
110
|
+
if (match) {
|
|
111
|
+
return (
|
|
112
|
+
Number.parseInt(
|
|
113
|
+
`${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}ff`,
|
|
114
|
+
16
|
|
115
|
+
) >>> 0
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
match = matchers.hex8.exec(color)
|
|
120
|
+
if (match) return Number.parseInt(match[1], 16) >>> 0
|
|
121
|
+
|
|
122
|
+
match = matchers.hex4.exec(color)
|
|
123
|
+
if (match) {
|
|
124
|
+
return (
|
|
125
|
+
Number.parseInt(
|
|
126
|
+
`${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}${match[4]}${match[4]}`,
|
|
127
|
+
16
|
|
128
|
+
) >>> 0
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
match = matchers.hsl.exec(color)
|
|
133
|
+
if (match) {
|
|
134
|
+
return (
|
|
135
|
+
(hslToRgb(
|
|
136
|
+
parse360(match[1]),
|
|
137
|
+
parsePercentage(match[2]),
|
|
138
|
+
parsePercentage(match[3])
|
|
139
|
+
) |
|
|
140
|
+
0xff) >>>
|
|
141
|
+
0
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
match = matchers.hsla.exec(color)
|
|
146
|
+
if (match) {
|
|
147
|
+
const offset = match[6] === undefined ? 2 : 6
|
|
148
|
+
return (
|
|
149
|
+
(hslToRgb(
|
|
150
|
+
parse360(match[offset]),
|
|
151
|
+
parsePercentage(match[offset + 1]),
|
|
152
|
+
parsePercentage(match[offset + 2])
|
|
153
|
+
) |
|
|
154
|
+
parse1(match[offset + 3])) >>>
|
|
155
|
+
0
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
match = matchers.hwb.exec(color)
|
|
160
|
+
if (match) {
|
|
161
|
+
return (
|
|
162
|
+
(hwbToRgb(
|
|
163
|
+
parse360(match[1]),
|
|
164
|
+
parsePercentage(match[2]),
|
|
165
|
+
parsePercentage(match[3])
|
|
166
|
+
) |
|
|
167
|
+
0xff) >>>
|
|
168
|
+
0
|
|
169
|
+
)
|
|
17
170
|
}
|
|
171
|
+
|
|
172
|
+
const namedColor = getColorNameMap().get(color)
|
|
173
|
+
if (namedColor !== undefined) return namedColor
|
|
174
|
+
|
|
175
|
+
return null
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function getColorNameMap() {
|
|
179
|
+
colorNameMap ||= new Map(
|
|
180
|
+
colorNames
|
|
181
|
+
.split(',')
|
|
182
|
+
.map((name, index) => [
|
|
183
|
+
name,
|
|
184
|
+
Number.parseInt(colorValues.slice(index * 8, index * 8 + 8), 16) >>> 0,
|
|
185
|
+
])
|
|
186
|
+
)
|
|
187
|
+
return colorNameMap
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function isKnownColorName(color: string): boolean {
|
|
191
|
+
return getColorNameMap().has(color)
|
|
18
192
|
}
|
|
19
193
|
|
|
20
194
|
export default normalizeCSSColor
|
package/src/rgba.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function rgba(colorInt: number) {
|
|
2
|
+
const r = Math.round((colorInt & 0xff000000) >>> 24)
|
|
3
|
+
const g = Math.round((colorInt & 0x00ff0000) >>> 16)
|
|
4
|
+
const b = Math.round((colorInt & 0x0000ff00) >>> 8)
|
|
5
|
+
const a = ((colorInt & 0x000000ff) >>> 0) / 255
|
|
6
|
+
return {
|
|
7
|
+
r,
|
|
8
|
+
g,
|
|
9
|
+
b,
|
|
10
|
+
a,
|
|
11
|
+
}
|
|
12
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
export { rgba } from './rgba';
|
|
8
|
+
export declare function normalizeCSSColor(color: string): number | null;
|
|
9
|
+
export declare function isKnownColorName(color: string): boolean;
|
|
8
10
|
export default normalizeCSSColor;
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAwE7B,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgG9D;AAcD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;eAEc,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAI7B,eAAO,MAAM,iBAAiB,EAAW,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;AAGzE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;eAEc,iBAAiB"}
|
package/types/rgba.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgba.d.ts","sourceRoot":"","sources":["../src/rgba.ts"],"names":[],"mappings":"AAAA,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM;;;;;EAWpC"}
|