UNPKG

tailwind-material-colors

Version:

TailwindCSS Plugin to use the Material 3 Color System with Tailwind

1 lines 376 kB
{"version":3,"file":"index.min.cjs","sources":["../node_modules/@material/material-color-utilities/utils/math_utils.js","../node_modules/@material/material-color-utilities/utils/color_utils.js","../node_modules/@material/material-color-utilities/hct/viewing_conditions.js","../node_modules/@material/material-color-utilities/hct/cam16.js","../node_modules/@material/material-color-utilities/hct/hct_solver.js","../node_modules/@material/material-color-utilities/hct/hct.js","../node_modules/@material/material-color-utilities/blend/blend.js","../node_modules/@material/material-color-utilities/contrast/contrast.js","../node_modules/@material/material-color-utilities/dislike/dislike_analyzer.js","../node_modules/@material/material-color-utilities/dynamiccolor/dynamic_color.js","../node_modules/@material/material-color-utilities/scheme/variant.js","../node_modules/@material/material-color-utilities/dynamiccolor/contrast_curve.js","../node_modules/@material/material-color-utilities/dynamiccolor/tone_delta_pair.js","../node_modules/@material/material-color-utilities/dynamiccolor/material_dynamic_colors.js","../node_modules/@material/material-color-utilities/palettes/tonal_palette.js","../node_modules/@material/material-color-utilities/palettes/core_palette.js","../node_modules/@material/material-color-utilities/scheme/dynamic_scheme.js","../node_modules/@material/material-color-utilities/temperature/temperature_cache.js","../node_modules/@material/material-color-utilities/scheme/scheme_content.js","../node_modules/@material/material-color-utilities/scheme/scheme_expressive.js","../node_modules/@material/material-color-utilities/scheme/scheme_fidelity.js","../node_modules/@material/material-color-utilities/scheme/scheme_monochrome.js","../node_modules/@material/material-color-utilities/scheme/scheme_neutral.js","../node_modules/@material/material-color-utilities/scheme/scheme_tonal_spot.js","../node_modules/@material/material-color-utilities/scheme/scheme_vibrant.js","../node_modules/@material/material-color-utilities/utils/string_utils.js","../src/kebabize.js","../src/tailwindThemeFromColor.js","../node_modules/@material/material-color-utilities/utils/theme_utils.js","../node_modules/tailwindcss/lib/public/create-plugin.js","../node_modules/tailwindcss/lib/util/createPlugin.js","../node_modules/tailwindcss/plugin.js","../node_modules/tailwindcss/lib/util/toColorValue.js","../node_modules/tailwindcss/lib/util/flattenColorPalette.js","../node_modules/tailwindcss/lib/util/color.js","../node_modules/tailwindcss/lib/util/colorNames.js","../node_modules/tailwindcss/lib/util/withAlphaVariable.js","../node_modules/tailwind-material-surfaces/src/index.js","../node_modules/tailwindcss-color-mix/src/index.js","../node_modules/color-name/index.js","../node_modules/simple-swizzle/node_modules/is-arrayish/index.js","../node_modules/color-string/index.js","../node_modules/simple-swizzle/index.js","../node_modules/color-convert/conversions.js","../node_modules/color-convert/route.js","../node_modules/color-convert/index.js","../node_modules/color/index.js","../node_modules/tailwind-mode-aware-colors/src/index.js","../src/index.js"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// This file is automatically generated. Do not modify it.\n/**\n * Utility methods for mathematical operations.\n */\n/**\n * The signum function.\n *\n * @return 1 if num > 0, -1 if num < 0, and 0 if num = 0\n */\nexport function signum(num) {\n if (num < 0) {\n return -1;\n }\n else if (num === 0) {\n return 0;\n }\n else {\n return 1;\n }\n}\n/**\n * The linear interpolation function.\n *\n * @return start if amount = 0 and stop if amount = 1\n */\nexport function lerp(start, stop, amount) {\n return (1.0 - amount) * start + amount * stop;\n}\n/**\n * Clamps an integer between two integers.\n *\n * @return input when min <= input <= max, and either min or max\n * otherwise.\n */\nexport function clampInt(min, max, input) {\n if (input < min) {\n return min;\n }\n else if (input > max) {\n return max;\n }\n return input;\n}\n/**\n * Clamps an integer between two floating-point numbers.\n *\n * @return input when min <= input <= max, and either min or max\n * otherwise.\n */\nexport function clampDouble(min, max, input) {\n if (input < min) {\n return min;\n }\n else if (input > max) {\n return max;\n }\n return input;\n}\n/**\n * Sanitizes a degree measure as an integer.\n *\n * @return a degree measure between 0 (inclusive) and 360\n * (exclusive).\n */\nexport function sanitizeDegreesInt(degrees) {\n degrees = degrees % 360;\n if (degrees < 0) {\n degrees = degrees + 360;\n }\n return degrees;\n}\n/**\n * Sanitizes a degree measure as a floating-point number.\n *\n * @return a degree measure between 0.0 (inclusive) and 360.0\n * (exclusive).\n */\nexport function sanitizeDegreesDouble(degrees) {\n degrees = degrees % 360.0;\n if (degrees < 0) {\n degrees = degrees + 360.0;\n }\n return degrees;\n}\n/**\n * Sign of direction change needed to travel from one angle to\n * another.\n *\n * For angles that are 180 degrees apart from each other, both\n * directions have the same travel distance, so either direction is\n * shortest. The value 1.0 is returned in this case.\n *\n * @param from The angle travel starts from, in degrees.\n * @param to The angle travel ends at, in degrees.\n * @return -1 if decreasing from leads to the shortest travel\n * distance, 1 if increasing from leads to the shortest travel\n * distance.\n */\nexport function rotationDirection(from, to) {\n const increasingDifference = sanitizeDegreesDouble(to - from);\n return increasingDifference <= 180.0 ? 1.0 : -1.0;\n}\n/**\n * Distance of two points on a circle, represented using degrees.\n */\nexport function differenceDegrees(a, b) {\n return 180.0 - Math.abs(Math.abs(a - b) - 180.0);\n}\n/**\n * Multiplies a 1x3 row vector with a 3x3 matrix.\n */\nexport function matrixMultiply(row, matrix) {\n const a = row[0] * matrix[0][0] + row[1] * matrix[0][1] + row[2] * matrix[0][2];\n const b = row[0] * matrix[1][0] + row[1] * matrix[1][1] + row[2] * matrix[1][2];\n const c = row[0] * matrix[2][0] + row[1] * matrix[2][1] + row[2] * matrix[2][2];\n return [a, b, c];\n}\n//# sourceMappingURL=math_utils.js.map","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// This file is automatically generated. Do not modify it.\nimport * as mathUtils from './math_utils.js';\n/**\n * Color science utilities.\n *\n * Utility methods for color science constants and color space\n * conversions that aren't HCT or CAM16.\n */\nconst SRGB_TO_XYZ = [\n [0.41233895, 0.35762064, 0.18051042],\n [0.2126, 0.7152, 0.0722],\n [0.01932141, 0.11916382, 0.95034478],\n];\nconst XYZ_TO_SRGB = [\n [\n 3.2413774792388685,\n -1.5376652402851851,\n -0.49885366846268053,\n ],\n [\n -0.9691452513005321,\n 1.8758853451067872,\n 0.04156585616912061,\n ],\n [\n 0.05562093689691305,\n -0.20395524564742123,\n 1.0571799111220335,\n ],\n];\nconst WHITE_POINT_D65 = [95.047, 100.0, 108.883];\n/**\n * Converts a color from RGB components to ARGB format.\n */\nexport function argbFromRgb(red, green, blue) {\n return (255 << 24 | (red & 255) << 16 | (green & 255) << 8 | blue & 255) >>>\n 0;\n}\n/**\n * Converts a color from linear RGB components to ARGB format.\n */\nexport function argbFromLinrgb(linrgb) {\n const r = delinearized(linrgb[0]);\n const g = delinearized(linrgb[1]);\n const b = delinearized(linrgb[2]);\n return argbFromRgb(r, g, b);\n}\n/**\n * Returns the alpha component of a color in ARGB format.\n */\nexport function alphaFromArgb(argb) {\n return argb >> 24 & 255;\n}\n/**\n * Returns the red component of a color in ARGB format.\n */\nexport function redFromArgb(argb) {\n return argb >> 16 & 255;\n}\n/**\n * Returns the green component of a color in ARGB format.\n */\nexport function greenFromArgb(argb) {\n return argb >> 8 & 255;\n}\n/**\n * Returns the blue component of a color in ARGB format.\n */\nexport function blueFromArgb(argb) {\n return argb & 255;\n}\n/**\n * Returns whether a color in ARGB format is opaque.\n */\nexport function isOpaque(argb) {\n return alphaFromArgb(argb) >= 255;\n}\n/**\n * Converts a color from ARGB to XYZ.\n */\nexport function argbFromXyz(x, y, z) {\n const matrix = XYZ_TO_SRGB;\n const linearR = matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z;\n const linearG = matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z;\n const linearB = matrix[2][0] * x + matrix[2][1] * y + matrix[2][2] * z;\n const r = delinearized(linearR);\n const g = delinearized(linearG);\n const b = delinearized(linearB);\n return argbFromRgb(r, g, b);\n}\n/**\n * Converts a color from XYZ to ARGB.\n */\nexport function xyzFromArgb(argb) {\n const r = linearized(redFromArgb(argb));\n const g = linearized(greenFromArgb(argb));\n const b = linearized(blueFromArgb(argb));\n return mathUtils.matrixMultiply([r, g, b], SRGB_TO_XYZ);\n}\n/**\n * Converts a color represented in Lab color space into an ARGB\n * integer.\n */\nexport function argbFromLab(l, a, b) {\n const whitePoint = WHITE_POINT_D65;\n const fy = (l + 16.0) / 116.0;\n const fx = a / 500.0 + fy;\n const fz = fy - b / 200.0;\n const xNormalized = labInvf(fx);\n const yNormalized = labInvf(fy);\n const zNormalized = labInvf(fz);\n const x = xNormalized * whitePoint[0];\n const y = yNormalized * whitePoint[1];\n const z = zNormalized * whitePoint[2];\n return argbFromXyz(x, y, z);\n}\n/**\n * Converts a color from ARGB representation to L*a*b*\n * representation.\n *\n * @param argb the ARGB representation of a color\n * @return a Lab object representing the color\n */\nexport function labFromArgb(argb) {\n const linearR = linearized(redFromArgb(argb));\n const linearG = linearized(greenFromArgb(argb));\n const linearB = linearized(blueFromArgb(argb));\n const matrix = SRGB_TO_XYZ;\n const x = matrix[0][0] * linearR + matrix[0][1] * linearG + matrix[0][2] * linearB;\n const y = matrix[1][0] * linearR + matrix[1][1] * linearG + matrix[1][2] * linearB;\n const z = matrix[2][0] * linearR + matrix[2][1] * linearG + matrix[2][2] * linearB;\n const whitePoint = WHITE_POINT_D65;\n const xNormalized = x / whitePoint[0];\n const yNormalized = y / whitePoint[1];\n const zNormalized = z / whitePoint[2];\n const fx = labF(xNormalized);\n const fy = labF(yNormalized);\n const fz = labF(zNormalized);\n const l = 116.0 * fy - 16;\n const a = 500.0 * (fx - fy);\n const b = 200.0 * (fy - fz);\n return [l, a, b];\n}\n/**\n * Converts an L* value to an ARGB representation.\n *\n * @param lstar L* in L*a*b*\n * @return ARGB representation of grayscale color with lightness\n * matching L*\n */\nexport function argbFromLstar(lstar) {\n const y = yFromLstar(lstar);\n const component = delinearized(y);\n return argbFromRgb(component, component, component);\n}\n/**\n * Computes the L* value of a color in ARGB representation.\n *\n * @param argb ARGB representation of a color\n * @return L*, from L*a*b*, coordinate of the color\n */\nexport function lstarFromArgb(argb) {\n const y = xyzFromArgb(argb)[1];\n return 116.0 * labF(y / 100.0) - 16.0;\n}\n/**\n * Converts an L* value to a Y value.\n *\n * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.\n *\n * L* measures perceptual luminance, a linear scale. Y in XYZ\n * measures relative luminance, a logarithmic scale.\n *\n * @param lstar L* in L*a*b*\n * @return Y in XYZ\n */\nexport function yFromLstar(lstar) {\n return 100.0 * labInvf((lstar + 16.0) / 116.0);\n}\n/**\n * Converts a Y value to an L* value.\n *\n * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.\n *\n * L* measures perceptual luminance, a linear scale. Y in XYZ\n * measures relative luminance, a logarithmic scale.\n *\n * @param y Y in XYZ\n * @return L* in L*a*b*\n */\nexport function lstarFromY(y) {\n return labF(y / 100.0) * 116.0 - 16.0;\n}\n/**\n * Linearizes an RGB component.\n *\n * @param rgbComponent 0 <= rgb_component <= 255, represents R/G/B\n * channel\n * @return 0.0 <= output <= 100.0, color channel converted to\n * linear RGB space\n */\nexport function linearized(rgbComponent) {\n const normalized = rgbComponent / 255.0;\n if (normalized <= 0.040449936) {\n return normalized / 12.92 * 100.0;\n }\n else {\n return Math.pow((normalized + 0.055) / 1.055, 2.4) * 100.0;\n }\n}\n/**\n * Delinearizes an RGB component.\n *\n * @param rgbComponent 0.0 <= rgb_component <= 100.0, represents\n * linear R/G/B channel\n * @return 0 <= output <= 255, color channel converted to regular\n * RGB space\n */\nexport function delinearized(rgbComponent) {\n const normalized = rgbComponent / 100.0;\n let delinearized = 0.0;\n if (normalized <= 0.0031308) {\n delinearized = normalized * 12.92;\n }\n else {\n delinearized = 1.055 * Math.pow(normalized, 1.0 / 2.4) - 0.055;\n }\n return mathUtils.clampInt(0, 255, Math.round(delinearized * 255.0));\n}\n/**\n * Returns the standard white point; white on a sunny day.\n *\n * @return The white point\n */\nexport function whitePointD65() {\n return WHITE_POINT_D65;\n}\n/**\n * Return RGBA from a given int32 color\n *\n * @param argb ARGB representation of a int32 color.\n * @return RGBA representation of a int32 color.\n */\nexport function rgbaFromArgb(argb) {\n const r = redFromArgb(argb);\n const g = greenFromArgb(argb);\n const b = blueFromArgb(argb);\n const a = alphaFromArgb(argb);\n return { r, g, b, a };\n}\n/**\n * Return int32 color from a given RGBA component\n *\n * @param rgba RGBA representation of a int32 color.\n * @returns ARGB representation of a int32 color.\n */\nexport function argbFromRgba({ r, g, b, a }) {\n const rValue = clampComponent(r);\n const gValue = clampComponent(g);\n const bValue = clampComponent(b);\n const aValue = clampComponent(a);\n return (aValue << 24) | (rValue << 16) | (gValue << 8) | bValue;\n}\nfunction clampComponent(value) {\n if (value < 0)\n return 0;\n if (value > 255)\n return 255;\n return value;\n}\nfunction labF(t) {\n const e = 216.0 / 24389.0;\n const kappa = 24389.0 / 27.0;\n if (t > e) {\n return Math.pow(t, 1.0 / 3.0);\n }\n else {\n return (kappa * t + 16) / 116;\n }\n}\nfunction labInvf(ft) {\n const e = 216.0 / 24389.0;\n const kappa = 24389.0 / 27.0;\n const ft3 = ft * ft * ft;\n if (ft3 > e) {\n return ft3;\n }\n else {\n return (116 * ft - 16) / kappa;\n }\n}\n//# sourceMappingURL=color_utils.js.map","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as utils from '../utils/color_utils.js';\nimport * as math from '../utils/math_utils.js';\n/**\n * In traditional color spaces, a color can be identified solely by the\n * observer's measurement of the color. Color appearance models such as CAM16\n * also use information about the environment where the color was\n * observed, known as the viewing conditions.\n *\n * For example, white under the traditional assumption of a midday sun white\n * point is accurately measured as a slightly chromatic blue by CAM16. (roughly,\n * hue 203, chroma 3, lightness 100)\n *\n * This class caches intermediate values of the CAM16 conversion process that\n * depend only on viewing conditions, enabling speed ups.\n */\nexport class ViewingConditions {\n /**\n * Create ViewingConditions from a simple, physically relevant, set of\n * parameters.\n *\n * @param whitePoint White point, measured in the XYZ color space.\n * default = D65, or sunny day afternoon\n * @param adaptingLuminance The luminance of the adapting field. Informally,\n * how bright it is in the room where the color is viewed. Can be\n * calculated from lux by multiplying lux by 0.0586. default = 11.72,\n * or 200 lux.\n * @param backgroundLstar The lightness of the area surrounding the color.\n * measured by L* in L*a*b*. default = 50.0\n * @param surround A general description of the lighting surrounding the\n * color. 0 is pitch dark, like watching a movie in a theater. 1.0 is a\n * dimly light room, like watching TV at home at night. 2.0 means there\n * is no difference between the lighting on the color and around it.\n * default = 2.0\n * @param discountingIlluminant Whether the eye accounts for the tint of the\n * ambient lighting, such as knowing an apple is still red in green light.\n * default = false, the eye does not perform this process on\n * self-luminous objects like displays.\n */\n static make(whitePoint = utils.whitePointD65(), adaptingLuminance = (200.0 / Math.PI) * utils.yFromLstar(50.0) / 100.0, backgroundLstar = 50.0, surround = 2.0, discountingIlluminant = false) {\n const xyz = whitePoint;\n const rW = xyz[0] * 0.401288 + xyz[1] * 0.650173 + xyz[2] * -0.051461;\n const gW = xyz[0] * -0.250268 + xyz[1] * 1.204414 + xyz[2] * 0.045854;\n const bW = xyz[0] * -0.002079 + xyz[1] * 0.048952 + xyz[2] * 0.953127;\n const f = 0.8 + surround / 10.0;\n const c = f >= 0.9 ? math.lerp(0.59, 0.69, (f - 0.9) * 10.0) :\n math.lerp(0.525, 0.59, (f - 0.8) * 10.0);\n let d = discountingIlluminant ?\n 1.0 :\n f * (1.0 - (1.0 / 3.6) * Math.exp((-adaptingLuminance - 42.0) / 92.0));\n d = d > 1.0 ? 1.0 : d < 0.0 ? 0.0 : d;\n const nc = f;\n const rgbD = [\n d * (100.0 / rW) + 1.0 - d,\n d * (100.0 / gW) + 1.0 - d,\n d * (100.0 / bW) + 1.0 - d,\n ];\n const k = 1.0 / (5.0 * adaptingLuminance + 1.0);\n const k4 = k * k * k * k;\n const k4F = 1.0 - k4;\n const fl = k4 * adaptingLuminance +\n 0.1 * k4F * k4F * Math.cbrt(5.0 * adaptingLuminance);\n const n = utils.yFromLstar(backgroundLstar) / whitePoint[1];\n const z = 1.48 + Math.sqrt(n);\n const nbb = 0.725 / Math.pow(n, 0.2);\n const ncb = nbb;\n const rgbAFactors = [\n Math.pow((fl * rgbD[0] * rW) / 100.0, 0.42),\n Math.pow((fl * rgbD[1] * gW) / 100.0, 0.42),\n Math.pow((fl * rgbD[2] * bW) / 100.0, 0.42),\n ];\n const rgbA = [\n (400.0 * rgbAFactors[0]) / (rgbAFactors[0] + 27.13),\n (400.0 * rgbAFactors[1]) / (rgbAFactors[1] + 27.13),\n (400.0 * rgbAFactors[2]) / (rgbAFactors[2] + 27.13),\n ];\n const aw = (2.0 * rgbA[0] + rgbA[1] + 0.05 * rgbA[2]) * nbb;\n return new ViewingConditions(n, aw, nbb, ncb, c, nc, rgbD, fl, Math.pow(fl, 0.25), z);\n }\n /**\n * Parameters are intermediate values of the CAM16 conversion process. Their\n * names are shorthand for technical color science terminology, this class\n * would not benefit from documenting them individually. A brief overview\n * is available in the CAM16 specification, and a complete overview requires\n * a color science textbook, such as Fairchild's Color Appearance Models.\n */\n constructor(n, aw, nbb, ncb, c, nc, rgbD, fl, fLRoot, z) {\n this.n = n;\n this.aw = aw;\n this.nbb = nbb;\n this.ncb = ncb;\n this.c = c;\n this.nc = nc;\n this.rgbD = rgbD;\n this.fl = fl;\n this.fLRoot = fLRoot;\n this.z = z;\n }\n}\n/** sRGB-like viewing conditions. */\nViewingConditions.DEFAULT = ViewingConditions.make();\n//# sourceMappingURL=viewing_conditions.js.map","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as utils from '../utils/color_utils.js';\nimport * as math from '../utils/math_utils.js';\nimport { ViewingConditions } from './viewing_conditions.js';\n/**\n * CAM16, a color appearance model. Colors are not just defined by their hex\n * code, but rather, a hex code and viewing conditions.\n *\n * CAM16 instances also have coordinates in the CAM16-UCS space, called J*, a*,\n * b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16\n * specification, and should be used when measuring distances between colors.\n *\n * In traditional color spaces, a color can be identified solely by the\n * observer's measurement of the color. Color appearance models such as CAM16\n * also use information about the environment where the color was\n * observed, known as the viewing conditions.\n *\n * For example, white under the traditional assumption of a midday sun white\n * point is accurately measured as a slightly chromatic blue by CAM16. (roughly,\n * hue 203, chroma 3, lightness 100)\n */\nexport class Cam16 {\n /**\n * All of the CAM16 dimensions can be calculated from 3 of the dimensions, in\n * the following combinations:\n * - {j or q} and {c, m, or s} and hue\n * - jstar, astar, bstar\n * Prefer using a static method that constructs from 3 of those dimensions.\n * This constructor is intended for those methods to use to return all\n * possible dimensions.\n *\n * @param hue\n * @param chroma informally, colorfulness / color intensity. like saturation\n * in HSL, except perceptually accurate.\n * @param j lightness\n * @param q brightness; ratio of lightness to white point's lightness\n * @param m colorfulness\n * @param s saturation; ratio of chroma to white point's chroma\n * @param jstar CAM16-UCS J coordinate\n * @param astar CAM16-UCS a coordinate\n * @param bstar CAM16-UCS b coordinate\n */\n constructor(hue, chroma, j, q, m, s, jstar, astar, bstar) {\n this.hue = hue;\n this.chroma = chroma;\n this.j = j;\n this.q = q;\n this.m = m;\n this.s = s;\n this.jstar = jstar;\n this.astar = astar;\n this.bstar = bstar;\n }\n /**\n * CAM16 instances also have coordinates in the CAM16-UCS space, called J*,\n * a*, b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16\n * specification, and is used to measure distances between colors.\n */\n distance(other) {\n const dJ = this.jstar - other.jstar;\n const dA = this.astar - other.astar;\n const dB = this.bstar - other.bstar;\n const dEPrime = Math.sqrt(dJ * dJ + dA * dA + dB * dB);\n const dE = 1.41 * Math.pow(dEPrime, 0.63);\n return dE;\n }\n /**\n * @param argb ARGB representation of a color.\n * @return CAM16 color, assuming the color was viewed in default viewing\n * conditions.\n */\n static fromInt(argb) {\n return Cam16.fromIntInViewingConditions(argb, ViewingConditions.DEFAULT);\n }\n /**\n * @param argb ARGB representation of a color.\n * @param viewingConditions Information about the environment where the color\n * was observed.\n * @return CAM16 color.\n */\n static fromIntInViewingConditions(argb, viewingConditions) {\n const red = (argb & 0x00ff0000) >> 16;\n const green = (argb & 0x0000ff00) >> 8;\n const blue = (argb & 0x000000ff);\n const redL = utils.linearized(red);\n const greenL = utils.linearized(green);\n const blueL = utils.linearized(blue);\n const x = 0.41233895 * redL + 0.35762064 * greenL + 0.18051042 * blueL;\n const y = 0.2126 * redL + 0.7152 * greenL + 0.0722 * blueL;\n const z = 0.01932141 * redL + 0.11916382 * greenL + 0.95034478 * blueL;\n const rC = 0.401288 * x + 0.650173 * y - 0.051461 * z;\n const gC = -0.250268 * x + 1.204414 * y + 0.045854 * z;\n const bC = -0.002079 * x + 0.048952 * y + 0.953127 * z;\n const rD = viewingConditions.rgbD[0] * rC;\n const gD = viewingConditions.rgbD[1] * gC;\n const bD = viewingConditions.rgbD[2] * bC;\n const rAF = Math.pow((viewingConditions.fl * Math.abs(rD)) / 100.0, 0.42);\n const gAF = Math.pow((viewingConditions.fl * Math.abs(gD)) / 100.0, 0.42);\n const bAF = Math.pow((viewingConditions.fl * Math.abs(bD)) / 100.0, 0.42);\n const rA = (math.signum(rD) * 400.0 * rAF) / (rAF + 27.13);\n const gA = (math.signum(gD) * 400.0 * gAF) / (gAF + 27.13);\n const bA = (math.signum(bD) * 400.0 * bAF) / (bAF + 27.13);\n const a = (11.0 * rA + -12.0 * gA + bA) / 11.0;\n const b = (rA + gA - 2.0 * bA) / 9.0;\n const u = (20.0 * rA + 20.0 * gA + 21.0 * bA) / 20.0;\n const p2 = (40.0 * rA + 20.0 * gA + bA) / 20.0;\n const atan2 = Math.atan2(b, a);\n const atanDegrees = (atan2 * 180.0) / Math.PI;\n const hue = atanDegrees < 0 ? atanDegrees + 360.0 :\n atanDegrees >= 360 ? atanDegrees - 360.0 :\n atanDegrees;\n const hueRadians = (hue * Math.PI) / 180.0;\n const ac = p2 * viewingConditions.nbb;\n const j = 100.0 *\n Math.pow(ac / viewingConditions.aw, viewingConditions.c * viewingConditions.z);\n const q = (4.0 / viewingConditions.c) * Math.sqrt(j / 100.0) *\n (viewingConditions.aw + 4.0) * viewingConditions.fLRoot;\n const huePrime = hue < 20.14 ? hue + 360 : hue;\n const eHue = 0.25 * (Math.cos((huePrime * Math.PI) / 180.0 + 2.0) + 3.8);\n const p1 = (50000.0 / 13.0) * eHue * viewingConditions.nc * viewingConditions.ncb;\n const t = (p1 * Math.sqrt(a * a + b * b)) / (u + 0.305);\n const alpha = Math.pow(t, 0.9) *\n Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73);\n const c = alpha * Math.sqrt(j / 100.0);\n const m = c * viewingConditions.fLRoot;\n const s = 50.0 *\n Math.sqrt((alpha * viewingConditions.c) / (viewingConditions.aw + 4.0));\n const jstar = ((1.0 + 100.0 * 0.007) * j) / (1.0 + 0.007 * j);\n const mstar = (1.0 / 0.0228) * Math.log(1.0 + 0.0228 * m);\n const astar = mstar * Math.cos(hueRadians);\n const bstar = mstar * Math.sin(hueRadians);\n return new Cam16(hue, c, j, q, m, s, jstar, astar, bstar);\n }\n /**\n * @param j CAM16 lightness\n * @param c CAM16 chroma\n * @param h CAM16 hue\n */\n static fromJch(j, c, h) {\n return Cam16.fromJchInViewingConditions(j, c, h, ViewingConditions.DEFAULT);\n }\n /**\n * @param j CAM16 lightness\n * @param c CAM16 chroma\n * @param h CAM16 hue\n * @param viewingConditions Information about the environment where the color\n * was observed.\n */\n static fromJchInViewingConditions(j, c, h, viewingConditions) {\n const q = (4.0 / viewingConditions.c) * Math.sqrt(j / 100.0) *\n (viewingConditions.aw + 4.0) * viewingConditions.fLRoot;\n const m = c * viewingConditions.fLRoot;\n const alpha = c / Math.sqrt(j / 100.0);\n const s = 50.0 *\n Math.sqrt((alpha * viewingConditions.c) / (viewingConditions.aw + 4.0));\n const hueRadians = (h * Math.PI) / 180.0;\n const jstar = ((1.0 + 100.0 * 0.007) * j) / (1.0 + 0.007 * j);\n const mstar = (1.0 / 0.0228) * Math.log(1.0 + 0.0228 * m);\n const astar = mstar * Math.cos(hueRadians);\n const bstar = mstar * Math.sin(hueRadians);\n return new Cam16(h, c, j, q, m, s, jstar, astar, bstar);\n }\n /**\n * @param jstar CAM16-UCS lightness.\n * @param astar CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian\n * coordinate on the Y axis.\n * @param bstar CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian\n * coordinate on the X axis.\n */\n static fromUcs(jstar, astar, bstar) {\n return Cam16.fromUcsInViewingConditions(jstar, astar, bstar, ViewingConditions.DEFAULT);\n }\n /**\n * @param jstar CAM16-UCS lightness.\n * @param astar CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian\n * coordinate on the Y axis.\n * @param bstar CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian\n * coordinate on the X axis.\n * @param viewingConditions Information about the environment where the color\n * was observed.\n */\n static fromUcsInViewingConditions(jstar, astar, bstar, viewingConditions) {\n const a = astar;\n const b = bstar;\n const m = Math.sqrt(a * a + b * b);\n const M = (Math.exp(m * 0.0228) - 1.0) / 0.0228;\n const c = M / viewingConditions.fLRoot;\n let h = Math.atan2(b, a) * (180.0 / Math.PI);\n if (h < 0.0) {\n h += 360.0;\n }\n const j = jstar / (1 - (jstar - 100) * 0.007);\n return Cam16.fromJchInViewingConditions(j, c, h, viewingConditions);\n }\n /**\n * @return ARGB representation of color, assuming the color was viewed in\n * default viewing conditions, which are near-identical to the default\n * viewing conditions for sRGB.\n */\n toInt() {\n return this.viewed(ViewingConditions.DEFAULT);\n }\n /**\n * @param viewingConditions Information about the environment where the color\n * will be viewed.\n * @return ARGB representation of color\n */\n viewed(viewingConditions) {\n const alpha = this.chroma === 0.0 || this.j === 0.0 ?\n 0.0 :\n this.chroma / Math.sqrt(this.j / 100.0);\n const t = Math.pow(alpha / Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73), 1.0 / 0.9);\n const hRad = (this.hue * Math.PI) / 180.0;\n const eHue = 0.25 * (Math.cos(hRad + 2.0) + 3.8);\n const ac = viewingConditions.aw *\n Math.pow(this.j / 100.0, 1.0 / viewingConditions.c / viewingConditions.z);\n const p1 = eHue * (50000.0 / 13.0) * viewingConditions.nc * viewingConditions.ncb;\n const p2 = ac / viewingConditions.nbb;\n const hSin = Math.sin(hRad);\n const hCos = Math.cos(hRad);\n const gamma = (23.0 * (p2 + 0.305) * t) /\n (23.0 * p1 + 11.0 * t * hCos + 108.0 * t * hSin);\n const a = gamma * hCos;\n const b = gamma * hSin;\n const rA = (460.0 * p2 + 451.0 * a + 288.0 * b) / 1403.0;\n const gA = (460.0 * p2 - 891.0 * a - 261.0 * b) / 1403.0;\n const bA = (460.0 * p2 - 220.0 * a - 6300.0 * b) / 1403.0;\n const rCBase = Math.max(0, (27.13 * Math.abs(rA)) / (400.0 - Math.abs(rA)));\n const rC = math.signum(rA) * (100.0 / viewingConditions.fl) *\n Math.pow(rCBase, 1.0 / 0.42);\n const gCBase = Math.max(0, (27.13 * Math.abs(gA)) / (400.0 - Math.abs(gA)));\n const gC = math.signum(gA) * (100.0 / viewingConditions.fl) *\n Math.pow(gCBase, 1.0 / 0.42);\n const bCBase = Math.max(0, (27.13 * Math.abs(bA)) / (400.0 - Math.abs(bA)));\n const bC = math.signum(bA) * (100.0 / viewingConditions.fl) *\n Math.pow(bCBase, 1.0 / 0.42);\n const rF = rC / viewingConditions.rgbD[0];\n const gF = gC / viewingConditions.rgbD[1];\n const bF = bC / viewingConditions.rgbD[2];\n const x = 1.86206786 * rF - 1.01125463 * gF + 0.14918677 * bF;\n const y = 0.38752654 * rF + 0.62144744 * gF - 0.00897398 * bF;\n const z = -0.01584150 * rF - 0.03412294 * gF + 1.04996444 * bF;\n const argb = utils.argbFromXyz(x, y, z);\n return argb;\n }\n /// Given color expressed in XYZ and viewed in [viewingConditions], convert to\n /// CAM16.\n static fromXyzInViewingConditions(x, y, z, viewingConditions) {\n // Transform XYZ to 'cone'/'rgb' responses\n const rC = 0.401288 * x + 0.650173 * y - 0.051461 * z;\n const gC = -0.250268 * x + 1.204414 * y + 0.045854 * z;\n const bC = -0.002079 * x + 0.048952 * y + 0.953127 * z;\n // Discount illuminant\n const rD = viewingConditions.rgbD[0] * rC;\n const gD = viewingConditions.rgbD[1] * gC;\n const bD = viewingConditions.rgbD[2] * bC;\n // chromatic adaptation\n const rAF = Math.pow(viewingConditions.fl * Math.abs(rD) / 100.0, 0.42);\n const gAF = Math.pow(viewingConditions.fl * Math.abs(gD) / 100.0, 0.42);\n const bAF = Math.pow(viewingConditions.fl * Math.abs(bD) / 100.0, 0.42);\n const rA = math.signum(rD) * 400.0 * rAF / (rAF + 27.13);\n const gA = math.signum(gD) * 400.0 * gAF / (gAF + 27.13);\n const bA = math.signum(bD) * 400.0 * bAF / (bAF + 27.13);\n // redness-greenness\n const a = (11.0 * rA + -12.0 * gA + bA) / 11.0;\n // yellowness-blueness\n const b = (rA + gA - 2.0 * bA) / 9.0;\n // auxiliary components\n const u = (20.0 * rA + 20.0 * gA + 21.0 * bA) / 20.0;\n const p2 = (40.0 * rA + 20.0 * gA + bA) / 20.0;\n // hue\n const atan2 = Math.atan2(b, a);\n const atanDegrees = atan2 * 180.0 / Math.PI;\n const hue = atanDegrees < 0 ? atanDegrees + 360.0 :\n atanDegrees >= 360 ? atanDegrees - 360 :\n atanDegrees;\n const hueRadians = hue * Math.PI / 180.0;\n // achromatic response to color\n const ac = p2 * viewingConditions.nbb;\n // CAM16 lightness and brightness\n const J = 100.0 *\n Math.pow(ac / viewingConditions.aw, viewingConditions.c * viewingConditions.z);\n const Q = (4.0 / viewingConditions.c) * Math.sqrt(J / 100.0) *\n (viewingConditions.aw + 4.0) * (viewingConditions.fLRoot);\n const huePrime = (hue < 20.14) ? hue + 360 : hue;\n const eHue = (1.0 / 4.0) * (Math.cos(huePrime * Math.PI / 180.0 + 2.0) + 3.8);\n const p1 = 50000.0 / 13.0 * eHue * viewingConditions.nc * viewingConditions.ncb;\n const t = p1 * Math.sqrt(a * a + b * b) / (u + 0.305);\n const alpha = Math.pow(t, 0.9) *\n Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73);\n // CAM16 chroma, colorfulness, chroma\n const C = alpha * Math.sqrt(J / 100.0);\n const M = C * viewingConditions.fLRoot;\n const s = 50.0 *\n Math.sqrt((alpha * viewingConditions.c) / (viewingConditions.aw + 4.0));\n // CAM16-UCS components\n const jstar = (1.0 + 100.0 * 0.007) * J / (1.0 + 0.007 * J);\n const mstar = Math.log(1.0 + 0.0228 * M) / 0.0228;\n const astar = mstar * Math.cos(hueRadians);\n const bstar = mstar * Math.sin(hueRadians);\n return new Cam16(hue, C, J, Q, M, s, jstar, astar, bstar);\n }\n /// XYZ representation of CAM16 seen in [viewingConditions].\n xyzInViewingConditions(viewingConditions) {\n const alpha = (this.chroma === 0.0 || this.j === 0.0) ?\n 0.0 :\n this.chroma / Math.sqrt(this.j / 100.0);\n const t = Math.pow(alpha / Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73), 1.0 / 0.9);\n const hRad = this.hue * Math.PI / 180.0;\n const eHue = 0.25 * (Math.cos(hRad + 2.0) + 3.8);\n const ac = viewingConditions.aw *\n Math.pow(this.j / 100.0, 1.0 / viewingConditions.c / viewingConditions.z);\n const p1 = eHue * (50000.0 / 13.0) * viewingConditions.nc * viewingConditions.ncb;\n const p2 = (ac / viewingConditions.nbb);\n const hSin = Math.sin(hRad);\n const hCos = Math.cos(hRad);\n const gamma = 23.0 * (p2 + 0.305) * t /\n (23.0 * p1 + 11 * t * hCos + 108.0 * t * hSin);\n const a = gamma * hCos;\n const b = gamma * hSin;\n const rA = (460.0 * p2 + 451.0 * a + 288.0 * b) / 1403.0;\n const gA = (460.0 * p2 - 891.0 * a - 261.0 * b) / 1403.0;\n const bA = (460.0 * p2 - 220.0 * a - 6300.0 * b) / 1403.0;\n const rCBase = Math.max(0, (27.13 * Math.abs(rA)) / (400.0 - Math.abs(rA)));\n const rC = math.signum(rA) * (100.0 / viewingConditions.fl) *\n Math.pow(rCBase, 1.0 / 0.42);\n const gCBase = Math.max(0, (27.13 * Math.abs(gA)) / (400.0 - Math.abs(gA)));\n const gC = math.signum(gA) * (100.0 / viewingConditions.fl) *\n Math.pow(gCBase, 1.0 / 0.42);\n const bCBase = Math.max(0, (27.13 * Math.abs(bA)) / (400.0 - Math.abs(bA)));\n const bC = math.signum(bA) * (100.0 / viewingConditions.fl) *\n Math.pow(bCBase, 1.0 / 0.42);\n const rF = rC / viewingConditions.rgbD[0];\n const gF = gC / viewingConditions.rgbD[1];\n const bF = bC / viewingConditions.rgbD[2];\n const x = 1.86206786 * rF - 1.01125463 * gF + 0.14918677 * bF;\n const y = 0.38752654 * rF + 0.62144744 * gF - 0.00897398 * bF;\n const z = -0.01584150 * rF - 0.03412294 * gF + 1.04996444 * bF;\n return [x, y, z];\n }\n}\n//# sourceMappingURL=cam16.js.map","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// This file is automatically generated. Do not modify it.\nimport * as colorUtils from '../utils/color_utils.js';\nimport * as mathUtils from '../utils/math_utils.js';\nimport { Cam16 } from './cam16.js';\nimport { ViewingConditions } from './viewing_conditions.js';\n// material_color_utilities is designed to have a consistent API across\n// platforms and modular components that can be moved around easily. Using a\n// class as a namespace facilitates this.\n//\n// tslint:disable:class-as-namespace\n/**\n * A class that solves the HCT equation.\n */\nexport class HctSolver {\n /**\n * Sanitizes a small enough angle in radians.\n *\n * @param angle An angle in radians; must not deviate too much\n * from 0.\n * @return A coterminal angle between 0 and 2pi.\n */\n static sanitizeRadians(angle) {\n return (angle + Math.PI * 8) % (Math.PI * 2);\n }\n /**\n * Delinearizes an RGB component, returning a floating-point\n * number.\n *\n * @param rgbComponent 0.0 <= rgb_component <= 100.0, represents\n * linear R/G/B channel\n * @return 0.0 <= output <= 255.0, color channel converted to\n * regular RGB space\n */\n static trueDelinearized(rgbComponent) {\n const normalized = rgbComponent / 100.0;\n let delinearized = 0.0;\n if (normalized <= 0.0031308) {\n delinearized = normalized * 12.92;\n }\n else {\n delinearized = 1.055 * Math.pow(normalized, 1.0 / 2.4) - 0.055;\n }\n return delinearized * 255.0;\n }\n static chromaticAdaptation(component) {\n const af = Math.pow(Math.abs(component), 0.42);\n return mathUtils.signum(component) * 400.0 * af / (af + 27.13);\n }\n /**\n * Returns the hue of a linear RGB color in CAM16.\n *\n * @param linrgb The linear RGB coordinates of a color.\n * @return The hue of the color in CAM16, in radians.\n */\n static hueOf(linrgb) {\n const scaledDiscount = mathUtils.matrixMultiply(linrgb, HctSolver.SCALED_DISCOUNT_FROM_LINRGB);\n const rA = HctSolver.chromaticAdaptation(scaledDiscount[0]);\n const gA = HctSolver.chromaticAdaptation(scaledDiscount[1]);\n const bA = HctSolver.chromaticAdaptation(scaledDiscount[2]);\n // redness-greenness\n const a = (11.0 * rA + -12.0 * gA + bA) / 11.0;\n // yellowness-blueness\n const b = (rA + gA - 2.0 * bA) / 9.0;\n return Math.atan2(b, a);\n }\n static areInCyclicOrder(a, b, c) {\n const deltaAB = HctSolver.sanitizeRadians(b - a);\n const deltaAC = HctSolver.sanitizeRadians(c - a);\n return deltaAB < deltaAC;\n }\n /**\n * Solves the lerp equation.\n *\n * @param source The starting number.\n * @param mid The number in the middle.\n * @param target The ending number.\n * @return A number t such that lerp(source, target, t) = mid.\n */\n static intercept(source, mid, target) {\n return (mid - source) / (target - source);\n }\n static lerpPoint(source, t, target) {\n return [\n source[0] + (target[0] - source[0]) * t,\n source[1] + (target[1] - source[1]) * t,\n source[2] + (target[2] - source[2]) * t,\n ];\n }\n /**\n * Intersects a segment with a plane.\n *\n * @param source The coordinates of point A.\n * @param coordinate The R-, G-, or B-coordinate of the plane.\n * @param target The coordinates of point B.\n * @param axis The axis the plane is perpendicular with. (0: R, 1:\n * G, 2: B)\n * @return The intersection point of the segment AB with the plane\n * R=coordinate, G=coordinate, or B=coordinate\n */\n static setCoordinate(source, coordinate, target, axis) {\n const t = HctSolver.intercept(source[axis], coordinate, target[axis]);\n return HctSolver.lerpPoint(source, t, target);\n }\n static isBounded(x) {\n return 0.0 <= x && x <= 100.0;\n }\n /**\n * Returns the nth possible vertex of the polygonal intersection.\n *\n * @param y The Y value of the plane.\n * @param n The zero-based index of the point. 0 <= n <= 11.\n * @return The nth possible vertex of the polygonal intersection\n * of the y plane and the RGB cube, in linear RGB coordinates, if\n * it exists. If this possible vertex lies outside of the cube,\n * [-1.0, -1.0, -1.0] is returned.\n */\n static nthVertex(y, n) {\n const kR = HctSolver.Y_FROM_LINRGB[0];\n const kG = HctSolver.Y_FROM_LINRGB[1];\n const kB = HctSolver.Y_FROM_LINRGB[2];\n const coordA = n % 4 <= 1 ? 0.0 : 100.0;\n const coordB = n % 2 === 0 ? 0.0 : 100.0;\n if (n < 4) {\n const g = coordA;\n const b = coordB;\n const r = (y - g * kG - b * kB) / kR;\n if (HctSolver.isBounded(r)) {\n return [r, g, b];\n }\n else {\n return [-1.0, -1.0, -1.0];\n }\n }\n else if (n < 8) {\n const b = coordA;\n const r = coordB;\n const g = (y - r * kR - b * kB) / kG;\n if (HctSolver.isBounded(g)) {\n return [r, g, b];\n }\n else {\n return [-1.0, -1.0, -1.0];\n }\n }\n else {\n const r = coordA;\n const g = coordB;\n const b = (y - r * kR - g * kG) / kB;\n if (HctSolver.isBounded(b)) {\n return [r, g, b];\n }\n else {\n return [-1.0, -1.0, -1.0];\n }\n }\n }\n /**\n * Finds the segment containing the desired color.\n *\n * @param y The Y value of the color.\n * @param targetHue The hue of the color.\n * @return A list of two sets of linear RGB coordinates, each\n * corresponding to an endpoint of the segment containing the\n * desired color.\n */\n static bisectToSegment(y, targetHue) {\n let left = [-1.0, -1.0, -1.0];\n let right = left;\n let leftHue = 0.0;\n let rightHue = 0.0;\n let initialized = false;\n let uncut = true;\n for (let n = 0; n < 12; n++) {\n const mid = HctSolver.nthVertex(y, n);\n if (mid[0] < 0) {\n continue;\n }\n const midHue = HctSolver.hueOf(mid);\n if (!initialized) {\n left = mid;\n right = mid;\n leftHue = midHue;\n rightHue = midHue;\n initialized = true;\n continue;\n }\n if (uncut || HctSolver.areInCyclicOrder(leftHue, midHue, rightHue)) {\n uncut = false;\n if (HctSolver.areInCyclicOrder(leftHue, targetHue, midHue)) {\n right = mid;\n rightHue = midHue;\n }\n else {\n left = mid;\n leftHue = midHue;\n }\n }\n }\n return [left, right];\n }\n static midpoint(a, b) {\n return [\n (a[0] + b[0]) / 2,\n (a[1] + b[1]) / 2,\n (a[2] + b[2]) / 2,\n ];\n }\n static criticalPlaneBelow(x) {\n return Math.floor(x - 0.5);\n }\n static criticalPlaneAbove(x) {\n return Math.ceil(x - 0.5);\n }\n /**\n * Finds a color with the given Y and hue on the boundary of the\n * cube.\n *\n * @param y The Y value of the color.\n * @param targetHue The hue of the color.\n * @return The desired color, in linear RGB coordinates.\n */\n static bisectToLimit(y, targetHue) {\n const segment = HctSolver.bisectToSegment(y, targetHue);\n let left = segment[0];\n let leftHue = HctSolver.hueOf(left);\n let right = segment[1];\n for (let axis = 0; axis < 3; axis++) {\n if (left[axis] !== right[axis]) {\n let lPlane = -1;\n let rPlane = 255;\n if (left[axis] < right[axis]) {\n lPlane = HctSolver.criticalPlaneBelow(HctSolver.trueDelinearized(left[axis]));\n rPlane = HctSolver.criticalPlaneAbove(HctSolver.trueDelinearized(right[axis]));\n }\n else {\n lPlane = HctSolver.criticalPlaneAbove(HctSolver.trueDelinearized(left[axis]));\n rPlane = HctSolver.criticalPlaneBelow(HctSolver.trueDelinearized(right[axis]));\n }\n for (let i = 0; i < 8; i++) {\n if (Math.abs(rPlane - lPlane) <= 1) {\n break;\n }\n else {\n const mPlane = Math.floor((lPlane + rPlane) / 2.0);\n const midPlaneCoordinate = HctSolver.CRITICAL_PLANES[mPlane];\n const mid = HctSolver.setCoordinate(left, midPlaneCoordinate, right, axis);\n const midHue = HctSolver.hueOf(mid);\n if (HctSolver.areInCyclicOrder(leftHue, targetHue, midHue)) {\n right = mid;\n rPlane = mPlane;\n }\n else {\n left = mid;\n leftHue = midHue;\n lPlane = mPlane;\n }\n }\n }\n }\n }\n return HctSolver.midpoint(left, right);\n }\n static inverseChromaticAdaptation(adapted) {\n const adaptedAbs = Math.abs(adapted);\n const base = Math.max(0, 27.13 * adaptedAbs / (400.0 - adaptedAbs));\n return mathUtil