@tbela99/css-parser
Version:
CSS parser, minifier and validator for node and the browser
1,691 lines (1,681 loc) • 809 kB
JavaScript
'use strict';
var process = require('node:process');
var node_stream = require('node:stream');
var node_fs = require('node:fs');
var promises = require('node:fs/promises');
/**
* syntax validation enum
*/
var SyntaxValidationResult;
(function (SyntaxValidationResult) {
/** valid syntax */
SyntaxValidationResult[SyntaxValidationResult["Valid"] = 0] = "Valid";
/** drop invalid syntax */
SyntaxValidationResult[SyntaxValidationResult["Drop"] = 1] = "Drop";
/** preserve unknown at-rules, declarations and pseudo-classes */
SyntaxValidationResult[SyntaxValidationResult["Lenient"] = 2] = "Lenient";
})(SyntaxValidationResult || (SyntaxValidationResult = {}));
/**
* enum of validation levels
*/
exports.ValidationLevel = void 0;
(function (ValidationLevel) {
/**
* disable validation
*/
ValidationLevel[ValidationLevel["None"] = 0] = "None";
/**
* validate selectors
*/
ValidationLevel[ValidationLevel["Selector"] = 1] = "Selector";
/**
* validate at-rules
*/
ValidationLevel[ValidationLevel["AtRule"] = 2] = "AtRule";
/**
* validate declarations
*/
ValidationLevel[ValidationLevel["Declaration"] = 4] = "Declaration";
/**
* validate selectors and at-rules
*/
ValidationLevel[ValidationLevel["Default"] = 3] = "Default";
/**
* validate selectors, at-rules and declarations
*/
ValidationLevel[ValidationLevel["All"] = 7] = "All"; // selectors + at-rules + declarations
})(exports.ValidationLevel || (exports.ValidationLevel = {}));
/**
* enum of all token types
*/
exports.EnumToken = void 0;
(function (EnumToken) {
/**
* comment token
*/
EnumToken[EnumToken["CommentTokenType"] = 0] = "CommentTokenType";
/**
* cdata section token
*/
EnumToken[EnumToken["CDOCOMMTokenType"] = 1] = "CDOCOMMTokenType";
/**
* style sheet node type
*/
EnumToken[EnumToken["StyleSheetNodeType"] = 2] = "StyleSheetNodeType";
/**
* at-rule node type
*/
EnumToken[EnumToken["AtRuleNodeType"] = 3] = "AtRuleNodeType";
/**
* rule node type
*/
EnumToken[EnumToken["RuleNodeType"] = 4] = "RuleNodeType";
/**
* declaration node type
*/
EnumToken[EnumToken["DeclarationNodeType"] = 5] = "DeclarationNodeType";
/**
* literal token type
*/
EnumToken[EnumToken["LiteralTokenType"] = 6] = "LiteralTokenType";
/**
* identifier token type
*/
EnumToken[EnumToken["IdenTokenType"] = 7] = "IdenTokenType";
/**
* dashed identifier token type
*/
EnumToken[EnumToken["DashedIdenTokenType"] = 8] = "DashedIdenTokenType";
/**
* comma token type
*/
EnumToken[EnumToken["CommaTokenType"] = 9] = "CommaTokenType";
/**
* colon token type
*/
EnumToken[EnumToken["ColonTokenType"] = 10] = "ColonTokenType";
/**
* semicolon token type
*/
EnumToken[EnumToken["SemiColonTokenType"] = 11] = "SemiColonTokenType";
/**
* number token type
*/
EnumToken[EnumToken["NumberTokenType"] = 12] = "NumberTokenType";
/**
* at-rule token type
*/
EnumToken[EnumToken["AtRuleTokenType"] = 13] = "AtRuleTokenType";
/**
* percentage token type
*/
EnumToken[EnumToken["PercentageTokenType"] = 14] = "PercentageTokenType";
/**
* function token type
*/
EnumToken[EnumToken["FunctionTokenType"] = 15] = "FunctionTokenType";
/**
* timeline function token type
*/
EnumToken[EnumToken["TimelineFunctionTokenType"] = 16] = "TimelineFunctionTokenType";
/**
* timing function token type
*/
EnumToken[EnumToken["TimingFunctionTokenType"] = 17] = "TimingFunctionTokenType";
/**
* url function token type
*/
EnumToken[EnumToken["UrlFunctionTokenType"] = 18] = "UrlFunctionTokenType";
/**
* image function token type
*/
EnumToken[EnumToken["ImageFunctionTokenType"] = 19] = "ImageFunctionTokenType";
/**
* string token type
*/
EnumToken[EnumToken["StringTokenType"] = 20] = "StringTokenType";
/**
* unclosed string token type
*/
EnumToken[EnumToken["UnclosedStringTokenType"] = 21] = "UnclosedStringTokenType";
/**
* dimension token type
*/
EnumToken[EnumToken["DimensionTokenType"] = 22] = "DimensionTokenType";
/**
* length token type
*/
EnumToken[EnumToken["LengthTokenType"] = 23] = "LengthTokenType";
/**
* angle token type
*/
EnumToken[EnumToken["AngleTokenType"] = 24] = "AngleTokenType";
/**
* time token type
*/
EnumToken[EnumToken["TimeTokenType"] = 25] = "TimeTokenType";
/**
* frequency token type
*/
EnumToken[EnumToken["FrequencyTokenType"] = 26] = "FrequencyTokenType";
/**
* resolution token type
*/
EnumToken[EnumToken["ResolutionTokenType"] = 27] = "ResolutionTokenType";
/**
* hash token type
*/
EnumToken[EnumToken["HashTokenType"] = 28] = "HashTokenType";
/**
* block start token type
*/
EnumToken[EnumToken["BlockStartTokenType"] = 29] = "BlockStartTokenType";
/**
* block end token type
*/
EnumToken[EnumToken["BlockEndTokenType"] = 30] = "BlockEndTokenType";
/**
* attribute start token type
*/
EnumToken[EnumToken["AttrStartTokenType"] = 31] = "AttrStartTokenType";
/**
* attribute end token type
*/
EnumToken[EnumToken["AttrEndTokenType"] = 32] = "AttrEndTokenType";
/**
* start parentheses token type
*/
EnumToken[EnumToken["StartParensTokenType"] = 33] = "StartParensTokenType";
/**
* end parentheses token type
*/
EnumToken[EnumToken["EndParensTokenType"] = 34] = "EndParensTokenType";
/**
* parentheses token type
*/
EnumToken[EnumToken["ParensTokenType"] = 35] = "ParensTokenType";
/**
* whitespace token type
*/
EnumToken[EnumToken["WhitespaceTokenType"] = 36] = "WhitespaceTokenType";
/**
* include match token type
*/
EnumToken[EnumToken["IncludeMatchTokenType"] = 37] = "IncludeMatchTokenType";
/**
* dash match token type
*/
EnumToken[EnumToken["DashMatchTokenType"] = 38] = "DashMatchTokenType";
/**
* equal match token type
*/
EnumToken[EnumToken["EqualMatchTokenType"] = 39] = "EqualMatchTokenType";
/**
* less than token type
*/
EnumToken[EnumToken["LtTokenType"] = 40] = "LtTokenType";
/**
* less than or equal to token type
*/
EnumToken[EnumToken["LteTokenType"] = 41] = "LteTokenType";
/**
* greater than token type
*/
EnumToken[EnumToken["GtTokenType"] = 42] = "GtTokenType";
/**
* greater than or equal to token type
*/
EnumToken[EnumToken["GteTokenType"] = 43] = "GteTokenType";
/**
* pseudo-class token type
*/
EnumToken[EnumToken["PseudoClassTokenType"] = 44] = "PseudoClassTokenType";
/**
* pseudo-class function token type
*/
EnumToken[EnumToken["PseudoClassFuncTokenType"] = 45] = "PseudoClassFuncTokenType";
/**
* delimiter token type
*/
EnumToken[EnumToken["DelimTokenType"] = 46] = "DelimTokenType";
/**
* URL token type
*/
EnumToken[EnumToken["UrlTokenTokenType"] = 47] = "UrlTokenTokenType";
/**
* end of file token type
*/
EnumToken[EnumToken["EOFTokenType"] = 48] = "EOFTokenType";
/**
* important token type
*/
EnumToken[EnumToken["ImportantTokenType"] = 49] = "ImportantTokenType";
/**
* color token type
*/
EnumToken[EnumToken["ColorTokenType"] = 50] = "ColorTokenType";
/**
* attribute token type
*/
EnumToken[EnumToken["AttrTokenType"] = 51] = "AttrTokenType";
/**
* bad comment token type
*/
EnumToken[EnumToken["BadCommentTokenType"] = 52] = "BadCommentTokenType";
/**
* bad cdo token type
*/
EnumToken[EnumToken["BadCdoTokenType"] = 53] = "BadCdoTokenType";
/**
* bad URL token type
*/
EnumToken[EnumToken["BadUrlTokenType"] = 54] = "BadUrlTokenType";
/**
* bad string token type
*/
EnumToken[EnumToken["BadStringTokenType"] = 55] = "BadStringTokenType";
/**
* binary expression token type
*/
EnumToken[EnumToken["BinaryExpressionTokenType"] = 56] = "BinaryExpressionTokenType";
/**
* unary expression token type
*/
EnumToken[EnumToken["UnaryExpressionTokenType"] = 57] = "UnaryExpressionTokenType";
/**
* flex token type
*/
EnumToken[EnumToken["FlexTokenType"] = 58] = "FlexTokenType";
/**
* token list token type
*/
EnumToken[EnumToken["ListToken"] = 59] = "ListToken";
/* arithmetic tokens */
/**
* addition token type
*/
EnumToken[EnumToken["Add"] = 60] = "Add";
/**
* multiplication token type
*/
EnumToken[EnumToken["Mul"] = 61] = "Mul";
/**
* division token type
*/
EnumToken[EnumToken["Div"] = 62] = "Div";
/**
* subtraction token type
*/
EnumToken[EnumToken["Sub"] = 63] = "Sub";
/* new tokens */
/**
* column combinator token type
*/
EnumToken[EnumToken["ColumnCombinatorTokenType"] = 64] = "ColumnCombinatorTokenType";
/**
* contain match token type
*/
EnumToken[EnumToken["ContainMatchTokenType"] = 65] = "ContainMatchTokenType";
/**
* start match token type
*/
EnumToken[EnumToken["StartMatchTokenType"] = 66] = "StartMatchTokenType";
/**
* end match token type
*/
EnumToken[EnumToken["EndMatchTokenType"] = 67] = "EndMatchTokenType";
/**
* match expression token type
*/
EnumToken[EnumToken["MatchExpressionTokenType"] = 68] = "MatchExpressionTokenType";
/**
* namespace attribute token type
*/
EnumToken[EnumToken["NameSpaceAttributeTokenType"] = 69] = "NameSpaceAttributeTokenType";
/**
* fraction token type
*/
EnumToken[EnumToken["FractionTokenType"] = 70] = "FractionTokenType";
/**
* identifier list token type
*/
EnumToken[EnumToken["IdenListTokenType"] = 71] = "IdenListTokenType";
/**
* grid template function token type
*/
EnumToken[EnumToken["GridTemplateFuncTokenType"] = 72] = "GridTemplateFuncTokenType";
/**
* keyframe rule node type
*/
EnumToken[EnumToken["KeyFramesRuleNodeType"] = 73] = "KeyFramesRuleNodeType";
/**
* class selector token type
*/
EnumToken[EnumToken["ClassSelectorTokenType"] = 74] = "ClassSelectorTokenType";
/**
* universal selector token type
*/
EnumToken[EnumToken["UniversalSelectorTokenType"] = 75] = "UniversalSelectorTokenType";
/**
* child combinator token type
*/
EnumToken[EnumToken["ChildCombinatorTokenType"] = 76] = "ChildCombinatorTokenType";
/**
* descendant combinator token type
*/
EnumToken[EnumToken["DescendantCombinatorTokenType"] = 77] = "DescendantCombinatorTokenType";
/**
* next sibling combinator token type
*/
EnumToken[EnumToken["NextSiblingCombinatorTokenType"] = 78] = "NextSiblingCombinatorTokenType";
/**
* subsequent sibling combinator token type
*/
EnumToken[EnumToken["SubsequentSiblingCombinatorTokenType"] = 79] = "SubsequentSiblingCombinatorTokenType";
/**
* nesting selector token type
*/
EnumToken[EnumToken["NestingSelectorTokenType"] = 80] = "NestingSelectorTokenType";
/**
* invalid rule token type
*/
EnumToken[EnumToken["InvalidRuleTokenType"] = 81] = "InvalidRuleTokenType";
/**
* invalid class selector token type
*/
EnumToken[EnumToken["InvalidClassSelectorTokenType"] = 82] = "InvalidClassSelectorTokenType";
/**
* invalid attribute token type
*/
EnumToken[EnumToken["InvalidAttrTokenType"] = 83] = "InvalidAttrTokenType";
/**
* invalid at rule token type
*/
EnumToken[EnumToken["InvalidAtRuleTokenType"] = 84] = "InvalidAtRuleTokenType";
/**
* media query condition token type
*/
EnumToken[EnumToken["MediaQueryConditionTokenType"] = 85] = "MediaQueryConditionTokenType";
/**
* media feature token type
*/
EnumToken[EnumToken["MediaFeatureTokenType"] = 86] = "MediaFeatureTokenType";
/**
* media feature only token type
*/
EnumToken[EnumToken["MediaFeatureOnlyTokenType"] = 87] = "MediaFeatureOnlyTokenType";
/**
* media feature not token type
*/
EnumToken[EnumToken["MediaFeatureNotTokenType"] = 88] = "MediaFeatureNotTokenType";
/**
* media feature and token type
*/
EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
/**
* media feature or token type
*/
EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
/**
* pseudo page token type
*/
EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
/**
* pseudo element token type
*/
EnumToken[EnumToken["PseudoElementTokenType"] = 92] = "PseudoElementTokenType";
/**
* keyframe at rule node type
*/
EnumToken[EnumToken["KeyframesAtRuleNodeType"] = 93] = "KeyframesAtRuleNodeType";
/**
* invalid declaration node type
*/
EnumToken[EnumToken["InvalidDeclarationNodeType"] = 94] = "InvalidDeclarationNodeType";
/* aliases */
/**
* alias for time token type
*/
EnumToken[EnumToken["Time"] = 25] = "Time";
/**
* alias for identifier token type
*/
EnumToken[EnumToken["Iden"] = 7] = "Iden";
/**
* alias for end of file token type
*/
EnumToken[EnumToken["EOF"] = 48] = "EOF";
/**
* alias for hash token type
*/
EnumToken[EnumToken["Hash"] = 28] = "Hash";
/**
* alias for flex token type
*/
EnumToken[EnumToken["Flex"] = 58] = "Flex";
/**
* alias for angle token type
*/
EnumToken[EnumToken["Angle"] = 24] = "Angle";
/**
* alias for color token type
*/
EnumToken[EnumToken["Color"] = 50] = "Color";
/**
* alias for comma token type
*/
EnumToken[EnumToken["Comma"] = 9] = "Comma";
/**
* alias for string token type
*/
EnumToken[EnumToken["String"] = 20] = "String";
/**
* alias for length token type
*/
EnumToken[EnumToken["Length"] = 23] = "Length";
/**
* alias for number token type
*/
EnumToken[EnumToken["Number"] = 12] = "Number";
/**
* alias for percentage token type
*/
EnumToken[EnumToken["Perc"] = 14] = "Perc";
/**
* alias for literal token type
*/
EnumToken[EnumToken["Literal"] = 6] = "Literal";
/**
* alias for comment token type
*/
EnumToken[EnumToken["Comment"] = 0] = "Comment";
/**
* alias for url function token type
*/
EnumToken[EnumToken["UrlFunc"] = 18] = "UrlFunc";
/**
* alias for dimension token type
*/
EnumToken[EnumToken["Dimension"] = 22] = "Dimension";
/**
* alias for frequency token type
*/
EnumToken[EnumToken["Frequency"] = 26] = "Frequency";
/**
* alias for resolution token type
*/
EnumToken[EnumToken["Resolution"] = 27] = "Resolution";
/**
* alias for whitespace token type
*/
EnumToken[EnumToken["Whitespace"] = 36] = "Whitespace";
/**
* alias for identifier list token type
*/
EnumToken[EnumToken["IdenList"] = 71] = "IdenList";
/**
* alias for dashed identifier token type
*/
EnumToken[EnumToken["DashedIden"] = 8] = "DashedIden";
/**
* alias for grid template function token type
*/
EnumToken[EnumToken["GridTemplateFunc"] = 72] = "GridTemplateFunc";
/**
* alias for image function token type
*/
EnumToken[EnumToken["ImageFunc"] = 19] = "ImageFunc";
/**
* alias for comment node type
*/
EnumToken[EnumToken["CommentNodeType"] = 0] = "CommentNodeType";
/**
* alias for cdata section node type
*/
EnumToken[EnumToken["CDOCOMMNodeType"] = 1] = "CDOCOMMNodeType";
/**
* alias for timing function token type
*/
EnumToken[EnumToken["TimingFunction"] = 17] = "TimingFunction";
/**
* alias for timeline function token type
*/
EnumToken[EnumToken["TimelineFunction"] = 16] = "TimelineFunction";
})(exports.EnumToken || (exports.EnumToken = {}));
/**
* supported color types enum
*/
exports.ColorType = void 0;
(function (ColorType) {
/**
* system colors
*/
ColorType[ColorType["SYS"] = 0] = "SYS";
/**
* deprecated system colors
*/
ColorType[ColorType["DPSYS"] = 1] = "DPSYS";
/**
* colors as literals
*/
ColorType[ColorType["LIT"] = 2] = "LIT";
/**
* colors as hex values
*/
ColorType[ColorType["HEX"] = 3] = "HEX";
/**
* colors as rgb values
*/
ColorType[ColorType["RGBA"] = 4] = "RGBA";
/**
* colors as hsl values
*/
ColorType[ColorType["HSLA"] = 5] = "HSLA";
/**
* colors as hwb values
*/
ColorType[ColorType["HWB"] = 6] = "HWB";
/**
* colors as cmyk values
*/
ColorType[ColorType["CMYK"] = 7] = "CMYK";
/**
* colors as oklab values
* */
ColorType[ColorType["OKLAB"] = 8] = "OKLAB";
/**
* colors as oklch values
* */
ColorType[ColorType["OKLCH"] = 9] = "OKLCH";
/**
* colors as lab values
*/
ColorType[ColorType["LAB"] = 10] = "LAB";
/**
* colors as lch values
*/
ColorType[ColorType["LCH"] = 11] = "LCH";
/**
* colors using color() function
*/
ColorType[ColorType["COLOR"] = 12] = "COLOR";
/**
* color using srgb values
*/
ColorType[ColorType["SRGB"] = 13] = "SRGB";
/**
* color using prophoto-rgb values
*/
ColorType[ColorType["PROPHOTO_RGB"] = 14] = "PROPHOTO_RGB";
/**
* color using a98-rgb values
*/
ColorType[ColorType["A98_RGB"] = 15] = "A98_RGB";
/**
* color using rec2020 values
*/
ColorType[ColorType["REC2020"] = 16] = "REC2020";
/**
* color using display-p3 values
*/
ColorType[ColorType["DISPLAY_P3"] = 17] = "DISPLAY_P3";
/**
* color using srgb-linear values
*/
ColorType[ColorType["SRGB_LINEAR"] = 18] = "SRGB_LINEAR";
/**
* color using xyz-d50 values
*/
ColorType[ColorType["XYZ_D50"] = 19] = "XYZ_D50";
/**
* color using xyz-d65 values
*/
ColorType[ColorType["XYZ_D65"] = 20] = "XYZ_D65";
/**
* light-dark() color function
*/
ColorType[ColorType["LIGHT_DARK"] = 21] = "LIGHT_DARK";
/**
* color-mix() color function
*/
ColorType[ColorType["COLOR_MIX"] = 22] = "COLOR_MIX";
/**
* alias for rgba
*/
ColorType[ColorType["RGB"] = 4] = "RGB";
/**
* alias for hsl
*/
ColorType[ColorType["HSL"] = 5] = "HSL";
/**
* alias for xyz-d65
*/
ColorType[ColorType["XYZ"] = 20] = "XYZ";
/**
* alias for cmyk
*/
ColorType[ColorType["DEVICE_CMYK"] = 7] = "DEVICE_CMYK";
})(exports.ColorType || (exports.ColorType = {}));
// from https://www.w3.org/TR/css-color-4/multiply-matrices.js
/**
* Simple matrix (and vector) multiplication
* Warning: No error handling for incompatible dimensions!
* @author Lea Verou 2020 MIT License
*/
// A is m x n. B is n x p. product is m x p.
function multiplyMatrices(A, B) {
let m = A.length;
if (!Array.isArray(A[0])) {
// A is vector, convert to [[a, b, c, ...]]
A = [A];
}
if (!Array.isArray(B[0])) {
// B is vector, convert to [[a], [b], [c], ...]]
B = B.map((x) => [x]);
}
let p = B[0].length;
let B_cols = B[0].map((_, i) => B.map((x) => x[i])); // transpose B
let product = A.map((row) => B_cols.map((col) => {
if (!Array.isArray(row)) {
return col.reduce((a, c) => a + c * row, 0);
}
return row.reduce((a, c, i) => a + c * (col[i] || 0), 0);
}));
if (m === 1) {
product = product[0]; // Avoid [[a, b, c, ...]]
}
if (p === 1) {
return product.map((x) => x[0]); // Avoid [[a], [b], [c], ...]]
}
return product;
}
const colorPrecision = 6;
const anglePrecision = .001;
const colorRange = {
lab: {
l: [0, 100],
a: [-125, 125],
b: [-125, 125]
},
lch: {
l: [0, 100],
c: [0, 150],
h: [0, 360]
},
oklab: {
l: [0, 1],
a: [-0.4, .4],
b: [-0.4, 0.4]
},
oklch: {
l: [0, 1],
a: [0, .4],
b: [0, 0.4]
}
};
const timelineFunc = ['view', 'scroll'];
const generalEnclosedFunc = ['selector', 'font-tech', 'font-format', 'media', 'supports'];
const timingFunc = ['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear', 'step-start', 'step-end', 'steps', 'cubic-bezier'];
const funcLike = [
exports.EnumToken.ParensTokenType,
exports.EnumToken.FunctionTokenType,
exports.EnumToken.UrlFunctionTokenType,
exports.EnumToken.StartParensTokenType,
exports.EnumToken.ImageFunctionTokenType,
exports.EnumToken.TimingFunctionTokenType,
exports.EnumToken.TimingFunctionTokenType,
exports.EnumToken.PseudoClassFuncTokenType,
exports.EnumToken.GridTemplateFuncTokenType
];
const colorsFunc = ['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'device-cmyk', 'color-mix', 'color', 'oklab', 'lab', 'oklch', 'lch', 'light-dark'];
const colorFuncColorSpace = ['srgb', 'srgb-linear', 'display-p3', 'prophoto-rgb', 'a98-rgb', 'rec2020', 'xyz', 'xyz-d65', 'xyz-d50'];
const D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
const k = Math.pow(29, 3) / Math.pow(3, 3);
const e = Math.pow(6, 3) / Math.pow(29, 3);
// color module v4
const systemColors = new Set(['ActiveText', 'ButtonBorder', 'ButtonFace', 'ButtonText', 'Canvas', 'CanvasText', 'Field', 'FieldText', 'GrayText', 'Highlight', 'HighlightText', 'LinkText', 'Mark', 'MarkText', 'VisitedText', '-webkit-focus-ring-color'].map(m => m.toLowerCase()));
// deprecated
const deprecatedSystemColors = new Set(['ActiveBorder', 'ActiveCaption', 'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow', 'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText', 'InactiveBorder', 'InactiveCaption', 'InactiveCaptionText', 'InfoBackground', 'InfoText', 'Menu', 'MenuText', 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace', 'ThreeDHighlight', 'ThreeDLightShadow', 'ThreeDShadow', 'Window', 'WindowFrame', 'WindowText'].map(t => t.toLowerCase()));
// name to color
const COLORS_NAMES = Object.seal({
'aliceblue': '#f0f8ff',
'antiquewhite': '#faebd7',
'aqua': '#00ffff',
'aquamarine': '#7fffd4',
'azure': '#f0ffff',
'beige': '#f5f5dc',
'bisque': '#ffe4c4',
'black': '#000000',
'blanchedalmond': '#ffebcd',
'blue': '#0000ff',
'blueviolet': '#8a2be2',
'brown': '#a52a2a',
'burlywood': '#deb887',
'cadetblue': '#5f9ea0',
'chartreuse': '#7fff00',
'chocolate': '#d2691e',
'coral': '#ff7f50',
'cornflowerblue': '#6495ed',
'cornsilk': '#fff8dc',
'crimson': '#dc143c',
'cyan': '#00ffff',
'darkblue': '#00008b',
'darkcyan': '#008b8b',
'darkgoldenrod': '#b8860b',
'darkgray': '#a9a9a9',
'darkgrey': '#a9a9a9',
'darkgreen': '#006400',
'darkkhaki': '#bdb76b',
'darkmagenta': '#8b008b',
'darkolivegreen': '#556b2f',
'darkorange': '#ff8c00',
'darkorchid': '#9932cc',
'darkred': '#8b0000',
'darksalmon': '#e9967a',
'darkseagreen': '#8fbc8f',
'darkslateblue': '#483d8b',
'darkslategray': '#2f4f4f',
'darkslategrey': '#2f4f4f',
'darkturquoise': '#00ced1',
'darkviolet': '#9400d3',
'deeppink': '#ff1493',
'deepskyblue': '#00bfff',
'dimgray': '#696969',
'dimgrey': '#696969',
'dodgerblue': '#1e90ff',
'firebrick': '#b22222',
'floralwhite': '#fffaf0',
'forestgreen': '#228b22',
'fuchsia': '#ff00ff',
'gainsboro': '#dcdcdc',
'ghostwhite': '#f8f8ff',
'gold': '#ffd700',
'goldenrod': '#daa520',
'gray': '#808080',
'grey': '#808080',
'green': '#008000',
'greenyellow': '#adff2f',
'honeydew': '#f0fff0',
'hotpink': '#ff69b4',
'indianred': '#cd5c5c',
'indigo': '#4b0082',
'ivory': '#fffff0',
'khaki': '#f0e68c',
'lavender': '#e6e6fa',
'lavenderblush': '#fff0f5',
'lawngreen': '#7cfc00',
'lemonchiffon': '#fffacd',
'lightblue': '#add8e6',
'lightcoral': '#f08080',
'lightcyan': '#e0ffff',
'lightgoldenrodyellow': '#fafad2',
'lightgray': '#d3d3d3',
'lightgrey': '#d3d3d3',
'lightgreen': '#90ee90',
'lightpink': '#ffb6c1',
'lightsalmon': '#ffa07a',
'lightseagreen': '#20b2aa',
'lightskyblue': '#87cefa',
'lightslategray': '#778899',
'lightslategrey': '#778899',
'lightsteelblue': '#b0c4de',
'lightyellow': '#ffffe0',
'lime': '#00ff00',
'limegreen': '#32cd32',
'linen': '#faf0e6',
'magenta': '#ff00ff',
'maroon': '#800000',
'mediumaquamarine': '#66cdaa',
'mediumblue': '#0000cd',
'mediumorchid': '#ba55d3',
'mediumpurple': '#9370d8',
'mediumseagreen': '#3cb371',
'mediumslateblue': '#7b68ee',
'mediumspringgreen': '#00fa9a',
'mediumturquoise': '#48d1cc',
'mediumvioletred': '#c71585',
'midnightblue': '#191970',
'mintcream': '#f5fffa',
'mistyrose': '#ffe4e1',
'moccasin': '#ffe4b5',
'navajowhite': '#ffdead',
'navy': '#000080',
'oldlace': '#fdf5e6',
'olive': '#808000',
'olivedrab': '#6b8e23',
'orange': '#ffa500',
'orangered': '#ff4500',
'orchid': '#da70d6',
'palegoldenrod': '#eee8aa',
'palegreen': '#98fb98',
'paleturquoise': '#afeeee',
'palevioletred': '#d87093',
'papayawhip': '#ffefd5',
'peachpuff': '#ffdab9',
'peru': '#cd853f',
'pink': '#ffc0cb',
'plum': '#dda0dd',
'powderblue': '#b0e0e6',
'purple': '#800080',
'red': '#ff0000',
'rosybrown': '#bc8f8f',
'royalblue': '#4169e1',
'saddlebrown': '#8b4513',
'salmon': '#fa8072',
'sandybrown': '#f4a460',
'seagreen': '#2e8b57',
'seashell': '#fff5ee',
'sienna': '#a0522d',
'silver': '#c0c0c0',
'skyblue': '#87ceeb',
'slateblue': '#6a5acd',
'slategray': '#708090',
'slategrey': '#708090',
'snow': '#fffafa',
'springgreen': '#00ff7f',
'steelblue': '#4682b4',
'tan': '#d2b48c',
'teal': '#008080',
'thistle': '#d8bfd8',
'tomato': '#ff6347',
'turquoise': '#40e0d0',
'violet': '#ee82ee',
'wheat': '#f5deb3',
'white': '#ffffff',
'whitesmoke': '#f5f5f5',
'yellow': '#ffff00',
'yellowgreen': '#9acd32',
'rebeccapurple': '#663399',
'transparent': '#00000000'
});
// color to name
const NAMES_COLORS = Object.seal(Object.entries(COLORS_NAMES).reduce((acc, [key, value]) => {
acc[value] = key;
return acc;
}, Object.create(null)));
function hex2lchToken(token) {
const values = hex2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function rgb2lchToken(token) {
const values = rgb2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function hsl2lchToken(token) {
const values = hsl2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function hwb2lchToken(token) {
const values = hwb2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function cmyk2lchToken(token) {
const values = cmyk2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function lab2lchToken(token) {
const values = lab2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function oklab2lchToken(token) {
const values = oklab2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function oklch2lchToken(token) {
const values = oklch2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function color2lchToken(token) {
const values = color2lchvalues(token);
if (values == null) {
return null;
}
return lchToken(values);
}
function lchToken(values) {
values[2] = toPrecisionAngle(values[2]);
const chi = [
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[0]) },
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[1]) },
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
];
if (values.length == 4) {
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
typ: exports.EnumToken.PercentageTokenType,
val: values[3] * 100
});
}
return {
typ: exports.EnumToken.ColorTokenType,
val: 'lch',
chi,
kin: exports.ColorType.LCH
};
}
function hex2lchvalues(token) {
const values = hex2labvalues(token);
// @ts-ignore
return values == null ? null : labvalues2lchvalues(...values);
}
function rgb2lchvalues(token) {
const values = rgb2labvalues(token);
// @ts-ignore
return values == null ? null : labvalues2lchvalues(...values);
}
function hsl2lchvalues(token) {
const values = hsl2labvalues(token);
// @ts-ignore
return values == null ? null : labvalues2lchvalues(...values);
}
function hwb2lchvalues(token) {
const values = hwb2labvalues(token);
// @ts-ignore
return values == null ? null : labvalues2lchvalues(...values);
}
function lab2lchvalues(token) {
const values = getLABComponents(token);
// @ts-ignore
return values == null ? null : labvalues2lchvalues(...values);
}
function srgb2lch(r, g, blue, alpha) {
// @ts-ignore
return labvalues2lchvalues(...srgb2labvalues(r, g, blue, alpha));
}
function oklab2lchvalues(token) {
const values = oklab2labvalues(token);
// @ts-ignore
return values == null ? null : labvalues2lchvalues(...values);
}
function cmyk2lchvalues(token) {
const values = cmyk2srgbvalues(token);
// @ts-ignore
return values == null ? null : srgb2lch(...values);
}
function oklch2lchvalues(token) {
const values = oklch2labvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return labvalues2lchvalues(...values);
}
function color2lchvalues(token) {
const values = color2srgbvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return srgb2lch(...values);
}
function labvalues2lchvalues(l, a, b, alpha = null) {
let c = Math.sqrt(a * a + b * b);
let h = Math.atan2(b, a) * 180 / Math.PI;
if (h < 0) {
h += 360;
}
if (c < .0001) {
c = h = 0;
}
return alpha == null ? [l, c, h] : [l, c, h, alpha];
}
function xyz2lchvalues(x, y, z, alpha) {
// @ts-ignore(
const lch = labvalues2lchvalues(...xyz2lab(x, y, z));
return alpha == null || alpha == 1 ? lch : lch.concat(alpha);
}
function getLCHComponents(token) {
const components = getComponents(token);
if (components == null) {
return null;
}
for (let i = 0; i < components.length; i++) {
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
return null;
}
}
// @ts-ignore
let t = components[0];
// @ts-ignore
const l = getNumber(t) * (t.typ == exports.EnumToken.PercentageTokenType ? 100 : 1);
// @ts-ignore
t = components[1];
// @ts-ignore
const c = getNumber(t) * (t.typ == exports.EnumToken.PercentageTokenType ? 150 : 1);
// @ts-ignore
t = components[2];
// @ts-ignore
const h = getAngle(t) * 360;
// @ts-ignore
t = components[3];
// @ts-ignore
const alpha = t == null ? 1 : getNumber(t);
return alpha == null ? [l, c, h] : [l, c, h, alpha];
}
/*
*/
function xyzd502lch(x, y, z, alpha) {
// @ts-ignore
const [l, a, b] = xyz2lab(...XYZ_D50_to_D65(x, y, z));
// L in range [0,100]. For use in CSS, add a percent
return labvalues2lchvalues(l, a, b, alpha);
}
function XYZ_D65_to_D50(x, y, z, alpha = null) {
// Bradford chromatic adaptation from D65 to D50
// The matrix below is the result of three operations:
// - convert from XYZ to retinal cone domain
// - scale components from one reference white to another
// - convert back to XYZ
// see https://github.com/LeaVerou/color.js/pull/354/files
let M = [
[1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
[0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
[-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]
];
return multiplyMatrices(M, [x, y, z]).concat(alpha == null || alpha == 1 ? [] : [alpha]);
}
function xyzd502srgb(x, y, z, alpha = null) {
// @ts-ignore
return lsrgb2srgbvalues(
/* r: */
x * 3.1341359569958707 -
y * 1.6173863321612538 -
0.4906619460083532 * z,
/* g: */
x * -0.978795502912089 +
y * 1.916254567259524 +
0.03344273116131949 * z,
/* b: */
x * 0.07195537988411677 -
y * 0.2289768264158322 +
1.405386058324125 * z, alpha);
}
function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
// convert XYZ to linear-light sRGB
const M = [
[12831 / 3959, -329 / 214, -1974 / 3959],
[-851781 / 878810, 1648619 / 878810, 36519 / 878810],
[705 / 12673, -2585 / 12673, 705 / 667],
];
const XYZ = [x, y, z]; // convert to XYZ
return multiplyMatrices(M, XYZ).map((v) => v).concat(alpha == null || alpha == 1 ? [] : [alpha]);
}
function XYZ_D50_to_D65(x, y, z) {
// Bradford chromatic adaptation from D50 to D65
const M = [
[0.9554734527042182, -0.023098536874261423, 0.0632593086610217],
[-0.028369706963208136, 1.0099954580058226, 0.021041398966943008],
[0.012314001688319899, -0.020507696433477912, 1.3303659366080753]
];
const XYZ = [x, y, z];
return multiplyMatrices(M, XYZ); //.map((v: number) => v);
}
// xyz d65
function srgb2xyz(r, g, b, alpha) {
[r, g, b] = srgb2lsrgbvalues(r, g, b);
// xyx d65
let rgb = [
0.4123907992659595 * r +
0.35758433938387796 * g +
0.1804807884018343 * b,
0.21263900587151036 * r +
0.7151686787677559 * g +
0.07219231536073371 * b,
0.01933081871559185 * r +
0.11919477979462599 * g +
0.9505321522496606 * b
];
if (alpha != null && alpha != 1) {
rgb.push(alpha);
}
return rgb;
}
// xyz d50
function srgb2xyz_d50(r, g, b, alpha) {
// xyx d65
// @ts-ignore
let rgb = XYZ_D65_to_D50(...srgb2xyz(r, g, b));
if (alpha != null && alpha != 1) {
rgb.push(alpha);
}
return rgb;
}
function hex2oklchToken(token) {
const values = hex2oklchvalues(token);
return oklchToken(values);
}
function rgb2oklchToken(token) {
const values = rgb2oklchvalues(token);
if (values == null) {
return null;
}
return oklchToken(values);
}
function hsl2oklchToken(token) {
const values = hsl2oklchvalues(token);
if (values == null) {
return null;
}
return oklchToken(values);
}
function hwb2oklchToken(token) {
const values = hwb2oklchvalues(token);
if (values == null) {
return null;
}
return oklchToken(values);
}
function cmyk2oklchToken(token) {
const values = cmyk2oklchvalues(token);
if (values == null) {
return null;
}
return oklchToken(values);
}
function lab2oklchToken(token) {
const values = lab2oklchvalues(token);
if (values == null) {
return null;
}
return oklchToken(values);
}
function oklab2oklchToken(token) {
const values = oklab2oklchvalues(token);
if (values == null) {
return null;
}
return oklchToken(values);
}
function lch2oklchToken(token) {
const values = lch2oklchvalues(token);
if (values == null) {
return null;
}
return oklchToken(values);
}
function color2oklchToken(token) {
const values = color2srgbvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return oklchToken(srgb2oklch(...values));
}
function oklchToken(values) {
values[2] = toPrecisionAngle(values[2]);
const chi = [
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[0]) },
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[1]) },
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
];
if (values.length == 4) {
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
typ: exports.EnumToken.PercentageTokenType,
val: values[3] * 100
});
}
return {
typ: exports.EnumToken.ColorTokenType,
val: 'oklch',
chi,
kin: exports.ColorType.OKLCH
};
}
function hex2oklchvalues(token) {
// @ts-ignore
return labvalues2lchvalues(...hex2oklabvalues(token));
}
function rgb2oklchvalues(token) {
const values = rgb2oklabvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return labvalues2lchvalues(...values);
}
function hsl2oklchvalues(token) {
// @ts-ignore
return labvalues2lchvalues(...hsl2oklabvalues(token));
}
function hwb2oklchvalues(token) {
// @ts-ignore
return labvalues2lchvalues(...hwb2oklabvalues(token));
}
function cmyk2oklchvalues(token) {
const values = cmyk2srgbvalues(token);
// @ts-ignore
return values == null ? null : srgb2oklch(...values);
}
function lab2oklchvalues(token) {
const values = lab2oklabvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return labvalues2lchvalues(...values);
}
function lch2oklchvalues(token) {
const values = lch2oklabvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return labvalues2lchvalues(...values);
}
function oklab2oklchvalues(token) {
const values = getOKLABComponents(token);
if (values == null) {
return null;
}
// @ts-ignore
return labvalues2lchvalues(...values);
}
function srgb2oklch(r, g, blue, alpha) {
// @ts-ignore
return labvalues2lchvalues(...srgb2oklab(r, g, blue, alpha));
}
function getOKLCHComponents(token) {
const components = getComponents(token);
if (components == null) {
return null;
}
for (let i = 0; i < components.length; i++) {
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
return [];
}
}
// @ts-ignore
let t = components[0];
// @ts-ignore
const l = getNumber(t);
// @ts-ignore
t = components[1];
// @ts-ignore
const c = getNumber(t) * (t.typ == exports.EnumToken.PercentageTokenType ? .4 : 1);
// @ts-ignore
t = components[2];
// @ts-ignore
const h = getAngle(t) * 360;
// @ts-ignore
t = components[3];
// @ts-ignore
const alpha = t == null || (t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t);
return [l, c, h, alpha];
}
function hex2oklabToken(token) {
const values = hex2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function rgb2oklabToken(token) {
const values = rgb2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function hsl2oklabToken(token) {
const values = hsl2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function hwb2oklabToken(token) {
const values = hwb2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function cmyk2oklabToken(token) {
const values = cmyk2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function lab2oklabToken(token) {
const values = lab2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function lch2oklabToken(token) {
const values = lch2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function oklch2oklabToken(token) {
const values = oklch2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function color2oklabToken(token) {
const values = color2oklabvalues(token);
if (values == null) {
return null;
}
return oklabToken(values);
}
function oklabToken(values) {
const chi = [
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[0]) },
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[1]) },
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[2]) },
];
if (values.length == 4) {
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
typ: exports.EnumToken.PercentageTokenType,
val: values[3] * 100
});
}
return {
typ: exports.EnumToken.ColorTokenType,
val: 'oklab',
chi,
kin: exports.ColorType.OKLAB
};
}
function hex2oklabvalues(token) {
const values = hex2srgbvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return srgb2oklab(...values);
}
function rgb2oklabvalues(token) {
const values = rgb2srgb(token);
if (values == null) {
return null;
}
// @ts-ignore
return srgb2oklab(...values);
}
function hsl2oklabvalues(token) {
const values = hsl2srgb(token);
if (values == null) {
return null;
}
// @ts-ignore
return srgb2oklab(...values);
}
function hwb2oklabvalues(token) {
// @ts-ignore
return srgb2oklab(...hwb2srgbvalues(token));
}
function cmyk2oklabvalues(token) {
const values = cmyk2srgbvalues(token);
// @ts-ignore
return values == null ? null : srgb2oklab(...values);
}
function lab2oklabvalues(token) {
const values = lab2srgbvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return srgb2oklab(...values);
}
function lch2oklabvalues(token) {
const values = lch2srgbvalues(token);
// @ts-ignore
return values == null ? null : srgb2oklab(...values);
}
function oklch2oklabvalues(token) {
const values = getOKLCHComponents(token);
// @ts-ignore
return values == null ? null : lchvalues2labvalues(...values);
}
function color2oklabvalues(token) {
const values = color2srgbvalues(token);
// @ts-ignore
return values == null ? null : srgb2oklab(...values);
}
function srgb2oklab(r, g, blue, alpha) {
[r, g, blue] = srgb2lsrgbvalues(r, g, blue);
let L = Math.cbrt(0.41222147079999993 * r + 0.5363325363 * g + 0.0514459929 * blue);
let M = Math.cbrt(0.2119034981999999 * r + 0.6806995450999999 * g + 0.1073969566 * blue);
let S = Math.cbrt(0.08830246189999998 * r + 0.2817188376 * g + 0.6299787005000002 * blue);
const l = 0.2104542553 * L + 0.793617785 * M - 0.0040720468 * S;
const a = r == g && g == blue ? 0 : 1.9779984951 * L - 2.428592205 * M + 0.4505937099 * S;
const b = r == g && g == blue ? 0 : 0.0259040371 * L + 0.7827717662 * M - 0.808675766 * S;
return alpha == null || alpha == 1 ? [l, a, b] : [l, a, b, alpha];
}
function getOKLABComponents(token) {
const components = getComponents(token);
if (components == null || components.length < 3) {
return null;
}
// @ts-ignore
let t = components[0];
// @ts-ignore
const l = getNumber(t);
// @ts-ignore
t = components[1];
// @ts-ignore
const a = getNumber(t) * (t.typ == exports.EnumToken.PercentageTokenType ? .4 : 1);
// @ts-ignore
t = components[2];
// @ts-ignore
const b = getNumber(t) * (t.typ == exports.EnumToken.PercentageTokenType ? .4 : 1);
// @ts-ignore
let alpha = null;
if (components.length > 3) {
alpha = getNumber(components[3]);
}
const rgb = [l, a, b];
if (alpha != 1 && alpha != null) {
rgb.push(alpha);
}
return rgb;
}
function OKLab_to_XYZ(l, a, b, alpha = null) {
// Given OKLab, convert to XYZ relative to D65
const LMStoXYZ = [
[1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
[-0.0405757452148008, 1.1122868032803170, -0.0717110580655164],
[-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]
];
const OKLabtoLMS = [
[1.0000000000000000, 0.3963377773761749, 0.2158037573099136],
[1.0000000000000000, -0.1055613458156586, -0.0638541728258133],
[1.0000000000000000, -0.0894841775298119, -1.2914855480194092]
];
const LMSnl = multiplyMatrices(OKLabtoLMS, [l, a, b]);
const xyz = multiplyMatrices(LMStoXYZ, LMSnl.map((c) => c ** 3));
if (alpha != null) {
xyz.push(alpha);
}
return xyz;
}
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
function OKLab_to_sRGB(l, a, b) {
let L = Math.pow(l * 0.99999999845051981432 +
0.39633779217376785678 * a +
0.21580375806075880339 * b, 3);
let M = Math.pow(l * 1.0000000088817607767 -
0.1055613423236563494 * a -
0.063854174771705903402 * b, 3);
let S = Math.pow(l * 1.0000000546724109177 -
0.089484182094965759684 * a -
1.2914855378640917399 * b, 3);
return lsrgb2srgbvalues(
/* r: */
4.076741661347994 * L -
3.307711590408193 * M +
0.230969928729428 * S,
/* g: */
-1.2684380040921763 * L +
2.6097574006633715 * M -
0.3413193963102197 * S,
/* b: */
-0.004196086541837188 * L -
0.7034186144594493 * M +
1.7076147009309444 * S);
}
function hex2labToken(token) {
const values = hex2labvalues(token);
return values == null ? null : labToken(values);
}
function rgb2labToken(token) {
const values = rgb2labvalues(token);
if (values == null) {
return null;
}
return labToken(values);
}
function hsl2labToken(token) {
const values = hsl2labvalues(token);
if (values == null) {
return null;
}
return labToken(values);
}
function hwb2labToken(token) {
const values = hwb2labvalues(token);
if (values == null) {
return null;
}
return labToken(values);
}
function cmyk2labToken(token) {
const values = cmyk2labvalues(token);
if (values == null) {
return null;
}
return labToken(values);
}
function lch2labToken(token) {
const values = lch2labvalues(token);
if (values == null) {
return null;
}
return labToken(values);
}
function oklab2labToken(token) {
const values = oklab2labvalues(token);
if (values == null) {
return null;
}
return labToken(values);
}
function oklch2labToken(token) {
const values = oklch2labvalues(token);
if (values == null) {
return null;
}
return labToken(values);
}
function color2labToken(token) {
const values = color2labvalues(token);
if (values == null) {
return null;
}
return labToken(values);
}
function labToken(values) {
const chi = [
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[0]) },
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[1]) },
{ typ: exports.EnumToken.NumberTokenType, val: toPrecisionValue(values[2]) },
];
if (values.length == 4) {
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
typ: exports.EnumToken.PercentageTokenType,
val: values[3] * 100
});
}
return {
typ: exports.EnumToken.ColorTokenType,
val: 'lab',
chi,
kin: exports.ColorType.LAB
};
}
// L: 0% = 0.0, 100% = 100.0
// for a and b: -100% = -125, 100% = 125
function hex2labvalues(token) {
const values = hex2srgbvalues(token);
// @ts-ignore
return values == null ? null : srgb2labvalues(...values);
}
function rgb2labvalues(token) {
const values = rgb2srgb(token);
// @ts-ignore
return values == null ? null : srgb2labvalues(...values);
}
function cmyk2labvalues(token) {
const values = cmyk2srgbvalues(token);
// @ts-ignore
return values == null ? null : srgb2labvalues(...values);
}
function hsl2labvalues(token) {
const values = hsl2srgb(token);
if (values == null) {
return null;
}
// @ts-ignore
return srgb2labvalues(...values);
}
function hwb2labvalues(token) {
const values = hwb2srgbvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return srgb2labvalues(...values);
}
function lch2labvalues(token) {
const values = getLCHComponents(token);
// @ts-ignore
return values == null ? null : lchvalues2labvalues(...values);
}
function oklab2labvalues(token) {
const values = getOKLABComponents(token);
if (values == null) {
return null;
}
// @ts-ignore
return xyz2lab(...XYZ_D65_to_D50(...OKLab_to_XYZ(...values)));
}
function oklch2labvalues(token) {
const values = oklch2srgbvalues(token);
if (values == null) {
return null;
}
// @ts-ignore
return srgb2labvalues(...values);
}
function color2labvalues(token)